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