js.documents 14.3.0 → 14.3.2

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.
@@ -58,7 +58,6 @@ function buildDocxPackage(content, options) {
58
58
  const remap = /* @__PURE__ */ new Map();
59
59
  if (numIdLevels.size > 0) {
60
60
  const entries = [];
61
- let abstractNumId = 0;
62
61
  let numId = 1;
63
62
  for (const [sourceNumId, levels] of numIdLevels) {
64
63
  const remapped = String(numId);
@@ -66,22 +65,22 @@ function buildDocxPackage(content, options) {
66
65
  entries.push({
67
66
  sourceNumId,
68
67
  remappedNumId: remapped,
69
- abstractNumId: String(abstractNumId),
70
- levels: [...levels].sort((a, b) => a - b)
68
+ levels
71
69
  });
72
- abstractNumId += 1;
73
70
  numId += 1;
74
71
  }
75
- const numberingRoot = require_edit_docx_numbering.buildNumberingRoot(entries);
76
- pkg.parts[require_edit_docx_numbering.NUMBERING_PART_PATH] = {
77
- kind: "xml",
78
- nodes: [require_edit_docx_numbering.declaration(), numberingRoot]
79
- };
80
- require_opc_content_types.ensureContentTypeOverride(pkg, require_edit_docx_numbering.NUMBERING_PART_PATH, require_edit_docx_numbering.NUMBERING_CONTENT_TYPE);
81
- require_opc_rels.addRelationship(pkg, "word/document.xml", {
82
- type: require_edit_docx_numbering.NUMBERING_REL_TYPE,
83
- target: "numbering.xml"
84
- });
72
+ const numberingRoot = (0, ooxml_js.buildNumberingElement)(require_edit_docx_numbering.buildNumberingDefinitions(entries));
73
+ if (numberingRoot !== void 0) {
74
+ pkg.parts[require_edit_docx_numbering.NUMBERING_PART_PATH] = {
75
+ kind: "xml",
76
+ nodes: [require_edit_docx_numbering.declaration(), numberingRoot]
77
+ };
78
+ require_opc_content_types.ensureContentTypeOverride(pkg, require_edit_docx_numbering.NUMBERING_PART_PATH, require_edit_docx_numbering.NUMBERING_CONTENT_TYPE);
79
+ require_opc_rels.addRelationship(pkg, "word/document.xml", {
80
+ type: require_edit_docx_numbering.NUMBERING_REL_TYPE,
81
+ target: "numbering.xml"
82
+ });
83
+ }
85
84
  }
86
85
  const editor = new require_edit_docx_editor.DocxEditor(pkg);
87
86
  const markers = new ConstructMarkerState();
@@ -101,10 +100,10 @@ function collectListNumIds(blocks, out) {
101
100
  for (const block of blocks) if (block.kind === "paragraph" && block.list !== void 0) {
102
101
  let levels = out.get(block.list.numId);
103
102
  if (levels === void 0) {
104
- levels = /* @__PURE__ */ new Set();
103
+ levels = /* @__PURE__ */ new Map();
105
104
  out.set(block.list.numId, levels);
106
105
  }
107
- levels.add(block.list.level);
106
+ if (!levels.has(block.list.level)) levels.set(block.list.level, block.list.format);
108
107
  } else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) collectListNumIds(cell.blocks, out);
109
108
  }
110
109
  function remapListNumIds(blocks, numIdMap) {
@@ -115,8 +114,8 @@ function remapListNumIds(blocks, numIdMap) {
115
114
  return remapped === void 0 ? block : {
116
115
  ...block,
117
116
  list: {
118
- numId: remapped,
119
- level: block.list.level
117
+ ...block.list,
118
+ numId: remapped
120
119
  }
121
120
  };
122
121
  }
@@ -10,8 +10,8 @@ import { DocxEditor } from "./editor.js";
10
10
  import { FLOW_CONTAINER_ORIGIN, drawingOfBlock, embeddedDrawingVectors } from "../../model/embedded-drawing.js";
11
11
  import { formulaOfBlock, formulaPlaceholderText } from "../../model/formula.js";
12
12
  import { DocxWriteDiagnosticCodes, NOOP_DOCX_WRITE_DIAGNOSTIC_SINK } from "./diagnostics.js";
13
- import { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, buildNumberingRoot, declaration } from "./numbering.js";
14
- import { base64ToBytes } from "ooxml.js";
13
+ import { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, buildNumberingDefinitions, declaration } from "./numbering.js";
14
+ import { base64ToBytes, buildNumberingElement } from "ooxml.js";
15
15
  import { resolveCellFillColor, tableCellColumnSpan, tableCellRowSpan, tableGridColumnCount, walkTableGrid } from "document-schema.js";
16
16
  //#region src/edit/docx/content.ts
17
17
  var ConstructMarkerState = class {
@@ -57,7 +57,6 @@ function buildDocxPackage(content, options) {
57
57
  const remap = /* @__PURE__ */ new Map();
58
58
  if (numIdLevels.size > 0) {
59
59
  const entries = [];
60
- let abstractNumId = 0;
61
60
  let numId = 1;
62
61
  for (const [sourceNumId, levels] of numIdLevels) {
63
62
  const remapped = String(numId);
@@ -65,22 +64,22 @@ function buildDocxPackage(content, options) {
65
64
  entries.push({
66
65
  sourceNumId,
67
66
  remappedNumId: remapped,
68
- abstractNumId: String(abstractNumId),
69
- levels: [...levels].sort((a, b) => a - b)
67
+ levels
70
68
  });
71
- abstractNumId += 1;
72
69
  numId += 1;
73
70
  }
74
- const numberingRoot = buildNumberingRoot(entries);
75
- pkg.parts[NUMBERING_PART_PATH] = {
76
- kind: "xml",
77
- nodes: [declaration(), numberingRoot]
78
- };
79
- ensureContentTypeOverride(pkg, NUMBERING_PART_PATH, NUMBERING_CONTENT_TYPE);
80
- addRelationship(pkg, "word/document.xml", {
81
- type: NUMBERING_REL_TYPE,
82
- target: "numbering.xml"
83
- });
71
+ const numberingRoot = buildNumberingElement(buildNumberingDefinitions(entries));
72
+ if (numberingRoot !== void 0) {
73
+ pkg.parts[NUMBERING_PART_PATH] = {
74
+ kind: "xml",
75
+ nodes: [declaration(), numberingRoot]
76
+ };
77
+ ensureContentTypeOverride(pkg, NUMBERING_PART_PATH, NUMBERING_CONTENT_TYPE);
78
+ addRelationship(pkg, "word/document.xml", {
79
+ type: NUMBERING_REL_TYPE,
80
+ target: "numbering.xml"
81
+ });
82
+ }
84
83
  }
85
84
  const editor = new DocxEditor(pkg);
86
85
  const markers = new ConstructMarkerState();
@@ -100,10 +99,10 @@ function collectListNumIds(blocks, out) {
100
99
  for (const block of blocks) if (block.kind === "paragraph" && block.list !== void 0) {
101
100
  let levels = out.get(block.list.numId);
102
101
  if (levels === void 0) {
103
- levels = /* @__PURE__ */ new Set();
102
+ levels = /* @__PURE__ */ new Map();
104
103
  out.set(block.list.numId, levels);
105
104
  }
106
- levels.add(block.list.level);
105
+ if (!levels.has(block.list.level)) levels.set(block.list.level, block.list.format);
107
106
  } else if (block.kind === "table") for (const row of block.rows) for (const cell of row.cells) collectListNumIds(cell.blocks, out);
108
107
  }
109
108
  function remapListNumIds(blocks, numIdMap) {
@@ -114,8 +113,8 @@ function remapListNumIds(blocks, numIdMap) {
114
113
  return remapped === void 0 ? block : {
115
114
  ...block,
116
115
  list: {
117
- numId: remapped,
118
- level: block.list.level
116
+ ...block.list,
117
+ numId: remapped
119
118
  }
120
119
  };
121
120
  }
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_xml_fragment = require("../../xml/fragment.cjs");
3
2
  //#region src/edit/docx/numbering.ts
4
3
  const NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
5
4
  const NUMBERING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
@@ -23,23 +22,25 @@ function declaration() {
23
22
  ]
24
23
  };
25
24
  }
26
- function buildNumberingRoot(entries) {
27
- const W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
28
- const abstractNums = entries.map((entry) => require_xml_fragment.el("w:abstractNum", { "w:abstractNumId": entry.abstractNumId }, entry.levels.map((level) => require_xml_fragment.el("w:lvl", {
29
- "w:ilvl": String(level),
30
- "w:tentative": "1"
31
- }, [
32
- require_xml_fragment.el("w:start", { "w:val": "1" }),
33
- require_xml_fragment.el("w:numFmt", { "w:val": "bullet" }),
34
- require_xml_fragment.el("w:lvlText", { "w:val": "•" }),
35
- require_xml_fragment.el("w:lvlJc", { "w:val": "left" })
36
- ]))));
37
- const nums = entries.map((entry) => require_xml_fragment.el("w:num", { "w:numId": entry.remappedNumId }, [require_xml_fragment.el("w:abstractNumId", { "w:val": entry.abstractNumId })]));
38
- return require_xml_fragment.el("w:numbering", { "xmlns:w": W }, [...abstractNums, ...nums]);
25
+ function lvlText(format, level) {
26
+ return format === void 0 || format === "bullet" ? "•" : `%${level + 1}.`;
27
+ }
28
+ function buildNumberingDefinitions(entries) {
29
+ const definitions = {};
30
+ for (const entry of entries) {
31
+ const levels = {};
32
+ for (const [level, format] of entry.levels) levels[String(level)] = {
33
+ format: format ?? "bullet",
34
+ text: lvlText(format, level),
35
+ startAt: 1
36
+ };
37
+ definitions[entry.remappedNumId] = { levels };
38
+ }
39
+ return definitions;
39
40
  }
40
41
  //#endregion
41
42
  exports.NUMBERING_CONTENT_TYPE = NUMBERING_CONTENT_TYPE;
42
43
  exports.NUMBERING_PART_PATH = NUMBERING_PART_PATH;
43
44
  exports.NUMBERING_REL_TYPE = NUMBERING_REL_TYPE;
44
- exports.buildNumberingRoot = buildNumberingRoot;
45
+ exports.buildNumberingDefinitions = buildNumberingDefinitions;
45
46
  exports.declaration = declaration;
@@ -1,4 +1,5 @@
1
- import { XmlElement, XmlNode } from "ooxml.js";
1
+ import { ContentListMembership } from "document-schema.js";
2
+ import { NumberingDefinitions, XmlNode } from "ooxml.js";
2
3
  //#region src/edit/docx/numbering.d.ts
3
4
  declare const NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
4
5
  declare const NUMBERING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
@@ -7,9 +8,8 @@ declare function declaration(): XmlNode;
7
8
  interface NumberingEntry {
8
9
  readonly sourceNumId: string | undefined;
9
10
  readonly remappedNumId: string;
10
- readonly abstractNumId: string;
11
- readonly levels: readonly number[];
11
+ readonly levels: ReadonlyMap<number, ContentListMembership["format"]>;
12
12
  }
13
- declare function buildNumberingRoot(entries: readonly NumberingEntry[]): XmlElement;
13
+ declare function buildNumberingDefinitions(entries: readonly NumberingEntry[]): NumberingDefinitions;
14
14
  //#endregion
15
- export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, NumberingEntry, buildNumberingRoot, declaration };
15
+ export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, NumberingEntry, buildNumberingDefinitions, declaration };
@@ -1,4 +1,5 @@
1
- import { XmlElement, XmlNode } from "ooxml.js";
1
+ import { NumberingDefinitions, XmlNode } from "ooxml.js";
2
+ import { ContentListMembership } from "document-schema.js";
2
3
  //#region src/edit/docx/numbering.d.ts
3
4
  declare const NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
4
5
  declare const NUMBERING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
@@ -7,9 +8,8 @@ declare function declaration(): XmlNode;
7
8
  interface NumberingEntry {
8
9
  readonly sourceNumId: string | undefined;
9
10
  readonly remappedNumId: string;
10
- readonly abstractNumId: string;
11
- readonly levels: readonly number[];
11
+ readonly levels: ReadonlyMap<number, ContentListMembership["format"]>;
12
12
  }
13
- declare function buildNumberingRoot(entries: readonly NumberingEntry[]): XmlElement;
13
+ declare function buildNumberingDefinitions(entries: readonly NumberingEntry[]): NumberingDefinitions;
14
14
  //#endregion
15
- export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, NumberingEntry, buildNumberingRoot, declaration };
15
+ export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, NumberingEntry, buildNumberingDefinitions, declaration };
@@ -1,4 +1,3 @@
1
- import { el } from "../../xml/fragment.js";
2
1
  //#region src/edit/docx/numbering.ts
3
2
  const NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
4
3
  const NUMBERING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
@@ -22,19 +21,21 @@ function declaration() {
22
21
  ]
23
22
  };
24
23
  }
25
- function buildNumberingRoot(entries) {
26
- const W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
27
- const abstractNums = entries.map((entry) => el("w:abstractNum", { "w:abstractNumId": entry.abstractNumId }, entry.levels.map((level) => el("w:lvl", {
28
- "w:ilvl": String(level),
29
- "w:tentative": "1"
30
- }, [
31
- el("w:start", { "w:val": "1" }),
32
- el("w:numFmt", { "w:val": "bullet" }),
33
- el("w:lvlText", { "w:val": "•" }),
34
- el("w:lvlJc", { "w:val": "left" })
35
- ]))));
36
- const nums = entries.map((entry) => el("w:num", { "w:numId": entry.remappedNumId }, [el("w:abstractNumId", { "w:val": entry.abstractNumId })]));
37
- return el("w:numbering", { "xmlns:w": W }, [...abstractNums, ...nums]);
24
+ function lvlText(format, level) {
25
+ return format === void 0 || format === "bullet" ? "•" : `%${level + 1}.`;
26
+ }
27
+ function buildNumberingDefinitions(entries) {
28
+ const definitions = {};
29
+ for (const entry of entries) {
30
+ const levels = {};
31
+ for (const [level, format] of entry.levels) levels[String(level)] = {
32
+ format: format ?? "bullet",
33
+ text: lvlText(format, level),
34
+ startAt: 1
35
+ };
36
+ definitions[entry.remappedNumId] = { levels };
37
+ }
38
+ return definitions;
38
39
  }
39
40
  //#endregion
40
- export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, buildNumberingRoot, declaration };
41
+ export { NUMBERING_CONTENT_TYPE, NUMBERING_PART_PATH, NUMBERING_REL_TYPE, buildNumberingDefinitions, declaration };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "14.3.0",
3
+ "version": "14.3.2",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -78,20 +78,20 @@
78
78
  "license": "MIT",
