pptx-glimpse 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -29,7 +29,8 @@ __export(index_exports, {
29
29
  createOpentypeTextMeasurerFromBuffers: () => createOpentypeTextMeasurerFromBuffers,
30
30
  getMappedFont: () => getMappedFont,
31
31
  getWarningEntries: () => getWarningEntries,
32
- getWarningSummary: () => getWarningSummary
32
+ getWarningSummary: () => getWarningSummary,
33
+ initResvgWasm: () => initResvgWasm
33
34
  });
34
35
  module.exports = __toCommonJS(index_exports);
35
36
 
@@ -1570,15 +1571,36 @@ function parseXmlOrdered(xml) {
1570
1571
  }
1571
1572
 
1572
1573
  // src/png/png-converter.ts
1573
- var import_resvg_js = require("@resvg/resvg-js");
1574
+ var import_resvg_wasm = require("@resvg/resvg-wasm");
1575
+ var import_promises2 = require("fs/promises");
1576
+ var import_module = require("module");
1577
+ var import_meta = {};
1578
+ var wasmInitPromise = null;
1579
+ function resolveWasmPath() {
1580
+ const baseUrl = import_meta.url || `file://${__filename}`;
1581
+ const require2 = (0, import_module.createRequire)(baseUrl);
1582
+ return require2.resolve("@resvg/resvg-wasm/index_bg.wasm");
1583
+ }
1584
+ async function initResvgWasm() {
1585
+ if (!wasmInitPromise) {
1586
+ wasmInitPromise = (async () => {
1587
+ const wasmPath = resolveWasmPath();
1588
+ const wasmBuffer = await (0, import_promises2.readFile)(wasmPath);
1589
+ await (0, import_resvg_wasm.initWasm)(wasmBuffer);
1590
+ })();
1591
+ }
1592
+ await wasmInitPromise;
1593
+ }
1574
1594
  async function svgToPng(svgString, options) {
1595
+ await initResvgWasm();
1575
1596
  const resvgOptions = {};
1576
1597
  if (options?.width) {
1577
1598
  resvgOptions.fitTo = { mode: "width", value: options.width };
1578
1599
  } else if (options?.height) {
1579
1600
  resvgOptions.fitTo = { mode: "height", value: options.height };
1580
1601
  }
1581
- const rendered = await (0, import_resvg_js.renderAsync)(svgString, resvgOptions);
1602
+ const resvg = new import_resvg_wasm.Resvg(svgString, resvgOptions);
1603
+ const rendered = resvg.render();
1582
1604
  return {
1583
1605
  png: Buffer.from(rendered.asPng()),
1584
1606
  width: rendered.width,
@@ -8892,5 +8914,6 @@ function collectFontsFromTextBody(textBody, fonts) {
8892
8914
  createOpentypeTextMeasurerFromBuffers,
8893
8915
  getMappedFont,
8894
8916
  getWarningEntries,
8895
- getWarningSummary
8917
+ getWarningSummary,
8918
+ initResvgWasm
8896
8919
  });
package/dist/index.d.cts CHANGED
@@ -177,4 +177,11 @@ interface OpentypeSetup {
177
177
  */
178
178
  declare function createOpentypeSetupFromBuffers(fontBuffers: FontBuffer[], fontMapping?: FontMapping): Promise<OpentypeSetup | null>;
179
179
 
180
- export { type ConvertOptions, DEFAULT_FONT_MAPPING, type FontBuffer, type FontMapping, type LogLevel, type OpentypeSetup, type SlideImage, type SlideSvg, type UsedFonts, type WarningEntry, type WarningSummary, collectUsedFonts, convertPptxToPng, convertPptxToSvg, createFontMapping, createOpentypeSetupFromBuffers, createOpentypeTextMeasurerFromBuffers, getMappedFont, getWarningEntries, getWarningSummary };
180
+ /**
181
+ * resvg-wasm の WASM モジュールを初期化する。
182
+ * 明示的に呼び出さなくても、初回の PNG 変換時に自動的に初期化される。
183
+ * アプリケーション起動時に初期化しておきたい場合に使用する。
184
+ */
185
+ declare function initResvgWasm(): Promise<void>;
186
+
187
+ export { type ConvertOptions, DEFAULT_FONT_MAPPING, type FontBuffer, type FontMapping, type LogLevel, type OpentypeSetup, type SlideImage, type SlideSvg, type UsedFonts, type WarningEntry, type WarningSummary, collectUsedFonts, convertPptxToPng, convertPptxToSvg, createFontMapping, createOpentypeSetupFromBuffers, createOpentypeTextMeasurerFromBuffers, getMappedFont, getWarningEntries, getWarningSummary, initResvgWasm };
package/dist/index.d.ts CHANGED
@@ -177,4 +177,11 @@ interface OpentypeSetup {
177
177
  */
178
178
  declare function createOpentypeSetupFromBuffers(fontBuffers: FontBuffer[], fontMapping?: FontMapping): Promise<OpentypeSetup | null>;
179
179
 
180
- export { type ConvertOptions, DEFAULT_FONT_MAPPING, type FontBuffer, type FontMapping, type LogLevel, type OpentypeSetup, type SlideImage, type SlideSvg, type UsedFonts, type WarningEntry, type WarningSummary, collectUsedFonts, convertPptxToPng, convertPptxToSvg, createFontMapping, createOpentypeSetupFromBuffers, createOpentypeTextMeasurerFromBuffers, getMappedFont, getWarningEntries, getWarningSummary };
180
+ /**
181
+ * resvg-wasm の WASM モジュールを初期化する。
182
+ * 明示的に呼び出さなくても、初回の PNG 変換時に自動的に初期化される。
183
+ * アプリケーション起動時に初期化しておきたい場合に使用する。
184
+ */
185
+ declare function initResvgWasm(): Promise<void>;
186
+
187
+ export { type ConvertOptions, DEFAULT_FONT_MAPPING, type FontBuffer, type FontMapping, type LogLevel, type OpentypeSetup, type SlideImage, type SlideSvg, type UsedFonts, type WarningEntry, type WarningSummary, collectUsedFonts, convertPptxToPng, convertPptxToSvg, createFontMapping, createOpentypeSetupFromBuffers, createOpentypeTextMeasurerFromBuffers, getMappedFont, getWarningEntries, getWarningSummary, initResvgWasm };
package/dist/index.js CHANGED
@@ -1535,15 +1535,35 @@ function parseXmlOrdered(xml) {
1535
1535
  }
1536
1536
 
1537
1537
  // src/png/png-converter.ts
1538
- import { renderAsync } from "@resvg/resvg-js";
1538
+ import { initWasm, Resvg } from "@resvg/resvg-wasm";
1539
+ import { readFile as readFile2 } from "fs/promises";
1540
+ import { createRequire } from "module";
1541
+ var wasmInitPromise = null;
1542
+ function resolveWasmPath() {
1543
+ const baseUrl = import.meta.url || `file://${__filename}`;
1544
+ const require2 = createRequire(baseUrl);
1545
+ return require2.resolve("@resvg/resvg-wasm/index_bg.wasm");
1546
+ }
1547
+ async function initResvgWasm() {
1548
+ if (!wasmInitPromise) {
1549
+ wasmInitPromise = (async () => {
1550
+ const wasmPath = resolveWasmPath();
1551
+ const wasmBuffer = await readFile2(wasmPath);
1552
+ await initWasm(wasmBuffer);
1553
+ })();
1554
+ }
1555
+ await wasmInitPromise;
1556
+ }
1539
1557
  async function svgToPng(svgString, options) {
1558
+ await initResvgWasm();
1540
1559
  const resvgOptions = {};
1541
1560
  if (options?.width) {
1542
1561
  resvgOptions.fitTo = { mode: "width", value: options.width };
1543
1562
  } else if (options?.height) {
1544
1563
  resvgOptions.fitTo = { mode: "height", value: options.height };
1545
1564
  }
1546
- const rendered = await renderAsync(svgString, resvgOptions);
1565
+ const resvg = new Resvg(svgString, resvgOptions);
1566
+ const rendered = resvg.render();
1547
1567
  return {
1548
1568
  png: Buffer.from(rendered.asPng()),
1549
1569
  width: rendered.width,
@@ -8856,5 +8876,6 @@ export {
8856
8876
  createOpentypeTextMeasurerFromBuffers,
8857
8877
  getMappedFont,
8858
8878
  getWarningEntries,
8859
- getWarningSummary
8879
+ getWarningSummary,
8880
+ initResvgWasm
8860
8881
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-glimpse",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "A lightweight JavaScript library for rendering PowerPoint (.pptx) files as SVG or PNG in Node.js. No LibreOffice required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -64,7 +64,7 @@
64
64
  "author": "hirokisakabe",
65
65
  "license": "MIT",
66
66
  "dependencies": {
67
- "@resvg/resvg-js": "^2.6.2",
67
+ "@resvg/resvg-wasm": "^2.6.2",
68
68
  "fast-xml-parser": "^5.3.6",
69
69
  "fflate": "^0.8.2",
70
70
  "opentype.js": "^1.3.4"