@office-kit/xlsx 0.15.0 → 0.17.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 (66) hide show
  1. package/README.md +29 -8
  2. package/dist/cell/cell.d.ts +12 -19
  3. package/dist/{cell-Df3cKRIl.mjs → cell-B5OUUdfI.mjs} +13 -7
  4. package/dist/cell-B5OUUdfI.mjs.map +1 -0
  5. package/dist/{cell-style-CNsET6WU.mjs → cell-style-DjKKPWDL.mjs} +2 -2
  6. package/dist/{cell-style-CNsET6WU.mjs.map → cell-style-DjKKPWDL.mjs.map} +1 -1
  7. package/dist/cell.mjs +1 -1
  8. package/dist/{coordinate-Bt5Gni2I.mjs → coordinate-CxC88uBk.mjs} +31 -2
  9. package/dist/coordinate-CxC88uBk.mjs.map +1 -0
  10. package/dist/{defined-names-Ctu3F6ls.mjs → defined-names-Cmp8rbvI.mjs} +2 -2
  11. package/dist/{defined-names-Ctu3F6ls.mjs.map → defined-names-Cmp8rbvI.mjs.map} +1 -1
  12. package/dist/{differential-BPKa7wXi.mjs → differential-7KGzbliB.mjs} +2 -2
  13. package/dist/{differential-BPKa7wXi.mjs.map → differential-7KGzbliB.mjs.map} +1 -1
  14. package/dist/{drawing-ZJ3h4VHD.mjs → drawing-Cv6UtInY.mjs} +2 -2
  15. package/dist/{drawing-ZJ3h4VHD.mjs.map → drawing-Cv6UtInY.mjs.map} +1 -1
  16. package/dist/drawing.mjs +1 -1
  17. package/dist/{escape-rnWSPpWY.mjs → escape-rA5UpibT.mjs} +26 -3
  18. package/dist/escape-rA5UpibT.mjs.map +1 -0
  19. package/dist/io/load.d.ts +28 -0
  20. package/dist/io.mjs +2 -2
  21. package/dist/{load-CspGc399.mjs → load-DIdQ_zum.mjs} +66 -39
  22. package/dist/{load-CspGc399.mjs.map → load-DIdQ_zum.mjs.map} +1 -1
  23. package/dist/{manifest-pLmx7KYh.mjs → manifest-BHUYpjUG.mjs} +3 -3
  24. package/dist/{manifest-pLmx7KYh.mjs.map → manifest-BHUYpjUG.mjs.map} +1 -1
  25. package/dist/node.mjs +1 -1
  26. package/dist/packaging.mjs +1 -1
  27. package/dist/{reader-DHMxLBQV.mjs → reader-pC7bxYAs.mjs} +30 -7
  28. package/dist/reader-pC7bxYAs.mjs.map +1 -0
  29. package/dist/{save-DgPf1DyF.mjs → save-ax11Gsw0.mjs} +7 -7
  30. package/dist/{save-DgPf1DyF.mjs.map → save-ax11Gsw0.mjs.map} +1 -1
  31. package/dist/schema.mjs +1 -1
  32. package/dist/{serialize-BC2Wu3bR.mjs → serialize-Dmb6Vtt9.mjs} +23 -6
  33. package/dist/serialize-Dmb6Vtt9.mjs.map +1 -0
  34. package/dist/{serializer-C6nm0mRJ.mjs → serializer-dhv07Z6F.mjs} +2 -2
  35. package/dist/{serializer-C6nm0mRJ.mjs.map → serializer-dhv07Z6F.mjs.map} +1 -1
  36. package/dist/streaming/string-table.d.ts +7 -0
  37. package/dist/streaming.mjs +189 -83
  38. package/dist/streaming.mjs.map +1 -1
  39. package/dist/styles.mjs +3 -3
  40. package/dist/{stylesheet-writer-TxsinwbO.mjs → stylesheet-writer-BBYjNSMA.mjs} +201 -118
  41. package/dist/stylesheet-writer-BBYjNSMA.mjs.map +1 -0
  42. package/dist/{table-BrP0RwUd.mjs → table-BFi2WmgG.mjs} +2 -2
  43. package/dist/{table-BrP0RwUd.mjs.map → table-BFi2WmgG.mjs.map} +1 -1
  44. package/dist/utils/cell-number.d.ts +10 -0
  45. package/dist/utils/coordinate.d.ts +11 -0
  46. package/dist/utils/escape.d.ts +17 -0
  47. package/dist/utils/xsd-boolean.d.ts +9 -0
  48. package/dist/utils.mjs +2 -2
  49. package/dist/workbook/shared-strings.d.ts +2 -0
  50. package/dist/{workbook-DQCslHzY.mjs → workbook-CMel6UcI.mjs} +13 -12
  51. package/dist/workbook-CMel6UcI.mjs.map +1 -0
  52. package/dist/workbook.mjs +2 -2
  53. package/dist/worksheet/writer.d.ts +9 -5
  54. package/dist/{worksheet-B2NOQ6dM.mjs → worksheet-Cxn2c-jz.mjs} +3 -3
  55. package/dist/{worksheet-B2NOQ6dM.mjs.map → worksheet-Cxn2c-jz.mjs.map} +1 -1
  56. package/dist/worksheet.mjs +2 -2
  57. package/dist/xml.mjs +2 -2
  58. package/dist/zip.mjs +1 -1
  59. package/package.json +1 -1
  60. package/dist/cell-Df3cKRIl.mjs.map +0 -1
  61. package/dist/coordinate-Bt5Gni2I.mjs.map +0 -1
  62. package/dist/escape-rnWSPpWY.mjs.map +0 -1
  63. package/dist/reader-DHMxLBQV.mjs.map +0 -1
  64. package/dist/serialize-BC2Wu3bR.mjs.map +0 -1
  65. package/dist/stylesheet-writer-TxsinwbO.mjs.map +0 -1
  66. package/dist/workbook-DQCslHzY.mjs.map +0 -1
