wordinweb 0.3.3 → 0.3.4

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.
@@ -21731,12 +21731,16 @@ function renderToDom(doc, layout, container, options = {}, prev) {
21731
21731
  }
21732
21732
  return handle;
21733
21733
  }
21734
- function buildPrintHtml(root, pageWidthPx, pageHeightPx) {
21735
- const head = [`<base href="${document.location.href}">`];
21736
- for (const node of Array.from(document.head.querySelectorAll("style, link[rel=stylesheet]"))) {
21737
- head.push(node.outerHTML);
21738
- }
21739
- head.push(`<style>
21734
+ var pendingPaints = /* @__PURE__ */ new Set();
21735
+ function trackPaint(work) {
21736
+ pendingPaints.add(work);
21737
+ void work.finally(() => pendingPaints.delete(work));
21738
+ }
21739
+ async function paintsSettled() {
21740
+ while (pendingPaints.size > 0) await Promise.allSettled([...pendingPaints]);
21741
+ }
21742
+ function printStylesheet(pageWidthPx, pageHeightPx) {
21743
+ return `
21740
21744
  @page { size: ${pageWidthPx / 96}in ${pageHeightPx / 96}in; margin: 0; }
21741
21745
  html, body { margin: 0; padding: 0; }
21742
21746
  .dxw-pages { display: block !important; padding: 0 !important; gap: 0 !important; }
@@ -21746,7 +21750,14 @@ function buildPrintHtml(root, pageWidthPx, pageHeightPx) {
21746
21750
  }
21747
21751
  .dxw-page { box-shadow: none !important; margin: 0 !important; break-after: page; }
21748
21752
  .dxw-comment-card, .dxw-hf-marker { display: none !important; }
21749
- </style>`);
21753
+ `;
21754
+ }
21755
+ function buildPrintHtml(root, pageWidthPx, pageHeightPx) {
21756
+ const head = [`<base href="${document.location.href}">`];
21757
+ for (const node of Array.from(document.head.querySelectorAll("style, link[rel=stylesheet]"))) {
21758
+ head.push(node.outerHTML);
21759
+ }
21760
+ head.push(`<style>${printStylesheet(pageWidthPx, pageHeightPx)}</style>`);
21750
21761
  return `<!doctype html><html><head>${head.join("")}</head><body>${root.outerHTML}</body></html>`;
21751
21762
  }
21752
21763
  function printPages(root, pageWidthPx, pageHeightPx) {
@@ -22905,13 +22916,13 @@ function renderItem(doc, item2, urls, interactive) {
22905
22916
  if (cachedWmf) {
22906
22917
  decoded = cachedWmf;
22907
22918
  } else {
22908
- void import("./wmf-53LMIKNI.js").then(({ renderWmf }) => {
22919
+ trackPaint(import("./wmf-53LMIKNI.js").then(({ renderWmf }) => {
22909
22920
  const url = renderWmf(bytes, item2.width, item2.height);
22910
22921
  if (url) {
22911
22922
  setDocDerivedSrc(doc, wmfKey, url);
22912
22923
  img.src = url;
22913
22924
  }
22914
- });
22925
+ }));
22915
22926
  }
22916
22927
  } else if (ext === "emf") {
22917
22928
  const emfKey = `emf:${item2.part}`;
@@ -22920,12 +22931,12 @@ function renderItem(doc, item2, urls, interactive) {
22920
22931
  decoded = cachedEmf;
22921
22932
  } else {
22922
22933
  const buf = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
22923
- void import("emf-converter").then(({ convertEmfToDataUrl }) => convertEmfToDataUrl(buf)).then((url) => {
22934
+ trackPaint(import("emf-converter").then(({ convertEmfToDataUrl }) => convertEmfToDataUrl(buf)).then((url) => {
22924
22935
  if (url) {
22925
22936
  setDocDerivedSrc(doc, emfKey, url);
22926
22937
  img.src = url;
22927
22938
  }
22928
- });
22939
+ }));
22929
22940
  }
22930
22941
  }
22931
22942
  if (decoded) {
@@ -45318,6 +45329,21 @@ function setChartData(doc, drawing, input) {
45318
45329
  return true;
45319
45330
  }
45320
45331
 
45332
+ // ../core/src/render/print.ts
45333
+ async function renderForPrint(bytes, container) {
45334
+ await document.fonts.ready;
45335
+ const doc = DocxDocument.load(bytes);
45336
+ const layout = layoutDocument(doc);
45337
+ renderToDom(doc, layout, container, { zoom: 1, pageGap: 0, pageShadow: false, comments: false });
45338
+ const first = layout.pages[0];
45339
+ const style = document.createElement("style");
45340
+ style.textContent = printStylesheet(first?.width ?? 816, first?.height ?? 1056);
45341
+ document.head.append(style);
45342
+ await paintsSettled();
45343
+ await Promise.all(Array.from(container.querySelectorAll("img"), (img) => img.decode().catch(() => void 0)));
45344
+ return { pageCount: layout.pages.length };
45345
+ }
45346
+
45321
45347
  // ../core/src/render/fonts.ts
45322
45348
  var GENERIC = /* @__PURE__ */ new Set([
45323
45349
  "serif",
@@ -55746,6 +55772,7 @@ export {
55746
55772
  removeLink,
55747
55773
  insertChartAt,
55748
55774
  setChartData,
55775
+ renderForPrint,
55749
55776
  compareWithFile,
55750
55777
  pickDocx,
55751
55778
  downloadDocx,
@@ -55764,4 +55791,4 @@ export {
55764
55791
  cfb/cfb.js:
55765
55792
  (*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
55766
55793
  */
55767
- //# sourceMappingURL=chunk-5SLXOYCF.js.map
55794
+ //# sourceMappingURL=chunk-PZIJZDQ7.js.map