@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.
- package/LICENSE +190 -0
- package/dist/adapters/fs.d.ts +9 -0
- package/dist/adapters/fs.d.ts.map +1 -0
- package/dist/adapters/fs.js +122 -0
- package/dist/adapters/fs.js.map +1 -0
- package/dist/adapters/headless.d.ts +3 -0
- package/dist/adapters/headless.d.ts.map +1 -0
- package/dist/adapters/headless.js +17 -0
- package/dist/adapters/headless.js.map +1 -0
- package/dist/adapters/iframe.d.ts +102 -0
- package/dist/adapters/iframe.d.ts.map +1 -0
- package/dist/adapters/iframe.js +569 -0
- package/dist/adapters/iframe.js.map +1 -0
- package/dist/adapters/memory.d.ts +5 -0
- package/dist/adapters/memory.d.ts.map +1 -0
- package/dist/adapters/memory.js +54 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/types.d.ts +65 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/document.d.ts +25 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +238 -0
- package/dist/document.js.map +1 -0
- package/dist/engine/apply-patches.d.ts +20 -0
- package/dist/engine/apply-patches.d.ts.map +1 -0
- package/dist/engine/apply-patches.js +284 -0
- package/dist/engine/apply-patches.js.map +1 -0
- package/dist/engine/cssWriter.d.ts +18 -0
- package/dist/engine/cssWriter.d.ts.map +1 -0
- package/dist/engine/cssWriter.js +139 -0
- package/dist/engine/cssWriter.js.map +1 -0
- package/dist/engine/keyframeBackfill.d.ts +17 -0
- package/dist/engine/keyframeBackfill.d.ts.map +1 -0
- package/dist/engine/keyframeBackfill.js +43 -0
- package/dist/engine/keyframeBackfill.js.map +1 -0
- package/dist/engine/model.d.ts +55 -0
- package/dist/engine/model.d.ts.map +1 -0
- package/dist/engine/model.js +256 -0
- package/dist/engine/model.js.map +1 -0
- package/dist/engine/mutate.d.ts +26 -0
- package/dist/engine/mutate.d.ts.map +1 -0
- package/dist/engine/mutate.js +1243 -0
- package/dist/engine/mutate.js.map +1 -0
- package/dist/engine/patches.d.ts +71 -0
- package/dist/engine/patches.d.ts.map +1 -0
- package/dist/engine/patches.js +197 -0
- package/dist/engine/patches.js.map +1 -0
- package/dist/engine/serialize.d.ts +15 -0
- package/dist/engine/serialize.d.ts.map +1 -0
- package/dist/engine/serialize.js +20 -0
- package/dist/engine/serialize.js.map +1 -0
- package/dist/engine/variableModel.d.ts +29 -0
- package/dist/engine/variableModel.d.ts.map +1 -0
- package/dist/engine/variableModel.js +81 -0
- package/dist/engine/variableModel.js.map +1 -0
- package/dist/history.d.ts +39 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +116 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/persist-queue.d.ts +24 -0
- package/dist/persist-queue.d.ts.map +1 -0
- package/dist/persist-queue.js +62 -0
- package/dist/persist-queue.js.map +1 -0
- package/dist/session.d.ts +38 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +514 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +521 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
package/dist/history.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional history module (F5 layering).
|
|
3
|
+
*
|
|
4
|
+
* Wires onto a Composition session via on('patch') and implements undo/redo.
|
|
5
|
+
* Coalesces same-op+same-targets bursts within coalesceMs into one undo entry.
|
|
6
|
+
*
|
|
7
|
+
* Usage (standalone / T1):
|
|
8
|
+
* const comp = await openComposition(html, { persist });
|
|
9
|
+
* // openComposition attaches this automatically in non-embedded mode.
|
|
10
|
+
*
|
|
11
|
+
* Usage (manual / custom undo timeline):
|
|
12
|
+
* const history = createHistory(comp, { coalesceMs: 500, trackedOrigins: ['local'] });
|
|
13
|
+
* // host calls history.undo() / history.redo() instead of comp.undo() / comp.redo()
|
|
14
|
+
*/
|
|
15
|
+
import { ORIGIN_APPLY_PATCHES } from "./types.js";
|
|
16
|
+
export function createHistory(session, opts = {}) {
|
|
17
|
+
const coalesceMs = opts.coalesceMs ?? 300;
|
|
18
|
+
const maxEntries = opts.maxEntries ?? 100;
|
|
19
|
+
const { trackedOrigins } = opts;
|
|
20
|
+
const undoStack = [];
|
|
21
|
+
let redoStack = [];
|
|
22
|
+
function isTracked(origin) {
|
|
23
|
+
if (origin === ORIGIN_APPLY_PATCHES)
|
|
24
|
+
return false;
|
|
25
|
+
if (!trackedOrigins)
|
|
26
|
+
return true;
|
|
27
|
+
return trackedOrigins.includes(origin);
|
|
28
|
+
}
|
|
29
|
+
function pathsKey(patches) {
|
|
30
|
+
return patches
|
|
31
|
+
.map((p) => p.path)
|
|
32
|
+
.sort()
|
|
33
|
+
.join("\n");
|
|
34
|
+
}
|
|
35
|
+
function opTypesKey(opTypes) {
|
|
36
|
+
// Sorted: the same op-type SET coalesces regardless of dispatch order.
|
|
37
|
+
return [...opTypes].sort().join(",");
|
|
38
|
+
}
|
|
39
|
+
function shouldCoalesce(entry, incoming) {
|
|
40
|
+
if (coalesceMs <= 0)
|
|
41
|
+
return false;
|
|
42
|
+
if (opTypesKey(entry.opTypes) !== opTypesKey(incoming.opTypes))
|
|
43
|
+
return false;
|
|
44
|
+
if (entry.origin !== incoming.origin)
|
|
45
|
+
return false;
|
|
46
|
+
// Coalesce only when the SAME paths are touched (e.g. slider drag on one
|
|
47
|
+
// property). Without this, rapid edits to different elements would merge
|
|
48
|
+
// into one entry holding the second forward + first inverse — undo would
|
|
49
|
+
// then revert the wrong element.
|
|
50
|
+
if (pathsKey(entry.patches) !== pathsKey(incoming.patches))
|
|
51
|
+
return false;
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
return now - entry.timestamp <= coalesceMs;
|
|
54
|
+
}
|
|
55
|
+
// fallow-ignore-next-line complexity
|
|
56
|
+
const unsubscribe = session.on("patch", (event) => {
|
|
57
|
+
if (!isTracked(event.origin))
|
|
58
|
+
return;
|
|
59
|
+
const last = undoStack[undoStack.length - 1];
|
|
60
|
+
if (last && shouldCoalesce(last, event)) {
|
|
61
|
+
// Coalesce: keep first inverse (original prev), replace forward with latest value.
|
|
62
|
+
// Slide timestamp forward so rapid-fire edits keep coalescing.
|
|
63
|
+
const coalesced = {
|
|
64
|
+
patches: event.patches,
|
|
65
|
+
inversePatches: last.inversePatches,
|
|
66
|
+
opTypes: last.opTypes,
|
|
67
|
+
origin: last.origin,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
};
|
|
70
|
+
undoStack[undoStack.length - 1] = coalesced;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
undoStack.push({
|
|
74
|
+
patches: event.patches,
|
|
75
|
+
inversePatches: event.inversePatches,
|
|
76
|
+
opTypes: event.opTypes,
|
|
77
|
+
origin: event.origin,
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
});
|
|
80
|
+
if (undoStack.length > maxEntries)
|
|
81
|
+
undoStack.shift();
|
|
82
|
+
}
|
|
83
|
+
// Any new op clears the redo stack.
|
|
84
|
+
redoStack = [];
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
undo() {
|
|
88
|
+
const entry = undoStack.pop();
|
|
89
|
+
if (!entry)
|
|
90
|
+
return false;
|
|
91
|
+
session.applyPatches(entry.inversePatches, { origin: ORIGIN_APPLY_PATCHES });
|
|
92
|
+
redoStack.push(entry);
|
|
93
|
+
return true;
|
|
94
|
+
},
|
|
95
|
+
redo() {
|
|
96
|
+
const entry = redoStack.pop();
|
|
97
|
+
if (!entry)
|
|
98
|
+
return false;
|
|
99
|
+
session.applyPatches(entry.patches, { origin: ORIGIN_APPLY_PATCHES });
|
|
100
|
+
undoStack.push(entry);
|
|
101
|
+
return true;
|
|
102
|
+
},
|
|
103
|
+
canUndo() {
|
|
104
|
+
return undoStack.length > 0;
|
|
105
|
+
},
|
|
106
|
+
canRedo() {
|
|
107
|
+
return redoStack.length > 0;
|
|
108
|
+
},
|
|
109
|
+
dispose() {
|
|
110
|
+
unsubscribe();
|
|
111
|
+
undoStack.length = 0;
|
|
112
|
+
redoStack.length = 0;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA2BlD,MAAM,UAAU,aAAa,CAAC,OAAoB,EAAE,OAAuB,EAAE;IAC3E,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC;IAC1C,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAEhC,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,IAAI,SAAS,GAAmB,EAAE,CAAC;IAEnC,SAAS,SAAS,CAAC,MAAe;QAChC,IAAI,MAAM,KAAK,oBAAoB;YAAE,OAAO,KAAK,CAAC;QAClD,IAAI,CAAC,cAAc;YAAE,OAAO,IAAI,CAAC;QACjC,OAAO,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,SAAS,QAAQ,CAAC,OAA+B;QAC/C,OAAO,OAAO;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAClB,IAAI,EAAE;aACN,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,SAAS,UAAU,CAAC,OAA0B;QAC5C,uEAAuE;QACvE,OAAO,CAAC,G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AM,GAAG,CAAC,CAAC;QAC9B,CAAC;QAED,OAAO;YACL,WAAW,EAAE,CAAC;YACd,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACrB,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { HyperFramesElement, SdkDocument, OverrideSet, EditOp, ElasticHold, FontValue, ImageValue, GsapTweenSpec, HfId, JsonPatchOp, PatchEvent, PersistErrorEvent, ElementSnapshot, ElementTimingSnapshot, FindQuery, SelectionProxy, ElementHandle, Composition, CanResult, } from "./types.js";
|
|
2
|
+
export { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
|
|
3
|
+
export { UnsupportedOpError } from "./engine/mutate.js";
|
|
4
|
+
export { buildDocument, buildRoots, flatElements } from "./document.js";
|
|
5
|
+
export { openComposition } from "./session.js";
|
|
6
|
+
export type { OpenCompositionOptions } from "./session.js";
|
|
7
|
+
export { createHistory } from "./history.js";
|
|
8
|
+
export type { HistoryModule, HistoryOptions, HistoryEntry } from "./history.js";
|
|
9
|
+
export { createPersistQueue } from "./persist-queue.js";
|
|
10
|
+
export type { PersistQueueModule, PersistQueueOptions } from "./persist-queue.js";
|
|
11
|
+
export type { PersistAdapter, PreviewAdapter, PersistVersionEntry } from "./adapters/types.js";
|
|
12
|
+
export { createMemoryAdapter } from "./adapters/memory.js";
|
|
13
|
+
export { createHeadlessAdapter } from "./adapters/headless.js";
|
|
14
|
+
export { createIframePreviewAdapter, resolveNearestHfElement } from "./adapters/iframe.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElF,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
|
|
2
|
+
export { UnsupportedOpError } from "./engine/mutate.js";
|
|
3
|
+
export { buildDocument, buildRoots, flatElements } from "./document.js";
|
|
4
|
+
export { openComposition } from "./session.js";
|
|
5
|
+
export { createHistory } from "./history.js";
|
|
6
|
+
export { createPersistQueue } from "./persist-queue.js";
|
|
7
|
+
// Concrete adapter factories (browser-safe — Node-only fs adapter: @hyperframes/sdk/adapters/fs).
|
|
8
|
+
export { createMemoryAdapter } from "./adapters/memory.js";
|
|
9
|
+
export { createHeadlessAdapter } from "./adapters/headless.js";
|
|
10
|
+
export { createIframePreviewAdapter, resolveNearestHfElement } from "./adapters/iframe.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAKxD,kGAAkG;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional persist queue module (F5 layering).
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to 'change' events and schedules async writes via a PersistAdapter.
|
|
5
|
+
* One in-flight write at a time; latest state always wins (last-write-wins coalescing).
|
|
6
|
+
*
|
|
7
|
+
* Wired automatically by openComposition() in standalone (T1/T2) mode.
|
|
8
|
+
* T3 (embedded) hosts own persistence — do not use this module.
|
|
9
|
+
*/
|
|
10
|
+
import type { Composition, PersistErrorEvent } from "./types.js";
|
|
11
|
+
import type { PersistAdapter } from "./adapters/types.js";
|
|
12
|
+
export interface PersistQueueModule {
|
|
13
|
+
/** Force an immediate write (e.g. before app close). */
|
|
14
|
+
flush(): Promise<void>;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface PersistQueueOptions {
|
|
18
|
+
/** Adapter path to write to. Default: "composition.html" */
|
|
19
|
+
path?: string;
|
|
20
|
+
/** Called when adapter.write() rejects. */
|
|
21
|
+
onError?: (e: PersistErrorEvent) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createPersistQueue(session: Composition, adapter: PersistAdapter, opts?: PersistQueueOptions): PersistQueueModule;
|
|
24
|
+
//# sourceMappingURL=persist-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persist-queue.d.ts","sourceRoot":"","sources":["../src/persist-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC1C;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,cAAc,EACvB,IAAI,GAAE,mBAAwB,GAC7B,kBAAkB,CAoDpB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional persist queue module (F5 layering).
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to 'change' events and schedules async writes via a PersistAdapter.
|
|
5
|
+
* One in-flight write at a time; latest state always wins (last-write-wins coalescing).
|
|
6
|
+
*
|
|
7
|
+
* Wired automatically by openComposition() in standalone (T1/T2) mode.
|
|
8
|
+
* T3 (embedded) hosts own persistence — do not use this module.
|
|
9
|
+
*/
|
|
10
|
+
export function createPersistQueue(session, adapter, opts = {}) {
|
|
11
|
+
const path = opts.path ?? "composition.html";
|
|
12
|
+
let pendingWrite = null;
|
|
13
|
+
// Promise-chain mutex: each write chains onto the prior, preventing concurrent writes.
|
|
14
|
+
let writeChain = Promise.resolve();
|
|
15
|
+
let disposed = false;
|
|
16
|
+
function scheduleWrite() {
|
|
17
|
+
if (pendingWrite !== null)
|
|
18
|
+
clearTimeout(pendingWrite);
|
|
19
|
+
pendingWrite = setTimeout(() => {
|
|
20
|
+
pendingWrite = null;
|
|
21
|
+
void doWrite();
|
|
22
|
+
}, 0);
|
|
23
|
+
}
|
|
24
|
+
function doWrite() {
|
|
25
|
+
if (disposed)
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
const content = session.serialize();
|
|
28
|
+
writeChain = writeChain.then(async () => {
|
|
29
|
+
if (disposed)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
await adapter.write(path, content);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
36
|
+
opts.onError?.({ error: { message, cause: err } });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return writeChain;
|
|
40
|
+
}
|
|
41
|
+
const unsubscribe = session.on("change", () => {
|
|
42
|
+
scheduleWrite();
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
async flush() {
|
|
46
|
+
if (pendingWrite !== null) {
|
|
47
|
+
clearTimeout(pendingWrite);
|
|
48
|
+
pendingWrite = null;
|
|
49
|
+
}
|
|
50
|
+
await doWrite();
|
|
51
|
+
},
|
|
52
|
+
dispose() {
|
|
53
|
+
disposed = true;
|
|
54
|
+
if (pendingWrite !== null) {
|
|
55
|
+
clearTimeout(pendingWrite);
|
|
56
|
+
pendingWrite = null;
|
|
57
|
+
}
|
|
58
|
+
unsubscribe();
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=persist-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persist-queue.js","sourceRoot":"","sources":["../src/persist-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkBH,MAAM,UAAU,kBAAkB,CAChC,OAAoB,EACpB,OAAuB,EACvB,OAA4B,EAAE;IAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,kBAAkB,CAAC;IAC7C,IAAI,YAAY,GAAyC,IAAI,CAAC;IAC9D,uFAAuF;IACvF,IAAI,UAAU,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAClD,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,SAAS,aAAa;QACpB,IAAI,YAAY,KAAK,IAAI;YAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QACtD,YAAY,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,YAAY,GAAG,IAAI,CAAC;YACpB,KAAK,OAAO,EAAE,CAAC;QACjB,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAED,SAAS,OAAO;QACd,IAAI,QAAQ;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QACpC,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YACtC,IAAI,QAAQ;gBAAE,OAAO;YACrB,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjE,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QAC5C,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,CAAC,KAAK;YACT,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;gBAC1B,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC3B,YAAY,GAAG,IAAI,CAAC;YACtB,CAAC;YACD,MAAM,OAAO,EAAE,CAAC;QAClB,CAAC;QAED,OAAO;YACL,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;gBAC1B,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC3B,YAAY,GAAG,IAAI,CAAC;YACtB,CAAC;YACD,WAAW,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 type { Composition, OverrideSet } from "./types.js";
|
|
11
|
+
import type { PersistAdapter, PreviewAdapter } from "./adapters/types.js";
|
|
12
|
+
export interface OpenCompositionOptions {
|
|
13
|
+
persist?: PersistAdapter;
|
|
14
|
+
/** Adapter path the persist queue writes to. Default: "composition.html". Immutable for the session lifetime. */
|
|
15
|
+
persistPath?: string;
|
|
16
|
+
preview?: PreviewAdapter;
|
|
17
|
+
/** T3 embedded mode: override-set applied on top of the base template. */
|
|
18
|
+
overrides?: OverrideSet;
|
|
19
|
+
/** Origins whose mutations enter the undo stack. Default: all non-applyPatches. */
|
|
20
|
+
trackedOrigins?: unknown[];
|
|
21
|
+
/** Auto-coalesce window for history entries (ms). Default: 300. */
|
|
22
|
+
coalesceMs?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Pass `false` to skip attaching the history module (undo/redo).
|
|
25
|
+
* Default: history is attached in standalone (non-embedded) mode.
|
|
26
|
+
* Use when the host owns the undo stack and SDK undo is dead weight.
|
|
27
|
+
*/
|
|
28
|
+
history?: false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Open a composition for editing.
|
|
32
|
+
*
|
|
33
|
+
* Standalone (T1/T2): supply persist adapter — SDK owns history + auto-save.
|
|
34
|
+
* Embedded (T3): supply overrides — SDK emits patches; host owns history + persistence.
|
|
35
|
+
* Headless (agents): omit both — SDK is a stateless transform + serializer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function openComposition(html: string, opts?: OpenCompositionOptions): Promise<Composition>;
|
|
38
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,WAAW,EAYX,WAAW,EAKZ,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAc1E,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iHAAiH;IACjH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,mFAAmF;IACnF,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;IAC3B,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB;AA+iBD;;;;;;GAMG;AAEH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,sBAAsB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
|