js.documents 1.84.0 → 1.85.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 (61) hide show
  1. package/dist/edit/docx/content.cjs +10 -1
  2. package/dist/edit/docx/content.js +10 -1
  3. package/dist/edit/docx/paragraph.cjs +98 -0
  4. package/dist/edit/docx/paragraph.d.cts +12 -0
  5. package/dist/edit/docx/paragraph.d.ts +12 -0
  6. package/dist/edit/docx/paragraph.js +99 -1
  7. package/dist/edit/docx/props.cjs +1 -1
  8. package/dist/edit/docx/props.js +1 -1
  9. package/dist/edit/docx/table.cjs +119 -1
  10. package/dist/edit/docx/table.d.cts +8 -0
  11. package/dist/edit/docx/table.d.ts +8 -0
  12. package/dist/edit/docx/table.js +119 -1
  13. package/dist/edit/odg/page.d.cts +1 -1
  14. package/dist/edit/odg/page.d.ts +1 -1
  15. package/dist/edit/odp/shape.d.cts +1 -1
  16. package/dist/edit/odp/shape.d.ts +1 -1
  17. package/dist/edit/odp/slide.d.cts +2 -2
  18. package/dist/edit/odp/slide.d.ts +2 -2
  19. package/dist/edit/odt/content.cjs +7 -0
  20. package/dist/edit/odt/content.d.cts +2 -2
  21. package/dist/edit/odt/content.d.ts +2 -2
  22. package/dist/edit/odt/content.js +7 -0
  23. package/dist/edit/odt/editor.d.cts +3 -3
  24. package/dist/edit/odt/editor.d.ts +3 -3
  25. package/dist/edit/odt/list.d.cts +1 -1
  26. package/dist/edit/odt/list.d.ts +1 -1
  27. package/dist/edit/odt/paragraph.cjs +30 -0
  28. package/dist/edit/odt/paragraph.d.cts +1 -1
  29. package/dist/edit/odt/paragraph.d.ts +1 -1
  30. package/dist/edit/odt/paragraph.js +30 -0
  31. package/dist/edit/odt/table.cjs +105 -0
  32. package/dist/edit/odt/table.d.cts +2 -2
  33. package/dist/edit/odt/table.d.ts +2 -2
  34. package/dist/edit/odt/table.js +105 -2
  35. package/dist/edit/pptx/content.cjs +4 -0
  36. package/dist/edit/pptx/content.js +4 -0
  37. package/dist/edit/pptx/shape.cjs +3 -1
  38. package/dist/edit/pptx/shape.d.cts +1 -1
  39. package/dist/edit/pptx/shape.d.ts +1 -1
  40. package/dist/edit/pptx/shape.js +3 -1
  41. package/dist/edit/pptx/slide.d.cts +2 -2
  42. package/dist/edit/pptx/slide.d.ts +2 -2
  43. package/dist/edit/pptx/table.cjs +1 -1
  44. package/dist/edit/pptx/table.d.cts +1 -1
  45. package/dist/edit/pptx/table.d.ts +1 -1
  46. package/dist/edit/pptx/table.js +1 -1
  47. package/dist/index.d.cts +6 -6
  48. package/dist/index.d.ts +6 -6
  49. package/dist/{list-CYsXBdVG.d.cts → list-CxoEJwNO.d.cts} +1 -1
  50. package/dist/{list-DVRX7hm9.d.ts → list-DA1hCBVI.d.ts} +1 -1
  51. package/dist/{paragraph-Bg446o16.d.ts → paragraph-DV4_ZNGr.d.ts} +10 -0
  52. package/dist/{paragraph-BZIDHdnv.d.cts → paragraph-DXIJfPMw.d.cts} +10 -0
  53. package/dist/{shape-BhkP6HB8.d.cts → shape-BwBiRGha.d.cts} +2 -0
  54. package/dist/{shape-BjX3wlig.d.ts → shape-D5IoGzf9.d.ts} +2 -0
  55. package/dist/{shape-rvNMzcun.d.cts → shape-Dch9pDCf.d.cts} +2 -2
  56. package/dist/{shape-Be0LdJGE.d.ts → shape-DyviC6ZG.d.ts} +2 -2
  57. package/dist/{table-DIXStwnk.d.cts → table-BtMtRYqc.d.cts} +13 -2
  58. package/dist/{table-CLhAexfN.d.ts → table-BxeHHD7r.d.ts} +13 -2
  59. package/dist/{table-L5SxKy8_.d.ts → table-CCdAhdcG.d.ts} +1 -1
  60. package/dist/{table-CfRjVOFN.d.cts → table-SczxeRF0.d.cts} +1 -1
  61. package/package.json +1 -1
