@sarmal/core 0.15.1 → 0.17.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 +176 -78
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.js +175 -77
- package/dist/auto-init.js.map +1 -1
- package/dist/curves/artemis2.cjs +10 -7
- package/dist/curves/artemis2.d.cts +1 -1
- package/dist/curves/artemis2.d.ts +1 -1
- package/dist/curves/artemis2.js +9 -6
- 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 +114 -29
- package/dist/curves/index.cjs.map +1 -1
- package/dist/curves/index.d.cts +29 -21
- package/dist/curves/index.d.ts +29 -21
- package/dist/curves/index.js +126 -29
- package/dist/curves/index.js.map +1 -1
- package/dist/curves/lame.cjs +6 -5
- package/dist/curves/lame.d.cts +1 -1
- package/dist/curves/lame.d.ts +1 -1
- package/dist/curves/lame.js +5 -4
- 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/curves/rose52.cjs +21 -0
- package/dist/curves/rose52.cjs.map +1 -0
- package/dist/curves/rose52.d.cts +9 -0
- package/dist/curves/rose52.d.ts +9 -0
- package/dist/curves/rose52.js +19 -0
- package/dist/curves/rose52.js.map +1 -0
- package/dist/curves/star.cjs +24 -0
- package/dist/curves/star.cjs.map +1 -0
- package/dist/curves/star.d.cts +8 -0
- package/dist/curves/star.d.ts +8 -0
- package/dist/curves/star.js +22 -0
- package/dist/curves/star.js.map +1 -0
- package/dist/curves/star4.cjs +24 -0
- package/dist/curves/star4.cjs.map +1 -0
- package/dist/curves/star4.d.cts +9 -0
- package/dist/curves/star4.d.ts +9 -0
- package/dist/curves/star4.js +22 -0
- package/dist/curves/star4.js.map +1 -0
- package/dist/curves/star7.cjs +24 -0
- package/dist/curves/star7.cjs.map +1 -0
- package/dist/curves/star7.d.cts +9 -0
- package/dist/curves/star7.d.ts +9 -0
- package/dist/curves/star7.js +22 -0
- package/dist/curves/star7.js.map +1 -0
- package/dist/index.cjs +190 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -29
- package/dist/index.d.ts +70 -29
- package/dist/index.js +208 -78
- package/dist/index.js.map +1 -1
- package/dist/types-BL9HhEmk.d.cts +259 -246
- package/dist/types-BL9HhEmk.d.ts +259 -246
- package/package.json +1 -1
package/dist/auto-init.js
CHANGED
|
@@ -61,13 +61,13 @@ function resolveCurve(curveDef) {
|
|
|
61
61
|
period,
|
|
62
62
|
speed,
|
|
63
63
|
skeleton: curveDef.skeleton,
|
|
64
|
-
skeletonFn: curveDef.skeletonFn
|
|
64
|
+
skeletonFn: curveDef.skeletonFn,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
function createEngine(curveDef, trailLength = 120) {
|
|
68
68
|
if (!Number.isFinite(trailLength) || trailLength <= 0) {
|
|
69
69
|
throw new RangeError(
|
|
70
|
-
`[sarmal] trailLength must be a positive finite number, got ${trailLength}
|
|
70
|
+
`[sarmal] trailLength must be a positive finite number, got ${trailLength}`,
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
let curve = resolveCurve(curveDef);
|
|
@@ -108,7 +108,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
108
108
|
actualTime += deltaTime;
|
|
109
109
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
110
110
|
const a = curve.fn(t, actualTime, EMPTY_PARAMS);
|
|
111
|
-
const tB = _morphStrategy === "normalized" ? t / curve.period * morphCurveB.period : t;
|
|
111
|
+
const tB = _morphStrategy === "normalized" ? (t / curve.period) * morphCurveB.period : t;
|
|
112
112
|
const b = morphCurveB.fn(tB, actualTime, EMPTY_PARAMS);
|
|
113
113
|
trail.push(a.x + (b.x - a.x) * _morphAlpha, a.y + (b.y - a.y) * _morphAlpha);
|
|
114
114
|
} else {
|
|
@@ -132,14 +132,14 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
132
132
|
trail.clear();
|
|
133
133
|
},
|
|
134
134
|
jump(newT, { clearTrail = false } = {}) {
|
|
135
|
-
t = (newT % curve.period + curve.period) % curve.period;
|
|
135
|
+
t = ((newT % curve.period) + curve.period) % curve.period;
|
|
136
136
|
if (clearTrail) {
|
|
137
137
|
trail.clear();
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
|
|
141
141
|
const advance = curve.speed * step;
|
|
142
|
-
const target = (targetT % curve.period + curve.period) % curve.period;
|
|
142
|
+
const target = ((targetT % curve.period) + curve.period) % curve.period;
|
|
143
143
|
const targetTime = target / curve.speed;
|
|
144
144
|
t = target;
|
|
145
145
|
actualTime = targetTime;
|
|
@@ -148,7 +148,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
148
148
|
const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
|
|
149
149
|
for (let i = count - 1; i >= 0; i--) {
|
|
150
150
|
const sampleT = target - i * advance;
|
|
151
|
-
const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
|
|
151
|
+
const wrappedT = ((sampleT % curve.period) + curve.period) % curve.period;
|
|
152
152
|
const time = targetTime - i * step;
|
|
153
153
|
const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
|
|
154
154
|
trail.push(point.x, point.y);
|
|
@@ -165,13 +165,16 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
165
165
|
...frozenB,
|
|
166
166
|
fn: (sampleT, time, params) => {
|
|
167
167
|
const a = frozenA.fn(sampleT, time, params);
|
|
168
|
-
const tB =
|
|
168
|
+
const tB =
|
|
169
|
+
frozenStrategy === "normalized"
|
|
170
|
+
? (sampleT / frozenA.period) * frozenB.period
|
|
171
|
+
: sampleT;
|
|
169
172
|
const b = frozenB.fn(tB, time, params);
|
|
170
173
|
return {
|
|
171
174
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
172
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
175
|
+
y: a.y + (b.y - a.y) * frozenAlpha,
|
|
173
176
|
};
|
|
174
|
-
}
|
|
177
|
+
},
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
180
|
_morphStrategy = strategy;
|
|
@@ -184,7 +187,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
184
187
|
completeMorph() {
|
|
185
188
|
if (morphCurveB !== null) {
|
|
186
189
|
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
187
|
-
t = t / curve.period * morphCurveB.period;
|
|
190
|
+
t = (t / curve.period) * morphCurveB.period;
|
|
188
191
|
}
|
|
189
192
|
curve = morphCurveB;
|
|
190
193
|
}
|
|
@@ -196,19 +199,22 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
196
199
|
const points = new Array(steps);
|
|
197
200
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
198
201
|
for (let i = 0; i < steps; i++) {
|
|
199
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
202
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
200
203
|
const a = sampleSkeleton(curve, sampleT);
|
|
201
|
-
const tB =
|
|
204
|
+
const tB =
|
|
205
|
+
_morphStrategy === "normalized"
|
|
206
|
+
? (sampleT / curve.period) * morphCurveB.period
|
|
207
|
+
: sampleT;
|
|
202
208
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
203
209
|
points[i] = {
|
|
204
210
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
205
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
211
|
+
y: a.y + (b.y - a.y) * _morphAlpha,
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
214
|
return points;
|
|
209
215
|
}
|
|
210
216
|
for (let i = 0; i < steps; i++) {
|
|
211
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
217
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
212
218
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
213
219
|
}
|
|
214
220
|
return points;
|
|
@@ -250,7 +256,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
250
256
|
_speedTransition.reject(new Error("Speed transition cancelled"));
|
|
251
257
|
_speedTransition = null;
|
|
252
258
|
}
|
|
253
|
-
}
|
|
259
|
+
},
|
|
254
260
|
};
|
|
255
261
|
}
|
|
256
262
|
|
|
@@ -313,13 +319,16 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
|
|
|
313
319
|
r1x: nx - n1.x * w1,
|
|
314
320
|
r1y: ny - n1.y * w1,
|
|
315
321
|
opacity,
|
|
316
|
-
progress
|
|
322
|
+
progress,
|
|
317
323
|
};
|
|
318
324
|
}
|
|
319
325
|
function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
320
326
|
if (pts.length === 0) return null;
|
|
321
327
|
const first = pts[0];
|
|
322
|
-
let minX = first.x,
|
|
328
|
+
let minX = first.x,
|
|
329
|
+
maxX = first.x,
|
|
330
|
+
minY = first.y,
|
|
331
|
+
maxY = first.y;
|
|
323
332
|
for (const p of pts) {
|
|
324
333
|
if (p.x < minX) {
|
|
325
334
|
minX = p.x;
|
|
@@ -338,7 +347,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
338
347
|
const h = maxY - minY;
|
|
339
348
|
if (w === 0 && h === 0) {
|
|
340
349
|
throw new Error(
|
|
341
|
-
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t."
|
|
350
|
+
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t.",
|
|
342
351
|
);
|
|
343
352
|
}
|
|
344
353
|
const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
|
|
@@ -349,12 +358,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
349
358
|
scaleXProportional,
|
|
350
359
|
scaleYProportional,
|
|
351
360
|
scaleXMinPadding,
|
|
352
|
-
scaleYMinPadding
|
|
361
|
+
scaleYMinPadding,
|
|
353
362
|
);
|
|
354
363
|
return {
|
|
355
364
|
scale,
|
|
356
365
|
offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
|
|
357
|
-
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
366
|
+
offsetY: (logicalHeight - h * scale) / 2 - minY * scale,
|
|
358
367
|
};
|
|
359
368
|
}
|
|
360
369
|
function enginePassthroughs(engine) {
|
|
@@ -364,17 +373,17 @@ function enginePassthroughs(engine) {
|
|
|
364
373
|
setSpeed: engine.setSpeed,
|
|
365
374
|
getSpeed: engine.getSpeed,
|
|
366
375
|
resetSpeed: engine.resetSpeed,
|
|
367
|
-
setSpeedOver: engine.setSpeedOver
|
|
376
|
+
setSpeedOver: engine.setSpeedOver,
|
|
368
377
|
};
|
|
369
378
|
}
|
|
370
379
|
function hexToRgb(hex) {
|
|
371
380
|
const n = parseInt(hex.slice(1), 16);
|
|
372
|
-
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
381
|
+
return { r: n >> 16, g: (n >> 8) & 255, b: n & 255 };
|
|
373
382
|
}
|
|
374
383
|
var lerpRgb = (a, b, t) => ({
|
|
375
384
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
376
385
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
377
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
386
|
+
b: Math.round(a.b + (b.b - a.b) * t),
|
|
378
387
|
});
|
|
379
388
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
380
389
|
if (palette.length === 0) {
|
|
@@ -397,7 +406,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
397
406
|
"trailColor",
|
|
398
407
|
"headColor",
|
|
399
408
|
"skeletonColor",
|
|
400
|
-
"trailStyle"
|
|
409
|
+
"trailStyle",
|
|
401
410
|
]);
|
|
402
411
|
function validateRenderOptions(partial) {
|
|
403
412
|
for (const key of Object.keys(partial)) {
|
|
@@ -422,7 +431,7 @@ function assertTrailColor(value) {
|
|
|
422
431
|
if (typeof value === "string") {
|
|
423
432
|
if (!HEX_COLOR_RE.test(value)) {
|
|
424
433
|
throw new TypeError(
|
|
425
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"
|
|
434
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`,
|
|
426
435
|
);
|
|
427
436
|
}
|
|
428
437
|
return;
|
|
@@ -430,21 +439,21 @@ function assertTrailColor(value) {
|
|
|
430
439
|
if (Array.isArray(value)) {
|
|
431
440
|
if (value.length < 2) {
|
|
432
441
|
throw new RangeError(
|
|
433
|
-
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}
|
|
442
|
+
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`,
|
|
434
443
|
);
|
|
435
444
|
}
|
|
436
445
|
for (let i = 0; i < value.length; i++) {
|
|
437
446
|
const entry = value[i];
|
|
438
447
|
if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
|
|
439
448
|
throw new TypeError(
|
|
440
|
-
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}
|
|
449
|
+
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`,
|
|
441
450
|
);
|
|
442
451
|
}
|
|
443
452
|
}
|
|
444
453
|
return;
|
|
445
454
|
}
|
|
446
455
|
throw new TypeError(
|
|
447
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}
|
|
456
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`,
|
|
448
457
|
);
|
|
449
458
|
}
|
|
450
459
|
function assertHeadColor(value) {
|
|
@@ -453,7 +462,7 @@ function assertHeadColor(value) {
|
|
|
453
462
|
}
|
|
454
463
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
455
464
|
throw new TypeError(
|
|
456
|
-
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}
|
|
465
|
+
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`,
|
|
457
466
|
);
|
|
458
467
|
}
|
|
459
468
|
}
|
|
@@ -463,14 +472,14 @@ function assertSkeletonColor(value) {
|
|
|
463
472
|
}
|
|
464
473
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
465
474
|
throw new TypeError(
|
|
466
|
-
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}
|
|
475
|
+
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`,
|
|
467
476
|
);
|
|
468
477
|
}
|
|
469
478
|
}
|
|
470
479
|
function assertTrailStyle(value) {
|
|
471
480
|
if (!TRAIL_STYLES.includes(value)) {
|
|
472
481
|
throw new RangeError(
|
|
473
|
-
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}
|
|
482
|
+
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`,
|
|
474
483
|
);
|
|
475
484
|
}
|
|
476
485
|
}
|
|
@@ -492,13 +501,13 @@ function resolveHeadColor(trailColor, trailStyle) {
|
|
|
492
501
|
function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
493
502
|
if (trailStyle === "default" && Array.isArray(trailColor)) {
|
|
494
503
|
console.warn(
|
|
495
|
-
'[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.'
|
|
504
|
+
'[sarmal] trailColor is an array but trailStyle is "default"; only the first color will be used. Pass a gradient trailStyle to use the whole palette.',
|
|
496
505
|
);
|
|
497
506
|
return;
|
|
498
507
|
}
|
|
499
508
|
if (trailStyle !== "default" && typeof trailColor === "string") {
|
|
500
509
|
console.warn(
|
|
501
|
-
`[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient
|
|
510
|
+
`[sarmal] trailColor is a single color but trailStyle is "${trailStyle}"; the trail will render as a solid color. Pass an array of hex colors to use a real gradient.`,
|
|
502
511
|
);
|
|
503
512
|
}
|
|
504
513
|
}
|
|
@@ -508,7 +517,7 @@ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160)
|
|
|
508
517
|
var WHITE_HEX = "#ffffff";
|
|
509
518
|
function hexToRgbComponents(hex) {
|
|
510
519
|
const n = parseInt(hex.slice(1), 16);
|
|
511
|
-
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
520
|
+
return `${n >> 16},${(n >> 8) & 255},${n & 255}`;
|
|
512
521
|
}
|
|
513
522
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
514
523
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -552,6 +561,7 @@ function createRenderer(options) {
|
|
|
552
561
|
let animationId = null;
|
|
553
562
|
let lastTime = 0;
|
|
554
563
|
let morphResolve = null;
|
|
564
|
+
let morphReject = null;
|
|
555
565
|
let morphDurationMs = DEFAULT_MORPH_DURATION_MS;
|
|
556
566
|
let morphAlpha = 0;
|
|
557
567
|
let gradientAnimTime = 0;
|
|
@@ -632,7 +642,7 @@ function createRenderer(options) {
|
|
|
632
642
|
i,
|
|
633
643
|
trailCount,
|
|
634
644
|
toX,
|
|
635
|
-
toY
|
|
645
|
+
toY,
|
|
636
646
|
);
|
|
637
647
|
if (trailStyle === "default") {
|
|
638
648
|
ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
|
|
@@ -680,6 +690,7 @@ function createRenderer(options) {
|
|
|
680
690
|
engine.completeMorph();
|
|
681
691
|
morphResolve?.();
|
|
682
692
|
morphResolve = null;
|
|
693
|
+
morphReject = null;
|
|
683
694
|
morphAlpha = 0;
|
|
684
695
|
skeleton = engine.getSarmalSkeleton();
|
|
685
696
|
if (!engine.isLiveSkeleton) {
|
|
@@ -742,6 +753,11 @@ function createRenderer(options) {
|
|
|
742
753
|
cancelAnimationFrame(animationId);
|
|
743
754
|
animationId = null;
|
|
744
755
|
}
|
|
756
|
+
if (morphReject !== null) {
|
|
757
|
+
morphReject(new Error("Instance destroyed during morph"));
|
|
758
|
+
morphResolve = null;
|
|
759
|
+
morphReject = null;
|
|
760
|
+
}
|
|
745
761
|
},
|
|
746
762
|
...enginePassthroughs(engine),
|
|
747
763
|
morphTo(target, options2) {
|
|
@@ -749,13 +765,15 @@ function createRenderer(options) {
|
|
|
749
765
|
engine.completeMorph();
|
|
750
766
|
morphResolve();
|
|
751
767
|
morphResolve = null;
|
|
768
|
+
morphReject = null;
|
|
752
769
|
morphAlpha = 0;
|
|
753
770
|
}
|
|
754
771
|
morphDurationMs = options2?.duration ?? DEFAULT_MORPH_DURATION_MS;
|
|
755
772
|
morphAlpha = 0;
|
|
756
773
|
engine.startMorph(target, options2?.morphStrategy);
|
|
757
|
-
return new Promise((resolve) => {
|
|
774
|
+
return new Promise((resolve, reject) => {
|
|
758
775
|
morphResolve = resolve;
|
|
776
|
+
morphReject = reject;
|
|
759
777
|
});
|
|
760
778
|
},
|
|
761
779
|
setRenderOptions(partial) {
|
|
@@ -785,7 +803,7 @@ function createRenderer(options) {
|
|
|
785
803
|
if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
|
|
786
804
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
787
805
|
}
|
|
788
|
-
}
|
|
806
|
+
},
|
|
789
807
|
};
|
|
790
808
|
if (shouldAutoStart) {
|
|
791
809
|
instance.play();
|
|
@@ -796,19 +814,22 @@ function createRenderer(options) {
|
|
|
796
814
|
// src/curves/artemis2.ts
|
|
797
815
|
var TWO_PI2 = Math.PI * 2;
|
|
798
816
|
function artemis2Fn(t, _time, _params) {
|
|
799
|
-
const a = 0.35,
|
|
800
|
-
|
|
817
|
+
const a = 0.35,
|
|
818
|
+
b = 0.15,
|
|
819
|
+
ox = 0.175;
|
|
820
|
+
const s = Math.sin(t),
|
|
821
|
+
c = Math.cos(t);
|
|
801
822
|
const denom = 1 + s * s;
|
|
802
823
|
return {
|
|
803
|
-
x: c * (1 + a * c) / denom - ox,
|
|
804
|
-
y: s * c * (1 + b * c) / denom
|
|
824
|
+
x: (c * (1 + a * c)) / denom - ox,
|
|
825
|
+
y: (s * c * (1 + b * c)) / denom,
|
|
805
826
|
};
|
|
806
827
|
}
|
|
807
828
|
var artemis2 = {
|
|
808
829
|
name: "Artemis II",
|
|
809
830
|
fn: artemis2Fn,
|
|
810
831
|
period: TWO_PI2,
|
|
811
|
-
speed: 0.7
|
|
832
|
+
speed: 0.7,
|
|
812
833
|
};
|
|
813
834
|
|
|
814
835
|
// src/curves/astroid.ts
|
|
@@ -818,14 +839,14 @@ function astroidFn(t, _time, _params) {
|
|
|
818
839
|
const s = Math.sin(t);
|
|
819
840
|
return {
|
|
820
841
|
x: c * c * c,
|
|
821
|
-
y: s * s * s
|
|
842
|
+
y: s * s * s,
|
|
822
843
|
};
|
|
823
844
|
}
|
|
824
845
|
var astroid = {
|
|
825
846
|
name: "Astroid",
|
|
826
847
|
fn: astroidFn,
|
|
827
848
|
period: TWO_PI3,
|
|
828
|
-
speed: 1.1
|
|
849
|
+
speed: 1.1,
|
|
829
850
|
};
|
|
830
851
|
|
|
831
852
|
// src/curves/deltoid.ts
|
|
@@ -833,14 +854,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
833
854
|
function deltoidFn(t, _time, _params) {
|
|
834
855
|
return {
|
|
835
856
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
836
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
857
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t),
|
|
837
858
|
};
|
|
838
859
|
}
|
|
839
860
|
var deltoid = {
|
|
840
861
|
name: "Deltoid",
|
|
841
862
|
fn: deltoidFn,
|
|
842
863
|
period: TWO_PI4,
|
|
843
|
-
speed: 0.9
|
|
864
|
+
speed: 0.9,
|
|
844
865
|
};
|
|
845
866
|
|
|
846
867
|
// src/curves/epicycloid3.ts
|
|
@@ -848,14 +869,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
848
869
|
function epicycloid3Fn(t, _time, _params) {
|
|
849
870
|
return {
|
|
850
871
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
851
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
872
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t),
|
|
852
873
|
};
|
|
853
874
|
}
|
|
854
875
|
var epicycloid3 = {
|
|
855
876
|
name: "Epicycloid (n=3)",
|
|
856
877
|
fn: epicycloid3Fn,
|
|
857
878
|
period: TWO_PI5,
|
|
858
|
-
speed: 0.75
|
|
879
|
+
speed: 0.75,
|
|
859
880
|
};
|
|
860
881
|
|
|
861
882
|
// src/curves/epitrochoid7.ts
|
|
@@ -864,14 +885,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
864
885
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
865
886
|
return {
|
|
866
887
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
867
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
888
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
868
889
|
};
|
|
869
890
|
}
|
|
870
891
|
function epitrochoid7SkeletonFn(t) {
|
|
871
892
|
const d = 1.275;
|
|
872
893
|
return {
|
|
873
894
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
874
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
895
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
875
896
|
};
|
|
876
897
|
}
|
|
877
898
|
var epitrochoid7 = {
|
|
@@ -879,7 +900,7 @@ var epitrochoid7 = {
|
|
|
879
900
|
fn: epitrochoid7Fn,
|
|
880
901
|
period: TWO_PI6,
|
|
881
902
|
speed: 1.4,
|
|
882
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
903
|
+
skeletonFn: epitrochoid7SkeletonFn,
|
|
883
904
|
};
|
|
884
905
|
|
|
885
906
|
// src/curves/lissajous32.ts
|
|
@@ -888,7 +909,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
888
909
|
const phi = time * 0.45;
|
|
889
910
|
return {
|
|
890
911
|
x: Math.sin(3 * t + phi),
|
|
891
|
-
y: Math.sin(2 * t)
|
|
912
|
+
y: Math.sin(2 * t),
|
|
892
913
|
};
|
|
893
914
|
}
|
|
894
915
|
var lissajous32 = {
|
|
@@ -896,7 +917,7 @@ var lissajous32 = {
|
|
|
896
917
|
fn: lissajous32Fn,
|
|
897
918
|
period: TWO_PI7,
|
|
898
919
|
speed: 2,
|
|
899
|
-
skeleton: "live"
|
|
920
|
+
skeleton: "live",
|
|
900
921
|
};
|
|
901
922
|
|
|
902
923
|
// src/curves/lissajous43.ts
|
|
@@ -905,7 +926,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
905
926
|
const phi = time * 0.38;
|
|
906
927
|
return {
|
|
907
928
|
x: Math.sin(4 * t + phi),
|
|
908
|
-
y: Math.sin(3 * t)
|
|
929
|
+
y: Math.sin(3 * t),
|
|
909
930
|
};
|
|
910
931
|
}
|
|
911
932
|
var lissajous43 = {
|
|
@@ -913,17 +934,18 @@ var lissajous43 = {
|
|
|
913
934
|
fn: lissajous43Fn,
|
|
914
935
|
period: TWO_PI8,
|
|
915
936
|
speed: 1.8,
|
|
916
|
-
skeleton: "live"
|
|
937
|
+
skeleton: "live",
|
|
917
938
|
};
|
|
918
939
|
|
|
919
940
|
// src/curves/lame.ts
|
|
920
941
|
var TWO_PI9 = Math.PI * 2;
|
|
921
942
|
function lameFn(t, time, _params) {
|
|
922
943
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
923
|
-
const c = Math.cos(t),
|
|
944
|
+
const c = Math.cos(t),
|
|
945
|
+
s = Math.sin(t);
|
|
924
946
|
return {
|
|
925
947
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
926
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
948
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p),
|
|
927
949
|
};
|
|
928
950
|
}
|
|
929
951
|
var lame = {
|
|
@@ -931,7 +953,7 @@ var lame = {
|
|
|
931
953
|
fn: lameFn,
|
|
932
954
|
period: TWO_PI9,
|
|
933
955
|
speed: 1,
|
|
934
|
-
skeleton: "live"
|
|
956
|
+
skeleton: "live",
|
|
935
957
|
};
|
|
936
958
|
|
|
937
959
|
// src/curves/rose3.ts
|
|
@@ -940,14 +962,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
940
962
|
const r = Math.cos(3 * t);
|
|
941
963
|
return {
|
|
942
964
|
x: r * Math.cos(t),
|
|
943
|
-
y: r * Math.sin(t)
|
|
965
|
+
y: r * Math.sin(t),
|
|
944
966
|
};
|
|
945
967
|
}
|
|
946
968
|
var rose3 = {
|
|
947
969
|
name: "Rose (n=3)",
|
|
948
970
|
fn: rose3Fn,
|
|
949
971
|
period: TWO_PI10,
|
|
950
|
-
speed: 1.15
|
|
972
|
+
speed: 1.15,
|
|
951
973
|
};
|
|
952
974
|
|
|
953
975
|
// src/curves/rose5.ts
|
|
@@ -956,14 +978,87 @@ function rose5Fn(t, _time, _params) {
|
|
|
956
978
|
const r = Math.cos(5 * t);
|
|
957
979
|
return {
|
|
958
980
|
x: r * Math.cos(t),
|
|
959
|
-
y: r * Math.sin(t)
|
|
981
|
+
y: r * Math.sin(t),
|
|
960
982
|
};
|
|
961
983
|
}
|
|
962
984
|
var rose5 = {
|
|
963
985
|
name: "Rose (n=5)",
|
|
964
986
|
fn: rose5Fn,
|
|
965
987
|
period: TWO_PI11,
|
|
966
|
-
speed: 1
|
|
988
|
+
speed: 1,
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
// src/curves/rose52.ts
|
|
992
|
+
var FOUR_PI = Math.PI * 4;
|
|
993
|
+
function rose52Fn(t, _time, _params) {
|
|
994
|
+
const r = Math.cos((5 / 2) * t);
|
|
995
|
+
return {
|
|
996
|
+
x: r * Math.cos(t),
|
|
997
|
+
y: r * Math.sin(t),
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
var rose52 = {
|
|
1001
|
+
name: "Rose (n=5/2)",
|
|
1002
|
+
fn: rose52Fn,
|
|
1003
|
+
period: FOUR_PI,
|
|
1004
|
+
speed: 0.8,
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
// src/curves/star.ts
|
|
1008
|
+
var TWO_PI12 = Math.PI * 2;
|
|
1009
|
+
function starFn(t, _time, _params) {
|
|
1010
|
+
const r =
|
|
1011
|
+
Math.abs(Math.cos((5 / 2) * t)) +
|
|
1012
|
+
0.35 * Math.abs(Math.cos((15 / 2) * t)) +
|
|
1013
|
+
0.15 * Math.abs(Math.cos((25 / 2) * t));
|
|
1014
|
+
return {
|
|
1015
|
+
x: r * Math.cos(t),
|
|
1016
|
+
y: r * Math.sin(t),
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
var star = {
|
|
1020
|
+
name: "Star",
|
|
1021
|
+
fn: starFn,
|
|
1022
|
+
period: TWO_PI12,
|
|
1023
|
+
speed: 1,
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
// src/curves/star4.ts
|
|
1027
|
+
var TWO_PI13 = Math.PI * 2;
|
|
1028
|
+
function star4Fn(t, _time, _params) {
|
|
1029
|
+
const r =
|
|
1030
|
+
Math.abs(Math.cos(2 * t)) +
|
|
1031
|
+
0.35 * Math.abs(Math.cos(6 * t)) +
|
|
1032
|
+
0.15 * Math.abs(Math.cos(10 * t));
|
|
1033
|
+
return {
|
|
1034
|
+
x: r * Math.cos(t),
|
|
1035
|
+
y: r * Math.sin(t),
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
var star4 = {
|
|
1039
|
+
name: "Star (4-arm)",
|
|
1040
|
+
fn: star4Fn,
|
|
1041
|
+
period: TWO_PI13,
|
|
1042
|
+
speed: 1,
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
// src/curves/star7.ts
|
|
1046
|
+
var TWO_PI14 = Math.PI * 2;
|
|
1047
|
+
function star7Fn(t, _time, _params) {
|
|
1048
|
+
const r =
|
|
1049
|
+
Math.abs(Math.cos((7 / 2) * t)) +
|
|
1050
|
+
0.35 * Math.abs(Math.cos((21 / 2) * t)) +
|
|
1051
|
+
0.15 * Math.abs(Math.cos((35 / 2) * t));
|
|
1052
|
+
return {
|
|
1053
|
+
x: r * Math.cos(t),
|
|
1054
|
+
y: r * Math.sin(t),
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
var star7 = {
|
|
1058
|
+
name: "Star (7-arm)",
|
|
1059
|
+
fn: star7Fn,
|
|
1060
|
+
period: TWO_PI14,
|
|
1061
|
+
speed: 1,
|
|
967
1062
|
};
|
|
968
1063
|
|
|
969
1064
|
// src/curves/index.ts
|
|
@@ -972,12 +1067,16 @@ var curves = {
|
|
|
972
1067
|
epitrochoid7,
|
|
973
1068
|
astroid,
|
|
974
1069
|
deltoid,
|
|
975
|
-
rose5,
|
|
976
1070
|
rose3,
|
|
1071
|
+
rose5,
|
|
1072
|
+
rose52,
|
|
1073
|
+
star,
|
|
1074
|
+
star4,
|
|
1075
|
+
star7,
|
|
977
1076
|
lissajous32,
|
|
978
1077
|
lissajous43,
|
|
979
1078
|
epicycloid3,
|
|
980
|
-
lame
|
|
1079
|
+
lame,
|
|
981
1080
|
};
|
|
982
1081
|
|
|
983
1082
|
// src/index.ts
|
|
@@ -994,8 +1093,7 @@ function parseTrailColor(value) {
|
|
|
994
1093
|
if (Array.isArray(parsed)) {
|
|
995
1094
|
return parsed;
|
|
996
1095
|
}
|
|
997
|
-
} catch {
|
|
998
|
-
}
|
|
1096
|
+
} catch {}
|
|
999
1097
|
return value;
|
|
1000
1098
|
}
|
|
1001
1099
|
function init() {
|
|
@@ -1010,16 +1108,16 @@ function init() {
|
|
|
1010
1108
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
1011
1109
|
}
|
|
1012
1110
|
const instance = createSarmal(canvas, curveDef, {
|
|
1013
|
-
...canvas.dataset.trailColor && {
|
|
1014
|
-
trailColor: parseTrailColor(canvas.dataset.trailColor)
|
|
1015
|
-
},
|
|
1016
|
-
...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
|
|
1017
|
-
...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
|
|
1018
|
-
...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
|
|
1019
|
-
...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) },
|
|
1020
|
-
...canvas.dataset.trailStyle && {
|
|
1021
|
-
trailStyle: canvas.dataset.trailStyle
|
|
1022
|
-
}
|
|
1111
|
+
...(canvas.dataset.trailColor && {
|
|
1112
|
+
trailColor: parseTrailColor(canvas.dataset.trailColor),
|
|
1113
|
+
}),
|
|
1114
|
+
...(canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor }),
|
|
1115
|
+
...(canvas.dataset.headColor && { headColor: canvas.dataset.headColor }),
|
|
1116
|
+
...(canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) }),
|
|
1117
|
+
...(canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) }),
|
|
1118
|
+
...(canvas.dataset.trailStyle && {
|
|
1119
|
+
trailStyle: canvas.dataset.trailStyle,
|
|
1120
|
+
}),
|
|
1023
1121
|
});
|
|
1024
1122
|
if (canvas.dataset.speed) {
|
|
1025
1123
|
instance.setSpeed(parseFloat(canvas.dataset.speed));
|
|
@@ -1036,4 +1134,4 @@ if (document.readyState === "loading") {
|
|
|
1036
1134
|
|
|
1037
1135
|
export { init };
|
|
1038
1136
|
//# sourceMappingURL=auto-init.js.map
|
|
1039
|
-
//# sourceMappingURL=auto-init.js.map
|
|
1137
|
+
//# sourceMappingURL=auto-init.js.map
|