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