@js-ak/excel-toolbox 1.8.3 → 1.9.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 (207) hide show
  1. package/build/cjs/lib/template/template-fs.js +2 -1
  2. package/build/cjs/lib/template/template-memory.js +2 -1
  3. package/build/cjs/lib/template/utils/column-letter-to-index.js +15 -0
  4. package/build/cjs/lib/template/utils/index.js +1 -1
  5. package/build/cjs/lib/template/utils/prepare-row-to-cells.js +2 -2
  6. package/build/cjs/lib/template/utils/validate-worksheet-xml.js +19 -9
  7. package/build/cjs/lib/utils/index.js +2 -0
  8. package/build/cjs/lib/utils/trim-and-join-multiline.js +32 -0
  9. package/build/cjs/lib/workbook-builder/default/border.js +18 -0
  10. package/build/cjs/lib/workbook-builder/default/cell-xf.js +15 -0
  11. package/build/cjs/lib/workbook-builder/default/fill.js +18 -0
  12. package/build/cjs/lib/workbook-builder/default/font.js +19 -0
  13. package/build/cjs/lib/workbook-builder/default/index.js +21 -0
  14. package/build/cjs/lib/workbook-builder/default/sheet-name.js +10 -0
  15. package/build/cjs/lib/workbook-builder/index.js +18 -0
  16. package/build/cjs/lib/workbook-builder/merge-cells/add.js +72 -0
  17. package/build/cjs/lib/workbook-builder/merge-cells/helpers/index.js +18 -0
  18. package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +17 -0
  19. package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +17 -0
  20. package/build/cjs/lib/workbook-builder/merge-cells/index.js +18 -0
  21. package/build/cjs/lib/workbook-builder/merge-cells/remove.js +60 -0
  22. package/build/cjs/lib/workbook-builder/shared-string-ref/add.js +24 -0
  23. package/build/cjs/lib/workbook-builder/shared-string-ref/index.js +19 -0
  24. package/build/cjs/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +66 -0
  25. package/build/cjs/lib/workbook-builder/shared-string-ref/remove.js +66 -0
  26. package/build/cjs/lib/workbook-builder/style-ref/add-or-get.js +94 -0
  27. package/build/cjs/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +25 -0
  28. package/build/cjs/lib/workbook-builder/style-ref/helpers/border-to-xml.js +49 -0
  29. package/build/cjs/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +51 -0
  30. package/build/cjs/lib/workbook-builder/style-ref/helpers/font-to-xml.js +112 -0
  31. package/build/cjs/lib/workbook-builder/style-ref/helpers/index.js +21 -0
  32. package/build/cjs/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +30 -0
  33. package/build/cjs/lib/workbook-builder/style-ref/index.js +19 -0
  34. package/build/cjs/lib/workbook-builder/style-ref/remove-all-from-sheet.js +26 -0
  35. package/build/cjs/lib/workbook-builder/style-ref/remove.js +52 -0
  36. package/build/cjs/lib/workbook-builder/types/app-xml-options.js +2 -0
  37. package/build/cjs/lib/workbook-builder/types/border-style.js +2 -0
  38. package/build/cjs/lib/workbook-builder/types/cell-data.js +2 -0
  39. package/build/cjs/lib/workbook-builder/types/cell-style.js +2 -0
  40. package/build/cjs/lib/workbook-builder/types/cell-type.js +2 -0
  41. package/build/cjs/lib/workbook-builder/types/cell-value.js +2 -0
  42. package/build/cjs/lib/workbook-builder/types/cell-xf.js +2 -0
  43. package/build/cjs/lib/workbook-builder/types/index.js +27 -0
  44. package/build/cjs/lib/workbook-builder/types/merge-cell.js +2 -0
  45. package/build/cjs/lib/workbook-builder/types/row-data.js +2 -0
  46. package/build/cjs/lib/workbook-builder/types/sheet-data.js +2 -0
  47. package/build/cjs/lib/workbook-builder/types/xml-node.js +2 -0
  48. package/build/cjs/lib/workbook-builder/utils/build-app-xml.js +51 -0
  49. package/build/cjs/lib/workbook-builder/utils/build-cell-children.js +59 -0
  50. package/build/cjs/lib/workbook-builder/utils/build-content-types-xml.js +42 -0
  51. package/build/cjs/lib/workbook-builder/utils/build-core-xml.js +27 -0
  52. package/build/cjs/lib/workbook-builder/utils/build-rels-xml.js +19 -0
  53. package/build/cjs/lib/workbook-builder/utils/build-shared-strings-xml.js +39 -0
  54. package/build/cjs/lib/workbook-builder/utils/build-styles-xml.js +178 -0
  55. package/build/cjs/lib/workbook-builder/utils/build-theme-xml.js +609 -0
  56. package/build/cjs/lib/workbook-builder/utils/build-workbook-rels-xml.js +58 -0
  57. package/build/cjs/lib/workbook-builder/utils/build-workbook-xml.js +26 -0
  58. package/build/cjs/lib/workbook-builder/utils/build-worksheet-xml.js +66 -0
  59. package/build/cjs/lib/workbook-builder/utils/build-xml.js +72 -0
  60. package/build/cjs/lib/workbook-builder/utils/constants.js +55 -0
  61. package/build/cjs/lib/workbook-builder/utils/date-to-excel-serial.js +16 -0
  62. package/build/cjs/lib/workbook-builder/utils/index.js +34 -0
  63. package/build/cjs/lib/workbook-builder/utils/initialize-files.js +40 -0
  64. package/build/cjs/lib/workbook-builder/utils/sheet.js +144 -0
  65. package/build/cjs/lib/workbook-builder/utils/write-shared-strings-xml.js +49 -0
  66. package/build/cjs/lib/workbook-builder/utils/write-styles-xml.js +196 -0
  67. package/build/cjs/lib/workbook-builder/utils/write-worksheet-xml.js +209 -0
  68. package/build/cjs/lib/workbook-builder/utils/write-xml.js +37 -0
  69. package/build/cjs/lib/workbook-builder/workbook-builder.js +414 -0
  70. package/build/esm/lib/template/template-fs.js +2 -1
  71. package/build/esm/lib/template/template-memory.js +2 -1
  72. package/build/esm/lib/template/utils/column-letter-to-index.js +12 -0
  73. package/build/esm/lib/template/utils/index.js +1 -1
  74. package/build/esm/lib/template/utils/prepare-row-to-cells.js +1 -1
  75. package/build/esm/lib/template/utils/validate-worksheet-xml.js +19 -9
  76. package/build/esm/lib/utils/index.js +2 -0
  77. package/build/esm/lib/utils/trim-and-join-multiline.js +29 -0
  78. package/build/esm/lib/workbook-builder/default/border.js +14 -0
  79. package/build/esm/lib/workbook-builder/default/cell-xf.js +11 -0
  80. package/build/esm/lib/workbook-builder/default/fill.js +14 -0
  81. package/build/esm/lib/workbook-builder/default/font.js +15 -0
  82. package/build/esm/lib/workbook-builder/default/index.js +5 -0
  83. package/build/esm/lib/workbook-builder/default/sheet-name.js +6 -0
  84. package/build/esm/lib/workbook-builder/index.js +2 -0
  85. package/build/esm/lib/workbook-builder/merge-cells/add.js +36 -0
  86. package/build/esm/lib/workbook-builder/merge-cells/helpers/index.js +2 -0
  87. package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +14 -0
  88. package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +14 -0
  89. package/build/esm/lib/workbook-builder/merge-cells/index.js +2 -0
  90. package/build/esm/lib/workbook-builder/merge-cells/remove.js +24 -0
  91. package/build/esm/lib/workbook-builder/shared-string-ref/add.js +21 -0
  92. package/build/esm/lib/workbook-builder/shared-string-ref/index.js +3 -0
  93. package/build/esm/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +63 -0
  94. package/build/esm/lib/workbook-builder/shared-string-ref/remove.js +63 -0
  95. package/build/esm/lib/workbook-builder/style-ref/add-or-get.js +58 -0
  96. package/build/esm/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +21 -0
  97. package/build/esm/lib/workbook-builder/style-ref/helpers/border-to-xml.js +45 -0
  98. package/build/esm/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +47 -0
  99. package/build/esm/lib/workbook-builder/style-ref/helpers/font-to-xml.js +75 -0
  100. package/build/esm/lib/workbook-builder/style-ref/helpers/index.js +5 -0
  101. package/build/esm/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +26 -0
  102. package/build/esm/lib/workbook-builder/style-ref/index.js +3 -0
  103. package/build/esm/lib/workbook-builder/style-ref/remove-all-from-sheet.js +23 -0
  104. package/build/esm/lib/workbook-builder/style-ref/remove.js +49 -0
  105. package/build/esm/lib/workbook-builder/types/app-xml-options.js +1 -0
  106. package/build/esm/lib/workbook-builder/types/border-style.js +1 -0
  107. package/build/esm/lib/workbook-builder/types/cell-data.js +1 -0
  108. package/build/esm/lib/workbook-builder/types/cell-style.js +1 -0
  109. package/build/esm/lib/workbook-builder/types/cell-type.js +1 -0
  110. package/build/esm/lib/workbook-builder/types/cell-value.js +1 -0
  111. package/build/esm/lib/workbook-builder/types/cell-xf.js +1 -0
  112. package/build/esm/lib/workbook-builder/types/index.js +11 -0
  113. package/build/esm/lib/workbook-builder/types/merge-cell.js +1 -0
  114. package/build/esm/lib/workbook-builder/types/row-data.js +1 -0
  115. package/build/esm/lib/workbook-builder/types/sheet-data.js +1 -0
  116. package/build/esm/lib/workbook-builder/types/xml-node.js +1 -0
  117. package/build/esm/lib/workbook-builder/utils/build-app-xml.js +48 -0
  118. package/build/esm/lib/workbook-builder/utils/build-cell-children.js +56 -0
  119. package/build/esm/lib/workbook-builder/utils/build-content-types-xml.js +39 -0
  120. package/build/esm/lib/workbook-builder/utils/build-core-xml.js +24 -0
  121. package/build/esm/lib/workbook-builder/utils/build-rels-xml.js +16 -0
  122. package/build/esm/lib/workbook-builder/utils/build-shared-strings-xml.js +36 -0
  123. package/build/esm/lib/workbook-builder/utils/build-styles-xml.js +142 -0
  124. package/build/esm/lib/workbook-builder/utils/build-theme-xml.js +606 -0
  125. package/build/esm/lib/workbook-builder/utils/build-workbook-rels-xml.js +55 -0
  126. package/build/esm/lib/workbook-builder/utils/build-workbook-xml.js +23 -0
  127. package/build/esm/lib/workbook-builder/utils/build-worksheet-xml.js +63 -0
  128. package/build/esm/lib/workbook-builder/utils/build-xml.js +69 -0
  129. package/build/esm/lib/workbook-builder/utils/constants.js +52 -0
  130. package/build/esm/lib/workbook-builder/utils/date-to-excel-serial.js +13 -0
  131. package/build/esm/lib/workbook-builder/utils/index.js +18 -0
  132. package/build/esm/lib/workbook-builder/utils/initialize-files.js +36 -0
  133. package/build/esm/lib/workbook-builder/utils/sheet.js +141 -0
  134. package/build/esm/lib/workbook-builder/utils/write-shared-strings-xml.js +43 -0
  135. package/build/esm/lib/workbook-builder/utils/write-styles-xml.js +157 -0
  136. package/build/esm/lib/workbook-builder/utils/write-worksheet-xml.js +203 -0
  137. package/build/esm/lib/workbook-builder/utils/write-xml.js +34 -0
  138. package/build/esm/lib/workbook-builder/workbook-builder.js +374 -0
  139. package/build/types/lib/template/utils/column-letter-to-index.d.ts +1 -0
  140. package/build/types/lib/template/utils/index.d.ts +1 -1
  141. package/build/types/lib/utils/index.d.ts +2 -0
  142. package/build/types/lib/utils/trim-and-join-multiline.d.ts +23 -0
  143. package/build/types/lib/workbook-builder/default/border.d.ts +7 -0
  144. package/build/types/lib/workbook-builder/default/cell-xf.d.ts +7 -0
  145. package/build/types/lib/workbook-builder/default/fill.d.ts +7 -0
  146. package/build/types/lib/workbook-builder/default/font.d.ts +21 -0
  147. package/build/types/lib/workbook-builder/default/index.d.ts +5 -0
  148. package/build/types/lib/workbook-builder/default/sheet-name.d.ts +6 -0
  149. package/build/types/lib/workbook-builder/index.d.ts +2 -0
  150. package/build/types/lib/workbook-builder/merge-cells/add.d.ts +15 -0
  151. package/build/types/lib/workbook-builder/merge-cells/helpers/index.d.ts +2 -0
  152. package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-equal.d.ts +10 -0
  153. package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-intersect.d.ts +10 -0
  154. package/build/types/lib/workbook-builder/merge-cells/index.d.ts +2 -0
  155. package/build/types/lib/workbook-builder/merge-cells/remove.d.ts +15 -0
  156. package/build/types/lib/workbook-builder/shared-string-ref/add.d.ts +13 -0
  157. package/build/types/lib/workbook-builder/shared-string-ref/index.d.ts +3 -0
  158. package/build/types/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.d.ts +10 -0
  159. package/build/types/lib/workbook-builder/shared-string-ref/remove.d.ts +13 -0
  160. package/build/types/lib/workbook-builder/style-ref/add-or-get.d.ts +16 -0
  161. package/build/types/lib/workbook-builder/style-ref/helpers/add-num-fmt.d.ts +17 -0
  162. package/build/types/lib/workbook-builder/style-ref/helpers/border-to-xml.d.ts +16 -0
  163. package/build/types/lib/workbook-builder/style-ref/helpers/fill-to-xml.d.ts +17 -0
  164. package/build/types/lib/workbook-builder/style-ref/helpers/font-to-xml.d.ts +18 -0
  165. package/build/types/lib/workbook-builder/style-ref/helpers/index.d.ts +5 -0
  166. package/build/types/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.d.ts +15 -0
  167. package/build/types/lib/workbook-builder/style-ref/index.d.ts +3 -0
  168. package/build/types/lib/workbook-builder/style-ref/remove-all-from-sheet.d.ts +4 -0
  169. package/build/types/lib/workbook-builder/style-ref/remove.d.ts +18 -0
  170. package/build/types/lib/workbook-builder/types/app-xml-options.d.ts +9 -0
  171. package/build/types/lib/workbook-builder/types/border-style.d.ts +5 -0
  172. package/build/types/lib/workbook-builder/types/cell-data.d.ts +10 -0
  173. package/build/types/lib/workbook-builder/types/cell-style.d.ts +32 -0
  174. package/build/types/lib/workbook-builder/types/cell-type.d.ts +11 -0
  175. package/build/types/lib/workbook-builder/types/cell-value.d.ts +2 -0
  176. package/build/types/lib/workbook-builder/types/cell-xf.d.ts +13 -0
  177. package/build/types/lib/workbook-builder/types/index.d.ts +11 -0
  178. package/build/types/lib/workbook-builder/types/merge-cell.d.ts +6 -0
  179. package/build/types/lib/workbook-builder/types/row-data.d.ts +5 -0
  180. package/build/types/lib/workbook-builder/types/sheet-data.d.ts +13 -0
  181. package/build/types/lib/workbook-builder/types/xml-node.d.ts +11 -0
  182. package/build/types/lib/workbook-builder/utils/build-app-xml.d.ts +2 -0
  183. package/build/types/lib/workbook-builder/utils/build-cell-children.d.ts +9 -0
  184. package/build/types/lib/workbook-builder/utils/build-content-types-xml.d.ts +1 -0
  185. package/build/types/lib/workbook-builder/utils/build-core-xml.d.ts +1 -0
  186. package/build/types/lib/workbook-builder/utils/build-rels-xml.d.ts +1 -0
  187. package/build/types/lib/workbook-builder/utils/build-shared-strings-xml.d.ts +10 -0
  188. package/build/types/lib/workbook-builder/utils/build-styles-xml.d.ts +23 -0
  189. package/build/types/lib/workbook-builder/utils/build-theme-xml.d.ts +1 -0
  190. package/build/types/lib/workbook-builder/utils/build-workbook-rels-xml.d.ts +9 -0
  191. package/build/types/lib/workbook-builder/utils/build-workbook-xml.d.ts +3 -0
  192. package/build/types/lib/workbook-builder/utils/build-worksheet-xml.d.ts +2 -0
  193. package/build/types/lib/workbook-builder/utils/build-xml.d.ts +50 -0
  194. package/build/types/lib/workbook-builder/utils/constants.d.ts +47 -0
  195. package/build/types/lib/workbook-builder/utils/date-to-excel-serial.d.ts +9 -0
  196. package/build/types/lib/workbook-builder/utils/index.d.ts +18 -0
  197. package/build/types/lib/workbook-builder/utils/initialize-files.d.ts +13 -0
  198. package/build/types/lib/workbook-builder/utils/sheet.d.ts +21 -0
  199. package/build/types/lib/workbook-builder/utils/write-shared-strings-xml.d.ts +11 -0
  200. package/build/types/lib/workbook-builder/utils/write-styles-xml.d.ts +24 -0
  201. package/build/types/lib/workbook-builder/utils/write-worksheet-xml.d.ts +14 -0
  202. package/build/types/lib/workbook-builder/utils/write-xml.d.ts +3 -0
  203. package/build/types/lib/workbook-builder/workbook-builder.d.ts +110 -0
  204. package/package.json +1 -1
  205. /package/build/cjs/lib/{template/utils → utils}/escape-xml.js +0 -0
  206. /package/build/esm/lib/{template/utils → utils}/escape-xml.js +0 -0
  207. /package/build/types/lib/{template/utils → utils}/escape-xml.d.ts +0 -0
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remove = remove;
4
+ /**
5
+ * Removes a shared string reference for a specific sheet and cleans up if unused.
6
+ *
7
+ * @param this - WorkbookBuilder instance
8
+ * @param payload - Object containing sheet name and string index to remove
9
+ *
10
+ * @returns True if the reference was successfully removed, false if string or reference not found
11
+ */
12
+ function remove(payload) {
13
+ const { sheetName, strIdx } = payload;
14
+ if (!this.getSheet(sheetName)) {
15
+ throw new Error(`Sheet not found: ${sheetName}`);
16
+ }
17
+ const str = this.sharedStrings[strIdx];
18
+ if (!str) {
19
+ throw new Error(`String not found: ${strIdx}`);
20
+ }
21
+ return true;
22
+ // const refs = this.sharedStringRefs.get(str);
23
+ // if (!refs || !refs.has(sheetName)) {
24
+ // return false;
25
+ // }
26
+ // refs.delete(sheetName);
27
+ // if (refs.size === 0) {
28
+ // // Build map of old indices → new indices before removal
29
+ // const oldToNew = new Map<number, number>();
30
+ // for (let i = 0; i < this.sharedStrings.length; i++) {
31
+ // if (i < strIdx) {
32
+ // oldToNew.set(i, i);
33
+ // } else if (i > strIdx) {
34
+ // oldToNew.set(i, i - 1);
35
+ // }
36
+ // // i === strIdx — this string will be removed, no index
37
+ // }
38
+ // // Remove string from array and refs
39
+ // this.sharedStrings.splice(strIdx, 1);
40
+ // this.sharedStringMap.delete(str);
41
+ // this.sharedStringRefs.delete(str);
42
+ // // Update sharedStringMap with new indices
43
+ // for (let i = 0; i < this.sharedStrings.length; i++) {
44
+ // const str = this.sharedStrings[i];
45
+ // if (str) {
46
+ // this.sharedStringMap.set(str, i);
47
+ // }
48
+ // }
49
+ // // Update indices across all sheets
50
+ // for (const sheet of this.sheets.values()) {
51
+ // for (const row of sheet.rows.values()) {
52
+ // for (const cell of row.cells.values()) {
53
+ // if (cell.type === "s" && typeof cell.value === "number") {
54
+ // const newIdx = oldToNew.get(cell.value);
55
+ // if (newIdx !== undefined) {
56
+ // cell.value = newIdx;
57
+ // } else {
58
+ // // Just in case, if cell.value was a removed string
59
+ // cell.value = 0; // or null, according to your application logic
60
+ // }
61
+ // }
62
+ // }
63
+ // }
64
+ // }
65
+ // }
66
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.addOrGet = addOrGet;
37
+ const Helpers = __importStar(require("./helpers/index.js"));
38
+ /**
39
+ * Adds a new cell style to the workbook or returns the index of an existing identical style.
40
+ * This function manages style deduplication by checking if an identical style already exists
41
+ * before creating a new one.
42
+ *
43
+ * @param this - The WorkbookBuilder instance
44
+ * @param payload - Object containing the style to add or get
45
+ * @param payload.style - The cell style configuration
46
+ *
47
+ * @returns The index of the style in the cellXfs array
48
+ */
49
+ function addOrGet(payload) {
50
+ const { style } = payload;
51
+ // Convert each style component to XML and get their IDs using Map-backed de-duplication
52
+ const fontXml = Helpers.fontToXml({ existingFonts: this.fonts, font: style.font });
53
+ const fontKey = JSON.stringify(fontXml);
54
+ let fontId = this.fontsMap.get(fontKey);
55
+ if (fontId === undefined) {
56
+ fontId = this.fonts.length;
57
+ this.fonts.push(fontXml);
58
+ this.fontsMap.set(fontKey, fontId);
59
+ }
60
+ const fillXml = Helpers.fillToXml({ existingFills: this.fills, fill: style.fill });
61
+ const fillKey = JSON.stringify(fillXml);
62
+ let fillId = this.fillsMap.get(fillKey);
63
+ if (fillId === undefined) {
64
+ fillId = this.fills.length;
65
+ this.fills.push(fillXml);
66
+ this.fillsMap.set(fillKey, fillId);
67
+ }
68
+ const borderXml = Helpers.borderToXml({ border: style.border, existingBorders: this.borders });
69
+ const borderKey = JSON.stringify(borderXml);
70
+ let borderId = this.bordersMap.get(borderKey);
71
+ if (borderId === undefined) {
72
+ borderId = this.borders.length;
73
+ this.borders.push(borderXml);
74
+ this.bordersMap.set(borderKey, borderId);
75
+ }
76
+ const numFmtId = style.numberFormat
77
+ ? Helpers.addNumFmt({ formatCode: style.numberFormat, numFmts: this.numFmts })
78
+ : 0;
79
+ const xf = {
80
+ alignment: style.alignment,
81
+ borderId,
82
+ fillId,
83
+ fontId,
84
+ numFmtId,
85
+ };
86
+ const xfKey = JSON.stringify(xf);
87
+ if (this.styleMap.has(xfKey)) {
88
+ return this.styleMap.get(xfKey);
89
+ }
90
+ const index = this.cellXfs.length;
91
+ this.cellXfs.push(xf);
92
+ this.styleMap.set(xfKey, index);
93
+ return index;
94
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addNumFmt = void 0;
4
+ /**
5
+ * Adds a custom number format to the collection or returns the existing id.
6
+ *
7
+ * Excel reserves built-in ids below 164; custom formats start from 164.
8
+ *
9
+ * @param payload - Input arguments
10
+ * @param payload.formatCode - Format code, e.g., "0.00" or "dd/mm/yyyy"
11
+ * @param payload.numFmts - Mutable list of custom formats to search/extend
12
+ * @returns Numeric id of the number format
13
+ */
14
+ const addNumFmt = (payload) => {
15
+ const { formatCode, numFmts } = payload;
16
+ // 164+ is reserved for custom formats
17
+ const existing = numFmts.find(nf => nf.formatCode === formatCode);
18
+ if (existing) {
19
+ return existing.id;
20
+ }
21
+ const id = 164 + numFmts.length;
22
+ numFmts.push({ formatCode, id });
23
+ return id;
24
+ };
25
+ exports.addNumFmt = addNumFmt;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.borderToXml = void 0;
4
+ /**
5
+ * Builds an XmlNode representing a <border> element based on the provided CellStyle.
6
+ *
7
+ * If no border is provided, the first existing border is returned (assumed default).
8
+ * Color values beginning with # are converted to RGB without the leading hash, as expected by Excel.
9
+ *
10
+ * @param payload - Input arguments
11
+ * @param payload.border - Optional border style from the cell style
12
+ * @param payload.existingBorders - Existing borders collection to fall back to
13
+ * @returns XmlNode representing a <border> element
14
+ */
15
+ const borderToXml = (payload) => {
16
+ const { border, existingBorders } = payload;
17
+ if (!existingBorders?.length) {
18
+ throw new Error("existingBorders is empty");
19
+ }
20
+ if (!border) {
21
+ return existingBorders[0];
22
+ }
23
+ const children = [];
24
+ for (const side of ["left", "right", "top", "bottom"]) {
25
+ const b = border?.[side];
26
+ if (b) {
27
+ const attrs = { style: b.style };
28
+ const sideChildren = b.color
29
+ ? [{
30
+ attrs: { rgb: b.color.replace(/^#/, "") },
31
+ tag: "color",
32
+ }]
33
+ : [];
34
+ children.push({
35
+ attrs,
36
+ children: sideChildren,
37
+ tag: side,
38
+ });
39
+ }
40
+ else {
41
+ children.push({ tag: side });
42
+ }
43
+ }
44
+ return {
45
+ children,
46
+ tag: "border",
47
+ };
48
+ };
49
+ exports.borderToXml = borderToXml;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fillToXml = void 0;
4
+ /**
5
+ * Builds an XmlNode representing a <fill> element based on the provided CellStyle.
6
+ *
7
+ * If no fill is provided, the first existing fill is returned (assumed default).
8
+ * Foreground/background colors may include a leading '#', which is removed to
9
+ * match Excel's expected RGB format.
10
+ *
11
+ * @param payload - Input arguments
12
+ * @param payload.existingFills - Existing fills collection to fall back to
13
+ * @param payload.fill - Optional fill from the cell style
14
+ * @returns XmlNode representing a <fill> element
15
+ */
16
+ const fillToXml = (payload) => {
17
+ const { existingFills, fill } = payload;
18
+ if (!existingFills?.length) {
19
+ throw new Error("existingFills is empty");
20
+ }
21
+ if (!fill)
22
+ return existingFills[0];
23
+ const patternType = fill.patternType ?? "solid";
24
+ const children = [];
25
+ const attrs = { patternType };
26
+ const fillChildren = [];
27
+ if (fill.fgColor) {
28
+ const colorVal = fill.fgColor.startsWith("#") ? fill.fgColor.slice(1) : fill.fgColor;
29
+ fillChildren.push({
30
+ attrs: { rgb: colorVal },
31
+ tag: "fgColor",
32
+ });
33
+ }
34
+ if (fill.bgColor) {
35
+ const colorVal = fill.bgColor.startsWith("#") ? fill.bgColor.slice(1) : fill.bgColor;
36
+ fillChildren.push({
37
+ attrs: { rgb: colorVal },
38
+ tag: "bgColor",
39
+ });
40
+ }
41
+ children.push({
42
+ attrs,
43
+ children: fillChildren,
44
+ tag: "patternFill",
45
+ });
46
+ return {
47
+ children,
48
+ tag: "fill",
49
+ };
50
+ };
51
+ exports.fillToXml = fillToXml;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.fontToXml = void 0;
37
+ const Default = __importStar(require("../../default/index.js"));
38
+ /**
39
+ * Builds an XmlNode representing a <font> element based on the provided CellStyle.
40
+ *
41
+ * If no font is provided, returns the default font from the template. Color
42
+ * values may include a leading '#'. Six-digit RGB values are prefixed with
43
+ * 'FF' (alpha) to form ARGB; eight-digit values are used as-is. Throws for
44
+ * invalid color lengths.
45
+ *
46
+ * @param payload - Input arguments
47
+ * @param payload.existingFonts - Existing fonts collection (not used directly; kept for parity)
48
+ * @param payload.font - Optional font from the cell style
49
+ * @returns XmlNode representing a <font> element
50
+ */
51
+ const fontToXml = (payload) => {
52
+ const { existingFonts, font } = payload;
53
+ if (!existingFonts?.length) {
54
+ throw new Error("existingFonts is empty");
55
+ }
56
+ // Default values
57
+ const defaultFont = Default.font();
58
+ if (!font) {
59
+ // If no font style provided — return default font (as in Excel template)
60
+ return defaultFont;
61
+ }
62
+ const children = [];
63
+ // Size is always present
64
+ children.push({
65
+ attrs: { val: String(font.size ?? defaultFont.children.at(0)?.attrs.val) },
66
+ tag: "sz",
67
+ });
68
+ // Color (if provided) otherwise default
69
+ if (font.color) {
70
+ const colorVal = font.color.startsWith("#") ? font.color.slice(1) : font.color;
71
+ if (colorVal.length === 6) {
72
+ children.push({
73
+ attrs: { rgb: "FF" + colorVal.toUpperCase() },
74
+ tag: "color",
75
+ });
76
+ }
77
+ else if (colorVal.length === 8) {
78
+ children.push({
79
+ attrs: { rgb: colorVal.toUpperCase() },
80
+ tag: "color",
81
+ });
82
+ }
83
+ else {
84
+ throw new Error(`Invalid font color: ${font.color}`);
85
+ }
86
+ }
87
+ else {
88
+ children.push(defaultFont.children.at(1));
89
+ }
90
+ // Font name (required)
91
+ children.push({
92
+ attrs: { val: font.name ?? defaultFont.children.at(2)?.attrs.val },
93
+ tag: "name",
94
+ });
95
+ // Additional attributes
96
+ if (font.bold)
97
+ children.push({ tag: "b" });
98
+ if (font.italic)
99
+ children.push({ tag: "i" });
100
+ if (font.underline) {
101
+ const val = font.underline === true ? "single" : font.underline;
102
+ children.push({
103
+ attrs: { val },
104
+ tag: "u",
105
+ });
106
+ }
107
+ return {
108
+ children,
109
+ tag: "font",
110
+ };
111
+ };
112
+ exports.fontToXml = fontToXml;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./add-num-fmt.js"), exports);
18
+ __exportStar(require("./border-to-xml.js"), exports);
19
+ __exportStar(require("./fill-to-xml.js"), exports);
20
+ __exportStar(require("./font-to-xml.js"), exports);
21
+ __exportStar(require("./reindex-style-map-after-removal.js"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reindexStyleMapAfterRemoval = void 0;
4
+ /**
5
+ * Reindexes a style map in-place after removing a style at a given index.
6
+ *
7
+ * - Deletes entries that point to the removed index
8
+ * - Decrements by 1 all indices greater than the removed index
9
+ *
10
+ * @param payload - Input arguments
11
+ * @param payload.removedIndex - The style index that was removed
12
+ * @param payload.styleMap - Map of serialized style key to style index
13
+ * @returns void
14
+ */
15
+ const reindexStyleMapAfterRemoval = (payload) => {
16
+ const { removedIndex, styleMap } = payload;
17
+ const updates = [];
18
+ for (const [key, idx] of styleMap.entries()) {
19
+ if (idx === removedIndex) {
20
+ styleMap.delete(key);
21
+ }
22
+ else if (idx > removedIndex) {
23
+ updates.push([key, idx - 1]);
24
+ }
25
+ }
26
+ for (const [key, newIdx] of updates) {
27
+ styleMap.set(key, newIdx);
28
+ }
29
+ };
30
+ exports.reindexStyleMapAfterRemoval = reindexStyleMapAfterRemoval;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./add-or-get.js"), exports);
18
+ __exportStar(require("./remove-all-from-sheet.js"), exports);
19
+ __exportStar(require("./remove.js"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeAllFromSheet = removeAllFromSheet;
4
+ const remove_js_1 = require("./remove.js");
5
+ function removeAllFromSheet(payload) {
6
+ const { sheetName } = payload;
7
+ const sheet = this.sheets.get(sheetName);
8
+ if (!sheet)
9
+ return false;
10
+ const stylesToRemove = [];
11
+ let removedSomething = false;
12
+ for (const row of sheet.rows.values()) {
13
+ for (const cell of row.cells.values()) {
14
+ if (cell.style?.index !== undefined) {
15
+ stylesToRemove.push(cell.style);
16
+ }
17
+ }
18
+ }
19
+ for (const style of stylesToRemove) {
20
+ const removed = remove_js_1.remove.bind(this)({ style });
21
+ if (removed) {
22
+ removedSomething = true;
23
+ }
24
+ }
25
+ return removedSomething;
26
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remove = remove;
4
+ // import * as Helpers from "./helpers/index.js";
5
+ /**
6
+ * Validates a cell style index and checks if the style exists in the workbook.
7
+ * This function performs validation checks on the provided style index and
8
+ * verifies that the style exists at the given index in the cellXfs array.
9
+ *
10
+ * @param this - The WorkbookBuilder instance
11
+ * @param payload - Object containing the style to validate
12
+ * @param payload.style - The cell style configuration with index
13
+ *
14
+ * @returns True if the style index is valid and the style exists
15
+ *
16
+ * @throws {Error} When styleIndex is invalid (not a number) or when style doesn't exist at the given index
17
+ */
18
+ function remove(payload) {
19
+ const { style } = payload;
20
+ const styleIndex = style.index;
21
+ if (typeof styleIndex !== "number") {
22
+ throw new Error("Invalid styleIndex: not a number");
23
+ }
24
+ if (styleIndex === 0) {
25
+ throw new Error("Invalid styleIndex: 0 is the default style and cannot be removed");
26
+ }
27
+ const xf = this.cellXfs[styleIndex];
28
+ if (!xf) {
29
+ throw new Error(`Invalid styleIndex: style not found at index ${styleIndex}`);
30
+ }
31
+ return true;
32
+ // let removedSomething = false;
33
+ // // Get style parts before splice - indices are still valid
34
+ // const xf = this.cellXfs[styleIndex];
35
+ // if (xf) {
36
+ // this.cellXfs.splice(styleIndex, 1);
37
+ // // Fix: reindex styleMap after splice
38
+ // Helpers.reindexStyleMapAfterRemoval({ removedIndex: styleIndex, styleMap: this.styleMap });
39
+ // // Reindex style references in cells across all sheets
40
+ // for (const sheet of this.sheets.values()) {
41
+ // for (const row of sheet.rows.values()) {
42
+ // for (const cell of row.cells.values()) {
43
+ // if (cell.style?.index !== undefined && cell.style.index > styleIndex) {
44
+ // cell.style.index -= 1;
45
+ // }
46
+ // }
47
+ // }
48
+ // }
49
+ // removedSomething = true;
50
+ // }
51
+ // return removedSomething;
52
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./app-xml-options.js"), exports);
18
+ __exportStar(require("./border-style.js"), exports);
19
+ __exportStar(require("./cell-data.js"), exports);
20
+ __exportStar(require("./cell-style.js"), exports);
21
+ __exportStar(require("./cell-type.js"), exports);
22
+ __exportStar(require("./cell-value.js"), exports);
23
+ __exportStar(require("./cell-xf.js"), exports);
24
+ __exportStar(require("./merge-cell.js"), exports);
25
+ __exportStar(require("./row-data.js"), exports);
26
+ __exportStar(require("./sheet-data.js"), exports);
27
+ __exportStar(require("./xml-node.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });