{"id":19346744,"url":"https://github.com/lume/kiwi","last_synced_at":"2025-04-05T18:07:22.314Z","repository":{"id":37967236,"uuid":"369953373","full_name":"lume/kiwi","owner":"lume","description":"Fast TypeScript implementation of the Cassowary constraint solving algorithm (soon for AssemblyScript / WebAssembly).","archived":false,"fork":false,"pushed_at":"2024-01-25T08:02:07.000Z","size":548,"stargazers_count":131,"open_issues_count":4,"forks_count":8,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-05-23T06:35:26.622Z","etag":null,"topics":["assemblyscript","autolayout","autolayout-constraints","cassowary","constraint-layout","constraint-programming","constraint-solver","constraints","javascript","kiwi","typescript","webassembly"],"latest_commit_sha":null,"homepage":"https://codepen.io/trusktr/pen/abMLVxa","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lume.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-05-23T03:38:20.000Z","updated_at":"2024-05-20T03:40:00.000Z","dependencies_parsed_at":"2022-08-08T22:31:29.663Z","dependency_job_id":"eaa29b3c-cd59-41f6-9dc2-c7b82b2239d0","html_url":"https://github.com/lume/kiwi","commit_stats":{"total_commits":295,"total_committers":13,"mean_commits":"22.692307692307693","dds":0.4949152542372881,"last_synced_commit":"4e63a0c199452e93ddbc73bd24f1a6c58b4a4c10"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lume%2Fkiwi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lume%2Fkiwi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lume%2Fkiwi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lume%2Fkiwi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lume","download_url":"https://codeload.github.com/lume/kiwi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142433,"owners_count":20890730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assemblyscript","autolayout","autolayout-constraints","cassowary","constraint-layout","constraint-programming","constraint-solver","constraints","javascript","kiwi","typescript","webassembly"],"created_at":"2024-11-10T04:12:12.023Z","updated_at":"2025-04-05T18:07:22.287Z","avatar_url":"https://github.com/lume.png","language":"TypeScript","readme":"# LUME Kiwi\n\nLUME Kiwi is a fast TypeScript implementation of the [Cassowary constraint\nsolving algorithm](\u003chttps://en.wikipedia.org/wiki/Cassowary_(software)\u003e), based on the seminal Cassowary paper. Originally created by\nChris Colbert, it was redesigned from the ground up to be lightweight, fast and\neasy to maintain. View the [benchmarks](#benchmarks) to see how it compares to\n[Cassowary.js](https://github.com/slightlyoff/cassowary.js).\n\nSoon it will be compiled to\n[WebAssembly](https://developer.mozilla.org/en-US/docs/WebAssembly) with\n[AssemblyScript](http://assemblyscript.org) (TypeScript to WebAssembly\ncompiler).\n\n## Index\n\n- [Demo](#demo)\n- [Install](#install)\n- [Usage](#usage)\n- [Documentation](#documentation)\n- [Benchmarks](#benchmarks)\n- [Tests](#tests)\n\n## Demo\n\n[Live demo on CodePen.](https://codepen.io/trusktr/pen/abMLVxa?editors=1010)\n\n## Install\n\n### Local Install\n\nInstall using NPM:\n\n```sh\nnpm install @lume/kiwi\n```\n\nIf you have a plain web app with no build, or a non-browser JS runtime that also\nsupports import maps like Deno, you'll need to add `@lume/kiwi` to your\n`importmap` script so that the browser or JS runtime knows where to import kiwi from. F.e.\nsomething like this:\n\n```html\n\u003cscript type=\"importmap\"\u003e\n  {\n    \"imports\": {\n      \"@lume/kiwi\": \"./node_modules/@lume/kiwi/dist/kiwi.js\"\n    }\n  }\n\u003c/script\u003e\n```\n\n### CDN Install\n\nNote, if using importmaps and native ES Modules in a browser, or in a JS runtime like Deno, you can get Kiwi directly from the UNPKG CDN without installing it locally (just as the [live CodePen demo](#demo) does):\n\n```html\n\u003cscript type=\"importmap\"\u003e\n  {\n    \"imports\": {\n      \"@lume/kiwi\": \"https://unpkg.com/@lume/kiwi@0.4.2/dist/kiwi.js\"\n    }\n  }\n\u003c/script\u003e\n```\n\n## Usage\n\nAfter installing, import kiwi into your project:\n\n```js\nimport * as kiwi from '@lume/kiwi'\n\nconsole.log(kiwi)\n\n// ...use kiwi...\n```\n\nThe following example creates a solver which automatically calculates a width based on some constraints:\n\n```js\n// Create a solver\nvar solver = new kiwi.Solver()\n\n// Create edit variables\nvar left = new kiwi.Variable()\nvar width = new kiwi.Variable()\nsolver.addEditVariable(left, kiwi.Strength.strong)\nsolver.addEditVariable(width, kiwi.Strength.strong)\nsolver.suggestValue(left, 100)\nsolver.suggestValue(width, 400)\n\n// Create and add a constraint\nvar right = new kiwi.Variable()\nsolver.addConstraint(new kiwi.Constraint(new kiwi.Expression([-1, right], left, width), kiwi.Operator.Eq))\n\n// Solve the constraints\nsolver.updateVariables()\n\nconsole.assert(right.value() === 500)\n\n// later, update the constraints and re-calculate\nsetTimeout(() =\u003e {\n  solver.suggestValue(left, 200)\n  solver.suggestValue(width, 600)\n\n  solver.updateVariables() // update\n\n  console.assert(right.value() === 800)\n}, 2000)\n```\n\n## Documentation\n\n- [API Reference](docs/Kiwi.md)\n\n## Benchmarks\n\nTo run the benchmark in the browser, [just visit this page](https://raw.githack.com/lume/kiwi/main/bench/index.html).\n\nTo run the benchmark locally using nodejs, _clone or download this repository_ and execute the following steps:\n\n    npm install\n    npm run bench\n\nStatically serve the project, f.e. `npx five-server .` which opens a new browser\ntab, then visit `/bench/index.html` to verify that the benchmark also runs in a\nbrowser.\n\nSample result output:\n\n```\n----- Running creation benchmark...\nCassowary.js x 2,597 ops/sec ±1.56% (93 runs sampled)\nkiwi x 26,243 ops/sec ±1.34% (91 runs sampled)\nkiwi new API x 20,840 ops/sec ±7.19% (80 runs sampled)\nFastest is kiwi (± 10.11x faster)\n----- Running solving benchmark...\nCassowary.js x 260,002 ops/sec ±2.62% (89 runs sampled)\nkiwi x 595,455 ops/sec ±1.74% (89 runs sampled)\nFastest is kiwi (± 2.29x faster)\n```\n\n## Tests\n\nTo run the tests in the browser, [just visit this page](https://raw.githack.com/lume/kiwi/main/test/index.html).\n\nTo run the tests locally using nodejs, _clone or download this repository_ and execute the following steps:\n\n    npm install\n    npm run build \u0026\u0026 npm run test\n\nStart a static server, f.e. `npx five-server .` which opens a new browser tab,\nand visit `/test/index.html` to verify that tests also pass in a browser.\n\n## Contribute\n\nIf you like this project and want to support it, show some love and give it a\nstar, try it and report any bugs, write new feature ideas, or even\nopen a pull request!\n\n## License\n\n© 2013 Nucleic Development Team\n© 2021 Joseph Orbegoso Pea (http://github.com/trusktr)\n© 2021 Lume\n\n[![License](https://img.shields.io/badge/license-BDS%203--clause-brightgreen)](\u003chttps://tldrlegal.com/license/bsd-3-clause-license-(revised)\u003e)\n\n## Status\n\n[![Build Status](https://github.com/lume/kiwi/actions/workflows/tests.yml/badge.svg)](https://github.com/lume/kiwi/actions/workflows/tests.yml)\n\n\u003c!--\nTODO coverage status\n[![codecov](https://codecov.io/gh/IjzerenHein/kiwi.js/branch/master/graph/badge.svg)](https://codecov.io/gh/IjzerenHein/kiwi.js)\n--\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flume%2Fkiwi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flume%2Fkiwi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flume%2Fkiwi/lists"}