ooxml.js 4.2.0 → 4.4.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.
Files changed (50) hide show
  1. package/README.md +6 -6
  2. package/dist/{codec-DNjHjEDm.d.cts → codec-CoqS3uGe.d.cts} +2 -2
  3. package/dist/{codec-BrTMlL0a.d.ts → codec-CzqiAWdz.d.ts} +4 -4
  4. package/dist/codec.d.cts +1 -1
  5. package/dist/codec.d.ts +1 -1
  6. package/dist/{content-UlQ-Nhgi.d.cts → content-C79O3esU.d.cts} +6 -1
  7. package/dist/{content-t6ZfmfQM.d.ts → content-MEmp_Rlx.d.ts} +6 -1
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.d.cts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +1 -1
  12. package/dist/{read-C3AaxcT9.cjs → read-D-L3dItC.cjs} +318 -45
  13. package/dist/{read-CxMli3Om.d.ts → read-D30xHgEp.d.ts} +58 -1
  14. package/dist/{read-fuJpC4BH.js → read-DGknK1YY.js} +309 -48
  15. package/dist/{read-CDX1WbiF.d.cts → read-LTgVJIPU.d.cts} +58 -1
  16. package/dist/typed/document-package.cjs +8 -2
  17. package/dist/typed/document-package.js +8 -2
  18. package/dist/typed/docx/constructs.cjs +81 -0
  19. package/dist/typed/docx/constructs.d.cts +13 -2
  20. package/dist/typed/docx/constructs.d.ts +13 -2
  21. package/dist/typed/docx/constructs.js +80 -1
  22. package/dist/typed/docx/read.cjs +3 -1
  23. package/dist/typed/docx/read.d.cts +2 -2
  24. package/dist/typed/docx/read.d.ts +2 -2
  25. package/dist/typed/docx/read.js +2 -2
  26. package/dist/typed/docx/write.cjs +117 -10
  27. package/dist/typed/docx/write.js +118 -11
  28. package/dist/typed/embedded.cjs +1 -1
  29. package/dist/typed/embedded.js +1 -1
  30. package/dist/typed/pptx/read.cjs +1 -1
  31. package/dist/typed/pptx/read.js +1 -1
  32. package/dist/typed/xlsx/build.cjs +1 -1
  33. package/dist/typed/xlsx/build.js +1 -1
  34. package/dist/typed/xlsx/content.cjs +42 -1
  35. package/dist/typed/xlsx/content.d.cts +2 -2
  36. package/dist/typed/xlsx/content.d.ts +2 -2
  37. package/dist/typed/xlsx/content.js +42 -2
  38. package/dist/typed/xlsx/definitions.cjs +54 -0
  39. package/dist/typed/xlsx/definitions.d.cts +6 -0
  40. package/dist/typed/xlsx/definitions.d.ts +6 -0
  41. package/dist/typed/xlsx/definitions.js +53 -0
  42. package/dist/typed/xlsx/drawings.cjs +170 -0
  43. package/dist/typed/xlsx/drawings.d.cts +7 -0
  44. package/dist/typed/xlsx/drawings.d.ts +7 -0
  45. package/dist/typed/xlsx/drawings.js +169 -0
  46. package/dist/typed/xlsx/units.cjs +2 -0
  47. package/dist/typed/xlsx/units.d.cts +2 -1
  48. package/dist/typed/xlsx/units.d.ts +2 -1
  49. package/dist/typed/xlsx/units.js +2 -1
  50. package/package.json +2 -2
@@ -6,7 +6,7 @@ import { encodeXmlText } from "../../xml/entities.js";
6
6
  import { ptToEighthPoints, ptToEmu, ptToHalfPoints, ptToTwips } from "../shared/units.js";
7
7
  import { TABLE_OF_CONTENTS_GALLERY, isDeletedChange } from "./constructs.js";
8
8
  import { buildXlsxPackageFromContent } from "../xlsx/build.js";
