npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

contro-ui

v3.3.19

Published

This UI library is used by [Nostlan](https://github.com/quinton-ashley/nostlan) to create a UI that can be interacted with via game controllers and/or mouse and keyboard. It requires jQuery and Mousetrap. Optionally you can install `gca-js` as a peer depe

Downloads

39

Readme

contro-ui

This UI library is used by Nostlan to create a UI that can be interacted with via game controllers and/or mouse and keyboard. It requires jQuery and Mousetrap. Optionally you can install gca-js as a peer dependency for Gamecube controller support.

global.cui = require("contro-ui");
cui.start();
doctype html
html
  head
    title Your App's Title
    meta(charset='utf-8')
    link(rel='stylesheet' type='text/css' href=node_modules + '/bootstrap/dist/css/bootstrap.min.css')
    link(rel='stylesheet' type='text/css' href=node_modules + '/contro-ui/dist/css/contro-ui.css')
  body
    #nameOfMenu.menu.row-y
      //- full width button
      .cui.col(name='actionName0') button 0 label text
      .row.row-x
        //- three buttons in horizontal row
        .cui.col(name='actionName1') button 1 label text
        .cui.col(name='actionName2') button 2 label text
        .cui.col(name='actionName3') button 3 label text
    #otherMenu.menu.row-y
      //- ...

API

Experimental UI library!

start(Object options)

Required to initialize contro-ui, adds event listener for gamepad connections, adds click and hover event listeners to all .cui elements.

boolean options.v
enable verbose logging
boolean options.haptic
enable haptic feedback (controller vibrations)
boolean options.gca
enable Gamecube Controller Adapter support (requires npm package gca-js)

async change(String state[, String subState, Object options])

Switch to another state: menu or cui context.

boolean options.keepBackground
keep showing the previous ui, by default it's hidden.

async onChange(String state[, String subState])

Override this function to do something when cui changes to a different state.

async afterChange(String state[, String subState])

Override this function to do something after cui changes to a different state.

async doAction(String act)

Do the specified action.

String act
the action, can be a controller or keyboard action
'a', 'b', 'x', 'y', 'l', 'r' controller face button actions
'up', 'down', 'left', 'right' dpad/leftStick directional movement actions
'back' change state back to the previous ui state
'doubleBack' go back two ui states
'quit' quit the app

async onAction(String act)

Override this function to do something after a keyboard key or controller button press.

async doHeldAction(String act, Number timeHeld)

Do the specified held action.

async onHeldAction(String act, Number timeHeld)

Override this function to do something after a keyboard key or controller button is held.

makeCursor(jQuery $cursor[, String state])

Make $cursor the current cursor, state is the current ui by default.

beforeMove(jQuery $cursor[, String state])

Override this function to do something before the cursor changes.

afterMove(jQuery $cursor[, String state])

Override this function to do something after the cursor changes.

bind(String|Array keys, String act)

Bind keyboard key(s) to a controller button or cui action.

For modifier keys you can use shift, ctrl, alt, or meta.

You can substitute option for alt and command for meta.

Other special keys are backspace, tab, enter, return, capslock, esc, escape, space, pageup, pagedown, end, home, left, up, right, down, ins, del, and plus.

Any other key you should be able to reference by name like a, /, $, *, or =.

For more info look at the Mousetrap documentation.

// example of binding keyboard keys
for (let char of "abcdefghijklmnopqrstuvwxyz1234567890") {
  cui.bind(char, "char-" + char);
}
cui.bind("space", "char-_");

click(jQuery $elem, String act)

Bind mouse clicking on a jQuery DOM element to a controller button or cui action. Don't use on .cui elements! Use the "name" property to set the click action for .cui elements.

addView(String state[, Object options])

Add a menu or other cui context. Will add click listeners for any .cui elems within the view.

editView(String state[, Object options])

Replace view options with the options object given.

async alert(String msg, String title[, String stateAfterAlert])

msg can be text or html, if stateAfterAlert is provided cui will change to that state after the user presses the "okay" button.

async error(String msg[, var code, String stateAfterError])

Error code can be a Number or String, calls the alert function internally.

// example that displays unexpected errors to users
// before quitting the app
const process = require("process");
process.on("uncaughtException", ror => {
  console.error(ror);
  cui.err(`<textarea rows=8>${ror.stack}</textarea>`, "App crashed!", "quit");
});

async resize(Boolean adjust, String state)

Adjust ui components (or not) on resize.

async onResize(Boolean adjust)

Override this method to adjust ui components on resize.

passthrough(Object contro)

Override this function to access the contro object directly, which has the parsed controller button, stick, and trigger info.