@idle-screens/savers-classic 1.0.0 → 2.0.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/chunk-MIVXP2IL.js +3232 -0
- package/dist/chunk-MIVXP2IL.js.map +1 -0
- package/dist/idle-worker.js +1346 -8
- package/dist/idle-worker.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +9 -1971
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-5EPTQV3C.js +0 -965
- package/dist/chunk-5EPTQV3C.js.map +0 -1
package/dist/chunk-5EPTQV3C.js
DELETED
|
@@ -1,965 +0,0 @@
|
|
|
1
|
-
// src/warp.ts
|
|
2
|
-
var warpManifest = {
|
|
3
|
-
id: "warp",
|
|
4
|
-
label: "Warp",
|
|
5
|
-
passthrough: false,
|
|
6
|
-
minBackend: "canvas2d",
|
|
7
|
-
costTier: "low",
|
|
8
|
-
motionIntensity: "energetic",
|
|
9
|
-
reducedMotionFallback: "static",
|
|
10
|
-
a11y: { flashSafe: true },
|
|
11
|
-
workerReady: true
|
|
12
|
-
};
|
|
13
|
-
var STAR_COUNT = 520;
|
|
14
|
-
var SPEED = 0.012;
|
|
15
|
-
var WarpInstance = class {
|
|
16
|
-
ctxSaver;
|
|
17
|
-
canvas;
|
|
18
|
-
ctx;
|
|
19
|
-
w = 0;
|
|
20
|
-
h = 0;
|
|
21
|
-
stars = [];
|
|
22
|
-
frameId = null;
|
|
23
|
-
paused = false;
|
|
24
|
-
constructor(ctx) {
|
|
25
|
-
this.ctxSaver = ctx;
|
|
26
|
-
let canvas;
|
|
27
|
-
if (ctx.surface) {
|
|
28
|
-
canvas = ctx.surface;
|
|
29
|
-
} else {
|
|
30
|
-
const el = document.createElement("canvas");
|
|
31
|
-
el.style.cssText = "display:block;width:100%;height:100%";
|
|
32
|
-
el.setAttribute("aria-hidden", "true");
|
|
33
|
-
ctx.host.appendChild(el);
|
|
34
|
-
canvas = el;
|
|
35
|
-
}
|
|
36
|
-
this.canvas = canvas;
|
|
37
|
-
const c2d = canvas.getContext("2d", { alpha: false });
|
|
38
|
-
if (!c2d) throw new Error("warp: no 2d context");
|
|
39
|
-
this.ctx = c2d;
|
|
40
|
-
this.w = ctx.width;
|
|
41
|
-
this.h = ctx.height;
|
|
42
|
-
this.sizeCanvas();
|
|
43
|
-
this.buildStars();
|
|
44
|
-
this.paused = ctx.reducedMotion;
|
|
45
|
-
if (this.paused) this.renderStill();
|
|
46
|
-
else this.start();
|
|
47
|
-
}
|
|
48
|
-
sizeCanvas() {
|
|
49
|
-
const dpr = Math.min(this.ctxSaver.dpr, 2);
|
|
50
|
-
this.canvas.width = Math.max(1, Math.round(this.w * dpr));
|
|
51
|
-
this.canvas.height = Math.max(1, Math.round(this.h * dpr));
|
|
52
|
-
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
53
|
-
}
|
|
54
|
-
buildStars() {
|
|
55
|
-
const rng = this.ctxSaver.rng;
|
|
56
|
-
this.stars = new Array(STAR_COUNT);
|
|
57
|
-
for (let i = 0; i < STAR_COUNT; i++) {
|
|
58
|
-
this.stars[i] = this.spawn(rng.range(0.01, 1));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
spawn(z) {
|
|
62
|
-
const rng = this.ctxSaver.rng;
|
|
63
|
-
return {
|
|
64
|
-
x: rng.range(-1, 1),
|
|
65
|
-
y: rng.range(-1, 1),
|
|
66
|
-
z,
|
|
67
|
-
pz: z
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
start() {
|
|
71
|
-
if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
|
|
72
|
-
this.loop();
|
|
73
|
-
}
|
|
74
|
-
stop() {
|
|
75
|
-
if (this.frameId !== null) {
|
|
76
|
-
cancelAnimationFrame(this.frameId);
|
|
77
|
-
this.frameId = null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
loop() {
|
|
81
|
-
this.frameId = requestAnimationFrame(() => this.loop());
|
|
82
|
-
this.step();
|
|
83
|
-
this.render();
|
|
84
|
-
}
|
|
85
|
-
step() {
|
|
86
|
-
for (const s of this.stars) {
|
|
87
|
-
s.pz = s.z;
|
|
88
|
-
s.z -= SPEED;
|
|
89
|
-
if (s.z <= 0.01) {
|
|
90
|
-
const respawned = this.spawn(1);
|
|
91
|
-
s.x = respawned.x;
|
|
92
|
-
s.y = respawned.y;
|
|
93
|
-
s.z = 1;
|
|
94
|
-
s.pz = 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
render() {
|
|
99
|
-
const ctx = this.ctx;
|
|
100
|
-
const w = this.w;
|
|
101
|
-
const h = this.h;
|
|
102
|
-
const cx = w / 2;
|
|
103
|
-
const cy = h / 2;
|
|
104
|
-
const focal = Math.min(w, h) * 0.9;
|
|
105
|
-
ctx.fillStyle = "rgba(17,17,17,0.45)";
|
|
106
|
-
ctx.fillRect(0, 0, w, h);
|
|
107
|
-
ctx.lineCap = "round";
|
|
108
|
-
for (const s of this.stars) {
|
|
109
|
-
const sx = cx + s.x / s.z * focal;
|
|
110
|
-
const sy = cy + s.y / s.z * focal;
|
|
111
|
-
const px = cx + s.x / s.pz * focal;
|
|
112
|
-
const py = cy + s.y / s.pz * focal;
|
|
113
|
-
if (sx < -50 || sx > w + 50 || sy < -50 || sy > h + 50) continue;
|
|
114
|
-
const depth = 1 - s.z;
|
|
115
|
-
const alpha = Math.min(1, 0.15 + depth * 1.1);
|
|
116
|
-
const size = Math.max(0.4, depth * 2.6);
|
|
117
|
-
ctx.strokeStyle = `rgba(220,235,255,${alpha.toFixed(3)})`;
|
|
118
|
-
ctx.lineWidth = size;
|
|
119
|
-
ctx.beginPath();
|
|
120
|
-
ctx.moveTo(px, py);
|
|
121
|
-
ctx.lineTo(sx, sy);
|
|
122
|
-
ctx.stroke();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
renderStill() {
|
|
126
|
-
const ctx = this.ctx;
|
|
127
|
-
ctx.fillStyle = "#111";
|
|
128
|
-
ctx.fillRect(0, 0, this.w, this.h);
|
|
129
|
-
const cx = this.w / 2;
|
|
130
|
-
const cy = this.h / 2;
|
|
131
|
-
const focal = Math.min(this.w, this.h) * 0.9;
|
|
132
|
-
for (const s of this.stars) {
|
|
133
|
-
const sx = cx + s.x / s.z * focal;
|
|
134
|
-
const sy = cy + s.y / s.z * focal;
|
|
135
|
-
if (sx < 0 || sx > this.w || sy < 0 || sy > this.h) continue;
|
|
136
|
-
const depth = 1 - s.z;
|
|
137
|
-
const alpha = Math.min(1, 0.15 + depth * 1.1);
|
|
138
|
-
const size = Math.max(0.4, depth * 2.6);
|
|
139
|
-
ctx.fillStyle = `rgba(220,235,255,${alpha.toFixed(3)})`;
|
|
140
|
-
ctx.beginPath();
|
|
141
|
-
ctx.arc(sx, sy, size, 0, Math.PI * 2);
|
|
142
|
-
ctx.fill();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
setPaused(paused) {
|
|
146
|
-
this.paused = paused;
|
|
147
|
-
if (paused) {
|
|
148
|
-
this.stop();
|
|
149
|
-
this.renderStill();
|
|
150
|
-
} else {
|
|
151
|
-
this.start();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
resize(width, height, dpr) {
|
|
155
|
-
this.w = width;
|
|
156
|
-
this.h = height;
|
|
157
|
-
if (dpr !== void 0) this.ctxSaver.dpr = dpr;
|
|
158
|
-
this.sizeCanvas();
|
|
159
|
-
if (this.paused) this.renderStill();
|
|
160
|
-
}
|
|
161
|
-
dispose() {
|
|
162
|
-
this.stop();
|
|
163
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
var warp = {
|
|
167
|
-
manifest: warpManifest,
|
|
168
|
-
mount: (ctx) => new WarpInstance(ctx)
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// src/hard-rain.ts
|
|
172
|
-
var hardRainManifest = {
|
|
173
|
-
id: "hard-rain",
|
|
174
|
-
label: "Hard Rain",
|
|
175
|
-
passthrough: false,
|
|
176
|
-
minBackend: "canvas2d",
|
|
177
|
-
costTier: "low",
|
|
178
|
-
motionIntensity: "moderate",
|
|
179
|
-
reducedMotionFallback: "static",
|
|
180
|
-
a11y: { flashSafe: true, notes: "Slow-expanding coloured rings on black; no flashing." },
|
|
181
|
-
workerReady: true
|
|
182
|
-
};
|
|
183
|
-
var CYCLE = 4500;
|
|
184
|
-
var POSITIONS = {
|
|
185
|
-
"p0-1": [0.05, -0.02],
|
|
186
|
-
"p0-2": [0.25, -0.17],
|
|
187
|
-
"p0-3": [0.45, 0.04],
|
|
188
|
-
"p0-4": [0.65, -0.04],
|
|
189
|
-
"p0-5": [0.85, 0.01],
|
|
190
|
-
"p1-1": [0.05, 0.18],
|
|
191
|
-
"p1-2": [0.25, 0.07],
|
|
192
|
-
"p1-3": [0.45, 0.24],
|
|
193
|
-
"p1-4": [0.65, 0.16],
|
|
194
|
-
"p1-5": [0.85, 0.21],
|
|
195
|
-
"p2-1": [0.15, 0.38],
|
|
196
|
-
"p2-2": [0.35, 0.27],
|
|
197
|
-
"p2-3": [0.55, 0.44],
|
|
198
|
-
"p2-4": [0.75, 0.36],
|
|
199
|
-
"p2-5": [0.95, 0.41],
|
|
200
|
-
"p3-1": [0.05, 0.58],
|
|
201
|
-
"p3-2": [0.25, 0.47],
|
|
202
|
-
"p3-3": [0.45, 0.64],
|
|
203
|
-
"p3-4": [0.65, 0.56],
|
|
204
|
-
"p3-5": [0.85, 0.61],
|
|
205
|
-
"p4-1": [0.15, 0.78],
|
|
206
|
-
"p4-2": [0.35, 0.67],
|
|
207
|
-
"p4-3": [0.55, 0.84],
|
|
208
|
-
"p4-4": [0.75, 0.76],
|
|
209
|
-
"p4-5": [0.95, 0.81],
|
|
210
|
-
"p5-1": [0.15, 0.98],
|
|
211
|
-
"p5-2": [0.35, 0.87],
|
|
212
|
-
"p5-3": [0.55, 1.04],
|
|
213
|
-
"p5-4": [0.75, 0.96],
|
|
214
|
-
"p5-5": [0.95, 1.01]
|
|
215
|
-
};
|
|
216
|
-
var SIZES = { s140: 70, s200: 100, s250: 125, s300: 150, s350: 175 };
|
|
217
|
-
var COLOURS = {
|
|
218
|
-
dkblue: "#00006e",
|
|
219
|
-
lime: "#c8d354",
|
|
220
|
-
ltgray: "#c2c2c2",
|
|
221
|
-
red: "#861f23",
|
|
222
|
-
ltblue: "#45a0cc",
|
|
223
|
-
pink: "#9a3368",
|
|
224
|
-
yellow: "#efda1d",
|
|
225
|
-
green: "#397132"
|
|
226
|
-
};
|
|
227
|
-
function timingPhase(t) {
|
|
228
|
-
const map = {
|
|
229
|
-
t1: -4.35,
|
|
230
|
-
t2: -4.2,
|
|
231
|
-
t3: -4.05,
|
|
232
|
-
t4: -3.9,
|
|
233
|
-
t5: -3.75,
|
|
234
|
-
t6: -3.6,
|
|
235
|
-
t7: -3.45,
|
|
236
|
-
t8: -3.3,
|
|
237
|
-
t9: -3.15,
|
|
238
|
-
t10: -3,
|
|
239
|
-
t11: -2.85,
|
|
240
|
-
t12: -2.7,
|
|
241
|
-
t13: -2.55,
|
|
242
|
-
t14: -2.4,
|
|
243
|
-
t15: -2.25,
|
|
244
|
-
t16: -2.1,
|
|
245
|
-
t17: -1.95,
|
|
246
|
-
t18: -1.8,
|
|
247
|
-
t19: -1.65,
|
|
248
|
-
t20: -1.5,
|
|
249
|
-
t21: -1.35,
|
|
250
|
-
t22: -1.2,
|
|
251
|
-
t23: -1.05,
|
|
252
|
-
t24: -0.9,
|
|
253
|
-
t25: -0.75,
|
|
254
|
-
t26: -0.6,
|
|
255
|
-
t27: -0.45,
|
|
256
|
-
t28: 0.3,
|
|
257
|
-
t29: -0.15,
|
|
258
|
-
t30: 0
|
|
259
|
-
};
|
|
260
|
-
return (map[t] ?? 0) * 1e3;
|
|
261
|
-
}
|
|
262
|
-
var DROP_SPECS = [
|
|
263
|
-
"t7 p0-1 s200 dkblue",
|
|
264
|
-
"t23 p0-2 s350 lime",
|
|
265
|
-
"t17 p0-3 s140 ltgray",
|
|
266
|
-
"t11 p0-4 s300 red",
|
|
267
|
-
"t14 p0-5 s250 ltblue",
|
|
268
|
-
"t29 p1-1 s350 pink",
|
|
269
|
-
"t18 p1-2 s300 yellow",
|
|
270
|
-
"t30 p1-3 s140 green",
|
|
271
|
-
"t12 p1-4 s200 ltgray",
|
|
272
|
-
"t27 p1-5 s250 dkblue",
|
|
273
|
-
"t10 p2-1 s140 pink",
|
|
274
|
-
"t4 p2-2 s200 red",
|
|
275
|
-
"t8 p2-3 s300 ltblue",
|
|
276
|
-
"t22 p2-4 s350 yellow",
|
|
277
|
-
"t1 p2-5 s250 lime",
|
|
278
|
-
"t3 p3-1 s300 green",
|
|
279
|
-
"t6 p3-2 s250 dkblue",
|
|
280
|
-
"t15 p3-3 s350 ltgray",
|
|
281
|
-
"t24 p3-4 s140 pink",
|
|
282
|
-
"t21 p3-5 s200 ltblue",
|
|
283
|
-
"t13 p4-1 s250 yellow",
|
|
284
|
-
"t28 p4-2 s140 red",
|
|
285
|
-
"t2 p4-3 s200 ltgray",
|
|
286
|
-
"t19 p4-4 s300 green",
|
|
287
|
-
"t25 p4-5 s350 lime",
|
|
288
|
-
"t5 p5-1 s350 dkblue",
|
|
289
|
-
"t26 p5-2 s300 pink",
|
|
290
|
-
"t20 p5-3 s140 ltblue",
|
|
291
|
-
"t16 p5-4 s250 yellow",
|
|
292
|
-
"t9 p5-5 s200 ltgray",
|
|
293
|
-
"t22 p0-1 s200 dkblue",
|
|
294
|
-
"t8 p0-2 s350 lime",
|
|
295
|
-
"t2 p0-3 s140 ltgray",
|
|
296
|
-
"t26 p0-4 s300 red",
|
|
297
|
-
"t29 p0-5 s250 ltblue",
|
|
298
|
-
"t14 p1-1 s350 pink",
|
|
299
|
-
"t3 p1-2 s300 yellow",
|
|
300
|
-
"t15 p1-3 s140 green",
|
|
301
|
-
"t27 p1-4 s200 ltgray",
|
|
302
|
-
"t12 p1-5 s250 dkblue",
|
|
303
|
-
"t25 p2-1 s140 pink",
|
|
304
|
-
"t19 p2-2 s200 red",
|
|
305
|
-
"t23 p2-3 s300 ltblue",
|
|
306
|
-
"t7 p2-4 s350 yellow",
|
|
307
|
-
"t16 p2-5 s250 lime",
|
|
308
|
-
"t18 p3-1 s300 green",
|
|
309
|
-
"t21 p3-2 s250 dkblue",
|
|
310
|
-
"t30 p3-3 s350 ltgray",
|
|
311
|
-
"t9 p3-4 s140 pink",
|
|
312
|
-
"t6 p3-5 s200 ltblue",
|
|
313
|
-
"t28 p4-1 s250 yellow",
|
|
314
|
-
"t13 p4-2 s140 red",
|
|
315
|
-
"t17 p4-3 s200 ltgray",
|
|
316
|
-
"t4 p4-4 s300 green",
|
|
317
|
-
"t10 p4-5 s350 lime",
|
|
318
|
-
"t20 p5-1 s350 dkblue",
|
|
319
|
-
"t11 p5-2 s300 pink",
|
|
320
|
-
"t5 p5-3 s140 ltblue",
|
|
321
|
-
"t1 p5-4 s250 yellow",
|
|
322
|
-
"t24 p5-5 s200 ltgray"
|
|
323
|
-
];
|
|
324
|
-
function hexToRgb(hex) {
|
|
325
|
-
const n = parseInt(hex.slice(1), 16);
|
|
326
|
-
return `${n >> 16 & 255},${n >> 8 & 255},${n & 255}`;
|
|
327
|
-
}
|
|
328
|
-
var HardRainInstance = class {
|
|
329
|
-
ctx;
|
|
330
|
-
canvas;
|
|
331
|
-
c2d;
|
|
332
|
-
w = 0;
|
|
333
|
-
h = 0;
|
|
334
|
-
scale = 1;
|
|
335
|
-
drops = [];
|
|
336
|
-
frameId = null;
|
|
337
|
-
paused = false;
|
|
338
|
-
last = 0;
|
|
339
|
-
clock = 0;
|
|
340
|
-
constructor(ctx) {
|
|
341
|
-
this.ctx = ctx;
|
|
342
|
-
let canvas;
|
|
343
|
-
if (ctx.surface) {
|
|
344
|
-
canvas = ctx.surface;
|
|
345
|
-
} else {
|
|
346
|
-
const el = document.createElement("canvas");
|
|
347
|
-
el.style.cssText = "display:block;width:100%;height:100%";
|
|
348
|
-
ctx.host.appendChild(el);
|
|
349
|
-
canvas = el;
|
|
350
|
-
}
|
|
351
|
-
this.canvas = canvas;
|
|
352
|
-
const c2d = canvas.getContext("2d", { alpha: false });
|
|
353
|
-
if (!c2d) throw new Error("hard-rain: no 2d context");
|
|
354
|
-
this.c2d = c2d;
|
|
355
|
-
this.w = ctx.width;
|
|
356
|
-
this.h = ctx.height;
|
|
357
|
-
this.buildDrops();
|
|
358
|
-
this.sizeCanvas();
|
|
359
|
-
this.setPaused(ctx.reducedMotion);
|
|
360
|
-
if (this.paused) this.renderStill();
|
|
361
|
-
}
|
|
362
|
-
buildDrops() {
|
|
363
|
-
this.drops = DROP_SPECS.map((spec) => {
|
|
364
|
-
const parts = spec.split(" ");
|
|
365
|
-
const [tCls, pCls, sCls, cCls] = parts;
|
|
366
|
-
const pos = POSITIONS[pCls] ?? [0.5, 0.5];
|
|
367
|
-
return {
|
|
368
|
-
fx: pos[0],
|
|
369
|
-
fy: pos[1],
|
|
370
|
-
maxR: SIZES[sCls] ?? 100,
|
|
371
|
-
rgb: hexToRgb(COLOURS[cCls] ?? "#c2c2c2"),
|
|
372
|
-
phase: timingPhase(tCls)
|
|
373
|
-
};
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
sizeCanvas() {
|
|
377
|
-
const dpr = Math.min(this.ctx.dpr, 2);
|
|
378
|
-
this.canvas.width = Math.max(1, Math.round(this.w * dpr));
|
|
379
|
-
this.canvas.height = Math.max(1, Math.round(this.h * dpr));
|
|
380
|
-
this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
381
|
-
this.scale = Math.min(this.w, this.h * 1.4) / 900;
|
|
382
|
-
}
|
|
383
|
-
// ---- loop ----
|
|
384
|
-
start() {
|
|
385
|
-
if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
|
|
386
|
-
this.last = 0;
|
|
387
|
-
this.frameId = requestAnimationFrame((now) => this.loop(now));
|
|
388
|
-
}
|
|
389
|
-
stop() {
|
|
390
|
-
if (this.frameId !== null) {
|
|
391
|
-
cancelAnimationFrame(this.frameId);
|
|
392
|
-
this.frameId = null;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
loop(now) {
|
|
396
|
-
this.frameId = requestAnimationFrame((n) => this.loop(n));
|
|
397
|
-
if (this.last === 0) this.last = now;
|
|
398
|
-
const dt = now - this.last;
|
|
399
|
-
this.last = now;
|
|
400
|
-
this.clock += Math.min(50, dt);
|
|
401
|
-
this.render();
|
|
402
|
-
}
|
|
403
|
-
render() {
|
|
404
|
-
const ctx = this.c2d;
|
|
405
|
-
ctx.fillStyle = "#000";
|
|
406
|
-
ctx.fillRect(0, 0, this.w, this.h);
|
|
407
|
-
for (const d of this.drops) {
|
|
408
|
-
let k = (this.clock - d.phase) % CYCLE / CYCLE;
|
|
409
|
-
if (k < 0) k += 1;
|
|
410
|
-
if (k >= 0.89) continue;
|
|
411
|
-
const g = k / 0.89;
|
|
412
|
-
const r = g * d.maxR * this.scale;
|
|
413
|
-
if (r < 0.5) continue;
|
|
414
|
-
const alpha = Math.min(1, g * 4) * (1 - g * 0.55);
|
|
415
|
-
ctx.strokeStyle = `rgba(${d.rgb},${alpha.toFixed(3)})`;
|
|
416
|
-
ctx.lineWidth = 2;
|
|
417
|
-
ctx.beginPath();
|
|
418
|
-
ctx.arc(d.fx * this.w, d.fy * this.h, r, 0, Math.PI * 2);
|
|
419
|
-
ctx.stroke();
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
renderStill() {
|
|
423
|
-
this.clock = CYCLE * 0.4;
|
|
424
|
-
this.render();
|
|
425
|
-
}
|
|
426
|
-
// ---- SaverInstance ----
|
|
427
|
-
setPaused(paused) {
|
|
428
|
-
this.paused = paused;
|
|
429
|
-
if (paused) {
|
|
430
|
-
this.stop();
|
|
431
|
-
this.renderStill();
|
|
432
|
-
} else {
|
|
433
|
-
this.start();
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
resize(width, height, dpr) {
|
|
437
|
-
this.w = width;
|
|
438
|
-
this.h = height;
|
|
439
|
-
if (dpr !== void 0) this.ctx.dpr = dpr;
|
|
440
|
-
this.sizeCanvas();
|
|
441
|
-
if (this.paused) this.renderStill();
|
|
442
|
-
}
|
|
443
|
-
dispose() {
|
|
444
|
-
this.stop();
|
|
445
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
var hardRain = {
|
|
449
|
-
manifest: hardRainManifest,
|
|
450
|
-
mount: (ctx) => new HardRainInstance(ctx)
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// src/rainstorm.ts
|
|
454
|
-
var rainstormManifest = {
|
|
455
|
-
id: "rainstorm",
|
|
456
|
-
label: "Rainstorm",
|
|
457
|
-
passthrough: false,
|
|
458
|
-
minBackend: "canvas2d",
|
|
459
|
-
costTier: "low",
|
|
460
|
-
motionIntensity: "moderate",
|
|
461
|
-
reducedMotionFallback: "static",
|
|
462
|
-
a11y: { flashSafe: true, notes: "Rain streaks over a dark sky; the lightning is a brief, gentle brightening (no rapid strobe)." },
|
|
463
|
-
workerReady: true
|
|
464
|
-
};
|
|
465
|
-
var FLASH_PERIOD = 8e3;
|
|
466
|
-
var RainstormInstance = class {
|
|
467
|
-
ctx;
|
|
468
|
-
canvas;
|
|
469
|
-
c2d;
|
|
470
|
-
w = 0;
|
|
471
|
-
h = 0;
|
|
472
|
-
layers = [];
|
|
473
|
-
frameId = null;
|
|
474
|
-
paused = false;
|
|
475
|
-
last = 0;
|
|
476
|
-
clock = 0;
|
|
477
|
-
constructor(ctx) {
|
|
478
|
-
this.ctx = ctx;
|
|
479
|
-
let canvas;
|
|
480
|
-
if (ctx.surface) {
|
|
481
|
-
canvas = ctx.surface;
|
|
482
|
-
} else {
|
|
483
|
-
const el = document.createElement("canvas");
|
|
484
|
-
el.style.cssText = "display:block;width:100%;height:100%";
|
|
485
|
-
ctx.host.appendChild(el);
|
|
486
|
-
canvas = el;
|
|
487
|
-
}
|
|
488
|
-
this.canvas = canvas;
|
|
489
|
-
const c2d = canvas.getContext("2d", { alpha: false });
|
|
490
|
-
if (!c2d) throw new Error("rainstorm: no 2d context");
|
|
491
|
-
this.c2d = c2d;
|
|
492
|
-
this.w = ctx.width;
|
|
493
|
-
this.h = ctx.height;
|
|
494
|
-
this.sizeCanvas();
|
|
495
|
-
this.buildLayers();
|
|
496
|
-
this.setPaused(ctx.reducedMotion);
|
|
497
|
-
if (this.paused) this.renderStill();
|
|
498
|
-
}
|
|
499
|
-
sizeCanvas() {
|
|
500
|
-
const dpr = Math.min(this.ctx.dpr, 2);
|
|
501
|
-
this.canvas.width = Math.max(1, Math.round(this.w * dpr));
|
|
502
|
-
this.canvas.height = Math.max(1, Math.round(this.h * dpr));
|
|
503
|
-
this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
504
|
-
}
|
|
505
|
-
/** Three depth layers: near (fast, long, bright), mid, distant (slow, faint). */
|
|
506
|
-
buildLayers() {
|
|
507
|
-
const rng = this.ctx.rng;
|
|
508
|
-
const area = this.w * this.h / (1280 * 800);
|
|
509
|
-
const specs = [
|
|
510
|
-
{ count: 220, minLen: 26, maxLen: 46, minSpd: 900, maxSpd: 1150, width: 1.6, alpha: 0.5, slant: 0.19 },
|
|
511
|
-
{ count: 160, minLen: 16, maxLen: 30, minSpd: 520, maxSpd: 700, width: 1.2, alpha: 0.34, slant: 0.19 },
|
|
512
|
-
{ count: 120, minLen: 10, maxLen: 20, minSpd: 300, maxSpd: 420, width: 0.9, alpha: 0.22, slant: 0.19 }
|
|
513
|
-
];
|
|
514
|
-
this.layers = specs.map((s) => {
|
|
515
|
-
const n = Math.max(8, Math.round(s.count * area));
|
|
516
|
-
const drops = new Array(n);
|
|
517
|
-
for (let i = 0; i < n; i++) {
|
|
518
|
-
drops[i] = {
|
|
519
|
-
x: rng.range(-40, this.w + 40),
|
|
520
|
-
y: rng.range(-this.h, this.h),
|
|
521
|
-
len: rng.range(s.minLen, s.maxLen),
|
|
522
|
-
speed: rng.range(s.minSpd, s.maxSpd),
|
|
523
|
-
width: s.width,
|
|
524
|
-
alpha: rng.range(s.alpha * 0.7, s.alpha)
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
return { drops, slant: s.slant };
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
// ---- lightning ----
|
|
531
|
-
/** 0..1 flash intensity given the wall clock (ms). A short white pulse near the
|
|
532
|
-
* top of each period, echoing the CSS `flash` keyframe (98% black → 99% white). */
|
|
533
|
-
flashLevel() {
|
|
534
|
-
const p = (this.clock % FLASH_PERIOD + FLASH_PERIOD) % FLASH_PERIOD;
|
|
535
|
-
const start = FLASH_PERIOD - 140;
|
|
536
|
-
if (p < start) return 0;
|
|
537
|
-
const k = (p - start) / 140;
|
|
538
|
-
return k < 0.4 ? k / 0.4 : Math.max(0, 1 - (k - 0.4) / 0.6);
|
|
539
|
-
}
|
|
540
|
-
// ---- loop ----
|
|
541
|
-
start() {
|
|
542
|
-
if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
|
|
543
|
-
this.last = 0;
|
|
544
|
-
this.frameId = requestAnimationFrame((now) => this.loop(now));
|
|
545
|
-
}
|
|
546
|
-
stop() {
|
|
547
|
-
if (this.frameId !== null) {
|
|
548
|
-
cancelAnimationFrame(this.frameId);
|
|
549
|
-
this.frameId = null;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
loop(now) {
|
|
553
|
-
this.frameId = requestAnimationFrame((n) => this.loop(n));
|
|
554
|
-
if (this.last === 0) this.last = now;
|
|
555
|
-
const dt = Math.min(0.05, (now - this.last) / 1e3);
|
|
556
|
-
this.last = now;
|
|
557
|
-
this.clock += dt * 1e3;
|
|
558
|
-
this.update(dt);
|
|
559
|
-
this.render();
|
|
560
|
-
}
|
|
561
|
-
update(dt) {
|
|
562
|
-
for (const layer of this.layers) {
|
|
563
|
-
for (const d of layer.drops) {
|
|
564
|
-
d.y += d.speed * dt;
|
|
565
|
-
d.x += d.speed * layer.slant * dt;
|
|
566
|
-
if (d.y - d.len > this.h) {
|
|
567
|
-
d.y = -d.len - this.ctx.rng.range(0, this.h * 0.4);
|
|
568
|
-
d.x = this.ctx.rng.range(-40, this.w + 40);
|
|
569
|
-
}
|
|
570
|
-
if (d.x - d.len > this.w) d.x = -40;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
render() {
|
|
575
|
-
const ctx = this.c2d;
|
|
576
|
-
const flash = this.flashLevel();
|
|
577
|
-
const base = 8 + flash * 235;
|
|
578
|
-
ctx.fillStyle = `rgb(${base | 0},${base + 2 | 0},${base + 8 | 0})`;
|
|
579
|
-
ctx.fillRect(0, 0, this.w, this.h);
|
|
580
|
-
ctx.lineCap = "round";
|
|
581
|
-
for (const layer of this.layers) {
|
|
582
|
-
const dx = -layer.slant;
|
|
583
|
-
for (const d of layer.drops) {
|
|
584
|
-
ctx.strokeStyle = `rgba(200,215,235,${d.alpha.toFixed(3)})`;
|
|
585
|
-
ctx.lineWidth = d.width;
|
|
586
|
-
ctx.beginPath();
|
|
587
|
-
ctx.moveTo(d.x, d.y);
|
|
588
|
-
ctx.lineTo(d.x + dx * d.len, d.y - d.len);
|
|
589
|
-
ctx.stroke();
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
renderStill() {
|
|
594
|
-
this.clock = 0;
|
|
595
|
-
this.render();
|
|
596
|
-
}
|
|
597
|
-
// ---- SaverInstance ----
|
|
598
|
-
setPaused(paused) {
|
|
599
|
-
this.paused = paused;
|
|
600
|
-
if (paused) {
|
|
601
|
-
this.stop();
|
|
602
|
-
this.renderStill();
|
|
603
|
-
} else {
|
|
604
|
-
this.start();
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
resize(width, height, dpr) {
|
|
608
|
-
this.w = width;
|
|
609
|
-
this.h = height;
|
|
610
|
-
if (dpr !== void 0) this.ctx.dpr = dpr;
|
|
611
|
-
this.sizeCanvas();
|
|
612
|
-
this.buildLayers();
|
|
613
|
-
if (this.paused) this.renderStill();
|
|
614
|
-
}
|
|
615
|
-
dispose() {
|
|
616
|
-
this.stop();
|
|
617
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
var rainstorm = {
|
|
621
|
-
manifest: rainstormManifest,
|
|
622
|
-
mount: (ctx) => new RainstormInstance(ctx)
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
// src/globe.ts
|
|
626
|
-
var globeManifest = {
|
|
627
|
-
id: "globe",
|
|
628
|
-
label: "Globe",
|
|
629
|
-
passthrough: false,
|
|
630
|
-
minBackend: "canvas2d",
|
|
631
|
-
costTier: "low",
|
|
632
|
-
motionIntensity: "calm",
|
|
633
|
-
reducedMotionFallback: "static",
|
|
634
|
-
a11y: { flashSafe: true, notes: "A slowly spinning dotted globe drifting on black; no flashing." },
|
|
635
|
-
workerReady: true
|
|
636
|
-
};
|
|
637
|
-
var RADIUS = 120;
|
|
638
|
-
var SPIN = 0.9;
|
|
639
|
-
var LAT_LINES = 11;
|
|
640
|
-
var LON_LINES = 21;
|
|
641
|
-
var GlobeInstance = class {
|
|
642
|
-
ctx;
|
|
643
|
-
canvas;
|
|
644
|
-
c2d;
|
|
645
|
-
w = 0;
|
|
646
|
-
h = 0;
|
|
647
|
-
// globe centre + velocity (DVD bounce)
|
|
648
|
-
cx = 0;
|
|
649
|
-
cy = 0;
|
|
650
|
-
vx = 0;
|
|
651
|
-
vy = 0;
|
|
652
|
-
spinPhase = 0;
|
|
653
|
-
// precomputed unit-sphere lattice (spun about Y at render time)
|
|
654
|
-
lattice = [];
|
|
655
|
-
frameId = null;
|
|
656
|
-
paused = false;
|
|
657
|
-
last = 0;
|
|
658
|
-
constructor(ctx) {
|
|
659
|
-
this.ctx = ctx;
|
|
660
|
-
let canvas;
|
|
661
|
-
if (ctx.surface) {
|
|
662
|
-
canvas = ctx.surface;
|
|
663
|
-
} else {
|
|
664
|
-
const el = document.createElement("canvas");
|
|
665
|
-
el.style.cssText = "display:block;width:100%;height:100%";
|
|
666
|
-
ctx.host.appendChild(el);
|
|
667
|
-
canvas = el;
|
|
668
|
-
}
|
|
669
|
-
this.canvas = canvas;
|
|
670
|
-
const c2d = canvas.getContext("2d", { alpha: false });
|
|
671
|
-
if (!c2d) throw new Error("globe: no 2d context");
|
|
672
|
-
this.c2d = c2d;
|
|
673
|
-
this.buildLattice();
|
|
674
|
-
this.w = ctx.width;
|
|
675
|
-
this.h = ctx.height;
|
|
676
|
-
this.sizeCanvas();
|
|
677
|
-
const rng = ctx.rng;
|
|
678
|
-
this.cx = rng.range(RADIUS, Math.max(RADIUS + 1, this.w - RADIUS));
|
|
679
|
-
this.cy = rng.range(RADIUS, Math.max(RADIUS + 1, this.h - RADIUS));
|
|
680
|
-
const dir = rng.range(0, Math.PI * 2);
|
|
681
|
-
const speed = 90;
|
|
682
|
-
this.vx = Math.cos(dir) * speed;
|
|
683
|
-
this.vy = Math.sin(dir) * speed;
|
|
684
|
-
this.setPaused(ctx.reducedMotion);
|
|
685
|
-
if (this.paused) this.renderStill();
|
|
686
|
-
}
|
|
687
|
-
/** Dotted lat/long lattice on the unit sphere. */
|
|
688
|
-
buildLattice() {
|
|
689
|
-
for (let i = 1; i < LAT_LINES; i++) {
|
|
690
|
-
const lat = -Math.PI / 2 + Math.PI * i / LAT_LINES;
|
|
691
|
-
const ringR = Math.cos(lat);
|
|
692
|
-
const y = Math.sin(lat);
|
|
693
|
-
const dots = Math.max(6, Math.round(LON_LINES * ringR + 4));
|
|
694
|
-
for (let j = 0; j < dots; j++) {
|
|
695
|
-
const lon = Math.PI * 2 * j / dots;
|
|
696
|
-
this.lattice.push({ x: ringR * Math.cos(lon), y, z: ringR * Math.sin(lon) });
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
for (let m = 0; m < LON_LINES; m++) {
|
|
700
|
-
const lon = Math.PI * 2 * m / LON_LINES;
|
|
701
|
-
for (let s = 0; s <= 24; s++) {
|
|
702
|
-
const lat = -Math.PI / 2 + Math.PI * s / 24;
|
|
703
|
-
const ringR = Math.cos(lat);
|
|
704
|
-
this.lattice.push({ x: ringR * Math.cos(lon), y: Math.sin(lat), z: ringR * Math.sin(lon) });
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
sizeCanvas() {
|
|
709
|
-
const dpr = Math.min(this.ctx.dpr, 2);
|
|
710
|
-
this.canvas.width = Math.max(1, Math.round(this.w * dpr));
|
|
711
|
-
this.canvas.height = Math.max(1, Math.round(this.h * dpr));
|
|
712
|
-
this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
713
|
-
}
|
|
714
|
-
// ---- loop ----
|
|
715
|
-
start() {
|
|
716
|
-
if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
|
|
717
|
-
this.last = 0;
|
|
718
|
-
this.frameId = requestAnimationFrame((now) => this.loop(now));
|
|
719
|
-
}
|
|
720
|
-
stop() {
|
|
721
|
-
if (this.frameId !== null) {
|
|
722
|
-
cancelAnimationFrame(this.frameId);
|
|
723
|
-
this.frameId = null;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
loop(now) {
|
|
727
|
-
this.frameId = requestAnimationFrame((n) => this.loop(n));
|
|
728
|
-
if (this.last === 0) this.last = now;
|
|
729
|
-
const dt = Math.min(0.05, (now - this.last) / 1e3);
|
|
730
|
-
this.last = now;
|
|
731
|
-
this.update(dt);
|
|
732
|
-
this.render();
|
|
733
|
-
}
|
|
734
|
-
update(dt) {
|
|
735
|
-
this.spinPhase += SPIN * dt;
|
|
736
|
-
this.cx += this.vx * dt;
|
|
737
|
-
this.cy += this.vy * dt;
|
|
738
|
-
const minX = RADIUS;
|
|
739
|
-
const maxX = this.w - RADIUS;
|
|
740
|
-
const minY = RADIUS;
|
|
741
|
-
const maxY = this.h - RADIUS;
|
|
742
|
-
if (this.cx < minX) {
|
|
743
|
-
this.cx = minX;
|
|
744
|
-
this.vx = Math.abs(this.vx);
|
|
745
|
-
} else if (this.cx > maxX) {
|
|
746
|
-
this.cx = maxX;
|
|
747
|
-
this.vx = -Math.abs(this.vx);
|
|
748
|
-
}
|
|
749
|
-
if (this.cy < minY) {
|
|
750
|
-
this.cy = minY;
|
|
751
|
-
this.vy = Math.abs(this.vy);
|
|
752
|
-
} else if (this.cy > maxY) {
|
|
753
|
-
this.cy = maxY;
|
|
754
|
-
this.vy = -Math.abs(this.vy);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
render() {
|
|
758
|
-
const ctx = this.c2d;
|
|
759
|
-
ctx.fillStyle = "#000";
|
|
760
|
-
ctx.fillRect(0, 0, this.w, this.h);
|
|
761
|
-
const body = ctx.createRadialGradient(
|
|
762
|
-
this.cx - RADIUS * 0.35,
|
|
763
|
-
this.cy - RADIUS * 0.35,
|
|
764
|
-
RADIUS * 0.1,
|
|
765
|
-
this.cx,
|
|
766
|
-
this.cy,
|
|
767
|
-
RADIUS
|
|
768
|
-
);
|
|
769
|
-
body.addColorStop(0, "rgba(30,60,90,0.55)");
|
|
770
|
-
body.addColorStop(1, "rgba(6,14,26,0.15)");
|
|
771
|
-
ctx.fillStyle = body;
|
|
772
|
-
ctx.beginPath();
|
|
773
|
-
ctx.arc(this.cx, this.cy, RADIUS, 0, Math.PI * 2);
|
|
774
|
-
ctx.fill();
|
|
775
|
-
const cos = Math.cos(this.spinPhase);
|
|
776
|
-
const sin = Math.sin(this.spinPhase);
|
|
777
|
-
for (const p of this.lattice) {
|
|
778
|
-
const rx = p.x * cos + p.z * sin;
|
|
779
|
-
const rz = -p.x * sin + p.z * cos;
|
|
780
|
-
const x = this.cx + rx * RADIUS;
|
|
781
|
-
const y = this.cy + p.y * RADIUS;
|
|
782
|
-
const depth = (rz + 1) / 2;
|
|
783
|
-
const alpha = 0.12 + depth * 0.7;
|
|
784
|
-
const size = 0.7 + depth * 1.2;
|
|
785
|
-
ctx.fillStyle = `rgba(120,200,255,${alpha.toFixed(3)})`;
|
|
786
|
-
ctx.beginPath();
|
|
787
|
-
ctx.arc(x, y, size, 0, Math.PI * 2);
|
|
788
|
-
ctx.fill();
|
|
789
|
-
}
|
|
790
|
-
ctx.strokeStyle = "rgba(120,200,255,0.35)";
|
|
791
|
-
ctx.lineWidth = 1;
|
|
792
|
-
ctx.beginPath();
|
|
793
|
-
ctx.arc(this.cx, this.cy, RADIUS, 0, Math.PI * 2);
|
|
794
|
-
ctx.stroke();
|
|
795
|
-
}
|
|
796
|
-
renderStill() {
|
|
797
|
-
this.render();
|
|
798
|
-
}
|
|
799
|
-
// ---- SaverInstance ----
|
|
800
|
-
setPaused(paused) {
|
|
801
|
-
this.paused = paused;
|
|
802
|
-
if (paused) {
|
|
803
|
-
this.stop();
|
|
804
|
-
this.renderStill();
|
|
805
|
-
} else {
|
|
806
|
-
this.start();
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
resize(width, height, dpr) {
|
|
810
|
-
this.w = width;
|
|
811
|
-
this.h = height;
|
|
812
|
-
if (dpr !== void 0) this.ctx.dpr = dpr;
|
|
813
|
-
this.sizeCanvas();
|
|
814
|
-
this.cx = Math.min(Math.max(this.cx, RADIUS), Math.max(RADIUS, this.w - RADIUS));
|
|
815
|
-
this.cy = Math.min(Math.max(this.cy, RADIUS), Math.max(RADIUS, this.h - RADIUS));
|
|
816
|
-
if (this.paused) this.renderStill();
|
|
817
|
-
}
|
|
818
|
-
dispose() {
|
|
819
|
-
this.stop();
|
|
820
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
var globe = {
|
|
824
|
-
manifest: globeManifest,
|
|
825
|
-
mount: (ctx) => new GlobeInstance(ctx)
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
// src/spotlight.ts
|
|
829
|
-
var spotlightManifest = {
|
|
830
|
-
id: "spotlight",
|
|
831
|
-
label: "Spotlight",
|
|
832
|
-
passthrough: true,
|
|
833
|
-
minBackend: "canvas2d",
|
|
834
|
-
costTier: "low",
|
|
835
|
-
motionIntensity: "calm",
|
|
836
|
-
reducedMotionFallback: "static",
|
|
837
|
-
a11y: { flashSafe: true, notes: "A soft light circle drifting over the live page; no flashing." },
|
|
838
|
-
workerReady: true
|
|
839
|
-
};
|
|
840
|
-
var HOLE_RADIUS = 220;
|
|
841
|
-
var SPEED_X = 5e3;
|
|
842
|
-
var SPEED_Y = 5600;
|
|
843
|
-
var SpotlightInstance = class {
|
|
844
|
-
ctx;
|
|
845
|
-
canvas;
|
|
846
|
-
c2d;
|
|
847
|
-
w = 0;
|
|
848
|
-
h = 0;
|
|
849
|
-
frameId = null;
|
|
850
|
-
paused = false;
|
|
851
|
-
last = 0;
|
|
852
|
-
clock = 0;
|
|
853
|
-
constructor(ctx) {
|
|
854
|
-
this.ctx = ctx;
|
|
855
|
-
let canvas;
|
|
856
|
-
if (ctx.surface) {
|
|
857
|
-
canvas = ctx.surface;
|
|
858
|
-
} else {
|
|
859
|
-
const el = document.createElement("canvas");
|
|
860
|
-
el.style.cssText = "display:block;width:100%;height:100%";
|
|
861
|
-
ctx.host.appendChild(el);
|
|
862
|
-
canvas = el;
|
|
863
|
-
}
|
|
864
|
-
this.canvas = canvas;
|
|
865
|
-
const c2d = canvas.getContext("2d", { alpha: true });
|
|
866
|
-
if (!c2d) throw new Error("spotlight: no 2d context");
|
|
867
|
-
this.c2d = c2d;
|
|
868
|
-
this.w = ctx.width;
|
|
869
|
-
this.h = ctx.height;
|
|
870
|
-
this.sizeCanvas();
|
|
871
|
-
this.setPaused(ctx.reducedMotion);
|
|
872
|
-
if (this.paused) this.render();
|
|
873
|
-
}
|
|
874
|
-
sizeCanvas() {
|
|
875
|
-
const dpr = Math.min(this.ctx.dpr, 2);
|
|
876
|
-
this.canvas.width = Math.max(1, Math.round(this.w * dpr));
|
|
877
|
-
this.canvas.height = Math.max(1, Math.round(this.h * dpr));
|
|
878
|
-
this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
879
|
-
}
|
|
880
|
-
centre() {
|
|
881
|
-
const tri = (t, period) => {
|
|
882
|
-
const p = (t % (period * 2) + period * 2) % (period * 2);
|
|
883
|
-
return p < period ? p / period : 2 - p / period;
|
|
884
|
-
};
|
|
885
|
-
const kx = tri(this.clock, SPEED_X);
|
|
886
|
-
const ky = tri(this.clock, SPEED_Y);
|
|
887
|
-
const x = HOLE_RADIUS + kx * (this.w - HOLE_RADIUS * 2);
|
|
888
|
-
const y = HOLE_RADIUS + ky * (this.h - HOLE_RADIUS * 2);
|
|
889
|
-
return [x, y];
|
|
890
|
-
}
|
|
891
|
-
start() {
|
|
892
|
-
if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
|
|
893
|
-
this.last = 0;
|
|
894
|
-
this.frameId = requestAnimationFrame((now) => this.loop(now));
|
|
895
|
-
}
|
|
896
|
-
stop() {
|
|
897
|
-
if (this.frameId !== null) {
|
|
898
|
-
cancelAnimationFrame(this.frameId);
|
|
899
|
-
this.frameId = null;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
loop(now) {
|
|
903
|
-
this.frameId = requestAnimationFrame((n) => this.loop(n));
|
|
904
|
-
if (this.last === 0) this.last = now;
|
|
905
|
-
this.clock += Math.min(50, now - this.last);
|
|
906
|
-
this.last = now;
|
|
907
|
-
this.render();
|
|
908
|
-
}
|
|
909
|
-
render() {
|
|
910
|
-
const ctx = this.c2d;
|
|
911
|
-
const [sx, sy] = this.centre();
|
|
912
|
-
ctx.clearRect(0, 0, this.w, this.h);
|
|
913
|
-
ctx.fillStyle = "rgba(0, 0, 0, 0.92)";
|
|
914
|
-
ctx.fillRect(0, 0, this.w, this.h);
|
|
915
|
-
ctx.globalCompositeOperation = "destination-out";
|
|
916
|
-
const hole = ctx.createRadialGradient(sx, sy, 0, sx, sy, HOLE_RADIUS * 1.15);
|
|
917
|
-
hole.addColorStop(0, "rgba(0,0,0,1)");
|
|
918
|
-
hole.addColorStop(0.62, "rgba(0,0,0,1)");
|
|
919
|
-
hole.addColorStop(0.85, "rgba(0,0,0,0.5)");
|
|
920
|
-
hole.addColorStop(1, "rgba(0,0,0,0)");
|
|
921
|
-
ctx.fillStyle = hole;
|
|
922
|
-
ctx.fillRect(sx - HOLE_RADIUS * 1.2, sy - HOLE_RADIUS * 1.2, HOLE_RADIUS * 2.4, HOLE_RADIUS * 2.4);
|
|
923
|
-
ctx.globalCompositeOperation = "source-over";
|
|
924
|
-
const glow = ctx.createRadialGradient(sx, sy, 0, sx, sy, HOLE_RADIUS);
|
|
925
|
-
glow.addColorStop(0, "rgba(255,250,230,0.12)");
|
|
926
|
-
glow.addColorStop(1, "rgba(255,250,230,0)");
|
|
927
|
-
ctx.fillStyle = glow;
|
|
928
|
-
ctx.beginPath();
|
|
929
|
-
ctx.arc(sx, sy, HOLE_RADIUS, 0, Math.PI * 2);
|
|
930
|
-
ctx.fill();
|
|
931
|
-
}
|
|
932
|
-
setPaused(paused) {
|
|
933
|
-
this.paused = paused;
|
|
934
|
-
if (paused) {
|
|
935
|
-
this.stop();
|
|
936
|
-
this.render();
|
|
937
|
-
} else {
|
|
938
|
-
this.start();
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
resize(width, height, dpr) {
|
|
942
|
-
this.w = width;
|
|
943
|
-
this.h = height;
|
|
944
|
-
if (dpr !== void 0) this.ctx.dpr = dpr;
|
|
945
|
-
this.sizeCanvas();
|
|
946
|
-
if (this.paused) this.render();
|
|
947
|
-
}
|
|
948
|
-
dispose() {
|
|
949
|
-
this.stop();
|
|
950
|
-
if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
var spotlight = {
|
|
954
|
-
manifest: spotlightManifest,
|
|
955
|
-
mount: (ctx) => new SpotlightInstance(ctx)
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
export {
|
|
959
|
-
warp,
|
|
960
|
-
hardRain,
|
|
961
|
-
rainstorm,
|
|
962
|
-
globe,
|
|
963
|
-
spotlight
|
|
964
|
-
};
|
|
965
|
-
//# sourceMappingURL=chunk-5EPTQV3C.js.map
|