@silvery/examples 0.17.3 → 0.17.4

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.
Files changed (112) hide show
  1. package/dist/UPNG-Cy7ViL8f.mjs +5074 -0
  2. package/dist/__vite-browser-external-2447137e-BML7CYau.mjs +4 -0
  3. package/dist/_banner-DLPxCqVy.mjs +44 -0
  4. package/dist/ansi-CCE2pVS0.mjs +16397 -0
  5. package/dist/apng-HhhBjRGt.mjs +68 -0
  6. package/dist/apng-mwUQbTTF.mjs +3 -0
  7. package/dist/apps/aichat/index.mjs +1299 -0
  8. package/dist/apps/app-todo.mjs +139 -0
  9. package/dist/apps/async-data.mjs +204 -0
  10. package/dist/apps/cli-wizard.mjs +339 -0
  11. package/dist/apps/clipboard.mjs +198 -0
  12. package/dist/apps/components.mjs +864 -0
  13. package/dist/apps/data-explorer.mjs +483 -0
  14. package/dist/apps/dev-tools.mjs +397 -0
  15. package/dist/apps/explorer.mjs +698 -0
  16. package/dist/apps/gallery.mjs +766 -0
  17. package/dist/apps/inline-bench.mjs +115 -0
  18. package/dist/apps/kanban.mjs +280 -0
  19. package/dist/apps/layout-ref.mjs +187 -0
  20. package/dist/apps/outline.mjs +203 -0
  21. package/dist/apps/paste-demo.mjs +189 -0
  22. package/dist/apps/scroll.mjs +86 -0
  23. package/dist/apps/search-filter.mjs +287 -0
  24. package/dist/apps/selection.mjs +355 -0
  25. package/dist/apps/spatial-focus-demo.mjs +388 -0
  26. package/dist/apps/task-list.mjs +258 -0
  27. package/dist/apps/terminal-caps-demo.mjs +315 -0
  28. package/dist/apps/terminal.mjs +872 -0
  29. package/dist/apps/text-selection-demo.mjs +254 -0
  30. package/dist/apps/textarea.mjs +178 -0
  31. package/dist/apps/theme.mjs +661 -0
  32. package/dist/apps/transform.mjs +215 -0
  33. package/dist/apps/virtual-10k.mjs +422 -0
  34. package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
  35. package/dist/backends-Bahh9mKN.mjs +1179 -0
  36. package/dist/backends-CCtCDQ94.mjs +3 -0
  37. package/dist/{cli.mjs → bin/cli.mjs} +15 -19
  38. package/dist/chunk-BSw8zbkd.mjs +37 -0
  39. package/dist/components/counter.mjs +48 -0
  40. package/dist/components/hello.mjs +31 -0
  41. package/dist/components/progress-bar.mjs +59 -0
  42. package/dist/components/select-list.mjs +85 -0
  43. package/dist/components/spinner.mjs +57 -0
  44. package/dist/components/text-input.mjs +62 -0
  45. package/dist/components/virtual-list.mjs +51 -0
  46. package/dist/flexily-zero-adapter-UB-ra8fR.mjs +3374 -0
  47. package/dist/gif-BZaqPPVX.mjs +3 -0
  48. package/dist/gif-BtnXuxLF.mjs +71 -0
  49. package/dist/gifenc-CLRW41dk.mjs +728 -0
  50. package/dist/jsx-runtime-dMs_8fNu.mjs +241 -0
  51. package/dist/key-mapping-5oYQdAQE.mjs +3 -0
  52. package/dist/key-mapping-D4LR1go6.mjs +130 -0
  53. package/dist/layout/dashboard.mjs +1204 -0
  54. package/dist/layout/live-resize.mjs +303 -0
  55. package/dist/layout/overflow.mjs +70 -0
  56. package/dist/layout/text-layout.mjs +335 -0
  57. package/dist/node-NuJ94BWl.mjs +1083 -0
  58. package/dist/plugins-D1KtkT4a.mjs +3057 -0
  59. package/dist/resvg-js-C_8Wps1F.mjs +201 -0
  60. package/dist/src-BTEVGpd9.mjs +23538 -0
  61. package/dist/src-CUUOuRH6.mjs +5322 -0
  62. package/dist/src-CzfRafCQ.mjs +814 -0
  63. package/dist/usingCtx-CsEf0xO3.mjs +57 -0
  64. package/dist/yoga-adapter-BVtQ5OJR.mjs +237 -0
  65. package/package.json +18 -13
  66. package/_banner.tsx +0 -60
  67. package/apps/aichat/components.tsx +0 -469
  68. package/apps/aichat/index.tsx +0 -220
  69. package/apps/aichat/script.ts +0 -460
  70. package/apps/aichat/state.ts +0 -325
  71. package/apps/aichat/types.ts +0 -19
  72. package/apps/app-todo.tsx +0 -201
  73. package/apps/async-data.tsx +0 -196
  74. package/apps/cli-wizard.tsx +0 -332
  75. package/apps/clipboard.tsx +0 -183
  76. package/apps/components.tsx +0 -658
  77. package/apps/data-explorer.tsx +0 -490
  78. package/apps/dev-tools.tsx +0 -395
  79. package/apps/explorer.tsx +0 -731
  80. package/apps/gallery.tsx +0 -653
  81. package/apps/inline-bench.tsx +0 -138
  82. package/apps/kanban.tsx +0 -265
  83. package/apps/layout-ref.tsx +0 -173
  84. package/apps/outline.tsx +0 -160
  85. package/apps/panes/index.tsx +0 -203
  86. package/apps/paste-demo.tsx +0 -185
  87. package/apps/scroll.tsx +0 -80
  88. package/apps/search-filter.tsx +0 -240
  89. package/apps/selection.tsx +0 -346
  90. package/apps/spatial-focus-demo.tsx +0 -372
  91. package/apps/task-list.tsx +0 -271
  92. package/apps/terminal-caps-demo.tsx +0 -317
  93. package/apps/terminal.tsx +0 -784
  94. package/apps/text-selection-demo.tsx +0 -193
  95. package/apps/textarea.tsx +0 -155
  96. package/apps/theme.tsx +0 -515
  97. package/apps/transform.tsx +0 -229
  98. package/apps/virtual-10k.tsx +0 -405
  99. package/apps/vterm-demo/index.tsx +0 -216
  100. package/components/counter.tsx +0 -49
  101. package/components/hello.tsx +0 -38
  102. package/components/progress-bar.tsx +0 -52
  103. package/components/select-list.tsx +0 -54
  104. package/components/spinner.tsx +0 -44
  105. package/components/text-input.tsx +0 -61
  106. package/components/virtual-list.tsx +0 -56
  107. package/dist/cli.d.mts +0 -1
  108. package/dist/cli.mjs.map +0 -1
  109. package/layout/dashboard.tsx +0 -953
  110. package/layout/live-resize.tsx +0 -282
  111. package/layout/overflow.tsx +0 -51
  112. package/layout/text-layout.tsx +0 -283