9
- import { colorToRgbHex, findConstructMarkerImbalance } from "document-schema.js";
9
+ import { colorToRgbHex, findConstructMarkerImbalance, findRunConstructFault } from "document-schema.js";
10
10
  //#region src/typed/docx/write.ts
11
11
  const WML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
12
12
  const REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
@@ -178,10 +178,112 @@ function buildParagraph(paragraph, state, pageBreakBefore, deleted, provenance)
178
178
  const changeTag = provenance === void 0 ? void 0 : TRACKED_CHANGE_TAG_BY_CHANGE[provenance.change];
179
179
  const pPr = properties === void 0 && changeTag !== void 0 ? el("w:pPr", {}, []) : properties;
180
180
  if (pPr !== void 0 && changeTag !== void 0 && provenance !== void 0) pPr.children.push(el("w:rPr", {}, [el(changeTag, trackChangeAttrs(state, provenance))]));
181
- const runs = paragraph.runs.map((run) => buildRun(run, state, deleted));
181
+ const runs = interleaveRunConstructExtents(paragraph.runs.map((run) => buildRun(run, state, deleted)), paragraph, state);
182
182
  const content = changeTag === void 0 || provenance === void 0 ? runs : [el(changeTag, trackChangeAttrs(state, provenance), runs)];
183
183
  return el("w:p", {}, [...pPr === void 0 ? [] : [pPr], ...content]);
184
184
  }