@@ -1,14 +1,14 @@
1
1
  import { o as OpenXmlSchemaError } from "./exceptions-D-CFwxgm.mjs";
2
- import { h as loadImage } from "./drawing-ZJ3h4VHD.mjs";
2
+ import { h as loadImage } from "./drawing-Cv6UtInY.mjs";
3
3
  import { At as parseQName, a as findChildren, c as ARC_CONTENT_TYPES, f as ARC_ROOT_RELS, ft as SHEET_MAIN_NS, g as ARC_WORKBOOK, h as ARC_THEME, i as findChild, jt as qname, l as ARC_CORE, lt as REL_NS, m as ARC_STYLE, p as ARC_SHARED_STRINGS, q as MARKUP_COMPAT_NS, s as ARC_APP, u as ARC_CUSTOM } from "./tree-BX-sRRVp.mjs";
4
- import { D as findUserShapesRId, O as parseChartXml, T as parseChartExXml, _ as parseChartsheetXml, a as parseCommentsXml, b as parseWorksheetXml, c as NumberFormatSchema, d as BorderSchema, f as AlignmentSchema, h as parseDrawingXml, l as FontSchema, n as parseTableXml, p as collectRawRelIds, s as ProtectionSchema, u as fillFromTree, w as isChartExBytes, x as parseUserShapesXml } from "./stylesheet-writer-TxsinwbO.mjs";
4
+ import { E as parseChartExXml, O as findUserShapesRId, S as parseUserShapesXml, T as isChartExBytes, _ as parseChartsheetXml, a as parseCommentsXml, b as parseWorksheetXml, c as NumberFormatSchema, d as BorderSchema, f as AlignmentSchema, h as parseDrawingXml, k as parseChartXml, l as FontSchema, n as parseTableXml, p as collectRawRelIds, s as ProtectionSchema, u as fillFromTree } from "./stylesheet-writer-BBYjNSMA.mjs";
5
5
  import { n as parseXmlDocument, t as parseXml } from "./parser-By6RWZVW.mjs";
6
- import { t as fromTree } from "./serialize-BC2Wu3bR.mjs";
7
- import { B as corePropsFromBytes, Q as findById, _ as customPropsFromBytes, c as extendedPropsFromBytes, et as indexRelsById, nt as relsFromBytes, o as manifestFromBytes, tt as makeRelationships } from "./manifest-pLmx7KYh.mjs";
8
- import { en as stableStringify, ht as makeStylesheet } from "./cell-style-CNsET6WU.mjs";
9
- import { k as parseSharedStringsXml, r as createWorkbook } from "./workbook-DQCslHzY.mjs";
10
- import { a as makeDefinedName } from "./defined-names-Ctu3F6ls.mjs";
11
- import { t as openZip } from "./reader-DHMxLBQV.mjs";
6
+ import { t as fromTree } from "./serialize-Dmb6Vtt9.mjs";
7
+ import { $ as findByType, B as corePropsFromBytes, Q as findById, _ as customPropsFromBytes, c as extendedPropsFromBytes, et as indexRelsById, nt as relsFromBytes, o as manifestFromBytes, tt as makeRelationships } from "./manifest-BHUYpjUG.mjs";
8
+ import { en as stableStringify, ht as makeStylesheet } from "./cell-style-DjKKPWDL.mjs";
9
+ import { k as parseSharedStringsXml, r as createWorkbook } from "./workbook-CMel6UcI.mjs";
10
+ import { a as makeDefinedName } from "./defined-names-Cmp8rbvI.mjs";
11
+ import { t as openZip } from "./reader-pC7bxYAs.mjs";
12
12
  //#region src/styles/stylesheet-reader.ts
