@mlightcad/emf-converter 1.15.10 → 1.15.12
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/index.js +26 -10
- package/dist/index.mjs +26 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -529,12 +529,14 @@ function getStockObject(index) {
|
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
async function blobToDataUrl(blob) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
532
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
533
|
+
let binary = "";
|
|
534
|
+
const chunkSize = 32768;
|
|
535
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
536
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
|
|
537
|
+
}
|
|
538
|
+
const mime = blob.type || "application/octet-stream";
|
|
539
|
+
return `data:${mime};base64,${btoa(binary)}`;
|
|
538
540
|
}
|
|
539
541
|
async function exportCanvasToPngDataUrl(canvas) {
|
|
540
542
|
if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) {
|
|
@@ -1084,6 +1086,13 @@ function reapplyClipRegion(holder, region, identityTransform = false) {
|
|
|
1084
1086
|
}
|
|
1085
1087
|
|
|
1086
1088
|
// src/emf-dib-rle-decoder.ts
|
|
1089
|
+
function createImageData(data, width, height) {
|
|
1090
|
+
const ImageDataCtor = globalThis.ImageData;
|
|
1091
|
+
if (typeof ImageDataCtor === "function") {
|
|
1092
|
+
return new ImageDataCtor(data, width, height);
|
|
1093
|
+
}
|
|
1094
|
+
return { data, width, height, colorSpace: "srgb" };
|
|
1095
|
+
}
|
|
1087
1096
|
function decodeRleBitmap(view, bitsOffset, bitsSize, width, height, _topDown, isRle4, colorTable, out, setPixel) {
|
|
1088
1097
|
let x = 0;
|
|
1089
1098
|
let y = height - 1;
|
|
@@ -1178,7 +1187,7 @@ function decodeRleBitmap(view, bitsOffset, bitsSize, width, height, _topDown, is
|
|
|
1178
1187
|
}
|
|
1179
1188
|
}
|
|
1180
1189
|
}
|
|
1181
|
-
return
|
|
1190
|
+
return createImageData(
|
|
1182
1191
|
new Uint8ClampedArray(out.buffer, out.byteOffset, out.byteLength),
|
|
1183
1192
|
width,
|
|
1184
1193
|
height
|
|
@@ -1388,7 +1397,7 @@ function decodeDibToImageData(view, bmiOffset, bitsOffset, bitsSize) {
|
|
|
1388
1397
|
masks,
|
|
1389
1398
|
out
|
|
1390
1399
|
);
|
|
1391
|
-
return
|
|
1400
|
+
return createImageData(out, width, height);
|
|
1392
1401
|
}
|
|
1393
1402
|
|
|
1394
1403
|
// src/emf-gdi-draw-text-bitmap.ts
|
|
@@ -4839,6 +4848,13 @@ function replayWmfRecords(view, ctx, header, canvasW, canvasH, replayOptions = {
|
|
|
4839
4848
|
|
|
4840
4849
|
// src/emf-converter.ts
|
|
4841
4850
|
var MAX_METAFILE_RECURSION = 3;
|
|
4851
|
+
async function decodeImageBitmap(blob) {
|
|
4852
|
+
const decode = globalThis.createImageBitmap;
|
|
4853
|
+
if (typeof decode !== "function") {
|
|
4854
|
+
throw new Error("createImageBitmap is not available in this runtime");
|
|
4855
|
+
}
|
|
4856
|
+
return decode(blob);
|
|
4857
|
+
}
|
|
4842
4858
|
async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
4843
4859
|
emfLog(
|
|
4844
4860
|
`processDeferredImages: processing ${deferredImages.length} deferred images (recursionDepth=${recursionDepth})...`
|
|
@@ -4885,7 +4901,7 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
|
4885
4901
|
emfLog(
|
|
4886
4902
|
` Deferred image [${idx}]: creating ImageBitmap from ${metaBlob.size} byte blob (${mime})...`
|
|
4887
4903
|
);
|
|
4888
|
-
const bitmap = await
|
|
4904
|
+
const bitmap = await decodeImageBitmap(metaBlob);
|
|
4889
4905
|
emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
|
|
4890
4906
|
ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
|
|
4891
4907
|
bitmap.close();
|
|
@@ -4897,7 +4913,7 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
|
4897
4913
|
` Deferred image [${idx}]: creating ImageBitmap from ${plainBuffer.byteLength} byte blob...`
|
|
4898
4914
|
);
|
|
4899
4915
|
const blob = new Blob([plainBuffer]);
|
|
4900
|
-
const bitmap = await
|
|
4916
|
+
const bitmap = await decodeImageBitmap(blob);
|
|
4901
4917
|
emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
|
|
4902
4918
|
ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
|
|
4903
4919
|
bitmap.close();
|
package/dist/index.mjs
CHANGED
|
@@ -527,12 +527,14 @@ function getStockObject(index) {
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
async function blobToDataUrl(blob) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
530
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
531
|
+
let binary = "";
|
|
532
|
+
const chunkSize = 32768;
|
|
533
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
534
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
|
|
535
|
+
}
|
|
536
|
+
const mime = blob.type || "application/octet-stream";
|
|
537
|
+
return `data:${mime};base64,${btoa(binary)}`;
|
|
536
538
|
}
|
|
537
539
|
async function exportCanvasToPngDataUrl(canvas) {
|
|
538
540
|
if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) {
|
|
@@ -1082,6 +1084,13 @@ function reapplyClipRegion(holder, region, identityTransform = false) {
|
|
|
1082
1084
|
}
|
|
1083
1085
|
|
|
1084
1086
|
// src/emf-dib-rle-decoder.ts
|
|
1087
|
+
function createImageData(data, width, height) {
|
|
1088
|
+
const ImageDataCtor = globalThis.ImageData;
|
|
1089
|
+
if (typeof ImageDataCtor === "function") {
|
|
1090
|
+
return new ImageDataCtor(data, width, height);
|
|
1091
|
+
}
|
|
1092
|
+
return { data, width, height, colorSpace: "srgb" };
|
|
1093
|
+
}
|
|
1085
1094
|
function decodeRleBitmap(view, bitsOffset, bitsSize, width, height, _topDown, isRle4, colorTable, out, setPixel) {
|
|
1086
1095
|
let x = 0;
|
|
1087
1096
|
let y = height - 1;
|
|
@@ -1176,7 +1185,7 @@ function decodeRleBitmap(view, bitsOffset, bitsSize, width, height, _topDown, is
|
|
|
1176
1185
|
}
|
|
1177
1186
|
}
|
|
1178
1187
|
}
|
|
1179
|
-
return
|
|
1188
|
+
return createImageData(
|
|
1180
1189
|
new Uint8ClampedArray(out.buffer, out.byteOffset, out.byteLength),
|
|
1181
1190
|
width,
|
|
1182
1191
|
height
|
|
@@ -1386,7 +1395,7 @@ function decodeDibToImageData(view, bmiOffset, bitsOffset, bitsSize) {
|
|
|
1386
1395
|
masks,
|
|
1387
1396
|
out
|
|
1388
1397
|
);
|
|
1389
|
-
return
|
|
1398
|
+
return createImageData(out, width, height);
|
|
1390
1399
|
}
|
|
1391
1400
|
|
|
1392
1401
|
// src/emf-gdi-draw-text-bitmap.ts
|
|
@@ -4837,6 +4846,13 @@ function replayWmfRecords(view, ctx, header, canvasW, canvasH, replayOptions = {
|
|
|
4837
4846
|
|
|
4838
4847
|
// src/emf-converter.ts
|
|
4839
4848
|
var MAX_METAFILE_RECURSION = 3;
|
|
4849
|
+
async function decodeImageBitmap(blob) {
|
|
4850
|
+
const decode = globalThis.createImageBitmap;
|
|
4851
|
+
if (typeof decode !== "function") {
|
|
4852
|
+
throw new Error("createImageBitmap is not available in this runtime");
|
|
4853
|
+
}
|
|
4854
|
+
return decode(blob);
|
|
4855
|
+
}
|
|
4840
4856
|
async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
4841
4857
|
emfLog(
|
|
4842
4858
|
`processDeferredImages: processing ${deferredImages.length} deferred images (recursionDepth=${recursionDepth})...`
|
|
@@ -4883,7 +4899,7 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
|
4883
4899
|
emfLog(
|
|
4884
4900
|
` Deferred image [${idx}]: creating ImageBitmap from ${metaBlob.size} byte blob (${mime})...`
|
|
4885
4901
|
);
|
|
4886
|
-
const bitmap = await
|
|
4902
|
+
const bitmap = await decodeImageBitmap(metaBlob);
|
|
4887
4903
|
emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
|
|
4888
4904
|
ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
|
|
4889
4905
|
bitmap.close();
|
|
@@ -4895,7 +4911,7 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
|
|
|
4895
4911
|
` Deferred image [${idx}]: creating ImageBitmap from ${plainBuffer.byteLength} byte blob...`
|
|
4896
4912
|
);
|
|
4897
4913
|
const blob = new Blob([plainBuffer]);
|
|
4898
|
-
const bitmap = await
|
|
4914
|
+
const bitmap = await decodeImageBitmap(blob);
|
|
4899
4915
|
emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
|
|
4900
4916
|
ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
|
|
4901
4917
|
bitmap.close();
|