185
+ function interleaveRunConstructExtents(runElements, paragraph, state) {
186
+ if (paragraph.constructs === void 0) return [...runElements];
187
+ const fault = findRunConstructFault(paragraph);
188
+ if (fault !== void 0) throw new Error(`buildDocxPackageFromContent: run-level construct extent at index ${String(fault.index)} of a paragraph does not name real runs (${fault.kind})`);
189
+ const bookmarks = paragraph.constructs.filter((extent) => extent.descriptor.kind === "anchor" && extent.descriptor.anchorType === "bookmark");
190
+ const fields = paragraph.constructs.filter((extent) => extent.descriptor.kind === "field");
191
+ const links = [];
192
+ for (const extent of paragraph.constructs) if (extent.descriptor.kind === "link" && extent.descriptor.target.kind === "internal") links.push({
193
+ descriptor: extent.descriptor,
194
+ startRun: extent.startRun,
195
+ endRun: extent.endRun,
196
+ anchor: extent.descriptor.target.anchor
197
+ });
198
+ if (bookmarks.length === 0 && fields.length === 0) return wrapInternalLinks([...runElements], new RunPositions(runElements), links);
199
+ const closingAt = /* @__PURE__ */ new Map();
200
+ const openingAt = /* @__PURE__ */ new Map();
201
+ const pointAt = /* @__PURE__ */ new Map();
202
+ const push = (map, position, element) => {
203
+ const existing = map.get(position);
204
+ if (existing === void 0) map.set(position, [element]);
205
+ else existing.push(element);
206
+ };
207
+ for (const bookmark of bookmarks) {
208
+ const id = String(state.nextMarkerId++);
209
+ const open = el("w:bookmarkStart", {
210
+ "w:id": id,
211
+ "w:name": encodeXmlText(bookmark.descriptor.name)
212
+ });
213
+ const close = el("w:bookmarkEnd", { "w:id": id });
214
+ if (bookmark.startRun === bookmark.endRun) {
215
+ push(pointAt, bookmark.startRun, open);
216
+ push(pointAt, bookmark.startRun, close);
217
+ } else {
218
+ push(openingAt, bookmark.startRun, open);
219
+ push(closingAt, bookmark.endRun, close);
220
+ }
221
+ }
222
+ for (const field of fields) {
223
+ const opening = [
224
+ fieldCharRun("begin"),
225
+ el("w:r", {}, [el("w:instrText", { "xml:space": "preserve" }, [txt(encodeXmlText(field.descriptor.instruction))])]),
226
+ fieldCharRun("separate")
227
+ ];
228
+ if (field.startRun === field.endRun) {
229
+ for (const run of opening) push(pointAt, field.startRun, run);
230
+ push(pointAt, field.startRun, fieldCharRun("end"));
231
+ } else {
232
+ for (const run of opening) push(openingAt, field.startRun, run);
233
+ push(closingAt, field.endRun, fieldCharRun("end"));
234
+ }
235
+ }
236
+ const out = [];
237
+ const positions = new RunPositions(runElements);
238
+ for (let position = 0; position <= runElements.length; position++) {
239
+ for (const close of closingAt.get(position) ?? []) out.push(close);
240
+ for (const open of openingAt.get(position) ?? []) out.push(open);
241
+ for (const half of pointAt.get(position) ?? []) out.push(half);
242
+ const run = runElements[position];
243
+ if (run !== void 0) out.push(run);
244
+ }
245
+ return wrapInternalLinks(out, positions, links);
246
+ }
247
+ var RunPositions = class {
248
+ indexOfElement = /* @__PURE__ */ new Map();
249
+ constructor(runElements) {
250
+ runElements.forEach((element, index) => {
251
+ this.indexOfElement.set(element, index);
252
+ });
253
+ }
254
+ positionOf(element) {
255
+ return this.indexOfElement.get(element);
256
+ }
257
+ };
258
+ function wrapInternalLinks(elements, positions, links) {
259
+ if (links.length === 0) return elements;
260
+ let out = elements;
261
+ const wrapped = [];
262
+ for (const link of [...links].sort((a, b) => a.startRun - b.startRun || b.endRun - a.endRun)) {
263
+ let first = -1;
264
+ let last = -1;
265
+ out.forEach((element, index) => {
266
+ const position = positions.positionOf(element);
267
+ if (position === link.startRun) first = index;
268
+ if (position === link.endRun - 1) last = index;
269
+ });
270
+ if (first === -1 || last === -1 || last < first) continue;
271
+ const slice = out.slice(first, last + 1);
272
+ const overlapsWrapped = wrapped.some((range) => first <= range.last && range.first <= last);
273
+ const carriesHyperlink = slice.some((element) => element.tag === "w:hyperlink");
274
+ if (overlapsWrapped || carriesHyperlink) continue;
275
+ wrapped.push({
276
+ first,
277
+ last
278
+ });
279
+ out = [
280
+ ...out.slice(0, first),
281
+ el("w:hyperlink", { "w:anchor": encodeXmlText(link.anchor) }, slice),
282
+ ...out.slice(last + 1)
283
+ ];
284
+ }
285
+ return out;
286
+ }
185
287
  function trailingEmptyRunElements(paragraph, element) {
186
288
  const runElements = [];
187
289
  for (const child of element.children) if (child.type === "element" && (child.tag === "w:r" || child.tag === "w:hyperlink")) runElements.push(child);
@@ -596,15 +698,20 @@ function buildBlockFlow(blocks, state, deleted) {
596
698
  return buildFlowItems(parseFlow(blocks), state, deleted, void 0);
597
699
  }
598
700
  function buildSectionProperties(section) {
599
- return el("w:sectPr", {}, [el("w:pgSz", {
600
- "w:w": String(ptToTwips(section.pageSize.widthPt)),
601
- "w:h": String(ptToTwips(section.pageSize.heightPt))
602
- }), el("w:pgMar", {
603
- "w:top": String(ptToTwips(section.margins.topPt)),
604
- "w:right": String(ptToTwips(section.margins.rightPt)),
605
- "w:bottom": String(ptToTwips(section.margins.bottomPt)),
606
- "w:left": String(ptToTwips(section.margins.leftPt))
607
- })]);
701
+ const type = section.breakType === void 0 ? [] : [el("w:type", { "w:val": section.breakType })];
702
+ return el("w:sectPr", {}, [
703
+ ...type,
704
+ el("w:pgSz", {
705
+ "w:w": String(ptToTwips(section.pageSize.widthPt)),
706
+ "w:h": String(ptToTwips(section.pageSize.heightPt))
707
+ }),
708
+ el("w:pgMar", {
709
+ "w:top": String(ptToTwips(section.margins.topPt)),
710
+ "w:right": String(ptToTwips(section.margins.rightPt)),
711
+ "w:bottom": String(ptToTwips(section.margins.bottomPt)),
712
+ "w:left": String(ptToTwips(section.margins.leftPt))
713
+ })
714
+ ]);
608
715
  }
609
716
  function attachSectionBreak(nodes, section) {
610
717
  const target = findParagraph(nodes, true);
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-C3AaxcT9.cjs");
2
+ const require_read = require("../read-D-L3dItC.cjs");
3
3
  exports.readEmbeddedOoxmlPayload = require_read.readEmbeddedOoxmlPayload;
4
4
  exports.readEmbeddedPayloadPart = require_read.readEmbeddedPayloadPart;
@@ -1,2 +1,2 @@
1
- import { a as readEmbeddedOoxmlPayload, o as readEmbeddedPayloadPart } from "../read-fuJpC4BH.js";
1
+ import { c as readEmbeddedPayloadPart, s as readEmbeddedOoxmlPayload } from "../read-DGknK1YY.js";
2
2
  export { readEmbeddedOoxmlPayload, readEmbeddedPayloadPart };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../../read-C3AaxcT9.cjs");
2
+ const require_read = require("../../read-D-L3dItC.cjs");
3
3
  exports.PptxDocumentSchema = require_read.PptxDocumentSchema;
4
4
  exports.readPptxContent = require_read.readPptxContent;
@@ -1,2 +1,2 @@
1
- import { c as readPptxContent, s as PptxDocumentSchema } from "../../read-fuJpC4BH.js";
1
+ import { l as PptxDocumentSchema, u as readPptxContent } from "../../read-DGknK1YY.js";
2
2
  export { PptxDocumentSchema, readPptxContent };
@@ -6,10 +6,10 @@ const require_typed_xlsx_defined_names = require("./defined-names.cjs");
6
6
  const require_typed_xlsx_number_format = require("./number-format.cjs");
7
7
  const require_typed_xlsx_util = require("./util.cjs");
8
8
  const require_typed_xlsx_print_settings = require("./print-settings.cjs");
9
+ const require_typed_xlsx_units = require("./units.cjs");
9
10
  const require_typed_xlsx_serial = require("./serial.cjs");
10
11
  const require_typed_xlsx_shared_strings = require("./shared-strings.cjs");
11
12
  const require_typed_xlsx_styles = require("./styles.cjs");
12
- const require_typed_xlsx_units = require("./units.cjs");
13
13
  let document_schema_js = require("document-schema.js");
14
14
  //#region src/typed/xlsx/build.ts
15
15
  const SML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
@@ -5,10 +5,10 @@ import { XLNM_PRINT_AREA, XLNM_PRINT_TITLES, buildPrintAreaValue, buildPrintTitl
5
5
  import { BOOLEAN_NUMBER_FORMAT, DATE_NUMBER_FORMAT, DATE_TIME_NUMBER_FORMAT, PERCENTAGE_NUMBER_FORMAT, TIME_NUMBER_FORMAT, currencyNumberFormat } from "./number-format.js";
6
6
  import { pageSizeToPaperSizeCode, ptToUniversalMeasure, writeXmlBool } from "./util.js";
7
7
  import { DEFAULT_HEADER_FOOTER_MARGIN_PT } from "./print-settings.js";
8
+ import { ptToColumnWidthChars } from "./units.js";
8
9
  import { isoDateTimeToSerial, isoDateToSerial, isoTimeToSerial } from "./serial.js";
9
10
  import { SharedStringTable } from "./shared-strings.js";
10
11
  import { CellFormatTable, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES } from "./styles.js";
11
- import { ptToColumnWidthChars } from "./units.js";
12
12
  import { cellReference, rangeReference } from "document-schema.js";
13
13
  //#region src/typed/xlsx/build.ts
14
14
  const SML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
@@ -1,15 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_build = require("../../xml/build.cjs");
2
3
  const require_typed_util = require("../util.cjs");
3
4
  const require_typed_shared_metadata = require("../shared/metadata.cjs");
4
5
  const require_typed_xlsx_defined_names = require("./defined-names.cjs");
5
6
  const require_typed_xlsx_number_format = require("./number-format.cjs");
6
7
  const require_typed_xlsx_util = require("./util.cjs");
7
8
  const require_typed_xlsx_print_settings = require("./print-settings.cjs");
9
+ const require_typed_xlsx_units = require("./units.cjs");
10
+ const require_typed_xlsx_drawings = require("./drawings.cjs");
8
11
  const require_typed_xlsx_serial = require("./serial.cjs");
9
12
  const require_typed_xlsx_shared_strings = require("./shared-strings.cjs");
10
13
  const require_typed_xlsx_styles = require("./styles.cjs");
11
14
  const require_typed_xlsx_comments = require("./comments.cjs");
12
- const require_typed_xlsx_units = require("./units.cjs");
13
15
  let document_schema_js = require("document-schema.js");
14
16
  //#region src/typed/xlsx/content.ts
15
17
  const WORKBOOK_PATH = "xl/workbook.xml";
@@ -318,6 +320,41 @@ function applyCellComments(comments, cells) {
318
320
  byPosition.set(key, materialised);
319
321
  }
320
322
  }
323
+ function applyCellResidueRules(worksheet, cells) {
324
+ const rules = [];
325
+ for (const container of require_typed_util.childrenWithTag(worksheet, "dataValidations")) rules.push(...require_typed_util.childrenWithTag(container, "dataValidation"));
326
+ rules.push(...require_typed_util.childrenWithTag(worksheet, "conditionalFormatting"));
327
+ if (rules.length === 0) return;
328
+ const byPosition = /* @__PURE__ */ new Map();
329
+ for (const cell of cells) byPosition.set(`${cell.row}:${cell.column}`, cell);
330
+ for (const rule of rules) {
331
+ const sqref = require_typed_util.attr(rule, "sqref");
332
+ const firstToken = sqref === void 0 ? void 0 : sqref.split(/\s+/)[0];
333
+ const range = firstToken === void 0 || firstToken === "" ? void 0 : (0, document_schema_js.parseRangeReference)(firstToken);
334
+ if (range === void 0) continue;
335
+ const key = `${range.startRow}:${range.startColumn}`;
336
+ const existing = byPosition.get(key);
337
+ if (existing === void 0) {
338
+ const materialised = {
339
+ row: range.startRow,
340
+ column: range.startColumn,
341
+ value: { kind: "empty" },
342
+ displayText: "",
343
+ source: {
344
+ format: "xlsx",
345
+ xml: require_xml_build.buildXml([rule])
346
+ }
347
+ };
348
+ cells.push(materialised);
349
+ byPosition.set(key, materialised);
350
+ continue;
351
+ }
352
+ existing.source ??= {
353
+ format: "xlsx",
354
+ xml: require_xml_build.buildXml([rule])
355
+ };
356
+ }
357
+ }
321
358
  function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context) {
322
359
  const worksheet = require_typed_util.rootElement(pkg.parts[entry.path]);
323
360
  if (worksheet === void 0) return {
@@ -330,12 +367,15 @@ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, c
330
367
  };
331
368
  const cells = readCells(worksheet, sharedStrings, context);
332
369
  applyCellComments(require_typed_xlsx_comments.readSheetCellComments(pkg, entry.path), cells);
370
+ applyCellResidueRules(worksheet, cells);
371
+ const embeddedObjects = require_typed_xlsx_drawings.readSheetEmbeddedObjects(pkg, entry.path, worksheet);
333
372
  return {
334
373
  name: entry.name,
335
374
  cells,
336
375
  columns: readColumns(worksheet),
337
376
  rows: readRows(worksheet),
338
377
  images: [],
378
+ ...embeddedObjects === void 0 ? {} : { embeddedObjects },
339
379
  printSettings: require_typed_xlsx_print_settings.readPrintSettings(worksheet, sheetIndex, definedNamesBySheet)
340
380
  };
341
381
  }
@@ -360,3 +400,4 @@ function readXlsxContent(pkg) {
360
400
  }
361
401
  //#endregion
362
402
  exports.readXlsxContent = readXlsxContent;
403
+ exports.resolveSheetEntries = resolveSheetEntries;
@@ -1,2 +1,2 @@
1
- import { t as readXlsxContent } from "../../content-UlQ-Nhgi.cjs";
2
- export { readXlsxContent };
1
+ import { n as resolveSheetEntries, t as readXlsxContent } from "../../content-C79O3esU.cjs";
2
+ export { readXlsxContent, resolveSheetEntries };
@@ -1,2 +1,2 @@
1
- import { t as readXlsxContent } from "../../content-t6ZfmfQM.js";
2
- export { readXlsxContent };
1
+ import { n as resolveSheetEntries, t as readXlsxContent } from "../../content-MEmp_Rlx.js";
2
+ export { readXlsxContent, resolveSheetEntries };
@@ -1,14 +1,16 @@
1
+ import { buildXml } from "../../xml/build.js";
1
2
  import { attr, childrenWithTag, elementsWithTag, resolveRelationships, rootElement, textContent } from "../util.js";
2
3
  import { readCoreProperties } from "../shared/metadata.js";
3
4
  import { readDefinedNamesBySheet } from "./defined-names.js";
4
5
  import { classifyNumberFormat } from "./number-format.js";
5
6
  import { readXmlBool } from "./util.js";
6
7
  import { readPrintSettings } from "./print-settings.js";
8
+ import { columnWidthCharsToPt } from "./units.js";
9
+ import { readSheetEmbeddedObjects } from "./drawings.js";
7
10
  import { readDate1904, serialToIsoDate, serialToIsoDateTime, serialToIsoTime } from "./serial.js";
8
11
  import { loadSharedStrings } from "./shared-strings.js";
9
12
  import { readCellStyles } from "./styles.js";
10
13
  import { readSheetCellComments } from "./comments.js";
11
- import { columnWidthCharsToPt } from "./units.js";
12
14
  import { parseCellReference, parseRangeReference } from "document-schema.js";
13
15
  //#region src/typed/xlsx/content.ts
14
16
  const WORKBOOK_PATH = "xl/workbook.xml";
@@ -317,6 +319,41 @@ function applyCellComments(comments, cells) {
317
319
  byPosition.set(key, materialised);
318
320
  }
319
321
  }
