emf-converter 4.25.0 → 4.25.2

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 CHANGED
@@ -13,7 +13,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
13
13
  throw Error('Dynamic require of "' + x + '" is not supported');
14
14
  });
15
15
  var __commonJS = (cb, mod3) => function __require2() {
16
- return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
16
+ try {
17
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
18
+ } catch (e) {
19
+ throw mod3 = 0, e;
20
+ }
17
21
  };
18
22
  var __copyProps = (to, from, except, desc) => {
19
23
  if (from && typeof from === "object" || typeof from === "function") {
@@ -43624,6 +43628,10 @@ function parseWmfHeader(view) {
43624
43628
  boundsBottom = view.getInt16(12, true);
43625
43629
  unitsPerInch = view.getUint16(14, true) || 96;
43626
43630
  headerOffset = 22;
43631
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43632
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43633
+ headerOffset = 24;
43634
+ }
43627
43635
  }
43628
43636
  if (headerOffset + 18 > view.byteLength) {
43629
43637
  return null;
@@ -56288,7 +56296,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56288
56296
  continue;
56289
56297
  }
56290
56298
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56291
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56299
+ if (recType === EMR_SAVEDC) {
56300
+ saveSkippedDc(rCtx);
56301
+ } else if (recType === EMR_RESTOREDC) {
56302
+ if (recSize >= 12) {
56303
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56304
+ }
56305
+ } else {
56292
56306
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56293
56307
  }
56294
56308
  offset += recSize;
@@ -56314,6 +56328,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56314
56328
  }
56315
56329
  return allDeferredImages;
56316
56330
  }
56331
+ function saveSkippedDc(rCtx) {
56332
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56333
+ rCtx.skippedDcStack.push({
56334
+ state: cloneState(rCtx.state),
56335
+ mapping: {
56336
+ mapMode: rCtx.mapMode,
56337
+ windowOrg: { ...rCtx.windowOrg },
56338
+ windowExt: { ...rCtx.windowExt },
56339
+ viewportOrg: { ...rCtx.viewportOrg },
56340
+ viewportExt: { ...rCtx.viewportExt },
56341
+ useMappingMode: rCtx.useMappingMode
56342
+ }
56343
+ });
56344
+ }
56345
+ function restoreSkippedDc(rCtx, level) {
56346
+ const stack = rCtx.skippedDcStack ?? [];
56347
+ const at = level < 0 ? stack.length + level : level - 1;
56348
+ if (at < 0 || at >= stack.length) {
56349
+ return;
56350
+ }
56351
+ const saved = stack[at];
56352
+ stack.length = at;
56353
+ Object.assign(rCtx.state, saved.state);
56354
+ Object.assign(rCtx, saved.mapping);
56355
+ }
56317
56356
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56318
56357
  const view = new DataView(bytes);
56319
56358
  const header = parseEmfHeader(view);
package/dist/browser.mjs CHANGED
@@ -11,7 +11,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
13
  var __commonJS = (cb, mod3) => function __require2() {
14
- return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
14
+ try {
15
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
16
+ } catch (e) {
17
+ throw mod3 = 0, e;
18
+ }
15
19
  };
16
20
  var __copyProps = (to, from, except, desc) => {
17
21
  if (from && typeof from === "object" || typeof from === "function") {
@@ -43622,6 +43626,10 @@ function parseWmfHeader(view) {
43622
43626
  boundsBottom = view.getInt16(12, true);
43623
43627
  unitsPerInch = view.getUint16(14, true) || 96;
43624
43628
  headerOffset = 22;
43629
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43630
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43631
+ headerOffset = 24;
43632
+ }
43625
43633
  }
43626
43634
  if (headerOffset + 18 > view.byteLength) {
43627
43635
  return null;
@@ -56286,7 +56294,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56286
56294
  continue;
56287
56295
  }
56288
56296
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56289
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56297
+ if (recType === EMR_SAVEDC) {
56298
+ saveSkippedDc(rCtx);
56299
+ } else if (recType === EMR_RESTOREDC) {
56300
+ if (recSize >= 12) {
56301
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56302
+ }
56303
+ } else {
56290
56304
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56291
56305
  }
56292
56306
  offset += recSize;
@@ -56312,6 +56326,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56312
56326
  }
56313
56327
  return allDeferredImages;
56314
56328
  }
56329
+ function saveSkippedDc(rCtx) {
56330
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56331
+ rCtx.skippedDcStack.push({
56332
+ state: cloneState(rCtx.state),
56333
+ mapping: {
56334
+ mapMode: rCtx.mapMode,
56335
+ windowOrg: { ...rCtx.windowOrg },
56336
+ windowExt: { ...rCtx.windowExt },
56337
+ viewportOrg: { ...rCtx.viewportOrg },
56338
+ viewportExt: { ...rCtx.viewportExt },
56339
+ useMappingMode: rCtx.useMappingMode
56340
+ }
56341
+ });
56342
+ }
56343
+ function restoreSkippedDc(rCtx, level) {
56344
+ const stack = rCtx.skippedDcStack ?? [];
56345
+ const at = level < 0 ? stack.length + level : level - 1;
56346
+ if (at < 0 || at >= stack.length) {
56347
+ return;
56348
+ }
56349
+ const saved = stack[at];
56350
+ stack.length = at;
56351
+ Object.assign(rCtx.state, saved.state);
56352
+ Object.assign(rCtx, saved.mapping);
56353
+ }
56315
56354
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56316
56355
  const view = new DataView(bytes);
56317
56356
  const header = parseEmfHeader(view);
package/dist/index.d.mts CHANGED
@@ -763,4 +763,5 @@ interface MetafileInfoOptions {
763
763
  */
764
764
  declare function getMetafileInfo(input: MetafileInput, options?: MetafileInfoOptions): Promise<MetafileInfo | null>;
765
765
 
766
- export { type ConvertOptions, type ConvertedImage, type CreateElement, DEFAULT_DPI_SCALE, type EmfConvertOptions, type JpegConvertOptions, type LoadSystemFontsOptions, type MetafileFont, type MetafileInfo, type MetafileInfoOptions, type MetafileInput, type MetafileOutputFormat, type MetafileRect, type PdfConvertOptions, type PdfDecodedImage, type PdfOptions, type RgbaImage, type SvgConvertOptions, type SvgJsxOptions, type SvgNode, type WebpConvertOptions, convertMetafile, convertMetafileToDataUrl, convertMetafileToImageData, convertMetafileToJpegDataUrl, convertMetafileToPdf, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, convertMetafileToWebpDataUrl, getMetafileInfo, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToPdf, svgTreeToReact, svgTreeToString };
766
+ export { DEFAULT_DPI_SCALE, convertMetafile, convertMetafileToDataUrl, convertMetafileToImageData, convertMetafileToJpegDataUrl, convertMetafileToPdf, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, convertMetafileToWebpDataUrl, getMetafileInfo, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToPdf, svgTreeToReact, svgTreeToString };
767
+ export type { ConvertOptions, ConvertedImage, CreateElement, EmfConvertOptions, JpegConvertOptions, LoadSystemFontsOptions, MetafileFont, MetafileInfo, MetafileInfoOptions, MetafileInput, MetafileOutputFormat, MetafileRect, PdfConvertOptions, PdfDecodedImage, PdfOptions, RgbaImage, SvgConvertOptions, SvgJsxOptions, SvgNode, WebpConvertOptions };
package/dist/index.d.ts CHANGED
@@ -763,4 +763,5 @@ interface MetafileInfoOptions {
763
763
  */
764
764
  declare function getMetafileInfo(input: MetafileInput, options?: MetafileInfoOptions): Promise<MetafileInfo | null>;
765
765
 
766
- export { type ConvertOptions, type ConvertedImage, type CreateElement, DEFAULT_DPI_SCALE, type EmfConvertOptions, type JpegConvertOptions, type LoadSystemFontsOptions, type MetafileFont, type MetafileInfo, type MetafileInfoOptions, type MetafileInput, type MetafileOutputFormat, type MetafileRect, type PdfConvertOptions, type PdfDecodedImage, type PdfOptions, type RgbaImage, type SvgConvertOptions, type SvgJsxOptions, type SvgNode, type WebpConvertOptions, convertMetafile, convertMetafileToDataUrl, convertMetafileToImageData, convertMetafileToJpegDataUrl, convertMetafileToPdf, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, convertMetafileToWebpDataUrl, getMetafileInfo, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToPdf, svgTreeToReact, svgTreeToString };
766
+ export { DEFAULT_DPI_SCALE, convertMetafile, convertMetafileToDataUrl, convertMetafileToImageData, convertMetafileToJpegDataUrl, convertMetafileToPdf, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, convertMetafileToWebpDataUrl, getMetafileInfo, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToPdf, svgTreeToReact, svgTreeToString };
767
+ export type { ConvertOptions, ConvertedImage, CreateElement, EmfConvertOptions, JpegConvertOptions, LoadSystemFontsOptions, MetafileFont, MetafileInfo, MetafileInfoOptions, MetafileInput, MetafileOutputFormat, MetafileRect, PdfConvertOptions, PdfDecodedImage, PdfOptions, RgbaImage, SvgConvertOptions, SvgJsxOptions, SvgNode, WebpConvertOptions };
package/dist/index.js CHANGED
@@ -13,7 +13,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
13
13
  throw Error('Dynamic require of "' + x + '" is not supported');
14
14
  });
