emf-converter 4.4.8 → 4.4.10
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/dist/browser.js +200 -102
- package/dist/browser.mjs +200 -102
- package/dist/index.js +204 -106
- package/dist/index.mjs +204 -106
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1367,21 +1367,21 @@ var require_decoder = __commonJS({
|
|
|
1367
1367
|
successiveACState = 0;
|
|
1368
1368
|
}
|
|
1369
1369
|
}
|
|
1370
|
-
function decodeMcu(component2,
|
|
1370
|
+
function decodeMcu(component2, decode4, mcu2, row, col) {
|
|
1371
1371
|
var mcuRow = mcu2 / mcusPerLine | 0;
|
|
1372
1372
|
var mcuCol = mcu2 % mcusPerLine;
|
|
1373
1373
|
var blockRow = mcuRow * component2.v + row;
|
|
1374
1374
|
var blockCol = mcuCol * component2.h + col;
|
|
1375
1375
|
if (component2.blocks[blockRow] === void 0 && opts.tolerantDecoding)
|
|
1376
1376
|
return;
|
|
1377
|
-
|
|
1377
|
+
decode4(component2, component2.blocks[blockRow][blockCol]);
|
|
1378
1378
|
}
|
|
1379
|
-
function decodeBlock(component2,
|
|
1379
|
+
function decodeBlock(component2, decode4, mcu2) {
|
|
1380
1380
|
var blockRow = mcu2 / component2.blocksPerLine | 0;
|
|
1381
1381
|
var blockCol = mcu2 % component2.blocksPerLine;
|
|
1382
1382
|
if (component2.blocks[blockRow] === void 0 && opts.tolerantDecoding)
|
|
1383
1383
|
return;
|
|
1384
|
-
|
|
1384
|
+
decode4(component2, component2.blocks[blockRow][blockCol]);
|
|
1385
1385
|
}
|
|
1386
1386
|
var componentsLength = components.length;
|
|
1387
1387
|
var component, i, j, k, n;
|
|
@@ -2102,12 +2102,12 @@ var require_decoder = __commonJS({
|
|
|
2102
2102
|
return constructor;
|
|
2103
2103
|
})();
|
|
2104
2104
|
if (typeof module !== "undefined") {
|
|
2105
|
-
module.exports =
|
|
2105
|
+
module.exports = decode3;
|
|
2106
2106
|
} else if (typeof window !== "undefined") {
|
|
2107
2107
|
window["jpeg-js"] = window["jpeg-js"] || {};
|
|
2108
|
-
window["jpeg-js"].decode =
|
|
2108
|
+
window["jpeg-js"].decode = decode3;
|
|
2109
2109
|
}
|
|
2110
|
-
function
|
|
2110
|
+
function decode3(jpegData, userOpts = {}) {
|
|
2111
2111
|
var defaultOpts = {
|
|
2112
2112
|
// "undefined" means "Choose whether to transform colors based on the image’s color model."
|
|
2113
2113
|
colorTransform: void 0,
|
|
@@ -2159,10 +2159,10 @@ var require_decoder = __commonJS({
|
|
|
2159
2159
|
var require_jpeg_js = __commonJS({
|
|
2160
2160
|
"node_modules/jpeg-js/index.js"(exports, module) {
|
|
2161
2161
|
var encode2 = require_encoder();
|
|
2162
|
-
var
|
|
2162
|
+
var decode3 = require_decoder();
|
|
2163
2163
|
module.exports = {
|
|
2164
2164
|
encode: encode2,
|
|
2165
|
-
decode:
|
|
2165
|
+
decode: decode3
|
|
2166
2166
|
};
|
|
2167
2167
|
}
|
|
2168
2168
|
});
|
|
@@ -4760,8 +4760,8 @@ var require_deflate2 = __commonJS({
|
|
|
4760
4760
|
var Z_DEFAULT_COMPRESSION = -1;
|
|
4761
4761
|
var Z_DEFAULT_STRATEGY = 0;
|
|
4762
4762
|
var Z_DEFLATED = 8;
|
|
4763
|
-
function Deflate(
|
|
4764
|
-
if (!(this instanceof Deflate)) return new Deflate(
|
|
4763
|
+
function Deflate(options2) {
|
|
4764
|
+
if (!(this instanceof Deflate)) return new Deflate(options2);
|
|
4765
4765
|
this.options = utils.assign({
|
|
4766
4766
|
level: Z_DEFAULT_COMPRESSION,
|
|
4767
4767
|
method: Z_DEFLATED,
|
|
@@ -4770,7 +4770,7 @@ var require_deflate2 = __commonJS({
|
|
|
4770
4770
|
memLevel: 8,
|
|
4771
4771
|
strategy: Z_DEFAULT_STRATEGY,
|
|
4772
4772
|
to: ""
|
|
4773
|
-
},
|
|
4773
|
+
}, options2 || {});
|
|
4774
4774
|
var opt = this.options;
|
|
4775
4775
|
if (opt.raw && opt.windowBits > 0) {
|
|
4776
4776
|
opt.windowBits = -opt.windowBits;
|
|
@@ -4878,23 +4878,23 @@ var require_deflate2 = __commonJS({
|
|
|
4878
4878
|
this.err = status;
|
|
4879
4879
|
this.msg = this.strm.msg;
|
|
4880
4880
|
};
|
|
4881
|
-
function deflate(input,
|
|
4882
|
-
var deflator = new Deflate(
|
|
4881
|
+
function deflate(input, options2) {
|
|
4882
|
+
var deflator = new Deflate(options2);
|
|
4883
4883
|
deflator.push(input, true);
|
|
4884
4884
|
if (deflator.err) {
|
|
4885
4885
|
throw deflator.msg || msg[deflator.err];
|
|
4886
4886
|
}
|
|
4887
4887
|
return deflator.result;
|
|
4888
4888
|
}
|
|
4889
|
-
function deflateRaw(input,
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
return deflate(input,
|
|
4889
|
+
function deflateRaw(input, options2) {
|
|
4890
|
+
options2 = options2 || {};
|
|
4891
|
+
options2.raw = true;
|
|
4892
|
+
return deflate(input, options2);
|
|
4893
4893
|
}
|
|
4894
|
-
function gzip(input,
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
return deflate(input,
|
|
4894
|
+
function gzip(input, options2) {
|
|
4895
|
+
options2 = options2 || {};
|
|
4896
|
+
options2.gzip = true;
|
|
4897
|
+
return deflate(input, options2);
|
|
4898
4898
|
}
|
|
4899
4899
|
exports.Deflate = Deflate;
|
|
4900
4900
|
exports.deflate = deflate;
|
|
@@ -6757,13 +6757,13 @@ var require_inflate2 = __commonJS({
|
|
|
6757
6757
|
var ZStream = require_zstream();
|
|
6758
6758
|
var GZheader = require_gzheader();
|
|
6759
6759
|
var toString = Object.prototype.toString;
|
|
6760
|
-
function Inflate(
|
|
6761
|
-
if (!(this instanceof Inflate)) return new Inflate(
|
|
6760
|
+
function Inflate(options2) {
|
|
6761
|
+
if (!(this instanceof Inflate)) return new Inflate(options2);
|
|
6762
6762
|
this.options = utils.assign({
|
|
6763
6763
|
chunkSize: 16384,
|
|
6764
6764
|
windowBits: 0,
|
|
6765
6765
|
to: ""
|
|
6766
|
-
},
|
|
6766
|
+
}, options2 || {});
|
|
6767
6767
|
var opt = this.options;
|
|
6768
6768
|
if (opt.raw && opt.windowBits >= 0 && opt.windowBits < 16) {
|
|
6769
6769
|
opt.windowBits = -opt.windowBits;
|
|
@@ -6771,7 +6771,7 @@ var require_inflate2 = __commonJS({
|
|
|
6771
6771
|
opt.windowBits = -15;
|
|
6772
6772
|
}
|
|
6773
6773
|
}
|
|
6774
|
-
if (opt.windowBits >= 0 && opt.windowBits < 16 && !(
|
|
6774
|
+
if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options2 && options2.windowBits)) {
|
|
6775
6775
|
opt.windowBits += 32;
|
|
6776
6776
|
}
|
|
6777
6777
|
if (opt.windowBits > 15 && opt.windowBits < 48) {
|
|
@@ -6899,18 +6899,18 @@ var require_inflate2 = __commonJS({
|
|
|
6899
6899
|
this.err = status;
|
|
6900
6900
|
this.msg = this.strm.msg;
|
|
6901
6901
|
};
|
|
6902
|
-
function inflate(input,
|
|
6903
|
-
var inflator = new Inflate(
|
|
6902
|
+
function inflate(input, options2) {
|
|
6903
|
+
var inflator = new Inflate(options2);
|
|
6904
6904
|
inflator.push(input, true);
|
|
6905
6905
|
if (inflator.err) {
|
|
6906
6906
|
throw inflator.msg || msg[inflator.err];
|
|
6907
6907
|
}
|
|
6908
6908
|
return inflator.result;
|
|
6909
6909
|
}
|
|
6910
|
-
function inflateRaw(input,
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
return inflate(input,
|
|
6910
|
+
function inflateRaw(input, options2) {
|
|
6911
|
+
options2 = options2 || {};
|
|
6912
|
+
options2.raw = true;
|
|
6913
|
+
return inflate(input, options2);
|
|
6914
6914
|
}
|
|
6915
6915
|
exports.Inflate = Inflate;
|
|
6916
6916
|
exports.inflate = inflate;
|
|
@@ -10043,7 +10043,7 @@ function inflateZlibSync(input) {
|
|
|
10043
10043
|
bitCnt -= n;
|
|
10044
10044
|
return v;
|
|
10045
10045
|
};
|
|
10046
|
-
const
|
|
10046
|
+
const decode3 = (h) => {
|
|
10047
10047
|
let code = 0;
|
|
10048
10048
|
let first = 0;
|
|
10049
10049
|
let index = 0;
|
|
@@ -10101,7 +10101,7 @@ function inflateZlibSync(input) {
|
|
|
10101
10101
|
const clh = buildHuffman(cl, 19);
|
|
10102
10102
|
const lens = new Uint8Array(hlit + hdist);
|
|
10103
10103
|
for (let i = 0; i < hlit + hdist; ) {
|
|
10104
|
-
const sym =
|
|
10104
|
+
const sym = decode3(clh);
|
|
10105
10105
|
if (sym < 16) {
|
|
10106
10106
|
lens[i++] = sym;
|
|
10107
10107
|
} else if (sym === 16) {
|
|
@@ -10121,7 +10121,7 @@ function inflateZlibSync(input) {
|
|
|
10121
10121
|
throw new Error("inflate: invalid block type");
|
|
10122
10122
|
}
|
|
10123
10123
|
for (; ; ) {
|
|
10124
|
-
const sym =
|
|
10124
|
+
const sym = decode3(lit);
|
|
10125
10125
|
if (sym < 256) {
|
|
10126
10126
|
need(1);
|
|
10127
10127
|
out[outLen++] = sym;
|
|
@@ -10130,7 +10130,7 @@ function inflateZlibSync(input) {
|
|
|
10130
10130
|
} else {
|
|
10131
10131
|
const li = sym - 257;
|
|
10132
10132
|
const len = LENGTH_BASE[li] + bits(LENGTH_EXTRA[li]);
|
|
10133
|
-
const di =
|
|
10133
|
+
const di = decode3(dist);
|
|
10134
10134
|
const d = DIST_BASE[di] + bits(DIST_EXTRA[di]);
|
|
10135
10135
|
need(len);
|
|
10136
10136
|
for (let k = 0; k < len; k++) {
|
|
@@ -10310,15 +10310,74 @@ async function decodePng(bytes) {
|
|
|
10310
10310
|
return { width, height, data: out };
|
|
10311
10311
|
}
|
|
10312
10312
|
|
|
10313
|
-
// src/
|
|
10313
|
+
// src/jpeg-decoder.ts
|
|
10314
10314
|
var import_jpeg_js = __toESM(require_jpeg_js());
|
|
10315
|
+
var options = { useTArray: true, formatAsRGBA: true, maxResolutionInMP: 67.108864, maxMemoryUsageInMB: 512 };
|
|
10316
|
+
function decodeJpegPixels(bytes, colorTransform) {
|
|
10317
|
+
let sampling = [];
|
|
10318
|
+
let adobeTransform;
|
|
10319
|
+
let adobeOffset = -1;
|
|
10320
|
+
for (let position = 2; position + 4 <= bytes.length; ) {
|
|
10321
|
+
if (bytes[position] !== 255) break;
|
|
10322
|
+
if (bytes[position + 1] === 255) {
|
|
10323
|
+
position++;
|
|
10324
|
+
continue;
|
|
10325
|
+
}
|
|
10326
|
+
const marker = bytes[position + 1];
|
|
10327
|
+
if (marker === 218 || marker === 217) break;
|
|
10328
|
+
const length = bytes[position + 2] * 256 + bytes[position + 3];
|
|
10329
|
+
if (length < 2 || position + length + 2 > bytes.length) break;
|
|
10330
|
+
const start = position + 4;
|
|
10331
|
+
if ([192, 193, 194].includes(marker) && length >= 8) {
|
|
10332
|
+
const count = bytes[start + 5];
|
|
10333
|
+
if (length >= 8 + 3 * count) sampling = Array.from({ length: count }, (_, i) => ({ id: bytes[start + 6 + i * 3], h: bytes[start + 7 + i * 3] >> 4, v: bytes[start + 7 + i * 3] & 15 }));
|
|
10334
|
+
}
|
|
10335
|
+
if (marker === 238 && length >= 14 && String.fromCharCode(...bytes.subarray(start, start + 5)) === "Adobe") {
|
|
10336
|
+
adobeOffset = start + 11;
|
|
10337
|
+
adobeTransform = bytes[adobeOffset];
|
|
10338
|
+
}
|
|
10339
|
+
position += length + 2;
|
|
10340
|
+
}
|
|
10341
|
+
const transform = colorTransform ?? (adobeTransform !== void 0 ? adobeTransform !== 0 : !sampling.every((component, i) => component.id === [82, 71, 66][i]));
|
|
10342
|
+
if (sampling.length !== 3 || !transform) return (0, import_jpeg_js.decode)(bytes, { ...options, colorTransform: sampling.length === 3 ? transform : colorTransform });
|
|
10343
|
+
const maxH = Math.max(...sampling.map((c) => c.h)), maxV = Math.max(...sampling.map((c) => c.v));
|
|
10344
|
+
if (sampling.some((c) => !c.h || !c.v || maxH % c.h || maxV % c.v)) return (0, import_jpeg_js.decode)(bytes, { ...options, colorTransform });
|
|
10345
|
+
let encoded = bytes;
|
|
10346
|
+
if (adobeTransform) {
|
|
10347
|
+
encoded = bytes.slice();
|
|
10348
|
+
encoded[adobeOffset] = 0;
|
|
10349
|
+
}
|
|
10350
|
+
const raw = (0, import_jpeg_js.decode)(encoded, { ...options, colorTransform: false });
|
|
10351
|
+
const { width, height } = raw;
|
|
10352
|
+
const data = new Uint8Array(raw.data.length);
|
|
10353
|
+
const sample2 = (x, y, channel) => {
|
|
10354
|
+
const sx = maxH / sampling[channel].h, sy = maxV / sampling[channel].v;
|
|
10355
|
+
const px = Math.max(0, Math.min(Math.ceil(width / sx) - 1, (x + 0.5) / sx - 0.5));
|
|
10356
|
+
const py = Math.max(0, Math.min(Math.ceil(height / sy) - 1, (y + 0.5) / sy - 0.5));
|
|
10357
|
+
const ix = Math.floor(px), iy = Math.floor(py), fx = px - ix, fy = py - iy;
|
|
10358
|
+
const at = (xx, yy) => raw.data[(Math.min(height - 1, yy * sy) * width + Math.min(width - 1, xx * sx)) * 4 + channel];
|
|
10359
|
+
return (1 - fy) * ((1 - fx) * at(ix, iy) + fx * at(ix + 1, iy)) + fy * ((1 - fx) * at(ix, iy + 1) + fx * at(ix + 1, iy + 1));
|
|
10360
|
+
};
|
|
10361
|
+
const byte = (value) => Math.max(0, Math.min(255, Math.round(value)));
|
|
10362
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
10363
|
+
const luma = sample2(x, y, 0), cb = sample2(x, y, 1) - 128, cr = sample2(x, y, 2) - 128;
|
|
10364
|
+
const offset = (y * width + x) * 4;
|
|
10365
|
+
data[offset] = byte(luma + 1.402 * cr);
|
|
10366
|
+
data[offset + 1] = byte(luma - 0.3441363 * cb - 0.71413636 * cr);
|
|
10367
|
+
data[offset + 2] = byte(luma + 1.772 * cb);
|
|
10368
|
+
data[offset + 3] = 255;
|
|
10369
|
+
}
|
|
10370
|
+
return { ...raw, data };
|
|
10371
|
+
}
|
|
10372
|
+
|
|
10373
|
+
// src/image-codec-fallback.ts
|
|
10315
10374
|
var import_gifuct_js = __toESM(require_lib2());
|
|
10316
10375
|
var UTIF = __toESM(require_UTIF());
|
|
10317
10376
|
|
|
10318
10377
|
// src/tiff-group3.ts
|
|
10319
10378
|
function normalizeGroup3(buffer, page) {
|
|
10320
|
-
const
|
|
10321
|
-
if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (
|
|
10379
|
+
const options2 = Array.isArray(page.t292) ? Number(page.t292[0]) : 0;
|
|
10380
|
+
if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (options2 & 3) !== 0) return buffer;
|
|
10322
10381
|
const offsets = page.t273, lengths = page.t279;
|
|
10323
10382
|
if (!Array.isArray(offsets) || !Array.isArray(lengths) || offsets.length !== lengths.length) return buffer;
|
|
10324
10383
|
const source = new Uint8Array(buffer);
|
|
@@ -10352,16 +10411,50 @@ function normalizeGroup3(buffer, page) {
|
|
|
10352
10411
|
return offset;
|
|
10353
10412
|
});
|
|
10354
10413
|
page.t279 = strips.map((strip) => strip.length);
|
|
10355
|
-
page.t292 = [
|
|
10414
|
+
page.t292 = [options2 | 1];
|
|
10356
10415
|
return normalized.buffer;
|
|
10357
10416
|
}
|
|
10358
10417
|
|
|
10418
|
+
// src/tiff-jpeg.ts
|
|
10419
|
+
function decodeJpegTiff(bytes, page) {
|
|
10420
|
+
const values = (tag2) => Array.isArray(page[tag2]) ? page[tag2].map(Number) : [];
|
|
10421
|
+
const first = (tag2, fallback = 0) => values(tag2)[0] ?? fallback;
|
|
10422
|
+
const photo = first("t262");
|
|
10423
|
+
if (first("t259") !== 7 || photo !== 2 && photo !== 6 || first("t277") !== 3 || first("t284", 1) !== 1 || values("t258").some((v) => v !== 8)) return null;
|
|
10424
|
+
const width = first("t256"), height = first("t257");
|
|
10425
|
+
const tiled = !!page.t322;
|
|
10426
|
+
const blockWidth = tiled ? first("t322") : width;
|
|
10427
|
+
const blockHeight = tiled ? first("t323") : first("t278", height);
|
|
10428
|
+
if (!Number.isInteger(blockWidth) || !Number.isInteger(blockHeight) || blockWidth <= 0 || blockHeight <= 0 || blockWidth > 8192 || blockHeight > 8192) throw new Error("Invalid TIFF JPEG block");
|
|
10429
|
+
const offsets = values(tiled ? "t324" : "t273");
|
|
10430
|
+
const lengths = values(tiled ? "t325" : "t279");
|
|
10431
|
+
const columns = Math.ceil(width / blockWidth), rows = Math.ceil(height / blockHeight);
|
|
10432
|
+
if (offsets.length !== columns * rows || lengths.length !== offsets.length) throw new Error("Invalid TIFF JPEG offsets");
|
|
10433
|
+
const tables = page.t347 instanceof Uint8Array ? page.t347 : new Uint8Array(values("t347"));
|
|
10434
|
+
const tableLength = tables.length >= 2 && tables[tables.length - 2] === 255 && tables[tables.length - 1] === 217 ? tables.length - 2 : tables.length;
|
|
10435
|
+
const result = new Uint8ClampedArray(width * height * 4);
|
|
10436
|
+
for (let block = 0; block < offsets.length; block++) {
|
|
10437
|
+
const offset = offsets[block], length = lengths[block];
|
|
10438
|
+
if (!Number.isInteger(offset) || !Number.isInteger(length) || offset < 0 || length <= 0 || offset + length > bytes.length) throw new Error("Invalid TIFF JPEG data");
|
|
10439
|
+
const skip = tableLength && bytes[offset] === 255 && bytes[offset + 1] === 216 ? 2 : 0;
|
|
10440
|
+
const jpeg = new Uint8Array(tableLength + length - skip);
|
|
10441
|
+
jpeg.set(tables.subarray(0, tableLength));
|
|
10442
|
+
jpeg.set(bytes.subarray(offset + skip, offset + length), tableLength);
|
|
10443
|
+
const decoded = decodeJpegPixels(jpeg, photo === 6);
|
|
10444
|
+
const x = block % columns * blockWidth, y = Math.floor(block / columns) * blockHeight;
|
|
10445
|
+
const copyWidth = Math.min(blockWidth, width - x), copyHeight = Math.min(blockHeight, height - y);
|
|
10446
|
+
if (decoded.width !== blockWidth || decoded.height < copyHeight || decoded.height > blockHeight) throw new Error("Invalid TIFF JPEG dimensions");
|
|
10447
|
+
for (let row = 0; row < copyHeight; row++) result.set(decoded.data.subarray(row * decoded.width * 4, (row * decoded.width + copyWidth) * 4), ((y + row) * width + x) * 4);
|
|
10448
|
+
}
|
|
10449
|
+
return result;
|
|
10450
|
+
}
|
|
10451
|
+
|
|
10359
10452
|
// src/image-codec-fallback.ts
|
|
10360
10453
|
var validSize = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= 8192 && h <= 8192;
|
|
10361
10454
|
function decodeImageCodecFallback(bytes) {
|
|
10362
10455
|
try {
|
|
10363
10456
|
if (bytes[0] === 255 && bytes[1] === 216) {
|
|
10364
|
-
const p = (
|
|
10457
|
+
const p = decodeJpegPixels(bytes);
|
|
10365
10458
|
return validSize(p.width, p.height) ? { ...p, data: new Uint8ClampedArray(p.data) } : null;
|
|
10366
10459
|
}
|
|
10367
10460
|
if (bytes.length >= 13 && String.fromCharCode(...bytes.subarray(0, 6)).match(/^GIF8[79]a$/)) {
|
|
@@ -10395,6 +10488,9 @@ function decodeImageCodecFallback(bytes) {
|
|
|
10395
10488
|
const pages = UTIF.decode(buffer);
|
|
10396
10489
|
const page = pages.find((p) => p.t256 && p.t257);
|
|
10397
10490
|
if (!page || !Array.isArray(page.t256) || !Array.isArray(page.t257) || !validSize(Number(page.t256[0]), Number(page.t257[0]))) return null;
|
|
10491
|
+
const jpeg = decodeJpegTiff(new Uint8Array(buffer), page);
|
|
10492
|
+
if (jpeg) return { data: jpeg, width: Number(page.t256[0]), height: Number(page.t257[0]) };
|
|
10493
|
+
if (Array.isArray(page.t259) && page.t259[0] === 32946) page.t259 = [8];
|
|
10398
10494
|
UTIF.decodeImage(normalizeGroup3(buffer, page), page);
|
|
10399
10495
|
const width = page.width, height = page.height;
|
|
10400
10496
|
if (!validSize(width, height)) return null;
|
|
@@ -14313,13 +14409,13 @@ function writeJsx(node, depth, out, rootSpread) {
|
|
|
14313
14409
|
}
|
|
14314
14410
|
out.push(`${pad}</${node.tag}>`);
|
|
14315
14411
|
}
|
|
14316
|
-
function svgTreeToJsx(node,
|
|
14317
|
-
const name =
|
|
14412
|
+
function svgTreeToJsx(node, options2 = {}) {
|
|
14413
|
+
const name = options2.componentName ?? "Metafile";
|
|
14318
14414
|
if (!/^[A-Z][A-Za-z0-9_$]*$/.test(name)) {
|
|
14319
14415
|
throw new TypeError(`svgTreeToJsx: componentName must be a PascalCase identifier, got ${JSON.stringify(name)}`);
|
|
14320
14416
|
}
|
|
14321
|
-
const ts =
|
|
14322
|
-
const spread =
|
|
14417
|
+
const ts = options2.typescript ?? true;
|
|
14418
|
+
const spread = options2.spreadProps ?? true;
|
|
14323
14419
|
const body = [];
|
|
14324
14420
|
writeJsx(node, 2, body, spread);
|
|
14325
14421
|
const params = spread ? ts ? "props: SVGProps<SVGSVGElement>" : "props" : "";
|
|
@@ -15638,7 +15734,7 @@ function hslToRgb(h, s, l) {
|
|
|
15638
15734
|
return [r + m, g + m, b + m];
|
|
15639
15735
|
}
|
|
15640
15736
|
var HUE_SEXTANT = 43;
|
|
15641
|
-
var HUE_CIRCLE =
|
|
15737
|
+
var HUE_CIRCLE = 255;
|
|
15642
15738
|
function gdipHue(r, g, b) {
|
|
15643
15739
|
const max = Math.max(r, g, b);
|
|
15644
15740
|
const d = max - Math.min(r, g, b);
|
|
@@ -15647,13 +15743,14 @@ function gdipHue(r, g, b) {
|
|
|
15647
15743
|
return f(g - b);
|
|
15648
15744
|
}
|
|
15649
15745
|
if (max === b && b !== r) {
|
|
15650
|
-
return r >= g ?
|
|
15746
|
+
return r >= g ? 170 + f(r - g) : 127 + f(b - g);
|
|
15651
15747
|
}
|
|
15652
15748
|
if (max === g) {
|
|
15653
|
-
return b >= r ?
|
|
15749
|
+
return b >= r ? 86 + f(b - r) : 43 + f(g - r);
|
|
15654
15750
|
}
|
|
15655
15751
|
const t = f(b - g);
|
|
15656
|
-
|
|
15752
|
+
const q = (256 - t - (t >= 40 ? 1 : 0)) % 256;
|
|
15753
|
+
return q - Math.floor((q + 42) / 86);
|
|
15657
15754
|
}
|
|
15658
15755
|
function applyHueSaturationLightness(src, hue, saturation, lightness2) {
|
|
15659
15756
|
const out = new Uint8ClampedArray(src);
|
|
@@ -15671,11 +15768,12 @@ function applyHueSaturationLightness(src, hue, saturation, lightness2) {
|
|
|
15671
15768
|
continue;
|
|
15672
15769
|
}
|
|
15673
15770
|
const sum = max + min;
|
|
15674
|
-
const s = clamp((max - min) / (sum <= 255 ? sum : 510 - sum) * sMul, 0, 1);
|
|
15771
|
+
const s = Math.fround(clamp((max - min) / (sum <= 255 ? sum : 510 - sum) * sMul, 0, 1));
|
|
15675
15772
|
const hi = l <= 127 ? l * (1 + s) : l + s * (255 - l);
|
|
15676
15773
|
const m1 = l <= 127 ? 2 * l - Math.trunc(hi) : Math.round(2 * l - hi);
|
|
15677
15774
|
const m2 = 2 * l - m1;
|
|
15678
|
-
const
|
|
15775
|
+
const index = ((gdipHue(r, g, b) + shift) % HUE_CIRCLE + HUE_CIRCLE) % HUE_CIRCLE;
|
|
15776
|
+
const q = index + Math.floor((index + 41) / 85);
|
|
15679
15777
|
const sextant = Math.min(5, Math.floor(q / HUE_SEXTANT));
|
|
15680
15778
|
const f = (q - sextant * HUE_SEXTANT) / HUE_SEXTANT;
|
|
15681
15779
|
const up = Math.trunc(m1 + (m2 - m1) * f);
|
|
@@ -18671,11 +18769,11 @@ function capFigures(path, closeAll) {
|
|
|
18671
18769
|
}, [1, 0, 0, 1, 0, 0]);
|
|
18672
18770
|
return closeAll ? figures.map((f) => ({ ...f, closed: true })) : figures;
|
|
18673
18771
|
}
|
|
18674
|
-
function customCapGeometry(figures, width, start, end,
|
|
18772
|
+
function customCapGeometry(figures, width, start, end, options2 = {}) {
|
|
18675
18773
|
const out = [];
|
|
18676
18774
|
const capped = [];
|
|
18677
18775
|
const polygons = [];
|
|
18678
|
-
const minFill =
|
|
18776
|
+
const minFill = options2.minFillScale ?? 2;
|
|
18679
18777
|
for (const fig of figures) {
|
|
18680
18778
|
if (fig.closed || !start && !end) {
|
|
18681
18779
|
out.push(fig);
|
|
@@ -18728,7 +18826,7 @@ function customCapGeometry(figures, width, start, end, options = {}) {
|
|
|
18728
18826
|
const pen = {
|
|
18729
18827
|
// GDI+'s widener never makes an outline thinner than one device pixel.
|
|
18730
18828
|
half: Math.max(ws, 1) / 2,
|
|
18731
|
-
join: (
|
|
18829
|
+
join: (options2.widenJoin ?? ((j) => j))(cap.strokeJoin),
|
|
18732
18830
|
miterLimit: 10,
|
|
18733
18831
|
startCap: cap.strokeStartCap,
|
|
18734
18832
|
endCap: cap.strokeEndCap,
|
|
@@ -18738,7 +18836,7 @@ function customCapGeometry(figures, width, start, end, options = {}) {
|
|
|
18738
18836
|
compound: null,
|
|
18739
18837
|
inset: false
|
|
18740
18838
|
};
|
|
18741
|
-
polygons.push(...(
|
|
18839
|
+
polygons.push(...(options2.widen ?? widenFigures)(capFigures(placed, false), pen).map((q) => q.reverse()));
|
|
18742
18840
|
}
|
|
18743
18841
|
};
|
|
18744
18842
|
if (start) {
|
|
@@ -20453,7 +20551,7 @@ var BLEND_MODES = /* @__PURE__ */ new Set([
|
|
|
20453
20551
|
"luminosity"
|
|
20454
20552
|
]);
|
|
20455
20553
|
var SvgContext = class {
|
|
20456
|
-
constructor(width, height,
|
|
20554
|
+
constructor(width, height, options2 = {}) {
|
|
20457
20555
|
this.nextId = 0;
|
|
20458
20556
|
this.stack = [];
|
|
20459
20557
|
/** The current path, in DEVICE space (see `canvas-path.ts`). */
|
|
@@ -20464,9 +20562,9 @@ var SvgContext = class {
|
|
|
20464
20562
|
this.group = null;
|
|
20465
20563
|
this.images = [];
|
|
20466
20564
|
this.canvas = { width, height, svgContext: this };
|
|
20467
|
-
this.shadow =
|
|
20468
|
-
this.imageResampling =
|
|
20469
|
-
this.idPrefix =
|
|
20565
|
+
this.shadow = options2.shadow ?? null;
|
|
20566
|
+
this.imageResampling = options2.imageResampling ?? "renderer";
|
|
20567
|
+
this.idPrefix = options2.idPrefix ?? "emf-";
|
|
20470
20568
|
this.state = {
|
|
20471
20569
|
transform: [...IDENTITY3],
|
|
20472
20570
|
fillStyle: "#000000",
|
|
@@ -21469,7 +21567,7 @@ var SvgContext = class {
|
|
|
21469
21567
|
* Encodes every pending raster payload and returns the finished `<svg>`
|
|
21470
21568
|
* tree. Call once, after replay (and deferred images) are complete.
|
|
21471
21569
|
*/
|
|
21472
|
-
async toTree(
|
|
21570
|
+
async toTree(options2 = {}) {
|
|
21473
21571
|
const cache2 = /* @__PURE__ */ new Map();
|
|
21474
21572
|
for (const img of this.images) {
|
|
21475
21573
|
let url = cache2.get(img.payload);
|
|
@@ -21481,7 +21579,7 @@ var SvgContext = class {
|
|
|
21481
21579
|
}
|
|
21482
21580
|
const { width, height } = this.canvas;
|
|
21483
21581
|
const attrs = { xmlns: "http://www.w3.org/2000/svg" };
|
|
21484
|
-
if (
|
|
21582
|
+
if (options2.includeSize ?? true) {
|
|
21485
21583
|
attrs.width = width;
|
|
21486
21584
|
attrs.height = height;
|
|
21487
21585
|
}
|
|
@@ -32306,12 +32404,12 @@ function drawWithFontEngine(rCtx, offset, dataOff, nChars, offString, viewEnd) {
|
|
|
32306
32404
|
if (!fonts) {
|
|
32307
32405
|
return false;
|
|
32308
32406
|
}
|
|
32309
|
-
const
|
|
32407
|
+
const options2 = view.getUint32(dataOff + 44, true);
|
|
32310
32408
|
const codes = [];
|
|
32311
32409
|
for (let i = 0; i < nChars; i++) {
|
|
32312
32410
|
codes.push(view.getUint16(offset + offString + i * 2, true));
|
|
32313
32411
|
}
|
|
32314
|
-
const pdy = (
|
|
32412
|
+
const pdy = (options2 & ETO_PDY) !== 0;
|
|
32315
32413
|
const raw = readDxArray(view, offset, dataOff, pdy ? nChars * 2 : nChars, viewEnd);
|
|
32316
32414
|
let dx = raw;
|
|
32317
32415
|
let dy = null;
|
|
@@ -32325,10 +32423,10 @@ function drawWithFontEngine(rCtx, offset, dataOff, nChars, offString, viewEnd) {
|
|
|
32325
32423
|
}
|
|
32326
32424
|
const adv = drawGdiTextCall(ctx, fonts, state, {
|
|
32327
32425
|
codes,
|
|
32328
|
-
glyphIndices: (
|
|
32426
|
+
glyphIndices: (options2 & ETO_GLYPH_INDEX) !== 0,
|
|
32329
32427
|
x: view.getInt32(dataOff + 28, true),
|
|
32330
32428
|
y: view.getInt32(dataOff + 32, true),
|
|
32331
|
-
options,
|
|
32429
|
+
options: options2,
|
|
32332
32430
|
rect: {
|
|
32333
32431
|
left: view.getInt32(dataOff + 48, true),
|
|
32334
32432
|
top: view.getInt32(dataOff + 52, true),
|
|
@@ -32470,7 +32568,7 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
32470
32568
|
}
|
|
32471
32569
|
return true;
|
|
32472
32570
|
}
|
|
32473
|
-
function drawTextCall(rCtx, x, y, codes,
|
|
32571
|
+
function drawTextCall(rCtx, x, y, codes, options2, rect, dx) {
|
|
32474
32572
|
const n = codes.length;
|
|
32475
32573
|
const offString = 76;
|
|
32476
32574
|
const offDx = offString + n * 2 + 3 & -4;
|
|
@@ -32479,7 +32577,7 @@ function drawTextCall(rCtx, x, y, codes, options, rect, dx) {
|
|
|
32479
32577
|
const view = new DataView(new ArrayBuffer(size));
|
|
32480
32578
|
view.setUint32(44, n, true);
|
|
32481
32579
|
view.setUint32(48, offString, true);
|
|
32482
|
-
view.setUint32(52,
|
|
32580
|
+
view.setUint32(52, options2, true);
|
|
32483
32581
|
view.setInt32(36, x, true);
|
|
32484
32582
|
view.setInt32(40, y, true);
|
|
32485
32583
|
view.setInt32(56, rect[0], true);
|
|
@@ -32523,7 +32621,7 @@ function handlePolyText(rCtx, offset, dataOff, recSize, wide) {
|
|
|
32523
32621
|
const e = arrayStart + i * 40;
|
|
32524
32622
|
const x = view.getInt32(e, true), y = view.getInt32(e + 4, true);
|
|
32525
32623
|
const n = view.getUint32(e + 8, true), offString = view.getUint32(e + 12, true);
|
|
32526
|
-
const
|
|
32624
|
+
const options2 = view.getUint32(e + 16, true);
|
|
32527
32625
|
const rect = [view.getInt32(e + 20, true), view.getInt32(e + 24, true), view.getInt32(e + 28, true), view.getInt32(e + 32, true)];
|
|
32528
32626
|
const offDx = view.getUint32(e + 36, true);
|
|
32529
32627
|
const unit = wide ? 2 : 1;
|
|
@@ -32531,13 +32629,13 @@ function handlePolyText(rCtx, offset, dataOff, recSize, wide) {
|
|
|
32531
32629
|
const ansi = wide ? null : readAnsiRecord(view, offset + offString, n, charSet);
|
|
32532
32630
|
const codes = wide ? Array.from({ length: n }, (_, j) => view.getUint16(offset + offString + j * 2, true)) : ansi.codes;
|
|
32533
32631
|
let dx = null;
|
|
32534
|
-
const pdy = (
|
|
32632
|
+
const pdy = (options2 & ETO_PDY) !== 0;
|
|
32535
32633
|
const dxCount = n * (pdy ? 2 : 1);
|
|
32536
32634
|
if (offDx && offDx <= end - offset && dxCount <= Math.floor((end - (offset + offDx)) / 4)) {
|
|
32537
32635
|
dx = Array.from({ length: dxCount }, (_, j) => view.getInt32(offset + offDx + j * 4, true));
|
|
32538
32636
|
if (!wide) dx = collapseAnsiDx(dx, ansi.byteLengths, pdy);
|
|
32539
32637
|
}
|
|
32540
|
-
drawTextCall(rCtx, x, y, codes,
|
|
32638
|
+
drawTextCall(rCtx, x, y, codes, options2, rect, dx);
|
|
32541
32639
|
}
|
|
32542
32640
|
return true;
|
|
32543
32641
|
}
|
|
@@ -32546,13 +32644,13 @@ function handleSmallTextOut(rCtx, offset, dataOff, recSize) {
|
|
|
32546
32644
|
const end = Math.min(view.byteLength, offset + recSize);
|
|
32547
32645
|
if (recSize < 36) return true;
|
|
32548
32646
|
const x = view.getInt32(dataOff, true), y = view.getInt32(dataOff + 4, true);
|
|
32549
|
-
const n = view.getUint32(dataOff + 8, true),
|
|
32550
|
-
const small = (
|
|
32647
|
+
const n = view.getUint32(dataOff + 8, true), options2 = view.getUint32(dataOff + 12, true);
|
|
32648
|
+
const small = (options2 & 512) !== 0, noRect = (options2 & 256) !== 0;
|
|
32551
32649
|
const base = dataOff + 28 + (noRect ? 0 : 16);
|
|
32552
32650
|
if (base > end || n > Math.floor((end - base) / (small ? 1 : 2))) return true;
|
|
32553
32651
|
const rect = noRect ? [0, 0, 0, 0] : [view.getInt32(dataOff + 28, true), view.getInt32(dataOff + 32, true), view.getInt32(dataOff + 36, true), view.getInt32(dataOff + 40, true)];
|
|
32554
32652
|
const codes = small ? Array.from({ length: n }, (_, i) => view.getUint8(base + i)) : Array.from({ length: n }, (_, i) => view.getUint16(base + i * 2, true));
|
|
32555
|
-
drawTextCall(rCtx, x, y, codes,
|
|
32653
|
+
drawTextCall(rCtx, x, y, codes, options2, rect, null);
|
|
32556
32654
|
return true;
|
|
32557
32655
|
}
|
|
32558
32656
|
function handleEmfGdiDrawTextRecord(rCtx, recType, offset, dataOff, recSize) {
|
|
@@ -32566,20 +32664,20 @@ function handleEmfGdiDrawTextRecord(rCtx, recType, offset, dataOff, recSize) {
|
|
|
32566
32664
|
const end = Math.min(view.byteLength, offset + recSize);
|
|
32567
32665
|
if (recSize < 76) return true;
|
|
32568
32666
|
const x = view.getInt32(dataOff + 28, true), y = view.getInt32(dataOff + 32, true);
|
|
32569
|
-
const n = view.getUint32(dataOff + 36, true), strOff = view.getUint32(dataOff + 40, true),
|
|
32667
|
+
const n = view.getUint32(dataOff + 36, true), strOff = view.getUint32(dataOff + 40, true), options2 = view.getUint32(dataOff + 44, true);
|
|
32570
32668
|
if (!strOff || strOff > end - offset) return true;
|
|
32571
32669
|
if (n > end - (offset + strOff)) return true;
|
|
32572
32670
|
const ansi = readAnsiRecord(view, offset + strOff, n, state.fontDetails?.charSet ?? 1);
|
|
32573
32671
|
const rect = [view.getInt32(dataOff + 48, true), view.getInt32(dataOff + 52, true), view.getInt32(dataOff + 56, true), view.getInt32(dataOff + 60, true)];
|
|
32574
32672
|
const offDx = view.getUint32(dataOff + 64, true);
|
|
32575
32673
|
let dx = null;
|
|
32576
|
-
const pdy = (
|
|
32674
|
+
const pdy = (options2 & ETO_PDY) !== 0;
|
|
32577
32675
|
const dxCount = n * (pdy ? 2 : 1);
|
|
32578
32676
|
if (offDx && offDx <= end - offset && dxCount <= Math.floor((end - (offset + offDx)) / 4)) {
|
|
32579
32677
|
dx = Array.from({ length: dxCount }, (_, i) => view.getInt32(offset + offDx + i * 4, true));
|
|
32580
32678
|
dx = collapseAnsiDx(dx, ansi.byteLengths, pdy);
|
|
32581
32679
|
}
|
|
32582
|
-
drawTextCall(rCtx, x, y, ansi.codes,
|
|
32680
|
+
drawTextCall(rCtx, x, y, ansi.codes, options2, rect, dx);
|
|
32583
32681
|
return true;
|
|
32584
32682
|
}
|
|
32585
32683
|
return false;
|
|
@@ -33560,8 +33658,8 @@ function widenBracketPath(rCtx) {
|
|
|
33560
33658
|
if (rCtx.inPath || !rCtx.rasterPath || (state.penStyle & 15) === 5) {
|
|
33561
33659
|
return;
|
|
33562
33660
|
}
|
|
33563
|
-
const
|
|
33564
|
-
const polys = widenPath(rCtx.rasterPath,
|
|
33661
|
+
const options2 = penIsCosmetic(rCtx) ? { width: 16, cap: "round", join: "round", miterLimit: state.miterLimit ?? 10 } : penWidenOptions(rCtx);
|
|
33662
|
+
const polys = widenPath(rCtx.rasterPath, options2);
|
|
33565
33663
|
const path = new GdiRasterPath();
|
|
33566
33664
|
for (const poly of polys) {
|
|
33567
33665
|
if (poly.length < 4) {
|
|
@@ -36342,7 +36440,7 @@ function replayEmfRecords(view, ctx, bounds, canvasW, canvasH, dpiScale = 1, rep
|
|
|
36342
36440
|
}
|
|
36343
36441
|
return allDeferredImages;
|
|
36344
36442
|
}
|
|
36345
|
-
function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas,
|
|
36443
|
+
function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
|
|
36346
36444
|
const view = new DataView(bytes);
|
|
36347
36445
|
const header = parseEmfHeader(view);
|
|
36348
36446
|
if (!header) {
|
|
@@ -36353,11 +36451,11 @@ function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options) {
|
|
|
36353
36451
|
const left = -e / a;
|
|
36354
36452
|
const top = -f / d;
|
|
36355
36453
|
const bounds2 = { left, top, right: left + canvasW / a, bottom: top + canvasH / d };
|
|
36356
|
-
return replayEmfRecords(view, ctx, bounds2, canvasW, canvasH, 1,
|
|
36454
|
+
return replayEmfRecords(view, ctx, bounds2, canvasW, canvasH, 1, options2);
|
|
36357
36455
|
}
|
|
36358
36456
|
const bounds = { left: 0, top: 0, right: canvasW, bottom: canvasH };
|
|
36359
36457
|
return replayEmfRecords(view, ctx, bounds, canvasW, canvasH, 1, {
|
|
36360
|
-
...
|
|
36458
|
+
...options2,
|
|
36361
36459
|
plusBaseTransform: toCanvas,
|
|
36362
36460
|
gdiDrawing: false
|
|
36363
36461
|
});
|
|
@@ -37901,8 +37999,8 @@ function wmfExtTextOut(p, dataOff, recEnd) {
|
|
|
37901
37999
|
const y = view.getInt16(dataOff, true);
|
|
37902
38000
|
const x = view.getInt16(dataOff + 2, true);
|
|
37903
38001
|
const n = view.getInt16(dataOff + 4, true);
|
|
37904
|
-
const
|
|
37905
|
-
const hasRect = (
|
|
38002
|
+
const options2 = view.getUint16(dataOff + 6, true);
|
|
38003
|
+
const hasRect = (options2 & (ETO_OPAQUE | ETO_CLIPPED)) !== 0;
|
|
37906
38004
|
const strOff = dataOff + 8 + (hasRect ? 8 : 0);
|
|
37907
38005
|
const rect = hasRect && dataOff + 16 <= recEnd ? [view.getInt16(dataOff + 8, true), view.getInt16(dataOff + 10, true), view.getInt16(dataOff + 12, true), view.getInt16(dataOff + 14, true)] : null;
|
|
37908
38006
|
const count = Math.max(0, n);
|
|
@@ -37922,12 +38020,12 @@ function wmfExtTextOut(p, dataOff, recEnd) {
|
|
|
37922
38020
|
}
|
|
37923
38021
|
}
|
|
37924
38022
|
if (count === 0) {
|
|
37925
|
-
if (rect &&
|
|
37926
|
-
playText(p, { x, y, bytes: [32], options, rect, dx: [0] });
|
|
38023
|
+
if (rect && options2 & ETO_OPAQUE) {
|
|
38024
|
+
playText(p, { x, y, bytes: [32], options: options2, rect, dx: [0] });
|
|
37927
38025
|
}
|
|
37928
38026
|
return;
|
|
37929
38027
|
}
|
|
37930
|
-
playText(p, { x, y, bytes, options, rect, dx });
|
|
38028
|
+
playText(p, { x, y, bytes, options: options2, rect, dx });
|
|
37931
38029
|
}
|
|
37932
38030
|
|
|
37933
38031
|
// src/wmf-replay.ts
|
|
@@ -38397,7 +38495,7 @@ function replayWmfRecords(view, ctx, header, canvasW, canvasH, replayOptions = {
|
|
|
38397
38495
|
|
|
38398
38496
|
// src/emf-converter.ts
|
|
38399
38497
|
var MAX_METAFILE_RECURSION = 3;
|
|
38400
|
-
async function replayMetafile(buffer,
|
|
38498
|
+
async function replayMetafile(buffer, options2, createSurface) {
|
|
38401
38499
|
emfLog(`replayMetafile: input buffer ${buffer.byteLength} bytes`);
|
|
38402
38500
|
if (buffer.byteLength >= 16) {
|
|
38403
38501
|
const hdrBytes = new Uint8Array(buffer, 0, 16);
|
|
@@ -38405,7 +38503,7 @@ async function replayMetafile(buffer, options, createSurface) {
|
|
|
38405
38503
|
`replayMetafile: first 16 bytes: [${Array.from(hdrBytes).map((b) => b.toString(16).padStart(2, "0")).join(" ")}]`
|
|
38406
38504
|
);
|
|
38407
38505
|
}
|
|
38408
|
-
const opts =
|
|
38506
|
+
const opts = options2 ?? {};
|
|
38409
38507
|
const dpiScale = opts.dpiScale ?? DEFAULT_DPI_SCALE;
|
|
38410
38508
|
let view = new DataView(buffer);
|
|
38411
38509
|
let emfHeader = null;
|
|
@@ -38611,12 +38709,12 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth) {
|
|
|
38611
38709
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
38612
38710
|
return complete;
|
|
38613
38711
|
}
|
|
38614
|
-
async function convertMetafileToDataUrl(buffer,
|
|
38712
|
+
async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
|
|
38615
38713
|
await ensureNodeCanvasModule();
|
|
38616
38714
|
if (recursionDepth > MAX_METAFILE_RECURSION) {
|
|
38617
38715
|
return null;
|
|
38618
38716
|
}
|
|
38619
|
-
const opts = { ...
|
|
38717
|
+
const opts = { ...options2, gdiAntialias: options2?.gdiAntialias ?? false };
|
|
38620
38718
|
let canvas = null;
|
|
38621
38719
|
const result = await replayMetafile(buffer, opts, (w, h) => {
|
|
38622
38720
|
const setup = createCanvas(
|
|
@@ -38685,7 +38783,7 @@ async function resampleExact(bytes, spec, surface) {
|
|
|
38685
38783
|
}
|
|
38686
38784
|
return resampleImage(pixels.data, pixels.width, pixels.height, spec, { w: surface.width, h: surface.height });
|
|
38687
38785
|
}
|
|
38688
|
-
async function processDeferredImagesSvg(svg, deferredImages,
|
|
38786
|
+
async function processDeferredImagesSvg(svg, deferredImages, options2, recursionDepth) {
|
|
38689
38787
|
for (let idx = 0; idx < deferredImages.length; idx++) {
|
|
38690
38788
|
let img = deferredImages[idx];
|
|
38691
38789
|
try {
|
|
@@ -38708,7 +38806,7 @@ async function processDeferredImagesSvg(svg, deferredImages, options, recursionD
|
|
|
38708
38806
|
}
|
|
38709
38807
|
const nested = await convertMetafileToSvgTree(
|
|
38710
38808
|
bytes,
|
|
38711
|
-
{ ...
|
|
38809
|
+
{ ...options2, includeSize: true, idPrefix: void 0 },
|
|
38712
38810
|
recursionDepth + 1
|
|
38713
38811
|
);
|
|
38714
38812
|
if (nested) {
|
|
@@ -38745,7 +38843,7 @@ async function processDeferredImagesSvg(svg, deferredImages, options, recursionD
|
|
|
38745
38843
|
continue;
|
|
38746
38844
|
}
|
|
38747
38845
|
const slot = img.svgSlot ?? svg.reserveSlot();
|
|
38748
|
-
if (img.resample &&
|
|
38846
|
+
if (img.resample && options2.imageResampling === "exact" && !img.isMetafile) {
|
|
38749
38847
|
const block = await resampleExact(bytes, img.resample, svg.canvas);
|
|
38750
38848
|
if (block) {
|
|
38751
38849
|
svg.fillSlot(slot, { kind: "rgba", data: block.rgba, width: block.w, height: block.h }, [1, 0, 0, 1, 0, 0], block.x, block.y, block.w, block.h);
|
|
@@ -38765,16 +38863,16 @@ async function processDeferredImagesSvg(svg, deferredImages, options, recursionD
|
|
|
38765
38863
|
}
|
|
38766
38864
|
}
|
|
38767
38865
|
}
|
|
38768
|
-
async function convertMetafileToSvgTree(buffer,
|
|
38769
|
-
const svg = await replayToSvgContext(buffer,
|
|
38770
|
-
return svg ? svg.toTree({ includeSize:
|
|
38866
|
+
async function convertMetafileToSvgTree(buffer, options2, recursionDepth = 0) {
|
|
38867
|
+
const svg = await replayToSvgContext(buffer, options2, recursionDepth);
|
|
38868
|
+
return svg ? svg.toTree({ includeSize: options2?.includeSize }) : null;
|
|
38771
38869
|
}
|
|
38772
|
-
async function replayToSvgContext(buffer,
|
|
38870
|
+
async function replayToSvgContext(buffer, options2, recursionDepth = 0) {
|
|
38773
38871
|
await ensureNodeCanvasModule();
|
|
38774
38872
|
if (recursionDepth > MAX_METAFILE_RECURSION) {
|
|
38775
38873
|
return null;
|
|
38776
38874
|
}
|
|
38777
|
-
const opts =
|
|
38875
|
+
const opts = options2 ?? {};
|
|
38778
38876
|
const dpiScale = opts.dpiScale ?? DEFAULT_DPI_SCALE;
|
|
38779
38877
|
const idPrefix = opts.idPrefix ?? `emf${++svgDocumentCounter}-`;
|
|
38780
38878
|
let svg = null;
|
|
@@ -38791,18 +38889,18 @@ async function replayToSvgContext(buffer, options, recursionDepth = 0) {
|
|
|
38791
38889
|
await processDeferredImagesSvg(target, result.deferredImages, opts, recursionDepth);
|
|
38792
38890
|
return target;
|
|
38793
38891
|
}
|
|
38794
|
-
async function convertMetafileToSvg(buffer,
|
|
38795
|
-
const tree = await convertMetafileToSvgTree(buffer,
|
|
38892
|
+
async function convertMetafileToSvg(buffer, options2) {
|
|
38893
|
+
const tree = await convertMetafileToSvgTree(buffer, options2);
|
|
38796
38894
|
return tree ? svgTreeToString(tree) : null;
|
|
38797
38895
|
}
|
|
38798
|
-
async function convertMetafileToSvgDataUrl(buffer,
|
|
38799
|
-
const markup = await convertMetafileToSvg(buffer,
|
|
38896
|
+
async function convertMetafileToSvgDataUrl(buffer, options2) {
|
|
38897
|
+
const markup = await convertMetafileToSvg(buffer, options2);
|
|
38800
38898
|
return markup ? svgMarkupToDataUrl(markup) : null;
|
|
38801
38899
|
}
|
|
38802
38900
|
|
|
38803
38901
|
// src/load-system-fonts.ts
|
|
38804
38902
|
var FONT_FILE = /\.(ttf|ttc|fon|fnt)$/i;
|
|
38805
|
-
async function loadSystemFonts(
|
|
38903
|
+
async function loadSystemFonts(options2 = {}) {
|
|
38806
38904
|
if (typeof process === "undefined" || !process.versions?.node) {
|
|
38807
38905
|
return [];
|
|
38808
38906
|
}
|
|
@@ -38828,8 +38926,8 @@ async function loadSystemFonts(options = {}) {
|
|
|
38828
38926
|
} catch {
|
|
38829
38927
|
return [];
|
|
38830
38928
|
}
|
|
38831
|
-
const dirs =
|
|
38832
|
-
const maxDepth =
|
|
38929
|
+
const dirs = options2.dirs ?? defaultFontDirs(path, os);
|
|
38930
|
+
const maxDepth = options2.maxDepth ?? 4;
|
|
38833
38931
|
const files = [];
|
|
38834
38932
|
const seen = /* @__PURE__ */ new Set();
|
|
38835
38933
|
const walk2 = async (dir, depth) => {
|
|
@@ -38847,7 +38945,7 @@ async function loadSystemFonts(options = {}) {
|
|
|
38847
38945
|
}
|
|
38848
38946
|
} else if (FONT_FILE.test(e.name)) {
|
|
38849
38947
|
const key = full.toLowerCase();
|
|
38850
|
-
if (!seen.has(key) && (!
|
|
38948
|
+
if (!seen.has(key) && (!options2.filter || options2.filter(full, e.name.toLowerCase()))) {
|
|
38851
38949
|
seen.add(key);
|
|
38852
38950
|
files.push(full);
|
|
38853
38951
|
}
|