@algorisys/yappydraw 0.8.253
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/LICENSE +661 -0
- package/README.md +45 -0
- package/chunks/AllPackages-DNX4gUvL.js +6879 -0
- package/chunks/BaseConfiguration-iE_YypNt.js +4401 -0
- package/chunks/Entities-XwxJEcR3.js +467 -0
- package/chunks/Factory--zguTNZ7.js +2768 -0
- package/chunks/InputJax-BYq2tqUz.js +42 -0
- package/chunks/MathItem-DD5NNBjZ.js +76 -0
- package/chunks/Options-BStFr0zv.js +199 -0
- package/chunks/PrioritizedList-TjDg4i-s.js +39 -0
- package/chunks/Styles-DdTYCumM.js +397 -0
- package/chunks/TeXAtom-Bp5xoo7F.js +2175 -0
- package/chunks/ai-providers-CycU8sO1.js +229 -0
- package/chunks/canva-ai-BREIRXSl.js +285 -0
- package/chunks/design-generator-C89SKTqv.js +149 -0
- package/chunks/drawing-engine-DLFI-cNg.js +903 -0
- package/chunks/drawings-store-C-PoHakg.js +109 -0
- package/chunks/ds-operations-D5B9Z5vO.js +253 -0
- package/chunks/export-game-DOlM1w0F.js +104 -0
- package/chunks/game-runtime-Hn9umSvi.js +346 -0
- package/chunks/gifenc.esm-48qFK9lH.js +278 -0
- package/chunks/html-DxnOvKy4.js +1694 -0
- package/chunks/image-utils-CJQBaGoQ.js +37 -0
- package/chunks/index-Bm3Inzn8.js +62744 -0
- package/chunks/lengths-DNFHULBn.js +70 -0
- package/chunks/liteAdaptor-BZby1Qz2.js +919 -0
- package/chunks/lucide-solid-D_6t_rbY.js +35452 -0
- package/chunks/markdown-to-slides-_1GIcD8M.js +96 -0
- package/chunks/mathjax-CnUrFnFS.js +117 -0
- package/chunks/mathjax-D6cR72fZ.js +26 -0
- package/chunks/morph-animator-7qX2s9j_.js +25 -0
- package/chunks/onboarding-tour-CthiVc3W.js +192 -0
- package/chunks/rocket-settings-CU8w9S9I.js +100 -0
- package/chunks/search-CnWoMV6A.js +384 -0
- package/chunks/slide-generator-BG0Oacui.js +553 -0
- package/chunks/svg-BvVc02XL.js +12498 -0
- package/chunks/tex-Cfi4Kfun.js +442 -0
- package/chunks/tinyfly-engine-Wfa50sVI.js +1804 -0
- package/chunks/turntable-ai-Bfq-oSsD.js +120 -0
- package/chunks/yappy-NspTXSPk.css +1 -0
- package/package.json +21 -0
- package/yappy.d.ts +34 -0
- package/yappy.js +9 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { s as o, b as m, d as b, f as a, z as W, w as z, x as U, y as B } from "./index-Bm3Inzn8.js";
|
|
2
|
+
const h = /* @__PURE__ */ new Set(), x = [], G = {
|
|
3
|
+
ArrowLeft: "left",
|
|
4
|
+
a: "left",
|
|
5
|
+
A: "left",
|
|
6
|
+
ArrowRight: "right",
|
|
7
|
+
d: "right",
|
|
8
|
+
D: "right",
|
|
9
|
+
ArrowUp: "up",
|
|
10
|
+
w: "up",
|
|
11
|
+
W: "up",
|
|
12
|
+
ArrowDown: "down",
|
|
13
|
+
s: "down",
|
|
14
|
+
S: "down",
|
|
15
|
+
" ": "a",
|
|
16
|
+
z: "a",
|
|
17
|
+
Z: "a",
|
|
18
|
+
Enter: "a",
|
|
19
|
+
x: "b",
|
|
20
|
+
X: "b",
|
|
21
|
+
Shift: "b"
|
|
22
|
+
}, Q = (e) => {
|
|
23
|
+
h.has(e) || (h.add(e), I(e));
|
|
24
|
+
}, q = (e) => {
|
|
25
|
+
h.delete(e);
|
|
26
|
+
}, I = (e) => {
|
|
27
|
+
for (const i of x) i.button === e && L(i.fn);
|
|
28
|
+
}, u = { x: 0, y: 0, down: !1 }, v = [], ee = (e, i) => {
|
|
29
|
+
u.x = e, u.y = i;
|
|
30
|
+
}, te = (e, i) => {
|
|
31
|
+
u.x = e, u.y = i, u.down = !0;
|
|
32
|
+
for (const s of v) L(() => s(e, i));
|
|
33
|
+
}, ne = () => {
|
|
34
|
+
u.down = !1;
|
|
35
|
+
};
|
|
36
|
+
class A {
|
|
37
|
+
id;
|
|
38
|
+
constructor(i) {
|
|
39
|
+
this.id = i;
|
|
40
|
+
}
|
|
41
|
+
el() {
|
|
42
|
+
return o.elements.find((i) => i.id === this.id);
|
|
43
|
+
}
|
|
44
|
+
get alive() {
|
|
45
|
+
return !!this.el();
|
|
46
|
+
}
|
|
47
|
+
get x() {
|
|
48
|
+
return this.el()?.x ?? 0;
|
|
49
|
+
}
|
|
50
|
+
get y() {
|
|
51
|
+
return this.el()?.y ?? 0;
|
|
52
|
+
}
|
|
53
|
+
get width() {
|
|
54
|
+
return this.el()?.width ?? 0;
|
|
55
|
+
}
|
|
56
|
+
get height() {
|
|
57
|
+
return this.el()?.height ?? 0;
|
|
58
|
+
}
|
|
59
|
+
get angle() {
|
|
60
|
+
return this.el()?.angle ?? 0;
|
|
61
|
+
}
|
|
62
|
+
get text() {
|
|
63
|
+
return this.el()?.text ?? "";
|
|
64
|
+
}
|
|
65
|
+
/** Center coordinates. */
|
|
66
|
+
get cx() {
|
|
67
|
+
const i = this.el();
|
|
68
|
+
return i ? i.x + i.width / 2 : 0;
|
|
69
|
+
}
|
|
70
|
+
get cy() {
|
|
71
|
+
const i = this.el();
|
|
72
|
+
return i ? i.y + i.height / 2 : 0;
|
|
73
|
+
}
|
|
74
|
+
set(i) {
|
|
75
|
+
return C(this.id, i), this;
|
|
76
|
+
}
|
|
77
|
+
moveTo(i, s) {
|
|
78
|
+
return this.set({ x: i, y: s });
|
|
79
|
+
}
|
|
80
|
+
moveBy(i, s) {
|
|
81
|
+
return this.set({ x: this.x + i, y: this.y + s });
|
|
82
|
+
}
|
|
83
|
+
centerAt(i, s) {
|
|
84
|
+
return this.set({ x: i - this.width / 2, y: s - this.height / 2 });
|
|
85
|
+
}
|
|
86
|
+
rotateBy(i) {
|
|
87
|
+
return this.set({ angle: this.angle + i * Math.PI / 180 });
|
|
88
|
+
}
|
|
89
|
+
color(i) {
|
|
90
|
+
return this.set({ backgroundColor: i, fillStyle: "solid" });
|
|
91
|
+
}
|
|
92
|
+
setText(i) {
|
|
93
|
+
return this.set({ text: i });
|
|
94
|
+
}
|
|
95
|
+
hide() {
|
|
96
|
+
return this.set({ opacity: 0 });
|
|
97
|
+
}
|
|
98
|
+
show() {
|
|
99
|
+
return this.set({ opacity: 100 });
|
|
100
|
+
}
|
|
101
|
+
destroy() {
|
|
102
|
+
H(this.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const C = (e, i) => {
|
|
106
|
+
a("elements", (s) => s.id === e, i);
|
|
107
|
+
}, H = (e) => {
|
|
108
|
+
a("elements", (i) => i.filter((s) => s.id !== e));
|
|
109
|
+
};
|
|
110
|
+
let g = null, y = null, w = [], k = 0, M = 0, c = null, T = !1, F = "", f = 0;
|
|
111
|
+
const N = "SCORE ";
|
|
112
|
+
let $ = null, V = !1, E = () => {
|
|
113
|
+
};
|
|
114
|
+
const ie = (e) => {
|
|
115
|
+
E = e;
|
|
116
|
+
}, J = (e) => {
|
|
117
|
+
$ = e, E();
|
|
118
|
+
}, P = (e) => {
|
|
119
|
+
T = e, V = e, E();
|
|
120
|
+
}, L = (e) => {
|
|
121
|
+
try {
|
|
122
|
+
e();
|
|
123
|
+
} catch (i) {
|
|
124
|
+
console.error("[arcade] script error:", i), m(`Game error: ${i?.message || i}`, "error"), p();
|
|
125
|
+
}
|
|
126
|
+
}, K = (e) => {
|
|
127
|
+
if (e.key === "Escape") {
|
|
128
|
+
p();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const i = G[e.key];
|
|
132
|
+
i && (e.preventDefault(), h.has(i) || (h.add(i), I(i)));
|
|
133
|
+
}, O = (e) => {
|
|
134
|
+
const i = G[e.key];
|
|
135
|
+
i && h.delete(i);
|
|
136
|
+
};
|
|
137
|
+
let X = 0;
|
|
138
|
+
function Y() {
|
|
139
|
+
const e = o.slides[o.activeSlideIndex] || o.slides[0];
|
|
140
|
+
return e ? { x: e.spatialPosition.x, y: e.spatialPosition.y, width: e.dimensions.width, height: e.dimensions.height } : { x: 0, y: 0, width: 800, height: 600 };
|
|
141
|
+
}
|
|
142
|
+
function Z() {
|
|
143
|
+
const e = Y(), i = {
|
|
144
|
+
strokeColor: "transparent",
|
|
145
|
+
strokeWidth: 0,
|
|
146
|
+
strokeStyle: "solid",
|
|
147
|
+
fillStyle: "solid",
|
|
148
|
+
opacity: 100,
|
|
149
|
+
angle: 0,
|
|
150
|
+
roughness: 0,
|
|
151
|
+
renderStyle: "architectural",
|
|
152
|
+
locked: !1,
|
|
153
|
+
layerId: o.activeLayerId || "default-layer",
|
|
154
|
+
roundness: null
|
|
155
|
+
}, s = (n, t, r, d, l, S) => {
|
|
156
|
+
const D = {
|
|
157
|
+
id: `game-${Date.now()}-${++X}`,
|
|
158
|
+
type: n,
|
|
159
|
+
x: t,
|
|
160
|
+
y: r,
|
|
161
|
+
width: d,
|
|
162
|
+
height: l,
|
|
163
|
+
backgroundColor: "#3b82f6",
|
|
164
|
+
seed: 1,
|
|
165
|
+
...i,
|
|
166
|
+
...S
|
|
167
|
+
};
|
|
168
|
+
return a("elements", (R) => [...R, D]), new A(D.id);
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
x: e.x,
|
|
172
|
+
y: e.y,
|
|
173
|
+
width: e.width,
|
|
174
|
+
height: e.height,
|
|
175
|
+
onTick: (n) => {
|
|
176
|
+
w.push(n);
|
|
177
|
+
},
|
|
178
|
+
onKey: (n, t) => {
|
|
179
|
+
x.push({ button: n, fn: t });
|
|
180
|
+
},
|
|
181
|
+
key: (n) => h.has(n),
|
|
182
|
+
pointer: () => ({ ...u }),
|
|
183
|
+
onPointerDown: (n) => {
|
|
184
|
+
v.push(n);
|
|
185
|
+
},
|
|
186
|
+
find: (n) => {
|
|
187
|
+
const t = o.elements.find((r) => r.id === n || r.tag === n || r.text === n);
|
|
188
|
+
return t ? new A(t.id) : null;
|
|
189
|
+
},
|
|
190
|
+
findAll: (n) => o.elements.filter((t) => t.id === n || t.tag === n || t.text === n).map((t) => new A(t.id)),
|
|
191
|
+
spawn: (n, t, r, d, l, S) => s(n, t, r, d, l, S),
|
|
192
|
+
spawnText: (n, t, r, d = 32, l) => s("text", t, r, Math.max(60, n.length * d * 0.6), d * 1.4, {
|
|
193
|
+
text: n,
|
|
194
|
+
fontSize: d,
|
|
195
|
+
textColor: "#111827",
|
|
196
|
+
textAlign: "center",
|
|
197
|
+
backgroundColor: "transparent",
|
|
198
|
+
fontFamily: "poppins",
|
|
199
|
+
...l
|
|
200
|
+
}),
|
|
201
|
+
hit: (n, t) => !n?.alive || !t?.alive ? !1 : n.x < t.x + t.width && n.x + n.width > t.x && n.y < t.y + t.height && n.y + n.height > t.y,
|
|
202
|
+
hud: (n) => {
|
|
203
|
+
if (c && o.elements.some((t) => t.id === c))
|
|
204
|
+
C(c, { text: n });
|
|
205
|
+
else {
|
|
206
|
+
const t = Math.round(e.width / 18);
|
|
207
|
+
c = s("text", e.x + e.width * 0.1, e.y + 16, e.width * 0.8, t * 1.5, {
|
|
208
|
+
text: n,
|
|
209
|
+
fontSize: t,
|
|
210
|
+
textColor: "#111827",
|
|
211
|
+
textAlign: "center",
|
|
212
|
+
backgroundColor: "transparent",
|
|
213
|
+
fontFamily: "poppins",
|
|
214
|
+
fontWeight: "bold"
|
|
215
|
+
}).id;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
score: (n) => {
|
|
219
|
+
f += n;
|
|
220
|
+
const t = N + f;
|
|
221
|
+
if (c && o.elements.some((r) => r.id === c))
|
|
222
|
+
C(c, { text: t });
|
|
223
|
+
else {
|
|
224
|
+
const r = Math.round(e.width / 18);
|
|
225
|
+
c = s("text", e.x + e.width * 0.1, e.y + 16, e.width * 0.8, r * 1.5, {
|
|
226
|
+
text: t,
|
|
227
|
+
fontSize: r,
|
|
228
|
+
textColor: "#111827",
|
|
229
|
+
textAlign: "center",
|
|
230
|
+
backgroundColor: "transparent",
|
|
231
|
+
fontFamily: "poppins",
|
|
232
|
+
fontWeight: "bold"
|
|
233
|
+
}).id;
|
|
234
|
+
}
|
|
235
|
+
return f;
|
|
236
|
+
},
|
|
237
|
+
getScore: () => f,
|
|
238
|
+
goToState: (n) => {
|
|
239
|
+
const t = o.states.find((r) => r.name === n || r.id === n);
|
|
240
|
+
t && B(t.id);
|
|
241
|
+
},
|
|
242
|
+
playAnim: (n, t) => {
|
|
243
|
+
n?.alive && import("./index-Bm3Inzn8.js").then((r) => r.ao).then((r) => r.sequenceAnimator.playAnimation(n.id, { id: `bhv-${Date.now()}`, type: "preset", name: t, trigger: "programmatic" }, () => {
|
|
244
|
+
}));
|
|
245
|
+
},
|
|
246
|
+
goToPage: (n) => {
|
|
247
|
+
n >= 0 && n < o.slides.length && U(n);
|
|
248
|
+
},
|
|
249
|
+
sound: (n) => {
|
|
250
|
+
import("./index-Bm3Inzn8.js").then((t) => t.ap).then((t) => t.playSfx(n));
|
|
251
|
+
},
|
|
252
|
+
music: (n) => {
|
|
253
|
+
import("./index-Bm3Inzn8.js").then((t) => t.ap).then((t) => n ? t.startMusic() : t.stopMusic());
|
|
254
|
+
},
|
|
255
|
+
end: (n) => {
|
|
256
|
+
if (P(!0), n) {
|
|
257
|
+
const t = Math.round(e.width / 10);
|
|
258
|
+
s("text", e.x, e.y + e.height / 2 - t, e.width, t * 2, {
|
|
259
|
+
text: n,
|
|
260
|
+
fontSize: t,
|
|
261
|
+
textColor: "#dc2626",
|
|
262
|
+
textAlign: "center",
|
|
263
|
+
backgroundColor: "transparent",
|
|
264
|
+
fontFamily: "poppins",
|
|
265
|
+
fontWeight: "bold"
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
pad: (n) => J(n),
|
|
270
|
+
random: (n, t) => n + Math.random() * (t - n),
|
|
271
|
+
clamp: (n, t, r) => Math.max(t, Math.min(r, n))
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const re = () => o.gameActive;
|
|
275
|
+
function _(e) {
|
|
276
|
+
o.gameActive && p();
|
|
277
|
+
const i = e ?? o.gameScript;
|
|
278
|
+
if (!i?.trim())
|
|
279
|
+
return m("No game script yet — open Menu → Game Script…", "info"), !1;
|
|
280
|
+
g = {
|
|
281
|
+
elements: JSON.stringify(o.elements),
|
|
282
|
+
selection: [...o.selection],
|
|
283
|
+
activeSlideIndex: o.activeSlideIndex,
|
|
284
|
+
appMode: o.appMode,
|
|
285
|
+
viewState: { ...o.viewState }
|
|
286
|
+
}, F = i, w = [], x.length = 0, v.length = 0, h.clear(), c = null, f = 0, P(!1), $ = null;
|
|
287
|
+
let s;
|
|
288
|
+
try {
|
|
289
|
+
s = new Function("game", `'use strict';
|
|
290
|
+
${i}`);
|
|
291
|
+
} catch (t) {
|
|
292
|
+
return m(`Game script error: ${t?.message || t}`, "error"), g = null, !1;
|
|
293
|
+
}
|
|
294
|
+
b(() => {
|
|
295
|
+
a("selection", []), a("gameActive", !0), a("appMode", "presentation");
|
|
296
|
+
}), W();
|
|
297
|
+
try {
|
|
298
|
+
s(Z());
|
|
299
|
+
} catch (t) {
|
|
300
|
+
return m(`Game error: ${t?.message || t}`, "error"), p(), !1;
|
|
301
|
+
}
|
|
302
|
+
window.addEventListener("keydown", K, !0), window.addEventListener("keyup", O, !0), k = performance.now(), M = k;
|
|
303
|
+
const n = (t) => {
|
|
304
|
+
y = requestAnimationFrame(n);
|
|
305
|
+
const r = Math.min(0.05, (t - M) / 1e3);
|
|
306
|
+
if (M = t, T) return;
|
|
307
|
+
const d = (t - k) / 1e3;
|
|
308
|
+
try {
|
|
309
|
+
b(() => {
|
|
310
|
+
for (const l of w) l(r, d);
|
|
311
|
+
});
|
|
312
|
+
} catch (l) {
|
|
313
|
+
console.error("[arcade] tick error:", l), m(`Game error: ${l?.message || l}`, "error"), p();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
return y = requestAnimationFrame(n), !0;
|
|
317
|
+
}
|
|
318
|
+
function p() {
|
|
319
|
+
if (y !== null && (cancelAnimationFrame(y), y = null), window.removeEventListener("keydown", K, !0), window.removeEventListener("keyup", O, !0), import("./index-Bm3Inzn8.js").then((e) => e.ap).then((e) => e.stopMusic()), h.clear(), w = [], x.length = 0, v.length = 0, g) {
|
|
320
|
+
const e = g;
|
|
321
|
+
g = null, b(() => {
|
|
322
|
+
a("elements", JSON.parse(e.elements)), a("selection", e.selection), a("activeSlideIndex", e.activeSlideIndex), a("appMode", e.appMode), a("gameActive", !1);
|
|
323
|
+
}), z(e.viewState);
|
|
324
|
+
} else
|
|
325
|
+
a("gameActive", !1);
|
|
326
|
+
P(!1);
|
|
327
|
+
}
|
|
328
|
+
function se() {
|
|
329
|
+
const e = F;
|
|
330
|
+
p(), e && _(e);
|
|
331
|
+
}
|
|
332
|
+
export {
|
|
333
|
+
A as Sprite,
|
|
334
|
+
V as gameEnded,
|
|
335
|
+
te as gamePointerDown,
|
|
336
|
+
ee as gamePointerMove,
|
|
337
|
+
ne as gamePointerUp,
|
|
338
|
+
re as isGameRunning,
|
|
339
|
+
ie as onGameUiSignal,
|
|
340
|
+
Q as padPress,
|
|
341
|
+
q as padRelease,
|
|
342
|
+
$ as padVisibleOverride,
|
|
343
|
+
se as restartGame,
|
|
344
|
+
_ as startGame,
|
|
345
|
+
p as stopGame
|
|
346
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
var Y = { trailer: 59 };
|
|
2
|
+
function K(t = 256) {
|
|
3
|
+
let r = 0, f = new Uint8Array(t);
|
|
4
|
+
return { get buffer() {
|
|
5
|
+
return f.buffer;
|
|
6
|
+
}, reset() {
|
|
7
|
+
r = 0;
|
|
8
|
+
}, bytesView() {
|
|
9
|
+
return f.subarray(0, r);
|
|
10
|
+
}, bytes() {
|
|
11
|
+
return f.slice(0, r);
|
|
12
|
+
}, writeByte(a) {
|
|
13
|
+
n(r + 1), f[r] = a, r++;
|
|
14
|
+
}, writeBytes(a, i = 0, l = a.length) {
|
|
15
|
+
n(r + l);
|
|
16
|
+
for (let o = 0; o < l; o++) f[r++] = a[o + i];
|
|
17
|
+
}, writeBytesView(a, i = 0, l = a.byteLength) {
|
|
18
|
+
n(r + l), f.set(a.subarray(i, i + l), r), r += l;
|
|
19
|
+
} };
|
|
20
|
+
function n(a) {
|
|
21
|
+
var i = f.length;
|
|
22
|
+
if (i >= a) return;
|
|
23
|
+
var l = 1024 * 1024;
|
|
24
|
+
a = Math.max(a, i * (i < l ? 2 : 1.125) >>> 0), i != 0 && (a = Math.max(a, 256));
|
|
25
|
+
let o = f;
|
|
26
|
+
f = new Uint8Array(a), r > 0 && f.set(o.subarray(0, r), 0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var T = 12, _ = 5003, Z = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535];
|
|
30
|
+
function $(t, r, f, n, a = K(512), i = new Uint8Array(256), l = new Int32Array(_), o = new Int32Array(_)) {
|
|
31
|
+
let y = l.length, w = Math.max(2, n);
|
|
32
|
+
i.fill(0), o.fill(0), l.fill(-1);
|
|
33
|
+
let c = 0, e = 0, h = w + 1, x = h, s = !1, p = x, u = (1 << p) - 1, g = 1 << h - 1, E = g + 1, m = g + 2, b = 0, M = f[0], d = 0;
|
|
34
|
+
for (let A = y; A < 65536; A *= 2) ++d;
|
|
35
|
+
d = 8 - d, a.writeByte(w), U(g);
|
|
36
|
+
let B = f.length;
|
|
37
|
+
for (let A = 1; A < B; A++)
|
|
38
|
+
t: {
|
|
39
|
+
let V = f[A], q = (V << T) + M, v = V << d ^ M;
|
|
40
|
+
if (l[v] === q) {
|
|
41
|
+
M = o[v];
|
|
42
|
+
break t;
|
|
43
|
+
}
|
|
44
|
+
let I = v === 0 ? 1 : y - v;
|
|
45
|
+
for (; l[v] >= 0; ) if (v -= I, v < 0 && (v += y), l[v] === q) {
|
|
46
|
+
M = o[v];
|
|
47
|
+
break t;
|
|
48
|
+
}
|
|
49
|
+
U(M), M = V, m < 1 << T ? (o[v] = m++, l[v] = q) : (l.fill(-1), m = g + 2, s = !0, U(g));
|
|
50
|
+
}
|
|
51
|
+
return U(M), U(E), a.writeByte(0), a.bytesView();
|
|
52
|
+
function U(A) {
|
|
53
|
+
for (c &= Z[e], e > 0 ? c |= A << e : c = A, e += p; e >= 8; ) i[b++] = c & 255, b >= 254 && (a.writeByte(b), a.writeBytesView(i, 0, b), b = 0), c >>= 8, e -= 8;
|
|
54
|
+
if ((m > u || s) && (s ? (p = x, u = (1 << p) - 1, s = !1) : (++p, u = p === T ? 1 << p : (1 << p) - 1)), A == E) {
|
|
55
|
+
for (; e > 0; ) i[b++] = c & 255, b >= 254 && (a.writeByte(b), a.writeBytesView(i, 0, b), b = 0), c >>= 8, e -= 8;
|
|
56
|
+
b > 0 && (a.writeByte(b), a.writeBytesView(i, 0, b), b = 0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var W = $;
|
|
61
|
+
function N(t, r, f) {
|
|
62
|
+
return t << 8 & 63488 | r << 2 & 992 | f >> 3;
|
|
63
|
+
}
|
|
64
|
+
function O(t, r, f, n) {
|
|
65
|
+
return t >> 4 | r & 240 | (f & 240) << 4 | (n & 240) << 8;
|
|
66
|
+
}
|
|
67
|
+
function Q(t, r, f) {
|
|
68
|
+
return t >> 4 << 8 | r & 240 | f >> 4;
|
|
69
|
+
}
|
|
70
|
+
function F(t, r, f) {
|
|
71
|
+
return t < r ? r : t > f ? f : t;
|
|
72
|
+
}
|
|
73
|
+
function R(t) {
|
|
74
|
+
return t * t;
|
|
75
|
+
}
|
|
76
|
+
function j(t, r, f) {
|
|
77
|
+
var n = 0, a = 1e100;
|
|
78
|
+
let i = t[r], l = i.cnt;
|
|
79
|
+
i.ac;
|
|
80
|
+
let o = i.rc, y = i.gc, w = i.bc;
|
|
81
|
+
for (var c = i.fw; c != 0; c = t[c].fw) {
|
|
82
|
+
let h = t[c], x = h.cnt, s = l * x / (l + x);
|
|
83
|
+
if (!(s >= a)) {
|
|
84
|
+
var e = 0;
|
|
85
|
+
e += s * R(h.rc - o), !(e >= a) && (e += s * R(h.gc - y), !(e >= a) && (e += s * R(h.bc - w), !(e >= a) && (a = e, n = c)));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
i.err = a, i.nn = n;
|
|
89
|
+
}
|
|
90
|
+
function D() {
|
|
91
|
+
return { ac: 0, rc: 0, gc: 0, bc: 0, cnt: 0, nn: 0, fw: 0, bk: 0, tm: 0, mtm: 0, err: 0 };
|
|
92
|
+
}
|
|
93
|
+
function tt(t, r) {
|
|
94
|
+
let f = r === "rgb444" ? 4096 : 65536, n = new Array(f), a = t.length;
|
|
95
|
+
if (r === "rgba4444") for (let i = 0; i < a; ++i) {
|
|
96
|
+
let l = t[i], o = l >> 24 & 255, y = l >> 16 & 255, w = l >> 8 & 255, c = l & 255, e = O(c, w, y, o), h = e in n ? n[e] : n[e] = D();
|
|
97
|
+
h.rc += c, h.gc += w, h.bc += y, h.ac += o, h.cnt++;
|
|
98
|
+
}
|
|
99
|
+
else if (r === "rgb444") for (let i = 0; i < a; ++i) {
|
|
100
|
+
let l = t[i], o = l >> 16 & 255, y = l >> 8 & 255, w = l & 255, c = Q(w, y, o), e = c in n ? n[c] : n[c] = D();
|
|
101
|
+
e.rc += w, e.gc += y, e.bc += o, e.cnt++;
|
|
102
|
+
}
|
|
103
|
+
else for (let i = 0; i < a; ++i) {
|
|
104
|
+
let l = t[i], o = l >> 16 & 255, y = l >> 8 & 255, w = l & 255, c = N(w, y, o), e = c in n ? n[c] : n[c] = D();
|
|
105
|
+
e.rc += w, e.gc += y, e.bc += o, e.cnt++;
|
|
106
|
+
}
|
|
107
|
+
return n;
|
|
108
|
+
}
|
|
109
|
+
function wt(t, r, f = {}) {
|
|
110
|
+
let { format: n = "rgb565", clearAlpha: a = !0, clearAlphaColor: i = 0, clearAlphaThreshold: l = 0, oneBitAlpha: o = !1 } = f;
|
|
111
|
+
if (!t || !t.buffer) throw new Error("quantize() expected RGBA Uint8Array data");
|
|
112
|
+
if (!(t instanceof Uint8Array) && !(t instanceof Uint8ClampedArray)) throw new Error("quantize() expected RGBA Uint8Array data");
|
|
113
|
+
let y = new Uint32Array(t.buffer), w = f.useSqrt !== !1, c = n === "rgba4444", e = tt(y, n), h = e.length, x = h - 1, s = new Uint32Array(h + 1);
|
|
114
|
+
for (var p = 0, u = 0; u < h; ++u) {
|
|
115
|
+
let k = e[u];
|
|
116
|
+
if (k != null) {
|
|
117
|
+
var g = 1 / k.cnt;
|
|
118
|
+
c && (k.ac *= g), k.rc *= g, k.gc *= g, k.bc *= g, e[p++] = k;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
R(r) / p < 0.022 && (w = !1);
|
|
122
|
+
for (var u = 0; u < p - 1; ++u) e[u].fw = u + 1, e[u + 1].bk = u, w && (e[u].cnt = Math.sqrt(e[u].cnt));
|
|
123
|
+
w && (e[u].cnt = Math.sqrt(e[u].cnt));
|
|
124
|
+
var E, m, b;
|
|
125
|
+
for (u = 0; u < p; ++u) {
|
|
126
|
+
j(e, u);
|
|
127
|
+
var M = e[u].err;
|
|
128
|
+
for (m = ++s[0]; m > 1 && (b = m >> 1, !(e[E = s[b]].err <= M)); m = b) s[m] = E;
|
|
129
|
+
s[m] = u;
|
|
130
|
+
}
|
|
131
|
+
var d = p - r;
|
|
132
|
+
for (u = 0; u < d; ) {
|
|
133
|
+
for (var B; ; ) {
|
|
134
|
+
var U = s[1];
|
|
135
|
+
if (B = e[U], B.tm >= B.mtm && e[B.nn].mtm <= B.tm) break;
|
|
136
|
+
B.mtm == x ? U = s[1] = s[s[0]--] : (j(e, U), B.tm = u);
|
|
137
|
+
var M = e[U].err;
|
|
138
|
+
for (m = 1; (b = m + m) <= s[0] && (b < s[0] && e[s[b]].err > e[s[b + 1]].err && b++, !(M <= e[E = s[b]].err)); m = b) s[m] = E;
|
|
139
|
+
s[m] = U;
|
|
140
|
+
}
|
|
141
|
+
var A = e[B.nn], V = B.cnt, q = A.cnt, g = 1 / (V + q);
|
|
142
|
+
c && (B.ac = g * (V * B.ac + q * A.ac)), B.rc = g * (V * B.rc + q * A.rc), B.gc = g * (V * B.gc + q * A.gc), B.bc = g * (V * B.bc + q * A.bc), B.cnt += A.cnt, B.mtm = ++u, e[A.bk].fw = A.fw, e[A.fw].bk = A.bk, A.mtm = x;
|
|
143
|
+
}
|
|
144
|
+
let v = [];
|
|
145
|
+
var I = 0;
|
|
146
|
+
for (u = 0; ; ++I) {
|
|
147
|
+
let k = F(Math.round(e[u].rc), 0, 255), P = F(Math.round(e[u].gc), 0, 255), S = F(Math.round(e[u].bc), 0, 255), G = 255;
|
|
148
|
+
c && (G = F(Math.round(e[u].ac), 0, 255), o && (G = G <= (typeof o == "number" ? o : 127) ? 0 : 255), a && G <= l && (k = P = S = i, G = 0));
|
|
149
|
+
let L = c ? [k, P, S, G] : [k, P, S];
|
|
150
|
+
if (et(v, L) || v.push(L), (u = e[u].fw) == 0) break;
|
|
151
|
+
}
|
|
152
|
+
return v;
|
|
153
|
+
}
|
|
154
|
+
function et(t, r) {
|
|
155
|
+
for (let f = 0; f < t.length; f++) {
|
|
156
|
+
let n = t[f], a = n[0] === r[0] && n[1] === r[1] && n[2] === r[2], i = n.length >= 4 && r.length >= 4 ? n[3] === r[3] : !0;
|
|
157
|
+
if (a && i) return !0;
|
|
158
|
+
}
|
|
159
|
+
return !1;
|
|
160
|
+
}
|
|
161
|
+
function ut(t, r, f = "rgb565") {
|
|
162
|
+
if (!t || !t.buffer) throw new Error("quantize() expected RGBA Uint8Array data");
|
|
163
|
+
if (!(t instanceof Uint8Array) && !(t instanceof Uint8ClampedArray)) throw new Error("quantize() expected RGBA Uint8Array data");
|
|
164
|
+
if (r.length > 256) throw new Error("applyPalette() only works with 256 colors or less");
|
|
165
|
+
let n = new Uint32Array(t.buffer), a = n.length, i = f === "rgb444" ? 4096 : 65536, l = new Uint8Array(a), o = new Array(i);
|
|
166
|
+
if (f === "rgba4444") for (let y = 0; y < a; y++) {
|
|
167
|
+
let w = n[y], c = w >> 24 & 255, e = w >> 16 & 255, h = w >> 8 & 255, x = w & 255, s = O(x, h, e, c), p = s in o ? o[s] : o[s] = rt(x, h, e, c, r);
|
|
168
|
+
l[y] = p;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
let y = f === "rgb444" ? Q : N;
|
|
172
|
+
for (let w = 0; w < a; w++) {
|
|
173
|
+
let c = n[w], e = c >> 16 & 255, h = c >> 8 & 255, x = c & 255, s = y(x, h, e), p = s in o ? o[s] : o[s] = nt(x, h, e, r);
|
|
174
|
+
l[w] = p;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return l;
|
|
178
|
+
}
|
|
179
|
+
function rt(t, r, f, n, a) {
|
|
180
|
+
let i = 0, l = 1e100;
|
|
181
|
+
for (let o = 0; o < a.length; o++) {
|
|
182
|
+
let y = a[o], w = y[3], c = C(w - n);
|
|
183
|
+
if (c > l) continue;
|
|
184
|
+
let e = y[0];
|
|
185
|
+
if (c += C(e - t), c > l) continue;
|
|
186
|
+
let h = y[1];
|
|
187
|
+
if (c += C(h - r), c > l) continue;
|
|
188
|
+
let x = y[2];
|
|
189
|
+
c += C(x - f), !(c > l) && (l = c, i = o);
|
|
190
|
+
}
|
|
191
|
+
return i;
|
|
192
|
+
}
|
|
193
|
+
function nt(t, r, f, n) {
|
|
194
|
+
let a = 0, i = 1e100;
|
|
195
|
+
for (let l = 0; l < n.length; l++) {
|
|
196
|
+
let o = n[l], y = o[0], w = C(y - t);
|
|
197
|
+
if (w > i) continue;
|
|
198
|
+
let c = o[1];
|
|
199
|
+
if (w += C(c - r), w > i) continue;
|
|
200
|
+
let e = o[2];
|
|
201
|
+
w += C(e - f), !(w > i) && (i = w, a = l);
|
|
202
|
+
}
|
|
203
|
+
return a;
|
|
204
|
+
}
|
|
205
|
+
function C(t) {
|
|
206
|
+
return t * t;
|
|
207
|
+
}
|
|
208
|
+
function yt(t = {}) {
|
|
209
|
+
let { initialCapacity: r = 4096, auto: f = !0 } = t, n = K(r), a = 5003, i = new Uint8Array(256), l = new Int32Array(a), o = new Int32Array(a), y = !1;
|
|
210
|
+
return { reset() {
|
|
211
|
+
n.reset(), y = !1;
|
|
212
|
+
}, finish() {
|
|
213
|
+
n.writeByte(Y.trailer);
|
|
214
|
+
}, bytes() {
|
|
215
|
+
return n.bytes();
|
|
216
|
+
}, bytesView() {
|
|
217
|
+
return n.bytesView();
|
|
218
|
+
}, get buffer() {
|
|
219
|
+
return n.buffer;
|
|
220
|
+
}, get stream() {
|
|
221
|
+
return n;
|
|
222
|
+
}, writeHeader: w, writeFrame(c, e, h, x = {}) {
|
|
223
|
+
let { transparent: s = !1, transparentIndex: p = 0, delay: u = 0, palette: g = null, repeat: E = 0, colorDepth: m = 8, dispose: b = -1 } = x, M = !1;
|
|
224
|
+
if (f ? y || (M = !0, w(), y = !0) : M = !!x.first, e = Math.max(0, Math.floor(e)), h = Math.max(0, Math.floor(h)), M) {
|
|
225
|
+
if (!g) throw new Error("First frame must include a { palette } option");
|
|
226
|
+
it(n, e, h, g, m), J(n, g), E >= 0 && lt(n, E);
|
|
227
|
+
}
|
|
228
|
+
let d = Math.round(u / 10);
|
|
229
|
+
at(n, b, d, s, p);
|
|
230
|
+
let B = !!g && !M;
|
|
231
|
+
ft(n, e, h, B ? g : null), B && J(n, g), ct(n, c, e, h, m, i, l, o);
|
|
232
|
+
} };
|
|
233
|
+
function w() {
|
|
234
|
+
X(n, "GIF89a");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function at(t, r, f, n, a) {
|
|
238
|
+
t.writeByte(33), t.writeByte(249), t.writeByte(4), a < 0 && (a = 0, n = !1);
|
|
239
|
+
var i, l;
|
|
240
|
+
n ? (i = 1, l = 2) : (i = 0, l = 0), r >= 0 && (l = r & 7), l <<= 2, t.writeByte(0 | l | 0 | i), z(t, f), t.writeByte(a || 0), t.writeByte(0);
|
|
241
|
+
}
|
|
242
|
+
function it(t, r, f, n, a = 8) {
|
|
243
|
+
let i = 1, l = 0, o = H(n.length) - 1, y = i << 7 | a - 1 << 4 | l << 3 | o;
|
|
244
|
+
z(t, r), z(t, f), t.writeBytes([y, 0, 0]);
|
|
245
|
+
}
|
|
246
|
+
function lt(t, r) {
|
|
247
|
+
t.writeByte(33), t.writeByte(255), t.writeByte(11), X(t, "NETSCAPE2.0"), t.writeByte(3), t.writeByte(1), z(t, r), t.writeByte(0);
|
|
248
|
+
}
|
|
249
|
+
function J(t, r) {
|
|
250
|
+
let f = 1 << H(r.length);
|
|
251
|
+
for (let n = 0; n < f; n++) {
|
|
252
|
+
let a = [0, 0, 0];
|
|
253
|
+
n < r.length && (a = r[n]), t.writeByte(a[0]), t.writeByte(a[1]), t.writeByte(a[2]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function ft(t, r, f, n) {
|
|
257
|
+
if (t.writeByte(44), z(t, 0), z(t, 0), z(t, r), z(t, f), n) {
|
|
258
|
+
let a = 0, i = 0, l = H(n.length) - 1;
|
|
259
|
+
t.writeByte(128 | a | i | 0 | l);
|
|
260
|
+
} else t.writeByte(0);
|
|
261
|
+
}
|
|
262
|
+
function ct(t, r, f, n, a = 8, i, l, o) {
|
|
263
|
+
W(f, n, r, a, t, i, l, o);
|
|
264
|
+
}
|
|
265
|
+
function z(t, r) {
|
|
266
|
+
t.writeByte(r & 255), t.writeByte(r >> 8 & 255);
|
|
267
|
+
}
|
|
268
|
+
function X(t, r) {
|
|
269
|
+
for (var f = 0; f < r.length; f++) t.writeByte(r.charCodeAt(f));
|
|
270
|
+
}
|
|
271
|
+
function H(t) {
|
|
272
|
+
return Math.max(Math.ceil(Math.log2(t)), 1);
|
|
273
|
+
}
|
|
274
|
+
export {
|
|
275
|
+
yt as GIFEncoder,
|
|
276
|
+
ut as applyPalette,
|
|
277
|
+
wt as quantize
|
|
278
|
+
};
|