token-goat 2.9.14 → 2.9.16

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 (46) hide show
  1. package/README.md +15 -1
  2. package/dist/{token-goat-chunk-2ESBO4IN.mjs → token-goat-chunk-2IEIBVVD.mjs} +16 -9
  3. package/dist/{token-goat-chunk-RUDOKYPJ.mjs → token-goat-chunk-2PCFAQAS.mjs} +6582 -6194
  4. package/dist/{token-goat-chunk-AMYCQJX4.mjs → token-goat-chunk-3H6FQT62.mjs} +49 -256
  5. package/dist/{token-goat-chunk-PRJVGIC5.mjs → token-goat-chunk-4DC6DDIB.mjs} +7 -5
  6. package/dist/token-goat-chunk-4EXFN2AW.mjs +29 -0
  7. package/dist/{token-goat-chunk-VZYD4OZB.mjs → token-goat-chunk-5USHO7B6.mjs} +416 -4168
  8. package/dist/token-goat-chunk-63QWJ6UM.mjs +277 -0
  9. package/dist/token-goat-chunk-BFNTLGVA.mjs +4547 -0
  10. package/dist/token-goat-chunk-BGHSSJUA.mjs +102 -0
  11. package/dist/{token-goat-chunk-T2IWWTHB.mjs → token-goat-chunk-DMQ32ZSR.mjs} +35 -1142
  12. package/dist/{token-goat-chunk-DBNY4RLN.mjs → token-goat-chunk-EJCY6KHO.mjs} +5 -3
  13. package/dist/token-goat-chunk-ERTXEKB6.mjs +228 -0
  14. package/dist/{token-goat-chunk-Z6UXPYJA.mjs → token-goat-chunk-F2ARFHLJ.mjs} +1 -1
  15. package/dist/{token-goat-chunk-EG3663UT.mjs → token-goat-chunk-GIMGT34T.mjs} +4 -2
  16. package/dist/{token-goat-chunk-XVZ4MNQC.mjs → token-goat-chunk-GMXBQS6O.mjs} +360 -116
  17. package/dist/{token-goat-chunk-SAQ5PG4L.mjs → token-goat-chunk-H3DXI6VD.mjs} +8 -4
  18. package/dist/token-goat-chunk-LJL6FGDS.mjs +35 -0
  19. package/dist/{token-goat-chunk-NEI4NC54.mjs → token-goat-chunk-LKSXAMJB.mjs} +7 -2
  20. package/dist/token-goat-chunk-LMFO66YD.mjs +331 -0
  21. package/dist/{token-goat-chunk-7OGKZ7AP.mjs → token-goat-chunk-M2R4UQ3B.mjs} +5 -3
  22. package/dist/{token-goat-chunk-YHGTGG6K.mjs → token-goat-chunk-MA5BZ2KI.mjs} +68 -7
  23. package/dist/{token-goat-chunk-ASVVF4JV.mjs → token-goat-chunk-MIL62GMN.mjs} +171 -23
  24. package/dist/{token-goat-chunk-ZFM4PWXL.mjs → token-goat-chunk-NAMH252H.mjs} +10 -7
  25. package/dist/{token-goat-chunk-YTQHZJXW.mjs → token-goat-chunk-NOBZV7PM.mjs} +96 -22
  26. package/dist/{token-goat-chunk-4SDX3QP3.mjs → token-goat-chunk-NQZCSVN2.mjs} +13 -5
  27. package/dist/{token-goat-chunk-XEH6KBWW.mjs → token-goat-chunk-OCI25AXY.mjs} +4 -3
  28. package/dist/token-goat-chunk-OSUFN2FV.mjs +326 -0
  29. package/dist/{token-goat-chunk-O5WAMISC.mjs → token-goat-chunk-QMZMHQRR.mjs} +29 -18
  30. package/dist/{token-goat-chunk-POBYR64E.mjs → token-goat-chunk-R3X5TCPB.mjs} +801 -3
  31. package/dist/token-goat-chunk-RRNZMM3A.mjs +3364 -0
  32. package/dist/{token-goat-chunk-PGGDW7DZ.mjs → token-goat-chunk-ULA4WCED.mjs} +9 -6
  33. package/dist/token-goat-chunk-UMXD2M7O.mjs +975 -0
  34. package/dist/{token-goat-chunk-3XQPEJMV.mjs → token-goat-chunk-UXHDBVUR.mjs} +1 -1
  35. package/dist/{token-goat-chunk-EZNVAIR3.mjs → token-goat-chunk-VVIYEFBI.mjs} +4 -3
  36. package/dist/token-goat-chunk-XOHTFRDH.mjs +10760 -0
  37. package/dist/{token-goat-chunk-HF6H7RNK.mjs → token-goat-chunk-YPS64ACE.mjs} +13 -3
  38. package/dist/{token-goat-chunk-DAMXYVIW.mjs → token-goat-chunk-Z5VPAXTC.mjs} +2560 -820
  39. package/dist/{token-goat-chunk-XQF5J25J.mjs → token-goat-chunk-ZEHFYJ7Z.mjs} +5 -4
  40. package/dist/token-goat-hook.mjs +15 -10
  41. package/dist/token-goat.core.mjs +24 -18
  42. package/docs/cli.md +8 -6
  43. package/package.json +1 -1
  44. package/dist/token-goat-chunk-IT6O3PNN.mjs +0 -15463
  45. package/dist/token-goat-chunk-ZD4EM4LR.mjs +0 -30
  46. package/dist/token-goat-chunk-ZYNNQ36L.mjs +0 -479
@@ -0,0 +1,102 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ GIF_WEB_PALETTE,
5
+ assertDecodableSize,
6
+ quantizeRgbaToIndexed,
7
+ require_omggif,
8
+ resizeRgba
9
+ } from "./token-goat-chunk-RRNZMM3A.mjs";
10
+ import {
11
+ __toESM,
12
+ init_define_import_meta_env
13
+ } from "./token-goat-chunk-A37V4PBF.mjs";
14
+
15
+ // src/image_gif_encode.ts
16
+ init_define_import_meta_env();
17
+ var import_omggif = __toESM(require_omggif(), 1);
18
+ function unionRects(a, b) {
19
+ const x = Math.min(a.x, b.x);
20
+ const y = Math.min(a.y, b.y);
21
+ return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
22
+ }
23
+ function gifFrameDelta(prev, prevTransparentIndex, cur, curTransparentIndex, width, height) {
24
+ let minX = width;
25
+ let minY = height;
26
+ let maxX = -1;
27
+ let maxY = -1;
28
+ let cleared = false;
29
+ for (let y = 0; y < height; y++) {
30
+ const row = y * width;
31
+ for (let x = 0; x < width; x++) {
32
+ const i = row + x;
33
+ const curIdx = cur[i] ?? 0;
34
+ const prevIdx = prev[i] ?? 0;
35
+ const curClear = curTransparentIndex !== null && curIdx === curTransparentIndex;
36
+ if (curClear === (prevTransparentIndex !== null && prevIdx === prevTransparentIndex) && (curClear || curIdx === prevIdx)) continue;
37
+ if (curClear) cleared = true;
38
+ if (x < minX) minX = x;
39
+ if (x > maxX) maxX = x;
40
+ if (y < minY) minY = y;
41
+ if (y > maxY) maxY = y;
42
+ }
43
+ }
44
+ if (maxX < 0) return { changed: { x: 0, y: 0, width: 1, height: 1 }, cleared: false };
45
+ return { changed: { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 }, cleared };
46
+ }
47
+ function sliceIndexedRect(indexed, canvasWidth, rect) {
48
+ if (rect.x === 0 && rect.y === 0 && rect.width === canvasWidth && rect.height * canvasWidth === indexed.length) return indexed;
49
+ const out = new Array(rect.width * rect.height);
50
+ for (let row = 0; row < rect.height; row++) {
51
+ const src = (rect.y + row) * canvasWidth + rect.x;
52
+ const dst = row * rect.width;
53
+ for (let col = 0; col < rect.width; col++) out[dst + col] = indexed[src + col] ?? 0;
54
+ }
55
+ return out;
56
+ }
57
+ function encodeAnimatedGifDelta(decoded, targetW, targetH) {
58
+ assertDecodableSize("GIF output", targetW, targetH, 5, decoded.frames.length);
59
+ const outBuf = Buffer.alloc(targetW * targetH * 5 * decoded.frames.length + 4096);
60
+ const gifWriter = new import_omggif.default.GifWriter(outBuf, targetW, targetH, { loop: 0, palette: GIF_WEB_PALETTE });
61
+ let pending = null;
62
+ const writePending = (disposal) => {
63
+ if (pending === null) return;
64
+ gifWriter.addFrame(pending.rect.x, pending.rect.y, pending.rect.width, pending.rect.height, pending.pixels, {
65
+ delay: pending.delay,
66
+ disposal,
67
+ ...pending.transparent === null ? {} : { transparent: pending.transparent }
68
+ });
69
+ pending = null;
70
+ };
71
+ for (const frame of decoded.frames) {
72
+ const resizedFrameRgba = resizeRgba(frame.data, frame.width, frame.height, targetW, targetH);
73
+ const { indexedPixels, transparentIndex } = quantizeRgbaToIndexed(resizedFrameRgba, targetW, targetH);
74
+ let rect = { x: 0, y: 0, width: targetW, height: targetH };
75
+ if (pending !== null) {
76
+ const delta = gifFrameDelta(pending.canvas, pending.transparent, indexedPixels, transparentIndex, targetW, targetH);
77
+ rect = delta.changed;
78
+ if (delta.cleared) {
79
+ rect = unionRects(pending.rect, delta.changed);
80
+ pending = { ...pending, rect, pixels: sliceIndexedRect(pending.canvas, targetW, rect) };
81
+ writePending(2);
82
+ } else {
83
+ writePending(1);
84
+ }
85
+ }
86
+ pending = {
87
+ rect,
88
+ pixels: sliceIndexedRect(indexedPixels, targetW, rect),
89
+ canvas: indexedPixels,
90
+ transparent: transparentIndex,
91
+ delay: frame.delay
92
+ };
93
+ }
94
+ writePending(1);
95
+ return outBuf.subarray(0, gifWriter.end());
96
+ }
97
+ export {
98
+ encodeAnimatedGifDelta,
99
+ gifFrameDelta,
100
+ sliceIndexedRect,
101
+ unionRects
102
+ };