@sarmal/core 0.17.1 → 0.18.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 +113 -89
- package/dist/auto-init.cjs.map +1 -1
- package/dist/auto-init.js +112 -88
- 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 +53 -40
- package/dist/curves/index.d.cts +29 -29
- package/dist/curves/index.d.ts +29 -29
- package/dist/curves/index.js +69 -40
- 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 +5 -5
- package/dist/curves/rose52.d.cts +1 -1
- package/dist/curves/rose52.d.ts +1 -1
- package/dist/curves/rose52.js +4 -4
- package/dist/curves/star.cjs +8 -5
- package/dist/curves/star.d.cts +1 -1
- package/dist/curves/star.d.ts +1 -1
- package/dist/curves/star.js +7 -4
- package/dist/curves/star4.cjs +8 -5
- package/dist/curves/star4.d.cts +1 -1
- package/dist/curves/star4.d.ts +1 -1
- package/dist/curves/star4.js +7 -4
- package/dist/curves/star7.cjs +8 -5
- package/dist/curves/star7.d.cts +1 -1
- package/dist/curves/star7.d.ts +1 -1
- package/dist/curves/star7.js +7 -4
- package/dist/index.cjs +125 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -35
- package/dist/index.d.ts +74 -35
- package/dist/index.js +143 -93
- package/dist/index.js.map +1 -1
- package/dist/types-frtEoAq6.d.cts +317 -0
- package/dist/types-frtEoAq6.d.ts +317 -0
- package/package.json +1 -1
- package/dist/types-BL9HhEmk.d.cts +0 -299
- package/dist/types-BL9HhEmk.d.ts +0 -299
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 {
|
|
@@ -120,6 +120,9 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
120
120
|
get trailCount() {
|
|
121
121
|
return trail.length;
|
|
122
122
|
},
|
|
123
|
+
get trailLength() {
|
|
124
|
+
return trailLength;
|
|
125
|
+
},
|
|
123
126
|
get isLiveSkeleton() {
|
|
124
127
|
return curve.skeleton === "live";
|
|
125
128
|
},
|
|
@@ -132,14 +135,14 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
132
135
|
trail.clear();
|
|
133
136
|
},
|
|
134
137
|
jump(newT, { clearTrail = false } = {}) {
|
|
135
|
-
t = (newT % curve.period + curve.period) % curve.period;
|
|
138
|
+
t = ((newT % curve.period) + curve.period) % curve.period;
|
|
136
139
|
if (clearTrail) {
|
|
137
140
|
trail.clear();
|
|
138
141
|
}
|
|
139
142
|
},
|
|
140
143
|
seek(targetT, { wrap = false, step = curve.period / trailLength } = {}) {
|
|
141
144
|
const advance = curve.speed * step;
|
|
142
|
-
const target = (targetT % curve.period + curve.period) % curve.period;
|
|
145
|
+
const target = ((targetT % curve.period) + curve.period) % curve.period;
|
|
143
146
|
const targetTime = target / curve.speed;
|
|
144
147
|
t = target;
|
|
145
148
|
actualTime = targetTime;
|
|
@@ -148,7 +151,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
148
151
|
const count = wrap ? trailLength : Math.min(trailLength, pointsFromStart);
|
|
149
152
|
for (let i = count - 1; i >= 0; i--) {
|
|
150
153
|
const sampleT = target - i * advance;
|
|
151
|
-
const wrappedT = (sampleT % curve.period + curve.period) % curve.period;
|
|
154
|
+
const wrappedT = ((sampleT % curve.period) + curve.period) % curve.period;
|
|
152
155
|
const time = targetTime - i * step;
|
|
153
156
|
const point = curve.fn(wrappedT, time, EMPTY_PARAMS);
|
|
154
157
|
trail.push(point.x, point.y);
|
|
@@ -165,13 +168,16 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
165
168
|
...frozenB,
|
|
166
169
|
fn: (sampleT, time, params) => {
|
|
167
170
|
const a = frozenA.fn(sampleT, time, params);
|
|
168
|
-
const tB =
|
|
171
|
+
const tB =
|
|
172
|
+
frozenStrategy === "normalized"
|
|
173
|
+
? (sampleT / frozenA.period) * frozenB.period
|
|
174
|
+
: sampleT;
|
|
169
175
|
const b = frozenB.fn(tB, time, params);
|
|
170
176
|
return {
|
|
171
177
|
x: a.x + (b.x - a.x) * frozenAlpha,
|
|
172
|
-
y: a.y + (b.y - a.y) * frozenAlpha
|
|
178
|
+
y: a.y + (b.y - a.y) * frozenAlpha,
|
|
173
179
|
};
|
|
174
|
-
}
|
|
180
|
+
},
|
|
175
181
|
};
|
|
176
182
|
}
|
|
177
183
|
_morphStrategy = strategy;
|
|
@@ -184,7 +190,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
184
190
|
completeMorph() {
|
|
185
191
|
if (morphCurveB !== null) {
|
|
186
192
|
if (_morphStrategy === "normalized" && curve.period !== morphCurveB.period) {
|
|
187
|
-
t = t / curve.period * morphCurveB.period;
|
|
193
|
+
t = (t / curve.period) * morphCurveB.period;
|
|
188
194
|
}
|
|
189
195
|
curve = morphCurveB;
|
|
190
196
|
}
|
|
@@ -196,19 +202,22 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
196
202
|
const points = new Array(steps);
|
|
197
203
|
if (morphCurveB !== null && _morphAlpha !== null) {
|
|
198
204
|
for (let i = 0; i < steps; i++) {
|
|
199
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
205
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
200
206
|
const a = sampleSkeleton(curve, sampleT);
|
|
201
|
-
const tB =
|
|
207
|
+
const tB =
|
|
208
|
+
_morphStrategy === "normalized"
|
|
209
|
+
? (sampleT / curve.period) * morphCurveB.period
|
|
210
|
+
: sampleT;
|
|
202
211
|
const b = sampleSkeleton(morphCurveB, tB);
|
|
203
212
|
points[i] = {
|
|
204
213
|
x: a.x + (b.x - a.x) * _morphAlpha,
|
|
205
|
-
y: a.y + (b.y - a.y) * _morphAlpha
|
|
214
|
+
y: a.y + (b.y - a.y) * _morphAlpha,
|
|
206
215
|
};
|
|
207
216
|
}
|
|
208
217
|
return points;
|
|
209
218
|
}
|
|
210
219
|
for (let i = 0; i < steps; i++) {
|
|
211
|
-
const sampleT = i / (steps - 1) * curve.period;
|
|
220
|
+
const sampleT = (i / (steps - 1)) * curve.period;
|
|
212
221
|
points[i] = sampleSkeleton(curve, sampleT);
|
|
213
222
|
}
|
|
214
223
|
return points;
|
|
@@ -250,7 +259,7 @@ function createEngine(curveDef, trailLength = 120) {
|
|
|
250
259
|
_speedTransition.reject(new Error("Speed transition cancelled"));
|
|
251
260
|
_speedTransition = null;
|
|
252
261
|
}
|
|
253
|
-
}
|
|
262
|
+
},
|
|
254
263
|
};
|
|
255
264
|
}
|
|
256
265
|
|
|
@@ -313,13 +322,16 @@ function computeTrailQuad(trail, i, trailCount, toX, toY) {
|
|
|
313
322
|
r1x: nx - n1.x * w1,
|
|
314
323
|
r1y: ny - n1.y * w1,
|
|
315
324
|
opacity,
|
|
316
|
-
progress
|
|
325
|
+
progress,
|
|
317
326
|
};
|
|
318
327
|
}
|
|
319
328
|
function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
320
329
|
if (pts.length === 0) return null;
|
|
321
330
|
const first = pts[0];
|
|
322
|
-
let minX = first.x,
|
|
331
|
+
let minX = first.x,
|
|
332
|
+
maxX = first.x,
|
|
333
|
+
minY = first.y,
|
|
334
|
+
maxY = first.y;
|
|
323
335
|
for (const p of pts) {
|
|
324
336
|
if (p.x < minX) {
|
|
325
337
|
minX = p.x;
|
|
@@ -338,7 +350,7 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
338
350
|
const h = maxY - minY;
|
|
339
351
|
if (w === 0 && h === 0) {
|
|
340
352
|
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."
|
|
353
|
+
"[sarmal] Degenerate curve: all skeleton points are identical. Check that your curve fn returns distinct points for different values of t.",
|
|
342
354
|
);
|
|
343
355
|
}
|
|
344
356
|
const scaleXProportional = logicalWidth / (w * (1 + FIT_PADDING * 2));
|
|
@@ -349,12 +361,12 @@ function computeBoundaries(pts, logicalWidth, logicalHeight) {
|
|
|
349
361
|
scaleXProportional,
|
|
350
362
|
scaleYProportional,
|
|
351
363
|
scaleXMinPadding,
|
|
352
|
-
scaleYMinPadding
|
|
364
|
+
scaleYMinPadding,
|
|
353
365
|
);
|
|
354
366
|
return {
|
|
355
367
|
scale,
|
|
356
368
|
offsetX: (logicalWidth - w * scale) / 2 - minX * scale,
|
|
357
|
-
offsetY: (logicalHeight - h * scale) / 2 - minY * scale
|
|
369
|
+
offsetY: (logicalHeight - h * scale) / 2 - minY * scale,
|
|
358
370
|
};
|
|
359
371
|
}
|
|
360
372
|
function enginePassthroughs(engine) {
|
|
@@ -364,17 +376,17 @@ function enginePassthroughs(engine) {
|
|
|
364
376
|
setSpeed: engine.setSpeed,
|
|
365
377
|
getSpeed: engine.getSpeed,
|
|
366
378
|
resetSpeed: engine.resetSpeed,
|
|
367
|
-
setSpeedOver: engine.setSpeedOver
|
|
379
|
+
setSpeedOver: engine.setSpeedOver,
|
|
368
380
|
};
|
|
369
381
|
}
|
|
370
382
|
function hexToRgb(hex) {
|
|
371
383
|
const n = parseInt(hex.slice(1), 16);
|
|
372
|
-
return { r: n >> 16, g: n >> 8 & 255, b: n & 255 };
|
|
384
|
+
return { r: n >> 16, g: (n >> 8) & 255, b: n & 255 };
|
|
373
385
|
}
|
|
374
386
|
var lerpRgb = (a, b, t) => ({
|
|
375
387
|
r: Math.round(a.r + (b.r - a.r) * t),
|
|
376
388
|
g: Math.round(a.g + (b.g - a.g) * t),
|
|
377
|
-
b: Math.round(a.b + (b.b - a.b) * t)
|
|
389
|
+
b: Math.round(a.b + (b.b - a.b) * t),
|
|
378
390
|
});
|
|
379
391
|
function getPaletteColor(palette, position, timeOffset = 0) {
|
|
380
392
|
if (palette.length === 0) {
|
|
@@ -383,7 +395,7 @@ function getPaletteColor(palette, position, timeOffset = 0) {
|
|
|
383
395
|
if (palette.length === 1) {
|
|
384
396
|
return hexToRgb(palette[0]);
|
|
385
397
|
}
|
|
386
|
-
const cyclePos = (position + timeOffset) % 1;
|
|
398
|
+
const cyclePos = (((position + timeOffset) % 1) + 1) % 1;
|
|
387
399
|
const scaled = cyclePos * palette.length;
|
|
388
400
|
const idx = Math.floor(scaled);
|
|
389
401
|
const t = scaled - idx;
|
|
@@ -397,7 +409,7 @@ var RENDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
397
409
|
"trailColor",
|
|
398
410
|
"headColor",
|
|
399
411
|
"skeletonColor",
|
|
400
|
-
"trailStyle"
|
|
412
|
+
"trailStyle",
|
|
401
413
|
]);
|
|
402
414
|
function validateRenderOptions(partial) {
|
|
403
415
|
for (const key of Object.keys(partial)) {
|
|
@@ -422,7 +434,7 @@ function assertTrailColor(value) {
|
|
|
422
434
|
if (typeof value === "string") {
|
|
423
435
|
if (!HEX_COLOR_RE.test(value)) {
|
|
424
436
|
throw new TypeError(
|
|
425
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"
|
|
437
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string, got "${value}"`,
|
|
426
438
|
);
|
|
427
439
|
}
|
|
428
440
|
return;
|
|
@@ -430,21 +442,21 @@ function assertTrailColor(value) {
|
|
|
430
442
|
if (Array.isArray(value)) {
|
|
431
443
|
if (value.length < 2) {
|
|
432
444
|
throw new RangeError(
|
|
433
|
-
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}
|
|
445
|
+
`[sarmal] setRenderOptions: trailColor array must have at least 2 entries, got ${value.length}`,
|
|
434
446
|
);
|
|
435
447
|
}
|
|
436
448
|
for (let i = 0; i < value.length; i++) {
|
|
437
449
|
const entry = value[i];
|
|
438
450
|
if (typeof entry !== "string" || !HEX_COLOR_RE.test(entry)) {
|
|
439
451
|
throw new TypeError(
|
|
440
|
-
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}
|
|
452
|
+
`[sarmal] setRenderOptions: trailColor[${i}] must be a 6-digit hex string, got ${JSON.stringify(entry)}`,
|
|
441
453
|
);
|
|
442
454
|
}
|
|
443
455
|
}
|
|
444
456
|
return;
|
|
445
457
|
}
|
|
446
458
|
throw new TypeError(
|
|
447
|
-
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}
|
|
459
|
+
`[sarmal] setRenderOptions: trailColor must be a 6-digit hex string or an array of hex strings, got ${JSON.stringify(value)}`,
|
|
448
460
|
);
|
|
449
461
|
}
|
|
450
462
|
function assertHeadColor(value) {
|
|
@@ -453,7 +465,7 @@ function assertHeadColor(value) {
|
|
|
453
465
|
}
|
|
454
466
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
455
467
|
throw new TypeError(
|
|
456
|
-
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}
|
|
468
|
+
`[sarmal] setRenderOptions: headColor must be a 6-digit hex string or null, got ${JSON.stringify(value)}`,
|
|
457
469
|
);
|
|
458
470
|
}
|
|
459
471
|
}
|
|
@@ -463,14 +475,14 @@ function assertSkeletonColor(value) {
|
|
|
463
475
|
}
|
|
464
476
|
if (typeof value !== "string" || !HEX_COLOR_RE.test(value)) {
|
|
465
477
|
throw new TypeError(
|
|
466
|
-
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}
|
|
478
|
+
`[sarmal] setRenderOptions: skeletonColor must be a 6-digit hex string or "transparent", got ${JSON.stringify(value)}`,
|
|
467
479
|
);
|
|
468
480
|
}
|
|
469
481
|
}
|
|
470
482
|
function assertTrailStyle(value) {
|
|
471
483
|
if (!TRAIL_STYLES.includes(value)) {
|
|
472
484
|
throw new RangeError(
|
|
473
|
-
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}
|
|
485
|
+
`[sarmal] setRenderOptions: trailStyle must be one of "default", "gradient-static", "gradient-animated", got ${JSON.stringify(value)}`,
|
|
474
486
|
);
|
|
475
487
|
}
|
|
476
488
|
}
|
|
@@ -492,13 +504,13 @@ function resolveHeadColor(trailColor, trailStyle) {
|
|
|
492
504
|
function warnIfTrailColorMismatch(trailColor, trailStyle) {
|
|
493
505
|
if (trailStyle === "default" && Array.isArray(trailColor)) {
|
|
494
506
|
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.'
|
|
507
|
+
'[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
508
|
);
|
|
497
509
|
return;
|
|
498
510
|
}
|
|
499
511
|
if (trailStyle !== "default" && typeof trailColor === "string") {
|
|
500
512
|
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
|
|
513
|
+
`[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
514
|
);
|
|
503
515
|
}
|
|
504
516
|
}
|
|
@@ -508,7 +520,7 @@ var getHeadDotRadius = (w, h) => Math.max(1, 3 * Math.sqrt(Math.min(w, h) / 160)
|
|
|
508
520
|
var WHITE_HEX = "#ffffff";
|
|
509
521
|
function hexToRgbComponents(hex) {
|
|
510
522
|
const n = parseInt(hex.slice(1), 16);
|
|
511
|
-
return `${n >> 16},${n >> 8 & 255},${n & 255}`;
|
|
523
|
+
return `${n >> 16},${(n >> 8) & 255},${n & 255}`;
|
|
512
524
|
}
|
|
513
525
|
function applyDprSizing(target, logicalWidth, logicalHeight, dpr) {
|
|
514
526
|
target.style.width = `${logicalWidth}px`;
|
|
@@ -633,7 +645,7 @@ function createRenderer(options) {
|
|
|
633
645
|
i,
|
|
634
646
|
trailCount,
|
|
635
647
|
toX,
|
|
636
|
-
toY
|
|
648
|
+
toY,
|
|
637
649
|
);
|
|
638
650
|
if (trailStyle === "default") {
|
|
639
651
|
ctx.fillStyle = `rgba(${trailSolidRgb},${opacity})`;
|
|
@@ -794,7 +806,7 @@ function createRenderer(options) {
|
|
|
794
806
|
if (partial.trailColor !== void 0 || partial.trailStyle !== void 0) {
|
|
795
807
|
warnIfTrailColorMismatch(trailColor, trailStyle);
|
|
796
808
|
}
|
|
797
|
-
}
|
|
809
|
+
},
|
|
798
810
|
};
|
|
799
811
|
if (shouldAutoStart) {
|
|
800
812
|
instance.play();
|
|
@@ -805,19 +817,22 @@ function createRenderer(options) {
|
|
|
805
817
|
// src/curves/artemis2.ts
|
|
806
818
|
var TWO_PI2 = Math.PI * 2;
|
|
807
819
|
function artemis2Fn(t, _time, _params) {
|
|
808
|
-
const a = 0.35,
|
|
809
|
-
|
|
820
|
+
const a = 0.35,
|
|
821
|
+
b = 0.15,
|
|
822
|
+
ox = 0.175;
|
|
823
|
+
const s = Math.sin(t),
|
|
824
|
+
c = Math.cos(t);
|
|
810
825
|
const denom = 1 + s * s;
|
|
811
826
|
return {
|
|
812
|
-
x: c * (1 + a * c) / denom - ox,
|
|
813
|
-
y: s * c * (1 + b * c) / denom
|
|
827
|
+
x: (c * (1 + a * c)) / denom - ox,
|
|
828
|
+
y: (s * c * (1 + b * c)) / denom,
|
|
814
829
|
};
|
|
815
830
|
}
|
|
816
831
|
var artemis2 = {
|
|
817
832
|
name: "Artemis II",
|
|
818
833
|
fn: artemis2Fn,
|
|
819
834
|
period: TWO_PI2,
|
|
820
|
-
speed: 0.7
|
|
835
|
+
speed: 0.7,
|
|
821
836
|
};
|
|
822
837
|
|
|
823
838
|
// src/curves/astroid.ts
|
|
@@ -827,14 +842,14 @@ function astroidFn(t, _time, _params) {
|
|
|
827
842
|
const s = Math.sin(t);
|
|
828
843
|
return {
|
|
829
844
|
x: c * c * c,
|
|
830
|
-
y: s * s * s
|
|
845
|
+
y: s * s * s,
|
|
831
846
|
};
|
|
832
847
|
}
|
|
833
848
|
var astroid = {
|
|
834
849
|
name: "Astroid",
|
|
835
850
|
fn: astroidFn,
|
|
836
851
|
period: TWO_PI3,
|
|
837
|
-
speed: 1.1
|
|
852
|
+
speed: 1.1,
|
|
838
853
|
};
|
|
839
854
|
|
|
840
855
|
// src/curves/deltoid.ts
|
|
@@ -842,14 +857,14 @@ var TWO_PI4 = Math.PI * 2;
|
|
|
842
857
|
function deltoidFn(t, _time, _params) {
|
|
843
858
|
return {
|
|
844
859
|
x: 2 * Math.cos(t) + Math.cos(2 * t),
|
|
845
|
-
y: 2 * Math.sin(t) - Math.sin(2 * t)
|
|
860
|
+
y: 2 * Math.sin(t) - Math.sin(2 * t),
|
|
846
861
|
};
|
|
847
862
|
}
|
|
848
863
|
var deltoid = {
|
|
849
864
|
name: "Deltoid",
|
|
850
865
|
fn: deltoidFn,
|
|
851
866
|
period: TWO_PI4,
|
|
852
|
-
speed: 0.9
|
|
867
|
+
speed: 0.9,
|
|
853
868
|
};
|
|
854
869
|
|
|
855
870
|
// src/curves/epicycloid3.ts
|
|
@@ -857,14 +872,14 @@ var TWO_PI5 = Math.PI * 2;
|
|
|
857
872
|
function epicycloid3Fn(t, _time, _params) {
|
|
858
873
|
return {
|
|
859
874
|
x: 4 * Math.cos(t) - Math.cos(4 * t),
|
|
860
|
-
y: 4 * Math.sin(t) - Math.sin(4 * t)
|
|
875
|
+
y: 4 * Math.sin(t) - Math.sin(4 * t),
|
|
861
876
|
};
|
|
862
877
|
}
|
|
863
878
|
var epicycloid3 = {
|
|
864
879
|
name: "Epicycloid (n=3)",
|
|
865
880
|
fn: epicycloid3Fn,
|
|
866
881
|
period: TWO_PI5,
|
|
867
|
-
speed: 0.75
|
|
882
|
+
speed: 0.75,
|
|
868
883
|
};
|
|
869
884
|
|
|
870
885
|
// src/curves/epitrochoid7.ts
|
|
@@ -873,14 +888,14 @@ function epitrochoid7Fn(t, _time, _params) {
|
|
|
873
888
|
const d = 1 + 0.55 * Math.sin(t * 0.5);
|
|
874
889
|
return {
|
|
875
890
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
876
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
891
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
877
892
|
};
|
|
878
893
|
}
|
|
879
894
|
function epitrochoid7SkeletonFn(t) {
|
|
880
895
|
const d = 1.275;
|
|
881
896
|
return {
|
|
882
897
|
x: 7 * Math.cos(t) - d * Math.cos(7 * t),
|
|
883
|
-
y: 7 * Math.sin(t) - d * Math.sin(7 * t)
|
|
898
|
+
y: 7 * Math.sin(t) - d * Math.sin(7 * t),
|
|
884
899
|
};
|
|
885
900
|
}
|
|
886
901
|
var epitrochoid7 = {
|
|
@@ -888,7 +903,7 @@ var epitrochoid7 = {
|
|
|
888
903
|
fn: epitrochoid7Fn,
|
|
889
904
|
period: TWO_PI6,
|
|
890
905
|
speed: 1.4,
|
|
891
|
-
skeletonFn: epitrochoid7SkeletonFn
|
|
906
|
+
skeletonFn: epitrochoid7SkeletonFn,
|
|
892
907
|
};
|
|
893
908
|
|
|
894
909
|
// src/curves/lissajous32.ts
|
|
@@ -897,7 +912,7 @@ function lissajous32Fn(t, time, _params) {
|
|
|
897
912
|
const phi = time * 0.45;
|
|
898
913
|
return {
|
|
899
914
|
x: Math.sin(3 * t + phi),
|
|
900
|
-
y: Math.sin(2 * t)
|
|
915
|
+
y: Math.sin(2 * t),
|
|
901
916
|
};
|
|
902
917
|
}
|
|
903
918
|
var lissajous32 = {
|
|
@@ -905,7 +920,7 @@ var lissajous32 = {
|
|
|
905
920
|
fn: lissajous32Fn,
|
|
906
921
|
period: TWO_PI7,
|
|
907
922
|
speed: 2,
|
|
908
|
-
skeleton: "live"
|
|
923
|
+
skeleton: "live",
|
|
909
924
|
};
|
|
910
925
|
|
|
911
926
|
// src/curves/lissajous43.ts
|
|
@@ -914,7 +929,7 @@ function lissajous43Fn(t, time, _params) {
|
|
|
914
929
|
const phi = time * 0.38;
|
|
915
930
|
return {
|
|
916
931
|
x: Math.sin(4 * t + phi),
|
|
917
|
-
y: Math.sin(3 * t)
|
|
932
|
+
y: Math.sin(3 * t),
|
|
918
933
|
};
|
|
919
934
|
}
|
|
920
935
|
var lissajous43 = {
|
|
@@ -922,17 +937,18 @@ var lissajous43 = {
|
|
|
922
937
|
fn: lissajous43Fn,
|
|
923
938
|
period: TWO_PI8,
|
|
924
939
|
speed: 1.8,
|
|
925
|
-
skeleton: "live"
|
|
940
|
+
skeleton: "live",
|
|
926
941
|
};
|
|
927
942
|
|
|
928
943
|
// src/curves/lame.ts
|
|
929
944
|
var TWO_PI9 = Math.PI * 2;
|
|
930
945
|
function lameFn(t, time, _params) {
|
|
931
946
|
const p = 1.75 + 1.25 * Math.sin(time * 0.48);
|
|
932
|
-
const c = Math.cos(t),
|
|
947
|
+
const c = Math.cos(t),
|
|
948
|
+
s = Math.sin(t);
|
|
933
949
|
return {
|
|
934
950
|
x: Math.sign(c) * Math.pow(Math.abs(c), p),
|
|
935
|
-
y: Math.sign(s) * Math.pow(Math.abs(s), p)
|
|
951
|
+
y: Math.sign(s) * Math.pow(Math.abs(s), p),
|
|
936
952
|
};
|
|
937
953
|
}
|
|
938
954
|
var lame = {
|
|
@@ -940,7 +956,7 @@ var lame = {
|
|
|
940
956
|
fn: lameFn,
|
|
941
957
|
period: TWO_PI9,
|
|
942
958
|
speed: 1,
|
|
943
|
-
skeleton: "live"
|
|
959
|
+
skeleton: "live",
|
|
944
960
|
};
|
|
945
961
|
|
|
946
962
|
// src/curves/rose3.ts
|
|
@@ -949,14 +965,14 @@ function rose3Fn(t, _time, _params) {
|
|
|
949
965
|
const r = Math.cos(3 * t);
|
|
950
966
|
return {
|
|
951
967
|
x: r * Math.cos(t),
|
|
952
|
-
y: r * Math.sin(t)
|
|
968
|
+
y: r * Math.sin(t),
|
|
953
969
|
};
|
|
954
970
|
}
|
|
955
971
|
var rose3 = {
|
|
956
972
|
name: "Rose (n=3)",
|
|
957
973
|
fn: rose3Fn,
|
|
958
974
|
period: TWO_PI10,
|
|
959
|
-
speed: 1.15
|
|
975
|
+
speed: 1.15,
|
|
960
976
|
};
|
|
961
977
|
|
|
962
978
|
// src/curves/rose5.ts
|
|
@@ -965,78 +981,87 @@ function rose5Fn(t, _time, _params) {
|
|
|
965
981
|
const r = Math.cos(5 * t);
|
|
966
982
|
return {
|
|
967
983
|
x: r * Math.cos(t),
|
|
968
|
-
y: r * Math.sin(t)
|
|
984
|
+
y: r * Math.sin(t),
|
|
969
985
|
};
|
|
970
986
|
}
|
|
971
987
|
var rose5 = {
|
|
972
988
|
name: "Rose (n=5)",
|
|
973
989
|
fn: rose5Fn,
|
|
974
990
|
period: TWO_PI11,
|
|
975
|
-
speed: 1
|
|
991
|
+
speed: 1,
|
|
976
992
|
};
|
|
977
993
|
|
|
978
994
|
// src/curves/rose52.ts
|
|
979
995
|
var FOUR_PI = Math.PI * 4;
|
|
980
996
|
function rose52Fn(t, _time, _params) {
|
|
981
|
-
const r = Math.cos(5 / 2 * t);
|
|
997
|
+
const r = Math.cos((5 / 2) * t);
|
|
982
998
|
return {
|
|
983
999
|
x: r * Math.cos(t),
|
|
984
|
-
y: r * Math.sin(t)
|
|
1000
|
+
y: r * Math.sin(t),
|
|
985
1001
|
};
|
|
986
1002
|
}
|
|
987
1003
|
var rose52 = {
|
|
988
1004
|
name: "Rose (n=5/2)",
|
|
989
1005
|
fn: rose52Fn,
|
|
990
1006
|
period: FOUR_PI,
|
|
991
|
-
speed: 0.8
|
|
1007
|
+
speed: 0.8,
|
|
992
1008
|
};
|
|
993
1009
|
|
|
994
1010
|
// src/curves/star.ts
|
|
995
1011
|
var TWO_PI12 = Math.PI * 2;
|
|
996
1012
|
function starFn(t, _time, _params) {
|
|
997
|
-
const r =
|
|
1013
|
+
const r =
|
|
1014
|
+
Math.abs(Math.cos((5 / 2) * t)) +
|
|
1015
|
+
0.35 * Math.abs(Math.cos((15 / 2) * t)) +
|
|
1016
|
+
0.15 * Math.abs(Math.cos((25 / 2) * t));
|
|
998
1017
|
return {
|
|
999
1018
|
x: r * Math.cos(t),
|
|
1000
|
-
y: r * Math.sin(t)
|
|
1019
|
+
y: r * Math.sin(t),
|
|
1001
1020
|
};
|
|
1002
1021
|
}
|
|
1003
1022
|
var star = {
|
|
1004
1023
|
name: "Star",
|
|
1005
1024
|
fn: starFn,
|
|
1006
1025
|
period: TWO_PI12,
|
|
1007
|
-
speed: 1
|
|
1026
|
+
speed: 1,
|
|
1008
1027
|
};
|
|
1009
1028
|
|
|
1010
1029
|
// src/curves/star4.ts
|
|
1011
1030
|
var TWO_PI13 = Math.PI * 2;
|
|
1012
1031
|
function star4Fn(t, _time, _params) {
|
|
1013
|
-
const r =
|
|
1032
|
+
const r =
|
|
1033
|
+
Math.abs(Math.cos(2 * t)) +
|
|
1034
|
+
0.35 * Math.abs(Math.cos(6 * t)) +
|
|
1035
|
+
0.15 * Math.abs(Math.cos(10 * t));
|
|
1014
1036
|
return {
|
|
1015
1037
|
x: r * Math.cos(t),
|
|
1016
|
-
y: r * Math.sin(t)
|
|
1038
|
+
y: r * Math.sin(t),
|
|
1017
1039
|
};
|
|
1018
1040
|
}
|
|
1019
1041
|
var star4 = {
|
|
1020
1042
|
name: "Star (4-arm)",
|
|
1021
1043
|
fn: star4Fn,
|
|
1022
1044
|
period: TWO_PI13,
|
|
1023
|
-
speed: 1
|
|
1045
|
+
speed: 1,
|
|
1024
1046
|
};
|
|
1025
1047
|
|
|
1026
1048
|
// src/curves/star7.ts
|
|
1027
1049
|
var TWO_PI14 = Math.PI * 2;
|
|
1028
1050
|
function star7Fn(t, _time, _params) {
|
|
1029
|
-
const r =
|
|
1051
|
+
const r =
|
|
1052
|
+
Math.abs(Math.cos((7 / 2) * t)) +
|
|
1053
|
+
0.35 * Math.abs(Math.cos((21 / 2) * t)) +
|
|
1054
|
+
0.15 * Math.abs(Math.cos((35 / 2) * t));
|
|
1030
1055
|
return {
|
|
1031
1056
|
x: r * Math.cos(t),
|
|
1032
|
-
y: r * Math.sin(t)
|
|
1057
|
+
y: r * Math.sin(t),
|
|
1033
1058
|
};
|
|
1034
1059
|
}
|
|
1035
1060
|
var star7 = {
|
|
1036
1061
|
name: "Star (7-arm)",
|
|
1037
1062
|
fn: star7Fn,
|
|
1038
1063
|
period: TWO_PI14,
|
|
1039
|
-
speed: 1
|
|
1064
|
+
speed: 1,
|
|
1040
1065
|
};
|
|
1041
1066
|
|
|
1042
1067
|
// src/curves/index.ts
|
|
@@ -1054,7 +1079,7 @@ var curves = {
|
|
|
1054
1079
|
lissajous32,
|
|
1055
1080
|
lissajous43,
|
|
1056
1081
|
epicycloid3,
|
|
1057
|
-
lame
|
|
1082
|
+
lame,
|
|
1058
1083
|
};
|
|
1059
1084
|
|
|
1060
1085
|
// src/index.ts
|
|
@@ -1071,8 +1096,7 @@ function parseTrailColor(value) {
|
|
|
1071
1096
|
if (Array.isArray(parsed)) {
|
|
1072
1097
|
return parsed;
|
|
1073
1098
|
}
|
|
1074
|
-
} catch {
|
|
1075
|
-
}
|
|
1099
|
+
} catch {}
|
|
1076
1100
|
return value;
|
|
1077
1101
|
}
|
|
1078
1102
|
function init() {
|
|
@@ -1087,16 +1111,16 @@ function init() {
|
|
|
1087
1111
|
return console.error(`[sarmal] "${curveName}" is not a valid curve name`);
|
|
1088
1112
|
}
|
|
1089
1113
|
const instance = createSarmal(canvas, curveDef, {
|
|
1090
|
-
...canvas.dataset.trailColor && {
|
|
1091
|
-
trailColor: parseTrailColor(canvas.dataset.trailColor)
|
|
1092
|
-
},
|
|
1093
|
-
...canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor },
|
|
1094
|
-
...canvas.dataset.headColor && { headColor: canvas.dataset.headColor },
|
|
1095
|
-
...canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) },
|
|
1096
|
-
...canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) },
|
|
1097
|
-
...canvas.dataset.trailStyle && {
|
|
1098
|
-
trailStyle: canvas.dataset.trailStyle
|
|
1099
|
-
}
|
|
1114
|
+
...(canvas.dataset.trailColor && {
|
|
1115
|
+
trailColor: parseTrailColor(canvas.dataset.trailColor),
|
|
1116
|
+
}),
|
|
1117
|
+
...(canvas.dataset.skeletonColor && { skeletonColor: canvas.dataset.skeletonColor }),
|
|
1118
|
+
...(canvas.dataset.headColor && { headColor: canvas.dataset.headColor }),
|
|
1119
|
+
...(canvas.dataset.headRadius && { headRadius: parseFloat(canvas.dataset.headRadius) }),
|
|
1120
|
+
...(canvas.dataset.trailLength && { trailLength: parseInt(canvas.dataset.trailLength, 10) }),
|
|
1121
|
+
...(canvas.dataset.trailStyle && {
|
|
1122
|
+
trailStyle: canvas.dataset.trailStyle,
|
|
1123
|
+
}),
|
|
1100
1124
|
});
|
|
1101
1125
|
if (canvas.dataset.speed) {
|
|
1102
1126
|
instance.setSpeed(parseFloat(canvas.dataset.speed));
|
|
@@ -1113,4 +1137,4 @@ if (document.readyState === "loading") {
|
|
|
1113
1137
|
|
|
1114
1138
|
export { init };
|
|
1115
1139
|
//# sourceMappingURL=auto-init.js.map
|
|
1116
|
-
//# sourceMappingURL=auto-init.js.map
|
|
1140
|
+
//# sourceMappingURL=auto-init.js.map
|