@hyperframes/parsers 0.8.114 → 0.8.116
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/gsapParserAcorn.js +1 -1
- package/dist/gsapParserAcorn.js.map +1 -1
- package/dist/gsapParserExports.js.map +1 -1
- package/dist/gsapWriterAcorn.d.ts +18 -1
- package/dist/gsapWriterAcorn.js +66 -2
- package/dist/gsapWriterAcorn.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -101,6 +101,23 @@ declare function materializeKeyframesFromScript(script: string, animationId: str
|
|
|
101
101
|
properties: Record<string, number | string>;
|
|
102
102
|
ease?: string;
|
|
103
103
|
}>, easeEach?: string, resolvedSelector?: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Rewrites a tween as `to()` with these keyframes where it stands: the call keeps its place in the
|
|
106
|
+
* script and its position argument, so a tween placed after it ('>', '<', '+=', none) stays put.
|
|
107
|
+
*/
|
|
108
|
+
declare function replaceTweenWithKeyframesInScript(script: string, animationId: string, edit: {
|
|
109
|
+
targetSelector: string;
|
|
110
|
+
position: number;
|
|
111
|
+
duration: number;
|
|
112
|
+
keyframes: Array<{
|
|
113
|
+
percentage: number;
|
|
114
|
+
properties: Record<string, number | string>;
|
|
115
|
+
ease?: string;
|
|
116
|
+
auto?: boolean;
|
|
117
|
+
}>;
|
|
118
|
+
ease?: string;
|
|
119
|
+
easeEach?: string;
|
|
120
|
+
}): string | null;
|
|
104
121
|
/** Insert a new keyframed `to()` call and return the new animation ID. */
|
|
105
122
|
declare function addAnimationWithKeyframesToScript(script: string, targetSelector: string, position: number, duration: number, keyframes: Array<{
|
|
106
123
|
percentage: number;
|
|
@@ -160,4 +177,4 @@ type UnrollElement = {
|
|
|
160
177
|
*/
|
|
161
178
|
declare function unrollDynamicAnimations(script: string, animationId: string, elements: UnrollElement[]): string;
|
|
162
179
|
|
|
163
|
-
export { type UnrollElement, addAnimationToScript, addAnimationWithKeyframesToScript, addKeyframeToScript, addLabelToScript, addMotionPathPointInScript, addMotionPathToScript, clipQueryRoot, clipTweenMatcher, convertToKeyframesFromScript, copyAnimationsInScript, dedupePositionWritesInScript, hasExplicitTime, materializeKeyframesFromScript, moveKeyframeInScript, removeAllKeyframesFromScript, removeAnimationFromScript, removeArcPathFromScript, removeKeyframeFromScript, removeLabelFromScript, removeMotionPathPointInScript, removePropertyFromAnimation, resizeKeyframedTweenInScript, scalePositionsInScript, setArcPathInScript, shiftPositionsInScript, splitAnimationsInScript, splitIntoPropertyGroupsFromScript, syncPositionHoldsBeforeKeyframes, unrollDynamicAnimations, updateAnimationInScript, updateArcSegmentInScript, updateKeyframeInScript, updateMotionPathPointInScript };
|
|
180
|
+
export { type UnrollElement, addAnimationToScript, addAnimationWithKeyframesToScript, addKeyframeToScript, addLabelToScript, addMotionPathPointInScript, addMotionPathToScript, clipQueryRoot, clipTweenMatcher, convertToKeyframesFromScript, copyAnimationsInScript, dedupePositionWritesInScript, hasExplicitTime, materializeKeyframesFromScript, moveKeyframeInScript, removeAllKeyframesFromScript, removeAnimationFromScript, removeArcPathFromScript, removeKeyframeFromScript, removeLabelFromScript, removeMotionPathPointInScript, removePropertyFromAnimation, replaceTweenWithKeyframesInScript, resizeKeyframedTweenInScript, scalePositionsInScript, setArcPathInScript, shiftPositionsInScript, splitAnimationsInScript, splitIntoPropertyGroupsFromScript, syncPositionHoldsBeforeKeyframes, unrollDynamicAnimations, updateAnimationInScript, updateArcSegmentInScript, updateKeyframeInScript, updateMotionPathPointInScript };
|
package/dist/gsapWriterAcorn.js
CHANGED
|
@@ -1219,6 +1219,41 @@ function resolveTimelinePositions(anims, labelDefs = []) {
|
|
|
1219
1219
|
});
|
|
1220
1220
|
while (labelIdx < sortedLabels.length) defineLabel(sortedLabels[labelIdx++]);
|
|
1221
1221
|
}
|
|
1222
|
+
function collectAddLabelDefs(ast, ref, scope, sortedCalls) {
|
|
1223
|
+
const callKeys = sortedCalls.map((c) => ({
|
|
1224
|
+
site: callSiteStart(c),
|
|
1225
|
+
order: c.node.__hfOrder
|
|
1226
|
+
}));
|
|
1227
|
+
const comesAfter = (site, order, labelSite, labelOrder) => {
|
|
1228
|
+
if (site === void 0) return false;
|
|
1229
|
+
if (site !== labelSite) return site > labelSite;
|
|
1230
|
+
return (order ?? -Infinity) > (labelOrder ?? -Infinity);
|
|
1231
|
+
};
|
|
1232
|
+
const defs = [];
|
|
1233
|
+
acornWalk.simple(ast, {
|
|
1234
|
+
// fallow-ignore-next-line complexity
|
|
1235
|
+
CallExpression(node) {
|
|
1236
|
+
const callee = node.callee;
|
|
1237
|
+
const objMatches = ref.kind === "identifier" ? callee.object?.type === "Identifier" && callee.object.name === ref.name : sameMemberAccess(callee.object, ref.node);
|
|
1238
|
+
if (callee?.type !== "MemberExpression" || !objMatches || callee.property?.name !== "addLabel")
|
|
1239
|
+
return;
|
|
1240
|
+
const nameNode = node.arguments?.[0];
|
|
1241
|
+
const name = typeof nameNode?.value === "string" ? nameNode.value : void 0;
|
|
1242
|
+
if (!name) return;
|
|
1243
|
+
const posVal = resolveNode(node.arguments?.[1], scope);
|
|
1244
|
+
const position = typeof posVal === "number" || typeof posVal === "string" ? posVal : void 0;
|
|
1245
|
+
const labelStart = node.__hfSiteStart ?? callee.property?.start;
|
|
1246
|
+
const labelOrder = node.__hfOrder;
|
|
1247
|
+
let order = sortedCalls.length;
|
|
1248
|
+
if (labelStart !== void 0) {
|
|
1249
|
+
order = callKeys.findIndex((k) => comesAfter(k.site, k.order, labelStart, labelOrder));
|
|
1250
|
+
if (order === -1) order = sortedCalls.length;
|
|
1251
|
+
}
|
|
1252
|
+
defs.push({ name, position, order });
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
return defs;
|
|
1256
|
+
}
|
|
1222
1257
|
function compareByLoc(a, b) {
|
|
1223
1258
|
const aLoc = a.node.callee?.property?.loc?.start;
|
|
1224
1259
|
const bLoc = b.node.callee?.property?.loc?.start;
|
|
@@ -1271,7 +1306,7 @@ function parseGsapScriptAcornForWrite(script) {
|
|
|
1271
1306
|
(call) => tweenCallToAnimation(call, scope, script, identifierBindings)
|
|
1272
1307
|
);
|
|
1273
1308
|
applyTimelineDefaults(rawAnims, detection.defaults);
|
|
1274
|
-
resolveTimelinePositions(rawAnims);
|
|
1309
|
+
resolveTimelinePositions(rawAnims, collectAddLabelDefs(ast, ref, scope, calls));
|
|
1275
1310
|
const animations = assignStableIds(rawAnims);
|
|
1276
1311
|
const located = calls.map((call, i) => ({
|
|
1277
1312
|
id: animations[i].id,
|
|
@@ -1559,7 +1594,8 @@ function overwritePosition(ms, call, position) {
|
|
|
1559
1594
|
if (call.positionArg) {
|
|
1560
1595
|
ms.overwrite(call.positionArg.start, call.positionArg.end, valueToCode(position));
|
|
1561
1596
|
} else {
|
|
1562
|
-
|
|
1597
|
+
const last = call.node.arguments.at(-1);
|
|
1598
|
+
ms.appendLeft(last ? last.end : call.node.end - 1, `, ${valueToCode(position)}`);
|
|
1563
1599
|
}
|
|
1564
1600
|
}
|
|
1565
1601
|
function shiftPositionsInScript(script, targetSelector, delta, root) {
|
|
@@ -2362,6 +2398,33 @@ function materializeKeyframesFromScript(script, animationId, keyframes, easeEach
|
|
|
2362
2398
|
}
|
|
2363
2399
|
return ms.toString();
|
|
2364
2400
|
}
|
|
2401
|
+
function replaceTweenWithKeyframesInScript(script, animationId, edit) {
|
|
2402
|
+
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2403
|
+
const target = parsed?.located.find((l) => l.id === animationId);
|
|
2404
|
+
const call = target?.call;
|
|
2405
|
+
if (!target || call?.varsArg?.type !== "ObjectExpression") return null;
|
|
2406
|
+
const { animation } = target;
|
|
2407
|
+
if (animation.method !== "to" && animation.method !== "from" && animation.method !== "fromTo")
|
|
2408
|
+
return null;
|
|
2409
|
+
const ms = new MagicString(script);
|
|
2410
|
+
const start = animation.resolvedStart ?? animation.position;
|
|
2411
|
+
const moved = typeof start !== "number" || Math.abs(start - edit.position) > 5e-4;
|
|
2412
|
+
const kept = preservedVarsEntries(call.varsArg, script).filter(
|
|
2413
|
+
(e) => !/^\s*duration\s*:/.test(e) && !(moved && /^\s*delay\s*:/.test(e))
|
|
2414
|
+
);
|
|
2415
|
+
const sorted = [...edit.keyframes].sort((a, b) => a.percentage - b.percentage);
|
|
2416
|
+
const parts = [`keyframes: ${buildKeyframeObjectCode(sorted, edit.easeEach)}`, ...kept];
|
|
2417
|
+
parts.push(`duration: ${valueToCode(edit.duration)}`);
|
|
2418
|
+
if (edit.ease) parts.push(`ease: ${JSON.stringify(edit.ease)}`);
|
|
2419
|
+
if (animation.hasUnresolvedSelector || animation.targetSelector !== edit.targetSelector) {
|
|
2420
|
+
const selectorArg = call.node.arguments[0];
|
|
2421
|
+
ms.overwrite(selectorArg.start, selectorArg.end, JSON.stringify(edit.targetSelector));
|
|
2422
|
+
}
|
|
2423
|
+
convertMethodToTo(ms, animation, call, call.varsArg);
|
|
2424
|
+
overwriteVarsArg(ms, call, `{ ${parts.join(", ")} }`);
|
|
2425
|
+
if (moved) overwritePosition(ms, call, edit.position);
|
|
2426
|
+
return ms.toString();
|
|
2427
|
+
}
|
|
2365
2428
|
function addAnimationWithKeyframesToScript(script, targetSelector, position, duration, keyframes, ease, easeEach) {
|
|
2366
2429
|
const parsed = parseGsapScriptAcornForWrite(script);
|
|
2367
2430
|
if (!parsed) return { script, id: "" };
|
|
@@ -3115,6 +3178,7 @@ export {
|
|
|
3115
3178
|
removeLabelFromScript,
|
|
3116
3179
|
removeMotionPathPointInScript,
|
|
3117
3180
|
removePropertyFromAnimation,
|
|
3181
|
+
replaceTweenWithKeyframesInScript,
|
|
3118
3182
|
resizeKeyframedTweenInScript,
|
|
3119
3183
|
scalePositionsInScript,
|
|
3120
3184
|
setArcPathInScript,
|