79
79
  "dependencies": {
80
80
  "archive-codec": "1.11.12",
81
- "byte-codec": "1.8.1",
82
- "doc-codec": "6.1.0",
81
+ "byte-codec": "1.9.0",
82
+ "doc-codec": "6.1.1",
83
83
  "document-schema.js": "7.15.0",
84
- "epub-codec": "5.1.0",
84
+ "epub-codec": "5.1.1",
85
85
  "fflate": "0.8.3",
86
- "markdown-codec": "11.1.0",
87
- "odf.js": "11.1.0",
88
- "ooxml.js": "12.1.0",
89
- "pdf-codec": "5.2.6",
90
- "ppt-codec": "2.2.0",
91
- "rtf-codec": "8.1.0",
86
+ "markdown-codec": "11.1.1",
87
+ "odf.js": "11.1.1",
88
+ "ooxml.js": "12.2.1",
89
+ "pdf-codec": "5.2.7",
90
+ "ppt-codec": "2.2.1",
91
+ "rtf-codec": "8.1.1",
92
92
  "temml": "0.13.4",
93
- "wpd-codec": "5.1.2",
94
- "xls-codec": "4.15.18",
93
+ "wpd-codec": "5.1.3",
94
+ "xls-codec": "4.15.19",
95
95
  "zod": "4.4.3"
96
96
  },
97
97
  "devDependencies": {