bireactive 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/animation/anim.d.ts +57 -0
  4. package/dist/animation/anim.js +318 -0
  5. package/dist/animation/combinators.d.ts +39 -0
  6. package/dist/animation/combinators.js +113 -0
  7. package/dist/animation/easings.d.ts +5 -0
  8. package/dist/animation/easings.js +5 -0
  9. package/dist/animation/index.d.ts +3 -0
  10. package/dist/animation/index.js +3 -0
  11. package/dist/assert/algebra.d.ts +20 -0
  12. package/dist/assert/algebra.js +79 -0
  13. package/dist/assert/claim.d.ts +40 -0
  14. package/dist/assert/claim.js +129 -0
  15. package/dist/assert/index.d.ts +7 -0
  16. package/dist/assert/index.js +19 -0
  17. package/dist/assert/predicates.d.ts +18 -0
  18. package/dist/assert/predicates.js +43 -0
  19. package/dist/assert/record.d.ts +20 -0
  20. package/dist/assert/record.js +78 -0
  21. package/dist/assert/scope.d.ts +42 -0
  22. package/dist/assert/scope.js +233 -0
  23. package/dist/assert/span.d.ts +37 -0
  24. package/dist/assert/span.js +68 -0
  25. package/dist/assert/tree.d.ts +22 -0
  26. package/dist/assert/tree.js +65 -0
  27. package/dist/code/code.d.ts +70 -0
  28. package/dist/code/code.js +361 -0
  29. package/dist/code/index.d.ts +2 -0
  30. package/dist/code/index.js +9 -0
  31. package/dist/code/morph.d.ts +5 -0
  32. package/dist/code/morph.js +194 -0
  33. package/dist/code/tokenize.d.ts +8 -0
  34. package/dist/code/tokenize.js +51 -0
  35. package/dist/constraints/cluster.d.ts +83 -0
  36. package/dist/constraints/cluster.js +213 -0
  37. package/dist/constraints/drivers.d.ts +15 -0
  38. package/dist/constraints/drivers.js +40 -0
  39. package/dist/constraints/factories.d.ts +73 -0
  40. package/dist/constraints/factories.js +248 -0
  41. package/dist/constraints/index.d.ts +11 -0
  42. package/dist/constraints/index.js +39 -0
  43. package/dist/constraints/interaction.d.ts +21 -0
  44. package/dist/constraints/interaction.js +148 -0
  45. package/dist/constraints/linalg.d.ts +18 -0
  46. package/dist/constraints/linalg.js +141 -0
  47. package/dist/constraints/phases.d.ts +21 -0
  48. package/dist/constraints/phases.js +60 -0
  49. package/dist/constraints/physics.d.ts +34 -0
  50. package/dist/constraints/physics.js +128 -0
  51. package/dist/constraints/rigid.d.ts +210 -0
  52. package/dist/constraints/rigid.js +835 -0
  53. package/dist/constraints/solver.d.ts +107 -0
  54. package/dist/constraints/solver.js +510 -0
  55. package/dist/constraints/term.d.ts +50 -0
  56. package/dist/constraints/term.js +80 -0
  57. package/dist/constraints/terms.d.ts +80 -0
  58. package/dist/constraints/terms.js +302 -0
  59. package/dist/constraints/world.d.ts +31 -0
  60. package/dist/constraints/world.js +245 -0
  61. package/dist/core/aggregates.d.ts +64 -0
  62. package/dist/core/aggregates.js +198 -0
  63. package/dist/core/anim.d.ts +84 -0
  64. package/dist/core/anim.js +301 -0
  65. package/dist/core/index.d.ts +38 -0
  66. package/dist/core/index.js +38 -0
  67. package/dist/core/introspect.d.ts +5 -0
  68. package/dist/core/introspect.js +31 -0
  69. package/dist/core/lenses/closed-form-policies.d.ts +64 -0
  70. package/dist/core/lenses/closed-form-policies.js +452 -0
  71. package/dist/core/lenses/domain-aggregates.d.ts +54 -0
  72. package/dist/core/lenses/domain-aggregates.js +259 -0
  73. package/dist/core/lenses/factor-lens.d.ts +42 -0
  74. package/dist/core/lenses/factor-lens.js +419 -0
  75. package/dist/core/lenses/index.d.ts +5 -0
  76. package/dist/core/lenses/index.js +16 -0
  77. package/dist/core/lenses/memory.d.ts +47 -0
  78. package/dist/core/lenses/memory.js +102 -0
  79. package/dist/core/lenses/typed-factor.d.ts +45 -0
  80. package/dist/core/lenses/typed-factor.js +376 -0
  81. package/dist/core/network-utils.d.ts +14 -0
  82. package/dist/core/network-utils.js +62 -0
  83. package/dist/core/new-primitives.d.ts +33 -0
  84. package/dist/core/new-primitives.js +113 -0
  85. package/dist/core/signal.d.ts +254 -0
  86. package/dist/core/signal.js +1349 -0
  87. package/dist/core/traits.d.ts +61 -0
  88. package/dist/core/traits.js +56 -0
  89. package/dist/core/tree.d.ts +23 -0
  90. package/dist/core/tree.js +62 -0
  91. package/dist/core/values/anchor.d.ts +23 -0
  92. package/dist/core/values/anchor.js +23 -0
  93. package/dist/core/values/audio.d.ts +33 -0
  94. package/dist/core/values/audio.js +107 -0
  95. package/dist/core/values/bool.d.ts +37 -0
  96. package/dist/core/values/bool.js +75 -0
  97. package/dist/core/values/box.d.ts +77 -0
  98. package/dist/core/values/box.js +211 -0
  99. package/dist/core/values/canvas.d.ts +71 -0
  100. package/dist/core/values/canvas.js +495 -0
  101. package/dist/core/values/color.d.ts +49 -0
  102. package/dist/core/values/color.js +106 -0
  103. package/dist/core/values/flags.d.ts +18 -0
  104. package/dist/core/values/flags.js +50 -0
  105. package/dist/core/values/gpu.d.ts +74 -0
  106. package/dist/core/values/gpu.js +426 -0
  107. package/dist/core/values/matrix.d.ts +53 -0
  108. package/dist/core/values/matrix.js +140 -0
  109. package/dist/core/values/num.d.ts +62 -0
  110. package/dist/core/values/num.js +166 -0
  111. package/dist/core/values/pose.d.ts +31 -0
  112. package/dist/core/values/pose.js +83 -0
  113. package/dist/core/values/range.d.ts +83 -0
  114. package/dist/core/values/range.js +167 -0
  115. package/dist/core/values/str.d.ts +76 -0
  116. package/dist/core/values/str.js +346 -0
  117. package/dist/core/values/template.d.ts +49 -0
  118. package/dist/core/values/template.js +148 -0
  119. package/dist/core/values/transform.d.ts +49 -0
  120. package/dist/core/values/transform.js +115 -0
  121. package/dist/core/values/tri.d.ts +31 -0
  122. package/dist/core/values/tri.js +95 -0
  123. package/dist/core/values/vec.d.ts +72 -0
  124. package/dist/core/values/vec.js +219 -0
  125. package/dist/core/writable.d.ts +15 -0
  126. package/dist/core/writable.js +29 -0
  127. package/dist/ext/events.d.ts +10 -0
  128. package/dist/ext/events.js +31 -0
  129. package/dist/ext/index.d.ts +4 -0
  130. package/dist/ext/index.js +4 -0
  131. package/dist/ext/snapshot.d.ts +8 -0
  132. package/dist/ext/snapshot.js +29 -0
  133. package/dist/ext/timeline.d.ts +56 -0
  134. package/dist/ext/timeline.js +94 -0
  135. package/dist/ext/waapi.d.ts +25 -0
  136. package/dist/ext/waapi.js +198 -0
  137. package/dist/index.d.ts +8 -0
  138. package/dist/index.js +10 -0
  139. package/dist/propagators/index.d.ts +6 -0
  140. package/dist/propagators/index.js +6 -0
  141. package/dist/propagators/layout.d.ts +68 -0
  142. package/dist/propagators/layout.js +336 -0
  143. package/dist/propagators/network.d.ts +52 -0
  144. package/dist/propagators/network.js +185 -0
  145. package/dist/propagators/propagator.d.ts +12 -0
  146. package/dist/propagators/propagator.js +16 -0
  147. package/dist/propagators/range.d.ts +45 -0
  148. package/dist/propagators/range.js +147 -0
  149. package/dist/propagators/relations.d.ts +60 -0
  150. package/dist/propagators/relations.js +343 -0
  151. package/dist/shapes/annular-sector.d.ts +15 -0
  152. package/dist/shapes/annular-sector.js +64 -0
  153. package/dist/shapes/button.d.ts +14 -0
  154. package/dist/shapes/button.js +31 -0
  155. package/dist/shapes/choreographers.d.ts +22 -0
  156. package/dist/shapes/choreographers.js +69 -0
  157. package/dist/shapes/circle.d.ts +17 -0
  158. package/dist/shapes/circle.js +57 -0
  159. package/dist/shapes/clip.d.ts +5 -0
  160. package/dist/shapes/clip.js +31 -0
  161. package/dist/shapes/connect.d.ts +16 -0
  162. package/dist/shapes/connect.js +70 -0
  163. package/dist/shapes/curve.d.ts +60 -0
  164. package/dist/shapes/curve.js +285 -0
  165. package/dist/shapes/dashed.d.ts +16 -0
  166. package/dist/shapes/dashed.js +142 -0
  167. package/dist/shapes/debug.d.ts +43 -0
  168. package/dist/shapes/debug.js +97 -0
  169. package/dist/shapes/group.d.ts +5 -0
  170. package/dist/shapes/group.js +10 -0
  171. package/dist/shapes/handle.d.ts +32 -0
  172. package/dist/shapes/handle.js +88 -0
  173. package/dist/shapes/index.d.ts +23 -0
  174. package/dist/shapes/index.js +23 -0
  175. package/dist/shapes/interaction.d.ts +32 -0
  176. package/dist/shapes/interaction.js +187 -0
  177. package/dist/shapes/label.d.ts +20 -0
  178. package/dist/shapes/label.js +42 -0
  179. package/dist/shapes/layout.d.ts +29 -0
  180. package/dist/shapes/layout.js +74 -0
  181. package/dist/shapes/line.d.ts +21 -0
  182. package/dist/shapes/line.js +79 -0
  183. package/dist/shapes/list.d.ts +18 -0
  184. package/dist/shapes/list.js +51 -0
  185. package/dist/shapes/mount.d.ts +7 -0
  186. package/dist/shapes/mount.js +10 -0
  187. package/dist/shapes/path.d.ts +77 -0
  188. package/dist/shapes/path.js +227 -0
  189. package/dist/shapes/rect.d.ts +30 -0
  190. package/dist/shapes/rect.js +131 -0
  191. package/dist/shapes/shape.d.ts +132 -0
  192. package/dist/shapes/shape.js +306 -0
  193. package/dist/shapes/text.d.ts +24 -0
  194. package/dist/shapes/text.js +53 -0
  195. package/dist/shapes/tokens.d.ts +28 -0
  196. package/dist/shapes/tokens.js +27 -0
  197. package/dist/shapes/transitions.d.ts +23 -0
  198. package/dist/shapes/transitions.js +62 -0
  199. package/dist/tex/decorations.d.ts +26 -0
  200. package/dist/tex/decorations.js +116 -0
  201. package/dist/tex/index.d.ts +5 -0
  202. package/dist/tex/index.js +5 -0
  203. package/dist/tex/marker.d.ts +17 -0
  204. package/dist/tex/marker.js +63 -0
  205. package/dist/tex/motion.d.ts +43 -0
  206. package/dist/tex/motion.js +290 -0
  207. package/dist/tex/parts.d.ts +65 -0
  208. package/dist/tex/parts.js +149 -0
  209. package/dist/tex/tex.d.ts +45 -0
  210. package/dist/tex/tex.js +244 -0
  211. package/dist/web/attr.d.ts +16 -0
  212. package/dist/web/attr.js +98 -0
  213. package/dist/web/diagram.d.ts +49 -0
  214. package/dist/web/diagram.js +260 -0
  215. package/dist/web/index.d.ts +6 -0
  216. package/dist/web/index.js +6 -0
  217. package/dist/web/md-marker.d.ts +6 -0
  218. package/dist/web/md-marker.js +39 -0
  219. package/dist/web/md-tex.d.ts +6 -0
  220. package/dist/web/md-tex.js +61 -0
  221. package/dist/web/raf.d.ts +6 -0
  222. package/dist/web/raf.js +24 -0
  223. package/dist/web/viewport.d.ts +7 -0
  224. package/dist/web/viewport.js +13 -0
  225. package/package.json +87 -0
