@johnoscott/isometric-engine 0.14.1 → 0.16.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 (81) hide show
  1. package/README.md +1 -1
  2. package/iso-editor.js +249 -203
  3. package/iso-render.js +200 -154
  4. package/iso-systems.js +210 -162
  5. package/isometric-diagram.js +389 -0
  6. package/js/iso-core/index.js +5 -0
  7. package/js/iso-core/mono.js +242 -0
  8. package/js/iso-editor/ui/canvas.js +23 -1
  9. package/js/iso-objects/ants.js +36 -0
  10. package/js/iso-objects/index.js +55 -1
  11. package/js/iso-objects/looks.js +25 -0
  12. package/js/iso-objects/mono-paint.js +96 -0
  13. package/js/iso-objects/motion-builder.js +130 -0
  14. package/js/iso-objects/motion-doc.js +421 -0
  15. package/js/iso-objects/motion-entry.js +34 -0
  16. package/js/iso-objects/motion-schema.js +83 -0
  17. package/js/iso-objects/motion.js +640 -0
  18. package/js/iso-objects/resolve.js +238 -0
  19. package/js/iso-objects/scene.js +15 -13
  20. package/js/iso-objects/timeline.js +593 -0
  21. package/js/iso-systems/compile.js +83 -1
  22. package/js/iso-systems/index.js +4 -1
  23. package/js/iso-systems/render.js +20 -0
  24. package/js/iso-systems/schema.json +40 -0
  25. package/js/iso-viewer/index.js +6 -0
  26. package/js/iso-viewer/page.js +40 -16
  27. package/js/iso-viewer/play.js +340 -0
  28. package/js/iso-viewer/player.js +149 -175
  29. package/js/iso-viewer/transport.js +289 -0
  30. package/package.json +84 -2
  31. package/src/iso-core/index.ts +1 -0
  32. package/src/iso-core/mono.ts +306 -0
  33. package/src/iso-core/theme.ts +2 -1
  34. package/src/iso-editor/ui/canvas.ts +14 -1
  35. package/src/iso-objects/ants.ts +53 -0
  36. package/src/iso-objects/compile.ts +4 -1
  37. package/src/iso-objects/index.ts +16 -1
  38. package/src/iso-objects/looks.ts +21 -0
  39. package/src/iso-objects/mono-paint.ts +97 -0
  40. package/src/iso-objects/motion-builder.ts +79 -0
  41. package/src/iso-objects/motion-doc.ts +309 -0
  42. package/src/iso-objects/motion-entry.ts +13 -0
  43. package/src/iso-objects/motion-schema.ts +55 -0
  44. package/src/iso-objects/motion.ts +617 -0
  45. package/src/iso-objects/resolve.ts +196 -0
  46. package/src/iso-objects/scene.ts +32 -13
  47. package/src/iso-objects/timeline.ts +493 -0
  48. package/src/iso-objects/types.ts +22 -2
  49. package/src/iso-systems/compile.ts +86 -4
  50. package/src/iso-systems/index.ts +4 -1
  51. package/src/iso-systems/render.ts +45 -0
  52. package/src/iso-systems/schema.json +40 -0
  53. package/src/iso-viewer/index.ts +4 -0
  54. package/src/iso-viewer/page.ts +28 -11
  55. package/src/iso-viewer/play.ts +280 -0
  56. package/src/iso-viewer/player.ts +132 -150
  57. package/src/iso-viewer/transport.ts +272 -0
  58. package/types/iso-core/index.d.ts +1 -0
  59. package/types/iso-core/mono.d.ts +61 -0
  60. package/types/iso-core/theme.d.ts +2 -0
  61. package/types/iso-objects/ants.d.ts +34 -0
  62. package/types/iso-objects/compile.d.ts +3 -0
  63. package/types/iso-objects/index.d.ts +16 -1
  64. package/types/iso-objects/looks.d.ts +4 -0
  65. package/types/iso-objects/mono-paint.d.ts +20 -0
  66. package/types/iso-objects/motion-builder.d.ts +105 -0
  67. package/types/iso-objects/motion-doc.d.ts +193 -0
  68. package/types/iso-objects/motion-entry.d.ts +11 -0
  69. package/types/iso-objects/motion-schema.d.ts +594 -0
  70. package/types/iso-objects/motion.d.ts +202 -0
  71. package/types/iso-objects/resolve.d.ts +20 -0
  72. package/types/iso-objects/scene.d.ts +14 -0
  73. package/types/iso-objects/timeline.d.ts +66 -0
  74. package/types/iso-objects/types.d.ts +34 -0
  75. package/types/iso-systems/compile.d.ts +25 -3
  76. package/types/iso-systems/index.d.ts +4 -1
  77. package/types/iso-systems/render.d.ts +25 -0
  78. package/types/iso-viewer/index.d.ts +4 -0
  79. package/types/iso-viewer/play.d.ts +37 -0
  80. package/types/iso-viewer/transport.d.ts +73 -0
  81. package/types/player/isometric-diagram.d.ts +24 -0
