token-goat 2.9.15 → 2.9.17
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/README.md +2 -5
- package/dist/{token-goat-chunk-IVUQLQWN.mjs → token-goat-chunk-26YUO7MP.mjs} +5 -3
- package/dist/{token-goat-chunk-SZWYESBS.mjs → token-goat-chunk-2M33Q3O4.mjs} +172 -67
- package/dist/{token-goat-chunk-S4XRY446.mjs → token-goat-chunk-2VASS5VR.mjs} +4 -3
- package/dist/{token-goat-chunk-7ZYK25AO.mjs → token-goat-chunk-2XA5ZW4T.mjs} +4 -4
- package/dist/{token-goat-chunk-C5JIO6HK.mjs → token-goat-chunk-5WB7GDH4.mjs} +5 -5
- package/dist/{token-goat-chunk-MZDIJJ3R.mjs → token-goat-chunk-66224KCZ.mjs} +40 -3
- package/dist/{token-goat-chunk-NDRP4KJQ.mjs → token-goat-chunk-73GXYYZR.mjs} +248 -50
- package/dist/{token-goat-chunk-ATIFTMRC.mjs → token-goat-chunk-7EGKXBWT.mjs} +7 -7
- package/dist/{token-goat-chunk-GMQQA7E4.mjs → token-goat-chunk-7VQMOBPQ.mjs} +2453 -722
- package/dist/token-goat-chunk-BGHSSJUA.mjs +102 -0
- package/dist/{token-goat-chunk-2X2EBBC6.mjs → token-goat-chunk-BK3RPPTK.mjs} +2 -2
- package/dist/{token-goat-chunk-YQ7WI2CO.mjs → token-goat-chunk-C26ZBGBC.mjs} +393 -3957
- package/dist/{token-goat-chunk-SFAS46RE.mjs → token-goat-chunk-CICJFVIH.mjs} +2 -2
- package/dist/{token-goat-chunk-6DLVZDB6.mjs → token-goat-chunk-CKIJWTRQ.mjs} +13 -12
- package/dist/{token-goat-chunk-5V7DAC7V.mjs → token-goat-chunk-CPHVXKNU.mjs} +10 -3
- package/dist/{token-goat-chunk-LT7JRU6K.mjs → token-goat-chunk-EKGVCAES.mjs} +4 -4
- package/dist/{token-goat-chunk-Z6UXPYJA.mjs → token-goat-chunk-F2ARFHLJ.mjs} +1 -1
- package/dist/{token-goat-chunk-NDPO7GAH.mjs → token-goat-chunk-G75WIVFM.mjs} +21 -20
- package/dist/{token-goat-chunk-YZX7EFG4.mjs → token-goat-chunk-GLOM5W5C.mjs} +1 -1
- package/dist/{token-goat-chunk-GIIHUSZX.mjs → token-goat-chunk-GPCCYQSS.mjs} +41 -11
- package/dist/{token-goat-chunk-OUGNPMDA.mjs → token-goat-chunk-HRUGS6CO.mjs} +30 -14
- package/dist/{token-goat-chunk-LCZBPOIN.mjs → token-goat-chunk-IDHWKNKZ.mjs} +143 -51
- package/dist/{token-goat-chunk-YKG35VHC.mjs → token-goat-chunk-KZPO4DWC.mjs} +1 -1
- package/dist/{token-goat-chunk-NEI4NC54.mjs → token-goat-chunk-LKSXAMJB.mjs} +7 -2
- package/dist/{token-goat-chunk-K7F2BFIK.mjs → token-goat-chunk-MWSVUKVV.mjs} +1 -1
- package/dist/{token-goat-chunk-BL5LNGBG.mjs → token-goat-chunk-PKNOHVWP.mjs} +2966 -3869
- package/dist/{token-goat-chunk-A4JYKD5H.mjs → token-goat-chunk-RB24DBBS.mjs} +2 -2
- package/dist/{token-goat-chunk-3NSDDTGL.mjs → token-goat-chunk-RFFUCQK7.mjs} +5 -5
- package/dist/token-goat-chunk-RRNZMM3A.mjs +3364 -0
- package/dist/{token-goat-chunk-XEPXYDPI.mjs → token-goat-chunk-SWRKVA3J.mjs} +11 -2
- package/dist/{token-goat-chunk-NU7TLMQK.mjs → token-goat-chunk-THBLW56G.mjs} +10 -7
- package/dist/{token-goat-chunk-PM76YS22.mjs → token-goat-chunk-UBZCON6N.mjs} +1 -1
- package/dist/{token-goat-chunk-ASYEPR3S.mjs → token-goat-chunk-W2GUUQAQ.mjs} +7 -3
- package/dist/{token-goat-chunk-DQ4J5AFF.mjs → token-goat-chunk-YFGEUIEO.mjs} +69 -18
- package/dist/token-goat-hook.mjs +13 -12
- package/dist/token-goat.core.mjs +21 -20
- package/docs/cli.md +1 -0
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -2,12 +2,12 @@ import { createRequire as __cjsRequire } from 'node:module';
|
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
getDb
|
|
5
|
-
} from "./token-goat-chunk-
|
|
5
|
+
} from "./token-goat-chunk-MWSVUKVV.mjs";
|
|
6
6
|
import {
|
|
7
7
|
foldPath,
|
|
8
8
|
globalDbPath,
|
|
9
9
|
isCaseInsensitiveFs
|
|
10
|
-
} from "./token-goat-chunk-
|
|
10
|
+
} from "./token-goat-chunk-UBZCON6N.mjs";
|
|
11
11
|
import {
|
|
12
12
|
normalizePath
|
|
13
13
|
} from "./token-goat-chunk-ERTXEKB6.mjs";
|