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