@hyperframes/parsers 0.7.57 → 0.7.59
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/gsapParser.d.ts +2 -2
- package/dist/gsapParser.js.map +1 -1
- package/dist/gsapParserAcorn.d.ts +2 -2
- package/dist/gsapParserAcorn.js +127 -17
- package/dist/gsapParserAcorn.js.map +1 -1
- package/dist/gsapParserExports.d.ts +1 -1
- package/dist/gsapParserExports.js +122 -15
- package/dist/gsapParserExports.js.map +1 -1
- package/dist/{gsapSerialize-B8jHFdp3.d.ts → gsapSerialize-CTPaxKTV.d.ts} +2 -0
- package/dist/gsapWriterAcorn.d.ts +1 -1
- package/dist/gsapWriterAcorn.js +111 -11
- package/dist/gsapWriterAcorn.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +127 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as CompositionVariable, T as TimelineElement, a as CanvasResolution, K as Keyframe, S as StageZoomKeyframe, V as ValidationResult } from './types-CaeOJXdW.js';
|
|
2
2
|
export { A as AddElementData, b as Asset, B as BooleanVariable, c as CANVAS_DIMENSIONS, d as COMPOSITION_VARIABLE_TYPES, e as ColorVariable, f as CompositionAPI, g as CompositionAsset, h as CompositionSpec, i as CompositionVariableBase, j as CompositionVariableType, D as DEFAULT_DURATIONS, E as ElementKeyframes, k as EnumVariable, F as FontVariable, I as ImageVariable, l as KeyframeProperties, M as MediaElementType, m as MediaFile, N as NumberVariable, P as PlayerAPI, n as StageZoom, o as StringVariable, p as TIMELINE_COLORS, q as TimelineCompositionElement, r as TimelineElementBase, s as TimelineElementType, t as TimelineMediaElement, u as TimelineTextElement, v as VALID_CANVAS_RESOLUTIONS, W as WaveformData, w as getDefaultStageZoom, x as isCompositionElement, y as isMediaElement, z as isTextElement, G as normalizeResolutionFlag } from './types-CaeOJXdW.js';
|
|
3
|
-
export { A as ArcPathConfig, a as ArcPathSegment, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, P as ParsedGsap, S as SplitAnimationsOptions, g as SplitAnimationsResult, h as editabilityForProvenance, i as getAnimationsForElementId, j as gsapAnimationsToKeyframes, k as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-
|
|
3
|
+
export { A as ArcPathConfig, a as ArcPathSegment, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, P as ParsedGsap, S as SplitAnimationsOptions, g as SplitAnimationsResult, h as editabilityForProvenance, i as getAnimationsForElementId, j as gsapAnimationsToKeyframes, k as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-CTPaxKTV.js';
|
|
4
4
|
export { isStudioHoldSet } from './gsapParser.js';
|
|
5
5
|
export { PROPERTY_GROUPS, PropertyGroupName, SUPPORTED_EASES, SUPPORTED_PROPS, classifyPropertyGroup, classifyTweenPropertyGroup } from './gsapConstants.js';
|
|
6
6
|
export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
|
package/dist/index.js
CHANGED
|
@@ -480,13 +480,18 @@ function collectPatternNames(pattern, out) {
|
|
|
480
480
|
else if (pattern?.type === "AssignmentPattern") collectPatternNames(pattern.left, out);
|
|
481
481
|
else if (pattern?.type === "RestElement") collectPatternNames(pattern.argument, out);
|
|
482
482
|
}
|
|
483
|
+
function boundPatterns(node) {
|
|
484
|
+
if (isFunctionNode(node)) return node.params ?? [];
|
|
485
|
+
if (node.type === "VariableDeclarator") return [node.id];
|
|
486
|
+
if (node.type === "CatchClause") return [node.param];
|
|
487
|
+
if (node.type === "AssignmentExpression" && node.left?.type === "Identifier") return [node.left];
|
|
488
|
+
return [];
|
|
489
|
+
}
|
|
483
490
|
function collectBoundNames(root) {
|
|
484
491
|
const names = /* @__PURE__ */ new Set();
|
|
485
492
|
const visit = (node) => {
|
|
486
493
|
if (!isNode(node)) return node;
|
|
487
|
-
|
|
488
|
-
else if (node.type === "VariableDeclarator") collectPatternNames(node.id, names);
|
|
489
|
-
else if (node.type === "CatchClause") collectPatternNames(node.param, names);
|
|
494
|
+
for (const pattern of boundPatterns(node)) collectPatternNames(pattern, names);
|
|
490
495
|
transformChildren(node, visit);
|
|
491
496
|
return node;
|
|
492
497
|
};
|
|
@@ -654,8 +659,10 @@ function tagTimelineCalls(stmts, prov, ctx) {
|
|
|
654
659
|
}
|
|
655
660
|
function expandBody(bodyStmts, bindings, prov, ctx) {
|
|
656
661
|
const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
|
|
662
|
+
tagProvenance(block, prov);
|
|
657
663
|
tagTimelineCalls(block.body, prov, ctx);
|
|
658
|
-
|
|
664
|
+
block.body = expandStatements(block.body, { ...ctx, depth: ctx.depth + 1 });
|
|
665
|
+
return [block];
|
|
659
666
|
}
|
|
660
667
|
function inlineHelper(call, ctx) {
|
|
661
668
|
const fn = ctx.helpers.get(call.callee.name);
|
|
@@ -846,6 +853,7 @@ var QUERY_METHODS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll"
|
|
|
846
853
|
var ITERATION_METHODS = /* @__PURE__ */ new Set(["forEach", "map"]);
|
|
847
854
|
var SCOPE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
848
855
|
"Program",
|
|
856
|
+
"BlockStatement",
|
|
849
857
|
"FunctionDeclaration",
|
|
850
858
|
"FunctionExpression",
|
|
851
859
|
"ArrowFunctionExpression"
|
|
@@ -954,10 +962,12 @@ function selectorFromQueryCall(node, scope) {
|
|
|
954
962
|
if (method === "getElementById") return `#${argValue}`;
|
|
955
963
|
return null;
|
|
956
964
|
}
|
|
957
|
-
function enclosingScopeNodeFromAncestors(ancestors) {
|
|
965
|
+
function enclosingScopeNodeFromAncestors(ancestors, includeBlocks = true) {
|
|
958
966
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
959
967
|
const node = ancestors[i];
|
|
960
|
-
if (node && SCOPE_NODE_TYPES.has(node.type)
|
|
968
|
+
if (node && SCOPE_NODE_TYPES.has(node.type) && (includeBlocks || node.type !== "BlockStatement")) {
|
|
969
|
+
return node;
|
|
970
|
+
}
|
|
961
971
|
}
|
|
962
972
|
return null;
|
|
963
973
|
}
|
|
@@ -969,6 +979,64 @@ function scopeChainFromAncestors(ancestors) {
|
|
|
969
979
|
}
|
|
970
980
|
return chain;
|
|
971
981
|
}
|
|
982
|
+
function nearestExpandedScopeFromAncestors(ancestors) {
|
|
983
|
+
for (let index = ancestors.length - 2; index >= 0; index--) {
|
|
984
|
+
const candidate = ancestors[index];
|
|
985
|
+
if (candidate?.type === "BlockStatement" && readProvenance(candidate)) return candidate;
|
|
986
|
+
}
|
|
987
|
+
return void 0;
|
|
988
|
+
}
|
|
989
|
+
function findVisibleIdentifierDeclaration(name, ancestors, index, usageStart = Number.POSITIVE_INFINITY) {
|
|
990
|
+
const declarations = index.declarationsByName.get(name) ?? [];
|
|
991
|
+
const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
|
|
992
|
+
for (const scopeNode of scopeChainFromAncestors(ancestors)) {
|
|
993
|
+
const candidates = declarations.filter(
|
|
994
|
+
(declaration) => declaration.scopeNode === scopeNode && (!declaration.expandedScopeNode || declaration.expandedScopeNode === expandedScopeNode) && (declaration.kind === "var" || declaration.kind === "param" || declaration.node.start < usageStart)
|
|
995
|
+
).sort((left, right) => right.node.start - left.node.start);
|
|
996
|
+
if (candidates[0]) return candidates[0];
|
|
997
|
+
}
|
|
998
|
+
return void 0;
|
|
999
|
+
}
|
|
1000
|
+
function collectIdentifierBindingIndex(ast) {
|
|
1001
|
+
const declarationsByName = /* @__PURE__ */ new Map();
|
|
1002
|
+
const reassignedDeclarations = /* @__PURE__ */ new Set();
|
|
1003
|
+
acornWalk.ancestor(ast, {
|
|
1004
|
+
VariableDeclarator(node, _, ancestors) {
|
|
1005
|
+
const name = node.id?.name;
|
|
1006
|
+
if (!name) return;
|
|
1007
|
+
const declaration = ancestors.at(-2);
|
|
1008
|
+
const kind = declaration?.kind;
|
|
1009
|
+
if (!kind) return;
|
|
1010
|
+
const includeBlocks = declaration?.type !== "VariableDeclaration" || kind !== "var";
|
|
1011
|
+
const scopeNode = enclosingScopeNodeFromAncestors(ancestors, includeBlocks);
|
|
1012
|
+
const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
|
|
1013
|
+
const entries = declarationsByName.get(name) ?? [];
|
|
1014
|
+
entries.push({ node, scopeNode, expandedScopeNode, name, kind });
|
|
1015
|
+
declarationsByName.set(name, entries);
|
|
1016
|
+
},
|
|
1017
|
+
FunctionDeclaration: indexFunctionParameters,
|
|
1018
|
+
FunctionExpression: indexFunctionParameters,
|
|
1019
|
+
ArrowFunctionExpression: indexFunctionParameters
|
|
1020
|
+
});
|
|
1021
|
+
const index = { declarationsByName, reassignedDeclarations };
|
|
1022
|
+
acornWalk.ancestor(ast, {
|
|
1023
|
+
AssignmentExpression(node, _, ancestors) {
|
|
1024
|
+
const name = node.left?.type === "Identifier" ? node.left.name : void 0;
|
|
1025
|
+
if (!name) return;
|
|
1026
|
+
const declaration = findVisibleIdentifierDeclaration(name, ancestors, index, node.start);
|
|
1027
|
+
if (declaration) reassignedDeclarations.add(declaration.node);
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
return index;
|
|
1031
|
+
function indexFunctionParameters(node) {
|
|
1032
|
+
for (const parameter of node.params ?? []) {
|
|
1033
|
+
if (parameter?.type !== "Identifier") continue;
|
|
1034
|
+
const entries = declarationsByName.get(parameter.name) ?? [];
|
|
1035
|
+
entries.push({ node: parameter, scopeNode: node, name: parameter.name, kind: "param" });
|
|
1036
|
+
declarationsByName.set(parameter.name, entries);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
972
1040
|
function addBinding(bindings, scopeNode, name, selector) {
|
|
973
1041
|
let scoped = bindings.get(scopeNode);
|
|
974
1042
|
if (!scoped) {
|
|
@@ -1020,21 +1088,39 @@ function collectScopeBindings(ast) {
|
|
|
1020
1088
|
});
|
|
1021
1089
|
return bindings;
|
|
1022
1090
|
}
|
|
1023
|
-
function collectTargetBindings(ast, scope) {
|
|
1091
|
+
function collectTargetBindings(ast, scope, identifierBindings) {
|
|
1024
1092
|
const bindings = /* @__PURE__ */ new Map();
|
|
1025
1093
|
acornWalk.ancestor(ast, {
|
|
1026
1094
|
VariableDeclarator(node, _, ancestors) {
|
|
1027
1095
|
const name = node.id?.name;
|
|
1028
1096
|
const selector = selectorFromQueryCall(node.init, scope);
|
|
1029
1097
|
if (name && selector !== null) {
|
|
1030
|
-
|
|
1098
|
+
const declaration = ancestors.at(-2);
|
|
1099
|
+
const includeBlocks = declaration?.type !== "VariableDeclaration" || declaration.kind !== "var";
|
|
1100
|
+
addBinding(
|
|
1101
|
+
bindings,
|
|
1102
|
+
enclosingScopeNodeFromAncestors(ancestors, includeBlocks),
|
|
1103
|
+
name,
|
|
1104
|
+
selector
|
|
1105
|
+
);
|
|
1031
1106
|
}
|
|
1032
1107
|
},
|
|
1033
1108
|
AssignmentExpression(node, _, ancestors) {
|
|
1034
1109
|
const left = node.left;
|
|
1035
1110
|
const selector = selectorFromQueryCall(node.right, scope);
|
|
1036
1111
|
if (left?.type === "Identifier" && selector !== null) {
|
|
1037
|
-
|
|
1112
|
+
const declaration = findVisibleIdentifierDeclaration(
|
|
1113
|
+
left.name,
|
|
1114
|
+
ancestors,
|
|
1115
|
+
identifierBindings,
|
|
1116
|
+
node.start
|
|
1117
|
+
);
|
|
1118
|
+
addBinding(
|
|
1119
|
+
bindings,
|
|
1120
|
+
declaration?.scopeNode ?? nearestExpandedScopeFromAncestors(ancestors) ?? enclosingScopeNodeFromAncestors(ancestors),
|
|
1121
|
+
left.name,
|
|
1122
|
+
selector
|
|
1123
|
+
);
|
|
1038
1124
|
}
|
|
1039
1125
|
}
|
|
1040
1126
|
});
|
|
@@ -1514,7 +1600,8 @@ function parseMotionPathNode(node, scope, source) {
|
|
|
1514
1600
|
}
|
|
1515
1601
|
return buildArcPath(coords, curviness, autoRotate, isCubic);
|
|
1516
1602
|
}
|
|
1517
|
-
function tweenCallToAnimation(call, scope, source) {
|
|
1603
|
+
function tweenCallToAnimation(call, scope, source, identifierBindings) {
|
|
1604
|
+
const provenance = readProvenance(call.node);
|
|
1518
1605
|
const vars = objectExpressionToRecord(call.varsArg, scope, source);
|
|
1519
1606
|
const properties = {};
|
|
1520
1607
|
const extras = {};
|
|
@@ -1593,9 +1680,26 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1593
1680
|
duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
|
|
1594
1681
|
}
|
|
1595
1682
|
let selector = call.selector;
|
|
1683
|
+
let targetIdentity;
|
|
1596
1684
|
if (selector === "__unresolved__") {
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1685
|
+
const targetNode = call.node.arguments?.[0];
|
|
1686
|
+
const proxyLabel = describeProxyTarget(targetNode, call.varsArg, scope);
|
|
1687
|
+
if (proxyLabel) {
|
|
1688
|
+
selector = proxyLabel;
|
|
1689
|
+
if (targetNode?.type === "Identifier") {
|
|
1690
|
+
const declaration = findVisibleIdentifierDeclaration(
|
|
1691
|
+
targetNode.name,
|
|
1692
|
+
call.ancestors,
|
|
1693
|
+
identifierBindings,
|
|
1694
|
+
call.node.start
|
|
1695
|
+
);
|
|
1696
|
+
if (declaration?.node.init?.type === "ObjectExpression" && !identifierBindings.reassignedDeclarations.has(declaration.node)) {
|
|
1697
|
+
const declarationProvenance = readProvenance(declaration.scopeNode) ?? readProvenance(declaration.expandedScopeNode);
|
|
1698
|
+
const instanceIdentity = declarationProvenance && (declarationProvenance.kind === "helper" || declarationProvenance.kind === "loop") ? `:${declarationProvenance.kind}:${declarationProvenance.callSite ?? ""}:${declarationProvenance.iteration ?? ""}` : "";
|
|
1699
|
+
targetIdentity = `proxy:${targetNode.name}@${declaration.node.start}${instanceIdentity}`;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1599
1703
|
}
|
|
1600
1704
|
const anim = {
|
|
1601
1705
|
targetSelector: selector,
|
|
@@ -1606,6 +1710,7 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1606
1710
|
duration,
|
|
1607
1711
|
ease
|
|
1608
1712
|
};
|
|
1713
|
+
if (targetIdentity) anim.targetIdentity = targetIdentity;
|
|
1609
1714
|
if (!hasPositionArg) anim.implicitPosition = true;
|
|
1610
1715
|
let group = classifyTweenPropertyGroup(properties);
|
|
1611
1716
|
if (!group && keyframesData) {
|
|
@@ -1622,7 +1727,6 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1622
1727
|
if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
|
|
1623
1728
|
if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
|
|
1624
1729
|
if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
|
|
1625
|
-
const provenance = readProvenance(call.node);
|
|
1626
1730
|
if (provenance) anim.provenance = provenance;
|
|
1627
1731
|
return anim;
|
|
1628
1732
|
}
|
|
@@ -1874,13 +1978,16 @@ function parseGsapScriptAcornForWrite(script) {
|
|
|
1874
1978
|
locations: true
|
|
1875
1979
|
});
|
|
1876
1980
|
const scope = collectScopeBindings(ast);
|
|
1877
|
-
const
|
|
1981
|
+
const identifierBindings = collectIdentifierBindingIndex(ast);
|
|
1982
|
+
const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
|
|
1878
1983
|
const detection = findTimelineVar(ast, scope);
|
|
1879
1984
|
const ref = detection.ref ?? { kind: "identifier", name: "tl" };
|
|
1880
1985
|
const timelineVar = timelineRootSource(ref, script);
|
|
1881
1986
|
const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
|
|
1882
1987
|
sortBySourcePosition(calls);
|
|
1883
|
-
const rawAnims = calls.map(
|
|
1988
|
+
const rawAnims = calls.map(
|
|
1989
|
+
(call) => tweenCallToAnimation(call, scope, script, identifierBindings)
|
|
1990
|
+
);
|
|
1884
1991
|
applyTimelineDefaults(rawAnims, detection.defaults);
|
|
1885
1992
|
resolveTimelinePositions(rawAnims);
|
|
1886
1993
|
const animations = assignStableIds(rawAnims);
|
|
@@ -1911,10 +2018,13 @@ function parseGsapScriptAcorn(script) {
|
|
|
1911
2018
|
} catch {
|
|
1912
2019
|
}
|
|
1913
2020
|
}
|
|
1914
|
-
const
|
|
2021
|
+
const identifierBindings = collectIdentifierBindingIndex(ast);
|
|
2022
|
+
const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
|
|
1915
2023
|
const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
|
|
1916
2024
|
sortBySourcePosition(calls);
|
|
1917
|
-
const rawAnims = calls.map(
|
|
2025
|
+
const rawAnims = calls.map(
|
|
2026
|
+
(call) => tweenCallToAnimation(call, scope, script, identifierBindings)
|
|
2027
|
+
);
|
|
1918
2028
|
applyTimelineDefaults(rawAnims, detection.defaults);
|
|
1919
2029
|
seedSetStates(rawAnims, collectGsapSetStates(ast, scope, targetBindings, script));
|
|
1920
2030
|
const labelDefs = collectAddLabelDefs(ast, ref, scope, calls);
|