@hyperframes/sdk 0.7.45 → 0.7.47
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/adapters/headless.d.ts.map +1 -1
- package/dist/adapters/headless.js +3 -0
- package/dist/adapters/headless.js.map +1 -1
- package/dist/adapters/iframe.d.ts.map +1 -1
- package/dist/adapters/iframe.js +40 -0
- package/dist/adapters/iframe.js.map +1 -1
- package/dist/adapters/types.d.ts +19 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/engine/apply-patches.d.ts.map +1 -1
- package/dist/engine/apply-patches.js +46 -7
- package/dist/engine/apply-patches.js.map +1 -1
- package/dist/engine/model.d.ts +8 -0
- package/dist/engine/model.d.ts.map +1 -1
- package/dist/engine/model.js +17 -2
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/mutate.d.ts.map +1 -1
- package/dist/engine/mutate.js +209 -29
- package/dist/engine/mutate.js.map +1 -1
- package/dist/engine/patches.d.ts +5 -1
- package/dist/engine/patches.d.ts.map +1 -1
- package/dist/engine/patches.js +16 -1
- package/dist/engine/patches.js.map +1 -1
- package/dist/engine/variableModel.d.ts +46 -4
- package/dist/engine/variableModel.d.ts.map +1 -1
- package/dist/engine/variableModel.js +96 -17
- package/dist/engine/variableModel.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +132 -1
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
package/dist/engine/patches.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* /elements/{hfId}/timing/{start|end|duration|trackIndex} ← end = computed absolute data-end
|
|
9
9
|
* /elements/{hfId}/hold/{start|end|fill}
|
|
10
10
|
* /elements/{hfId} ← whole subtree (removeElement)
|
|
11
|
-
* /variables/{variableId}
|
|
11
|
+
* /variables/{variableId} ← declaration's default value
|
|
12
|
+
* /variableDeclarations/{variableId} ← whole declaration object
|
|
12
13
|
* /metadata/{width|height|duration}
|
|
13
14
|
* /script/gsap ← GSAP inline script textContent
|
|
14
15
|
* /style/css ← <style> element textContent
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
* /elements/hf-x/hold/start → "hf-x.hold.start"
|
|
22
23
|
* /elements/hf-x → "hf-x" (null = removal marker)
|
|
23
24
|
* /variables/brand-color-primary → "var.brand-color-primary"
|
|
25
|
+
* /variableDeclarations/brand-color-primary → "varDecl.brand-color-primary"
|
|
24
26
|
* /metadata/width → "meta.width"
|
|
25
27
|
* /script/gsap → "script.gsap"
|
|
26
28
|
* /style/css → "style.css"
|
|
@@ -62,6 +64,10 @@ export function elementPath(id) {
|
|
|
62
64
|
export function variablePath(id) {
|
|
63
65
|
return `/variables/${id}`;
|
|
64
66
|
}
|
|
67
|
+
/** Whole-declaration path — distinct from /variables/{id}, which is the default *value*. */
|
|
68
|
+
export function variableDeclPath(id) {
|
|
69
|
+
return `/variableDeclarations/${id}`;
|
|
70
|
+
}
|
|
65
71
|
export function metaPath(field) {
|
|
66
72
|
return `/metadata/${field}`;
|
|
67
73
|
}
|
|
@@ -103,6 +109,10 @@ export function pathToKey(path) {
|
|
|
103
109
|
const elemMatch = /^\/elements\/([^/]+)$/.exec(path);
|
|
104
110
|
if (elemMatch)
|
|
105
111
|
return decodePathSegment(elemMatch[1]);
|
|
112
|
+
// /variableDeclarations/{id} → "varDecl.{id}" (checked before /variables/)
|
|
113
|
+
const varDeclMatch = /^\/variableDeclarations\/(.+)$/.exec(path);
|
|
114
|
+
if (varDeclMatch)
|
|
115
|
+
return `varDecl.${varDeclMatch[1]}`;
|
|
106
116
|
// /variables/{id} → "var.{id}"
|
|
107
117
|
const varMatch = /^\/variables\/(.+)$/.exec(path);
|
|
108
118
|
if (varMatch)
|
|
@@ -123,6 +133,8 @@ export function pathToKey(path) {
|
|
|
123
133
|
* Inverse of pathToKey — maps an override-set key back to its RFC 6902 path.
|
|
124
134
|
* Used to replay a stored override-set onto a fresh base document (T3 init).
|
|
125
135
|
*/
|
|
136
|
+
// Exhaustive key-family dispatcher — same shape as apply-patches.ts parsePath.
|
|
137
|
+
// fallow-ignore-next-line complexity
|
|
126
138
|
export function keyToPath(key) {
|
|
127
139
|
const style = /^([^.]+)\.style\.(.+)$/.exec(key);
|
|
128
140
|
if (style?.[1] && style[2])
|
|
@@ -142,6 +154,9 @@ export function keyToPath(key) {
|
|
|
142
154
|
const hold = /^([^.]+)\.hold\.(start|end|fill)$/.exec(key);
|
|
143
155
|
if (hold?.[1])
|
|
144
156
|
return holdPath(hold[1], hold[2]);
|
|
157
|
+
const varDecl = /^varDecl\.(.+)$/.exec(key);
|
|
158
|
+
if (varDecl?.[1])
|
|
159
|
+
return variableDeclPath(varDecl[1]);
|
|
145
160
|
const variable = /^var\.(.+)$/.exec(key);
|
|
146
161
|
if (variable?.[1])
|
|
147
162
|
return variablePath(variable[1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patches.js","sourceRoot":"","sources":["../../src/engine/patches.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"patches.js","sourceRoot":"","sources":["../../src/engine/patches.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,iFAAiF;AAEjF;;;;GAIG;AACH,SAAS,eAAe,CAAC,EAAU;IACjC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,2FAA2F;AAC3F,SAAS,iBAAiB,CAAC,OAAe;IACxC,4DAA4D;IAC5D,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAA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C;IAC5F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,QAAiB,EACjB,QAAiB;IAEjB,MAAM,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC3F,MAAM,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,QAAmC;IAEnC,OAAO;QACL,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -1,23 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared helpers for the composition variable JSON model
|
|
3
|
-
* (`data-composition-variables`
|
|
3
|
+
* (`data-composition-variables`). The declaration-carrying element is resolved
|
|
4
|
+
* by the caller (`declarationElement` in model.ts): `<html>` for full-document
|
|
5
|
+
* comps, the composition root div for wrapped template/fragment comps.
|
|
4
6
|
*
|
|
5
7
|
* Single source for the parse → find-by-id → read/write/clear logic so the
|
|
6
8
|
* forward-mutation path (engine/mutate.ts) and the patch-replay path
|
|
7
9
|
* (engine/apply-patches.ts) can never disagree on the model's shape.
|
|
8
10
|
*/
|
|
11
|
+
import type { CompositionVariable } from "@hyperframes/core/variables";
|
|
12
|
+
export type VariableDecl = {
|
|
13
|
+
id: string;
|
|
14
|
+
default?: unknown;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Read the typed variable declarations from `data-composition-variables`.
|
|
19
|
+
* Delegates to the canonical parser (same filter the render pipeline uses),
|
|
20
|
+
* so malformed entries are dropped rather than surfaced. Returns `[]` when
|
|
21
|
+
* the declaration element is absent or has no declarations.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readVariableDeclarations(declEl: Element | null): CompositionVariable[];
|
|
24
|
+
/**
|
|
25
|
+
* Find the raw declaration entry for a variable id, verbatim (unvalidated).
|
|
26
|
+
* Returns undefined when the attribute is absent, the JSON is invalid, or no
|
|
27
|
+
* entry matches the id.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findVariableDeclaration(declEl: Element | null, id: string): VariableDecl | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Upsert a whole variable declaration by its id. Creates the
|
|
32
|
+
* `data-composition-variables` attribute when absent; replaces an unparseable
|
|
33
|
+
* attribute with a fresh single-entry array (the prior content was invisible
|
|
34
|
+
* to every reader anyway). Returns false only when there is no declaration
|
|
35
|
+
* element to carry the attribute.
|
|
36
|
+
*
|
|
37
|
+
* Accepts raw (unvalidated) entries as well as typed declarations: the patch
|
|
38
|
+
* REPLAY path must faithfully restore whatever entry the inverse patch
|
|
39
|
+
* captured — including loose hand-authored declarations the strict parser
|
|
40
|
+
* would drop — or undo silently diverges from history.
|
|
41
|
+
*/
|
|
42
|
+
export declare function writeVariableDeclaration(declEl: Element | null, declaration: CompositionVariable | ({
|
|
43
|
+
id: string;
|
|
44
|
+
} & Record<string, unknown>)): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Remove a variable declaration by id. Drops the whole attribute when the
|
|
47
|
+
* last declaration is removed (an empty `[]` is noise in authored HTML).
|
|
48
|
+
* No-ops (returns false) when the attribute or the entry is absent.
|
|
49
|
+
*/
|
|
50
|
+
export declare function removeVariableDeclarationEntry(declEl: Element | null, id: string): boolean;
|
|
9
51
|
/**
|
|
10
52
|
* Read the current `default` value for a variable id. Returns undefined when
|
|
11
53
|
* the attribute is absent, the JSON is invalid, or no entry matches the id.
|
|
12
54
|
*/
|
|
13
|
-
export declare function readVariableDefault(
|
|
55
|
+
export declare function readVariableDefault(declEl: Element | null, id: string): unknown;
|
|
14
56
|
/**
|
|
15
57
|
* Upsert a variable's `default`. No-ops (returns false) when the attribute is
|
|
16
58
|
* absent or contains no declaration for the id — we never auto-add declarations
|
|
17
59
|
* for undeclared variables, keeping the schema authoritative. Returns true when
|
|
18
60
|
* the attribute was updated.
|
|
19
61
|
*/
|
|
20
|
-
export declare function writeVariableDefault(
|
|
62
|
+
export declare function writeVariableDefault(declEl: Element | null, id: string, newDefault: unknown): boolean;
|
|
21
63
|
/**
|
|
22
64
|
* Remove the `default` key from a variable declaration, restoring its
|
|
23
65
|
* "no authored default" state. This is the exact inverse of writeVariableDefault
|
|
@@ -25,5 +67,5 @@ export declare function writeVariableDefault(document: Document, id: string, new
|
|
|
25
67
|
* default-less variable round-trips. No-ops when the decl or key is absent.
|
|
26
68
|
* Returns true when the attribute was updated.
|
|
27
69
|
*/
|
|
28
|
-
export declare function clearVariableDefault(
|
|
70
|
+
export declare function clearVariableDefault(declEl: Element | null, id: string): boolean;
|
|
29
71
|
//# sourceMappingURL=variableModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variableModel.d.ts","sourceRoot":"","sources":["../../src/engine/variableModel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"variableModel.d.ts","sourceRoot":"","sources":["../../src/engine/variableModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAqBrF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,GAAG,mBAAmB,EAAE,CAGtF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,EAAE,EAAE,MAAM,GACT,YAAY,GAAG,SAAS,CAK1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,WAAW,EAAE,mBAAmB,GAAG,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC5E,OAAO,CAaT;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAY1F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAK/E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,OAAO,GAClB,OAAO,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAShF"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared helpers for the composition variable JSON model
|
|
3
|
-
* (`data-composition-variables`
|
|
3
|
+
* (`data-composition-variables`). The declaration-carrying element is resolved
|
|
4
|
+
* by the caller (`declarationElement` in model.ts): `<html>` for full-document
|
|
5
|
+
* comps, the composition root div for wrapped template/fragment comps.
|
|
4
6
|
*
|
|
5
7
|
* Single source for the parse → find-by-id → read/write/clear logic so the
|
|
6
8
|
* forward-mutation path (engine/mutate.ts) and the patch-replay path
|
|
7
9
|
* (engine/apply-patches.ts) can never disagree on the model's shape.
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
11
|
+
// Browser-safe subpath — the core/parsers root entries pull Node-only modules
|
|
12
|
+
// and would break browser bundles that include the SDK (e.g. Studio).
|
|
13
|
+
import { parseCompositionVariables } from "@hyperframes/core/variables";
|
|
12
14
|
/** Parse the variable declaration array, or null when absent/invalid. */
|
|
13
|
-
function readDecls(
|
|
14
|
-
|
|
15
|
-
if (!htmlEl)
|
|
15
|
+
function readDecls(declEl) {
|
|
16
|
+
if (!declEl)
|
|
16
17
|
return null;
|
|
17
|
-
const raw =
|
|
18
|
+
const raw = declEl.getAttribute("data-composition-variables");
|
|
18
19
|
if (!raw)
|
|
19
20
|
return null;
|
|
20
21
|
let parsed;
|
|
@@ -26,17 +27,89 @@ function readDecls(document) {
|
|
|
26
27
|
}
|
|
27
28
|
if (!Array.isArray(parsed))
|
|
28
29
|
return null;
|
|
29
|
-
return {
|
|
30
|
+
return { declEl, arr: parsed };
|
|
30
31
|
}
|
|
31
32
|
function indexOfId(arr, id) {
|
|
32
33
|
return arr.findIndex((v) => typeof v === "object" && v !== null && v.id === id);
|
|
33
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Read the typed variable declarations from `data-composition-variables`.
|
|
37
|
+
* Delegates to the canonical parser (same filter the render pipeline uses),
|
|
38
|
+
* so malformed entries are dropped rather than surfaced. Returns `[]` when
|
|
39
|
+
* the declaration element is absent or has no declarations.
|
|
40
|
+
*/
|
|
41
|
+
export function readVariableDeclarations(declEl) {
|
|
42
|
+
if (!declEl)
|
|
43
|
+
return [];
|
|
44
|
+
return parseCompositionVariables(declEl);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Find the raw declaration entry for a variable id, verbatim (unvalidated).
|
|
48
|
+
* Returns undefined when the attribute is absent, the JSON is invalid, or no
|
|
49
|
+
* entry matches the id.
|
|
50
|
+
*/
|
|
51
|
+
export function findVariableDeclaration(declEl, id) {
|
|
52
|
+
const decls = readDecls(declEl);
|
|
53
|
+
if (!decls)
|
|
54
|
+
return undefined;
|
|
55
|
+
const idx = indexOfId(decls.arr, id);
|
|
56
|
+
return idx < 0 ? undefined : decls.arr[idx];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Upsert a whole variable declaration by its id. Creates the
|
|
60
|
+
* `data-composition-variables` attribute when absent; replaces an unparseable
|
|
61
|
+
* attribute with a fresh single-entry array (the prior content was invisible
|
|
62
|
+
* to every reader anyway). Returns false only when there is no declaration
|
|
63
|
+
* element to carry the attribute.
|
|
64
|
+
*
|
|
65
|
+
* Accepts raw (unvalidated) entries as well as typed declarations: the patch
|
|
66
|
+
* REPLAY path must faithfully restore whatever entry the inverse patch
|
|
67
|
+
* captured — including loose hand-authored declarations the strict parser
|
|
68
|
+
* would drop — or undo silently diverges from history.
|
|
69
|
+
*/
|
|
70
|
+
export function writeVariableDeclaration(declEl, declaration) {
|
|
71
|
+
if (!declEl)
|
|
72
|
+
return false;
|
|
73
|
+
const decls = readDecls(declEl);
|
|
74
|
+
const arr = decls?.arr ?? [];
|
|
75
|
+
const idx = indexOfId(arr, declaration.id);
|
|
76
|
+
const entry = { ...declaration };
|
|
77
|
+
if (idx < 0) {
|
|
78
|
+
arr.push(entry);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
arr[idx] = entry;
|
|
82
|
+
}
|
|
83
|
+
declEl.setAttribute("data-composition-variables", JSON.stringify(arr));
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove a variable declaration by id. Drops the whole attribute when the
|
|
88
|
+
* last declaration is removed (an empty `[]` is noise in authored HTML).
|
|
89
|
+
* No-ops (returns false) when the attribute or the entry is absent.
|
|
90
|
+
*/
|
|
91
|
+
export function removeVariableDeclarationEntry(declEl, id) {
|
|
92
|
+
const decls = readDecls(declEl);
|
|
93
|
+
if (!decls)
|
|
94
|
+
return false;
|
|
95
|
+
const idx = indexOfId(decls.arr, id);
|
|
96
|
+
if (idx < 0)
|
|
97
|
+
return false;
|
|
98
|
+
decls.arr.splice(idx, 1);
|
|
99
|
+
if (decls.arr.length === 0) {
|
|
100
|
+
decls.declEl.removeAttribute("data-composition-variables");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
decls.declEl.setAttribute("data-composition-variables", JSON.stringify(decls.arr));
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
34
107
|
/**
|
|
35
108
|
* Read the current `default` value for a variable id. Returns undefined when
|
|
36
109
|
* the attribute is absent, the JSON is invalid, or no entry matches the id.
|
|
37
110
|
*/
|
|
38
|
-
export function readVariableDefault(
|
|
39
|
-
const decls = readDecls(
|
|
111
|
+
export function readVariableDefault(declEl, id) {
|
|
112
|
+
const decls = readDecls(declEl);
|
|
40
113
|
if (!decls)
|
|
41
114
|
return undefined;
|
|
42
115
|
const idx = indexOfId(decls.arr, id);
|
|
@@ -48,15 +121,15 @@ export function readVariableDefault(document, id) {
|
|
|
48
121
|
* for undeclared variables, keeping the schema authoritative. Returns true when
|
|
49
122
|
* the attribute was updated.
|
|
50
123
|
*/
|
|
51
|
-
export function writeVariableDefault(
|
|
52
|
-
const decls = readDecls(
|
|
124
|
+
export function writeVariableDefault(declEl, id, newDefault) {
|
|
125
|
+
const decls = readDecls(declEl);
|
|
53
126
|
if (!decls)
|
|
54
127
|
return false;
|
|
55
128
|
const idx = indexOfId(decls.arr, id);
|
|
56
129
|
if (idx < 0)
|
|
57
130
|
return false; // variable not declared — don't auto-add
|
|
58
131
|
decls.arr[idx] = { ...decls.arr[idx], default: newDefault };
|
|
59
|
-
decls.
|
|
132
|
+
decls.declEl.setAttribute("data-composition-variables", JSON.stringify(decls.arr));
|
|
60
133
|
return true;
|
|
61
134
|
}
|
|
62
135
|
/**
|
|
@@ -66,8 +139,8 @@ export function writeVariableDefault(document, id, newDefault) {
|
|
|
66
139
|
* default-less variable round-trips. No-ops when the decl or key is absent.
|
|
67
140
|
* Returns true when the attribute was updated.
|
|
68
141
|
*/
|
|
69
|
-
export function clearVariableDefault(
|
|
70
|
-
const decls = readDecls(
|
|
142
|
+
export function clearVariableDefault(declEl, id) {
|
|
143
|
+
const decls = readDecls(declEl);
|
|
71
144
|
if (!decls)
|
|
72
145
|
return false;
|
|
73
146
|
const idx = indexOfId(decls.arr, id);
|
|
@@ -75,7 +148,13 @@ export function clearVariableDefault(document, id) {
|
|
|
75
148
|
return false;
|
|
76
149
|
const { default: _drop, ...rest } = decls.arr[idx];
|
|
77
150
|
decls.arr[idx] = rest;
|
|
78
|
-
decls.
|
|
151
|
+
decls.declEl.setAttribute("data-composition-variables", JSON.stringify(decls.arr));
|
|
79
152
|
return true;
|
|
80
153
|
}
|
|
154
|
+
// NOTE: #2098's Document-based helpers (listVariableDecls / declareVariableDecl /
|
|
155
|
+
// removeVariableDecl) were removed in the #2098-reconciliation — they duplicated
|
|
156
|
+
// the canonical declEl-based readVariableDeclarations / writeVariableDeclaration /
|
|
157
|
+
// removeVariableDeclarationEntry below and predate template/fragment declaration
|
|
158
|
+
// scope. The session conveniences (listVariables / removeVariable) delegate to
|
|
159
|
+
// the canonical methods instead.
|
|
81
160
|
//# sourceMappingURL=variableModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variableModel.js","sourceRoot":"","sources":["../../src/engine/variableModel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"variableModel.js","sourceRoot":"","sources":["../../src/engine/variableModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,8EAA8E;AAC9E,sEAAsE;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAMxE,yEAAyE;AACzE,SAAS,SAAS,CAAC,MAAsB;IACvC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAA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AO,KAAK,CAAC;IACzB,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,IAAI,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACpD,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAoB,CAAC;IACtC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,4BAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACnF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kFAAkF;AAClF,iFAAiF;AACjF,mFAAmF;AACnF,iFAAiF;AACjF,+EAA+E;AAC/E,iCAAiC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
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
2
|
export { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
|
|
3
|
+
export type { CompositionVariable, CompositionVariableType, CompositionVariableBase, StringVariable, NumberVariable, ColorVariable, BooleanVariable, EnumVariable, FontVariable, ImageVariable, VariableValidationIssue, VariableUsageScan, } from "@hyperframes/core/variables";
|
|
4
|
+
export type { VariableUsageReport } from "./types.js";
|
|
3
5
|
export { UnsupportedOpError } from "./engine/mutate.js";
|
|
4
6
|
export { buildDocument, buildRoots, flatElements } from "./document.js";
|
|
5
|
-
export { isNewHostBoundary, bareId } from "./engine/model.js";
|
|
7
|
+
export { isNewHostBoundary, bareId, resolveScoped, findById, escapeHfId } from "./engine/model.js";
|
|
8
|
+
export { readVariableDefault } from "./engine/variableModel.js";
|
|
6
9
|
export { openComposition } from "./session.js";
|
|
7
10
|
export type { OpenCompositionOptions } from "./session.js";
|
|
8
11
|
export { createHistory } from "./history.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAIhE,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,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
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
|
|
2
2
|
export { UnsupportedOpError } from "./engine/mutate.js";
|
|
3
3
|
export { buildDocument, buildRoots, flatElements } from "./document.js";
|
|
4
|
-
export { isNewHostBoundary, bareId } from "./engine/model.js";
|
|
4
|
+
export { isNewHostBoundary, bareId, resolveScoped, findById, escapeHfId } from "./engine/model.js";
|
|
5
|
+
export { readVariableDefault } from "./engine/variableModel.js";
|
|
5
6
|
export { openComposition } from "./session.js";
|
|
6
7
|
export { createHistory } from "./history.js";
|
|
7
8
|
export { createPersistQueue } from "./persist-queue.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAoBhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,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"}
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,WAAW,EAYX,WAAW,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,WAAW,EAYX,WAAW,EAMZ,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAuB1E,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+wBD;;;;;;GAMG;AAEH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,sBAAsB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
|
package/dist/session.js
CHANGED
|
@@ -11,16 +11,22 @@ import { ORIGIN_APPLY_PATCHES, ORIGIN_LOCAL } from "./types.js";
|
|
|
11
11
|
import { buildRoots, flatElements, parsedAnimationIds } from "./document.js";
|
|
12
12
|
import { parseMutable } from "./engine/model.js";
|
|
13
13
|
import { applyOp, validateOp } from "./engine/mutate.js";
|
|
14
|
-
import { getGsapScript, resolveScoped } from "./engine/model.js";
|
|
14
|
+
import { getGsapScript, resolveScoped, declarationElement } from "./engine/model.js";
|
|
15
15
|
import { extractGsapLabels } from "@hyperframes/core/gsap-parser-acorn";
|
|
16
16
|
import { stripEmbeddedRuntimeScripts } from "@hyperframes/core/compiler/html-document";
|
|
17
17
|
import { parseStartExpression } from "@hyperframes/core/runtime/start-expression";
|
|
18
|
+
import { readDeclaredDefaults, validateVariables, scanVariableUsage, } from "@hyperframes/core/variables";
|
|
19
|
+
import { readVariableDeclarations } from "./engine/variableModel.js";
|
|
18
20
|
import { serializeDocument } from "./engine/serialize.js";
|
|
19
21
|
import { applyPatchesToDocument, applyOverrideSet } from "./engine/apply-patches.js";
|
|
20
22
|
import { buildPatchEvent, pathToKey } from "./engine/patches.js";
|
|
21
23
|
import { createHistory } from "./history.js";
|
|
22
24
|
import { createPersistQueue } from "./persist-queue.js";
|
|
23
25
|
// ─── Implementation ───────────────────────────────────────────────────────────
|
|
26
|
+
/** Escape a string for literal use inside a RegExp. */
|
|
27
|
+
function escapeRegExp(s) {
|
|
28
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
29
|
+
}
|
|
24
30
|
class CompositionImpl {
|
|
25
31
|
parsed;
|
|
26
32
|
persist;
|
|
@@ -88,6 +94,131 @@ class CompositionImpl {
|
|
|
88
94
|
setVariableValue(id, value) {
|
|
89
95
|
this.dispatch({ type: "setVariableValue", id, value });
|
|
90
96
|
}
|
|
97
|
+
// ── #2098 CRUD conveniences — thin aliases over the canonical surface below.
|
|
98
|
+
// They delegate so the per-file declaration-element scope (template/fragment
|
|
99
|
+
// sub-comps included) is resolved in exactly one place.
|
|
100
|
+
getVariableValue(id) {
|
|
101
|
+
return this.getVariableValues()[id];
|
|
102
|
+
}
|
|
103
|
+
listVariables() {
|
|
104
|
+
return this.getVariableDeclarations();
|
|
105
|
+
}
|
|
106
|
+
removeVariable(id) {
|
|
107
|
+
this.dispatch({ type: "removeVariable", id });
|
|
108
|
+
}
|
|
109
|
+
// ── Canonical declaration edit ops (this stack) ──
|
|
110
|
+
// declareVariable unified onto the {declaration} op payload (#2098 used
|
|
111
|
+
// {decl}); the method signature is identical, so #2098 callers are unaffected.
|
|
112
|
+
declareVariable(declaration) {
|
|
113
|
+
this.dispatch({ type: "declareVariable", declaration });
|
|
114
|
+
}
|
|
115
|
+
updateVariableDeclaration(id, declaration) {
|
|
116
|
+
this.dispatch({ type: "updateVariableDeclaration", id, declaration });
|
|
117
|
+
}
|
|
118
|
+
removeVariableDeclaration(id) {
|
|
119
|
+
this.dispatch({ type: "removeVariableDeclaration", id });
|
|
120
|
+
}
|
|
121
|
+
getVariableDeclarations() {
|
|
122
|
+
return readVariableDeclarations(declarationElement(this.parsed.document, this.parsed.wrapped));
|
|
123
|
+
}
|
|
124
|
+
getVariableValues(overrides) {
|
|
125
|
+
// THIS composition's own declared defaults (loose extraction: any entry with
|
|
126
|
+
// a string id + a `default` key, even ones the strict declaration parser
|
|
127
|
+
// drops) spread under the overrides. Scope note: this reads the composition's
|
|
128
|
+
// single declaration element only — NOT a union of every `[data-composition-
|
|
129
|
+
// variables]` in the document. The runtime's getVariables()
|
|
130
|
+
// (core/runtime/getVariables.ts) additionally walks inlined sub-composition
|
|
131
|
+
// declarers because it operates on the bundled multi-composition document;
|
|
132
|
+
// the SDK models one composition file, so per-file scope is intended.
|
|
133
|
+
const defaults = readDeclaredDefaults(declarationElement(this.parsed.document, this.parsed.wrapped));
|
|
134
|
+
return { ...defaults, ...(overrides ?? {}) };
|
|
135
|
+
}
|
|
136
|
+
validateVariableValues(values) {
|
|
137
|
+
return validateVariables(values, this.getVariableDeclarations());
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Script scans are content-keyed (same rationale as _gsapLabelCache): the
|
|
141
|
+
* panel recomputes usage on every preview reload, and unchanged script text
|
|
142
|
+
* is the common case — never pay a second acorn parse for identical input.
|
|
143
|
+
*/
|
|
144
|
+
_variableUsageScanCache = new Map();
|
|
145
|
+
// Scan/merge dispatcher — same complexity class as the suppressed
|
|
146
|
+
// variableUsage.ts classifiers it drives.
|
|
147
|
+
// fallow-ignore-next-line complexity
|
|
148
|
+
getVariableUsage() {
|
|
149
|
+
const usedIds = [];
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
let scanIncomplete = false;
|
|
152
|
+
const freshCache = new Map();
|
|
153
|
+
// Inline scripts only — external src scripts aren't part of the document model.
|
|
154
|
+
for (const script of Array.from(this.parsed.document.querySelectorAll("script"))) {
|
|
155
|
+
if (script.getAttribute("src"))
|
|
156
|
+
continue;
|
|
157
|
+
const text = script.textContent ?? "";
|
|
158
|
+
// Direct global reads (window.__hfVariables / __hfVariablesByComp) are
|
|
159
|
+
// invisible to the getVariables() scanner — the report must degrade to
|
|
160
|
+
// a lower bound instead of confidently claiming declarations unused.
|
|
161
|
+
if (text.includes("__hfVariables"))
|
|
162
|
+
scanIncomplete = true;
|
|
163
|
+
if (!text.includes("getVariables"))
|
|
164
|
+
continue; // cheap pre-filter before an acorn parse
|
|
165
|
+
const scan = this._variableUsageScanCache.get(text) ?? scanVariableUsage(text);
|
|
166
|
+
freshCache.set(text, scan);
|
|
167
|
+
scanIncomplete = scanIncomplete || scan.scanIncomplete;
|
|
168
|
+
for (const id of scan.usedIds) {
|
|
169
|
+
if (!seen.has(id)) {
|
|
170
|
+
seen.add(id);
|
|
171
|
+
usedIds.push(id);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Declarative bindings (data-var-src / data-var-text) are direct reads.
|
|
176
|
+
for (const el of Array.from(this.parsed.document.querySelectorAll("[data-var-src], [data-var-text]"))) {
|
|
177
|
+
for (const attr of ["data-var-src", "data-var-text"]) {
|
|
178
|
+
const id = el.getAttribute(attr)?.trim();
|
|
179
|
+
if (id && !seen.has(id)) {
|
|
180
|
+
seen.add(id);
|
|
181
|
+
usedIds.push(id);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this._variableUsageScanCache = freshCache;
|
|
186
|
+
const declaredIds = this.getVariableDeclarations().map((d) => d.id);
|
|
187
|
+
// The CSS compat channel counts as usage: a variable consumed only via
|
|
188
|
+
// var(--id) in stylesheets or inline styles must not be badged unused
|
|
189
|
+
// (removing it also removes the --{id} root prop and breaks the binding).
|
|
190
|
+
const cssText = this._collectCssText();
|
|
191
|
+
// Match var(--id) only at a custom-property-name boundary: the id must be
|
|
192
|
+
// followed by whitespace, a comma (fallback), or the closing paren — so id
|
|
193
|
+
// "foo" is NOT counted as used by an unrelated var(--foo-header). Ids are
|
|
194
|
+
// regex-escaped because a value read from disk may predate can()'s
|
|
195
|
+
// /^[A-Za-z_][A-Za-z0-9_-]*$/ enforcement and carry metacharacters.
|
|
196
|
+
const cssUsed = (id) => new RegExp(`var\\(\\s*--${escapeRegExp(id)}[\\s,)]`).test(cssText);
|
|
197
|
+
const declaredSet = new Set(declaredIds);
|
|
198
|
+
return {
|
|
199
|
+
usedIds,
|
|
200
|
+
unusedDeclarations: declaredIds.filter((id) => !seen.has(id) && !cssUsed(id)),
|
|
201
|
+
undeclaredReads: usedIds.filter((id) => !declaredSet.has(id)),
|
|
202
|
+
scanIncomplete,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** All stylesheet + inline-style text, for var(--id) consumption checks. */
|
|
206
|
+
_collectCssText() {
|
|
207
|
+
const cssParts = [];
|
|
208
|
+
for (const styleEl of Array.from(this.parsed.document.querySelectorAll("style"))) {
|
|
209
|
+
cssParts.push(styleEl.textContent ?? "");
|
|
210
|
+
}
|
|
211
|
+
for (const el of Array.from(this.parsed.document.querySelectorAll("[style]"))) {
|
|
212
|
+
cssParts.push(el.getAttribute("style") ?? "");
|
|
213
|
+
}
|
|
214
|
+
return cssParts.join("\n");
|
|
215
|
+
}
|
|
216
|
+
setPreviewVariables(values) {
|
|
217
|
+
if (!this.preview?.setPreviewVariables)
|
|
218
|
+
return false;
|
|
219
|
+
this.preview.setPreviewVariables(values);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
91
222
|
// ── WS-C: timing accessors + typed setHold ───────────────────────────────────
|
|
92
223
|
/**
|
|
93
224
|
* Cache of parsed GSAP labels keyed by EXACT script text. extractGsapLabels does
|