@pixodesk/svg-animator-core 1.0.43 → 1.0.45
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/README.md +1 -1
- package/dist/{PxDocumentDiagnostic-DkBZYJ7X.d.cts → PxDocumentDiagnostic-CBhVyNEi.d.cts} +127 -91
- package/dist/{PxDocumentDiagnostic-DkBZYJ7X.d.ts → PxDocumentDiagnostic-CBhVyNEi.d.ts} +127 -91
- package/dist/chunk-5HEVTP2N.min.js +1 -0
- package/dist/{chunk-BOTZI36B.js → chunk-YVKMPBHE.js} +2043 -88
- package/dist/chunk-YVKMPBHE.js.map +1 -0
- package/dist/index.cjs +197 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +15 -1881
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.js +1 -1
- package/dist/internal.cjs +3228 -150
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +60 -3
- package/dist/internal.d.ts +60 -3
- package/dist/internal.js +53 -1
- package/dist/internal.js.map +1 -1
- package/dist/internal.min.cjs +1 -1
- package/dist/internal.min.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BOTZI36B.js.map +0 -1
- package/dist/chunk-CAZFG2HW.min.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
OFFSET_DISTANCE_ATTR,
|
|
3
2
|
PX_DEFAULT_DURATION_MS,
|
|
4
3
|
PX_TIMELINE_SHARED_KEYS,
|
|
5
4
|
PX_TIME_ONLY_TIMELINE_KEYS,
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
PxCloneWithout,
|
|
21
20
|
PxControlMode,
|
|
22
21
|
PxDefinitionsSchema,
|
|
22
|
+
PxDiagnosticCode,
|
|
23
23
|
PxDiagnosticKind,
|
|
24
24
|
PxEffectsSchema,
|
|
25
25
|
PxElementAnimationSchema,
|
|
@@ -37,9 +37,10 @@ import {
|
|
|
37
37
|
PxLoopSchema,
|
|
38
38
|
PxMaskType,
|
|
39
39
|
PxMaskedByEffectSchema,
|
|
40
|
+
PxMouseOutAction,
|
|
40
41
|
PxNodeBaseSchema,
|
|
41
42
|
PxNodeSchema,
|
|
42
|
-
|
|
43
|
+
PxOffScreenAction,
|
|
43
44
|
PxPathOverflow,
|
|
44
45
|
PxPinAlign,
|
|
45
46
|
PxPlaybackDirection,
|
|
@@ -53,7 +54,6 @@ import {
|
|
|
53
54
|
PxScrollRangeSchema,
|
|
54
55
|
PxScrollSchema,
|
|
55
56
|
PxScrollSource,
|
|
56
|
-
PxStartOn,
|
|
57
57
|
PxStrokeTrimEffectSchema,
|
|
58
58
|
PxStrokeTrimSubPaths,
|
|
59
59
|
PxSvgNodeRootSchema,
|
|
@@ -68,1883 +68,48 @@ import {
|
|
|
68
68
|
PxTransformPartsSchema,
|
|
69
69
|
PxTransformValueSchema,
|
|
70
70
|
PxTriggerSchema,
|
|
71
|
+
PxTriggerStart,
|
|
71
72
|
PxUnits,
|
|
72
73
|
PxWireStepKind,
|
|
73
74
|
PxWireVersionRelation,
|
|
74
|
-
TRANSFORM_ATTR,
|
|
75
|
-
TRANSFORM_PART,
|
|
76
75
|
__spreadProps,
|
|
77
76
|
__spreadValues,
|
|
78
|
-
applyTextGlyphsAlongPath,
|
|
79
|
-
applyTextGlyphsEffect,
|
|
80
|
-
applyTextPathEffect,
|
|
81
|
-
applyUseOffsetToG,
|
|
82
77
|
applyWireSteps,
|
|
83
|
-
bezier2D_arcLengthLUT,
|
|
84
|
-
bezierToSvgPath,
|
|
85
78
|
calcAnimationValues,
|
|
86
79
|
clamp,
|
|
87
|
-
clone,
|
|
88
80
|
compareWireVersion,
|
|
89
81
|
controlModeTakesOverTrigger,
|
|
90
82
|
convertWireDocument,
|
|
91
|
-
deepClonePxNode,
|
|
92
83
|
describeSchema,
|
|
93
84
|
diagnoseDocument,
|
|
94
85
|
downgradeWireDocument,
|
|
95
86
|
flattenAnimatorTimeline,
|
|
96
87
|
formatWireVersion,
|
|
97
|
-
genId,
|
|
98
88
|
generateNewIds,
|
|
99
89
|
getAnimatorConfig,
|
|
100
90
|
getBindings,
|
|
101
91
|
getChildren,
|
|
102
92
|
getDefinitions,
|
|
103
|
-
indexById,
|
|
104
93
|
isNativeForced,
|
|
105
94
|
isPxDocument,
|
|
106
95
|
isValidPxDocument,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
keyframeTangentOut,
|
|
110
|
-
keyframeTime,
|
|
111
|
-
keyframeValue,
|
|
112
|
-
keyframeWith,
|
|
113
|
-
materializeInternalLoopsInTree,
|
|
114
|
-
materializeMotionPathsInTree,
|
|
96
|
+
materializeAllInTree,
|
|
97
|
+
materializeNodeEffects,
|
|
115
98
|
mayUseNativeScrollTimeline,
|
|
116
99
|
nestAnimatorTimeline,
|
|
117
100
|
normalizeBindings,
|
|
118
|
-
parseSvgPathToBezier,
|
|
119
101
|
parseWireVersion,
|
|
120
|
-
partsRecord,
|
|
121
102
|
px,
|
|
122
|
-
readAnimatable,
|
|
123
|
-
readStaticOrigin,
|
|
124
103
|
readWireVersion,
|
|
125
|
-
regenerateIdsAndRewriteRefs,
|
|
126
|
-
regenerateIdsInClone,
|
|
127
104
|
resolveControlMode,
|
|
128
105
|
resolveTimelineEngine,
|
|
129
106
|
resolveTrigger,
|
|
130
107
|
schemaKeys,
|
|
131
|
-
spliceDefs,
|
|
132
|
-
stripHash,
|
|
133
108
|
toDomProps,
|
|
134
109
|
validateDocument,
|
|
135
110
|
validateNodeEffects,
|
|
136
|
-
wireVersionAdvice
|
|
137
|
-
|
|
138
|
-
} from "./chunk-BOTZI36B.js";
|
|
139
|
-
|
|
140
|
-
// src/effects/transform/transformationEffect.ts
|
|
141
|
-
function applyTransformByEffect(node, fx, ctx) {
|
|
142
|
-
if (!fx) return node;
|
|
143
|
-
delete node.transform;
|
|
144
|
-
let n = node;
|
|
145
|
-
n = wrapOrigin(
|
|
146
|
-
n,
|
|
147
|
-
fx.origin,
|
|
148
|
-
/*invert=*/
|
|
149
|
-
true
|
|
150
|
-
);
|
|
151
|
-
n = wrapTransformPart(n, "scale" /* Scale */, normalizeScale(fx.scale), ctx);
|
|
152
|
-
n = wrapTransformPart(n, "skew" /* Skew */, fx.skew, ctx);
|
|
153
|
-
n = wrapTransformPart(n, "rotate" /* Rotate */, fx.rotate, ctx);
|
|
154
|
-
n = wrapOrigin(
|
|
155
|
-
n,
|
|
156
|
-
fx.origin,
|
|
157
|
-
/*invert=*/
|
|
158
|
-
false
|
|
159
|
-
);
|
|
160
|
-
if (translateHasAutoOrient(fx.translate)) {
|
|
161
|
-
n = wrapOrigin(
|
|
162
|
-
n,
|
|
163
|
-
fx.origin,
|
|
164
|
-
/*invert=*/
|
|
165
|
-
true
|
|
166
|
-
);
|
|
167
|
-
n = wrapTransformPart(n, "translate" /* Translate */, fx.translate, ctx);
|
|
168
|
-
n = wrapOrigin(
|
|
169
|
-
n,
|
|
170
|
-
fx.origin,
|
|
171
|
-
/*invert=*/
|
|
172
|
-
false
|
|
173
|
-
);
|
|
174
|
-
} else {
|
|
175
|
-
n = wrapTransformPart(n, "translate" /* Translate */, fx.translate, ctx);
|
|
176
|
-
}
|
|
177
|
-
if (n !== node && node.id) {
|
|
178
|
-
n.id = node.id;
|
|
179
|
-
delete node.id;
|
|
180
|
-
}
|
|
181
|
-
return n;
|
|
182
|
-
}
|
|
183
|
-
function translateHasAutoOrient(translate) {
|
|
184
|
-
if (!translate || typeof translate !== "object") return false;
|
|
185
|
-
const obj = translate;
|
|
186
|
-
if (obj.autoOrient) return true;
|
|
187
|
-
return Array.isArray(obj.keyframes) && obj.keyframes.some((kf) => kf.tangentOut || kf.tangentIn);
|
|
188
|
-
}
|
|
189
|
-
function normalizeScale(raw) {
|
|
190
|
-
return raw;
|
|
191
|
-
}
|
|
192
|
-
function wrapTransformPart(inner, part, raw, ctx) {
|
|
193
|
-
if (raw === void 0) return inner;
|
|
194
|
-
const v = readAnimatable(raw);
|
|
195
|
-
if (v.kind === "static" /* Static */) {
|
|
196
|
-
return { type: "g", transform: { value: partsRecord(part, v.value, void 0) }, children: [inner] };
|
|
197
|
-
}
|
|
198
|
-
if (v.kind === "animated" /* Animated */) {
|
|
199
|
-
const animTr = { keyframes: v.keyframes.map((kf) => keyframeWith(kf, partsRecord(part, kf.value, void 0))) };
|
|
200
|
-
if (v.autoOrient) animTr.autoOrient = true;
|
|
201
|
-
if (v.loop !== void 0) animTr.loop = v.loop;
|
|
202
|
-
return {
|
|
203
|
-
type: "g",
|
|
204
|
-
animate: { transform: animTr },
|
|
205
|
-
children: [inner]
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
return inner;
|
|
209
|
-
}
|
|
210
|
-
function wrapOrigin(inner, raw, invert) {
|
|
211
|
-
if (raw === void 0) return inner;
|
|
212
|
-
const v = readAnimatable(raw);
|
|
213
|
-
const sign = (value) => invert ? [-value[0], -value[1]] : value;
|
|
214
|
-
if (v.kind === "absent" /* Absent */) return inner;
|
|
215
|
-
if (v.kind === "static" /* Static */) {
|
|
216
|
-
if (v.value[0] === 0 && v.value[1] === 0) return inner;
|
|
217
|
-
return { type: "g", transform: { value: { translate: sign(v.value) } }, children: [inner] };
|
|
218
|
-
}
|
|
219
|
-
if (v.kind === "animated" /* Animated */) {
|
|
220
|
-
const animTr = { keyframes: v.keyframes.map((kf) => keyframeWith(kf, { translate: sign(kf.value) })) };
|
|
221
|
-
if (v.loop !== void 0) animTr.loop = v.loop;
|
|
222
|
-
return {
|
|
223
|
-
type: "g",
|
|
224
|
-
animate: { transform: animTr },
|
|
225
|
-
children: [inner]
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
return inner;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/effects/reference/contentRefSplit.ts
|
|
232
|
-
function identifyContentRefTargets(node, ctx, allocator) {
|
|
233
|
-
var _a, _b, _c;
|
|
234
|
-
if (node.type === "use" && ((_b = (_a = node.effects) == null ? void 0 : _a.clone) == null ? void 0 : _b.without) === "translate") {
|
|
235
|
-
const sourceId = stripHash(node.effects.clone.source);
|
|
236
|
-
if (typeof sourceId === "string" && sourceId && !ctx.contentRefInnerIds.has(sourceId)) {
|
|
237
|
-
ctx.contentRefInnerIds.set(sourceId, allocator(sourceId));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
(_c = node.children) == null ? void 0 : _c.forEach((c) => identifyContentRefTargets(c, ctx, allocator));
|
|
241
|
-
}
|
|
242
|
-
function splitForContentRef(node, transformBy, originalId, innerId, ctx) {
|
|
243
|
-
const outerBody = liftBodyTranslate(node, transformBy);
|
|
244
|
-
if (typeof node.id === "string") delete node.id;
|
|
245
|
-
const { outer: outerTr, inner: innerTr } = splitTransformByEffect(transformBy);
|
|
246
|
-
let innerNode = node;
|
|
247
|
-
innerNode = applyTransformByEffect(innerNode, innerTr, ctx);
|
|
248
|
-
const innerWrapper = { type: "g", id: innerId, children: [innerNode] };
|
|
249
|
-
let outerWrapper = { type: "g", id: originalId, children: [innerWrapper] };
|
|
250
|
-
if (outerBody.transform !== void 0) outerWrapper.transform = outerBody.transform;
|
|
251
|
-
if (outerBody.animate !== void 0) outerWrapper.animate = outerBody.animate;
|
|
252
|
-
if (outerTr) {
|
|
253
|
-
delete outerWrapper.id;
|
|
254
|
-
outerWrapper = applyTransformByEffect(outerWrapper, outerTr, ctx);
|
|
255
|
-
outerWrapper.id = originalId;
|
|
256
|
-
}
|
|
257
|
-
return outerWrapper;
|
|
258
|
-
}
|
|
259
|
-
function liftBodyTranslate(node, transformBy) {
|
|
260
|
-
var _a, _b, _c;
|
|
261
|
-
const out = {};
|
|
262
|
-
let didLiftAnimate = false;
|
|
263
|
-
const animTr = (_a = node.animate) == null ? void 0 : _a.transform;
|
|
264
|
-
if (animTr && typeof animTr === "object" && Array.isArray(animTr.keyframes)) {
|
|
265
|
-
const kfs = animTr.keyframes;
|
|
266
|
-
const hasTranslate = kfs.some((kf) => kf.value && kf.value.translate);
|
|
267
|
-
if (hasTranslate) {
|
|
268
|
-
const outerHasOrigin = needsOriginOnOuter(animTr);
|
|
269
|
-
const outerKfs = kfs.map((kf) => {
|
|
270
|
-
const v = kf.value || {};
|
|
271
|
-
const newValue = {};
|
|
272
|
-
if (v.translate !== void 0) newValue.translate = v.translate;
|
|
273
|
-
if (outerHasOrigin && v.origin !== void 0) newValue.origin = v.origin;
|
|
274
|
-
const outerKf = { value: newValue };
|
|
275
|
-
if (kf.time !== void 0) outerKf.time = kf.time;
|
|
276
|
-
if (kf.easing !== void 0) outerKf.easing = kf.easing;
|
|
277
|
-
if (kf.tangentOut !== void 0) outerKf.tangentOut = kf.tangentOut;
|
|
278
|
-
if (kf.tangentIn !== void 0) outerKf.tangentIn = kf.tangentIn;
|
|
279
|
-
return outerKf;
|
|
280
|
-
});
|
|
281
|
-
const outerAnimTr = { keyframes: outerKfs };
|
|
282
|
-
if (animTr.autoOrient) outerAnimTr.autoOrient = true;
|
|
283
|
-
const srcLoop = animTr.loop;
|
|
284
|
-
if (srcLoop !== void 0) outerAnimTr.loop = srcLoop;
|
|
285
|
-
out.animate = { transform: outerAnimTr };
|
|
286
|
-
const innerHasPivotedPart = kfs.some((kf) => {
|
|
287
|
-
const v = kf.value || {};
|
|
288
|
-
return v.rotate !== void 0 || v.scale !== void 0;
|
|
289
|
-
});
|
|
290
|
-
const innerKfs = kfs.map((kf) => {
|
|
291
|
-
const v = kf.value || {};
|
|
292
|
-
const newValue = {};
|
|
293
|
-
if (v.rotate !== void 0) newValue.rotate = v.rotate;
|
|
294
|
-
if (v.scale !== void 0) newValue.scale = v.scale;
|
|
295
|
-
if (v.origin !== void 0 && (!outerHasOrigin || innerHasPivotedPart)) newValue.origin = v.origin;
|
|
296
|
-
const innerKf = { value: newValue };
|
|
297
|
-
if (kf.time !== void 0) innerKf.time = kf.time;
|
|
298
|
-
if (kf.easing !== void 0) innerKf.easing = kf.easing;
|
|
299
|
-
return innerKf;
|
|
300
|
-
});
|
|
301
|
-
const allInnerEmpty = innerKfs.every((kf) => Object.keys(kf.value).length === 0);
|
|
302
|
-
if (allInnerEmpty) {
|
|
303
|
-
delete node.animate.transform;
|
|
304
|
-
if (node.animate && Object.keys(node.animate).length === 0) delete node.animate;
|
|
305
|
-
} else {
|
|
306
|
-
const innerAnimTr = { keyframes: innerKfs };
|
|
307
|
-
if (srcLoop !== void 0) innerAnimTr.loop = srcLoop;
|
|
308
|
-
node.animate.transform = innerAnimTr;
|
|
309
|
-
}
|
|
310
|
-
didLiftAnimate = true;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
const transformationHasTranslate = (transformBy == null ? void 0 : transformBy.translate) !== void 0;
|
|
314
|
-
const stripBodyTranslateOnly = didLiftAnimate || transformationHasTranslate;
|
|
315
|
-
const liftedAnimateIsAutoOriented = didLiftAnimate && needsOriginOnOuter(((_b = node.animate) == null ? void 0 : _b.transform) || void 0) || didLiftAnimate && needsOriginOnOuter(((_c = out.animate) == null ? void 0 : _c.transform) || void 0);
|
|
316
|
-
if (typeof node.transform === "string") {
|
|
317
|
-
const split = splitTransformString(node.transform);
|
|
318
|
-
if (stripBodyTranslateOnly) {
|
|
319
|
-
if (split.translate !== void 0) {
|
|
320
|
-
if (split.rest) node.transform = split.rest;
|
|
321
|
-
else delete node.transform;
|
|
322
|
-
} else if (isPureTranslateBody(node.transform)) {
|
|
323
|
-
delete node.transform;
|
|
324
|
-
} else if (liftedAnimateIsAutoOriented && isSingleMatrixBody(node.transform)) {
|
|
325
|
-
delete node.transform;
|
|
326
|
-
}
|
|
327
|
-
} else if (split.translate) {
|
|
328
|
-
out.transform = split.translate;
|
|
329
|
-
if (split.rest) node.transform = split.rest;
|
|
330
|
-
else delete node.transform;
|
|
331
|
-
}
|
|
332
|
-
} else if (node.transform && typeof node.transform === "object" && !Array.isArray(node.transform) && !node.transform.keyframes) {
|
|
333
|
-
const wrapped = node.transform.value;
|
|
334
|
-
const isWrapped = !!(wrapped && typeof wrapped === "object");
|
|
335
|
-
const value = isWrapped ? wrapped : node.transform;
|
|
336
|
-
const rewrap = (rec) => isWrapped ? { value: rec } : rec;
|
|
337
|
-
if (Array.isArray(value.translate)) {
|
|
338
|
-
const rest = __spreadValues({}, value);
|
|
339
|
-
delete rest.translate;
|
|
340
|
-
const hasRest = Object.keys(rest).length > 0;
|
|
341
|
-
if (stripBodyTranslateOnly) {
|
|
342
|
-
if (hasRest) node.transform = rewrap(rest);
|
|
343
|
-
else delete node.transform;
|
|
344
|
-
} else {
|
|
345
|
-
out.transform = rewrap({ translate: value.translate });
|
|
346
|
-
if (hasRest) node.transform = rewrap(rest);
|
|
347
|
-
else delete node.transform;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return out;
|
|
352
|
-
}
|
|
353
|
-
function isSingleMatrixBody(s) {
|
|
354
|
-
const re = /(translate|rotate|scale|matrix|skewX|skewY)\(([^)]*)\)/g;
|
|
355
|
-
let count = 0;
|
|
356
|
-
let isMatrix = false;
|
|
357
|
-
let m;
|
|
358
|
-
while (m = re.exec(s)) {
|
|
359
|
-
count++;
|
|
360
|
-
if (m[1] === "matrix") isMatrix = true;
|
|
361
|
-
}
|
|
362
|
-
return count === 1 && isMatrix;
|
|
363
|
-
}
|
|
364
|
-
function isPureTranslateBody(s) {
|
|
365
|
-
const re = /(translate|rotate|scale|matrix|skewX|skewY)\(([^)]*)\)/g;
|
|
366
|
-
const ops = [];
|
|
367
|
-
let m;
|
|
368
|
-
while (m = re.exec(s)) ops.push({ name: m[1], full: m[0] });
|
|
369
|
-
if (ops.length !== 1) return false;
|
|
370
|
-
if (ops[0].name === "translate") return true;
|
|
371
|
-
if (ops[0].name !== "matrix") return false;
|
|
372
|
-
const args = /matrix\(([^)]*)\)/.exec(ops[0].full);
|
|
373
|
-
if (!args) return false;
|
|
374
|
-
const nums = args[1].split(/[\s,]+/).filter(Boolean).map(Number);
|
|
375
|
-
return nums.length >= 4 && nums[0] === 1 && nums[1] === 0 && nums[2] === 0 && nums[3] === 1;
|
|
376
|
-
}
|
|
377
|
-
function splitTransformString(s) {
|
|
378
|
-
const ops = [];
|
|
379
|
-
const re = /(translate|rotate|scale|matrix|skewX|skewY)\(([^)]*)\)/g;
|
|
380
|
-
let m;
|
|
381
|
-
while (m = re.exec(s)) ops.push({ name: m[1], full: m[0] });
|
|
382
|
-
if (!ops.length) return { rest: s || void 0 };
|
|
383
|
-
if (ops.every((o) => o.name === "translate")) {
|
|
384
|
-
return { translate: ops.map((o) => o.full).join("") };
|
|
385
|
-
}
|
|
386
|
-
const leading = ops[0];
|
|
387
|
-
const trailing = ops[ops.length - 1];
|
|
388
|
-
if (trailing.name === "translate" && leading.name === "translate") {
|
|
389
|
-
const trailingVec = parseTranslateArgs(trailing.full);
|
|
390
|
-
const leadingVec = parseTranslateArgs(leading.full);
|
|
391
|
-
const ox = -trailingVec[0];
|
|
392
|
-
const oy = -trailingVec[1];
|
|
393
|
-
const userTx = leadingVec[0] - ox;
|
|
394
|
-
const userTy = leadingVec[1] - oy;
|
|
395
|
-
if (userTx === 0 && userTy === 0) return { rest: s };
|
|
396
|
-
const middleAndTrailing = "translate(" + ox + "," + oy + ")" + ops.slice(1).map((o) => o.full).join("");
|
|
397
|
-
return { translate: "translate(" + userTx + "," + userTy + ")", rest: middleAndTrailing };
|
|
398
|
-
}
|
|
399
|
-
if (trailing.name === "translate") return { rest: s };
|
|
400
|
-
const lifted = [];
|
|
401
|
-
let i = 0;
|
|
402
|
-
while (i < ops.length && ops[i].name === "translate") {
|
|
403
|
-
lifted.push(ops[i].full);
|
|
404
|
-
i++;
|
|
405
|
-
}
|
|
406
|
-
if (!lifted.length) return { rest: s };
|
|
407
|
-
const rest = ops.slice(i).map((o) => o.full).join("");
|
|
408
|
-
return {
|
|
409
|
-
translate: lifted.join(""),
|
|
410
|
-
rest: rest || void 0
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
function parseTranslateArgs(translateOp) {
|
|
414
|
-
const m = /translate\(([^)]*)\)/.exec(translateOp);
|
|
415
|
-
if (!m) return [0, 0];
|
|
416
|
-
const nums = m[1].split(/[\s,]+/).filter(Boolean).map(Number);
|
|
417
|
-
return [nums[0] || 0, nums[1] || 0];
|
|
418
|
-
}
|
|
419
|
-
function splitTransformByEffect(fx) {
|
|
420
|
-
if (!fx) return {};
|
|
421
|
-
const originOnOuter = needsOriginOnOuter(fx.translate);
|
|
422
|
-
const innerHasPivotedPart = fx.rotate !== void 0 || fx.scale !== void 0;
|
|
423
|
-
const outer = {};
|
|
424
|
-
const inner = {};
|
|
425
|
-
if (fx.translate !== void 0) outer.translate = fx.translate;
|
|
426
|
-
if (originOnOuter && fx.origin !== void 0) outer.origin = fx.origin;
|
|
427
|
-
if (fx.rotate !== void 0) inner.rotate = fx.rotate;
|
|
428
|
-
if (fx.scale !== void 0) inner.scale = fx.scale;
|
|
429
|
-
if (fx.skew !== void 0) inner.skew = fx.skew;
|
|
430
|
-
if (fx.origin !== void 0 && (!originOnOuter || innerHasPivotedPart)) inner.origin = fx.origin;
|
|
431
|
-
return {
|
|
432
|
-
outer: Object.keys(outer).length ? outer : void 0,
|
|
433
|
-
inner: Object.keys(inner).length ? inner : void 0
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
function needsOriginOnOuter(translateAnim) {
|
|
437
|
-
if (!translateAnim || typeof translateAnim !== "object") return false;
|
|
438
|
-
const obj = translateAnim;
|
|
439
|
-
if (obj.autoOrient) return true;
|
|
440
|
-
if (Array.isArray(obj.keyframes)) {
|
|
441
|
-
return obj.keyframes.some((kf) => kf.tangentOut || kf.tangentIn);
|
|
442
|
-
}
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// src/effects/paint/gradientEffect.ts
|
|
447
|
-
function applyFillGradientEffect(node, fx, ctx) {
|
|
448
|
-
return applyGradient(node, fx, ctx, "fill");
|
|
449
|
-
}
|
|
450
|
-
function applyStrokeGradientEffect(node, fx, ctx) {
|
|
451
|
-
return applyGradient(node, fx, ctx, "stroke");
|
|
452
|
-
}
|
|
453
|
-
function applyGradient(node, fx, ctx, attr) {
|
|
454
|
-
if (!fx) return node;
|
|
455
|
-
const id = genId(ctx, "grad");
|
|
456
|
-
const def = synthesiseGradientDef(fx, id, ctx);
|
|
457
|
-
ctx.defs.push(def);
|
|
458
|
-
node[attr] = "url(#" + id + ")";
|
|
459
|
-
return node;
|
|
460
|
-
}
|
|
461
|
-
function synthesiseGradientDef(fx, id, ctx) {
|
|
462
|
-
const out = {
|
|
463
|
-
type: fx.type === PxGradientType.radial ? "radialGradient" : "linearGradient",
|
|
464
|
-
id
|
|
465
|
-
};
|
|
466
|
-
if (fx.type === PxGradientType.linear) {
|
|
467
|
-
applyGeomVec(out, "x1", "y1", fx.start);
|
|
468
|
-
applyGeomVec(out, "x2", "y2", fx.end);
|
|
469
|
-
} else {
|
|
470
|
-
applyGeomVec(out, "cx", "cy", fx.center);
|
|
471
|
-
applyGeomNumber(out, "r", fx.radius);
|
|
472
|
-
applyGeomVec(out, "fx", "fy", fx.focal);
|
|
473
|
-
}
|
|
474
|
-
if (fx.gradientUnits) out.gradientUnits = fx.gradientUnits;
|
|
475
|
-
if (fx.spreadMethod) out.spreadMethod = fx.spreadMethod;
|
|
476
|
-
if (fx.gradientTransform) out.gradientTransform = fx.gradientTransform;
|
|
477
|
-
out.children = buildStopChildren(fx.stops, ctx);
|
|
478
|
-
return out;
|
|
479
|
-
}
|
|
480
|
-
function applyGeomVec(out, xAttr, yAttr, raw) {
|
|
481
|
-
var _a, _b, _c;
|
|
482
|
-
const read = readAnimatable(raw);
|
|
483
|
-
if (read.kind === "absent" /* Absent */) return;
|
|
484
|
-
if (read.kind === "static" /* Static */) {
|
|
485
|
-
out[xAttr] = String(read.value[0]);
|
|
486
|
-
out[yAttr] = String(read.value[1]);
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
const axisChannel = (idx) => {
|
|
490
|
-
const block = {
|
|
491
|
-
keyframes: read.keyframes.map((kf) => {
|
|
492
|
-
const axisKf = { time: kf.time, value: Array.isArray(kf.value) ? kf.value[idx] : void 0 };
|
|
493
|
-
if (kf.easing !== void 0) axisKf.easing = kf.easing;
|
|
494
|
-
return axisKf;
|
|
495
|
-
})
|
|
496
|
-
};
|
|
497
|
-
if (read.loop !== void 0) block.loop = read.loop;
|
|
498
|
-
return block;
|
|
499
|
-
};
|
|
500
|
-
const animate = (_a = out.animate) != null ? _a : {};
|
|
501
|
-
animate[xAttr] = axisChannel(0);
|
|
502
|
-
animate[yAttr] = axisChannel(1);
|
|
503
|
-
out.animate = animate;
|
|
504
|
-
const baseline = (_c = read.base) != null ? _c : (_b = read.keyframes[0]) == null ? void 0 : _b.value;
|
|
505
|
-
if (Array.isArray(baseline)) {
|
|
506
|
-
out[xAttr] = String(baseline[0]);
|
|
507
|
-
out[yAttr] = String(baseline[1]);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
function applyGeomNumber(out, attrName, raw) {
|
|
511
|
-
const read = readAnimatable(raw);
|
|
512
|
-
if (read.kind === "absent" /* Absent */) return;
|
|
513
|
-
writeAnimatableChannel(out, attrName, read, { asString: true });
|
|
514
|
-
}
|
|
515
|
-
function buildStopChildren(stops, ctx) {
|
|
516
|
-
var _a, _b;
|
|
517
|
-
if (!stops) return [];
|
|
518
|
-
const read = readAnimatable(stops);
|
|
519
|
-
if (read.kind === "absent" /* Absent */) return [];
|
|
520
|
-
if (read.kind === "static" /* Static */) return Array.isArray(read.value) ? read.value.map(staticStopNode) : [];
|
|
521
|
-
const kfs = read.keyframes;
|
|
522
|
-
if (!kfs.length) return [];
|
|
523
|
-
const loopFromSource = read.loop;
|
|
524
|
-
let stopCount = 0;
|
|
525
|
-
for (const kf of kfs) {
|
|
526
|
-
const v = keyframeValue(kf);
|
|
527
|
-
if (Array.isArray(v) && v.length > stopCount) stopCount = v.length;
|
|
528
|
-
}
|
|
529
|
-
if (!stopCount) return [];
|
|
530
|
-
const firstKfValue = keyframeValue(kfs[0]);
|
|
531
|
-
const baselineStops = [];
|
|
532
|
-
for (let i = 0; i < stopCount; i++) {
|
|
533
|
-
const s = (_b = (_a = firstKfValue == null ? void 0 : firstKfValue[i]) != null ? _a : prevDefinedStop(kfs, 0, i)) != null ? _b : { offset: i / Math.max(1, stopCount - 1), color: "#000000" };
|
|
534
|
-
baselineStops.push({ offset: s.offset, color: s.color });
|
|
535
|
-
}
|
|
536
|
-
return baselineStops.map((bs, i) => animatedStopNode(bs, kfs, i, ctx, loopFromSource));
|
|
537
|
-
}
|
|
538
|
-
function staticStopNode(s) {
|
|
539
|
-
return {
|
|
540
|
-
type: "stop",
|
|
541
|
-
offset: formatOffset(s.offset),
|
|
542
|
-
stopColor: s.color
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
function animatedStopNode(baseline, kfs, stopIdx, _ctx, loop) {
|
|
546
|
-
var _a;
|
|
547
|
-
const colorKfs = [];
|
|
548
|
-
const offsetKfs = [];
|
|
549
|
-
let offsetVaries = false;
|
|
550
|
-
for (const kf of kfs) {
|
|
551
|
-
const t = keyframeTime(kf);
|
|
552
|
-
const arr = keyframeValue(kf);
|
|
553
|
-
const sliced = (_a = arr == null ? void 0 : arr[stopIdx]) != null ? _a : prevDefinedStop(kfs, kfs.indexOf(kf), stopIdx);
|
|
554
|
-
if (!sliced) continue;
|
|
555
|
-
const easing = keyframeEasing(kf);
|
|
556
|
-
const colorOut = { time: t, value: sliced.color };
|
|
557
|
-
if (easing !== void 0) colorOut.easing = easing;
|
|
558
|
-
colorKfs.push(colorOut);
|
|
559
|
-
const offsetOut = { time: t, value: sliced.offset };
|
|
560
|
-
if (easing !== void 0) offsetOut.easing = easing;
|
|
561
|
-
offsetKfs.push(offsetOut);
|
|
562
|
-
if (sliced.offset !== baseline.offset) offsetVaries = true;
|
|
563
|
-
}
|
|
564
|
-
const stop = {
|
|
565
|
-
type: "stop",
|
|
566
|
-
offset: formatOffset(baseline.offset),
|
|
567
|
-
stopColor: baseline.color
|
|
568
|
-
};
|
|
569
|
-
const animate = {};
|
|
570
|
-
if (colorKfs.length) {
|
|
571
|
-
animate.stopColor = { keyframes: colorKfs };
|
|
572
|
-
if (loop !== void 0) animate.stopColor.loop = loop;
|
|
573
|
-
}
|
|
574
|
-
if (offsetVaries && offsetKfs.length) {
|
|
575
|
-
animate.offset = { keyframes: offsetKfs };
|
|
576
|
-
if (loop !== void 0) animate.offset.loop = loop;
|
|
577
|
-
}
|
|
578
|
-
if (Object.keys(animate).length) stop.animate = animate;
|
|
579
|
-
return stop;
|
|
580
|
-
}
|
|
581
|
-
function prevDefinedStop(kfs, fromIdx, stopIdx) {
|
|
582
|
-
for (let i = fromIdx; i >= 0; i--) {
|
|
583
|
-
const arr = keyframeValue(kfs[i]);
|
|
584
|
-
if (arr == null ? void 0 : arr[stopIdx]) return arr[stopIdx];
|
|
585
|
-
}
|
|
586
|
-
for (let i = fromIdx + 1; i < kfs.length; i++) {
|
|
587
|
-
const arr = keyframeValue(kfs[i]);
|
|
588
|
-
if (arr == null ? void 0 : arr[stopIdx]) return arr[stopIdx];
|
|
589
|
-
}
|
|
590
|
-
return void 0;
|
|
591
|
-
}
|
|
592
|
-
function formatOffset(o) {
|
|
593
|
-
const pct = Math.round(o * 1e3) / 10;
|
|
594
|
-
return pct + "%";
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// src/effects/clipping/clipPathEffect.ts
|
|
598
|
-
function applyClipPathEffect(node, fx, ctx) {
|
|
599
|
-
if (!(fx == null ? void 0 : fx.pathData)) return node;
|
|
600
|
-
const clipId = genId(ctx, "clip");
|
|
601
|
-
const pathChild = { type: "path" };
|
|
602
|
-
const read = readAnimatable(fx.pathData);
|
|
603
|
-
if (read.kind !== "absent" /* Absent */) {
|
|
604
|
-
if (read.kind === "static" /* Static */) {
|
|
605
|
-
pathChild.d = pathString(read.value);
|
|
606
|
-
} else {
|
|
607
|
-
writeAnimatableChannel(pathChild, "d", read);
|
|
608
|
-
if (pathChild.d !== void 0) pathChild.d = pathString(pathChild.d);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
ctx.defs.push({ type: "clipPath", id: clipId, children: [pathChild] });
|
|
612
|
-
node.clipPath = "url(#" + clipId + ")";
|
|
613
|
-
return node;
|
|
614
|
-
}
|
|
615
|
-
function pathString(v) {
|
|
616
|
-
if (typeof v === "string") return v;
|
|
617
|
-
if (v && typeof v === "object" && typeof v.pathData === "string") return v.pathData;
|
|
618
|
-
return void 0;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// src/effects/clipping/maskedByEffect.ts
|
|
622
|
-
function applyMaskedByEffect(node, fx, transformBy, ctx) {
|
|
623
|
-
if (!fx) return node;
|
|
624
|
-
const sourceId = stripHash(fx.source);
|
|
625
|
-
if (!sourceId) {
|
|
626
|
-
ctx.errors.push("maskedBy.source missing \u2014 cannot build mask");
|
|
627
|
-
return node;
|
|
628
|
-
}
|
|
629
|
-
const maskId = genId(ctx, "mask");
|
|
630
|
-
let content = { type: "use", href: "#" + sourceId };
|
|
631
|
-
if (transformBy) {
|
|
632
|
-
content = wrapInverseTransform(content, transformBy, ctx);
|
|
633
|
-
} else if (hasAnimateTransform(node)) {
|
|
634
|
-
content = wrapInverseAnimatedBodyTransform(content, node, ctx);
|
|
635
|
-
} else {
|
|
636
|
-
const bodyStatic = readTransformationFromBody(node);
|
|
637
|
-
if (bodyStatic) content = wrapInverseTransform(content, bodyStatic, ctx);
|
|
638
|
-
}
|
|
639
|
-
const includeTargetOwn = transformBy === void 0 && !nodeHasBodyTransform(node);
|
|
640
|
-
content = wrapAncestorChainCompensation(content, node, sourceId, ctx, includeTargetOwn);
|
|
641
|
-
const mask = { type: "mask", id: maskId, children: [content] };
|
|
642
|
-
if (fx.maskType) mask.maskType = fx.maskType;
|
|
643
|
-
if (fx.maskUnits) mask.maskUnits = fx.maskUnits;
|
|
644
|
-
if (fx.maskContentUnits) mask.maskContentUnits = fx.maskContentUnits;
|
|
645
|
-
if (fx.x !== void 0) mask.x = String(fx.x);
|
|
646
|
-
if (fx.y !== void 0) mask.y = String(fx.y);
|
|
647
|
-
if (fx.width !== void 0) mask.width = String(fx.width);
|
|
648
|
-
if (fx.height !== void 0) mask.height = String(fx.height);
|
|
649
|
-
ctx.defs.push(mask);
|
|
650
|
-
node.mask = "url(#" + maskId + ")";
|
|
651
|
-
return node;
|
|
652
|
-
}
|
|
653
|
-
function wrapInverseTransform(inner, fx, ctx) {
|
|
654
|
-
if (!fx) return inner;
|
|
655
|
-
const origin = readStaticOrigin(fx.origin, ctx);
|
|
656
|
-
let n = inner;
|
|
657
|
-
n = wrapInversePart(n, "translate" /* Translate */, fx.translate, void 0, ctx);
|
|
658
|
-
n = wrapInversePart(n, "rotate" /* Rotate */, fx.rotate, origin, ctx);
|
|
659
|
-
n = wrapInversePart(n, "scale" /* Scale */, fx.scale, origin, ctx);
|
|
660
|
-
return n;
|
|
661
|
-
}
|
|
662
|
-
function wrapInversePart(inner, part, raw, origin, ctx) {
|
|
663
|
-
if (raw === void 0) return inner;
|
|
664
|
-
const normalizedRaw = part === "scale" /* Scale */ && Array.isArray(raw) ? [raw[0] / 100, raw[1] / 100] : raw;
|
|
665
|
-
const v = readAnimatable(normalizedRaw);
|
|
666
|
-
if (v.kind === "static" /* Static */) {
|
|
667
|
-
return { type: "g", transform: { value: partsRecord(part, invertPartValue(part, v.value), origin) }, children: [inner] };
|
|
668
|
-
}
|
|
669
|
-
if (v.kind === "animated" /* Animated */) {
|
|
670
|
-
const animTr = { keyframes: v.keyframes.map((kf) => {
|
|
671
|
-
const out = keyframeWith(kf, partsRecord(part, invertPartValue(part, kf.value), origin));
|
|
672
|
-
return part === "translate" /* Translate */ ? __spreadValues(__spreadValues({}, out), negatedSpatialTangents(kf)) : out;
|
|
673
|
-
}) };
|
|
674
|
-
if (v.loop !== void 0) animTr.loop = v.loop;
|
|
675
|
-
return {
|
|
676
|
-
type: "g",
|
|
677
|
-
animate: { transform: animTr },
|
|
678
|
-
children: [inner]
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
return inner;
|
|
682
|
-
}
|
|
683
|
-
function invertPartValue(part, value) {
|
|
684
|
-
if (part === "translate" /* Translate */) return [-value[0], -value[1]];
|
|
685
|
-
if (part === "rotate" /* Rotate */) return -value;
|
|
686
|
-
return [1 / value[0], 1 / value[1]];
|
|
687
|
-
}
|
|
688
|
-
function negatedSpatialTangents(kf) {
|
|
689
|
-
var _a, _b;
|
|
690
|
-
const out = {};
|
|
691
|
-
const to = (_a = kf.tangentOut) != null ? _a : kf.to;
|
|
692
|
-
const ti = (_b = kf.tangentIn) != null ? _b : kf.ti;
|
|
693
|
-
if (Array.isArray(to)) out.tangentOut = [-to[0], -to[1]];
|
|
694
|
-
if (Array.isArray(ti)) out.tangentIn = [-ti[0], -ti[1]];
|
|
695
|
-
return out;
|
|
696
|
-
}
|
|
697
|
-
function wrapInverseAnimatedBodyTransform(inner, node, _ctx) {
|
|
698
|
-
var _a;
|
|
699
|
-
const animate = node.animate && typeof node.animate === "object" && !Array.isArray(node.animate) ? node.animate : void 0;
|
|
700
|
-
const animTr = animate == null ? void 0 : animate.transform;
|
|
701
|
-
const kfs = animTr && typeof animTr === "object" && Array.isArray(animTr.keyframes) ? animTr.keyframes : void 0;
|
|
702
|
-
if (!kfs || !kfs.length) return inner;
|
|
703
|
-
const translateKfs = [];
|
|
704
|
-
const rotateKfs = [];
|
|
705
|
-
const scaleKfs = [];
|
|
706
|
-
for (const kf of kfs) {
|
|
707
|
-
const v = ((_a = kf.value) != null ? _a : kf.v) || {};
|
|
708
|
-
const baseKf = keyframeWith(kf, void 0);
|
|
709
|
-
if (Array.isArray(v.translate)) {
|
|
710
|
-
translateKfs.push(__spreadProps(__spreadValues(__spreadValues({}, baseKf), negatedSpatialTangents(kf)), { value: { translate: [-v.translate[0], -v.translate[1]] } }));
|
|
711
|
-
}
|
|
712
|
-
if (typeof v.rotate === "number") {
|
|
713
|
-
const rec = { rotate: -v.rotate };
|
|
714
|
-
if (Array.isArray(v.origin)) rec.origin = [v.origin[0], v.origin[1]];
|
|
715
|
-
rotateKfs.push(__spreadProps(__spreadValues({}, baseKf), { value: rec }));
|
|
716
|
-
}
|
|
717
|
-
if (Array.isArray(v.scale)) {
|
|
718
|
-
const rec = { scale: [1 / v.scale[0], 1 / v.scale[1]] };
|
|
719
|
-
if (Array.isArray(v.origin)) rec.origin = [v.origin[0], v.origin[1]];
|
|
720
|
-
scaleKfs.push(__spreadProps(__spreadValues({}, baseKf), { value: rec }));
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
const srcLoop = animTr == null ? void 0 : animTr.loop;
|
|
724
|
-
const withLoop = (kfs2) => {
|
|
725
|
-
const block = { keyframes: kfs2 };
|
|
726
|
-
if (srcLoop !== void 0) block.loop = srcLoop;
|
|
727
|
-
return block;
|
|
728
|
-
};
|
|
729
|
-
let n = inner;
|
|
730
|
-
if (translateKfs.length) n = { type: "g", animate: { transform: withLoop(translateKfs) }, children: [n] };
|
|
731
|
-
if (rotateKfs.length) n = { type: "g", animate: { transform: withLoop(rotateKfs) }, children: [n] };
|
|
732
|
-
if (scaleKfs.length) n = { type: "g", animate: { transform: withLoop(scaleKfs) }, children: [n] };
|
|
733
|
-
return n;
|
|
734
|
-
}
|
|
735
|
-
function nodeHasBodyTransform(node) {
|
|
736
|
-
if (typeof node.transform === "string") return true;
|
|
737
|
-
if (node.transform && typeof node.transform === "object") return true;
|
|
738
|
-
return hasAnimateTransform(node);
|
|
739
|
-
}
|
|
740
|
-
function hasAnimateTransform(node) {
|
|
741
|
-
const animate = node.animate && typeof node.animate === "object" && !Array.isArray(node.animate) ? node.animate : void 0;
|
|
742
|
-
return !!(animate && animate.transform);
|
|
743
|
-
}
|
|
744
|
-
function readTransformationFromBody(node) {
|
|
745
|
-
if (typeof node.transform === "string") {
|
|
746
|
-
const parts = parseTransformStringToParts(node.transform);
|
|
747
|
-
if (!parts) return void 0;
|
|
748
|
-
const out = {};
|
|
749
|
-
if (parts.translate) out.translate = parts.translate;
|
|
750
|
-
if (parts.rotate !== void 0) out.rotate = parts.rotate;
|
|
751
|
-
if (parts.scale) out.scale = { value: parts.scale };
|
|
752
|
-
if (parts.origin) out.origin = parts.origin;
|
|
753
|
-
return Object.keys(out).length ? out : void 0;
|
|
754
|
-
}
|
|
755
|
-
if (node.transform && typeof node.transform === "object" && !node.transform.keyframes) {
|
|
756
|
-
const wrapped = node.transform.value;
|
|
757
|
-
const value = wrapped && typeof wrapped === "object" ? wrapped : node.transform;
|
|
758
|
-
if (value && typeof value === "object") {
|
|
759
|
-
const out = {};
|
|
760
|
-
if (Array.isArray(value.translate)) out.translate = value.translate;
|
|
761
|
-
if (typeof value.rotate === "number") out.rotate = value.rotate;
|
|
762
|
-
if (typeof value.skew === "number") out.skew = value.skew;
|
|
763
|
-
if (Array.isArray(value.scale)) out.scale = { value: value.scale };
|
|
764
|
-
if (Array.isArray(value.origin)) out.origin = value.origin;
|
|
765
|
-
return Object.keys(out).length ? out : void 0;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
return void 0;
|
|
769
|
-
}
|
|
770
|
-
function parseTransformStringToParts(s) {
|
|
771
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
772
|
-
const re = /([a-zA-Z]+)\s*\(([^)]*)\)/g;
|
|
773
|
-
let m;
|
|
774
|
-
const ops = [];
|
|
775
|
-
while ((m = re.exec(s)) !== null) {
|
|
776
|
-
const args = m[2].split(/[\s,]+/).filter((a) => a.length > 0).map(Number);
|
|
777
|
-
ops.push({ name: m[1], args });
|
|
778
|
-
}
|
|
779
|
-
if (!ops.length) return void 0;
|
|
780
|
-
const last = ops[ops.length - 1];
|
|
781
|
-
if (last.name === "translate") {
|
|
782
|
-
for (let j = ops.length - 2; j >= 0; j--) {
|
|
783
|
-
const cand = ops[j];
|
|
784
|
-
if (cand.name !== "translate") continue;
|
|
785
|
-
const ox = (_a = cand.args[0]) != null ? _a : 0;
|
|
786
|
-
const oy = (_b = cand.args[1]) != null ? _b : 0;
|
|
787
|
-
const lx = (_c = last.args[0]) != null ? _c : 0;
|
|
788
|
-
const ly = (_d = last.args[1]) != null ? _d : 0;
|
|
789
|
-
if (lx !== -ox || ly !== -oy) continue;
|
|
790
|
-
const out2 = {};
|
|
791
|
-
out2.origin = [ox, oy];
|
|
792
|
-
for (let k = 0; k < j; k++) {
|
|
793
|
-
if (ops[k].name === "translate") {
|
|
794
|
-
const tx = (_e = ops[k].args[0]) != null ? _e : 0;
|
|
795
|
-
const ty = (_f = ops[k].args[1]) != null ? _f : 0;
|
|
796
|
-
out2.translate = out2.translate ? [out2.translate[0] + tx, out2.translate[1] + ty] : [tx, ty];
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
for (let k = j + 1; k < ops.length - 1; k++) {
|
|
800
|
-
const op = ops[k];
|
|
801
|
-
if (op.name === "rotate") out2.rotate = ((_g = out2.rotate) != null ? _g : 0) + ((_h = op.args[0]) != null ? _h : 0);
|
|
802
|
-
else if (op.name === "scale") {
|
|
803
|
-
const sx = (_i = op.args[0]) != null ? _i : 1;
|
|
804
|
-
const sy = op.args.length > 1 ? op.args[1] : sx;
|
|
805
|
-
out2.scale = out2.scale ? [out2.scale[0] * sx, out2.scale[1] * sy] : [sx, sy];
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
return out2;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
let translate;
|
|
812
|
-
let rotate;
|
|
813
|
-
let scale;
|
|
814
|
-
for (const op of ops) {
|
|
815
|
-
if (op.name === "translate") {
|
|
816
|
-
const dx = (_j = op.args[0]) != null ? _j : 0;
|
|
817
|
-
const dy = (_k = op.args[1]) != null ? _k : 0;
|
|
818
|
-
translate = translate ? [translate[0] + dx, translate[1] + dy] : [dx, dy];
|
|
819
|
-
} else if (op.name === "rotate") {
|
|
820
|
-
rotate = (rotate != null ? rotate : 0) + ((_l = op.args[0]) != null ? _l : 0);
|
|
821
|
-
} else if (op.name === "scale") {
|
|
822
|
-
const sx = (_m = op.args[0]) != null ? _m : 1;
|
|
823
|
-
const sy = op.args.length > 1 ? op.args[1] : sx;
|
|
824
|
-
scale = scale ? [scale[0] * sx, scale[1] * sy] : [sx, sy];
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
const out = {};
|
|
828
|
-
if (translate) out.translate = translate;
|
|
829
|
-
if (rotate !== void 0) out.rotate = rotate;
|
|
830
|
-
if (scale) out.scale = scale;
|
|
831
|
-
return Object.keys(out).length ? out : void 0;
|
|
832
|
-
}
|
|
833
|
-
function wrapAncestorChainCompensation(inner, maskedNode, sourceId, ctx, includeTargetOwn) {
|
|
834
|
-
const sourceNode = ctx.idMap.get(sourceId);
|
|
835
|
-
const targetAncestors = ctx.maskAncestorChains.get(maskedNode) || [];
|
|
836
|
-
const targetOwn = includeTargetOwn ? extractTranslateOnly(maskedNode, ctx) : void 0;
|
|
837
|
-
const targetChain = targetOwn ? [...targetAncestors, targetOwn] : targetAncestors;
|
|
838
|
-
const sourceChain = sourceNode && ctx.maskAncestorChains.get(sourceNode) || [];
|
|
839
|
-
if (!targetChain.length && !sourceChain.length) return inner;
|
|
840
|
-
const times = /* @__PURE__ */ new Set();
|
|
841
|
-
for (const a of targetChain) if (a.translateKeyframes) for (const kf of a.translateKeyframes) times.add(kf.time);
|
|
842
|
-
for (const a of sourceChain) if (a.translateKeyframes) for (const kf of a.translateKeyframes) times.add(kf.time);
|
|
843
|
-
const animated = times.size > 0;
|
|
844
|
-
if (!animated) {
|
|
845
|
-
const tgt = sumStaticTranslate(targetChain);
|
|
846
|
-
const src = sumStaticTranslate(sourceChain);
|
|
847
|
-
const dx = src[0] - tgt[0];
|
|
848
|
-
const dy = src[1] - tgt[1];
|
|
849
|
-
if (dx === 0 && dy === 0) return inner;
|
|
850
|
-
return { type: "g", transform: "translate(" + dx + "," + dy + ")", children: [inner] };
|
|
851
|
-
}
|
|
852
|
-
const sortedTimes = Array.from(times).sort((a, b) => a - b);
|
|
853
|
-
const keyframes = sortedTimes.map((t) => {
|
|
854
|
-
const tgt = sumTranslateAt(targetChain, t);
|
|
855
|
-
const src = sumTranslateAt(sourceChain, t);
|
|
856
|
-
return { time: t, value: { translate: [src[0] - tgt[0], src[1] - tgt[1]] } };
|
|
857
|
-
});
|
|
858
|
-
return { type: "g", animate: { transform: { keyframes } }, children: [inner] };
|
|
859
|
-
}
|
|
860
|
-
function sumStaticTranslate(chain) {
|
|
861
|
-
let x = 0, y = 0;
|
|
862
|
-
for (const a of chain) {
|
|
863
|
-
if (a.translate) {
|
|
864
|
-
x += a.translate[0];
|
|
865
|
-
y += a.translate[1];
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
return [x, y];
|
|
869
|
-
}
|
|
870
|
-
function sumTranslateAt(chain, t) {
|
|
871
|
-
let x = 0, y = 0;
|
|
872
|
-
for (const a of chain) {
|
|
873
|
-
if (a.translateKeyframes && a.translateKeyframes.length) {
|
|
874
|
-
const v = interpKfs(a.translateKeyframes, t);
|
|
875
|
-
x += v[0];
|
|
876
|
-
y += v[1];
|
|
877
|
-
} else if (a.translate) {
|
|
878
|
-
x += a.translate[0];
|
|
879
|
-
y += a.translate[1];
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
return [x, y];
|
|
883
|
-
}
|
|
884
|
-
function interpKfs(kfs, t) {
|
|
885
|
-
if (t <= kfs[0].time) return kfs[0].value;
|
|
886
|
-
if (t >= kfs[kfs.length - 1].time) return kfs[kfs.length - 1].value;
|
|
887
|
-
for (let i = 1; i < kfs.length; i++) {
|
|
888
|
-
if (t <= kfs[i].time) {
|
|
889
|
-
const prev = kfs[i - 1];
|
|
890
|
-
const cur = kfs[i];
|
|
891
|
-
const a = (t - prev.time) / (cur.time - prev.time);
|
|
892
|
-
return [prev.value[0] + (cur.value[0] - prev.value[0]) * a, prev.value[1] + (cur.value[1] - prev.value[1]) * a];
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
return kfs[kfs.length - 1].value;
|
|
896
|
-
}
|
|
897
|
-
function collectMaskAncestorChains(root, ctx) {
|
|
898
|
-
const interestingNodes = /* @__PURE__ */ new Set();
|
|
899
|
-
const collectInterestingNodes = (n) => {
|
|
900
|
-
var _a, _b;
|
|
901
|
-
const maskSourceId = stripHash((_b = (_a = n.effects) == null ? void 0 : _a.maskedBy) == null ? void 0 : _b.source);
|
|
902
|
-
if (typeof maskSourceId === "string") {
|
|
903
|
-
interestingNodes.add(n);
|
|
904
|
-
const sourceNode = ctx.idMap.get(maskSourceId);
|
|
905
|
-
if (sourceNode) interestingNodes.add(sourceNode);
|
|
906
|
-
}
|
|
907
|
-
if (Array.isArray(n.children)) for (const ch of n.children) collectInterestingNodes(ch);
|
|
908
|
-
};
|
|
909
|
-
collectInterestingNodes(root);
|
|
910
|
-
if (interestingNodes.size === 0) return;
|
|
911
|
-
const walk = (node, chain) => {
|
|
912
|
-
if (interestingNodes.has(node)) ctx.maskAncestorChains.set(node, chain);
|
|
913
|
-
if (Array.isArray(node.children)) {
|
|
914
|
-
const own = extractTranslateOnly(node, ctx);
|
|
915
|
-
const next = own ? [...chain, own] : chain;
|
|
916
|
-
for (const ch of node.children) walk(ch, next);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
walk(root, []);
|
|
920
|
-
}
|
|
921
|
-
function extractTranslateOnly(node, ctx) {
|
|
922
|
-
var _a, _b, _c;
|
|
923
|
-
const tr = node.transform;
|
|
924
|
-
const animateBlock = node.animate && typeof node.animate === "object" && !Array.isArray(node.animate) ? node.animate.transform : void 0;
|
|
925
|
-
if (tr === void 0 && !animateBlock) return void 0;
|
|
926
|
-
const out = {};
|
|
927
|
-
if (typeof tr === "string") {
|
|
928
|
-
const parts = parseTranslateOnlyFromString(tr, ctx);
|
|
929
|
-
if (parts) out.translate = parts;
|
|
930
|
-
} else if (tr && typeof tr === "object" && !tr.keyframes) {
|
|
931
|
-
const wrapped = tr.value;
|
|
932
|
-
const value = wrapped && typeof wrapped === "object" ? wrapped : tr;
|
|
933
|
-
if (value && typeof value === "object" && Array.isArray(value.translate)) {
|
|
934
|
-
out.translate = [value.translate[0] || 0, value.translate[1] || 0];
|
|
935
|
-
}
|
|
936
|
-
if (value && (value.rotate !== void 0 || value.scale !== void 0 || value.skew !== void 0)) {
|
|
937
|
-
ctx.warnings.push("maskedBy ancestor: non-translate transform parts ignored (rotate/scale not yet supported)");
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (animateBlock && Array.isArray(animateBlock.keyframes)) {
|
|
941
|
-
const kfs = animateBlock.keyframes;
|
|
942
|
-
const translateKfs = [];
|
|
943
|
-
for (const kf of kfs) {
|
|
944
|
-
const v = (_a = kf.value) != null ? _a : kf.v;
|
|
945
|
-
const t = (_c = (_b = kf.time) != null ? _b : kf.t) != null ? _c : 0;
|
|
946
|
-
if (v && typeof v === "object" && Array.isArray(v.translate)) {
|
|
947
|
-
translateKfs.push({ time: t, value: [v.translate[0] || 0, v.translate[1] || 0] });
|
|
948
|
-
if (v.rotate !== void 0 || v.scale !== void 0 || v.skew !== void 0) {
|
|
949
|
-
ctx.warnings.push("maskedBy ancestor: animated non-translate parts ignored");
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
if (translateKfs.length) out.translateKeyframes = translateKfs;
|
|
954
|
-
}
|
|
955
|
-
return out.translate || out.translateKeyframes ? out : void 0;
|
|
956
|
-
}
|
|
957
|
-
function parseTranslateOnlyFromString(s, ctx) {
|
|
958
|
-
const re = /([a-zA-Z]+)\s*\(([^)]*)\)/g;
|
|
959
|
-
let m;
|
|
960
|
-
let x = 0, y = 0;
|
|
961
|
-
let seen = false;
|
|
962
|
-
let droppedNonTranslate = false;
|
|
963
|
-
while ((m = re.exec(s)) !== null) {
|
|
964
|
-
const name = m[1];
|
|
965
|
-
const args = m[2].split(/[\s,]+/).filter((a) => a.length > 0).map(Number);
|
|
966
|
-
if (name === "translate") {
|
|
967
|
-
x += args[0] || 0;
|
|
968
|
-
y += args[1] || 0;
|
|
969
|
-
seen = true;
|
|
970
|
-
} else {
|
|
971
|
-
droppedNonTranslate = true;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
if (droppedNonTranslate) ctx.warnings.push("maskedBy ancestor: non-translate transform in string ignored: " + s);
|
|
975
|
-
return seen ? [x, y] : void 0;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// src/effects/reference/refEffect.ts
|
|
979
|
-
function applyRefHref(node, clone2, ctx) {
|
|
980
|
-
if (!clone2) return;
|
|
981
|
-
const sourceId = stripHash(clone2.source);
|
|
982
|
-
if (!sourceId) {
|
|
983
|
-
if (clone2.without === PxCloneWithout.translate) ctx.errors.push("clone: content ref missing `source`");
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
const targetId = clone2.without === PxCloneWithout.translate ? ctx.contentRefInnerIds.get(sourceId) || sourceId : sourceId;
|
|
987
|
-
node.href = "#" + targetId;
|
|
988
|
-
}
|
|
989
|
-
function applyRefAndTransformationEffect(node, clone2, transformBy, ctx) {
|
|
990
|
-
applyRefHref(node, clone2, ctx);
|
|
991
|
-
return applyTransformByEffect(node, transformBy, ctx);
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// src/effects/transform/repeaterEffect.ts
|
|
995
|
-
function applyRepeaterEffect(node, fx, ctx) {
|
|
996
|
-
var _a, _b;
|
|
997
|
-
if (!fx) return node;
|
|
998
|
-
const copies = (_a = fx.copies) != null ? _a : 1;
|
|
999
|
-
if (copies < 1) {
|
|
1000
|
-
ctx.errors.push("repeater.copies invalid: " + fx.copies);
|
|
1001
|
-
return node;
|
|
1002
|
-
}
|
|
1003
|
-
const sharedTransform = node.transform;
|
|
1004
|
-
const sharedAnimTransform = (_b = node.animate) == null ? void 0 : _b.transform;
|
|
1005
|
-
const base = clone(node);
|
|
1006
|
-
delete base.transform;
|
|
1007
|
-
if (base.animate) {
|
|
1008
|
-
delete base.animate.transform;
|
|
1009
|
-
if (Object.keys(base.animate).length === 0) delete base.animate;
|
|
1010
|
-
}
|
|
1011
|
-
delete base.id;
|
|
1012
|
-
const children = [base];
|
|
1013
|
-
for (let i = 1; i < copies; i++) {
|
|
1014
|
-
const baseClone = clone(base);
|
|
1015
|
-
const synthFx = synthesisePerCopyFx(fx, i);
|
|
1016
|
-
const wrapped = synthFx ? applyTransformByEffect(baseClone, synthFx, ctx) : baseClone;
|
|
1017
|
-
children.push(wrapped);
|
|
1018
|
-
}
|
|
1019
|
-
const wrapper = { type: "g", children };
|
|
1020
|
-
if (node.id) wrapper.id = node.id;
|
|
1021
|
-
if (sharedTransform !== void 0) wrapper.transform = sharedTransform;
|
|
1022
|
-
if (sharedAnimTransform !== void 0) wrapper.animate = { transform: sharedAnimTransform };
|
|
1023
|
-
return wrapper;
|
|
1024
|
-
}
|
|
1025
|
-
function synthesisePerCopyFx(fx, i) {
|
|
1026
|
-
const out = {};
|
|
1027
|
-
if (fx.translate !== void 0) {
|
|
1028
|
-
out.translate = mapAnimatable(fx.translate, (v) => [v[0] * i, v[1] * i]);
|
|
1029
|
-
}
|
|
1030
|
-
if (fx.rotate !== void 0) {
|
|
1031
|
-
out.rotate = mapAnimatable(fx.rotate, (v) => v * i);
|
|
1032
|
-
}
|
|
1033
|
-
if (fx.skew !== void 0) {
|
|
1034
|
-
out.skew = mapAnimatable(fx.skew, (v) => v * i);
|
|
1035
|
-
}
|
|
1036
|
-
if (fx.scale !== void 0) {
|
|
1037
|
-
out.scale = synthesiseScale(fx.scale, i);
|
|
1038
|
-
}
|
|
1039
|
-
if (fx.origin !== void 0) {
|
|
1040
|
-
out.origin = fx.origin;
|
|
1041
|
-
}
|
|
1042
|
-
return Object.keys(out).length ? out : void 0;
|
|
1043
|
-
}
|
|
1044
|
-
function mapAnimatable(raw, fn, wrapStatic = false) {
|
|
1045
|
-
const read = readAnimatable(raw);
|
|
1046
|
-
if (read.kind === "absent" /* Absent */) return raw;
|
|
1047
|
-
if (read.kind === "static" /* Static */) {
|
|
1048
|
-
const mapped = fn(read.value);
|
|
1049
|
-
const wasRawStatic = typeof raw === "number" || Array.isArray(raw);
|
|
1050
|
-
return wasRawStatic && !wrapStatic ? mapped : { value: mapped };
|
|
1051
|
-
}
|
|
1052
|
-
const out = {
|
|
1053
|
-
keyframes: read.keyframes.map((kf) => kf && kf.value !== void 0 ? __spreadProps(__spreadValues({}, kf), { value: fn(kf.value) }) : kf)
|
|
1054
|
-
};
|
|
1055
|
-
if (read.loop !== void 0) out.loop = read.loop;
|
|
1056
|
-
if (read.autoOrient !== void 0) out.autoOrient = read.autoOrient;
|
|
1057
|
-
if (read.base !== void 0) out.value = fn(read.base);
|
|
1058
|
-
return out;
|
|
1059
|
-
}
|
|
1060
|
-
function synthesiseScale(raw, i) {
|
|
1061
|
-
const scalePower = (v) => [Math.pow(v[0], i), Math.pow(v[1], i)];
|
|
1062
|
-
return mapAnimatable(raw, scalePower, true);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
// src/effects/reference/retimeEffect.ts
|
|
1066
|
-
var RETIME_MATERIALIZATION_MODE_INLINE_G = false;
|
|
1067
|
-
function asRetime(r) {
|
|
1068
|
-
var _a, _b;
|
|
1069
|
-
return { start: (_a = r.start) != null ? _a : 0, stretch: (_b = r.stretch) != null ? _b : 1 };
|
|
1070
|
-
}
|
|
1071
|
-
var CROP_EDGE_MS = 1;
|
|
1072
|
-
function applyTimeCrop(useNode, crop, ctx) {
|
|
1073
|
-
const [start, end] = crop;
|
|
1074
|
-
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
|
1075
|
-
ctx.warnings.push("retime: timeCrop is not a pair of finite numbers \u2014 ignored");
|
|
1076
|
-
return;
|
|
1077
|
-
}
|
|
1078
|
-
const keyframes = end <= start ? [{ time: 0, value: 0 }] : [
|
|
1079
|
-
...start > 0 ? [{ time: Math.max(0, start - CROP_EDGE_MS), value: 0 }] : [],
|
|
1080
|
-
{ time: Math.max(0, start), value: 1 },
|
|
1081
|
-
{ time: end, value: 1 },
|
|
1082
|
-
{ time: end + CROP_EDGE_MS, value: 0 }
|
|
1083
|
-
];
|
|
1084
|
-
const inner = __spreadValues({}, useNode);
|
|
1085
|
-
for (const k of Object.keys(useNode)) delete useNode[k];
|
|
1086
|
-
useNode.type = "g";
|
|
1087
|
-
useNode.children = [inner];
|
|
1088
|
-
useNode.animate = { opacity: { keyframes } };
|
|
1089
|
-
}
|
|
1090
|
-
function concatRetime(child, parent) {
|
|
1091
|
-
return {
|
|
1092
|
-
start: parent.start + parent.stretch * child.start,
|
|
1093
|
-
stretch: parent.stretch * child.stretch
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
function readCloneRetime(n) {
|
|
1097
|
-
var _a, _b;
|
|
1098
|
-
return (_b = (_a = n.effects) == null ? void 0 : _a.clone) == null ? void 0 : _b.retime;
|
|
1099
|
-
}
|
|
1100
|
-
function clearCloneRetime(n) {
|
|
1101
|
-
var _a;
|
|
1102
|
-
const clone2 = (_a = n.effects) == null ? void 0 : _a.clone;
|
|
1103
|
-
if (!clone2) return;
|
|
1104
|
-
delete clone2.retime;
|
|
1105
|
-
if (Object.keys(clone2).length === 0) delete n.effects.clone;
|
|
1106
|
-
if (n.effects && Object.keys(n.effects).length === 0) delete n.effects;
|
|
1107
|
-
}
|
|
1108
|
-
function applyAllRetimeEffects(root, ctx) {
|
|
1109
|
-
ctx.idMap.clear();
|
|
1110
|
-
indexById(root, ctx.idMap);
|
|
1111
|
-
const sites = [];
|
|
1112
|
-
const collect = (n) => {
|
|
1113
|
-
var _a;
|
|
1114
|
-
if (readCloneRetime(n)) sites.push(n);
|
|
1115
|
-
(_a = n.children) == null ? void 0 : _a.forEach(collect);
|
|
1116
|
-
};
|
|
1117
|
-
collect(root);
|
|
1118
|
-
const reachCount = /* @__PURE__ */ new Map();
|
|
1119
|
-
for (const site of sites) {
|
|
1120
|
-
let count = 0;
|
|
1121
|
-
const visited = /* @__PURE__ */ new Set();
|
|
1122
|
-
const walk = (n) => {
|
|
1123
|
-
var _a;
|
|
1124
|
-
if (!n) return;
|
|
1125
|
-
if (n !== site && readCloneRetime(n)) count++;
|
|
1126
|
-
if (n.type === "use" && n.href) {
|
|
1127
|
-
const id = stripHash(n.href);
|
|
1128
|
-
if (id && !visited.has(id)) {
|
|
1129
|
-
visited.add(id);
|
|
1130
|
-
walk(ctx.idMap.get(id));
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
(_a = n.children) == null ? void 0 : _a.forEach(walk);
|
|
1134
|
-
};
|
|
1135
|
-
const rootId = stripHash(site.href);
|
|
1136
|
-
if (rootId) {
|
|
1137
|
-
visited.add(rootId);
|
|
1138
|
-
walk(ctx.idMap.get(rootId));
|
|
1139
|
-
}
|
|
1140
|
-
reachCount.set(site, count);
|
|
1141
|
-
}
|
|
1142
|
-
sites.sort((a, b) => {
|
|
1143
|
-
var _a, _b;
|
|
1144
|
-
return ((_a = reachCount.get(b)) != null ? _a : 0) - ((_b = reachCount.get(a)) != null ? _b : 0);
|
|
1145
|
-
});
|
|
1146
|
-
for (const useNode of sites) {
|
|
1147
|
-
const retime = readCloneRetime(useNode);
|
|
1148
|
-
if (!retime) continue;
|
|
1149
|
-
const crop = retime.timeCrop;
|
|
1150
|
-
clearCloneRetime(useNode);
|
|
1151
|
-
materializeRetime(useNode, asRetime(retime), ctx);
|
|
1152
|
-
if (crop) applyTimeCrop(useNode, crop, ctx);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
function materializeRetime(useNode, retime, ctx) {
|
|
1156
|
-
const targetId = stripHash(useNode.href);
|
|
1157
|
-
if (!targetId) {
|
|
1158
|
-
ctx.errors.push("retime: <use> has no href to follow");
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
const chainRootId = buildChainClone(targetId, retime, ctx, /* @__PURE__ */ new Set());
|
|
1162
|
-
if (!chainRootId) return;
|
|
1163
|
-
if (RETIME_MATERIALIZATION_MODE_INLINE_G) {
|
|
1164
|
-
const cloneNode = ctx.idMap.get(chainRootId);
|
|
1165
|
-
useNode.type = "g";
|
|
1166
|
-
delete useNode.href;
|
|
1167
|
-
useNode.children = [cloneNode];
|
|
1168
|
-
applyUseOffsetToG(useNode);
|
|
1169
|
-
ctx.defs = ctx.defs.filter((d) => d !== cloneNode);
|
|
1170
|
-
} else {
|
|
1171
|
-
useNode.href = "#" + chainRootId;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
function buildChainClone(targetId, accum, ctx, chain) {
|
|
1175
|
-
if (chain.has(targetId)) {
|
|
1176
|
-
ctx.errors.push('retime: loop via "' + targetId + '"');
|
|
1177
|
-
return void 0;
|
|
1178
|
-
}
|
|
1179
|
-
const target = ctx.idMap.get(targetId);
|
|
1180
|
-
if (!target) {
|
|
1181
|
-
ctx.warnings.push('retime: target "' + targetId + '" not found');
|
|
1182
|
-
return void 0;
|
|
1183
|
-
}
|
|
1184
|
-
const cloneNode = clone(target);
|
|
1185
|
-
regenerateIdsInClone(cloneNode, ctx);
|
|
1186
|
-
if (target.type === "use") {
|
|
1187
|
-
remapKeyframeTimesOnly(cloneNode, accum.start, accum.stretch);
|
|
1188
|
-
} else {
|
|
1189
|
-
remapKeyframeTimes(cloneNode, accum.start, accum.stretch);
|
|
1190
|
-
}
|
|
1191
|
-
clearCloneRetime(cloneNode);
|
|
1192
|
-
if (target.type === "use" && target.href) {
|
|
1193
|
-
const subId = stripHash(target.href);
|
|
1194
|
-
if (subId) {
|
|
1195
|
-
const innerRetime = readCloneRetime(target);
|
|
1196
|
-
const subAccum = innerRetime ? concatRetime(asRetime(innerRetime), accum) : accum;
|
|
1197
|
-
const subChain = new Set(chain);
|
|
1198
|
-
subChain.add(targetId);
|
|
1199
|
-
const subId2 = buildChainClone(subId, subAccum, ctx, subChain);
|
|
1200
|
-
if (subId2) cloneNode.href = "#" + subId2;
|
|
1201
|
-
}
|
|
1202
|
-
} else {
|
|
1203
|
-
materializeNestedRetimeUses(cloneNode, accum, ctx, chain, targetId);
|
|
1204
|
-
}
|
|
1205
|
-
ctx.defs.push(cloneNode);
|
|
1206
|
-
if (typeof cloneNode.id === "string") ctx.idMap.set(cloneNode.id, cloneNode);
|
|
1207
|
-
return typeof cloneNode.id === "string" ? cloneNode.id : void 0;
|
|
1208
|
-
}
|
|
1209
|
-
function materializeNestedRetimeUses(node, accum, ctx, chain, parentTargetId) {
|
|
1210
|
-
const visit = (n) => {
|
|
1211
|
-
var _a;
|
|
1212
|
-
const retime = readCloneRetime(n);
|
|
1213
|
-
if (n.type === "use" && retime && n.href) {
|
|
1214
|
-
const subId = stripHash(n.href);
|
|
1215
|
-
if (subId) {
|
|
1216
|
-
const subAccum = concatRetime(asRetime(retime), accum);
|
|
1217
|
-
const subChain = new Set(chain);
|
|
1218
|
-
subChain.add(parentTargetId);
|
|
1219
|
-
const subId2 = buildChainClone(subId, subAccum, ctx, subChain);
|
|
1220
|
-
if (subId2) n.href = "#" + subId2;
|
|
1221
|
-
}
|
|
1222
|
-
clearCloneRetime(n);
|
|
1223
|
-
}
|
|
1224
|
-
(_a = n.children) == null ? void 0 : _a.forEach(visit);
|
|
1225
|
-
};
|
|
1226
|
-
visit(node);
|
|
1227
|
-
}
|
|
1228
|
-
function remapKeyframeTimes(node, start, stretch) {
|
|
1229
|
-
var _a;
|
|
1230
|
-
remapKeyframeTimesOnly(node, start, stretch);
|
|
1231
|
-
(_a = node.children) == null ? void 0 : _a.forEach((c) => remapKeyframeTimes(c, start, stretch));
|
|
1232
|
-
}
|
|
1233
|
-
function remapKeyframeTimesOnly(node, start, stretch) {
|
|
1234
|
-
const remap = (kfs) => {
|
|
1235
|
-
for (const kf of kfs) if (typeof kf.time === "number") kf.time = start + kf.time * stretch;
|
|
1236
|
-
};
|
|
1237
|
-
if (node.transform && typeof node.transform === "object" && Array.isArray(node.transform.keyframes)) {
|
|
1238
|
-
remap(node.transform.keyframes);
|
|
1239
|
-
}
|
|
1240
|
-
if (node.animate && typeof node.animate === "object") {
|
|
1241
|
-
for (const prop of Object.keys(node.animate)) {
|
|
1242
|
-
const anim = node.animate[prop];
|
|
1243
|
-
if (anim && Array.isArray(anim.keyframes)) remap(anim.keyframes);
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
// src/effects/stroke/strokeTrimEffect.ts
|
|
1249
|
-
function applyStrokeTrimEffect(node, strokeTrim, ctx) {
|
|
1250
|
-
if (!strokeTrim) return node;
|
|
1251
|
-
const combined = strokeTrim.subPaths === PxStrokeTrimSubPaths.combined;
|
|
1252
|
-
const leafEntries = [];
|
|
1253
|
-
const measure = (n) => {
|
|
1254
|
-
if (Array.isArray(n.children) && n.children.length > 0) {
|
|
1255
|
-
for (const ch of n.children) measure(ch);
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
const d = typeof n.d === "string" ? n.d : shapeToPathD(n);
|
|
1259
|
-
if (d === void 0) return;
|
|
1260
|
-
const subpaths = parseSvgPathToBezier(d);
|
|
1261
|
-
if (!subpaths.length) return;
|
|
1262
|
-
const entry = { leaf: n, subpaths: [] };
|
|
1263
|
-
for (const sp of subpaths) {
|
|
1264
|
-
const lengthPx = pxBezierPathLength(sp);
|
|
1265
|
-
entry.subpaths.push({ subpath: sp, lengthPx, startOffsetPx: 0 });
|
|
1266
|
-
}
|
|
1267
|
-
leafEntries.push(entry);
|
|
1268
|
-
};
|
|
1269
|
-
measure(node);
|
|
1270
|
-
if (!leafEntries.length) return node;
|
|
1271
|
-
let acc = 0;
|
|
1272
|
-
const iterOrder = combined ? [...leafEntries].reverse() : leafEntries;
|
|
1273
|
-
for (const entry of iterOrder) {
|
|
1274
|
-
for (const sp of entry.subpaths) {
|
|
1275
|
-
if (!combined) acc = 0;
|
|
1276
|
-
sp.startOffsetPx = acc;
|
|
1277
|
-
acc += sp.lengthPx;
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
const chainLengthPx = acc;
|
|
1281
|
-
if (combined && chainLengthPx < 1e-3) return node;
|
|
1282
|
-
const offsetReadRaw = readAnimatable(strokeTrim.offset);
|
|
1283
|
-
const offsetRead = offsetReadRaw.kind === "absent" /* Absent */ ? { kind: "static" /* Static */, value: 0 } : offsetReadRaw;
|
|
1284
|
-
const rangeReadRaw = readRangeWithCrossings(strokeTrim.range);
|
|
1285
|
-
const rangeRead = rangeReadRaw.kind === "absent" /* Absent */ ? { kind: "static" /* Static */, value: [0, 1] } : rangeReadRaw;
|
|
1286
|
-
const offsetValues = readScalarValues(offsetRead);
|
|
1287
|
-
const minOffset = offsetValues.length ? Math.min(...offsetValues) : 0;
|
|
1288
|
-
const maxOffset = offsetValues.length ? Math.max(...offsetValues) : 0;
|
|
1289
|
-
const minMaxOffset = [minOffset, maxOffset];
|
|
1290
|
-
if (leafEntries.length === 1 && leafEntries[0].leaf === node && leafEntries[0].subpaths.length === 1) {
|
|
1291
|
-
const entry = leafEntries[0];
|
|
1292
|
-
const sp = entry.subpaths[0];
|
|
1293
|
-
const pathLengthPx = combined ? chainLengthPx : sp.lengthPx;
|
|
1294
|
-
if (pathLengthPx < 1e-3) return node;
|
|
1295
|
-
const startOffsetPct = combined ? sp.startOffsetPx / pathLengthPx : 0;
|
|
1296
|
-
return collapseLeafWithTrim(entry.leaf, pathLengthPx, startOffsetPct, minMaxOffset, offsetRead, rangeRead);
|
|
1297
|
-
}
|
|
1298
|
-
const replacements = /* @__PURE__ */ new Map();
|
|
1299
|
-
for (const entry of leafEntries) {
|
|
1300
|
-
const newChildren = [];
|
|
1301
|
-
for (const sp of entry.subpaths) {
|
|
1302
|
-
const pathLengthPx = combined ? chainLengthPx : sp.lengthPx;
|
|
1303
|
-
if (pathLengthPx < 1e-3) continue;
|
|
1304
|
-
const startOffsetPct = combined ? sp.startOffsetPx / pathLengthPx : 0;
|
|
1305
|
-
newChildren.push(...buildSubpathNodes(entry.leaf, sp.subpath, pathLengthPx, startOffsetPct, minMaxOffset, offsetRead, rangeRead, ctx));
|
|
1306
|
-
}
|
|
1307
|
-
replacements.set(entry.leaf, wrapLeafAsGroup(entry.leaf, newChildren));
|
|
1308
|
-
}
|
|
1309
|
-
const swap = (n) => {
|
|
1310
|
-
const r = replacements.get(n);
|
|
1311
|
-
if (r) return r;
|
|
1312
|
-
if (Array.isArray(n.children) && n.children.length > 0) {
|
|
1313
|
-
return __spreadProps(__spreadValues({}, n), { children: n.children.map(swap) });
|
|
1314
|
-
}
|
|
1315
|
-
return n;
|
|
1316
|
-
};
|
|
1317
|
-
return swap(node);
|
|
1318
|
-
}
|
|
1319
|
-
function wrapLeafAsGroup(leaf, children) {
|
|
1320
|
-
const wrapper = __spreadProps(__spreadValues({}, leaf), { type: "g", children });
|
|
1321
|
-
delete wrapper.d;
|
|
1322
|
-
delete wrapper.strokeDasharray;
|
|
1323
|
-
delete wrapper.strokeDashoffset;
|
|
1324
|
-
delete wrapper.effects;
|
|
1325
|
-
return wrapper;
|
|
1326
|
-
}
|
|
1327
|
-
function buildSubpathNodes(leaf, subpath, pathLengthPx, startOffsetPct, minMaxOffset, offsetRead, rangeRead, ctx) {
|
|
1328
|
-
const offsetToDashOffset = makeOffsetToDashOffset(startOffsetPct, pathLengthPx, minMaxOffset);
|
|
1329
|
-
const rangeToDasharray = makeRangeToDasharray(pathLengthPx, minMaxOffset);
|
|
1330
|
-
const dashOffsetAttr = computeAnimAttr(offsetRead, offsetToDashOffset);
|
|
1331
|
-
const dashArrayAttr = computeAnimAttr(rangeRead, rangeToDasharray);
|
|
1332
|
-
const strokeOpacityAttr = computeOpacityFromRange(rangeRead);
|
|
1333
|
-
const dStr = bezierToSvgPath(subpath);
|
|
1334
|
-
const base = makeBareSubpath(dStr);
|
|
1335
|
-
applyAttr(base, "strokeDasharray", dashArrayAttr);
|
|
1336
|
-
applyAttr(base, "strokeDashoffset", dashOffsetAttr);
|
|
1337
|
-
applyAttr(base, "strokeOpacity", strokeOpacityAttr);
|
|
1338
|
-
return [base];
|
|
1339
|
-
}
|
|
1340
|
-
function collapseLeafWithTrim(leaf, pathLengthPx, startOffsetPct, minMaxOffset, offsetRead, rangeRead) {
|
|
1341
|
-
const offsetToDashOffset = makeOffsetToDashOffset(startOffsetPct, pathLengthPx, minMaxOffset);
|
|
1342
|
-
const rangeToDasharray = makeRangeToDasharray(pathLengthPx, minMaxOffset);
|
|
1343
|
-
const node = __spreadValues({}, leaf);
|
|
1344
|
-
delete node.effects;
|
|
1345
|
-
applyAttr(node, "strokeDasharray", computeAnimAttr(rangeRead, rangeToDasharray));
|
|
1346
|
-
applyAttr(node, "strokeDashoffset", computeAnimAttr(offsetRead, offsetToDashOffset));
|
|
1347
|
-
applyAttr(node, "strokeOpacity", computeOpacityFromRange(rangeRead));
|
|
1348
|
-
return node;
|
|
1349
|
-
}
|
|
1350
|
-
function makeBareSubpath(dStr) {
|
|
1351
|
-
return { type: "path", d: dStr };
|
|
1352
|
-
}
|
|
1353
|
-
var SMALL_PADDING_PX = 1;
|
|
1354
|
-
function makeOffsetToDashOffset(startOffsetPct, pathLengthPx, minMaxOffset) {
|
|
1355
|
-
const [minIdx] = getOffsetIndexRange(minMaxOffset);
|
|
1356
|
-
return (offsetVal) => pathLengthPx * (-offsetVal - minIdx + startOffsetPct) + SMALL_PADDING_PX;
|
|
1357
|
-
}
|
|
1358
|
-
function makeRangeToDasharray(pathLengthPx, minMaxOffset) {
|
|
1359
|
-
const [minIdx, maxIdx] = getOffsetIndexRange(minMaxOffset);
|
|
1360
|
-
const repeats = maxIdx - minIdx + 1;
|
|
1361
|
-
return (rangeVal) => {
|
|
1362
|
-
const a = clamp(rangeVal[0], 0, 1);
|
|
1363
|
-
const b = clamp(rangeVal[1], 0, 1);
|
|
1364
|
-
const minR = Math.min(a, b);
|
|
1365
|
-
const maxR = Math.max(a, b);
|
|
1366
|
-
const out = [0];
|
|
1367
|
-
let gap = SMALL_PADDING_PX;
|
|
1368
|
-
for (let i = 0; i < repeats; i++) {
|
|
1369
|
-
out.push(gap + minR * pathLengthPx);
|
|
1370
|
-
out.push((maxR - minR) * pathLengthPx);
|
|
1371
|
-
gap = (1 - maxR) * pathLengthPx;
|
|
1372
|
-
}
|
|
1373
|
-
out.push(gap + SMALL_PADDING_PX);
|
|
1374
|
-
return out;
|
|
1375
|
-
};
|
|
1376
|
-
}
|
|
1377
|
-
function getOffsetIndexRange(minMaxOffset) {
|
|
1378
|
-
return [
|
|
1379
|
-
Math.floor(Math.min(-minMaxOffset[0], -minMaxOffset[1])),
|
|
1380
|
-
Math.ceil(Math.max(-minMaxOffset[0], -minMaxOffset[1]))
|
|
1381
|
-
];
|
|
1382
|
-
}
|
|
1383
|
-
function readScalarValues(r) {
|
|
1384
|
-
if (r.kind === "absent" /* Absent */) return [];
|
|
1385
|
-
if (r.kind === "static" /* Static */) return [r.value];
|
|
1386
|
-
const out = [];
|
|
1387
|
-
for (const kf of r.keyframes) {
|
|
1388
|
-
const v = keyframeValue(kf);
|
|
1389
|
-
if (typeof v === "number") out.push(v);
|
|
1390
|
-
}
|
|
1391
|
-
return out;
|
|
1392
|
-
}
|
|
1393
|
-
function computeAnimAttr(read, map) {
|
|
1394
|
-
if (read.kind === "absent" /* Absent */) return void 0;
|
|
1395
|
-
if (read.kind === "static" /* Static */) return { kind: "static" /* Static */, value: map(read.value) };
|
|
1396
|
-
return {
|
|
1397
|
-
kind: "animated" /* Animated */,
|
|
1398
|
-
keyframes: read.keyframes.map((kf) => ({
|
|
1399
|
-
time: keyframeTime(kf),
|
|
1400
|
-
value: map(keyframeValue(kf)),
|
|
1401
|
-
easing: keyframeEasing(kf)
|
|
1402
|
-
})),
|
|
1403
|
-
loop: read.loop
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
function applyAttr(node, attrName, attr) {
|
|
1407
|
-
if (!attr) return;
|
|
1408
|
-
writeAnimatableChannel(node, attrName, attr);
|
|
1409
|
-
}
|
|
1410
|
-
var OPACITY_STEP_MS = 10;
|
|
1411
|
-
function computeOpacityFromRange(rangeRead) {
|
|
1412
|
-
const hide = (v) => v[0] === v[1];
|
|
1413
|
-
if (rangeRead.kind === "absent" /* Absent */) return void 0;
|
|
1414
|
-
if (rangeRead.kind === "static" /* Static */) return hide(rangeRead.value) ? { kind: "static" /* Static */, value: 0 } : void 0;
|
|
1415
|
-
const kfs = rangeRead.keyframes;
|
|
1416
|
-
let anyHide = false;
|
|
1417
|
-
let allHide = true;
|
|
1418
|
-
for (const kf of kfs) {
|
|
1419
|
-
if (hide(keyframeValue(kf))) anyHide = true;
|
|
1420
|
-
else allHide = false;
|
|
1421
|
-
}
|
|
1422
|
-
if (!anyHide) return void 0;
|
|
1423
|
-
if (allHide) return { kind: "static" /* Static */, value: 0 };
|
|
1424
|
-
const out = [];
|
|
1425
|
-
for (let i = 0; i < kfs.length; i++) {
|
|
1426
|
-
const kf = kfs[i];
|
|
1427
|
-
const prevKf = i > 0 ? kfs[i - 1] : void 0;
|
|
1428
|
-
const nextKf = i < kfs.length - 1 ? kfs[i + 1] : void 0;
|
|
1429
|
-
const t = keyframeTime(kf);
|
|
1430
|
-
const thisHide = hide(keyframeValue(kf));
|
|
1431
|
-
const prevHide = prevKf ? thisHide && hide(keyframeValue(prevKf)) : thisHide;
|
|
1432
|
-
const nextHide = nextKf ? thisHide && hide(keyframeValue(nextKf)) : thisHide;
|
|
1433
|
-
if (prevHide && !nextHide) {
|
|
1434
|
-
out.push({ time: t, value: 0 });
|
|
1435
|
-
out.push({ time: t + OPACITY_STEP_MS, value: 1 });
|
|
1436
|
-
} else if (!prevHide && nextHide) {
|
|
1437
|
-
out.push({ time: t - OPACITY_STEP_MS, value: 1 });
|
|
1438
|
-
out.push({ time: t, value: 0 });
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
if (out.length <= 1) return void 0;
|
|
1442
|
-
return { kind: "animated" /* Animated */, keyframes: out };
|
|
1443
|
-
}
|
|
1444
|
-
function readRangeWithCrossings(raw) {
|
|
1445
|
-
const r = readAnimatable(raw);
|
|
1446
|
-
if (r.kind !== "animated" /* Animated */) return r;
|
|
1447
|
-
const kfs = r.keyframes.map((kf) => ({
|
|
1448
|
-
time: keyframeTime(kf),
|
|
1449
|
-
value: keyframeValue(kf),
|
|
1450
|
-
easing: keyframeEasing(kf)
|
|
1451
|
-
}));
|
|
1452
|
-
const hasReverse = kfs.some((kf) => kf.value[0] > kf.value[1]);
|
|
1453
|
-
if (!hasReverse) {
|
|
1454
|
-
return {
|
|
1455
|
-
kind: "animated" /* Animated */,
|
|
1456
|
-
keyframes: kfs.map((kf) => ({ time: kf.time, value: kf.value, easing: kf.easing }))
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
const crossingTimes = [];
|
|
1460
|
-
for (let i = 1; i < kfs.length; i++) {
|
|
1461
|
-
const prev = kfs[i - 1];
|
|
1462
|
-
const cur = kfs[i];
|
|
1463
|
-
const dPrev = prev.value[1] - prev.value[0];
|
|
1464
|
-
const dCur = cur.value[1] - cur.value[0];
|
|
1465
|
-
if (dPrev * dCur < 0) {
|
|
1466
|
-
const t = bisectionForRangeCrossing(prev, cur);
|
|
1467
|
-
if (t !== null && t > prev.time && t < cur.time) {
|
|
1468
|
-
crossingTimes.push(Math.round(t));
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
const uniqueTs = Array.from(new Set(crossingTimes)).sort((a, b) => a - b);
|
|
1473
|
-
const out = [];
|
|
1474
|
-
let j = 0;
|
|
1475
|
-
for (const kf of kfs) {
|
|
1476
|
-
while (j < uniqueTs.length && uniqueTs[j] < kf.time) {
|
|
1477
|
-
const t = uniqueTs[j++];
|
|
1478
|
-
const v2 = interpolateRangeAt(kfs, t);
|
|
1479
|
-
const m = (v2[0] + v2[1]) / 2;
|
|
1480
|
-
out.push({ time: t, value: [m, m] });
|
|
1481
|
-
}
|
|
1482
|
-
const v = kf.value[0] > kf.value[1] ? [kf.value[1], kf.value[0]] : kf.value;
|
|
1483
|
-
out.push({ time: kf.time, value: v, easing: kf.easing });
|
|
1484
|
-
}
|
|
1485
|
-
while (j < uniqueTs.length) {
|
|
1486
|
-
const t = uniqueTs[j++];
|
|
1487
|
-
const v = interpolateRangeAt(kfs, t);
|
|
1488
|
-
const m = (v[0] + v[1]) / 2;
|
|
1489
|
-
out.push({ time: t, value: [m, m] });
|
|
1490
|
-
}
|
|
1491
|
-
return { kind: "animated" /* Animated */, keyframes: out };
|
|
1492
|
-
}
|
|
1493
|
-
function bisectionForRangeCrossing(prev, cur) {
|
|
1494
|
-
const f = (t) => {
|
|
1495
|
-
const a = (t - prev.time) / (cur.time - prev.time);
|
|
1496
|
-
const v0 = prev.value[0] + (cur.value[0] - prev.value[0]) * a;
|
|
1497
|
-
const v1 = prev.value[1] + (cur.value[1] - prev.value[1]) * a;
|
|
1498
|
-
return v1 - v0;
|
|
1499
|
-
};
|
|
1500
|
-
let lo = prev.time, hi = cur.time;
|
|
1501
|
-
let fLo = f(lo);
|
|
1502
|
-
if (fLo === 0) return lo;
|
|
1503
|
-
const fHi = f(hi);
|
|
1504
|
-
if (fHi === 0) return hi;
|
|
1505
|
-
if (fLo * fHi > 0) return null;
|
|
1506
|
-
for (let i = 0; i < 100; i++) {
|
|
1507
|
-
const mid = (lo + hi) / 2;
|
|
1508
|
-
const fMid = f(mid);
|
|
1509
|
-
if (fMid === 0 || Math.abs(hi - lo) < 1e-4) return mid;
|
|
1510
|
-
if (fLo * fMid < 0) {
|
|
1511
|
-
hi = mid;
|
|
1512
|
-
} else {
|
|
1513
|
-
lo = mid;
|
|
1514
|
-
fLo = fMid;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
return (lo + hi) / 2;
|
|
1518
|
-
}
|
|
1519
|
-
function interpolateRangeAt(kfs, t) {
|
|
1520
|
-
if (t <= kfs[0].time) return kfs[0].value;
|
|
1521
|
-
if (t >= kfs[kfs.length - 1].time) return kfs[kfs.length - 1].value;
|
|
1522
|
-
for (let i = 1; i < kfs.length; i++) {
|
|
1523
|
-
if (t <= kfs[i].time) {
|
|
1524
|
-
const prev = kfs[i - 1];
|
|
1525
|
-
const cur = kfs[i];
|
|
1526
|
-
const a = (t - prev.time) / (cur.time - prev.time);
|
|
1527
|
-
return [
|
|
1528
|
-
prev.value[0] + (cur.value[0] - prev.value[0]) * a,
|
|
1529
|
-
prev.value[1] + (cur.value[1] - prev.value[1]) * a
|
|
1530
|
-
];
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
return kfs[kfs.length - 1].value;
|
|
1534
|
-
}
|
|
1535
|
-
function pxBezierPathLength(path) {
|
|
1536
|
-
const v = path.v;
|
|
1537
|
-
if (!v || v.length < 2) return 0;
|
|
1538
|
-
let total = 0;
|
|
1539
|
-
for (let i = 0; i < v.length - 1; i++) {
|
|
1540
|
-
total += segmentLength(path, i, i + 1);
|
|
1541
|
-
}
|
|
1542
|
-
if (path.c && v.length > 1) {
|
|
1543
|
-
total += segmentLength(path, v.length - 1, 0);
|
|
1544
|
-
}
|
|
1545
|
-
return total;
|
|
1546
|
-
}
|
|
1547
|
-
function segmentLength(path, from, to) {
|
|
1548
|
-
var _a, _b, _c, _d;
|
|
1549
|
-
const v = path.v;
|
|
1550
|
-
const p0 = v[from];
|
|
1551
|
-
const p3 = v[to];
|
|
1552
|
-
const p1 = (_b = (_a = path.o) == null ? void 0 : _a[from]) != null ? _b : p0;
|
|
1553
|
-
const p2 = (_d = (_c = path.i) == null ? void 0 : _c[to]) != null ? _d : p3;
|
|
1554
|
-
const lut = bezier2D_arcLengthLUT(p0, p1, p2, p3);
|
|
1555
|
-
return lut.ds[lut.ds.length - 1];
|
|
1556
|
-
}
|
|
1557
|
-
var ARC_KAPPA = 0.5522847498307936;
|
|
1558
|
-
function shapeToPathD(node) {
|
|
1559
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1560
|
-
if (node.type === "rect") {
|
|
1561
|
-
const x = Number((_a = node.x) != null ? _a : 0), y = Number((_b = node.y) != null ? _b : 0);
|
|
1562
|
-
const w = Number((_c = node.width) != null ? _c : 0), h = Number((_d = node.height) != null ? _d : 0);
|
|
1563
|
-
return "M" + (x + w) + "," + y + "L" + (x + w) + "," + (y + h) + "L" + x + "," + (y + h) + "L" + x + "," + y + "L" + (x + w) + "," + y + "z";
|
|
1564
|
-
}
|
|
1565
|
-
if (node.type === "ellipse" || node.type === "circle") {
|
|
1566
|
-
const cx = Number((_e = node.cx) != null ? _e : 0), cy = Number((_f = node.cy) != null ? _f : 0);
|
|
1567
|
-
const rx = node.type === "circle" ? Number((_g = node.r) != null ? _g : 0) : Number((_h = node.rx) != null ? _h : 0);
|
|
1568
|
-
const ry = node.type === "circle" ? Number((_i = node.r) != null ? _i : 0) : Number((_j = node.ry) != null ? _j : 0);
|
|
1569
|
-
if (!(rx > 0) || !(ry > 0)) return void 0;
|
|
1570
|
-
const kx = rx * ARC_KAPPA, ky = ry * ARC_KAPPA;
|
|
1571
|
-
const c = (x1, y1, x2, y2, x, y) => "C" + x1 + "," + y1 + " " + x2 + "," + y2 + " " + x + "," + y;
|
|
1572
|
-
return "M" + (cx + rx) + "," + cy + c(cx + rx, cy + ky, cx + kx, cy + ry, cx, cy + ry) + c(cx - kx, cy + ry, cx - rx, cy + ky, cx - rx, cy) + c(cx - rx, cy - ky, cx - kx, cy - ry, cx, cy - ry) + c(cx + kx, cy - ry, cx + rx, cy - ky, cx + rx, cy) + "z";
|
|
1573
|
-
}
|
|
1574
|
-
return void 0;
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
// src/effects/PlayerEffectsUtil.ts
|
|
1578
|
-
function materializeNodeEffects(root) {
|
|
1579
|
-
var _a, _b;
|
|
1580
|
-
const ctx = {
|
|
1581
|
-
defs: [],
|
|
1582
|
-
warnings: [],
|
|
1583
|
-
errors: [],
|
|
1584
|
-
idMap: /* @__PURE__ */ new Map(),
|
|
1585
|
-
nextId: 0,
|
|
1586
|
-
contentRefInnerIds: /* @__PURE__ */ new Map(),
|
|
1587
|
-
maskAncestorChains: /* @__PURE__ */ new Map(),
|
|
1588
|
-
// Resolved engine: `frames` ONLY when explicitly set; auto/waapi/unset →
|
|
1589
|
-
// waapi (we're not 100% sure it's frames, and CSS/WAAPI need the inline form).
|
|
1590
|
-
engine: resolveTimelineEngine((_a = getAnimatorConfig(root)) == null ? void 0 : _a.engine),
|
|
1591
|
-
glyphs: (_b = getDefinitions(root)) == null ? void 0 : _b.fonts
|
|
1592
|
-
};
|
|
1593
|
-
const working = clone(root);
|
|
1594
|
-
indexById(working, ctx.idMap);
|
|
1595
|
-
identifyContentRefTargets(working, ctx, () => genId(ctx, "inner"));
|
|
1596
|
-
collectMaskAncestorChains(working, ctx);
|
|
1597
|
-
const afterPass1 = applyPlayerEffects_exceptRetime(working, ctx);
|
|
1598
|
-
const out = applyPlayerEffects_retime(afterPass1, ctx);
|
|
1599
|
-
spliceDefs(out, ctx.defs);
|
|
1600
|
-
return { root: out, defs: ctx.defs, warnings: ctx.warnings, errors: ctx.errors };
|
|
1601
|
-
}
|
|
1602
|
-
function applyPlayerEffects_exceptRetime(node, ctx) {
|
|
1603
|
-
if (node.children) node.children = node.children.map((child) => applyPlayerEffects_exceptRetime(child, ctx));
|
|
1604
|
-
const fx = node.effects;
|
|
1605
|
-
const originalId = typeof node.id === "string" ? node.id : void 0;
|
|
1606
|
-
const innerIdForContentRef = originalId ? ctx.contentRefInnerIds.get(originalId) : void 0;
|
|
1607
|
-
if (!fx && !innerIdForContentRef) return node;
|
|
1608
|
-
const { transformBy, repeater, maskedBy, clipPath, strokeTrim, clone: cloneFx, fillGradient, strokeGradient, textPath, text } = fx != null ? fx : {};
|
|
1609
|
-
if (fx) delete node.effects;
|
|
1610
|
-
let n = node;
|
|
1611
|
-
let consumedByGlyphs = false;
|
|
1612
|
-
if (text == null ? void 0 : text.useGlyphs) {
|
|
1613
|
-
if (textPath) {
|
|
1614
|
-
const pathD = typeof textPath.pathData === "string" ? textPath.pathData : void 0;
|
|
1615
|
-
const glyphed = applyTextGlyphsAlongPath(n, ctx, pathD, textPath.startOffset, textPath.textLength, textPath.pathOverflow);
|
|
1616
|
-
if (glyphed) {
|
|
1617
|
-
n = glyphed;
|
|
1618
|
-
consumedByGlyphs = true;
|
|
1619
|
-
}
|
|
1620
|
-
} else {
|
|
1621
|
-
n = applyTextGlyphsEffect(n, text, ctx);
|
|
1622
|
-
consumedByGlyphs = true;
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
if (!consumedByGlyphs) n = applyTextPathEffect(n, textPath, ctx);
|
|
1626
|
-
n = applyFillGradientEffect(n, fillGradient, ctx);
|
|
1627
|
-
n = applyStrokeGradientEffect(n, strokeGradient, ctx);
|
|
1628
|
-
n = applyStrokeTrimEffect(n, strokeTrim, ctx);
|
|
1629
|
-
n = applyRepeaterEffect(n, repeater, ctx);
|
|
1630
|
-
n = applyMaskedByEffect(n, maskedBy, transformBy, ctx);
|
|
1631
|
-
n = applyClipPathEffect(n, clipPath, ctx);
|
|
1632
|
-
if (innerIdForContentRef) {
|
|
1633
|
-
applyRefHref(n, cloneFx, ctx);
|
|
1634
|
-
n = splitForContentRef(n, transformBy, originalId, innerIdForContentRef, ctx);
|
|
1635
|
-
} else {
|
|
1636
|
-
n = applyRefAndTransformationEffect(n, cloneFx, transformBy, ctx);
|
|
1637
|
-
}
|
|
1638
|
-
if (cloneFx == null ? void 0 : cloneFx.retime) node.effects = { clone: { retime: cloneFx.retime } };
|
|
1639
|
-
if (originalId) ctx.idMap.set(originalId, n);
|
|
1640
|
-
return n;
|
|
1641
|
-
}
|
|
1642
|
-
function applyPlayerEffects_retime(node, ctx) {
|
|
1643
|
-
applyAllRetimeEffects(node, ctx);
|
|
1644
|
-
return node;
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
// src/materialize/PxOffsetPathMaterializer.ts
|
|
1648
|
-
function cubicAt(p0, c1, c2, p1, t) {
|
|
1649
|
-
const u = 1 - t;
|
|
1650
|
-
const a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
|
|
1651
|
-
return [
|
|
1652
|
-
a * p0[0] + b * c1[0] + c * c2[0] + d * p1[0],
|
|
1653
|
-
a * p0[1] + b * c1[1] + c * c2[1] + d * p1[1]
|
|
1654
|
-
];
|
|
1655
|
-
}
|
|
1656
|
-
function cubicLength(p0, c1, c2, p1, steps = 64) {
|
|
1657
|
-
let len = 0;
|
|
1658
|
-
let prev = p0;
|
|
1659
|
-
for (let i = 1; i <= steps; i++) {
|
|
1660
|
-
const pt = cubicAt(p0, c1, c2, p1, i / steps);
|
|
1661
|
-
len += Math.hypot(pt[0] - prev[0], pt[1] - prev[1]);
|
|
1662
|
-
prev = pt;
|
|
1663
|
-
}
|
|
1664
|
-
return len;
|
|
1665
|
-
}
|
|
1666
|
-
var fmt = (n) => {
|
|
1667
|
-
const r = Math.round(n * 1e4) / 1e4;
|
|
1668
|
-
return Object.is(r, -0) ? "0" : String(r);
|
|
1669
|
-
};
|
|
1670
|
-
function buildOffsetPath(propAnim) {
|
|
1671
|
-
var _a, _b, _c;
|
|
1672
|
-
if (propAnim.alongPathMode !== "offsetPath") return void 0;
|
|
1673
|
-
const kfs = propAnim.keyframes;
|
|
1674
|
-
if (!kfs || kfs.length < 2) return void 0;
|
|
1675
|
-
const first = keyframeValue(kfs[0]);
|
|
1676
|
-
const anchor = (first == null ? void 0 : first.origin) && first.origin.length >= 2 ? [first.origin[0], first.origin[1]] : [0, 0];
|
|
1677
|
-
const points = [];
|
|
1678
|
-
for (const kf of kfs) {
|
|
1679
|
-
const v = keyframeValue(kf);
|
|
1680
|
-
const tr = v == null ? void 0 : v.translate;
|
|
1681
|
-
if (!tr || tr.length < 2) return void 0;
|
|
1682
|
-
const parts = Object.keys(v);
|
|
1683
|
-
if (parts.some((p) => p !== "translate" && p !== "origin")) return void 0;
|
|
1684
|
-
const o = (_a = v == null ? void 0 : v.origin) != null ? _a : [0, 0];
|
|
1685
|
-
if (o[0] !== anchor[0] || o[1] !== anchor[1]) return void 0;
|
|
1686
|
-
points.push([tr[0] + anchor[0], tr[1] + anchor[1]]);
|
|
1687
|
-
}
|
|
1688
|
-
if (!kfs.some((kf) => keyframeTangentIn(kf) || keyframeTangentOut(kf))) return void 0;
|
|
1689
|
-
let d = "M" + fmt(points[0][0]) + "," + fmt(points[0][1]);
|
|
1690
|
-
const segLens = [];
|
|
1691
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
1692
|
-
const p0 = points[i], p1 = points[i + 1];
|
|
1693
|
-
const to = (_b = keyframeTangentOut(kfs[i])) != null ? _b : [0, 0];
|
|
1694
|
-
const ti = (_c = keyframeTangentIn(kfs[i + 1])) != null ? _c : [0, 0];
|
|
1695
|
-
const c1 = [p0[0] + to[0], p0[1] + to[1]];
|
|
1696
|
-
const c2 = [p1[0] + ti[0], p1[1] + ti[1]];
|
|
1697
|
-
d += "C" + fmt(c1[0]) + "," + fmt(c1[1]) + "," + fmt(c2[0]) + "," + fmt(c2[1]) + "," + fmt(p1[0]) + "," + fmt(p1[1]);
|
|
1698
|
-
segLens.push(cubicLength(p0, c1, c2, p1));
|
|
1699
|
-
}
|
|
1700
|
-
const total = segLens.reduce((a, b) => a + b, 0);
|
|
1701
|
-
if (!(total > 0)) return void 0;
|
|
1702
|
-
const distanceKfs = [];
|
|
1703
|
-
let cum = 0;
|
|
1704
|
-
for (let i = 0; i < kfs.length; i++) {
|
|
1705
|
-
if (i > 0) cum += segLens[i - 1];
|
|
1706
|
-
const out = { t: keyframeTime(kfs[i]), v: cum / total };
|
|
1707
|
-
const e = keyframeEasing(kfs[i]);
|
|
1708
|
-
if (e !== void 0) out.e = e;
|
|
1709
|
-
distanceKfs.push(out);
|
|
1710
|
-
}
|
|
1711
|
-
return { pathStr: d, distanceKfs, autoOrient: !!propAnim.autoOrient, anchor };
|
|
1712
|
-
}
|
|
1713
|
-
function materializeOffsetPathsInTree(root) {
|
|
1714
|
-
const walk = (node) => {
|
|
1715
|
-
var _a;
|
|
1716
|
-
let out = node;
|
|
1717
|
-
const anim = node.animate;
|
|
1718
|
-
const transform = anim == null ? void 0 : anim["transform"];
|
|
1719
|
-
if (transform) {
|
|
1720
|
-
const built = buildOffsetPath(transform);
|
|
1721
|
-
if (built) {
|
|
1722
|
-
const newAnimate = __spreadValues({}, anim);
|
|
1723
|
-
delete newAnimate[TRANSFORM_ATTR];
|
|
1724
|
-
const distance = { keyframes: built.distanceKfs };
|
|
1725
|
-
if (transform.loop !== void 0) distance.loop = transform.loop;
|
|
1726
|
-
newAnimate[OFFSET_DISTANCE_ATTR] = distance;
|
|
1727
|
-
const staticTr = node.transform;
|
|
1728
|
-
let newTransform = staticTr;
|
|
1729
|
-
if (staticTr && typeof staticTr === "object") {
|
|
1730
|
-
const t = __spreadValues({}, staticTr);
|
|
1731
|
-
delete t[TRANSFORM_PART.translate];
|
|
1732
|
-
delete t[TRANSFORM_PART.origin];
|
|
1733
|
-
newTransform = Object.keys(t).length ? t : void 0;
|
|
1734
|
-
}
|
|
1735
|
-
out = __spreadProps(__spreadValues({}, node), {
|
|
1736
|
-
animate: newAnimate,
|
|
1737
|
-
style: __spreadProps(__spreadValues({}, node.style), {
|
|
1738
|
-
offsetPath: "path('" + built.pathStr + "')",
|
|
1739
|
-
offsetAnchor: fmt(built.anchor[0]) + "px " + fmt(built.anchor[1]) + "px",
|
|
1740
|
-
offsetRotate: built.autoOrient ? "auto" : "0deg",
|
|
1741
|
-
offsetDistance: "0%"
|
|
1742
|
-
})
|
|
1743
|
-
});
|
|
1744
|
-
if (newTransform !== void 0) out.transform = newTransform;
|
|
1745
|
-
else delete out.transform;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
if ((_a = out.children) == null ? void 0 : _a.length) {
|
|
1749
|
-
const children = out.children.map(walk);
|
|
1750
|
-
if (children.some((c, i) => c !== out.children[i])) out = __spreadProps(__spreadValues({}, out), { children });
|
|
1751
|
-
}
|
|
1752
|
-
return out;
|
|
1753
|
-
};
|
|
1754
|
-
return walk(root);
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
// src/materialize/PxAnimatorUseMaterializer.ts
|
|
1758
|
-
function materializeAnimatedUseInstances(root) {
|
|
1759
|
-
var _a;
|
|
1760
|
-
const idMap = buildIdMap(root);
|
|
1761
|
-
const animatedIds = computeAnimatedSubtreeIds(root, idMap);
|
|
1762
|
-
if (animatedIds.size === 0) return root;
|
|
1763
|
-
let idCounter = 0;
|
|
1764
|
-
const genId3 = () => "_lw_use_mat_" + ++idCounter;
|
|
1765
|
-
const rootViewport = readRootViewport(root);
|
|
1766
|
-
const defsCollector = [];
|
|
1767
|
-
const walked = walkAndMaterialize(root, idMap, animatedIds, genId3, defsCollector, rootViewport);
|
|
1768
|
-
if (defsCollector.length === 0) return walked;
|
|
1769
|
-
const defsNode = { type: "defs", children: defsCollector };
|
|
1770
|
-
const newChildren = [...(_a = walked.children) != null ? _a : [], defsNode];
|
|
1771
|
-
return __spreadProps(__spreadValues({}, walked), { children: newChildren });
|
|
1772
|
-
}
|
|
1773
|
-
function readRootViewport(root) {
|
|
1774
|
-
const vb = parseViewBox(root.viewBox);
|
|
1775
|
-
if (vb) return [vb[2], vb[3]];
|
|
1776
|
-
const w = numericAttr(root.width);
|
|
1777
|
-
const h = numericAttr(root.height);
|
|
1778
|
-
if (w !== void 0 && h !== void 0) return [w, h];
|
|
1779
|
-
return [1, 1];
|
|
1780
|
-
}
|
|
1781
|
-
function numericAttr(v) {
|
|
1782
|
-
if (typeof v === "number") return v;
|
|
1783
|
-
if (typeof v === "string") {
|
|
1784
|
-
const n = parseFloat(v);
|
|
1785
|
-
return Number.isFinite(n) ? n : void 0;
|
|
1786
|
-
}
|
|
1787
|
-
return void 0;
|
|
1788
|
-
}
|
|
1789
|
-
function buildIdMap(root) {
|
|
1790
|
-
const map = /* @__PURE__ */ new Map();
|
|
1791
|
-
const visit = (n) => {
|
|
1792
|
-
var _a;
|
|
1793
|
-
if (typeof n.id === "string") map.set(n.id, n);
|
|
1794
|
-
(_a = n.children) == null ? void 0 : _a.forEach(visit);
|
|
1795
|
-
};
|
|
1796
|
-
visit(root);
|
|
1797
|
-
return map;
|
|
1798
|
-
}
|
|
1799
|
-
function computeAnimatedSubtreeIds(root, idMap) {
|
|
1800
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
1801
|
-
const result = /* @__PURE__ */ new Set();
|
|
1802
|
-
const hasAnim = (n, visiting) => {
|
|
1803
|
-
const cached = cache.get(n);
|
|
1804
|
-
if (cached !== void 0) return cached;
|
|
1805
|
-
if (visiting.has(n)) return false;
|
|
1806
|
-
visiting.add(n);
|
|
1807
|
-
let r = false;
|
|
1808
|
-
if (n.animate && typeof n.animate === "object" && !Array.isArray(n.animate)) {
|
|
1809
|
-
for (const _ in n.animate) {
|
|
1810
|
-
r = true;
|
|
1811
|
-
break;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
if (!r && n.children) {
|
|
1815
|
-
for (const ch of n.children) {
|
|
1816
|
-
if (hasAnim(ch, visiting)) {
|
|
1817
|
-
r = true;
|
|
1818
|
-
break;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
if (!r && n.type === "use" && typeof n.href === "string") {
|
|
1823
|
-
const targetId = stripHash2(n.href);
|
|
1824
|
-
const target = targetId ? idMap.get(targetId) : void 0;
|
|
1825
|
-
if (target) r = hasAnim(target, visiting);
|
|
1826
|
-
}
|
|
1827
|
-
visiting.delete(n);
|
|
1828
|
-
cache.set(n, r);
|
|
1829
|
-
return r;
|
|
1830
|
-
};
|
|
1831
|
-
for (const [id, node] of idMap) {
|
|
1832
|
-
if (hasAnim(node, /* @__PURE__ */ new Set())) result.add(id);
|
|
1833
|
-
}
|
|
1834
|
-
return result;
|
|
1835
|
-
}
|
|
1836
|
-
function stripHash2(href) {
|
|
1837
|
-
if (typeof href !== "string") return void 0;
|
|
1838
|
-
return href.startsWith("#") ? href.slice(1) : href;
|
|
1839
|
-
}
|
|
1840
|
-
function materializeOneUse(useNode, target, idMap, animatedIds, genId3, defsCollector, rootViewport) {
|
|
1841
|
-
var _a, _b, _c, _d;
|
|
1842
|
-
const clone2 = deepClonePxNode(target);
|
|
1843
|
-
regenerateIdsAndRewriteRefs(clone2, genId3);
|
|
1844
|
-
const symbolViewBox = clone2.type === "symbol" ? parseViewBox(clone2.viewBox) : void 0;
|
|
1845
|
-
const useW = (_b = (_a = numericAttr(useNode.width)) != null ? _a : symbolViewBox == null ? void 0 : symbolViewBox[2]) != null ? _b : rootViewport[0];
|
|
1846
|
-
const useH = (_d = (_c = numericAttr(useNode.height)) != null ? _c : symbolViewBox == null ? void 0 : symbolViewBox[3]) != null ? _d : rootViewport[1];
|
|
1847
|
-
const rewrittenClone = clone2.type === "symbol" ? rewriteSymbolRootToGroup(clone2, genId3, defsCollector, useW, useH) : clone2;
|
|
1848
|
-
const materializedClone = walkAndMaterialize(rewrittenClone, idMap, animatedIds, genId3, defsCollector, rootViewport);
|
|
1849
|
-
const newNode = __spreadProps(__spreadValues({}, useNode), { type: "g", children: [materializedClone] });
|
|
1850
|
-
delete newNode.href;
|
|
1851
|
-
delete newNode.width;
|
|
1852
|
-
delete newNode.height;
|
|
1853
|
-
return applyUseOffsetToG(newNode);
|
|
1854
|
-
}
|
|
1855
|
-
function rewriteSymbolRootToGroup(symbolNode, genId3, defsCollector, useW, useH) {
|
|
1856
|
-
const viewBox = parseViewBox(symbolNode.viewBox);
|
|
1857
|
-
const g = __spreadProps(__spreadValues({}, symbolNode), { type: "g" });
|
|
1858
|
-
delete g.viewBox;
|
|
1859
|
-
delete g.preserveAspectRatio;
|
|
1860
|
-
delete g.width;
|
|
1861
|
-
delete g.height;
|
|
1862
|
-
if (!viewBox) return g;
|
|
1863
|
-
const [vbX, vbY, vbW, vbH] = viewBox;
|
|
1864
|
-
const scale = vbW > 0 && vbH > 0 ? Math.min(useW / vbW, useH / vbH) : 1;
|
|
1865
|
-
const xOff = (useW - vbW * scale) / 2;
|
|
1866
|
-
const yOff = (useH - vbH * scale) / 2;
|
|
1867
|
-
const parts = [];
|
|
1868
|
-
if (xOff !== 0 || yOff !== 0) parts.push("translate(" + xOff + "," + yOff + ")");
|
|
1869
|
-
if (scale !== 1) parts.push("scale(" + scale + ")");
|
|
1870
|
-
if (vbX !== 0 || vbY !== 0) parts.push("translate(" + -vbX + "," + -vbY + ")");
|
|
1871
|
-
if (parts.length) g.transform = parts.join("");
|
|
1872
|
-
const clipId = genId3();
|
|
1873
|
-
defsCollector.push({
|
|
1874
|
-
type: "clipPath",
|
|
1875
|
-
id: clipId,
|
|
1876
|
-
children: [{ type: "rect", x: vbX, y: vbY, width: vbW, height: vbH }]
|
|
1877
|
-
});
|
|
1878
|
-
g.clipPath = "url(#" + clipId + ")";
|
|
1879
|
-
return g;
|
|
1880
|
-
}
|
|
1881
|
-
function parseViewBox(v) {
|
|
1882
|
-
if (typeof v !== "string") return void 0;
|
|
1883
|
-
const parts = v.trim().split(/[\s,]+/).map(Number);
|
|
1884
|
-
if (parts.length < 4 || parts.some((n) => !Number.isFinite(n))) return void 0;
|
|
1885
|
-
return [parts[0], parts[1], parts[2], parts[3]];
|
|
1886
|
-
}
|
|
1887
|
-
function walkAndMaterialize(node, idMap, animatedIds, genId3, defsCollector, rootViewport) {
|
|
1888
|
-
if (node.type === "use" && typeof node.href === "string") {
|
|
1889
|
-
const targetId = stripHash2(node.href);
|
|
1890
|
-
if (targetId && animatedIds.has(targetId)) {
|
|
1891
|
-
const target = idMap.get(targetId);
|
|
1892
|
-
if (target) return materializeOneUse(node, target, idMap, animatedIds, genId3, defsCollector, rootViewport);
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
if (!node.children) return node;
|
|
1896
|
-
let changed = false;
|
|
1897
|
-
const newChildren = node.children.map((ch) => {
|
|
1898
|
-
const m = walkAndMaterialize(ch, idMap, animatedIds, genId3, defsCollector, rootViewport);
|
|
1899
|
-
if (m !== ch) changed = true;
|
|
1900
|
-
return m;
|
|
1901
|
-
});
|
|
1902
|
-
return changed ? __spreadProps(__spreadValues({}, node), { children: newChildren }) : node;
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
|
-
// src/materialize/PxAnimatorMaterializeAll.ts
|
|
1906
|
-
function materializeAllInTree(doc, engine, options) {
|
|
1907
|
-
var _a, _b;
|
|
1908
|
-
let root = materializeNodeEffects(doc).root;
|
|
1909
|
-
root = materializeOffsetPathsInTree(root);
|
|
1910
|
-
const duration = (_b = (_a = getAnimatorConfig(root)) == null ? void 0 : _a.duration) != null ? _b : PX_DEFAULT_DURATION_MS;
|
|
1911
|
-
root = materializeInternalLoopsInTree(root, duration);
|
|
1912
|
-
if (engine === PxTimelineEngine.native) {
|
|
1913
|
-
root = materializeMotionPathsInTree(root, options == null ? void 0 : options.motionPath);
|
|
1914
|
-
root = materializeAnimatedUseInstances(root);
|
|
1915
|
-
root = pruneUnreferencedDefs(root);
|
|
1916
|
-
}
|
|
1917
|
-
return root;
|
|
1918
|
-
}
|
|
1919
|
-
function pruneUnreferencedDefs(root) {
|
|
1920
|
-
const stripHash3 = (h) => h.startsWith("#") ? h.slice(1) : h;
|
|
1921
|
-
const walk = (n, fn) => {
|
|
1922
|
-
var _a;
|
|
1923
|
-
fn(n);
|
|
1924
|
-
(_a = n.children) == null ? void 0 : _a.forEach((c) => walk(c, fn));
|
|
1925
|
-
};
|
|
1926
|
-
let changed = true;
|
|
1927
|
-
while (changed) {
|
|
1928
|
-
changed = false;
|
|
1929
|
-
const referenced = /* @__PURE__ */ new Set();
|
|
1930
|
-
walk(root, (n) => {
|
|
1931
|
-
if (n.type === "use" && typeof n.href === "string") referenced.add(stripHash3(n.href));
|
|
1932
|
-
});
|
|
1933
|
-
walk(root, (n) => {
|
|
1934
|
-
if (!n.children) return;
|
|
1935
|
-
let kept = n.children;
|
|
1936
|
-
if (n.type === "defs") {
|
|
1937
|
-
kept = kept.filter((c) => !((c.type === "g" || c.type === "symbol") && typeof c.id === "string" && !referenced.has(c.id)));
|
|
1938
|
-
}
|
|
1939
|
-
kept = kept.filter((c) => !(c.type === "defs" && (!c.children || c.children.length === 0)));
|
|
1940
|
-
if (kept.length !== n.children.length) {
|
|
1941
|
-
n.children = kept;
|
|
1942
|
-
changed = true;
|
|
1943
|
-
}
|
|
1944
|
-
});
|
|
1945
|
-
}
|
|
1946
|
-
return root;
|
|
1947
|
-
}
|
|
111
|
+
wireVersionAdvice
|
|
112
|
+
} from "./chunk-YVKMPBHE.js";
|
|
1948
113
|
|
|
1949
114
|
// src/playback/PxPlaybackTime.ts
|
|
1950
115
|
var PX_RATE_REJECTED = "setPlaybackRate: rate must be finite and non-zero";
|
|
@@ -2287,38 +452,6 @@ function createAdapterAnimator(doc, adapter, callbacks) {
|
|
|
2287
452
|
return api;
|
|
2288
453
|
}
|
|
2289
454
|
|
|
2290
|
-
// src/playback/PxDiagnosticCode.ts
|
|
2291
|
-
var PxDiagnosticCode = /* @__PURE__ */ ((PxDiagnosticCode2) => {
|
|
2292
|
-
PxDiagnosticCode2[PxDiagnosticCode2["buildFailed"] = 1001] = "buildFailed";
|
|
2293
|
-
PxDiagnosticCode2[PxDiagnosticCode2["invalidDocumentAtSrc"] = 1002] = "invalidDocumentAtSrc";
|
|
2294
|
-
PxDiagnosticCode2[PxDiagnosticCode2["loadFailed"] = 1003] = "loadFailed";
|
|
2295
|
-
PxDiagnosticCode2[PxDiagnosticCode2["animationBuildFailed"] = 1004] = "animationBuildFailed";
|
|
2296
|
-
PxDiagnosticCode2[PxDiagnosticCode2["effectsShape"] = 1101] = "effectsShape";
|
|
2297
|
-
PxDiagnosticCode2[PxDiagnosticCode2["timelineOverrideIgnored"] = 1102] = "timelineOverrideIgnored";
|
|
2298
|
-
PxDiagnosticCode2[PxDiagnosticCode2["blockedTag"] = 1103] = "blockedTag";
|
|
2299
|
-
PxDiagnosticCode2[PxDiagnosticCode2["unsupportedAnimatedAttrs"] = 1104] = "unsupportedAnimatedAttrs";
|
|
2300
|
-
PxDiagnosticCode2[PxDiagnosticCode2["noBindings"] = 1105] = "noBindings";
|
|
2301
|
-
PxDiagnosticCode2[PxDiagnosticCode2["unresolvedBinding"] = 1106] = "unresolvedBinding";
|
|
2302
|
-
PxDiagnosticCode2[PxDiagnosticCode2["triggersNoRoot"] = 1201] = "triggersNoRoot";
|
|
2303
|
-
PxDiagnosticCode2[PxDiagnosticCode2["noRootForSelector"] = 1202] = "noRootForSelector";
|
|
2304
|
-
PxDiagnosticCode2[PxDiagnosticCode2["noRootElement"] = 1203] = "noRootElement";
|
|
2305
|
-
PxDiagnosticCode2[PxDiagnosticCode2["noElementsForSelector"] = 1206] = "noElementsForSelector";
|
|
2306
|
-
PxDiagnosticCode2[PxDiagnosticCode2["setAttributeNoElement"] = 1207] = "setAttributeNoElement";
|
|
2307
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollSmoothingNeedsOwnDriver"] = 1301] = "scrollSmoothingNeedsOwnDriver";
|
|
2308
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollNativeUnavailable"] = 1302] = "scrollNativeUnavailable";
|
|
2309
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectInvalid"] = 1303] = "scrollSubjectInvalid";
|
|
2310
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectNoMatch"] = 1304] = "scrollSubjectNoMatch";
|
|
2311
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollNoRootToObserve"] = 1305] = "scrollNoRootToObserve";
|
|
2312
|
-
PxDiagnosticCode2[PxDiagnosticCode2["scrollTriggerIgnored"] = 1306] = "scrollTriggerIgnored";
|
|
2313
|
-
PxDiagnosticCode2[PxDiagnosticCode2["rateRejected"] = 1401] = "rateRejected";
|
|
2314
|
-
PxDiagnosticCode2[PxDiagnosticCode2["controlPropsConflict"] = 1501] = "controlPropsConflict";
|
|
2315
|
-
PxDiagnosticCode2[PxDiagnosticCode2["rnCompileFailed"] = 1601] = "rnCompileFailed";
|
|
2316
|
-
PxDiagnosticCode2[PxDiagnosticCode2["rnRenderFailed"] = 1602] = "rnRenderFailed";
|
|
2317
|
-
PxDiagnosticCode2[PxDiagnosticCode2["rnBoundaryCaught"] = 1603] = "rnBoundaryCaught";
|
|
2318
|
-
PxDiagnosticCode2[PxDiagnosticCode2["rnUnsupported"] = 1604] = "rnUnsupported";
|
|
2319
|
-
return PxDiagnosticCode2;
|
|
2320
|
-
})(PxDiagnosticCode || {});
|
|
2321
|
-
|
|
2322
455
|
// src/playback/PxAnimatorConfigPatch.ts
|
|
2323
456
|
var FLAT_ONLY_KEYS = [
|
|
2324
457
|
"timelineSource",
|
|
@@ -2394,16 +527,16 @@ function foldTimelineOverride(timeline, shortcuts) {
|
|
|
2394
527
|
} else {
|
|
2395
528
|
base = timeline != null ? timeline : void 0;
|
|
2396
529
|
}
|
|
2397
|
-
const { duration, delay, iterations,
|
|
2398
|
-
if (duration === void 0 && delay === void 0 && iterations === void 0 &&
|
|
530
|
+
const { duration, delay, iterations, start } = shortcuts;
|
|
531
|
+
if (duration === void 0 && delay === void 0 && iterations === void 0 && start === void 0) {
|
|
2399
532
|
return base === void 0 ? void 0 : { timeline: base };
|
|
2400
533
|
}
|
|
2401
534
|
const out = isPlainObject(base) ? __spreadValues({}, base) : {};
|
|
2402
535
|
if (duration !== void 0) out.duration = duration;
|
|
2403
536
|
if (delay !== void 0) out.delay = delay;
|
|
2404
537
|
if (iterations !== void 0) out.iterations = iterations;
|
|
2405
|
-
if (
|
|
2406
|
-
out.trigger = __spreadProps(__spreadValues({}, out.trigger), {
|
|
538
|
+
if (start !== void 0) {
|
|
539
|
+
out.trigger = __spreadProps(__spreadValues({}, out.trigger), { start });
|
|
2407
540
|
}
|
|
2408
541
|
return { timeline: out };
|
|
2409
542
|
}
|
|
@@ -2507,9 +640,10 @@ export {
|
|
|
2507
640
|
PxLoopSchema,
|
|
2508
641
|
PxMaskType,
|
|
2509
642
|
PxMaskedByEffectSchema,
|
|
643
|
+
PxMouseOutAction,
|
|
2510
644
|
PxNodeBaseSchema,
|
|
2511
645
|
PxNodeSchema,
|
|
2512
|
-
|
|
646
|
+
PxOffScreenAction,
|
|
2513
647
|
PxPathOverflow,
|
|
2514
648
|
PxPinAlign,
|
|
2515
649
|
PxPlaybackDirection,
|
|
@@ -2523,7 +657,6 @@ export {
|
|
|
2523
657
|
PxScrollRangeSchema,
|
|
2524
658
|
PxScrollSchema,
|
|
2525
659
|
PxScrollSource,
|
|
2526
|
-
PxStartOn,
|
|
2527
660
|
PxStrokeTrimEffectSchema,
|
|
2528
661
|
PxStrokeTrimSubPaths,
|
|
2529
662
|
PxSvgNodeRootSchema,
|
|
@@ -2538,6 +671,7 @@ export {
|
|
|
2538
671
|
PxTransformPartsSchema,
|
|
2539
672
|
PxTransformValueSchema,
|
|
2540
673
|
PxTriggerSchema,
|
|
674
|
+
PxTriggerStart,
|
|
2541
675
|
PxUnits,
|
|
2542
676
|
PxWireStepKind,
|
|
2543
677
|
PxWireVersionRelation,
|