322
+ function applyCellResidueRules(worksheet, cells) {
323
+ const rules = [];
324
+ for (const container of childrenWithTag(worksheet, "dataValidations")) rules.push(...childrenWithTag(container, "dataValidation"));
325
+ rules.push(...childrenWithTag(worksheet, "conditionalFormatting"));
326
+ if (rules.length === 0) return;
327
+ const byPosition = /* @__PURE__ */ new Map();
328
+ for (const cell of cells) byPosition.set(`${cell.row}:${cell.column}`, cell);
329
+ for (const rule of rules) {
330
+ const sqref = attr(rule, "sqref");
331
+ const firstToken = sqref === void 0 ? void 0 : sqref.split(/\s+/)[0];
332
+ const range = firstToken === void 0 || firstToken === "" ? void 0 : parseRangeReference(firstToken);
333
+ if (range === void 0) continue;
334
+ const key = `${range.startRow}:${range.startColumn}`;
335
+ const existing = byPosition.get(key);
336
+ if (existing === void 0) {
337
+ const materialised = {
338
+ row: range.startRow,
339
+ column: range.startColumn,
340
+ value: { kind: "empty" },
341
+ displayText: "",
342
+ source: {
343
+ format: "xlsx",
344
+ xml: buildXml([rule])
345
+ }
346
+ };
347
+ cells.push(materialised);
348
+ byPosition.set(key, materialised);
349
+ continue;
350
+ }
351
+ existing.source ??= {
352
+ format: "xlsx",
353
+ xml: buildXml([rule])
354
+ };
355
+ }
356
+ }
320
357
  function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, context) {
321
358
  const worksheet = rootElement(pkg.parts[entry.path]);
322
359
  if (worksheet === void 0) return {
@@ -329,12 +366,15 @@ function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet, c
329
366
  };
330
367
  const cells = readCells(worksheet, sharedStrings, context);
331
368
  applyCellComments(readSheetCellComments(pkg, entry.path), cells);
369
+ applyCellResidueRules(worksheet, cells);
370
+ const embeddedObjects = readSheetEmbeddedObjects(pkg, entry.path, worksheet);
332
371
  return {
333
372
  name: entry.name,
334
373
  cells,
335
374
  columns: readColumns(worksheet),
336
375
  rows: readRows(worksheet),
337
376
  images: [],
377
+ ...embeddedObjects === void 0 ? {} : { embeddedObjects },
338
378
  printSettings: readPrintSettings(worksheet, sheetIndex, definedNamesBySheet)
339
379
  };
340
380
  }
