@sarmal/core 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-init.cjs +84 -89
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.d.cts +2 -1
- package/dist/auto-init.d.ts +2 -1
- package/dist/auto-init.js +83 -88
- package/dist/auto-init.js.map +1 -1
- package/dist/curves/artemis2.cjs +7 -10
- package/dist/curves/artemis2.d.cts +1 -1
- package/dist/curves/artemis2.d.ts +1 -1
- package/dist/curves/artemis2.js +6 -9
- package/dist/curves/astroid.cjs +4 -4
- package/dist/curves/astroid.d.cts +1 -1
- package/dist/curves/astroid.d.ts +1 -1
- package/dist/curves/astroid.js +3 -3
- package/dist/curves/deltoid.cjs +4 -4
- package/dist/curves/deltoid.d.cts +1 -1
- package/dist/curves/deltoid.d.ts +1 -1
- package/dist/curves/deltoid.js +3 -3
- package/dist/curves/epicycloid3.cjs +4 -4
- package/dist/curves/epicycloid3.d.cts +1 -1
- package/dist/curves/epicycloid3.d.ts +1 -1
- package/dist/curves/epicycloid3.js +3 -3
- package/dist/curves/epitrochoid7.cjs +5 -5
- package/dist/curves/epitrochoid7.d.cts +1 -1
- package/dist/curves/epitrochoid7.d.ts +1 -1
- package/dist/curves/epitrochoid7.js +4 -4
- package/dist/curves/index.cjs +28 -32
- package/dist/curves/index.d.cts +21 -21
- package/dist/curves/index.d.ts +21 -21
- package/dist/curves/index.js +28 -44
- package/dist/curves/lame.cjs +5 -6
- package/dist/curves/lame.d.cts +1 -1
- package/dist/curves/lame.d.ts +1 -1
- package/dist/curves/lame.js +4 -5
- package/dist/curves/lissajous32.cjs +4 -4
- package/dist/curves/lissajous32.d.cts +1 -1
- package/dist/curves/lissajous32.d.ts +1 -1
- package/dist/curves/lissajous32.js +3 -3
- package/dist/curves/lissajous43.cjs +4 -4
- package/dist/curves/lissajous43.d.cts +1 -1
- package/dist/curves/lissajous43.d.ts +1 -1
- package/dist/curves/lissajous43.js +3 -3
- package/dist/curves/rose3.cjs +4 -4
- package/dist/curves/rose3.d.cts +1 -1
- package/dist/curves/rose3.d.ts +1 -1
- package/dist/curves/rose3.js +3 -3
- package/dist/curves/rose5.cjs +4 -4
- package/dist/curves/rose5.d.cts +1 -1
- package/dist/curves/rose5.d.ts +1 -1
- package/dist/curves/rose5.js +3 -3
- package/dist/index.cjs +98 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -58
- package/dist/index.d.ts +23 -58
- package/dist/index.js +98 -107
- package/dist/index.js.map +1 -1
- package/dist/types-BQosOzlf.d.cts +276 -0
- package/dist/types-BQosOzlf.d.ts +276 -0
- package/package.json +1 -1
- package/dist/types-BW0bpL1Z.d.cts +0 -290
- package/dist/types-BW0bpL1Z.d.ts +0 -290
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/engine.ts
|
|
4
4
|
var TWO_PI = Math.PI * 2;
|
|
@@ -63,13 +63,13 @@ function resolveCurve(curveDef) {
|
|
|
63
63
|
period,
|
|
64
64
|
speed,
|
|
65
65
|
skeleton: curveDef.skeleton,
|
|
66
|
-
skeletonFn: curveDef.skeletonFn
|
|
66
|
+
skeletonFn: curveDef.skeletonFn
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
function createEngine(curveDef, trailLength = 120) {
|
|
70
70
|
if (!Number.isFinite(trailLength) || trailLength <= 0) {
|
|
71
71
|
throw new RangeError(
|
|
72
|
-
`[sarmal] trailLength must be a positive finite number, got ${trailLength}
|
|
72
|
+
`[sarmal] trailLength must be a positive finite number, got ${trailLength}`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
let curve = resolveCurve(curveDef);
|
|
@@ -110,7 +110,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
110
110
|
actualTime += deltaTime;
|
|
111
111
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
112
112
|
const a = curve.fn(t, actualTime, EMPTY_PARAMS);
|
|
113
|
-
const tB = _morphStrategy === "normalized" ?
|
|
113
|
+
const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
|
|
114
114
|
const b = morphCurveB.fn(tB, actualTime, EMPTY_PARAMS);
|
|
115
115
|
trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
|
|
116
116
|
} else {
|
|
@@ -134,14 +134,14 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
134
134
|
trail.clear();
|
|
135
135
|
},
|
|
136
136
|
jump(newT, { clearTrail = false } = {}) {
|
|
137
|
-
t = (
|
|
137
|
+
t = (newT % curve.period + curve.period) % curve.period;
|
|
138
138
|
if (clearTrail) {
|
|
139
139
|
trail.clear();
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
|
|
143
143
|
const advance = curve.speed * step;
|
|
144
|
-
const target = (
|
|
144
|
+
const target = (targetT % curve.period + curve.period) % curve.period;
|
|
145
145
|
const targetTime = target / curve.speed;
|
|
146
146
|
t = target;
|
|
147
147
|
actualTime = targetTime;
|
|
@@ -150,7 +150,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
150
150
|
const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
|
|
151
151
|
for (let i = count - 1; i >= 0; i--) {
|
|
152
152
|
const sampleT = target - i * advance;
|
|
153
|
-
const wrappedT = (
|
|
153
|
+
const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
|
|
154
154
|
const time = targetTime - i * step;
|
|
155
155
|
const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
|
|
156
156
|
trail.push(point.x, point.y);
|
|
@@ -167,16 +167,13 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
167
167
|
...frozenB,
|
|
168
168
|
fn: (sampleT, time, params) => {
|
|
169
169
|
const a = frozenA.fn(sampleT, time, params);
|
|
170
|
-
const tB =
|
|
171
|
-
frozenStrategy === "normalized"
|
|
172
|
-
? (sampleT / frozenA.period) * frozenB.period
|
|
173
|
-
: sampleT;
|
|
170
|
+
const tB = frozenStrategy === "normalized" ? sampleT / frozenA.period * frozenB.period : sampleT;
|
|
174
171
|
const b = frozenB.fn(tB, time, params);
|
|
175
172
|
return {
|
|
176
173
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
177
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
174
|
+
y: a.y + (b.y - a.y) * frozenAlpha
|
|
178
175
|
};
|
|
179
|
-
}
|
|
176
|
+
}
|
|
180
177
|
};
|
|
181
178
|
}
|
|
182
179
|
_morphStrategy = strategy;
|
|
@@ -189,7 +186,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
189
186
|
completeMorph() {
|
|
190
187
|
if (morphCurveB !== null) {
|
|
191
188
|
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
192
|
-
t =
|
|
189
|
+
t = t / curve.period * morphCurveB.period;
|
|
193
190
|
}
|
|
194
191
|
curve = morphCurveB;
|
|
195
192
|
}
|
|
@@ -201,22 +198,19 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
201
198
|
const points = new Array(steps);
|
|
202
199
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
203
200
|
for (let i = 0; i < steps; i++) {
|
|
204
|
-
const sampleT =
|
|
201
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
205
202
|
const a = sampleSkeleton(curve, sampleT);
|
|
206
|
-
const tB =
|
|
207
|
-
_morphStrategy === "normalized"
|
|
208
|
-
? (sampleT / curve.period) * morphCurveB.period
|
|
209
|
-
: sampleT;
|
|
203
|
+
const tB = _morphStrategy === "normalized" ? sampleT / curve.period * morphCurveB.period : sampleT;
|
|
210
204
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
211
205
|
points[i] = {
|
|
212
206
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
213
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
207
|
+
y: a.y + (b.y - a.y) * _morphAlpha
|
|
214
208
|
};
|
|
215
209
|
}
|
|
216
210
|
return points;
|
|
217
211
|
}
|
|
218
212
|
for (let i = 0; i < steps; i++) {
|
|
219
|
-
const sampleT =
|
|
213
|
+
const sampleT = i / (steps - 1) * curve.period;
|
|
220
214
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
221
215
|
}
|
|
222
216
|
return points;
|
|
@@ -258,7 +252,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
258
252
|
_speedTransition.reject(new Error("Speed transition cancelled"));
|
|
259
253
|
_speedTransition = null;
|
|
260
254
|
}
|
|
261
|
-
}
|
|
255
|
+
}
|
|
262
256
|
};
|
|
263
257
|
}
|
|
264
258
|
|
|
@@ -321,16 +315,13 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
|
|
|
321
315
|
r1x: nx - n1.x * w1,
|
|
322
316
|
r1y: ny - n1.y * w1,
|
|
323
317
|
opacity,
|
|
324
|
-
progress
|
|
318
|
+
progress
|
|
325
319
|
};
|
|
326
320
|
}
|
|
327
321
|
function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
328
322
|
if (pts.length === 0) return null;
|
|
329
323
|
const first = pts[0];
|
|
330
|
-
let minX = first.x,
|
|
331
|
-
maxX = first.x,
|
|
332
|
-
minY = first.y,
|
|
333
|
-
maxY = first.y;
|
|
324
|
+
let minX = first.x, maxX = first.x, minY = first.y, maxY = first.y;
|
|
334
325
|
for (const p of pts) {
|
|
335
326
|
if (p.x < minX) {
|
|
336
327
|
minX = p.x;
|
|
@@ -349,7 +340,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
349
340
|
const h = maxY - minY;
|
|
350
341
|
if (w === 0 && h === 0) {
|
|
351
342
|
throw new Error(
|
|
352
|
-
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
343
|
+
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
353
344
|
);
|
|
354
345
|
}
|
|
355
346
|
const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
|
|
@@ -360,12 +351,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
360
351
|
scaleXProportional,
|
|
361
352
|
scaleYProportional,
|
|
362
353
|
scaleXMinPadding,
|
|
363
|
-
scaleYMinPadding
|
|
354
|
+
scaleYMinPadding
|
|
364
355
|
);
|
|
365
356
|
return {
|
|
366
357
|
scale,
|
|
367
358
|
offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
|
|
368
|
-
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
359
|
+
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
369
360
|
};
|
|
370
361
|
}
|
|
371
362
|
function enginePassthroughs(engine) {
|
|
@@ -375,19 +366,16 @@ function enginePassthroughs(engine) {
|
|
|
375
366
|
setSpeed: engine.setSpeed,
|
|
376
367
|
getSpeed: engine.getSpeed,
|
|
377
368
|
resetSpeed: engine.resetSpeed,
|
|
378
|
-
setSpeedOver: engine.setSpeedOver
|
|
369
|
+
setSpeedOver: engine.setSpeedOver
|
|
379
370
|
};
|
|
380
371
|
}
|
|
381
|
-
|
|
382
|
-
// src/renderer.ts
|
|
383
|
-
var DEFAULT_SKELETON_COLOR = "#ffffff";
|
|
384
372
|
var GRADIENT = {
|
|
385
373
|
bard: ["#a855f7", "#3b82f6", "#14b8a6", "#ec4899"],
|
|
386
374
|
sunset: ["#f97316", "#dc2626", "#9333ea", "#f472b6"],
|
|
387
375
|
ocean: ["#1e3a8a", "#06b6d4", "#22d3ee", "#e0f2fe"],
|
|
388
376
|
ice: ["#1e3a8a", "#67e8f9"],
|
|
389
377
|
fire: ["#7f1d1d", "#fbbf24"],
|
|
390
|
-
forest: ["#14532d", "#86efac"]
|
|
378
|
+
forest: ["#14532d", "#86efac"]
|
|
391
379
|
};
|
|
392
380
|
var PRESETS = {
|
|
393
381
|
bard: GRADIENT.bard,
|
|
@@ -395,20 +383,24 @@ var PRESETS = {
|
|
|
395
383
|
ocean: GRADIENT.ocean,
|
|
396
384
|
ice: GRADIENT.ice,
|
|
397
385
|
fire: GRADIENT.fire,
|
|
398
|
-
forest: GRADIENT.forest
|
|
386
|
+
forest: GRADIENT.forest
|
|
399
387
|
};
|
|
400
388
|
function hexToRgb(hex) {
|
|
401
389
|
const n = parseInt(hex.slice(1), 16);
|
|
402
|
-
return { r: n >> 16, g:
|
|
390
|
+
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
403
391
|
}
|
|
404
392
|
var lerpRgb = (a, b, t) => ({
|
|
405
393
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
406
394
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
407
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
395
|
+
b: Math.round(a.b + (b.b - a.b) * t)
|
|
408
396
|
});
|
|
409
397
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
410
|
-
if (palette.length === 0)
|
|
411
|
-
|
|
398
|
+
if (palette.length === 0) {
|
|
399
|
+
return { r: 255, g: 255, b: 255 };
|
|
400
|
+
}
|
|
401
|
+
if (palette.length === 1) {
|
|
402
|
+
return hexToRgb(palette[0]);
|
|
403
|
+
}
|
|
412
404
|
const cyclePos = (position + timeOffset) % 1;
|
|
413
405
|
const scaled = cyclePos * palette.length;
|
|
414
406
|
const idx = Math.floor(scaled);
|
|
@@ -418,13 +410,20 @@ function getPaletteColor(palette, position, timeOffset = 0) {
|
|
|
418
410
|
return lerpRgb(c1, c2, t);
|
|
419
411
|
}
|
|
420
412
|
function resolvePalette(palette, trailStyle) {
|
|
421
|
-
if (Array.isArray(palette))
|
|
422
|
-
|
|
413
|
+
if (Array.isArray(palette)) {
|
|
414
|
+
return palette;
|
|
415
|
+
}
|
|
416
|
+
if (palette && palette in PRESETS) {
|
|
417
|
+
return PRESETS[palette];
|
|
418
|
+
}
|
|
423
419
|
return trailStyle === "gradient-animated" ? GRADIENT.bard : GRADIENT.ice;
|
|
424
420
|
}
|
|
421
|
+
|
|
422
|
+
// src/renderer.ts
|
|
423
|
+
var DEFAULT_SKELETON_COLOR = "#ffffff";
|
|
425
424
|
function hexToRgbComponents(hex) {
|
|
426
425
|
const n = parseInt(hex.slice(1), 16);
|
|
427
|
-
return `${n >> 16},${
|
|
426
|
+
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
428
427
|
}
|
|
429
428
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
430
429
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -452,7 +451,7 @@ function createRenderer(options) {
|
|
|
452
451
|
const opts = {
|
|
453
452
|
skeletonColor: options.skeletonColor ?? DEFAULT_SKELETON_COLOR,
|
|
454
453
|
trailColor,
|
|
455
|
-
headColor: options.headColor ?? defaultHeadColor()
|
|
454
|
+
headColor: options.headColor ?? defaultHeadColor()
|
|
456
455
|
};
|
|
457
456
|
const trailRgb = hexToRgbComponents(opts.trailColor);
|
|
458
457
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
@@ -553,7 +552,7 @@ function createRenderer(options) {
|
|
|
553
552
|
i,
|
|
554
553
|
trailCount,
|
|
555
554
|
toX,
|
|
556
|
-
toY
|
|
555
|
+
toY
|
|
557
556
|
);
|
|
558
557
|
if (trailStyle === "default") {
|
|
559
558
|
ctx.fillStyle = `rgba(${trailRgb},${opacity})`;
|
|
@@ -577,8 +576,7 @@ function createRenderer(options) {
|
|
|
577
576
|
}
|
|
578
577
|
const x = head.x * scale + offsetX;
|
|
579
578
|
const y = head.y * scale + offsetY;
|
|
580
|
-
const r =
|
|
581
|
-
options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(logicalWidth, logicalHeight) / 160));
|
|
579
|
+
const r = options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(logicalWidth, logicalHeight) / 160));
|
|
582
580
|
ctx.fillStyle = opts.headColor;
|
|
583
581
|
ctx.beginPath();
|
|
584
582
|
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
@@ -679,7 +677,7 @@ function createRenderer(options) {
|
|
|
679
677
|
return new Promise((resolve) => {
|
|
680
678
|
morphResolve = resolve;
|
|
681
679
|
});
|
|
682
|
-
}
|
|
680
|
+
}
|
|
683
681
|
};
|
|
684
682
|
if (shouldAutoStart) {
|
|
685
683
|
instance.play();
|
|
@@ -705,7 +703,7 @@ function sampleCurveSkeleton(curveDef) {
|
|
|
705
703
|
const samples = Math.ceil(period * 50);
|
|
706
704
|
const pts = Array.from({ length: samples });
|
|
707
705
|
for (let i = 0; i < samples; i++) {
|
|
708
|
-
const t =
|
|
706
|
+
const t = i / (samples - 1) * period;
|
|
709
707
|
pts[i] = curveDef.skeletonFn ? curveDef.skeletonFn(t) : curveDef.fn(t, 0, EMPTY_PARAMS2);
|
|
710
708
|
}
|
|
711
709
|
return pts;
|
|
@@ -716,17 +714,21 @@ function el(tag) {
|
|
|
716
714
|
function createSVGRenderer(options) {
|
|
717
715
|
const { container, engine } = options;
|
|
718
716
|
const trailColor = options.trailColor ?? "#ffffff";
|
|
717
|
+
const trailStyle = options.trailStyle ?? "default";
|
|
718
|
+
const palette = resolvePalette(options.palette, trailStyle);
|
|
719
719
|
const opts = {
|
|
720
720
|
skeletonColor: options.skeletonColor ?? "#ffffff",
|
|
721
721
|
trailColor,
|
|
722
|
-
headColor: options.headColor ??
|
|
723
|
-
|
|
722
|
+
headColor: options.headColor ?? (trailStyle !== "default" ? (() => {
|
|
723
|
+
const { r, g, b } = getPaletteColor(palette, 1);
|
|
724
|
+
return `rgb(${r},${g},${b})`;
|
|
725
|
+
})() : trailColor),
|
|
726
|
+
ariaLabel: options.ariaLabel ?? "Loading"
|
|
724
727
|
};
|
|
725
728
|
const rect = container.getBoundingClientRect();
|
|
726
729
|
const width = rect.width || 200;
|
|
727
730
|
const height = rect.height || 200;
|
|
728
|
-
const headRadius =
|
|
729
|
-
options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(width, height) / 160));
|
|
731
|
+
const headRadius = options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(width, height) / 160));
|
|
730
732
|
const svg = el("svg");
|
|
731
733
|
svg.setAttribute("width", String(width));
|
|
732
734
|
svg.setAttribute("height", String(height));
|
|
@@ -737,6 +739,7 @@ function createSVGRenderer(options) {
|
|
|
737
739
|
titleEl.textContent = opts.ariaLabel;
|
|
738
740
|
svg.appendChild(titleEl);
|
|
739
741
|
const skeletonPath = el("path");
|
|
742
|
+
skeletonPath.setAttribute("data-sarmal-role", "skeleton");
|
|
740
743
|
skeletonPath.setAttribute("fill", "none");
|
|
741
744
|
skeletonPath.setAttribute("stroke", opts.skeletonColor);
|
|
742
745
|
skeletonPath.setAttribute("stroke-opacity", String(DEFAULT_SKELETON_OPACITY));
|
|
@@ -764,10 +767,12 @@ function createSVGRenderer(options) {
|
|
|
764
767
|
trailPaths.push(path);
|
|
765
768
|
}
|
|
766
769
|
const headCircle = el("circle");
|
|
770
|
+
headCircle.setAttribute("data-sarmal-role", "head");
|
|
767
771
|
headCircle.setAttribute("fill", opts.headColor);
|
|
768
772
|
headCircle.setAttribute("r", String(headRadius));
|
|
769
773
|
svg.appendChild(headCircle);
|
|
770
774
|
container.appendChild(svg);
|
|
775
|
+
let gradientAnimTime = 0;
|
|
771
776
|
let scale = 1;
|
|
772
777
|
let offsetX = 0;
|
|
773
778
|
let offsetY = 0;
|
|
@@ -801,16 +806,21 @@ function createSVGRenderer(options) {
|
|
|
801
806
|
return;
|
|
802
807
|
}
|
|
803
808
|
for (let i = 0; i < trailCount - 1; i++) {
|
|
804
|
-
const { l0x, l0y, r0x, r0y, l1x, l1y, r1x, r1y, opacity } = computeTrailQuad(
|
|
809
|
+
const { l0x, l0y, r0x, r0y, l1x, l1y, r1x, r1y, opacity, progress } = computeTrailQuad(
|
|
805
810
|
trail,
|
|
806
811
|
i,
|
|
807
812
|
trailCount,
|
|
808
813
|
px,
|
|
809
|
-
py
|
|
814
|
+
py
|
|
810
815
|
);
|
|
811
816
|
const d = `M${l0x.toFixed(2)} ${l0y.toFixed(2)} L${l1x.toFixed(2)} ${l1y.toFixed(2)} L${r1x.toFixed(2)} ${r1y.toFixed(2)} L${r0x.toFixed(2)} ${r0y.toFixed(2)} Z`;
|
|
812
817
|
trailPaths[i].setAttribute("d", d);
|
|
813
818
|
trailPaths[i].setAttribute("fill-opacity", opacity.toFixed(3));
|
|
819
|
+
if (trailStyle !== "default") {
|
|
820
|
+
const timeOffset = trailStyle === "gradient-animated" ? gradientAnimTime * 5e-4 : 0;
|
|
821
|
+
const { r, g, b } = getPaletteColor(palette, progress, timeOffset);
|
|
822
|
+
trailPaths[i].setAttribute("fill", `rgb(${r},${g},${b})`);
|
|
823
|
+
}
|
|
814
824
|
}
|
|
815
825
|
for (let i = trailCount - 1; i < trailPaths.length; i++) {
|
|
816
826
|
trailPaths[i].setAttribute("d", "");
|
|
@@ -828,13 +838,15 @@ function createSVGRenderer(options) {
|
|
|
828
838
|
}
|
|
829
839
|
let animationId = null;
|
|
830
840
|
let lastTime = 0;
|
|
831
|
-
const prefersReducedMotion =
|
|
832
|
-
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
841
|
+
const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
833
842
|
let morphResolve = null;
|
|
834
843
|
let morphDurationMs = DEFAULT_MORPH_DURATION_MS;
|
|
835
844
|
let morphTarget = null;
|
|
836
845
|
let morphAlpha = 0;
|
|
837
846
|
function renderFrame(deltaTime) {
|
|
847
|
+
if (trailStyle === "gradient-animated") {
|
|
848
|
+
gradientAnimTime += deltaTime * 1e3;
|
|
849
|
+
}
|
|
838
850
|
if (engine.morphAlpha !== null) {
|
|
839
851
|
morphAlpha = Math.min(1, morphAlpha + deltaTime / (morphDurationMs / 1e3));
|
|
840
852
|
engine.setMorphAlpha(morphAlpha);
|
|
@@ -843,7 +855,7 @@ function createSVGRenderer(options) {
|
|
|
843
855
|
skeletonPathA.setAttribute("visibility", "visible");
|
|
844
856
|
skeletonPathA.setAttribute(
|
|
845
857
|
"stroke-opacity",
|
|
846
|
-
String((1 - morphAlpha) * DEFAULT_SKELETON_OPACITY)
|
|
858
|
+
String((1 - morphAlpha) * DEFAULT_SKELETON_OPACITY)
|
|
847
859
|
);
|
|
848
860
|
}
|
|
849
861
|
if (morphPathBBuilt) {
|
|
@@ -939,7 +951,7 @@ function createSVGRenderer(options) {
|
|
|
939
951
|
return new Promise((resolve) => {
|
|
940
952
|
morphResolve = resolve;
|
|
941
953
|
});
|
|
942
|
-
}
|
|
954
|
+
}
|
|
943
955
|
};
|
|
944
956
|
if (shouldAutoStart) {
|
|
945
957
|
instance.play();
|
|
@@ -955,22 +967,19 @@ function createSarmalSVG(container, curveDef, options) {
|
|
|
955
967
|
// src/curves/artemis2.ts
|
|
956
968
|
var TWO_PI2 = Math.PI * 2;
|
|
957
969
|
function artemis2Fn(t, _time, _params) {
|
|
958
|
-
const a = 0.35,
|
|
959
|
-
|
|
960
|
-
ox = 0.175;
|
|
961
|
-
const s = Math.sin(t),
|
|
962
|
-
c = Math.cos(t);
|
|
970
|
+
const a = 0.35, b = 0.15, ox = 0.175;
|
|
971
|
+
const s = Math.sin(t), c = Math.cos(t);
|
|
963
972
|
const denom = 1 + s * s;
|
|
964
973
|
return {
|
|
965
|
-
x:
|
|
966
|
-
y:
|
|
974
|
+
x: c * (1 + a * c) / denom - ox,
|
|
975
|
+
y: s * c * (1 + b * c) / denom
|
|
967
976
|
};
|
|
968
977
|
}
|
|
969
978
|
var artemis2 = {
|
|
970
979
|
name: "Artemis II",
|
|
971
980
|
fn: artemis2Fn,
|
|
972
981
|
period: TWO_PI2,
|
|
973
|
-
speed: 0.7
|
|
982
|
+
speed: 0.7
|
|
974
983
|
};
|
|
975
984
|
|
|
976
985
|
// src/curves/astroid.ts
|
|
@@ -980,14 +989,14 @@ function astroidFn(t, _time, _params) {
|
|
|
980
989
|
const s = Math.sin(t);
|
|
981
990
|
return {
|
|
982
991
|
x: c * c * c,
|
|
983
|
-
y: s * s * s
|
|
992
|
+
y: s * s * s
|
|
984
993
|
};
|
|
985
994
|
}
|
|
986
995
|
var astroid = {
|
|
987
996
|
name: "Astroid",
|
|
988
997
|
fn: astroidFn,
|
|
989
998
|
period: TWO_PI3,
|
|
990
|
-
speed: 1.1
|
|
999
|
+
speed: 1.1
|
|
991
1000
|
};
|
|
992
1001
|
|
|
993
1002
|
// src/curves/deltoid.ts
|
|
@@ -995,14 +1004,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
995
1004
|
function deltoidFn(t, _time, _params) {
|
|
996
1005
|
return {
|
|
997
1006
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
998
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
1007
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
999
1008
|
};
|
|
1000
1009
|
}
|
|
1001
1010
|
var deltoid = {
|
|
1002
1011
|
name: "Deltoid",
|
|
1003
1012
|
fn: deltoidFn,
|
|
1004
1013
|
period: TWO_PI4,
|
|
1005
|
-
speed: 0.9
|
|
1014
|
+
speed: 0.9
|
|
1006
1015
|
};
|
|
1007
1016
|
|
|
1008
1017
|
// src/curves/epicycloid3.ts
|
|
@@ -1010,14 +1019,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
1010
1019
|
function epicycloid3Fn(t, _time, _params) {
|
|
1011
1020
|
return {
|
|
1012
1021
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
1013
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
1022
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
1014
1023
|
};
|
|
1015
1024
|
}
|
|
1016
1025
|
var epicycloid3 = {
|
|
1017
1026
|
name: "Epicycloid (n=3)",
|
|
1018
1027
|
fn: epicycloid3Fn,
|
|
1019
1028
|
period: TWO_PI5,
|
|
1020
|
-
speed: 0.75
|
|
1029
|
+
speed: 0.75
|
|
1021
1030
|
};
|
|
1022
1031
|
|
|
1023
1032
|
// src/curves/epitrochoid7.ts
|
|
@@ -1026,14 +1035,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
1026
1035
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
1027
1036
|
return {
|
|
1028
1037
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
1029
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
1038
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
1030
1039
|
};
|
|
1031
1040
|
}
|
|
1032
1041
|
function epitrochoid7SkeletonFn(t) {
|
|
1033
1042
|
const d = 1.275;
|
|
1034
1043
|
return {
|
|
1035
1044
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
1036
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
1045
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
1037
1046
|
};
|
|
1038
1047
|
}
|
|
1039
1048
|
var epitrochoid7 = {
|
|
@@ -1041,7 +1050,7 @@ var epitrochoid7 = {
|
|
|
1041
1050
|
fn: epitrochoid7Fn,
|
|
1042
1051
|
period: TWO_PI6,
|
|
1043
1052
|
speed: 1.4,
|
|
1044
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
1053
|
+
skeletonFn: epitrochoid7SkeletonFn
|
|
1045
1054
|
};
|
|
1046
1055
|
|
|
1047
1056
|
// src/curves/lissajous32.ts
|
|
@@ -1050,7 +1059,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
1050
1059
|
const phi = time * 0.45;
|
|
1051
1060
|
return {
|
|
1052
1061
|
x: Math.sin(3 * t + phi),
|
|
1053
|
-
y: Math.sin(2 * t)
|
|
1062
|
+
y: Math.sin(2 * t)
|
|
1054
1063
|
};
|
|
1055
1064
|
}
|
|
1056
1065
|
var lissajous32 = {
|
|
@@ -1058,7 +1067,7 @@ var lissajous32 = {
|
|
|
1058
1067
|
fn: lissajous32Fn,
|
|
1059
1068
|
period: TWO_PI7,
|
|
1060
1069
|
speed: 2,
|
|
1061
|
-
skeleton: "live"
|
|
1070
|
+
skeleton: "live"
|
|
1062
1071
|
};
|
|
1063
1072
|
|
|
1064
1073
|
// src/curves/lissajous43.ts
|
|
@@ -1067,7 +1076,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
1067
1076
|
const phi = time * 0.38;
|
|
1068
1077
|
return {
|
|
1069
1078
|
x: Math.sin(4 * t + phi),
|
|
1070
|
-
y: Math.sin(3 * t)
|
|
1079
|
+
y: Math.sin(3 * t)
|
|
1071
1080
|
};
|
|
1072
1081
|
}
|
|
1073
1082
|
var lissajous43 = {
|
|
@@ -1075,18 +1084,17 @@ var lissajous43 = {
|
|
|
1075
1084
|
fn: lissajous43Fn,
|
|
1076
1085
|
period: TWO_PI8,
|
|
1077
1086
|
speed: 1.8,
|
|
1078
|
-
skeleton: "live"
|
|
1087
|
+
skeleton: "live"
|
|
1079
1088
|
};
|
|
1080
1089
|
|
|
1081
1090
|
// src/curves/lame.ts
|
|
1082
1091
|
var TWO_PI9 = Math.PI * 2;
|
|
1083
1092
|
function lameFn(t, time, _params) {
|
|
1084
1093
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
1085
|
-
const c = Math.cos(t),
|
|
1086
|
-
s = Math.sin(t);
|
|
1094
|
+
const c = Math.cos(t), s = Math.sin(t);
|
|
1087
1095
|
return {
|
|
1088
1096
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
1089
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
1097
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
1090
1098
|
};
|
|
1091
1099
|
}
|
|
1092
1100
|
var lame = {
|
|
@@ -1094,7 +1102,7 @@ var lame = {
|
|
|
1094
1102
|
fn: lameFn,
|
|
1095
1103
|
period: TWO_PI9,
|
|
1096
1104
|
speed: 1,
|
|
1097
|
-
skeleton: "live"
|
|
1105
|
+
skeleton: "live"
|
|
1098
1106
|
};
|
|
1099
1107
|
|
|
1100
1108
|
// src/curves/rose3.ts
|
|
@@ -1103,14 +1111,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
1103
1111
|
const r = Math.cos(3 * t);
|
|
1104
1112
|
return {
|
|
1105
1113
|
x: r * Math.cos(t),
|
|
1106
|
-
y: r * Math.sin(t)
|
|
1114
|
+
y: r * Math.sin(t)
|
|
1107
1115
|
};
|
|
1108
1116
|
}
|
|
1109
1117
|
var rose3 = {
|
|
1110
1118
|
name: "Rose (n=3)",
|
|
1111
1119
|
fn: rose3Fn,
|
|
1112
1120
|
period: TWO_PI10,
|
|
1113
|
-
speed: 1.15
|
|
1121
|
+
speed: 1.15
|
|
1114
1122
|
};
|
|
1115
1123
|
|
|
1116
1124
|
// src/curves/rose5.ts
|
|
@@ -1119,14 +1127,14 @@ function rose5Fn(t, _time, _params) {
|
|
|
1119
1127
|
const r = Math.cos(5 * t);
|
|
1120
1128
|
return {
|
|
1121
1129
|
x: r * Math.cos(t),
|
|
1122
|
-
y: r * Math.sin(t)
|
|
1130
|
+
y: r * Math.sin(t)
|
|
1123
1131
|
};
|
|
1124
1132
|
}
|
|
1125
1133
|
var rose5 = {
|
|
1126
1134
|
name: "Rose (n=5)",
|
|
1127
1135
|
fn: rose5Fn,
|
|
1128
1136
|
period: TWO_PI11,
|
|
1129
|
-
speed: 1
|
|
1137
|
+
speed: 1
|
|
1130
1138
|
};
|
|
1131
1139
|
|
|
1132
1140
|
// src/curves/index.ts
|
|
@@ -1140,7 +1148,7 @@ var curves = {
|
|
|
1140
1148
|
lissajous32,
|
|
1141
1149
|
lissajous43,
|
|
1142
1150
|
epicycloid3,
|
|
1143
|
-
lame
|
|
1151
|
+
lame
|
|
1144
1152
|
};
|
|
1145
1153
|
|
|
1146
1154
|
// src/index.ts
|
|
@@ -1167,4 +1175,4 @@ exports.lissajous43 = lissajous43;
|
|
|
1167
1175
|
exports.rose3 = rose3;
|
|
1168
1176
|
exports.rose5 = rose5;
|
|
1169
1177
|
//# sourceMappingURL=index.cjs.map
|
|
1170
|
-
//# sourceMappingURL=index.cjs.map
|
|
1178
|
+
//# sourceMappingURL=index.cjs.map
|