create-opentray 0.22.0 → 0.24.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/assets/create-openspec-template-iOS-Dark-1024@1x.png +0 -0
- package/assets/create-openspec-template-iOS-Default-1024@1x.png +0 -0
- package/assets/inter-glyph.OFL.txt +93 -0
- package/assets/inter-glyph.ttf +0 -0
- package/dist/{bin-Dyfucd3C.mjs → bin-BQb2Bjcu.mjs} +449 -2787
- package/dist/bin-BQb2Bjcu.mjs.map +1 -0
- package/dist/bin.mjs +1 -1
- package/dist/{decode-ico-D3SL2BXi.mjs → decode-ico-BHd2POHf.mjs} +2 -2
- package/dist/{decode-ico-D3SL2BXi.mjs.map → decode-ico-BHd2POHf.mjs.map} +1 -1
- package/dist/index.d.mts +40 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{raster-BQ07mKLu.mjs → raster-DeMbA2zI.mjs} +15 -16
- package/dist/{raster-BQ07mKLu.mjs.map → raster-DeMbA2zI.mjs.map} +1 -1
- package/dist/shell/assets/browse.js +1 -1
- package/dist/shell/assets/index.css +1 -1
- package/dist/shell/assets/index.js +9 -9
- package/dist/shell/assets/index2.js +2 -0
- package/dist/shell/assets/input.js +1 -1
- package/dist/shell/assets/main.js +20 -19
- package/dist/shell/assets/ort.bundle.min.js +2763 -0
- package/dist/shell/assets/ort.bundle.min.mjs +2817 -0
- package/dist/shell/assets/ort.webgpu.bundle.min.js +2763 -0
- package/dist/shell/assets/ort.webgpu.bundle.min.mjs +2817 -0
- package/dist/shell/assets/terminal-pane.js +1 -1
- package/dist/shell/assets/terminal.js +1 -1
- package/dist/shell/browse.html +1 -1
- package/dist/shell/index.html +1 -1
- package/dist/shell/terminal.html +1 -1
- package/dist/webui/assets/browse.js +1 -1
- package/dist/webui/assets/index.css +1 -1
- package/dist/webui/assets/index.js +9 -9
- package/dist/webui/assets/index2.js +2 -0
- package/dist/webui/assets/input.js +1 -1
- package/dist/webui/assets/main.js +20 -19
- package/dist/webui/assets/ort.bundle.min.js +2763 -0
- package/dist/webui/assets/ort.bundle.min.mjs +2817 -0
- package/dist/webui/assets/ort.webgpu.bundle.min.js +2763 -0
- package/dist/webui/assets/ort.webgpu.bundle.min.mjs +2817 -0
- package/dist/webui/assets/terminal-pane.js +1 -1
- package/dist/webui/assets/terminal.js +1 -1
- package/dist/webui/browse.html +1 -1
- package/dist/webui/index.html +1 -1
- package/dist/webui/terminal.html +1 -1
- package/package.json +15 -6
- package/dist/avif-DCXcyYJR.mjs +0 -2
- package/dist/bin-Dyfucd3C.mjs.map +0 -1
- package/dist/decode-C4b5NXc_.mjs +0 -1236
- package/dist/decode-C4b5NXc_.mjs.map +0 -1
- package/dist/decode-Dsj9J0OD.mjs +0 -1214
- package/dist/decode-Dsj9J0OD.mjs.map +0 -1
- package/dist/decode-FysWS28R.mjs +0 -254
- package/dist/decode-FysWS28R.mjs.map +0 -1
- package/dist/decode-Xr7mARKr.mjs +0 -1262
- package/dist/decode-Xr7mARKr.mjs.map +0 -1
- package/dist/full.umd-oM1VUBRH.mjs +0 -3055
- package/dist/full.umd-oM1VUBRH.mjs.map +0 -1
- package/dist/jpeg-B4tsxG5f.mjs +0 -2
- package/dist/png-rD0XEazj.mjs +0 -35
- package/dist/png-rD0XEazj.mjs.map +0 -1
- package/dist/resize-B47sgoOb.mjs +0 -489
- package/dist/resize-B47sgoOb.mjs.map +0 -1
- package/dist/resvg-wasm-fcJTLpJs.mjs +0 -522
- package/dist/resvg-wasm-fcJTLpJs.mjs.map +0 -1
- package/dist/rolldown-runtime-JspESFgx.mjs +0 -35
- package/dist/webp-CcbaCrQ7.mjs +0 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import { _ as assetsDirectory, a as decodeImage, c as encodeImagePng, d as rasterizeSvg, f as resizeImage, g as glyphLadderFingerprint, h as embeddedGlyphFont, i as cropImage, l as insideImage, m as GLYPH_FONT_FAMILY, n as cloneImage, o as decodeImageFile, p as trimBounds, r as containImage, s as emptyImageOf, t as brightPixelRatio, u as pasteImage } from "./raster-BQ07mKLu.mjs";
|
|
1
|
+
import { _ as assetsDirectory, a as decodeImage, c as encodeImagePng, d as rasterizeSvg, f as resizeImage, g as glyphLadderFingerprint, h as embeddedGlyphFont, i as cropImage, l as insideImage, m as GLYPH_FONT_FAMILY, n as cloneImage, o as decodeImageFile, p as trimBounds, r as containImage, s as emptyImageOf, t as brightPixelRatio, u as pasteImage } from "./raster-DeMbA2zI.mjs";
|
|
3
2
|
import { createRequire } from "node:module";
|
|
4
3
|
import crypto, { createHash, randomBytes } from "node:crypto";
|
|
5
4
|
import fs, { access, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
@@ -9,9 +8,43 @@ import { constants, realpathSync } from "node:fs";
|
|
|
9
8
|
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
10
9
|
import net from "node:net";
|
|
11
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { getSvgPath } from "figma-squircle";
|
|
12
|
+
import { IconIcns, IconIco } from "@shockpkg/icon-encoder";
|
|
12
13
|
import { resolveDefaultDarwinAppBundlePath, sanitizeAppBundleName } from "@opentray/packaging";
|
|
13
14
|
import { promisify } from "node:util";
|
|
14
15
|
import { createServer } from "node:http";
|
|
16
|
+
//#region \0rolldown/runtime.js
|
|
17
|
+
var __create$1 = Object.create;
|
|
18
|
+
var __defProp$1 = Object.defineProperty;
|
|
19
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
20
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
21
|
+
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
22
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
23
|
+
var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
24
|
+
var __exportAll$1 = (all, no_symbols) => {
|
|
25
|
+
let target = {};
|
|
26
|
+
for (var name in all) __defProp$1(target, name, {
|
|
27
|
+
get: all[name],
|
|
28
|
+
enumerable: true
|
|
29
|
+
});
|
|
30
|
+
if (!no_symbols) __defProp$1(target, Symbol.toStringTag, { value: "Module" });
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __copyProps$1 = (to, from, except, desc) => {
|
|
34
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
35
|
+
key = keys[i];
|
|
36
|
+
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
|
|
37
|
+
get: ((k) => from[k]).bind(null, key),
|
|
38
|
+
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return to;
|
|
42
|
+
};
|
|
43
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
|
|
44
|
+
value: mod,
|
|
45
|
+
enumerable: true
|
|
46
|
+
}) : target, mod));
|
|
47
|
+
//#endregion
|
|
15
48
|
//#region packages/core/src/app-id.ts
|
|
16
49
|
/** A token that looks like a command option, e.g. `--xx`, `-p`, or `--port=8080`. */
|
|
17
50
|
const isOptionToken$1 = (token) => token.startsWith("-") && token.length > 1;
|
|
@@ -6004,2741 +6037,78 @@ function base_parse(data, options = {}) {
|
|
|
6004
6037
|
currentParent = arr_back(stack);
|
|
6005
6038
|
}
|
|
6006
6039
|
continue;
|
|
6007
|
-
}
|
|
6008
|
-
}
|
|
6009
|
-
break;
|
|
6010
|
-
}
|
|
6011
|
-
}
|
|
6012
|
-
}
|
|
6013
|
-
return stack;
|
|
6014
|
-
}
|
|
6015
|
-
/**
|
|
6016
|
-
* Parses HTML and returns a root element
|
|
6017
|
-
* Parse a chuck of HTML source.
|
|
6018
|
-
*/
|
|
6019
|
-
function parse$1(data, options = {}) {
|
|
6020
|
-
const stack = base_parse(data, options);
|
|
6021
|
-
const [root] = stack;
|
|
6022
|
-
while (stack.length > 1) {
|
|
6023
|
-
const last = stack.pop();
|
|
6024
|
-
const oneBefore = arr_back(stack);
|
|
6025
|
-
if (last.parentNode && last.parentNode.parentNode) {
|
|
6026
|
-
if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {
|
|
6027
|
-
if (options.parseNoneClosedTags !== true) {
|
|
6028
|
-
oneBefore.removeChild(last);
|
|
6029
|
-
last.childNodes.forEach((child) => {
|
|
6030
|
-
oneBefore.parentNode.appendChild(child);
|
|
6031
|
-
});
|
|
6032
|
-
stack.pop();
|
|
6033
|
-
}
|
|
6034
|
-
} else if (options.parseNoneClosedTags !== true) {
|
|
6035
|
-
oneBefore.removeChild(last);
|
|
6036
|
-
last.childNodes.forEach((child) => {
|
|
6037
|
-
oneBefore.appendChild(child);
|
|
6038
|
-
});
|
|
6039
|
-
}
|
|
6040
|
-
}
|
|
6041
|
-
}
|
|
6042
|
-
return root;
|
|
6043
|
-
}
|
|
6044
|
-
/**
|
|
6045
|
-
* Resolves a list of {@link NodeInsertable} to a list of nodes,
|
|
6046
|
-
* and removes nodes from any potential parent.
|
|
6047
|
-
*/
|
|
6048
|
-
function resolveInsertable(insertable) {
|
|
6049
|
-
return insertable.map((val) => {
|
|
6050
|
-
if (typeof val === "string") return new TextNode(val);
|
|
6051
|
-
val.remove();
|
|
6052
|
-
return val;
|
|
6053
|
-
});
|
|
6054
|
-
}
|
|
6055
|
-
function resetParent(nodes, parent) {
|
|
6056
|
-
return nodes.map((node) => {
|
|
6057
|
-
node.parentNode = parent;
|
|
6058
|
-
return node;
|
|
6059
|
-
});
|
|
6060
|
-
}
|
|
6061
|
-
/**
|
|
6062
|
-
* Parses HTML and returns a root element
|
|
6063
|
-
* Parse a chuck of HTML source.
|
|
6064
|
-
*/
|
|
6065
|
-
function valid(data, options = {}) {
|
|
6066
|
-
const stack = base_parse(data, options);
|
|
6067
|
-
return Boolean(stack.length === 1);
|
|
6068
|
-
}
|
|
6069
|
-
function parse$2(data, options = {}) {
|
|
6070
|
-
return parse$1(data, options);
|
|
6071
|
-
}
|
|
6072
|
-
parse$2.parse = parse$1;
|
|
6073
|
-
parse$2.HTMLElement = HTMLElement;
|
|
6074
|
-
parse$2.CommentNode = CommentNode;
|
|
6075
|
-
parse$2.valid = valid;
|
|
6076
|
-
parse$2.Node = Node;
|
|
6077
|
-
parse$2.TextNode = TextNode;
|
|
6078
|
-
parse$2.NodeType = NodeType;
|
|
6079
|
-
//#endregion
|
|
6080
|
-
//#region ../../node_modules/.pnpm/figma-squircle@1.1.0/node_modules/figma-squircle/dist/index.js
|
|
6081
|
-
function distributeAndNormalize({ topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, bottomLeftCornerRadius, width, height }) {
|
|
6082
|
-
const roundingAndSmoothingBudgetMap = {
|
|
6083
|
-
topLeft: -1,
|
|
6084
|
-
topRight: -1,
|
|
6085
|
-
bottomLeft: -1,
|
|
6086
|
-
bottomRight: -1
|
|
6087
|
-
};
|
|
6088
|
-
const cornerRadiusMap = {
|
|
6089
|
-
topLeft: topLeftCornerRadius,
|
|
6090
|
-
topRight: topRightCornerRadius,
|
|
6091
|
-
bottomLeft: bottomLeftCornerRadius,
|
|
6092
|
-
bottomRight: bottomRightCornerRadius
|
|
6093
|
-
};
|
|
6094
|
-
Object.entries(cornerRadiusMap).sort(([, radius1], [, radius2]) => {
|
|
6095
|
-
return radius2 - radius1;
|
|
6096
|
-
}).forEach(([cornerName, radius]) => {
|
|
6097
|
-
const corner = cornerName;
|
|
6098
|
-
const adjacents = adjacentsByCorner[corner];
|
|
6099
|
-
const budget = Math.min(...adjacents.map((adjacent) => {
|
|
6100
|
-
const adjacentCornerRadius = cornerRadiusMap[adjacent.corner];
|
|
6101
|
-
if (radius === 0 && adjacentCornerRadius === 0) return 0;
|
|
6102
|
-
const adjacentCornerBudget = roundingAndSmoothingBudgetMap[adjacent.corner];
|
|
6103
|
-
const sideLength = adjacent.side === "top" || adjacent.side === "bottom" ? width : height;
|
|
6104
|
-
if (adjacentCornerBudget >= 0) return sideLength - roundingAndSmoothingBudgetMap[adjacent.corner];
|
|
6105
|
-
else return radius / (radius + adjacentCornerRadius) * sideLength;
|
|
6106
|
-
}));
|
|
6107
|
-
roundingAndSmoothingBudgetMap[corner] = budget;
|
|
6108
|
-
cornerRadiusMap[corner] = Math.min(radius, budget);
|
|
6109
|
-
});
|
|
6110
|
-
return {
|
|
6111
|
-
topLeft: {
|
|
6112
|
-
radius: cornerRadiusMap.topLeft,
|
|
6113
|
-
roundingAndSmoothingBudget: roundingAndSmoothingBudgetMap.topLeft
|
|
6114
|
-
},
|
|
6115
|
-
topRight: {
|
|
6116
|
-
radius: cornerRadiusMap.topRight,
|
|
6117
|
-
roundingAndSmoothingBudget: roundingAndSmoothingBudgetMap.topRight
|
|
6118
|
-
},
|
|
6119
|
-
bottomLeft: {
|
|
6120
|
-
radius: cornerRadiusMap.bottomLeft,
|
|
6121
|
-
roundingAndSmoothingBudget: roundingAndSmoothingBudgetMap.bottomLeft
|
|
6122
|
-
},
|
|
6123
|
-
bottomRight: {
|
|
6124
|
-
radius: cornerRadiusMap.bottomRight,
|
|
6125
|
-
roundingAndSmoothingBudget: roundingAndSmoothingBudgetMap.bottomRight
|
|
6126
|
-
}
|
|
6127
|
-
};
|
|
6128
|
-
}
|
|
6129
|
-
var adjacentsByCorner = {
|
|
6130
|
-
topLeft: [{
|
|
6131
|
-
corner: "topRight",
|
|
6132
|
-
side: "top"
|
|
6133
|
-
}, {
|
|
6134
|
-
corner: "bottomLeft",
|
|
6135
|
-
side: "left"
|
|
6136
|
-
}],
|
|
6137
|
-
topRight: [{
|
|
6138
|
-
corner: "topLeft",
|
|
6139
|
-
side: "top"
|
|
6140
|
-
}, {
|
|
6141
|
-
corner: "bottomRight",
|
|
6142
|
-
side: "right"
|
|
6143
|
-
}],
|
|
6144
|
-
bottomLeft: [{
|
|
6145
|
-
corner: "bottomRight",
|
|
6146
|
-
side: "bottom"
|
|
6147
|
-
}, {
|
|
6148
|
-
corner: "topLeft",
|
|
6149
|
-
side: "left"
|
|
6150
|
-
}],
|
|
6151
|
-
bottomRight: [{
|
|
6152
|
-
corner: "bottomLeft",
|
|
6153
|
-
side: "bottom"
|
|
6154
|
-
}, {
|
|
6155
|
-
corner: "topRight",
|
|
6156
|
-
side: "right"
|
|
6157
|
-
}]
|
|
6158
|
-
};
|
|
6159
|
-
function getPathParamsForCorner({ cornerRadius, cornerSmoothing, preserveSmoothing, roundingAndSmoothingBudget }) {
|
|
6160
|
-
let p = (1 + cornerSmoothing) * cornerRadius;
|
|
6161
|
-
if (!preserveSmoothing) {
|
|
6162
|
-
const maxCornerSmoothing = roundingAndSmoothingBudget / cornerRadius - 1;
|
|
6163
|
-
cornerSmoothing = Math.min(cornerSmoothing, maxCornerSmoothing);
|
|
6164
|
-
p = Math.min(p, roundingAndSmoothingBudget);
|
|
6165
|
-
}
|
|
6166
|
-
const arcMeasure = 90 * (1 - cornerSmoothing);
|
|
6167
|
-
const arcSectionLength = Math.sin(toRadians(arcMeasure / 2)) * cornerRadius * Math.sqrt(2);
|
|
6168
|
-
const angleAlpha = (90 - arcMeasure) / 2;
|
|
6169
|
-
const p3ToP4Distance = cornerRadius * Math.tan(toRadians(angleAlpha / 2));
|
|
6170
|
-
const angleBeta = 45 * cornerSmoothing;
|
|
6171
|
-
const c = p3ToP4Distance * Math.cos(toRadians(angleBeta));
|
|
6172
|
-
const d = c * Math.tan(toRadians(angleBeta));
|
|
6173
|
-
let b = (p - arcSectionLength - c - d) / 3;
|
|
6174
|
-
let a = 2 * b;
|
|
6175
|
-
if (preserveSmoothing && p > roundingAndSmoothingBudget) {
|
|
6176
|
-
const p1ToP3MaxDistance = roundingAndSmoothingBudget - d - arcSectionLength - c;
|
|
6177
|
-
const maxB = p1ToP3MaxDistance - p1ToP3MaxDistance / 6;
|
|
6178
|
-
b = Math.min(b, maxB);
|
|
6179
|
-
a = p1ToP3MaxDistance - b;
|
|
6180
|
-
p = Math.min(p, roundingAndSmoothingBudget);
|
|
6181
|
-
}
|
|
6182
|
-
return {
|
|
6183
|
-
a,
|
|
6184
|
-
b,
|
|
6185
|
-
c,
|
|
6186
|
-
d,
|
|
6187
|
-
p,
|
|
6188
|
-
arcSectionLength,
|
|
6189
|
-
cornerRadius
|
|
6190
|
-
};
|
|
6191
|
-
}
|
|
6192
|
-
function getSVGPathFromPathParams({ width, height, topLeftPathParams, topRightPathParams, bottomLeftPathParams, bottomRightPathParams }) {
|
|
6193
|
-
return `
|
|
6194
|
-
M ${width - topRightPathParams.p} 0
|
|
6195
|
-
${drawTopRightPath(topRightPathParams)}
|
|
6196
|
-
L ${width} ${height - bottomRightPathParams.p}
|
|
6197
|
-
${drawBottomRightPath(bottomRightPathParams)}
|
|
6198
|
-
L ${bottomLeftPathParams.p} ${height}
|
|
6199
|
-
${drawBottomLeftPath(bottomLeftPathParams)}
|
|
6200
|
-
L 0 ${topLeftPathParams.p}
|
|
6201
|
-
${drawTopLeftPath(topLeftPathParams)}
|
|
6202
|
-
Z
|
|
6203
|
-
`.replace(/[\t\s\n]+/g, " ").trim();
|
|
6204
|
-
}
|
|
6205
|
-
function drawTopRightPath({ cornerRadius, a, b, c, d, p, arcSectionLength }) {
|
|
6206
|
-
if (cornerRadius) return rounded`
|
|
6207
|
-
c ${a} 0 ${a + b} 0 ${a + b + c} ${d}
|
|
6208
|
-
a ${cornerRadius} ${cornerRadius} 0 0 1 ${arcSectionLength} ${arcSectionLength}
|
|
6209
|
-
c ${d} ${c}
|
|
6210
|
-
${d} ${b + c}
|
|
6211
|
-
${d} ${a + b + c}`;
|
|
6212
|
-
else return rounded`l ${p} 0`;
|
|
6213
|
-
}
|
|
6214
|
-
function drawBottomRightPath({ cornerRadius, a, b, c, d, p, arcSectionLength }) {
|
|
6215
|
-
if (cornerRadius) return rounded`
|
|
6216
|
-
c 0 ${a}
|
|
6217
|
-
0 ${a + b}
|
|
6218
|
-
${-d} ${a + b + c}
|
|
6219
|
-
a ${cornerRadius} ${cornerRadius} 0 0 1 -${arcSectionLength} ${arcSectionLength}
|
|
6220
|
-
c ${-c} ${d}
|
|
6221
|
-
${-(b + c)} ${d}
|
|
6222
|
-
${-(a + b + c)} ${d}`;
|
|
6223
|
-
else return rounded`l 0 ${p}`;
|
|
6224
|
-
}
|
|
6225
|
-
function drawBottomLeftPath({ cornerRadius, a, b, c, d, p, arcSectionLength }) {
|
|
6226
|
-
if (cornerRadius) return rounded`
|
|
6227
|
-
c ${-a} 0
|
|
6228
|
-
${-(a + b)} 0
|
|
6229
|
-
${-(a + b + c)} ${-d}
|
|
6230
|
-
a ${cornerRadius} ${cornerRadius} 0 0 1 -${arcSectionLength} -${arcSectionLength}
|
|
6231
|
-
c ${-d} ${-c}
|
|
6232
|
-
${-d} ${-(b + c)}
|
|
6233
|
-
${-d} ${-(a + b + c)}`;
|
|
6234
|
-
else return rounded`l ${-p} 0`;
|
|
6235
|
-
}
|
|
6236
|
-
function drawTopLeftPath({ cornerRadius, a, b, c, d, p, arcSectionLength }) {
|
|
6237
|
-
if (cornerRadius) return rounded`
|
|
6238
|
-
c 0 ${-a}
|
|
6239
|
-
0 ${-(a + b)}
|
|
6240
|
-
${d} ${-(a + b + c)}
|
|
6241
|
-
a ${cornerRadius} ${cornerRadius} 0 0 1 ${arcSectionLength} -${arcSectionLength}
|
|
6242
|
-
c ${c} ${-d}
|
|
6243
|
-
${b + c} ${-d}
|
|
6244
|
-
${a + b + c} ${-d}`;
|
|
6245
|
-
else return rounded`l 0 ${-p}`;
|
|
6246
|
-
}
|
|
6247
|
-
function toRadians(degrees) {
|
|
6248
|
-
return degrees * Math.PI / 180;
|
|
6249
|
-
}
|
|
6250
|
-
function rounded(strings, ...values) {
|
|
6251
|
-
return strings.reduce((acc, str, i) => {
|
|
6252
|
-
const value = values[i];
|
|
6253
|
-
if (typeof value === "number") return acc + str + value.toFixed(4);
|
|
6254
|
-
else return acc + str + (value ?? "");
|
|
6255
|
-
}, "");
|
|
6256
|
-
}
|
|
6257
|
-
function getSvgPath({ cornerRadius = 0, topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, bottomLeftCornerRadius, cornerSmoothing, width, height, preserveSmoothing = false }) {
|
|
6258
|
-
topLeftCornerRadius = topLeftCornerRadius ?? cornerRadius;
|
|
6259
|
-
topRightCornerRadius = topRightCornerRadius ?? cornerRadius;
|
|
6260
|
-
bottomLeftCornerRadius = bottomLeftCornerRadius ?? cornerRadius;
|
|
6261
|
-
bottomRightCornerRadius = bottomRightCornerRadius ?? cornerRadius;
|
|
6262
|
-
if (topLeftCornerRadius === topRightCornerRadius && topRightCornerRadius === bottomRightCornerRadius && bottomRightCornerRadius === bottomLeftCornerRadius && bottomLeftCornerRadius === topLeftCornerRadius) {
|
|
6263
|
-
const roundingAndSmoothingBudget = Math.min(width, height) / 2;
|
|
6264
|
-
const pathParams = getPathParamsForCorner({
|
|
6265
|
-
cornerRadius: Math.min(topLeftCornerRadius, roundingAndSmoothingBudget),
|
|
6266
|
-
cornerSmoothing,
|
|
6267
|
-
preserveSmoothing,
|
|
6268
|
-
roundingAndSmoothingBudget
|
|
6269
|
-
});
|
|
6270
|
-
return getSVGPathFromPathParams({
|
|
6271
|
-
width,
|
|
6272
|
-
height,
|
|
6273
|
-
topLeftPathParams: pathParams,
|
|
6274
|
-
topRightPathParams: pathParams,
|
|
6275
|
-
bottomLeftPathParams: pathParams,
|
|
6276
|
-
bottomRightPathParams: pathParams
|
|
6277
|
-
});
|
|
6278
|
-
}
|
|
6279
|
-
const { topLeft, topRight, bottomLeft, bottomRight } = distributeAndNormalize({
|
|
6280
|
-
topLeftCornerRadius,
|
|
6281
|
-
topRightCornerRadius,
|
|
6282
|
-
bottomRightCornerRadius,
|
|
6283
|
-
bottomLeftCornerRadius,
|
|
6284
|
-
width,
|
|
6285
|
-
height
|
|
6286
|
-
});
|
|
6287
|
-
return getSVGPathFromPathParams({
|
|
6288
|
-
width,
|
|
6289
|
-
height,
|
|
6290
|
-
topLeftPathParams: getPathParamsForCorner({
|
|
6291
|
-
cornerSmoothing,
|
|
6292
|
-
preserveSmoothing,
|
|
6293
|
-
cornerRadius: topLeft.radius,
|
|
6294
|
-
roundingAndSmoothingBudget: topLeft.roundingAndSmoothingBudget
|
|
6295
|
-
}),
|
|
6296
|
-
topRightPathParams: getPathParamsForCorner({
|
|
6297
|
-
cornerSmoothing,
|
|
6298
|
-
preserveSmoothing,
|
|
6299
|
-
cornerRadius: topRight.radius,
|
|
6300
|
-
roundingAndSmoothingBudget: topRight.roundingAndSmoothingBudget
|
|
6301
|
-
}),
|
|
6302
|
-
bottomRightPathParams: getPathParamsForCorner({
|
|
6303
|
-
cornerSmoothing,
|
|
6304
|
-
preserveSmoothing,
|
|
6305
|
-
cornerRadius: bottomRight.radius,
|
|
6306
|
-
roundingAndSmoothingBudget: bottomRight.roundingAndSmoothingBudget
|
|
6307
|
-
}),
|
|
6308
|
-
bottomLeftPathParams: getPathParamsForCorner({
|
|
6309
|
-
cornerSmoothing,
|
|
6310
|
-
preserveSmoothing,
|
|
6311
|
-
cornerRadius: bottomLeft.radius,
|
|
6312
|
-
roundingAndSmoothingBudget: bottomLeft.roundingAndSmoothingBudget
|
|
6313
|
-
})
|
|
6314
|
-
});
|
|
6315
|
-
}
|
|
6316
|
-
//#endregion
|
|
6317
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/chunkstream.js
|
|
6318
|
-
var require_chunkstream = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6319
|
-
let util$5 = __require("util");
|
|
6320
|
-
let Stream$2 = __require("stream");
|
|
6321
|
-
let ChunkStream = module.exports = function() {
|
|
6322
|
-
Stream$2.call(this);
|
|
6323
|
-
this._buffers = [];
|
|
6324
|
-
this._buffered = 0;
|
|
6325
|
-
this._reads = [];
|
|
6326
|
-
this._paused = false;
|
|
6327
|
-
this._encoding = "utf8";
|
|
6328
|
-
this.writable = true;
|
|
6329
|
-
};
|
|
6330
|
-
util$5.inherits(ChunkStream, Stream$2);
|
|
6331
|
-
ChunkStream.prototype.read = function(length, callback) {
|
|
6332
|
-
this._reads.push({
|
|
6333
|
-
length: Math.abs(length),
|
|
6334
|
-
allowLess: length < 0,
|
|
6335
|
-
func: callback
|
|
6336
|
-
});
|
|
6337
|
-
process.nextTick(function() {
|
|
6338
|
-
this._process();
|
|
6339
|
-
if (this._paused && this._reads && this._reads.length > 0) {
|
|
6340
|
-
this._paused = false;
|
|
6341
|
-
this.emit("drain");
|
|
6342
|
-
}
|
|
6343
|
-
}.bind(this));
|
|
6344
|
-
};
|
|
6345
|
-
ChunkStream.prototype.write = function(data, encoding) {
|
|
6346
|
-
if (!this.writable) {
|
|
6347
|
-
this.emit("error", /* @__PURE__ */ new Error("Stream not writable"));
|
|
6348
|
-
return false;
|
|
6349
|
-
}
|
|
6350
|
-
let dataBuffer;
|
|
6351
|
-
if (Buffer.isBuffer(data)) dataBuffer = data;
|
|
6352
|
-
else dataBuffer = Buffer.from(data, encoding || this._encoding);
|
|
6353
|
-
this._buffers.push(dataBuffer);
|
|
6354
|
-
this._buffered += dataBuffer.length;
|
|
6355
|
-
this._process();
|
|
6356
|
-
if (this._reads && this._reads.length === 0) this._paused = true;
|
|
6357
|
-
return this.writable && !this._paused;
|
|
6358
|
-
};
|
|
6359
|
-
ChunkStream.prototype.end = function(data, encoding) {
|
|
6360
|
-
if (data) this.write(data, encoding);
|
|
6361
|
-
this.writable = false;
|
|
6362
|
-
if (!this._buffers) return;
|
|
6363
|
-
if (this._buffers.length === 0) this._end();
|
|
6364
|
-
else {
|
|
6365
|
-
this._buffers.push(null);
|
|
6366
|
-
this._process();
|
|
6367
|
-
}
|
|
6368
|
-
};
|
|
6369
|
-
ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
|
|
6370
|
-
ChunkStream.prototype._end = function() {
|
|
6371
|
-
if (this._reads.length > 0) this.emit("error", /* @__PURE__ */ new Error("Unexpected end of input"));
|
|
6372
|
-
this.destroy();
|
|
6373
|
-
};
|
|
6374
|
-
ChunkStream.prototype.destroy = function() {
|
|
6375
|
-
if (!this._buffers) return;
|
|
6376
|
-
this.writable = false;
|
|
6377
|
-
this._reads = null;
|
|
6378
|
-
this._buffers = null;
|
|
6379
|
-
this.emit("close");
|
|
6380
|
-
};
|
|
6381
|
-
ChunkStream.prototype._processReadAllowingLess = function(read) {
|
|
6382
|
-
this._reads.shift();
|
|
6383
|
-
let smallerBuf = this._buffers[0];
|
|
6384
|
-
if (smallerBuf.length > read.length) {
|
|
6385
|
-
this._buffered -= read.length;
|
|
6386
|
-
this._buffers[0] = smallerBuf.slice(read.length);
|
|
6387
|
-
read.func.call(this, smallerBuf.slice(0, read.length));
|
|
6388
|
-
} else {
|
|
6389
|
-
this._buffered -= smallerBuf.length;
|
|
6390
|
-
this._buffers.shift();
|
|
6391
|
-
read.func.call(this, smallerBuf);
|
|
6392
|
-
}
|
|
6393
|
-
};
|
|
6394
|
-
ChunkStream.prototype._processRead = function(read) {
|
|
6395
|
-
this._reads.shift();
|
|
6396
|
-
let pos = 0;
|
|
6397
|
-
let count = 0;
|
|
6398
|
-
let data = Buffer.alloc(read.length);
|
|
6399
|
-
while (pos < read.length) {
|
|
6400
|
-
let buf = this._buffers[count++];
|
|
6401
|
-
let len = Math.min(buf.length, read.length - pos);
|
|
6402
|
-
buf.copy(data, pos, 0, len);
|
|
6403
|
-
pos += len;
|
|
6404
|
-
if (len !== buf.length) this._buffers[--count] = buf.slice(len);
|
|
6405
|
-
}
|
|
6406
|
-
if (count > 0) this._buffers.splice(0, count);
|
|
6407
|
-
this._buffered -= read.length;
|
|
6408
|
-
read.func.call(this, data);
|
|
6409
|
-
};
|
|
6410
|
-
ChunkStream.prototype._process = function() {
|
|
6411
|
-
try {
|
|
6412
|
-
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
|
6413
|
-
let read = this._reads[0];
|
|
6414
|
-
if (read.allowLess) this._processReadAllowingLess(read);
|
|
6415
|
-
else if (this._buffered >= read.length) this._processRead(read);
|
|
6416
|
-
else break;
|
|
6417
|
-
}
|
|
6418
|
-
if (this._buffers && !this.writable) this._end();
|
|
6419
|
-
} catch (ex) {
|
|
6420
|
-
this.emit("error", ex);
|
|
6421
|
-
}
|
|
6422
|
-
};
|
|
6423
|
-
}));
|
|
6424
|
-
//#endregion
|
|
6425
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/interlace.js
|
|
6426
|
-
var require_interlace = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
6427
|
-
let imagePasses = [
|
|
6428
|
-
{
|
|
6429
|
-
x: [0],
|
|
6430
|
-
y: [0]
|
|
6431
|
-
},
|
|
6432
|
-
{
|
|
6433
|
-
x: [4],
|
|
6434
|
-
y: [0]
|
|
6435
|
-
},
|
|
6436
|
-
{
|
|
6437
|
-
x: [0, 4],
|
|
6438
|
-
y: [4]
|
|
6439
|
-
},
|
|
6440
|
-
{
|
|
6441
|
-
x: [2, 6],
|
|
6442
|
-
y: [0, 4]
|
|
6443
|
-
},
|
|
6444
|
-
{
|
|
6445
|
-
x: [
|
|
6446
|
-
0,
|
|
6447
|
-
2,
|
|
6448
|
-
4,
|
|
6449
|
-
6
|
|
6450
|
-
],
|
|
6451
|
-
y: [2, 6]
|
|
6452
|
-
},
|
|
6453
|
-
{
|
|
6454
|
-
x: [
|
|
6455
|
-
1,
|
|
6456
|
-
3,
|
|
6457
|
-
5,
|
|
6458
|
-
7
|
|
6459
|
-
],
|
|
6460
|
-
y: [
|
|
6461
|
-
0,
|
|
6462
|
-
2,
|
|
6463
|
-
4,
|
|
6464
|
-
6
|
|
6465
|
-
]
|
|
6466
|
-
},
|
|
6467
|
-
{
|
|
6468
|
-
x: [
|
|
6469
|
-
0,
|
|
6470
|
-
1,
|
|
6471
|
-
2,
|
|
6472
|
-
3,
|
|
6473
|
-
4,
|
|
6474
|
-
5,
|
|
6475
|
-
6,
|
|
6476
|
-
7
|
|
6477
|
-
],
|
|
6478
|
-
y: [
|
|
6479
|
-
1,
|
|
6480
|
-
3,
|
|
6481
|
-
5,
|
|
6482
|
-
7
|
|
6483
|
-
]
|
|
6484
|
-
}
|
|
6485
|
-
];
|
|
6486
|
-
exports.getImagePasses = function(width, height) {
|
|
6487
|
-
let images = [];
|
|
6488
|
-
let xLeftOver = width % 8;
|
|
6489
|
-
let yLeftOver = height % 8;
|
|
6490
|
-
let xRepeats = (width - xLeftOver) / 8;
|
|
6491
|
-
let yRepeats = (height - yLeftOver) / 8;
|
|
6492
|
-
for (let i = 0; i < imagePasses.length; i++) {
|
|
6493
|
-
let pass = imagePasses[i];
|
|
6494
|
-
let passWidth = xRepeats * pass.x.length;
|
|
6495
|
-
let passHeight = yRepeats * pass.y.length;
|
|
6496
|
-
for (let j = 0; j < pass.x.length; j++) if (pass.x[j] < xLeftOver) passWidth++;
|
|
6497
|
-
else break;
|
|
6498
|
-
for (let j = 0; j < pass.y.length; j++) if (pass.y[j] < yLeftOver) passHeight++;
|
|
6499
|
-
else break;
|
|
6500
|
-
if (passWidth > 0 && passHeight > 0) images.push({
|
|
6501
|
-
width: passWidth,
|
|
6502
|
-
height: passHeight,
|
|
6503
|
-
index: i
|
|
6504
|
-
});
|
|
6505
|
-
}
|
|
6506
|
-
return images;
|
|
6507
|
-
};
|
|
6508
|
-
exports.getInterlaceIterator = function(width) {
|
|
6509
|
-
return function(x, y, pass) {
|
|
6510
|
-
let outerXLeftOver = x % imagePasses[pass].x.length;
|
|
6511
|
-
let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
6512
|
-
let outerYLeftOver = y % imagePasses[pass].y.length;
|
|
6513
|
-
let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
6514
|
-
return outerX * 4 + outerY * width * 4;
|
|
6515
|
-
};
|
|
6516
|
-
};
|
|
6517
|
-
}));
|
|
6518
|
-
//#endregion
|
|
6519
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/paeth-predictor.js
|
|
6520
|
-
var require_paeth_predictor = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6521
|
-
module.exports = function paethPredictor(left, above, upLeft) {
|
|
6522
|
-
let paeth = left + above - upLeft;
|
|
6523
|
-
let pLeft = Math.abs(paeth - left);
|
|
6524
|
-
let pAbove = Math.abs(paeth - above);
|
|
6525
|
-
let pUpLeft = Math.abs(paeth - upLeft);
|
|
6526
|
-
if (pLeft <= pAbove && pLeft <= pUpLeft) return left;
|
|
6527
|
-
if (pAbove <= pUpLeft) return above;
|
|
6528
|
-
return upLeft;
|
|
6529
|
-
};
|
|
6530
|
-
}));
|
|
6531
|
-
//#endregion
|
|
6532
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse.js
|
|
6533
|
-
var require_filter_parse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6534
|
-
let interlaceUtils = require_interlace();
|
|
6535
|
-
let paethPredictor = require_paeth_predictor();
|
|
6536
|
-
function getByteWidth(width, bpp, depth) {
|
|
6537
|
-
let byteWidth = width * bpp;
|
|
6538
|
-
if (depth !== 8) byteWidth = Math.ceil(byteWidth / (8 / depth));
|
|
6539
|
-
return byteWidth;
|
|
6540
|
-
}
|
|
6541
|
-
let Filter = module.exports = function(bitmapInfo, dependencies) {
|
|
6542
|
-
let width = bitmapInfo.width;
|
|
6543
|
-
let height = bitmapInfo.height;
|
|
6544
|
-
let interlace = bitmapInfo.interlace;
|
|
6545
|
-
let bpp = bitmapInfo.bpp;
|
|
6546
|
-
let depth = bitmapInfo.depth;
|
|
6547
|
-
this.read = dependencies.read;
|
|
6548
|
-
this.write = dependencies.write;
|
|
6549
|
-
this.complete = dependencies.complete;
|
|
6550
|
-
this._imageIndex = 0;
|
|
6551
|
-
this._images = [];
|
|
6552
|
-
if (interlace) {
|
|
6553
|
-
let passes = interlaceUtils.getImagePasses(width, height);
|
|
6554
|
-
for (let i = 0; i < passes.length; i++) this._images.push({
|
|
6555
|
-
byteWidth: getByteWidth(passes[i].width, bpp, depth),
|
|
6556
|
-
height: passes[i].height,
|
|
6557
|
-
lineIndex: 0
|
|
6558
|
-
});
|
|
6559
|
-
} else this._images.push({
|
|
6560
|
-
byteWidth: getByteWidth(width, bpp, depth),
|
|
6561
|
-
height,
|
|
6562
|
-
lineIndex: 0
|
|
6563
|
-
});
|
|
6564
|
-
if (depth === 8) this._xComparison = bpp;
|
|
6565
|
-
else if (depth === 16) this._xComparison = bpp * 2;
|
|
6566
|
-
else this._xComparison = 1;
|
|
6567
|
-
};
|
|
6568
|
-
Filter.prototype.start = function() {
|
|
6569
|
-
this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
6570
|
-
};
|
|
6571
|
-
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
6572
|
-
let xComparison = this._xComparison;
|
|
6573
|
-
let xBiggerThan = xComparison - 1;
|
|
6574
|
-
for (let x = 0; x < byteWidth; x++) unfilteredLine[x] = rawData[1 + x] + (x > xBiggerThan ? unfilteredLine[x - xComparison] : 0);
|
|
6575
|
-
};
|
|
6576
|
-
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
6577
|
-
let lastLine = this._lastLine;
|
|
6578
|
-
for (let x = 0; x < byteWidth; x++) unfilteredLine[x] = rawData[1 + x] + (lastLine ? lastLine[x] : 0);
|
|
6579
|
-
};
|
|
6580
|
-
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
6581
|
-
let xComparison = this._xComparison;
|
|
6582
|
-
let xBiggerThan = xComparison - 1;
|
|
6583
|
-
let lastLine = this._lastLine;
|
|
6584
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
6585
|
-
let rawByte = rawData[1 + x];
|
|
6586
|
-
let f3Up = lastLine ? lastLine[x] : 0;
|
|
6587
|
-
let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
|
6588
|
-
unfilteredLine[x] = rawByte + Math.floor((f3Left + f3Up) / 2);
|
|
6589
|
-
}
|
|
6590
|
-
};
|
|
6591
|
-
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
6592
|
-
let xComparison = this._xComparison;
|
|
6593
|
-
let xBiggerThan = xComparison - 1;
|
|
6594
|
-
let lastLine = this._lastLine;
|
|
6595
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
6596
|
-
let rawByte = rawData[1 + x];
|
|
6597
|
-
let f4Up = lastLine ? lastLine[x] : 0;
|
|
6598
|
-
let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
|
6599
|
-
let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
|
|
6600
|
-
unfilteredLine[x] = rawByte + paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
6601
|
-
}
|
|
6602
|
-
};
|
|
6603
|
-
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
6604
|
-
let filter = rawData[0];
|
|
6605
|
-
let unfilteredLine;
|
|
6606
|
-
let currentImage = this._images[this._imageIndex];
|
|
6607
|
-
let byteWidth = currentImage.byteWidth;
|
|
6608
|
-
if (filter === 0) unfilteredLine = rawData.slice(1, byteWidth + 1);
|
|
6609
|
-
else {
|
|
6610
|
-
unfilteredLine = Buffer.alloc(byteWidth);
|
|
6611
|
-
switch (filter) {
|
|
6612
|
-
case 1:
|
|
6613
|
-
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
|
6614
|
-
break;
|
|
6615
|
-
case 2:
|
|
6616
|
-
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
|
6617
|
-
break;
|
|
6618
|
-
case 3:
|
|
6619
|
-
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
|
6620
|
-
break;
|
|
6621
|
-
case 4:
|
|
6622
|
-
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
|
6623
|
-
break;
|
|
6624
|
-
default: throw new Error("Unrecognised filter type - " + filter);
|
|
6625
|
-
}
|
|
6626
|
-
}
|
|
6627
|
-
this.write(unfilteredLine);
|
|
6628
|
-
currentImage.lineIndex++;
|
|
6629
|
-
if (currentImage.lineIndex >= currentImage.height) {
|
|
6630
|
-
this._lastLine = null;
|
|
6631
|
-
this._imageIndex++;
|
|
6632
|
-
currentImage = this._images[this._imageIndex];
|
|
6633
|
-
} else this._lastLine = unfilteredLine;
|
|
6634
|
-
if (currentImage) this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
6635
|
-
else {
|
|
6636
|
-
this._lastLine = null;
|
|
6637
|
-
this.complete();
|
|
6638
|
-
}
|
|
6639
|
-
};
|
|
6640
|
-
}));
|
|
6641
|
-
//#endregion
|
|
6642
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-async.js
|
|
6643
|
-
var require_filter_parse_async = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6644
|
-
let util$4 = __require("util");
|
|
6645
|
-
let ChunkStream = require_chunkstream();
|
|
6646
|
-
let Filter = require_filter_parse();
|
|
6647
|
-
let FilterAsync = module.exports = function(bitmapInfo) {
|
|
6648
|
-
ChunkStream.call(this);
|
|
6649
|
-
let buffers = [];
|
|
6650
|
-
let that = this;
|
|
6651
|
-
this._filter = new Filter(bitmapInfo, {
|
|
6652
|
-
read: this.read.bind(this),
|
|
6653
|
-
write: function(buffer) {
|
|
6654
|
-
buffers.push(buffer);
|
|
6655
|
-
},
|
|
6656
|
-
complete: function() {
|
|
6657
|
-
that.emit("complete", Buffer.concat(buffers));
|
|
6658
|
-
}
|
|
6659
|
-
});
|
|
6660
|
-
this._filter.start();
|
|
6661
|
-
};
|
|
6662
|
-
util$4.inherits(FilterAsync, ChunkStream);
|
|
6663
|
-
}));
|
|
6664
|
-
//#endregion
|
|
6665
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/constants.js
|
|
6666
|
-
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6667
|
-
module.exports = {
|
|
6668
|
-
PNG_SIGNATURE: [
|
|
6669
|
-
137,
|
|
6670
|
-
80,
|
|
6671
|
-
78,
|
|
6672
|
-
71,
|
|
6673
|
-
13,
|
|
6674
|
-
10,
|
|
6675
|
-
26,
|
|
6676
|
-
10
|
|
6677
|
-
],
|
|
6678
|
-
TYPE_IHDR: 1229472850,
|
|
6679
|
-
TYPE_IEND: 1229278788,
|
|
6680
|
-
TYPE_IDAT: 1229209940,
|
|
6681
|
-
TYPE_PLTE: 1347179589,
|
|
6682
|
-
TYPE_tRNS: 1951551059,
|
|
6683
|
-
TYPE_gAMA: 1732332865,
|
|
6684
|
-
COLORTYPE_GRAYSCALE: 0,
|
|
6685
|
-
COLORTYPE_PALETTE: 1,
|
|
6686
|
-
COLORTYPE_COLOR: 2,
|
|
6687
|
-
COLORTYPE_ALPHA: 4,
|
|
6688
|
-
COLORTYPE_PALETTE_COLOR: 3,
|
|
6689
|
-
COLORTYPE_COLOR_ALPHA: 6,
|
|
6690
|
-
COLORTYPE_TO_BPP_MAP: {
|
|
6691
|
-
0: 1,
|
|
6692
|
-
2: 3,
|
|
6693
|
-
3: 1,
|
|
6694
|
-
4: 2,
|
|
6695
|
-
6: 4
|
|
6696
|
-
},
|
|
6697
|
-
GAMMA_DIVISION: 1e5
|
|
6698
|
-
};
|
|
6699
|
-
}));
|
|
6700
|
-
//#endregion
|
|
6701
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/crc.js
|
|
6702
|
-
var require_crc = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6703
|
-
let crcTable = [];
|
|
6704
|
-
(function() {
|
|
6705
|
-
for (let i = 0; i < 256; i++) {
|
|
6706
|
-
let currentCrc = i;
|
|
6707
|
-
for (let j = 0; j < 8; j++) if (currentCrc & 1) currentCrc = 3988292384 ^ currentCrc >>> 1;
|
|
6708
|
-
else currentCrc = currentCrc >>> 1;
|
|
6709
|
-
crcTable[i] = currentCrc;
|
|
6710
|
-
}
|
|
6711
|
-
})();
|
|
6712
|
-
let CrcCalculator = module.exports = function() {
|
|
6713
|
-
this._crc = -1;
|
|
6714
|
-
};
|
|
6715
|
-
CrcCalculator.prototype.write = function(data) {
|
|
6716
|
-
for (let i = 0; i < data.length; i++) this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
|
|
6717
|
-
return true;
|
|
6718
|
-
};
|
|
6719
|
-
CrcCalculator.prototype.crc32 = function() {
|
|
6720
|
-
return this._crc ^ -1;
|
|
6721
|
-
};
|
|
6722
|
-
CrcCalculator.crc32 = function(buf) {
|
|
6723
|
-
let crc = -1;
|
|
6724
|
-
for (let i = 0; i < buf.length; i++) crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
|
|
6725
|
-
return crc ^ -1;
|
|
6726
|
-
};
|
|
6727
|
-
}));
|
|
6728
|
-
//#endregion
|
|
6729
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser.js
|
|
6730
|
-
var require_parser = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
6731
|
-
let constants = require_constants();
|
|
6732
|
-
let CrcCalculator = require_crc();
|
|
6733
|
-
let Parser = module.exports = function(options, dependencies) {
|
|
6734
|
-
this._options = options;
|
|
6735
|
-
options.checkCRC = options.checkCRC !== false;
|
|
6736
|
-
this._hasIHDR = false;
|
|
6737
|
-
this._hasIEND = false;
|
|
6738
|
-
this._emittedHeadersFinished = false;
|
|
6739
|
-
this._palette = [];
|
|
6740
|
-
this._colorType = 0;
|
|
6741
|
-
this._chunks = {};
|
|
6742
|
-
this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
6743
|
-
this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
|
|
6744
|
-
this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
6745
|
-
this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
6746
|
-
this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
6747
|
-
this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
6748
|
-
this.read = dependencies.read;
|
|
6749
|
-
this.error = dependencies.error;
|
|
6750
|
-
this.metadata = dependencies.metadata;
|
|
6751
|
-
this.gamma = dependencies.gamma;
|
|
6752
|
-
this.transColor = dependencies.transColor;
|
|
6753
|
-
this.palette = dependencies.palette;
|
|
6754
|
-
this.parsed = dependencies.parsed;
|
|
6755
|
-
this.inflateData = dependencies.inflateData;
|
|
6756
|
-
this.finished = dependencies.finished;
|
|
6757
|
-
this.simpleTransparency = dependencies.simpleTransparency;
|
|
6758
|
-
this.headersFinished = dependencies.headersFinished || function() {};
|
|
6759
|
-
};
|
|
6760
|
-
Parser.prototype.start = function() {
|
|
6761
|
-
this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
6762
|
-
};
|
|
6763
|
-
Parser.prototype._parseSignature = function(data) {
|
|
6764
|
-
let signature = constants.PNG_SIGNATURE;
|
|
6765
|
-
for (let i = 0; i < signature.length; i++) if (data[i] !== signature[i]) {
|
|
6766
|
-
this.error(/* @__PURE__ */ new Error("Invalid file signature"));
|
|
6767
|
-
return;
|
|
6768
|
-
}
|
|
6769
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
6770
|
-
};
|
|
6771
|
-
Parser.prototype._parseChunkBegin = function(data) {
|
|
6772
|
-
let length = data.readUInt32BE(0);
|
|
6773
|
-
let type = data.readUInt32BE(4);
|
|
6774
|
-
let name = "";
|
|
6775
|
-
for (let i = 4; i < 8; i++) name += String.fromCharCode(data[i]);
|
|
6776
|
-
let ancillary = Boolean(data[4] & 32);
|
|
6777
|
-
if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
|
|
6778
|
-
this.error(/* @__PURE__ */ new Error("Expected IHDR on beggining"));
|
|
6779
|
-
return;
|
|
6780
|
-
}
|
|
6781
|
-
this._crc = new CrcCalculator();
|
|
6782
|
-
this._crc.write(Buffer.from(name));
|
|
6783
|
-
if (this._chunks[type]) return this._chunks[type](length);
|
|
6784
|
-
if (!ancillary) {
|
|
6785
|
-
this.error(/* @__PURE__ */ new Error("Unsupported critical chunk type " + name));
|
|
6786
|
-
return;
|
|
6787
|
-
}
|
|
6788
|
-
this.read(length + 4, this._skipChunk.bind(this));
|
|
6789
|
-
};
|
|
6790
|
-
Parser.prototype._skipChunk = function() {
|
|
6791
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
6792
|
-
};
|
|
6793
|
-
Parser.prototype._handleChunkEnd = function() {
|
|
6794
|
-
this.read(4, this._parseChunkEnd.bind(this));
|
|
6795
|
-
};
|
|
6796
|
-
Parser.prototype._parseChunkEnd = function(data) {
|
|
6797
|
-
let fileCrc = data.readInt32BE(0);
|
|
6798
|
-
let calcCrc = this._crc.crc32();
|
|
6799
|
-
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
|
6800
|
-
this.error(/* @__PURE__ */ new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
|
6801
|
-
return;
|
|
6802
|
-
}
|
|
6803
|
-
if (!this._hasIEND) this.read(8, this._parseChunkBegin.bind(this));
|
|
6804
|
-
};
|
|
6805
|
-
Parser.prototype._handleIHDR = function(length) {
|
|
6806
|
-
this.read(length, this._parseIHDR.bind(this));
|
|
6807
|
-
};
|
|
6808
|
-
Parser.prototype._parseIHDR = function(data) {
|
|
6809
|
-
this._crc.write(data);
|
|
6810
|
-
let width = data.readUInt32BE(0);
|
|
6811
|
-
let height = data.readUInt32BE(4);
|
|
6812
|
-
let depth = data[8];
|
|
6813
|
-
let colorType = data[9];
|
|
6814
|
-
let compr = data[10];
|
|
6815
|
-
let filter = data[11];
|
|
6816
|
-
let interlace = data[12];
|
|
6817
|
-
if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
|
|
6818
|
-
this.error(/* @__PURE__ */ new Error("Unsupported bit depth " + depth));
|
|
6819
|
-
return;
|
|
6820
|
-
}
|
|
6821
|
-
if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
|
|
6822
|
-
this.error(/* @__PURE__ */ new Error("Unsupported color type"));
|
|
6823
|
-
return;
|
|
6824
|
-
}
|
|
6825
|
-
if (compr !== 0) {
|
|
6826
|
-
this.error(/* @__PURE__ */ new Error("Unsupported compression method"));
|
|
6827
|
-
return;
|
|
6828
|
-
}
|
|
6829
|
-
if (filter !== 0) {
|
|
6830
|
-
this.error(/* @__PURE__ */ new Error("Unsupported filter method"));
|
|
6831
|
-
return;
|
|
6832
|
-
}
|
|
6833
|
-
if (interlace !== 0 && interlace !== 1) {
|
|
6834
|
-
this.error(/* @__PURE__ */ new Error("Unsupported interlace method"));
|
|
6835
|
-
return;
|
|
6836
|
-
}
|
|
6837
|
-
this._colorType = colorType;
|
|
6838
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
6839
|
-
this._hasIHDR = true;
|
|
6840
|
-
this.metadata({
|
|
6841
|
-
width,
|
|
6842
|
-
height,
|
|
6843
|
-
depth,
|
|
6844
|
-
interlace: Boolean(interlace),
|
|
6845
|
-
palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
|
|
6846
|
-
color: Boolean(colorType & constants.COLORTYPE_COLOR),
|
|
6847
|
-
alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
|
|
6848
|
-
bpp,
|
|
6849
|
-
colorType
|
|
6850
|
-
});
|
|
6851
|
-
this._handleChunkEnd();
|
|
6852
|
-
};
|
|
6853
|
-
Parser.prototype._handlePLTE = function(length) {
|
|
6854
|
-
this.read(length, this._parsePLTE.bind(this));
|
|
6855
|
-
};
|
|
6856
|
-
Parser.prototype._parsePLTE = function(data) {
|
|
6857
|
-
this._crc.write(data);
|
|
6858
|
-
let entries = Math.floor(data.length / 3);
|
|
6859
|
-
for (let i = 0; i < entries; i++) this._palette.push([
|
|
6860
|
-
data[i * 3],
|
|
6861
|
-
data[i * 3 + 1],
|
|
6862
|
-
data[i * 3 + 2],
|
|
6863
|
-
255
|
|
6864
|
-
]);
|
|
6865
|
-
this.palette(this._palette);
|
|
6866
|
-
this._handleChunkEnd();
|
|
6867
|
-
};
|
|
6868
|
-
Parser.prototype._handleTRNS = function(length) {
|
|
6869
|
-
this.simpleTransparency();
|
|
6870
|
-
this.read(length, this._parseTRNS.bind(this));
|
|
6871
|
-
};
|
|
6872
|
-
Parser.prototype._parseTRNS = function(data) {
|
|
6873
|
-
this._crc.write(data);
|
|
6874
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
|
|
6875
|
-
if (this._palette.length === 0) {
|
|
6876
|
-
this.error(/* @__PURE__ */ new Error("Transparency chunk must be after palette"));
|
|
6877
|
-
return;
|
|
6878
|
-
}
|
|
6879
|
-
if (data.length > this._palette.length) {
|
|
6880
|
-
this.error(/* @__PURE__ */ new Error("More transparent colors than palette size"));
|
|
6881
|
-
return;
|
|
6882
|
-
}
|
|
6883
|
-
for (let i = 0; i < data.length; i++) this._palette[i][3] = data[i];
|
|
6884
|
-
this.palette(this._palette);
|
|
6885
|
-
}
|
|
6886
|
-
if (this._colorType === constants.COLORTYPE_GRAYSCALE) this.transColor([data.readUInt16BE(0)]);
|
|
6887
|
-
if (this._colorType === constants.COLORTYPE_COLOR) this.transColor([
|
|
6888
|
-
data.readUInt16BE(0),
|
|
6889
|
-
data.readUInt16BE(2),
|
|
6890
|
-
data.readUInt16BE(4)
|
|
6891
|
-
]);
|
|
6892
|
-
this._handleChunkEnd();
|
|
6893
|
-
};
|
|
6894
|
-
Parser.prototype._handleGAMA = function(length) {
|
|
6895
|
-
this.read(length, this._parseGAMA.bind(this));
|
|
6896
|
-
};
|
|
6897
|
-
Parser.prototype._parseGAMA = function(data) {
|
|
6898
|
-
this._crc.write(data);
|
|
6899
|
-
this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
|
|
6900
|
-
this._handleChunkEnd();
|
|
6901
|
-
};
|
|
6902
|
-
Parser.prototype._handleIDAT = function(length) {
|
|
6903
|
-
if (!this._emittedHeadersFinished) {
|
|
6904
|
-
this._emittedHeadersFinished = true;
|
|
6905
|
-
this.headersFinished();
|
|
6906
|
-
}
|
|
6907
|
-
this.read(-length, this._parseIDAT.bind(this, length));
|
|
6908
|
-
};
|
|
6909
|
-
Parser.prototype._parseIDAT = function(length, data) {
|
|
6910
|
-
this._crc.write(data);
|
|
6911
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) throw new Error("Expected palette not found");
|
|
6912
|
-
this.inflateData(data);
|
|
6913
|
-
let leftOverLength = length - data.length;
|
|
6914
|
-
if (leftOverLength > 0) this._handleIDAT(leftOverLength);
|
|
6915
|
-
else this._handleChunkEnd();
|
|
6916
|
-
};
|
|
6917
|
-
Parser.prototype._handleIEND = function(length) {
|
|
6918
|
-
this.read(length, this._parseIEND.bind(this));
|
|
6919
|
-
};
|
|
6920
|
-
Parser.prototype._parseIEND = function(data) {
|
|
6921
|
-
this._crc.write(data);
|
|
6922
|
-
this._hasIEND = true;
|
|
6923
|
-
this._handleChunkEnd();
|
|
6924
|
-
if (this.finished) this.finished();
|
|
6925
|
-
};
|
|
6926
|
-
}));
|
|
6927
|
-
//#endregion
|
|
6928
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitmapper.js
|
|
6929
|
-
var require_bitmapper = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
6930
|
-
let interlaceUtils = require_interlace();
|
|
6931
|
-
let pixelBppMapper = [
|
|
6932
|
-
function() {},
|
|
6933
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6934
|
-
if (rawPos === data.length) throw new Error("Ran out of data");
|
|
6935
|
-
let pixel = data[rawPos];
|
|
6936
|
-
pxData[pxPos] = pixel;
|
|
6937
|
-
pxData[pxPos + 1] = pixel;
|
|
6938
|
-
pxData[pxPos + 2] = pixel;
|
|
6939
|
-
pxData[pxPos + 3] = 255;
|
|
6940
|
-
},
|
|
6941
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6942
|
-
if (rawPos + 1 >= data.length) throw new Error("Ran out of data");
|
|
6943
|
-
let pixel = data[rawPos];
|
|
6944
|
-
pxData[pxPos] = pixel;
|
|
6945
|
-
pxData[pxPos + 1] = pixel;
|
|
6946
|
-
pxData[pxPos + 2] = pixel;
|
|
6947
|
-
pxData[pxPos + 3] = data[rawPos + 1];
|
|
6948
|
-
},
|
|
6949
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6950
|
-
if (rawPos + 2 >= data.length) throw new Error("Ran out of data");
|
|
6951
|
-
pxData[pxPos] = data[rawPos];
|
|
6952
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
6953
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
6954
|
-
pxData[pxPos + 3] = 255;
|
|
6955
|
-
},
|
|
6956
|
-
function(pxData, data, pxPos, rawPos) {
|
|
6957
|
-
if (rawPos + 3 >= data.length) throw new Error("Ran out of data");
|
|
6958
|
-
pxData[pxPos] = data[rawPos];
|
|
6959
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
6960
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
6961
|
-
pxData[pxPos + 3] = data[rawPos + 3];
|
|
6962
|
-
}
|
|
6963
|
-
];
|
|
6964
|
-
let pixelBppCustomMapper = [
|
|
6965
|
-
function() {},
|
|
6966
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
6967
|
-
let pixel = pixelData[0];
|
|
6968
|
-
pxData[pxPos] = pixel;
|
|
6969
|
-
pxData[pxPos + 1] = pixel;
|
|
6970
|
-
pxData[pxPos + 2] = pixel;
|
|
6971
|
-
pxData[pxPos + 3] = maxBit;
|
|
6972
|
-
},
|
|
6973
|
-
function(pxData, pixelData, pxPos) {
|
|
6974
|
-
let pixel = pixelData[0];
|
|
6975
|
-
pxData[pxPos] = pixel;
|
|
6976
|
-
pxData[pxPos + 1] = pixel;
|
|
6977
|
-
pxData[pxPos + 2] = pixel;
|
|
6978
|
-
pxData[pxPos + 3] = pixelData[1];
|
|
6979
|
-
},
|
|
6980
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
6981
|
-
pxData[pxPos] = pixelData[0];
|
|
6982
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
6983
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
6984
|
-
pxData[pxPos + 3] = maxBit;
|
|
6985
|
-
},
|
|
6986
|
-
function(pxData, pixelData, pxPos) {
|
|
6987
|
-
pxData[pxPos] = pixelData[0];
|
|
6988
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
6989
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
6990
|
-
pxData[pxPos + 3] = pixelData[3];
|
|
6991
|
-
}
|
|
6992
|
-
];
|
|
6993
|
-
function bitRetriever(data, depth) {
|
|
6994
|
-
let leftOver = [];
|
|
6995
|
-
let i = 0;
|
|
6996
|
-
function split() {
|
|
6997
|
-
if (i === data.length) throw new Error("Ran out of data");
|
|
6998
|
-
let byte = data[i];
|
|
6999
|
-
i++;
|
|
7000
|
-
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
7001
|
-
switch (depth) {
|
|
7002
|
-
default: throw new Error("unrecognised depth");
|
|
7003
|
-
case 16:
|
|
7004
|
-
byte2 = data[i];
|
|
7005
|
-
i++;
|
|
7006
|
-
leftOver.push((byte << 8) + byte2);
|
|
7007
|
-
break;
|
|
7008
|
-
case 4:
|
|
7009
|
-
byte2 = byte & 15;
|
|
7010
|
-
byte1 = byte >> 4;
|
|
7011
|
-
leftOver.push(byte1, byte2);
|
|
7012
|
-
break;
|
|
7013
|
-
case 2:
|
|
7014
|
-
byte4 = byte & 3;
|
|
7015
|
-
byte3 = byte >> 2 & 3;
|
|
7016
|
-
byte2 = byte >> 4 & 3;
|
|
7017
|
-
byte1 = byte >> 6 & 3;
|
|
7018
|
-
leftOver.push(byte1, byte2, byte3, byte4);
|
|
7019
|
-
break;
|
|
7020
|
-
case 1:
|
|
7021
|
-
byte8 = byte & 1;
|
|
7022
|
-
byte7 = byte >> 1 & 1;
|
|
7023
|
-
byte6 = byte >> 2 & 1;
|
|
7024
|
-
byte5 = byte >> 3 & 1;
|
|
7025
|
-
byte4 = byte >> 4 & 1;
|
|
7026
|
-
byte3 = byte >> 5 & 1;
|
|
7027
|
-
byte2 = byte >> 6 & 1;
|
|
7028
|
-
byte1 = byte >> 7 & 1;
|
|
7029
|
-
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
7030
|
-
break;
|
|
7031
|
-
}
|
|
7032
|
-
}
|
|
7033
|
-
return {
|
|
7034
|
-
get: function(count) {
|
|
7035
|
-
while (leftOver.length < count) split();
|
|
7036
|
-
let returner = leftOver.slice(0, count);
|
|
7037
|
-
leftOver = leftOver.slice(count);
|
|
7038
|
-
return returner;
|
|
7039
|
-
},
|
|
7040
|
-
resetAfterLine: function() {
|
|
7041
|
-
leftOver.length = 0;
|
|
7042
|
-
},
|
|
7043
|
-
end: function() {
|
|
7044
|
-
if (i !== data.length) throw new Error("extra data found");
|
|
7045
|
-
}
|
|
7046
|
-
};
|
|
7047
|
-
}
|
|
7048
|
-
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
7049
|
-
let imageWidth = image.width;
|
|
7050
|
-
let imageHeight = image.height;
|
|
7051
|
-
let imagePass = image.index;
|
|
7052
|
-
for (let y = 0; y < imageHeight; y++) for (let x = 0; x < imageWidth; x++) {
|
|
7053
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
7054
|
-
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
7055
|
-
rawPos += bpp;
|
|
7056
|
-
}
|
|
7057
|
-
return rawPos;
|
|
7058
|
-
}
|
|
7059
|
-
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
7060
|
-
let imageWidth = image.width;
|
|
7061
|
-
let imageHeight = image.height;
|
|
7062
|
-
let imagePass = image.index;
|
|
7063
|
-
for (let y = 0; y < imageHeight; y++) {
|
|
7064
|
-
for (let x = 0; x < imageWidth; x++) {
|
|
7065
|
-
let pixelData = bits.get(bpp);
|
|
7066
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
7067
|
-
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
7068
|
-
}
|
|
7069
|
-
bits.resetAfterLine();
|
|
7070
|
-
}
|
|
7071
|
-
}
|
|
7072
|
-
exports.dataToBitMap = function(data, bitmapInfo) {
|
|
7073
|
-
let width = bitmapInfo.width;
|
|
7074
|
-
let height = bitmapInfo.height;
|
|
7075
|
-
let depth = bitmapInfo.depth;
|
|
7076
|
-
let bpp = bitmapInfo.bpp;
|
|
7077
|
-
let interlace = bitmapInfo.interlace;
|
|
7078
|
-
let bits;
|
|
7079
|
-
if (depth !== 8) bits = bitRetriever(data, depth);
|
|
7080
|
-
let pxData;
|
|
7081
|
-
if (depth <= 8) pxData = Buffer.alloc(width * height * 4);
|
|
7082
|
-
else pxData = new Uint16Array(width * height * 4);
|
|
7083
|
-
let maxBit = Math.pow(2, depth) - 1;
|
|
7084
|
-
let rawPos = 0;
|
|
7085
|
-
let images;
|
|
7086
|
-
let getPxPos;
|
|
7087
|
-
if (interlace) {
|
|
7088
|
-
images = interlaceUtils.getImagePasses(width, height);
|
|
7089
|
-
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
7090
|
-
} else {
|
|
7091
|
-
let nonInterlacedPxPos = 0;
|
|
7092
|
-
getPxPos = function() {
|
|
7093
|
-
let returner = nonInterlacedPxPos;
|
|
7094
|
-
nonInterlacedPxPos += 4;
|
|
7095
|
-
return returner;
|
|
7096
|
-
};
|
|
7097
|
-
images = [{
|
|
7098
|
-
width,
|
|
7099
|
-
height
|
|
7100
|
-
}];
|
|
7101
|
-
}
|
|
7102
|
-
for (let imageIndex = 0; imageIndex < images.length; imageIndex++) if (depth === 8) rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
|
|
7103
|
-
else mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
|
|
7104
|
-
if (depth === 8) {
|
|
7105
|
-
if (rawPos !== data.length) throw new Error("extra data found");
|
|
7106
|
-
} else bits.end();
|
|
7107
|
-
return pxData;
|
|
7108
|
-
};
|
|
7109
|
-
}));
|
|
7110
|
-
//#endregion
|
|
7111
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/format-normaliser.js
|
|
7112
|
-
var require_format_normaliser = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7113
|
-
function dePalette(indata, outdata, width, height, palette) {
|
|
7114
|
-
let pxPos = 0;
|
|
7115
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
7116
|
-
let color = palette[indata[pxPos]];
|
|
7117
|
-
if (!color) throw new Error("index " + indata[pxPos] + " not in palette");
|
|
7118
|
-
for (let i = 0; i < 4; i++) outdata[pxPos + i] = color[i];
|
|
7119
|
-
pxPos += 4;
|
|
7120
|
-
}
|
|
7121
|
-
}
|
|
7122
|
-
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
7123
|
-
let pxPos = 0;
|
|
7124
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
7125
|
-
let makeTrans = false;
|
|
7126
|
-
if (transColor.length === 1) {
|
|
7127
|
-
if (transColor[0] === indata[pxPos]) makeTrans = true;
|
|
7128
|
-
} else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) makeTrans = true;
|
|
7129
|
-
if (makeTrans) for (let i = 0; i < 4; i++) outdata[pxPos + i] = 0;
|
|
7130
|
-
pxPos += 4;
|
|
7131
|
-
}
|
|
7132
|
-
}
|
|
7133
|
-
function scaleDepth(indata, outdata, width, height, depth) {
|
|
7134
|
-
let maxOutSample = 255;
|
|
7135
|
-
let maxInSample = Math.pow(2, depth) - 1;
|
|
7136
|
-
let pxPos = 0;
|
|
7137
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
7138
|
-
for (let i = 0; i < 4; i++) outdata[pxPos + i] = Math.floor(indata[pxPos + i] * maxOutSample / maxInSample + .5);
|
|
7139
|
-
pxPos += 4;
|
|
7140
|
-
}
|
|
7141
|
-
}
|
|
7142
|
-
module.exports = function(indata, imageData, skipRescale = false) {
|
|
7143
|
-
let depth = imageData.depth;
|
|
7144
|
-
let width = imageData.width;
|
|
7145
|
-
let height = imageData.height;
|
|
7146
|
-
let colorType = imageData.colorType;
|
|
7147
|
-
let transColor = imageData.transColor;
|
|
7148
|
-
let palette = imageData.palette;
|
|
7149
|
-
let outdata = indata;
|
|
7150
|
-
if (colorType === 3) dePalette(indata, outdata, width, height, palette);
|
|
7151
|
-
else {
|
|
7152
|
-
if (transColor) replaceTransparentColor(indata, outdata, width, height, transColor);
|
|
7153
|
-
if (depth !== 8 && !skipRescale) {
|
|
7154
|
-
if (depth === 16) outdata = Buffer.alloc(width * height * 4);
|
|
7155
|
-
scaleDepth(indata, outdata, width, height, depth);
|
|
7156
|
-
}
|
|
7157
|
-
}
|
|
7158
|
-
return outdata;
|
|
7159
|
-
};
|
|
7160
|
-
}));
|
|
7161
|
-
//#endregion
|
|
7162
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-async.js
|
|
7163
|
-
var require_parser_async = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7164
|
-
let util$3 = __require("util");
|
|
7165
|
-
let zlib$4 = __require("zlib");
|
|
7166
|
-
let ChunkStream = require_chunkstream();
|
|
7167
|
-
let FilterAsync = require_filter_parse_async();
|
|
7168
|
-
let Parser = require_parser();
|
|
7169
|
-
let bitmapper = require_bitmapper();
|
|
7170
|
-
let formatNormaliser = require_format_normaliser();
|
|
7171
|
-
let ParserAsync = module.exports = function(options) {
|
|
7172
|
-
ChunkStream.call(this);
|
|
7173
|
-
this._parser = new Parser(options, {
|
|
7174
|
-
read: this.read.bind(this),
|
|
7175
|
-
error: this._handleError.bind(this),
|
|
7176
|
-
metadata: this._handleMetaData.bind(this),
|
|
7177
|
-
gamma: this.emit.bind(this, "gamma"),
|
|
7178
|
-
palette: this._handlePalette.bind(this),
|
|
7179
|
-
transColor: this._handleTransColor.bind(this),
|
|
7180
|
-
finished: this._finished.bind(this),
|
|
7181
|
-
inflateData: this._inflateData.bind(this),
|
|
7182
|
-
simpleTransparency: this._simpleTransparency.bind(this),
|
|
7183
|
-
headersFinished: this._headersFinished.bind(this)
|
|
7184
|
-
});
|
|
7185
|
-
this._options = options;
|
|
7186
|
-
this.writable = true;
|
|
7187
|
-
this._parser.start();
|
|
7188
|
-
};
|
|
7189
|
-
util$3.inherits(ParserAsync, ChunkStream);
|
|
7190
|
-
ParserAsync.prototype._handleError = function(err) {
|
|
7191
|
-
this.emit("error", err);
|
|
7192
|
-
this.writable = false;
|
|
7193
|
-
this.destroy();
|
|
7194
|
-
if (this._inflate && this._inflate.destroy) this._inflate.destroy();
|
|
7195
|
-
if (this._filter) {
|
|
7196
|
-
this._filter.destroy();
|
|
7197
|
-
this._filter.on("error", function() {});
|
|
7198
|
-
}
|
|
7199
|
-
this.errord = true;
|
|
7200
|
-
};
|
|
7201
|
-
ParserAsync.prototype._inflateData = function(data) {
|
|
7202
|
-
if (!this._inflate) if (this._bitmapInfo.interlace) {
|
|
7203
|
-
this._inflate = zlib$4.createInflate();
|
|
7204
|
-
this._inflate.on("error", this.emit.bind(this, "error"));
|
|
7205
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
7206
|
-
this._inflate.pipe(this._filter);
|
|
7207
|
-
} else {
|
|
7208
|
-
let imageSize = ((this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1) * this._bitmapInfo.height;
|
|
7209
|
-
let chunkSize = Math.max(imageSize, zlib$4.Z_MIN_CHUNK);
|
|
7210
|
-
this._inflate = zlib$4.createInflate({ chunkSize });
|
|
7211
|
-
let leftToInflate = imageSize;
|
|
7212
|
-
let emitError = this.emit.bind(this, "error");
|
|
7213
|
-
this._inflate.on("error", function(err) {
|
|
7214
|
-
if (!leftToInflate) return;
|
|
7215
|
-
emitError(err);
|
|
7216
|
-
});
|
|
7217
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
7218
|
-
let filterWrite = this._filter.write.bind(this._filter);
|
|
7219
|
-
this._inflate.on("data", function(chunk) {
|
|
7220
|
-
if (!leftToInflate) return;
|
|
7221
|
-
if (chunk.length > leftToInflate) chunk = chunk.slice(0, leftToInflate);
|
|
7222
|
-
leftToInflate -= chunk.length;
|
|
7223
|
-
filterWrite(chunk);
|
|
7224
|
-
});
|
|
7225
|
-
this._inflate.on("end", this._filter.end.bind(this._filter));
|
|
7226
|
-
}
|
|
7227
|
-
this._inflate.write(data);
|
|
7228
|
-
};
|
|
7229
|
-
ParserAsync.prototype._handleMetaData = function(metaData) {
|
|
7230
|
-
this._metaData = metaData;
|
|
7231
|
-
this._bitmapInfo = Object.create(metaData);
|
|
7232
|
-
this._filter = new FilterAsync(this._bitmapInfo);
|
|
7233
|
-
};
|
|
7234
|
-
ParserAsync.prototype._handleTransColor = function(transColor) {
|
|
7235
|
-
this._bitmapInfo.transColor = transColor;
|
|
7236
|
-
};
|
|
7237
|
-
ParserAsync.prototype._handlePalette = function(palette) {
|
|
7238
|
-
this._bitmapInfo.palette = palette;
|
|
7239
|
-
};
|
|
7240
|
-
ParserAsync.prototype._simpleTransparency = function() {
|
|
7241
|
-
this._metaData.alpha = true;
|
|
7242
|
-
};
|
|
7243
|
-
ParserAsync.prototype._headersFinished = function() {
|
|
7244
|
-
this.emit("metadata", this._metaData);
|
|
7245
|
-
};
|
|
7246
|
-
ParserAsync.prototype._finished = function() {
|
|
7247
|
-
if (this.errord) return;
|
|
7248
|
-
if (!this._inflate) this.emit("error", "No Inflate block");
|
|
7249
|
-
else this._inflate.end();
|
|
7250
|
-
};
|
|
7251
|
-
ParserAsync.prototype._complete = function(filteredData) {
|
|
7252
|
-
if (this.errord) return;
|
|
7253
|
-
let normalisedBitmapData;
|
|
7254
|
-
try {
|
|
7255
|
-
let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
|
|
7256
|
-
normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo, this._options.skipRescale);
|
|
7257
|
-
bitmapData = null;
|
|
7258
|
-
} catch (ex) {
|
|
7259
|
-
this._handleError(ex);
|
|
7260
|
-
return;
|
|
7261
|
-
}
|
|
7262
|
-
this.emit("parsed", normalisedBitmapData);
|
|
7263
|
-
};
|
|
7264
|
-
}));
|
|
7265
|
-
//#endregion
|
|
7266
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitpacker.js
|
|
7267
|
-
var require_bitpacker = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7268
|
-
let constants = require_constants();
|
|
7269
|
-
module.exports = function(dataIn, width, height, options) {
|
|
7270
|
-
let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
|
|
7271
|
-
if (options.colorType === options.inputColorType) {
|
|
7272
|
-
let bigEndian = (function() {
|
|
7273
|
-
let buffer = /* @__PURE__ */ new ArrayBuffer(2);
|
|
7274
|
-
new DataView(buffer).setInt16(0, 256, true);
|
|
7275
|
-
return new Int16Array(buffer)[0] !== 256;
|
|
7276
|
-
})();
|
|
7277
|
-
if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) return dataIn;
|
|
7278
|
-
}
|
|
7279
|
-
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
7280
|
-
let maxValue = 255;
|
|
7281
|
-
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
7282
|
-
if (inBpp === 4 && !options.inputHasAlpha) inBpp = 3;
|
|
7283
|
-
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
7284
|
-
if (options.bitDepth === 16) {
|
|
7285
|
-
maxValue = 65535;
|
|
7286
|
-
outBpp *= 2;
|
|
7287
|
-
}
|
|
7288
|
-
let outData = Buffer.alloc(width * height * outBpp);
|
|
7289
|
-
let inIndex = 0;
|
|
7290
|
-
let outIndex = 0;
|
|
7291
|
-
let bgColor = options.bgColor || {};
|
|
7292
|
-
if (bgColor.red === void 0) bgColor.red = maxValue;
|
|
7293
|
-
if (bgColor.green === void 0) bgColor.green = maxValue;
|
|
7294
|
-
if (bgColor.blue === void 0) bgColor.blue = maxValue;
|
|
7295
|
-
function getRGBA() {
|
|
7296
|
-
let red;
|
|
7297
|
-
let green;
|
|
7298
|
-
let blue;
|
|
7299
|
-
let alpha = maxValue;
|
|
7300
|
-
switch (options.inputColorType) {
|
|
7301
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
7302
|
-
alpha = data[inIndex + 3];
|
|
7303
|
-
red = data[inIndex];
|
|
7304
|
-
green = data[inIndex + 1];
|
|
7305
|
-
blue = data[inIndex + 2];
|
|
7306
|
-
break;
|
|
7307
|
-
case constants.COLORTYPE_COLOR:
|
|
7308
|
-
red = data[inIndex];
|
|
7309
|
-
green = data[inIndex + 1];
|
|
7310
|
-
blue = data[inIndex + 2];
|
|
7311
|
-
break;
|
|
7312
|
-
case constants.COLORTYPE_ALPHA:
|
|
7313
|
-
alpha = data[inIndex + 1];
|
|
7314
|
-
red = data[inIndex];
|
|
7315
|
-
green = red;
|
|
7316
|
-
blue = red;
|
|
7317
|
-
break;
|
|
7318
|
-
case constants.COLORTYPE_GRAYSCALE:
|
|
7319
|
-
red = data[inIndex];
|
|
7320
|
-
green = red;
|
|
7321
|
-
blue = red;
|
|
7322
|
-
break;
|
|
7323
|
-
default: throw new Error("input color type:" + options.inputColorType + " is not supported at present");
|
|
7324
|
-
}
|
|
7325
|
-
if (options.inputHasAlpha) {
|
|
7326
|
-
if (!outHasAlpha) {
|
|
7327
|
-
alpha /= maxValue;
|
|
7328
|
-
red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
|
|
7329
|
-
green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
|
|
7330
|
-
blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
|
|
7331
|
-
}
|
|
7332
|
-
}
|
|
7333
|
-
return {
|
|
7334
|
-
red,
|
|
7335
|
-
green,
|
|
7336
|
-
blue,
|
|
7337
|
-
alpha
|
|
7338
|
-
};
|
|
7339
|
-
}
|
|
7340
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
7341
|
-
let rgba = getRGBA(data, inIndex);
|
|
7342
|
-
switch (options.colorType) {
|
|
7343
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
7344
|
-
case constants.COLORTYPE_COLOR:
|
|
7345
|
-
if (options.bitDepth === 8) {
|
|
7346
|
-
outData[outIndex] = rgba.red;
|
|
7347
|
-
outData[outIndex + 1] = rgba.green;
|
|
7348
|
-
outData[outIndex + 2] = rgba.blue;
|
|
7349
|
-
if (outHasAlpha) outData[outIndex + 3] = rgba.alpha;
|
|
7350
|
-
} else {
|
|
7351
|
-
outData.writeUInt16BE(rgba.red, outIndex);
|
|
7352
|
-
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
7353
|
-
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
7354
|
-
if (outHasAlpha) outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
7355
|
-
}
|
|
7356
|
-
break;
|
|
7357
|
-
case constants.COLORTYPE_ALPHA:
|
|
7358
|
-
case constants.COLORTYPE_GRAYSCALE: {
|
|
7359
|
-
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
7360
|
-
if (options.bitDepth === 8) {
|
|
7361
|
-
outData[outIndex] = grayscale;
|
|
7362
|
-
if (outHasAlpha) outData[outIndex + 1] = rgba.alpha;
|
|
7363
|
-
} else {
|
|
7364
|
-
outData.writeUInt16BE(grayscale, outIndex);
|
|
7365
|
-
if (outHasAlpha) outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
7366
|
-
}
|
|
7367
|
-
break;
|
|
7368
|
-
}
|
|
7369
|
-
default: throw new Error("unrecognised color Type " + options.colorType);
|
|
7370
|
-
}
|
|
7371
|
-
inIndex += inBpp;
|
|
7372
|
-
outIndex += outBpp;
|
|
7373
|
-
}
|
|
7374
|
-
return outData;
|
|
7375
|
-
};
|
|
7376
|
-
}));
|
|
7377
|
-
//#endregion
|
|
7378
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-pack.js
|
|
7379
|
-
var require_filter_pack = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7380
|
-
let paethPredictor = require_paeth_predictor();
|
|
7381
|
-
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
7382
|
-
for (let x = 0; x < byteWidth; x++) rawData[rawPos + x] = pxData[pxPos + x];
|
|
7383
|
-
}
|
|
7384
|
-
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
7385
|
-
let sum = 0;
|
|
7386
|
-
let length = pxPos + byteWidth;
|
|
7387
|
-
for (let i = pxPos; i < length; i++) sum += Math.abs(pxData[i]);
|
|
7388
|
-
return sum;
|
|
7389
|
-
}
|
|
7390
|
-
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7391
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7392
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7393
|
-
let val = pxData[pxPos + x] - left;
|
|
7394
|
-
rawData[rawPos + x] = val;
|
|
7395
|
-
}
|
|
7396
|
-
}
|
|
7397
|
-
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
7398
|
-
let sum = 0;
|
|
7399
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7400
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7401
|
-
let val = pxData[pxPos + x] - left;
|
|
7402
|
-
sum += Math.abs(val);
|
|
7403
|
-
}
|
|
7404
|
-
return sum;
|
|
7405
|
-
}
|
|
7406
|
-
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
7407
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7408
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
7409
|
-
let val = pxData[pxPos + x] - up;
|
|
7410
|
-
rawData[rawPos + x] = val;
|
|
7411
|
-
}
|
|
7412
|
-
}
|
|
7413
|
-
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
7414
|
-
let sum = 0;
|
|
7415
|
-
let length = pxPos + byteWidth;
|
|
7416
|
-
for (let x = pxPos; x < length; x++) {
|
|
7417
|
-
let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
|
|
7418
|
-
let val = pxData[x] - up;
|
|
7419
|
-
sum += Math.abs(val);
|
|
7420
|
-
}
|
|
7421
|
-
return sum;
|
|
7422
|
-
}
|
|
7423
|
-
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7424
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7425
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7426
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
7427
|
-
let val = pxData[pxPos + x] - (left + up >> 1);
|
|
7428
|
-
rawData[rawPos + x] = val;
|
|
7429
|
-
}
|
|
7430
|
-
}
|
|
7431
|
-
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
7432
|
-
let sum = 0;
|
|
7433
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7434
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7435
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
7436
|
-
let val = pxData[pxPos + x] - (left + up >> 1);
|
|
7437
|
-
sum += Math.abs(val);
|
|
7438
|
-
}
|
|
7439
|
-
return sum;
|
|
7440
|
-
}
|
|
7441
|
-
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7442
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7443
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7444
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
7445
|
-
let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
7446
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
7447
|
-
rawData[rawPos + x] = val;
|
|
7448
|
-
}
|
|
7449
|
-
}
|
|
7450
|
-
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
7451
|
-
let sum = 0;
|
|
7452
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7453
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
7454
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
7455
|
-
let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
7456
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
7457
|
-
sum += Math.abs(val);
|
|
7458
|
-
}
|
|
7459
|
-
return sum;
|
|
7460
|
-
}
|
|
7461
|
-
let filters = {
|
|
7462
|
-
0: filterNone,
|
|
7463
|
-
1: filterSub,
|
|
7464
|
-
2: filterUp,
|
|
7465
|
-
3: filterAvg,
|
|
7466
|
-
4: filterPaeth
|
|
7467
|
-
};
|
|
7468
|
-
let filterSums = {
|
|
7469
|
-
0: filterSumNone,
|
|
7470
|
-
1: filterSumSub,
|
|
7471
|
-
2: filterSumUp,
|
|
7472
|
-
3: filterSumAvg,
|
|
7473
|
-
4: filterSumPaeth
|
|
7474
|
-
};
|
|
7475
|
-
module.exports = function(pxData, width, height, options, bpp) {
|
|
7476
|
-
let filterTypes;
|
|
7477
|
-
if (!("filterType" in options) || options.filterType === -1) filterTypes = [
|
|
7478
|
-
0,
|
|
7479
|
-
1,
|
|
7480
|
-
2,
|
|
7481
|
-
3,
|
|
7482
|
-
4
|
|
7483
|
-
];
|
|
7484
|
-
else if (typeof options.filterType === "number") filterTypes = [options.filterType];
|
|
7485
|
-
else throw new Error("unrecognised filter types");
|
|
7486
|
-
if (options.bitDepth === 16) bpp *= 2;
|
|
7487
|
-
let byteWidth = width * bpp;
|
|
7488
|
-
let rawPos = 0;
|
|
7489
|
-
let pxPos = 0;
|
|
7490
|
-
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
7491
|
-
let sel = filterTypes[0];
|
|
7492
|
-
for (let y = 0; y < height; y++) {
|
|
7493
|
-
if (filterTypes.length > 1) {
|
|
7494
|
-
let min = Infinity;
|
|
7495
|
-
for (let i = 0; i < filterTypes.length; i++) {
|
|
7496
|
-
let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
|
|
7497
|
-
if (sum < min) {
|
|
7498
|
-
sel = filterTypes[i];
|
|
7499
|
-
min = sum;
|
|
7500
|
-
}
|
|
7501
|
-
}
|
|
7502
|
-
}
|
|
7503
|
-
rawData[rawPos] = sel;
|
|
7504
|
-
rawPos++;
|
|
7505
|
-
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
7506
|
-
rawPos += byteWidth;
|
|
7507
|
-
pxPos += byteWidth;
|
|
7508
|
-
}
|
|
7509
|
-
return rawData;
|
|
7510
|
-
};
|
|
7511
|
-
}));
|
|
7512
|
-
//#endregion
|
|
7513
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer.js
|
|
7514
|
-
var require_packer = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7515
|
-
let constants = require_constants();
|
|
7516
|
-
let CrcStream = require_crc();
|
|
7517
|
-
let bitPacker = require_bitpacker();
|
|
7518
|
-
let filter = require_filter_pack();
|
|
7519
|
-
let zlib$3 = __require("zlib");
|
|
7520
|
-
let Packer = module.exports = function(options) {
|
|
7521
|
-
this._options = options;
|
|
7522
|
-
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
|
7523
|
-
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
|
|
7524
|
-
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
|
|
7525
|
-
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
7526
|
-
options.deflateFactory = options.deflateFactory || zlib$3.createDeflate;
|
|
7527
|
-
options.bitDepth = options.bitDepth || 8;
|
|
7528
|
-
options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
7529
|
-
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
7530
|
-
if ([
|
|
7531
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
7532
|
-
constants.COLORTYPE_COLOR,
|
|
7533
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
7534
|
-
constants.COLORTYPE_ALPHA
|
|
7535
|
-
].indexOf(options.colorType) === -1) throw new Error("option color type:" + options.colorType + " is not supported at present");
|
|
7536
|
-
if ([
|
|
7537
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
7538
|
-
constants.COLORTYPE_COLOR,
|
|
7539
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
7540
|
-
constants.COLORTYPE_ALPHA
|
|
7541
|
-
].indexOf(options.inputColorType) === -1) throw new Error("option input color type:" + options.inputColorType + " is not supported at present");
|
|
7542
|
-
if (options.bitDepth !== 8 && options.bitDepth !== 16) throw new Error("option bit depth:" + options.bitDepth + " is not supported at present");
|
|
7543
|
-
};
|
|
7544
|
-
Packer.prototype.getDeflateOptions = function() {
|
|
7545
|
-
return {
|
|
7546
|
-
chunkSize: this._options.deflateChunkSize,
|
|
7547
|
-
level: this._options.deflateLevel,
|
|
7548
|
-
strategy: this._options.deflateStrategy
|
|
7549
|
-
};
|
|
7550
|
-
};
|
|
7551
|
-
Packer.prototype.createDeflate = function() {
|
|
7552
|
-
return this._options.deflateFactory(this.getDeflateOptions());
|
|
7553
|
-
};
|
|
7554
|
-
Packer.prototype.filterData = function(data, width, height) {
|
|
7555
|
-
let packedData = bitPacker(data, width, height, this._options);
|
|
7556
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
7557
|
-
return filter(packedData, width, height, this._options, bpp);
|
|
7558
|
-
};
|
|
7559
|
-
Packer.prototype._packChunk = function(type, data) {
|
|
7560
|
-
let len = data ? data.length : 0;
|
|
7561
|
-
let buf = Buffer.alloc(len + 12);
|
|
7562
|
-
buf.writeUInt32BE(len, 0);
|
|
7563
|
-
buf.writeUInt32BE(type, 4);
|
|
7564
|
-
if (data) data.copy(buf, 8);
|
|
7565
|
-
buf.writeInt32BE(CrcStream.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
|
|
7566
|
-
return buf;
|
|
7567
|
-
};
|
|
7568
|
-
Packer.prototype.packGAMA = function(gamma) {
|
|
7569
|
-
let buf = Buffer.alloc(4);
|
|
7570
|
-
buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
|
|
7571
|
-
return this._packChunk(constants.TYPE_gAMA, buf);
|
|
7572
|
-
};
|
|
7573
|
-
Packer.prototype.packIHDR = function(width, height) {
|
|
7574
|
-
let buf = Buffer.alloc(13);
|
|
7575
|
-
buf.writeUInt32BE(width, 0);
|
|
7576
|
-
buf.writeUInt32BE(height, 4);
|
|
7577
|
-
buf[8] = this._options.bitDepth;
|
|
7578
|
-
buf[9] = this._options.colorType;
|
|
7579
|
-
buf[10] = 0;
|
|
7580
|
-
buf[11] = 0;
|
|
7581
|
-
buf[12] = 0;
|
|
7582
|
-
return this._packChunk(constants.TYPE_IHDR, buf);
|
|
7583
|
-
};
|
|
7584
|
-
Packer.prototype.packIDAT = function(data) {
|
|
7585
|
-
return this._packChunk(constants.TYPE_IDAT, data);
|
|
7586
|
-
};
|
|
7587
|
-
Packer.prototype.packIEND = function() {
|
|
7588
|
-
return this._packChunk(constants.TYPE_IEND, null);
|
|
7589
|
-
};
|
|
7590
|
-
}));
|
|
7591
|
-
//#endregion
|
|
7592
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-async.js
|
|
7593
|
-
var require_packer_async = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7594
|
-
let util$2 = __require("util");
|
|
7595
|
-
let Stream$1 = __require("stream");
|
|
7596
|
-
let constants = require_constants();
|
|
7597
|
-
let Packer = require_packer();
|
|
7598
|
-
let PackerAsync = module.exports = function(opt) {
|
|
7599
|
-
Stream$1.call(this);
|
|
7600
|
-
let options = opt || {};
|
|
7601
|
-
this._packer = new Packer(options);
|
|
7602
|
-
this._deflate = this._packer.createDeflate();
|
|
7603
|
-
this.readable = true;
|
|
7604
|
-
};
|
|
7605
|
-
util$2.inherits(PackerAsync, Stream$1);
|
|
7606
|
-
PackerAsync.prototype.pack = function(data, width, height, gamma) {
|
|
7607
|
-
this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
|
|
7608
|
-
this.emit("data", this._packer.packIHDR(width, height));
|
|
7609
|
-
if (gamma) this.emit("data", this._packer.packGAMA(gamma));
|
|
7610
|
-
let filteredData = this._packer.filterData(data, width, height);
|
|
7611
|
-
this._deflate.on("error", this.emit.bind(this, "error"));
|
|
7612
|
-
this._deflate.on("data", function(compressedData) {
|
|
7613
|
-
this.emit("data", this._packer.packIDAT(compressedData));
|
|
7614
|
-
}.bind(this));
|
|
7615
|
-
this._deflate.on("end", function() {
|
|
7616
|
-
this.emit("data", this._packer.packIEND());
|
|
7617
|
-
this.emit("end");
|
|
7618
|
-
}.bind(this));
|
|
7619
|
-
this._deflate.end(filteredData);
|
|
7620
|
-
};
|
|
7621
|
-
}));
|
|
7622
|
-
//#endregion
|
|
7623
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-inflate.js
|
|
7624
|
-
var require_sync_inflate = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7625
|
-
let assert = __require("assert").ok;
|
|
7626
|
-
let zlib$2 = __require("zlib");
|
|
7627
|
-
let util$1 = __require("util");
|
|
7628
|
-
let kMaxLength = __require("buffer").kMaxLength;
|
|
7629
|
-
function Inflate(opts) {
|
|
7630
|
-
if (!(this instanceof Inflate)) return new Inflate(opts);
|
|
7631
|
-
if (opts && opts.chunkSize < zlib$2.Z_MIN_CHUNK) opts.chunkSize = zlib$2.Z_MIN_CHUNK;
|
|
7632
|
-
zlib$2.Inflate.call(this, opts);
|
|
7633
|
-
this._offset = this._offset === void 0 ? this._outOffset : this._offset;
|
|
7634
|
-
this._buffer = this._buffer || this._outBuffer;
|
|
7635
|
-
if (opts && opts.maxLength != null) this._maxLength = opts.maxLength;
|
|
7636
|
-
}
|
|
7637
|
-
function createInflate(opts) {
|
|
7638
|
-
return new Inflate(opts);
|
|
7639
|
-
}
|
|
7640
|
-
function _close(engine, callback) {
|
|
7641
|
-
if (callback) process.nextTick(callback);
|
|
7642
|
-
if (!engine._handle) return;
|
|
7643
|
-
engine._handle.close();
|
|
7644
|
-
engine._handle = null;
|
|
7645
|
-
}
|
|
7646
|
-
Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
|
|
7647
|
-
if (typeof asyncCb === "function") return zlib$2.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
7648
|
-
let self = this;
|
|
7649
|
-
let availInBefore = chunk && chunk.length;
|
|
7650
|
-
let availOutBefore = this._chunkSize - this._offset;
|
|
7651
|
-
let leftToInflate = this._maxLength;
|
|
7652
|
-
let inOff = 0;
|
|
7653
|
-
let buffers = [];
|
|
7654
|
-
let nread = 0;
|
|
7655
|
-
let error;
|
|
7656
|
-
this.on("error", function(err) {
|
|
7657
|
-
error = err;
|
|
7658
|
-
});
|
|
7659
|
-
function handleChunk(availInAfter, availOutAfter) {
|
|
7660
|
-
if (self._hadError) return;
|
|
7661
|
-
let have = availOutBefore - availOutAfter;
|
|
7662
|
-
assert(have >= 0, "have should not go down");
|
|
7663
|
-
if (have > 0) {
|
|
7664
|
-
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
7665
|
-
self._offset += have;
|
|
7666
|
-
if (out.length > leftToInflate) out = out.slice(0, leftToInflate);
|
|
7667
|
-
buffers.push(out);
|
|
7668
|
-
nread += out.length;
|
|
7669
|
-
leftToInflate -= out.length;
|
|
7670
|
-
if (leftToInflate === 0) return false;
|
|
7671
|
-
}
|
|
7672
|
-
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
7673
|
-
availOutBefore = self._chunkSize;
|
|
7674
|
-
self._offset = 0;
|
|
7675
|
-
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
7676
|
-
}
|
|
7677
|
-
if (availOutAfter === 0) {
|
|
7678
|
-
inOff += availInBefore - availInAfter;
|
|
7679
|
-
availInBefore = availInAfter;
|
|
7680
|
-
return true;
|
|
7681
|
-
}
|
|
7682
|
-
return false;
|
|
7683
|
-
}
|
|
7684
|
-
assert(this._handle, "zlib binding closed");
|
|
7685
|
-
let res;
|
|
7686
|
-
do {
|
|
7687
|
-
res = this._handle.writeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, availOutBefore);
|
|
7688
|
-
res = res || this._writeState;
|
|
7689
|
-
} while (!this._hadError && handleChunk(res[0], res[1]));
|
|
7690
|
-
if (this._hadError) throw error;
|
|
7691
|
-
if (nread >= kMaxLength) {
|
|
7692
|
-
_close(this);
|
|
7693
|
-
throw new RangeError("Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes");
|
|
7694
|
-
}
|
|
7695
|
-
let buf = Buffer.concat(buffers, nread);
|
|
7696
|
-
_close(this);
|
|
7697
|
-
return buf;
|
|
7698
|
-
};
|
|
7699
|
-
util$1.inherits(Inflate, zlib$2.Inflate);
|
|
7700
|
-
function zlibBufferSync(engine, buffer) {
|
|
7701
|
-
if (typeof buffer === "string") buffer = Buffer.from(buffer);
|
|
7702
|
-
if (!(buffer instanceof Buffer)) throw new TypeError("Not a string or buffer");
|
|
7703
|
-
let flushFlag = engine._finishFlushFlag;
|
|
7704
|
-
if (flushFlag == null) flushFlag = zlib$2.Z_FINISH;
|
|
7705
|
-
return engine._processChunk(buffer, flushFlag);
|
|
7706
|
-
}
|
|
7707
|
-
function inflateSync(buffer, opts) {
|
|
7708
|
-
return zlibBufferSync(new Inflate(opts), buffer);
|
|
7709
|
-
}
|
|
7710
|
-
module.exports = exports = inflateSync;
|
|
7711
|
-
exports.Inflate = Inflate;
|
|
7712
|
-
exports.createInflate = createInflate;
|
|
7713
|
-
exports.inflateSync = inflateSync;
|
|
7714
|
-
}));
|
|
7715
|
-
//#endregion
|
|
7716
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-reader.js
|
|
7717
|
-
var require_sync_reader = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7718
|
-
let SyncReader = module.exports = function(buffer) {
|
|
7719
|
-
this._buffer = buffer;
|
|
7720
|
-
this._reads = [];
|
|
7721
|
-
};
|
|
7722
|
-
SyncReader.prototype.read = function(length, callback) {
|
|
7723
|
-
this._reads.push({
|
|
7724
|
-
length: Math.abs(length),
|
|
7725
|
-
allowLess: length < 0,
|
|
7726
|
-
func: callback
|
|
7727
|
-
});
|
|
7728
|
-
};
|
|
7729
|
-
SyncReader.prototype.process = function() {
|
|
7730
|
-
while (this._reads.length > 0 && this._buffer.length) {
|
|
7731
|
-
let read = this._reads[0];
|
|
7732
|
-
if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
|
|
7733
|
-
this._reads.shift();
|
|
7734
|
-
let buf = this._buffer;
|
|
7735
|
-
this._buffer = buf.slice(read.length);
|
|
7736
|
-
read.func.call(this, buf.slice(0, read.length));
|
|
7737
|
-
} else break;
|
|
7738
|
-
}
|
|
7739
|
-
if (this._reads.length > 0) throw new Error("There are some read requests waitng on finished stream");
|
|
7740
|
-
if (this._buffer.length > 0) throw new Error("unrecognised content at end of stream");
|
|
7741
|
-
};
|
|
7742
|
-
}));
|
|
7743
|
-
//#endregion
|
|
7744
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-sync.js
|
|
7745
|
-
var require_filter_parse_sync = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
7746
|
-
let SyncReader = require_sync_reader();
|
|
7747
|
-
let Filter = require_filter_parse();
|
|
7748
|
-
exports.process = function(inBuffer, bitmapInfo) {
|
|
7749
|
-
let outBuffers = [];
|
|
7750
|
-
let reader = new SyncReader(inBuffer);
|
|
7751
|
-
new Filter(bitmapInfo, {
|
|
7752
|
-
read: reader.read.bind(reader),
|
|
7753
|
-
write: function(bufferPart) {
|
|
7754
|
-
outBuffers.push(bufferPart);
|
|
7755
|
-
},
|
|
7756
|
-
complete: function() {}
|
|
7757
|
-
}).start();
|
|
7758
|
-
reader.process();
|
|
7759
|
-
return Buffer.concat(outBuffers);
|
|
7760
|
-
};
|
|
7761
|
-
}));
|
|
7762
|
-
//#endregion
|
|
7763
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-sync.js
|
|
7764
|
-
var require_parser_sync = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7765
|
-
let hasSyncZlib = true;
|
|
7766
|
-
let zlib$1 = __require("zlib");
|
|
7767
|
-
let inflateSync = require_sync_inflate();
|
|
7768
|
-
if (!zlib$1.deflateSync) hasSyncZlib = false;
|
|
7769
|
-
let SyncReader = require_sync_reader();
|
|
7770
|
-
let FilterSync = require_filter_parse_sync();
|
|
7771
|
-
let Parser = require_parser();
|
|
7772
|
-
let bitmapper = require_bitmapper();
|
|
7773
|
-
let formatNormaliser = require_format_normaliser();
|
|
7774
|
-
module.exports = function(buffer, options) {
|
|
7775
|
-
if (!hasSyncZlib) throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
7776
|
-
let err;
|
|
7777
|
-
function handleError(_err_) {
|
|
7778
|
-
err = _err_;
|
|
7779
|
-
}
|
|
7780
|
-
let metaData;
|
|
7781
|
-
function handleMetaData(_metaData_) {
|
|
7782
|
-
metaData = _metaData_;
|
|
7783
|
-
}
|
|
7784
|
-
function handleTransColor(transColor) {
|
|
7785
|
-
metaData.transColor = transColor;
|
|
7786
|
-
}
|
|
7787
|
-
function handlePalette(palette) {
|
|
7788
|
-
metaData.palette = palette;
|
|
7789
|
-
}
|
|
7790
|
-
function handleSimpleTransparency() {
|
|
7791
|
-
metaData.alpha = true;
|
|
7792
|
-
}
|
|
7793
|
-
let gamma;
|
|
7794
|
-
function handleGamma(_gamma_) {
|
|
7795
|
-
gamma = _gamma_;
|
|
7796
|
-
}
|
|
7797
|
-
let inflateDataList = [];
|
|
7798
|
-
function handleInflateData(inflatedData) {
|
|
7799
|
-
inflateDataList.push(inflatedData);
|
|
7800
|
-
}
|
|
7801
|
-
let reader = new SyncReader(buffer);
|
|
7802
|
-
new Parser(options, {
|
|
7803
|
-
read: reader.read.bind(reader),
|
|
7804
|
-
error: handleError,
|
|
7805
|
-
metadata: handleMetaData,
|
|
7806
|
-
gamma: handleGamma,
|
|
7807
|
-
palette: handlePalette,
|
|
7808
|
-
transColor: handleTransColor,
|
|
7809
|
-
inflateData: handleInflateData,
|
|
7810
|
-
simpleTransparency: handleSimpleTransparency
|
|
7811
|
-
}).start();
|
|
7812
|
-
reader.process();
|
|
7813
|
-
if (err) throw err;
|
|
7814
|
-
let inflateData = Buffer.concat(inflateDataList);
|
|
7815
|
-
inflateDataList.length = 0;
|
|
7816
|
-
let inflatedData;
|
|
7817
|
-
if (metaData.interlace) inflatedData = zlib$1.inflateSync(inflateData);
|
|
7818
|
-
else {
|
|
7819
|
-
let imageSize = ((metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1) * metaData.height;
|
|
7820
|
-
inflatedData = inflateSync(inflateData, {
|
|
7821
|
-
chunkSize: imageSize,
|
|
7822
|
-
maxLength: imageSize
|
|
7823
|
-
});
|
|
7824
|
-
}
|
|
7825
|
-
inflateData = null;
|
|
7826
|
-
if (!inflatedData || !inflatedData.length) throw new Error("bad png - invalid inflate data response");
|
|
7827
|
-
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
|
7828
|
-
inflateData = null;
|
|
7829
|
-
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
|
7830
|
-
unfilteredData = null;
|
|
7831
|
-
let normalisedBitmapData = formatNormaliser(bitmapData, metaData, options.skipRescale);
|
|
7832
|
-
metaData.data = normalisedBitmapData;
|
|
7833
|
-
metaData.gamma = gamma || 0;
|
|
7834
|
-
return metaData;
|
|
7835
|
-
};
|
|
7836
|
-
}));
|
|
7837
|
-
//#endregion
|
|
7838
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-sync.js
|
|
7839
|
-
var require_packer_sync = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
7840
|
-
let hasSyncZlib = true;
|
|
7841
|
-
let zlib = __require("zlib");
|
|
7842
|
-
if (!zlib.deflateSync) hasSyncZlib = false;
|
|
7843
|
-
let constants = require_constants();
|
|
7844
|
-
let Packer = require_packer();
|
|
7845
|
-
module.exports = function(metaData, opt) {
|
|
7846
|
-
if (!hasSyncZlib) throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
|
|
7847
|
-
let packer = new Packer(opt || {});
|
|
7848
|
-
let chunks = [];
|
|
7849
|
-
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
|
7850
|
-
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
7851
|
-
if (metaData.gamma) chunks.push(packer.packGAMA(metaData.gamma));
|
|
7852
|
-
let filteredData = packer.filterData(metaData.data, metaData.width, metaData.height);
|
|
7853
|
-
let compressedData = zlib.deflateSync(filteredData, packer.getDeflateOptions());
|
|
7854
|
-
filteredData = null;
|
|
7855
|
-
if (!compressedData || !compressedData.length) throw new Error("bad png - invalid compressed data response");
|
|
7856
|
-
chunks.push(packer.packIDAT(compressedData));
|
|
7857
|
-
chunks.push(packer.packIEND());
|
|
7858
|
-
return Buffer.concat(chunks);
|
|
7859
|
-
};
|
|
7860
|
-
}));
|
|
7861
|
-
//#endregion
|
|
7862
|
-
//#region ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/png-sync.js
|
|
7863
|
-
var require_png_sync = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
7864
|
-
let parse = require_parser_sync();
|
|
7865
|
-
let pack = require_packer_sync();
|
|
7866
|
-
exports.read = function(buffer, options) {
|
|
7867
|
-
return parse(buffer, options || {});
|
|
7868
|
-
};
|
|
7869
|
-
exports.write = function(png, options) {
|
|
7870
|
-
return pack(png, options);
|
|
7871
|
-
};
|
|
7872
|
-
}));
|
|
7873
|
-
//#endregion
|
|
7874
|
-
//#region ../../node_modules/.pnpm/@shockpkg+icon-encoder@3.2.3/node_modules/@shockpkg/icon-encoder/esm/util.mjs
|
|
7875
|
-
var import_png = (/* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
7876
|
-
let util = __require("util");
|
|
7877
|
-
let Stream = __require("stream");
|
|
7878
|
-
let Parser = require_parser_async();
|
|
7879
|
-
let Packer = require_packer_async();
|
|
7880
|
-
let PNGSync = require_png_sync();
|
|
7881
|
-
let PNG = exports.PNG = function(options) {
|
|
7882
|
-
Stream.call(this);
|
|
7883
|
-
options = options || {};
|
|
7884
|
-
this.width = options.width | 0;
|
|
7885
|
-
this.height = options.height | 0;
|
|
7886
|
-
this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
|
|
7887
|
-
if (options.fill && this.data) this.data.fill(0);
|
|
7888
|
-
this.gamma = 0;
|
|
7889
|
-
this.readable = this.writable = true;
|
|
7890
|
-
this._parser = new Parser(options);
|
|
7891
|
-
this._parser.on("error", this.emit.bind(this, "error"));
|
|
7892
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
7893
|
-
this._parser.on("metadata", this._metadata.bind(this));
|
|
7894
|
-
this._parser.on("gamma", this._gamma.bind(this));
|
|
7895
|
-
this._parser.on("parsed", function(data) {
|
|
7896
|
-
this.data = data;
|
|
7897
|
-
this.emit("parsed", data);
|
|
7898
|
-
}.bind(this));
|
|
7899
|
-
this._packer = new Packer(options);
|
|
7900
|
-
this._packer.on("data", this.emit.bind(this, "data"));
|
|
7901
|
-
this._packer.on("end", this.emit.bind(this, "end"));
|
|
7902
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
7903
|
-
this._packer.on("error", this.emit.bind(this, "error"));
|
|
7904
|
-
};
|
|
7905
|
-
util.inherits(PNG, Stream);
|
|
7906
|
-
PNG.sync = PNGSync;
|
|
7907
|
-
PNG.prototype.pack = function() {
|
|
7908
|
-
if (!this.data || !this.data.length) {
|
|
7909
|
-
this.emit("error", "No data provided");
|
|
7910
|
-
return this;
|
|
7911
|
-
}
|
|
7912
|
-
process.nextTick(function() {
|
|
7913
|
-
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
|
7914
|
-
}.bind(this));
|
|
7915
|
-
return this;
|
|
7916
|
-
};
|
|
7917
|
-
PNG.prototype.parse = function(data, callback) {
|
|
7918
|
-
if (callback) {
|
|
7919
|
-
let onParsed, onError;
|
|
7920
|
-
onParsed = function(parsedData) {
|
|
7921
|
-
this.removeListener("error", onError);
|
|
7922
|
-
this.data = parsedData;
|
|
7923
|
-
callback(null, this);
|
|
7924
|
-
}.bind(this);
|
|
7925
|
-
onError = function(err) {
|
|
7926
|
-
this.removeListener("parsed", onParsed);
|
|
7927
|
-
callback(err, null);
|
|
7928
|
-
}.bind(this);
|
|
7929
|
-
this.once("parsed", onParsed);
|
|
7930
|
-
this.once("error", onError);
|
|
7931
|
-
}
|
|
7932
|
-
this.end(data);
|
|
7933
|
-
return this;
|
|
7934
|
-
};
|
|
7935
|
-
PNG.prototype.write = function(data) {
|
|
7936
|
-
this._parser.write(data);
|
|
7937
|
-
return true;
|
|
7938
|
-
};
|
|
7939
|
-
PNG.prototype.end = function(data) {
|
|
7940
|
-
this._parser.end(data);
|
|
7941
|
-
};
|
|
7942
|
-
PNG.prototype._metadata = function(metadata) {
|
|
7943
|
-
this.width = metadata.width;
|
|
7944
|
-
this.height = metadata.height;
|
|
7945
|
-
this.emit("metadata", metadata);
|
|
7946
|
-
};
|
|
7947
|
-
PNG.prototype._gamma = function(gamma) {
|
|
7948
|
-
this.gamma = gamma;
|
|
7949
|
-
};
|
|
7950
|
-
PNG.prototype._handleClose = function() {
|
|
7951
|
-
if (!this._parser.writable && !this._packer.readable) this.emit("close");
|
|
7952
|
-
};
|
|
7953
|
-
PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
7954
|
-
srcX |= 0;
|
|
7955
|
-
srcY |= 0;
|
|
7956
|
-
width |= 0;
|
|
7957
|
-
height |= 0;
|
|
7958
|
-
deltaX |= 0;
|
|
7959
|
-
deltaY |= 0;
|
|
7960
|
-
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) throw new Error("bitblt reading outside image");
|
|
7961
|
-
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) throw new Error("bitblt writing outside image");
|
|
7962
|
-
for (let y = 0; y < height; y++) src.data.copy(dst.data, (deltaY + y) * dst.width + deltaX << 2, (srcY + y) * src.width + srcX << 2, (srcY + y) * src.width + srcX + width << 2);
|
|
7963
|
-
};
|
|
7964
|
-
PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
7965
|
-
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
|
7966
|
-
return this;
|
|
7967
|
-
};
|
|
7968
|
-
PNG.adjustGamma = function(src) {
|
|
7969
|
-
if (src.gamma) {
|
|
7970
|
-
for (let y = 0; y < src.height; y++) for (let x = 0; x < src.width; x++) {
|
|
7971
|
-
let idx = src.width * y + x << 2;
|
|
7972
|
-
for (let i = 0; i < 3; i++) {
|
|
7973
|
-
let sample = src.data[idx + i] / 255;
|
|
7974
|
-
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
|
7975
|
-
src.data[idx + i] = Math.round(sample * 255);
|
|
7976
|
-
}
|
|
7977
|
-
}
|
|
7978
|
-
src.gamma = 0;
|
|
7979
|
-
}
|
|
7980
|
-
};
|
|
7981
|
-
PNG.prototype.adjustGamma = function() {
|
|
7982
|
-
PNG.adjustGamma(this);
|
|
7983
|
-
};
|
|
7984
|
-
})))();
|
|
7985
|
-
const PNG_MAGIC = [
|
|
7986
|
-
137,
|
|
7987
|
-
80,
|
|
7988
|
-
78,
|
|
7989
|
-
71,
|
|
7990
|
-
13,
|
|
7991
|
-
10,
|
|
7992
|
-
26,
|
|
7993
|
-
10
|
|
7994
|
-
];
|
|
7995
|
-
const PNG_MAGIC_SIZE = 8;
|
|
7996
|
-
const IHDR = 1229472850;
|
|
7997
|
-
const SRGB = 1934772034;
|
|
7998
|
-
const IDAT = 1229209940;
|
|
7999
|
-
const IEND = 1229278788;
|
|
8000
|
-
const CRC32_TABLE = [];
|
|
8001
|
-
/**
|
|
8002
|
-
* Hash data with CRC32.
|
|
8003
|
-
*
|
|
8004
|
-
* @param data Data to be hashed.
|
|
8005
|
-
* @returns Data hash.
|
|
8006
|
-
*/
|
|
8007
|
-
function crc32$1(data) {
|
|
8008
|
-
if (!CRC32_TABLE.length) for (let i = 256; i--;) {
|
|
8009
|
-
let c = i;
|
|
8010
|
-
for (let j = 0; j < 8; j++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
8011
|
-
CRC32_TABLE[i] = c;
|
|
8012
|
-
}
|
|
8013
|
-
let r = -1;
|
|
8014
|
-
const l = data.length;
|
|
8015
|
-
for (let i = 0; i < l;) r = CRC32_TABLE[(r ^ data[i++]) & 255] ^ r >>> 8;
|
|
8016
|
-
return r ^ -1;
|
|
8017
|
-
}
|
|
8018
|
-
/**
|
|
8019
|
-
* Concatenate multiple Uint8Array together.
|
|
8020
|
-
*
|
|
8021
|
-
* @param arrays Uint8Array arrays.
|
|
8022
|
-
* @returns Uint8Array array.
|
|
8023
|
-
*/
|
|
8024
|
-
function concatUint8Arrays(arrays) {
|
|
8025
|
-
let l = 0;
|
|
8026
|
-
for (const a of arrays) l += a.length;
|
|
8027
|
-
const r = new Uint8Array(l);
|
|
8028
|
-
let i = 0;
|
|
8029
|
-
for (const a of arrays) {
|
|
8030
|
-
r.set(a, i);
|
|
8031
|
-
i += a.length;
|
|
8032
|
-
}
|
|
8033
|
-
return r;
|
|
8034
|
-
}
|
|
8035
|
-
/**
|
|
8036
|
-
* Decode PNG data to RGBA image.
|
|
8037
|
-
*
|
|
8038
|
-
* @param data PNG data.
|
|
8039
|
-
* @returns Image data.
|
|
8040
|
-
*/
|
|
8041
|
-
async function decodePngToRgba(data) {
|
|
8042
|
-
const png = new import_png.PNG();
|
|
8043
|
-
await new Promise((resolve, reject) => {
|
|
8044
|
-
png.parse(Buffer.from(data.buffer, data.byteOffset, data.byteLength), (err) => {
|
|
8045
|
-
if (err) {
|
|
8046
|
-
reject(err);
|
|
8047
|
-
return;
|
|
8048
|
-
}
|
|
8049
|
-
resolve(png);
|
|
8050
|
-
});
|
|
8051
|
-
});
|
|
8052
|
-
const { width, height, data: d } = png;
|
|
8053
|
-
return {
|
|
8054
|
-
width,
|
|
8055
|
-
height,
|
|
8056
|
-
data: new Uint8Array(d.buffer, d.byteOffset, d.byteLength)
|
|
8057
|
-
};
|
|
8058
|
-
}
|
|
8059
|
-
/**
|
|
8060
|
-
* Encode RGBA image to PNG data.
|
|
8061
|
-
*
|
|
8062
|
-
* @param imageData Image data.
|
|
8063
|
-
* @param srgb SRGB mode.
|
|
8064
|
-
* @returns PNG data.
|
|
8065
|
-
*/
|
|
8066
|
-
async function encodeRgbaToPng(imageData, srgb = null) {
|
|
8067
|
-
const { width, height, data } = imageData;
|
|
8068
|
-
const png = new import_png.PNG({
|
|
8069
|
-
width,
|
|
8070
|
-
height,
|
|
8071
|
-
deflateLevel: 9,
|
|
8072
|
-
deflateStrategy: 1,
|
|
8073
|
-
deflateChunkSize: 32 * 1024
|
|
8074
|
-
});
|
|
8075
|
-
png.data = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
8076
|
-
const packed = [];
|
|
8077
|
-
await new Promise((resolve, reject) => {
|
|
8078
|
-
png.on("data", (d) => {
|
|
8079
|
-
packed.push(d);
|
|
8080
|
-
});
|
|
8081
|
-
png.on("error", reject);
|
|
8082
|
-
png.on("end", resolve);
|
|
8083
|
-
png.pack();
|
|
8084
|
-
});
|
|
8085
|
-
return pngRepack(concatUint8Arrays(packed), srgb);
|
|
8086
|
-
}
|
|
8087
|
-
/**
|
|
8088
|
-
* Read PNG file tags.
|
|
8089
|
-
*
|
|
8090
|
-
* @param data PNG data.
|
|
8091
|
-
* @yields PNG tags.
|
|
8092
|
-
*/
|
|
8093
|
-
function* pngReader(data) {
|
|
8094
|
-
let i = 0;
|
|
8095
|
-
for (; i < PNG_MAGIC_SIZE; i++) if (data[i] !== PNG_MAGIC[i]) throw new Error("Invalid PNG header signature");
|
|
8096
|
-
const dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
8097
|
-
while (i < data.length) {
|
|
8098
|
-
const size = dv.getUint32(i, false);
|
|
8099
|
-
i += 4;
|
|
8100
|
-
const tag = dv.getUint32(i, false);
|
|
8101
|
-
i += 4;
|
|
8102
|
-
const d = data.subarray(i, i + size);
|
|
8103
|
-
i += size;
|
|
8104
|
-
yield [
|
|
8105
|
-
tag,
|
|
8106
|
-
d,
|
|
8107
|
-
dv.getUint32(i, false)
|
|
8108
|
-
];
|
|
8109
|
-
i += 4;
|
|
8110
|
-
}
|
|
8111
|
-
}
|
|
8112
|
-
/**
|
|
8113
|
-
* Encode PNG from tags.
|
|
8114
|
-
*
|
|
8115
|
-
* @param tags PNG tags and data.
|
|
8116
|
-
* @returns PNG data.
|
|
8117
|
-
*/
|
|
8118
|
-
function pngEncode(tags) {
|
|
8119
|
-
let total = PNG_MAGIC_SIZE;
|
|
8120
|
-
for (const [, data] of tags) total += 12 + data.length;
|
|
8121
|
-
const r = new Uint8Array(total);
|
|
8122
|
-
const d = new DataView(r.buffer, r.byteOffset, r.byteLength);
|
|
8123
|
-
r.set(PNG_MAGIC);
|
|
8124
|
-
let i = PNG_MAGIC_SIZE;
|
|
8125
|
-
for (const [tag, data] of tags) {
|
|
8126
|
-
const l = data.length;
|
|
8127
|
-
d.setUint32(i, l, false);
|
|
8128
|
-
i += 4;
|
|
8129
|
-
const f = i;
|
|
8130
|
-
d.setUint32(i, tag, false);
|
|
8131
|
-
i += 4;
|
|
8132
|
-
r.set(data, i);
|
|
8133
|
-
i += l;
|
|
8134
|
-
d.setUint32(i, crc32$1(r.subarray(f, i)), false);
|
|
8135
|
-
i += 4;
|
|
8136
|
-
}
|
|
8137
|
-
return r;
|
|
8138
|
-
}
|
|
8139
|
-
/**
|
|
8140
|
-
* Repack PNG tag data with a single IDAT.
|
|
8141
|
-
*
|
|
8142
|
-
* @param data PNG data.
|
|
8143
|
-
* @param srgb Set an SRGB value.
|
|
8144
|
-
* @returns PNG data.
|
|
8145
|
-
*/
|
|
8146
|
-
function pngRepack(data, srgb = null) {
|
|
8147
|
-
let ihdr = null;
|
|
8148
|
-
let iend = null;
|
|
8149
|
-
const idats = [];
|
|
8150
|
-
for (const [tag, d] of pngReader(data)) switch (tag) {
|
|
8151
|
-
case IDAT:
|
|
8152
|
-
idats.push(d);
|
|
8153
|
-
break;
|
|
8154
|
-
case IHDR:
|
|
8155
|
-
ihdr = d;
|
|
8156
|
-
break;
|
|
8157
|
-
case IEND:
|
|
8158
|
-
iend = d;
|
|
8159
|
-
break;
|
|
8160
|
-
default:
|
|
8161
|
-
}
|
|
8162
|
-
if (!ihdr || !iend) throw new Error("Invalid PNG");
|
|
8163
|
-
const pieces = [[IHDR, ihdr]];
|
|
8164
|
-
if (srgb !== null) pieces.push([SRGB, new Uint8Array([srgb])]);
|
|
8165
|
-
pieces.push([IDAT, concatUint8Arrays(idats)], [IEND, iend]);
|
|
8166
|
-
return pngEncode(pieces);
|
|
8167
|
-
}
|
|
8168
|
-
/**
|
|
8169
|
-
* Read PNG IHDR data.
|
|
8170
|
-
*
|
|
8171
|
-
* @param data PNG data.
|
|
8172
|
-
* @returns PNG IHDR.
|
|
8173
|
-
*/
|
|
8174
|
-
function pngIhdr(data) {
|
|
8175
|
-
for (const [tag, td] of pngReader(data)) if (tag === IHDR) {
|
|
8176
|
-
const d = new DataView(td.buffer, td.byteOffset, td.byteLength);
|
|
8177
|
-
return {
|
|
8178
|
-
width: d.getUint32(0, false),
|
|
8179
|
-
height: d.getUint32(4, false),
|
|
8180
|
-
bitDepth: d.getUint8(8),
|
|
8181
|
-
colorType: d.getUint8(9),
|
|
8182
|
-
compressionMethod: d.getUint8(10),
|
|
8183
|
-
filterMethod: d.getUint8(11),
|
|
8184
|
-
interlacemethod: d.getUint8(12)
|
|
8185
|
-
};
|
|
8186
|
-
}
|
|
8187
|
-
throw new Error("Missing PNG IHDR tag");
|
|
8188
|
-
}
|
|
8189
|
-
/**
|
|
8190
|
-
* Encode data using PackBits ICNS compression.
|
|
8191
|
-
*
|
|
8192
|
-
* @param data Data to be compressed.
|
|
8193
|
-
* @returns Compressed data.
|
|
8194
|
-
*/
|
|
8195
|
-
function packBitsIcns(data) {
|
|
8196
|
-
const chunks = [];
|
|
8197
|
-
const l = data.length;
|
|
8198
|
-
for (let i = 0; i < l;) {
|
|
8199
|
-
const b = data[i];
|
|
8200
|
-
if (i + 2 >= l) {
|
|
8201
|
-
chunks.push(new Uint8Array([l - i - 1]), data.subarray(i, l));
|
|
8202
|
-
break;
|
|
8203
|
-
}
|
|
8204
|
-
if (b === data[i + 1] && b === data[i + 2]) {
|
|
8205
|
-
i += 2;
|
|
8206
|
-
let c = 3;
|
|
8207
|
-
for (; ++i < l && b === data[i] && c < 130; c++);
|
|
8208
|
-
chunks.push(new Uint8Array([c + 125, b]));
|
|
8209
|
-
} else {
|
|
8210
|
-
let e = i + 2;
|
|
8211
|
-
let c = 3;
|
|
8212
|
-
for (let r = 1, p = data[e]; ++e < l && c < 128; c++) {
|
|
8213
|
-
const b = data[e];
|
|
8214
|
-
if (p !== b) {
|
|
8215
|
-
p = b;
|
|
8216
|
-
r = 1;
|
|
8217
|
-
} else if (++r > 2) {
|
|
8218
|
-
e -= 2;
|
|
8219
|
-
c -= 2;
|
|
8220
|
-
break;
|
|
8221
|
-
}
|
|
8222
|
-
}
|
|
8223
|
-
chunks.push(new Uint8Array([c - 1]), data.subarray(i, e));
|
|
8224
|
-
i = e;
|
|
8225
|
-
}
|
|
8226
|
-
}
|
|
8227
|
-
return concatUint8Arrays(chunks);
|
|
8228
|
-
}
|
|
8229
|
-
//#endregion
|
|
8230
|
-
//#region ../../node_modules/.pnpm/@shockpkg+icon-encoder@3.2.3/node_modules/@shockpkg/icon-encoder/esm/icon.mjs
|
|
8231
|
-
/**
|
|
8232
|
-
* Icon object.
|
|
8233
|
-
*/
|
|
8234
|
-
var Icon = class {
|
|
8235
|
-
/**
|
|
8236
|
-
* Icon constructor.
|
|
8237
|
-
*/
|
|
8238
|
-
constructor() {}
|
|
8239
|
-
/**
|
|
8240
|
-
* Decode PNG data to RGBA image.
|
|
8241
|
-
*
|
|
8242
|
-
* @param data PNG data.
|
|
8243
|
-
* @returns Image data.
|
|
8244
|
-
*/
|
|
8245
|
-
async _decodePngToRgba(data) {
|
|
8246
|
-
return decodePngToRgba(data);
|
|
8247
|
-
}
|
|
8248
|
-
/**
|
|
8249
|
-
* Encode RGBA image to PNG data.
|
|
8250
|
-
*
|
|
8251
|
-
* @param imageData Image data.
|
|
8252
|
-
* @param srgb SRGB mode.
|
|
8253
|
-
* @returns PNG data.
|
|
8254
|
-
*/
|
|
8255
|
-
async _encodeRgbaToPng(imageData, srgb = null) {
|
|
8256
|
-
return encodeRgbaToPng(imageData, srgb);
|
|
8257
|
-
}
|
|
8258
|
-
};
|
|
8259
|
-
//#endregion
|
|
8260
|
-
//#region ../../node_modules/.pnpm/@shockpkg+icon-encoder@3.2.3/node_modules/@shockpkg/icon-encoder/esm/icon/icns.mjs
|
|
8261
|
-
const typePng = [
|
|
8262
|
-
"icp4",
|
|
8263
|
-
"icp5",
|
|
8264
|
-
"icp6",
|
|
8265
|
-
"ic07",
|
|
8266
|
-
"ic08",
|
|
8267
|
-
"ic09",
|
|
8268
|
-
"ic10",
|
|
8269
|
-
"ic11",
|
|
8270
|
-
"ic12",
|
|
8271
|
-
"ic13",
|
|
8272
|
-
"ic14"
|
|
8273
|
-
];
|
|
8274
|
-
const typeArgb = ["ic04", "ic05"];
|
|
8275
|
-
const typeIcon24Bit = [
|
|
8276
|
-
"is32",
|
|
8277
|
-
"il32",
|
|
8278
|
-
"ih32",
|
|
8279
|
-
"it32"
|
|
8280
|
-
];
|
|
8281
|
-
const typeMask8Bit = [
|
|
8282
|
-
"s8mk",
|
|
8283
|
-
"l8mk",
|
|
8284
|
-
"h8mk",
|
|
8285
|
-
"t8mk"
|
|
8286
|
-
];
|
|
8287
|
-
/**
|
|
8288
|
-
* Icon entry.
|
|
8289
|
-
*/
|
|
8290
|
-
/**
|
|
8291
|
-
* IconIcns object.
|
|
8292
|
-
*/
|
|
8293
|
-
var IconIcns = class extends Icon {
|
|
8294
|
-
/**
|
|
8295
|
-
* Option to include TOC tag (table of contents) in encode.
|
|
8296
|
-
*/
|
|
8297
|
-
toc = false;
|
|
8298
|
-
/**
|
|
8299
|
-
* List of icon entries.
|
|
8300
|
-
*/
|
|
8301
|
-
entries = [];
|
|
8302
|
-
/**
|
|
8303
|
-
* Types that are ARGB.
|
|
8304
|
-
*/
|
|
8305
|
-
_typeArgb = new Set(typeArgb);
|
|
8306
|
-
/**
|
|
8307
|
-
* Types that are PNG.
|
|
8308
|
-
*/
|
|
8309
|
-
_typePng = new Set(typePng);
|
|
8310
|
-
/**
|
|
8311
|
-
* Types that are icon 24-bit.
|
|
8312
|
-
*/
|
|
8313
|
-
_typeIcon24Bit = new Set(typeIcon24Bit);
|
|
8314
|
-
/**
|
|
8315
|
-
* Types that are mask 8-bit.
|
|
8316
|
-
*/
|
|
8317
|
-
_typeMask8Bit = new Set(typeMask8Bit);
|
|
8318
|
-
/**
|
|
8319
|
-
* IconIcns constructor.
|
|
8320
|
-
*/
|
|
8321
|
-
constructor() {
|
|
8322
|
-
super();
|
|
8323
|
-
}
|
|
8324
|
-
/**
|
|
8325
|
-
* Add an icon from PNG data.
|
|
8326
|
-
*
|
|
8327
|
-
* @param data PNG data.
|
|
8328
|
-
* @param types Types to encode as.
|
|
8329
|
-
* @param raw Use raw PNG data without re-encoding for the PNG types.
|
|
8330
|
-
*/
|
|
8331
|
-
async addFromPng(data, types, raw = false) {
|
|
8332
|
-
if (!raw) {
|
|
8333
|
-
await this.addFromRgba(await this._decodePngToRgba(data), types);
|
|
8334
|
-
return;
|
|
8335
|
-
}
|
|
8336
|
-
let rgba = null;
|
|
8337
|
-
for (const type of types) {
|
|
8338
|
-
if (this._typePng.has(type)) {
|
|
8339
|
-
this.entries.push({
|
|
8340
|
-
type,
|
|
8341
|
-
data: new Uint8Array(data)
|
|
8342
|
-
});
|
|
8343
|
-
continue;
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
break;
|
|
8344
6043
|
}
|
|
8345
|
-
rgba ||= await this._decodePngToRgba(data);
|
|
8346
|
-
await this.addFromRgba(rgba, [type]);
|
|
8347
6044
|
}
|
|
8348
6045
|
}
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
addDarkIcns(data) {
|
|
8376
|
-
const { length } = data;
|
|
8377
|
-
if (length < 8 || data[0] !== 105 || data[1] !== 99 || data[2] !== 110 || data[3] !== 115 || new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(4) !== length) throw new Error("Invalid icns header data");
|
|
8378
|
-
const body = new Uint8Array(length - 8);
|
|
8379
|
-
body.set(data.subarray(8));
|
|
8380
|
-
this.entries.push({
|
|
8381
|
-
type: "ýÙ/¨",
|
|
8382
|
-
data: body
|
|
8383
|
-
});
|
|
8384
|
-
}
|
|
8385
|
-
/**
|
|
8386
|
-
* Encode icon.
|
|
8387
|
-
*
|
|
8388
|
-
* @returns Encoded icon.
|
|
8389
|
-
*/
|
|
8390
|
-
encode() {
|
|
8391
|
-
const { toc } = this;
|
|
8392
|
-
const headName = new Uint8Array([
|
|
8393
|
-
105,
|
|
8394
|
-
99,
|
|
8395
|
-
110,
|
|
8396
|
-
115
|
|
8397
|
-
]);
|
|
8398
|
-
const headSize = /* @__PURE__ */ new Uint8Array(4);
|
|
8399
|
-
let sized = 8;
|
|
8400
|
-
let tocSized = 8;
|
|
8401
|
-
const tocs = toc ? [new Uint8Array([
|
|
8402
|
-
84,
|
|
8403
|
-
79,
|
|
8404
|
-
67,
|
|
8405
|
-
32
|
|
8406
|
-
]), /* @__PURE__ */ new Uint8Array(4)] : null;
|
|
8407
|
-
const imgs = [];
|
|
8408
|
-
for (const { type, data } of this.entries) {
|
|
8409
|
-
const imgName = /* @__PURE__ */ new Uint8Array(4);
|
|
8410
|
-
for (let i = 0; i < 4; i++) imgName[i] = type.charCodeAt(i) || 0;
|
|
8411
|
-
const imgSize = /* @__PURE__ */ new Uint8Array(4);
|
|
8412
|
-
const imgSized = data.length + 8;
|
|
8413
|
-
new DataView(imgSize.buffer, imgSize.byteOffset, imgSize.byteLength).setUint32(0, imgSized, false);
|
|
8414
|
-
if (tocs) {
|
|
8415
|
-
tocs.push(imgName, imgSize);
|
|
8416
|
-
tocSized += 8;
|
|
8417
|
-
sized += 8;
|
|
6046
|
+
return stack;
|
|
6047
|
+
}
|
|
6048
|
+
/**
|
|
6049
|
+
* Parses HTML and returns a root element
|
|
6050
|
+
* Parse a chuck of HTML source.
|
|
6051
|
+
*/
|
|
6052
|
+
function parse$1(data, options = {}) {
|
|
6053
|
+
const stack = base_parse(data, options);
|
|
6054
|
+
const [root] = stack;
|
|
6055
|
+
while (stack.length > 1) {
|
|
6056
|
+
const last = stack.pop();
|
|
6057
|
+
const oneBefore = arr_back(stack);
|
|
6058
|
+
if (last.parentNode && last.parentNode.parentNode) {
|
|
6059
|
+
if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {
|
|
6060
|
+
if (options.parseNoneClosedTags !== true) {
|
|
6061
|
+
oneBefore.removeChild(last);
|
|
6062
|
+
last.childNodes.forEach((child) => {
|
|
6063
|
+
oneBefore.parentNode.appendChild(child);
|
|
6064
|
+
});
|
|
6065
|
+
stack.pop();
|
|
6066
|
+
}
|
|
6067
|
+
} else if (options.parseNoneClosedTags !== true) {
|
|
6068
|
+
oneBefore.removeChild(last);
|
|
6069
|
+
last.childNodes.forEach((child) => {
|
|
6070
|
+
oneBefore.appendChild(child);
|
|
6071
|
+
});
|
|
8418
6072
|
}
|
|
8419
|
-
imgs.push(imgName, imgSize, data);
|
|
8420
|
-
sized += imgSized;
|
|
8421
|
-
}
|
|
8422
|
-
if (tocs) {
|
|
8423
|
-
const [, tocSize] = tocs;
|
|
8424
|
-
new DataView(tocSize.buffer, tocSize.byteOffset, tocSize.byteLength).setUint32(0, tocSized, false);
|
|
8425
|
-
sized += 8;
|
|
8426
|
-
}
|
|
8427
|
-
new DataView(headSize.buffer, headSize.byteOffset, headSize.byteLength).setUint32(0, sized, false);
|
|
8428
|
-
return concatUint8Arrays([
|
|
8429
|
-
headName,
|
|
8430
|
-
headSize,
|
|
8431
|
-
...tocs || [],
|
|
8432
|
-
...imgs
|
|
8433
|
-
]);
|
|
8434
|
-
}
|
|
8435
|
-
/**
|
|
8436
|
-
* Add an icon from RGBA image data, individual type.
|
|
8437
|
-
*
|
|
8438
|
-
* @param imageData RGBA image data.
|
|
8439
|
-
* @param type Type to encode as.
|
|
8440
|
-
*/
|
|
8441
|
-
async _addFromRgbaType(imageData, type) {
|
|
8442
|
-
if (this._typePng.has(type)) {
|
|
8443
|
-
this.entries.push({
|
|
8444
|
-
type,
|
|
8445
|
-
data: await this._encodeRgbaToTypePng(imageData, type)
|
|
8446
|
-
});
|
|
8447
|
-
return;
|
|
8448
|
-
}
|
|
8449
|
-
if (this._typeArgb.has(type)) {
|
|
8450
|
-
this.entries.push({
|
|
8451
|
-
type,
|
|
8452
|
-
data: this._encodeRgbaToTypeArgb(imageData, type)
|
|
8453
|
-
});
|
|
8454
|
-
return;
|
|
8455
|
-
}
|
|
8456
|
-
if (this._typeIcon24Bit.has(type)) {
|
|
8457
|
-
this.entries.push({
|
|
8458
|
-
type,
|
|
8459
|
-
data: this._encodeRgbaToTypeIcon24Bit(imageData, type)
|
|
8460
|
-
});
|
|
8461
|
-
return;
|
|
8462
|
-
}
|
|
8463
|
-
if (this._typeMask8Bit.has(type)) {
|
|
8464
|
-
this.entries.push({
|
|
8465
|
-
type,
|
|
8466
|
-
data: this._encodeRgbaToTypeMask8Bit(imageData, type)
|
|
8467
|
-
});
|
|
8468
|
-
return;
|
|
8469
6073
|
}
|
|
8470
|
-
throw new Error(`Unknown type: ${type}`);
|
|
8471
|
-
}
|
|
8472
|
-
/**
|
|
8473
|
-
* Encode RGBA image data to PNG.
|
|
8474
|
-
*
|
|
8475
|
-
* @param imageData RGBA image data.
|
|
8476
|
-
* @param _type Icon type.
|
|
8477
|
-
* @returns Encoded data.
|
|
8478
|
-
*/
|
|
8479
|
-
async _encodeRgbaToTypePng(imageData, _type) {
|
|
8480
|
-
return this._encodeRgbaToPng(imageData, 0);
|
|
8481
|
-
}
|
|
8482
|
-
/**
|
|
8483
|
-
* Encode RGBA image data to ARGB.
|
|
8484
|
-
*
|
|
8485
|
-
* @param imageData RGBA image data.
|
|
8486
|
-
* @param _type Icon type.
|
|
8487
|
-
* @returns Encoded data.
|
|
8488
|
-
*/
|
|
8489
|
-
_encodeRgbaToTypeArgb(imageData, _type) {
|
|
8490
|
-
return this._encodeRgbaToPackBits(imageData, true, new Uint8Array([
|
|
8491
|
-
65,
|
|
8492
|
-
82,
|
|
8493
|
-
71,
|
|
8494
|
-
66
|
|
8495
|
-
]));
|
|
8496
|
-
}
|
|
8497
|
-
/**
|
|
8498
|
-
* Encode RGBA image data to icon 24-bit.
|
|
8499
|
-
*
|
|
8500
|
-
* @param imageData RGBA image data.
|
|
8501
|
-
* @param type Icon type.
|
|
8502
|
-
* @returns Encoded data.
|
|
8503
|
-
*/
|
|
8504
|
-
_encodeRgbaToTypeIcon24Bit(imageData, type) {
|
|
8505
|
-
return this._encodeRgbaToPackBits(imageData, false, type === "it32" ? /* @__PURE__ */ new Uint8Array(4) : null);
|
|
8506
|
-
}
|
|
8507
|
-
/**
|
|
8508
|
-
* Encode RGBA image data to mask 8-bit.
|
|
8509
|
-
*
|
|
8510
|
-
* @param imageData RGBA image data.
|
|
8511
|
-
* @param _type Icon type.
|
|
8512
|
-
* @returns Encoded data.
|
|
8513
|
-
*/
|
|
8514
|
-
_encodeRgbaToTypeMask8Bit(imageData, _type) {
|
|
8515
|
-
return this._encodeRgbaChannel(imageData, 3);
|
|
8516
|
-
}
|
|
8517
|
-
/**
|
|
8518
|
-
* Encode RGBA image data to packbits.
|
|
8519
|
-
*
|
|
8520
|
-
* @param imageData RGBA image data.
|
|
8521
|
-
* @param alpha Incldue the alpha channel.
|
|
8522
|
-
* @param header Header to prepend to the output.
|
|
8523
|
-
* @returns Encoded data.
|
|
8524
|
-
*/
|
|
8525
|
-
_encodeRgbaToPackBits(imageData, alpha, header = null) {
|
|
8526
|
-
const pieces = header ? [header] : [];
|
|
8527
|
-
if (alpha) pieces.push(this._encodePackBitsIcns(this._encodeRgbaChannel(imageData, 3)));
|
|
8528
|
-
pieces.push(this._encodePackBitsIcns(this._encodeRgbaChannel(imageData, 0)), this._encodePackBitsIcns(this._encodeRgbaChannel(imageData, 1)), this._encodePackBitsIcns(this._encodeRgbaChannel(imageData, 2)));
|
|
8529
|
-
return concatUint8Arrays(pieces);
|
|
8530
|
-
}
|
|
8531
|
-
/**
|
|
8532
|
-
* Encode channel from RGBA image data.
|
|
8533
|
-
*
|
|
8534
|
-
* @param imageData RGBA image data.
|
|
8535
|
-
* @param index Channel index (R=0, B=1, G=2, A=3).
|
|
8536
|
-
* @returns Encoded data.
|
|
8537
|
-
*/
|
|
8538
|
-
_encodeRgbaChannel(imageData, index) {
|
|
8539
|
-
const { data } = imageData;
|
|
8540
|
-
const size = data.length;
|
|
8541
|
-
const encoded = new Uint8Array(size / 4);
|
|
8542
|
-
for (let i = index, j = 0; i < size; i += 4) encoded[j++] = data[i];
|
|
8543
|
-
return encoded;
|
|
8544
|
-
}
|
|
8545
|
-
/**
|
|
8546
|
-
* Encode data using PackBits ICNS compression.
|
|
8547
|
-
*
|
|
8548
|
-
* @param data Data to be compressed.
|
|
8549
|
-
* @returns Compressed data.
|
|
8550
|
-
*/
|
|
8551
|
-
_encodePackBitsIcns(data) {
|
|
8552
|
-
return packBitsIcns(data);
|
|
8553
6074
|
}
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
//#region ../../node_modules/.pnpm/@shockpkg+icon-encoder@3.2.3/node_modules/@shockpkg/icon-encoder/esm/icon/ico.mjs
|
|
6075
|
+
return root;
|
|
6076
|
+
}
|
|
8557
6077
|
/**
|
|
8558
|
-
*
|
|
6078
|
+
* Resolves a list of {@link NodeInsertable} to a list of nodes,
|
|
6079
|
+
* and removes nodes from any potential parent.
|
|
8559
6080
|
*/
|
|
6081
|
+
function resolveInsertable(insertable) {
|
|
6082
|
+
return insertable.map((val) => {
|
|
6083
|
+
if (typeof val === "string") return new TextNode(val);
|
|
6084
|
+
val.remove();
|
|
6085
|
+
return val;
|
|
6086
|
+
});
|
|
6087
|
+
}
|
|
6088
|
+
function resetParent(nodes, parent) {
|
|
6089
|
+
return nodes.map((node) => {
|
|
6090
|
+
node.parentNode = parent;
|
|
6091
|
+
return node;
|
|
6092
|
+
});
|
|
6093
|
+
}
|
|
8560
6094
|
/**
|
|
8561
|
-
*
|
|
6095
|
+
* Parses HTML and returns a root element
|
|
6096
|
+
* Parse a chuck of HTML source.
|
|
8562
6097
|
*/
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
* @param data PNG data.
|
|
8578
|
-
* @param png Encode entry as PNG.
|
|
8579
|
-
* @param raw Use raw PNG data without re-encoding, if using PNG format.
|
|
8580
|
-
*/
|
|
8581
|
-
async addFromPng(data, png = null, raw = false) {
|
|
8582
|
-
if (raw && png !== false) {
|
|
8583
|
-
const ihdr = pngIhdr(data);
|
|
8584
|
-
if (png || !this.sizeRequiresLegacyBitmap(ihdr.width, ihdr.height)) {
|
|
8585
|
-
this.entries.push({
|
|
8586
|
-
width: ihdr.width,
|
|
8587
|
-
height: ihdr.height,
|
|
8588
|
-
data: new Uint8Array(data)
|
|
8589
|
-
});
|
|
8590
|
-
return;
|
|
8591
|
-
}
|
|
8592
|
-
}
|
|
8593
|
-
await this.addFromRgba(await this._decodePngToRgba(data), png);
|
|
8594
|
-
}
|
|
8595
|
-
/**
|
|
8596
|
-
* Add an icon from RGBA image data.
|
|
8597
|
-
*
|
|
8598
|
-
* @param imageData RGBA image data.
|
|
8599
|
-
* @param png Encode entry as PNG.
|
|
8600
|
-
*/
|
|
8601
|
-
async addFromRgba(imageData, png = null) {
|
|
8602
|
-
const isPng = png || png === null && !this.sizeRequiresLegacyBitmap(imageData.width, imageData.height);
|
|
8603
|
-
this.entries.push({
|
|
8604
|
-
width: imageData.width,
|
|
8605
|
-
height: imageData.height,
|
|
8606
|
-
data: isPng ? await this._encodeRgbaToPng(imageData, 0) : this._encodeRgbaToBmp(imageData)
|
|
8607
|
-
});
|
|
8608
|
-
}
|
|
8609
|
-
/**
|
|
8610
|
-
* Encode icon.
|
|
8611
|
-
*
|
|
8612
|
-
* @returns Encoded icon.
|
|
8613
|
-
*/
|
|
8614
|
-
encode() {
|
|
8615
|
-
const { entries } = this;
|
|
8616
|
-
const dir = this._encodeIcoDir(entries.length);
|
|
8617
|
-
const dirs = [];
|
|
8618
|
-
const imgs = [];
|
|
8619
|
-
let offset = dir.length + entries.length * 16;
|
|
8620
|
-
for (const entry of entries) {
|
|
8621
|
-
const { data } = entry;
|
|
8622
|
-
const dataSize = data.length;
|
|
8623
|
-
const ent = this._encodeIcoDirEntry(entry, offset);
|
|
8624
|
-
dirs.push(ent);
|
|
8625
|
-
imgs.push(data);
|
|
8626
|
-
offset += dataSize;
|
|
8627
|
-
}
|
|
8628
|
-
return concatUint8Arrays([
|
|
8629
|
-
dir,
|
|
8630
|
-
...dirs,
|
|
8631
|
-
...imgs
|
|
8632
|
-
]);
|
|
8633
|
-
}
|
|
8634
|
-
/**
|
|
8635
|
-
* Check if height requires legacy bitmap for compatiblity.
|
|
8636
|
-
*
|
|
8637
|
-
* @param width Image width.
|
|
8638
|
-
* @param height Image height.
|
|
8639
|
-
* @returns Returns true if requires legacy bitmap.
|
|
8640
|
-
*/
|
|
8641
|
-
sizeRequiresLegacyBitmap(width, height) {
|
|
8642
|
-
return width < 64 || height < 64;
|
|
8643
|
-
}
|
|
8644
|
-
/**
|
|
8645
|
-
* Encode icon directory header.
|
|
8646
|
-
*
|
|
8647
|
-
* @param count Entry count.
|
|
8648
|
-
* @returns Encoded header.
|
|
8649
|
-
*/
|
|
8650
|
-
_encodeIcoDir(count) {
|
|
8651
|
-
const r = /* @__PURE__ */ new Uint8Array(6);
|
|
8652
|
-
const encoded = new DataView(r.buffer, r.byteOffset, r.byteLength);
|
|
8653
|
-
encoded.setUint16(0, 0, true);
|
|
8654
|
-
encoded.setUint16(2, 1, true);
|
|
8655
|
-
encoded.setUint16(4, count, true);
|
|
8656
|
-
return r;
|
|
8657
|
-
}
|
|
8658
|
-
/**
|
|
8659
|
-
* Encode icon directory entry.
|
|
8660
|
-
*
|
|
8661
|
-
* @param entry Icon entry.
|
|
8662
|
-
* @param offset File offset.
|
|
8663
|
-
* @returns Encoded entry.
|
|
8664
|
-
*/
|
|
8665
|
-
_encodeIcoDirEntry(entry, offset) {
|
|
8666
|
-
const { width, height, data } = entry;
|
|
8667
|
-
const r = /* @__PURE__ */ new Uint8Array(16);
|
|
8668
|
-
const encoded = new DataView(r.buffer, r.byteOffset, r.byteLength);
|
|
8669
|
-
encoded.setUint8(0, width >= 256 ? 0 : width);
|
|
8670
|
-
encoded.setUint8(1, height >= 256 ? 0 : height);
|
|
8671
|
-
encoded.setUint8(2, 0);
|
|
8672
|
-
encoded.setUint8(3, 0);
|
|
8673
|
-
encoded.setUint16(4, 1, true);
|
|
8674
|
-
encoded.setUint16(6, 32, true);
|
|
8675
|
-
encoded.setUint32(8, data.length, true);
|
|
8676
|
-
encoded.setUint32(12, offset, true);
|
|
8677
|
-
return r;
|
|
8678
|
-
}
|
|
8679
|
-
/**
|
|
8680
|
-
* Encode RGBA image to BMP data.
|
|
8681
|
-
*
|
|
8682
|
-
* @param imageData Image data.
|
|
8683
|
-
* @returns BMP data.
|
|
8684
|
-
*/
|
|
8685
|
-
_encodeRgbaToBmp(imageData) {
|
|
8686
|
-
const { width, height, data } = imageData;
|
|
8687
|
-
const dataSize = data.length;
|
|
8688
|
-
const headerSize = 40;
|
|
8689
|
-
const bodySize = dataSize + (width + (width % 32 ? 32 - width % 32 : 0)) * height / 8;
|
|
8690
|
-
const imgOffset = headerSize;
|
|
8691
|
-
const maskOff = imgOffset + dataSize;
|
|
8692
|
-
const r = new Uint8Array(headerSize + bodySize);
|
|
8693
|
-
const encoded = new DataView(r.buffer, r.byteOffset, r.byteLength);
|
|
8694
|
-
encoded.setUint32(0, 40, true);
|
|
8695
|
-
encoded.setInt32(4, width, true);
|
|
8696
|
-
encoded.setInt32(8, height * 2, true);
|
|
8697
|
-
encoded.setUint16(12, 1, true);
|
|
8698
|
-
encoded.setUint16(14, 32, true);
|
|
8699
|
-
encoded.setUint32(16, 0, true);
|
|
8700
|
-
encoded.setUint32(20, bodySize, true);
|
|
8701
|
-
encoded.setInt32(24, 3780, true);
|
|
8702
|
-
encoded.setInt32(28, 3780, true);
|
|
8703
|
-
encoded.setUint32(32, 0, true);
|
|
8704
|
-
encoded.setUint32(36, 0, true);
|
|
8705
|
-
const cols = width * 4;
|
|
8706
|
-
const rows = height * cols;
|
|
8707
|
-
const end = rows - cols;
|
|
8708
|
-
let maskI = 0;
|
|
8709
|
-
for (let row = 0; row < rows; row += cols) {
|
|
8710
|
-
let bits = 0;
|
|
8711
|
-
let bitc = 0;
|
|
8712
|
-
for (let col = 0; col < cols; col += 4) {
|
|
8713
|
-
let pos = row + col;
|
|
8714
|
-
const r = data[pos++];
|
|
8715
|
-
const g = data[pos++];
|
|
8716
|
-
const b = data[pos++];
|
|
8717
|
-
const a = data[pos];
|
|
8718
|
-
pos = end - row + col;
|
|
8719
|
-
encoded.setUint8(imgOffset + pos++, b);
|
|
8720
|
-
encoded.setUint8(imgOffset + pos++, g);
|
|
8721
|
-
encoded.setUint8(imgOffset + pos++, r);
|
|
8722
|
-
encoded.setUint8(imgOffset + pos, a);
|
|
8723
|
-
bits = bits << 1 | (data[pos] === 0 ? 1 : 0);
|
|
8724
|
-
if (++bitc === 8) {
|
|
8725
|
-
encoded.setUint8(maskOff + maskI++, bits);
|
|
8726
|
-
bits = 0;
|
|
8727
|
-
bitc = 0;
|
|
8728
|
-
}
|
|
8729
|
-
}
|
|
8730
|
-
while (maskI % 4) {
|
|
8731
|
-
bits <<= 1;
|
|
8732
|
-
if (++bitc === 8) {
|
|
8733
|
-
encoded.setUint8(maskOff + maskI++, bits);
|
|
8734
|
-
bits = 0;
|
|
8735
|
-
bitc = 0;
|
|
8736
|
-
}
|
|
8737
|
-
}
|
|
8738
|
-
}
|
|
8739
|
-
return r;
|
|
8740
|
-
}
|
|
8741
|
-
};
|
|
6098
|
+
function valid(data, options = {}) {
|
|
6099
|
+
const stack = base_parse(data, options);
|
|
6100
|
+
return Boolean(stack.length === 1);
|
|
6101
|
+
}
|
|
6102
|
+
function parse$2(data, options = {}) {
|
|
6103
|
+
return parse$1(data, options);
|
|
6104
|
+
}
|
|
6105
|
+
parse$2.parse = parse$1;
|
|
6106
|
+
parse$2.HTMLElement = HTMLElement;
|
|
6107
|
+
parse$2.CommentNode = CommentNode;
|
|
6108
|
+
parse$2.valid = valid;
|
|
6109
|
+
parse$2.Node = Node;
|
|
6110
|
+
parse$2.TextNode = TextNode;
|
|
6111
|
+
parse$2.NodeType = NodeType;
|
|
8742
6112
|
//#endregion
|
|
8743
6113
|
//#region ../icon/src/encode.ts
|
|
8744
6114
|
/**
|
|
@@ -9767,22 +7137,7 @@ const scrapeUrl = async (url, options = {}) => {
|
|
|
9767
7137
|
...c,
|
|
9768
7138
|
order
|
|
9769
7139
|
}));
|
|
9770
|
-
const
|
|
9771
|
-
for (const original of originals) for (const variant of ["solid-black", "solid-white"]) {
|
|
9772
|
-
const solid = await renderSolidSilhouette(original.path, variant === "solid-black" ? black : white);
|
|
9773
|
-
if (solid === void 0) continue;
|
|
9774
|
-
const hash = await iconPerceptualHash(solid);
|
|
9775
|
-
if (hash !== void 0 && solids.some((s) => s.hash !== void 0 && hamming(hash, s.hash) <= 6)) continue;
|
|
9776
|
-
const path = await writeIconTemp(solid, dir);
|
|
9777
|
-
solids.push({
|
|
9778
|
-
url: original.url,
|
|
9779
|
-
path,
|
|
9780
|
-
variant,
|
|
9781
|
-
variantOf: original.order,
|
|
9782
|
-
hash
|
|
9783
|
-
});
|
|
9784
|
-
}
|
|
9785
|
-
const icons = [...originals.map((c) => ({
|
|
7140
|
+
const icons = originals.map((c) => ({
|
|
9786
7141
|
index: c.order,
|
|
9787
7142
|
url: c.url,
|
|
9788
7143
|
path: c.path,
|
|
@@ -9790,16 +7145,7 @@ const scrapeUrl = async (url, options = {}) => {
|
|
|
9790
7145
|
height: c.height,
|
|
9791
7146
|
format: c.format,
|
|
9792
7147
|
variant: "original"
|
|
9793
|
-
}))
|
|
9794
|
-
index: originals.length + i,
|
|
9795
|
-
url: s.url,
|
|
9796
|
-
path: s.path,
|
|
9797
|
-
width: SOLID_SIZE,
|
|
9798
|
-
height: SOLID_SIZE,
|
|
9799
|
-
format: "png",
|
|
9800
|
-
variant: s.variant,
|
|
9801
|
-
variantOf: s.variantOf
|
|
9802
|
-
}))];
|
|
7148
|
+
}));
|
|
9803
7149
|
return {
|
|
9804
7150
|
ok: true,
|
|
9805
7151
|
title,
|
|
@@ -9827,25 +7173,15 @@ const deriveUrlPresets = async (url, options = {}) => {
|
|
|
9827
7173
|
...scraped.frameEmbeddable === void 0 ? {} : { frameEmbeddable: scraped.frameEmbeddable }
|
|
9828
7174
|
};
|
|
9829
7175
|
};
|
|
9830
|
-
const black = {
|
|
9831
|
-
r: 0,
|
|
9832
|
-
g: 0,
|
|
9833
|
-
b: 0
|
|
9834
|
-
};
|
|
9835
|
-
const white = {
|
|
9836
|
-
r: 255,
|
|
9837
|
-
g: 255,
|
|
9838
|
-
b: 255
|
|
9839
|
-
};
|
|
9840
|
-
const SOLID_SIZE = 128;
|
|
9841
7176
|
/**
|
|
9842
7177
|
* Render a solid-color silhouette from an icon's alpha mask (RGB discarded,
|
|
9843
|
-
* alpha kept) — the shape language macOS tray templates want.
|
|
9844
|
-
*
|
|
7178
|
+
* alpha kept) — the shape language macOS tray templates want. Called on the
|
|
7179
|
+
* browser-extracted SUBJECT (its alpha mask IS the subject shape); returns
|
|
7180
|
+
* undefined for non-decodable sources instead of failing the caller.
|
|
9845
7181
|
*/
|
|
9846
7182
|
const renderSolidSilhouette = async (sourcePath, color) => {
|
|
9847
7183
|
try {
|
|
9848
|
-
const image = await containImage(await decodeImageFile(sourcePath),
|
|
7184
|
+
const image = await containImage(await decodeImageFile(sourcePath), 128, 128);
|
|
9849
7185
|
for (let i = 0; i < image.data.length; i += 4) {
|
|
9850
7186
|
image.data[i] = color.r;
|
|
9851
7187
|
image.data[i + 1] = color.g;
|
|
@@ -9944,7 +7280,7 @@ const isIcoContainer = (bytes) => bytes.length >= 8 && bytes[0] === 0 && bytes[1
|
|
|
9944
7280
|
* from the decoder's RGBA through the shared kernel encoder.
|
|
9945
7281
|
*/
|
|
9946
7282
|
const extractLargestIcoFrame = async (ico) => {
|
|
9947
|
-
const decodeIco = (await import("./decode-ico-
|
|
7283
|
+
const decodeIco = (await import("./decode-ico-BHd2POHf.mjs").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
|
|
9948
7284
|
const { toPngBuffer } = await Promise.resolve().then(() => icon_codec_exports);
|
|
9949
7285
|
let best;
|
|
9950
7286
|
for (const frame of decodeIco(ico)) {
|
|
@@ -10194,6 +7530,7 @@ const startCommandRun = async (options) => {
|
|
|
10194
7530
|
}
|
|
10195
7531
|
else if (process.versions.bun !== void 0) options.onEvent({
|
|
10196
7532
|
type: "pty-unavailable",
|
|
7533
|
+
reason: "pty_bun_terminal_missing",
|
|
10197
7534
|
message: "Bun 版本缺少 Bun.Terminal(需要 Bun ≥ 1.2.19),预览以非交互模式运行。"
|
|
10198
7535
|
});
|
|
10199
7536
|
else {
|
|
@@ -10208,6 +7545,7 @@ const startCommandRun = async (options) => {
|
|
|
10208
7545
|
}
|
|
10209
7546
|
else options.onEvent({
|
|
10210
7547
|
type: "pty-unavailable",
|
|
7548
|
+
reason: "pty_node_pty_missing",
|
|
10211
7549
|
message: "node-pty 不可用,预览以非交互模式运行(无法向命令输入内容)。可安装 @lydell/node-pty 启用交互。"
|
|
10212
7550
|
});
|
|
10213
7551
|
}
|
|
@@ -11572,6 +8910,131 @@ const runPackageManagerInstall = async (options) => {
|
|
|
11572
8910
|
});
|
|
11573
8911
|
};
|
|
11574
8912
|
//#endregion
|
|
8913
|
+
//#region packages/core/src/user-messages.ts
|
|
8914
|
+
const UI_LOCALES = [
|
|
8915
|
+
"zh-CN",
|
|
8916
|
+
"ja",
|
|
8917
|
+
"ko",
|
|
8918
|
+
"en",
|
|
8919
|
+
"ar",
|
|
8920
|
+
"fr",
|
|
8921
|
+
"es",
|
|
8922
|
+
"de",
|
|
8923
|
+
"ru"
|
|
8924
|
+
];
|
|
8925
|
+
/** Resolve a raw header/query value to a catalog locale (case-insensitive). */
|
|
8926
|
+
const resolveUiLocale = (raw) => {
|
|
8927
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
8928
|
+
const exact = UI_LOCALES.find((locale) => locale.toLowerCase() === raw.toLowerCase());
|
|
8929
|
+
if (exact !== void 0) return exact;
|
|
8930
|
+
const base = raw.toLowerCase().split("-")[0];
|
|
8931
|
+
return UI_LOCALES.find((locale) => locale.toLowerCase().split("-")[0] === base) ?? (base === "zh" ? "zh-CN" : void 0);
|
|
8932
|
+
};
|
|
8933
|
+
const CATALOGS = {
|
|
8934
|
+
en: {
|
|
8935
|
+
pinHintDarwin: "After opening the app for the first time, right-click its Dock icon and choose “Options → Keep in Dock” to pin it.",
|
|
8936
|
+
pinHintWindows: "Right-click the app's taskbar icon and choose “Pin to taskbar”. (OpenTray does not generate Start-menu shortcuts yet)",
|
|
8937
|
+
pinHintOther: "Pin the app window to the taskbar/favorites; Linux desktop shortcut generation is not provided yet.",
|
|
8938
|
+
ptyBunTerminalMissing: "This Bun build lacks Bun.Terminal (Bun ≥ 1.2.19 required); the preview runs non-interactively.",
|
|
8939
|
+
ptyNodePtyMissing: "node-pty is unavailable, so the preview runs non-interactively (you cannot type into the command). Install @lydell/node-pty to enable interaction.",
|
|
8940
|
+
dirOccupiedSuffix: " — enable “Force overwrite” under Advanced options and retry, or pick another directory",
|
|
8941
|
+
urlInvalid: "Invalid URL: a full http(s) address is required",
|
|
8942
|
+
urlSchemeUnsupported: "URLs must use http(s)",
|
|
8943
|
+
argvProgramRequired: "Array mode needs at least the program element (the first argument)"
|
|
8944
|
+
},
|
|
8945
|
+
"zh-CN": {
|
|
8946
|
+
pinHintDarwin: "首次打开应用后,右键点击 Dock 中的应用图标,选择“选项 → 在程序坞中保留”,即可固定到 Dock。",
|
|
8947
|
+
pinHintWindows: "右键点击任务栏中的应用图标,选择“固定到任务栏”即可固定。(OpenTray 尚未生成开始菜单快捷方式)",
|
|
8948
|
+
pinHintOther: "可将应用窗口固定到任务栏/收藏夹;Linux 桌面快捷方式生成尚未提供。",
|
|
8949
|
+
ptyBunTerminalMissing: "Bun 版本缺少 Bun.Terminal(需要 Bun ≥ 1.2.19),预览以非交互模式运行。",
|
|
8950
|
+
ptyNodePtyMissing: "node-pty 不可用,预览以非交互模式运行(无法向命令输入内容)。可安装 @lydell/node-pty 启用交互。",
|
|
8951
|
+
dirOccupiedSuffix: ";可在「高级选项」中开启 强制覆盖 后重试",
|
|
8952
|
+
urlInvalid: "URL 无效:需要完整的 http(s) 地址",
|
|
8953
|
+
urlSchemeUnsupported: "URL 仅支持 http(s) 地址",
|
|
8954
|
+
argvProgramRequired: "数组模式至少需要程序元素(第一个参数)"
|
|
8955
|
+
},
|
|
8956
|
+
ja: {
|
|
8957
|
+
pinHintDarwin: "初回起動後、Dock のアプリアイコンを右クリックし「オプション → Dock に保管」で固定できます。",
|
|
8958
|
+
pinHintWindows: "タスクバーのアプリアイコンを右クリックし「タスクバーにピン留め」で固定できます。(スタートメニューのショートカット生成には未対応)",
|
|
8959
|
+
pinHintOther: "アプリウィンドウはタスクバー/お気に入りに固定できます。Linux デスクトップのショートカット生成は未提供です。",
|
|
8960
|
+
ptyBunTerminalMissing: "この Bun には Bun.Terminal がありません(Bun ≥ 1.2.19 が必要)。プレビューは非対話モードで動作します。",
|
|
8961
|
+
ptyNodePtyMissing: "node-pty を利用できないため、プレビューは非対話モードで動作します(コマンドに入力できません)。@lydell/node-pty をインストールすると対話できます。",
|
|
8962
|
+
dirOccupiedSuffix: " — 「詳細オプション」で 強制上書き を有効にして再試行するか、別のディレクトリを選択してください",
|
|
8963
|
+
urlInvalid: "URL が無効です:完全な http(s) アドレスが必要です",
|
|
8964
|
+
urlSchemeUnsupported: "URL は http(s) のみ対応しています",
|
|
8965
|
+
argvProgramRequired: "配列モードにはプログラム要素(先頭の引数)が必須です"
|
|
8966
|
+
},
|
|
8967
|
+
ko: {
|
|
8968
|
+
pinHintDarwin: "앱을 처음 연 후 Dock의 앱 아이콘을 우클릭하고 “옵션 → Dock에 유지”를 선택하면 고정됩니다.",
|
|
8969
|
+
pinHintWindows: "작업표시줄의 앱 아이콘을 우클릭하고 “작업표시줄에 고정”을 선택하세요. (시작 메뉴 바로 가기 생성은 아직 미지원)",
|
|
8970
|
+
pinHintOther: "앱 창을 작업표시줄/즐겨찾기에 고정할 수 있습니다. Linux 바탕화면 바로 가기 생성은 아직 제공되지 않습니다.",
|
|
8971
|
+
ptyBunTerminalMissing: "이 Bun 빌드에는 Bun.Terminal이 없습니다(Bun ≥ 1.2.19 필요). 미리보기는 비대화형으로 실행됩니다.",
|
|
8972
|
+
ptyNodePtyMissing: "node-pty를 사용할 수 없어 미리보기가 비대화형으로 실행됩니다(명령에 입력할 수 없음). @lydell/node-pty를 설치하면 대화형으로 사용할 수 있습니다.",
|
|
8973
|
+
dirOccupiedSuffix: " — “고급 옵션”에서 강제 덮어쓰기를 켜고 다시 시도하거나 다른 디렉터리를 선택하세요",
|
|
8974
|
+
urlInvalid: "잘못된 URL: 전체 http(s) 주소가 필요합니다",
|
|
8975
|
+
urlSchemeUnsupported: "URL은 http(s)만 지원합니다",
|
|
8976
|
+
argvProgramRequired: "배열 모드에는 프로그램 요소(첫 번째 인자)가 필요합니다"
|
|
8977
|
+
},
|
|
8978
|
+
ar: {
|
|
8979
|
+
pinHintDarwin: "بعد أول تشغيل للتطبيق، انقر بزر الفأرة الأيمن على أيقونته في Dock واختر «خيارات → الاحتفاظ في Dock» لتثبيتها.",
|
|
8980
|
+
pinHintWindows: "انقر بزر الفأرة الأيمن على أيقونة التطبيق في شريط المهام واختر «تثبيت في شريط المهام». (لم يوفر OpenTray اختصارات قائمة ابدأ بعد)",
|
|
8981
|
+
pinHintOther: "يمكن تثبيت نافذة التطبيق في شريط المهام/المفضلة؛ ولم تُوفَّر أداة إنشاء اختصارات سطح المكتب في Linux بعد.",
|
|
8982
|
+
ptyBunTerminalMissing: "هذا الإصدار من Bun يفتقد Bun.Terminal (يلزم Bun ≥ 1.2.19)؛ يعمل المعاينة في وضع غير تفاعلي.",
|
|
8983
|
+
ptyNodePtyMissing: "node-pty غير متاح، لذا تعمل المعاينة في وضع غير تفاعلي (لا يمكن الكتابة إلى الأمر). ثبّت @lydell/node-pty لتمكين التفاعل.",
|
|
8984
|
+
dirOccupiedSuffix: " — فعّل «الكتابة فوق بالقوة» في الخيارات المتقدمة وأعد المحاولة، أو اختر دليلًا آخر",
|
|
8985
|
+
urlInvalid: "عنوان URL غير صالح: يلزم عنوان http(s) كامل",
|
|
8986
|
+
urlSchemeUnsupported: "يدعم URL مخطط http(s) فقط",
|
|
8987
|
+
argvProgramRequired: "يتطلب وضع المصفوفة عنصر البرنامج (الوسيطة الأولى) على الأقل"
|
|
8988
|
+
},
|
|
8989
|
+
fr: {
|
|
8990
|
+
pinHintDarwin: "Après la première ouverture de l'app, faites un clic droit sur son icône dans le Dock et choisissez « Options → Garder dans le Dock » pour l'épingler.",
|
|
8991
|
+
pinHintWindows: "Faites un clic droit sur l'icône de l'app dans la barre des tâches et choisissez « Épingler à la barre des tâches ». (OpenTray ne génère pas encore de raccourcis du menu Démarrer)",
|
|
8992
|
+
pinHintOther: "Épinglez la fenêtre de l'app à la barre des tâches/favoris ; la génération de raccourcis bureau Linux n'est pas encore fournie.",
|
|
8993
|
+
ptyBunTerminalMissing: "Ce build de Bun ne dispose pas de Bun.Terminal (Bun ≥ 1.2.19 requis) ; l'aperçu s'exécute en mode non interactif.",
|
|
8994
|
+
ptyNodePtyMissing: "node-pty est indisponible, l'aperçu s'exécute donc en mode non interactif (impossible de saisir dans la commande). Installez @lydell/node-pty pour activer l'interaction.",
|
|
8995
|
+
dirOccupiedSuffix: " — activez « Écrasement forcé » dans les options avancées et réessayez, ou choisissez un autre répertoire",
|
|
8996
|
+
urlInvalid: "URL invalide : une adresse http(s) complète est requise",
|
|
8997
|
+
urlSchemeUnsupported: "Les URL doivent utiliser http(s)",
|
|
8998
|
+
argvProgramRequired: "Le mode tableau exige au moins l'élément programme (le premier argument)"
|
|
8999
|
+
},
|
|
9000
|
+
es: {
|
|
9001
|
+
pinHintDarwin: "Tras abrir la app por primera vez, haz clic derecho en su icono del Dock y elige «Opciones → Mantener en el Dock» para fijarlo.",
|
|
9002
|
+
pinHintWindows: "Haz clic derecho en el icono de la app en la barra de tareas y elige «Anclar a la barra de tareas». (OpenTray aún no genera accesos del menú Inicio)",
|
|
9003
|
+
pinHintOther: "Puedes anclar la ventana de la app a la barra de tareas/favoritos; la generación de accesos de escritorio en Linux aún no está disponible.",
|
|
9004
|
+
ptyBunTerminalMissing: "Esta build de Bun carece de Bun.Terminal (se necesita Bun ≥ 1.2.19); la vista previa se ejecuta en modo no interactivo.",
|
|
9005
|
+
ptyNodePtyMissing: "node-pty no está disponible, así que la vista previa se ejecuta en modo no interactivo (no puedes escribir en el comando). Instala @lydell/node-pty para habilitar la interacción.",
|
|
9006
|
+
dirOccupiedSuffix: " — activa «Sobrescritura forzada» en las opciones avanzadas y reintenta, o elige otro directorio",
|
|
9007
|
+
urlInvalid: "URL no válida: se requiere una dirección http(s) completa",
|
|
9008
|
+
urlSchemeUnsupported: "Las URL deben usar http(s)",
|
|
9009
|
+
argvProgramRequired: "El modo array necesita al menos el elemento programa (el primer argumento)"
|
|
9010
|
+
},
|
|
9011
|
+
de: {
|
|
9012
|
+
pinHintDarwin: "Nach dem ersten Öffnen der App rechts auf ihr Dock-Symbol klicken und „Optionen → Im Dock behalten“ wählen, um sie zu halten.",
|
|
9013
|
+
pinHintWindows: "Rechts auf das App-Symbol in der Taskleiste klicken und „An Taskleiste anheften“ wählen. (OpenTray erzeugt noch keine Startmenü-Verknüpfungen)",
|
|
9014
|
+
pinHintOther: "Das App-Fenster lässt sich an Taskleiste/Favoriten anheften; Linux-Desktop-Verknüpfungen werden noch nicht erzeugt.",
|
|
9015
|
+
ptyBunTerminalMissing: "Dieser Bun-Build fehlt Bun.Terminal (Bun ≥ 1.2.19 erforderlich); die Vorschau läuft nicht interaktiv.",
|
|
9016
|
+
ptyNodePtyMissing: "node-pty ist nicht verfügbar, daher läuft die Vorschau nicht interaktiv (keine Eingabe in den Befehl möglich). Installiere @lydell/node-pty für Interaktion.",
|
|
9017
|
+
dirOccupiedSuffix: " — aktiviere „Erzwungenes Überschreiben“ in den erweiterten Optionen und versuche es erneut, oder wähle ein anderes Verzeichnis",
|
|
9018
|
+
urlInvalid: "Ungültige URL: eine vollständige http(s)-Adresse ist erforderlich",
|
|
9019
|
+
urlSchemeUnsupported: "URLs müssen http(s) verwenden",
|
|
9020
|
+
argvProgramRequired: "Der Array-Modus braucht mindestens das Programmelement (das erste Argument)"
|
|
9021
|
+
},
|
|
9022
|
+
ru: {
|
|
9023
|
+
pinHintDarwin: "После первого запуска приложения кликните правой кнопкой по его значку в Dock и выберите «Параметры → Оставить в Dock».",
|
|
9024
|
+
pinHintWindows: "Кликните правой кнопкой по значку приложения на панели задач и выберите «Закрепить на панели задач». (OpenTray пока не создаёт ярлыки в меню «Пуск»)",
|
|
9025
|
+
pinHintOther: "Окно приложения можно закрепить на панели задач/в избранном; создание ярлыков рабочего стола Linux пока не предусмотрено.",
|
|
9026
|
+
ptyBunTerminalMissing: "В этой сборке Bun нет Bun.Terminal (нужен Bun ≥ 1.2.19); предпросмотр работает в неинтерактивном режиме.",
|
|
9027
|
+
ptyNodePtyMissing: "node-pty недоступен, поэтому предпросмотр работает в неинтерактивном режиме (ввести данные в команду нельзя). Установите @lydell/node-pty для интерактивности.",
|
|
9028
|
+
dirOccupiedSuffix: " — включите «Принудительную перезапись» в расширенных настройках и повторите либо выберите другой каталог",
|
|
9029
|
+
urlInvalid: "Некорректный URL: требуется полный http(s)-адрес",
|
|
9030
|
+
urlSchemeUnsupported: "URL поддерживает только http(s)",
|
|
9031
|
+
argvProgramRequired: "В режиме массива нужен хотя бы элемент программы (первый аргумент)"
|
|
9032
|
+
}
|
|
9033
|
+
};
|
|
9034
|
+
const userMessages = (locale) => CATALOGS[locale];
|
|
9035
|
+
/** Localized text for the machine-readable pty-unavailable event codes. */
|
|
9036
|
+
const ptyUnavailableMessage = (code, locale) => code === "pty_bun_terminal_missing" ? CATALOGS[locale].ptyBunTerminalMissing : CATALOGS[locale].ptyNodePtyMissing;
|
|
9037
|
+
//#endregion
|
|
11575
9038
|
//#region packages/core/src/open-app.ts
|
|
11576
9039
|
/** The generated entry embeds a native PTY: it needs Node, never a Bun host. */
|
|
11577
9040
|
const nodeExecutable = () => {
|
|
@@ -11641,11 +9104,16 @@ const openMaterializedApp = async (input) => {
|
|
|
11641
9104
|
}
|
|
11642
9105
|
return spawnEntryCold(input.projectDir);
|
|
11643
9106
|
};
|
|
11644
|
-
/**
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
9107
|
+
/**
|
|
9108
|
+
* Platform-truthful pinning hint; makes no persistence claim before first
|
|
9109
|
+
* open. `locale` localizes the wizard/webui projection; the default keeps
|
|
9110
|
+
* direct core consumers (CLI) on their historical output.
|
|
9111
|
+
*/
|
|
9112
|
+
const pinningHint = (platform = process.platform, locale = "zh-CN") => {
|
|
9113
|
+
const messages = userMessages(locale);
|
|
9114
|
+
if (platform === "darwin") return messages.pinHintDarwin;
|
|
9115
|
+
if (platform === "win32") return messages.pinHintWindows;
|
|
9116
|
+
return messages.pinHintOther;
|
|
11649
9117
|
};
|
|
11650
9118
|
//#endregion
|
|
11651
9119
|
//#region packages/core/src/errors.ts
|
|
@@ -17321,12 +14789,14 @@ const createWizardSession = (options) => {
|
|
|
17321
14789
|
let trayIconIsSolid = false;
|
|
17322
14790
|
let iconCandidates = [];
|
|
17323
14791
|
let iconPort;
|
|
14792
|
+
let iconGeneration = 0;
|
|
17324
14793
|
let currentTokens = [];
|
|
17325
14794
|
let currentCommand = "";
|
|
17326
14795
|
let urlSource;
|
|
17327
14796
|
let urlFrameEmbeddable;
|
|
17328
14797
|
let scrapedTitle;
|
|
17329
14798
|
let interactive = true;
|
|
14799
|
+
let uiLocale = "zh-CN";
|
|
17330
14800
|
let resolvedVector;
|
|
17331
14801
|
let frozenForm;
|
|
17332
14802
|
let resolvedServicePort;
|
|
@@ -17459,13 +14929,15 @@ const createWizardSession = (options) => {
|
|
|
17459
14929
|
if (stateNow === "frozen" || stateNow === "materializing" || stateNow === "success") return;
|
|
17460
14930
|
iconCandidates = scraped.icons;
|
|
17461
14931
|
iconPort = port;
|
|
14932
|
+
iconGeneration += 1;
|
|
17462
14933
|
currentIconPath = scraped.icons[0]?.path;
|
|
17463
14934
|
currentIconUrl = scraped.icons[0]?.url;
|
|
17464
14935
|
if (scraped.title !== void 0) scrapedTitle = scraped.title;
|
|
17465
14936
|
emit({
|
|
17466
14937
|
type: "icons",
|
|
17467
14938
|
port,
|
|
17468
|
-
icons: scraped.icons
|
|
14939
|
+
icons: scraped.icons,
|
|
14940
|
+
generation: iconGeneration
|
|
17469
14941
|
});
|
|
17470
14942
|
emit({
|
|
17471
14943
|
type: "scrape",
|
|
@@ -17552,6 +15024,9 @@ const createWizardSession = (options) => {
|
|
|
17552
15024
|
get state() {
|
|
17553
15025
|
return state;
|
|
17554
15026
|
},
|
|
15027
|
+
setLocale(locale) {
|
|
15028
|
+
uiLocale = locale;
|
|
15029
|
+
},
|
|
17555
15030
|
snapshot() {
|
|
17556
15031
|
return {
|
|
17557
15032
|
type: "snapshot",
|
|
@@ -17570,6 +15045,7 @@ const createWizardSession = (options) => {
|
|
|
17570
15045
|
...selectedPort === void 0 ? {} : { selectedPort },
|
|
17571
15046
|
iconCandidates: [...iconCandidates],
|
|
17572
15047
|
...iconPort === void 0 ? {} : { iconsPort: iconPort },
|
|
15048
|
+
iconsGeneration: iconGeneration,
|
|
17573
15049
|
interactive
|
|
17574
15050
|
};
|
|
17575
15051
|
},
|
|
@@ -17595,6 +15071,64 @@ const createWizardSession = (options) => {
|
|
|
17595
15071
|
replaceIconCandidates(port, icons) {
|
|
17596
15072
|
iconPort = port;
|
|
17597
15073
|
iconCandidates = icons;
|
|
15074
|
+
iconGeneration += 1;
|
|
15075
|
+
},
|
|
15076
|
+
async addIconCandidate(port, candidate) {
|
|
15077
|
+
if (state === "frozen" || state === "materializing" || state === "success") return;
|
|
15078
|
+
if (iconPort !== port) return;
|
|
15079
|
+
const source = iconCandidates.find((icon) => icon.index === candidate.variantOf);
|
|
15080
|
+
if (source === void 0) return;
|
|
15081
|
+
const dir = tempIconDir ?? (tempIconDir = await mkdtemp(join(tmpdir(), "create-opentray-")));
|
|
15082
|
+
const path = join(dir, `subject-${createHash("sha256").update(candidate.bytes).digest("hex").slice(0, 16)}.bin`);
|
|
15083
|
+
await writeFile(path, candidate.bytes);
|
|
15084
|
+
const priorSubject = iconCandidates.find((icon) => icon.variant === "subject" && icon.variantOf === source.index);
|
|
15085
|
+
const base = priorSubject === void 0 ? iconCandidates : iconCandidates.filter((icon) => icon !== priorSubject && !(icon.variantOf === priorSubject.index && icon.variant !== "original" && icon.variant !== "subject"));
|
|
15086
|
+
let nextIndex = base.reduce((max, icon) => Math.max(max, icon.index), -1) + 1;
|
|
15087
|
+
const appended = {
|
|
15088
|
+
index: nextIndex,
|
|
15089
|
+
url: source.url,
|
|
15090
|
+
path,
|
|
15091
|
+
width: candidate.width,
|
|
15092
|
+
height: candidate.height,
|
|
15093
|
+
format: candidate.format,
|
|
15094
|
+
variant: "subject",
|
|
15095
|
+
variantOf: source.index
|
|
15096
|
+
};
|
|
15097
|
+
let candidates = [...base, appended];
|
|
15098
|
+
for (const [variant, color] of [["solid-black", {
|
|
15099
|
+
r: 0,
|
|
15100
|
+
g: 0,
|
|
15101
|
+
b: 0
|
|
15102
|
+
}], ["solid-white", {
|
|
15103
|
+
r: 255,
|
|
15104
|
+
g: 255,
|
|
15105
|
+
b: 255
|
|
15106
|
+
}]]) {
|
|
15107
|
+
const solid = await renderSolidSilhouette(path, color);
|
|
15108
|
+
if (solid === void 0) continue;
|
|
15109
|
+
const solidPath = join(dir, `solid-${variant}-${createHash("sha256").update(solid).digest("hex").slice(0, 12)}.bin`);
|
|
15110
|
+
await writeFile(solidPath, solid);
|
|
15111
|
+
nextIndex += 1;
|
|
15112
|
+
candidates = [...candidates, {
|
|
15113
|
+
index: nextIndex,
|
|
15114
|
+
url: source.url,
|
|
15115
|
+
path: solidPath,
|
|
15116
|
+
width: 128,
|
|
15117
|
+
height: 128,
|
|
15118
|
+
format: "png",
|
|
15119
|
+
variant,
|
|
15120
|
+
variantOf: appended.index
|
|
15121
|
+
}];
|
|
15122
|
+
}
|
|
15123
|
+
iconCandidates = candidates;
|
|
15124
|
+
if (priorSubject !== void 0) iconGeneration += 1;
|
|
15125
|
+
emit({
|
|
15126
|
+
type: "icons",
|
|
15127
|
+
port,
|
|
15128
|
+
icons: iconCandidates,
|
|
15129
|
+
generation: iconGeneration
|
|
15130
|
+
});
|
|
15131
|
+
return appended;
|
|
17598
15132
|
},
|
|
17599
15133
|
selectTrayIconCandidate(port, index) {
|
|
17600
15134
|
if (state === "frozen" || state === "materializing" || state === "success") return false;
|
|
@@ -17603,7 +15137,7 @@ const createWizardSession = (options) => {
|
|
|
17603
15137
|
touched.trayIconPath = true;
|
|
17604
15138
|
currentTrayIconPath = candidate.path;
|
|
17605
15139
|
currentTrayIconUrl = candidate.url;
|
|
17606
|
-
trayIconIsSolid = candidate.variant
|
|
15140
|
+
trayIconIsSolid = candidate.variant === "solid-black" || candidate.variant === "solid-white";
|
|
17607
15141
|
form = {
|
|
17608
15142
|
...form,
|
|
17609
15143
|
trayIconPath: candidate.path
|
|
@@ -17621,7 +15155,7 @@ const createWizardSession = (options) => {
|
|
|
17621
15155
|
if (!touched.trayIconPath) {
|
|
17622
15156
|
currentTrayIconPath = candidate.path;
|
|
17623
15157
|
currentTrayIconUrl = candidate.url;
|
|
17624
|
-
trayIconIsSolid = candidate.variant
|
|
15158
|
+
trayIconIsSolid = candidate.variant === "solid-black" || candidate.variant === "solid-white";
|
|
17625
15159
|
form = {
|
|
17626
15160
|
...form,
|
|
17627
15161
|
iconPath: candidate.path,
|
|
@@ -17649,6 +15183,7 @@ const createWizardSession = (options) => {
|
|
|
17649
15183
|
scrapedTitle = void 0;
|
|
17650
15184
|
iconCandidates = [];
|
|
17651
15185
|
iconPort = void 0;
|
|
15186
|
+
iconGeneration += 1;
|
|
17652
15187
|
currentIconPath = void 0;
|
|
17653
15188
|
currentIconUrl = void 0;
|
|
17654
15189
|
stopTimers();
|
|
@@ -17661,11 +15196,11 @@ const createWizardSession = (options) => {
|
|
|
17661
15196
|
try {
|
|
17662
15197
|
parsed = new URL(trimmed);
|
|
17663
15198
|
} catch {
|
|
17664
|
-
setState("failed",
|
|
15199
|
+
setState("failed", userMessages(uiLocale).urlInvalid);
|
|
17665
15200
|
return;
|
|
17666
15201
|
}
|
|
17667
15202
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
17668
|
-
setState("failed",
|
|
15203
|
+
setState("failed", userMessages(uiLocale).urlSchemeUnsupported);
|
|
17669
15204
|
return;
|
|
17670
15205
|
}
|
|
17671
15206
|
urlSource = parsed.href;
|
|
@@ -17678,6 +15213,7 @@ const createWizardSession = (options) => {
|
|
|
17678
15213
|
const scraped = await (options.scrapeUrl ?? scrapeUrl)(parsed.href, tempIconDir === void 0 ? {} : { tempDir: tempIconDir });
|
|
17679
15214
|
iconCandidates = scraped.ok ? scraped.icons : [];
|
|
17680
15215
|
iconPort = 0;
|
|
15216
|
+
iconGeneration += 1;
|
|
17681
15217
|
currentIconPath = scraped.ok ? scraped.icons[0]?.path : void 0;
|
|
17682
15218
|
currentIconUrl = scraped.ok ? scraped.icons[0]?.url : void 0;
|
|
17683
15219
|
scrapedTitle = scraped.ok ? scraped.title : void 0;
|
|
@@ -17687,7 +15223,8 @@ const createWizardSession = (options) => {
|
|
|
17687
15223
|
emit({
|
|
17688
15224
|
type: "icons",
|
|
17689
15225
|
port: 0,
|
|
17690
|
-
icons: iconCandidates
|
|
15226
|
+
icons: iconCandidates,
|
|
15227
|
+
generation: iconGeneration
|
|
17691
15228
|
});
|
|
17692
15229
|
emit({
|
|
17693
15230
|
type: "scrape",
|
|
@@ -17713,7 +15250,7 @@ const createWizardSession = (options) => {
|
|
|
17713
15250
|
}
|
|
17714
15251
|
} else if (tokens.length === 0 || tokens[0].trim().length === 0) {
|
|
17715
15252
|
submitting = false;
|
|
17716
|
-
setState("failed",
|
|
15253
|
+
setState("failed", userMessages(uiLocale).argvProgramRequired);
|
|
17717
15254
|
return;
|
|
17718
15255
|
}
|
|
17719
15256
|
const pendingTokens = tokens ?? tokenized.tokens;
|
|
@@ -17741,6 +15278,7 @@ const createWizardSession = (options) => {
|
|
|
17741
15278
|
currentTrayIconUrl = void 0;
|
|
17742
15279
|
trayIconIsSolid = false;
|
|
17743
15280
|
iconCandidates = [];
|
|
15281
|
+
iconGeneration += 1;
|
|
17744
15282
|
touched.appId = false;
|
|
17745
15283
|
touched.appName = false;
|
|
17746
15284
|
touched.pm = false;
|
|
@@ -17794,10 +15332,11 @@ const createWizardSession = (options) => {
|
|
|
17794
15332
|
}
|
|
17795
15333
|
if (event.type === "pty-unavailable") {
|
|
17796
15334
|
interactive = false;
|
|
15335
|
+
const message = event.reason !== void 0 ? ptyUnavailableMessage(event.reason, uiLocale) : event.message;
|
|
17797
15336
|
emit({
|
|
17798
15337
|
type: "term-mode",
|
|
17799
15338
|
interactive: false,
|
|
17800
|
-
...
|
|
15339
|
+
...message === void 0 ? {} : { message }
|
|
17801
15340
|
});
|
|
17802
15341
|
return;
|
|
17803
15342
|
}
|
|
@@ -18245,12 +15784,12 @@ const createWizardSession = (options) => {
|
|
|
18245
15784
|
emit({
|
|
18246
15785
|
type: "success",
|
|
18247
15786
|
projectDir: result.projectDir,
|
|
18248
|
-
pinHint: pinningHint()
|
|
15787
|
+
pinHint: pinningHint(process.platform, uiLocale)
|
|
18249
15788
|
});
|
|
18250
15789
|
} catch (error) {
|
|
18251
15790
|
const message = error instanceof Error ? error.message : String(error);
|
|
18252
15791
|
const occupied = message.includes("target directory is not empty");
|
|
18253
|
-
setState("failed", occupied ? `${message}
|
|
15792
|
+
setState("failed", occupied ? `${message}${userMessages(uiLocale).dirOccupiedSuffix}` : message);
|
|
18254
15793
|
}
|
|
18255
15794
|
return;
|
|
18256
15795
|
}
|
|
@@ -18322,12 +15861,12 @@ const createWizardSession = (options) => {
|
|
|
18322
15861
|
emit({
|
|
18323
15862
|
type: "success",
|
|
18324
15863
|
projectDir: result.projectDir,
|
|
18325
|
-
pinHint: pinningHint()
|
|
15864
|
+
pinHint: pinningHint(process.platform, uiLocale)
|
|
18326
15865
|
});
|
|
18327
15866
|
} catch (error) {
|
|
18328
15867
|
const message = error instanceof Error ? error.message : String(error);
|
|
18329
15868
|
const occupied = message.includes("target directory is not empty");
|
|
18330
|
-
setState("failed", occupied ? `${message}
|
|
15869
|
+
setState("failed", occupied ? `${message}${userMessages(uiLocale).dirOccupiedSuffix}` : message);
|
|
18331
15870
|
}
|
|
18332
15871
|
},
|
|
18333
15872
|
async stop() {
|
|
@@ -18859,6 +16398,8 @@ const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
|
|
|
18859
16398
|
]);
|
|
18860
16399
|
const createWizardServer = async (createSession, options = {}) => {
|
|
18861
16400
|
const token = randomBytes(16).toString("hex");
|
|
16401
|
+
const imglyUpstream = options.imglyUpstream ?? IMGLY_UPSTREAM;
|
|
16402
|
+
const imglyCacheRoot = options.imglyCacheRoot ?? join(homedir(), ".opentray", "cache", "imgly-data");
|
|
18862
16403
|
const clients = /* @__PURE__ */ new Set();
|
|
18863
16404
|
const eventLog = [];
|
|
18864
16405
|
const EVENT_LOG_LIMIT = 200;
|
|
@@ -18915,6 +16456,8 @@ const createWizardServer = async (createSession, options = {}) => {
|
|
|
18915
16456
|
respond(response, 401, "text/plain", "unauthorized\n");
|
|
18916
16457
|
return;
|
|
18917
16458
|
}
|
|
16459
|
+
const streamLocale = resolveUiLocale(url.searchParams.get("lang"));
|
|
16460
|
+
if (streamLocale !== void 0) session.setLocale(streamLocale);
|
|
18918
16461
|
response.writeHead(200, {
|
|
18919
16462
|
"content-type": "text/event-stream",
|
|
18920
16463
|
"cache-control": "no-cache",
|
|
@@ -18933,6 +16476,10 @@ const createWizardServer = async (createSession, options = {}) => {
|
|
|
18933
16476
|
await handleAssetFile(url.pathname, response);
|
|
18934
16477
|
return;
|
|
18935
16478
|
}
|
|
16479
|
+
if (url.pathname.startsWith("/imgly-data/")) {
|
|
16480
|
+
await handleImglyAsset(url, response, imglyCacheRoot, imglyUpstream);
|
|
16481
|
+
return;
|
|
16482
|
+
}
|
|
18936
16483
|
if (url.pathname === "/logo.png" || FAVICON_PATHS.has(url.pathname)) {
|
|
18937
16484
|
await handleAssetFile(url.pathname, response);
|
|
18938
16485
|
return;
|
|
@@ -19006,6 +16553,9 @@ const createWizardServer = async (createSession, options = {}) => {
|
|
|
19006
16553
|
respond(response, 403, "application/json", "{\"error\":\"forbidden host\"}\n");
|
|
19007
16554
|
return;
|
|
19008
16555
|
}
|
|
16556
|
+
const headerLocale = request.headers["x-opentray-locale"];
|
|
16557
|
+
const requestLocale = resolveUiLocale(Array.isArray(headerLocale) ? headerLocale[0] : headerLocale);
|
|
16558
|
+
if (requestLocale !== void 0) session.setLocale(requestLocale);
|
|
19009
16559
|
if (url.pathname === "/api/apps" || url.pathname.startsWith("/api/apps/") || url.pathname === "/api/skill" || url.pathname === "/api/skill/list") {
|
|
19010
16560
|
let body = {};
|
|
19011
16561
|
if (request.method === "POST") body = await readJsonBody(request);
|
|
@@ -19137,6 +16687,83 @@ const handleVendorAsset = async (pathname, response) => {
|
|
|
19137
16687
|
}
|
|
19138
16688
|
respond(response, 404, "text/plain", "terminal renderer asset is missing\n");
|
|
19139
16689
|
};
|
|
16690
|
+
/**
|
|
16691
|
+
* Backend model proxy/cache for the browser subject extraction (owner
|
|
16692
|
+
* round-8): the wizard rebinds a RANDOM port every launch, so a browser-side
|
|
16693
|
+
* cache can never survive — the backend downloads model assets from the
|
|
16694
|
+
* vendor CDN ONCE into a persistent disk cache and serves the frontend from
|
|
16695
|
+
* loopback. Content-addressed chunks are immutable → long-lived cache headers.
|
|
16696
|
+
*/
|
|
16697
|
+
const IMGLY_CONTENT_TYPES = {
|
|
16698
|
+
".json": "application/json",
|
|
16699
|
+
".wasm": "application/wasm",
|
|
16700
|
+
".mjs": "text/javascript; charset=utf-8"
|
|
16701
|
+
};
|
|
16702
|
+
/** Model chunks are 4 MiB; bound the proxy to stop unbounded disk writes. */
|
|
16703
|
+
const IMGLY_FILE_LIMIT = 16 * 1024 * 1024;
|
|
16704
|
+
const IMGLY_UPSTREAM = (version) => `https://staticimgly.com/@imgly/background-removal-data/${version}/dist/`;
|
|
16705
|
+
const handleImglyAsset = async (url, response, cacheRoot, upstream) => {
|
|
16706
|
+
const match = /^\/imgly-data\/([\w.-]+)\/([\w.-]+)$/.exec(url.pathname);
|
|
16707
|
+
if (match === null) {
|
|
16708
|
+
respond(response, 404, "text/plain", "not found\n");
|
|
16709
|
+
return;
|
|
16710
|
+
}
|
|
16711
|
+
const version = match[1];
|
|
16712
|
+
const name = match[2];
|
|
16713
|
+
if (version.includes("..") || name.includes("..")) {
|
|
16714
|
+
respond(response, 404, "text/plain", "not found\n");
|
|
16715
|
+
return;
|
|
16716
|
+
}
|
|
16717
|
+
const contentType = IMGLY_CONTENT_TYPES[extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
16718
|
+
const respondBytes = (bytes, fromCache) => {
|
|
16719
|
+
response.writeHead(200, {
|
|
16720
|
+
"content-type": contentType,
|
|
16721
|
+
"content-length": bytes.length,
|
|
16722
|
+
"cache-control": "public, max-age=31536000, immutable",
|
|
16723
|
+
"x-opentray-imgly-cache": fromCache ? "hit" : "miss"
|
|
16724
|
+
});
|
|
16725
|
+
response.end(bytes);
|
|
16726
|
+
};
|
|
16727
|
+
const dir = join(cacheRoot, version);
|
|
16728
|
+
const path = join(dir, name);
|
|
16729
|
+
const cached = await readFile(path).catch(() => void 0);
|
|
16730
|
+
if (cached !== void 0) {
|
|
16731
|
+
respondBytes(cached, true);
|
|
16732
|
+
return;
|
|
16733
|
+
}
|
|
16734
|
+
const fetchFromUpstream = async () => {
|
|
16735
|
+
const upstreamResponse = await fetch(`${upstream(version)}${name}`);
|
|
16736
|
+
if (!upstreamResponse.ok) throw new Error(`upstream ${upstreamResponse.status}`);
|
|
16737
|
+
const bytes = Buffer.from(await upstreamResponse.arrayBuffer());
|
|
16738
|
+
if (bytes.length === 0 || bytes.length > IMGLY_FILE_LIMIT) throw new Error(`upstream size out of bounds: ${bytes.length}`);
|
|
16739
|
+
await mkdir(dir, { recursive: true });
|
|
16740
|
+
const tempPath = join(dir, `.${name}.${randomBytes(6).toString("hex")}.tmp`);
|
|
16741
|
+
await writeFile(tempPath, bytes);
|
|
16742
|
+
await rm(path, { force: true });
|
|
16743
|
+
await rename(tempPath, path);
|
|
16744
|
+
return bytes;
|
|
16745
|
+
};
|
|
16746
|
+
const inFlight = handleImglyAsset.inFlight.get(path);
|
|
16747
|
+
if (inFlight !== void 0) {
|
|
16748
|
+
try {
|
|
16749
|
+
respondBytes(await inFlight, true);
|
|
16750
|
+
} catch {
|
|
16751
|
+
respond(response, 502, "text/plain", "model asset upstream failed\n");
|
|
16752
|
+
}
|
|
16753
|
+
return;
|
|
16754
|
+
}
|
|
16755
|
+
const download = fetchFromUpstream();
|
|
16756
|
+
handleImglyAsset.inFlight.set(path, download);
|
|
16757
|
+
try {
|
|
16758
|
+
respondBytes(await download, false);
|
|
16759
|
+
} catch (error) {
|
|
16760
|
+
respond(response, 502, "text/plain", `model asset upstream failed: ${String(error)}\n`);
|
|
16761
|
+
} finally {
|
|
16762
|
+
handleImglyAsset.inFlight.delete(path);
|
|
16763
|
+
}
|
|
16764
|
+
};
|
|
16765
|
+
/** In-flight upstream downloads, keyed by cache path (per server instance). */
|
|
16766
|
+
handleImglyAsset.inFlight = /* @__PURE__ */ new Map();
|
|
19140
16767
|
/** Containment: icon routes must only read sources the wizard itself
|
|
19141
16768
|
* produced (its temp dirs / saved uploads), never arbitrary paths. */
|
|
19142
16769
|
const isWizardOwnedIconPath = (session, target) => {
|
|
@@ -19163,6 +16790,41 @@ const handleApi = async (pathname, request, response, session, preReadBody) => {
|
|
|
19163
16790
|
respond(response, 200, "application/json", JSON.stringify({ path }) + "\n");
|
|
19164
16791
|
return;
|
|
19165
16792
|
}
|
|
16793
|
+
if (pathname === "/api/icon-candidate") {
|
|
16794
|
+
const query = new URL(request.url ?? "/", "http://127.0.0.1").searchParams;
|
|
16795
|
+
const port = Number.parseInt(query.get("port") ?? "", 10);
|
|
16796
|
+
const variantOf = Number.parseInt(query.get("variantOf") ?? "", 10);
|
|
16797
|
+
const width = Number.parseInt(query.get("width") ?? "", 10);
|
|
16798
|
+
const height = Number.parseInt(query.get("height") ?? "", 10);
|
|
16799
|
+
if (!Number.isInteger(port) || !Number.isInteger(variantOf) || !Number.isInteger(width) || width <= 0 || !Number.isInteger(height) || height <= 0) {
|
|
16800
|
+
respond(response, 400, "application/json", "{\"error\":\"port, variantOf, width and height are required\"}\n");
|
|
16801
|
+
return;
|
|
16802
|
+
}
|
|
16803
|
+
const chunks = [];
|
|
16804
|
+
for await (const chunk of request) {
|
|
16805
|
+
const piece = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
16806
|
+
chunks.push(piece);
|
|
16807
|
+
}
|
|
16808
|
+
const bytes = Buffer.concat(chunks);
|
|
16809
|
+
if (bytes.length < 64) {
|
|
16810
|
+
respond(response, 400, "application/json", "{\"error\":\"image bytes are required\"}\n");
|
|
16811
|
+
return;
|
|
16812
|
+
}
|
|
16813
|
+
const format = query.get("format") ?? "png";
|
|
16814
|
+
const appended = await session.addIconCandidate(port, {
|
|
16815
|
+
bytes,
|
|
16816
|
+
variantOf,
|
|
16817
|
+
width,
|
|
16818
|
+
height,
|
|
16819
|
+
format
|
|
16820
|
+
});
|
|
16821
|
+
if (appended === void 0) {
|
|
16822
|
+
respond(response, 409, "application/json", "{\"error\":\"candidate not acceptable for this port/state\"}\n");
|
|
16823
|
+
return;
|
|
16824
|
+
}
|
|
16825
|
+
respond(response, 200, "application/json", JSON.stringify({ index: appended.index }) + "\n");
|
|
16826
|
+
return;
|
|
16827
|
+
}
|
|
19166
16828
|
const body = preReadBody ?? await readJsonBody(request);
|
|
19167
16829
|
switch (pathname) {
|
|
19168
16830
|
case "/api/url": {
|
|
@@ -20805,6 +18467,6 @@ if (isMainModule()) main(process.argv.slice(2)).then((code) => {
|
|
|
20805
18467
|
process.exitCode = code;
|
|
20806
18468
|
});
|
|
20807
18469
|
//#endregion
|
|
20808
|
-
export { resolveOnPath as A, parseNetstatPorts as C, waitForTcpPort as D, verifyHttpService as E, toProjectDirectoryName as F, deriveDefaultAppId as M, deriveDefaultAppName as N, parseShebangInterpreter as O, isValidAppId as P, parseLsofPorts as S, serviceUrl as T, faviconCandidateSize as _, isAuthorized as a, scrapeService as b, openMaterializedApp as c, expectedDarwinBundlePath as d, isDirectoryOccupied$1 as f, extractTitle as g, extractFaviconCandidates as h, createWizardServer as i, tokenizeCommandLine as j, resolveLaunchVector as k, pinningHint as l, writeScaffold as m, openBrowser as n, isLoopbackHost as o, materialize as p, parseWizardCli as r, createWizardSession as s, main as t, detectPackageManager as u, rankFaviconCandidates as v, parsePowerShellPorts as w, createPortDiscovery as x, resolveFaviconUrl as y };
|
|
18470
|
+
export { resolveOnPath as A, parseNetstatPorts as C, waitForTcpPort as D, verifyHttpService as E, toProjectDirectoryName as F, __commonJSMin$1 as I, deriveDefaultAppId as M, deriveDefaultAppName as N, parseShebangInterpreter as O, isValidAppId as P, parseLsofPorts as S, serviceUrl as T, faviconCandidateSize as _, isAuthorized as a, scrapeService as b, openMaterializedApp as c, expectedDarwinBundlePath as d, isDirectoryOccupied$1 as f, extractTitle as g, extractFaviconCandidates as h, createWizardServer as i, tokenizeCommandLine as j, resolveLaunchVector as k, pinningHint as l, writeScaffold as m, openBrowser as n, isLoopbackHost as o, materialize as p, parseWizardCli as r, createWizardSession as s, main as t, detectPackageManager as u, rankFaviconCandidates as v, parsePowerShellPorts as w, createPortDiscovery as x, resolveFaviconUrl as y };
|
|
20809
18471
|
|
|
20810
|
-
//# sourceMappingURL=bin-
|
|
18472
|
+
//# sourceMappingURL=bin-BQb2Bjcu.mjs.map
|