@sebastianwessel/isostate 0.2.0 → 0.4.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 (54) hide show
  1. package/dist/browser/isostate.runtime.js +4 -4
  2. package/dist/browser/isostate.runtime.js.map +7 -6
  3. package/dist/chunks/{index-DoyWxJDm.js → index-C3qcXbPI.js} +6 -1145
  4. package/dist/chunks/index-C3qcXbPI.js.map +1 -0
  5. package/dist/chunks/rendering-engine-BUUV3Qq-.js +1124 -0
  6. package/dist/chunks/rendering-engine-BUUV3Qq-.js.map +1 -0
  7. package/dist/chunks/scene-parser-B9SPDLYs.js +2688 -0
  8. package/dist/chunks/scene-parser-B9SPDLYs.js.map +1 -0
  9. package/dist/chunks/sha256-4JuurR-b.js +69 -0
  10. package/dist/chunks/sha256-4JuurR-b.js.map +1 -0
  11. package/dist/dsl/browser.d.ts +7 -0
  12. package/dist/dsl/browser.d.ts.map +1 -0
  13. package/dist/dsl/browser.js +5 -0
  14. package/dist/dsl/browser.js.map +1 -0
  15. package/dist/dsl/compiler.d.ts.map +1 -1
  16. package/dist/dsl/index.js +4 -2299
  17. package/dist/dsl/index.js.map +1 -1
  18. package/dist/dsl/scene-parser.d.ts.map +1 -1
  19. package/dist/dsl/scene-validator.d.ts.map +1 -1
  20. package/dist/editor-support/adapter.d.ts +47 -0
  21. package/dist/editor-support/adapter.d.ts.map +1 -0
  22. package/dist/editor-support/geometry.d.ts +32 -0
  23. package/dist/editor-support/geometry.d.ts.map +1 -0
  24. package/dist/editor-support/hit-test.d.ts +29 -0
  25. package/dist/editor-support/hit-test.d.ts.map +1 -0
  26. package/dist/editor-support/index.d.ts +7 -0
  27. package/dist/editor-support/index.d.ts.map +1 -0
  28. package/dist/editor-support/index.js +429 -0
  29. package/dist/editor-support/index.js.map +1 -0
  30. package/dist/index.js +3 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/rendering/asset-node.d.ts +2 -1
  33. package/dist/rendering/asset-node.d.ts.map +1 -1
  34. package/dist/rendering/rendering-engine.d.ts +13 -0
  35. package/dist/rendering/rendering-engine.d.ts.map +1 -1
  36. package/dist/runtime/index.js +3 -1
  37. package/dist/runtime/index.js.map +1 -1
  38. package/dist/runtime/mount-scene.d.ts.map +1 -1
  39. package/dist/types/assets.d.ts +27 -2
  40. package/dist/types/assets.d.ts.map +1 -1
  41. package/dist/types/index.d.ts +4 -4
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/node.d.ts +15 -2
  44. package/dist/types/node.d.ts.map +1 -1
  45. package/dist/types/runtime-bundle.d.ts +5 -0
  46. package/dist/types/runtime-bundle.d.ts.map +1 -1
  47. package/dist/types/scene.d.ts +25 -2
  48. package/dist/types/scene.d.ts.map +1 -1
  49. package/dist/types/validation.d.ts +6 -0
  50. package/dist/types/validation.d.ts.map +1 -1
  51. package/dist/utils/sha256.d.ts +3 -0
  52. package/dist/utils/sha256.d.ts.map +1 -0
  53. package/package.json +9 -1
  54. package/dist/chunks/index-DoyWxJDm.js.map +0 -1
