@nkzw/palette-swap 2.1.2 → 3.1.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/lib/palette-swap.js +5 -5
- package/package.json +7 -9
- package/pnpm-workspace.yaml +4 -0
package/lib/palette-swap.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createCanvas,
|
|
4
4
|
createImageData
|
|
5
5
|
} from "canvas";
|
|
6
|
-
var
|
|
6
|
+
var hexToUint32LE = (hex2) => {
|
|
7
7
|
const n = Number.parseInt(hex2.slice(1), 16) & 16777215;
|
|
8
8
|
const [r, g, b] = int32ToRgb(n);
|
|
9
9
|
return b << 16 | g << 8 | r;
|
|
@@ -107,9 +107,9 @@ function paletteSwap(image, inputVariants, staticColors, images, options) {
|
|
|
107
107
|
);
|
|
108
108
|
if (typeof palette !== "number") {
|
|
109
109
|
for (const [key, value] of palette) {
|
|
110
|
-
const k =
|
|
110
|
+
const k = hexToUint32LE(key);
|
|
111
111
|
const v = palettes.get(k) || [];
|
|
112
|
-
v[i] =
|
|
112
|
+
v[i] = hexToUint32LE(value);
|
|
113
113
|
palettes.set(k, v);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -121,7 +121,7 @@ function paletteSwap(image, inputVariants, staticColors, images, options) {
|
|
|
121
121
|
]);
|
|
122
122
|
i++;
|
|
123
123
|
}
|
|
124
|
-
const staticColorNumbers = staticColors ? new Set([...staticColors].map(
|
|
124
|
+
const staticColorNumbers = staticColors ? new Set([...staticColors].map(hexToUint32LE)) : null;
|
|
125
125
|
const missing = /* @__PURE__ */ new Set();
|
|
126
126
|
for (var y = 0; y < height; ++y) {
|
|
127
127
|
for (var x = 0; x < width; ++x) {
|
|
@@ -155,7 +155,7 @@ function paletteSwap(image, inputVariants, staticColors, images, options) {
|
|
|
155
155
|
}
|
|
156
156
|
if (!options?.ignoreMissing && missing.size) {
|
|
157
157
|
throw new Error(
|
|
158
|
-
`${options?.imageName ? `${options.imageName}` : "
|
|
158
|
+
`${options?.imageName ? `${options.imageName}` : "Palette Swap"}: Missing ${Array.from(
|
|
159
159
|
new Set(
|
|
160
160
|
[...missing].map(
|
|
161
161
|
([variant, color]) => `'${int32ToHex(color)}' in '${variant}'`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/palette-swap",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"author": "Christoph Nakazawa <christoph.pojer@gmail.com>",
|
|
5
5
|
"description": "Image palette swapping and color replacement tool based on canvas for Node.js and browsers.",
|
|
6
6
|
"repository": {
|
|
@@ -16,20 +16,18 @@
|
|
|
16
16
|
"canvas"
|
|
17
17
|
],
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">=22.0.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"canvas": "^
|
|
22
|
+
"canvas": "^3.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"esbuild": "^0.19.11",
|
|
29
|
-
"typescript": "^5.3.3"
|
|
25
|
+
"@types/node": "^22.15.21",
|
|
26
|
+
"esbuild": "^0.25.4",
|
|
27
|
+
"typescript": "^5.8.3"
|
|
30
28
|
},
|
|
31
29
|
"scripts": {
|
|
32
|
-
"build": "mkdir -p lib && rm lib/*; tsc --declaration --emitDeclarationOnly --noEmit false && esbuild --target=
|
|
30
|
+
"build": "mkdir -p lib && rm lib/*; tsc --declaration --emitDeclarationOnly --noEmit false && esbuild --target=node22 --format=esm --platform=node --outfile=lib/palette-swap.js --external:canvas --bundle ./src/palette-swap.js",
|
|
33
31
|
"test": "tsc"
|
|
34
32
|
}
|
|
35
33
|
}
|