@hyperframes/sdk 0.6.113

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 (78) hide show
  1. package/LICENSE +190 -0
  2. package/dist/adapters/fs.d.ts +9 -0
  3. package/dist/adapters/fs.d.ts.map +1 -0
  4. package/dist/adapters/fs.js +122 -0
  5. package/dist/adapters/fs.js.map +1 -0
  6. package/dist/adapters/headless.d.ts +3 -0
  7. package/dist/adapters/headless.d.ts.map +1 -0
  8. package/dist/adapters/headless.js +17 -0
  9. package/dist/adapters/headless.js.map +1 -0
  10. package/dist/adapters/iframe.d.ts +102 -0
  11. package/dist/adapters/iframe.d.ts.map +1 -0
  12. package/dist/adapters/iframe.js +569 -0
  13. package/dist/adapters/iframe.js.map +1 -0
  14. package/dist/adapters/memory.d.ts +5 -0
  15. package/dist/adapters/memory.d.ts.map +1 -0
  16. package/dist/adapters/memory.js +54 -0
  17. package/dist/adapters/memory.js.map +1 -0
  18. package/dist/adapters/types.d.ts +65 -0
  19. package/dist/adapters/types.d.ts.map +1 -0
  20. package/dist/adapters/types.js +2 -0
  21. package/dist/adapters/types.js.map +1 -0
  22. package/dist/document.d.ts +25 -0
  23. package/dist/document.d.ts.map +1 -0
  24. package/dist/document.js +238 -0
  25. package/dist/document.js.map +1 -0
  26. package/dist/engine/apply-patches.d.ts +20 -0
  27. package/dist/engine/apply-patches.d.ts.map +1 -0
  28. package/dist/engine/apply-patches.js +284 -0
  29. package/dist/engine/apply-patches.js.map +1 -0
  30. package/dist/engine/cssWriter.d.ts +18 -0
  31. package/dist/engine/cssWriter.d.ts.map +1 -0
  32. package/dist/engine/cssWriter.js +139 -0
  33. package/dist/engine/cssWriter.js.map +1 -0
  34. package/dist/engine/keyframeBackfill.d.ts +17 -0
  35. package/dist/engine/keyframeBackfill.d.ts.map +1 -0
  36. package/dist/engine/keyframeBackfill.js +43 -0
  37. package/dist/engine/keyframeBackfill.js.map +1 -0
  38. package/dist/engine/model.d.ts +55 -0
  39. package/dist/engine/model.d.ts.map +1 -0
  40. package/dist/engine/model.js +256 -0
  41. package/dist/engine/model.js.map +1 -0
  42. package/dist/engine/mutate.d.ts +26 -0
  43. package/dist/engine/mutate.d.ts.map +1 -0
  44. package/dist/engine/mutate.js +1243 -0
  45. package/dist/engine/mutate.js.map +1 -0
  46. package/dist/engine/patches.d.ts +71 -0
  47. package/dist/engine/patches.d.ts.map +1 -0
  48. package/dist/engine/patches.js +197 -0
  49. package/dist/engine/patches.js.map +1 -0
  50. package/dist/engine/serialize.d.ts +15 -0
  51. package/dist/engine/serialize.d.ts.map +1 -0
  52. package/dist/engine/serialize.js +20 -0
  53. package/dist/engine/serialize.js.map +1 -0
  54. package/dist/engine/variableModel.d.ts +29 -0
  55. package/dist/engine/variableModel.d.ts.map +1 -0
  56. package/dist/engine/variableModel.js +81 -0
  57. package/dist/engine/variableModel.js.map +1 -0
  58. package/dist/history.d.ts +39 -0
  59. package/dist/history.d.ts.map +1 -0
  60. package/dist/history.js +116 -0
  61. package/dist/history.js.map +1 -0
  62. package/dist/index.d.ts +15 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +11 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/persist-queue.d.ts +24 -0
  67. package/dist/persist-queue.d.ts.map +1 -0
  68. package/dist/persist-queue.js +62 -0
  69. package/dist/persist-queue.js.map +1 -0
  70. package/dist/session.d.ts +38 -0
  71. package/dist/session.d.ts.map +1 -0
  72. package/dist/session.js +514 -0
  73. package/dist/session.js.map +1 -0
  74. package/dist/types.d.ts +521 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +16 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +55 -0
@@ -0,0 +1,514 @@
1
+ /**
2
+ * Phase 3a — real editing session.
3
+ *
4
+ * CompositionImpl: live linkedom document, real dispatch, RFC 6902 patch emission,
5
+ * override-set accumulation, batch, can(), serialize(), applyPatches().
6
+ *
7
+ * openComposition() wires history + persist queue for standalone (T1/T2) mode.
8
+ * T3 (embedded) callers supply overrides; SDK emits patches only — host owns state.
9
+ */
10
+ import { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
11
+ import { buildRoots, flatElements } from "./document.js";
12
+ import { parseMutable } from "./engine/model.js";
13
+ import { applyOp, validateOp } from "./engine/mutate.js";
14
+ import { getGsapScript, resolveScoped } from "./engine/model.js";
15
+ import { extractGsapLabels } from "@hyperframes/core/gsap-parser-acorn";
16
+ import { serializeDocument } from "./engine/serialize.js";
17
+ import { applyPatchesToDocument, applyOverrideSet } from "./engine/apply-patches.js";
18
+ import { buildPatchEvent, pathToKey } from "./engine/patches.js";
19
+ import { createHistory } from "./history.js";
20
+ import { createPersistQueue } from "./persist-queue.js";
21
+ // ─── Implementation ───────────────────────────────────────────────────────────
22
+ class CompositionImpl {
23
+ parsed;
24
+ persist;
25
+ preview;
26
+ /** Accumulated override-set — T3 embedded mode fold contract. */
27
+ overrides;
28
+ /** Lazily-built element snapshot, invalidated on every mutation. */
29
+ elementsCache = null;
30
+ currentSelection = [];
31
+ changeHandlers = [];
32
+ selectionHandlers = [];
33
+ patchHandlers = [];
34
+ errorHandlers = [];
35
+ previewSelectionUnsubscribe = null;
36
+ /** Attached by openComposition() for standalone mode. */
37
+ historyModule = null;
38
+ persistQueueModule = null;
39
+ /** Batching state: accumulates patches from multiple dispatches. */
40
+ batchDepth = 0;
41
+ batchForward = [];
42
+ batchInverse = [];
43
+ batchOpTypes = [];
44
+ batchOrigin = ORIGIN_LOCAL;
45
+ /** Override-set state at outermost batch entry — restored if the batch throws. */
46
+ batchOverridesSnapshot = {};
47
+ constructor(parsed, opts) {
48
+ this.parsed = parsed;
49
+ this.persist = opts.persist;
50
+ this.preview = opts.preview;
51
+ this.overrides = { ...(opts.overrides ?? {}) };
52
+ this.previewSelectionUnsubscribe =
53
+ this.preview?.on("selection", (ids) => this.updateSelection(ids)) ?? null;
54
+ }
55
+ attachHistory(module) {
56
+ this.historyModule = module;
57
+ }
58
+ attachPersistQueue(module) {
59
+ this.persistQueueModule = module;
60
+ }
61
+ _fireError(e) {
62
+ this.errorHandlers.forEach((h) => h(e));
63
+ }
64
+ // ── Typed methods (F10 layer 1) ─────────────────────────────────────────────
65
+ setStyle(id, styles) {
66
+ this.dispatch({ type: "setStyle", target: id, styles });
67
+ }
68
+ setText(id, value) {
69
+ this.dispatch({ type: "setText", target: id, value });
70
+ }
71
+ setAttribute(id, name, value) {
72
+ this.dispatch({ type: "setAttribute", target: id, name, value });
73
+ }
74
+ setTiming(id, timing) {
75
+ this.dispatch({ type: "setTiming", target: id, ...timing });
76
+ }
77
+ removeElement(id) {
78
+ this.dispatch({ type: "removeElement", target: id });
79
+ }
80
+ addElement(parent, index, html) {
81
+ const result = this._dispatch({ type: "addElement", parent, index, html }, ORIGIN_LOCAL);
82
+ return result.meta?.newId ?? "";
83
+ }
84
+ setVariableValue(id, value) {
85
+ this.dispatch({ type: "setVariableValue", id, value });
86
+ }
87
+ // ── WS-C: timing accessors + typed setHold ───────────────────────────────────
88
+ /**
89
+ * Cache of parsed GSAP labels keyed by EXACT script text. extractGsapLabels does
90
+ * a full acorn parse; caching avoids re-parsing on repeated getElementTimings reads
91
+ * when the script is unchanged. The content (not reference) key means any script
92
+ * edit changes the text and invalidates the cache, so renumbered tweens never yield
93
+ * stale label positions.
94
+ */
95
+ _gsapLabelCache = null;
96
+ // fallow-ignore-next-line complexity
97
+ getElementTimings() {
98
+ const script = getGsapScript(this.parsed.document);
99
+ // Extract all addLabel("name", position) calls from the GSAP script (see cache note above).
100
+ let allLabels;
101
+ if (script && this._gsapLabelCache?.script === script) {
102
+ allLabels = this._gsapLabelCache.labels;
103
+ }
104
+ else {
105
+ allLabels = script ? extractGsapLabels(script) : [];
106
+ this._gsapLabelCache = script ? { script, labels: allLabels } : null;
107
+ }
108
+ const result = {};
109
+ const elements = this.getElements();
110
+ for (const el of elements) {
111
+ const domEl = resolveScoped(this.parsed.document, el.scopedId);
112
+ if (!domEl)
113
+ continue;
114
+ const startStr = domEl.getAttribute("data-start");
115
+ const endStr = domEl.getAttribute("data-end");
116
+ const durationStr = domEl.getAttribute("data-duration");
117
+ // Same preference as handleSetTiming: prefer data-duration, fall back to end - start.
118
+ const start = startStr !== null ? parseFloat(startStr) : 0;
119
+ const durationAttr = durationStr !== null ? parseFloat(durationStr) : null;
120
+ const endAttr = endStr !== null ? parseFloat(endStr) : null;
121
+ let duration;
122
+ if (durationAttr !== null && Number.isFinite(durationAttr)) {
123
+ duration = durationAttr;
124
+ }
125
+ else if (endAttr !== null && Number.isFinite(endAttr)) {
126
+ duration = endAttr - start;
127
+ }
128
+ else {
129
+ // No timing info — skip non-timed elements.
130
+ continue;
131
+ }
132
+ const enterAt = Number.isFinite(start) ? start : 0;
133
+ const exitAt = enterAt + (Number.isFinite(duration) ? duration : 0);
134
+ // Labels whose position falls within [enterAt, exitAt] (end-inclusive: a
135
+ // label exactly at exitAt is treated as within the element's window).
136
+ const labels = allLabels
137
+ .filter(({ position }) => position >= enterAt && position <= exitAt)
138
+ .map(({ name }) => name);
139
+ result[el.scopedId] = { enterAt, exitAt, labels };
140
+ }
141
+ return result;
142
+ }
143
+ setElementTiming(map) {
144
+ const entries = Object.entries(map);
145
+ if (entries.length === 0)
146
+ return;
147
+ this.batch(() => {
148
+ for (const [id, timing] of entries) {
149
+ this.dispatch({ type: "setTiming", target: id, ...timing });
150
+ }
151
+ });
152
+ }
153
+ setHold(id, hold) {
154
+ this.dispatch({ type: "setHold", target: id, hold });
155
+ }
156
+ addGsapTween(target, tween) {
157
+ const result = this._dispatch({ type: "addGsapTween", target, tween }, ORIGIN_LOCAL);
158
+ return result.meta?.animationId ?? "";
159
+ }
160
+ setGsapTween(animationId, properties) {
161
+ this.dispatch({ type: "setGsapTween", animationId, properties });
162
+ }
163
+ removeGsapTween(animationId) {
164
+ this.dispatch({ type: "removeGsapTween", animationId });
165
+ }
166
+ addWithKeyframes(targetSelector, position, duration, keyframes, ease) {
167
+ const result = this._dispatch({ type: "addWithKeyframes", targetSelector, position, duration, keyframes, ease }, ORIGIN_LOCAL);
168
+ return result.meta?.animationId ?? "";
169
+ }
170
+ replaceWithKeyframes(animationId, targetSelector, position, duration, keyframes, ease) {
171
+ const result = this._dispatch({
172
+ type: "replaceWithKeyframes",
173
+ animationId,
174
+ targetSelector,
175
+ position,
176
+ duration,
177
+ keyframes,
178
+ ease,
179
+ }, ORIGIN_LOCAL);
180
+ // Position-derived IDs renumber after the remove — this is the NEW id, which
181
+ // may differ from the input animationId.
182
+ return result.meta?.animationId ?? "";
183
+ }
184
+ undo() {
185
+ this.historyModule?.undo();
186
+ }
187
+ redo() {
188
+ this.historyModule?.redo();
189
+ }
190
+ canUndo() {
191
+ return this.historyModule?.canUndo() ?? false;
192
+ }
193
+ canRedo() {
194
+ return this.historyModule?.canRedo() ?? false;
195
+ }
196
+ // ── Query API (F1) ───────────────────────────────────────────────────────────
197
+ getElements() {
198
+ // Walk the live linkedom DOM directly — no serialize/re-parse round trip.
199
+ this.elementsCache ??= flatElements(buildRoots(this.parsed.document));
200
+ return [...this.elementsCache];
201
+ }
202
+ getElement(id) {
203
+ // Accept both bare ids (top-level) and scoped ids (sub-composition elements).
204
+ // Match by scopedId first (canonical); bare-id fallback keeps top-level compat
205
+ // for callers that don't yet use scoped ids.
206
+ return (this.getElements().find((el) => el.scopedId === id) ??
207
+ this.getElements().find((el) => el.id === id && el.scopedId === el.id) ??
208
+ null);
209
+ }
210
+ find(query) {
211
+ return (this.getElements()
212
+ // fallow-ignore-next-line complexity
213
+ .filter((el) => {
214
+ if (query.tag && el.tag !== query.tag)
215
+ return false;
216
+ if (query.text && !el.text?.includes(query.text))
217
+ return false;
218
+ if (query.name && el.attributes["data-name"] !== query.name)
219
+ return false;
220
+ if (query.track !== undefined && el.trackIndex !== query.track)
221
+ return false;
222
+ if (query.composition && !el.scopedId.startsWith(`${query.composition}/`))
223
+ return false;
224
+ return true;
225
+ })
226
+ .map((el) => el.scopedId));
227
+ }
228
+ // ── Selection API ────────────────────────────────────────────────────────────
229
+ selection() {
230
+ const ids = [...this.currentSelection];
231
+ return {
232
+ ids,
233
+ setStyle: (styles) => this.dispatch({ type: "setStyle", target: ids, styles }),
234
+ setText: (value) => this.dispatch({ type: "setText", target: ids, value }),
235
+ setAttribute: (name, value) => this.dispatch({ type: "setAttribute", target: ids, name, value }),
236
+ setTiming: (timing) => this.dispatch({ type: "setTiming", target: ids, ...timing }),
237
+ removeElement: () => this.dispatch({ type: "removeElement", target: ids }),
238
+ };
239
+ }
240
+ element(id) {
241
+ return {
242
+ id,
243
+ setStyle: (styles) => this.dispatch({ type: "setStyle", target: id, styles }),
244
+ setText: (value) => this.dispatch({ type: "setText", target: id, value }),
245
+ setAttribute: (name, value) => this.dispatch({ type: "setAttribute", target: id, name, value }),
246
+ setTiming: (timing) => this.dispatch({ type: "setTiming", target: id, ...timing }),
247
+ removeElement: () => this.dispatch({ type: "removeElement", target: id }),
248
+ };
249
+ }
250
+ getSelection() {
251
+ return [...this.currentSelection];
252
+ }
253
+ setSelection(ids) {
254
+ const deduped = Array.from(new Set(ids));
255
+ if (deduped.length === this.currentSelection.length &&
256
+ deduped.every((id, i) => id === this.currentSelection[i])) {
257
+ return;
258
+ }
259
+ this.updateSelection(deduped);
260
+ }
261
+ updateSelection(ids) {
262
+ this.currentSelection = [...ids];
263
+ for (const handler of this.selectionHandlers) {
264
+ handler([...this.currentSelection]);
265
+ }
266
+ }
267
+ // ── Dispatch / batch ─────────────────────────────────────────────────────────
268
+ // fallow-ignore-next-line complexity
269
+ _dispatch(op, origin) {
270
+ const result = applyOp(this.parsed, op);
271
+ const { forward, inverse } = result;
272
+ if (forward.length === 0 && inverse.length === 0) {
273
+ if (this.batchDepth === 0)
274
+ this.changeHandlers.forEach((h) => h());
275
+ return result;
276
+ }
277
+ this.elementsCache = null;
278
+ // Update override-set from forward patches
279
+ for (const p of forward) {
280
+ const key = pathToKey(p.path);
281
+ if (key !== null) {
282
+ this.overrides[key] =
283
+ p.op === "remove"
284
+ ? null
285
+ : p.value;
286
+ }
287
+ }
288
+ // Purge orphan property keys for removed elements so the override-set stays
289
+ // compact and a future T3 session doesn't replay stale properties onto a
290
+ // non-existent element. Override-set keys use decoded scoped ids ("hf-host/hf-leaf")
291
+ // while path segments use RFC 6902 encoding ("hf-host~1hf-leaf") — decode before compare.
292
+ for (const p of forward) {
293
+ const elemMatch = /^\/elements\/([^/]+)$/.exec(p.path);
294
+ if (p.op === "remove" && elemMatch) {
295
+ // Decode RFC 6902 escaping: ~1 → /, ~0 → ~
296
+ const id = elemMatch[1].replace(/~1/g, "/").replace(/~0/g, "~");
297
+ for (const key of Object.keys(this.overrides)) {
298
+ // Purge property sub-keys (e.g. "hf-x.style.color") but preserve
299
+ // the removal marker itself (key === id, set to null in the loop above).
300
+ if (key.startsWith(`${id}.`) || key.startsWith(`${id}/`)) {
301
+ delete this.overrides[key];
302
+ }
303
+ }
304
+ }
305
+ }
306
+ if (this.batchDepth > 0) {
307
+ this.batchForward.push(...forward);
308
+ this.batchInverse.push(...inverse);
309
+ if (!this.batchOpTypes.includes(op.type))
310
+ this.batchOpTypes.push(op.type);
311
+ }
312
+ else {
313
+ // Reverse the inverse list (parity with batch() below): an op that emits
314
+ // multiple patches whose undo order matters — same path (reorderElements
315
+ // with a duplicate target), an aliased multi-target, or a nested
316
+ // parent+child removeElement — must undo in reverse application order, or
317
+ // undo lands on an intermediate value / drops a subtree. Harmless for the
318
+ // common single-patch / independent-path case.
319
+ const event = buildPatchEvent(forward, [...inverse].reverse(), origin, [op.type]);
320
+ this.patchHandlers.forEach((h) => h(event));
321
+ this.changeHandlers.forEach((h) => h());
322
+ }
323
+ return result;
324
+ }
325
+ dispatch(op, opts) {
326
+ this._dispatch(op, opts?.origin ?? ORIGIN_LOCAL);
327
+ }
328
+ /**
329
+ * Coalesce multiple dispatches into one undo entry / one patch event.
330
+ *
331
+ * Transactional: if the callback throws, all DOM mutations applied so far
332
+ * are reverted (accumulated inverse patches replayed in reverse) and the
333
+ * override-set is restored — the model is exactly as it was at batch entry.
334
+ *
335
+ * Note: a batch that produces no effective mutations still fires 'change'
336
+ * handlers (parity with no-op dispatch) — subscribers must not assume
337
+ * silence when wrapping speculative operations.
338
+ */
339
+ // fallow-ignore-next-line complexity
340
+ batch(fn, opts) {
341
+ const origin = opts?.origin ?? ORIGIN_LOCAL;
342
+ this.batchDepth++;
343
+ if (this.batchDepth === 1) {
344
+ this.batchOrigin = origin; // only set on outermost entry
345
+ this.batchOverridesSnapshot = { ...this.overrides };
346
+ }
347
+ let threw = false;
348
+ try {
349
+ fn();
350
+ }
351
+ catch (err) {
352
+ threw = true;
353
+ throw err;
354
+ }
355
+ finally {
356
+ this.batchDepth--;
357
+ if (this.batchDepth === 0) {
358
+ if (!threw && this.batchForward.length > 0) {
359
+ const event = buildPatchEvent(this.batchForward, [...this.batchInverse].reverse(), this.batchOrigin, this.batchOpTypes);
360
+ // Fire handlers before resetting batch state so that if a handler
361
+ // throws the patch data (batchForward/batchInverse) is still intact
362
+ // for callers that inspect it on error. The event was already built
363
+ // from a snapshot so handler re-entrancy does not corrupt the event.
364
+ this.patchHandlers.forEach((h) => h(event));
365
+ this.changeHandlers.forEach((h) => h());
366
+ this.resetBatchState();
367
+ }
368
+ else {
369
+ if (threw && this.batchInverse.length > 0) {
370
+ // Roll back: the dispatches inside the batch already mutated the
371
+ // DOM. Without this, a throwing batch would leave the model in a
372
+ // partial state with no patch trail to undo it.
373
+ applyPatchesToDocument(this.parsed, [...this.batchInverse].reverse());
374
+ this.overrides = { ...this.batchOverridesSnapshot };
375
+ this.elementsCache = null;
376
+ }
377
+ this.resetBatchState();
378
+ // Empty no-op batch: fire changeHandlers (parity with dispatch)
379
+ if (!threw)
380
+ this.changeHandlers.forEach((h) => h());
381
+ }
382
+ }
383
+ }
384
+ }
385
+ resetBatchState() {
386
+ this.batchForward = [];
387
+ this.batchInverse = [];
388
+ this.batchOpTypes = [];
389
+ this.batchOrigin = ORIGIN_LOCAL;
390
+ this.batchOverridesSnapshot = {};
391
+ }
392
+ can(op) {
393
+ return validateOp(this.parsed, op);
394
+ }
395
+ // fallow-ignore-next-line complexity
396
+ on(event, handler) {
397
+ const h = handler;
398
+ if (event === "change") {
399
+ this.changeHandlers.push(h);
400
+ return () => {
401
+ this.changeHandlers = this.changeHandlers.filter((x) => x !== h);
402
+ };
403
+ }
404
+ if (event === "selectionchange") {
405
+ this.selectionHandlers.push(h);
406
+ return () => {
407
+ this.selectionHandlers = this.selectionHandlers.filter((x) => x !== h);
408
+ };
409
+ }
410
+ if (event === "patch") {
411
+ this.patchHandlers.push(h);
412
+ return () => {
413
+ this.patchHandlers = this.patchHandlers.filter((x) => x !== h);
414
+ };
415
+ }
416
+ if (event === "persist:error") {
417
+ const typedH = h;
418
+ this.errorHandlers.push(typedH);
419
+ const offPersist = this.persist?.on("persist:error", typedH);
420
+ return () => {
421
+ this.errorHandlers = this.errorHandlers.filter((x) => x !== typedH);
422
+ offPersist?.();
423
+ };
424
+ }
425
+ return () => { };
426
+ }
427
+ // ── Serialization ────────────────────────────────────────────────────────────
428
+ serialize() {
429
+ return serializeDocument(this.parsed);
430
+ }
431
+ // ── T3 embedded-mode extras ──────────────────────────────────────────────────
432
+ getOverrides() {
433
+ return { ...this.overrides };
434
+ }
435
+ // fallow-ignore-next-line complexity
436
+ applyPatches(patches, opts) {
437
+ const origin = opts?.origin ?? ORIGIN_APPLY_PATCHES;
438
+ // The emitted PatchEvent carries an EMPTY inversePatches array — hosts
439
+ // maintaining an external inverse log must compute inverses from their own
440
+ // state; applyPatches events never enter history (origin-guarded).
441
+ // Emit a patch event so subscribers stay in sync.
442
+ applyPatchesToDocument(this.parsed, patches);
443
+ this.elementsCache = null;
444
+ // Update override-set
445
+ for (const p of patches) {
446
+ const key = pathToKey(p.path);
447
+ if (key !== null) {
448
+ this.overrides[key] =
449
+ p.op === "remove"
450
+ ? null
451
+ : p.value;
452
+ }
453
+ }
454
+ const opTypes = ["applyPatches"];
455
+ const event = buildPatchEvent(patches, [], origin, opTypes);
456
+ this.patchHandlers.forEach((h) => h(event));
457
+ this.changeHandlers.forEach((h) => h());
458
+ }
459
+ // ── Lifecycle ────────────────────────────────────────────────────────────────
460
+ async flush() {
461
+ await this.persistQueueModule?.flush();
462
+ }
463
+ dispose() {
464
+ this.previewSelectionUnsubscribe?.();
465
+ this.previewSelectionUnsubscribe = null;
466
+ this.persistQueueModule?.dispose();
467
+ this.historyModule?.dispose();
468
+ this.changeHandlers = [];
469
+ this.selectionHandlers = [];
470
+ this.patchHandlers = [];
471
+ this.errorHandlers = [];
472
+ }
473
+ }
474
+ // ─── Public factory ───────────────────────────────────────────────────────────
475
+ /**
476
+ * Open a composition for editing.
477
+ *
478
+ * Standalone (T1/T2): supply persist adapter — SDK owns history + auto-save.
479
+ * Embedded (T3): supply overrides — SDK emits patches; host owns history + persistence.
480
+ * Headless (agents): omit both — SDK is a stateless transform + serializer.
481
+ */
482
+ // fallow-ignore-next-line complexity
483
+ export async function openComposition(html, opts) {
484
+ // Single parse: parseMutable stamps hf-ids + builds the live linkedom DOM;
485
+ // the query API derives element snapshots from it lazily.
486
+ const parsed = parseMutable(html);
487
+ // T3 embedded: replay the stored override-set onto the base in one pass,
488
+ // so the session exposes the user's exact edited state — not the template.
489
+ if (opts?.overrides)
490
+ applyOverrideSet(parsed, opts.overrides);
491
+ const session = new CompositionImpl(parsed, opts ?? {});
492
+ const isEmbedded = opts?.overrides !== undefined;
493
+ if (!isEmbedded) {
494
+ // history:false opts out of the SDK undo stack ONLY. Persist (auto-save) is
495
+ // independent — gating it on the history flag too would silently drop every
496
+ // disk write for a caller that just wanted to disable undo (data loss).
497
+ if (opts?.history !== false) {
498
+ const history = createHistory(session, {
499
+ coalesceMs: opts?.coalesceMs ?? 300,
500
+ trackedOrigins: opts?.trackedOrigins,
501
+ });
502
+ session.attachHistory(history);
503
+ }
504
+ if (opts?.persist) {
505
+ const pq = createPersistQueue(session, opts.persist, {
506
+ path: opts.persistPath,
507
+ onError: (e) => session._fireError(e),
508
+ });
509
+ session.attachPersistQueue(pq);
510
+ }
511
+ }
512
+ return session;
513
+ }
514
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAuB,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAsBxD,iFAAiF;AAEjF,MAAM,eAAe;IACF,MAAM,CAAiB;IACvB,OAAO,CAA6B;IAC5C,OAAO,CAA6B;IAE7C,iEAAiE;IACzD,SAAS,CAAc;IAE/B,oEAAoE;IAC5D,aAAa,GAA6B,IAAI,CAAC;IAE/C,gBAAgB,GAAa,EAAE,CAAC;IAEhC,cAAc,GAAsB,EAAE,CAAC;IACvC,iBAAiB,GAAmC,EAAE,CAAC;IACvD,aAAa,GAAmC,EAAE,CAAC;IACnD,aAAa,GAA0C,EAAE,CAAC;IAC1D,2BAA2B,GAAwB,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