@@ -0,0 +1,1124 @@
1
+ import { R as RenderError } from './errors-DyqEkrm5.js';
2
+
3
+ // ── Built-in themes ────────────────────────────────────────────────────────
4
+ const BUILTIN_THEMES = {
5
+ light: {
6
+ "--color-top": "#e2e8f0",
7
+ "--color-front": "#94a3b8",
8
+ "--color-side": "#64748b",
9
+ "--color-back": "#475569",
10
+ "--color-leaf": "#15803d",
11
+ "--color-trunk": "#78350f",
12
+ "--color-accent": "#3b82f6",
13
+ },
14
+ dark: {
15
+ "--color-top": "#334155",
16
+ "--color-front": "#1e293b",
17
+ "--color-side": "#0f172a",
18
+ "--color-back": "#020617",
19
+ "--color-leaf": "#166534",
20
+ "--color-trunk": "#451a03",
21
+ "--color-accent": "#60a5fa",
22
+ },
23
+ brand: {
24
+ "--color-top": "#c7d2fe",
25
+ "--color-front": "#818cf8",
26
+ "--color-side": "#6366f1",
27
+ "--color-back": "#4338ca",
28
+ "--color-leaf": "#22c55e",
29
+ "--color-trunk": "#854d0e",
30
+ "--color-accent": "#f59e0b",
31
+ },
32
+ };
33
+ /**
34
+ * Resolve a theme name to its CSS variable map.
35
+ * Returns undefined if the theme is not found.
36
+ */
37
+ function resolveTheme(name) {
38
+ return BUILTIN_THEMES[name];
39
+ }
40
+ /**
41
+ * Compose a new theme by extending an existing one with overrides.
42
+ */
43
+ function composeTheme(baseName, overrides) {
44
+ const base = BUILTIN_THEMES[baseName];
45
+ if (!base) {
46
+ return { name: baseName, vars: { ...overrides } };
47
+ }
48
+ return { name: baseName, vars: { ...base, ...overrides } };
49
+ }
50
+ // ── Asset registry implementation ──────────────────────────────────────────
51
+ /**
52
+ * Default asset registry implementation.
53
+ * Maps asset ids to definitions and supports category filtering.
54
+ */
55
+ class AssetRegistryImpl {
56
+ _assets = new Map();
57
+ register(asset) {
58
+ this._assets.set(asset.id, asset);
59
+ }
60
+ get(id) {
61
+ return this._assets.get(id);
62
+ }
63
+ getAll(category) {
64
+ if (category) {
65
+ return [...this._assets.values()].filter((a) => a.category === category);
66
+ }
67
+ return [...this._assets.values()];
68
+ }
69
+ has(id) {
70
+ return this._assets.has(id);
71
+ }
72
+ remove(id) {
73
+ this._assets.delete(id);
74
+ }
75
+ }
76
+ function createAssetRegistry(assets = []) {
77
+ const registry = new AssetRegistryImpl();
78
+ for (const asset of assets) {
79
+ registry.register(asset);
80
+ }
81
+ return registry;
82
+ }
83
+ /** Create a fresh registry populated with the built-in demo assets. */
84
+ function createDefaultRegistry() {
85
+ return createAssetRegistry([
86
+ {
87
+ id: "iso-platform",
88
+ category: "infrastructure",
89
+ },
90
+ {
91
+ id: "iso-server",
92
+ category: "equipment",
93
+ },
94
+ {
95
+ id: "iso-database",
96
+ category: "equipment",
97
+ },
98
+ {
99
+ id: "iso-connector",
100
+ category: "decoration",
101
+ },
102
+ {
103
+ id: "iso-cloud",
104
+ category: "decoration",
105
+ },
106
+ ]);
107
+ }
108
+
109
+ /** Default cell size in pixels */
110
+ const DEFAULT_CELL_SIZE = 64;
111
+ /**
112
+ * Calculate raw scene-space coordinates from isometric grid position.
113
+ * Layout is applied separately by subtracting resolved bounds and adding padding.
114
+ */
115
+ function projectToRaw(gridX, gridY, cellSize) {
116
+ return {
117
+ rawX: cellSize * (gridX - gridY) * 0.5,
118
+ rawY: cellSize * (gridX + gridY) * 0.25,
119
+ };
120
+ }
121
+ /**
122
+ * Calculate screen coordinates from raw isometric projection and resolved bounds.
123
+ */
124
+ function projectToScreen(gridX, gridY, cellSize, boundsMinX = 0, boundsMinY = 0, paddingX = 0, paddingY = 0) {
125
+ const { rawX, rawY } = projectToRaw(gridX, gridY, cellSize);
126
+ return {
127
+ screenX: rawX - boundsMinX + paddingX,
128
+ screenY: rawY - boundsMinY + paddingY,
129
+ };
130
+ }
131
+ /** Calculate the screen size for an element based on its grid size. */
132
+ function calculateVisualSize(gridSize, cellSize) {
133
+ return cellSize * gridSize;
134
+ }
135
+ /** Calculate the element transform string for positioning and scaling. */
136
+ function calculateTransform(screenX, screenY, visualSize, cellSize) {
137
+ const scale = visualSize / cellSize;
138
+ return `translate(${screenX}px, ${screenY}px) scale(${scale})`;
139
+ }
140
+
141
+ /** Build built-in entry, exit, ambient, and reduced-motion CSS keyframes. */
142
+ function buildKeyframeCSS() {
143
+ return [
144
+ "@keyframes iso-anim-fade-in{from{opacity:0}to{opacity:1}}",
145
+ "@keyframes iso-anim-fade-in-grow{from{opacity:0;scale:.01}to{opacity:1;scale:1}}",
146
+ "@keyframes iso-anim-fall-in{from{opacity:0;translate:0 -40px}to{opacity:1;translate:0 0}}",
147
+ "@keyframes iso-anim-rise-from-ground{from{opacity:0;translate:0 40px}to{opacity:1;translate:0 0}}",
148
+ "@keyframes iso-anim-slide-in-left{from{opacity:0;translate:-60px 0}to{opacity:1;translate:0 0}}",
149
+ "@keyframes iso-anim-slide-in-right{from{opacity:0;translate:60px 0}to{opacity:1;translate:0 0}}",
150
+ "@keyframes iso-anim-flip-in{from{opacity:1;scale:0 1}to{opacity:1;scale:1 1}}",
151
+ "@keyframes iso-anim-fade-out{from{opacity:1}to{opacity:0}}",
152
+ "@keyframes iso-anim-fade-out-shrink{from{opacity:1;scale:1}to{opacity:0;scale:.01}}",
153
+ "@keyframes iso-anim-fall-through-ground{from{opacity:1;translate:0 0}to{opacity:0;translate:0 40px}}",
154
+ "@keyframes iso-anim-rise-away{from{opacity:1;translate:0 0}to{opacity:0;translate:0 -40px}}",
155
+ "@keyframes iso-anim-slide-out-left{from{opacity:1;translate:0 0}to{opacity:0;translate:-60px 0}}",
156
+ "@keyframes iso-anim-slide-out-right{from{opacity:1;translate:0 0}to{opacity:0;translate:60px 0}}",
157
+ "@keyframes iso-anim-flip-out{from{opacity:1;scale:1 1}to{opacity:0;scale:0 1}}",
158
+ "@keyframes iso-anim-pulse{0%,100%{opacity:.7}50%{opacity:1}}",
159
+ "@keyframes iso-anim-float{0%,100%{translate:0 0}50%{translate:0 -6px}}",
160
+ "@keyframes iso-anim-shake{0%,25%,75%,100%{translate:0 0}50%{translate:3px 0}}",
161
+ "@keyframes iso-anim-glow{0%,100%{filter:drop-shadow(0 0 2px rgba(255,255,255,.5))}50%{filter:drop-shadow(0 0 8px rgba(255,255,255,.9))}}",
162
+ "@keyframes iso-anim-spin{from{rotate:0deg}to{rotate:360deg}}",
163
+ "@keyframes iso-anim-blink{0%,49%{opacity:1}50%,100%{opacity:0}}",
164
+ "@keyframes iso-connector-flow-route{from{stroke-dashoffset:0}to{stroke-dashoffset:calc(-1px * var(--iso-flow-distance,20))}}",
165
+ "@keyframes iso-connector-flow-reverse{from{stroke-dashoffset:0}to{stroke-dashoffset:calc(1px * var(--iso-flow-distance,20))}}",
166
+ ".iso-connector-pattern-dashed .iso-connector-shaft,.iso-connector-pattern-dotted .iso-connector-shaft{--iso-flow-distance:20}",
167
+ ".iso-connector-direction-route .iso-connector-shaft.iso-ambient-flow{animation:iso-connector-flow-route 900ms linear infinite}",
168
+ ".iso-connector-direction-reverse .iso-connector-shaft.iso-ambient-flow{animation:iso-connector-flow-reverse 900ms linear infinite}",
169
+ "@media (prefers-reduced-motion: reduce){.iso-element,.iso-connector{animation-duration:1ms!important}.iso-ambient-pulse,.iso-ambient-float,.iso-ambient-shake,.iso-ambient-glow,.iso-ambient-spin,.iso-ambient-blink,.iso-ambient-flow{animation:none!important}}",
170
+ ].join("\n");
171
+ }
172
+
173
+ const NS$1 = "http://www.w3.org/2000/svg";
174
+ function createAssetResolver(bundle) {
175
+ const embedded = new Map();
176
+ const bundleAssets = bundle?.assets;
177
+ if (bundleAssets && typeof bundleAssets === "object") {
178
+ for (const [name, asset] of Object.entries(bundleAssets)) {
179
+ if (asset && typeof asset === "object" && typeof asset.url === "string") {
180
+ embedded.set(name, { url: asset.url, anchor: asset.anchor, sprite: asset.sprite });
181
+ }
182
+ }
183
+ }
184
+ return (name) => embedded.get(name);
185
+ }
186
+ function createAssetNode(asset, assetName, cellSize) {
187
+ if (asset.sprite) {
188
+ return createSpriteAssetNode(asset.url, assetName, cellSize, asset.sprite, asset.anchor);
189
+ }
190
+ return createUrlAssetNode(asset.url, assetName, cellSize, asset.anchor);
191
+ }
192
+ function createTextAssetNode(textContent, assetName, cellSize) {
193
+ if (!textContent?.value) {
194
+ throw new RenderError("TEXT_CONTENT_MISSING", `Text content is missing for built-in asset: ${assetName}`, {
195
+ asset: assetName,
196
+ });
197
+ }
198
+ const group = document.createElementNS(NS$1, "g");
199
+ const text = document.createElementNS(NS$1, "text");
200
+ const align = textContent.align ?? "middle";
201
+ const placement = textContent.placement ?? "cell";
202
+ const fontSize = textContent.fontSize ?? 12;
203
+ const lineHeight = textContent.lineHeight ?? 1.2;
204
+ const anchorX = textAnchorX(align, cellSize);
205
+ const vertical = textVerticalAnchor(placement, cellSize);
206
+ text.setAttribute("x", String(anchorX));
207
+ text.setAttribute("y", String(vertical.y));
208
+ text.setAttribute("text-anchor", align);
209
+ text.setAttribute("dominant-baseline", vertical.baseline);
210
+ text.setAttribute("font-family", "Arial, Helvetica, sans-serif");
211
+ text.setAttribute("font-size", String(fontSize));
212
+ text.setAttribute("font-weight", String(textContent.fontWeight ?? 700));
213
+ text.setAttribute("fill", textContent.fill ?? "currentColor");
214
+ const lines = normalizeTextLines(textContent.value);
215
+ for (const [index, line] of lines.entries()) {
216
+ const tspan = document.createElementNS(NS$1, "tspan");
217
+ tspan.setAttribute("x", String(anchorX));
218
+ tspan.setAttribute("dy", index === 0 ? "0" : String(fontSize * lineHeight));
219
+ tspan.textContent = line;
220
+ text.appendChild(tspan);
221
+ }
222
+ group.appendChild(text);
223
+ return group;
224
+ }
225
+ function createPrimitiveAssetNode(assetName, primitive, cellSize) {
226
+ const group = document.createElementNS(NS$1, "g");
227
+ switch (assetName) {
228
+ case "rectangle":
229
+ appendProjectedPolygon(group, rectanglePoints(), primitive?.rectangle, cellSize);
230
+ return group;
231
+ case "polygon":
232
+ appendProjectedPolygon(group, primitive?.polygon?.points, primitive?.polygon, cellSize);
233
+ return group;
234
+ case "line":
235
+ appendProjectedPolyline(group, primitive?.line, primitive?.line, cellSize);
236
+ return group;
237
+ case "circle":
238
+ appendCircle(group, primitive?.circle, cellSize);
239
+ return group;
240
+ default:
241
+ throw new RenderError("PRIMITIVE_ASSET_UNKNOWN", `Unknown built-in primitive asset: ${assetName}`, {
242
+ asset: assetName,
243
+ });
244
+ }
245
+ }
246
+ function textAnchorX(align, cellSize) {
247
+ if (align === "start")
248
+ return -cellSize / 2;
249
+ if (align === "end")
250
+ return cellSize / 2;
251
+ return 0;
252
+ }
253
+ function textVerticalAnchor(placement, cellSize) {
254
+ if (placement === "caption")
255
+ return { y: -cellSize, baseline: "text-before-edge" };
256
+ return { y: -cellSize / 2, baseline: "middle" };
257
+ }
258
+ function normalizeTextLines(value) {
259
+ const normalized = value.replace(/\r\n?/g, "\n").replace(/\n$/, "");
260
+ return normalized.split("\n");
261
+ }
262
+ function rectanglePoints() {
263
+ return [
264
+ [0, 0],
265
+ [1, 0],
266
+ [1, 1],
267
+ [0, 1],
268
+ ];
269
+ }
270
+ function appendProjectedPolygon(group, points, style, cellSize) {
271
+ if (!points)
272
+ return;
273
+ const polygon = document.createElementNS(NS$1, "polygon");
274
+ polygon.setAttribute("points", points.map((point) => projectLocalPoint(point, cellSize)).join(" "));
275
+ applyPrimitiveStyle(polygon, style, { fill: "currentColor", stroke: "none" });
276
+ group.appendChild(polygon);
277
+ }
278
+ function appendProjectedPolyline(group, line, style, cellSize) {
279
+ if (!line?.points)
280
+ return;
281
+ const polyline = document.createElementNS(NS$1, "polyline");
282
+ polyline.setAttribute("points", line.points.map((point) => projectLocalPoint(point, cellSize)).join(" "));
283
+ polyline.setAttribute("fill", "none");
284
+ polyline.setAttribute("stroke-linecap", line.lineCap ?? "round");
285
+ polyline.setAttribute("stroke-linejoin", line.lineJoin ?? "round");
286
+ applyPrimitiveStyle(polyline, style, {
287
+ fill: "none",
288
+ stroke: "currentColor",
289
+ });
290
+ group.appendChild(polyline);
291
+ }
292
+ function appendCircle(group, style, cellSize) {
293
+ const center = projectLocalPoint([0.5, 0.5], cellSize);
294
+ const circle = document.createElementNS(NS$1, "circle");
295
+ const [cx, cy] = center.split(",").map(Number);
296
+ circle.setAttribute("cx", String(cx));
297
+ circle.setAttribute("cy", String(cy));
298
+ circle.setAttribute("r", String(cellSize * 0.2));
299
+ applyPrimitiveStyle(circle, style, {
300
+ fill: "currentColor",
301
+ stroke: "none",
302
+ });
303
+ group.appendChild(circle);
304
+ }
305
+ function projectLocalPoint(point, cellSize) {
306
+ const projected = projectToRaw(point[0], point[1], cellSize);
307
+ const anchor = projectToRaw(1, 1, cellSize);
308
+ return `${projected.rawX - anchor.rawX},${projected.rawY - anchor.rawY}`;
309
+ }
310
+ function applyPrimitiveStyle(node, style, defaults) {
311
+ node.setAttribute("fill", style?.fill ?? defaults.fill);
312
+ node.setAttribute("stroke", style?.stroke ?? defaults.stroke);
313
+ node.setAttribute("stroke-width", String(style?.strokeWidth ?? 0));
314
+ node.setAttribute("opacity", String(style?.opacity ?? 1));
315
+ if (style?.dash)
316
+ node.setAttribute("stroke-dasharray", style.dash.join(" "));
317
+ }
318
+ function createUrlAssetNode(url, assetName, cellSize, anchor) {
319
+ if (!isSafeAssetUrl(url)) {
320
+ throw new RenderError("INVALID_ASSET_URL", `Asset URL is unsafe: ${assetName}`, { asset: assetName });
321
+ }
322
+ const group = document.createElementNS(NS$1, "g");
323
+ const image = document.createElementNS(NS$1, "image");
324
+ const resolvedUrl = resolveBrowserAssetUrl(url);
325
+ const [anchorX, anchorY] = anchor ?? [0.5, 1];
326
+ image.setAttribute("href", resolvedUrl);
327
+ image.setAttributeNS("http://www.w3.org/1999/xlink", "href", resolvedUrl);
328
+ image.setAttribute("x", String(-cellSize * anchorX));
329
+ image.setAttribute("y", String(-cellSize * anchorY));
330
+ image.setAttribute("width", String(cellSize));
331
+ image.setAttribute("height", String(cellSize));
332
+ image.setAttribute("preserveAspectRatio", "xMidYMax meet");
333
+ group.appendChild(image);
334
+ return group;
335
+ }
336
+ function createSpriteAssetNode(url, assetName, cellSize, sprite, anchor) {
337
+ if (!isSafeAssetUrl(url)) {
338
+ throw new RenderError("INVALID_ASSET_URL", `Asset URL is unsafe: ${assetName}`, { asset: assetName });
339
+ }
340
+ const group = document.createElementNS(NS$1, "g");
341
+ const viewport = document.createElementNS(NS$1, "svg");
342
+ const image = document.createElementNS(NS$1, "image");
343
+ const resolvedUrl = resolveBrowserAssetUrl(url);
344
+ const [anchorX, anchorY] = anchor ?? [0.5, 1];
345
+ const [rectX, rectY, rectWidth, rectHeight] = sprite.rect;
346
+ viewport.setAttribute("x", String(-cellSize * anchorX));
347
+ viewport.setAttribute("y", String(-cellSize * anchorY));
348
+ viewport.setAttribute("width", String(cellSize));
349
+ viewport.setAttribute("height", String(cellSize));
350
+ viewport.setAttribute("viewBox", `${rectX} ${rectY} ${rectWidth} ${rectHeight}`);
351
+ viewport.setAttribute("preserveAspectRatio", "xMidYMax meet");
352
+ image.setAttribute("href", resolvedUrl);
353
+ image.setAttributeNS("http://www.w3.org/1999/xlink", "href", resolvedUrl);
354
+ image.setAttribute("x", "0");
355
+ image.setAttribute("y", "0");
356
+ image.setAttribute("width", String(sprite.sheetSize[0]));
357
+ image.setAttribute("height", String(sprite.sheetSize[1]));
358
+ viewport.appendChild(image);
359
+ group.appendChild(viewport);
360
+ return group;
361
+ }
362
+ function resolveBrowserAssetUrl(url) {
363
+ try {
364
+ const baseURI = document.baseURI;
365
+ return typeof baseURI === "string" ? new URL(url, baseURI).href : url;
366
+ }
367
+ catch {
368
+ return url;
369
+ }
370
+ }
371
+ function isSafeAssetUrl(url) {
372
+ const normalized = url.trim().toLowerCase();
373
+ return normalized.length > 0 && !normalized.startsWith("javascript:");
374
+ }
375
+
376
+ const CSS_CUSTOM_PROPERTY_PATTERN = /^--[a-zA-Z0-9-_]+$/;
377
+ function applyThemeToElement(element, themeVars) {
378
+ for (const [name, value] of Object.entries(themeVars)) {
379
+ if (!CSS_CUSTOM_PROPERTY_PATTERN.test(name)) {
380
+ throw new RenderError("INVALID_THEME_VAR", `Invalid CSS custom property name: ${name}`);
381
+ }
382
+ element.style.setProperty(name, value);
383
+ }
384
+ }
385
+
386
+ const NS = "http://www.w3.org/2000/svg";
387
+ const BUILT_IN_TEXT_ASSET_ID = "text";
388
+ const BUILT_IN_PRIMITIVE_ASSET_IDS = new Set(["rectangle", "circle", "polygon", "line"]);
389
+ const DEFAULT_CONNECTOR_DASH = {
390
+ dashed: [12, 8],
391
+ dotted: [0, 8],
392
+ };
393
+ const ENDPOINT_RADIUS_GRID = 0.14;
394
+ const ARROW_LENGTH_GRID = 0.35;
395
+ const ARROW_WIDTH_GRID = 0.28;
396
+ const BAR_WIDTH_GRID = 0.4;
397
+ // ── Public API ────────────────────────────────────────────────────────────
398
+ /** Build the SVG DOM for a compiled runtime bundle and mount it into a container. */
399
+ function buildSceneDOM(container, bundle, config) {
400
+ const layout = resolveSceneLayout(bundle);
401
+ const initialStop = bundle.scenes[0];
402
+ const allElements = collectElementDefinitions(bundle);
403
+ const allConnectors = collectConnectorDefinitions(bundle);
404
+ const initialById = new Map((initialStop?.elements ?? []).map((element) => [element.id, element]));
405
+ const initialConnectorsById = new Map((initialStop?.connectors ?? []).map((connector) => [connector.id, connector]));
406
+ const svg = createRootSvg(layout, config?.label, bundle.className);
407
+ const assetResolver = createAssetResolver(bundle);
408
+ svg.appendChild(createCssDefs());
409
+ applyThemeToElement(svg, {
410
+ ...(resolveTheme(bundle.theme) ?? {}),
411
+ ...(bundle.themeVars ?? {}),
412
+ ...(config?.themeVars ?? {}),
413
+ });
414
+ const sortedLayers = sortLayers(bundle.layers);
415
+ const layerMap = createLayerMap(sortedLayers);
416
+ if (bundle.floor.visible) {
417
+ svg.appendChild(createFloorGrid(bundle, layout));
418
+ }
419
+ const connectorMap = new Map();
420
+ for (const def of allConnectors) {
421
+ const initial = initialConnectorsById.get(def.id) ?? {
422
+ ...def,
423
+ presence: "removed",
424
+ };
425
+ const state = createConnectorInstance(initial, layout);
426
+ if (initial.presence === "removed") {
427
+ state.isHidden = true;
428
+ hideElementAfterExit(state.node);
429
+ }
430
+ applyConnectorAmbientClasses(state, initial.ambient ?? []);
431
+ svg.appendChild(state.node);
432
+ connectorMap.set(def.id, state);
433
+ }
434
+ const depthGroup = document.createElementNS(NS, "g");
435
+ depthGroup.classList.add("iso-depth-layer");
436
+ depthGroup.setAttribute("data-layer", "depth");
437
+ svg.appendChild(depthGroup);
438
+ const labelGroup = document.createElementNS(NS, "g");
439
+ labelGroup.classList.add("iso-layer", "iso-layer-labels");
440
+ labelGroup.setAttribute("data-layer", "labels");
441
+ svg.appendChild(labelGroup);
442
+ const elementMap = new Map();
443
+ const sortedElements = sortElementsForPerspective(allElements);
444
+ for (const def of sortedElements) {
445
+ const declaredLayer = layerMap.get(def.layer);
446
+ if (!declaredLayer) {
447
+ throw new RenderError("MISSING_LAYER", `Unknown layer for "${def.id}": ${def.layer}`);
448
+ }
449
+ const initial = initialById.get(def.id) ?? {
450
+ ...def,
451
+ presence: "removed",
452
+ };
453
+ const instance = createElementInstance(initial, layout, assetResolver);
454
+ instance.anchor = assetAnchorForBounds(bundle, initial);
455
+ instance.node.classList.add(`iso-layer-${def.layer}`);
456
+ instance.node.setAttribute("data-layer", def.layer);
457
+ if (initial.presence === "removed") {
458
+ instance.isHidden = true;
459
+ hideElementAfterExit(instance.node);
460
+ }
461
+ applyAmbientClasses(instance, initial.ambient ?? []);
462
+ const parent = isTextAsset(def.asset) ? labelGroup : depthGroup;
463
+ parent.appendChild(instance.node);
464
+ elementMap.set(def.id, instance);
465
+ }
466
+ svg._layerMap = layerMap;
467
+ svg._elementMap = elementMap;
468
+ svg._connectorMap = connectorMap;
469
+ container.appendChild(svg);
470
+ return svg;
471
+ }
472
+ /** Update transforms and ambient classes for a live set of interpolated runtime values. */
473
+ function updateElementTransforms(svg, elements, connectors = []) {
474
+ const layout = svg._layout;
475
+ if (!layout)
476
+ return;
477
+ const map = svg._elementMap;
478
+ if (map) {
479
+ for (const def of elements) {
480
+ const state = map.get(def.id);
481
+ if (!state)
482
+ continue;
483
+ state.current = def;
484
+ updateGeneratedElementContent(state.node, def, layout);
485
+ applyElementTransform(state.node, def, layout);
486
+ applyAmbientClasses(state, def.ambient ?? []);
487
+ }
488
+ }
489
+ const connectorMap = svg._connectorMap;
490
+ if (!connectorMap)
491
+ return;
492
+ for (const def of connectors) {
493
+ const state = connectorMap.get(def.id);
494
+ if (!state)
495
+ continue;
496
+ applyConnectorState(state, def, layout);
497
+ }
498
+ }
499
+ /** Read the internal ElementState for an element by its id. */
500
+ function getElementState(svg, id) {
501
+ return svg._elementMap?.get(id);
502
+ }
503
+ /** Read the internal ConnectorState for a connector by its id. */
504
+ function getConnectorState(svg, id) {
505
+ return svg._connectorMap?.get(id);
506
+ }
507
+ function getResolvedViewBox(bundle) {
508
+ return resolveSceneLayout(bundle).viewBox;
509
+ }
510
+ function getResolvedProjectionLayout(bundle) {
511
+ const layout = resolveSceneLayout(bundle);
512
+ return {
513
+ cellSize: layout.cellSize,
514
+ padding: layout.padding,
515
+ selectedBounds: layout.selectedBounds,
516
+ };
517
+ }
518
+ function getCurrentElementBounds(svg, id) {
519
+ const layout = svg._layout;
520
+ const state = svg._elementMap?.get(id);
521
+ if (!layout || !state || state.current.presence === "removed")
522
+ return undefined;
523
+ return boundsToViewBox(calculateElementBounds(state.current, layout, state.anchor));
524
+ }
525
+ function getGridAreaBounds(bundle, area) {
526
+ const layout = resolveSceneLayout(bundle);
527
+ const [x, y] = area.at;
528
+ const [width, height] = area.size;
529
+ let bounds = emptyBounds();
530
+ for (const point of [
531
+ [x, y],
532
+ [x + width, y],
533
+ [x, y + height],
534
+ [x + width, y + height],
535
+ ]) {
536
+ const screen = projectToScreen(point[0], point[1], layout.cellSize, layout.selectedBounds.minX, layout.selectedBounds.minY, layout.padding.x, layout.padding.y);
537
+ bounds = includePoint(bounds, screen.screenX, screen.screenY);
538
+ }
539
+ return boundsToViewBox(bounds);
540
+ }
541
+ function applySceneViewBox(svg, viewBox) {
542
+ svg.setAttribute("viewBox", `${viewBox.minX} ${viewBox.minY} ${viewBox.width} ${viewBox.height}`);
543
+ }
544
+ // ── Lifecycle helpers ─────────────────────────────────────────────────────
545
+ /** Hide an element after its exit animation completes. */
546
+ function hideElementAfterExit(node) {
547
+ node.style.visibility = "hidden";
548
+ node.style.pointerEvents = "none";
549
+ }
550
+ /** Show an element on re-addition. */
551
+ function unhideElementOnReadd(node) {
552
+ node.style.visibility = "visible";
553
+ node.style.pointerEvents = "auto";
554
+ }
555
+ // ── Layout helpers ────────────────────────────────────────────────────────
556
+ function resolveSceneLayout(bundle) {
557
+ const cellSize = bundle.grid.cellSize;
558
+ const padding = bundle.layout.padding;
559
+ const contentBounds = calculateContentBounds(bundle, cellSize);
560
+ const floorBounds = calculateFloorBounds(bundle, cellSize);
561
+ const selectedBounds = selectBounds(bundle.layout.bounds, contentBounds, floorBounds);
562
+ const width = selectedBounds.maxX - selectedBounds.minX + padding.x * 2;
563
+ const height = selectedBounds.maxY - selectedBounds.minY + padding.y * 2;
564
+ const viewBox = {
565
+ minX: 0,
566
+ minY: 0,
567
+ width: roundDimension(width || cellSize),
568
+ height: roundDimension(height || cellSize),
569
+ };
570
+ return {
571
+ cellSize,
572
+ padding,
573
+ contentBounds,
574
+ floorBounds,
575
+ selectedBounds,
576
+ viewBox,
577
+ };
578
+ }
579
+ function calculateContentBounds(bundle, cellSize) {
580
+ let bounds = emptyBounds();
581
+ for (const stop of bundle.scenes) {
582
+ for (const element of stop.elements ?? []) {
583
+ if (element.presence === "removed")
584
+ continue;
585
+ bounds = includeBounds(bounds, calculateRawElementBounds(bundle, element, cellSize));
586
+ }
587
+ for (const connector of stop.connectors ?? []) {
588
+ if (connector.presence === "removed")
589
+ continue;
590
+ bounds = includeBounds(bounds, calculateConnectorBounds(connector, cellSize));
591
+ }
592
+ }
593
+ return normalizeBounds(bounds, cellSize);
594
+ }
595
+ function calculateRawElementBounds(bundle, element, cellSize) {
596
+ const { rawX, rawY } = projectToRaw(element.pos[0] + element.size, element.pos[1] + element.size, cellSize);
597
+ const visualSize = calculateVisualSize(element.size, cellSize);
598
+ const [anchorX, anchorY] = assetAnchorForBounds(bundle, element);
599
+ return {
600
+ minX: rawX - visualSize * anchorX,
601
+ minY: rawY - visualSize * anchorY,
602
+ maxX: rawX + visualSize * (1 - anchorX),
603
+ maxY: rawY + visualSize * (1 - anchorY),
604
+ };
605
+ }
606
+ function calculateElementBounds(element, layout, anchor) {
607
+ const screen = projectToScreen(element.pos[0] + element.size, element.pos[1] + element.size, layout.cellSize, layout.selectedBounds.minX, layout.selectedBounds.minY, layout.padding.x, layout.padding.y);
608
+ const visualSize = calculateVisualSize(element.size, layout.cellSize);
609
+ return {
610
+ minX: screen.screenX - visualSize * anchor[0],
611
+ minY: screen.screenY - visualSize * anchor[1],
612
+ maxX: screen.screenX + visualSize * (1 - anchor[0]),
613
+ maxY: screen.screenY + visualSize * (1 - anchor[1]),
614
+ };
615
+ }
616
+ function assetAnchorForBounds(bundle, element) {
617
+ return bundle.assets?.[element.asset]?.anchor ?? [0.5, 1];
618
+ }
619
+ function calculateConnectorBounds(connector, cellSize) {
620
+ let bounds = emptyBounds();
621
+ for (const [x, y] of connector.route) {
622
+ const { rawX, rawY } = projectToRaw(x, y, cellSize);
623
+ bounds = includePoint(bounds, rawX, rawY);
624
+ }
625
+ const endpointPadding = Math.max(ARROW_LENGTH_GRID, BAR_WIDTH_GRID, ENDPOINT_RADIUS_GRID * 2) * cellSize;
626
+ const strokePadding = connector.style.strokeWidth / 2 + (connector.style.outlineWidth ?? 0);
627
+ const padding = endpointPadding + strokePadding;
628
+ return {
629
+ minX: bounds.minX - padding,
630
+ minY: bounds.minY - padding,
631
+ maxX: bounds.maxX + padding,
632
+ maxY: bounds.maxY + padding,
633
+ };
634
+ }
635
+ function calculateFloorBounds(bundle, cellSize) {
636
+ const origin = bundle.floor.origin;
637
+ const [width, height] = bundle.floor.size;
638
+ const points = [
639
+ origin,
640
+ [origin[0] + width, origin[1]],
641
+ [origin[0], origin[1] + height],
642
+ [origin[0] + width, origin[1] + height],
643
+ ];
644
+ let bounds = emptyBounds();
645
+ for (const [x, y] of points) {
646
+ const { rawX, rawY } = projectToRaw(x, y, cellSize);
647
+ bounds = includePoint(bounds, rawX, rawY);
648
+ }
649
+ return normalizeBounds(bounds, cellSize);
650
+ }
651
+ function selectBounds(mode, content, floor) {
652
+ if (mode === "content")
653
+ return content;
654
+ if (mode === "floor")
655
+ return floor;
656
+ return includeBounds(content, floor);
657
+ }
658
+ function emptyBounds() {
659
+ return {
660
+ minX: Number.POSITIVE_INFINITY,
661
+ minY: Number.POSITIVE_INFINITY,
662
+ maxX: Number.NEGATIVE_INFINITY,
663
+ maxY: Number.NEGATIVE_INFINITY,
664
+ };
665
+ }
666
+ function normalizeBounds(bounds, cellSize) {
667
+ if (Number.isFinite(bounds.minX))
668
+ return bounds;
669
+ return { minX: 0, minY: 0, maxX: cellSize, maxY: cellSize };
670
+ }
671
+ function boundsToViewBox(bounds) {
672
+ const centerX = (bounds.minX + bounds.maxX) / 2;
673
+ const centerY = (bounds.minY + bounds.maxY) / 2;
674
+ const width = Math.max(1, bounds.maxX - bounds.minX);
675
+ const height = Math.max(1, bounds.maxY - bounds.minY);
676
+ return {
677
+ minX: roundDimension(centerX - width / 2),
678
+ minY: roundDimension(centerY - height / 2),
679
+ width: roundDimension(width),
680
+ height: roundDimension(height),
681
+ };
682
+ }
683
+ function includePoint(bounds, x, y) {
684
+ return {
685
+ minX: Math.min(bounds.minX, x),
686
+ minY: Math.min(bounds.minY, y),
687
+ maxX: Math.max(bounds.maxX, x),
688
+ maxY: Math.max(bounds.maxY, y),
689
+ };
690
+ }
691
+ function includeBounds(bounds, next) {
692
+ return {
693
+ minX: Math.min(bounds.minX, next.minX),
694
+ minY: Math.min(bounds.minY, next.minY),
695
+ maxX: Math.max(bounds.maxX, next.maxX),
696
+ maxY: Math.max(bounds.maxY, next.maxY),
697
+ };
698
+ }
699
+ function roundDimension(value) {
700
+ return Math.round(value * 1000) / 1000;
701
+ }
702
+ // ── Private helpers ───────────────────────────────────────────────────────
703
+ function createRootSvg(layout, label, className) {
704
+ const svg = document.createElementNS(NS, "svg");
705
+ svg.classList.add("iso-scene");
706
+ for (const token of className?.trim().split(/\s+/) ?? []) {
707
+ if (token)
708
+ svg.classList.add(token);
709
+ }
710
+ svg.setAttribute("width", "100%");
711
+ svg.setAttribute("height", "100%");
712
+ svg.setAttribute("viewBox", `${layout.viewBox.minX} ${layout.viewBox.minY} ${layout.viewBox.width} ${layout.viewBox.height}`);
713
+ svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
714
+ svg.style.width = "100%";
715
+ svg.style.height = "100%";
716
+ svg.style.display = "block";
717
+ if (label) {
718
+ svg.setAttribute("role", "img");
719
+ svg.setAttribute("aria-label", label);
720
+ }
721
+ else {
722
+ svg.setAttribute("aria-hidden", "true");
723
+ }
724
+ svg._layout = layout;
725
+ svg._viewBoxW = layout.viewBox.width;
726
+ svg._viewBoxH = layout.viewBox.height;
727
+ return svg;
728
+ }
729
+ function createCssDefs() {
730
+ const styleEl = document.createElementNS(NS, "style");
731
+ styleEl.textContent = buildKeyframeCSS();
732
+ return styleEl;
733
+ }
734
+ function createFloorGrid(bundle, layout) {
735
+ const group = document.createElementNS(NS, "g");
736
+ group.classList.add("iso-floor-grid", `iso-layer-${bundle.floor.layer}`);
737
+ group.setAttribute("data-layer", bundle.floor.layer);
738
+ const [originX, originY] = bundle.floor.origin;
739
+ const [columns, rows] = bundle.floor.size;
740
+ const corners = [
741
+ projectGridPoint(originX, originY, layout),
742
+ projectGridPoint(originX + columns, originY, layout),
743
+ projectGridPoint(originX + columns, originY + rows, layout),
744
+ projectGridPoint(originX, originY + rows, layout),
745
+ ];
746
+ const slab = document.createElementNS(NS, "polygon");
747
+ slab.classList.add("iso-floor-slab");
748
+ slab.setAttribute("points", corners.map(pointToString).join(" "));
749
+ slab.setAttribute("fill", "#dbe6f4");
750
+ slab.setAttribute("fill-opacity", "0.22");
751
+ slab.setAttribute("stroke", "#b9c9df");
752
+ slab.setAttribute("stroke-width", "1");
753
+ group.appendChild(slab);
754
+ for (let x = 0; x <= columns; x++) {
755
+ group.appendChild(createFloorLine(projectGridPoint(originX + x, originY, layout), projectGridPoint(originX + x, originY + rows, layout)));
756
+ }
757
+ for (let y = 0; y <= rows; y++) {
758
+ group.appendChild(createFloorLine(projectGridPoint(originX, originY + y, layout), projectGridPoint(originX + columns, originY + y, layout)));
759
+ }
760
+ return group;
761
+ }
762
+ function createFloorLine(start, end) {
763
+ const line = document.createElementNS(NS, "line");
764
+ line.setAttribute("x1", String(start.x));
765
+ line.setAttribute("y1", String(start.y));
766
+ line.setAttribute("x2", String(end.x));
767
+ line.setAttribute("y2", String(end.y));
768
+ line.setAttribute("stroke", "#2563eb");
769
+ line.setAttribute("stroke-width", "1");
770
+ line.setAttribute("stroke-dasharray", "5 5");
771
+ line.setAttribute("stroke-opacity", "0.2");
772
+ return line;
773
+ }
774
+ function projectGridPoint(x, y, layout) {
775
+ const screen = projectToScreen(x, y, layout.cellSize, layout.selectedBounds.minX, layout.selectedBounds.minY, layout.padding.x, layout.padding.y);
776
+ return { x: screen.screenX, y: screen.screenY };
777
+ }
778
+ function pointToString(point) {
779
+ return `${point.x},${point.y}`;
780
+ }
781
+ function createLayerMap(layers) {
782
+ return new Map(layers.map((layer) => [layer.name, layer]));
783
+ }
784
+ function sortLayers(layers) {
785
+ return [...layers]
786
+ .map((layer, index) => ({ name: layer.name, order: layer.order ?? index }))
787
+ .sort((a, b) => a.order - b.order || a.name.localeCompare(b.name));
788
+ }
789
+ function sortElementsForPerspective(elements) {
790
+ return elements.slice().sort((a, b) => {
791
+ const bucket = renderBucket(a) - renderBucket(b);
792
+ if (bucket !== 0)
793
+ return bucket;
794
+ const depth = a.pos[0] + a.pos[1] - (b.pos[0] + b.pos[1]);
795
+ if (depth !== 0)
796
+ return depth;
797
+ return a.id.localeCompare(b.id);
798
+ });
799
+ }
800
+ function renderBucket(element) {
801
+ if (isPrimitiveAsset(element.asset))
802
+ return 0;
803
+ if (isTextAsset(element.asset))
804
+ return 2;
805
+ return 1;
806
+ }
807
+ function collectElementDefinitions(bundle) {
808
+ const byId = new Map();
809
+ for (const stop of bundle.scenes) {
810
+ for (const element of stop.elements ?? []) {
811
+ if (!byId.has(element.id) || byId.get(element.id)?.presence === "removed") {
812
+ byId.set(element.id, element);
813
+ }
814
+ }
815
+ }
816
+ return [...byId.values()];
817
+ }
818
+ function collectConnectorDefinitions(bundle) {
819
+ const byId = new Map();
820
+ for (const stop of bundle.scenes) {
821
+ for (const connector of stop.connectors ?? []) {
822
+ if (!byId.has(connector.id) || byId.get(connector.id)?.presence === "removed") {
823
+ byId.set(connector.id, connector);
824
+ }
825
+ }
826
+ }
827
+ return [...byId.values()];
828
+ }
829
+ /** Create a single element SVG instance applying entry animation. */
830
+ function createElementInstance(def, layout, resolveAsset) {
831
+ const node = def.asset === BUILT_IN_TEXT_ASSET_ID
832
+ ? createTextAssetNode(def.text, def.asset, layout.cellSize)
833
+ : isPrimitiveAsset(def.asset)
834
+ ? createPrimitiveAssetNode(def.asset, def.primitive, layout.cellSize)
835
+ : createResolvedAssetNode(def, resolveAsset, layout.cellSize);
836
+ node.classList.add("iso-element", `iso-element-${def.id}`);
837
+ node.setAttribute("data-id", def.id);
838
+ node.setAttribute("data-asset", def.asset);
839
+ node.style.overflow = "visible";
840
+ node.style.pointerEvents = "auto";
841
+ applyElementTransform(node, def, layout);
842
+ const entryAnim = def.enter;
843
+ if (entryAnim && entryAnim !== "none" && def.presence !== "removed") {
844
+ const keyName = `iso-anim-${entryAnim}`;
845
+ animateElement(node, keyName, "enter");
846
+ node.addEventListener("animationend", () => {
847
+ node.style.animation = "";
848
+ }, { once: true });
849
+ return { node, current: def, anchor: [0.5, 1], isHidden: false, entryKey: entryAnim, ambient: new Set() };
850
+ }
851
+ return { node, current: def, anchor: [0.5, 1], isHidden: false, ambient: new Set() };
852
+ }
853
+ function isTextAsset(assetId) {
854
+ return assetId === BUILT_IN_TEXT_ASSET_ID;
855
+ }
856
+ function isPrimitiveAsset(assetId) {
857
+ return BUILT_IN_PRIMITIVE_ASSET_IDS.has(assetId);
858
+ }
859
+ function createResolvedAssetNode(def, resolveAsset, cellSize) {
860
+ const asset = resolveAsset(def.asset);
861
+ if (!asset) {
862
+ throw new RenderError("ASSET_NOT_FOUND", `Asset not found: ${def.asset}`, {
863
+ asset: def.asset,
864
+ elementId: def.id,
865
+ });
866
+ }
867
+ return createAssetNode(asset, def.asset, cellSize);
868
+ }
869
+ function updateGeneratedElementContent(node, def, layout) {
870
+ if (!isTextAsset(def.asset) && !isPrimitiveAsset(def.asset))
871
+ return;
872
+ const replacement = isTextAsset(def.asset)
873
+ ? createTextAssetNode(def.text, def.asset, layout.cellSize)
874
+ : createPrimitiveAssetNode(def.asset, def.primitive, layout.cellSize);
875
+ clearChildren(node);
876
+ while (replacement.firstChild) {
877
+ const child = replacement.firstChild;
878
+ replacement.removeChild(child);
879
+ node.appendChild(child);
880
+ }
881
+ }
882
+ function createConnectorInstance(def, layout) {
883
+ const node = document.createElementNS(NS, "g");
884
+ const shaft = document.createElementNS(NS, "path");
885
+ const state = { node, shaft, isHidden: false, ambient: new Set() };
886
+ applyConnectorState(state, def, layout);
887
+ const entryAnim = def.enter;
888
+ if (entryAnim && entryAnim !== "none" && def.presence !== "removed") {
889
+ animateElement(node, `iso-anim-${entryAnim}`, "enter");
890
+ node.addEventListener("animationend", () => {
891
+ node.style.animation = "";
892
+ }, { once: true });
893
+ }
894
+ return state;
895
+ }
896
+ function applyConnectorState(state, def, layout) {
897
+ applyConnectorGroupAttrs(state.node, def);
898
+ clearChildren(state.node);
899
+ const d = routePath(def.route, layout);
900
+ if (shouldRenderOutline(def)) {
901
+ const outline = document.createElementNS(NS, "path");
902
+ outline.classList.add("iso-connector-outline");
903
+ applyConnectorPathAttrs(outline, def, d, {
904
+ stroke: def.style.outline ?? def.style.stroke,
905
+ strokeWidth: def.style.strokeWidth + def.style.outlineWidth * 2,
906
+ includeDash: false,
907
+ });
908
+ state.node.appendChild(outline);
909
+ }
910
+ state.shaft = document.createElementNS(NS, "path");
911
+ state.shaft.classList.add("iso-connector-shaft");
912
+ applyConnectorPathAttrs(state.shaft, def, d, {
913
+ stroke: def.style.stroke,
914
+ strokeWidth: def.style.strokeWidth,
915
+ includeDash: true,
916
+ });
917
+ state.node.appendChild(state.shaft);
918
+ if (def.style.variant === "road" && def.style.lane === "center-dashed") {
919
+ const lane = document.createElementNS(NS, "path");
920
+ lane.classList.add("iso-connector-lane");
921
+ applyConnectorPathAttrs(lane, def, d, {
922
+ stroke: "#ffffff",
923
+ strokeWidth: Math.max(1, def.style.strokeWidth * 0.12),
924
+ includeDash: false,
925
+ });
926
+ lane.setAttribute("stroke-dasharray", "8 8");
927
+ state.node.appendChild(lane);
928
+ }
929
+ appendEndpoint(state.node, def, "start", layout);
930
+ appendEndpoint(state.node, def, "end", layout);
931
+ applyConnectorAmbientClasses(state, def.ambient ?? []);
932
+ }
933
+ function clearChildren(node) {
934
+ while (node.firstChild)
935
+ node.removeChild(node.firstChild);
936
+ }
937
+ function applyConnectorGroupAttrs(node, def) {
938
+ node.setAttribute("class", [
939
+ "iso-connector",
940
+ `iso-connector-${def.id}`,
941
+ `iso-connector-variant-${def.style.variant}`,
942
+ `iso-connector-pattern-${def.style.pattern}`,
943
+ `iso-connector-direction-${def.direction}`,
944
+ `iso-layer-${def.layer}`,
945
+ ].join(" "));
946
+ node.setAttribute("data-id", def.id);
947
+ node.setAttribute("data-layer", def.layer);
948
+ node.style.overflow = "visible";
949
+ node.style.pointerEvents = "auto";
950
+ }
951
+ function shouldRenderOutline(def) {
952
+ return Boolean(def.style.outline && def.style.outlineWidth > 0);
953
+ }
954
+ function applyConnectorPathAttrs(path, def, d, options) {
955
+ path.setAttribute("d", d);
956
+ path.setAttribute("fill", "none");
957
+ path.setAttribute("stroke", options.stroke);
958
+ path.setAttribute("stroke-width", String(options.strokeWidth));
959
+ path.setAttribute("stroke-linecap", "round");
960
+ path.setAttribute("stroke-linejoin", "round");
961
+ path.setAttribute("opacity", String(def.style.opacity));
962
+ if (options.includeDash && def.style.pattern !== "solid") {
963
+ const dash = def.style.dash ?? DEFAULT_CONNECTOR_DASH[def.style.pattern];
964
+ path.setAttribute("stroke-dasharray", dash.join(" "));
965
+ }
966
+ }
967
+ function routePath(route, layout) {
968
+ return route
969
+ .map((point, index) => {
970
+ const projected = projectGridPoint(point[0], point[1], layout);
971
+ return `${index === 0 ? "M" : "L"} ${projected.x} ${projected.y}`;
972
+ })
973
+ .join(" ");
974
+ }
975
+ function appendEndpoint(group, def, kind, layout) {
976
+ const endpoint = def[kind];
977
+ if (endpoint === "none" || def.route.length < 2)
978
+ return;
979
+ const node = createEndpointNode(endpoint, def, kind, layout);
980
+ node.classList.add(`iso-connector-${kind}`);
981
+ group.appendChild(node);
982
+ }
983
+ function createEndpointNode(endpoint, def, kind, layout) {
984
+ switch (endpoint) {
985
+ case "arrow":
986
+ return createArrowEndpoint(def, kind, layout);
987
+ case "dot":
988
+ return createCircleEndpoint(def, kind, layout, true);
989
+ case "circle":
990
+ return createCircleEndpoint(def, kind, layout, false);
991
+ case "diamond":
992
+ return createDiamondEndpoint(def, kind, layout);
993
+ case "bar":
994
+ return createBarEndpoint(def, kind, layout);
995
+ case "none":
996
+ throw new RenderError("CONNECTOR_ENDPOINT_NONE", "Cannot create geometry for endpoint none");
997
+ }
998
+ }
999
+ function createArrowEndpoint(def, kind, layout) {
1000
+ const tip = endpointPoint(def, kind);
1001
+ const direction = endpointDirection(def, kind);
1002
+ const perpendicular = [-direction[1], direction[0]];
1003
+ const base = [tip[0] - direction[0] * ARROW_LENGTH_GRID, tip[1] - direction[1] * ARROW_LENGTH_GRID];
1004
+ const halfWidth = ARROW_WIDTH_GRID / 2;
1005
+ const points = [
1006
+ tip,
1007
+ [base[0] + perpendicular[0] * halfWidth, base[1] + perpendicular[1] * halfWidth],
1008
+ [base[0] - perpendicular[0] * halfWidth, base[1] - perpendicular[1] * halfWidth],
1009
+ ].map((point) => projectGridPoint(point[0], point[1], layout));
1010
+ const polygon = document.createElementNS(NS, "polygon");
1011
+ polygon.setAttribute("points", points.map(pointToString).join(" "));
1012
+ polygon.setAttribute("fill", def.style.stroke);
1013
+ polygon.setAttribute("opacity", String(def.style.opacity));
1014
+ return polygon;
1015
+ }
1016
+ function createCircleEndpoint(def, kind, layout, filled) {
1017
+ const point = endpointPoint(def, kind);
1018
+ const projected = projectGridPoint(point[0], point[1], layout);
1019
+ const circle = document.createElementNS(NS, "circle");
1020
+ circle.setAttribute("cx", String(projected.x));
1021
+ circle.setAttribute("cy", String(projected.y));
1022
+ circle.setAttribute("r", String(ENDPOINT_RADIUS_GRID * layout.cellSize));
1023
+ circle.setAttribute("stroke", def.style.stroke);
1024
+ circle.setAttribute("stroke-width", String(Math.max(1, def.style.strokeWidth)));
1025
+ circle.setAttribute("opacity", String(def.style.opacity));
1026
+ circle.setAttribute("fill", filled ? def.style.stroke : "none");
1027
+ return circle;
1028
+ }
1029
+ function createDiamondEndpoint(def, kind, layout) {
1030
+ const center = endpointPoint(def, kind);
1031
+ const radius = ENDPOINT_RADIUS_GRID;
1032
+ const points = [
1033
+ [center[0], center[1] - radius],
1034
+ [center[0] + radius, center[1]],
1035
+ [center[0], center[1] + radius],
1036
+ [center[0] - radius, center[1]],
1037
+ ];
1038
+ const polygon = document.createElementNS(NS, "polygon");
1039
+ polygon.setAttribute("points", points
1040
+ .map((point) => projectGridPoint(point[0], point[1], layout))
1041
+ .map(pointToString)
1042
+ .join(" "));
1043
+ polygon.setAttribute("fill", def.style.stroke);
1044
+ polygon.setAttribute("opacity", String(def.style.opacity));
1045
+ return polygon;
1046
+ }
1047
+ function createBarEndpoint(def, kind, layout) {
1048
+ const center = endpointPoint(def, kind);
1049
+ const direction = endpointDirection(def, kind);
1050
+ const perpendicular = [-direction[1], direction[0]];
1051
+ const half = BAR_WIDTH_GRID / 2;
1052
+ const a = projectGridPoint(center[0] + perpendicular[0] * half, center[1] + perpendicular[1] * half, layout);
1053
+ const b = projectGridPoint(center[0] - perpendicular[0] * half, center[1] - perpendicular[1] * half, layout);
1054
+ const line = document.createElementNS(NS, "line");
1055
+ line.setAttribute("x1", String(a.x));
1056
+ line.setAttribute("y1", String(a.y));
1057
+ line.setAttribute("x2", String(b.x));
1058
+ line.setAttribute("y2", String(b.y));
1059
+ line.setAttribute("stroke", def.style.stroke);
1060
+ line.setAttribute("stroke-width", String(Math.max(1, def.style.strokeWidth)));
1061
+ line.setAttribute("stroke-linecap", "round");
1062
+ line.setAttribute("opacity", String(def.style.opacity));
1063
+ return line;
1064
+ }
1065
+ function endpointPoint(def, kind) {
1066
+ return kind === "start" ? def.route[0] : def.route[def.route.length - 1];
1067
+ }
1068
+ function endpointDirection(def, kind) {
1069
+ const point = kind === "start"
1070
+ ? vectorBetween(def.route[0], def.route[1])
1071
+ : vectorBetween(def.route[def.route.length - 2], def.route[def.route.length - 1]);
1072
+ const effective = def.direction === "reverse" ? [-point[0], -point[1]] : point;
1073
+ return normalizeVector(effective);
1074
+ }
1075
+ function vectorBetween(start, end) {
1076
+ return [end[0] - start[0], end[1] - start[1]];
1077
+ }
1078
+ function normalizeVector(vector) {
1079
+ const length = Math.hypot(vector[0], vector[1]);
1080
+ if (length === 0)
1081
+ return [1, 0];
1082
+ return [vector[0] / length, vector[1] / length];
1083
+ }
1084
+ function applyElementTransform(node, def, layout) {
1085
+ const screen = projectToScreen(def.pos[0] + def.size, def.pos[1] + def.size, layout.cellSize, layout.selectedBounds.minX, layout.selectedBounds.minY, layout.padding.x, layout.padding.y);
1086
+ const visualSize = calculateVisualSize(def.size, layout.cellSize);
1087
+ const scale = visualSize / layout.cellSize;
1088
+ node.setAttribute("transform", `translate(${screen.screenX} ${screen.screenY}) scale(${scale})`);
1089
+ }
1090
+ function applyAmbientClasses(state, ambient) {
1091
+ const next = new Set((ambient ?? []).map((item) => item.name));
1092
+ for (const name of state.ambient) {
1093
+ if (!next.has(name))
1094
+ state.node.classList.remove(`iso-ambient-${name}`);
1095
+ }
1096
+ for (const name of next) {
1097
+ if (!state.ambient.has(name))
1098
+ state.node.classList.add(`iso-ambient-${name}`);
1099
+ }
1100
+ state.ambient = next;
1101
+ }
1102
+ function applyConnectorAmbientClasses(state, ambient) {
1103
+ const next = new Set((ambient ?? []).map((item) => item.name));
1104
+ for (const name of state.ambient) {
1105
+ if (!next.has(name))
1106
+ state.shaft.classList.remove(`iso-ambient-${name}`);
1107
+ }
1108
+ for (const name of next) {
1109
+ state.shaft.classList.add(`iso-ambient-${name}`);
1110
+ }
1111
+ state.ambient = next;
1112
+ }
1113
+ /** Apply a CSS keyframe animation to an element. */
1114
+ function animateElement(node, keyframeName, type = "enter") {
1115
+ node.style.opacity = "1";
1116
+ node.style.animation = "none";
1117
+ node.getBoundingClientRect();
1118
+ const duration = type === "exit" ? "var(--iso-anim-duration-exit, 300ms)" : "var(--iso-anim-duration-enter, 400ms)";
1119
+ const easing = type === "exit" ? "var(--iso-anim-easing-exit, ease-in)" : "var(--iso-anim-easing-enter, ease-out)";
1120
+ node.style.animation = `${keyframeName} ${duration} ${easing} forwards`;
1121
+ }
1122
+
1123
+ export { AssetRegistryImpl as A, DEFAULT_CELL_SIZE as D, animateElement as a, applySceneViewBox as b, applyThemeToElement as c, buildSceneDOM as d, calculateTransform as e, calculateVisualSize as f, composeTheme as g, createAssetRegistry as h, createDefaultRegistry as i, getConnectorState as j, getCurrentElementBounds as k, getElementState as l, getGridAreaBounds as m, getResolvedProjectionLayout as n, getResolvedViewBox as o, hideElementAfterExit as p, projectToRaw as q, projectToScreen as r, resolveTheme as s, updateElementTransforms as t, unhideElementOnReadd as u };
1124
+ //# sourceMappingURL=rendering-engine-BUUV3Qq-.js.map