@@ -50,6 +50,11 @@ function populateParagraph(paragraph, block) {
50
50
  paragraph.styleId = block.styleId;
51
51
  paragraph.alignment = block.alignment;
52
52
  paragraph.list = block.list;
53
+ if (block.spacingBeforePt !== void 0) paragraph.spacingBeforePt = block.spacingBeforePt;
54
+ if (block.spacingAfterPt !== void 0) paragraph.spacingAfterPt = block.spacingAfterPt;
55
+ if (block.lineSpacing !== void 0) paragraph.lineSpacing = block.lineSpacing;
56
+ if (block.indentLeftPt !== void 0) paragraph.indentLeftPt = block.indentLeftPt;
57
+ if (block.indentFirstLinePt !== void 0) paragraph.indentFirstLinePt = block.indentFirstLinePt;
53
58
  for (const run of block.runs) {
54
59
  if (run.text === " ") {
55
60
  paragraph.appendTab();
@@ -82,7 +87,9 @@ function appendTable(body, block) {
82
87
  });
83
88
  const verticalMerges = /* @__PURE__ */ new Map();
84
89
  block.rows.forEach((row) => {
85
- const domCells = table.appendRow(row.cells.length).cells();
90
+ const tableRow = table.appendRow(row.cells.length);
91
+ if (row.heightPt !== void 0) tableRow.heightPt = row.heightPt;
92
+ const domCells = tableRow.cells();
86
93
  let colIndex = 0;
87
94
  row.cells.forEach((cell, cellIndex) => {
88
95
  const tableCell = domCells[cellIndex];
@@ -107,6 +114,8 @@ function appendTable(body, block) {
107
114
  gridSpan: span
108
115
  });
109
116
  }
117
+ if (cell.background !== void 0) tableCell.background = cell.background;
118
+ if (cell.borders !== void 0) tableCell.borders = cell.borders;
110
119
  populateCellBlocks(tableCell, cell.blocks);
111
120
  colIndex += span;
112
121
  });
@@ -49,6 +49,11 @@ function populateParagraph(paragraph, block) {
49
49
  paragraph.styleId = block.styleId;
50
50
  paragraph.alignment = block.alignment;
51
51
  paragraph.list = block.list;
52
+ if (block.spacingBeforePt !== void 0) paragraph.spacingBeforePt = block.spacingBeforePt;
53
+ if (block.spacingAfterPt !== void 0) paragraph.spacingAfterPt = block.spacingAfterPt;
54
+ if (block.lineSpacing !== void 0) paragraph.lineSpacing = block.lineSpacing;
55
+ if (block.indentLeftPt !== void 0) paragraph.indentLeftPt = block.indentLeftPt;
56
+ if (block.indentFirstLinePt !== void 0) paragraph.indentFirstLinePt = block.indentFirstLinePt;
52
57
  for (const run of block.runs) {
53
58
  if (run.text === " ") {
54
59
  paragraph.appendTab();
@@ -81,7 +86,9 @@ function appendTable(body, block) {
81
86
  });
82
87
  const verticalMerges = /* @__PURE__ */ new Map();
83
88
  block.rows.forEach((row) => {
84
- const domCells = table.appendRow(row.cells.length).cells();
89
+ const tableRow = table.appendRow(row.cells.length);
90
+ if (row.heightPt !== void 0) tableRow.heightPt = row.heightPt;
91
+ const domCells = tableRow.cells();
85
92
  let colIndex = 0;
86
93
  row.cells.forEach((cell, cellIndex) => {
87
94
  const tableCell = domCells[cellIndex];
@@ -106,6 +113,8 @@ function appendTable(body, block) {
106
113
  gridSpan: span
107
114
  });
108
115
  }
116
+ if (cell.background !== void 0) tableCell.background = cell.background;
117
+ if (cell.borders !== void 0) tableCell.borders = cell.borders;
109
118
  populateCellBlocks(tableCell, cell.blocks);
110
119
  colIndex += span;
111
120
  });
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_fragment = require("../../xml/fragment.cjs");
3
3
  const require_omml_write = require("../../omml/write.cjs");
4
+ const require_model_units = require("../../model/units.cjs");
4
5
  const require_xml_edit = require("../../xml/edit.cjs");
5
6
  const require_edit_docx_image = require("./image.cjs");
6
7
  const require_edit_docx_props = require("./props.cjs");
@@ -82,6 +83,103 @@ var DocxParagraph = class {
82
83
  }
83
84
  require_edit_docx_props.setAlignment(this.pPr(true), value);
84
85
  }
86
+ spacingElement(create) {
87
+ const node = this.live();
88
+ const pPr = create ? require_edit_docx_props.ensureFirstChild(node, "w:pPr") : directChild(node, "w:pPr");
89
+ if (pPr === void 0) return;
90
+ return create ? require_xml_edit.getOrCreateChildElement(pPr, "w:spacing", require_edit_docx_props.PPR_ORDER, () => require_xml_fragment.el("w:spacing")) : directChild(pPr, "w:spacing");
91
+ }
92
+ get spacingBeforePt() {
93
+ const spacing = this.spacingElement(false);
94
+ const before = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:before");
95
+ return before === void 0 ? void 0 : require_model_units.twipsToPt(Number(before));
96
+ }
97
+ set spacingBeforePt(value) {
98
+ const spacing = this.spacingElement(value !== void 0);
99
+ if (spacing === void 0) return;
100
+ if (value === void 0) {
101
+ require_xml_edit.removeAttr(spacing, "w:before");
102
+ return;
103
+ }
104
+ require_xml_edit.setAttr(spacing, "w:before", String(require_model_units.ptToTwips(value)));
105
+ }
106
+ get spacingAfterPt() {
107
+ const spacing = this.spacingElement(false);
108
+ const after = spacing === void 0 ? void 0 : (0, ooxml_js.attr)(spacing, "w:after");
109
+ return after === void 0 ? void 0 : require_model_units.twipsToPt(Number(after));
110
+ }
111
+ set spacingAfterPt(value) {
112
+ const spacing = this.spacingElement(value !== void 0);
113
+ if (spacing === void 0) return;
114
+ if (value === void 0) {
115
+ require_xml_edit.removeAttr(spacing, "w:after");
116
+ return;
117
+ }
118
+ require_xml_edit.setAttr(spacing, "w:after", String(require_model_units.ptToTwips(value)));
119
+ }
120
+ get lineSpacing() {
121
+ const spacing = this.spacingElement(false);
122
+ if (spacing === void 0) return;
123
+ const lineRule = (0, ooxml_js.attr)(spacing, "w:lineRule");
124
+ if (lineRule === "exact" || lineRule === "atLeast") return;
125
+ const line = (0, ooxml_js.attr)(spacing, "w:line");
126
+ return line === void 0 ? void 0 : Number(line) / 240;
127
+ }
128
+ set lineSpacing(value) {
129
+ const spacing = this.spacingElement(value !== void 0);
130
+ if (spacing === void 0) return;
131
+ if (value === void 0) {
132
+ require_xml_edit.removeAttr(spacing, "w:line");
133
+ require_xml_edit.removeAttr(spacing, "w:lineRule");
134
+ return;
135
+ }
136
+ require_xml_edit.setAttr(spacing, "w:line", String(Math.round(value * 240)));
137
+ require_xml_edit.setAttr(spacing, "w:lineRule", "auto");
138
+ }
139
+ indElement(create) {
140
+ const node = this.live();
141
+ const pPr = create ? require_edit_docx_props.ensureFirstChild(node, "w:pPr") : directChild(node, "w:pPr");
142
+ if (pPr === void 0) return;
143
+ return create ? require_xml_edit.getOrCreateChildElement(pPr, "w:ind", require_edit_docx_props.PPR_ORDER, () => require_xml_fragment.el("w:ind")) : directChild(pPr, "w:ind");
144
+ }
145
+ get indentLeftPt() {
146
+ const ind = this.indElement(false);
147
+ const left = ind === void 0 ? void 0 : (0, ooxml_js.attr)(ind, "w:left");
148
+ return left === void 0 ? void 0 : require_model_units.twipsToPt(Number(left));
149
+ }
150
+ set indentLeftPt(value) {
151
+ const ind = this.indElement(value !== void 0);
152
+ if (ind === void 0) return;
153
+ if (value === void 0) {
154
+ require_xml_edit.removeAttr(ind, "w:left");
155
+ return;
156
+ }
157
+ require_xml_edit.setAttr(ind, "w:left", String(require_model_units.ptToTwips(value)));
158
+ }
159
+ get indentFirstLinePt() {
160
+ const ind = this.indElement(false);
161
+ if (ind === void 0) return;
162
+ const firstLine = (0, ooxml_js.attr)(ind, "w:firstLine");
163
+ if (firstLine !== void 0) return require_model_units.twipsToPt(Number(firstLine));
164
+ const hanging = (0, ooxml_js.attr)(ind, "w:hanging");
165
+ return hanging === void 0 ? void 0 : -require_model_units.twipsToPt(Number(hanging));
166
+ }
167
+ set indentFirstLinePt(value) {
168
+ const ind = this.indElement(value !== void 0);
169
+ if (ind === void 0) return;
170
+ if (value === void 0) {
171
+ require_xml_edit.removeAttr(ind, "w:firstLine");
172
+ require_xml_edit.removeAttr(ind, "w:hanging");
173
+ return;
174
+ }
175
+ if (value >= 0) {
176
+ require_xml_edit.removeAttr(ind, "w:hanging");
177
+ require_xml_edit.setAttr(ind, "w:firstLine", String(require_model_units.ptToTwips(value)));
178
+ } else {
179
+ require_xml_edit.removeAttr(ind, "w:firstLine");
180
+ require_xml_edit.setAttr(ind, "w:hanging", String(require_model_units.ptToTwips(-value)));
181
+ }
182
+ }
85
183
  get list() {
86
184
  const pPr = this.pPr(false);
87
185
  const numPr = pPr === void 0 ? void 0 : directChild(pPr, "w:numPr");
@@ -32,6 +32,18 @@ declare class DocxParagraph {
32
32
  set styleId(value: string | undefined);
33
33
  get alignment(): 'left' | 'center' | 'right' | 'justify' | undefined;
34
34
  set alignment(value: 'left' | 'center' | 'right' | 'justify' | undefined);
35
+ private spacingElement;
36
+ get spacingBeforePt(): number | undefined;
37
+ set spacingBeforePt(value: number | undefined);
38
+ get spacingAfterPt(): number | undefined;
39
+ set spacingAfterPt(value: number | undefined);
40
+ get lineSpacing(): number | undefined;
41
+ set lineSpacing(value: number | undefined);
42
+ private indElement;
43
+ get indentLeftPt(): number | undefined;
44
+ set indentLeftPt(value: number | undefined);
45
+ get indentFirstLinePt(): number | undefined;
46
+ set indentFirstLinePt(value: number | undefined);
35
47
  get list(): ContentListMembership | undefined;
36
48
  set list(value: ContentListMembership | undefined);
37
49
  appendOfficeMath(mathml: readonly MathMlNode$1[]): OmmlWriteResult & {
@@ -32,6 +32,18 @@ declare class DocxParagraph {
32
32
  set styleId(value: string | undefined);
33
33
  get alignment(): 'left' | 'center' | 'right' | 'justify' | undefined;
34
34
  set alignment(value: 'left' | 'center' | 'right' | 'justify' | undefined);
35
+ private spacingElement;
36
+ get spacingBeforePt(): number | undefined;
37
+ set spacingBeforePt(value: number | undefined);
38
+ get spacingAfterPt(): number | undefined;
39
+ set spacingAfterPt(value: number | undefined);
40
+ get lineSpacing(): number | undefined;
41
+ set lineSpacing(value: number | undefined);
42
+ private indElement;
43
+ get indentLeftPt(): number | undefined;
44
+ set indentLeftPt(value: number | undefined);
45
+ get indentFirstLinePt(): number | undefined;
46
+ set indentFirstLinePt(value: number | undefined);
35
47
  get list(): ContentListMembership | undefined;
36
48
  set list(value: ContentListMembership | undefined);
37
49
  appendOfficeMath(mathml: readonly MathMlNode$1[]): OmmlWriteResult & {
@@ -1,6 +1,7 @@
1
1
  import { el } from "../../xml/fragment.js";
2
2
  import { buildOfficeMathParagraph } from "../../omml/write.js";
3
- import { getOrCreateChildElement, removeChild } from "../../xml/edit.js";
3
+ import { ptToTwips, twipsToPt } from "../../model/units.js";
4
+ import { getOrCreateChildElement, removeAttr, removeChild, setAttr } from "../../xml/edit.js";
4
5
  import { insertImageMedia, nextDrawingId } from "./image.js";
5
6
  import { PPR_ORDER, ensureFirstChild, getAlignment, getStyleId, setAlignment, setStyleId } from "./props.js";
6
7
  import { DocxRun, buildRun, wordprocessingText } from "./run.js";
@@ -81,6 +82,103 @@ var DocxParagraph = class {
81
82
  }
82
83
  setAlignment(this.pPr(true), value);
83
84
  }
85
+ spacingElement(create) {
86
+ const node = this.live();
87
+ const pPr = create ? ensureFirstChild(node, "w:pPr") : directChild(node, "w:pPr");
88
+ if (pPr === void 0) return;
89
+ return create ? getOrCreateChildElement(pPr, "w:spacing", PPR_ORDER, () => el("w:spacing")) : directChild(pPr, "w:spacing");
90
+ }
91
+ get spacingBeforePt() {
92
+ const spacing = this.spacingElement(false);
93
+ const before = spacing === void 0 ? void 0 : attr(spacing, "w:before");
94
+ return before === void 0 ? void 0 : twipsToPt(Number(before));
95
+ }
96
+ set spacingBeforePt(value) {
97
+ const spacing = this.spacingElement(value !== void 0);
98
+ if (spacing === void 0) return;
99
+ if (value === void 0) {
100
+ removeAttr(spacing, "w:before");
101
+ return;
102
+ }
103
+ setAttr(spacing, "w:before", String(ptToTwips(value)));
104
+ }
105
+ get spacingAfterPt() {
106
+ const spacing = this.spacingElement(false);
107
+ const after = spacing === void 0 ? void 0 : attr(spacing, "w:after");
108
+ return after === void 0 ? void 0 : twipsToPt(Number(after));
109
+ }
110
+ set spacingAfterPt(value) {
111
+ const spacing = this.spacingElement(value !== void 0);
112
+ if (spacing === void 0) return;
113
+ if (value === void 0) {
114
+ removeAttr(spacing, "w:after");
115
+ return;
116
+ }
117
+ setAttr(spacing, "w:after", String(ptToTwips(value)));
118
+ }
119
+ get lineSpacing() {
120
+ const spacing = this.spacingElement(false);
121
+ if (spacing === void 0) return;
122
+ const lineRule = attr(spacing, "w:lineRule");
123
+ if (lineRule === "exact" || lineRule === "atLeast") return;
124
+ const line = attr(spacing, "w:line");
125
+ return line === void 0 ? void 0 : Number(line) / 240;
126
+ }
127
+ set lineSpacing(value) {
128
+ const spacing = this.spacingElement(value !== void 0);
129
+ if (spacing === void 0) return;
130
+ if (value === void 0) {
131
+ removeAttr(spacing, "w:line");
132
+ removeAttr(spacing, "w:lineRule");
133
+ return;
134
+ }
135
+ setAttr(spacing, "w:line", String(Math.round(value * 240)));
136
+ setAttr(spacing, "w:lineRule", "auto");
137
+ }
138
+ indElement(create) {
139
+ const node = this.live();
140
+ const pPr = create ? ensureFirstChild(node, "w:pPr") : directChild(node, "w:pPr");
141
+ if (pPr === void 0) return;
142
+ return create ? getOrCreateChildElement(pPr, "w:ind", PPR_ORDER, () => el("w:ind")) : directChild(pPr, "w:ind");
143
+ }
144
+ get indentLeftPt() {
145
+ const ind = this.indElement(false);
146
+ const left = ind === void 0 ? void 0 : attr(ind, "w:left");
147
+ return left === void 0 ? void 0 : twipsToPt(Number(left));
148
+ }
149
+ set indentLeftPt(value) {
150
+ const ind = this.indElement(value !== void 0);
151
+ if (ind === void 0) return;
152
+ if (value === void 0) {
153
+ removeAttr(ind, "w:left");
154
+ return;
155
+ }
156
+ setAttr(ind, "w:left", String(ptToTwips(value)));
157
+ }
158
+ get indentFirstLinePt() {
159
+ const ind = this.indElement(false);
160
+ if (ind === void 0) return;
161
+ const firstLine = attr(ind, "w:firstLine");
162
+ if (firstLine !== void 0) return twipsToPt(Number(firstLine));
163
+ const hanging = attr(ind, "w:hanging");
164
+ return hanging === void 0 ? void 0 : -twipsToPt(Number(hanging));
165
+ }
166
+ set indentFirstLinePt(value) {
167
+ const ind = this.indElement(value !== void 0);
168
+ if (ind === void 0) return;
169
+ if (value === void 0) {
170
+ removeAttr(ind, "w:firstLine");
171
+ removeAttr(ind, "w:hanging");
172
+ return;
173
+ }
174
+ if (value >= 0) {
175
+ removeAttr(ind, "w:hanging");
176
+ setAttr(ind, "w:firstLine", String(ptToTwips(value)));
177
+ } else {
178
+ removeAttr(ind, "w:firstLine");
179
+ setAttr(ind, "w:hanging", String(ptToTwips(-value)));
180
+ }
181
+ }
84
182
  get list() {
85
183
  const pPr = this.pPr(false);
86
184
  const numPr = pPr === void 0 ? void 0 : directChild(pPr, "w:numPr");
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_fragment = require("../../xml/fragment.cjs");
3
- const require_xml_edit = require("../../xml/edit.cjs");
4
3
  const require_model_units = require("../../model/units.cjs");
4
+ const require_xml_edit = require("../../xml/edit.cjs");
5
5
  let ooxml_js = require("ooxml.js");
6
6
  let document_schema_js = require("document-schema.js");
7
7
  //#region src/edit/docx/props.ts
@@ -1,7 +1,7 @@
1
1
  import { colorToRgbHex, rgbHexToColor } from "../../model/color.js";
2
2
  import { el } from "../../xml/fragment.js";
3
- import { directChildElement, getOrCreateChildElement, insertInSchemaOrder, removeAttr, setAttr } from "../../xml/edit.js";
4
3
  import { halfPointsToPt, ptToHalfPoints } from "../../model/units.js";
4
+ import { directChildElement, getOrCreateChildElement, insertInSchemaOrder, removeAttr, setAttr } from "../../xml/edit.js";
5
5
  import { attr } from "ooxml.js";
6
6
  //#region src/edit/docx/props.ts
7
7
  const RPR_ORDER = [
@@ -1,11 +1,37 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_fragment = require("../../xml/fragment.cjs");
3
+ const require_model_units = require("../../model/units.cjs");
3
4
  const require_xml_edit = require("../../xml/edit.cjs");
4
5
  const require_edit_docx_paragraph = require("./paragraph.cjs");
5
6
  let ooxml_js = require("ooxml.js");
7
+ let document_schema_js = require("document-schema.js");
6
8
  //#region src/edit/docx/table.ts
7
9
  const DEFAULT_TABLE_WIDTH_TWIPS = 9360;
8
- const TC_PR_CHILD_ORDER = ["w:gridSpan", "w:vMerge"];
10
+ const TC_PR_CHILD_ORDER = [
11
+ "w:gridSpan",
12
+ "w:vMerge",
13
+ "w:tcBorders",
14
+ "w:shd"
15
+ ];
16
+ const TC_BORDERS_CHILD_ORDER = [
17
+ "w:top",
18
+ "w:left",
19
+ "w:bottom",
20
+ "w:right"
21
+ ];
22
+ const EIGHTH_POINTS_PER_POINT = 8;
23
+ const DOCX_BORDER_STYLE_TO_VAL = {
24
+ solid: "single",
25
+ dashed: "dashed",
26
+ dotted: "dotted",
27
+ double: "double"
28
+ };
29
+ function valToBorderStyle(val) {
30
+ if (val === "dashed") return "dashed";
31
+ if (val === "dotted") return "dotted";
32
+ if (val === "double") return "double";
33
+ return "solid";
34
+ }
9
35
  var DocxTableCell = class {
10
36
  node;
11
37
  constructor(node) {
@@ -50,6 +76,75 @@ var DocxTableCell = class {
50
76
  tcPr.children = tcPr.children.filter((c) => !(c.type === "element" && c.tag === "w:vMerge"));
51
77
  require_xml_edit.insertInSchemaOrder(tcPr, value === "restart" ? require_xml_fragment.el("w:vMerge", { "w:val": "restart" }) : require_xml_fragment.el("w:vMerge"), TC_PR_CHILD_ORDER);
52
78
  }
79
+ get background() {
80
+ const tcPr = this.tcPrElement(false);
81
+ const shd = tcPr === void 0 ? void 0 : require_xml_edit.directChildElement(tcPr, "w:shd");
82
+ const fill = shd === void 0 ? void 0 : (0, ooxml_js.attr)(shd, "w:fill");
83
+ if (fill === void 0 || fill === "auto" || fill === "none") return;
84
+ return (0, document_schema_js.rgbHexToColor)(fill);
85
+ }
86
+ set background(value) {
87
+ if (value === void 0) {
88
+ const tcPr = this.tcPrElement(false);
89
+ if (tcPr !== void 0) tcPr.children = tcPr.children.filter((c) => !(c.type === "element" && c.tag === "w:shd"));
90
+ return;
91
+ }
92
+ const tcPr = this.tcPrElement(true);
93
+ tcPr.children = tcPr.children.filter((c) => !(c.type === "element" && c.tag === "w:shd"));
94
+ require_xml_edit.insertInSchemaOrder(tcPr, require_xml_fragment.el("w:shd", {
95
+ "w:val": "clear",
96
+ "w:color": "auto",
97
+ "w:fill": (0, document_schema_js.colorToRgbHex)(value)
98
+ }), TC_PR_CHILD_ORDER);
99
+ }
100
+ get borders() {
101
+ const tcPr = this.tcPrElement(false);
102
+ const tcBorders = tcPr === void 0 ? void 0 : require_xml_edit.directChildElement(tcPr, "w:tcBorders");
103
+ if (tcBorders === void 0) return;
104
+ const borders = {};
105
+ for (const edge of [
106
+ "top",
107
+ "left",
108
+ "bottom",
109
+ "right"
110
+ ]) {
111
+ const element = require_xml_edit.directChildElement(tcBorders, `w:${edge}`);
112
+ const val = element === void 0 ? void 0 : (0, ooxml_js.attr)(element, "w:val");
113
+ if (element === void 0 || val === void 0 || val === "nil" || val === "none") continue;
114
+ const sz = (0, ooxml_js.attr)(element, "w:sz");
115
+ const colorVal = (0, ooxml_js.attr)(element, "w:color");
116
+ borders[edge] = {
117
+ color: colorVal === void 0 || colorVal === "auto" ? {
118
+ r: 0,
119
+ g: 0,
120
+ b: 0
121
+ } : (0, document_schema_js.rgbHexToColor)(colorVal),
122
+ widthPt: Number(sz ?? String(EIGHTH_POINTS_PER_POINT)) / EIGHTH_POINTS_PER_POINT,
123
+ style: valToBorderStyle(val)
124
+ };
125
+ }
126
+ return Object.keys(borders).length === 0 ? void 0 : borders;
127
+ }
128
+ set borders(value) {
129
+ if (value === void 0) {
130
+ const tcPr = this.tcPrElement(false);
131
+ if (tcPr !== void 0) tcPr.children = tcPr.children.filter((c) => !(c.type === "element" && c.tag === "w:tcBorders"));
132
+ return;
133
+ }
134
+ const tcPr = this.tcPrElement(true);
135
+ tcPr.children = tcPr.children.filter((c) => !(c.type === "element" && c.tag === "w:tcBorders"));
136
+ const tcBorders = require_xml_fragment.el("w:tcBorders");
137
+ for (const edge of TC_BORDERS_CHILD_ORDER) {
138
+ const border = value[edge === "w:top" ? "top" : edge === "w:left" ? "left" : edge === "w:bottom" ? "bottom" : "right"];
139
+ if (border === void 0) continue;
140
+ tcBorders.children.push(require_xml_fragment.el(edge, {
141
+ "w:val": DOCX_BORDER_STYLE_TO_VAL[border.style ?? "solid"],
142
+ "w:sz": String(Math.round(border.widthPt * EIGHTH_POINTS_PER_POINT)),
143
+ "w:color": (0, document_schema_js.colorToRgbHex)(border.color)
144
+ }));
145
+ }
146
+ require_xml_edit.insertInSchemaOrder(tcPr, tcBorders, TC_PR_CHILD_ORDER);
147
+ }
53
148
  paragraphs() {
54
149
  const out = [];
55
150
  for (const child of this.node.children) if (child.type === "element" && child.tag === "w:p") out.push(new require_edit_docx_paragraph.DocxParagraph(this.node.children, child));
@@ -69,11 +164,34 @@ var DocxTableRow = class {
69
164
  constructor(node) {
70
165
  this.node = node;
71
166
  }
167
+ trPrElement(create) {
168
+ const existing = require_xml_edit.directChildElement(this.node, "w:trPr");
169
+ if (existing !== void 0 || !create) return existing;
170
+ const created = require_xml_fragment.el("w:trPr");
171
+ this.node.children.unshift(created);
172
+ return created;
173
+ }
72
174
  cells() {
73
175
  const out = [];
74
176
  for (const child of this.node.children) if (child.type === "element" && child.tag === "w:tc") out.push(new DocxTableCell(child));
75
177
  return out;
76
178
  }
179
+ get heightPt() {
180
+ const trPr = this.trPrElement(false);
181
+ const trHeight = trPr === void 0 ? void 0 : require_xml_edit.directChildElement(trPr, "w:trHeight");
182
+ const val = trHeight === void 0 ? void 0 : (0, ooxml_js.attr)(trHeight, "w:val");
183
+ return val === void 0 ? void 0 : require_model_units.twipsToPt(Number(val));
184
+ }
185
+ set heightPt(value) {
186
+ const trPr = this.trPrElement(value !== void 0);
187
+ if (trPr === void 0) return;
188
+ trPr.children = trPr.children.filter((c) => !(c.type === "element" && c.tag === "w:trHeight"));
189
+ if (value === void 0) return;
190
+ trPr.children.push(require_xml_fragment.el("w:trHeight", {
191
+ "w:val": String(require_model_units.ptToTwips(value)),
192
+ "w:hRule": "atLeast"
193
+ }));
194
+ }
77
195
  mergeCellsHorizontally(startColumnIndex, colSpan) {
78
196
  if (!Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCellsHorizontally: colSpan must be a positive integer, got ${colSpan}`);
79
197
  const cellElements = [];
@@ -1,4 +1,5 @@
1
1
  import { DocxParagraph, ParagraphInit } from "./paragraph.cjs";
2
+ import { Color, ContentCellBorders } from "document-schema.js";
2
3
  import { XmlElement, XmlNode } from "ooxml.js";
3
4
  //#region src/edit/docx/table.d.ts
4
5
  interface TableInit {
@@ -15,6 +16,10 @@ declare class DocxTableCell {
15
16
  set colSpan(value: number | undefined);
16
17
  get verticalMerge(): DocxVerticalMerge | undefined;
17
18
  set verticalMerge(value: DocxVerticalMerge | undefined);
19
+ get background(): Color | undefined;
20
+ set background(value: Color | undefined);
21
+ get borders(): ContentCellBorders | undefined;
22
+ set borders(value: ContentCellBorders | undefined);
18
23
  paragraphs(): DocxParagraph[];
19
24
  appendParagraph(init?: ParagraphInit): DocxParagraph;
20
25
  get text(): string;
@@ -22,7 +27,10 @@ declare class DocxTableCell {
22
27
  declare class DocxTableRow {
23
28
  private readonly node;
24
29
  constructor(node: XmlElement);
30
+ private trPrElement;
25
31
  cells(): DocxTableCell[];
32
+ get heightPt(): number | undefined;
33
+ set heightPt(value: number | undefined);
26
34
  mergeCellsHorizontally(startColumnIndex: number, colSpan: number): DocxTableCell;
27
35
  }
28
36
  declare class DocxTable {
@@ -1,5 +1,6 @@
1
1
  import { DocxParagraph, ParagraphInit } from "./paragraph.js";
2
2
  import { XmlElement, XmlNode } from "ooxml.js";
3
+ import { Color, ContentCellBorders } from "document-schema.js";
3
4
  //#region src/edit/docx/table.d.ts
4
5
  interface TableInit {
5
6
  readonly rows: number;
@@ -15,6 +16,10 @@ declare class DocxTableCell {
15
16
  set colSpan(value: number | undefined);
16
17
  get verticalMerge(): DocxVerticalMerge | undefined;
17
18
  set verticalMerge(value: DocxVerticalMerge | undefined);
19
+ get background(): Color | undefined;
20
+ set background(value: Color | undefined);
21
+ get borders(): ContentCellBorders | undefined;
22
+ set borders(value: ContentCellBorders | undefined);
18
23
  paragraphs(): DocxParagraph[];
19
24
  appendParagraph(init?: ParagraphInit): DocxParagraph;
20
25
  get text(): string;
@@ -22,7 +27,10 @@ declare class DocxTableCell {
22
27
  declare class DocxTableRow {
23
28
  private readonly node;
24
29
  constructor(node: XmlElement);
30
+ private trPrElement;
25
31
  cells(): DocxTableCell[];
32
+ get heightPt(): number | undefined;
33
+ set heightPt(value: number | undefined);
26
34
  mergeCellsHorizontally(startColumnIndex: number, colSpan: number): DocxTableCell;
27
35
  }
28
36
  declare class DocxTable {