15
15
  var __commonJS = (cb, mod3) => function __require2() {
16
- return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
16
+ try {
17
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
18
+ } catch (e) {
19
+ throw mod3 = 0, e;
20
+ }
17
21
  };
18
22
  var __copyProps = (to, from, except, desc) => {
19
23
  if (from && typeof from === "object" || typeof from === "function") {
@@ -43625,6 +43629,10 @@ function parseWmfHeader(view) {
43625
43629
  boundsBottom = view.getInt16(12, true);
43626
43630
  unitsPerInch = view.getUint16(14, true) || 96;
43627
43631
  headerOffset = 22;
43632
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43633
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43634
+ headerOffset = 24;
43635
+ }
43628
43636
  }
43629
43637
  if (headerOffset + 18 > view.byteLength) {
43630
43638
  return null;
@@ -56289,7 +56297,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56289
56297
  continue;
56290
56298
  }
56291
56299
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56292
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56300
+ if (recType === EMR_SAVEDC) {
56301
+ saveSkippedDc(rCtx);
56302
+ } else if (recType === EMR_RESTOREDC) {
56303
+ if (recSize >= 12) {
56304
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56305
+ }
56306
+ } else {
56293
56307
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56294
56308
  }
56295
56309
  offset += recSize;
@@ -56315,6 +56329,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56315
56329
  }
56316
56330
  return allDeferredImages;
56317
56331
  }
56332
+ function saveSkippedDc(rCtx) {
56333
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56334
+ rCtx.skippedDcStack.push({
56335
+ state: cloneState(rCtx.state),
56336
+ mapping: {
56337
+ mapMode: rCtx.mapMode,
56338
+ windowOrg: { ...rCtx.windowOrg },
56339
+ windowExt: { ...rCtx.windowExt },
56340
+ viewportOrg: { ...rCtx.viewportOrg },
56341
+ viewportExt: { ...rCtx.viewportExt },
56342
+ useMappingMode: rCtx.useMappingMode
56343
+ }
56344
+ });
56345
+ }
56346
+ function restoreSkippedDc(rCtx, level) {
56347
+ const stack = rCtx.skippedDcStack ?? [];
56348
+ const at = level < 0 ? stack.length + level : level - 1;
56349
+ if (at < 0 || at >= stack.length) {
56350
+ return;
56351
+ }
56352
+ const saved = stack[at];
56353
+ stack.length = at;
56354
+ Object.assign(rCtx.state, saved.state);
56355
+ Object.assign(rCtx, saved.mapping);
56356
+ }
56318
56357
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56319
56358
  const view = new DataView(bytes);
56320
56359
  const header = parseEmfHeader(view);
