@entro314labs/iso-engine 0.0.0-stage → 0.5.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -2
  3. package/THIRD_PARTY_NOTICES.md +39 -0
  4. package/dist/engine/anim.js +225 -0
  5. package/dist/engine/behaviors.js +105 -0
  6. package/dist/engine/diagram.js +80 -0
  7. package/dist/engine/draw.js +117 -0
  8. package/dist/engine/export.js +81 -0
  9. package/dist/engine/figure.js +35 -0
  10. package/dist/engine/global.js +4 -0
  11. package/dist/engine/index.d.ts +278 -0
  12. package/dist/engine/index.js +164 -0
  13. package/dist/engine/math.js +190 -0
  14. package/dist/engine/node.js +290 -0
  15. package/dist/engine/paths.js +76 -0
  16. package/dist/engine/prefabs/architecture.js +136 -0
  17. package/dist/engine/prefabs/basics.js +131 -0
  18. package/dist/engine/prefabs/devices.js +295 -0
  19. package/dist/engine/prefabs/icons.js +49 -0
  20. package/dist/engine/prefabs/index.js +12 -0
  21. package/dist/engine/prefabs/logistics.js +156 -0
  22. package/dist/engine/scene.js +466 -0
  23. package/dist/engine/shapes.js +781 -0
  24. package/dist/engine/sort.js +153 -0
  25. package/dist/engine/spec.js +81 -0
  26. package/dist/engine/style.js +87 -0
  27. package/dist/engine.css +1 -0
  28. package/dist/figure.css +93 -0
  29. package/dist/figure.d.ts +22 -0
  30. package/dist/figure.js +73 -0
  31. package/dist/filters.d.ts +9 -0
  32. package/dist/filters.js +22 -0
  33. package/dist/index.d.ts +9 -0
  34. package/dist/index.js +8 -0
  35. package/dist/iso.global.js +7990 -0
  36. package/dist/kernel.d.ts +102 -0
  37. package/dist/kernel.js +172 -0
  38. package/dist/loops.d.ts +49 -0
  39. package/dist/loops.js +64 -0
  40. package/dist/patterns.d.ts +44 -0
  41. package/dist/patterns.js +97 -0
  42. package/dist/theme.css +19 -0
  43. package/dist/types.d.ts +86 -0
  44. package/dist/types.js +1 -0
  45. package/package.json +50 -4
  46. package/skills/iso-engine/SKILL.md +143 -0
  47. package/skills/iso-engine/examples/engine.html +42 -0
  48. package/skills/iso-engine/examples/figure.html +51 -0
  49. package/skills/iso-engine/examples/loop.html +68 -0
  50. package/skills/iso-engine/examples/loop.js +36 -0
  51. package/skills/iso-engine/examples/matcher.js +134 -0
  52. package/skills/iso-engine/examples/spec.html +42 -0
  53. package/skills/iso-engine/references/animation.md +116 -0
  54. package/skills/iso-engine/references/api.md +207 -0
  55. package/skills/iso-engine/references/composition.md +66 -0
  56. package/skills/iso-engine/references/diagrams.md +68 -0
  57. package/skills/iso-engine/references/figures.md +359 -0
  58. package/skills/iso-engine/references/loops.md +126 -0
  59. package/skills/iso-engine/references/prefabs.md +103 -0
  60. package/skills/iso-engine/references/spec.md +66 -0
  61. package/skills/iso-engine/references/style.md +76 -0
  62. package/skills/iso-engine/references/troubleshooting.md +49 -0
  63. package/skills/iso-engine/scripts/build.mjs +35 -0
