@idle-screens/savers-classic 3.2.0 → 3.2.2
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/{chunk-GVD3Q4LE.js → chunk-ZF4KJIVM.js} +13 -1
- package/dist/chunk-ZF4KJIVM.js.map +1 -0
- package/dist/idle-worker.js +401 -101
- package/dist/idle-worker.js.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-GVD3Q4LE.js.map +0 -1
package/dist/idle-worker.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
reactionDiffusion,
|
|
12
12
|
spotlight,
|
|
13
13
|
warp
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-ZF4KJIVM.js";
|
|
15
15
|
|
|
16
16
|
// src/idle-worker.ts
|
|
17
17
|
import { runIdleWorker } from "@idle-screens/core";
|
|
@@ -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"]);
|
|
@@ -130,6 +247,14 @@ function validateSpec(spec) {
|
|
|
130
247
|
if (spec.units !== void 0 && spec.units !== "px" && spec.units !== "viewport") {
|
|
131
248
|
err("units", "must be 'px' | 'viewport'");
|
|
132
249
|
}
|
|
250
|
+
if (spec.units === "px" && Array.isArray(spec.layers)) {
|
|
251
|
+
for (const l of spec.layers) {
|
|
252
|
+
if (isObj(l) && isObj(l.sprite) && l.sprite.kind === "textBlock") {
|
|
253
|
+
err("units", "textBlock dimensions are viewport fractions \u2014 units: 'px' is not supported with textBlock sprites");
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
133
258
|
if (spec.referenceViewport !== void 0) {
|
|
134
259
|
if (!isNum(spec.referenceViewport) || spec.referenceViewport < 100 || spec.referenceViewport > 8640) {
|
|
135
260
|
err("referenceViewport", "must be a number between 100 and 8640");
|
|
@@ -156,7 +281,7 @@ function validateSpec(spec) {
|
|
|
156
281
|
return { valid: errors.length === 0, errors, warnings };
|
|
157
282
|
}
|
|
158
283
|
function color(v, path, err) {
|
|
159
|
-
if (!isStr(v) || !
|
|
284
|
+
if (!isStr(v) || !HEX2.test(v)) err(path, "must be a hex colour like #0a3a52");
|
|
160
285
|
}
|
|
161
286
|
function validateBackground(bg, err, warn) {
|
|
162
287
|
if (!isObj(bg)) return err("background", "must be an object");
|
|
@@ -429,8 +554,61 @@ function validateSprite(sprite, path, err, warn) {
|
|
|
429
554
|
}
|
|
430
555
|
color(sprite.color, `${path}.color`, err);
|
|
431
556
|
validatePalette(sprite, path, err);
|
|
557
|
+
} else if (sprite.kind === "textBlock") {
|
|
558
|
+
knownSet = KNOWN_TEXT_BLOCK;
|
|
559
|
+
if (typeof sprite.text !== "string" || sprite.text.length === 0) {
|
|
560
|
+
err(`${path}.text`, "must be a non-empty string");
|
|
561
|
+
} else if (sprite.text.length > LIMITS.maxTextBlockLength) {
|
|
562
|
+
err(`${path}.text`, `must be at most ${LIMITS.maxTextBlockLength} characters`);
|
|
563
|
+
}
|
|
564
|
+
if (!isNum(sprite.maxWidth) || sprite.maxWidth <= 0 || sprite.maxWidth > LIMITS.maxTextBlockMaxWidth) {
|
|
565
|
+
err(`${path}.maxWidth`, `must be a positive number up to ${LIMITS.maxTextBlockMaxWidth} (viewport fraction)`);
|
|
566
|
+
}
|
|
567
|
+
if (!isNum(sprite.fontSize) || sprite.fontSize < LIMITS.minTextBlockFontSize || sprite.fontSize > LIMITS.maxTextBlockFontSize) {
|
|
568
|
+
err(`${path}.fontSize`, `must be between ${LIMITS.minTextBlockFontSize} and ${LIMITS.maxTextBlockFontSize} (viewport fraction)`);
|
|
569
|
+
}
|
|
570
|
+
if (sprite.lineHeight !== void 0 && (!isNum(sprite.lineHeight) || sprite.lineHeight < 0.5 || sprite.lineHeight > 4)) {
|
|
571
|
+
err(`${path}.lineHeight`, "must be between 0.5 and 4 (multiplier)");
|
|
572
|
+
}
|
|
573
|
+
if (sprite.align !== void 0 && !["left", "center", "right"].includes(sprite.align)) {
|
|
574
|
+
err(`${path}.align`, "must be 'left' | 'center' | 'right'");
|
|
575
|
+
}
|
|
576
|
+
if (sprite.color !== void 0) color(sprite.color, `${path}.color`, err);
|
|
577
|
+
if (sprite.reveal !== void 0) {
|
|
578
|
+
const rv = sprite.reveal;
|
|
579
|
+
if (typeof rv !== "object" || rv === null || Array.isArray(rv)) {
|
|
580
|
+
err(`${path}.reveal`, "must be an object");
|
|
581
|
+
} else {
|
|
582
|
+
for (const k of Object.keys(rv)) {
|
|
583
|
+
if (!KNOWN_REVEAL.has(k)) err(`${path}.reveal.${k}`, "unknown reveal field");
|
|
584
|
+
}
|
|
585
|
+
if (rv.progress !== void 0 && (!isNum(rv.progress) || rv.progress < 0 || rv.progress > 1)) {
|
|
586
|
+
err(`${path}.reveal.progress`, "must be a number between 0 and 1");
|
|
587
|
+
}
|
|
588
|
+
if (rv.mode !== void 0 && !["typewriter", "word", "line"].includes(rv.mode)) {
|
|
589
|
+
err(`${path}.reveal.mode`, "must be 'typewriter' | 'word' | 'line'");
|
|
590
|
+
}
|
|
591
|
+
if (rv.speed !== void 0 && (!isNum(rv.speed) || rv.speed < 0 || rv.speed > LIMITS.maxRevealSpeed)) {
|
|
592
|
+
err(`${path}.reveal.speed`, `must be between 0 and ${LIMITS.maxRevealSpeed} (graphemes/sec)`);
|
|
593
|
+
}
|
|
594
|
+
if (rv.caret !== void 0 && typeof rv.caret !== "boolean") {
|
|
595
|
+
const caret = rv.caret;
|
|
596
|
+
if (typeof caret !== "object" || caret === null || Array.isArray(caret)) {
|
|
597
|
+
err(`${path}.reveal.caret`, "must be a boolean or an object");
|
|
598
|
+
} else {
|
|
599
|
+
for (const k of Object.keys(caret)) {
|
|
600
|
+
if (!KNOWN_REVEAL_CARET.has(k)) err(`${path}.reveal.caret.${k}`, "unknown caret field");
|
|
601
|
+
}
|
|
602
|
+
if (caret.blink !== void 0 && (!isNum(caret.blink) || caret.blink <= 0 || caret.blink > LIMITS.maxCaretBlinkHz)) {
|
|
603
|
+
err(`${path}.reveal.caret.blink`, `must be between 0 (exclusive) and ${LIMITS.maxCaretBlinkHz} Hz (flash safety)`);
|
|
604
|
+
}
|
|
605
|
+
if (caret.color !== void 0) color(caret.color, `${path}.reveal.caret.color`, err);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
432
610
|
} else {
|
|
433
|
-
err(`${path}.kind`, "must be emoji | text | circle | ring | streak | rect");
|
|
611
|
+
err(`${path}.kind`, "must be emoji | text | circle | ring | streak | rect | textBlock");
|
|
434
612
|
return;
|
|
435
613
|
}
|
|
436
614
|
for (const k of unknownKeys(sprite, knownSet)) {
|
|
@@ -680,7 +858,7 @@ function buildEntities(layer, rng, w, h, scale = 1, countScale = 1) {
|
|
|
680
858
|
}
|
|
681
859
|
const out = [];
|
|
682
860
|
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;
|
|
861
|
+
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
862
|
const size2 = sprite.kind === "rect" ? size * (sprite.aspect ? rng.range(sprite.aspect[0], sprite.aspect[1]) : 1) : void 0;
|
|
685
863
|
let vx = 0;
|
|
686
864
|
let vy = 0;
|
|
@@ -1064,106 +1242,137 @@ function linkPairs(positions, k, maxDist, doWrap, w, h) {
|
|
|
1064
1242
|
}
|
|
1065
1243
|
return out;
|
|
1066
1244
|
}
|
|
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;
|
|
1245
|
+
var CHAR_NARROW = new Set(`iIljtf1!|.,;:'"()[]{}`);
|
|
1246
|
+
var CHAR_WIDE = new Set("mwMWGOQD@%");
|
|
1247
|
+
function charWidthEm(ch) {
|
|
1248
|
+
if (ch === " " || ch === " ") return 0.3;
|
|
1249
|
+
if (CHAR_NARROW.has(ch)) return 0.35;
|
|
1250
|
+
if (CHAR_WIDE.has(ch)) return 0.72;
|
|
1251
|
+
return 0.55;
|
|
1088
1252
|
}
|
|
1089
|
-
function
|
|
1090
|
-
|
|
1091
|
-
for (
|
|
1092
|
-
|
|
1093
|
-
|
|
1253
|
+
function textWidthEm(str) {
|
|
1254
|
+
let w = 0;
|
|
1255
|
+
for (let i = 0; i < str.length; i++) w += charWidthEm(str[i]);
|
|
1256
|
+
return w;
|
|
1257
|
+
}
|
|
1258
|
+
function breakTextBlock(text, maxWidthEm) {
|
|
1259
|
+
const paragraphs = text.split("\n");
|
|
1260
|
+
const lines = [];
|
|
1261
|
+
for (const para of paragraphs) {
|
|
1262
|
+
if (para.length === 0) {
|
|
1263
|
+
lines.push({ text: "", widthEm: 0 });
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
const words = para.split(/\s+/).filter((w) => w.length > 0);
|
|
1267
|
+
if (words.length === 0) {
|
|
1268
|
+
lines.push({ text: "", widthEm: 0 });
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
let lineText = words[0];
|
|
1272
|
+
let lineW = textWidthEm(lineText);
|
|
1273
|
+
const spaceW = charWidthEm(" ");
|
|
1274
|
+
for (let i = 1; i < words.length; i++) {
|
|
1275
|
+
const word = words[i];
|
|
1276
|
+
const wordW = textWidthEm(word);
|
|
1277
|
+
if (lineW + spaceW + wordW <= maxWidthEm) {
|
|
1278
|
+
lineText += " " + word;
|
|
1279
|
+
lineW += spaceW + wordW;
|
|
1280
|
+
} else {
|
|
1281
|
+
lines.push({ text: lineText, widthEm: lineW });
|
|
1282
|
+
lineText = word;
|
|
1283
|
+
lineW = wordW;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
lines.push({ text: lineText, widthEm: lineW });
|
|
1094
1287
|
}
|
|
1095
|
-
return
|
|
1288
|
+
return lines;
|
|
1096
1289
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1290
|
+
function isClusterExtend(cp) {
|
|
1291
|
+
return cp >= 768 && cp <= 879 || // combining diacritics
|
|
1292
|
+
cp >= 6832 && cp <= 6911 || cp >= 8400 && cp <= 8447 || cp >= 65024 && cp <= 65039 || // variation selectors
|
|
1293
|
+
cp >= 127995 && cp <= 127999 || // skin tones
|
|
1294
|
+
cp === 8419;
|
|
1102
1295
|
}
|
|
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("")}`;
|
|
1296
|
+
function isRegionalIndicator(cp) {
|
|
1297
|
+
return cp >= 127462 && cp <= 127487;
|
|
1108
1298
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
if (
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1299
|
+
var ZWJ = 8205;
|
|
1300
|
+
function graphemeClusters(text) {
|
|
1301
|
+
const out = [];
|
|
1302
|
+
let i = 0;
|
|
1303
|
+
while (i < text.length) {
|
|
1304
|
+
const cp = text.codePointAt(i);
|
|
1305
|
+
let end = i + (cp > 65535 ? 2 : 1);
|
|
1306
|
+
if (isRegionalIndicator(cp) && end < text.length) {
|
|
1307
|
+
const next = text.codePointAt(end);
|
|
1308
|
+
if (isRegionalIndicator(next)) end += next > 65535 ? 2 : 1;
|
|
1309
|
+
}
|
|
1310
|
+
while (end < text.length) {
|
|
1311
|
+
const next = text.codePointAt(end);
|
|
1312
|
+
if (isClusterExtend(next)) {
|
|
1313
|
+
end += next > 65535 ? 2 : 1;
|
|
1314
|
+
} else if (next === ZWJ && end + 1 < text.length) {
|
|
1315
|
+
const after = text.codePointAt(end + 1);
|
|
1316
|
+
end += 1 + (after > 65535 ? 2 : 1);
|
|
1317
|
+
} else {
|
|
1318
|
+
break;
|
|
1126
1319
|
}
|
|
1127
|
-
return out;
|
|
1128
1320
|
}
|
|
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);
|
|
1321
|
+
out.push(text.slice(i, end));
|
|
1322
|
+
i = end;
|
|
1323
|
+
}
|
|
1324
|
+
return out;
|
|
1136
1325
|
}
|
|
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
|
-
|
|
1326
|
+
function revealState(lines, reveal, tMs) {
|
|
1327
|
+
const lineClusters = lines.map((l) => graphemeClusters(l.text));
|
|
1328
|
+
const totalGraphemes = lineClusters.reduce((n, c) => n + c.length, 0);
|
|
1329
|
+
const authored = Math.max(0, Math.min(1, reveal.progress ?? 1));
|
|
1330
|
+
const speed = reveal.speed ?? 0;
|
|
1331
|
+
const timed = speed > 0 && totalGraphemes > 0 ? Math.min(1, speed * tMs / 1e3 / totalGraphemes) : 1;
|
|
1332
|
+
const progress = Math.min(authored, timed);
|
|
1333
|
+
const mode = reveal.mode ?? "typewriter";
|
|
1334
|
+
let fullLines = 0;
|
|
1335
|
+
let partialText = "";
|
|
1336
|
+
if (mode === "line") {
|
|
1337
|
+
fullLines = Math.round(progress * lines.length);
|
|
1338
|
+
} else if (mode === "word") {
|
|
1339
|
+
const lineWords = lines.map((l) => l.text.length === 0 ? [] : l.text.split(" "));
|
|
1340
|
+
const totalWords = lineWords.reduce((n, ws) => n + ws.length, 0);
|
|
1341
|
+
let remaining = Math.round(progress * totalWords);
|
|
1342
|
+
for (const ws of lineWords) {
|
|
1343
|
+
if (remaining >= ws.length) {
|
|
1344
|
+
remaining -= ws.length;
|
|
1345
|
+
fullLines++;
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
if (remaining > 0) partialText = ws.slice(0, remaining).join(" ");
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
} else {
|
|
1352
|
+
let remaining = Math.round(progress * totalGraphemes);
|
|
1353
|
+
for (const clusters of lineClusters) {
|
|
1354
|
+
if (remaining >= clusters.length) {
|
|
1355
|
+
remaining -= clusters.length;
|
|
1356
|
+
fullLines++;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (remaining > 0) partialText = clusters.slice(0, remaining).join("");
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
let caretLine;
|
|
1364
|
+
let caretPrefix;
|
|
1365
|
+
if (partialText.length > 0) {
|
|
1366
|
+
caretLine = fullLines;
|
|
1367
|
+
caretPrefix = partialText;
|
|
1368
|
+
} else if (fullLines > 0) {
|
|
1369
|
+
caretLine = fullLines - 1;
|
|
1370
|
+
caretPrefix = lines[fullLines - 1].text;
|
|
1371
|
+
} else {
|
|
1372
|
+
caretLine = 0;
|
|
1373
|
+
caretPrefix = "";
|
|
1374
|
+
}
|
|
1375
|
+
return { progress, fullLines, partialText, caretLine, caretPrefix };
|
|
1167
1376
|
}
|
|
1168
1377
|
var DEFAULT_STEER_DUR = 1e3;
|
|
1169
1378
|
function hexToRgba(hex, alpha) {
|
|
@@ -1211,12 +1420,14 @@ var SpecInstance = class {
|
|
|
1211
1420
|
let canvas;
|
|
1212
1421
|
if (ctx.surface) {
|
|
1213
1422
|
canvas = ctx.surface;
|
|
1423
|
+
this.ownsCanvas = false;
|
|
1214
1424
|
} else {
|
|
1215
1425
|
const el = document.createElement("canvas");
|
|
1216
1426
|
el.style.cssText = "display:block;width:100%;height:100%";
|
|
1217
1427
|
el.setAttribute("aria-hidden", "true");
|
|
1218
1428
|
ctx.host.appendChild(el);
|
|
1219
1429
|
canvas = el;
|
|
1430
|
+
this.ownsCanvas = true;
|
|
1220
1431
|
}
|
|
1221
1432
|
this.canvas = canvas;
|
|
1222
1433
|
const c2d = canvas.getContext("2d", { alpha: false });
|
|
@@ -1232,6 +1443,7 @@ var SpecInstance = class {
|
|
|
1232
1443
|
}
|
|
1233
1444
|
spec;
|
|
1234
1445
|
canvas;
|
|
1446
|
+
ownsCanvas;
|
|
1235
1447
|
ctx;
|
|
1236
1448
|
saverCtx;
|
|
1237
1449
|
seed;
|
|
@@ -1350,7 +1562,7 @@ var SpecInstance = class {
|
|
|
1350
1562
|
const headAlpha = alphaAt(e, t) * lifeA;
|
|
1351
1563
|
const headSize = sizeAt(e, t);
|
|
1352
1564
|
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";
|
|
1565
|
+
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
1566
|
const isSoft = sprite.kind === "circle" && sprite.soft;
|
|
1355
1567
|
const wrap2 = built.layer.wrap !== false;
|
|
1356
1568
|
const head = this.entityPos(e, t, parentE);
|
|
@@ -1457,6 +1669,45 @@ var SpecInstance = class {
|
|
|
1457
1669
|
ctx.restore();
|
|
1458
1670
|
return;
|
|
1459
1671
|
}
|
|
1672
|
+
if (sprite.kind === "textBlock") {
|
|
1673
|
+
const unitScale2 = Math.min(this.w, this.h);
|
|
1674
|
+
const fsPx = sprite.fontSize * unitScale2;
|
|
1675
|
+
const lh = (sprite.lineHeight ?? 1.4) * fsPx;
|
|
1676
|
+
const maxWPx = sprite.maxWidth * unitScale2;
|
|
1677
|
+
const maxWEm = maxWPx / fsPx;
|
|
1678
|
+
const lines = breakTextBlock(sprite.text, maxWEm);
|
|
1679
|
+
const align = sprite.align ?? "left";
|
|
1680
|
+
const reveal = sprite.reveal;
|
|
1681
|
+
const rs = reveal ? revealState(lines, reveal, t) : null;
|
|
1682
|
+
const fullLines = rs ? rs.fullLines : lines.length;
|
|
1683
|
+
ctx.save();
|
|
1684
|
+
ctx.translate(p.x, p.y);
|
|
1685
|
+
if (rot) ctx.rotate(rot);
|
|
1686
|
+
ctx.font = `${fsPx}px system-ui, sans-serif`;
|
|
1687
|
+
ctx.fillStyle = sprite.color ?? "#e6e8ef";
|
|
1688
|
+
ctx.textBaseline = "top";
|
|
1689
|
+
ctx.textAlign = align;
|
|
1690
|
+
const xOff = align === "center" ? maxWPx / 2 : align === "right" ? maxWPx : 0;
|
|
1691
|
+
for (let li = 0; li < fullLines; li++) {
|
|
1692
|
+
ctx.fillText(lines[li].text, xOff, li * lh);
|
|
1693
|
+
}
|
|
1694
|
+
if (rs && rs.partialText.length > 0) {
|
|
1695
|
+
ctx.fillText(rs.partialText, xOff, fullLines * lh);
|
|
1696
|
+
}
|
|
1697
|
+
if (rs && reveal.caret) {
|
|
1698
|
+
const cfg = reveal.caret === true ? {} : reveal.caret;
|
|
1699
|
+
const hz = Math.min(3, cfg.blink ?? 1.2);
|
|
1700
|
+
const on = hz <= 0 || Math.floor(t / 1e3 * hz * 2) % 2 === 0;
|
|
1701
|
+
if (on) {
|
|
1702
|
+
const pw = ctx.measureText(rs.caretPrefix).width;
|
|
1703
|
+
const cx = align === "center" ? xOff + pw / 2 : align === "right" ? xOff : pw;
|
|
1704
|
+
ctx.fillStyle = cfg.color ?? sprite.color ?? "#e6e8ef";
|
|
1705
|
+
ctx.fillRect(cx + fsPx * 0.06, rs.caretLine * lh, Math.max(1, fsPx * 0.08), fsPx);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
ctx.restore();
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1460
1711
|
ctx.save();
|
|
1461
1712
|
ctx.translate(p.x, p.y);
|
|
1462
1713
|
if (rot) ctx.rotate(rot);
|
|
@@ -1624,9 +1875,29 @@ var SpecInstance = class {
|
|
|
1624
1875
|
this.rebuild();
|
|
1625
1876
|
if (this.paused) this.renderFrame(0, this.seed);
|
|
1626
1877
|
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Replace the rendered spec without triggering a transition glide.
|
|
1880
|
+
* Checks structural signature — use `hotSwapPaint` when the caller
|
|
1881
|
+
* already knows the signature is unchanged (e.g. mid-morph lerp).
|
|
1882
|
+
*/
|
|
1883
|
+
hotSwapSpec(spec) {
|
|
1884
|
+
this.effSpec = spec;
|
|
1885
|
+
const sig = structuralSignature(this.effSpec);
|
|
1886
|
+
if (sig !== this.lastStructural) this.rebuild();
|
|
1887
|
+
else this.layers.forEach((b, i) => {
|
|
1888
|
+
b.layer = this.effSpec.layers[i] ?? b.layer;
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
/** Paint-only hot-swap: skips structuralSignature (caller guarantees match). */
|
|
1892
|
+
hotSwapPaint(spec) {
|
|
1893
|
+
this.effSpec = spec;
|
|
1894
|
+
this.layers.forEach((b, i) => {
|
|
1895
|
+
b.layer = this.effSpec.layers[i] ?? b.layer;
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1627
1898
|
dispose() {
|
|
1628
1899
|
this.stop();
|
|
1629
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
1900
|
+
if (this.ownsCanvas && typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
1630
1901
|
}
|
|
1631
1902
|
};
|
|
1632
1903
|
function compileSaver(spec) {
|
|
@@ -2345,6 +2616,34 @@ var DASHBOARD_SPEC = {
|
|
|
2345
2616
|
}
|
|
2346
2617
|
]
|
|
2347
2618
|
};
|
|
2619
|
+
var HAIKU_SPEC = {
|
|
2620
|
+
schemaVersion: 1,
|
|
2621
|
+
id: "haiku",
|
|
2622
|
+
label: "Haiku",
|
|
2623
|
+
seed: 42,
|
|
2624
|
+
background: { type: "solid", color: "#080812" },
|
|
2625
|
+
layers: [
|
|
2626
|
+
{
|
|
2627
|
+
count: 1,
|
|
2628
|
+
sprite: {
|
|
2629
|
+
kind: "textBlock",
|
|
2630
|
+
text: "An old silent pond\nA frog jumps into the pond \u2014\nSplash! Silence again.",
|
|
2631
|
+
maxWidth: 0.8,
|
|
2632
|
+
fontSize: 0.05,
|
|
2633
|
+
lineHeight: 1.8,
|
|
2634
|
+
align: "center",
|
|
2635
|
+
color: "#c8cad4"
|
|
2636
|
+
},
|
|
2637
|
+
motion: { type: "static" },
|
|
2638
|
+
position: { x: 0.1, y: 0.35 }
|
|
2639
|
+
},
|
|
2640
|
+
{
|
|
2641
|
+
count: 30,
|
|
2642
|
+
sprite: { kind: "circle", radius: [5e-4, 15e-4], color: "#3a3a5c" },
|
|
2643
|
+
motion: { type: "drift", speed: [2e-3, 6e-3], angle: 270 }
|
|
2644
|
+
}
|
|
2645
|
+
]
|
|
2646
|
+
};
|
|
2348
2647
|
var LANTERNS_SPEC = {
|
|
2349
2648
|
schemaVersion: 1,
|
|
2350
2649
|
id: "lanterns",
|
|
@@ -3017,7 +3316,8 @@ var SCHEMA_EXAMPLES = [
|
|
|
3017
3316
|
{ id: "polygons", label: "Polygons", spec: POLYGONS_SPEC },
|
|
3018
3317
|
{ id: "matrix-rain", label: "Matrix Rain", spec: MATRIX_RAIN_SPEC },
|
|
3019
3318
|
{ id: "procession", label: "Night Procession", spec: PROCESSION_SPEC },
|
|
3020
|
-
{ id: "nostalghia-candle", label: "Nostalghia's Candle", spec: NOSTALGHIA_CANDLE_SPEC }
|
|
3319
|
+
{ id: "nostalghia-candle", label: "Nostalghia's Candle", spec: NOSTALGHIA_CANDLE_SPEC },
|
|
3320
|
+
{ id: "haiku", label: "Haiku", spec: HAIKU_SPEC }
|
|
3021
3321
|
];
|
|
3022
3322
|
var EXAMPLE_SPECS = SCHEMA_EXAMPLES.map((e) => e.spec);
|
|
3023
3323
|
var EXAMPLE_BY_ID = Object.fromEntries(
|