package/dist/index.mjs CHANGED
@@ -11,7 +11,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
13
  var __commonJS = (cb, mod3) => function __require2() {
14
- return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
14
+ try {
15
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
16
+ } catch (e) {
17
+ throw mod3 = 0, e;
18
+ }
15
19
  };
16
20
  var __copyProps = (to, from, except, desc) => {
17
21
  if (from && typeof from === "object" || typeof from === "function") {
@@ -43623,6 +43627,10 @@ function parseWmfHeader(view) {
43623
43627
  boundsBottom = view.getInt16(12, true);
43624
43628
  unitsPerInch = view.getUint16(14, true) || 96;
43625
43629
  headerOffset = 22;
43630
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43631
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43632
+ headerOffset = 24;
43633
+ }
43626
43634
  }
43627
43635
  if (headerOffset + 18 > view.byteLength) {
43628
43636
  return null;
@@ -56287,7 +56295,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56287
56295
  continue;
56288
56296
  }
56289
56297
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56290
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56298
+ if (recType === EMR_SAVEDC) {
56299
+ saveSkippedDc(rCtx);
56300
+ } else if (recType === EMR_RESTOREDC) {
56301
+ if (recSize >= 12) {
56302
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56303
+ }
56304
+ } else {
56291
56305
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56292
56306
  }
56293
56307
  offset += recSize;
@@ -56313,6 +56327,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56313
56327
  }
56314
56328
  return allDeferredImages;
56315
56329
  }
56330
+ function saveSkippedDc(rCtx) {
56331
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56332
+ rCtx.skippedDcStack.push({
56333
+ state: cloneState(rCtx.state),
56334
+ mapping: {
56335
+ mapMode: rCtx.mapMode,
56336
+ windowOrg: { ...rCtx.windowOrg },
56337
+ windowExt: { ...rCtx.windowExt },
56338
+ viewportOrg: { ...rCtx.viewportOrg },
56339
+ viewportExt: { ...rCtx.viewportExt },
56340
+ useMappingMode: rCtx.useMappingMode
56341
+ }
56342
+ });
56343
+ }
56344
+ function restoreSkippedDc(rCtx, level) {
56345
+ const stack = rCtx.skippedDcStack ?? [];
56346
+ const at = level < 0 ? stack.length + level : level - 1;
56347
+ if (at < 0 || at >= stack.length) {
56348
+ return;
56349
+ }
56350
+ const saved = stack[at];
56351
+ stack.length = at;
56352
+ Object.assign(rCtx.state, saved.state);
56353
+ Object.assign(rCtx, saved.mapping);
56354
+ }
56316
56355
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56317
56356
  const view = new DataView(bytes);
56318
56357
  const header = parseEmfHeader(view);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.25.0",
3
+ "version": "4.25.2",
4
4
  "description": "Convert EMF/WMF metafile binaries to PNG, JPEG or WebP data URLs, SVG (markup, data URL, React/JSX) or PDF",
5
5
  "keywords": [
6
6
  "canvas",
@@ -66,7 +66,7 @@
66
66
  "docs:preview": "vitepress preview docs"
67
67
  },
68
68
  "devDependencies": {
69
- "@napi-rs/canvas": "^1.0.10",
69
+ "@napi-rs/canvas": "1.0.10",
70
70
  "@types/node": "^26.6.4",
71
71
  "@types/react": "^19.3.0",
72
72
  "@types/react-dom": "^19.3.0",
@@ -76,13 +76,16 @@
76
76
  "pdfjs-dist": "^6.4.299",
77
77
  "react": "^19.3.0",
78
78
  "react-dom": "^19.3.0",
79
- "tsup": "^8.5.1",
79
+ "tsup": "^9.0.0",
80
80
  "typescript": "^6.0.3",
81
81
  "utif": "3.1.0",
82
82
  "vitepress": "^1.6.4",
83
83
  "vitest": "^5.0.3",
84
84
  "vue-tsc": "^3.3.12"
85
85
  },
86
+ "overrides": {
87
+ "@napi-rs/canvas": "1.0.10"
88
+ },
86
89
  "peerDependencies": {
87
90
  "@napi-rs/canvas": "^1.0.9"
88
91
  },