13
13
  const STYLESHEET_TAG = qname(SHEET_MAIN_NS, "styleSheet");
14
14
  const FONTS_TAG = qname(SHEET_MAIN_NS, "fonts");
@@ -196,7 +196,7 @@ const buildKeyIndex = (arr) => {
196
196
  };
197
197
  //#endregion
198
198
  //#region src/io/load.ts
199
- /** Office Document relationship type the package-root pointer to `xl/workbook.xml`. */
199
+ /** Office Document relationship type: the package-root pointer to `xl/workbook.xml`. */
200
200
  const OFFICE_DOC_REL_TYPE = `${REL_NS}/officeDocument`;
201
201
  /**
202
202
  * Resolve an OPC relationship target against its source part path.
@@ -210,6 +210,19 @@ function resolveRelTarget(sourcePartPath, target) {
210
210
  const lastSlash = sourcePartPath.lastIndexOf("/");
211
211
  return normalizePath((lastSlash >= 0 ? sourcePartPath.slice(0, lastSlash + 1) : "") + target);
212
212
  }
213
+ /**
214
+ * Some producers store literal spaces in ZIP entry names. Decode only as a
215
+ * fallback after looking for the exact package name, so encoded names retain
216
+ * their identity and existing relationship resolution stays compatible.
217
+ */
218
+ function decodeTarget(target) {
219
+ if (!target.includes("%")) return target;
220
+ try {
221
+ return decodeURIComponent(target);
222
+ } catch {
223
+ return target;
224
+ }
225
+ }
213
226
  function normalizePath(path) {
214
227
  const segments = path.split("/");
215
228
  const out = [];
@@ -223,6 +236,42 @@ function normalizePath(path) {
223
236
  }
224
237
  return out.join("/");
225
238
  }
239
+ const SHARED_STRINGS_PART = {
240
+ name: "sharedStrings",
241
+ relType: `${REL_NS}/sharedStrings`,
242
+ conventionalPath: ARC_SHARED_STRINGS
243
+ };
244
+ const STYLES_PART = {
245
+ name: "styles",
246
+ relType: `${REL_NS}/styles`,
247
+ conventionalPath: ARC_STYLE
248
+ };
249
+ const THEME_PART = {
250
+ name: "theme",
251
+ relType: `${REL_NS}/theme`,
252
+ conventionalPath: ARC_THEME
253
+ };
254
+ /**
255
+ * Read an optional workbook-level part, following the relationship that binds
256
+ * it to the workbook.
257
+ *
258
+ * The relationship decides. `xl/sharedStrings.xml` and its siblings are only
259
+ * where Excel happens to write these parts, and a producer may point the rel
260
+ * at any part in the package, so the conventional path serves the packages
261
+ * that ship the part with no relationship at all.
262
+ *
263
+ * A relationship that resolves to nothing is a malformed package rather than
264
+ * an absent part, so it throws instead of reading back as an empty table.
265
+ */
266
+ function readOptionalWorkbookPart(archive, workbookPath, wbRels, part) {
267
+ const rel = findByType(wbRels, part.relType);
268
+ if (!rel) return archive.has(part.conventionalPath) ? archive.read(part.conventionalPath) : void 0;
269
+ if (rel.targetMode === "External") throw new OpenXmlSchemaError(`workbook rels: the ${part.name} relationship is external ("${rel.target}"), and has to name a part inside the package`);
270
+ let path = resolveRelTarget(workbookPath, rel.target);
271
+ if (!archive.has(path)) path = resolveRelTarget(workbookPath, decodeTarget(rel.target));
272
+ if (!archive.has(path)) throw new OpenXmlSchemaError(`workbook rels: the ${part.name} relationship targets "${path}", which the package does not contain`);
273
+ return archive.read(path);
274
+ }
226
275
  /** Sibling rels-part path for a given part. `xl/workbook.xml` → `xl/_rels/workbook.xml.rels`. */
227
276
  function relsPathFor(partPath) {
228
277
  const i = partPath.lastIndexOf("/");
@@ -346,37 +395,15 @@ function loadWorkbookFromArchive(archive) {
346
395
  const definedNamesFromXml = parseDefinedNames(wbRoot);
347
396
  const wbRelsPath = relsPathFor(workbookPath);
348
397
  if (sheetEntries.length > 0 && !archive.has(wbRelsPath)) throw new OpenXmlSchemaError(`loadWorkbook: workbook has sheets but rels part "${wbRelsPath}" is missing`);
349
- const wbRels = archive.has(wbRelsPath) ? relsFromBytes(archive.read(wbRelsPath)) : { rels: [] };
350
- let sharedStrings;
351
- if (archive.has(ARC_SHARED_STRINGS)) sharedStrings = parseSharedStringsXml(archive.read(ARC_SHARED_STRINGS));
352
- else {
353
- const sstRel = wbRels.rels.find((r) => r.type === `${REL_NS}/sharedStrings`);
354
- if (sstRel) {
355
- const sstPath = resolveRelTarget(workbookPath, sstRel.target);
356
- if (archive.has(sstPath)) sharedStrings = parseSharedStringsXml(archive.read(sstPath));
357
- }
358
- }
359
- const sst = sharedStrings?.entries ?? [];
360
- let styles;
361
- if (archive.has(ARC_STYLE)) styles = parseStylesheetXml(archive.read(ARC_STYLE));
362
- else {
363
- const stylesRel = wbRels.rels.find((r) => r.type === `${REL_NS}/styles`);
364
- if (stylesRel) {
365
- const stylesPath = resolveRelTarget(workbookPath, stylesRel.target);
366
- if (archive.has(stylesPath)) styles = parseStylesheetXml(archive.read(stylesPath));
367
- }
368
- }
398
+ const wbRels = archive.has(wbRelsPath) ? relsFromBytes(archive.read(wbRelsPath)) : makeRelationships();
399
+ const sstBytes = readOptionalWorkbookPart(archive, workbookPath, wbRels, SHARED_STRINGS_PART);
400
+ const sst = (sstBytes === void 0 ? void 0 : parseSharedStringsXml(sstBytes))?.entries ?? [];
401
+ const stylesBytes = readOptionalWorkbookPart(archive, workbookPath, wbRels, STYLES_PART);
402
+ const styles = stylesBytes === void 0 ? void 0 : parseStylesheetXml(stylesBytes);
369
403
  const properties = archive.has(ARC_CORE) ? corePropsFromBytes(archive.read(ARC_CORE)) : void 0;
370
404
  const appProperties = archive.has(ARC_APP) ? extendedPropsFromBytes(archive.read(ARC_APP)) : void 0;
371
405
  const customProperties = archive.has(ARC_CUSTOM) ? customPropsFromBytes(archive.read(ARC_CUSTOM)) : void 0;
372
- const themeXml = (() => {
373
- if (archive.has(ARC_THEME)) return archive.read(ARC_THEME);
374
- const themeRel = wbRels.rels.find((r) => r.type === `${REL_NS}/theme`);
375
- if (themeRel) {
376
- const themePath = resolveRelTarget(workbookPath, themeRel.target);
377
- if (archive.has(themePath)) return archive.read(themePath);
378
- }
379
- })();
406
+ const themeXml = readOptionalWorkbookPart(archive, workbookPath, wbRels, THEME_PART);
380
407
  const wb = createWorkbook({ date1904: parseDate1904(wbRoot) });
381
408
  if (styles) wb.styles = styles;
382
409
  if (properties) wb.properties = properties;
@@ -1167,6 +1194,6 @@ function capturePassthrough(archive, manifest, wb, roots, vml) {
1167
1194
  }
1168
1195
  }
1169
1196
  //#endregion
1170
- export { parseStylesheetXml as i, parseDate1904 as n, resolveRelTarget as r, loadWorkbook as t };
1197
+ export { parseDate1904 as a, resolveRelTarget as c, loadWorkbook as i, parseStylesheetXml as l, SHARED_STRINGS_PART as n, parseSheetEntries as o, STYLES_PART as r, readOptionalWorkbookPart as s, OFFICE_DOC_REL_TYPE as t };
1171
1198
 
1172
- //# sourceMappingURL=load-CspGc399.mjs.map
1199
+ //# sourceMappingURL=load-DIdQ_zum.mjs.map