@sarmal/core 0.15.0 → 0.15.1
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 +86 -94
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.d.cts +3 -1
- package/dist/auto-init.d.ts +3 -1
- package/dist/auto-init.js +85 -93
- 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 +78 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -66
- package/dist/index.d.ts +29 -66
- package/dist/index.js +78 -112
- package/dist/index.js.map +1 -1
- package/dist/types-BL9HhEmk.d.cts +246 -259
- package/dist/types-BL9HhEmk.d.ts +246 -259
- 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" ?
|
|
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,17 +366,17 @@ 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
372
|
function hexToRgb(hex) {
|
|
382
373
|
const n = parseInt(hex.slice(1), 16);
|
|
383
|
-
return { r: n >> 16, g:
|
|
374
|
+
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
384
375
|
}
|
|
385
376
|
var lerpRgb = (a, b, t) => ({
|
|
386
377
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
387
378
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
388
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
379
|
+
b: Math.round(a.b + (b.b - a.b) * t)
|
|
389
380
|
});
|
|
390
381
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
391
382
|
if (palette.length === 0) {
|
|
@@ -408,7 +399,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
408
399
|
"trailColor",
|
|
409
400
|
"headColor",
|
|
410
401
|
"skeletonColor",
|
|
411
|
-
"trailStyle"
|
|
402
|
+
"trailStyle"
|
|
412
403
|
]);
|
|
413
404
|
function validateRenderOptions(partial) {
|
|
414
405
|
for (const key of Object.keys(partial)) {
|
|
@@ -433,7 +424,7 @@ function assertTrailColor(value) {
|
|
|
433
424
|
if (typeof value === "string") {
|
|
434
425
|
if (!HEX_COLOR_RE.test(value)) {
|
|
435
426
|
throw new TypeError(
|
|
436
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"
|
|
427
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`
|
|
437
428
|
);
|
|
438
429
|
}
|
|
439
430
|
return;
|
|
@@ -441,21 +432,21 @@ function assertTrailColor(value) {
|
|
|
441
432
|
if (Array.isArray(value)) {
|
|
442
433
|
if (value.length < 2) {
|
|
443
434
|
throw new RangeError(
|
|
444
|
-
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}
|
|
435
|
+
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`
|
|
445
436
|
);
|
|
446
437
|
}
|
|
447
438
|
for (let i = 0; i < value.length; i++) {
|
|
448
439
|
const entry = value[i];
|
|
449
440
|
if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
|
|
450
441
|
throw new TypeError(
|
|
451
|
-
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}
|
|
442
|
+
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`
|
|
452
443
|
);
|
|
453
444
|
}
|
|
454
445
|
}
|
|
455
446
|
return;
|
|
456
447
|
}
|
|
457
448
|
throw new TypeError(
|
|
458
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}
|
|
449
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`
|
|
459
450
|
);
|
|
460
451
|
}
|
|
461
452
|
function assertHeadColor(value) {
|
|
@@ -464,7 +455,7 @@ function assertHeadColor(value) {
|
|
|
464
455
|
}
|
|
465
456
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
466
457
|
throw new TypeError(
|
|
467
|
-
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}
|
|
458
|
+
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`
|
|
468
459
|
);
|
|
469
460
|
}
|
|
470
461
|
}
|
|
@@ -474,14 +465,14 @@ function assertSkeletonColor(value) {
|
|
|
474
465
|
}
|
|
475
466
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
476
467
|
throw new TypeError(
|
|
477
|
-
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}
|
|
468
|
+
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`
|
|
478
469
|
);
|
|
479
470
|
}
|
|
480
471
|
}
|
|
481
472
|
function assertTrailStyle(value) {
|
|
482
473
|
if (!TRAIL_STYLES.includes(value)) {
|
|
483
474
|
throw new RangeError(
|
|
484
|
-
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}
|
|
475
|
+
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`
|
|
485
476
|
);
|
|
486
477
|
}
|
|
487
478
|
}
|
|
@@ -503,22 +494,23 @@ function resolveHeadColor(trailColor, trailStyle) {
|
|
|
503
494
|
function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
504
495
|
if (trailStyle === "default" && Array.isArray(trailColor)) {
|
|
505
496
|
console.warn(
|
|
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.'
|
|
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.'
|
|
507
498
|
);
|
|
508
499
|
return;
|
|
509
500
|
}
|
|
510
501
|
if (trailStyle !== "default" && typeof trailColor === "string") {
|
|
511
502
|
console.warn(
|
|
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
|
|
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.`
|
|
513
504
|
);
|
|
514
505
|
}
|
|
515
506
|
}
|
|
507
|
+
var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160));
|
|
516
508
|
|
|
517
509
|
// src/renderer.ts
|
|
518
510
|
var WHITE_HEX = "#ffffff";
|
|
519
511
|
function hexToRgbComponents(hex) {
|
|
520
512
|
const n = parseInt(hex.slice(1), 16);
|
|
521
|
-
return `${n >> 16},${
|
|
513
|
+
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
522
514
|
}
|
|
523
515
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
524
516
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -543,9 +535,8 @@ function createRenderer(options) {
|
|
|
543
535
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
544
536
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
545
537
|
function setupCanvas() {
|
|
546
|
-
const
|
|
547
|
-
const
|
|
548
|
-
const lh = rect.height || 200;
|
|
538
|
+
const lw = canvas.offsetWidth || 200;
|
|
539
|
+
const lh = canvas.offsetHeight || 200;
|
|
549
540
|
applyDprSizing(canvas, lw, lh, dpr);
|
|
550
541
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
551
542
|
}
|
|
@@ -643,7 +634,7 @@ function createRenderer(options) {
|
|
|
643
634
|
i,
|
|
644
635
|
trailCount,
|
|
645
636
|
toX,
|
|
646
|
-
toY
|
|
637
|
+
toY
|
|
647
638
|
);
|
|
648
639
|
if (trailStyle === "default") {
|
|
649
640
|
ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
|
|
@@ -667,8 +658,7 @@ function createRenderer(options) {
|
|
|
667
658
|
}
|
|
668
659
|
const x = head.x * scale + offsetX;
|
|
669
660
|
const y = head.y * scale + offsetY;
|
|
670
|
-
const r =
|
|
671
|
-
options.headRadius ?? Math.max(2, 3 * Math.sqrt(Math.min(logicalWidth, logicalHeight) / 160));
|
|
661
|
+
const r = options.headRadius ?? getHeadDotRadius(logicalWidth, logicalHeight);
|
|
672
662
|
ctx.fillStyle = headColor;
|
|
673
663
|
ctx.beginPath();
|
|
674
664
|
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
@@ -797,7 +787,7 @@ function createRenderer(options) {
|
|
|
797
787
|
if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
|
|
798
788
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
799
789
|
}
|
|
800
|
-
}
|
|
790
|
+
}
|
|
801
791
|
};
|
|
802
792
|
if (shouldAutoStart) {
|
|
803
793
|
instance.play();
|
|
@@ -808,22 +798,19 @@ function createRenderer(options) {
|
|
|
808
798
|
// src/curves/artemis2.ts
|
|
809
799
|
var TWO_PI2 = Math.PI * 2;
|
|
810
800
|
function artemis2Fn(t, _time, _params) {
|
|
811
|
-
const a = 0.35,
|
|
812
|
-
|
|
813
|
-
ox = 0.175;
|
|
814
|
-
const s = Math.sin(t),
|
|
815
|
-
c = Math.cos(t);
|
|
801
|
+
const a = 0.35, b = 0.15, ox = 0.175;
|
|
802
|
+
const s = Math.sin(t), c = Math.cos(t);
|
|
816
803
|
const denom = 1 + s * s;
|
|
817
804
|
return {
|
|
818
|
-
x:
|
|
819
|
-
y:
|
|
805
|
+
x: c * (1 + a * c) / denom - ox,
|
|
806
|
+
y: s * c * (1 + b * c) / denom
|
|
820
807
|
};
|
|
821
808
|
}
|
|
822
809
|
var artemis2 = {
|
|
823
810
|
name: "Artemis II",
|
|
824
811
|
fn: artemis2Fn,
|
|
825
812
|
period: TWO_PI2,
|
|
826
|
-
speed: 0.7
|
|
813
|
+
speed: 0.7
|
|
827
814
|
};
|
|
828
815
|
|
|
829
816
|
// src/curves/astroid.ts
|
|
@@ -833,14 +820,14 @@ function astroidFn(t, _time, _params) {
|
|
|
833
820
|
const s = Math.sin(t);
|
|
834
821
|
return {
|
|
835
822
|
x: c * c * c,
|
|
836
|
-
y: s * s * s
|
|
823
|
+
y: s * s * s
|
|
837
824
|
};
|
|
838
825
|
}
|
|
839
826
|
var astroid = {
|
|
840
827
|
name: "Astroid",
|
|
841
828
|
fn: astroidFn,
|
|
842
829
|
period: TWO_PI3,
|
|
843
|
-
speed: 1.1
|
|
830
|
+
speed: 1.1
|
|
844
831
|
};
|
|
845
832
|
|
|
846
833
|
// src/curves/deltoid.ts
|
|
@@ -848,14 +835,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
848
835
|
function deltoidFn(t, _time, _params) {
|
|
849
836
|
return {
|
|
850
837
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
851
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
838
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
852
839
|
};
|
|
853
840
|
}
|
|
854
841
|
var deltoid = {
|
|
855
842
|
name: "Deltoid",
|
|
856
843
|
fn: deltoidFn,
|
|
857
844
|
period: TWO_PI4,
|
|
858
|
-
speed: 0.9
|
|
845
|
+
speed: 0.9
|
|
859
846
|
};
|
|
860
847
|
|
|
861
848
|
// src/curves/epicycloid3.ts
|
|
@@ -863,14 +850,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
863
850
|
function epicycloid3Fn(t, _time, _params) {
|
|
864
851
|
return {
|
|
865
852
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
866
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
853
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
867
854
|
};
|
|
868
855
|
}
|
|
869
856
|
var epicycloid3 = {
|
|
870
857
|
name: "Epicycloid (n=3)",
|
|
871
858
|
fn: epicycloid3Fn,
|
|
872
859
|
period: TWO_PI5,
|
|
873
|
-
speed: 0.75
|
|
860
|
+
speed: 0.75
|
|
874
861
|
};
|
|
875
862
|
|
|
876
863
|
// src/curves/epitrochoid7.ts
|
|
@@ -879,14 +866,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
879
866
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
880
867
|
return {
|
|
881
868
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
882
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
869
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
883
870
|
};
|
|
884
871
|
}
|
|
885
872
|
function epitrochoid7SkeletonFn(t) {
|
|
886
873
|
const d = 1.275;
|
|
887
874
|
return {
|
|
888
875
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
889
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
876
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
890
877
|
};
|
|
891
878
|
}
|
|
892
879
|
var epitrochoid7 = {
|
|
@@ -894,7 +881,7 @@ var epitrochoid7 = {
|
|
|
894
881
|
fn: epitrochoid7Fn,
|
|
895
882
|
period: TWO_PI6,
|
|
896
883
|
speed: 1.4,
|
|
897
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
884
|
+
skeletonFn: epitrochoid7SkeletonFn
|
|
898
885
|
};
|
|
899
886
|
|
|
900
887
|
// src/curves/lissajous32.ts
|
|
@@ -903,7 +890,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
903
890
|
const phi = time * 0.45;
|
|
904
891
|
return {
|
|
905
892
|
x: Math.sin(3 * t + phi),
|
|
906
|
-
y: Math.sin(2 * t)
|
|
893
|
+
y: Math.sin(2 * t)
|
|
907
894
|
};
|
|
908
895
|
}
|
|
909
896
|
var lissajous32 = {
|
|
@@ -911,7 +898,7 @@ var lissajous32 = {
|
|
|
911
898
|
fn: lissajous32Fn,
|
|
912
899
|
period: TWO_PI7,
|
|
913
900
|
speed: 2,
|
|
914
|
-
skeleton: "live"
|
|
901
|
+
skeleton: "live"
|
|
915
902
|
};
|
|
916
903
|
|
|
917
904
|
// src/curves/lissajous43.ts
|
|
@@ -920,7 +907,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
920
907
|
const phi = time * 0.38;
|
|
921
908
|
return {
|
|
922
909
|
x: Math.sin(4 * t + phi),
|
|
923
|
-
y: Math.sin(3 * t)
|
|
910
|
+
y: Math.sin(3 * t)
|
|
924
911
|
};
|
|
925
912
|
}
|
|
926
913
|
var lissajous43 = {
|
|
@@ -928,18 +915,17 @@ var lissajous43 = {
|
|
|
928
915
|
fn: lissajous43Fn,
|
|
929
916
|
period: TWO_PI8,
|
|
930
917
|
speed: 1.8,
|
|
931
|
-
skeleton: "live"
|
|
918
|
+
skeleton: "live"
|
|
932
919
|
};
|
|
933
920
|
|
|
934
921
|
// src/curves/lame.ts
|
|
935
922
|
var TWO_PI9 = Math.PI * 2;
|
|
936
923
|
function lameFn(t, time, _params) {
|
|
937
924
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
938
|
-
const c = Math.cos(t),
|
|
939
|
-
s = Math.sin(t);
|
|
925
|
+
const c = Math.cos(t), s = Math.sin(t);
|
|
940
926
|
return {
|
|
941
927
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
942
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
928
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
943
929
|
};
|
|
944
930
|
}
|
|
945
931
|
var lame = {
|
|
@@ -947,7 +933,7 @@ var lame = {
|
|
|
947
933
|
fn: lameFn,
|
|
948
934
|
period: TWO_PI9,
|
|
949
935
|
speed: 1,
|
|
950
|
-
skeleton: "live"
|
|
936
|
+
skeleton: "live"
|
|
951
937
|
};
|
|
952
938
|
|
|
953
939
|
// src/curves/rose3.ts
|
|
@@ -956,14 +942,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
956
942
|
const r = Math.cos(3 * t);
|
|
957
943
|
return {
|
|
958
944
|
x: r * Math.cos(t),
|
|
959
|
-
y: r * Math.sin(t)
|
|
945
|
+
y: r * Math.sin(t)
|
|
960
946
|
};
|
|
961
947
|
}
|
|
962
948
|
var rose3 = {
|
|
963
949
|
name: "Rose (n=3)",
|
|
964
950
|
fn: rose3Fn,
|
|
965
951
|
period: TWO_PI10,
|
|
966
|
-
speed: 1.15
|
|
952
|
+
speed: 1.15
|
|
967
953
|
};
|
|
968
954
|
|
|
969
955
|
// src/curves/rose5.ts
|
|
@@ -972,14 +958,14 @@ function rose5Fn(t, _time, _params) {
|
|
|
972
958
|
const r = Math.cos(5 * t);
|
|
973
959
|
return {
|
|
974
960
|
x: r * Math.cos(t),
|
|
975
|
-
y: r * Math.sin(t)
|
|
961
|
+
y: r * Math.sin(t)
|
|
976
962
|
};
|
|
977
963
|
}
|
|
978
964
|
var rose5 = {
|
|
979
965
|
name: "Rose (n=5)",
|
|
980
966
|
fn: rose5Fn,
|
|
981
967
|
period: TWO_PI11,
|
|
982
|
-
speed: 1
|
|
968
|
+
speed: 1
|
|
983
969
|
};
|
|
984
970
|
|
|
985
971
|
// src/curves/index.ts
|
|
@@ -993,7 +979,7 @@ var curves = {
|
|
|
993
979
|
lissajous32,
|
|
994
980
|
lissajous43,
|
|
995
981
|
epicycloid3,
|
|
996
|
-
lame
|
|
982
|
+
lame
|
|
997
983
|
};
|
|
998
984
|
|
|
999
985
|
// src/index.ts
|
|
@@ -1010,7 +996,8 @@ function parseTrailColor(value) {
|
|
|
1010
996
|
if (Array.isArray(parsed)) {
|
|
1011
997
|
return parsed;
|
|
1012
998
|
}
|
|
1013
|
-
} catch {
|
|
999
|
+
} catch {
|
|
1000
|
+
}
|
|
1014
1001
|
return value;
|
|
1015
1002
|
}
|
|
1016
1003
|
function init() {
|
|
@@ -1024,18 +1011,21 @@ function init() {
|
|
|
1024
1011
|
if (!curveDef) {
|
|
1025
1012
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
1026
1013
|
}
|
|
1027
|
-
createSarmal(canvas, curveDef, {
|
|
1028
|
-
...
|
|
1029
|
-
trailColor: parseTrailColor(canvas.dataset.trailColor)
|
|
1030
|
-
}
|
|
1031
|
-
...
|
|
1032
|
-
...
|
|
1033
|
-
...
|
|
1034
|
-
...
|
|
1035
|
-
...
|
|
1036
|
-
trailStyle: canvas.dataset.trailStyle
|
|
1037
|
-
}
|
|
1014
|
+
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
|
+
}
|
|
1038
1025
|
});
|
|
1026
|
+
if (canvas.dataset.speed) {
|
|
1027
|
+
instance.setSpeed(parseFloat(canvas.dataset.speed));
|
|
1028
|
+
}
|
|
1039
1029
|
});
|
|
1040
1030
|
}
|
|
1041
1031
|
if (document.readyState === "loading") {
|
|
@@ -1045,5 +1035,7 @@ if (document.readyState === "loading") {
|
|
|
1045
1035
|
} else {
|
|
1046
1036
|
requestAnimationFrame(init);
|
|
1047
1037
|
}
|
|
1038
|
+
|
|
1039
|
+
exports.init = init;
|
|
1048
1040
|
//# sourceMappingURL=auto-init.cjs.map
|
|
1049
|
-
//# sourceMappingURL=auto-init.cjs.map
|
|
1041
|
+
//# sourceMappingURL=auto-init.cjs.map
|