@@ -0,0 +1,117 @@
1
+ /* Draw context: shapes emit an ordered list of SVG ops in screen space.
2
+ Fill ops never stroke (CSS gives them a hairline of their own colour to hide seams);
3
+ line ops never fill. Colour always comes from CSS classes → custom properties. */
4
+ import { DEG, fmt, cssClass } from './math.js';
5
+
6
+ export const IDENTITY = Object.freeze({ x: 0, y: 0, z: 0, rot: 0, c: 1, s: 0 });
7
+
8
+ export function makeFrame(x = 0, y = 0, z = 0, rot = 0) {
9
+ return { x, y, z, rot, c: Math.cos(rot * DEG), s: Math.sin(rot * DEG) };
10
+ }
11
+
12
+ /* parent ∘ local */
13
+ export function compose(p, l) {
14
+ if (!l || l === IDENTITY) return p;
15
+ const x = p.x + l.x * p.c - l.y * p.s;
16
+ const y = p.y + l.x * p.s + l.y * p.c;
17
+ return makeFrame(x, y, p.z + l.z, p.rot + l.rot);
18
+ }
19
+
20
+ export function applyFrame(f, x, y, z = 0) {
21
+ if (!f.rot) return [x + f.x, y + f.y, z + f.z];
22
+ return [f.x + x * f.c - y * f.s, f.y + x * f.s + y * f.c, z + f.z];
23
+ }
24
+
25
+ export function frameVec(f, v) {
26
+ if (!f.rot) return v;
27
+ return [v[0] * f.c - v[1] * f.s, v[0] * f.s + v[1] * f.c, v[2]];
28
+ }
29
+
30
+ export class Draw {
31
+ constructor(view, frame = IDENTITY) {
32
+ this.view = view;
33
+ this.frame = frame;
34
+ this.ops = [];
35
+ this.b = [Infinity, Infinity, -Infinity, -Infinity];
36
+ }
37
+ /* local → world */
38
+ w(x, y, z = 0) { return applyFrame(this.frame, x, y, z); }
39
+ /* world → screen (tracks bounds) */
40
+ P(x, y, z = 0) {
41
+ const q = this.view.P(x, y, z), b = this.b;
42
+ if (q[0] < b[0]) b[0] = q[0]; if (q[1] < b[1]) b[1] = q[1];
43
+ if (q[0] > b[2]) b[2] = q[0]; if (q[1] > b[3]) b[3] = q[1];
44
+ return q;
45
+ }
46
+ /* local → screen */
47
+ p(x, y, z = 0) { const w = this.w(x, y, z); return this.P(w[0], w[1], w[2]); }
48
+
49
+ /* screen points → path data */
50
+ d(pts, close) {
51
+ let s = '';
52
+ for (let i = 0; i < pts.length; i++) s += (i ? 'L' : 'M') + fmt(pts[i][0]) + ' ' + fmt(pts[i][1]);
53
+ return close ? s + 'Z' : s;
54
+ }
55
+ /* world points → path data */
56
+ dw(pts, close) { return this.d(pts.map((p) => this.P(p[0], p[1], p[2] || 0)), close); }
57
+ /* local points → path data */
58
+ dl(pts, close) { return this.d(pts.map((p) => this.p(p[0], p[1], p[2] || 0)), close); }
59
+
60
+ fill(d, cls, extra) { if (d) this.ops.push({ k: 'f', d, cls, extra }); return this; }
61
+ line(d, cls = 'ln', extra) { if (d) this.ops.push({ k: 'l', d, cls, extra }); return this; }
62
+ both(d, fillCls, lineCls = 'ln', extra) { this.fill(d, fillCls, extra); this.line(d, lineCls); return this; }
63
+ raw(markup) { if (markup) this.ops.push({ k: 'r', s: markup }); return this; }
64
+
65
+ /* Horizontal circle (world centre) → ellipse in screen, axis aligned.
66
+ Angle t is measured in plan from +x towards +y (clockwise on screen). */
67
+ hpt(cx, cy, z, r, t) { return this.P(cx + r * Math.cos(t * DEG), cy + r * Math.sin(t * DEG), z); }
68
+ /* Arc commands from angle t0 to t1 (t1 > t0 draws clockwise on screen). Current point must be at t0. */
69
+ harc(cx, cy, z, r, t0, t1) {
70
+ const { C, S } = this.view;
71
+ const rx = r * Math.SQRT2 * C, ry = r * Math.SQRT2 * S;
72
+ if (r < 1e-6) return '';
73
+ let s = '', span = t1 - t0;
74
+ const steps = Math.max(1, Math.ceil(Math.abs(span) / 170));
75
+ for (let i = 1; i <= steps; i++) {
76
+ const t = t0 + (span * i) / steps;
77
+ const q = this.hpt(cx, cy, z, r, t);
78
+ s += 'A' + fmt(rx) + ' ' + fmt(ry) + ' 0 0 ' + (span > 0 ? 1 : 0) + ' ' + fmt(q[0]) + ' ' + fmt(q[1]);
79
+ }
80
+ /* bounds: include extremes crossed */
81
+ for (let a = Math.ceil((Math.min(t0, t1) + 45) / 90) * 90 - 45; a <= Math.max(t0, t1); a += 90) this.hpt(cx, cy, z, r, a);
82
+ return s;
83
+ }
84
+ /* Full horizontal ellipse path. */
85
+ hcircle(cx, cy, z, r) {
86
+ const a = this.hpt(cx, cy, z, r, -45);
87
+ return 'M' + fmt(a[0]) + ' ' + fmt(a[1]) + this.harc(cx, cy, z, r, -45, 315) + 'Z';
88
+ }
89
+
90
+ /* SVG matrix mapping 2D content (u →, v ↓, world units) onto a world plane through o spanned by unit vectors u, v. */
91
+ planeMatrix(o, u, v) {
92
+ const { C, S } = this.view;
93
+ const pu = [(u[0] - u[1]) * C, (u[0] + u[1]) * S - u[2]];
94
+ const pv = [(v[0] - v[1]) * C, (v[0] + v[1]) * S - v[2]];
95
+ const po = this.P(o[0], o[1], o[2]);
96
+ return 'matrix(' + [pu[0], pu[1], pv[0], pv[1], po[0], po[1]].map(fmt).join(' ') + ')';
97
+ }
98
+
99
+ toString() {
100
+ let s = '', i = 0;
101
+ const ops = this.ops;
102
+ while (i < ops.length) {
103
+ const o = ops[i];
104
+ if (o.k === 'r') { s += o.s; i++; continue; }
105
+ if (o.k === 'f') {
106
+ s += '<path class="' + cssClass(o.cls) + '" d="' + o.d + '"' + (o.extra || '') + '/>';
107
+ i++; continue;
108
+ }
109
+ /* merge consecutive strokes of the same class */
110
+ let d = o.d, j = i + 1;
111
+ while (j < ops.length && ops[j].k === 'l' && ops[j].cls === o.cls && ops[j].extra === o.extra) d += ops[j++].d;
112
+ s += '<path class="' + cssClass(o.cls) + '" d="' + d + '"' + (o.extra || '') + '/>';
113
+ i = j;
114
+ }
115
+ return s;
116
+ }
117
+ }
@@ -0,0 +1,81 @@
1
+ /* Export: portable SVG (computed colours inlined), PNG, and downloads. */
2
+ import { Scene } from './scene.js';
3
+
4
+ const PROPS = ['fill', 'stroke', 'stroke-width', 'stroke-dasharray', 'stroke-dashoffset', 'opacity', 'fill-opacity', 'stroke-opacity', 'font-family', 'font-size', 'letter-spacing', 'text-transform', 'display', 'filter'];
5
+ let ctx2d = null;
6
+ const cache = new Map();
7
+ function rgba(c) {
8
+ if (!c || c === 'none' || c.startsWith('url(')) return c;
9
+ if (cache.has(c)) return cache.get(c);
10
+ if (!ctx2d) { const cv = document.createElement('canvas'); cv.width = cv.height = 1; ctx2d = cv.getContext('2d', { willReadFrequently: true }); }
11
+ ctx2d.clearRect(0, 0, 1, 1);
12
+ ctx2d.fillStyle = '#000'; ctx2d.fillStyle = c;
13
+ ctx2d.fillRect(0, 0, 1, 1);
14
+ const d = ctx2d.getImageData(0, 0, 1, 1).data;
15
+ const out = d[3] === 255 ? `rgb(${d[0]},${d[1]},${d[2]})` : d[3] === 0 ? 'none' : `rgba(${d[0]},${d[1]},${d[2]},${(d[3] / 255).toFixed(3)})`;
16
+ cache.set(c, out);
17
+ return out;
18
+ }
19
+
20
+ Object.assign(Scene.prototype, {
21
+ /* Self-contained SVG string: every computed paint inlined, so it renders anywhere. */
22
+ toSVG(o = {}) {
23
+ if (!this.svg) this.render();
24
+ const src = this.svg, clone = src.cloneNode(true);
25
+ const a = src.querySelectorAll('*'), b = clone.querySelectorAll('*');
26
+ for (let i = 0; i < a.length; i++) {
27
+ const cs = getComputedStyle(a[i]), el = b[i];
28
+ if (a[i].tagName === 'title') continue;
29
+ if (cs.display === 'none') { el.setAttribute('display', 'none'); continue; }
30
+ for (const p of PROPS) {
31
+ let v = cs.getPropertyValue(p);
32
+ if (!v || v === 'normal' || v === 'auto') continue;
33
+ if (p === 'fill' || p === 'stroke') v = rgba(v);
34
+ if (p === 'filter') { if (v === 'none') continue; }
35
+ if (p === 'opacity' && v === '1') continue;
36
+ if (p === 'text-transform') { if (v === 'uppercase') el.textContent = el.textContent.toUpperCase(); continue; }
37
+ el.setAttribute(p, v);
38
+ }
39
+ if (el.getAttribute('vector-effect') === null && /^(path|line|polyline|rect|circle|ellipse)$/.test(el.tagName)) el.setAttribute('vector-effect', 'non-scaling-stroke');
40
+ el.removeAttribute('class');
41
+ el.removeAttribute('style');
42
+ el.removeAttribute('tabindex');
43
+ }
44
+ clone.removeAttribute('class');
45
+ clone.removeAttribute('style');
46
+ const vb = this.vb, w = o.width || Math.round(vb[2] * (o.scale || 1)), h = Math.round((w * vb[3]) / vb[2]);
47
+ clone.setAttribute('width', w); clone.setAttribute('height', h);
48
+ if (o.background !== false) {
49
+ const bg = o.background || rgba(getComputedStyle(src).getPropertyValue('--iso-bg').trim() || '#111');
50
+ const r = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
51
+ r.setAttribute('x', vb[0]); r.setAttribute('y', vb[1]); r.setAttribute('width', vb[2]); r.setAttribute('height', vb[3]); r.setAttribute('fill', bg);
52
+ clone.insertBefore(r, clone.firstChild);
53
+ }
54
+ return new XMLSerializer().serializeToString(clone);
55
+ },
56
+ /* PNG blob. o: scale (default 2), background */
57
+ toPNG(o = {}) {
58
+ const scale = o.scale || 2, vb = this.vb;
59
+ const svg = this.toSVG({ ...o, width: Math.round(vb[2] * scale) });
60
+ const img = new Image();
61
+ const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
62
+ return new Promise((res, rej) => {
63
+ img.onload = () => {
64
+ const c = document.createElement('canvas');
65
+ c.width = img.width; c.height = img.height;
66
+ c.getContext('2d').drawImage(img, 0, 0);
67
+ URL.revokeObjectURL(url);
68
+ c.toBlob((b) => (b ? res(b) : rej(new Error('toBlob failed'))), 'image/png');
69
+ };
70
+ img.onerror = rej;
71
+ img.src = url;
72
+ });
73
+ },
74
+ async download(name = 'illustration', type = 'svg', o = {}) {
75
+ const blob = type === 'png' ? await this.toPNG(o) : new Blob([this.toSVG(o)], { type: 'image/svg+xml' });
76
+ const a = document.createElement('a');
77
+ a.href = URL.createObjectURL(blob); a.download = name + '.' + type;
78
+ document.body.appendChild(a); a.click(); a.remove();
79
+ setTimeout(() => URL.revokeObjectURL(a.href), 2000);
80
+ },
81
+ });
@@ -0,0 +1,35 @@
1
+ /* Figure frame: a quiet card with mono captions at the four corners
2
+ (index · name · hint · state), the same grammar as the reference figures. */
3
+ import { injectCSS } from './style.js';
4
+ import { cssClass } from './math.js';
5
+
6
+ export function figure(host, o = {}) {
7
+ injectCSS();
8
+ host = typeof host === 'string' ? document.querySelector(host) : host;
9
+ const fig = document.createElement('figure');
10
+ fig.className = 'iso-fig iso-' + cssClass(o.theme || 'dark') + (o.class ? ' ' + cssClass(o.class) : '');
11
+ const cap = (pos, text, live) => {
12
+ const p = document.createElement('p');
13
+ p.className = 'iso-cap iso-cap-' + pos;
14
+ if (live) p.setAttribute('aria-live', 'polite');
15
+ p.textContent = text || '';
16
+ if (!text && !live) p.hidden = true;
17
+ fig.appendChild(p);
18
+ return p;
19
+ };
20
+ const caps = { tl: cap('tl', o.index), tr: cap('tr', o.title) };
21
+ const stage = document.createElement('div');
22
+ stage.className = 'iso-stage';
23
+ fig.appendChild(stage);
24
+ caps.bl = cap('bl', o.hint);
25
+ caps.br = cap('br', o.status, true);
26
+ if (o.maxWidth) stage.style.maxWidth = typeof o.maxWidth === 'number' ? o.maxWidth + 'px' : o.maxWidth, stage.style.margin = '0 auto';
27
+ host.appendChild(fig);
28
+ return {
29
+ el: fig,
30
+ stage,
31
+ caps,
32
+ status(text) { caps.br.textContent = text; caps.br.hidden = false; return this; },
33
+ caption(pos, text) { const c = caps[pos]; if (c) { c.textContent = text; c.hidden = !text; } return this; },
34
+ };
35
+ }
@@ -0,0 +1,4 @@
1
+ /* Browser global build: window.Iso */
2
+ import Iso from './index.js';
3
+ if (typeof window !== 'undefined') window.Iso = Iso;
4
+ export default Iso;
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Types for the Iso engine (`@entro314-labs/iso-engine/engine`). They follow the API reference
3
+ * (skills/iso-engine/references/api.md in this package). Primitive and prefab options stay open
4
+ * records, as in the engine: each type reads its own options (see the reference's Primitives and prefabs.md).
5
+ */
6
+ export type Vec3 = [number, number, number];
7
+ export type Opts = Record<string, unknown>;
8
+ export type Target = string | IsoNode | readonly (string | IsoNode)[] | ((n: IsoNode) => boolean);
9
+
10
+ /** The drawing surface a face drawer receives (`top`, `left`, `right` on boxes): (u, v) from the face's top-left as
11
+ * seen on screen, u → right, v → down, in world units. */
12
+ export interface Face {
13
+ readonly w: number;
14
+ readonly h: number;
15
+ rect(u: number, v: number, w: number, h: number, o?: { r?: number; fill?: string | null; line?: string | null; dash?: string }): void;
16
+ circle(u: number, v: number, r: number, o?: { fill?: string | null; line?: string | null }): void;
17
+ line(u1: number, v1: number, u2: number, v2: number, cls?: string): void;
18
+ hlines(u: number, v: number, w: number, h: number, n: number, cls?: string): void;
19
+ vlines(u: number, v: number, w: number, h: number, n: number, cls?: string): void;
20
+ poly(points: [number, number][], o?: { fill?: string | null; line?: string | null; close?: boolean }): void;
21
+ /** Text on the face; it shrinks to the room left on the face (or `max`), and `fit: false` turns that off. */
22
+ text(s: string, u: number, v: number, o?: { size?: number; anchor?: 'start' | 'middle' | 'end'; cls?: string; spacing?: number; weight?: number; max?: number; minSize?: number; pad?: number; fit?: boolean }): void;
23
+ svg(markup: string, o?: { u?: number; v?: number; transform?: string }): void;
24
+ /** `cols` × `rows` cells; `each(i, j)` may return per-cell overrides (or null). */
25
+ grid(u: number, v: number, w: number, h: number, cols: number, rows: number, o?: { gap?: number; r?: number; fill?: string | null; line?: string | null; each?: (i: number, j: number) => { fill?: string | null; line?: string | null } | null }): void;
26
+ /** A sub-face at (u, v), `w` × `h` (default: the rest of the face). */
27
+ sub(u: number, v: number, w?: number, h?: number): Face;
28
+ }
29
+
30
+ export type EaseName =
31
+ | 'linear' | 'out' | 'standard' | 'smooth' | 'outElastic' | 'outBounce'
32
+ | `${'in' | 'out' | 'inOut'}${'Quad' | 'Cubic' | 'Quart' | 'Expo' | 'Sine' | 'Back'}`;
33
+ export type Ease = EaseName | ((t: number) => number);
34
+
35
+ /** Stagger between targets: seconds each, or spread over `amount` seconds, ordered `from`. */
36
+ export type Stagger = number | { each?: number; amount?: number; from?: 'start' | 'end' | 'center' | 'random' | 'depth' | 'front' };
37
+
38
+ export interface TweenOpts { duration?: number; ease?: Ease | (string & {}); delay?: number; stagger?: Stagger }
39
+
40
+ /** Every primitive, builder and prefab type name the engine ships. `s.<type>(opts)` and `group.<type>(opts)` add one. */
41
+ export type PrimitiveType =
42
+ | 'box' | 'prism' | 'cylinder' | 'cone' | 'sphere' | 'hull' | 'panel' | 'slab' | 'wedge' | 'pyramid' | 'roof'
43
+ | 'rect' | 'circle' | 'ring' | 'poly' | 'line' | 'connector' | 'ribbon' | 'helix' | 'text' | 'pane' | 'grid' | 'custom'
44
+ | 'tube' | 'label' | 'diagram';
45
+ export type PrefabType =
46
+ | 'platform' | 'tree' | 'forest' | 'plant' | 'lamp' | 'pin' | 'zone' | 'plaque' | 'desk' | 'car' | 'solar' | 'bench'
47
+ | 'phone' | 'card' | 'laptop' | 'monitor' | 'keyboard' | 'deskComputer' | 'server' | 'database' | 'chip' | 'router'
48
+ | 'building' | 'tower' | 'gate' | 'conveyor' | 'stack' | 'block' | 'parcel' | 'pallet' | 'rack' | 'forklift' | 'truck'
49
+ | 'scanner' | 'tunnel';
50
+ /** Shorthand creators: `s.box({ … })`, `g.laptop({ … })`. Prefabs added with `Iso.define` are reachable the same way at
51
+ * runtime, or through `add('name', opts)`. */
52
+ export type Creators = { [K in Exclude<PrimitiveType | PrefabType, 'diagram'>]: (opts?: Opts) => IsoNode } & {
53
+ /** A grid of nodes, routed edges, zones and packets (diagrams.md). */
54
+ diagram(opts: Opts): Diagram;
55
+ };
56
+
57
+ export type NodeEvent = 'click' | 'press' | 'hover' | 'leave' | 'focus' | 'down' | 'up';
58
+
59
+ export interface IsoNode {
60
+ readonly id?: string;
61
+ readonly prefab?: string;
62
+ /** Set x/y/z (world offsets from the rest pose), scale, opacity or any option; a geometry option re-draws the node. */
63
+ set(key: string, value: unknown): IsoNode;
64
+ set(props: Opts): IsoNode;
65
+ get(key: string): unknown;
66
+ /** Reactive tween from the current values. */
67
+ to(props: Record<string, number>, opts?: TweenOpts): Promise<void>;
68
+ /** click/press also make the node focusable and operable with Enter/Space. */
69
+ on(event: NodeEvent, fn: () => void): IsoNode;
70
+ remove(): void;
71
+ add(node: IsoNode): IsoNode;
72
+ items(): IsoNode[];
73
+ }
74
+
75
+ /** A node that holds others: scenes' roots, `group()` results and prefabs. */
76
+ export interface IsoGroup extends IsoNode, Creators {
77
+ readonly children: IsoNode[];
78
+ find(pred: (n: IsoNode) => boolean): IsoNode | null;
79
+ findAll(pred: (n: IsoNode) => boolean): IsoNode[];
80
+ each(fn: (n: IsoNode) => void): void;
81
+ clear(): void;
82
+ group(opts: Opts, fill?: (g: IsoGroup) => void): IsoGroup;
83
+ }
84
+
85
+ export interface IsoPath {
86
+ readonly length: number;
87
+ readonly points: Vec3[];
88
+ at(u: number): Vec3;
89
+ tangent(u: number): Vec3;
90
+ /** Plan angle of travel at `u`, in degrees from +x toward +y. */
91
+ heading(u: number): number;
92
+ reverse(): IsoPath;
93
+ offset(dx: number, dy: number, dz: number): IsoPath;
94
+ }
95
+
96
+ /**
97
+ * Where a step goes: seconds from the timeline start, `'<'` (start of the previous step), `'>'` (its end), `'+=0.2'`,
98
+ * `'-=0.2'`, `'<0.3'`.
99
+ */
100
+ export type Position = number | string;
101
+
102
+ /** Deterministic, seekable sequence of steps. Thenable: `await tl` resolves when a finite timeline ends. */
103
+ export interface Timeline extends PromiseLike<void> {
104
+ to(target: Target, props: Opts, opts?: TweenOpts, at?: Position): Timeline;
105
+ from(target: Target, props: Opts, opts?: TweenOpts, at?: Position): Timeline;
106
+ fromTo(target: Target, from: Opts, to: Opts, opts?: TweenOpts, at?: Position): Timeline;
107
+ set(target: Target, props: Opts, at?: Position): Timeline;
108
+ call(fn: () => void, at?: Position): Timeline;
109
+ wait(seconds: number): Timeline;
110
+ /** Nest another timeline at a position. */
111
+ add(tl: Timeline, at?: Position): Timeline;
112
+ play(): Timeline;
113
+ pause(): Timeline;
114
+ restart(): Timeline;
115
+ reset(): void;
116
+ kill(): void;
117
+ readonly duration: number;
118
+ }
119
+
120
+ /** A diagram group, with its nodes by id and its routed edges. */
121
+ export interface Diagram extends IsoGroup {
122
+ nodesById: Map<string, IsoNode>;
123
+ edges: { line: IsoNode; path: IsoPath; from: string; to: string }[];
124
+ }
125
+
126
+ /** The caption frame of a scene made with `figure` (or `Iso.figure`). */
127
+ export interface FigureFrame {
128
+ readonly el: HTMLElement;
129
+ readonly stage: HTMLElement;
130
+ status(text: string): FigureFrame;
131
+ caption(pos: 'tl' | 'tr' | 'bl' | 'br', text: string): FigureFrame;
132
+ }
133
+
134
+ export type ThemeName = 'dark' | 'light' | 'paper' | 'blueprint' | 'terminal' | 'inherit';
135
+
136
+ export interface SceneOptions {
137
+ theme?: ThemeName;
138
+ colors?: { bg?: string; fg?: string; accent?: string };
139
+ figure?: { index?: string; title?: string; hint?: string; status?: string; maxWidth?: number | string };
140
+ /** Accessible description of the drawing. */
141
+ label?: string;
142
+ padding?: number;
143
+ extend?: [number, number, number, number];
144
+ aspect?: number;
145
+ zoom?: number;
146
+ view?: [number, number, number, number];
147
+ height?: number;
148
+ angle?: number;
149
+ autoplay?: boolean;
150
+ reducedMotion?: 'static' | 'ignore';
151
+ restTime?: number;
152
+ [option: string]: unknown;
153
+ }
154
+
155
+ /** A running per-frame behaviour (`loop`, ambient presets). */
156
+ export interface Behavior { stop(): void }
157
+
158
+ export interface TravelOptions {
159
+ duration?: number; speed?: number; start?: number; offset?: number; spread?: number; orient?: boolean; orientOffset?: number;
160
+ yoyo?: boolean; once?: boolean; repeat?: number; lift?: number; ease?: (t: number) => number;
161
+ }
162
+
163
+ export interface ExportOptions { scale?: number; [option: string]: unknown }
164
+
165
+ export interface Scene extends Creators {
166
+ readonly svg: SVGSVGElement;
167
+ readonly root: IsoGroup;
168
+ readonly time: number;
169
+ /** Present on scenes made with `figure`. */
170
+ readonly figure?: FigureFrame;
171
+ timeScale: number;
172
+ add(type: string, opts?: Opts): IsoNode;
173
+ add(node: IsoNode): IsoNode;
174
+ group(opts: Opts, fill: (g: IsoGroup) => void): IsoGroup;
175
+ get(id: string | IsoNode): IsoNode | null;
176
+ find(pred: (n: IsoNode) => boolean): IsoNode | null;
177
+ all(pred?: (n: IsoNode) => boolean): IsoNode[];
178
+ /** Nodes a target names: a node, an id, `'#id'`, `'.class'`, `'prefix*'`, an array, or a predicate. */
179
+ resolve(target: Target): IsoNode[];
180
+ timeline(opts?: { repeat?: number; yoyo?: boolean; delay?: number; repeatDelay?: number }): Timeline;
181
+ to(target: Target, props: Record<string, number>, opts?: TweenOpts): Promise<void>;
182
+ loop(fn: (time: number, dt: number, scene: Scene) => void): Behavior;
183
+ nudge(target: Target, key: string, factor: number): void;
184
+ /** Entrance: drop in and fade. Default target: every top-level item. */
185
+ assemble(target?: Target, opts?: { drop?: number; duration?: number; stagger?: Stagger; from?: string; delay?: number; filter?: (n: IsoNode) => boolean }): Timeline;
186
+ float(target: Target, opts?: { amp?: number; period?: number; phase?: number; stagger?: number }): Behavior;
187
+ pulse(target: Target, opts?: { min?: number; max?: number; period?: number; stagger?: number }): Behavior;
188
+ blink(target: Target, opts?: { period?: number; duty?: number; stagger?: number; low?: number }): Behavior;
189
+ spin(target: Target, opts?: { speed?: number }): Behavior;
190
+ /** Move along a world path; the footprint centre rides it. `ease` shapes progress along the path (a function). */
191
+ travel(target: Target, path: IsoPath, opts?: TravelOptions): Behavior;
192
+ orbit(target: Target, opts?: TravelOptions & { center?: Vec3; r?: number; start?: number; ccw?: boolean }): Behavior;
193
+ drawOn(target: Target, opts?: { duration?: number; stagger?: Stagger; delay?: number }): Timeline;
194
+ typewriter(target: Target, opts?: { perChar?: number; duration?: number }): Timeline;
195
+ hoverLift(target: Target, opts?: { z?: number }): Behavior;
196
+ play(): Scene;
197
+ pause(): Scene;
198
+ toggle(): Scene;
199
+ seek(t: number): Scene;
200
+ reset(): Scene;
201
+ /** Update the figure's state caption (scenes made with `figure`; a no-op otherwise). */
202
+ status(text: string): Scene;
203
+ setTheme(name: ThemeName): Scene;
204
+ /** World point → CSS px inside the SVG (for HTML overlays and tooltips). */
205
+ project(p: Vec3): [number, number];
206
+ refit(): Scene;
207
+ /** Self-contained SVG markup with every colour inlined. */
208
+ toSVG(opts?: ExportOptions): string;
209
+ toPNG(opts?: ExportOptions): Promise<Blob>;
210
+ download(name?: string, type?: 'svg' | 'png', opts?: ExportOptions): Promise<void>;
211
+ /** SVG markup at rest; works without a DOM. */
212
+ toString(): string;
213
+ on(event: 'render' | 'tick' | 'destroy', fn: () => void): Scene;
214
+ destroy(): void;
215
+ }
216
+
217
+ export interface Rng {
218
+ (): number;
219
+ range(a: number, b: number): number;
220
+ int(a: number, b: number): number;
221
+ pick<T>(arr: readonly T[]): T;
222
+ chance(p: number): boolean;
223
+ }
224
+
225
+ export interface IsoNamespace {
226
+ scene(host: string | Element, opts?: SceneOptions): Scene;
227
+ /** Build a scene from a JSON spec (spec.md). */
228
+ render(spec: Opts, host?: string | Element): Scene;
229
+ /** Register a prefab: `build(g, opts, Iso)` fills `g` in local coordinates (origin = footprint centre, base). */
230
+ define(name: string, build: (g: IsoGroup, o: Opts, iso: IsoNamespace) => unknown, meta?: { sort?: 'auto' | 'none'; flat?: boolean }): void;
231
+ make(type: string, opts?: Opts): IsoNode;
232
+ readonly prefabs: Readonly<Record<string, { build: (g: IsoGroup, o: Opts, iso: IsoNamespace) => unknown; meta: { sort?: 'auto' | 'none'; flat?: boolean } }>>;
233
+ readonly shapes: Readonly<Record<string, (opts: Opts) => IsoNode>>;
234
+ path: {
235
+ line(a: Vec3, b: Vec3): IsoPath;
236
+ polyline(points: Vec3[], opts?: { radius?: number; closed?: boolean }): IsoPath;
237
+ circle(opts: { center: Vec3; r: number; start?: number; ccw?: boolean }): IsoPath;
238
+ arc(opts: { center: Vec3; r: number; from: number; to: number }): IsoPath;
239
+ bezier(p0: Vec3, p1: Vec3, p2: Vec3, p3: Vec3): IsoPath;
240
+ hop(a: Vec3, b: Vec3, height: number): IsoPath;
241
+ rect(opts: { at: Vec3; size: [number, number]; r?: number }): IsoPath;
242
+ join(...paths: IsoPath[]): IsoPath;
243
+ };
244
+ readonly ease: Readonly<Record<EaseName, (t: number) => number>> & {
245
+ bezier(x1: number, y1: number, x2: number, y2: number): (t: number) => number;
246
+ steps(n: number): (t: number) => number;
247
+ spring(k: number): (t: number) => number;
248
+ };
249
+ rng(seed: number): Rng;
250
+ /** Built-in 24-grid line icons, by name → path data. */
251
+ readonly ICONS: Readonly<Record<string, string>>;
252
+ /** `<path>` markup for a built-in icon. */
253
+ icon(name: string, cls?: string): string;
254
+ /** A 9×9 pixel mark (path data); replace it with your own. */
255
+ readonly MARK: string;
256
+ readonly THEMES: Readonly<Record<string, Readonly<Record<string, string | number>>>>;
257
+ readonly MATERIALS: Readonly<Record<string, unknown>>;
258
+ /** Just the caption frame, without a scene. */
259
+ figure(host: string | Element, opts?: { theme?: ThemeName; index?: string; title?: string; hint?: string; status?: string; maxWidth?: number | string; class?: string }): FigureFrame;
260
+ /** The engine's stylesheet as text (also shipped as `@entro314-labs/iso-engine/engine.css`). */
261
+ css(): string;
262
+ /** Add the engine's stylesheet to `doc` once; skipped when an element with id `iso-engine-css` is already there. */
263
+ injectCSS(doc?: Document | null): void;
264
+ /** Manual clock for exports and tests: set true, then step it with `advance(dt)`. */
265
+ manual: boolean;
266
+ advance(dt: number): void;
267
+ scenes(): Scene[];
268
+ readonly VERSION: string;
269
+ }
270
+
271
+ /**
272
+ * Fit one line of mono text into `avail` world units: shrink the size, and below `min` truncate with an ellipsis.
273
+ * Tracked labels (`cls` containing `tx-label`) are estimated at 0.72 em per character, plain text at 0.62 em.
274
+ */
275
+ export declare function fitText(str: string, size: number, cls: string, spacing: number | undefined, avail: number, min?: number): { str: string; size: number };
276
+
277
+ export declare const Iso: IsoNamespace;
278
+ export default Iso;