Skip to content

cacaodev/lume-kiwi

 
 

Repository files navigation

LUME Kiwi

LUME Kiwi is a fast TypeScript implementation of the Cassowary constraint solving algorithm, based on the seminal Cassowary paper. Originally created by Chris Colbert, it was redesigned from the ground up to be lightweight, fast and easy to maintain. View the benchmarks to see how it compares to Cassowary.js.

Soon it will be compiled to WebAssembly with AssemblyScript (TypeScript to WebAssembly compiler).

Index

Getting started

Install using NPM:

npm install @lume/kiwi

then either load kiwi as a global variable using a script tag,

<script src="/node_modules/kiwi/lib/kiwi.js"></script>
<script>
	console.log(kiwi);

	// ...use kiwi...
</script>

or import it into your ES Module script:

import * as kiwi from '@lume/kiwi';

console.log(kiwi);

// ...use kiwi...

The following example creates a solver which automatically calculates a width based on some constraints:

// Create a solver
var solver = new kiwi.Solver();

// Create edit variables
var left = new kiwi.Variable();
var width = new kiwi.Variable();
solver.addEditVariable(left, kiwi.Strength.strong);
solver.addEditVariable(width, kiwi.Strength.strong);
solver.suggestValue(left, 100);
solver.suggestValue(width, 400);

// Create and add a constraint
var right = new kiwi.Variable();
solver.addConstraint(new kiwi.Constraint(new kiwi.Expression([-1, right], left, width), kiwi.Operator.Eq));

// Solve the constraints
solver.updateVariables();

console.assert(right.value() === 500);

Documentation

Benchmarks

To run the benchmark in the browser, just visit this page.

To run the benchmark locally using nodejs, clone or download this repository and execute the following steps:

npm install
npm run bench

Tests

To run the tests in the browser, just visit this page.

To run the tests locally using nodejs, clone or download this repository and execute the following steps:

npm install
npm run build && npm run test

Contribute

If you like this project and want to support it, show some love and give it a star.

License

© 2013 Nucleic Development Team © 2021 Joseph Orbegoso Pea (http://github.com/trusktr) © 2021 LUME

License

About

Fast TypeScript implementation of the Cassowary constraint solving algorithm (soon for AssemblyScript / WebAssembly).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 57.8%
  • JavaScript 38.7%
  • HTML 3.5%