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

uzi

v0.0.4

Published

a constraint based layout system

Downloads

4

Readme

An Element positioning system inspired by SICP's "Propagation of Constraints".

Quick Start

npm install
python -mSimpleHTTPServer

Browse the /examples directory.

Feature Overview

<div uz-rect id="A"></div>
<div uz-rect id="B"></div>

Constrain properties of an element.

#B {

  /*  Anchor elements to eachother */
  left: A.right;

  /* Center in another element. */
  center-in: A;

  /* Basic expressions can be used. */
  right: A.right + B.width / 2;

}

/* Classes are supported */
.class-name {
  height: B.width / A.height;
}

Interface with JavaScript.


// assign variables
engine.assign("x", 100);

// add user defined functions
engine.func("fooBar", () => 200);
engine.funcs(Math, "Math");
#B {

  /* using variable */
  height: x * A.height;

  /* using user defined functions */
  width: C.height - Math.min(A.height, fooBar());
  left:  B.right + Math.sin(x) * 100px;
}

Declare rules inline.

<div uz-rect id="A"></div>
<div uz-style="width: A.height * 3"></div>

Rule Attributes

  • left
  • right
  • top
  • bottom
  • width
  • height
  • center-x
  • center-y
  • center-in
  • relative-to
  • align-x
  • align-y
  • size
  • watch

Element Attributes

  • uz-rect
  • uz-style

Special Rects

  • viewport
  • body
  • document

These can be used like any other rect in the system.

#item {
  center-x: viewport.center-x;
  top: 10px;
}

Note: user's can create custom rects by extending the Rect class.

Setup

The Engine class is how the user interacts with the system.

let engine = new uzi.Engine();

// assign variables and attach functions

engine.initialize(/* options */);

By default, the engine will walk the entire DOM and mount Elements which have an uz-rect or uz-style attribute. This behaviour is configured via an options object passed into the Engine#initialize method.

interface EngineOptions {

  // Find and parse script tags where type="text/uzi"
  findStyleSheets?: boolean;

  // Walk the dom and find elements with `uz-rect` or `uz-style` attributes.
  findElements?: boolean;

  // Use the selectors in the stylesheets to lookup elements in the dom.
  lookupSelectors?: boolean;

  // Provide pre-compiled rules to the env.
  envData?: EnvData;
}

Default Engine Options:

{
  findStyleSheets: true,
  findElements:    true
}

Manually managing Element life-cycle

Element life-cycles can be manually managed using the Engine#mount and Engine#unmount methods.

// start managing the element.
engine.mount(element);

// stop managing the element.
engine.unmount(element);

Pre-Compiling

This is still a work in progress.

A cache of all source to compiled rules is kept during runtime. If you export this data, and initialize uzi with it, the parser doesn't need to be sent to the client.

Export:

let envData = engine.getEnv().getExportData();

Import:

let engine = new uzi.Engine({ envData });

Angular Integration

Angular integration lets you use functions and variables from the $scope in your rules.

<div uz-rect
     uz-style="width: 100px * $index"
     ng-repeat="foo in foos">
</div>

Debugging:

The simplest way to debug is to use the System class.

window.system = engine.getSystem();

The System#toString() method will show all relationships. toString takes an optional string parameters which is used to filter the resulting lines.

There is also a System#$ property which uses a Proxy to provide access to the underlying variables with support for tab completion.