@@ -7,12 +7,14 @@ import { parse } from "./parse.js";
7
7
  import { allowed, parseSvg, buildSvg } from "./svg-dom.js";
8
8
  import { VEl, vdoc, serialize } from "./vdom.js";
9
9
  import { createHash, sha256Hex } from "./shims/crypto.js";
10
+ import { MONO, greyOf, contrast, monoOf } from "./mono.js";
10
11
  export {
11
12
  Bounds,
12
13
  C,
13
14
  DiagError,
14
15
  FONTS,
15
16
  Kernel,
17
+ MONO,
16
18
  S,
17
19
  VEl,
18
20
  allowed,
@@ -21,6 +23,7 @@ export {
21
23
  buildSvg,
22
24
  center,
23
25
  colorRef,
26
+ contrast,
24
27
  createHash,
25
28
  depthSort,
26
29
  didYouMean,
@@ -32,10 +35,12 @@ export {
32
35
  fileLines,
33
36
  formatDiag,
34
37
  formatDiags,
38
+ greyOf,
35
39
  iso,
36
40
  keyGlyph,
37
41
  loadTheme,
38
42
  matStr,
43
+ monoOf,
39
44
  n1,
40
45
  parse,
41
46
  parseSvg,
@@ -0,0 +1,242 @@
1
+ const deepFreeze = (v) => {
2
+ if (v && typeof v === "object") {
3
+ Object.freeze(v);
4
+ for (const child of Object.values(v)) deepFreeze(child);
5
+ }
6
+ return v;
7
+ };
8
+ const STEP_THRESHOLDS = [86, 81, 76];
9
+ const KIND_ORDER = ["send", "reply", "token", "blocked", "user", "event", "control", "planned"];
10
+ const MONO = deepFreeze({
11
+ light: {
12
+ paper: "#ffffff",
13
+ ink: "#141414",
14
+ steps: [
15
+ { top: "#f4f4f4", left: "#dcdcdc", right: "#c4c4c4", edge: "#3a3a3a" },
16
+ { top: "#dedede", left: "#bfbfbf", right: "#a2a2a2", edge: "#2e2e2e" },
17
+ { top: "#bcbcbc", left: "#9a9a9a", right: "#7e7e7e", edge: "#222222" },
18
+ { top: "#8f8f8f", left: "#707070", right: "#565656", edge: "#141414" }
19
+ ]
20
+ },
21
+ dark: {
22
+ paper: "#161616",
23
+ ink: "#f2f2f2",
24
+ steps: [
25
+ { top: "#2a2a2a", left: "#222222", right: "#1b1b1b", edge: "#b8b8b8" },
26
+ { top: "#454545", left: "#383838", right: "#2c2c2c", edge: "#c8c8c8" },
27
+ { top: "#6a6a6a", left: "#565656", right: "#444444", edge: "#dadada" },
28
+ { top: "#9c9c9c", left: "#808080", right: "#686868", edge: "#141414" }
29
+ ]
30
+ },
31
+ patterns: ["none", "hatch", "hatch-wide", "dots"],
32
+ rhythms: [
33
+ { dash: [], width: 2.6 },
34
+ { dash: [9, 4], width: 2.4 },
35
+ { dash: [7, 6], width: 2.4 },
36
+ { dash: [3, 6], width: 2.4 },
37
+ { dash: [1.5, 3.5], width: 2.6 },
38
+ { dash: [10, 3, 2, 3], width: 2.4 },
39
+ { dash: [], width: 1.4 },
40
+ { dash: [7, 6], width: 1.4 },
41
+ { dash: [3, 3], width: 1.6 },
42
+ { dash: [14, 4], width: 1.8 }
43
+ ],
44
+ kindOrder: KIND_ORDER,
45
+ thresholds: STEP_THRESHOLDS,
46
+ darkWidthAdd: 0.4
47
+ });
48
+ const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
49
+ const HSL_RE = /^hsl\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))%\s+([+-]?(?:\d+\.?\d*|\.\d+))%\s*\)$/i;
50
+ function parseColor(color) {
51
+ if (typeof color !== "string") throw new Error(`mono: invalid colour "${String(color)}"`);
52
+ const s = color.trim();
53
+ const hex = HEX_RE.exec(s);
54
+ if (hex) {
55
+ const h = hex[1];
56
+ if (h.length === 3) {
57
+ return [
58
+ parseInt(h[0] + h[0], 16) / 255,
59
+ parseInt(h[1] + h[1], 16) / 255,
60
+ parseInt(h[2] + h[2], 16) / 255
61
+ ];
62
+ }
63
+ return [
64
+ parseInt(h.slice(0, 2), 16) / 255,
65
+ parseInt(h.slice(2, 4), 16) / 255,
66
+ parseInt(h.slice(4, 6), 16) / 255
67
+ ];
68
+ }
69
+ const hsl = HSL_RE.exec(s);
70
+ if (hsl) {
71
+ const h = Number(hsl[1]);
72
+ const sat = Number(hsl[2]);
73
+ const lig = Number(hsl[3]);
74
+ if (!Number.isFinite(h) || sat < 0 || sat > 100 || lig < 0 || lig > 100) {
75
+ throw new Error(`mono: invalid colour "${color}"`);
76
+ }
77
+ const hue = (h % 360 + 360) % 360;
78
+ const S = sat / 100;
79
+ const L = lig / 100;
80
+ const a = S * Math.min(L, 1 - L);
81
+ const f = (n) => {
82
+ const k = (n + hue / 30) % 12;
83
+ return L - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
84
+ };
85
+ return [f(0), f(8), f(4)];
86
+ }
87
+ throw new Error(`mono: invalid colour "${color}"`);
88
+ }
89
+ function luminance(color) {
90
+ const [r, g, b] = parseColor(color);
91
+ const lin = (c) => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
92
+ return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
93
+ }
94
+ function greyOf(color) {
95
+ const y = luminance(color);
96
+ return y > 216 / 24389 ? 116 * Math.cbrt(y) - 16 : 24389 / 27 * y;
97
+ }
98
+ function contrast(a, b) {
99
+ const la = luminance(a);
100
+ const lb = luminance(b);
101
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
102
+ }
103
+ const VALID_PATTERNS = new Set(MONO.patterns);
104
+ const FIXED_KIND_INDEX = new Map(MONO.kindOrder.map((k, i) => [k, i]));
105
+ const cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
106
+ const uniqueSorted = (names) => [...new Set(names)].sort(cmp);
107
+ const round2 = (n) => Math.round(n * 100) / 100;
108
+ function stepFromLightness(lStar) {
109
+ if (lStar >= STEP_THRESHOLDS[0]) return 0;
110
+ if (lStar >= STEP_THRESHOLDS[1]) return 1;
111
+ if (lStar >= STEP_THRESHOLDS[2]) return 2;
112
+ return 3;
113
+ }
114
+ function validateOwn(own) {
115
+ if (own.roles) {
116
+ for (const [name, ov] of Object.entries(own.roles)) {
117
+ if (ov.step !== void 0) {
118
+ if (typeof ov.step !== "number" || !Number.isInteger(ov.step) || ov.step < 0 || ov.step > 3) {
119
+ throw new Error(`mono: invalid step "${String(ov.step)}" for role "${name}"`);
120
+ }
121
+ }
122
+ if (ov.pattern !== void 0) {
123
+ if (typeof ov.pattern !== "string" || !VALID_PATTERNS.has(ov.pattern)) {
124
+ throw new Error(`mono: invalid pattern "${String(ov.pattern)}" for role "${name}"`);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ if (own.kinds) {
130
+ for (const [name, ov] of Object.entries(own.kinds)) {
131
+ if (ov.dash !== void 0) {
132
+ if (!Array.isArray(ov.dash) || !ov.dash.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0)) {
133
+ throw new Error(`mono: invalid dash "${String(ov.dash)}" for kind "${name}"`);
134
+ }
135
+ }
136
+ if (ov.width !== void 0) {
137
+ if (typeof ov.width !== "number" || !Number.isFinite(ov.width) || ov.width <= 0) {
138
+ throw new Error(`mono: invalid width "${String(ov.width)}" for kind "${name}"`);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ function monoOf(theme, mode, use, own) {
145
+ if (mode !== "light" && mode !== "dark") throw new Error(`mono: invalid mode "${String(mode)}"`);
146
+ if (own) validateOwn(own);
147
+ const palette = MONO[mode];
148
+ const warnings = [];
149
+ const lTop = theme.light["l-top"];
150
+ const roleNames = uniqueSorted(use?.roles ?? Object.keys(theme.roles));
151
+ const stepByRole = /* @__PURE__ */ new Map();
152
+ const byStep = [[], [], [], []];
153
+ for (const name of roleNames) {
154
+ const ovStep = own?.roles?.[name]?.step;
155
+ let step;
156
+ if (ovStep !== void 0) {
157
+ step = ovStep;
158
+ } else {
159
+ const def = theme.roles[name];
160
+ if (!def) throw new Error(`mono: unknown role "${name}"`);
161
+ if (typeof lTop !== "string") throw new Error('mono: theme.light is missing "l-top"');
162
+ step = stepFromLightness(greyOf(`hsl(${def.h} ${def.s}% ${lTop})`));
163
+ }
164
+ stepByRole.set(name, step);
165
+ byStep[step].push(name);
166
+ }
167
+ const patternByRole = /* @__PURE__ */ new Map();
168
+ for (let step = 0; step < byStep.length; step++) {
169
+ const group = byStep[step];
170
+ for (let i = 0; i < group.length; i++) {
171
+ const name = group[i];
172
+ const ovPattern = own?.roles?.[name]?.pattern;
173
+ if (ovPattern !== void 0) {
174
+ patternByRole.set(name, ovPattern);
175
+ } else {
176
+ const idx = i % MONO.patterns.length;
177
+ const pattern = MONO.patterns[idx];
178
+ patternByRole.set(name, pattern);
179
+ if (i >= MONO.patterns.length) {
180
+ const alike = group.slice(0, i).find((r) => patternByRole.get(r) === pattern);
181
+ if (alike !== void 0) {
182
+ warnings.push(`role "${name}" wraps on step ${step} to pattern "${pattern}", matching "${alike}"`);
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ const roles = {};
189
+ for (const name of roleNames) {
190
+ const step = stepByRole.get(name);
191
+ const pattern = patternByRole.get(name);
192
+ const face = palette.steps[step];
193
+ roles[name] = {
194
+ step,
195
+ pattern,
196
+ top: face.top,
197
+ left: face.left,
198
+ right: face.right,
199
+ edge: face.edge
200
+ };
201
+ }
202
+ const kindNames = uniqueSorted(use?.kinds ?? Object.keys(theme.kinds));
203
+ const widthBump = mode === "dark" ? MONO.darkWidthAdd : 0;
204
+ const kinds = {};
205
+ let extraIndex = 0;
206
+ for (const name of kindNames) {
207
+ const ov = own?.kinds?.[name];
208
+ const fixedIdx = FIXED_KIND_INDEX.get(name);
209
+ let rhythmIdx;
210
+ if (fixedIdx !== void 0) {
211
+ rhythmIdx = fixedIdx;
212
+ } else {
213
+ rhythmIdx = MONO.kindOrder.length + extraIndex;
214
+ extraIndex++;
215
+ if (rhythmIdx >= MONO.rhythms.length) {
216
+ const wrapped = rhythmIdx % MONO.rhythms.length;
217
+ if (!ov || ov.dash === void 0 || ov.width === void 0) {
218
+ warnings.push(`kind "${name}" exceeds the ${MONO.rhythms.length} line rhythms; reusing rhythm ${wrapped}`);
219
+ }
220
+ rhythmIdx = wrapped;
221
+ }
222
+ }
223
+ const base = MONO.rhythms[rhythmIdx];
224
+ const dash = ov?.dash !== void 0 ? [...ov.dash] : [...base.dash];
225
+ const width = ov?.width !== void 0 ? ov.width : round2(base.width + widthBump);
226
+ kinds[name] = { dash, width };
227
+ }
228
+ return {
229
+ mode,
230
+ paper: palette.paper,
231
+ ink: palette.ink,
232
+ roles,
233
+ kinds,
234
+ warnings
235
+ };
236
+ }
237
+ export {
238
+ MONO,
239
+ contrast,
240
+ greyOf,
241
+ monoOf
242
+ };
@@ -241,6 +241,10 @@ function canvasView(host, doc, opts) {
241
241
  empty.hidden = true;
242
242
  layer?.drawn?.();
243
243
  if (pendingReveal && reveal(pendingReveal)) pendingReveal = void 0;
244
+ if (pendingNudge) {
245
+ if (!drag) nudge(pendingNudge);
246
+ pendingNudge = void 0;
247
+ }
244
248
  paintNav();
245
249
  paintOverlay();
246
250
  if (from && from.svg !== s) {
@@ -1200,7 +1204,10 @@ function canvasView(host, doc, opts) {
1200
1204
  await draw(g.origCd);
1201
1205
  return;
1202
1206
  }
1203
- if (g.invalid) opts.note(`${f.name} added; that spot is taken, so the layout placed it`);
1207
+ if (g.invalid) {
1208
+ opts.note(`${f.name} added; that spot is taken, so the layout placed it`);
1209
+ pendingNudge = f.path;
1210
+ }
1204
1211
  doc.select([f.path], "canvas");
1205
1212
  rename(f.path, { joins: doc.undoId, at: lastPin });
1206
1213
  }
@@ -1836,6 +1843,21 @@ function canvasView(host, doc, opts) {
1836
1843
  return true;
1837
1844
  }
1838
1845
  let pendingReveal;
1846
+ function nudge(p) {
1847
+ const b = boxFor(p), v = V.view;
1848
+ if (!v || !b) return;
1849
+ if (b.w > v.w || b.h > v.h) {
1850
+ reveal([p]);
1851
+ return;
1852
+ }
1853
+ const m = 12 / scale(), by = (a, n, va, vn) => a < va ? a - va - m : a + n > va + vn ? a + n - va - vn + m : 0;
1854
+ const dx = by(b.x, b.w, v.x, v.w), dy = by(b.y, b.h, v.y, v.h);
1855
+ if (dx || dy) {
1856
+ V.view = { ...v, x: v.x + dx, y: v.y + dy };
1857
+ applyView();
1858
+ }
1859
+ }
1860
+ let pendingNudge;
1839
1861
  ifEvents();
1840
1862
  doc.onSelect((c) => {
1841
1863
  paintOverlay();
@@ -0,0 +1,36 @@
1
+ const ANT_SPEED = 32 / 1.1;
2
+ const ANT_DASH = { solid: [9, 7], dashed: [7, 6], dotted: [3, 6] };
3
+ const ANT_STILL = ["blocked", "planned"];
4
+ const ANTS_CSS = `
5
+ .flow.iso-ants{stroke-dasharray:var(--ant-on) var(--ant-off);animation:iso-ants var(--ant-turn) linear infinite;animation-play-state:var(--ants,running)}
6
+ @keyframes iso-ants{to{stroke-dashoffset:var(--ant-to)}}
7
+ `;
8
+ function antDash(kind, o = {}) {
9
+ return (o.still ?? ANT_STILL).includes(kind) ? void 0 : o.dash ?? o.kinds?.[kind]?.ants ?? ANT_DASH[o.kinds?.[kind]?.dash ?? "solid"];
10
+ }
11
+ function antsOf(raw) {
12
+ const a = raw?.ants;
13
+ return !a ? void 0 : a === true ? {} : Array.isArray(a) ? { ids: a } : a;
14
+ }
15
+ function withAnts(scene, o = {}) {
16
+ const kindOf = new Map(scene.routes.map((r) => [r.id, r.kind])), wanted = o.ids && new Set(o.ids), speed = o.speed ?? ANT_SPEED;
17
+ const n = (v) => String(Number(v.toFixed(3)));
18
+ return scene.rendered.svg.replace(/(<g data-route="([^"]*)" data-part="line">(?:<g[^>]*>)*)<path ([^>]*?)\s*\/>/g, (m, before, id, attrs) => {
19
+ const route = id.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
20
+ const dash = wanted && !wanted.has(route) ? void 0 : antDash(kindOf.get(route) ?? "", o);
21
+ if (!dash || !/class="flow\b/.test(attrs)) return m;
22
+ const period = dash[0] + dash[1], turn = n(period / Math.max(1e-6, Math.abs(speed))), to = n(speed < 0 ? period : -period);
23
+ if (o.by === "css") return `${before}<path ${attrs.replace(/class="flow\b/, 'class="flow iso-ants')} style="--ant-on:${n(dash[0])};--ant-off:${n(dash[1])};--ant-to:${to};--ant-turn:${turn}s"/>`;
24
+ if (o.by === "none") return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, "")} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"/>`;
25
+ return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, "")} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"><animate attributeName="stroke-dashoffset" from="0" to="${to}" dur="${turn}s" repeatCount="indefinite"/></path>`;
26
+ });
27
+ }
28
+ export {
29
+ ANTS_CSS,
30
+ ANT_DASH,
31
+ ANT_SPEED,
32
+ ANT_STILL,
33
+ antDash,
34
+ antsOf,
35
+ withAnts
36
+ };
@@ -4,6 +4,15 @@ import { WALL_T, place, gateBox, overlap2 } from "./place.js";
4
4
  import { parseEnd, floorAt, ROUTE_BUDGET, routeAll, openList, simplify } from "./route.js";
5
5
  import { silhouette, polyBounds, polyRectArea, rectArea, lineRectArea, Obstacles, labelRect, placeNodeLabel, calloutRect, placeCallout, inConvex, convexOverlap } from "./labels.js";
6
6
  import { offscreen, assembly } from "./assemble.js";
7
+ import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS, MOTION_EASINGS, motionModel, motionOrder, planOf, assemble, disassemble, alongPath, svgAt, paint, introSvg } from "./motion.js";
8
+ import { drawLooks } from "./looks.js";
9
+ import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
10
+ import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
11
+ import { bindMotion, motionOfSteps, motionSource } from "./timeline.js";
12
+ import { MOTION_SCHEMA } from "./motion-schema.js";
13
+ import { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
14
+ import { resolveSvg, FONT_STACKS } from "./resolve.js";
15
+ import { monoOfDrawing, monoTheme, monoCss, paintMono, usedIn } from "./mono-paint.js";
7
16
  import { durationFor, resolveSteps, midpoint } from "./steps.js";
8
17
  import { focusView } from "./focus.js";
9
18
  import { regionRole, renderScene, wallsOf, LABEL_BUDGET } from "./scene.js";
@@ -13,21 +22,42 @@ import { screenToGrid, localAt, boxSilhouette, floorOf, paddingOf, snapMove, ove
13
22
  import { FLAT_DEFAULTS, FLAT_FONTS, metricsMeasure, boardErrors, placeBoard, layoutFlat, flatHit } from "./flat.js";
14
23
  import { boardOf, BOARD_3D, BOARD_CSS, cardAsset, boardCatalog, boardDiagram } from "./board.js";
15
24
  export {
25
+ ANTS_CSS,
26
+ ANT_DASH,
27
+ ANT_SPEED,
28
+ ANT_STILL,
29
+ ASSEMBLE_STYLES,
16
30
  BOARD_3D,
17
31
  BOARD_CSS,
32
+ DISASSEMBLE_STYLES,
33
+ EASING_NAMES,
34
+ EXTRAPOLATE,
18
35
  FLAT_DEFAULTS,
19
36
  FLAT_FONTS,
37
+ FONT_STACKS,
20
38
  GRID_CSS,
21
39
  LABEL_BUDGET,
22
40
  MARKS_CSS,
41
+ MOTION_EASINGS,
42
+ MOTION_ORDERS,
43
+ MOTION_SCHEMA,
44
+ MotionBuilder,
45
+ NodesBuilder,
23
46
  Obstacles,
24
47
  PAGE_CSS,
25
48
  PLAYER_CSS,
26
49
  PLAYER_UI_CSS,
27
50
  ROUTE_BUDGET,
51
+ SeriesBuilder,
28
52
  WALL_T,
53
+ alongPath,
54
+ antDash,
55
+ antsOf,
56
+ assemble,
29
57
  assembly,
30
58
  baseCss,
59
+ bezier,
60
+ bindMotion,
31
61
  boardCatalog,
32
62
  boardDiagram,
33
63
  boardErrors,
@@ -36,14 +66,19 @@ export {
36
66
  boxSilhouette,
37
67
  calloutRect,
38
68
  cardAsset,
69
+ checkMotion,
39
70
  cloudPath,
40
71
  compileRaw,
41
72
  convexOverlap,
73
+ curveAt,
42
74
  defaultLabel,
75
+ disassemble,
43
76
  drawCloud,
44
77
  drawDecos,
78
+ drawLooks,
45
79
  drawingCss,
46
80
  durationFor,
81
+ easeOf,
47
82
  facePainter,
48
83
  flatHit,
49
84
  floorAt,
@@ -52,6 +87,7 @@ export {
52
87
  gateBox,
53
88
  iconPainter,
54
89
  inConvex,
90
+ introSvg,
55
91
  kindsCss,
56
92
  labelRect,
57
93
  layoutFlat,
@@ -60,6 +96,15 @@ export {
60
96
  markCss,
61
97
  metricsMeasure,
62
98
  midpoint,
99
+ monoCss,
100
+ monoOfDrawing,
101
+ monoTheme,
102
+ motion,
103
+ motionModel,
104
+ motionOfSteps,
105
+ motionOrder,
106
+ motionSource,
107
+ msOf,
63
108
  noSource,
64
109
  nodeKind,
65
110
  nodeKindOr,
@@ -68,26 +113,35 @@ export {
68
113
  overlap2,
69
114
  overlaps,
70
115
  paddingOf,
116
+ paint,
117
+ paintMono,
71
118
  parseEnd,
72
119
  place,
73
120
  placeBoard,
74
121
  placeCallout,
75
122
  placeNodeLabel,
76
123
  placeholderIcon,
124
+ planOf,
77
125
  plate,
78
126
  polyBounds,
79
127
  polyRectArea,
128
+ readMs,
80
129
  rectArea,
81
130
  regionKind,
82
131
  regionRole,
83
132
  registerMarks,
84
133
  renderScene,
85
134
  resolveSteps,
135
+ resolveSvg,
86
136
  routeAll,
87
137
  screenToGrid,
88
138
  silhouette,
89
139
  simplify,
90
140
  snapMove,
141
+ springAt,
142
+ svgAt,
143
+ usedIn,
91
144
  wallHeight,
92
- wallsOf
145
+ wallsOf,
146
+ withAnts
93
147
  };
@@ -0,0 +1,25 @@
1
+ import { renderScene } from "./scene.js";
2
+ function drawLooks(s, theme) {
3
+ const looks = {};
4
+ for (const p of s.layout.items) {
5
+ const v = (p.region ?? p.node)?.variants;
6
+ if (v) looks[p.id] = Object.keys(v);
7
+ }
8
+ if (!Object.keys(looks).length) return;
9
+ s.rendered.looks = looks;
10
+ s.rendered.variants = Object.fromEntries([...new Set(Object.values(looks).flat())].map((name) => [name, renderScene({
11
+ scene: s.raw,
12
+ routes: s.routes,
13
+ steps: s.steps,
14
+ theme,
15
+ id: s.raw.id,
16
+ gridStep: s.grid.step ?? s.grid.snap ?? 1,
17
+ layout: { ...s.layout, items: s.layout.items.map((p) => {
18
+ const v = (p.region ?? p.node)?.variants?.[name];
19
+ return !v ? p : p.region ? { ...p, region: { ...p.region, ...v, deco: void 0 } } : { ...p, node: { ...p.node, ...v } };
20
+ }) }
21
+ }).svg]));
22
+ }
23
+ export {
24
+ drawLooks
25
+ };
@@ -0,0 +1,96 @@
1
+ import { extendTheme } from "../iso-core/theme.js";
2
+ import { contrast, greyOf, MONO, monoOf } from "../iso-core/mono.js";
3
+ const pct = (grey) => `${Math.round(parseInt(grey.slice(1, 3), 16) / 255 * 1e4) / 100}%`;
4
+ const between = (a, b, f) => {
5
+ const [x, y] = [a, b].map((c) => parseInt(c.slice(1, 3), 16)), v = Math.round(x + (y - x) * f).toString(16).padStart(2, "0");
6
+ return `#${v}${v}${v}`;
7
+ };
8
+ function usedIn(svg, theme, kinds) {
9
+ const seen = new Set([...svg.matchAll(/\sclass="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/)).filter((c) => c.startsWith("k-")).map((c) => c.slice(2)));
10
+ return { roles: Object.keys(theme.roles).filter((r) => seen.has(r)), kinds: [...new Set(kinds)].filter((k) => k in theme.kinds) };
11
+ }
12
+ function monoTheme(theme, look) {
13
+ const steps = MONO[look.mode].steps, face = (role, step) => look.roles[role] ?? steps[step];
14
+ const tokens = {};
15
+ for (const [k, v] of Object.entries(theme.light)) tokens[k] = /%$/.test(v) ? v : look.ink;
16
+ const slab = face("slab", 0), pad = face("pad", 0);
17
+ Object.assign(tokens, {
18
+ bg: look.paper,
19
+ surface: look.paper,
20
+ on: look.paper,
21
+ ink: look.ink,
22
+ muted: between(look.paper, look.ink, 0.72),
23
+ line: between(look.paper, look.ink, 0.3),
24
+ "code-bg": between(look.paper, look.ink, 0.06),
25
+ "slab-top": slab.top,
26
+ "slab-l": slab.left,
27
+ "slab-r": slab.right,
28
+ "pad-top": pad.top
29
+ });
30
+ const roles = Object.fromEntries(Object.entries(theme.roles).map(([k]) => [k, { h: 0, s: 0 }]));
31
+ const kinds = Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => [k, { ...v, color: look.ink }]));
32
+ return extendTheme({ ...theme, light: tokens, dark: tokens, roles, kinds });
33
+ }
34
+ function monoCss(look) {
35
+ let css = "";
36
+ for (const [name, r] of Object.entries(look.roles)) css += `.k-${name}{--s:0%;--l-top:${pct(r.top)};--l-left:${pct(r.left)};--l-right:${pct(r.right)};--l-edge:${pct(r.edge)}}
37
+ `;
38
+ for (const [name, k] of Object.entries(look.kinds)) css += `.flow.f-${name}{stroke-width:${k.width}${k.dash.length ? `;stroke-dasharray:${k.dash.join(" ")}` : ";stroke-dasharray:none"}}
39
+ `;
40
+ return css;
41
+ }
42
+ const TILE = {
43
+ hatch: { size: 6, draw: (c, w) => `<path d="M0,6L6,0M-1.5,1.5L1.5,-1.5M4.5,7.5L7.5,4.5" stroke="${c}" stroke-width="${w}" fill="none"/>` },
44
+ "hatch-wide": { size: 12, draw: (c, w) => `<path d="M0,0L12,12M-3,9L3,15M9,-3L15,3" stroke="${c}" stroke-width="${w}" fill="none"/>` },
45
+ dots: { size: 8, draw: (c, w) => `<circle cx="2" cy="2" r="${w + 0.2}" fill="${c}"/><circle cx="6" cy="6" r="${w + 0.2}" fill="${c}"/>` }
46
+ };
47
+ const round = (v) => Math.round(v * 100) / 100;
48
+ const patternInk = (face, look) => contrast(face, look.ink) >= contrast(face, look.paper) ? look.ink : look.paper;
49
+ function paintMono(svg, look, id) {
50
+ const need = /* @__PURE__ */ new Map();
51
+ const use = (pattern, ink) => {
52
+ const key = `${id}-mono-${pattern}-${ink.slice(1)}`, t = TILE[pattern], w = look.mode === "dark" ? 1.2 : 0.9;
53
+ if (!need.has(key)) need.set(key, `<pattern id="${key}" width="${t.size}" height="${t.size}" patternUnits="userSpaceOnUse">${t.draw(ink, round(w))}</pattern>`);
54
+ return key;
55
+ };
56
+ const depth = [];
57
+ let out = "", layer = "";
58
+ for (const m of svg.matchAll(/<\/[a-zA-Z][\w:-]*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|[^<]+/g)) {
59
+ out += m[0];
60
+ if (m[0].startsWith("</")) {
61
+ depth.pop();
62
+ continue;
63
+ }
64
+ if (m[1] === void 0) continue;
65
+ const cls = (/\sclass="([^"]*)"/.exec(m[2])?.[1] ?? "").split(/\s+/);
66
+ if (depth.length === 1) layer = cls.find((c) => c.startsWith("g-")) ?? "";
67
+ const role = cls.find((c) => c.startsWith("k-"))?.slice(2) ?? depth.at(-1);
68
+ if (!m[3]) depth.push(cls.includes("ghost") ? "" : role);
69
+ if (!m[3] || m[1] !== "polygon" && m[1] !== "path" || !role || !cls.some((c) => c === "top" || c === "lft" || c === "rgt")) continue;
70
+ if (layer === "g-base" && !cls.includes("rgt")) continue;
71
+ const p = Object.hasOwn(look.roles, role) ? look.roles[role].pattern : "none";
72
+ const fill = /\sfill="(#[0-9a-f]{6})"/.exec(m[2])?.[1], shape = /\s(points|d)="[^"]*"/.exec(m[2])?.[0];
73
+ if (p === "none" || !fill || !shape) continue;
74
+ const opacity = /\sfill-opacity="[^"]*"/.exec(m[2])?.[0] ?? "";
75
+ out += `<${m[1]}${shape} class="mono-pattern" fill="url(#${use(p, patternInk(fill, look))})" stroke="none"${opacity}/>`;
76
+ }
77
+ out = out.replace(/#([0-9a-f]{6})\b/g, (h, x) => x.slice(0, 2) === x.slice(2, 4) && x.slice(2, 4) === x.slice(4, 6) ? h : greyHex(h));
78
+ if (need.size) out = out.replace(/<defs\/>|<defs>/, (d) => d === "<defs/>" ? `<defs>${[...need.values()].join("")}</defs>` : d + [...need.values()].join(""));
79
+ return out;
80
+ }
81
+ function greyHex(c) {
82
+ const l = greyOf(c), y = l > 8 ? ((l + 16) / 116) ** 3 : l / (24389 / 27), s = y <= 31308e-7 ? y * 12.92 : 1.055 * y ** (1 / 2.4) - 0.055;
83
+ const v = Math.max(0, Math.min(255, Math.round(s * 255))).toString(16).padStart(2, "0");
84
+ return `#${v}${v}${v}`;
85
+ }
86
+ function monoOfDrawing(svg, theme, mode, kinds, own) {
87
+ const look = monoOf(theme, mode, usedIn(svg, theme, kinds), own);
88
+ return { look, theme: monoTheme(theme, look), css: monoCss(look) };
89
+ }
90
+ export {
91
+ monoCss,
92
+ monoOfDrawing,
93
+ monoTheme,
94
+ paintMono,
95
+ usedIn
96
+ };