@hyperframes/parsers 0.7.58 → 0.7.60
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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-
|
|
1
|
+
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';
|
|
2
2
|
export { isStudioHoldSet } from './gsapParser.js';
|
|
3
3
|
export { PROPERTY_GROUPS, PropertyGroupName, SUPPORTED_EASES, SUPPORTED_PROPS, classifyPropertyGroup, classifyTweenPropertyGroup } from './gsapConstants.js';
|
|
4
4
|
export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
|
|
@@ -407,13 +407,18 @@ function collectPatternNames(pattern, out) {
|
|
|
407
407
|
else if (pattern?.type === "AssignmentPattern") collectPatternNames(pattern.left, out);
|
|
408
408
|
else if (pattern?.type === "RestElement") collectPatternNames(pattern.argument, out);
|
|
409
409
|
}
|
|
410
|
+
function boundPatterns(node) {
|
|
411
|
+
if (isFunctionNode(node)) return node.params ?? [];
|
|
412
|
+
if (node.type === "VariableDeclarator") return [node.id];
|
|
413
|
+
if (node.type === "CatchClause") return [node.param];
|
|
414
|
+
if (node.type === "AssignmentExpression" && node.left?.type === "Identifier") return [node.left];
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
410
417
|
function collectBoundNames(root) {
|
|
411
418
|
const names = /* @__PURE__ */ new Set();
|
|
412
419
|
const visit = (node) => {
|
|
413
420
|
if (!isNode(node)) return node;
|
|
414
|
-
|
|
415
|
-
else if (node.type === "VariableDeclarator") collectPatternNames(node.id, names);
|
|
416
|
-
else if (node.type === "CatchClause") collectPatternNames(node.param, names);
|
|
421
|
+
for (const pattern of boundPatterns(node)) collectPatternNames(pattern, names);
|
|
417
422
|
transformChildren(node, visit);
|
|
418
423
|
return node;
|
|
419
424
|
};
|
|
@@ -581,8 +586,10 @@ function tagTimelineCalls(stmts, prov, ctx) {
|
|
|
581
586
|
}
|
|
582
587
|
function expandBody(bodyStmts, bindings, prov, ctx) {
|
|
583
588
|
const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
|
|
589
|
+
tagProvenance(block, prov);
|
|
584
590
|
tagTimelineCalls(block.body, prov, ctx);
|
|
585
|
-
|
|
591
|
+
block.body = expandStatements(block.body, { ...ctx, depth: ctx.depth + 1 });
|
|
592
|
+
return [block];
|
|
586
593
|
}
|
|
587
594
|
function inlineHelper(call, ctx) {
|
|
588
595
|
const fn = ctx.helpers.get(call.callee.name);
|
|
@@ -773,6 +780,7 @@ var QUERY_METHODS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll"
|
|
|
773
780
|
var ITERATION_METHODS = /* @__PURE__ */ new Set(["forEach", "map"]);
|
|
774
781
|
var SCOPE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
775
782
|
"Program",
|
|
783
|
+
"BlockStatement",
|
|
776
784
|
"FunctionDeclaration",
|
|
777
785
|
"FunctionExpression",
|
|
778
786
|
"ArrowFunctionExpression"
|
|
@@ -881,10 +889,12 @@ function selectorFromQueryCall(node, scope) {
|
|
|
881
889
|
if (method === "getElementById") return `#${argValue}`;
|
|
882
890
|
return null;
|
|
883
891
|
}
|
|
884
|
-
function enclosingScopeNodeFromAncestors(ancestors) {
|
|
892
|
+
function enclosingScopeNodeFromAncestors(ancestors, includeBlocks = true) {
|
|
885
893
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
886
894
|
const node = ancestors[i];
|
|
887
|
-
if (node && SCOPE_NODE_TYPES.has(node.type)
|
|
895
|
+
if (node && SCOPE_NODE_TYPES.has(node.type) && (includeBlocks || node.type !== "BlockStatement")) {
|
|
896
|
+
return node;
|
|
897
|
+
}
|
|
888
898
|
}
|
|
889
899
|
return null;
|
|
890
900
|
}
|
|
@@ -896,6 +906,64 @@ function scopeChainFromAncestors(ancestors) {
|
|
|
896
906
|
}
|
|
897
907
|
return chain;
|
|
898
908
|
}
|
|
909
|
+
function nearestExpandedScopeFromAncestors(ancestors) {
|
|
910
|
+
for (let index = ancestors.length - 2; index >= 0; index--) {
|
|
911
|
+
const candidate = ancestors[index];
|
|
912
|
+
if (candidate?.type === "BlockStatement" && readProvenance(candidate)) return candidate;
|
|
913
|
+
}
|
|
914
|
+
return void 0;
|
|
915
|
+
}
|
|
916
|
+
function findVisibleIdentifierDeclaration(name, ancestors, index, usageStart = Number.POSITIVE_INFINITY) {
|
|
917
|
+
const declarations = index.declarationsByName.get(name) ?? [];
|
|
918
|
+
const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
|
|
919
|
+
for (const scopeNode of scopeChainFromAncestors(ancestors)) {
|
|
920
|
+
const candidates = declarations.filter(
|
|
921
|
+
(declaration) => declaration.scopeNode === scopeNode && (!declaration.expandedScopeNode || declaration.expandedScopeNode === expandedScopeNode) && (declaration.kind === "var" || declaration.kind === "param" || declaration.node.start < usageStart)
|
|
922
|
+
).sort((left, right) => right.node.start - left.node.start);
|
|
923
|
+
if (candidates[0]) return candidates[0];
|
|
924
|
+
}
|
|
925
|
+
return void 0;
|
|
926
|
+
}
|
|
927
|
+
function collectIdentifierBindingIndex(ast) {
|
|
928
|
+
const declarationsByName = /* @__PURE__ */ new Map();
|
|
929
|
+
const reassignedDeclarations = /* @__PURE__ */ new Set();
|
|
930
|
+
acornWalk.ancestor(ast, {
|
|
931
|
+
VariableDeclarator(node, _, ancestors) {
|
|
932
|
+
const name = node.id?.name;
|
|
933
|
+
if (!name) return;
|
|
934
|
+
const declaration = ancestors.at(-2);
|
|
935
|
+
const kind = declaration?.kind;
|
|
936
|
+
if (!kind) return;
|
|
937
|
+
const includeBlocks = declaration?.type !== "VariableDeclaration" || kind !== "var";
|
|
938
|
+
const scopeNode = enclosingScopeNodeFromAncestors(ancestors, includeBlocks);
|
|
939
|
+
const expandedScopeNode = nearestExpandedScopeFromAncestors(ancestors);
|
|
940
|
+
const entries = declarationsByName.get(name) ?? [];
|
|
941
|
+
entries.push({ node, scopeNode, expandedScopeNode, name, kind });
|
|
942
|
+
declarationsByName.set(name, entries);
|
|
943
|
+
},
|
|
944
|
+
FunctionDeclaration: indexFunctionParameters,
|
|
945
|
+
FunctionExpression: indexFunctionParameters,
|
|
946
|
+
ArrowFunctionExpression: indexFunctionParameters
|
|
947
|
+
});
|
|
948
|
+
const index = { declarationsByName, reassignedDeclarations };
|
|
949
|
+
acornWalk.ancestor(ast, {
|
|
950
|
+
AssignmentExpression(node, _, ancestors) {
|
|
951
|
+
const name = node.left?.type === "Identifier" ? node.left.name : void 0;
|
|
952
|
+
if (!name) return;
|
|
953
|
+
const declaration = findVisibleIdentifierDeclaration(name, ancestors, index, node.start);
|
|
954
|
+
if (declaration) reassignedDeclarations.add(declaration.node);
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
return index;
|
|
958
|
+
function indexFunctionParameters(node) {
|
|
959
|
+
for (const parameter of node.params ?? []) {
|
|
960
|
+
if (parameter?.type !== "Identifier") continue;
|
|
961
|
+
const entries = declarationsByName.get(parameter.name) ?? [];
|
|
962
|
+
entries.push({ node: parameter, scopeNode: node, name: parameter.name, kind: "param" });
|
|
963
|
+
declarationsByName.set(parameter.name, entries);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
899
967
|
function addBinding(bindings, scopeNode, name, selector) {
|
|
900
968
|
let scoped = bindings.get(scopeNode);
|
|
901
969
|
if (!scoped) {
|
|
@@ -947,21 +1015,39 @@ function collectScopeBindings(ast) {
|
|
|
947
1015
|
});
|
|
948
1016
|
return bindings;
|
|
949
1017
|
}
|
|
950
|
-
function collectTargetBindings(ast, scope) {
|
|
1018
|
+
function collectTargetBindings(ast, scope, identifierBindings) {
|
|
951
1019
|
const bindings = /* @__PURE__ */ new Map();
|
|
952
1020
|
acornWalk.ancestor(ast, {
|
|
953
1021
|
VariableDeclarator(node, _, ancestors) {
|
|
954
1022
|
const name = node.id?.name;
|
|
955
1023
|
const selector = selectorFromQueryCall(node.init, scope);
|
|
956
1024
|
if (name && selector !== null) {
|
|
957
|
-
|
|
1025
|
+
const declaration = ancestors.at(-2);
|
|
1026
|
+
const includeBlocks = declaration?.type !== "VariableDeclaration" || declaration.kind !== "var";
|
|
1027
|
+
addBinding(
|
|
1028
|
+
bindings,
|
|
1029
|
+
enclosingScopeNodeFromAncestors(ancestors, includeBlocks),
|
|
1030
|
+
name,
|
|
1031
|
+
selector
|
|
1032
|
+
);
|
|
958
1033
|
}
|
|
959
1034
|
},
|
|
960
1035
|
AssignmentExpression(node, _, ancestors) {
|
|
961
1036
|
const left = node.left;
|
|
962
1037
|
const selector = selectorFromQueryCall(node.right, scope);
|
|
963
1038
|
if (left?.type === "Identifier" && selector !== null) {
|
|
964
|
-
|
|
1039
|
+
const declaration = findVisibleIdentifierDeclaration(
|
|
1040
|
+
left.name,
|
|
1041
|
+
ancestors,
|
|
1042
|
+
identifierBindings,
|
|
1043
|
+
node.start
|
|
1044
|
+
);
|
|
1045
|
+
addBinding(
|
|
1046
|
+
bindings,
|
|
1047
|
+
declaration?.scopeNode ?? nearestExpandedScopeFromAncestors(ancestors) ?? enclosingScopeNodeFromAncestors(ancestors),
|
|
1048
|
+
left.name,
|
|
1049
|
+
selector
|
|
1050
|
+
);
|
|
965
1051
|
}
|
|
966
1052
|
}
|
|
967
1053
|
});
|
|
@@ -1441,7 +1527,8 @@ function parseMotionPathNode(node, scope, source) {
|
|
|
1441
1527
|
}
|
|
1442
1528
|
return buildArcPath(coords, curviness, autoRotate, isCubic);
|
|
1443
1529
|
}
|
|
1444
|
-
function tweenCallToAnimation(call, scope, source) {
|
|
1530
|
+
function tweenCallToAnimation(call, scope, source, identifierBindings) {
|
|
1531
|
+
const provenance = readProvenance(call.node);
|
|
1445
1532
|
const vars = objectExpressionToRecord(call.varsArg, scope, source);
|
|
1446
1533
|
const properties = {};
|
|
1447
1534
|
const extras = {};
|
|
@@ -1520,9 +1607,26 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1520
1607
|
duration = computeKeyframesTotalDuration(call.varsArg, scope, source);
|
|
1521
1608
|
}
|
|
1522
1609
|
let selector = call.selector;
|
|
1610
|
+
let targetIdentity;
|
|
1523
1611
|
if (selector === "__unresolved__") {
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1612
|
+
const targetNode = call.node.arguments?.[0];
|
|
1613
|
+
const proxyLabel = describeProxyTarget(targetNode, call.varsArg, scope);
|
|
1614
|
+
if (proxyLabel) {
|
|
1615
|
+
selector = proxyLabel;
|
|
1616
|
+
if (targetNode?.type === "Identifier") {
|
|
1617
|
+
const declaration = findVisibleIdentifierDeclaration(
|
|
1618
|
+
targetNode.name,
|
|
1619
|
+
call.ancestors,
|
|
1620
|
+
identifierBindings,
|
|
1621
|
+
call.node.start
|
|
1622
|
+
);
|
|
1623
|
+
if (declaration?.node.init?.type === "ObjectExpression" && !identifierBindings.reassignedDeclarations.has(declaration.node)) {
|
|
1624
|
+
const declarationProvenance = readProvenance(declaration.scopeNode) ?? readProvenance(declaration.expandedScopeNode);
|
|
1625
|
+
const instanceIdentity = declarationProvenance && (declarationProvenance.kind === "helper" || declarationProvenance.kind === "loop") ? `:${declarationProvenance.kind}:${declarationProvenance.callSite ?? ""}:${declarationProvenance.iteration ?? ""}` : "";
|
|
1626
|
+
targetIdentity = `proxy:${targetNode.name}@${declaration.node.start}${instanceIdentity}`;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1526
1630
|
}
|
|
1527
1631
|
const anim = {
|
|
1528
1632
|
targetSelector: selector,
|
|
@@ -1533,6 +1637,7 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1533
1637
|
duration,
|
|
1534
1638
|
ease
|
|
1535
1639
|
};
|
|
1640
|
+
if (targetIdentity) anim.targetIdentity = targetIdentity;
|
|
1536
1641
|
if (!hasPositionArg) anim.implicitPosition = true;
|
|
1537
1642
|
let group = classifyTweenPropertyGroup(properties);
|
|
1538
1643
|
if (!group && keyframesData) {
|
|
@@ -1549,7 +1654,6 @@ function tweenCallToAnimation(call, scope, source) {
|
|
|
1549
1654
|
if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
|
|
1550
1655
|
if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
|
|
1551
1656
|
if (selector === "__unresolved__") anim.hasUnresolvedSelector = true;
|
|
1552
|
-
const provenance = readProvenance(call.node);
|
|
1553
1657
|
if (provenance) anim.provenance = provenance;
|
|
1554
1658
|
return anim;
|
|
1555
1659
|
}
|
|
@@ -1810,10 +1914,13 @@ function parseGsapScriptAcorn(script) {
|
|
|
1810
1914
|
} catch {
|
|
1811
1915
|
}
|
|
1812
1916
|
}
|
|
1813
|
-
const
|
|
1917
|
+
const identifierBindings = collectIdentifierBindingIndex(ast);
|
|
1918
|
+
const targetBindings = collectTargetBindings(ast, scope, identifierBindings);
|
|
1814
1919
|
const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
|
|
1815
1920
|
sortBySourcePosition(calls);
|
|
1816
|
-
const rawAnims = calls.map(
|
|
1921
|
+
const rawAnims = calls.map(
|
|
1922
|
+
(call) => tweenCallToAnimation(call, scope, script, identifierBindings)
|
|
1923
|
+
);
|
|
1817
1924
|
applyTimelineDefaults(rawAnims, detection.defaults);
|
|
1818
1925
|
seedSetStates(rawAnims, collectGsapSetStates(ast, scope, targetBindings, script));
|
|
1819
1926
|
const labelDefs = collectAddLabelDefs(ast, ref, scope, calls);
|