@sebastianwessel/isostate 0.4.0 → 0.6.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.
- package/dist/animation/animation-engine.d.ts +3 -0
- package/dist/animation/animation-engine.d.ts.map +1 -1
- package/dist/animation/controller.d.ts +36 -2
- package/dist/animation/controller.d.ts.map +1 -1
- package/dist/assets/software-architecture/IMAGEGEN-PROMPTS.md +66 -0
- package/dist/assets/software-architecture/LICENSE +21 -0
- package/dist/assets/software-architecture/NOTICE.md +17 -0
- package/dist/assets/software-architecture/README.md +105 -0
- package/dist/assets/software-architecture/agentic/AGENT-VISUAL-PROMPTS.md +42 -0
- package/dist/assets/software-architecture/agentic/HANDOFF-PROMPTS.md +19 -0
- package/dist/assets/software-architecture/agentic/PROCESS-VISUAL-PROMPTS.md +109 -0
- package/dist/assets/software-architecture/agentic/agents-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/ai-capabilities-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/ai-to-human-handoff.png +0 -0
- package/dist/assets/software-architecture/agentic/channels-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/human-to-ai-handoff.png +0 -0
- package/dist/assets/software-architecture/agentic/humans-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/infrastructure-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/lifecycle-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/orchestration-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/providers-sprites.png +0 -0
- package/dist/assets/software-architecture/agentic/servicenow-sprites.png +0 -0
- package/dist/assets/software-architecture/architecture/architecture-sprites.png +0 -0
- package/dist/assets/software-architecture/manifest.json +2095 -0
- package/dist/assets/software-architecture/workflow/workflow-process-sprites.png +0 -0
- package/dist/browser/isostate.runtime.js +4 -4
- package/dist/browser/isostate.runtime.js.map +12 -10
- package/dist/chunks/errors-2yA81Vfb.js +23 -0
- package/dist/chunks/{errors-DyqEkrm5.js.map → errors-2yA81Vfb.js.map} +1 -1
- package/dist/chunks/index-WmsNtuaZ.js +1685 -0
- package/dist/chunks/index-WmsNtuaZ.js.map +1 -0
- package/dist/chunks/rendering-engine-DLaM1XbU.js +1425 -0
- package/dist/chunks/rendering-engine-DLaM1XbU.js.map +1 -0
- package/dist/chunks/scene-parser-BNXXIAqj.js +3033 -0
- package/dist/chunks/scene-parser-BNXXIAqj.js.map +1 -0
- package/dist/chunks/sha256-BkgWUdh1.js +123 -0
- package/dist/chunks/sha256-BkgWUdh1.js.map +1 -0
- package/dist/dsl/browser.js +3 -3
- package/dist/dsl/index.js +3 -3
- package/dist/dsl/scene-parser.d.ts.map +1 -1
- package/dist/dsl/scene-validator.d.ts.map +1 -1
- package/dist/dsl/workflow-effects-validation.d.ts +8 -0
- package/dist/dsl/workflow-effects-validation.d.ts.map +1 -0
- package/dist/editor-support/adapter.d.ts.map +1 -1
- package/dist/editor-support/index.js +347 -394
- package/dist/editor-support/index.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +438 -40
- package/dist/index.js.map +1 -1
- package/dist/rendering/animation-css.d.ts.map +1 -1
- package/dist/rendering/rendering-engine.d.ts +11 -0
- package/dist/rendering/rendering-engine.d.ts.map +1 -1
- package/dist/rendering/scene-effects.d.ts +15 -0
- package/dist/rendering/scene-effects.d.ts.map +1 -0
- package/dist/rendering/theme.d.ts +4 -0
- package/dist/rendering/theme.d.ts.map +1 -1
- package/dist/runtime/diagnostics-overlay.d.ts +29 -0
- package/dist/runtime/diagnostics-overlay.d.ts.map +1 -0
- package/dist/runtime/export.d.ts +27 -0
- package/dist/runtime/export.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +4 -4
- package/dist/runtime/interactivity.d.ts +56 -0
- package/dist/runtime/interactivity.d.ts.map +1 -0
- package/dist/runtime/mount-scene.d.ts +11 -10
- package/dist/runtime/mount-scene.d.ts.map +1 -1
- package/dist/types/asset-registry.d.ts +1 -0
- package/dist/types/asset-registry.d.ts.map +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/node.d.ts +54 -1
- package/dist/types/node.d.ts.map +1 -1
- package/dist/types/runtime-bundle.d.ts +35 -0
- package/dist/types/runtime-bundle.d.ts.map +1 -1
- package/dist/types/scene.d.ts +2 -0
- package/dist/types/scene.d.ts.map +1 -1
- package/package.json +9 -8
- package/dist/chunks/errors-DyqEkrm5.js +0 -29
- package/dist/chunks/index-C3qcXbPI.js +0 -1542
- package/dist/chunks/index-C3qcXbPI.js.map +0 -1
- package/dist/chunks/rendering-engine-BUUV3Qq-.js +0 -1124
- package/dist/chunks/rendering-engine-BUUV3Qq-.js.map +0 -1
- package/dist/chunks/scene-parser-B9SPDLYs.js +0 -2688
- package/dist/chunks/scene-parser-B9SPDLYs.js.map +0 -1
- package/dist/chunks/sha256-4JuurR-b.js +0 -69
- package/dist/chunks/sha256-4JuurR-b.js.map +0 -1
|
@@ -1,1542 +0,0 @@
|
|
|
1
|
-
import { o as getResolvedViewBox, k as getCurrentElementBounds, m as getGridAreaBounds, t as updateElementTransforms, b as applySceneViewBox, l as getElementState, u as unhideElementOnReadd, p as hideElementAfterExit, j as getConnectorState, a as animateElement, d as buildSceneDOM, s as resolveTheme } from './rendering-engine-BUUV3Qq-.js';
|
|
2
|
-
import { C as ControllerError, R as RenderError } from './errors-DyqEkrm5.js';
|
|
3
|
-
import { s as sha256 } from './sha256-4JuurR-b.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Animation engine — resolves progress against compiled RuntimeBundle scene stops.
|
|
7
|
-
*
|
|
8
|
-
* The engine does not manipulate DOM. It computes interpolation data and lifecycle
|
|
9
|
-
* transitions that the controller applies to the rendering engine.
|
|
10
|
-
*/
|
|
11
|
-
class AnimationEngine {
|
|
12
|
-
_bundle = null;
|
|
13
|
-
_progress = 0;
|
|
14
|
-
_paused = false;
|
|
15
|
-
_prevFrameMap = new Map();
|
|
16
|
-
_elementFrameMap = new Map();
|
|
17
|
-
_prevConnectorFrameMap = new Map();
|
|
18
|
-
_connectorFrameMap = new Map();
|
|
19
|
-
get bundle() {
|
|
20
|
-
return this._bundle;
|
|
21
|
-
}
|
|
22
|
-
get progress() {
|
|
23
|
-
return this._progress;
|
|
24
|
-
}
|
|
25
|
-
getProgress() {
|
|
26
|
-
return this._progress;
|
|
27
|
-
}
|
|
28
|
-
get paused() {
|
|
29
|
-
return this._paused;
|
|
30
|
-
}
|
|
31
|
-
isPaused() {
|
|
32
|
-
return this._paused;
|
|
33
|
-
}
|
|
34
|
-
get elementsCount() {
|
|
35
|
-
return this._elementFrameMap.size;
|
|
36
|
-
}
|
|
37
|
-
get connectorsCount() {
|
|
38
|
-
return this._connectorFrameMap.size;
|
|
39
|
-
}
|
|
40
|
-
/** Initialize with a compiled runtime bundle. */
|
|
41
|
-
init(bundle) {
|
|
42
|
-
this._bundle = bundle;
|
|
43
|
-
this._progress = 0;
|
|
44
|
-
this._paused = false;
|
|
45
|
-
this._prevFrameMap.clear();
|
|
46
|
-
this._elementFrameMap.clear();
|
|
47
|
-
this._prevConnectorFrameMap.clear();
|
|
48
|
-
this._connectorFrameMap.clear();
|
|
49
|
-
const initial = resolveFrameMap(bundle, 0);
|
|
50
|
-
this._elementFrameMap = initial;
|
|
51
|
-
this._prevFrameMap = cloneFrameMap(initial);
|
|
52
|
-
const initialConnectors = resolveConnectorFrameMap(bundle, 0);
|
|
53
|
-
this._connectorFrameMap = initialConnectors;
|
|
54
|
-
this._prevConnectorFrameMap = cloneConnectorFrameMap(initialConnectors);
|
|
55
|
-
}
|
|
56
|
-
/** Set current scroll progress (0-1) and compute frame update. */
|
|
57
|
-
setProgress(progress) {
|
|
58
|
-
const clamped = Math.max(0, Math.min(1, progress));
|
|
59
|
-
if (this._paused)
|
|
60
|
-
return;
|
|
61
|
-
this._progress = clamped;
|
|
62
|
-
if (!this._bundle)
|
|
63
|
-
return;
|
|
64
|
-
this._prevFrameMap = cloneFrameMap(this._elementFrameMap);
|
|
65
|
-
this._elementFrameMap = resolveFrameMap(this._bundle, clamped);
|
|
66
|
-
this._prevConnectorFrameMap = cloneConnectorFrameMap(this._connectorFrameMap);
|
|
67
|
-
this._connectorFrameMap = resolveConnectorFrameMap(this._bundle, clamped);
|
|
68
|
-
}
|
|
69
|
-
/** Get interpolated FrameUpdate for an element id or runtime element. */
|
|
70
|
-
getElementUpdate(element) {
|
|
71
|
-
const id = typeof element === "string" ? element : element.id;
|
|
72
|
-
const frame = this._elementFrameMap.get(id);
|
|
73
|
-
if (!frame) {
|
|
74
|
-
return {
|
|
75
|
-
id,
|
|
76
|
-
asset: "",
|
|
77
|
-
lifecycle: "removed",
|
|
78
|
-
ambient: [],
|
|
79
|
-
pos: [0, 0],
|
|
80
|
-
size: 1,
|
|
81
|
-
layer: "",
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return frameToUpdate(frame);
|
|
85
|
-
}
|
|
86
|
-
getFrameUpdates() {
|
|
87
|
-
return [...this._elementFrameMap.values()].map(frameToUpdate);
|
|
88
|
-
}
|
|
89
|
-
/** Get interpolated ConnectorFrameUpdate for a connector id or runtime connector. */
|
|
90
|
-
getConnectorUpdate(connector) {
|
|
91
|
-
const id = typeof connector === "string" ? connector : connector.id;
|
|
92
|
-
const frame = this._connectorFrameMap.get(id);
|
|
93
|
-
if (!frame)
|
|
94
|
-
return connectorFrameToUpdate(removedConnectorFrame(id));
|
|
95
|
-
return connectorFrameToUpdate(frame);
|
|
96
|
-
}
|
|
97
|
-
getConnectorFrameUpdates() {
|
|
98
|
-
return [...this._connectorFrameMap.values()].map(connectorFrameToUpdate);
|
|
99
|
-
}
|
|
100
|
-
/** Compute lifecycle transition between previous and current frame. */
|
|
101
|
-
getLifecycleTransition(elId) {
|
|
102
|
-
const prev = this._prevFrameMap.get(elId);
|
|
103
|
-
const current = this._elementFrameMap.get(elId);
|
|
104
|
-
const from = (prev?.lifecycle ?? "removed");
|
|
105
|
-
const to = (current?.lifecycle ?? "removed");
|
|
106
|
-
if (from === to)
|
|
107
|
-
return null;
|
|
108
|
-
return {
|
|
109
|
-
from,
|
|
110
|
-
to,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/** Compute lifecycle transition between previous and current connector frame. */
|
|
114
|
-
getConnectorLifecycleTransition(connectorId) {
|
|
115
|
-
const prev = this._prevConnectorFrameMap.get(connectorId);
|
|
116
|
-
const current = this._connectorFrameMap.get(connectorId);
|
|
117
|
-
const from = (prev?.lifecycle ?? "removed");
|
|
118
|
-
const to = (current?.lifecycle ?? "removed");
|
|
119
|
-
if (from === to)
|
|
120
|
-
return null;
|
|
121
|
-
return {
|
|
122
|
-
from,
|
|
123
|
-
to,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
getCurrentState() {
|
|
127
|
-
const bundle = this._bundle;
|
|
128
|
-
if (!bundle)
|
|
129
|
-
return null;
|
|
130
|
-
const pair = findSurroundingStops(bundle.scenes, this._progress);
|
|
131
|
-
return pair?.nextStop ?? bundle.scenes[0] ?? null;
|
|
132
|
-
}
|
|
133
|
-
pause() {
|
|
134
|
-
this._paused = true;
|
|
135
|
-
}
|
|
136
|
-
resume() {
|
|
137
|
-
this._paused = false;
|
|
138
|
-
}
|
|
139
|
-
destroy() {
|
|
140
|
-
this._bundle = null;
|
|
141
|
-
this._progress = 0;
|
|
142
|
-
this._paused = false;
|
|
143
|
-
this._elementFrameMap.clear();
|
|
144
|
-
this._prevFrameMap.clear();
|
|
145
|
-
this._connectorFrameMap.clear();
|
|
146
|
-
this._prevConnectorFrameMap.clear();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// ── Interpolation helpers ──────────────────────────────────────────────────
|
|
150
|
-
function resolveFrameMap(bundle, progress) {
|
|
151
|
-
const pair = findSurroundingStops(bundle.scenes, progress);
|
|
152
|
-
const result = new Map();
|
|
153
|
-
if (!pair)
|
|
154
|
-
return result;
|
|
155
|
-
const ids = new Set();
|
|
156
|
-
for (const stop of bundle.scenes) {
|
|
157
|
-
for (const element of stop.elements ?? [])
|
|
158
|
-
ids.add(element.id);
|
|
159
|
-
}
|
|
160
|
-
for (const element of pair.prevStop.elements ?? [])
|
|
161
|
-
ids.add(element.id);
|
|
162
|
-
for (const element of pair.nextStop.elements ?? [])
|
|
163
|
-
ids.add(element.id);
|
|
164
|
-
for (const id of ids) {
|
|
165
|
-
const frame = withRemovedElementGeometry(interpolateElement(id, pair.prevStop, pair.nextStop, pair.t), bundle.scenes, id, progress);
|
|
166
|
-
result.set(id, frame);
|
|
167
|
-
}
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
|
-
function resolveConnectorFrameMap(bundle, progress) {
|
|
171
|
-
const pair = findSurroundingStops(bundle.scenes, progress);
|
|
172
|
-
const result = new Map();
|
|
173
|
-
if (!pair)
|
|
174
|
-
return result;
|
|
175
|
-
const ids = new Set();
|
|
176
|
-
for (const stop of bundle.scenes) {
|
|
177
|
-
for (const connector of stop.connectors ?? [])
|
|
178
|
-
ids.add(connector.id);
|
|
179
|
-
}
|
|
180
|
-
for (const connector of pair.prevStop.connectors ?? [])
|
|
181
|
-
ids.add(connector.id);
|
|
182
|
-
for (const connector of pair.nextStop.connectors ?? [])
|
|
183
|
-
ids.add(connector.id);
|
|
184
|
-
for (const id of ids) {
|
|
185
|
-
const frame = interpolateConnector(id, pair.prevStop, pair.nextStop, pair.t);
|
|
186
|
-
result.set(id, frame);
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
function findSurroundingStops(stops, progress) {
|
|
191
|
-
if (stops.length === 0)
|
|
192
|
-
return null;
|
|
193
|
-
const sorted = [...stops].sort((a, b) => a.progress - b.progress);
|
|
194
|
-
if (sorted.length === 1 || progress <= sorted[0].progress) {
|
|
195
|
-
return { prevStop: sorted[0], nextStop: sorted[0], t: 0, nextIndex: 0 };
|
|
196
|
-
}
|
|
197
|
-
const lastIndex = sorted.length - 1;
|
|
198
|
-
if (progress >= sorted[lastIndex].progress) {
|
|
199
|
-
return {
|
|
200
|
-
prevStop: sorted[lastIndex - 1] ?? sorted[lastIndex],
|
|
201
|
-
nextStop: sorted[lastIndex],
|
|
202
|
-
t: 1,
|
|
203
|
-
nextIndex: lastIndex,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
207
|
-
const nextStop = sorted[i];
|
|
208
|
-
if (nextStop.progress >= progress) {
|
|
209
|
-
const prevStop = sorted[i - 1];
|
|
210
|
-
const range = nextStop.progress - prevStop.progress;
|
|
211
|
-
const t = range > 0 ? (progress - prevStop.progress) / range : 0;
|
|
212
|
-
return { prevStop, nextStop, t, nextIndex: i };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
function interpolateElement(id, prevStop, nextStop, t) {
|
|
218
|
-
const prev = findElement(prevStop, id);
|
|
219
|
-
const next = findElement(nextStop, id);
|
|
220
|
-
const source = next ?? prev;
|
|
221
|
-
if (!source) {
|
|
222
|
-
return removedFrame(id);
|
|
223
|
-
}
|
|
224
|
-
if (!prev || prev.presence === "removed") {
|
|
225
|
-
return frameFromElement(source, source.presence === "removed" || t < 1 ? "removed" : source.presence);
|
|
226
|
-
}
|
|
227
|
-
if (!next || next.presence === "removed") {
|
|
228
|
-
return frameFromElement(prev, t < 1 ? prev.presence : "removed");
|
|
229
|
-
}
|
|
230
|
-
const lifecycle = t < 1 ? prev.presence : next.presence;
|
|
231
|
-
return {
|
|
232
|
-
id,
|
|
233
|
-
asset: next.asset,
|
|
234
|
-
pos: interpolatePos(prev.pos, next.pos, t),
|
|
235
|
-
size: prev.size + (next.size - prev.size) * t,
|
|
236
|
-
lifecycle,
|
|
237
|
-
ambient: cloneAmbient(next.ambient),
|
|
238
|
-
layer: t < 1 ? prev.layer : next.layer,
|
|
239
|
-
entry: next.enter ?? prev.enter,
|
|
240
|
-
exit: next.exit ?? prev.exit,
|
|
241
|
-
text: cloneText(next.text ?? prev.text),
|
|
242
|
-
primitive: clonePrimitive(next.primitive ?? prev.primitive),
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function interpolateConnector(id, prevStop, nextStop, t) {
|
|
246
|
-
const prev = findConnector(prevStop, id);
|
|
247
|
-
const next = findConnector(nextStop, id);
|
|
248
|
-
const source = next ?? prev;
|
|
249
|
-
if (!source)
|
|
250
|
-
return removedConnectorFrame(id);
|
|
251
|
-
if (!prev || prev.presence === "removed") {
|
|
252
|
-
return frameFromConnector(source, source.presence === "removed" || t < 1 ? "removed" : source.presence);
|
|
253
|
-
}
|
|
254
|
-
if (!next || next.presence === "removed") {
|
|
255
|
-
return frameFromConnector(prev, t < 1 ? prev.presence : "removed");
|
|
256
|
-
}
|
|
257
|
-
const lifecycle = t < 1 ? prev.presence : next.presence;
|
|
258
|
-
return {
|
|
259
|
-
id,
|
|
260
|
-
route: interpolateRoute(prev.route, next.route, t),
|
|
261
|
-
layer: t < 1 ? prev.layer : next.layer,
|
|
262
|
-
lifecycle,
|
|
263
|
-
style: cloneConnectorStyle(t < 1 ? prev.style : next.style),
|
|
264
|
-
start: next.start,
|
|
265
|
-
end: next.end,
|
|
266
|
-
direction: next.direction,
|
|
267
|
-
ambient: cloneAmbient(next.ambient),
|
|
268
|
-
entry: next.enter ?? prev.enter,
|
|
269
|
-
exit: next.exit ?? prev.exit,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function findElement(stop, id) {
|
|
273
|
-
return (stop.elements ?? []).find((element) => element.id === id);
|
|
274
|
-
}
|
|
275
|
-
function findConnector(stop, id) {
|
|
276
|
-
return (stop.connectors ?? []).find((connector) => connector.id === id);
|
|
277
|
-
}
|
|
278
|
-
function withRemovedElementGeometry(frame, stops, id, progress) {
|
|
279
|
-
if (frame.lifecycle !== "removed")
|
|
280
|
-
return frame;
|
|
281
|
-
const reference = findNearestElementGeometry(stops, id, progress);
|
|
282
|
-
if (!reference)
|
|
283
|
-
return frame;
|
|
284
|
-
return {
|
|
285
|
-
...frame,
|
|
286
|
-
asset: reference.asset,
|
|
287
|
-
pos: [...reference.pos],
|
|
288
|
-
size: reference.size,
|
|
289
|
-
ambient: cloneAmbient(reference.ambient),
|
|
290
|
-
layer: reference.layer,
|
|
291
|
-
entry: reference.enter,
|
|
292
|
-
exit: reference.exit,
|
|
293
|
-
text: cloneText(reference.text),
|
|
294
|
-
primitive: clonePrimitive(reference.primitive),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function findNearestElementGeometry(stops, id, progress) {
|
|
298
|
-
const sorted = [...stops].sort((a, b) => a.progress - b.progress);
|
|
299
|
-
const next = sorted
|
|
300
|
-
.filter((stop) => stop.progress >= progress)
|
|
301
|
-
.flatMap((stop) => stop.elements ?? [])
|
|
302
|
-
.find((element) => element.id === id && element.presence !== "removed");
|
|
303
|
-
if (next)
|
|
304
|
-
return next;
|
|
305
|
-
for (let index = sorted.length - 1; index >= 0; index -= 1) {
|
|
306
|
-
if (sorted[index].progress > progress)
|
|
307
|
-
continue;
|
|
308
|
-
const previous = (sorted[index].elements ?? []).find((element) => element.id === id && element.presence !== "removed");
|
|
309
|
-
if (previous)
|
|
310
|
-
return previous;
|
|
311
|
-
}
|
|
312
|
-
return undefined;
|
|
313
|
-
}
|
|
314
|
-
function frameFromElement(element, lifecycle = element.presence) {
|
|
315
|
-
return {
|
|
316
|
-
id: element.id,
|
|
317
|
-
asset: element.asset,
|
|
318
|
-
pos: [...element.pos],
|
|
319
|
-
size: element.size,
|
|
320
|
-
lifecycle,
|
|
321
|
-
ambient: cloneAmbient(element.ambient),
|
|
322
|
-
layer: element.layer,
|
|
323
|
-
entry: element.enter,
|
|
324
|
-
exit: element.exit,
|
|
325
|
-
text: cloneText(element.text),
|
|
326
|
-
primitive: clonePrimitive(element.primitive),
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function frameFromConnector(connector, lifecycle = connector.presence) {
|
|
330
|
-
return {
|
|
331
|
-
id: connector.id,
|
|
332
|
-
route: cloneRoute(connector.route),
|
|
333
|
-
layer: connector.layer,
|
|
334
|
-
lifecycle,
|
|
335
|
-
style: cloneConnectorStyle(connector.style),
|
|
336
|
-
start: connector.start,
|
|
337
|
-
end: connector.end,
|
|
338
|
-
direction: connector.direction,
|
|
339
|
-
ambient: cloneAmbient(connector.ambient),
|
|
340
|
-
entry: connector.enter,
|
|
341
|
-
exit: connector.exit,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
function removedFrame(id) {
|
|
345
|
-
return {
|
|
346
|
-
id,
|
|
347
|
-
asset: "",
|
|
348
|
-
pos: [0, 0],
|
|
349
|
-
size: 1,
|
|
350
|
-
lifecycle: "removed",
|
|
351
|
-
ambient: [],
|
|
352
|
-
layer: "",
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function removedConnectorFrame(id) {
|
|
356
|
-
return {
|
|
357
|
-
id,
|
|
358
|
-
route: [],
|
|
359
|
-
layer: "",
|
|
360
|
-
lifecycle: "removed",
|
|
361
|
-
style: {
|
|
362
|
-
variant: "line",
|
|
363
|
-
pattern: "solid",
|
|
364
|
-
stroke: "#2563eb",
|
|
365
|
-
strokeWidth: 3,
|
|
366
|
-
opacity: 1,
|
|
367
|
-
outlineWidth: 0,
|
|
368
|
-
lane: "none",
|
|
369
|
-
},
|
|
370
|
-
start: "none",
|
|
371
|
-
end: "none",
|
|
372
|
-
direction: "route",
|
|
373
|
-
ambient: [],
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function interpolatePos(prev, next, t) {
|
|
377
|
-
return [prev[0] + (next[0] - prev[0]) * t, prev[1] + (next[1] - prev[1]) * t];
|
|
378
|
-
}
|
|
379
|
-
function interpolateRoute(prev, next, t) {
|
|
380
|
-
if (prev.length !== next.length)
|
|
381
|
-
return cloneRoute(t < 1 ? prev : next);
|
|
382
|
-
return prev.map((point, index) => interpolatePos(point, next[index], t));
|
|
383
|
-
}
|
|
384
|
-
function cloneRoute(route) {
|
|
385
|
-
return route.map((point) => [point[0], point[1]]);
|
|
386
|
-
}
|
|
387
|
-
function cloneConnectorStyle(style) {
|
|
388
|
-
return {
|
|
389
|
-
...style,
|
|
390
|
-
...(style.dash ? { dash: [...style.dash] } : {}),
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
function cloneAmbient(ambient) {
|
|
394
|
-
return (ambient ?? []).map((item) => ({ ...item }));
|
|
395
|
-
}
|
|
396
|
-
function frameToUpdate(frame) {
|
|
397
|
-
return {
|
|
398
|
-
id: frame.id,
|
|
399
|
-
asset: frame.asset,
|
|
400
|
-
lifecycle: frame.lifecycle,
|
|
401
|
-
ambient: cloneAmbient(frame.ambient),
|
|
402
|
-
pos: [...frame.pos],
|
|
403
|
-
size: frame.size,
|
|
404
|
-
layer: frame.layer,
|
|
405
|
-
entry: frame.entry,
|
|
406
|
-
exit: frame.exit,
|
|
407
|
-
text: cloneText(frame.text),
|
|
408
|
-
primitive: clonePrimitive(frame.primitive),
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function connectorFrameToUpdate(frame) {
|
|
412
|
-
return {
|
|
413
|
-
id: frame.id,
|
|
414
|
-
route: cloneRoute(frame.route),
|
|
415
|
-
layer: frame.layer,
|
|
416
|
-
lifecycle: frame.lifecycle,
|
|
417
|
-
style: cloneConnectorStyle(frame.style),
|
|
418
|
-
start: frame.start,
|
|
419
|
-
end: frame.end,
|
|
420
|
-
direction: frame.direction,
|
|
421
|
-
ambient: cloneAmbient(frame.ambient),
|
|
422
|
-
entry: frame.entry,
|
|
423
|
-
exit: frame.exit,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function cloneFrameMap(map) {
|
|
427
|
-
const clone = new Map();
|
|
428
|
-
for (const [id, frame] of map) {
|
|
429
|
-
clone.set(id, {
|
|
430
|
-
...frame,
|
|
431
|
-
pos: [...frame.pos],
|
|
432
|
-
ambient: cloneAmbient(frame.ambient),
|
|
433
|
-
text: cloneText(frame.text),
|
|
434
|
-
primitive: clonePrimitive(frame.primitive),
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return clone;
|
|
438
|
-
}
|
|
439
|
-
function cloneText(text) {
|
|
440
|
-
return text ? { ...text } : undefined;
|
|
441
|
-
}
|
|
442
|
-
function clonePrimitive(primitive) {
|
|
443
|
-
if (!primitive)
|
|
444
|
-
return undefined;
|
|
445
|
-
return {
|
|
446
|
-
...(primitive.rectangle
|
|
447
|
-
? {
|
|
448
|
-
rectangle: {
|
|
449
|
-
...primitive.rectangle,
|
|
450
|
-
dash: cloneDash(primitive.rectangle.dash),
|
|
451
|
-
},
|
|
452
|
-
}
|
|
453
|
-
: {}),
|
|
454
|
-
...(primitive.circle
|
|
455
|
-
? {
|
|
456
|
-
circle: {
|
|
457
|
-
...primitive.circle,
|
|
458
|
-
dash: cloneDash(primitive.circle.dash),
|
|
459
|
-
},
|
|
460
|
-
}
|
|
461
|
-
: {}),
|
|
462
|
-
...(primitive.polygon
|
|
463
|
-
? {
|
|
464
|
-
polygon: {
|
|
465
|
-
...primitive.polygon,
|
|
466
|
-
dash: cloneDash(primitive.polygon.dash),
|
|
467
|
-
points: cloneRoute(primitive.polygon.points),
|
|
468
|
-
},
|
|
469
|
-
}
|
|
470
|
-
: {}),
|
|
471
|
-
...(primitive.line
|
|
472
|
-
? {
|
|
473
|
-
line: {
|
|
474
|
-
...primitive.line,
|
|
475
|
-
dash: cloneDash(primitive.line.dash),
|
|
476
|
-
points: cloneRoute(primitive.line.points),
|
|
477
|
-
},
|
|
478
|
-
}
|
|
479
|
-
: {}),
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
function cloneDash(dash) {
|
|
483
|
-
return dash ? [dash[0], dash[1]] : undefined;
|
|
484
|
-
}
|
|
485
|
-
function cloneConnectorFrameMap(map) {
|
|
486
|
-
const clone = new Map();
|
|
487
|
-
for (const [id, frame] of map) {
|
|
488
|
-
clone.set(id, {
|
|
489
|
-
...frame,
|
|
490
|
-
route: cloneRoute(frame.route),
|
|
491
|
-
style: cloneConnectorStyle(frame.style),
|
|
492
|
-
ambient: cloneAmbient(frame.ambient),
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
return clone;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Linear easing (no interpolation).
|
|
500
|
-
*/
|
|
501
|
-
function linear(t) {
|
|
502
|
-
return t;
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Cubic ease-in: starts slowly, accelerates.
|
|
506
|
-
*/
|
|
507
|
-
function easeInCubic(t) {
|
|
508
|
-
return t * t * t;
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Cubic ease-out: starts fast, decelerates.
|
|
512
|
-
*/
|
|
513
|
-
function easeOutCubic(t) {
|
|
514
|
-
return 1 - (1 - t) ** 3;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Cubic ease-in-out: slow start, fast middle, slow end.
|
|
518
|
-
*/
|
|
519
|
-
function easeInOutCubic(t) {
|
|
520
|
-
return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Resolve an easing type string to a function.
|
|
524
|
-
*/
|
|
525
|
-
function resolveEasing(type) {
|
|
526
|
-
switch (type) {
|
|
527
|
-
case "linear":
|
|
528
|
-
return linear;
|
|
529
|
-
case "easeInCubic":
|
|
530
|
-
return easeInCubic;
|
|
531
|
-
case "easeOutCubic":
|
|
532
|
-
return easeOutCubic;
|
|
533
|
-
case "easeInOutCubic":
|
|
534
|
-
return easeInOutCubic;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
const DEFAULT_CONFIG = {
|
|
539
|
-
scrollDirection: "vertical",
|
|
540
|
-
scrollOffset: {},
|
|
541
|
-
minProgress: 0,
|
|
542
|
-
maxProgress: 1,
|
|
543
|
-
keyboardControls: false,
|
|
544
|
-
touchControls: false,
|
|
545
|
-
scrollSensitivity: 1.0,
|
|
546
|
-
transitionDuration: 600,
|
|
547
|
-
transitionEasing: "ease-in-out",
|
|
548
|
-
};
|
|
549
|
-
// ── Controller implementation ──────────────────────────────────────────────
|
|
550
|
-
/**
|
|
551
|
-
* Animation controller — manages scroll progress, scene navigation,
|
|
552
|
-
* and delegates to the animation engine for frame updates.
|
|
553
|
-
*/
|
|
554
|
-
class AnimationController {
|
|
555
|
-
_engine = new AnimationEngine();
|
|
556
|
-
_bundle = null;
|
|
557
|
-
_sceneIndex = 0;
|
|
558
|
-
_progress = 0;
|
|
559
|
-
_paused = false;
|
|
560
|
-
_config = DEFAULT_CONFIG;
|
|
561
|
-
_container = null;
|
|
562
|
-
_sceneElement = null;
|
|
563
|
-
_ownsEngine = true;
|
|
564
|
-
_rafId = null;
|
|
565
|
-
_pendingProgress = null;
|
|
566
|
-
_destroyed = false;
|
|
567
|
-
_listeners = new Map();
|
|
568
|
-
_cameraAnim = null;
|
|
569
|
-
_cameraState = null;
|
|
570
|
-
// Scroll tracking state
|
|
571
|
-
_minScroll = 0;
|
|
572
|
-
_maxScroll = 0;
|
|
573
|
-
_touchStartY = 0;
|
|
574
|
-
_touchStartX = 0;
|
|
575
|
-
_isDragging = false;
|
|
576
|
-
// Transition animation state
|
|
577
|
-
_transitionAnim = null;
|
|
578
|
-
get engine() {
|
|
579
|
-
return this._engine;
|
|
580
|
-
}
|
|
581
|
-
get progress() {
|
|
582
|
-
return this._progress;
|
|
583
|
-
}
|
|
584
|
-
getProgress() {
|
|
585
|
-
this._assertNotDestroyed();
|
|
586
|
-
return this._progress;
|
|
587
|
-
}
|
|
588
|
-
get sceneIndex() {
|
|
589
|
-
return this._sceneIndex;
|
|
590
|
-
}
|
|
591
|
-
getSceneIndex() {
|
|
592
|
-
this._assertNotDestroyed();
|
|
593
|
-
return this._sceneIndex;
|
|
594
|
-
}
|
|
595
|
-
get scenes() {
|
|
596
|
-
return this._bundle?.scenes ?? [];
|
|
597
|
-
}
|
|
598
|
-
get paused() {
|
|
599
|
-
return this._paused;
|
|
600
|
-
}
|
|
601
|
-
get currentScene() {
|
|
602
|
-
return this.scenes[this._sceneIndex];
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Initialize the controller with a compiled bundle and optional runtime resources.
|
|
606
|
-
*/
|
|
607
|
-
init(bundle, config = {}, runtime = {}) {
|
|
608
|
-
this._assertNotDestroyed();
|
|
609
|
-
if (!bundle.scenes || bundle.scenes.length === 0) {
|
|
610
|
-
throw new ControllerError("CONTROLLER_NO_SCENES", "init() requires at least one compiled scene stop");
|
|
611
|
-
}
|
|
612
|
-
this._cancelFrame();
|
|
613
|
-
this._bundle = bundle;
|
|
614
|
-
this._engine = runtime.engine ?? new AnimationEngine();
|
|
615
|
-
this._ownsEngine = !runtime.engine;
|
|
616
|
-
this._sceneIndex = 0;
|
|
617
|
-
this._progress = 0;
|
|
618
|
-
this._paused = false;
|
|
619
|
-
this._config = { ...DEFAULT_CONFIG, ...config };
|
|
620
|
-
this._sceneElement = runtime.sceneElement ?? config.sceneElement ?? null;
|
|
621
|
-
this._cameraState = {
|
|
622
|
-
viewBox: getResolvedViewBox(bundle),
|
|
623
|
-
target: { type: "reset" },
|
|
624
|
-
isZoomed: false,
|
|
625
|
-
};
|
|
626
|
-
this._engine.init(bundle);
|
|
627
|
-
this._bindScroll();
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Set scroll progress (0–1, clamped) and trigger frame update.
|
|
631
|
-
*/
|
|
632
|
-
setProgress(progress) {
|
|
633
|
-
this._assertNotDestroyed();
|
|
634
|
-
if (!Number.isFinite(progress)) {
|
|
635
|
-
throw new ControllerError("CONTROLLER_PROGRESS_OUT_OF_RANGE", "setProgress() requires a finite progress value");
|
|
636
|
-
}
|
|
637
|
-
const clamped = Math.max(0, Math.min(1, progress));
|
|
638
|
-
if (clamped === this._progress && !this._paused && this._rafId !== null) {
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
this._progress = clamped;
|
|
642
|
-
this._cancelCameraAnimation();
|
|
643
|
-
if (this._paused)
|
|
644
|
-
return;
|
|
645
|
-
this._scheduleProgressForward(clamped);
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Navigate to next scene (wraps to 0 if at end).
|
|
649
|
-
*/
|
|
650
|
-
nextScene() {
|
|
651
|
-
this._assertNotDestroyed();
|
|
652
|
-
if (this.scenes.length <= 1)
|
|
653
|
-
return;
|
|
654
|
-
const nextIndex = (this._sceneIndex + 1) % this.scenes.length;
|
|
655
|
-
this._transitionToScene(nextIndex);
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* Navigate to previous scene (wraps to last if at beginning).
|
|
659
|
-
*/
|
|
660
|
-
prevScene() {
|
|
661
|
-
this._assertNotDestroyed();
|
|
662
|
-
if (this.scenes.length <= 1)
|
|
663
|
-
return;
|
|
664
|
-
const prevIndex = (this._sceneIndex - 1 + this.scenes.length) % this.scenes.length;
|
|
665
|
-
this._transitionToScene(prevIndex);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Set scene index directly.
|
|
669
|
-
*/
|
|
670
|
-
setSceneIndex(index) {
|
|
671
|
-
this._assertNotDestroyed();
|
|
672
|
-
if (index < 0 || index >= this.scenes.length) {
|
|
673
|
-
throw new ControllerError("CONTROLLER_SCENE_INDEX_OUT_OF_RANGE", `Scene index ${index} is out of bounds [0, ${this.scenes.length - 1}]`);
|
|
674
|
-
}
|
|
675
|
-
this._transitionToScene(index);
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Pause all animations.
|
|
679
|
-
*/
|
|
680
|
-
pause() {
|
|
681
|
-
this._assertNotDestroyed();
|
|
682
|
-
if (this._paused)
|
|
683
|
-
return;
|
|
684
|
-
this._paused = true;
|
|
685
|
-
this._cancelFrame();
|
|
686
|
-
this._engine.pause();
|
|
687
|
-
this._applyPauseState(true);
|
|
688
|
-
this._emit("paused");
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Resume from paused state.
|
|
692
|
-
*/
|
|
693
|
-
resume() {
|
|
694
|
-
this._assertNotDestroyed();
|
|
695
|
-
if (!this._paused)
|
|
696
|
-
return;
|
|
697
|
-
this._paused = false;
|
|
698
|
-
this._engine.resume();
|
|
699
|
-
this._applyPauseState(false);
|
|
700
|
-
this._scheduleProgressForward(this._progress);
|
|
701
|
-
this._emit("resumed");
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Check if controller is paused.
|
|
705
|
-
*/
|
|
706
|
-
isPaused() {
|
|
707
|
-
this._assertNotDestroyed();
|
|
708
|
-
return this._paused;
|
|
709
|
-
}
|
|
710
|
-
zoomToElement(id, options = {}) {
|
|
711
|
-
this._assertNotDestroyed();
|
|
712
|
-
const svg = this._getSceneSvg();
|
|
713
|
-
if (!this._bundle || !svg) {
|
|
714
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "zoomToElement() requires an initialized scene SVG");
|
|
715
|
-
}
|
|
716
|
-
const elementBounds = getCurrentElementBounds(svg, id);
|
|
717
|
-
if (!elementBounds) {
|
|
718
|
-
throw new ControllerError("CAMERA_TARGET_NOT_FOUND", `Camera target element "${id}" was not found`, {
|
|
719
|
-
elementId: id,
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
this._applyCameraDestination(expandViewBox(elementBounds, this._resolveCameraPadding(options)), { type: "element", id }, options);
|
|
723
|
-
}
|
|
724
|
-
zoomToArea(area, options = {}) {
|
|
725
|
-
this._assertNotDestroyed();
|
|
726
|
-
if (!this._bundle || !this._getSceneSvg()) {
|
|
727
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "zoomToArea() requires an initialized scene SVG");
|
|
728
|
-
}
|
|
729
|
-
this._assertValidCameraArea(area);
|
|
730
|
-
const bounds = getGridAreaBounds(this._bundle, area);
|
|
731
|
-
this._applyCameraDestination(expandViewBox(bounds, this._resolveCameraPadding(options)), {
|
|
732
|
-
type: "area",
|
|
733
|
-
at: [...area.at],
|
|
734
|
-
size: [...area.size],
|
|
735
|
-
}, options);
|
|
736
|
-
}
|
|
737
|
-
resetZoom(options = {}) {
|
|
738
|
-
this._assertNotDestroyed();
|
|
739
|
-
if (!this._bundle || !this._getSceneSvg()) {
|
|
740
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "resetZoom() requires an initialized scene SVG");
|
|
741
|
-
}
|
|
742
|
-
this._applyCameraDestination(getResolvedViewBox(this._bundle), { type: "reset" }, options);
|
|
743
|
-
}
|
|
744
|
-
getCameraState() {
|
|
745
|
-
this._assertNotDestroyed();
|
|
746
|
-
if (!this._cameraState) {
|
|
747
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "Camera state is not initialized");
|
|
748
|
-
}
|
|
749
|
-
return copyCameraState(this._cameraState);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Destroy controller and clean up all listeners and resources.
|
|
753
|
-
*/
|
|
754
|
-
destroy() {
|
|
755
|
-
this._assertNotDestroyed();
|
|
756
|
-
this._unbindScroll();
|
|
757
|
-
this._cancelFrame();
|
|
758
|
-
this._cancelTransition();
|
|
759
|
-
this._cancelCameraAnimation();
|
|
760
|
-
if (this._ownsEngine)
|
|
761
|
-
this._engine.destroy();
|
|
762
|
-
this._listeners.clear();
|
|
763
|
-
this._bundle = null;
|
|
764
|
-
this._container = null;
|
|
765
|
-
this._pendingProgress = null;
|
|
766
|
-
this._cameraState = null;
|
|
767
|
-
this._destroyed = true;
|
|
768
|
-
}
|
|
769
|
-
// ── Event system ───────────────────────────────────────────────────────
|
|
770
|
-
on(event, listener) {
|
|
771
|
-
this._assertNotDestroyed();
|
|
772
|
-
const set = this._listeners.get(event) ?? new Set();
|
|
773
|
-
set.add(listener);
|
|
774
|
-
this._listeners.set(event, set);
|
|
775
|
-
}
|
|
776
|
-
off(event, listener) {
|
|
777
|
-
this._assertNotDestroyed();
|
|
778
|
-
const set = this._listeners.get(event);
|
|
779
|
-
if (set) {
|
|
780
|
-
set.delete(listener);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
_emit(event, ...args) {
|
|
784
|
-
const set = this._listeners.get(event);
|
|
785
|
-
if (set) {
|
|
786
|
-
for (const listener of set) {
|
|
787
|
-
try {
|
|
788
|
-
listener(...args);
|
|
789
|
-
}
|
|
790
|
-
catch (error) {
|
|
791
|
-
queueMicrotask(() => {
|
|
792
|
-
throw error;
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
// ── Frame update ───────────────────────────────────────────────────────
|
|
799
|
-
_scheduleProgressForward(progress) {
|
|
800
|
-
this._pendingProgress = progress;
|
|
801
|
-
if (this._rafId !== null)
|
|
802
|
-
return;
|
|
803
|
-
this._rafId = requestAnimationFrame(() => {
|
|
804
|
-
this._rafId = null;
|
|
805
|
-
const pending = this._pendingProgress;
|
|
806
|
-
this._pendingProgress = null;
|
|
807
|
-
if (pending === null || this._paused || this._destroyed)
|
|
808
|
-
return;
|
|
809
|
-
this._engine.setProgress(pending);
|
|
810
|
-
this._applyFrameUpdate();
|
|
811
|
-
this._emit("progress-change", pending);
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
_cancelFrame() {
|
|
815
|
-
if (this._rafId !== null) {
|
|
816
|
-
cancelAnimationFrame(this._rafId);
|
|
817
|
-
this._rafId = null;
|
|
818
|
-
}
|
|
819
|
-
this._pendingProgress = null;
|
|
820
|
-
}
|
|
821
|
-
_applyFrameUpdate() {
|
|
822
|
-
if (!this._bundle)
|
|
823
|
-
return;
|
|
824
|
-
const svg = (this._sceneElement ?? this._container?.querySelector("svg") ?? null);
|
|
825
|
-
if (!svg)
|
|
826
|
-
return;
|
|
827
|
-
const updates = this._engine.getFrameUpdates().map((update) => ({
|
|
828
|
-
id: update.id,
|
|
829
|
-
asset: update.asset,
|
|
830
|
-
pos: update.pos,
|
|
831
|
-
size: update.size,
|
|
832
|
-
layer: update.layer,
|
|
833
|
-
presence: update.lifecycle,
|
|
834
|
-
enter: update.entry,
|
|
835
|
-
exit: update.exit,
|
|
836
|
-
ambient: update.ambient,
|
|
837
|
-
text: update.text,
|
|
838
|
-
primitive: update.primitive,
|
|
839
|
-
}));
|
|
840
|
-
const connectors = this._engine.getConnectorFrameUpdates().map((update) => ({
|
|
841
|
-
id: update.id,
|
|
842
|
-
route: update.route,
|
|
843
|
-
layer: update.layer,
|
|
844
|
-
presence: update.lifecycle,
|
|
845
|
-
style: update.style,
|
|
846
|
-
start: update.start,
|
|
847
|
-
end: update.end,
|
|
848
|
-
direction: update.direction,
|
|
849
|
-
enter: update.entry,
|
|
850
|
-
exit: update.exit,
|
|
851
|
-
ambient: update.ambient,
|
|
852
|
-
}));
|
|
853
|
-
updateElementTransforms(svg, updates, connectors);
|
|
854
|
-
this._applyLifecycleChanges(updates);
|
|
855
|
-
this._applyConnectorLifecycleChanges(connectors);
|
|
856
|
-
this._applyCameraForProgress(this._progress);
|
|
857
|
-
}
|
|
858
|
-
_applyCameraForProgress(progress) {
|
|
859
|
-
const svg = this._getSceneSvg();
|
|
860
|
-
if (!this._bundle || !svg)
|
|
861
|
-
return;
|
|
862
|
-
const sceneStops = this.scenes;
|
|
863
|
-
if (sceneStops.length === 0)
|
|
864
|
-
return;
|
|
865
|
-
const { previous, next } = surroundingStops(sceneStops, progress);
|
|
866
|
-
const previousCamera = this._effectiveCameraAt(previous.index);
|
|
867
|
-
const nextCamera = this._effectiveCameraAt(next.index);
|
|
868
|
-
const previousViewBox = this._resolveCameraViewBox(previousCamera);
|
|
869
|
-
const nextViewBox = this._resolveCameraViewBox(nextCamera);
|
|
870
|
-
const range = next.scene.progress - previous.scene.progress;
|
|
871
|
-
const rawT = range <= 0 ? 0 : (progress - previous.scene.progress) / range;
|
|
872
|
-
const t = resolveCameraEasing(nextCamera.easing)(Math.max(0, Math.min(1, rawT)));
|
|
873
|
-
const viewBox = lerpViewBox(previousViewBox, nextViewBox, t);
|
|
874
|
-
const target = t < 1 ? previousCamera.target : nextCamera.target;
|
|
875
|
-
this._setCameraViewBox(svg, viewBox, target);
|
|
876
|
-
}
|
|
877
|
-
_effectiveCameraAt(index) {
|
|
878
|
-
for (let i = index; i >= 0; i--) {
|
|
879
|
-
const camera = this.scenes[i]?.camera;
|
|
880
|
-
if (camera) {
|
|
881
|
-
return {
|
|
882
|
-
target: camera.target,
|
|
883
|
-
padding: camera.padding,
|
|
884
|
-
duration: camera.duration,
|
|
885
|
-
easing: camera.easing,
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return { target: { type: "reset" } };
|
|
890
|
-
}
|
|
891
|
-
_resolveCameraViewBox(camera) {
|
|
892
|
-
if (!this._bundle)
|
|
893
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "Camera requires an initialized bundle");
|
|
894
|
-
if (camera.target.type === "reset")
|
|
895
|
-
return getResolvedViewBox(this._bundle);
|
|
896
|
-
if (camera.target.type === "area") {
|
|
897
|
-
return expandViewBox(getGridAreaBounds(this._bundle, { at: camera.target.at, size: camera.target.size }), camera.padding ?? 32);
|
|
898
|
-
}
|
|
899
|
-
const svg = this._getSceneSvg();
|
|
900
|
-
if (!svg)
|
|
901
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "Camera requires an initialized scene SVG");
|
|
902
|
-
const bounds = getCurrentElementBounds(svg, camera.target.id);
|
|
903
|
-
if (!bounds) {
|
|
904
|
-
throw new ControllerError("CAMERA_TARGET_NOT_FOUND", `Camera target element "${camera.target.id}" was not found`, {
|
|
905
|
-
elementId: camera.target.id,
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
return expandViewBox(bounds, camera.padding ?? 32);
|
|
909
|
-
}
|
|
910
|
-
_applyCameraDestination(viewBox, target, options) {
|
|
911
|
-
const svg = this._getSceneSvg();
|
|
912
|
-
if (!svg)
|
|
913
|
-
throw new ControllerError("CAMERA_NOT_INITIALIZED", "Camera requires an initialized scene SVG");
|
|
914
|
-
this._cancelCameraAnimation();
|
|
915
|
-
const duration = this._resolveCameraDuration(options);
|
|
916
|
-
if (duration === 0) {
|
|
917
|
-
this._setCameraViewBox(svg, viewBox, target);
|
|
918
|
-
return;
|
|
919
|
-
}
|
|
920
|
-
const from = currentSvgViewBox(svg) ?? this._cameraState?.viewBox ?? viewBox;
|
|
921
|
-
const easing = resolveCameraEasing(options.easing ?? this._config.transitionEasing);
|
|
922
|
-
const start = performance.now();
|
|
923
|
-
const step = (now) => {
|
|
924
|
-
const t = Math.min((now - start) / duration, 1);
|
|
925
|
-
this._setCameraViewBox(svg, lerpViewBox(from, viewBox, easing(t)), target);
|
|
926
|
-
if (t < 1) {
|
|
927
|
-
this._cameraAnim = requestAnimationFrame(step);
|
|
928
|
-
}
|
|
929
|
-
else {
|
|
930
|
-
this._cameraAnim = null;
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
this._cameraAnim = requestAnimationFrame(step);
|
|
934
|
-
}
|
|
935
|
-
_setCameraViewBox(svg, viewBox, target) {
|
|
936
|
-
applySceneViewBox(svg, viewBox);
|
|
937
|
-
const full = this._bundle ? getResolvedViewBox(this._bundle) : viewBox;
|
|
938
|
-
this._cameraState = {
|
|
939
|
-
viewBox,
|
|
940
|
-
target,
|
|
941
|
-
isZoomed: !sameViewBox(viewBox, full),
|
|
942
|
-
};
|
|
943
|
-
this._emit("camera-change", this.getCameraState());
|
|
944
|
-
}
|
|
945
|
-
_getSceneSvg() {
|
|
946
|
-
return (this._sceneElement ?? this._container?.querySelector("svg") ?? null);
|
|
947
|
-
}
|
|
948
|
-
_resolveCameraPadding(options) {
|
|
949
|
-
const padding = options.padding ?? 32;
|
|
950
|
-
if (!Number.isFinite(padding) || padding < 0 || padding > 2048) {
|
|
951
|
-
throw new ControllerError("INVALID_CAMERA_OPTIONS", "Camera padding must be between 0 and 2048");
|
|
952
|
-
}
|
|
953
|
-
return padding;
|
|
954
|
-
}
|
|
955
|
-
_resolveCameraDuration(options) {
|
|
956
|
-
const duration = options.duration ?? this._config.transitionDuration;
|
|
957
|
-
if (!Number.isInteger(duration) || duration < 0 || duration > 10000) {
|
|
958
|
-
throw new ControllerError("INVALID_CAMERA_OPTIONS", "Camera duration must be an integer from 0 to 10000");
|
|
959
|
-
}
|
|
960
|
-
return duration;
|
|
961
|
-
}
|
|
962
|
-
_assertValidCameraArea(area) {
|
|
963
|
-
if (!Array.isArray(area.at) ||
|
|
964
|
-
area.at.length !== 2 ||
|
|
965
|
-
!area.at.every((value) => Number.isFinite(value) && value >= 0) ||
|
|
966
|
-
!Array.isArray(area.size) ||
|
|
967
|
-
area.size.length !== 2 ||
|
|
968
|
-
!area.size.every((value) => Number.isFinite(value) && value > 0)) {
|
|
969
|
-
throw new ControllerError("INVALID_CAMERA_OPTIONS", "Camera area must use non-negative at and positive size");
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
_applyLifecycleChanges(elements) {
|
|
973
|
-
for (const elDef of elements) {
|
|
974
|
-
const transition = this._engine.getLifecycleTransition(elDef.id);
|
|
975
|
-
if (!transition)
|
|
976
|
-
continue;
|
|
977
|
-
const svgForState = (this._sceneElement ?? this._container?.querySelector("svg"));
|
|
978
|
-
if (!svgForState)
|
|
979
|
-
continue;
|
|
980
|
-
const state = getElementState(svgForState, elDef.id);
|
|
981
|
-
if (!state)
|
|
982
|
-
continue;
|
|
983
|
-
if (transition.to === "entering" || transition.to === "present") {
|
|
984
|
-
state.isHidden = false;
|
|
985
|
-
unhideElementOnReadd(state.node);
|
|
986
|
-
}
|
|
987
|
-
if (isForwardEntryTransition(transition)) {
|
|
988
|
-
this._applyEntryAnimation(elDef, state);
|
|
989
|
-
}
|
|
990
|
-
if (isReverseExitTransition(transition)) {
|
|
991
|
-
this._applyExitAnimation({ ...elDef, exit: oppositeExitAnimation(elDef.enter ?? "fade-in") }, state);
|
|
992
|
-
continue;
|
|
993
|
-
}
|
|
994
|
-
if (isForwardExitTransition(transition)) {
|
|
995
|
-
this._applyExitAnimation(elDef, state);
|
|
996
|
-
}
|
|
997
|
-
if (isReverseEntryTransition(transition)) {
|
|
998
|
-
state.isHidden = false;
|
|
999
|
-
unhideElementOnReadd(state.node);
|
|
1000
|
-
this._applyEntryAnimation({ ...elDef, enter: oppositeEntryAnimation(elDef.exit ?? "fade-out") }, state);
|
|
1001
|
-
continue;
|
|
1002
|
-
}
|
|
1003
|
-
if (transition.to === "removed") {
|
|
1004
|
-
state.isHidden = true;
|
|
1005
|
-
hideElementAfterExit(state.node);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
_applyConnectorLifecycleChanges(connectors) {
|
|
1010
|
-
for (const connectorDef of connectors) {
|
|
1011
|
-
const transition = this._engine.getConnectorLifecycleTransition(connectorDef.id);
|
|
1012
|
-
if (!transition)
|
|
1013
|
-
continue;
|
|
1014
|
-
const svgForState = (this._sceneElement ?? this._container?.querySelector("svg"));
|
|
1015
|
-
if (!svgForState)
|
|
1016
|
-
continue;
|
|
1017
|
-
const state = getConnectorState(svgForState, connectorDef.id);
|
|
1018
|
-
if (!state)
|
|
1019
|
-
continue;
|
|
1020
|
-
if (transition.to === "entering" || transition.to === "present") {
|
|
1021
|
-
state.isHidden = false;
|
|
1022
|
-
unhideElementOnReadd(state.node);
|
|
1023
|
-
}
|
|
1024
|
-
if (isForwardEntryTransition(transition)) {
|
|
1025
|
-
this._applyConnectorEntryAnimation(connectorDef, state);
|
|
1026
|
-
}
|
|
1027
|
-
if (isReverseExitTransition(transition)) {
|
|
1028
|
-
this._applyConnectorExitAnimation({
|
|
1029
|
-
...connectorDef,
|
|
1030
|
-
exit: oppositeExitAnimation(connectorDef.enter ?? "fade-in"),
|
|
1031
|
-
}, state);
|
|
1032
|
-
continue;
|
|
1033
|
-
}
|
|
1034
|
-
if (isForwardExitTransition(transition)) {
|
|
1035
|
-
this._applyConnectorExitAnimation(connectorDef, state);
|
|
1036
|
-
}
|
|
1037
|
-
if (isReverseEntryTransition(transition)) {
|
|
1038
|
-
state.isHidden = false;
|
|
1039
|
-
unhideElementOnReadd(state.node);
|
|
1040
|
-
this._applyConnectorEntryAnimation({
|
|
1041
|
-
...connectorDef,
|
|
1042
|
-
enter: oppositeEntryAnimation(connectorDef.exit ?? "fade-out"),
|
|
1043
|
-
}, state);
|
|
1044
|
-
continue;
|
|
1045
|
-
}
|
|
1046
|
-
if (transition.to === "removed") {
|
|
1047
|
-
state.isHidden = true;
|
|
1048
|
-
hideElementAfterExit(state.node);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
_applyEntryAnimation(elDef, state) {
|
|
1053
|
-
const entryAnim = elDef.enter ?? "fade-in";
|
|
1054
|
-
if (entryAnim === "none")
|
|
1055
|
-
return;
|
|
1056
|
-
animateElement(state.node, `iso-anim-${entryAnim}`, "enter");
|
|
1057
|
-
const expectedAnimation = state.node.style.animation;
|
|
1058
|
-
state.node.addEventListener("animationend", () => {
|
|
1059
|
-
if (state.node.style.animation === expectedAnimation) {
|
|
1060
|
-
state.node.style.animation = "";
|
|
1061
|
-
}
|
|
1062
|
-
}, { once: true });
|
|
1063
|
-
}
|
|
1064
|
-
_applyExitAnimation(elDef, state) {
|
|
1065
|
-
const exitAnim = elDef.exit ?? "fade-out";
|
|
1066
|
-
if (exitAnim === "none") {
|
|
1067
|
-
hideElementAfterExit(state.node);
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
animateElement(state.node, `iso-anim-${exitAnim}`, "exit");
|
|
1071
|
-
const expectedAnimation = state.node.style.animation;
|
|
1072
|
-
state.node.addEventListener("animationend", () => {
|
|
1073
|
-
if (state.node.style.animation === expectedAnimation) {
|
|
1074
|
-
hideElementAfterExit(state.node);
|
|
1075
|
-
}
|
|
1076
|
-
}, { once: true });
|
|
1077
|
-
}
|
|
1078
|
-
_applyConnectorEntryAnimation(connectorDef, state) {
|
|
1079
|
-
const entryAnim = connectorDef.enter ?? "fade-in";
|
|
1080
|
-
if (entryAnim === "none")
|
|
1081
|
-
return;
|
|
1082
|
-
animateElement(state.node, `iso-anim-${entryAnim}`, "enter");
|
|
1083
|
-
const expectedAnimation = state.node.style.animation;
|
|
1084
|
-
state.node.addEventListener("animationend", () => {
|
|
1085
|
-
if (state.node.style.animation === expectedAnimation) {
|
|
1086
|
-
state.node.style.animation = "";
|
|
1087
|
-
}
|
|
1088
|
-
}, { once: true });
|
|
1089
|
-
}
|
|
1090
|
-
_applyConnectorExitAnimation(connectorDef, state) {
|
|
1091
|
-
const exitAnim = connectorDef.exit ?? "fade-out";
|
|
1092
|
-
if (exitAnim === "none") {
|
|
1093
|
-
hideElementAfterExit(state.node);
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
animateElement(state.node, `iso-anim-${exitAnim}`, "exit");
|
|
1097
|
-
const expectedAnimation = state.node.style.animation;
|
|
1098
|
-
state.node.addEventListener("animationend", () => {
|
|
1099
|
-
if (state.node.style.animation === expectedAnimation) {
|
|
1100
|
-
hideElementAfterExit(state.node);
|
|
1101
|
-
}
|
|
1102
|
-
}, { once: true });
|
|
1103
|
-
}
|
|
1104
|
-
// ── Scene transitions ──────────────────────────────────────────────────
|
|
1105
|
-
_transitionToScene(index) {
|
|
1106
|
-
this._cancelTransition();
|
|
1107
|
-
if (index === this._sceneIndex)
|
|
1108
|
-
return;
|
|
1109
|
-
this._sceneIndex = index;
|
|
1110
|
-
this._emit("scene-change", index);
|
|
1111
|
-
const stop = this.scenes[index];
|
|
1112
|
-
const from = this._progress;
|
|
1113
|
-
const to = stop.progress;
|
|
1114
|
-
const duration = this._config.transitionDuration;
|
|
1115
|
-
if (duration > 0 && from !== to) {
|
|
1116
|
-
this._animateProgress(from, to, duration);
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
this._progress = to;
|
|
1120
|
-
this._scheduleProgressForward(to);
|
|
1121
|
-
}
|
|
1122
|
-
_animateProgress(from, to, duration) {
|
|
1123
|
-
const easing = resolveEasing((this._config.transitionEasing === "ease-in-out"
|
|
1124
|
-
? "easeInOutCubic"
|
|
1125
|
-
: this._config.transitionEasing === "ease-out"
|
|
1126
|
-
? "easeOutCubic"
|
|
1127
|
-
: "linear"));
|
|
1128
|
-
const start = performance.now();
|
|
1129
|
-
const step = (now) => {
|
|
1130
|
-
const elapsed = now - start;
|
|
1131
|
-
const t = Math.min(elapsed / duration, 1);
|
|
1132
|
-
const easedT = easing(t);
|
|
1133
|
-
const currentProgress = from + (to - from) * easedT;
|
|
1134
|
-
this.setProgress(currentProgress);
|
|
1135
|
-
if (t < 1) {
|
|
1136
|
-
this._transitionAnim = requestAnimationFrame(step);
|
|
1137
|
-
}
|
|
1138
|
-
else {
|
|
1139
|
-
this._transitionAnim = null;
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
this._transitionAnim = requestAnimationFrame(step);
|
|
1143
|
-
}
|
|
1144
|
-
_cancelTransition() {
|
|
1145
|
-
if (this._transitionAnim !== null) {
|
|
1146
|
-
cancelAnimationFrame(this._transitionAnim);
|
|
1147
|
-
this._transitionAnim = null;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
_cancelCameraAnimation() {
|
|
1151
|
-
if (this._cameraAnim !== null) {
|
|
1152
|
-
cancelAnimationFrame(this._cameraAnim);
|
|
1153
|
-
this._cameraAnim = null;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
// ── Scroll binding ─────────────────────────────────────────────────────
|
|
1157
|
-
_bindScroll() {
|
|
1158
|
-
const container = this._config.container;
|
|
1159
|
-
if (!container)
|
|
1160
|
-
return;
|
|
1161
|
-
this._container = container;
|
|
1162
|
-
this._calculateScrollBounds();
|
|
1163
|
-
container.addEventListener("scroll", this._onScroll, { passive: true });
|
|
1164
|
-
window.addEventListener("resize", this._onResize, { passive: true });
|
|
1165
|
-
if (this._config.keyboardControls) {
|
|
1166
|
-
document.addEventListener("keydown", this._onKeyDown);
|
|
1167
|
-
}
|
|
1168
|
-
if (this._config.touchControls) {
|
|
1169
|
-
container.addEventListener("touchstart", this._onTouchStart, {
|
|
1170
|
-
passive: true,
|
|
1171
|
-
});
|
|
1172
|
-
container.addEventListener("touchmove", this._onTouchMove, {
|
|
1173
|
-
passive: false,
|
|
1174
|
-
});
|
|
1175
|
-
container.addEventListener("touchend", this._onTouchEnd);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
_unbindScroll() {
|
|
1179
|
-
const container = this._config.container;
|
|
1180
|
-
if (!container)
|
|
1181
|
-
return;
|
|
1182
|
-
container.removeEventListener("scroll", this._onScroll);
|
|
1183
|
-
window.removeEventListener("resize", this._onResize);
|
|
1184
|
-
document.removeEventListener("keydown", this._onKeyDown);
|
|
1185
|
-
container.removeEventListener("touchstart", this._onTouchStart);
|
|
1186
|
-
container.removeEventListener("touchmove", this._onTouchMove);
|
|
1187
|
-
container.removeEventListener("touchend", this._onTouchEnd);
|
|
1188
|
-
}
|
|
1189
|
-
_calculateScrollBounds() {
|
|
1190
|
-
const container = this._config.container;
|
|
1191
|
-
if (!container)
|
|
1192
|
-
return;
|
|
1193
|
-
const offset = this._config.scrollOffset ?? {};
|
|
1194
|
-
if (this._config.scrollDirection === "horizontal") {
|
|
1195
|
-
this._minScroll = offset.left ?? 0;
|
|
1196
|
-
this._maxScroll = container.scrollWidth - container.clientWidth - (offset.right ?? 0);
|
|
1197
|
-
return;
|
|
1198
|
-
}
|
|
1199
|
-
this._minScroll = offset.top ?? 0;
|
|
1200
|
-
this._maxScroll = container.scrollHeight - container.clientHeight - (offset.bottom ?? 0);
|
|
1201
|
-
}
|
|
1202
|
-
_onScroll = () => {
|
|
1203
|
-
if (this._paused || this._destroyed)
|
|
1204
|
-
return;
|
|
1205
|
-
const container = this._config.container;
|
|
1206
|
-
if (!container)
|
|
1207
|
-
return;
|
|
1208
|
-
const currentScroll = this._config.scrollDirection === "horizontal" ? container.scrollLeft : container.scrollTop;
|
|
1209
|
-
const range = this._maxScroll - this._minScroll;
|
|
1210
|
-
if (range <= 0)
|
|
1211
|
-
return;
|
|
1212
|
-
const rawProgress = (currentScroll - this._minScroll) / range;
|
|
1213
|
-
const clampedProgress = Math.max(this._config.minProgress ?? 0, Math.min(this._config.maxProgress ?? 1, rawProgress));
|
|
1214
|
-
const sensitivity = this._config.scrollSensitivity ?? 1;
|
|
1215
|
-
if (clampedProgress !== this._progress) {
|
|
1216
|
-
this.setProgress(clampedProgress * sensitivity);
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
_onResize = () => {
|
|
1220
|
-
if (this._destroyed)
|
|
1221
|
-
return;
|
|
1222
|
-
this._calculateScrollBounds();
|
|
1223
|
-
};
|
|
1224
|
-
_onKeyDown = (e) => {
|
|
1225
|
-
if (this._destroyed)
|
|
1226
|
-
return;
|
|
1227
|
-
if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === " ") {
|
|
1228
|
-
e.preventDefault();
|
|
1229
|
-
this.nextScene();
|
|
1230
|
-
}
|
|
1231
|
-
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
1232
|
-
e.preventDefault();
|
|
1233
|
-
this.prevScene();
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1236
|
-
_onTouchStart = (e) => {
|
|
1237
|
-
if (this._destroyed)
|
|
1238
|
-
return;
|
|
1239
|
-
this._isDragging = true;
|
|
1240
|
-
const touch = e.touches[0];
|
|
1241
|
-
if (this._config.scrollDirection === "horizontal") {
|
|
1242
|
-
this._touchStartX = touch.clientX;
|
|
1243
|
-
}
|
|
1244
|
-
else {
|
|
1245
|
-
this._touchStartY = touch.clientY;
|
|
1246
|
-
}
|
|
1247
|
-
};
|
|
1248
|
-
_onTouchMove = (e) => {
|
|
1249
|
-
if (this._destroyed)
|
|
1250
|
-
return;
|
|
1251
|
-
if (!this._isDragging)
|
|
1252
|
-
return;
|
|
1253
|
-
const touch = e.touches[0];
|
|
1254
|
-
const delta = this._config.scrollDirection === "horizontal"
|
|
1255
|
-
? this._touchStartX - touch.clientX
|
|
1256
|
-
: this._touchStartY - touch.clientY;
|
|
1257
|
-
const sensitivity = this._config.scrollSensitivity ?? 1.0;
|
|
1258
|
-
const progressDelta = (delta / 300) * sensitivity;
|
|
1259
|
-
const newProgress = Math.max(0, Math.min(1, this._progress + progressDelta));
|
|
1260
|
-
this.setProgress(newProgress);
|
|
1261
|
-
};
|
|
1262
|
-
_onTouchEnd = () => {
|
|
1263
|
-
if (this._destroyed)
|
|
1264
|
-
return;
|
|
1265
|
-
this._isDragging = false;
|
|
1266
|
-
};
|
|
1267
|
-
// ── Pause state ────────────────────────────────────────────────────────
|
|
1268
|
-
_applyPauseState(pause) {
|
|
1269
|
-
const container = this._config.container;
|
|
1270
|
-
if (!container)
|
|
1271
|
-
return;
|
|
1272
|
-
const svg = container.querySelector("svg");
|
|
1273
|
-
if (!svg)
|
|
1274
|
-
return;
|
|
1275
|
-
const playState = pause ? "paused" : "running";
|
|
1276
|
-
const ambientElements = svg.querySelectorAll('[class*="iso-ambient-"]');
|
|
1277
|
-
for (let i = 0; i < ambientElements.length; i++) {
|
|
1278
|
-
const el = ambientElements[i];
|
|
1279
|
-
el.style.animationPlayState = playState;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
_assertNotDestroyed() {
|
|
1283
|
-
if (!this._destroyed)
|
|
1284
|
-
return;
|
|
1285
|
-
throw new ControllerError("CONTROLLER_DESTROYED", "AnimationController has been destroyed");
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
function isForwardEntryTransition(transition) {
|
|
1289
|
-
return transition.from === "removed" && transition.to === "entering";
|
|
1290
|
-
}
|
|
1291
|
-
function isForwardExitTransition(transition) {
|
|
1292
|
-
return transition.to === "exiting";
|
|
1293
|
-
}
|
|
1294
|
-
function isReverseExitTransition(transition) {
|
|
1295
|
-
return transition.to === "removed" && transition.from !== "exiting";
|
|
1296
|
-
}
|
|
1297
|
-
function isReverseEntryTransition(transition) {
|
|
1298
|
-
return transition.from === "exiting" && transition.to !== "removed";
|
|
1299
|
-
}
|
|
1300
|
-
function oppositeExitAnimation(entry) {
|
|
1301
|
-
switch (entry) {
|
|
1302
|
-
case "fade-in":
|
|
1303
|
-
return "fade-out";
|
|
1304
|
-
case "fade-in-grow":
|
|
1305
|
-
return "fade-out-shrink";
|
|
1306
|
-
case "fall-in":
|
|
1307
|
-
return "rise-away";
|
|
1308
|
-
case "rise-from-ground":
|
|
1309
|
-
return "fall-through-ground";
|
|
1310
|
-
case "slide-in-left":
|
|
1311
|
-
return "slide-out-left";
|
|
1312
|
-
case "slide-in-right":
|
|
1313
|
-
return "slide-out-right";
|
|
1314
|
-
case "flip-in":
|
|
1315
|
-
return "flip-out";
|
|
1316
|
-
case "none":
|
|
1317
|
-
return "none";
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
function oppositeEntryAnimation(exit) {
|
|
1321
|
-
switch (exit) {
|
|
1322
|
-
case "fade-out":
|
|
1323
|
-
return "fade-in";
|
|
1324
|
-
case "fade-out-shrink":
|
|
1325
|
-
return "fade-in-grow";
|
|
1326
|
-
case "fall-through-ground":
|
|
1327
|
-
return "rise-from-ground";
|
|
1328
|
-
case "rise-away":
|
|
1329
|
-
return "fall-in";
|
|
1330
|
-
case "slide-out-left":
|
|
1331
|
-
return "slide-in-left";
|
|
1332
|
-
case "slide-out-right":
|
|
1333
|
-
return "slide-in-right";
|
|
1334
|
-
case "flip-out":
|
|
1335
|
-
return "flip-in";
|
|
1336
|
-
case "none":
|
|
1337
|
-
return "none";
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
function surroundingStops(scenes, progress) {
|
|
1341
|
-
let previousIndex = 0;
|
|
1342
|
-
let nextIndex = scenes.length - 1;
|
|
1343
|
-
for (let i = 0; i < scenes.length; i++) {
|
|
1344
|
-
if (scenes[i].progress <= progress)
|
|
1345
|
-
previousIndex = i;
|
|
1346
|
-
if (scenes[i].progress >= progress) {
|
|
1347
|
-
nextIndex = i;
|
|
1348
|
-
break;
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
return {
|
|
1352
|
-
previous: { scene: scenes[previousIndex], index: previousIndex },
|
|
1353
|
-
next: { scene: scenes[nextIndex], index: nextIndex },
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
function expandViewBox(viewBox, padding) {
|
|
1357
|
-
return {
|
|
1358
|
-
minX: roundCameraNumber(viewBox.minX - padding),
|
|
1359
|
-
minY: roundCameraNumber(viewBox.minY - padding),
|
|
1360
|
-
width: roundCameraNumber(Math.max(1, viewBox.width + padding * 2)),
|
|
1361
|
-
height: roundCameraNumber(Math.max(1, viewBox.height + padding * 2)),
|
|
1362
|
-
};
|
|
1363
|
-
}
|
|
1364
|
-
function lerpViewBox(from, to, t) {
|
|
1365
|
-
return {
|
|
1366
|
-
minX: roundCameraNumber(from.minX + (to.minX - from.minX) * t),
|
|
1367
|
-
minY: roundCameraNumber(from.minY + (to.minY - from.minY) * t),
|
|
1368
|
-
width: roundCameraNumber(from.width + (to.width - from.width) * t),
|
|
1369
|
-
height: roundCameraNumber(from.height + (to.height - from.height) * t),
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
|
-
function sameViewBox(a, b) {
|
|
1373
|
-
return a.minX === b.minX && a.minY === b.minY && a.width === b.width && a.height === b.height;
|
|
1374
|
-
}
|
|
1375
|
-
function currentSvgViewBox(svg) {
|
|
1376
|
-
const raw = svg.getAttribute("viewBox");
|
|
1377
|
-
if (!raw)
|
|
1378
|
-
return undefined;
|
|
1379
|
-
const parts = raw.trim().split(/\s+/).map(Number);
|
|
1380
|
-
if (parts.length !== 4 || parts.some((part) => !Number.isFinite(part)))
|
|
1381
|
-
return undefined;
|
|
1382
|
-
return { minX: parts[0], minY: parts[1], width: parts[2], height: parts[3] };
|
|
1383
|
-
}
|
|
1384
|
-
function resolveCameraEasing(easing) {
|
|
1385
|
-
return resolveEasing(easing === "ease-in-out" ? "easeInOutCubic" : easing === "ease-out" ? "easeOutCubic" : "linear");
|
|
1386
|
-
}
|
|
1387
|
-
function copyCameraState(state) {
|
|
1388
|
-
return {
|
|
1389
|
-
viewBox: { ...state.viewBox },
|
|
1390
|
-
target: state.target?.type === "area"
|
|
1391
|
-
? { type: "area", at: [...state.target.at], size: [...state.target.size] }
|
|
1392
|
-
: state.target
|
|
1393
|
-
? { ...state.target }
|
|
1394
|
-
: undefined,
|
|
1395
|
-
isZoomed: state.isZoomed,
|
|
1396
|
-
};
|
|
1397
|
-
}
|
|
1398
|
-
function roundCameraNumber(value) {
|
|
1399
|
-
return Math.round(value * 1000) / 1000;
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
const RUNTIME_BUNDLE_FORMAT = "isostate-runtime-bundle";
|
|
1403
|
-
const RUNTIME_VERSION = "0.4.0";
|
|
1404
|
-
const HEX_DIGEST_PATTERN = /^[a-f0-9]{64}$/;
|
|
1405
|
-
/** Mount a compiled runtime bundle into an HTML element. */
|
|
1406
|
-
function mountScene(target, bundle, options = {}) {
|
|
1407
|
-
assertMountTarget(target);
|
|
1408
|
-
validateRuntimeBundle(bundle);
|
|
1409
|
-
const engine = new AnimationEngine();
|
|
1410
|
-
engine.init(bundle);
|
|
1411
|
-
const svg = buildSceneDOM(target, bundle, {
|
|
1412
|
-
label: options.label,
|
|
1413
|
-
themeVars: options.themeVars,
|
|
1414
|
-
});
|
|
1415
|
-
let controller;
|
|
1416
|
-
if (options.controller !== undefined && options.controller !== false) {
|
|
1417
|
-
controller = new AnimationController();
|
|
1418
|
-
controller.init(bundle, {
|
|
1419
|
-
...options.controller,
|
|
1420
|
-
container: options.controller.container ?? target,
|
|
1421
|
-
sceneElement: svg,
|
|
1422
|
-
}, {
|
|
1423
|
-
engine,
|
|
1424
|
-
sceneElement: svg,
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
let destroyed = false;
|
|
1428
|
-
return {
|
|
1429
|
-
svg,
|
|
1430
|
-
engine,
|
|
1431
|
-
controller,
|
|
1432
|
-
getResolvedConfig: () => getResolvedConfig(bundle, options),
|
|
1433
|
-
destroy: () => {
|
|
1434
|
-
if (destroyed)
|
|
1435
|
-
return;
|
|
1436
|
-
destroyed = true;
|
|
1437
|
-
controller?.destroy();
|
|
1438
|
-
engine.destroy();
|
|
1439
|
-
if (svg.parentNode === target) {
|
|
1440
|
-
target.removeChild(svg);
|
|
1441
|
-
}
|
|
1442
|
-
else {
|
|
1443
|
-
svg.parentNode?.removeChild(svg);
|
|
1444
|
-
}
|
|
1445
|
-
},
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
function assertMountTarget(target) {
|
|
1449
|
-
if (!target || typeof target.appendChild !== "function" || typeof target.removeChild !== "function") {
|
|
1450
|
-
throw new RenderError("INVALID_MOUNT_TARGET", "mountScene() requires a DOM HTMLElement target");
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
function validateRuntimeBundle(bundle) {
|
|
1454
|
-
if (!bundle || typeof bundle !== "object") {
|
|
1455
|
-
throw new RenderError("BUNDLE_FORMAT_MISSING", "Runtime bundle must be a plain object");
|
|
1456
|
-
}
|
|
1457
|
-
if (bundle._format !== RUNTIME_BUNDLE_FORMAT) {
|
|
1458
|
-
throw new RenderError("BUNDLE_FORMAT_MISSING", "Runtime bundle format is missing or unsupported", {
|
|
1459
|
-
expected: RUNTIME_BUNDLE_FORMAT,
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
if (!Array.isArray(bundle.scenes) || bundle.scenes.length === 0) {
|
|
1463
|
-
throw new RenderError("BUNDLE_FORMAT_MISSING", "Runtime bundle must include compiled scenes[]");
|
|
1464
|
-
}
|
|
1465
|
-
if (majorVersion(bundle._version) !== majorVersion(RUNTIME_VERSION)) {
|
|
1466
|
-
throw new RenderError("BUNDLE_VERSION_MISMATCH", `Runtime bundle version ${bundle._version} is not compatible with runtime ${RUNTIME_VERSION}`, { bundleVersion: bundle._version, runtimeVersion: RUNTIME_VERSION });
|
|
1467
|
-
}
|
|
1468
|
-
if (!bundle._digest) {
|
|
1469
|
-
throw new RenderError("BUNDLE_DIGEST_MISSING", "Runtime bundle digest is missing");
|
|
1470
|
-
}
|
|
1471
|
-
if (typeof bundle._digest !== "string" || !HEX_DIGEST_PATTERN.test(bundle._digest)) {
|
|
1472
|
-
throw new RenderError("BUNDLE_DIGEST_MISMATCH", "Runtime bundle digest is malformed");
|
|
1473
|
-
}
|
|
1474
|
-
const { _digest, ...bundleWithoutDigest } = bundle;
|
|
1475
|
-
const actualDigest = sha256(canonicalStringify(bundleWithoutDigest));
|
|
1476
|
-
if (actualDigest !== _digest) {
|
|
1477
|
-
throw new RenderError("BUNDLE_DIGEST_MISMATCH", "Runtime bundle digest does not match bundle content", {
|
|
1478
|
-
expected: _digest,
|
|
1479
|
-
actual: actualDigest,
|
|
1480
|
-
});
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
function getResolvedConfig(bundle, options = {}) {
|
|
1484
|
-
return {
|
|
1485
|
-
grid: { cellSize: bundle.grid.cellSize },
|
|
1486
|
-
floor: { ...bundle.floor },
|
|
1487
|
-
layout: {
|
|
1488
|
-
...bundle.layout,
|
|
1489
|
-
padding: { ...bundle.layout.padding },
|
|
1490
|
-
align: [...bundle.layout.align],
|
|
1491
|
-
},
|
|
1492
|
-
viewBox: getResolvedViewBox(bundle),
|
|
1493
|
-
camera: {
|
|
1494
|
-
viewBox: getResolvedViewBox(bundle),
|
|
1495
|
-
isZoomed: false,
|
|
1496
|
-
},
|
|
1497
|
-
theme: bundle.theme,
|
|
1498
|
-
themeVars: getResolvedThemeVars(bundle, options.themeVars),
|
|
1499
|
-
scenes: bundle.scenes.map((scene) => ({
|
|
1500
|
-
id: scene.id,
|
|
1501
|
-
progress: scene.progress,
|
|
1502
|
-
})),
|
|
1503
|
-
layerOrder: bundle.layers
|
|
1504
|
-
.map((layer) => ({ name: layer.name, order: layer.order }))
|
|
1505
|
-
.sort((a, b) => a.order - b.order || a.name.localeCompare(b.name)),
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
function getResolvedThemeVars(bundle, overrides = {}) {
|
|
1509
|
-
return {
|
|
1510
|
-
...(resolveTheme(bundle.theme) ?? {}),
|
|
1511
|
-
...(bundle.themeVars ?? {}),
|
|
1512
|
-
...overrides,
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
function majorVersion(version) {
|
|
1516
|
-
const major = Number.parseInt(String(version).split(".")[0] ?? "", 10);
|
|
1517
|
-
return Number.isFinite(major) ? major : Number.NaN;
|
|
1518
|
-
}
|
|
1519
|
-
function canonicalStringify(value) {
|
|
1520
|
-
return JSON.stringify(normalizeValue(value));
|
|
1521
|
-
}
|
|
1522
|
-
function normalizeValue(value) {
|
|
1523
|
-
if (Array.isArray(value)) {
|
|
1524
|
-
return value.map((item) => (item === undefined ? null : normalizeValue(item)));
|
|
1525
|
-
}
|
|
1526
|
-
if (!isPlainObject(value))
|
|
1527
|
-
return value;
|
|
1528
|
-
const normalized = {};
|
|
1529
|
-
for (const key of Object.keys(value).sort()) {
|
|
1530
|
-
const child = value[key];
|
|
1531
|
-
if (child !== undefined) {
|
|
1532
|
-
normalized[key] = normalizeValue(child);
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
return normalized;
|
|
1536
|
-
}
|
|
1537
|
-
function isPlainObject(value) {
|
|
1538
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
export { AnimationController as A, AnimationEngine as a, easeInOutCubic as b, easeOutCubic as c, easeInCubic as e, linear as l, mountScene as m, resolveEasing as r };
|
|
1542
|
-
//# sourceMappingURL=index-C3qcXbPI.js.map
|