@open-file-viewer/core 0.1.25 → 0.1.26

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
@@ -6458,6 +6458,7 @@ function decodeXml(value) {
6458
6458
  // src/plugins/office.ts
6459
6459
  var import_jszip3 = __toESM(require("jszip"), 1);
6460
6460
  var import_dompurify2 = __toESM(require("dompurify"), 1);
6461
+ var docxPreview = __toESM(require("docx-preview"), 1);
6461
6462
 
6462
6463
  // src/plugins/msdoc.ts
6463
6464
  var CFB_SIGNATURE = [208, 207, 17, 224, 161, 177, 26, 225];
@@ -7894,6 +7895,7 @@ var presentationExtensions = /* @__PURE__ */ new Set(["pptx", "pptm", "ppt", "pp
7894
7895
  var packagedOfficeCandidates = /* @__PURE__ */ new Set(["wps", "et", "dps", "numbers", "key"]);
7895
7896
  var SHEET_WINDOW_ROWS = 200;
7896
7897
  var SHEET_WINDOW_COLUMNS = 80;
7898
+ var DEFAULT_DOCX_RENDER_TIMEOUT_MS = 15e3;
7897
7899
  var DEFAULT_PPTX_RENDER_TIMEOUT_MS = 12e3;
7898
7900
  var PPTX_REL_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
7899
7901
  var officeMimeTypes = /* @__PURE__ */ new Set([
@@ -8202,23 +8204,28 @@ async function renderDocx(panel, arrayBuffer, fit) {
8202
8204
  document.head.append(styleContainer);
8203
8205
  let disposeFit;
8204
8206
  try {
8205
- const docxPreview = await import("docx-preview");
8206
- await docxPreview.renderAsync(arrayBuffer, content, styleContainer, {
8207
- className: "ofv-docx",
8208
- inWrapper: true,
8209
- breakPages: true,
8210
- ignoreWidth: false,
8211
- ignoreHeight: false,
8212
- ignoreFonts: false,
8213
- renderHeaders: true,
8214
- renderFooters: true,
8215
- renderFootnotes: true,
8216
- renderEndnotes: true,
8217
- renderComments: true,
8218
- renderAltChunks: true,
8219
- experimental: true,
8220
- useBase64URL: true
8221
- });
8207
+ await withTimeout(
8208
+ (async () => {
8209
+ await docxPreview.renderAsync(arrayBuffer, content, styleContainer, {
8210
+ className: "ofv-docx",
8211
+ inWrapper: true,
8212
+ breakPages: true,
8213
+ ignoreWidth: false,
8214
+ ignoreHeight: false,
8215
+ ignoreFonts: false,
8216
+ renderHeaders: true,
8217
+ renderFooters: true,
8218
+ renderFootnotes: true,
8219
+ renderEndnotes: true,
8220
+ renderComments: true,
8221
+ renderAltChunks: true,
8222
+ experimental: true,
8223
+ useBase64URL: true
8224
+ });
8225
+ })(),
8226
+ docxRenderTimeoutMs(),
8227
+ "DOCX rendering"
8228
+ );
8222
8229
  await normalizeDocxLayout(content, arrayBuffer);
8223
8230
  const shouldUseTextboxFallback = await docxPreviewLooksBlank(content, arrayBuffer) || await docxPreviewMissesRichTextboxContent(content, arrayBuffer) || await docxShouldPreferTextboxLayoutFallback(arrayBuffer);
8224
8231
  if (shouldUseTextboxFallback) {
@@ -8241,13 +8248,18 @@ async function renderDocx(panel, arrayBuffer, fit) {
8241
8248
  } catch (error) {
8242
8249
  disposeFit?.();
8243
8250
  styleContainer.remove();
8244
- content.replaceChildren();
8245
- await renderDocxContentFallback(content, arrayBuffer);
8246
- panel.append(content);
8251
+ const fallbackContent = document.createElement("div");
8252
+ fallbackContent.className = "ofv-docx-document";
8253
+ await renderDocxContentFallback(fallbackContent, arrayBuffer);
8254
+ panel.append(fallbackContent);
8247
8255
  console.warn("DOCX layout preview failed, fell back to Mammoth:", error);
8248
8256
  }
8249
8257
  return () => void 0;
8250
8258
  }
8259
+ function docxRenderTimeoutMs() {
8260
+ const override = globalThis.__OFV_DOCX_RENDER_TIMEOUT_MS__;
8261
+ return typeof override === "number" && override > 0 ? override : DEFAULT_DOCX_RENDER_TIMEOUT_MS;
8262
+ }
8251
8263
  async function docxPreviewLooksBlank(container, arrayBuffer) {
8252
8264
  if (container.querySelector("img, svg, canvas, table")) {
8253
8265
  return false;
@@ -8340,12 +8352,13 @@ async function renderDocxContentFallback(container, arrayBuffer, options = {}) {
8340
8352
  return;
8341
8353
  }
8342
8354
  try {
8343
- await renderDocxWithMammoth(container, arrayBuffer);
8344
- const renderedText = normalizePreviewText(container.querySelector(".ofv-document")?.textContent || "");
8355
+ const mammothContent = document.createElement("div");
8356
+ await withTimeout(renderDocxWithMammoth(mammothContent, arrayBuffer), docxRenderTimeoutMs(), "DOCX fallback rendering");
8357
+ const renderedText = normalizePreviewText(mammothContent.querySelector(".ofv-document")?.textContent || "");
8345
8358
  if (renderedText.length >= 24) {
8359
+ container.append(...Array.from(mammothContent.childNodes));
8346
8360
  return;
8347
8361
  }
8348
- container.querySelector(".ofv-document")?.remove();
8349
8362
  await renderDocxTextFallback(container, arrayBuffer);
8350
8363
  } catch (fallbackError) {
8351
8364
  await renderDocxTextFallback(container, arrayBuffer);
@@ -10630,13 +10643,13 @@ function renderPptxTextFallback(container, insight) {
10630
10643
  container.append(article);
10631
10644
  }
10632
10645
  }
10633
- async function withTimeout(promise, timeoutMs) {
10646
+ async function withTimeout(promise, timeoutMs, label = "PPTX rendering") {
10634
10647
  let timeoutId;
10635
10648
  try {
10636
10649
  return await Promise.race([
10637
10650
  promise,
10638
10651
  new Promise((_resolve, reject) => {
10639
- timeoutId = window.setTimeout(() => reject(new Error(`PPTX rendering timed out after ${timeoutMs}ms.`)), timeoutMs);
10652
+ timeoutId = window.setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms.`)), timeoutMs);
10640
10653
  })
10641
10654
  ]);
10642
10655
  } finally {