ooxml.js 2.5.2 → 2.6.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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +22 -0
  3. package/dist/index.d.cts +3 -2
  4. package/dist/index.d.ts +3 -2
  5. package/dist/index.js +3 -2
  6. package/dist/typed/docx/numbering.cjs +86 -0
  7. package/dist/typed/docx/numbering.d.cts +23 -0
  8. package/dist/typed/docx/numbering.d.ts +23 -0
  9. package/dist/typed/docx/numbering.js +83 -0
  10. package/dist/typed/docx/read.cjs +115 -15
  11. package/dist/typed/docx/read.d.cts +8 -0
  12. package/dist/typed/docx/read.d.ts +8 -0
  13. package/dist/typed/docx/read.js +117 -17
  14. package/dist/typed/docx/styles.cjs +26 -2
  15. package/dist/typed/docx/styles.js +26 -2
  16. package/dist/typed/pptx/read.cjs +5 -20
  17. package/dist/typed/pptx/read.js +5 -20
  18. package/dist/typed/shared/drawingml.cjs +112 -5
  19. package/dist/typed/shared/drawingml.d.cts +19 -2
  20. package/dist/typed/shared/drawingml.d.ts +19 -2
  21. package/dist/typed/shared/drawingml.js +111 -6
  22. package/dist/typed/shared/units.cjs +10 -0
  23. package/dist/typed/shared/units.d.cts +4 -1
  24. package/dist/typed/shared/units.d.ts +4 -1
  25. package/dist/typed/shared/units.js +8 -1
  26. package/dist/typed/xlsx/build.cjs +83 -55
  27. package/dist/typed/xlsx/build.js +83 -55
  28. package/dist/typed/xlsx/content.cjs +85 -15
  29. package/dist/typed/xlsx/content.js +85 -15
  30. package/dist/typed/xlsx/number-format.cjs +324 -0
  31. package/dist/typed/xlsx/number-format.d.cts +52 -0
  32. package/dist/typed/xlsx/number-format.d.ts +52 -0
  33. package/dist/typed/xlsx/number-format.js +312 -0
  34. package/dist/typed/xlsx/serial.cjs +109 -0
  35. package/dist/typed/xlsx/serial.d.cts +11 -0
  36. package/dist/typed/xlsx/serial.d.ts +11 -0
  37. package/dist/typed/xlsx/serial.js +102 -0
  38. package/dist/typed/xlsx/styles.cjs +73 -0
  39. package/dist/typed/xlsx/styles.d.cts +21 -0
  40. package/dist/typed/xlsx/styles.d.ts +21 -0
  41. package/dist/typed/xlsx/styles.js +69 -0
  42. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ import { attr, childrenWithTag, decodeEntities, rootElement } from "../util.js";
2
+ import { BUILTIN_NUMBER_FORMATS } from "./number-format.js";
3
+ //#region src/typed/xlsx/styles.ts
4
+ const STYLES_PATH = "xl/styles.xml";
5
+ const GENERAL_NUM_FMT_ID = 0;
6
+ function readNumberFormatCodesById(styleSheet) {
7
+ const codes = new Map(BUILTIN_NUMBER_FORMATS);
8
+ const numFmtsEl = childrenWithTag(styleSheet, "numFmts")[0];
9
+ if (numFmtsEl === void 0) return codes;
10
+ for (const numFmt of childrenWithTag(numFmtsEl, "numFmt")) {
11
+ const idRaw = attr(numFmt, "numFmtId");
12
+ const formatCode = attr(numFmt, "formatCode");
13
+ if (idRaw === void 0 || formatCode === void 0) continue;
14
+ const id = Number.parseInt(idRaw, 10);
15
+ if (Number.isInteger(id)) codes.set(id, decodeEntities(formatCode));
16
+ }
17
+ return codes;
18
+ }
19
+ function readCellFormatCodes(pkg) {
20
+ const styleSheet = rootElement(pkg.parts[STYLES_PATH]);
21
+ if (styleSheet === void 0) return [];
22
+ const cellXfsEl = childrenWithTag(styleSheet, "cellXfs")[0];
23
+ if (cellXfsEl === void 0) return [];
24
+ const codes = readNumberFormatCodesById(styleSheet);
25
+ return childrenWithTag(cellXfsEl, "xf").map((xf) => {
26
+ const raw = attr(xf, "numFmtId");
27
+ const id = raw === void 0 ? 0 : Number.parseInt(raw, 10);
28
+ return Number.isInteger(id) ? codes.get(id) : void 0;
29
+ });
30
+ }
31
+ const FIRST_CUSTOM_NUM_FMT_ID = 164;
32
+ const DEFAULT_CELL_FORMAT_INDEX = 0;
33
+ function signatureOf(format) {
34
+ return format.kind === "builtin" ? `builtin:${format.id}` : `custom:${format.code}`;
35
+ }
36
+ var CellFormatTable = class {
37
+ indexBySignature = /* @__PURE__ */ new Map([[signatureOf({
38
+ kind: "builtin",
39
+ id: 0
40
+ }), 0]]);
41
+ numFmtIdByIndex = [0];
42
+ declared = [];
43
+ intern(format) {
44
+ const signature = signatureOf(format);
45
+ const existing = this.indexBySignature.get(signature);
46
+ if (existing !== void 0) return existing;
47
+ const numFmtId = format.kind === "builtin" ? format.id : this.declare(format.code);
48
+ const index = this.numFmtIdByIndex.length;
49
+ this.numFmtIdByIndex.push(numFmtId);
50
+ this.indexBySignature.set(signature, index);
51
+ return index;
52
+ }
53
+ declarations() {
54
+ return this.declared;
55
+ }
56
+ cellFormats() {
57
+ return this.numFmtIdByIndex;
58
+ }
59
+ declare(code) {
60
+ const id = FIRST_CUSTOM_NUM_FMT_ID + this.declared.length;
61
+ this.declared.push({
62
+ id,
63
+ code
64
+ });
65
+ return id;
66
+ }
67
+ };
68
+ //#endregion
69
+ export { CellFormatTable, DEFAULT_CELL_FORMAT_INDEX, GENERAL_NUM_FMT_ID, readCellFormatCodes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml.js",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "description": "Type-safe, lossless round-trip conversion between OOXML packages (docx, pptx, xlsx) and JSON, built on Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {