@open-file-viewer/core 0.1.17 → 0.1.18

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/README.md CHANGED
@@ -228,15 +228,15 @@ createViewer({
228
228
  file,
229
229
  toolbar: {
230
230
  labels: {
231
- download: "下载",
232
- fullscreen: "全屏",
233
- search: "搜索"
231
+ download: "Download",
232
+ fullscreen: "Fullscreen",
233
+ search: "Search"
234
234
  },
235
235
  order: ["search", "download", "approve", "fullscreen"],
236
236
  actions: [
237
237
  {
238
238
  id: "approve",
239
- label: "审批",
239
+ label: "Approve",
240
240
  onClick(ctx) {
241
241
  openApprovalDialog(ctx.file);
242
242
  }
@@ -251,13 +251,13 @@ Use `toolbar.render(ctx)` when you need to replace the toolbar completely. The c
251
251
 
252
252
  ## Locale and Fallback Text
253
253
 
254
- Fallback text defaults to Simplified Chinese for compatibility. Set `locale: "en-US"` for English built-in loading and unsupported-file messages, or override individual strings with `messages`:
254
+ Fallback text defaults to English. Set `locale: "zh-CN"` for Simplified Chinese built-in loading and unsupported-file messages, or override individual strings with `messages`:
255
255
 
256
256
  ```ts
257
257
  createViewer({
258
258
  container: "#viewer",
259
259
  file,
260
- locale: "en-US",
260
+ locale: "zh-CN",
261
261
  messages: {
262
262
  unsupportedTitle: "No inline preview available",
263
263
  downloadFile: "Download original file"
package/dist/index.cjs CHANGED
@@ -384,7 +384,7 @@ function getFileNameFromUrl(source) {
384
384
  function getExtension(name) {
385
385
  const clean = name.split("?")[0]?.split("#")[0] || "";
386
386
  const index = clean.lastIndexOf(".");
387
- return index >= 0 ? clean.slice(index + 1).toLowerCase() : "";
387
+ return index >= 0 ? clean.slice(index + 1).split("!", 1)[0].toLowerCase() : "";
388
388
  }
389
389
  function isTextLike(file) {
390
390
  const textFileName = normalizeFileName(file.name);
@@ -643,7 +643,7 @@ var defaultMessages = {
643
643
  };
644
644
  function resolveMessages(options) {
645
645
  return {
646
- ...defaultMessages[options.locale || "zh-CN"],
646
+ ...defaultMessages[options.locale || "en-US"],
647
647
  ...options.messages
648
648
  };
649
649
  }
@@ -8517,7 +8517,7 @@ async function renderSheet(panel, arrayBuffer, extension) {
8517
8517
  heading.textContent = sheetName;
8518
8518
  const sheet = workbook.Sheets[sheetName];
8519
8519
  const sheetImages = workbookImages.get(sheetName) || [];
8520
- const range = trimWorkbookSheetRange(sheet, xlsx.utils.decode_range(sheet["!ref"] || "A1:A1"), xlsx.utils.decode_cell);
8520
+ const range = trimWorkbookSheetRange(sheet, xlsx.utils.decode_range(sheet["!ref"] || "A1:A1"), xlsx.utils.decode_cell, sheetImages);
8521
8521
  const rowCount = range.e.r - range.s.r + 1;
8522
8522
  const columnCount = range.e.c - range.s.c + 1;
8523
8523
  const formulaRows = collectFormulaRows(sheet, range, xlsx.utils.encode_cell);
@@ -8616,7 +8616,7 @@ function renderSheetFallback(panel, extension, detail) {
8616
8616
  async function readWorkbookSheetImages(arrayBuffer) {
8617
8617
  const zip = await import_jszip3.default.loadAsync(arrayBuffer);
8618
8618
  const fileNames = Object.keys(zip.files);
8619
- if (!fileNames.some((name) => /^xl\/drawings\/.+\.xml$/i.test(name)) || !fileNames.some((name) => /^xl\/media\//i.test(name))) {
8619
+ if (!fileNames.some((name) => /^xl\/drawings\/.+\.xml$/i.test(name))) {
8620
8620
  return /* @__PURE__ */ new Map();
8621
8621
  }
8622
8622
  const workbookXml = await zip.file("xl/workbook.xml")?.async("text");
@@ -8676,6 +8676,7 @@ async function readWorksheetDrawingImages(zip, drawingPath) {
8676
8676
  const images = [];
8677
8677
  for (const anchor of anchors) {
8678
8678
  const from = Array.from(anchor.children).find((element) => element.localName === "from");
8679
+ const to = Array.from(anchor.children).find((element) => element.localName === "to");
8679
8680
  const embedId = findDrawingImageRelationshipId(anchor);
8680
8681
  const mediaRel = drawingRels.find((rel) => rel.id === embedId && /\/image$/i.test(rel.type));
8681
8682
  const mediaPath = resolveOfficeRelationshipTarget(drawingPath, mediaRel?.target);
@@ -8687,6 +8688,8 @@ async function readWorksheetDrawingImages(zip, drawingPath) {
8687
8688
  images.push({
8688
8689
  row: readDrawingMarkerIndex(from, "row"),
8689
8690
  column: readDrawingMarkerIndex(from, "col"),
8691
+ endRow: to ? readDrawingMarkerIndex(to, "row") : void 0,
8692
+ endColumn: to ? readDrawingMarkerIndex(to, "col") : void 0,
8690
8693
  fileName: mediaPath.split("/").pop() || "image",
8691
8694
  mimeType,
8692
8695
  dataUrl: `data:${mimeType};base64,${await mediaFile.async("base64")}`,
@@ -9142,7 +9145,7 @@ function chartText(element) {
9142
9145
  function chartStringValues(element) {
9143
9146
  return Array.from(element.querySelectorAll("*")).filter((item) => item.localName === "v" || item.localName === "t").map((item) => item.textContent?.trim() || "").filter(Boolean);
9144
9147
  }
9145
- function trimWorkbookSheetRange(sheet, range, decodeCell) {
9148
+ function trimWorkbookSheetRange(sheet, range, decodeCell, images = []) {
9146
9149
  let minRow = Number.POSITIVE_INFINITY;
9147
9150
  let minColumn = Number.POSITIVE_INFINITY;
9148
9151
  let maxRow = Number.NEGATIVE_INFINITY;
@@ -9167,17 +9170,21 @@ function trimWorkbookSheetRange(sheet, range, decodeCell) {
9167
9170
  include(merge.s.r, merge.s.c);
9168
9171
  include(merge.e.r, merge.e.c);
9169
9172
  }
9173
+ for (const image of images) {
9174
+ include(image.row, image.column);
9175
+ include(image.endRow ?? image.row, image.endColumn ?? image.column);
9176
+ }
9170
9177
  if (!Number.isFinite(minRow) || !Number.isFinite(minColumn) || !Number.isFinite(maxRow) || !Number.isFinite(maxColumn)) {
9171
9178
  return range;
9172
9179
  }
9173
9180
  return {
9174
9181
  s: {
9175
- r: Math.max(range.s.r, minRow),
9176
- c: Math.max(range.s.c, minColumn)
9182
+ r: minRow,
9183
+ c: minColumn
9177
9184
  },
9178
9185
  e: {
9179
- r: Math.min(range.e.r, maxRow),
9180
- c: Math.min(range.e.c, maxColumn)
9186
+ r: maxRow,
9187
+ c: maxColumn
9181
9188
  }
9182
9189
  };
9183
9190
  }
@@ -9308,7 +9315,9 @@ function createWorkbookSheetTable(sheet, range, sheetIndex, viewport, encodeCell
9308
9315
  cell.classList.add("ofv-cell-multiline");
9309
9316
  }
9310
9317
  appendWorkbookCellImages(cell, imagesByCell.get(`${rowIndex}:${columnIndex}`), text);
9311
- appendColumnResizeHandle(cell, columnIndex, columnSizing);
9318
+ if (rowIndex === rowStart) {
9319
+ appendColumnResizeHandle(cell, columnIndex, columnSizing);
9320
+ }
9312
9321
  row.append(cell);
9313
9322
  }
9314
9323
  table.append(row);
@@ -9534,7 +9543,9 @@ function createParsedSheetTable(sheet, sheetIndex, viewport, columnSizing, reren
9534
9543
  if (value.includes("\n")) {
9535
9544
  cell.classList.add("ofv-cell-multiline");
9536
9545
  }
9537
- appendColumnResizeHandle(cell, columnIndex, columnSizing);
9546
+ if (rowIndex === viewport.rowStart) {
9547
+ appendColumnResizeHandle(cell, columnIndex, columnSizing);
9548
+ }
9538
9549
  row.append(cell);
9539
9550
  }
9540
9551
  table.append(row);