@idle-screens/savers-classic 3.2.1 → 3.2.3
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/idle-worker.js +414 -101
- package/dist/idle-worker.js.map +1 -1
- package/package.json +4 -4
package/dist/idle-worker.js
CHANGED
|
@@ -66,9 +66,123 @@ var LIMITS = {
|
|
|
66
66
|
maxPathPoints: 24,
|
|
67
67
|
minPathDuration: 2e3,
|
|
68
68
|
// ms — a path lap can't be faster than this
|
|
69
|
-
maxGridColumns: 100
|
|
69
|
+
maxGridColumns: 100,
|
|
70
|
+
maxTextBlockLength: 2e3,
|
|
71
|
+
minTextBlockFontSize: 0.01,
|
|
72
|
+
maxTextBlockFontSize: 0.2,
|
|
73
|
+
maxTextBlockMaxWidth: 1,
|
|
74
|
+
maxRevealSpeed: 120,
|
|
75
|
+
// graphemes/sec — faster than any readable typing
|
|
76
|
+
maxCaretBlinkHz: 3,
|
|
77
|
+
// full blink cycles/sec — WCAG 2.3.1 flash-safety cap
|
|
78
|
+
maxSegments: 24,
|
|
79
|
+
minSegmentDuration: 1e3,
|
|
80
|
+
// ms — flash-safety floor: segment cuts are luminance transitions
|
|
81
|
+
maxTransitionDur: 5e3,
|
|
82
|
+
minTransitionDur: 200
|
|
70
83
|
};
|
|
71
|
-
var
|
|
84
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
85
|
+
function resolveSpecPath(spec, path) {
|
|
86
|
+
if (!spec || typeof spec !== "object" || !path) return null;
|
|
87
|
+
const parts = path.split(".");
|
|
88
|
+
if (parts.some((p) => UNSAFE_KEYS.has(p))) return null;
|
|
89
|
+
const s = spec;
|
|
90
|
+
if (parts[0] !== "layers" && parts[0] !== "background" && Array.isArray(s.layers)) {
|
|
91
|
+
const idx = s.layers.findIndex((l) => l && l.key === parts[0]);
|
|
92
|
+
if (idx === -1) return null;
|
|
93
|
+
parts.splice(0, 1, "layers", String(idx));
|
|
94
|
+
}
|
|
95
|
+
let node = spec;
|
|
96
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
97
|
+
if (node === null || typeof node !== "object") return null;
|
|
98
|
+
node = node[parts[i]];
|
|
99
|
+
}
|
|
100
|
+
if (node === null || typeof node !== "object") return null;
|
|
101
|
+
const last = parts[parts.length - 1];
|
|
102
|
+
const key = Array.isArray(node) ? Number(last) : last;
|
|
103
|
+
const exists = Array.isArray(node) ? Number.isInteger(key) && key >= 0 && key < node.length : last in node;
|
|
104
|
+
return exists ? { parent: node, key } : null;
|
|
105
|
+
}
|
|
106
|
+
function applyDeltasToSpec(spec, deltas) {
|
|
107
|
+
const copy = JSON.parse(JSON.stringify(spec));
|
|
108
|
+
for (const d of deltas) {
|
|
109
|
+
const loc = resolveSpecPath(copy, d.path);
|
|
110
|
+
if (loc) loc.parent[loc.key] = d.value;
|
|
111
|
+
}
|
|
112
|
+
return copy;
|
|
113
|
+
}
|
|
114
|
+
var HEX = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
115
|
+
function hexToRgb(hex) {
|
|
116
|
+
const h = hex.length === 4 ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}` : hex;
|
|
117
|
+
const n = parseInt(h.slice(1), 16);
|
|
118
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
119
|
+
}
|
|
120
|
+
function lerpHex(a, b, k) {
|
|
121
|
+
const ca = hexToRgb(a);
|
|
122
|
+
const cb = hexToRgb(b);
|
|
123
|
+
const mix = ca.map((v, i) => Math.round(v + (cb[i] - v) * k));
|
|
124
|
+
return `#${mix.map((v) => v.toString(16).padStart(2, "0")).join("")}`;
|
|
125
|
+
}
|
|
126
|
+
function lerpSpec(from, to, k) {
|
|
127
|
+
const kk = Math.max(0, Math.min(1, k));
|
|
128
|
+
const walk = (a, b, key) => {
|
|
129
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
130
|
+
const v = a + (b - a) * kk;
|
|
131
|
+
return key === "count" ? Math.max(1, Math.round(v)) : v;
|
|
132
|
+
}
|
|
133
|
+
if (typeof a === "string" && typeof b === "string" && HEX.test(a) && HEX.test(b)) {
|
|
134
|
+
return lerpHex(a, b, kk);
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
|
|
137
|
+
return b.map((bv, i) => walk(a[i], bv, i));
|
|
138
|
+
}
|
|
139
|
+
if (a && b && typeof a === "object" && typeof b === "object" && !Array.isArray(a) && !Array.isArray(b)) {
|
|
140
|
+
const out = {};
|
|
141
|
+
for (const kName of Object.keys(b)) {
|
|
142
|
+
out[kName] = walk(a[kName], b[kName], kName);
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
return kk > 0 ? b : a;
|
|
147
|
+
};
|
|
148
|
+
return walk(from, to);
|
|
149
|
+
}
|
|
150
|
+
function easeSmooth(k) {
|
|
151
|
+
const c = Math.max(0, Math.min(1, k));
|
|
152
|
+
return c * c * (3 - 2 * c);
|
|
153
|
+
}
|
|
154
|
+
function structuralSignature(spec) {
|
|
155
|
+
return JSON.stringify([
|
|
156
|
+
spec.units,
|
|
157
|
+
spec.layers.map((l) => {
|
|
158
|
+
const s = l.sprite;
|
|
159
|
+
return [
|
|
160
|
+
l.count,
|
|
161
|
+
l.size,
|
|
162
|
+
l.region,
|
|
163
|
+
l.position,
|
|
164
|
+
l.motion,
|
|
165
|
+
l.wrap,
|
|
166
|
+
l.flip,
|
|
167
|
+
l.alpha,
|
|
168
|
+
l.pulse,
|
|
169
|
+
l.spin,
|
|
170
|
+
l.grow,
|
|
171
|
+
l.layout,
|
|
172
|
+
l.sprite.kind,
|
|
173
|
+
// Dimensional draws baked into entities: radius (circle/ring), length
|
|
174
|
+
// (streak), width+aspect (rect), palette pick (all shaped sprites).
|
|
175
|
+
s.radius,
|
|
176
|
+
s.length,
|
|
177
|
+
l.sprite.kind === "rect" ? [s.width, s.aspect] : void 0,
|
|
178
|
+
Array.isArray(s.colors) ? s.colors.length : void 0,
|
|
179
|
+
s.colorWeights,
|
|
180
|
+
l.sprite.kind === "emoji" ? [l.sprite.glyphs.length, l.sprite.cycle?.period] : l.sprite.kind === "text" ? [l.sprite.strings.length, l.sprite.cycle?.period] : l.sprite.kind === "textBlock" ? [l.sprite.fontSize] : void 0
|
|
181
|
+
];
|
|
182
|
+
})
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
var HEX2 = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
72
186
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
73
187
|
var isStr = (v) => typeof v === "string";
|
|
74
188
|
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
@@ -100,6 +214,9 @@ var KNOWN_STREAK = /* @__PURE__ */ new Set(["kind", "length", "color", "width",
|
|
|
100
214
|
var KNOWN_RECT = /* @__PURE__ */ new Set(["kind", "width", "aspect", "color", "colors", "colorWeights"]);
|
|
101
215
|
var KNOWN_EMOJI = /* @__PURE__ */ new Set(["kind", "glyphs", "cycle"]);
|
|
102
216
|
var KNOWN_TEXT = /* @__PURE__ */ new Set(["kind", "strings", "color", "font", "align", "baseline", "maxWidth", "cycle"]);
|
|
217
|
+
var KNOWN_TEXT_BLOCK = /* @__PURE__ */ new Set(["kind", "text", "maxWidth", "fontSize", "lineHeight", "align", "color", "reveal"]);
|
|
218
|
+
var KNOWN_REVEAL = /* @__PURE__ */ new Set(["progress", "mode", "speed", "caret"]);
|
|
219
|
+
var KNOWN_REVEAL_CARET = /* @__PURE__ */ new Set(["blink", "color"]);
|
|
103
220
|
var KNOWN_DRIFT = /* @__PURE__ */ new Set(["type", "speed", "angle", "bidirectional", "bob"]);
|
|
104
221
|
var KNOWN_RISE = /* @__PURE__ */ new Set(["type", "speed", "sway"]);
|
|
105
222
|
var KNOWN_BOUNCE = /* @__PURE__ */ new Set(["type", "speed"]);
|
|
@@ -114,7 +231,20 @@ var LAYER_PROPS_ON_SPRITE = /* @__PURE__ */ new Set(["blend", "trail", "alpha",
|
|
|
114
231
|
function unknownKeys(obj, known) {
|
|
115
232
|
return Object.keys(obj).filter((k) => !known.has(k));
|
|
116
233
|
}
|
|
234
|
+
function normalizeColors(spec) {
|
|
235
|
+
if (!isObj(spec) || !Array.isArray(spec.layers)) return;
|
|
236
|
+
for (const layer of spec.layers) {
|
|
237
|
+
if (!isObj(layer)) continue;
|
|
238
|
+
const sprite = layer.sprite;
|
|
239
|
+
if (!isObj(sprite)) continue;
|
|
240
|
+
const sp = sprite;
|
|
241
|
+
if (Array.isArray(sp.colors) && sp.colors.length > 0 && sp.color === void 0) {
|
|
242
|
+
sp.color = sp.colors[0];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
117
246
|
function validateSpec(spec) {
|
|
247
|
+
normalizeColors(spec);
|
|
118
248
|
const errors = [];
|
|
119
249
|
const warnings = [];
|
|
120
250
|
const err = (path, message) => void errors.push({ path, message });
|
|
@@ -130,6 +260,14 @@ function validateSpec(spec) {
|
|
|
130
260
|
if (spec.units !== void 0 && spec.units !== "px" && spec.units !== "viewport") {
|
|
131
261
|
err("units", "must be 'px' | 'viewport'");
|
|
132
262
|
}
|
|
263
|
+
if (spec.units === "px" && Array.isArray(spec.layers)) {
|
|
264
|
+
for (const l of spec.layers) {
|
|
265
|
+
if (isObj(l) && isObj(l.sprite) && l.sprite.kind === "textBlock") {
|
|
266
|
+
err("units", "textBlock dimensions are viewport fractions \u2014 units: 'px' is not supported with textBlock sprites");
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
133
271
|
if (spec.referenceViewport !== void 0) {
|
|
134
272
|
if (!isNum(spec.referenceViewport) || spec.referenceViewport < 100 || spec.referenceViewport > 8640) {
|
|
135
273
|
err("referenceViewport", "must be a number between 100 and 8640");
|
|
@@ -156,7 +294,7 @@ function validateSpec(spec) {
|
|
|
156
294
|
return { valid: errors.length === 0, errors, warnings };
|
|
157
295
|
}
|
|
158
296
|
function color(v, path, err) {
|
|
159
|
-
if (!isStr(v) || !
|
|
297
|
+
if (!isStr(v) || !HEX2.test(v)) err(path, "must be a hex colour like #0a3a52");
|
|
160
298
|
}
|
|
161
299
|
function validateBackground(bg, err, warn) {
|
|
162
300
|
if (!isObj(bg)) return err("background", "must be an object");
|
|
@@ -429,8 +567,61 @@ function validateSprite(sprite, path, err, warn) {
|
|
|
429
567
|
}
|
|
430
568
|
color(sprite.color, `${path}.color`, err);
|
|
431
569
|
validatePalette(sprite, path, err);
|
|
570
|
+
} else if (sprite.kind === "textBlock") {
|
|
571
|
+
knownSet = KNOWN_TEXT_BLOCK;
|
|
572
|
+
if (typeof sprite.text !== "string" || sprite.text.length === 0) {
|
|
573
|
+
err(`${path}.text`, "must be a non-empty string");
|
|
574
|
+
} else if (sprite.text.length > LIMITS.maxTextBlockLength) {
|
|
575
|
+
err(`${path}.text`, `must be at most ${LIMITS.maxTextBlockLength} characters`);
|
|
576
|
+
}
|
|
577
|
+
if (!isNum(sprite.maxWidth) || sprite.maxWidth <= 0 || sprite.maxWidth > LIMITS.maxTextBlockMaxWidth) {
|
|
578
|
+
err(`${path}.maxWidth`, `must be a positive number up to ${LIMITS.maxTextBlockMaxWidth} (viewport fraction)`);
|
|
579
|
+
}
|
|
580
|
+
if (!isNum(sprite.fontSize) || sprite.fontSize < LIMITS.minTextBlockFontSize || sprite.fontSize > LIMITS.maxTextBlockFontSize) {
|
|
581
|
+
err(`${path}.fontSize`, `must be between ${LIMITS.minTextBlockFontSize} and ${LIMITS.maxTextBlockFontSize} (viewport fraction)`);
|
|
582
|
+
}
|
|
583
|
+
if (sprite.lineHeight !== void 0 && (!isNum(sprite.lineHeight) || sprite.lineHeight < 0.5 || sprite.lineHeight > 4)) {
|
|
584
|
+
err(`${path}.lineHeight`, "must be between 0.5 and 4 (multiplier)");
|
|
585
|
+
}
|
|
586
|
+
if (sprite.align !== void 0 && !["left", "center", "right"].includes(sprite.align)) {
|
|
587
|
+
err(`${path}.align`, "must be 'left' | 'center' | 'right'");
|
|
588
|
+
}
|
|
589
|
+
if (sprite.color !== void 0) color(sprite.color, `${path}.color`, err);
|
|
590
|
+
if (sprite.reveal !== void 0) {
|
|
591
|
+
const rv = sprite.reveal;
|
|
592
|
+
if (typeof rv !== "object" || rv === null || Array.isArray(rv)) {
|
|
593
|
+
err(`${path}.reveal`, "must be an object");
|
|
594
|
+
} else {
|
|
595
|
+
for (const k of Object.keys(rv)) {
|
|
596
|
+
if (!KNOWN_REVEAL.has(k)) err(`${path}.reveal.${k}`, "unknown reveal field");
|
|
597
|
+
}
|
|
598
|
+
if (rv.progress !== void 0 && (!isNum(rv.progress) || rv.progress < 0 || rv.progress > 1)) {
|
|
599
|
+
err(`${path}.reveal.progress`, "must be a number between 0 and 1");
|
|
600
|
+
}
|
|
601
|
+
if (rv.mode !== void 0 && !["typewriter", "word", "line"].includes(rv.mode)) {
|
|
602
|
+
err(`${path}.reveal.mode`, "must be 'typewriter' | 'word' | 'line'");
|
|
603
|
+
}
|
|
604
|
+
if (rv.speed !== void 0 && (!isNum(rv.speed) || rv.speed < 0 || rv.speed > LIMITS.maxRevealSpeed)) {
|
|
605
|
+
err(`${path}.reveal.speed`, `must be between 0 and ${LIMITS.maxRevealSpeed} (graphemes/sec)`);
|
|
606
|
+
}
|
|
607
|
+
if (rv.caret !== void 0 && typeof rv.caret !== "boolean") {
|
|
608
|
+
const caret = rv.caret;
|
|
609
|
+
if (typeof caret !== "object" || caret === null || Array.isArray(caret)) {
|
|
610
|
+
err(`${path}.reveal.caret`, "must be a boolean or an object");
|
|
611
|
+
} else {
|
|
612
|
+
for (const k of Object.keys(caret)) {
|
|
613
|
+
if (!KNOWN_REVEAL_CARET.has(k)) err(`${path}.reveal.caret.${k}`, "unknown caret field");
|
|
614
|
+
}
|
|
615
|
+
if (caret.blink !== void 0 && (!isNum(caret.blink) || caret.blink <= 0 || caret.blink > LIMITS.maxCaretBlinkHz)) {
|
|
616
|
+
err(`${path}.reveal.caret.blink`, `must be between 0 (exclusive) and ${LIMITS.maxCaretBlinkHz} Hz (flash safety)`);
|
|
617
|
+
}
|
|
618
|
+
if (caret.color !== void 0) color(caret.color, `${path}.reveal.caret.color`, err);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
432
623
|
} else {
|
|
433
|
-
err(`${path}.kind`, "must be emoji | text | circle | ring | streak | rect");
|
|
624
|
+
err(`${path}.kind`, "must be emoji | text | circle | ring | streak | rect | textBlock");
|
|
434
625
|
return;
|
|
435
626
|
}
|
|
436
627
|
for (const k of unknownKeys(sprite, knownSet)) {
|
|
@@ -635,7 +826,7 @@ function weightedIndex(u, weights) {
|
|
|
635
826
|
return weights.length - 1;
|
|
636
827
|
}
|
|
637
828
|
function buildEntities(layer, rng, w, h, scale = 1, countScale = 1) {
|
|
638
|
-
const effectiveCount = countScale === 1 ? layer.count : Math.max(1, Math.min(
|
|
829
|
+
const effectiveCount = countScale === 1 || layer.layout?.type === "grid" ? layer.count : Math.max(1, Math.min(
|
|
639
830
|
Math.round(layer.count * countScale),
|
|
640
831
|
layer.links ? LIMITS.maxLinkLayerCount : LIMITS.maxPerLayer
|
|
641
832
|
));
|
|
@@ -680,7 +871,7 @@ function buildEntities(layer, rng, w, h, scale = 1, countScale = 1) {
|
|
|
680
871
|
}
|
|
681
872
|
const out = [];
|
|
682
873
|
for (let i = 0; i < effectiveCount; i++) {
|
|
683
|
-
const size = sprite.kind === "circle" || sprite.kind === "ring" ? rng.range(sprite.radius[0], sprite.radius[1]) * 2 * scale : sprite.kind === "streak" ? rng.range(sprite.length[0], sprite.length[1]) * scale : sprite.kind === "rect" ? rng.range(sprite.width[0], sprite.width[1]) * scale : rng.range(smin, smax) * scale;
|
|
874
|
+
const size = sprite.kind === "textBlock" ? sprite.fontSize * scale : sprite.kind === "circle" || sprite.kind === "ring" ? rng.range(sprite.radius[0], sprite.radius[1]) * 2 * scale : sprite.kind === "streak" ? rng.range(sprite.length[0], sprite.length[1]) * scale : sprite.kind === "rect" ? rng.range(sprite.width[0], sprite.width[1]) * scale : rng.range(smin, smax) * scale;
|
|
684
875
|
const size2 = sprite.kind === "rect" ? size * (sprite.aspect ? rng.range(sprite.aspect[0], sprite.aspect[1]) : 1) : void 0;
|
|
685
876
|
let vx = 0;
|
|
686
877
|
let vy = 0;
|
|
@@ -1064,106 +1255,137 @@ function linkPairs(positions, k, maxDist, doWrap, w, h) {
|
|
|
1064
1255
|
}
|
|
1065
1256
|
return out;
|
|
1066
1257
|
}
|
|
1067
|
-
var
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
const idx = s.layers.findIndex((l) => l && l.key === parts[0]);
|
|
1075
|
-
if (idx === -1) return null;
|
|
1076
|
-
parts.splice(0, 1, "layers", String(idx));
|
|
1077
|
-
}
|
|
1078
|
-
let node = spec;
|
|
1079
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
1080
|
-
if (node === null || typeof node !== "object") return null;
|
|
1081
|
-
node = node[parts[i]];
|
|
1082
|
-
}
|
|
1083
|
-
if (node === null || typeof node !== "object") return null;
|
|
1084
|
-
const last = parts[parts.length - 1];
|
|
1085
|
-
const key = Array.isArray(node) ? Number(last) : last;
|
|
1086
|
-
const exists = Array.isArray(node) ? Number.isInteger(key) && key >= 0 && key < node.length : last in node;
|
|
1087
|
-
return exists ? { parent: node, key } : null;
|
|
1258
|
+
var CHAR_NARROW = new Set(`iIljtf1!|.,;:'"()[]{}`);
|
|
1259
|
+
var CHAR_WIDE = new Set("mwMWGOQD@%");
|
|
1260
|
+
function charWidthEm(ch) {
|
|
1261
|
+
if (ch === " " || ch === " ") return 0.3;
|
|
1262
|
+
if (CHAR_NARROW.has(ch)) return 0.35;
|
|
1263
|
+
if (CHAR_WIDE.has(ch)) return 0.72;
|
|
1264
|
+
return 0.55;
|
|
1088
1265
|
}
|
|
1089
|
-
function
|
|
1090
|
-
|
|
1091
|
-
for (
|
|
1092
|
-
|
|
1093
|
-
|
|
1266
|
+
function textWidthEm(str) {
|
|
1267
|
+
let w = 0;
|
|
1268
|
+
for (let i = 0; i < str.length; i++) w += charWidthEm(str[i]);
|
|
1269
|
+
return w;
|
|
1270
|
+
}
|
|
1271
|
+
function breakTextBlock(text, maxWidthEm) {
|
|
1272
|
+
const paragraphs = text.split("\n");
|
|
1273
|
+
const lines = [];
|
|
1274
|
+
for (const para of paragraphs) {
|
|
1275
|
+
if (para.length === 0) {
|
|
1276
|
+
lines.push({ text: "", widthEm: 0 });
|
|
1277
|
+
continue;
|
|
1278
|
+
}
|
|
1279
|
+
const words = para.split(/\s+/).filter((w) => w.length > 0);
|
|
1280
|
+
if (words.length === 0) {
|
|
1281
|
+
lines.push({ text: "", widthEm: 0 });
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
let lineText = words[0];
|
|
1285
|
+
let lineW = textWidthEm(lineText);
|
|
1286
|
+
const spaceW = charWidthEm(" ");
|
|
1287
|
+
for (let i = 1; i < words.length; i++) {
|
|
1288
|
+
const word = words[i];
|
|
1289
|
+
const wordW = textWidthEm(word);
|
|
1290
|
+
if (lineW + spaceW + wordW <= maxWidthEm) {
|
|
1291
|
+
lineText += " " + word;
|
|
1292
|
+
lineW += spaceW + wordW;
|
|
1293
|
+
} else {
|
|
1294
|
+
lines.push({ text: lineText, widthEm: lineW });
|
|
1295
|
+
lineText = word;
|
|
1296
|
+
lineW = wordW;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
lines.push({ text: lineText, widthEm: lineW });
|
|
1094
1300
|
}
|
|
1095
|
-
return
|
|
1301
|
+
return lines;
|
|
1096
1302
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1303
|
+
function isClusterExtend(cp) {
|
|
1304
|
+
return cp >= 768 && cp <= 879 || // combining diacritics
|
|
1305
|
+
cp >= 6832 && cp <= 6911 || cp >= 8400 && cp <= 8447 || cp >= 65024 && cp <= 65039 || // variation selectors
|
|
1306
|
+
cp >= 127995 && cp <= 127999 || // skin tones
|
|
1307
|
+
cp === 8419;
|
|
1102
1308
|
}
|
|
1103
|
-
function
|
|
1104
|
-
|
|
1105
|
-
const cb = hexToRgb(b);
|
|
1106
|
-
const mix = ca.map((v, i) => Math.round(v + (cb[i] - v) * k));
|
|
1107
|
-
return `#${mix.map((v) => v.toString(16).padStart(2, "0")).join("")}`;
|
|
1309
|
+
function isRegionalIndicator(cp) {
|
|
1310
|
+
return cp >= 127462 && cp <= 127487;
|
|
1108
1311
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
if (
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1312
|
+
var ZWJ = 8205;
|
|
1313
|
+
function graphemeClusters(text) {
|
|
1314
|
+
const out = [];
|
|
1315
|
+
let i = 0;
|
|
1316
|
+
while (i < text.length) {
|
|
1317
|
+
const cp = text.codePointAt(i);
|
|
1318
|
+
let end = i + (cp > 65535 ? 2 : 1);
|
|
1319
|
+
if (isRegionalIndicator(cp) && end < text.length) {
|
|
1320
|
+
const next = text.codePointAt(end);
|
|
1321
|
+
if (isRegionalIndicator(next)) end += next > 65535 ? 2 : 1;
|
|
1322
|
+
}
|
|
1323
|
+
while (end < text.length) {
|
|
1324
|
+
const next = text.codePointAt(end);
|
|
1325
|
+
if (isClusterExtend(next)) {
|
|
1326
|
+
end += next > 65535 ? 2 : 1;
|
|
1327
|
+
} else if (next === ZWJ && end + 1 < text.length) {
|
|
1328
|
+
const after = text.codePointAt(end + 1);
|
|
1329
|
+
end += 1 + (after > 65535 ? 2 : 1);
|
|
1330
|
+
} else {
|
|
1331
|
+
break;
|
|
1126
1332
|
}
|
|
1127
|
-
return out;
|
|
1128
1333
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
function easeSmooth(k) {
|
|
1134
|
-
const c = Math.max(0, Math.min(1, k));
|
|
1135
|
-
return c * c * (3 - 2 * c);
|
|
1334
|
+
out.push(text.slice(i, end));
|
|
1335
|
+
i = end;
|
|
1336
|
+
}
|
|
1337
|
+
return out;
|
|
1136
1338
|
}
|
|
1137
|
-
function
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1339
|
+
function revealState(lines, reveal, tMs) {
|
|
1340
|
+
const lineClusters = lines.map((l) => graphemeClusters(l.text));
|
|
1341
|
+
const totalGraphemes = lineClusters.reduce((n, c) => n + c.length, 0);
|
|
1342
|
+
const authored = Math.max(0, Math.min(1, reveal.progress ?? 1));
|
|
1343
|
+
const speed = reveal.speed ?? 0;
|
|
1344
|
+
const timed = speed > 0 && totalGraphemes > 0 ? Math.min(1, speed * tMs / 1e3 / totalGraphemes) : 1;
|
|
1345
|
+
const progress = Math.min(authored, timed);
|
|
1346
|
+
const mode = reveal.mode ?? "typewriter";
|
|
1347
|
+
let fullLines = 0;
|
|
1348
|
+
let partialText = "";
|
|
1349
|
+
if (mode === "line") {
|
|
1350
|
+
fullLines = Math.round(progress * lines.length);
|
|
1351
|
+
} else if (mode === "word") {
|
|
1352
|
+
const lineWords = lines.map((l) => l.text.length === 0 ? [] : l.text.split(" "));
|
|
1353
|
+
const totalWords = lineWords.reduce((n, ws) => n + ws.length, 0);
|
|
1354
|
+
let remaining = Math.round(progress * totalWords);
|
|
1355
|
+
for (const ws of lineWords) {
|
|
1356
|
+
if (remaining >= ws.length) {
|
|
1357
|
+
remaining -= ws.length;
|
|
1358
|
+
fullLines++;
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
if (remaining > 0) partialText = ws.slice(0, remaining).join(" ");
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
} else {
|
|
1365
|
+
let remaining = Math.round(progress * totalGraphemes);
|
|
1366
|
+
for (const clusters of lineClusters) {
|
|
1367
|
+
if (remaining >= clusters.length) {
|
|
1368
|
+
remaining -= clusters.length;
|
|
1369
|
+
fullLines++;
|
|
1370
|
+
continue;
|
|
1371
|
+
}
|
|
1372
|
+
if (remaining > 0) partialText = clusters.slice(0, remaining).join("");
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
let caretLine;
|
|
1377
|
+
let caretPrefix;
|
|
1378
|
+
if (partialText.length > 0) {
|
|
1379
|
+
caretLine = fullLines;
|
|
1380
|
+
caretPrefix = partialText;
|
|
1381
|
+
} else if (fullLines > 0) {
|
|
1382
|
+
caretLine = fullLines - 1;
|
|
1383
|
+
caretPrefix = lines[fullLines - 1].text;
|
|
1384
|
+
} else {
|
|
1385
|
+
caretLine = 0;
|
|
1386
|
+
caretPrefix = "";
|
|
1387
|
+
}
|
|
1388
|
+
return { progress, fullLines, partialText, caretLine, caretPrefix };
|
|
1167
1389
|
}
|
|
1168
1390
|
var DEFAULT_STEER_DUR = 1e3;
|
|
1169
1391
|
function hexToRgba(hex, alpha) {
|
|
@@ -1211,12 +1433,14 @@ var SpecInstance = class {
|
|
|
1211
1433
|
let canvas;
|
|
1212
1434
|
if (ctx.surface) {
|
|
1213
1435
|
canvas = ctx.surface;
|
|
1436
|
+
this.ownsCanvas = false;
|
|
1214
1437
|
} else {
|
|
1215
1438
|
const el = document.createElement("canvas");
|
|
1216
1439
|
el.style.cssText = "display:block;width:100%;height:100%";
|
|
1217
1440
|
el.setAttribute("aria-hidden", "true");
|
|
1218
1441
|
ctx.host.appendChild(el);
|
|
1219
1442
|
canvas = el;
|
|
1443
|
+
this.ownsCanvas = true;
|
|
1220
1444
|
}
|
|
1221
1445
|
this.canvas = canvas;
|
|
1222
1446
|
const c2d = canvas.getContext("2d", { alpha: false });
|
|
@@ -1232,6 +1456,7 @@ var SpecInstance = class {
|
|
|
1232
1456
|
}
|
|
1233
1457
|
spec;
|
|
1234
1458
|
canvas;
|
|
1459
|
+
ownsCanvas;
|
|
1235
1460
|
ctx;
|
|
1236
1461
|
saverCtx;
|
|
1237
1462
|
seed;
|
|
@@ -1350,7 +1575,7 @@ var SpecInstance = class {
|
|
|
1350
1575
|
const headAlpha = alphaAt(e, t) * lifeA;
|
|
1351
1576
|
const headSize = sizeAt(e, t);
|
|
1352
1577
|
const sprite = built.layer.sprite;
|
|
1353
|
-
const resolvedColor = sprite.kind === "circle" || sprite.kind === "ring" || sprite.kind === "streak" || sprite.kind === "rect" ? sprite.colors?.[e.colorIndex] ?? sprite.color : sprite.kind === "text" ? sprite.color ?? "#e6e8ef" : "#e6e8ef";
|
|
1578
|
+
const resolvedColor = sprite.kind === "circle" || sprite.kind === "ring" || sprite.kind === "streak" || sprite.kind === "rect" ? sprite.colors?.[e.colorIndex] ?? sprite.color : sprite.kind === "text" || sprite.kind === "textBlock" ? sprite.color ?? "#e6e8ef" : "#e6e8ef";
|
|
1354
1579
|
const isSoft = sprite.kind === "circle" && sprite.soft;
|
|
1355
1580
|
const wrap2 = built.layer.wrap !== false;
|
|
1356
1581
|
const head = this.entityPos(e, t, parentE);
|
|
@@ -1457,6 +1682,45 @@ var SpecInstance = class {
|
|
|
1457
1682
|
ctx.restore();
|
|
1458
1683
|
return;
|
|
1459
1684
|
}
|
|
1685
|
+
if (sprite.kind === "textBlock") {
|
|
1686
|
+
const unitScale2 = Math.min(this.w, this.h);
|
|
1687
|
+
const fsPx = sprite.fontSize * unitScale2;
|
|
1688
|
+
const lh = (sprite.lineHeight ?? 1.4) * fsPx;
|
|
1689
|
+
const maxWPx = sprite.maxWidth * unitScale2;
|
|
1690
|
+
const maxWEm = maxWPx / fsPx;
|
|
1691
|
+
const lines = breakTextBlock(sprite.text, maxWEm);
|
|
1692
|
+
const align = sprite.align ?? "left";
|
|
1693
|
+
const reveal = sprite.reveal;
|
|
1694
|
+
const rs = reveal ? revealState(lines, reveal, t) : null;
|
|
1695
|
+
const fullLines = rs ? rs.fullLines : lines.length;
|
|
1696
|
+
ctx.save();
|
|
1697
|
+
ctx.translate(p.x, p.y);
|
|
1698
|
+
if (rot) ctx.rotate(rot);
|
|
1699
|
+
ctx.font = `${fsPx}px system-ui, sans-serif`;
|
|
1700
|
+
ctx.fillStyle = sprite.color ?? "#e6e8ef";
|
|
1701
|
+
ctx.textBaseline = "top";
|
|
1702
|
+
ctx.textAlign = align;
|
|
1703
|
+
const xOff = align === "center" ? maxWPx / 2 : align === "right" ? maxWPx : 0;
|
|
1704
|
+
for (let li = 0; li < fullLines; li++) {
|
|
1705
|
+
ctx.fillText(lines[li].text, xOff, li * lh);
|
|
1706
|
+
}
|
|
1707
|
+
if (rs && rs.partialText.length > 0) {
|
|
1708
|
+
ctx.fillText(rs.partialText, xOff, fullLines * lh);
|
|
1709
|
+
}
|
|
1710
|
+
if (rs && reveal.caret) {
|
|
1711
|
+
const cfg = reveal.caret === true ? {} : reveal.caret;
|
|
1712
|
+
const hz = Math.min(3, cfg.blink ?? 1.2);
|
|
1713
|
+
const on = hz <= 0 || Math.floor(t / 1e3 * hz * 2) % 2 === 0;
|
|
1714
|
+
if (on) {
|
|
1715
|
+
const pw = ctx.measureText(rs.caretPrefix).width;
|
|
1716
|
+
const cx = align === "center" ? xOff + pw / 2 : align === "right" ? xOff : pw;
|
|
1717
|
+
ctx.fillStyle = cfg.color ?? sprite.color ?? "#e6e8ef";
|
|
1718
|
+
ctx.fillRect(cx + fsPx * 0.06, rs.caretLine * lh, Math.max(1, fsPx * 0.08), fsPx);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
ctx.restore();
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1460
1724
|
ctx.save();
|
|
1461
1725
|
ctx.translate(p.x, p.y);
|
|
1462
1726
|
if (rot) ctx.rotate(rot);
|
|
@@ -1624,9 +1888,29 @@ var SpecInstance = class {
|
|
|
1624
1888
|
this.rebuild();
|
|
1625
1889
|
if (this.paused) this.renderFrame(0, this.seed);
|
|
1626
1890
|
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Replace the rendered spec without triggering a transition glide.
|
|
1893
|
+
* Checks structural signature — use `hotSwapPaint` when the caller
|
|
1894
|
+
* already knows the signature is unchanged (e.g. mid-morph lerp).
|
|
1895
|
+
*/
|
|
1896
|
+
hotSwapSpec(spec) {
|
|
1897
|
+
this.effSpec = spec;
|
|
1898
|
+
const sig = structuralSignature(this.effSpec);
|
|
1899
|
+
if (sig !== this.lastStructural) this.rebuild();
|
|
1900
|
+
else this.layers.forEach((b, i) => {
|
|
1901
|
+
b.layer = this.effSpec.layers[i] ?? b.layer;
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
/** Paint-only hot-swap: skips structuralSignature (caller guarantees match). */
|
|
1905
|
+
hotSwapPaint(spec) {
|
|
1906
|
+
this.effSpec = spec;
|
|
1907
|
+
this.layers.forEach((b, i) => {
|
|
1908
|
+
b.layer = this.effSpec.layers[i] ?? b.layer;
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1627
1911
|
dispose() {
|
|
1628
1912
|
this.stop();
|
|
1629
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
1913
|
+
if (this.ownsCanvas && typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
1630
1914
|
}
|
|
1631
1915
|
};
|
|
1632
1916
|
function compileSaver(spec) {
|
|
@@ -2345,6 +2629,34 @@ var DASHBOARD_SPEC = {
|
|
|
2345
2629
|
}
|
|
2346
2630
|
]
|
|
2347
2631
|
};
|
|
2632
|
+
var HAIKU_SPEC = {
|
|
2633
|
+
schemaVersion: 1,
|
|
2634
|
+
id: "haiku",
|
|
2635
|
+
label: "Haiku",
|
|
2636
|
+
seed: 42,
|
|
2637
|
+
background: { type: "solid", color: "#080812" },
|
|
2638
|
+
layers: [
|
|
2639
|
+
{
|
|
2640
|
+
count: 1,
|
|
2641
|
+
sprite: {
|
|
2642
|
+
kind: "textBlock",
|
|
2643
|
+
text: "An old silent pond\nA frog jumps into the pond \u2014\nSplash! Silence again.",
|
|
2644
|
+
maxWidth: 0.8,
|
|
2645
|
+
fontSize: 0.05,
|
|
2646
|
+
lineHeight: 1.8,
|
|
2647
|
+
align: "center",
|
|
2648
|
+
color: "#c8cad4"
|
|
2649
|
+
},
|
|
2650
|
+
motion: { type: "static" },
|
|
2651
|
+
position: { x: 0.1, y: 0.35 }
|
|
2652
|
+
},
|
|
2653
|
+
{
|
|
2654
|
+
count: 30,
|
|
2655
|
+
sprite: { kind: "circle", radius: [5e-4, 15e-4], color: "#3a3a5c" },
|
|
2656
|
+
motion: { type: "drift", speed: [2e-3, 6e-3], angle: 270 }
|
|
2657
|
+
}
|
|
2658
|
+
]
|
|
2659
|
+
};
|
|
2348
2660
|
var LANTERNS_SPEC = {
|
|
2349
2661
|
schemaVersion: 1,
|
|
2350
2662
|
id: "lanterns",
|
|
@@ -3017,7 +3329,8 @@ var SCHEMA_EXAMPLES = [
|
|
|
3017
3329
|
{ id: "polygons", label: "Polygons", spec: POLYGONS_SPEC },
|
|
3018
3330
|
{ id: "matrix-rain", label: "Matrix Rain", spec: MATRIX_RAIN_SPEC },
|
|
3019
3331
|
{ id: "procession", label: "Night Procession", spec: PROCESSION_SPEC },
|
|
3020
|
-
{ id: "nostalghia-candle", label: "Nostalghia's Candle", spec: NOSTALGHIA_CANDLE_SPEC }
|
|
3332
|
+
{ id: "nostalghia-candle", label: "Nostalghia's Candle", spec: NOSTALGHIA_CANDLE_SPEC },
|
|
3333
|
+
{ id: "haiku", label: "Haiku", spec: HAIKU_SPEC }
|
|
3021
3334
|
];
|
|
3022
3335
|
var EXAMPLE_SPECS = SCHEMA_EXAMPLES.map((e) => e.spec);
|
|
3023
3336
|
var EXAMPLE_BY_ID = Object.fromEntries(
|