@@ -0,0 +1,39 @@
1
+ // Prose-linking element for plain (non-math) text — same wiring as <md-tex sym="...">.
2
+ import { effect } from "../core/index.js";
3
+ import { getMarker as getGlobalMarker, highlightTint, hover } from "../tex/index.js";
4
+ function resolveMarker(id, forId) {
5
+ if (forId) {
6
+ const el = document.getElementById(forId);
7
+ return el?.getMarker?.(id);
8
+ }
9
+ return getGlobalMarker(id);
10
+ }
11
+ export class MdMarker extends HTMLElement {
12
+ #disposers = [];
13
+ connectedCallback() {
14
+ const id = this.getAttribute("sym");
15
+ if (!id)
16
+ return;
17
+ const forId = this.getAttribute("for");
18
+ const m = resolveMarker(id, forId);
19
+ if (!m)
20
+ return;
21
+ this.style.borderRadius = "2px";
22
+ this.style.transition = "background-color 120ms ease-out";
23
+ this.style.cursor = "default";
24
+ this.#disposers.push(hover(this, m), effect(() => {
25
+ this.style.color = m.color.value ?? "";
26
+ }), effect(() => {
27
+ const color = m.color.value;
28
+ this.style.backgroundColor = m.active.value && color ? highlightTint(color) : "";
29
+ }));
30
+ }
31
+ disconnectedCallback() {
32
+ for (const d of this.#disposers)
33
+ d();
34
+ this.#disposers.length = 0;
35
+ }
36
+ static define() {
37
+ customElements.define("md-marker", this);
38
+ }
39
+ }
@@ -0,0 +1,6 @@
1
+ export declare class MdTex extends HTMLElement {
2
+ #private;
3
+ connectedCallback(): void;
4
+ disconnectedCallback(): void;
5
+ static define(): void;
6
+ }
@@ -0,0 +1,61 @@
1
+ // Inline math custom element with optional prose-linking via `for`/`sym`.
2
+ import { effect } from "../core/index.js";
3
+ import { getMarker as getGlobalMarker, highlightTint, hover, renderToMathML, } from "../tex/index.js";
4
+ const SYM_RE = /\\sym\{([^}]+)\}\{([^}]*)\}/g;
5
+ const symClass = (id) => `bireactive-sym-${id.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
6
+ function resolveMarker(id, forId) {
7
+ if (forId) {
8
+ const el = document.getElementById(forId);
9
+ return el?.getMarker?.(id);
10
+ }
11
+ return getGlobalMarker(id);
12
+ }
13
+ export class MdTex extends HTMLElement {
14
+ #disposers = [];
15
+ connectedCallback() {
16
+ const singleId = this.getAttribute("sym");
17
+ const forId = this.getAttribute("for");
18
+ const src = this.textContent?.trim() ?? "";
19
+ if (singleId) {
20
+ this.innerHTML = renderToMathML(src);
21
+ const m = resolveMarker(singleId, forId);
22
+ if (m)
23
+ this.#wire(this, m);
24
+ return;
25
+ }
26
+ // Full expression — pre-process \sym{id}{content}
27
+ const symIds = new Map(); // cssClass → registryId
28
+ const processedSrc = src.replace(SYM_RE, (_, id, content) => {
29
+ const cls = symClass(id);
30
+ symIds.set(cls, id);
31
+ return `\\class{${cls}}{${content}}`;
32
+ });
33
+ this.innerHTML = renderToMathML(processedSrc);
34
+ for (const [cls, id] of symIds) {
35
+ const m = resolveMarker(id, forId);
36
+ if (!m)
37
+ continue;
38
+ for (const el of this.querySelectorAll(`.${cls}`))
39
+ this.#wire(el, m);
40
+ }
41
+ }
42
+ #wire(el, m) {
43
+ el.style.borderRadius = "2px";
44
+ el.style.transition = "background-color 120ms ease-out";
45
+ el.style.cursor = "default";
46
+ this.#disposers.push(hover(el, m), effect(() => {
47
+ el.style.color = m.color.value ?? "";
48
+ }), effect(() => {
49
+ const color = m.color.value;
50
+ el.style.backgroundColor = m.active.value && color ? highlightTint(color) : "";
51
+ }));
52
+ }
53
+ disconnectedCallback() {
54
+ for (const d of this.#disposers)
55
+ d();
56
+ this.#disposers.length = 0;
57
+ }
58
+ static define() {
59
+ customElements.define("md-tex", this);
60
+ }
61
+ }
@@ -0,0 +1,6 @@
1
+ /** Drive `anim.step(dt)` on every animation frame. Caps `dt` at 32 ms
2
+ * so a backgrounded tab doesn't deliver one giant frame on resume.
3
+ * Returns a disposer. */
4
+ export declare function attachRaf(anim: {
5
+ step(dt: number): void;
6
+ }): () => void;
@@ -0,0 +1,24 @@
1
+ // requestAnimationFrame adapter for the engine. Lives in `web/`
2
+ // because it depends on the browser; core is renderer-agnostic.
3
+ /** Drive `anim.step(dt)` on every animation frame. Caps `dt` at 32 ms
4
+ * so a backgrounded tab doesn't deliver one giant frame on resume.
5
+ * Returns a disposer. */
6
+ export function attachRaf(anim) {
7
+ if (typeof requestAnimationFrame !== "function")
8
+ return () => { };
9
+ const FRAME_CAP_MS = 32;
10
+ let rafId = 0, last = 0;
11
+ const tick = (now) => {
12
+ rafId = requestAnimationFrame(tick);
13
+ const dt = last ? Math.min(now - last, FRAME_CAP_MS) / 1000 : 0;
14
+ last = now;
15
+ anim.step(dt);
16
+ };
17
+ rafId = requestAnimationFrame(tick);
18
+ return () => {
19
+ if (rafId)
20
+ cancelAnimationFrame(rafId);
21
+ rafId = 0;
22
+ last = 0;
23
+ };
24
+ }
@@ -0,0 +1,7 @@
1
+ import { type Cell } from "../core/index.js";
2
+ interface Viewport {
3
+ w: number;
4
+ h: number;
5
+ }
6
+ export declare function viewport(): Cell<Viewport>;
7
+ export {};
@@ -0,0 +1,13 @@
1
+ // Shared viewport signal — one lazy resize listener, re-emits on resize.
2
+ import { cell } from "../core/index.js";
3
+ let cached;
4
+ export function viewport() {
5
+ if (cached)
6
+ return cached;
7
+ const sig = cell({ w: window.innerWidth, h: window.innerHeight });
8
+ window.addEventListener("resize", () => {
9
+ sig.value = { w: window.innerWidth, h: window.innerHeight };
10
+ });
11
+ cached = sig;
12
+ return sig;
13
+ }
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "bireactive",
3
+ "version": "0.2.0",
4
+ "description": "Bi-directional reactive programming.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "module": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "import": "./src/index.ts"
13
+ }
14
+ },
15
+ "publishConfig": {
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ }
25
+ },
26
+ "sideEffects": false,
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "dev": "vite --host",
34
+ "site": "vite-node site/build.ts && vite build && vite-node site/build.ts",
35
+ "preview": "vite preview",
36
+ "prebuild": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
37
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths",
38
+ "test": "vitest --config vitest.config.ts run",
39
+ "test:watch": "vitest --config vitest.config.ts",
40
+ "bench": "node --expose-gc node_modules/.bin/vite-node",
41
+ "typecheck": "tsc --noEmit --pretty",
42
+ "fmt": "biome check --write .",
43
+ "prepublishOnly": "npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "prism-esm": "^1.29.0-fix.6",
47
+ "temml": "^0.13.3"
48
+ },
49
+ "devDependencies": {
50
+ "@biomejs/biome": "2.4.15",
51
+ "@preact/signals-core": "^1.14.2",
52
+ "@types/node": "^22.0.0",
53
+ "alien-signals": "^3.2.1",
54
+ "fast-check": "^4.8.0",
55
+ "gray-matter": "^4.0.3",
56
+ "marked": "^12.0.0",
57
+ "marked-footnote": "^1.4.0",
58
+ "mitata": "^1.0.34",
59
+ "reactive-framework-test-suite": "^0.0.2",
60
+ "tsc-alias": "^1.8.17",
61
+ "typescript": "^6.0.3",
62
+ "vite": "^7.3.3",
63
+ "vite-node": "^5.3.0",
64
+ "vitest": "^4.1.7"
65
+ },
66
+ "keywords": [
67
+ "bireactive",
68
+ "reactive",
69
+ "signals",
70
+ "svg",
71
+ "animation",
72
+ "diagrams",
73
+ "constraints",
74
+ "propagators"
75
+ ],
76
+ "author": "Orion Reed",
77
+ "license": "MIT",
78
+ "engines": {
79
+ "node": ">=20.19"
80
+ },
81
+ "repository": {
82
+ "type": "git",
83
+ "url": "git+https://github.com/OrionReed/bireactive.git"
84
+ },
85
+ "homepage": "https://github.com/OrionReed/bireactive",
86
+ "bugs": "https://github.com/OrionReed/bireactive/issues"
87
+ }