@hyperframes/parsers 0.8.98 → 0.8.100
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 +4 -4
- package/dist/gsapParser.js +48 -11
- package/dist/gsapParser.js.map +1 -1
- package/dist/gsapParserAcorn.d.ts +8 -3
- package/dist/gsapParserAcorn.js +14 -0
- package/dist/gsapParserAcorn.js.map +1 -1
- package/dist/gsapParserExports.d.ts +1 -1
- package/dist/gsapParserExports.js +9 -0
- package/dist/gsapParserExports.js.map +1 -1
- package/dist/{gsapSerialize-b8lNzSbI.d.ts → gsapSerialize-D92cSJOu.d.ts} +1 -0
- package/dist/gsapWriterAcorn.d.ts +16 -6
- package/dist/gsapWriterAcorn.js +56 -11
- package/dist/gsapWriterAcorn.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/gsapParser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GsapAnimation, P as ParsedGsap, A as ArcPathConfig, a as ArcPathSegment } from './gsapSerialize-
|
|
2
|
-
export { n as GsapKeyframeFormat, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, j as getAnimationsForElementId, k as gsapAnimationsToKeyframes, l as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-
|
|
1
|
+
import { G as GsapAnimation, P as ParsedGsap, A as ArcPathConfig, a as ArcPathSegment } from './gsapSerialize-D92cSJOu.js';
|
|
2
|
+
export { n as GsapKeyframeFormat, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, j as getAnimationsForElementId, k as gsapAnimationsToKeyframes, l as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-D92cSJOu.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';
|
|
5
5
|
import './types-Y0NXTiVo.js';
|
|
@@ -9,8 +9,8 @@ declare function updateAnimationInScript(script: string, animationId: string, up
|
|
|
9
9
|
easeEach?: string;
|
|
10
10
|
resetKeyframeEases?: boolean;
|
|
11
11
|
}): string;
|
|
12
|
-
declare function shiftPositionsInScript(script: string, targetSelector: string, delta: number): string;
|
|
13
|
-
declare function scalePositionsInScript(script: string, targetSelector: string, oldStart: number, oldDuration: number, newStart: number, newDuration: number): string;
|
|
12
|
+
declare function shiftPositionsInScript(script: string, targetSelector: string, delta: number, root?: ParentNode): string;
|
|
13
|
+
declare function scalePositionsInScript(script: string, targetSelector: string, oldStart: number, oldDuration: number, newStart: number, newDuration: number, root?: ParentNode): string;
|
|
14
14
|
declare function addAnimationToScript(script: string, animation: Omit<GsapAnimation, "id">): {
|
|
15
15
|
script: string;
|
|
16
16
|
id: string;
|
package/dist/gsapParser.js
CHANGED
|
@@ -351,6 +351,32 @@ function resolveConversionProps(anim, resolvedFromValues) {
|
|
|
351
351
|
return { fromProps: { ...anim.fromProperties ?? {} }, toProps };
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
// src/clipTweens.ts
|
|
355
|
+
function clipTweenMatcher(clipSelectors, root) {
|
|
356
|
+
const own = typeof clipSelectors === "string" ? [clipSelectors] : clipSelectors;
|
|
357
|
+
const clips = root ? own.flatMap((selector) => queryAll(root, selector)) : [];
|
|
358
|
+
return ({ targetSelector, hasPartialSelector }) => {
|
|
359
|
+
if (hasPartialSelector) return false;
|
|
360
|
+
if (own.includes(targetSelector)) return true;
|
|
361
|
+
if (!root || clips.length === 0) return false;
|
|
362
|
+
const targets = queryAll(root, targetSelector);
|
|
363
|
+
return targets.length > 0 && targets.every((target) => {
|
|
364
|
+
const owner = target.closest("[data-start]");
|
|
365
|
+
return clips.includes(target) || owner !== null && clips.includes(owner);
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function hasExplicitTime(animation) {
|
|
370
|
+
return typeof animation.position === "number" && !animation.implicitPosition;
|
|
371
|
+
}
|
|
372
|
+
function queryAll(root, selector) {
|
|
373
|
+
try {
|
|
374
|
+
return Array.from(root.querySelectorAll(selector));
|
|
375
|
+
} catch {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
354
380
|
// src/gsapObjectArrayTiming.ts
|
|
355
381
|
var roundPercentage = (percentage) => Math.round(percentage * 10) / 10;
|
|
356
382
|
var OBJECT_ARRAY_PERCENTAGE_TOLERANCE = 2;
|
|
@@ -672,6 +698,11 @@ function lookupBinding(name, path, bindings) {
|
|
|
672
698
|
}
|
|
673
699
|
return null;
|
|
674
700
|
}
|
|
701
|
+
function hasUnresolvedArrayPart(node, path, scope, bindings, helpers) {
|
|
702
|
+
return node?.type === "ArrayExpression" && node.elements.some(
|
|
703
|
+
(el) => !resolveTargetSelector(el, path, scope, bindings, helpers) || hasUnresolvedArrayPart(el, path, scope, bindings, helpers)
|
|
704
|
+
);
|
|
705
|
+
}
|
|
675
706
|
function resolveTargetSelector(node, path, scope, bindings, helpers) {
|
|
676
707
|
if (!node) return null;
|
|
677
708
|
if (node.type === "StringLiteral" || node.type === "Literal") {
|
|
@@ -819,12 +850,14 @@ function findAllTweenCalls(ast, ref, scope, targetBindings, targetHelpers) {
|
|
|
819
850
|
return;
|
|
820
851
|
}
|
|
821
852
|
const selectorValue = resolveTargetSelector(args[0], path, scope, targetBindings, targetHelpers) ?? "__unresolved__";
|
|
853
|
+
const partial = hasUnresolvedArrayPart(args[0], path, scope, targetBindings, targetHelpers) ? { selectorPartial: true } : {};
|
|
822
854
|
if (method === "fromTo") {
|
|
823
855
|
results.push({
|
|
824
856
|
path,
|
|
825
857
|
node,
|
|
826
858
|
method: "fromTo",
|
|
827
859
|
selector: selectorValue,
|
|
860
|
+
...partial,
|
|
828
861
|
fromArg: args[1],
|
|
829
862
|
varsArg: args[2],
|
|
830
863
|
positionArg: args[3]
|
|
@@ -835,6 +868,7 @@ function findAllTweenCalls(ast, ref, scope, targetBindings, targetHelpers) {
|
|
|
835
868
|
node,
|
|
836
869
|
method,
|
|
837
870
|
selector: selectorValue,
|
|
871
|
+
...partial,
|
|
838
872
|
varsArg: args[1],
|
|
839
873
|
positionArg: args[2],
|
|
840
874
|
...isGlobalSet ? { global: true } : {}
|
|
@@ -1183,6 +1217,7 @@ function tweenCallToAnimation(call, scope) {
|
|
|
1183
1217
|
if (motionPathResult) anim.arcPath = motionPathResult.arcPath;
|
|
1184
1218
|
if (hasUnresolvedKeyframes) anim.hasUnresolvedKeyframes = true;
|
|
1185
1219
|
if (call.selector === "__unresolved__") anim.hasUnresolvedSelector = true;
|
|
1220
|
+
if (call.selectorPartial) anim.hasPartialSelector = true;
|
|
1186
1221
|
return anim;
|
|
1187
1222
|
}
|
|
1188
1223
|
var GSAP_DEFAULT_DURATION = 0.5;
|
|
@@ -1457,7 +1492,8 @@ function updateAnimationInScript(script, animationId, updates) {
|
|
|
1457
1492
|
applyUpdatesToCall(target.call, updates);
|
|
1458
1493
|
return recast.print(parsed.ast).code;
|
|
1459
1494
|
}
|
|
1460
|
-
function shiftPositionsInScript(script, targetSelector, delta) {
|
|
1495
|
+
function shiftPositionsInScript(script, targetSelector, delta, root) {
|
|
1496
|
+
const carries = clipTweenMatcher(targetSelector, root);
|
|
1461
1497
|
let parsed;
|
|
1462
1498
|
try {
|
|
1463
1499
|
parsed = parseGsapAst(script);
|
|
@@ -1467,17 +1503,17 @@ function shiftPositionsInScript(script, targetSelector, delta) {
|
|
|
1467
1503
|
}
|
|
1468
1504
|
let changed = false;
|
|
1469
1505
|
for (const entry of parsed.located) {
|
|
1470
|
-
if (entry.animation
|
|
1471
|
-
if (typeof entry.animation.position !== "number") continue;
|
|
1506
|
+
if (!carries(entry.animation) || !hasExplicitTime(entry.animation)) continue;
|
|
1472
1507
|
const newPos = Math.max(0, Math.round((entry.animation.position + delta) * 1e3) / 1e3);
|
|
1473
1508
|
applyUpdatesToCall(entry.call, { position: newPos });
|
|
1474
1509
|
changed = true;
|
|
1475
1510
|
}
|
|
1476
1511
|
return changed ? recast.print(parsed.ast).code : script;
|
|
1477
1512
|
}
|
|
1478
|
-
function scalePositionsInScript(script, targetSelector, oldStart, oldDuration, newStart, newDuration) {
|
|
1513
|
+
function scalePositionsInScript(script, targetSelector, oldStart, oldDuration, newStart, newDuration, root) {
|
|
1479
1514
|
if (oldDuration <= 0 || newDuration <= 0) return script;
|
|
1480
1515
|
const ratio = newDuration / oldDuration;
|
|
1516
|
+
const carries = clipTweenMatcher(targetSelector, root);
|
|
1481
1517
|
let parsed;
|
|
1482
1518
|
try {
|
|
1483
1519
|
parsed = parseGsapAst(script);
|
|
@@ -1487,13 +1523,14 @@ function scalePositionsInScript(script, targetSelector, oldStart, oldDuration, n
|
|
|
1487
1523
|
}
|
|
1488
1524
|
let changed = false;
|
|
1489
1525
|
for (const entry of parsed.located) {
|
|
1490
|
-
if (entry.animation.
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1526
|
+
if (!carries(entry.animation) || typeof entry.animation.position !== "number") continue;
|
|
1527
|
+
const updates = {};
|
|
1528
|
+
if (hasExplicitTime(entry.animation)) {
|
|
1529
|
+
updates.position = Math.max(
|
|
1530
|
+
0,
|
|
1531
|
+
Math.round((newStart + (entry.animation.position - oldStart) * ratio) * 1e3) / 1e3
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1497
1534
|
if (typeof entry.animation.duration === "number" && entry.animation.duration > 0) {
|
|
1498
1535
|
updates.duration = Math.max(
|
|
1499
1536
|
1e-3,
|