@@ -358,4 +398,4 @@ function readXlsxContent(pkg) {
358
398
  };
359
399
  }
360
400
  //#endregion
361
- export { readXlsxContent };
401
+ export { readXlsxContent, resolveSheetEntries };
@@ -0,0 +1,54 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_typed_util = require("../util.cjs");
3
+ require("./defined-names.cjs");
4
+ const require_typed_xlsx_content = require("./content.cjs");
5
+ //#region src/typed/xlsx/definitions.ts
6
+ const WORKBOOK_PATH = "xl/workbook.xml";
7
+ const TABLE_REL_SUFFIX = "/table";
8
+ function readNamedRanges(pkg, out) {
9
+ const workbook = require_typed_util.rootElement(pkg.parts[WORKBOOK_PATH]);
10
+ const container = workbook === void 0 ? void 0 : require_typed_util.childrenWithTag(workbook, "definedNames")[0];
11
+ if (container === void 0) return;
12
+ for (const definedName of require_typed_util.childrenWithTag(container, "definedName")) {
13
+ const name = require_typed_util.attr(definedName, "name");
14
+ if (name === void 0 || name === "_xlnm.Print_Area" || name === "_xlnm.Print_Titles") continue;
15
+ const localSheetIdRaw = require_typed_util.attr(definedName, "localSheetId");
16
+ const localSheetId = localSheetIdRaw === void 0 ? void 0 : Number.parseInt(localSheetIdRaw, 10);
17
+ out[`namedRange:${name}`] = {
18
+ kind: "namedRange",
19
+ name,
20
+ refersTo: require_typed_util.textContent(definedName),
21
+ ...Number.isInteger(localSheetId) ? { localSheetId } : {}
22
+ };
23
+ }
24
+ }
25
+ function readTableEntries(pkg, out) {
26
+ for (const entry of require_typed_xlsx_content.resolveSheetEntries(pkg)) for (const rel of require_typed_util.resolveRelationships(pkg, entry.path).values()) {
27
+ if (!rel.type.endsWith(TABLE_REL_SUFFIX)) continue;
28
+ const table = require_typed_util.rootElement(pkg.parts[rel.target]);
29
+ const name = table === void 0 ? void 0 : require_typed_util.attr(table, "name");
30
+ const ref = table === void 0 ? void 0 : require_typed_util.attr(table, "ref");
31
+ if (table === void 0 || name === void 0 || ref === void 0) continue;
32
+ const columns = [];
33
+ const tableColumns = require_typed_util.childrenWithTag(table, "tableColumns")[0];
34
+ for (const column of tableColumns === void 0 ? [] : require_typed_util.childrenWithTag(tableColumns, "tableColumn")) {
35
+ const columnName = require_typed_util.attr(column, "name");
36
+ if (columnName !== void 0) columns.push(columnName);
37
+ }
38
+ out[`table:${name}`] = {
39
+ kind: "table",
40
+ name,
41
+ ref,
42
+ sheet: entry.name,
43
+ columns
44
+ };
45
+ }
46
+ }
47
+ function readWorkbookDefinitions(pkg) {
48
+ const out = {};
49
+ readNamedRanges(pkg, out);
50
+ readTableEntries(pkg, out);
51
+ return Object.keys(out).length === 0 ? void 0 : out;
52
+ }
53
+ //#endregion
54
+ exports.readWorkbookDefinitions = readWorkbookDefinitions;
@@ -0,0 +1,6 @@
1
+ import { r as Package } from "../../package-L24lkba-.cjs";
2
+ import { DefinitionsTable } from "document-schema.js";
3
+ //#region src/typed/xlsx/definitions.d.ts
4
+ declare function readWorkbookDefinitions(pkg: Package): DefinitionsTable | undefined;
5
+ //#endregion
6
+ export { readWorkbookDefinitions };
@@ -0,0 +1,6 @@
1
+ import { r as Package } from "../../package-BUojjTXf.js";
2
+ import { DefinitionsTable } from "document-schema.js";
3
+ //#region src/typed/xlsx/definitions.d.ts
4
+ declare function readWorkbookDefinitions(pkg: Package): DefinitionsTable | undefined;
5
+ //#endregion
6
+ export { readWorkbookDefinitions };
@@ -0,0 +1,53 @@
1
+ import { attr, childrenWithTag, resolveRelationships, rootElement, textContent } from "../util.js";
2
+ import "./defined-names.js";
3
+ import { resolveSheetEntries } from "./content.js";
4
+ //#region src/typed/xlsx/definitions.ts
5
+ const WORKBOOK_PATH = "xl/workbook.xml";
6
+ const TABLE_REL_SUFFIX = "/table";
7
+ function readNamedRanges(pkg, out) {
8
+ const workbook = rootElement(pkg.parts[WORKBOOK_PATH]);
9
+ const container = workbook === void 0 ? void 0 : childrenWithTag(workbook, "definedNames")[0];
10
+ if (container === void 0) return;
11
+ for (const definedName of childrenWithTag(container, "definedName")) {
12
+ const name = attr(definedName, "name");
13
+ if (name === void 0 || name === "_xlnm.Print_Area" || name === "_xlnm.Print_Titles") continue;
14
+ const localSheetIdRaw = attr(definedName, "localSheetId");
15
+ const localSheetId = localSheetIdRaw === void 0 ? void 0 : Number.parseInt(localSheetIdRaw, 10);
16
+ out[`namedRange:${name}`] = {
17
+ kind: "namedRange",
18
+ name,
19
+ refersTo: textContent(definedName),
20
+ ...Number.isInteger(localSheetId) ? { localSheetId } : {}
21
+ };
22
+ }
23
+ }
24
+ function readTableEntries(pkg, out) {
25
+ for (const entry of resolveSheetEntries(pkg)) for (const rel of resolveRelationships(pkg, entry.path).values()) {
26
+ if (!rel.type.endsWith(TABLE_REL_SUFFIX)) continue;
27
+ const table = rootElement(pkg.parts[rel.target]);
28
+ const name = table === void 0 ? void 0 : attr(table, "name");
29
+ const ref = table === void 0 ? void 0 : attr(table, "ref");
30
+ if (table === void 0 || name === void 0 || ref === void 0) continue;
31
+ const columns = [];
32
+ const tableColumns = childrenWithTag(table, "tableColumns")[0];
33
+ for (const column of tableColumns === void 0 ? [] : childrenWithTag(tableColumns, "tableColumn")) {
34
+ const columnName = attr(column, "name");
35
+ if (columnName !== void 0) columns.push(columnName);
36
+ }
37
+ out[`table:${name}`] = {
38
+ kind: "table",
39
+ name,
40
+ ref,
41
+ sheet: entry.name,
42
+ columns
43
+ };
44
+ }
45
+ }
46
+ function readWorkbookDefinitions(pkg) {
47
+ const out = {};
48
+ readNamedRanges(pkg, out);
49
+ readTableEntries(pkg, out);
50
+ return Object.keys(out).length === 0 ? void 0 : out;
51
+ }
52
+ //#endregion
53
+ export { readWorkbookDefinitions };