@hyperframes/parsers 0.7.62 → 0.7.64
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.
|
@@ -113,7 +113,25 @@ declare function addLabelToScript(script: string, name: string, position: number
|
|
|
113
113
|
declare function removeLabelFromScript(script: string, name: string): string;
|
|
114
114
|
declare function setArcPathInScript(script: string, animationId: string, config: ArcPathConfig): string;
|
|
115
115
|
declare function updateArcSegmentInScript(script: string, animationId: string, segmentIndex: number, update: Partial<ArcPathSegment>): string;
|
|
116
|
+
declare function updateMotionPathPointInScript(script: string, animationId: string, pointIndex: number, point: {
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
}): string;
|
|
120
|
+
declare function addMotionPathPointInScript(script: string, animationId: string, index: number, point: {
|
|
121
|
+
x: number;
|
|
122
|
+
y: number;
|
|
123
|
+
}): string;
|
|
124
|
+
declare function removeMotionPathPointInScript(script: string, animationId: string, index: number): string;
|
|
125
|
+
declare function addMotionPathToScript(script: string, targetSelector: string, position: number, duration: number, point: {
|
|
126
|
+
x: number;
|
|
127
|
+
y: number;
|
|
128
|
+
}, ease?: string): {
|
|
129
|
+
script: string;
|
|
130
|
+
id: string | null;
|
|
131
|
+
};
|
|
116
132
|
declare function removeArcPathFromScript(script: string, animationId: string): string;
|
|
133
|
+
/** Acorn-native, byte-preserving hold synchronization used after mutations. */
|
|
134
|
+
declare function syncPositionHoldsBeforeKeyframes(script: string): string;
|
|
117
135
|
declare function splitAnimationsInScript(script: string, opts: SplitAnimationsOptions): SplitAnimationsResult;
|
|
118
136
|
type UnrollElement = {
|
|
119
137
|
selector: string;
|
|
@@ -131,4 +149,4 @@ type UnrollElement = {
|
|
|
131
149
|
*/
|
|
132
150
|
declare function unrollDynamicAnimations(script: string, animationId: string, elements: UnrollElement[]): string;
|
|
133
151
|
|
|
134
|
-
export { type UnrollElement, addAnimationToScript, addAnimationWithKeyframesToScript, addKeyframeToScript, addLabelToScript, convertToKeyframesFromScript, dedupePositionWritesInScript, materializeKeyframesFromScript, moveKeyframeInScript, removeAllKeyframesFromScript, removeAnimationFromScript, removeArcPathFromScript, removeKeyframeFromScript, removeLabelFromScript, removePropertyFromAnimation, resizeKeyframedTweenInScript, scalePositionsInScript, setArcPathInScript, shiftPositionsInScript, splitAnimationsInScript, splitIntoPropertyGroupsFromScript, unrollDynamicAnimations, updateAnimationInScript, updateArcSegmentInScript, updateKeyframeInScript };
|
|
152
|
+
export { type UnrollElement, addAnimationToScript, addAnimationWithKeyframesToScript, addKeyframeToScript, addLabelToScript, addMotionPathPointInScript, addMotionPathToScript, convertToKeyframesFromScript, dedupePositionWritesInScript, materializeKeyframesFromScript, moveKeyframeInScript, removeAllKeyframesFromScript, removeAnimationFromScript, removeArcPathFromScript, removeKeyframeFromScript, removeLabelFromScript, removeMotionPathPointInScript, removePropertyFromAnimation, resizeKeyframedTweenInScript, scalePositionsInScript, setArcPathInScript, shiftPositionsInScript, splitAnimationsInScript, splitIntoPropertyGroupsFromScript, syncPositionHoldsBeforeKeyframes, unrollDynamicAnimations, updateAnimationInScript, updateArcSegmentInScript, updateKeyframeInScript, updateMotionPathPointInScript };
|
package/dist/gsapWriterAcorn.js
CHANGED
|
@@ -2418,6 +2418,72 @@ function updateArcSegmentInScript(script, animationId, segmentIndex, update) {
|
|
|
2418
2418
|
ms.overwrite(mpProp.value.start, mpProp.value.end, motionPathCode);
|
|
2419
2419
|
return ms.toString();
|
|
2420
2420
|
}
|
|
2421
|
+
function hasCubicSegments(segments) {
|
|
2422
|
+
return segments.some((segment) => segment.cp1 != null || segment.cp2 != null);
|
|
2423
|
+
}
|
|
2424
|
+
function writeMotionPathValue(script, target, waypoints, segments, autoRotate) {
|
|
2425
|
+
const motionPath = findPropertyNode2(target.call.varsArg, "motionPath");
|
|
2426
|
+
if (!motionPath) return script;
|
|
2427
|
+
const code = buildMotionPathObjectCode({ waypoints, segments, autoRotate });
|
|
2428
|
+
const ms = new MagicString(script);
|
|
2429
|
+
ms.overwrite(motionPath.value.start, motionPath.value.end, code);
|
|
2430
|
+
return ms.toString();
|
|
2431
|
+
}
|
|
2432
|
+
function updateMotionPathPointInScript(script, animationId, pointIndex, point) {
|
|
2433
|
+
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2434
|
+
const target = parsed?.located.find((entry) => entry.id === animationId);
|
|
2435
|
+
if (!target?.animation.arcPath?.enabled) return script;
|
|
2436
|
+
const waypoints = extractArcWaypoints(target.animation);
|
|
2437
|
+
if (waypoints.length < 2 || pointIndex < 0 || pointIndex >= waypoints.length) return script;
|
|
2438
|
+
const next = waypoints.map((waypoint, index) => index === pointIndex ? { ...point } : waypoint);
|
|
2439
|
+
return writeMotionPathValue(
|
|
2440
|
+
script,
|
|
2441
|
+
target,
|
|
2442
|
+
next,
|
|
2443
|
+
target.animation.arcPath.segments,
|
|
2444
|
+
target.animation.arcPath.autoRotate
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
function addMotionPathPointInScript(script, animationId, index, point) {
|
|
2448
|
+
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2449
|
+
const target = parsed?.located.find((entry) => entry.id === animationId);
|
|
2450
|
+
const arc = target?.animation.arcPath;
|
|
2451
|
+
if (!target || !arc?.enabled || hasCubicSegments(arc.segments)) return script;
|
|
2452
|
+
const waypoints = extractArcWaypoints(target.animation);
|
|
2453
|
+
if (index < 1 || index > waypoints.length - 1) return script;
|
|
2454
|
+
const segments = [...arc.segments];
|
|
2455
|
+
waypoints.splice(index, 0, { ...point });
|
|
2456
|
+
segments.splice(index - 1, 0, { curviness: segments[index - 1]?.curviness ?? 1 });
|
|
2457
|
+
return writeMotionPathValue(script, target, waypoints, segments, arc.autoRotate);
|
|
2458
|
+
}
|
|
2459
|
+
function removeMotionPathPointInScript(script, animationId, index) {
|
|
2460
|
+
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2461
|
+
const target = parsed?.located.find((entry) => entry.id === animationId);
|
|
2462
|
+
const arc = target?.animation.arcPath;
|
|
2463
|
+
if (!target || !arc?.enabled || hasCubicSegments(arc.segments)) return script;
|
|
2464
|
+
const waypoints = extractArcWaypoints(target.animation);
|
|
2465
|
+
if (waypoints.length <= 2 || index < 0 || index >= waypoints.length) return script;
|
|
2466
|
+
const segments = [...arc.segments];
|
|
2467
|
+
waypoints.splice(index, 1);
|
|
2468
|
+
segments.splice(Math.min(index, segments.length - 1), 1);
|
|
2469
|
+
return writeMotionPathValue(script, target, waypoints, segments, arc.autoRotate);
|
|
2470
|
+
}
|
|
2471
|
+
function addMotionPathToScript(script, targetSelector, position, duration, point, ease = "power1.inOut") {
|
|
2472
|
+
const motionPath = buildMotionPathObjectCode({
|
|
2473
|
+
waypoints: [{ x: 0, y: 0 }, { ...point }],
|
|
2474
|
+
segments: [{ curviness: 1 }],
|
|
2475
|
+
autoRotate: false
|
|
2476
|
+
});
|
|
2477
|
+
const result = addAnimationToScript(script, {
|
|
2478
|
+
targetSelector,
|
|
2479
|
+
method: "to",
|
|
2480
|
+
position,
|
|
2481
|
+
duration,
|
|
2482
|
+
ease,
|
|
2483
|
+
properties: { motionPath: `__raw:${motionPath}` }
|
|
2484
|
+
});
|
|
2485
|
+
return { script: result.script, id: result.id || null };
|
|
2486
|
+
}
|
|
2421
2487
|
function removeArcPathFromScript(script, animationId) {
|
|
2422
2488
|
return setArcPathInScript(script, animationId, {
|
|
2423
2489
|
enabled: false,
|
|
@@ -2456,6 +2522,57 @@ function insertInheritedStateSetInScript(script, selector, position, properties)
|
|
|
2456
2522
|
}
|
|
2457
2523
|
return ms.toString();
|
|
2458
2524
|
}
|
|
2525
|
+
var STUDIO_HOLD_MARKER = "hf-hold";
|
|
2526
|
+
function isStudioHoldSet(animation) {
|
|
2527
|
+
return animation.method === "set" && animation.properties.data === STUDIO_HOLD_MARKER;
|
|
2528
|
+
}
|
|
2529
|
+
function removeStudioHoldSets(script, parsed) {
|
|
2530
|
+
const staleHolds = parsed.located.filter((entry) => isStudioHoldSet(entry.animation));
|
|
2531
|
+
if (staleHolds.length === 0) return script;
|
|
2532
|
+
const ms = new MagicString(script);
|
|
2533
|
+
for (const hold of staleHolds) removeCallFromMagicString(ms, hold.call, script);
|
|
2534
|
+
return ms.toString();
|
|
2535
|
+
}
|
|
2536
|
+
function animationStart(animation) {
|
|
2537
|
+
if (animation.resolvedStart !== void 0) return animation.resolvedStart;
|
|
2538
|
+
return typeof animation.position === "number" ? animation.position : 0;
|
|
2539
|
+
}
|
|
2540
|
+
function positionProperties(properties) {
|
|
2541
|
+
const position = {};
|
|
2542
|
+
for (const [property, value] of Object.entries(properties)) {
|
|
2543
|
+
if (classifyPropertyGroup(property) === "position" && typeof value === "number") {
|
|
2544
|
+
position[property] = value;
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
return position;
|
|
2548
|
+
}
|
|
2549
|
+
function positionHoldForAnimation(animation) {
|
|
2550
|
+
if (!animation.keyframes) return null;
|
|
2551
|
+
if (!(animationStart(animation) > 1e-3)) return null;
|
|
2552
|
+
const first = [...animation.keyframes.keyframes].sort(
|
|
2553
|
+
(left, right) => left.percentage - right.percentage
|
|
2554
|
+
)[0];
|
|
2555
|
+
if (!first) return null;
|
|
2556
|
+
const position = positionProperties(first.properties);
|
|
2557
|
+
return Object.keys(position).length > 0 ? position : null;
|
|
2558
|
+
}
|
|
2559
|
+
function syncPositionHoldsBeforeKeyframes(script) {
|
|
2560
|
+
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2561
|
+
if (!parsed) return script;
|
|
2562
|
+
let result = removeStudioHoldSets(script, parsed);
|
|
2563
|
+
const current = parseGsapScriptAcornForWrite(result);
|
|
2564
|
+
if (!current) return result;
|
|
2565
|
+
for (const entry of current.located) {
|
|
2566
|
+
const animation = entry.animation;
|
|
2567
|
+
const position = positionHoldForAnimation(animation);
|
|
2568
|
+
if (!position) continue;
|
|
2569
|
+
result = insertInheritedStateSetInScript(result, animation.targetSelector, 0, {
|
|
2570
|
+
...position,
|
|
2571
|
+
data: STUDIO_HOLD_MARKER
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
return result;
|
|
2575
|
+
}
|
|
2459
2576
|
function computeForwardBaselines(matching, splitTime) {
|
|
2460
2577
|
const before = [];
|
|
2461
2578
|
const acc = {};
|
|
@@ -2746,6 +2863,8 @@ export {
|
|
|
2746
2863
|
addAnimationWithKeyframesToScript,
|
|
2747
2864
|
addKeyframeToScript,
|
|
2748
2865
|
addLabelToScript,
|
|
2866
|
+
addMotionPathPointInScript,
|
|
2867
|
+
addMotionPathToScript,
|
|
2749
2868
|
convertToKeyframesFromScript,
|
|
2750
2869
|
dedupePositionWritesInScript,
|
|
2751
2870
|
materializeKeyframesFromScript,
|
|
@@ -2755,6 +2874,7 @@ export {
|
|
|
2755
2874
|
removeArcPathFromScript,
|
|
2756
2875
|
removeKeyframeFromScript,
|
|
2757
2876
|
removeLabelFromScript,
|
|
2877
|
+
removeMotionPathPointInScript,
|
|
2758
2878
|
removePropertyFromAnimation,
|
|
2759
2879
|
resizeKeyframedTweenInScript,
|
|
2760
2880
|
scalePositionsInScript,
|
|
@@ -2762,9 +2882,11 @@ export {
|
|
|
2762
2882
|
shiftPositionsInScript,
|
|
2763
2883
|
splitAnimationsInScript,
|
|
2764
2884
|
splitIntoPropertyGroupsFromScript,
|
|
2885
|
+
syncPositionHoldsBeforeKeyframes,
|
|
2765
2886
|
unrollDynamicAnimations,
|
|
2766
2887
|
updateAnimationInScript,
|
|
2767
2888
|
updateArcSegmentInScript,
|
|
2768
|
-
updateKeyframeInScript
|
|
2889
|
+
updateKeyframeInScript,
|
|
2890
|
+
updateMotionPathPointInScript
|
|
2769
2891
|
};
|
|
2770
2892
|
//# sourceMappingURL=gsapWriterAcorn.js.map
|