@@ -0,0 +1,728 @@
1
+ import { t as __commonJSMin } from "./chunk-BSw8zbkd.mjs";
2
+ //#region ../../../node_modules/.bun/gifenc@1.0.3/node_modules/gifenc/dist/gifenc.js
3
+ var require_gifenc = /* @__PURE__ */ __commonJSMin(((exports) => {
4
+ var __defProp = Object.defineProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ __markAsModule(exports);
13
+ __export(exports, {
14
+ GIFEncoder: () => GIFEncoder,
15
+ applyPalette: () => applyPalette,
16
+ default: () => src_default,
17
+ nearestColor: () => nearestColor,
18
+ nearestColorIndex: () => nearestColorIndex,
19
+ nearestColorIndexWithDistance: () => nearestColorIndexWithDistance,
20
+ prequantize: () => prequantize,
21
+ quantize: () => quantize,
22
+ snapColorsToPalette: () => snapColorsToPalette
23
+ });
24
+ var constants_default = {
25
+ signature: "GIF",
26
+ version: "89a",
27
+ trailer: 59,
28
+ extensionIntroducer: 33,
29
+ applicationExtensionLabel: 255,
30
+ graphicControlExtensionLabel: 249,
31
+ imageSeparator: 44,
32
+ signatureSize: 3,
33
+ versionSize: 3,
34
+ globalColorTableFlagMask: 128,
35
+ colorResolutionMask: 112,
36
+ sortFlagMask: 8,
37
+ globalColorTableSizeMask: 7,
38
+ applicationIdentifierSize: 8,
39
+ applicationAuthCodeSize: 3,
40
+ disposalMethodMask: 28,
41
+ userInputFlagMask: 2,
42
+ transparentColorFlagMask: 1,
43
+ localColorTableFlagMask: 128,
44
+ interlaceFlagMask: 64,
45
+ idSortFlagMask: 32,
46
+ localColorTableSizeMask: 7
47
+ };
48
+ function createStream(initialCapacity = 256) {
49
+ let cursor = 0;
50
+ let contents = new Uint8Array(initialCapacity);
51
+ return {
52
+ get buffer() {
53
+ return contents.buffer;
54
+ },
55
+ reset() {
56
+ cursor = 0;
57
+ },
58
+ bytesView() {
59
+ return contents.subarray(0, cursor);
60
+ },
61
+ bytes() {
62
+ return contents.slice(0, cursor);
63
+ },
64
+ writeByte(byte) {
65
+ expand(cursor + 1);
66
+ contents[cursor] = byte;
67
+ cursor++;
68
+ },
69
+ writeBytes(data, offset = 0, byteLength = data.length) {
70
+ expand(cursor + byteLength);
71
+ for (let i = 0; i < byteLength; i++) contents[cursor++] = data[i + offset];
72
+ },
73
+ writeBytesView(data, offset = 0, byteLength = data.byteLength) {
74
+ expand(cursor + byteLength);
75
+ contents.set(data.subarray(offset, offset + byteLength), cursor);
76
+ cursor += byteLength;
77
+ }
78
+ };
79
+ function expand(newCapacity) {
80
+ var prevCapacity = contents.length;
81
+ if (prevCapacity >= newCapacity) return;
82
+ newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < 1024 * 1024 ? 2 : 1.125) >>> 0);
83
+ if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256);
84
+ const oldContents = contents;
85
+ contents = new Uint8Array(newCapacity);
86
+ if (cursor > 0) contents.set(oldContents.subarray(0, cursor), 0);
87
+ }
88
+ }
89
+ var BITS = 12;
90
+ var DEFAULT_HSIZE = 5003;
91
+ var MASKS = [
92
+ 0,
93
+ 1,
94
+ 3,
95
+ 7,
96
+ 15,
97
+ 31,
98
+ 63,
99
+ 127,
100
+ 255,
101
+ 511,
102
+ 1023,
103
+ 2047,
104
+ 4095,
105
+ 8191,
106
+ 16383,
107
+ 32767,
108
+ 65535
109
+ ];
110
+ function lzwEncode(width, height, pixels, colorDepth, outStream = createStream(512), accum = new Uint8Array(256), htab = new Int32Array(DEFAULT_HSIZE), codetab = new Int32Array(DEFAULT_HSIZE)) {
111
+ const hsize = htab.length;
112
+ const initCodeSize = Math.max(2, colorDepth);
113
+ accum.fill(0);
114
+ codetab.fill(0);
115
+ htab.fill(-1);
116
+ let cur_accum = 0;
117
+ let cur_bits = 0;
118
+ const init_bits = initCodeSize + 1;
119
+ const g_init_bits = init_bits;
120
+ let clear_flg = false;
121
+ let n_bits = g_init_bits;
122
+ let maxcode = (1 << n_bits) - 1;
123
+ const ClearCode = 1 << init_bits - 1;
124
+ const EOFCode = ClearCode + 1;
125
+ let free_ent = ClearCode + 2;
126
+ let a_count = 0;
127
+ let ent = pixels[0];
128
+ let hshift = 0;
129
+ for (let fcode = hsize; fcode < 65536; fcode *= 2) ++hshift;
130
+ hshift = 8 - hshift;
131
+ outStream.writeByte(initCodeSize);
132
+ output(ClearCode);
133
+ const length = pixels.length;
134
+ for (let idx = 1; idx < length; idx++) next_block: {
135
+ const c = pixels[idx];
136
+ const fcode = (c << BITS) + ent;
137
+ let i = c << hshift ^ ent;
138
+ if (htab[i] === fcode) {
139
+ ent = codetab[i];
140
+ break next_block;
141
+ }
142
+ const disp = i === 0 ? 1 : hsize - i;
143
+ while (htab[i] >= 0) {
144
+ i -= disp;
145
+ if (i < 0) i += hsize;
146
+ if (htab[i] === fcode) {
147
+ ent = codetab[i];
148
+ break next_block;
149
+ }
150
+ }
151
+ output(ent);
152
+ ent = c;
153
+ if (free_ent < 1 << BITS) {
154
+ codetab[i] = free_ent++;
155
+ htab[i] = fcode;
156
+ } else {
157
+ htab.fill(-1);
158
+ free_ent = ClearCode + 2;
159
+ clear_flg = true;
160
+ output(ClearCode);
161
+ }
162
+ }
163
+ output(ent);
164
+ output(EOFCode);
165
+ outStream.writeByte(0);
166
+ return outStream.bytesView();
167
+ function output(code) {
168
+ cur_accum &= MASKS[cur_bits];
169
+ if (cur_bits > 0) cur_accum |= code << cur_bits;
170
+ else cur_accum = code;
171
+ cur_bits += n_bits;
172
+ while (cur_bits >= 8) {
173
+ accum[a_count++] = cur_accum & 255;
174
+ if (a_count >= 254) {
175
+ outStream.writeByte(a_count);
176
+ outStream.writeBytesView(accum, 0, a_count);
177
+ a_count = 0;
178
+ }
179
+ cur_accum >>= 8;
180
+ cur_bits -= 8;
181
+ }
182
+ if (free_ent > maxcode || clear_flg) if (clear_flg) {
183
+ n_bits = g_init_bits;
184
+ maxcode = (1 << n_bits) - 1;
185
+ clear_flg = false;
186
+ } else {
187
+ ++n_bits;
188
+ maxcode = n_bits === BITS ? 1 << n_bits : (1 << n_bits) - 1;
189
+ }
190
+ if (code == EOFCode) {
191
+ while (cur_bits > 0) {
192
+ accum[a_count++] = cur_accum & 255;
193
+ if (a_count >= 254) {
194
+ outStream.writeByte(a_count);
195
+ outStream.writeBytesView(accum, 0, a_count);
196
+ a_count = 0;
197
+ }
198
+ cur_accum >>= 8;
199
+ cur_bits -= 8;
200
+ }
201
+ if (a_count > 0) {
202
+ outStream.writeByte(a_count);
203
+ outStream.writeBytesView(accum, 0, a_count);
204
+ a_count = 0;
205
+ }
206
+ }
207
+ }
208
+ }
209
+ var lzwEncode_default = lzwEncode;
210
+ function rgb888_to_rgb565(r, g, b) {
211
+ return r << 8 & 63488 | g << 2 & 992 | b >> 3;
212
+ }
213
+ function rgba8888_to_rgba4444(r, g, b, a) {
214
+ return r >> 4 | g & 240 | (b & 240) << 4 | (a & 240) << 8;
215
+ }
216
+ function rgb888_to_rgb444(r, g, b) {
217
+ return r >> 4 << 8 | g & 240 | b >> 4;
218
+ }
219
+ function clamp(value, min, max) {
220
+ return value < min ? min : value > max ? max : value;
221
+ }
222
+ function sqr(value) {
223
+ return value * value;
224
+ }
225
+ function find_nn(bins, idx, hasAlpha) {
226
+ var nn = 0;
227
+ var err = 1e100;
228
+ const bin1 = bins[idx];
229
+ const n1 = bin1.cnt;
230
+ const wa = bin1.ac;
231
+ const wr = bin1.rc;
232
+ const wg = bin1.gc;
233
+ const wb = bin1.bc;
234
+ for (var i = bin1.fw; i != 0; i = bins[i].fw) {
235
+ const bin = bins[i];
236
+ const n2 = bin.cnt;
237
+ const nerr2 = n1 * n2 / (n1 + n2);
238
+ if (nerr2 >= err) continue;
239
+ var nerr = 0;
240
+ if (hasAlpha) {
241
+ nerr += nerr2 * sqr(bin.ac - wa);
242
+ if (nerr >= err) continue;
243
+ }
244
+ nerr += nerr2 * sqr(bin.rc - wr);
245
+ if (nerr >= err) continue;
246
+ nerr += nerr2 * sqr(bin.gc - wg);
247
+ if (nerr >= err) continue;
248
+ nerr += nerr2 * sqr(bin.bc - wb);
249
+ if (nerr >= err) continue;
250
+ err = nerr;
251
+ nn = i;
252
+ }
253
+ bin1.err = err;
254
+ bin1.nn = nn;
255
+ }
256
+ function create_bin() {
257
+ return {
258
+ ac: 0,
259
+ rc: 0,
260
+ gc: 0,
261
+ bc: 0,
262
+ cnt: 0,
263
+ nn: 0,
264
+ fw: 0,
265
+ bk: 0,
266
+ tm: 0,
267
+ mtm: 0,
268
+ err: 0
269
+ };
270
+ }
271
+ function create_bin_list(data, format) {
272
+ const bins = new Array(format === "rgb444" ? 4096 : 65536);
273
+ const size = data.length;
274
+ if (format === "rgba4444") for (let i = 0; i < size; ++i) {
275
+ const color = data[i];
276
+ const a = color >> 24 & 255;
277
+ const b = color >> 16 & 255;
278
+ const g = color >> 8 & 255;
279
+ const r = color & 255;
280
+ const index = rgba8888_to_rgba4444(r, g, b, a);
281
+ let bin = index in bins ? bins[index] : bins[index] = create_bin();
282
+ bin.rc += r;
283
+ bin.gc += g;
284
+ bin.bc += b;
285
+ bin.ac += a;
286
+ bin.cnt++;
287
+ }
288
+ else if (format === "rgb444") for (let i = 0; i < size; ++i) {
289
+ const color = data[i];
290
+ const b = color >> 16 & 255;
291
+ const g = color >> 8 & 255;
292
+ const r = color & 255;
293
+ const index = rgb888_to_rgb444(r, g, b);
294
+ let bin = index in bins ? bins[index] : bins[index] = create_bin();
295
+ bin.rc += r;
296
+ bin.gc += g;
297
+ bin.bc += b;
298
+ bin.cnt++;
299
+ }
300
+ else for (let i = 0; i < size; ++i) {
301
+ const color = data[i];
302
+ const b = color >> 16 & 255;
303
+ const g = color >> 8 & 255;
304
+ const r = color & 255;
305
+ const index = rgb888_to_rgb565(r, g, b);
306
+ let bin = index in bins ? bins[index] : bins[index] = create_bin();
307
+ bin.rc += r;
308
+ bin.gc += g;
309
+ bin.bc += b;
310
+ bin.cnt++;
311
+ }
312
+ return bins;
313
+ }
314
+ function quantize(rgba, maxColors, opts = {}) {
315
+ const { format = "rgb565", clearAlpha = true, clearAlphaColor = 0, clearAlphaThreshold = 0, oneBitAlpha = false } = opts;
316
+ if (!rgba || !rgba.buffer) throw new Error("quantize() expected RGBA Uint8Array data");
317
+ if (!(rgba instanceof Uint8Array) && !(rgba instanceof Uint8ClampedArray)) throw new Error("quantize() expected RGBA Uint8Array data");
318
+ const data = new Uint32Array(rgba.buffer);
319
+ let useSqrt = opts.useSqrt !== false;
320
+ const hasAlpha = format === "rgba4444";
321
+ const bins = create_bin_list(data, format);
322
+ const bincount = bins.length;
323
+ const bincountMinusOne = bincount - 1;
324
+ const heap = new Uint32Array(bincount + 1);
325
+ var maxbins = 0;
326
+ for (var i = 0; i < bincount; ++i) {
327
+ const bin = bins[i];
328
+ if (bin != null) {
329
+ var d = 1 / bin.cnt;
330
+ if (hasAlpha) bin.ac *= d;
331
+ bin.rc *= d;
332
+ bin.gc *= d;
333
+ bin.bc *= d;
334
+ bins[maxbins++] = bin;
335
+ }
336
+ }
337
+ if (sqr(maxColors) / maxbins < .022) useSqrt = false;
338
+ var i = 0;
339
+ for (; i < maxbins - 1; ++i) {
340
+ bins[i].fw = i + 1;
341
+ bins[i + 1].bk = i;
342
+ if (useSqrt) bins[i].cnt = Math.sqrt(bins[i].cnt);
343
+ }
344
+ if (useSqrt) bins[i].cnt = Math.sqrt(bins[i].cnt);
345
+ var h, l, l2;
346
+ for (i = 0; i < maxbins; ++i) {
347
+ find_nn(bins, i, false);
348
+ var err = bins[i].err;
349
+ for (l = ++heap[0]; l > 1; l = l2) {
350
+ l2 = l >> 1;
351
+ if (bins[h = heap[l2]].err <= err) break;
352
+ heap[l] = h;
353
+ }
354
+ heap[l] = i;
355
+ }
356
+ var extbins = maxbins - maxColors;
357
+ for (i = 0; i < extbins;) {
358
+ var tb;
359
+ for (;;) {
360
+ var b1 = heap[1];
361
+ tb = bins[b1];
362
+ if (tb.tm >= tb.mtm && bins[tb.nn].mtm <= tb.tm) break;
363
+ if (tb.mtm == bincountMinusOne) b1 = heap[1] = heap[heap[0]--];
364
+ else {
365
+ find_nn(bins, b1, false);
366
+ tb.tm = i;
367
+ }
368
+ var err = bins[b1].err;
369
+ for (l = 1; (l2 = l + l) <= heap[0]; l = l2) {
370
+ if (l2 < heap[0] && bins[heap[l2]].err > bins[heap[l2 + 1]].err) l2++;
371
+ if (err <= bins[h = heap[l2]].err) break;
372
+ heap[l] = h;
373
+ }
374
+ heap[l] = b1;
375
+ }
376
+ var nb = bins[tb.nn];
377
+ var n1 = tb.cnt;
378
+ var n2 = nb.cnt;
379
+ var d = 1 / (n1 + n2);
380
+ if (hasAlpha) tb.ac = d * (n1 * tb.ac + n2 * nb.ac);
381
+ tb.rc = d * (n1 * tb.rc + n2 * nb.rc);
382
+ tb.gc = d * (n1 * tb.gc + n2 * nb.gc);
383
+ tb.bc = d * (n1 * tb.bc + n2 * nb.bc);
384
+ tb.cnt += nb.cnt;
385
+ tb.mtm = ++i;
386
+ bins[nb.bk].fw = nb.fw;
387
+ bins[nb.fw].bk = nb.bk;
388
+ nb.mtm = bincountMinusOne;
389
+ }
390
+ let palette = [];
391
+ var k = 0;
392
+ for (i = 0;; ++k) {
393
+ let r = clamp(Math.round(bins[i].rc), 0, 255);
394
+ let g = clamp(Math.round(bins[i].gc), 0, 255);
395
+ let b = clamp(Math.round(bins[i].bc), 0, 255);
396
+ let a = 255;
397
+ if (hasAlpha) {
398
+ a = clamp(Math.round(bins[i].ac), 0, 255);
399
+ if (oneBitAlpha) a = a <= (typeof oneBitAlpha === "number" ? oneBitAlpha : 127) ? 0 : 255;
400
+ if (clearAlpha && a <= clearAlphaThreshold) {
401
+ r = g = b = clearAlphaColor;
402
+ a = 0;
403
+ }
404
+ }
405
+ const color = hasAlpha ? [
406
+ r,
407
+ g,
408
+ b,
409
+ a
410
+ ] : [
411
+ r,
412
+ g,
413
+ b
414
+ ];
415
+ if (!existsInPalette(palette, color)) palette.push(color);
416
+ if ((i = bins[i].fw) == 0) break;
417
+ }
418
+ return palette;
419
+ }
420
+ function existsInPalette(palette, color) {
421
+ for (let i = 0; i < palette.length; i++) {
422
+ const p = palette[i];
423
+ let matchesRGB = p[0] === color[0] && p[1] === color[1] && p[2] === color[2];
424
+ let matchesAlpha = p.length >= 4 && color.length >= 4 ? p[3] === color[3] : true;
425
+ if (matchesRGB && matchesAlpha) return true;
426
+ }
427
+ return false;
428
+ }
429
+ function euclideanDistanceSquared(a, b) {
430
+ var sum = 0;
431
+ var n;
432
+ for (n = 0; n < a.length; n++) {
433
+ const dx = a[n] - b[n];
434
+ sum += dx * dx;
435
+ }
436
+ return sum;
437
+ }
438
+ function roundStep(byte, step) {
439
+ return step > 1 ? Math.round(byte / step) * step : byte;
440
+ }
441
+ function prequantize(rgba, { roundRGB = 5, roundAlpha = 10, oneBitAlpha = null } = {}) {
442
+ const data = new Uint32Array(rgba.buffer);
443
+ for (let i = 0; i < data.length; i++) {
444
+ const color = data[i];
445
+ let a = color >> 24 & 255;
446
+ let b = color >> 16 & 255;
447
+ let g = color >> 8 & 255;
448
+ let r = color & 255;
449
+ a = roundStep(a, roundAlpha);
450
+ if (oneBitAlpha) a = a <= (typeof oneBitAlpha === "number" ? oneBitAlpha : 127) ? 0 : 255;
451
+ r = roundStep(r, roundRGB);
452
+ g = roundStep(g, roundRGB);
453
+ b = roundStep(b, roundRGB);
454
+ data[i] = a << 24 | b << 16 | g << 8 | r << 0;
455
+ }
456
+ }
457
+ function applyPalette(rgba, palette, format = "rgb565") {
458
+ if (!rgba || !rgba.buffer) throw new Error("quantize() expected RGBA Uint8Array data");
459
+ if (!(rgba instanceof Uint8Array) && !(rgba instanceof Uint8ClampedArray)) throw new Error("quantize() expected RGBA Uint8Array data");
460
+ if (palette.length > 256) throw new Error("applyPalette() only works with 256 colors or less");
461
+ const data = new Uint32Array(rgba.buffer);
462
+ const length = data.length;
463
+ const bincount = format === "rgb444" ? 4096 : 65536;
464
+ const index = new Uint8Array(length);
465
+ const cache = new Array(bincount);
466
+ if (format === "rgba4444") for (let i = 0; i < length; i++) {
467
+ const color = data[i];
468
+ const a = color >> 24 & 255;
469
+ const b = color >> 16 & 255;
470
+ const g = color >> 8 & 255;
471
+ const r = color & 255;
472
+ const key = rgba8888_to_rgba4444(r, g, b, a);
473
+ index[i] = key in cache ? cache[key] : cache[key] = nearestColorIndexRGBA(r, g, b, a, palette);
474
+ }
475
+ else {
476
+ const rgb888_to_key = format === "rgb444" ? rgb888_to_rgb444 : rgb888_to_rgb565;
477
+ for (let i = 0; i < length; i++) {
478
+ const color = data[i];
479
+ const b = color >> 16 & 255;
480
+ const g = color >> 8 & 255;
481
+ const r = color & 255;
482
+ const key = rgb888_to_key(r, g, b);
483
+ index[i] = key in cache ? cache[key] : cache[key] = nearestColorIndexRGB(r, g, b, palette);
484
+ }
485
+ }
486
+ return index;
487
+ }
488
+ function nearestColorIndexRGBA(r, g, b, a, palette) {
489
+ let k = 0;
490
+ let mindist = 1e100;
491
+ for (let i = 0; i < palette.length; i++) {
492
+ const px2 = palette[i];
493
+ const a2 = px2[3];
494
+ let curdist = sqr2(a2 - a);
495
+ if (curdist > mindist) continue;
496
+ const r2 = px2[0];
497
+ curdist += sqr2(r2 - r);
498
+ if (curdist > mindist) continue;
499
+ const g2 = px2[1];
500
+ curdist += sqr2(g2 - g);
501
+ if (curdist > mindist) continue;
502
+ const b2 = px2[2];
503
+ curdist += sqr2(b2 - b);
504
+ if (curdist > mindist) continue;
505
+ mindist = curdist;
506
+ k = i;
507
+ }
508
+ return k;
509
+ }
510
+ function nearestColorIndexRGB(r, g, b, palette) {
511
+ let k = 0;
512
+ let mindist = 1e100;
513
+ for (let i = 0; i < palette.length; i++) {
514
+ const px2 = palette[i];
515
+ const r2 = px2[0];
516
+ let curdist = sqr2(r2 - r);
517
+ if (curdist > mindist) continue;
518
+ const g2 = px2[1];
519
+ curdist += sqr2(g2 - g);
520
+ if (curdist > mindist) continue;
521
+ const b2 = px2[2];
522
+ curdist += sqr2(b2 - b);
523
+ if (curdist > mindist) continue;
524
+ mindist = curdist;
525
+ k = i;
526
+ }
527
+ return k;
528
+ }
529
+ function snapColorsToPalette(palette, knownColors, threshold = 5) {
530
+ if (!palette.length || !knownColors.length) return;
531
+ const paletteRGB = palette.map((p) => p.slice(0, 3));
532
+ const thresholdSq = threshold * threshold;
533
+ const dim = palette[0].length;
534
+ for (let i = 0; i < knownColors.length; i++) {
535
+ let color = knownColors[i];
536
+ if (color.length < dim) color = [
537
+ color[0],
538
+ color[1],
539
+ color[2],
540
+ 255
541
+ ];
542
+ else if (color.length > dim) color = color.slice(0, 3);
543
+ else color = color.slice();
544
+ const r = nearestColorIndexWithDistance(paletteRGB, color.slice(0, 3), euclideanDistanceSquared);
545
+ const idx = r[0];
546
+ const distanceSq = r[1];
547
+ if (distanceSq > 0 && distanceSq <= thresholdSq) palette[idx] = color;
548
+ }
549
+ }
550
+ function sqr2(a) {
551
+ return a * a;
552
+ }
553
+ function nearestColorIndex(colors, pixel, distanceFn = euclideanDistanceSquared) {
554
+ let minDist = Infinity;
555
+ let minDistIndex = -1;
556
+ for (let j = 0; j < colors.length; j++) {
557
+ const paletteColor = colors[j];
558
+ const dist = distanceFn(pixel, paletteColor);
559
+ if (dist < minDist) {
560
+ minDist = dist;
561
+ minDistIndex = j;
562
+ }
563
+ }
564
+ return minDistIndex;
565
+ }
566
+ function nearestColorIndexWithDistance(colors, pixel, distanceFn = euclideanDistanceSquared) {
567
+ let minDist = Infinity;
568
+ let minDistIndex = -1;
569
+ for (let j = 0; j < colors.length; j++) {
570
+ const paletteColor = colors[j];
571
+ const dist = distanceFn(pixel, paletteColor);
572
+ if (dist < minDist) {
573
+ minDist = dist;
574
+ minDistIndex = j;
575
+ }
576
+ }
577
+ return [minDistIndex, minDist];
578
+ }
579
+ function nearestColor(colors, pixel, distanceFn = euclideanDistanceSquared) {
580
+ return colors[nearestColorIndex(colors, pixel, distanceFn)];
581
+ }
582
+ function GIFEncoder(opt = {}) {
583
+ const { initialCapacity = 4096, auto = true } = opt;
584
+ const stream = createStream(initialCapacity);
585
+ const HSIZE = 5003;
586
+ const accum = new Uint8Array(256);
587
+ const htab = new Int32Array(HSIZE);
588
+ const codetab = new Int32Array(HSIZE);
589
+ let hasInit = false;
590
+ return {
591
+ reset() {
592
+ stream.reset();
593
+ hasInit = false;
594
+ },
595
+ finish() {
596
+ stream.writeByte(constants_default.trailer);
597
+ },
598
+ bytes() {
599
+ return stream.bytes();
600
+ },
601
+ bytesView() {
602
+ return stream.bytesView();
603
+ },
604
+ get buffer() {
605
+ return stream.buffer;
606
+ },
607
+ get stream() {
608
+ return stream;
609
+ },
610
+ writeHeader,
611
+ writeFrame(index, width, height, opts = {}) {
612
+ const { transparent = false, transparentIndex = 0, delay = 0, palette = null, repeat = 0, colorDepth = 8, dispose = -1 } = opts;
613
+ let first = false;
614
+ if (auto) {
615
+ if (!hasInit) {
616
+ first = true;
617
+ writeHeader();
618
+ hasInit = true;
619
+ }
620
+ } else first = Boolean(opts.first);
621
+ width = Math.max(0, Math.floor(width));
622
+ height = Math.max(0, Math.floor(height));
623
+ if (first) {
624
+ if (!palette) throw new Error("First frame must include a { palette } option");
625
+ encodeLogicalScreenDescriptor(stream, width, height, palette, colorDepth);
626
+ encodeColorTable(stream, palette);
627
+ if (repeat >= 0) encodeNetscapeExt(stream, repeat);
628
+ }
629
+ encodeGraphicControlExt(stream, dispose, Math.round(delay / 10), transparent, transparentIndex);
630
+ const useLocalColorTable = Boolean(palette) && !first;
631
+ encodeImageDescriptor(stream, width, height, useLocalColorTable ? palette : null);
632
+ if (useLocalColorTable) encodeColorTable(stream, palette);
633
+ encodePixels(stream, index, width, height, colorDepth, accum, htab, codetab);
634
+ }
635
+ };
636
+ function writeHeader() {
637
+ writeUTFBytes(stream, "GIF89a");
638
+ }
639
+ }
640
+ function encodeGraphicControlExt(stream, dispose, delay, transparent, transparentIndex) {
641
+ stream.writeByte(33);
642
+ stream.writeByte(249);
643
+ stream.writeByte(4);
644
+ if (transparentIndex < 0) {
645
+ transparentIndex = 0;
646
+ transparent = false;
647
+ }
648
+ var transp, disp;
649
+ if (!transparent) {
650
+ transp = 0;
651
+ disp = 0;
652
+ } else {
653
+ transp = 1;
654
+ disp = 2;
655
+ }
656
+ if (dispose >= 0) disp = dispose & 7;
657
+ disp <<= 2;
658
+ stream.writeByte(disp | 0 | transp);
659
+ writeUInt16(stream, delay);
660
+ stream.writeByte(transparentIndex || 0);
661
+ stream.writeByte(0);
662
+ }
663
+ function encodeLogicalScreenDescriptor(stream, width, height, palette, colorDepth = 8) {
664
+ const globalColorTableSize = colorTableSize(palette.length) - 1;
665
+ const fields = colorDepth - 1 << 4 | 128 | globalColorTableSize;
666
+ const backgroundColorIndex = 0;
667
+ const pixelAspectRatio = 0;
668
+ writeUInt16(stream, width);
669
+ writeUInt16(stream, height);
670
+ stream.writeBytes([
671
+ fields,
672
+ backgroundColorIndex,
673
+ pixelAspectRatio
674
+ ]);
675
+ }
676
+ function encodeNetscapeExt(stream, repeat) {
677
+ stream.writeByte(33);
678
+ stream.writeByte(255);
679
+ stream.writeByte(11);
680
+ writeUTFBytes(stream, "NETSCAPE2.0");
681
+ stream.writeByte(3);
682
+ stream.writeByte(1);
683
+ writeUInt16(stream, repeat);
684
+ stream.writeByte(0);
685
+ }
686
+ function encodeColorTable(stream, palette) {
687
+ const colorTableLength = 1 << colorTableSize(palette.length);
688
+ for (let i = 0; i < colorTableLength; i++) {
689
+ let color = [
690
+ 0,
691
+ 0,
692
+ 0
693
+ ];
694
+ if (i < palette.length) color = palette[i];
695
+ stream.writeByte(color[0]);
696
+ stream.writeByte(color[1]);
697
+ stream.writeByte(color[2]);
698
+ }
699
+ }
700
+ function encodeImageDescriptor(stream, width, height, localPalette) {
701
+ stream.writeByte(44);
702
+ writeUInt16(stream, 0);
703
+ writeUInt16(stream, 0);
704
+ writeUInt16(stream, width);
705
+ writeUInt16(stream, height);
706
+ if (localPalette) {
707
+ const palSize = colorTableSize(localPalette.length) - 1;
708
+ stream.writeByte(128 | palSize);
709
+ } else stream.writeByte(0);
710
+ }
711
+ function encodePixels(stream, index, width, height, colorDepth = 8, accum, htab, codetab) {
712
+ lzwEncode_default(width, height, index, colorDepth, stream, accum, htab, codetab);
713
+ }
714
+ function writeUInt16(stream, short) {
715
+ stream.writeByte(short & 255);
716
+ stream.writeByte(short >> 8 & 255);
717
+ }
718
+ function writeUTFBytes(stream, text) {
719
+ for (var i = 0; i < text.length; i++) stream.writeByte(text.charCodeAt(i));
720
+ }
721
+ function colorTableSize(length) {
722
+ return Math.max(Math.ceil(Math.log2(length)), 1);
723
+ }
724
+ var src_default = GIFEncoder;
725
+ }));
726
+ //#endregion
727
+ export default require_gifenc();
728
+ export {};