create-opentray 0.23.0 → 0.25.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/README.md +21 -13
- 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-DDNgskyb.mjs → bin-Bz16rwKs.mjs} +406 -2958
- package/dist/bin-Bz16rwKs.mjs.map +1 -0
- package/dist/bin-CrMTyTux.d.mts +751 -0
- package/dist/bin-CrMTyTux.d.mts.map +1 -0
- package/dist/bin.d.mts +2 -15
- package/dist/bin.mjs +2 -2
- package/dist/{decode-ico-D3SL2BXi.mjs → decode-ico-DDEIV7iZ.mjs} +2 -2
- package/dist/{decode-ico-D3SL2BXi.mjs.map → decode-ico-DDEIV7iZ.mjs.map} +1 -1
- package/dist/encode-CTEluLqt.mjs +167 -0
- package/dist/encode-CTEluLqt.mjs.map +1 -0
- package/dist/icon-codec-Bs3XehqZ.mjs +20 -0
- package/dist/icon-codec-Bs3XehqZ.mjs.map +1 -0
- package/dist/index.d.mts +5 -713
- 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/{rolldown-runtime-JspESFgx.mjs → rolldown-runtime-DJK8HYOj.mjs} +2 -3
- package/dist/shell/assets/ghostty-web.js +1 -1
- package/dist/shell/assets/index.css +1 -1
- package/dist/shell/assets/index.js +2 -9
- package/dist/shell/assets/index2.js +9 -2
- package/dist/shell/assets/input.js +1 -1
- package/dist/shell/assets/main.js +20 -20
- package/dist/shell/assets/terminal-pane.js +2 -2
- package/dist/shell/assets/terminal.js +1 -1
- package/dist/shell/assets/toolbar.js +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/shell/terminal.html +2 -2
- package/dist/shell/{browse.html → toolbar.html} +4 -4
- package/dist/skill/SKILL.md +14 -11
- package/dist/skill/references/cli-reference.md +1 -1
- package/dist/skill/references/how-it-works.md +15 -9
- package/dist/webui/assets/ghostty-web.js +1 -1
- package/dist/webui/assets/index.css +1 -1
- package/dist/webui/assets/index.js +2 -9
- package/dist/webui/assets/index2.js +9 -2
- package/dist/webui/assets/input.js +1 -1
- package/dist/webui/assets/main.js +20 -20
- package/dist/webui/assets/terminal-pane.js +2 -2
- package/dist/webui/assets/terminal.js +1 -1
- package/dist/webui/assets/toolbar.js +1 -0
- package/dist/webui/index.html +2 -2
- package/dist/webui/terminal.html +2 -2
- package/dist/webui/{browse.html → toolbar.html} +4 -4
- package/package.json +15 -6
- package/skill/SKILL.md +14 -11
- package/skill/references/cli-reference.md +1 -1
- package/skill/references/how-it-works.md +15 -9
- package/dist/avif-DCXcyYJR.mjs +0 -2
- package/dist/bin-DDNgskyb.mjs.map +0 -1
- package/dist/bin.d.mts.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/shell/assets/browse.js +0 -1
- package/dist/webp-CcbaCrQ7.mjs +0 -2
- package/dist/webui/assets/browse.js +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
1
|
+
import { r as __toESM$1, t as __commonJSMin$1 } from "./rolldown-runtime-DJK8HYOj.mjs";
|
|
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-DeMbA2zI.mjs";
|
|
3
|
+
import { i as encodeIco, n as encodeDensePng, r as encodeIcns, t as LINUX_SIZES } from "./encode-CTEluLqt.mjs";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import crypto, { createHash, randomBytes } from "node:crypto";
|
|
5
6
|
import fs, { access, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
@@ -9,6 +10,7 @@ import { constants, realpathSync } from "node:fs";
|
|
|
9
10
|
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
10
11
|
import net from "node:net";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { getSvgPath } from "figma-squircle";
|
|
12
14
|
import { resolveDefaultDarwinAppBundlePath, sanitizeAppBundleName } from "@opentray/packaging";
|
|
13
15
|
import { promisify } from "node:util";
|
|
14
16
|
import { createServer } from "node:http";
|
|
@@ -6077,2830 +6079,6 @@ parse$2.Node = Node;
|
|
|
6077
6079
|
parse$2.TextNode = TextNode;
|
|
6078
6080
|
parse$2.NodeType = NodeType;
|
|
6079
6081
|
//#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;
|
|
8344
|
-
}
|
|
8345
|
-
rgba ||= await this._decodePngToRgba(data);
|
|
8346
|
-
await this.addFromRgba(rgba, [type]);
|
|
8347
|
-
}
|
|
8348
|
-
}
|
|
8349
|
-
/**
|
|
8350
|
-
* Add an icon from RGBA image data.
|
|
8351
|
-
*
|
|
8352
|
-
* @param imageData RGBA image data.
|
|
8353
|
-
* @param types Types to encode as.
|
|
8354
|
-
*/
|
|
8355
|
-
async addFromRgba(imageData, types) {
|
|
8356
|
-
for (const type of types) await this._addFromRgbaType(imageData, type);
|
|
8357
|
-
}
|
|
8358
|
-
/**
|
|
8359
|
-
* Add raw data chunk.
|
|
8360
|
-
*
|
|
8361
|
-
* @param data Chunk data.
|
|
8362
|
-
* @param type Chunk tag.
|
|
8363
|
-
*/
|
|
8364
|
-
addRaw(data, type) {
|
|
8365
|
-
this.entries.push({
|
|
8366
|
-
type,
|
|
8367
|
-
data: new Uint8Array(data)
|
|
8368
|
-
});
|
|
8369
|
-
}
|
|
8370
|
-
/**
|
|
8371
|
-
* Add dark mode icns.
|
|
8372
|
-
*
|
|
8373
|
-
* @param data Full encoded icns data.
|
|
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;
|
|
8418
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
8554
|
-
};
|
|
8555
|
-
//#endregion
|
|
8556
|
-
//#region ../../node_modules/.pnpm/@shockpkg+icon-encoder@3.2.3/node_modules/@shockpkg/icon-encoder/esm/icon/ico.mjs
|
|
8557
|
-
/**
|
|
8558
|
-
* Icon entry.
|
|
8559
|
-
*/
|
|
8560
|
-
/**
|
|
8561
|
-
* IconIco object.
|
|
8562
|
-
*/
|
|
8563
|
-
var IconIco = class extends Icon {
|
|
8564
|
-
/**
|
|
8565
|
-
* List of icon entries.
|
|
8566
|
-
*/
|
|
8567
|
-
entries = [];
|
|
8568
|
-
/**
|
|
8569
|
-
* IconIco constructor.
|
|
8570
|
-
*/
|
|
8571
|
-
constructor() {
|
|
8572
|
-
super();
|
|
8573
|
-
}
|
|
8574
|
-
/**
|
|
8575
|
-
* Add an icon from PNG data.
|
|
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
|
-
};
|
|
8742
|
-
//#endregion
|
|
8743
|
-
//#region ../icon/src/encode.ts
|
|
8744
|
-
/**
|
|
8745
|
-
* Platform encoders. PNG payloads carry explicit 72 DPI density: the WASM PNG
|
|
8746
|
-
* encoder emits no `pHYs` chunk (spike-verified), so density is injected with
|
|
8747
|
-
* a minimal chunk surgery (insert/replace after IHDR, CRC32 over type+data).
|
|
8748
|
-
* ICNS keeps the ten-tag explicit representation set; ICO and Linux PNGs keep
|
|
8749
|
-
* their ladders. All encoders consume PNG bytes so the density law applies to
|
|
8750
|
-
* every emitted pixel payload.
|
|
8751
|
-
*/
|
|
8752
|
-
var encode_exports = /* @__PURE__ */ __exportAll$1({
|
|
8753
|
-
ICNS_REPRESENTATIONS: () => ICNS_REPRESENTATIONS,
|
|
8754
|
-
ICO_SIZES: () => ICO_SIZES,
|
|
8755
|
-
LINUX_SIZES: () => LINUX_SIZES,
|
|
8756
|
-
encodeDensePng: () => encodeDensePng,
|
|
8757
|
-
encodeIcns: () => encodeIcns,
|
|
8758
|
-
encodeIco: () => encodeIco,
|
|
8759
|
-
pngWithDensity: () => pngWithDensity
|
|
8760
|
-
});
|
|
8761
|
-
/** Pixels per metre for 72 DPI (72 × 39.3701 ≈ 2834.65, the Apple value). */
|
|
8762
|
-
const PIXELS_PER_METRE_72DPI = 2835;
|
|
8763
|
-
const ICNS_REPRESENTATIONS = [
|
|
8764
|
-
{
|
|
8765
|
-
tag: "ic12",
|
|
8766
|
-
size: 64
|
|
8767
|
-
},
|
|
8768
|
-
{
|
|
8769
|
-
tag: "ic07",
|
|
8770
|
-
size: 128
|
|
8771
|
-
},
|
|
8772
|
-
{
|
|
8773
|
-
tag: "ic13",
|
|
8774
|
-
size: 256
|
|
8775
|
-
},
|
|
8776
|
-
{
|
|
8777
|
-
tag: "ic08",
|
|
8778
|
-
size: 256
|
|
8779
|
-
},
|
|
8780
|
-
{
|
|
8781
|
-
tag: "ic04",
|
|
8782
|
-
size: 16
|
|
8783
|
-
},
|
|
8784
|
-
{
|
|
8785
|
-
tag: "ic14",
|
|
8786
|
-
size: 512
|
|
8787
|
-
},
|
|
8788
|
-
{
|
|
8789
|
-
tag: "ic09",
|
|
8790
|
-
size: 512
|
|
8791
|
-
},
|
|
8792
|
-
{
|
|
8793
|
-
tag: "ic05",
|
|
8794
|
-
size: 32
|
|
8795
|
-
},
|
|
8796
|
-
{
|
|
8797
|
-
tag: "ic10",
|
|
8798
|
-
size: 1024
|
|
8799
|
-
},
|
|
8800
|
-
{
|
|
8801
|
-
tag: "ic11",
|
|
8802
|
-
size: 32
|
|
8803
|
-
}
|
|
8804
|
-
];
|
|
8805
|
-
const ICO_SIZES = [
|
|
8806
|
-
16,
|
|
8807
|
-
24,
|
|
8808
|
-
32,
|
|
8809
|
-
48,
|
|
8810
|
-
64,
|
|
8811
|
-
128,
|
|
8812
|
-
256
|
|
8813
|
-
];
|
|
8814
|
-
const LINUX_SIZES = [
|
|
8815
|
-
16,
|
|
8816
|
-
32,
|
|
8817
|
-
48,
|
|
8818
|
-
64,
|
|
8819
|
-
128,
|
|
8820
|
-
256,
|
|
8821
|
-
512
|
|
8822
|
-
];
|
|
8823
|
-
const CRC_TABLE = (() => {
|
|
8824
|
-
const table = new Array(256);
|
|
8825
|
-
for (let n = 0; n < 256; n += 1) {
|
|
8826
|
-
let c = n;
|
|
8827
|
-
for (let k = 0; k < 8; k += 1) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
8828
|
-
table[n] = c >>> 0;
|
|
8829
|
-
}
|
|
8830
|
-
return table;
|
|
8831
|
-
})();
|
|
8832
|
-
const crc32 = (bytes) => {
|
|
8833
|
-
let crc = 4294967295;
|
|
8834
|
-
for (let i = 0; i < bytes.length; i += 1) crc = CRC_TABLE[(crc ^ bytes[i]) & 255] ^ crc >>> 8;
|
|
8835
|
-
return (crc ^ 4294967295) >>> 0;
|
|
8836
|
-
};
|
|
8837
|
-
const chunkLength = (view, offset) => view.getUint32(offset);
|
|
8838
|
-
const chunkType = (bytes, offset) => String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
|
|
8839
|
-
const PHYS_DATA = (() => {
|
|
8840
|
-
const data = /* @__PURE__ */ new Uint8Array(9);
|
|
8841
|
-
const view = new DataView(data.buffer);
|
|
8842
|
-
view.setUint32(0, PIXELS_PER_METRE_72DPI);
|
|
8843
|
-
view.setUint32(4, PIXELS_PER_METRE_72DPI);
|
|
8844
|
-
data[8] = 1;
|
|
8845
|
-
return data;
|
|
8846
|
-
})();
|
|
8847
|
-
/**
|
|
8848
|
-
* Ensure a PNG carries exactly one `pHYs` chunk at 72 DPI, inserted after
|
|
8849
|
-
* IHDR. Every pre-existing `pHYs` chunk (however many a malformed input
|
|
8850
|
-
* carried) is dropped so the emitted density cannot drift.
|
|
8851
|
-
*/
|
|
8852
|
-
const pngWithDensity = (png) => {
|
|
8853
|
-
const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
8854
|
-
let offset = 8;
|
|
8855
|
-
let ihdrEnd = -1;
|
|
8856
|
-
const segments = [];
|
|
8857
|
-
const tail = [];
|
|
8858
|
-
while (offset + 12 <= png.length) {
|
|
8859
|
-
const length = chunkLength(view, offset);
|
|
8860
|
-
const type = chunkType(png, offset + 4);
|
|
8861
|
-
const chunkEnd = offset + 12 + length;
|
|
8862
|
-
if (type === "IHDR") {
|
|
8863
|
-
ihdrEnd = chunkEnd;
|
|
8864
|
-
segments.push(png.subarray(offset, chunkEnd));
|
|
8865
|
-
} else if (type !== "pHYs") (ihdrEnd === -1 ? segments : tail).push(png.subarray(offset, chunkEnd));
|
|
8866
|
-
offset = chunkEnd;
|
|
8867
|
-
if (type === "IEND") break;
|
|
8868
|
-
}
|
|
8869
|
-
if (ihdrEnd === -1) throw new Error("pngWithDensity: IHDR chunk not found");
|
|
8870
|
-
const chunk = new Uint8Array(12 + PHYS_DATA.length);
|
|
8871
|
-
const chunkView = new DataView(chunk.buffer);
|
|
8872
|
-
chunkView.setUint32(0, PHYS_DATA.length);
|
|
8873
|
-
chunk.set(new TextEncoder().encode("pHYs"), 4);
|
|
8874
|
-
chunk.set(PHYS_DATA, 8);
|
|
8875
|
-
chunkView.setUint32(8 + PHYS_DATA.length, crc32(chunk.subarray(4, 8 + PHYS_DATA.length)));
|
|
8876
|
-
return concat(png.subarray(0, 8), ...segments, chunk, ...tail);
|
|
8877
|
-
};
|
|
8878
|
-
const concat = (...parts) => {
|
|
8879
|
-
const total = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
8880
|
-
const out = new Uint8Array(total);
|
|
8881
|
-
let offset = 0;
|
|
8882
|
-
for (const part of parts) {
|
|
8883
|
-
out.set(part, offset);
|
|
8884
|
-
offset += part.byteLength;
|
|
8885
|
-
}
|
|
8886
|
-
return out;
|
|
8887
|
-
};
|
|
8888
|
-
/** Encode RGBA pixels to a density-carrying PNG. */
|
|
8889
|
-
const encodeDensePng = async (image) => pngWithDensity(await encodeImagePng(image));
|
|
8890
|
-
/** Encode the ten-tag ICNS from per-size PNG payloads (macOS variant source). */
|
|
8891
|
-
const encodeIcns = async (pngAt) => {
|
|
8892
|
-
const icns = new IconIcns();
|
|
8893
|
-
icns.toc = true;
|
|
8894
|
-
for (const { tag, size } of ICNS_REPRESENTATIONS) await icns.addFromPng(await pngAt(size), [tag], false);
|
|
8895
|
-
return icns.encode();
|
|
8896
|
-
};
|
|
8897
|
-
/** Encode the ICO ladder from per-size PNG payloads (Windows variant source). */
|
|
8898
|
-
const encodeIco = async (pngAt) => {
|
|
8899
|
-
const ico = new IconIco();
|
|
8900
|
-
for (const size of ICO_SIZES) await ico.addFromPng(await pngAt(size), null, false);
|
|
8901
|
-
return ico.encode();
|
|
8902
|
-
};
|
|
8903
|
-
//#endregion
|
|
8904
6082
|
//#region ../icon/src/generate.ts
|
|
8905
6083
|
const ICON_SIZE = 1024;
|
|
8906
6084
|
const TILE_INSET = 64;
|
|
@@ -9339,7 +6517,7 @@ const composeAppIcon = async (options) => {
|
|
|
9339
6517
|
pasteImage(macOSVariant, macOSContent, macOSMargin, macOSMargin);
|
|
9340
6518
|
const writeVariant = async (image, suffix) => {
|
|
9341
6519
|
const path = join(compositionDir, `app-composited${suffix}.png`);
|
|
9342
|
-
const { encodeDensePng } = await
|
|
6520
|
+
const { encodeDensePng } = await import("./encode-CTEluLqt.mjs").then((n) => n.a);
|
|
9343
6521
|
await writeFile(path, await encodeDensePng(image));
|
|
9344
6522
|
return path;
|
|
9345
6523
|
};
|
|
@@ -9673,19 +6851,13 @@ const defaultFetch = {
|
|
|
9673
6851
|
if (response === void 0) return {
|
|
9674
6852
|
ok: false,
|
|
9675
6853
|
status: 0,
|
|
9676
|
-
body: ""
|
|
9677
|
-
headers: {}
|
|
6854
|
+
body: ""
|
|
9678
6855
|
};
|
|
9679
6856
|
const body = await response.text();
|
|
9680
|
-
const headers = {};
|
|
9681
|
-
response.headers.forEach((value, key) => {
|
|
9682
|
-
headers[key.toLowerCase()] = value;
|
|
9683
|
-
});
|
|
9684
6857
|
return {
|
|
9685
6858
|
ok: response.ok,
|
|
9686
6859
|
status: response.status,
|
|
9687
|
-
body
|
|
9688
|
-
headers
|
|
6860
|
+
body
|
|
9689
6861
|
};
|
|
9690
6862
|
},
|
|
9691
6863
|
async bytes(url, timeoutMs = 5e3) {
|
|
@@ -9708,22 +6880,6 @@ const defaultFetch = {
|
|
|
9708
6880
|
/** Cap on downloaded candidates per scrape. */
|
|
9709
6881
|
const MAX_ICON_DOWNLOADS = 8;
|
|
9710
6882
|
/**
|
|
9711
|
-
* Whether the page's response headers permit embedding by a third-party
|
|
9712
|
-
* origin (the toolbar wrapper): rejects on X-Frame-Options (except
|
|
9713
|
-
* ALLOWALL) and on CSP frame-ancestors without a wildcard. Absent both
|
|
9714
|
-
* policies, embedding is allowed by default — same default browsers use.
|
|
9715
|
-
*/
|
|
9716
|
-
const responseHeadersAllowEmbedding = (headers) => {
|
|
9717
|
-
const xfo = (headers["x-frame-options"] ?? "").trim().toUpperCase();
|
|
9718
|
-
if (xfo.length > 0 && !xfo.split(",").map((token) => token.trim()).includes("ALLOWALL")) return false;
|
|
9719
|
-
const csp = (headers["content-security-policy"] ?? "").toLowerCase();
|
|
9720
|
-
for (const match of csp.matchAll(/frame-ancestors\s+([^;]+)/gu)) {
|
|
9721
|
-
const sources = (match[1] ?? "").trim();
|
|
9722
|
-
if (sources.length === 0 || !sources.split(/\s+/u).includes("*")) return false;
|
|
9723
|
-
}
|
|
9724
|
-
return true;
|
|
9725
|
-
};
|
|
9726
|
-
/**
|
|
9727
6883
|
* Scrape title and ALL icon candidates from an arbitrary http(s) URL.
|
|
9728
6884
|
* Never throws: failures return `ok: false` with whatever partial identity
|
|
9729
6885
|
* was found. (`scrapeService` is the loopback-port wrapper over this.)
|
|
@@ -9781,8 +6937,7 @@ const scrapeUrl = async (url, options = {}) => {
|
|
|
9781
6937
|
title,
|
|
9782
6938
|
iconPath: originals[0]?.path,
|
|
9783
6939
|
...originals[0] === void 0 ? {} : { iconUrl: originals[0].url },
|
|
9784
|
-
icons
|
|
9785
|
-
frameEmbeddable: responseHeadersAllowEmbedding(page.headers)
|
|
6940
|
+
icons
|
|
9786
6941
|
};
|
|
9787
6942
|
};
|
|
9788
6943
|
/**
|
|
@@ -9799,8 +6954,7 @@ const deriveUrlPresets = async (url, options = {}) => {
|
|
|
9799
6954
|
const appName = title !== void 0 && title.length > 0 ? title.length > PRESET_TITLE_MAX ? `${title.slice(0, PRESET_TITLE_MAX - 1).trimEnd()}…` : title : void 0;
|
|
9800
6955
|
return {
|
|
9801
6956
|
...appName === void 0 ? {} : { appName },
|
|
9802
|
-
...scraped.iconPath === void 0 ? {} : { appIconPath: scraped.iconPath }
|
|
9803
|
-
...scraped.frameEmbeddable === void 0 ? {} : { frameEmbeddable: scraped.frameEmbeddable }
|
|
6957
|
+
...scraped.iconPath === void 0 ? {} : { appIconPath: scraped.iconPath }
|
|
9804
6958
|
};
|
|
9805
6959
|
};
|
|
9806
6960
|
/**
|
|
@@ -9910,8 +7064,8 @@ const isIcoContainer = (bytes) => bytes.length >= 8 && bytes[0] === 0 && bytes[1
|
|
|
9910
7064
|
* from the decoder's RGBA through the shared kernel encoder.
|
|
9911
7065
|
*/
|
|
9912
7066
|
const extractLargestIcoFrame = async (ico) => {
|
|
9913
|
-
const decodeIco = (await import("./decode-ico-
|
|
9914
|
-
const { toPngBuffer } = await
|
|
7067
|
+
const decodeIco = (await import("./decode-ico-DDEIV7iZ.mjs").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
|
|
7068
|
+
const { toPngBuffer } = await import("./icon-codec-Bs3XehqZ.mjs").then((n) => n.t);
|
|
9915
7069
|
let best;
|
|
9916
7070
|
for (const frame of decodeIco(ico)) {
|
|
9917
7071
|
const width = frame.width;
|
|
@@ -10021,21 +7175,6 @@ const writeIconTemp = async (bytes, dir) => {
|
|
|
10021
7175
|
return path;
|
|
10022
7176
|
};
|
|
10023
7177
|
//#endregion
|
|
10024
|
-
//#region packages/core/src/icon-codec.ts
|
|
10025
|
-
var icon_codec_exports = /* @__PURE__ */ __exportAll$1({ toPngBuffer: () => toPngBuffer });
|
|
10026
|
-
const toPngBuffer = async (rgba, width, height, channels) => {
|
|
10027
|
-
const pixels = width * height;
|
|
10028
|
-
const image = emptyImageOf(width, height);
|
|
10029
|
-
if (channels === 3) for (let i = 0; i < pixels; i += 1) {
|
|
10030
|
-
image.data[i * 4] = rgba[i * 3] ?? 0;
|
|
10031
|
-
image.data[i * 4 + 1] = rgba[i * 3 + 1] ?? 0;
|
|
10032
|
-
image.data[i * 4 + 2] = rgba[i * 3 + 2] ?? 0;
|
|
10033
|
-
image.data[i * 4 + 3] = 255;
|
|
10034
|
-
}
|
|
10035
|
-
else image.data.set(rgba.subarray(0, pixels * 4));
|
|
10036
|
-
return Buffer.from(await encodeImagePng(image));
|
|
10037
|
-
};
|
|
10038
|
-
//#endregion
|
|
10039
7178
|
//#region packages/core/src/command-run.ts
|
|
10040
7179
|
const SHELL_METACHARS = /[<>&|;$`"'%]/u;
|
|
10041
7180
|
/** True when the command line needs a shell (only Windows uses cmd /c). */
|
|
@@ -10160,6 +7299,7 @@ const startCommandRun = async (options) => {
|
|
|
10160
7299
|
}
|
|
10161
7300
|
else if (process.versions.bun !== void 0) options.onEvent({
|
|
10162
7301
|
type: "pty-unavailable",
|
|
7302
|
+
reason: "pty_bun_terminal_missing",
|
|
10163
7303
|
message: "Bun 版本缺少 Bun.Terminal(需要 Bun ≥ 1.2.19),预览以非交互模式运行。"
|
|
10164
7304
|
});
|
|
10165
7305
|
else {
|
|
@@ -10174,6 +7314,7 @@ const startCommandRun = async (options) => {
|
|
|
10174
7314
|
}
|
|
10175
7315
|
else options.onEvent({
|
|
10176
7316
|
type: "pty-unavailable",
|
|
7317
|
+
reason: "pty_node_pty_missing",
|
|
10177
7318
|
message: "node-pty 不可用,预览以非交互模式运行(无法向命令输入内容)。可安装 @lydell/node-pty 启用交互。"
|
|
10178
7319
|
});
|
|
10179
7320
|
}
|
|
@@ -10439,6 +7580,113 @@ const runExecFileCapture = (command, args) => new Promise((resolve, reject) => {
|
|
|
10439
7580
|
});
|
|
10440
7581
|
});
|
|
10441
7582
|
//#endregion
|
|
7583
|
+
//#region packages/core/src/toolbar-carrier.ts
|
|
7584
|
+
/**
|
|
7585
|
+
* The generated-entry helper source. The embedding template supplies
|
|
7586
|
+
* `column`/`fixed`/`grow` (imported from "@opentray/ext-webview" beside
|
|
7587
|
+
* `WebviewExt`) — the carrier deliberately performs no imports of its own so
|
|
7588
|
+
* both templates stay single-import consumers of the facade.
|
|
7589
|
+
*/
|
|
7590
|
+
const toolbarCarrierSource = () => `// Toolbar navigation carrier (add-webview-orchestration plan D12/D13):
|
|
7591
|
+
// composes the native navigation toolbar over one content webview and drives
|
|
7592
|
+
// it through the create-private message channel. Channel failure is an
|
|
7593
|
+
// exposed bug (D12: no fallback path) — errors land in app.log through
|
|
7594
|
+
// options.log instead of being silently swallowed.
|
|
7595
|
+
const attachToolbarCarrier = async (shell, options) => {
|
|
7596
|
+
// Per-child bridge policy (D2): the toolbar page is trusted shell UI and
|
|
7597
|
+
// gets exactly the channel surface; the content webview gets NO policy, so
|
|
7598
|
+
// it is bridgeless regardless of what it loads.
|
|
7599
|
+
await shell.createWebview({
|
|
7600
|
+
id: "toolbar",
|
|
7601
|
+
url: options.toolbarUrl,
|
|
7602
|
+
bridge: { webviewId: true, messageChannels: true },
|
|
7603
|
+
});
|
|
7604
|
+
const content = await shell.createWebview({ id: "content", url: options.contentUrl });
|
|
7605
|
+
// Declarative layered layout (D8 sugar): toolbar pinned at a fixed 44px
|
|
7606
|
+
// height, content filling the remainder; resize is recomputed natively.
|
|
7607
|
+
await shell.setLayout(column([fixed("toolbar", 44), grow("content")]));
|
|
7608
|
+
const channel = await shell.createMessageChannel({ target: "toolbar" });
|
|
7609
|
+
const note = (error) => {
|
|
7610
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7611
|
+
void options.log("toolbar carrier: " + message);
|
|
7612
|
+
};
|
|
7613
|
+
// Address-bar truth (D13): the content webview's urlChange events ARE the
|
|
7614
|
+
// address bar's source of truth — pushed over the channel, never scraped
|
|
7615
|
+
// from a wrapper document.
|
|
7616
|
+
const pushUrl = async (url) => {
|
|
7617
|
+
await channel.post({ kind: "url", url: String(url) });
|
|
7618
|
+
};
|
|
7619
|
+
content.onUrlChange((event) => {
|
|
7620
|
+
void pushUrl(event.url).catch(note);
|
|
7621
|
+
});
|
|
7622
|
+
// Loading affordance input (D24): the content webview's loadState pushes
|
|
7623
|
+
// (phase always; progress/errorCode best-effort) reach the toolbar page
|
|
7624
|
+
// over the same channel. The toolbar page owns the progress-bar state
|
|
7625
|
+
// machine — this carrier forwards verbatim and adds no interpretation, so
|
|
7626
|
+
// a missed "failed" frame (macOS dead-port loads finish about:blank
|
|
7627
|
+
// honestly) is converged by whatever terminal frame does arrive.
|
|
7628
|
+
const pushLoadState = async (event) => {
|
|
7629
|
+
const frame = { kind: "load-state", phase: event.phase, url: String(event.url) };
|
|
7630
|
+
if (typeof event.progress === "number") frame.progress = event.progress;
|
|
7631
|
+
if (typeof event.errorCode === "number") frame.errorCode = event.errorCode;
|
|
7632
|
+
await channel.post(frame);
|
|
7633
|
+
};
|
|
7634
|
+
content.onLoadState((event) => {
|
|
7635
|
+
void pushLoadState(event).catch(note);
|
|
7636
|
+
});
|
|
7637
|
+
if (options.titleFollows === true) {
|
|
7638
|
+
// Sync defaults project onto the CONTENT document (the real target page).
|
|
7639
|
+
// A windowOnly session has no primary webview for native titleSync, and
|
|
7640
|
+
// the v1 frozen facade exposes no host set-title command, so the entry is
|
|
7641
|
+
// the one-way projector through the native re-show title update
|
|
7642
|
+
// (apply_reused_show_updates): show({title, windowOnly}) on an existing
|
|
7643
|
+
// session updates the window title without touching content or
|
|
7644
|
+
// visibility. Icon following stays opt-in and carries no window-level
|
|
7645
|
+
// option here because a bridgeless content child is not a favicon
|
|
7646
|
+
// emitter (documented v1 limitation).
|
|
7647
|
+
const projectTitle = (title) => {
|
|
7648
|
+
if (typeof title === "string" && title.length > 0) {
|
|
7649
|
+
void shell.show({ title, windowOnly: true }).catch(note);
|
|
7650
|
+
}
|
|
7651
|
+
};
|
|
7652
|
+
content.onTitleChange((event) => {
|
|
7653
|
+
projectTitle(event.title);
|
|
7654
|
+
});
|
|
7655
|
+
}
|
|
7656
|
+
// Command surface (D12): instructions and state queries arrive as channel
|
|
7657
|
+
// payloads; back/forward drive the content webview's NATIVE history and
|
|
7658
|
+
// reload re-navigates to the current URL through the native navigate
|
|
7659
|
+
// command (never evaluate(location.reload()) on a wrapper).
|
|
7660
|
+
channel.onMessage((payload) => {
|
|
7661
|
+
const message = typeof payload === "object" && payload !== null ? payload : {};
|
|
7662
|
+
const kind = message.kind;
|
|
7663
|
+
if (kind === "navigate" && typeof message.url === "string" && message.url.length > 0) {
|
|
7664
|
+
void content.navigate(message.url).catch(note);
|
|
7665
|
+
return;
|
|
7666
|
+
}
|
|
7667
|
+
if (kind === "back") {
|
|
7668
|
+
void content.back().catch(note);
|
|
7669
|
+
return;
|
|
7670
|
+
}
|
|
7671
|
+
if (kind === "forward") {
|
|
7672
|
+
void content.forward().catch(note);
|
|
7673
|
+
return;
|
|
7674
|
+
}
|
|
7675
|
+
if (kind === "reload") {
|
|
7676
|
+
void content.getUrl().then((state) => content.navigate(state.url)).catch(note);
|
|
7677
|
+
return;
|
|
7678
|
+
}
|
|
7679
|
+
if (kind === "get-url") {
|
|
7680
|
+
void content.getUrl().then((state) => pushUrl(state.url)).catch(note);
|
|
7681
|
+
}
|
|
7682
|
+
});
|
|
7683
|
+
// Seed the address bar with the current truth (pre-subscription buffering
|
|
7684
|
+
// on both endpoints covers the race before the toolbar page registers).
|
|
7685
|
+
void content.getUrl().then((state) => pushUrl(state.url)).catch(note);
|
|
7686
|
+
return { content, channel };
|
|
7687
|
+
};
|
|
7688
|
+
`;
|
|
7689
|
+
//#endregion
|
|
10442
7690
|
//#region packages/core/src/entry-template.ts
|
|
10443
7691
|
/** The generated app entry: supervises the command, owns tray + window. */
|
|
10444
7692
|
const createEntrySource = (config) => {
|
|
@@ -10454,7 +7702,7 @@ import { dirname, resolve } from "node:path";
|
|
|
10454
7702
|
import { fileURLToPath } from "node:url";
|
|
10455
7703
|
|
|
10456
7704
|
import { createTray } from "opentray";
|
|
10457
|
-
import { WebviewExt } from "@opentray/ext-webview";
|
|
7705
|
+
import { WebviewExt, column, fixed, grow } from "@opentray/ext-webview";
|
|
10458
7706
|
|
|
10459
7707
|
const PROJECT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
10460
7708
|
|
|
@@ -10475,11 +7723,20 @@ const config = ${JSON.stringify(config, null, 2)};
|
|
|
10475
7723
|
const appLogPath = resolve(PROJECT_DIR, "app.log");
|
|
10476
7724
|
await mkdir(dirname(appLogPath), { recursive: true });
|
|
10477
7725
|
const logSink = appendFile.bind(undefined, appLogPath);
|
|
7726
|
+
const logNote = (message) => { void logSink("[create-opentray] " + message + "\\n", "utf8"); };
|
|
10478
7727
|
const sleep = (ms) => new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
|
|
10479
7728
|
|
|
10480
7729
|
const shellOptions = ${JSON.stringify(config.shell ?? null)};
|
|
10481
7730
|
const showTerminal = shellOptions !== null && shellOptions.showTerminal === true;
|
|
10482
|
-
|
|
7731
|
+
// Toolbar carrier (add-webview-orchestration D13): window.toolbar is the one
|
|
7732
|
+
// canonical toolbar fact for BOTH application forms; the retired legacy shell
|
|
7733
|
+
// address-bar input is deliberately not read (stale frozen occurrences are
|
|
7734
|
+
// ignored by loose parsing).
|
|
7735
|
+
const toolbarMode = config.window.toolbar === true;
|
|
7736
|
+
const titleFollows = config.window.titleFollowsDocument !== false;
|
|
7737
|
+
const iconFollows = config.window.iconFollowsDocument === true;
|
|
7738
|
+
|
|
7739
|
+
${toolbarCarrierSource()}
|
|
10483
7740
|
|
|
10484
7741
|
// Configured env overlay (advanced command options); empty by default.
|
|
10485
7742
|
const commandEnv = ${JSON.stringify(config.command.env ?? {})};
|
|
@@ -10551,7 +7808,8 @@ const main = async () => {
|
|
|
10551
7808
|
}
|
|
10552
7809
|
|
|
10553
7810
|
// Shell host (D2): unconditional — the terminal window is every app's
|
|
10554
|
-
// abnormal-exit surface, and the
|
|
7811
|
+
// abnormal-exit surface, and the toolbar carrier's page asset is served
|
|
7812
|
+
// from the same host (its navigation surface stays channel-only, D12).
|
|
10555
7813
|
const shellApi = await import("./app-shell-server.mjs");
|
|
10556
7814
|
const shellPort = await shellApi.listenShell();
|
|
10557
7815
|
|
|
@@ -10651,11 +7909,11 @@ const main = async () => {
|
|
|
10651
7909
|
const devtools = config.developerMode === true ? { devtools: true } : {};
|
|
10652
7910
|
|
|
10653
7911
|
// Dedicated windows: one terminal window (always available; initially
|
|
10654
|
-
// visible only under showTerminal), one window per listened port —
|
|
10655
|
-
//
|
|
10656
|
-
// Each window gets its OWN extension mount (tray.extend per
|
|
10657
|
-
//
|
|
10658
|
-
//
|
|
7912
|
+
// visible only under showTerminal), one window per listened port — the
|
|
7913
|
+
// native toolbar carrier when window.toolbar is on, the direct service URL
|
|
7914
|
+
// otherwise. Each window gets its OWN extension mount (tray.extend per
|
|
7915
|
+
// window = its own window session), so dedicated windows never collide on
|
|
7916
|
+
// content.
|
|
10659
7917
|
const serviceWindows = new Map();
|
|
10660
7918
|
let terminalWindow = null;
|
|
10661
7919
|
|
|
@@ -10688,28 +7946,45 @@ const main = async () => {
|
|
|
10688
7946
|
const ensureServiceWindow = async (port) => {
|
|
10689
7947
|
if (serviceWindows.has(port)) return;
|
|
10690
7948
|
const direct = \`http://127.0.0.1:\${port}\`;
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
7949
|
+
// Toolbar service windows (D13): the SAME native carrier URL applications
|
|
7950
|
+
// use — a windowOnly session whose toolbar webview (shell-served
|
|
7951
|
+
// toolbar page) sits above a content webview loading the verified
|
|
7952
|
+
// service URL directly (no iframe wrapper, no bridge on the content
|
|
7953
|
+
// side, no embedding-policy consultation). Direct service windows keep
|
|
7954
|
+
// the D13 native sync defaults unchanged.
|
|
7955
|
+
if (toolbarMode && shellPort !== null) {
|
|
7956
|
+
const win = tray.extend(WebviewExt).createWebviewWindow({
|
|
7957
|
+
windowOnly: true,
|
|
7958
|
+
width: config.window.width,
|
|
7959
|
+
height: config.window.height,
|
|
7960
|
+
title: baseTitle,
|
|
7961
|
+
style: { appMode: true, autoHide: false, keepOnTop: false },
|
|
7962
|
+
...devtools,
|
|
7963
|
+
});
|
|
7964
|
+
await win.show().catch(() => {});
|
|
7965
|
+
await attachToolbarCarrier(win, {
|
|
7966
|
+
toolbarUrl: \`http://127.0.0.1:\${shellPort}/toolbar.html\`,
|
|
7967
|
+
contentUrl: direct,
|
|
7968
|
+
titleFollows,
|
|
7969
|
+
log: logNote,
|
|
7970
|
+
});
|
|
7971
|
+
serviceWindows.set(port, { win, detached: false });
|
|
7972
|
+
return;
|
|
7973
|
+
}
|
|
10694
7974
|
const win = tray.extend(WebviewExt).createWebviewWindow({
|
|
10695
|
-
url,
|
|
7975
|
+
url: direct,
|
|
10696
7976
|
width: config.window.width,
|
|
10697
7977
|
height: config.window.height,
|
|
10698
7978
|
title: baseTitle,
|
|
10699
7979
|
style: { appMode: true, autoHide: false, keepOnTop: false },
|
|
10700
7980
|
...devtools,
|
|
10701
|
-
...(
|
|
10702
|
-
...(
|
|
7981
|
+
...(!titleFollows ? {} : { titleSync: { documentToWindow: true } }),
|
|
7982
|
+
...(!iconFollows ? {} : { iconSync: { faviconToWindow: true } }),
|
|
10703
7983
|
});
|
|
10704
7984
|
serviceWindows.set(port, { win, detached: false });
|
|
10705
7985
|
await win.show().catch(() => {});
|
|
10706
7986
|
};
|
|
10707
7987
|
|
|
10708
|
-
// D13 sync defaults (address-bar-less service windows): the title follows
|
|
10709
|
-
// the document one-way; runtime favicon following is opt-in only.
|
|
10710
|
-
const titleFollows = config.window.titleFollowsDocument !== false;
|
|
10711
|
-
const iconFollows = config.window.iconFollowsDocument === true;
|
|
10712
|
-
|
|
10713
7988
|
if (showTerminal) {
|
|
10714
7989
|
await ensureTerminalWindow();
|
|
10715
7990
|
}
|
|
@@ -10867,7 +8142,7 @@ main().catch(async (error) => {
|
|
|
10867
8142
|
};
|
|
10868
8143
|
//#endregion
|
|
10869
8144
|
//#region packages/core/src/url-entry-template.ts
|
|
10870
|
-
/** The generated URL app entry: owns tray + one direct or
|
|
8145
|
+
/** The generated URL app entry: owns tray + one direct or toolbar-carrier window. */
|
|
10871
8146
|
const createUrlEntrySource = (config) => {
|
|
10872
8147
|
if (config.url === void 0) throw new Error("URL entry template requires a url source");
|
|
10873
8148
|
return `#!/usr/bin/env node
|
|
@@ -10879,7 +8154,7 @@ import { dirname, resolve } from "node:path";
|
|
|
10879
8154
|
import { fileURLToPath } from "node:url";
|
|
10880
8155
|
|
|
10881
8156
|
import { createTray } from "opentray";
|
|
10882
|
-
import { WebviewExt } from "@opentray/ext-webview";
|
|
8157
|
+
import { WebviewExt, column, fixed, grow } from "@opentray/ext-webview";
|
|
10883
8158
|
|
|
10884
8159
|
const PROJECT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
10885
8160
|
|
|
@@ -10903,8 +8178,9 @@ const iconFollows = config.window.iconFollowsDocument === true;
|
|
|
10903
8178
|
const appLogPath = resolve(PROJECT_DIR, "app.log");
|
|
10904
8179
|
await mkdir(dirname(appLogPath), { recursive: true });
|
|
10905
8180
|
const logSink = appendFile.bind(undefined, appLogPath);
|
|
8181
|
+
const logNote = (message) => { void logSink("[create-opentray] " + message + "\\n", "utf8"); };
|
|
10906
8182
|
|
|
10907
|
-
const main = async () => {
|
|
8183
|
+
${toolbarCarrierSource()}const main = async () => {
|
|
10908
8184
|
let appIcon;
|
|
10909
8185
|
try {
|
|
10910
8186
|
const manifest = JSON.parse(await readFile(resolve(PROJECT_DIR, "app-icon", "app-icon.json"), "utf8"));
|
|
@@ -10954,42 +8230,59 @@ const main = async () => {
|
|
|
10954
8230
|
// must not request devtools at all — default windows are not inspectable.
|
|
10955
8231
|
const devtools = config.developerMode === true ? { devtools: true } : {};
|
|
10956
8232
|
|
|
10957
|
-
// Toolbar
|
|
10958
|
-
//
|
|
10959
|
-
//
|
|
8233
|
+
// Toolbar shell host (D12): the shell server serves the toolbar page (and
|
|
8234
|
+
// nothing else for a URL app — its navigation surface is channel-only);
|
|
8235
|
+
// no PTY is registered because a URL app supervises nothing. This is a
|
|
8236
|
+
// LOCAL transport dependency only — never an embedding-policy fallback
|
|
8237
|
+
// (embedding policy is not consulted at all, D14).
|
|
10960
8238
|
let shellPort = null;
|
|
10961
8239
|
if (toolbarMode) {
|
|
10962
8240
|
const shellApi = await import("./app-shell-server.mjs");
|
|
10963
8241
|
shellPort = await shellApi.listenShell();
|
|
10964
8242
|
if (shellPort === null) {
|
|
10965
|
-
await logSink("[create-opentray] toolbar shell host failed to listen;
|
|
8243
|
+
await logSink("[create-opentray] toolbar shell host failed to listen; opening the direct window\\n", "utf8");
|
|
10966
8244
|
}
|
|
10967
8245
|
}
|
|
10968
|
-
const
|
|
10969
|
-
? \`http://127.0.0.1:\${shellPort}/browse.html?url=\${encodeURIComponent(config.url)}\`
|
|
10970
|
-
: null;
|
|
8246
|
+
const toolbarReady = toolbarMode && shellPort !== null;
|
|
10971
8247
|
|
|
8248
|
+
// Toolbar carrier (D12/D13): windowOnly session composed of the toolbar +
|
|
8249
|
+
// content webviews through attachToolbarCarrier below. Direct mode keeps
|
|
8250
|
+
// the single-webview window with the native sync defaults (D13): the title
|
|
8251
|
+
// follows the document one-way; icon following is opt-in.
|
|
10972
8252
|
const window = tray.extend(WebviewExt).createWebviewWindow({
|
|
10973
|
-
|
|
8253
|
+
...(toolbarReady ? { windowOnly: true } : { url: config.url }),
|
|
10974
8254
|
width: config.window.width,
|
|
10975
8255
|
height: config.window.height,
|
|
10976
8256
|
title: config.appName,
|
|
10977
8257
|
style: { appMode: true, autoHide: false, keepOnTop: false },
|
|
10978
8258
|
...devtools,
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
...(titleFollows ? { titleSync: { documentToWindow: true } } : {}),
|
|
10984
|
-
...(iconFollows ? { iconSync: { faviconToWindow: true } } : {}),
|
|
10985
|
-
}
|
|
10986
|
-
: {}),
|
|
8259
|
+
...(toolbarReady ? {} : {
|
|
8260
|
+
...(titleFollows ? { titleSync: { documentToWindow: true } } : {}),
|
|
8261
|
+
...(iconFollows ? { iconSync: { faviconToWindow: true } } : {}),
|
|
8262
|
+
}),
|
|
10987
8263
|
});
|
|
10988
8264
|
await window.show().catch(() => {});
|
|
10989
8265
|
|
|
10990
|
-
|
|
8266
|
+
let content = null;
|
|
8267
|
+
if (toolbarReady) {
|
|
8268
|
+
({ content } = await attachToolbarCarrier(window, {
|
|
8269
|
+
toolbarUrl: \`http://127.0.0.1:\${shellPort}/toolbar.html\`,
|
|
8270
|
+
contentUrl: config.url,
|
|
8271
|
+
titleFollows,
|
|
8272
|
+
log: logNote,
|
|
8273
|
+
}));
|
|
8274
|
+
}
|
|
8275
|
+
|
|
8276
|
+
// Tray reload (D11): toolbar mode reloads the CONTENT webview natively
|
|
8277
|
+
// (navigate to its current URL — no wrapper evaluate); direct mode reloads
|
|
8278
|
+
// the page in place through the evaluate channel. The app never restarts.
|
|
10991
8279
|
const reload = async () => {
|
|
10992
8280
|
try {
|
|
8281
|
+
if (content !== null) {
|
|
8282
|
+
const { url } = await content.getUrl();
|
|
8283
|
+
await content.navigate(url);
|
|
8284
|
+
return;
|
|
8285
|
+
}
|
|
10993
8286
|
await window.evaluate("location.reload()");
|
|
10994
8287
|
} catch { /* window gone */ }
|
|
10995
8288
|
};
|
|
@@ -11222,14 +8515,14 @@ const writeScaffold = async (options) => {
|
|
|
11222
8515
|
};
|
|
11223
8516
|
};
|
|
11224
8517
|
/**
|
|
11225
|
-
* Locate the adapter-staged shell UI (terminal.html/
|
|
8518
|
+
* Locate the adapter-staged shell UI (terminal.html/toolbar.html + assets).
|
|
11226
8519
|
* Layouts, in order:
|
|
11227
8520
|
* - published create-opentray: `dist/shell` beside the package root (resolved
|
|
11228
8521
|
* through the package self-reference; core is bundled into that dist);
|
|
11229
8522
|
* - source checkout: `<create root>/dist/shell` (built) or the create-webui
|
|
11230
8523
|
* vite output one workspace up.
|
|
11231
8524
|
* Undefined means "no staged assets found" — the entry still runs; only the
|
|
11232
|
-
* optional terminal/
|
|
8525
|
+
* optional terminal/toolbar pages would 404.
|
|
11233
8526
|
*/
|
|
11234
8527
|
const resolveBundledShellAssetsDir = async () => {
|
|
11235
8528
|
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -11538,6 +8831,131 @@ const runPackageManagerInstall = async (options) => {
|
|
|
11538
8831
|
});
|
|
11539
8832
|
};
|
|
11540
8833
|
//#endregion
|
|
8834
|
+
//#region packages/core/src/user-messages.ts
|
|
8835
|
+
const UI_LOCALES = [
|
|
8836
|
+
"zh-CN",
|
|
8837
|
+
"ja",
|
|
8838
|
+
"ko",
|
|
8839
|
+
"en",
|
|
8840
|
+
"ar",
|
|
8841
|
+
"fr",
|
|
8842
|
+
"es",
|
|
8843
|
+
"de",
|
|
8844
|
+
"ru"
|
|
8845
|
+
];
|
|
8846
|
+
/** Resolve a raw header/query value to a catalog locale (case-insensitive). */
|
|
8847
|
+
const resolveUiLocale = (raw) => {
|
|
8848
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
8849
|
+
const exact = UI_LOCALES.find((locale) => locale.toLowerCase() === raw.toLowerCase());
|
|
8850
|
+
if (exact !== void 0) return exact;
|
|
8851
|
+
const base = raw.toLowerCase().split("-")[0];
|
|
8852
|
+
return UI_LOCALES.find((locale) => locale.toLowerCase().split("-")[0] === base) ?? (base === "zh" ? "zh-CN" : void 0);
|
|
8853
|
+
};
|
|
8854
|
+
const CATALOGS = {
|
|
8855
|
+
en: {
|
|
8856
|
+
pinHintDarwin: "After opening the app for the first time, right-click its Dock icon and choose “Options → Keep in Dock” to pin it.",
|
|
8857
|
+
pinHintWindows: "Right-click the app's taskbar icon and choose “Pin to taskbar”. (OpenTray does not generate Start-menu shortcuts yet)",
|
|
8858
|
+
pinHintOther: "Pin the app window to the taskbar/favorites; Linux desktop shortcut generation is not provided yet.",
|
|
8859
|
+
ptyBunTerminalMissing: "This Bun build lacks Bun.Terminal (Bun ≥ 1.2.19 required); the preview runs non-interactively.",
|
|
8860
|
+
ptyNodePtyMissing: "node-pty is unavailable, so the preview runs non-interactively (you cannot type into the command). Install @lydell/node-pty to enable interaction.",
|
|
8861
|
+
dirOccupiedSuffix: " — enable “Force overwrite” under Advanced options and retry, or pick another directory",
|
|
8862
|
+
urlInvalid: "Invalid URL: a full http(s) address is required",
|
|
8863
|
+
urlSchemeUnsupported: "URLs must use http(s)",
|
|
8864
|
+
argvProgramRequired: "Array mode needs at least the program element (the first argument)"
|
|
8865
|
+
},
|
|
8866
|
+
"zh-CN": {
|
|
8867
|
+
pinHintDarwin: "首次打开应用后,右键点击 Dock 中的应用图标,选择“选项 → 在程序坞中保留”,即可固定到 Dock。",
|
|
8868
|
+
pinHintWindows: "右键点击任务栏中的应用图标,选择“固定到任务栏”即可固定。(OpenTray 尚未生成开始菜单快捷方式)",
|
|
8869
|
+
pinHintOther: "可将应用窗口固定到任务栏/收藏夹;Linux 桌面快捷方式生成尚未提供。",
|
|
8870
|
+
ptyBunTerminalMissing: "Bun 版本缺少 Bun.Terminal(需要 Bun ≥ 1.2.19),预览以非交互模式运行。",
|
|
8871
|
+
ptyNodePtyMissing: "node-pty 不可用,预览以非交互模式运行(无法向命令输入内容)。可安装 @lydell/node-pty 启用交互。",
|
|
8872
|
+
dirOccupiedSuffix: ";可在「高级选项」中开启 强制覆盖 后重试",
|
|
8873
|
+
urlInvalid: "URL 无效:需要完整的 http(s) 地址",
|
|
8874
|
+
urlSchemeUnsupported: "URL 仅支持 http(s) 地址",
|
|
8875
|
+
argvProgramRequired: "数组模式至少需要程序元素(第一个参数)"
|
|
8876
|
+
},
|
|
8877
|
+
ja: {
|
|
8878
|
+
pinHintDarwin: "初回起動後、Dock のアプリアイコンを右クリックし「オプション → Dock に保管」で固定できます。",
|
|
8879
|
+
pinHintWindows: "タスクバーのアプリアイコンを右クリックし「タスクバーにピン留め」で固定できます。(スタートメニューのショートカット生成には未対応)",
|
|
8880
|
+
pinHintOther: "アプリウィンドウはタスクバー/お気に入りに固定できます。Linux デスクトップのショートカット生成は未提供です。",
|
|
8881
|
+
ptyBunTerminalMissing: "この Bun には Bun.Terminal がありません(Bun ≥ 1.2.19 が必要)。プレビューは非対話モードで動作します。",
|
|
8882
|
+
ptyNodePtyMissing: "node-pty を利用できないため、プレビューは非対話モードで動作します(コマンドに入力できません)。@lydell/node-pty をインストールすると対話できます。",
|
|
8883
|
+
dirOccupiedSuffix: " — 「詳細オプション」で 強制上書き を有効にして再試行するか、別のディレクトリを選択してください",
|
|
8884
|
+
urlInvalid: "URL が無効です:完全な http(s) アドレスが必要です",
|
|
8885
|
+
urlSchemeUnsupported: "URL は http(s) のみ対応しています",
|
|
8886
|
+
argvProgramRequired: "配列モードにはプログラム要素(先頭の引数)が必須です"
|
|
8887
|
+
},
|
|
8888
|
+
ko: {
|
|
8889
|
+
pinHintDarwin: "앱을 처음 연 후 Dock의 앱 아이콘을 우클릭하고 “옵션 → Dock에 유지”를 선택하면 고정됩니다.",
|
|
8890
|
+
pinHintWindows: "작업표시줄의 앱 아이콘을 우클릭하고 “작업표시줄에 고정”을 선택하세요. (시작 메뉴 바로 가기 생성은 아직 미지원)",
|
|
8891
|
+
pinHintOther: "앱 창을 작업표시줄/즐겨찾기에 고정할 수 있습니다. Linux 바탕화면 바로 가기 생성은 아직 제공되지 않습니다.",
|
|
8892
|
+
ptyBunTerminalMissing: "이 Bun 빌드에는 Bun.Terminal이 없습니다(Bun ≥ 1.2.19 필요). 미리보기는 비대화형으로 실행됩니다.",
|
|
8893
|
+
ptyNodePtyMissing: "node-pty를 사용할 수 없어 미리보기가 비대화형으로 실행됩니다(명령에 입력할 수 없음). @lydell/node-pty를 설치하면 대화형으로 사용할 수 있습니다.",
|
|
8894
|
+
dirOccupiedSuffix: " — “고급 옵션”에서 강제 덮어쓰기를 켜고 다시 시도하거나 다른 디렉터리를 선택하세요",
|
|
8895
|
+
urlInvalid: "잘못된 URL: 전체 http(s) 주소가 필요합니다",
|
|
8896
|
+
urlSchemeUnsupported: "URL은 http(s)만 지원합니다",
|
|
8897
|
+
argvProgramRequired: "배열 모드에는 프로그램 요소(첫 번째 인자)가 필요합니다"
|
|
8898
|
+
},
|
|
8899
|
+
ar: {
|
|
8900
|
+
pinHintDarwin: "بعد أول تشغيل للتطبيق، انقر بزر الفأرة الأيمن على أيقونته في Dock واختر «خيارات → الاحتفاظ في Dock» لتثبيتها.",
|
|
8901
|
+
pinHintWindows: "انقر بزر الفأرة الأيمن على أيقونة التطبيق في شريط المهام واختر «تثبيت في شريط المهام». (لم يوفر OpenTray اختصارات قائمة ابدأ بعد)",
|
|
8902
|
+
pinHintOther: "يمكن تثبيت نافذة التطبيق في شريط المهام/المفضلة؛ ولم تُوفَّر أداة إنشاء اختصارات سطح المكتب في Linux بعد.",
|
|
8903
|
+
ptyBunTerminalMissing: "هذا الإصدار من Bun يفتقد Bun.Terminal (يلزم Bun ≥ 1.2.19)؛ يعمل المعاينة في وضع غير تفاعلي.",
|
|
8904
|
+
ptyNodePtyMissing: "node-pty غير متاح، لذا تعمل المعاينة في وضع غير تفاعلي (لا يمكن الكتابة إلى الأمر). ثبّت @lydell/node-pty لتمكين التفاعل.",
|
|
8905
|
+
dirOccupiedSuffix: " — فعّل «الكتابة فوق بالقوة» في الخيارات المتقدمة وأعد المحاولة، أو اختر دليلًا آخر",
|
|
8906
|
+
urlInvalid: "عنوان URL غير صالح: يلزم عنوان http(s) كامل",
|
|
8907
|
+
urlSchemeUnsupported: "يدعم URL مخطط http(s) فقط",
|
|
8908
|
+
argvProgramRequired: "يتطلب وضع المصفوفة عنصر البرنامج (الوسيطة الأولى) على الأقل"
|
|
8909
|
+
},
|
|
8910
|
+
fr: {
|
|
8911
|
+
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.",
|
|
8912
|
+
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)",
|
|
8913
|
+
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.",
|
|
8914
|
+
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.",
|
|
8915
|
+
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.",
|
|
8916
|
+
dirOccupiedSuffix: " — activez « Écrasement forcé » dans les options avancées et réessayez, ou choisissez un autre répertoire",
|
|
8917
|
+
urlInvalid: "URL invalide : une adresse http(s) complète est requise",
|
|
8918
|
+
urlSchemeUnsupported: "Les URL doivent utiliser http(s)",
|
|
8919
|
+
argvProgramRequired: "Le mode tableau exige au moins l'élément programme (le premier argument)"
|
|
8920
|
+
},
|
|
8921
|
+
es: {
|
|
8922
|
+
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.",
|
|
8923
|
+
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)",
|
|
8924
|
+
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.",
|
|
8925
|
+
ptyBunTerminalMissing: "Esta build de Bun carece de Bun.Terminal (se necesita Bun ≥ 1.2.19); la vista previa se ejecuta en modo no interactivo.",
|
|
8926
|
+
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.",
|
|
8927
|
+
dirOccupiedSuffix: " — activa «Sobrescritura forzada» en las opciones avanzadas y reintenta, o elige otro directorio",
|
|
8928
|
+
urlInvalid: "URL no válida: se requiere una dirección http(s) completa",
|
|
8929
|
+
urlSchemeUnsupported: "Las URL deben usar http(s)",
|
|
8930
|
+
argvProgramRequired: "El modo array necesita al menos el elemento programa (el primer argumento)"
|
|
8931
|
+
},
|
|
8932
|
+
de: {
|
|
8933
|
+
pinHintDarwin: "Nach dem ersten Öffnen der App rechts auf ihr Dock-Symbol klicken und „Optionen → Im Dock behalten“ wählen, um sie zu halten.",
|
|
8934
|
+
pinHintWindows: "Rechts auf das App-Symbol in der Taskleiste klicken und „An Taskleiste anheften“ wählen. (OpenTray erzeugt noch keine Startmenü-Verknüpfungen)",
|
|
8935
|
+
pinHintOther: "Das App-Fenster lässt sich an Taskleiste/Favoriten anheften; Linux-Desktop-Verknüpfungen werden noch nicht erzeugt.",
|
|
8936
|
+
ptyBunTerminalMissing: "Dieser Bun-Build fehlt Bun.Terminal (Bun ≥ 1.2.19 erforderlich); die Vorschau läuft nicht interaktiv.",
|
|
8937
|
+
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.",
|
|
8938
|
+
dirOccupiedSuffix: " — aktiviere „Erzwungenes Überschreiben“ in den erweiterten Optionen und versuche es erneut, oder wähle ein anderes Verzeichnis",
|
|
8939
|
+
urlInvalid: "Ungültige URL: eine vollständige http(s)-Adresse ist erforderlich",
|
|
8940
|
+
urlSchemeUnsupported: "URLs müssen http(s) verwenden",
|
|
8941
|
+
argvProgramRequired: "Der Array-Modus braucht mindestens das Programmelement (das erste Argument)"
|
|
8942
|
+
},
|
|
8943
|
+
ru: {
|
|
8944
|
+
pinHintDarwin: "После первого запуска приложения кликните правой кнопкой по его значку в Dock и выберите «Параметры → Оставить в Dock».",
|
|
8945
|
+
pinHintWindows: "Кликните правой кнопкой по значку приложения на панели задач и выберите «Закрепить на панели задач». (OpenTray пока не создаёт ярлыки в меню «Пуск»)",
|
|
8946
|
+
pinHintOther: "Окно приложения можно закрепить на панели задач/в избранном; создание ярлыков рабочего стола Linux пока не предусмотрено.",
|
|
8947
|
+
ptyBunTerminalMissing: "В этой сборке Bun нет Bun.Terminal (нужен Bun ≥ 1.2.19); предпросмотр работает в неинтерактивном режиме.",
|
|
8948
|
+
ptyNodePtyMissing: "node-pty недоступен, поэтому предпросмотр работает в неинтерактивном режиме (ввести данные в команду нельзя). Установите @lydell/node-pty для интерактивности.",
|
|
8949
|
+
dirOccupiedSuffix: " — включите «Принудительную перезапись» в расширенных настройках и повторите либо выберите другой каталог",
|
|
8950
|
+
urlInvalid: "Некорректный URL: требуется полный http(s)-адрес",
|
|
8951
|
+
urlSchemeUnsupported: "URL поддерживает только http(s)",
|
|
8952
|
+
argvProgramRequired: "В режиме массива нужен хотя бы элемент программы (первый аргумент)"
|
|
8953
|
+
}
|
|
8954
|
+
};
|
|
8955
|
+
const userMessages = (locale) => CATALOGS[locale];
|
|
8956
|
+
/** Localized text for the machine-readable pty-unavailable event codes. */
|
|
8957
|
+
const ptyUnavailableMessage = (code, locale) => code === "pty_bun_terminal_missing" ? CATALOGS[locale].ptyBunTerminalMissing : CATALOGS[locale].ptyNodePtyMissing;
|
|
8958
|
+
//#endregion
|
|
11541
8959
|
//#region packages/core/src/open-app.ts
|
|
11542
8960
|
/** The generated entry embeds a native PTY: it needs Node, never a Bun host. */
|
|
11543
8961
|
const nodeExecutable = () => {
|
|
@@ -11607,11 +9025,16 @@ const openMaterializedApp = async (input) => {
|
|
|
11607
9025
|
}
|
|
11608
9026
|
return spawnEntryCold(input.projectDir);
|
|
11609
9027
|
};
|
|
11610
|
-
/**
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
9028
|
+
/**
|
|
9029
|
+
* Platform-truthful pinning hint; makes no persistence claim before first
|
|
9030
|
+
* open. `locale` localizes the wizard/webui projection; the default keeps
|
|
9031
|
+
* direct core consumers (CLI) on their historical output.
|
|
9032
|
+
*/
|
|
9033
|
+
const pinningHint = (platform = process.platform, locale = "zh-CN") => {
|
|
9034
|
+
const messages = userMessages(locale);
|
|
9035
|
+
if (platform === "darwin") return messages.pinHintDarwin;
|
|
9036
|
+
if (platform === "win32") return messages.pinHintWindows;
|
|
9037
|
+
return messages.pinHintOther;
|
|
11615
9038
|
};
|
|
11616
9039
|
//#endregion
|
|
11617
9040
|
//#region packages/core/src/errors.ts
|
|
@@ -16372,7 +13795,8 @@ const readWizardProjectConfig = async (projectDir) => {
|
|
|
16372
13795
|
const url = typeof raw.url === "string" ? raw.url : void 0;
|
|
16373
13796
|
const window = isRecord(raw.window) ? {
|
|
16374
13797
|
width: Number.isFinite(raw.window.width) ? Number(raw.window.width) : 1200,
|
|
16375
|
-
height: Number.isFinite(raw.window.height) ? Number(raw.window.height) : 800
|
|
13798
|
+
height: Number.isFinite(raw.window.height) ? Number(raw.window.height) : 800,
|
|
13799
|
+
...raw.window.toolbar === true ? { toolbar: true } : {}
|
|
16376
13800
|
} : {
|
|
16377
13801
|
width: 1200,
|
|
16378
13802
|
height: 800
|
|
@@ -17291,9 +14715,9 @@ const createWizardSession = (options) => {
|
|
|
17291
14715
|
let currentTokens = [];
|
|
17292
14716
|
let currentCommand = "";
|
|
17293
14717
|
let urlSource;
|
|
17294
|
-
let urlFrameEmbeddable;
|
|
17295
14718
|
let scrapedTitle;
|
|
17296
14719
|
let interactive = true;
|
|
14720
|
+
let uiLocale = "zh-CN";
|
|
17297
14721
|
let resolvedVector;
|
|
17298
14722
|
let frozenForm;
|
|
17299
14723
|
let resolvedServicePort;
|
|
@@ -17317,7 +14741,7 @@ const createWizardSession = (options) => {
|
|
|
17317
14741
|
pm: false,
|
|
17318
14742
|
force: false,
|
|
17319
14743
|
showStartupTerminal: false,
|
|
17320
|
-
|
|
14744
|
+
toolbar: false,
|
|
17321
14745
|
imageSmoothingEnabled: false,
|
|
17322
14746
|
developerMode: false
|
|
17323
14747
|
};
|
|
@@ -17330,7 +14754,7 @@ const createWizardSession = (options) => {
|
|
|
17330
14754
|
trayIconPath: "",
|
|
17331
14755
|
force: options.force === true,
|
|
17332
14756
|
showStartupTerminal: false,
|
|
17333
|
-
|
|
14757
|
+
toolbar: false,
|
|
17334
14758
|
imageSmoothingEnabled: true,
|
|
17335
14759
|
developerMode: false,
|
|
17336
14760
|
pm: options.packageManager ?? detectPackageManager([], process.env.npm_config_user_agent)
|
|
@@ -17521,6 +14945,9 @@ const createWizardSession = (options) => {
|
|
|
17521
14945
|
get state() {
|
|
17522
14946
|
return state;
|
|
17523
14947
|
},
|
|
14948
|
+
setLocale(locale) {
|
|
14949
|
+
uiLocale = locale;
|
|
14950
|
+
},
|
|
17524
14951
|
snapshot() {
|
|
17525
14952
|
return {
|
|
17526
14953
|
type: "snapshot",
|
|
@@ -17673,7 +15100,6 @@ const createWizardSession = (options) => {
|
|
|
17673
15100
|
const trimmed = url.trim();
|
|
17674
15101
|
if (trimmed.length === 0) {
|
|
17675
15102
|
urlSource = void 0;
|
|
17676
|
-
urlFrameEmbeddable = void 0;
|
|
17677
15103
|
scrapedTitle = void 0;
|
|
17678
15104
|
iconCandidates = [];
|
|
17679
15105
|
iconPort = void 0;
|
|
@@ -17690,11 +15116,11 @@ const createWizardSession = (options) => {
|
|
|
17690
15116
|
try {
|
|
17691
15117
|
parsed = new URL(trimmed);
|
|
17692
15118
|
} catch {
|
|
17693
|
-
setState("failed",
|
|
15119
|
+
setState("failed", userMessages(uiLocale).urlInvalid);
|
|
17694
15120
|
return;
|
|
17695
15121
|
}
|
|
17696
15122
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
17697
|
-
setState("failed",
|
|
15123
|
+
setState("failed", userMessages(uiLocale).urlSchemeUnsupported);
|
|
17698
15124
|
return;
|
|
17699
15125
|
}
|
|
17700
15126
|
urlSource = parsed.href;
|
|
@@ -17711,7 +15137,6 @@ const createWizardSession = (options) => {
|
|
|
17711
15137
|
currentIconPath = scraped.ok ? scraped.icons[0]?.path : void 0;
|
|
17712
15138
|
currentIconUrl = scraped.ok ? scraped.icons[0]?.url : void 0;
|
|
17713
15139
|
scrapedTitle = scraped.ok ? scraped.title : void 0;
|
|
17714
|
-
urlFrameEmbeddable = scraped.ok ? scraped.frameEmbeddable : void 0;
|
|
17715
15140
|
stopTimers();
|
|
17716
15141
|
setState("discovered");
|
|
17717
15142
|
emit({
|
|
@@ -17744,7 +15169,7 @@ const createWizardSession = (options) => {
|
|
|
17744
15169
|
}
|
|
17745
15170
|
} else if (tokens.length === 0 || tokens[0].trim().length === 0) {
|
|
17746
15171
|
submitting = false;
|
|
17747
|
-
setState("failed",
|
|
15172
|
+
setState("failed", userMessages(uiLocale).argvProgramRequired);
|
|
17748
15173
|
return;
|
|
17749
15174
|
}
|
|
17750
15175
|
const pendingTokens = tokens ?? tokenized.tokens;
|
|
@@ -17786,7 +15211,7 @@ const createWizardSession = (options) => {
|
|
|
17786
15211
|
...touched.force ? { force: form.force } : { force: options.force === true },
|
|
17787
15212
|
...touched.trayIconPath ? { trayIconPath: form.trayIconPath } : { trayIconPath: "" },
|
|
17788
15213
|
...touched.showStartupTerminal ? { showStartupTerminal: form.showStartupTerminal } : { showStartupTerminal: false },
|
|
17789
|
-
...touched.
|
|
15214
|
+
...touched.toolbar ? { toolbar: form.toolbar } : { toolbar: false },
|
|
17790
15215
|
...touched.imageSmoothingEnabled ? { imageSmoothingEnabled: form.imageSmoothingEnabled } : { imageSmoothingEnabled: true },
|
|
17791
15216
|
...touched.developerMode ? { developerMode: form.developerMode } : { developerMode: false },
|
|
17792
15217
|
pm: options.packageManager ?? detectPackageManager([], process.env.npm_config_user_agent)
|
|
@@ -17826,10 +15251,11 @@ const createWizardSession = (options) => {
|
|
|
17826
15251
|
}
|
|
17827
15252
|
if (event.type === "pty-unavailable") {
|
|
17828
15253
|
interactive = false;
|
|
15254
|
+
const message = event.reason !== void 0 ? ptyUnavailableMessage(event.reason, uiLocale) : event.message;
|
|
17829
15255
|
emit({
|
|
17830
15256
|
type: "term-mode",
|
|
17831
15257
|
interactive: false,
|
|
17832
|
-
...
|
|
15258
|
+
...message === void 0 ? {} : { message }
|
|
17833
15259
|
});
|
|
17834
15260
|
return;
|
|
17835
15261
|
}
|
|
@@ -18133,7 +15559,7 @@ const createWizardSession = (options) => {
|
|
|
18133
15559
|
window: {
|
|
18134
15560
|
width: 1200,
|
|
18135
15561
|
height: 800,
|
|
18136
|
-
...frozen.
|
|
15562
|
+
...frozen.toolbar === true ? { toolbar: true } : {},
|
|
18137
15563
|
titleFollowsDocument: true,
|
|
18138
15564
|
iconFollowsDocument: false
|
|
18139
15565
|
}
|
|
@@ -18147,6 +15573,7 @@ const createWizardSession = (options) => {
|
|
|
18147
15573
|
window: {
|
|
18148
15574
|
width: 1200,
|
|
18149
15575
|
height: 800,
|
|
15576
|
+
...frozen.toolbar === true ? { toolbar: true } : {},
|
|
18150
15577
|
titleFollowsDocument: true,
|
|
18151
15578
|
iconFollowsDocument: false
|
|
18152
15579
|
}
|
|
@@ -18220,12 +15647,6 @@ const createWizardSession = (options) => {
|
|
|
18220
15647
|
run = void 0;
|
|
18221
15648
|
}
|
|
18222
15649
|
if (urlSource !== void 0) {
|
|
18223
|
-
const toolbarWanted = frozen.showAddressBar === true;
|
|
18224
|
-
const toolbar = toolbarWanted && urlFrameEmbeddable !== false;
|
|
18225
|
-
if (toolbarWanted && !toolbar) emit({
|
|
18226
|
-
type: "materialize-log",
|
|
18227
|
-
message: `warning: ${urlSource} forbids iframe embedding (X-Frame-Options / CSP frame-ancestors); the address bar falls back to the direct window`
|
|
18228
|
-
});
|
|
18229
15650
|
try {
|
|
18230
15651
|
result = await materialize({
|
|
18231
15652
|
config: {
|
|
@@ -18237,7 +15658,7 @@ const createWizardSession = (options) => {
|
|
|
18237
15658
|
window: {
|
|
18238
15659
|
width: 1200,
|
|
18239
15660
|
height: 800,
|
|
18240
|
-
...toolbar ? { toolbar: true } : {},
|
|
15661
|
+
...frozen.toolbar === true ? { toolbar: true } : {},
|
|
18241
15662
|
titleFollowsDocument: true,
|
|
18242
15663
|
iconFollowsDocument: false
|
|
18243
15664
|
},
|
|
@@ -18277,12 +15698,12 @@ const createWizardSession = (options) => {
|
|
|
18277
15698
|
emit({
|
|
18278
15699
|
type: "success",
|
|
18279
15700
|
projectDir: result.projectDir,
|
|
18280
|
-
pinHint: pinningHint()
|
|
15701
|
+
pinHint: pinningHint(process.platform, uiLocale)
|
|
18281
15702
|
});
|
|
18282
15703
|
} catch (error) {
|
|
18283
15704
|
const message = error instanceof Error ? error.message : String(error);
|
|
18284
15705
|
const occupied = message.includes("target directory is not empty");
|
|
18285
|
-
setState("failed", occupied ? `${message}
|
|
15706
|
+
setState("failed", occupied ? `${message}${userMessages(uiLocale).dirOccupiedSuffix}` : message);
|
|
18286
15707
|
}
|
|
18287
15708
|
return;
|
|
18288
15709
|
}
|
|
@@ -18311,6 +15732,7 @@ const createWizardSession = (options) => {
|
|
|
18311
15732
|
window: {
|
|
18312
15733
|
width: 1200,
|
|
18313
15734
|
height: 800,
|
|
15735
|
+
...frozen.toolbar === true ? { toolbar: true } : {},
|
|
18314
15736
|
titleFollowsDocument: true,
|
|
18315
15737
|
iconFollowsDocument: false
|
|
18316
15738
|
},
|
|
@@ -18323,10 +15745,7 @@ const createWizardSession = (options) => {
|
|
|
18323
15745
|
...frozen.iconScale === void 0 ? {} : { iconScale: frozen.iconScale },
|
|
18324
15746
|
...currentTrayIconPath === void 0 ? {} : { trayIconSourcePath: currentTrayIconPath },
|
|
18325
15747
|
...trayIconIsSolid ? { trayIconIsSolid: true } : {},
|
|
18326
|
-
shell: {
|
|
18327
|
-
showTerminal: frozen.showStartupTerminal,
|
|
18328
|
-
showAddressBar: frozen.showAddressBar
|
|
18329
|
-
},
|
|
15748
|
+
shell: { showTerminal: frozen.showStartupTerminal },
|
|
18330
15749
|
...frozen.imageSmoothingEnabled === false ? { imageSmoothingEnabled: false } : {},
|
|
18331
15750
|
...frozen.developerMode === true ? { developerMode: true } : {},
|
|
18332
15751
|
packageManager: frozen.pm,
|
|
@@ -18354,12 +15773,12 @@ const createWizardSession = (options) => {
|
|
|
18354
15773
|
emit({
|
|
18355
15774
|
type: "success",
|
|
18356
15775
|
projectDir: result.projectDir,
|
|
18357
|
-
pinHint: pinningHint()
|
|
15776
|
+
pinHint: pinningHint(process.platform, uiLocale)
|
|
18358
15777
|
});
|
|
18359
15778
|
} catch (error) {
|
|
18360
15779
|
const message = error instanceof Error ? error.message : String(error);
|
|
18361
15780
|
const occupied = message.includes("target directory is not empty");
|
|
18362
|
-
setState("failed", occupied ? `${message}
|
|
15781
|
+
setState("failed", occupied ? `${message}${userMessages(uiLocale).dirOccupiedSuffix}` : message);
|
|
18363
15782
|
}
|
|
18364
15783
|
},
|
|
18365
15784
|
async stop() {
|
|
@@ -18530,6 +15949,7 @@ const handleWorkbenchApi = async (request) => {
|
|
|
18530
15949
|
window: {
|
|
18531
15950
|
width: entry.config.window.width,
|
|
18532
15951
|
height: entry.config.window.height,
|
|
15952
|
+
...entry.config.window.toolbar === true ? { toolbar: true } : {},
|
|
18533
15953
|
titleFollowsDocument: true,
|
|
18534
15954
|
iconFollowsDocument: false
|
|
18535
15955
|
},
|
|
@@ -18697,6 +16117,7 @@ const handleWorkbenchApi = async (request) => {
|
|
|
18697
16117
|
window: {
|
|
18698
16118
|
width: entry.config.window.width,
|
|
18699
16119
|
height: entry.config.window.height,
|
|
16120
|
+
...entry.config.window.toolbar === true ? { toolbar: true } : {},
|
|
18700
16121
|
titleFollowsDocument: true,
|
|
18701
16122
|
iconFollowsDocument: false
|
|
18702
16123
|
},
|
|
@@ -18949,6 +16370,8 @@ const createWizardServer = async (createSession, options = {}) => {
|
|
|
18949
16370
|
respond(response, 401, "text/plain", "unauthorized\n");
|
|
18950
16371
|
return;
|
|
18951
16372
|
}
|
|
16373
|
+
const streamLocale = resolveUiLocale(url.searchParams.get("lang"));
|
|
16374
|
+
if (streamLocale !== void 0) session.setLocale(streamLocale);
|
|
18952
16375
|
response.writeHead(200, {
|
|
18953
16376
|
"content-type": "text/event-stream",
|
|
18954
16377
|
"cache-control": "no-cache",
|
|
@@ -19044,6 +16467,9 @@ const createWizardServer = async (createSession, options = {}) => {
|
|
|
19044
16467
|
respond(response, 403, "application/json", "{\"error\":\"forbidden host\"}\n");
|
|
19045
16468
|
return;
|
|
19046
16469
|
}
|
|
16470
|
+
const headerLocale = request.headers["x-opentray-locale"];
|
|
16471
|
+
const requestLocale = resolveUiLocale(Array.isArray(headerLocale) ? headerLocale[0] : headerLocale);
|
|
16472
|
+
if (requestLocale !== void 0) session.setLocale(requestLocale);
|
|
19047
16473
|
if (url.pathname === "/api/apps" || url.pathname.startsWith("/api/apps/") || url.pathname === "/api/skill" || url.pathname === "/api/skill/list") {
|
|
19048
16474
|
let body = {};
|
|
19049
16475
|
if (request.method === "POST") body = await readJsonBody(request);
|
|
@@ -19401,7 +16827,7 @@ const handleApi = async (pathname, request, response, session, preReadBody) => {
|
|
|
19401
16827
|
if (typeof body.iconScale === "number" && body.iconScale >= .5 && body.iconScale <= .95) patch.iconScale = body.iconScale;
|
|
19402
16828
|
for (const key of [
|
|
19403
16829
|
"showStartupTerminal",
|
|
19404
|
-
"
|
|
16830
|
+
"toolbar",
|
|
19405
16831
|
"imageSmoothingEnabled",
|
|
19406
16832
|
"developerMode",
|
|
19407
16833
|
"force"
|
|
@@ -20004,17 +17430,11 @@ const runCreate = async (args, context) => {
|
|
|
20004
17430
|
}
|
|
20005
17431
|
let enrichment;
|
|
20006
17432
|
let presetIconPath;
|
|
20007
|
-
|
|
20008
|
-
if (args.url !== void 0 && args.scrape !== false && (args.appName === void 0 || args.appIcon === void 0 || toolbarRequested)) {
|
|
17433
|
+
if (args.url !== void 0 && args.scrape !== false && (args.appName === void 0 || args.appIcon === void 0)) {
|
|
20009
17434
|
const presets = await deriveUrlPresets(args.url);
|
|
20010
17435
|
enrichment = presets;
|
|
20011
17436
|
presetIconPath = presets.appIconPath;
|
|
20012
17437
|
if (presets.appName !== void 0 || presets.appIconPath !== void 0) emitProgress(`scraped defaults from ${args.url}: ${[presets.appName !== void 0 ? "title" : void 0, presets.appIconPath !== void 0 ? "favicon" : void 0].filter(Boolean).join(" + ")} (defaults; explicit flags win)`, context.streams, args.json === true);
|
|
20013
|
-
if (toolbarRequested && presets.frameEmbeddable === false) {
|
|
20014
|
-
toolbarRequested = false;
|
|
20015
|
-
delete flags.toolbar;
|
|
20016
|
-
emitProgress(`warning: ${args.url} forbids iframe embedding (X-Frame-Options / CSP frame-ancestors); falling back to the direct window`, context.streams, args.json === true);
|
|
20017
|
-
}
|
|
20018
17438
|
}
|
|
20019
17439
|
const compiled = await compileDesiredConfig(flags, args.config, cwd, enrichment);
|
|
20020
17440
|
if (!compiled.ok) {
|
|
@@ -20139,7 +17559,7 @@ const createCommand = (context) => ({
|
|
|
20139
17559
|
describe: "window size <width>x<height> (default 1200x800)"
|
|
20140
17560
|
}).option("toolbar", {
|
|
20141
17561
|
type: "boolean",
|
|
20142
|
-
describe: "
|
|
17562
|
+
describe: "compose the native navigation toolbar over the target/service page (URL and command applications; back/forward/reload/address bar)"
|
|
20143
17563
|
}).option("title-follow", {
|
|
20144
17564
|
type: "boolean",
|
|
20145
17565
|
describe: "window title follows document.title (default true; negate with --no-title-follow)"
|
|
@@ -20849,6 +18269,33 @@ const openBrowser = async (url) => {
|
|
|
20849
18269
|
windowsHide: true
|
|
20850
18270
|
}).unref();
|
|
20851
18271
|
};
|
|
18272
|
+
/** Draft form values carry fields across versions — forward only the
|
|
18273
|
+
* known-safe, type-checked subset. Retired fields (the legacy
|
|
18274
|
+
* showAddressBar, replaced by `toolbar` in add-webview-orchestration D13)
|
|
18275
|
+
* are ignored here: a stale draft never resurrects a removed input.
|
|
18276
|
+
* Exported for tests alongside parseWizardCli. */
|
|
18277
|
+
const normalizeDraftForm = (raw) => {
|
|
18278
|
+
if (typeof raw !== "object" || raw === null) return;
|
|
18279
|
+
const source = raw;
|
|
18280
|
+
const patch = {};
|
|
18281
|
+
for (const key of [
|
|
18282
|
+
"appId",
|
|
18283
|
+
"appName",
|
|
18284
|
+
"iconPath",
|
|
18285
|
+
"trayIconPath"
|
|
18286
|
+
]) if (typeof source[key] === "string") patch[key] = source[key];
|
|
18287
|
+
if (source.pm === "npm" || source.pm === "pnpm" || source.pm === "bun") patch.pm = source.pm;
|
|
18288
|
+
if (source.iconBackground === "black" || source.iconBackground === "white" || source.iconBackground === "transparent") patch.iconBackground = source.iconBackground;
|
|
18289
|
+
if (typeof source.iconScale === "number" && source.iconScale >= .5 && source.iconScale <= .95) patch.iconScale = source.iconScale;
|
|
18290
|
+
for (const key of [
|
|
18291
|
+
"showStartupTerminal",
|
|
18292
|
+
"toolbar",
|
|
18293
|
+
"imageSmoothingEnabled",
|
|
18294
|
+
"developerMode",
|
|
18295
|
+
"force"
|
|
18296
|
+
]) if (typeof source[key] === "boolean") patch[key] = source[key];
|
|
18297
|
+
return Object.keys(patch).length > 0 ? patch : void 0;
|
|
18298
|
+
};
|
|
20852
18299
|
const runWebAdapter = async (options) => {
|
|
20853
18300
|
ensureLoopbackNoProxy();
|
|
20854
18301
|
const invocationDir = process.env.INIT_CWD || process.cwd();
|
|
@@ -20876,9 +18323,10 @@ const runWebAdapter = async (options) => {
|
|
|
20876
18323
|
const raw = await readFile(join(tmpdir(), `create-opentray-draft-${port ?? 0}.json`), "utf8");
|
|
20877
18324
|
const parsed = JSON.parse(raw);
|
|
20878
18325
|
const commandOptions = normalizeDraftCommandOptions(parsed.commandOptions);
|
|
20879
|
-
|
|
18326
|
+
const form = parsed.form === void 0 ? void 0 : normalizeDraftForm(parsed.form);
|
|
18327
|
+
if (form === void 0 && parsed.command === void 0 && commandOptions === void 0) return;
|
|
20880
18328
|
return {
|
|
20881
|
-
form
|
|
18329
|
+
form,
|
|
20882
18330
|
command: parsed.command,
|
|
20883
18331
|
commandOptions
|
|
20884
18332
|
};
|
|
@@ -20955,6 +18403,6 @@ if (isMainModule()) main(process.argv.slice(2)).then((code) => {
|
|
|
20955
18403
|
process.exitCode = code;
|
|
20956
18404
|
});
|
|
20957
18405
|
//#endregion
|
|
20958
|
-
export {
|
|
18406
|
+
export { resolveLaunchVector as A, parseLsofPorts as C, verifyHttpService as D, serviceUrl as E, isValidAppId as F, toProjectDirectoryName as I, tokenizeCommandLine as M, deriveDefaultAppId as N, waitForTcpPort as O, deriveDefaultAppName as P, createPortDiscovery as S, parsePowerShellPorts as T, extractTitle as _, createWizardServer as a, resolveFaviconUrl as b, createWizardSession as c, detectPackageManager as d, expectedDarwinBundlePath as f, extractFaviconCandidates as g, writeScaffold as h, parseWizardCli as i, resolveOnPath as j, parseShebangInterpreter as k, openMaterializedApp as l, materialize as m, normalizeDraftForm as n, isAuthorized as o, isDirectoryOccupied$1 as p, openBrowser as r, isLoopbackHost as s, main as t, pinningHint as u, faviconCandidateSize as v, parseNetstatPorts as w, scrapeService as x, rankFaviconCandidates as y };
|
|
20959
18407
|
|
|
20960
|
-
//# sourceMappingURL=bin-
|
|
18408
|
+
//# sourceMappingURL=bin-Bz16rwKs.mjs.map
|