@cj-tech-master/excelts 9.2.1 → 9.3.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 (383) hide show
  1. package/README.md +25 -2
  2. package/README_zh.md +29 -6
  3. package/dist/browser/index.browser.d.ts +1 -1
  4. package/dist/browser/index.browser.js +4 -0
  5. package/dist/browser/index.d.ts +1 -1
  6. package/dist/browser/index.js +4 -0
  7. package/dist/browser/modules/excel/cell.d.ts +17 -3
  8. package/dist/browser/modules/excel/cell.js +170 -22
  9. package/dist/browser/modules/excel/defined-names.d.ts +96 -1
  10. package/dist/browser/modules/excel/defined-names.js +411 -21
  11. package/dist/browser/modules/excel/image.d.ts +11 -0
  12. package/dist/browser/modules/excel/image.js +24 -1
  13. package/dist/browser/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
  14. package/dist/browser/modules/excel/stream/workbook-reader.browser.js +14 -0
  15. package/dist/browser/modules/excel/stream/workbook-reader.d.ts +2 -1
  16. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
  17. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +48 -1
  18. package/dist/browser/modules/excel/stream/workbook-writer.d.ts +3 -2
  19. package/dist/browser/modules/excel/stream/worksheet-reader.js +17 -1
  20. package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +39 -6
  21. package/dist/browser/modules/excel/stream/worksheet-writer.js +45 -5
  22. package/dist/browser/modules/excel/table.js +15 -2
  23. package/dist/browser/modules/excel/types.d.ts +133 -2
  24. package/dist/browser/modules/excel/utils/col-cache.d.ts +1 -0
  25. package/dist/browser/modules/excel/utils/col-cache.js +15 -0
  26. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +3 -3
  27. package/dist/browser/modules/excel/utils/drawing-utils.js +4 -0
  28. package/dist/browser/modules/excel/utils/external-link-formula.d.ts +76 -0
  29. package/dist/browser/modules/excel/utils/external-link-formula.js +208 -0
  30. package/dist/browser/modules/excel/utils/iterate-stream.d.ts +9 -3
  31. package/dist/browser/modules/excel/utils/iterate-stream.js +3 -1
  32. package/dist/browser/modules/excel/utils/ooxml-paths.d.ts +19 -0
  33. package/dist/browser/modules/excel/utils/ooxml-paths.js +37 -2
  34. package/dist/browser/modules/excel/utils/shared-strings.d.ts +8 -3
  35. package/dist/browser/modules/excel/utils/shared-strings.js +21 -2
  36. package/dist/browser/modules/excel/utils/workbook-protection.d.ts +30 -0
  37. package/dist/browser/modules/excel/utils/workbook-protection.js +30 -0
  38. package/dist/browser/modules/excel/workbook.browser.d.ts +257 -6
  39. package/dist/browser/modules/excel/workbook.browser.js +318 -34
  40. package/dist/browser/modules/excel/workbook.d.ts +1 -1
  41. package/dist/browser/modules/excel/worksheet.d.ts +3 -1
  42. package/dist/browser/modules/excel/worksheet.js +21 -2
  43. package/dist/browser/modules/excel/xlsx/rel-type.d.ts +15 -0
  44. package/dist/browser/modules/excel/xlsx/rel-type.js +16 -1
  45. package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
  46. package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  47. package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
  48. package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
  49. package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
  50. package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
  51. package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
  52. package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  53. package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
  54. package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
  55. package/dist/browser/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  56. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
  57. package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
  58. package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
  59. package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
  60. package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
  61. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  62. package/dist/browser/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  63. package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
  64. package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  65. package/dist/browser/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  66. package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
  67. package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
  68. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  69. package/dist/browser/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  70. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
  71. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +410 -20
  72. package/dist/browser/modules/excel/xlsx/xlsx.d.ts +7 -4
  73. package/dist/browser/modules/excel/xlsx/xlsx.js +4 -5
  74. package/dist/browser/modules/formula/compile/address-utils.d.ts +62 -0
  75. package/dist/browser/modules/formula/compile/address-utils.js +83 -0
  76. package/dist/browser/modules/formula/compile/binder.d.ts +42 -0
  77. package/dist/browser/modules/formula/compile/binder.js +487 -0
  78. package/dist/browser/modules/formula/compile/bound-ast.d.ts +230 -0
  79. package/dist/browser/modules/formula/compile/bound-ast.js +80 -0
  80. package/dist/browser/modules/formula/compile/compiled-formula.d.ts +137 -0
  81. package/dist/browser/modules/formula/compile/compiled-formula.js +383 -0
  82. package/dist/browser/modules/formula/compile/dependency-analysis.d.ts +93 -0
  83. package/dist/browser/modules/formula/compile/dependency-analysis.js +432 -0
  84. package/dist/browser/modules/formula/compile/structured-ref-utils.d.ts +93 -0
  85. package/dist/browser/modules/formula/compile/structured-ref-utils.js +136 -0
  86. package/dist/browser/modules/formula/default-syntax-probe.d.ts +79 -0
  87. package/dist/browser/modules/formula/default-syntax-probe.js +83 -0
  88. package/dist/browser/modules/formula/functions/_date-context.d.ts +4 -0
  89. package/dist/browser/modules/formula/functions/_date-context.js +29 -0
  90. package/dist/browser/modules/formula/functions/_shared.d.ts +121 -0
  91. package/dist/browser/modules/formula/functions/_shared.js +381 -0
  92. package/dist/browser/modules/formula/functions/conditional.d.ts +27 -0
  93. package/dist/browser/modules/formula/functions/conditional.js +343 -0
  94. package/dist/browser/modules/formula/functions/database.d.ts +37 -0
  95. package/dist/browser/modules/formula/functions/database.js +274 -0
  96. package/dist/browser/modules/formula/functions/date.d.ts +61 -0
  97. package/dist/browser/modules/formula/functions/date.js +855 -0
  98. package/dist/browser/modules/formula/functions/dynamic-array.d.ts +23 -0
  99. package/dist/browser/modules/formula/functions/dynamic-array.js +860 -0
  100. package/dist/browser/modules/formula/functions/engineering.d.ts +57 -0
  101. package/dist/browser/modules/formula/functions/engineering.js +1128 -0
  102. package/dist/browser/modules/formula/functions/financial.d.ts +202 -0
  103. package/dist/browser/modules/formula/functions/financial.js +2296 -0
  104. package/dist/browser/modules/formula/functions/lookup.d.ts +18 -0
  105. package/dist/browser/modules/formula/functions/lookup.js +886 -0
  106. package/dist/browser/modules/formula/functions/math.d.ts +114 -0
  107. package/dist/browser/modules/formula/functions/math.js +1406 -0
  108. package/dist/browser/modules/formula/functions/statistical.d.ts +193 -0
  109. package/dist/browser/modules/formula/functions/statistical.js +3390 -0
  110. package/dist/browser/modules/formula/functions/text.d.ts +86 -0
  111. package/dist/browser/modules/formula/functions/text.js +1845 -0
  112. package/dist/browser/modules/formula/host-registry.d.ts +53 -0
  113. package/dist/browser/modules/formula/host-registry.js +69 -0
  114. package/dist/browser/modules/formula/index.d.ts +39 -0
  115. package/dist/browser/modules/formula/index.js +49 -0
  116. package/dist/browser/modules/formula/install.d.ts +62 -0
  117. package/dist/browser/modules/formula/install.js +88 -0
  118. package/dist/browser/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
  119. package/dist/browser/modules/formula/integration/apply-writeback-plan.js +210 -0
  120. package/dist/browser/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
  121. package/dist/browser/modules/formula/integration/calculate-formulas-impl.js +616 -0
  122. package/dist/browser/modules/formula/integration/calculate-formulas.d.ts +67 -0
  123. package/dist/browser/modules/formula/integration/calculate-formulas.js +68 -0
  124. package/dist/browser/modules/formula/integration/formula-instance.d.ts +64 -0
  125. package/dist/browser/modules/formula/integration/formula-instance.js +79 -0
  126. package/dist/browser/modules/formula/integration/workbook-adapter.d.ts +26 -0
  127. package/dist/browser/modules/formula/integration/workbook-adapter.js +324 -0
  128. package/dist/browser/modules/formula/integration/workbook-snapshot.d.ts +267 -0
  129. package/dist/browser/modules/formula/integration/workbook-snapshot.js +77 -0
  130. package/dist/browser/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
  131. package/dist/browser/modules/formula/materialize/build-writeback-plan.js +473 -0
  132. package/dist/browser/modules/formula/materialize/spill-engine.d.ts +9 -0
  133. package/dist/browser/modules/formula/materialize/spill-engine.js +38 -0
  134. package/dist/browser/modules/formula/materialize/types.d.ts +179 -0
  135. package/dist/browser/modules/formula/materialize/types.js +29 -0
  136. package/dist/browser/modules/formula/materialize/writeback-plan.d.ts +167 -0
  137. package/dist/browser/modules/formula/materialize/writeback-plan.js +27 -0
  138. package/dist/browser/modules/formula/runtime/evaluator.d.ts +151 -0
  139. package/dist/browser/modules/formula/runtime/evaluator.js +2291 -0
  140. package/dist/browser/modules/formula/runtime/function-registry.d.ts +47 -0
  141. package/dist/browser/modules/formula/runtime/function-registry.js +840 -0
  142. package/dist/browser/modules/formula/runtime/values.d.ts +211 -0
  143. package/dist/browser/modules/formula/runtime/values.js +385 -0
  144. package/dist/browser/modules/formula/syntax/ast.d.ts +129 -0
  145. package/dist/browser/modules/formula/syntax/ast.js +28 -0
  146. package/dist/browser/modules/formula/syntax/parser.d.ts +18 -0
  147. package/dist/browser/modules/formula/syntax/parser.js +439 -0
  148. package/dist/browser/modules/formula/syntax/token-types.d.ts +153 -0
  149. package/dist/browser/modules/formula/syntax/token-types.js +59 -0
  150. package/dist/browser/modules/formula/syntax/tokenizer.d.ts +10 -0
  151. package/dist/browser/modules/formula/syntax/tokenizer.js +1074 -0
  152. package/dist/browser/modules/pdf/excel-bridge.js +9 -0
  153. package/dist/cjs/index.js +4 -0
  154. package/dist/cjs/modules/excel/cell.js +170 -22
  155. package/dist/cjs/modules/excel/defined-names.js +411 -21
  156. package/dist/cjs/modules/excel/image.js +24 -1
  157. package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +14 -0
  158. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +48 -1
  159. package/dist/cjs/modules/excel/stream/worksheet-reader.js +17 -1
  160. package/dist/cjs/modules/excel/stream/worksheet-writer.js +45 -5
  161. package/dist/cjs/modules/excel/table.js +15 -2
  162. package/dist/cjs/modules/excel/utils/col-cache.js +15 -0
  163. package/dist/cjs/modules/excel/utils/drawing-utils.js +4 -0
  164. package/dist/cjs/modules/excel/utils/external-link-formula.js +212 -0
  165. package/dist/cjs/modules/excel/utils/iterate-stream.js +3 -1
  166. package/dist/cjs/modules/excel/utils/ooxml-paths.js +42 -2
  167. package/dist/cjs/modules/excel/utils/shared-strings.js +21 -2
  168. package/dist/cjs/modules/excel/utils/workbook-protection.js +33 -0
  169. package/dist/cjs/modules/excel/workbook.browser.js +318 -34
  170. package/dist/cjs/modules/excel/worksheet.js +20 -1
  171. package/dist/cjs/modules/excel/xlsx/rel-type.js +16 -1
  172. package/dist/cjs/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  173. package/dist/cjs/modules/excel/xlsx/xform/book/external-link-xform.js +333 -0
  174. package/dist/cjs/modules/excel/xlsx/xform/book/external-reference-xform.js +27 -0
  175. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  176. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-protection-xform.js +69 -0
  177. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  178. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +18 -0
  179. package/dist/cjs/modules/excel/xlsx/xform/core/metadata-xform.js +161 -0
  180. package/dist/cjs/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +108 -0
  181. package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  182. package/dist/cjs/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  183. package/dist/cjs/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  184. package/dist/cjs/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  185. package/dist/cjs/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +83 -0
  186. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  187. package/dist/cjs/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  188. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +408 -18
  189. package/dist/cjs/modules/excel/xlsx/xlsx.js +4 -5
  190. package/dist/cjs/modules/formula/compile/address-utils.js +89 -0
  191. package/dist/cjs/modules/formula/compile/binder.js +489 -0
  192. package/dist/cjs/modules/formula/compile/bound-ast.js +68 -0
  193. package/dist/cjs/modules/formula/compile/compiled-formula.js +387 -0
  194. package/dist/cjs/modules/formula/compile/dependency-analysis.js +437 -0
  195. package/dist/cjs/modules/formula/compile/structured-ref-utils.js +141 -0
  196. package/dist/cjs/modules/formula/default-syntax-probe.js +87 -0
  197. package/dist/cjs/modules/formula/functions/_date-context.js +33 -0
  198. package/dist/cjs/modules/formula/functions/_shared.js +396 -0
  199. package/dist/cjs/modules/formula/functions/conditional.js +354 -0
  200. package/dist/cjs/modules/formula/functions/database.js +288 -0
  201. package/dist/cjs/modules/formula/functions/date.js +883 -0
  202. package/dist/cjs/modules/formula/functions/dynamic-array.js +881 -0
  203. package/dist/cjs/modules/formula/functions/engineering.js +1183 -0
  204. package/dist/cjs/modules/formula/functions/financial.js +2348 -0
  205. package/dist/cjs/modules/formula/functions/lookup.js +902 -0
  206. package/dist/cjs/modules/formula/functions/math.js +1487 -0
  207. package/dist/cjs/modules/formula/functions/statistical.js +3488 -0
  208. package/dist/cjs/modules/formula/functions/text.js +1889 -0
  209. package/dist/cjs/modules/formula/host-registry.js +75 -0
  210. package/dist/cjs/modules/formula/index.js +58 -0
  211. package/dist/cjs/modules/formula/install.js +93 -0
  212. package/dist/cjs/modules/formula/integration/apply-writeback-plan.js +213 -0
  213. package/dist/cjs/modules/formula/integration/calculate-formulas-impl.js +619 -0
  214. package/dist/cjs/modules/formula/integration/calculate-formulas.js +71 -0
  215. package/dist/cjs/modules/formula/integration/formula-instance.js +82 -0
  216. package/dist/cjs/modules/formula/integration/workbook-adapter.js +327 -0
  217. package/dist/cjs/modules/formula/integration/workbook-snapshot.js +84 -0
  218. package/dist/cjs/modules/formula/materialize/build-writeback-plan.js +475 -0
  219. package/dist/cjs/modules/formula/materialize/spill-engine.js +42 -0
  220. package/dist/cjs/modules/formula/materialize/types.js +32 -0
  221. package/dist/cjs/modules/formula/materialize/writeback-plan.js +28 -0
  222. package/dist/cjs/modules/formula/runtime/evaluator.js +2298 -0
  223. package/dist/cjs/modules/formula/runtime/function-registry.js +846 -0
  224. package/dist/cjs/modules/formula/runtime/values.js +385 -0
  225. package/dist/cjs/modules/formula/syntax/ast.js +8 -0
  226. package/dist/cjs/modules/formula/syntax/parser.js +440 -0
  227. package/dist/cjs/modules/formula/syntax/token-types.js +32 -0
  228. package/dist/cjs/modules/formula/syntax/tokenizer.js +1076 -0
  229. package/dist/cjs/modules/pdf/excel-bridge.js +9 -0
  230. package/dist/esm/index.browser.js +4 -0
  231. package/dist/esm/index.js +4 -0
  232. package/dist/esm/modules/excel/cell.js +170 -22
  233. package/dist/esm/modules/excel/defined-names.js +411 -21
  234. package/dist/esm/modules/excel/image.js +24 -1
  235. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +14 -0
  236. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +48 -1
  237. package/dist/esm/modules/excel/stream/worksheet-reader.js +17 -1
  238. package/dist/esm/modules/excel/stream/worksheet-writer.js +45 -5
  239. package/dist/esm/modules/excel/table.js +15 -2
  240. package/dist/esm/modules/excel/utils/col-cache.js +15 -0
  241. package/dist/esm/modules/excel/utils/drawing-utils.js +4 -0
  242. package/dist/esm/modules/excel/utils/external-link-formula.js +208 -0
  243. package/dist/esm/modules/excel/utils/iterate-stream.js +3 -1
  244. package/dist/esm/modules/excel/utils/ooxml-paths.js +37 -2
  245. package/dist/esm/modules/excel/utils/shared-strings.js +21 -2
  246. package/dist/esm/modules/excel/utils/workbook-protection.js +30 -0
  247. package/dist/esm/modules/excel/workbook.browser.js +318 -34
  248. package/dist/esm/modules/excel/worksheet.js +21 -2
  249. package/dist/esm/modules/excel/xlsx/rel-type.js +16 -1
  250. package/dist/esm/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  251. package/dist/esm/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
  252. package/dist/esm/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
  253. package/dist/esm/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  254. package/dist/esm/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
  255. package/dist/esm/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  256. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
  257. package/dist/esm/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
  258. package/dist/esm/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
  259. package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  260. package/dist/esm/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  261. package/dist/esm/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  262. package/dist/esm/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  263. package/dist/esm/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
  264. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  265. package/dist/esm/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  266. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +410 -20
  267. package/dist/esm/modules/excel/xlsx/xlsx.js +4 -5
  268. package/dist/esm/modules/formula/compile/address-utils.js +83 -0
  269. package/dist/esm/modules/formula/compile/binder.js +487 -0
  270. package/dist/esm/modules/formula/compile/bound-ast.js +80 -0
  271. package/dist/esm/modules/formula/compile/compiled-formula.js +383 -0
  272. package/dist/esm/modules/formula/compile/dependency-analysis.js +432 -0
  273. package/dist/esm/modules/formula/compile/structured-ref-utils.js +136 -0
  274. package/dist/esm/modules/formula/default-syntax-probe.js +83 -0
  275. package/dist/esm/modules/formula/functions/_date-context.js +29 -0
  276. package/dist/esm/modules/formula/functions/_shared.js +381 -0
  277. package/dist/esm/modules/formula/functions/conditional.js +343 -0
  278. package/dist/esm/modules/formula/functions/database.js +274 -0
  279. package/dist/esm/modules/formula/functions/date.js +855 -0
  280. package/dist/esm/modules/formula/functions/dynamic-array.js +860 -0
  281. package/dist/esm/modules/formula/functions/engineering.js +1128 -0
  282. package/dist/esm/modules/formula/functions/financial.js +2296 -0
  283. package/dist/esm/modules/formula/functions/lookup.js +886 -0
  284. package/dist/esm/modules/formula/functions/math.js +1406 -0
  285. package/dist/esm/modules/formula/functions/statistical.js +3390 -0
  286. package/dist/esm/modules/formula/functions/text.js +1845 -0
  287. package/dist/esm/modules/formula/host-registry.js +69 -0
  288. package/dist/esm/modules/formula/index.js +49 -0
  289. package/dist/esm/modules/formula/install.js +88 -0
  290. package/dist/esm/modules/formula/integration/apply-writeback-plan.js +210 -0
  291. package/dist/esm/modules/formula/integration/calculate-formulas-impl.js +616 -0
  292. package/dist/esm/modules/formula/integration/calculate-formulas.js +68 -0
  293. package/dist/esm/modules/formula/integration/formula-instance.js +79 -0
  294. package/dist/esm/modules/formula/integration/workbook-adapter.js +324 -0
  295. package/dist/esm/modules/formula/integration/workbook-snapshot.js +77 -0
  296. package/dist/esm/modules/formula/materialize/build-writeback-plan.js +473 -0
  297. package/dist/esm/modules/formula/materialize/spill-engine.js +38 -0
  298. package/dist/esm/modules/formula/materialize/types.js +29 -0
  299. package/dist/esm/modules/formula/materialize/writeback-plan.js +27 -0
  300. package/dist/esm/modules/formula/runtime/evaluator.js +2291 -0
  301. package/dist/esm/modules/formula/runtime/function-registry.js +840 -0
  302. package/dist/esm/modules/formula/runtime/values.js +385 -0
  303. package/dist/esm/modules/formula/syntax/ast.js +28 -0
  304. package/dist/esm/modules/formula/syntax/parser.js +439 -0
  305. package/dist/esm/modules/formula/syntax/token-types.js +59 -0
  306. package/dist/esm/modules/formula/syntax/tokenizer.js +1074 -0
  307. package/dist/esm/modules/pdf/excel-bridge.js +9 -0
  308. package/dist/iife/excelts.iife.js +2302 -373
  309. package/dist/iife/excelts.iife.js.map +1 -1
  310. package/dist/iife/excelts.iife.min.js +34 -34
  311. package/dist/types/index.browser.d.ts +1 -1
  312. package/dist/types/index.d.ts +1 -1
  313. package/dist/types/modules/excel/cell.d.ts +17 -3
  314. package/dist/types/modules/excel/defined-names.d.ts +96 -1
  315. package/dist/types/modules/excel/image.d.ts +11 -0
  316. package/dist/types/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
  317. package/dist/types/modules/excel/stream/workbook-reader.d.ts +2 -1
  318. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
  319. package/dist/types/modules/excel/stream/workbook-writer.d.ts +3 -2
  320. package/dist/types/modules/excel/stream/worksheet-writer.d.ts +39 -6
  321. package/dist/types/modules/excel/types.d.ts +133 -2
  322. package/dist/types/modules/excel/utils/col-cache.d.ts +1 -0
  323. package/dist/types/modules/excel/utils/drawing-utils.d.ts +3 -3
  324. package/dist/types/modules/excel/utils/external-link-formula.d.ts +76 -0
  325. package/dist/types/modules/excel/utils/iterate-stream.d.ts +9 -3
  326. package/dist/types/modules/excel/utils/ooxml-paths.d.ts +19 -0
  327. package/dist/types/modules/excel/utils/shared-strings.d.ts +8 -3
  328. package/dist/types/modules/excel/utils/workbook-protection.d.ts +30 -0
  329. package/dist/types/modules/excel/workbook.browser.d.ts +257 -6
  330. package/dist/types/modules/excel/workbook.d.ts +1 -1
  331. package/dist/types/modules/excel/worksheet.d.ts +3 -1
  332. package/dist/types/modules/excel/xlsx/rel-type.d.ts +15 -0
  333. package/dist/types/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
  334. package/dist/types/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
  335. package/dist/types/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
  336. package/dist/types/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
  337. package/dist/types/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
  338. package/dist/types/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
  339. package/dist/types/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
  340. package/dist/types/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
  341. package/dist/types/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
  342. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
  343. package/dist/types/modules/excel/xlsx/xlsx.d.ts +7 -4
  344. package/dist/types/modules/formula/compile/address-utils.d.ts +62 -0
  345. package/dist/types/modules/formula/compile/binder.d.ts +42 -0
  346. package/dist/types/modules/formula/compile/bound-ast.d.ts +230 -0
  347. package/dist/types/modules/formula/compile/compiled-formula.d.ts +137 -0
  348. package/dist/types/modules/formula/compile/dependency-analysis.d.ts +93 -0
  349. package/dist/types/modules/formula/compile/structured-ref-utils.d.ts +93 -0
  350. package/dist/types/modules/formula/default-syntax-probe.d.ts +79 -0
  351. package/dist/types/modules/formula/functions/_date-context.d.ts +4 -0
  352. package/dist/types/modules/formula/functions/_shared.d.ts +121 -0
  353. package/dist/types/modules/formula/functions/conditional.d.ts +27 -0
  354. package/dist/types/modules/formula/functions/database.d.ts +37 -0
  355. package/dist/types/modules/formula/functions/date.d.ts +61 -0
  356. package/dist/types/modules/formula/functions/dynamic-array.d.ts +23 -0
  357. package/dist/types/modules/formula/functions/engineering.d.ts +57 -0
  358. package/dist/types/modules/formula/functions/financial.d.ts +202 -0
  359. package/dist/types/modules/formula/functions/lookup.d.ts +18 -0
  360. package/dist/types/modules/formula/functions/math.d.ts +114 -0
  361. package/dist/types/modules/formula/functions/statistical.d.ts +193 -0
  362. package/dist/types/modules/formula/functions/text.d.ts +86 -0
  363. package/dist/types/modules/formula/host-registry.d.ts +53 -0
  364. package/dist/types/modules/formula/index.d.ts +39 -0
  365. package/dist/types/modules/formula/install.d.ts +62 -0
  366. package/dist/types/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
  367. package/dist/types/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
  368. package/dist/types/modules/formula/integration/calculate-formulas.d.ts +67 -0
  369. package/dist/types/modules/formula/integration/formula-instance.d.ts +64 -0
  370. package/dist/types/modules/formula/integration/workbook-adapter.d.ts +26 -0
  371. package/dist/types/modules/formula/integration/workbook-snapshot.d.ts +267 -0
  372. package/dist/types/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
  373. package/dist/types/modules/formula/materialize/spill-engine.d.ts +9 -0
  374. package/dist/types/modules/formula/materialize/types.d.ts +179 -0
  375. package/dist/types/modules/formula/materialize/writeback-plan.d.ts +167 -0
  376. package/dist/types/modules/formula/runtime/evaluator.d.ts +151 -0
  377. package/dist/types/modules/formula/runtime/function-registry.d.ts +47 -0
  378. package/dist/types/modules/formula/runtime/values.d.ts +211 -0
  379. package/dist/types/modules/formula/syntax/ast.d.ts +129 -0
  380. package/dist/types/modules/formula/syntax/parser.d.ts +18 -0
  381. package/dist/types/modules/formula/syntax/token-types.d.ts +153 -0
  382. package/dist/types/modules/formula/syntax/tokenizer.d.ts +10 -0
  383. package/package.json +28 -28
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * Formula Instance — Unified model for all formula cell variants.
4
+ *
5
+ * The normalizer converts the heterogeneous formula representations found
6
+ * in the snapshot (normal, shared-master, shared-slave, CSE, dynamic-array)
7
+ * into a uniform `FormulaInstance` structure. After normalization, the
8
+ * compile and runtime layers do not need to know how a formula originated.
9
+ *
10
+ * ## Invariants
11
+ *
12
+ * - Every `FormulaInstance` has a non-empty `sourceText` (the formula to parse).
13
+ * - Shared-slave formulas have already been translated (offset applied) by
14
+ * the snapshot builder, so `sourceText` is the final formula text.
15
+ * - `kind` is preserved so the materialize layer can determine the correct
16
+ * writeback strategy (scalar vs. CSE vs. spill).
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.collectFormulaInstances = collectFormulaInstances;
20
+ // ============================================================================
21
+ // Normalizer
22
+ // ============================================================================
23
+ /**
24
+ * Collect all formula instances from a workbook snapshot.
25
+ *
26
+ * Iterates every cell in every worksheet, selects cells with formulas,
27
+ * and normalizes them into `FormulaInstance` objects. The result is a
28
+ * flat list ordered by worksheet order then cell position.
29
+ *
30
+ * This replaces the old `collectFormulaCells()` function but operates
31
+ * entirely on snapshot data — no live workbook objects are touched.
32
+ */
33
+ function collectFormulaInstances(snapshot) {
34
+ const instances = [];
35
+ for (const ws of snapshot.worksheets) {
36
+ collectFromWorksheet(ws, instances);
37
+ }
38
+ return instances;
39
+ }
40
+ /**
41
+ * Collect formula instances from a single worksheet snapshot.
42
+ */
43
+ function collectFromWorksheet(ws, out) {
44
+ for (const cell of ws.cells.values()) {
45
+ if (cell.formulaKind === "none") {
46
+ continue;
47
+ }
48
+ if (!cell.formula) {
49
+ continue;
50
+ }
51
+ const instance = normalizeCell(ws, cell);
52
+ if (instance) {
53
+ out.push(instance);
54
+ }
55
+ }
56
+ }
57
+ /**
58
+ * Normalize a single cell snapshot into a FormulaInstance.
59
+ *
60
+ * This is where the different formula types are unified:
61
+ * - Normal formulas pass through directly.
62
+ * - Shared-master and shared-slave formulas are both treated as normal
63
+ * for evaluation purposes (the slave's formula text is already translated).
64
+ * - CSE formulas carry their target ref for the materialize layer.
65
+ * - Dynamic-array formulas are flagged for spill handling.
66
+ */
67
+ function normalizeCell(ws, cell) {
68
+ const formula = cell.formula;
69
+ if (!formula) {
70
+ return null;
71
+ }
72
+ return {
73
+ sheetName: ws.name,
74
+ sheetId: ws.id,
75
+ row: cell.row,
76
+ col: cell.col,
77
+ sourceText: formula,
78
+ kind: cell.formulaKind,
79
+ targetRef: cell.ref,
80
+ isDynamicArray: cell.isDynamicArray ?? false
81
+ };
82
+ }
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ /**
3
+ * Workbook Adapter — Bridge between a host workbook (implementing the
4
+ * `WorkbookLike` / `WorksheetLike` / `CellLike` interfaces) and the
5
+ * engine's snapshot representation.
6
+ *
7
+ * This is the only file in the engine pipeline that walks a live host
8
+ * workbook; the rest of the pipeline consumes the immutable
9
+ * `WorkbookSnapshot` this file produces.
10
+ *
11
+ * ## Responsibilities
12
+ *
13
+ * 1. `buildWorkbookSnapshot()` — walk the host workbook and produce an
14
+ * immutable `WorkbookSnapshot`.
15
+ * 2. Cell value conversion — Date → serial number, rich text → string,
16
+ * shared formula translation, etc.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.buildWorkbookSnapshot = buildWorkbookSnapshot;
20
+ const utils_base_1 = require("../../../utils/utils.base.js");
21
+ const types_1 = require("../materialize/types");
22
+ const workbook_snapshot_1 = require("./workbook-snapshot");
23
+ // ============================================================================
24
+ // Build Workbook Snapshot
25
+ // ============================================================================
26
+ /**
27
+ * Build a complete `WorkbookSnapshot` from a live workbook.
28
+ *
29
+ * This traverses all worksheets and cells once, converting everything to
30
+ * engine-internal snapshot types. The result is a fully self-contained,
31
+ * read-only data structure.
32
+ */
33
+ function buildWorkbookSnapshot(workbook) {
34
+ const worksheets = [];
35
+ const worksheetsByName = new Map();
36
+ const worksheetsById = new Map();
37
+ const date1904 = workbook.properties?.date1904 ?? false;
38
+ for (const ws of workbook.worksheets) {
39
+ const wsSnapshot = buildWorksheetSnapshot(ws, date1904);
40
+ worksheets.push(wsSnapshot);
41
+ worksheetsByName.set(ws.name.toLowerCase(), wsSnapshot);
42
+ worksheetsById.set(ws.id, wsSnapshot);
43
+ }
44
+ const definedNames = buildDefinedNames(workbook);
45
+ // Build table-by-name index for O(1) lookup
46
+ const tablesByName = new Map();
47
+ for (const wsSnapshot of worksheets) {
48
+ for (const table of wsSnapshot.tables) {
49
+ if (table.name) {
50
+ tablesByName.set(table.name.toLowerCase(), {
51
+ table,
52
+ sheetName: wsSnapshot.name
53
+ });
54
+ }
55
+ }
56
+ }
57
+ const calcProperties = {
58
+ fullCalcOnLoad: workbook.calcProperties?.fullCalcOnLoad,
59
+ iterate: workbook.calcProperties?.iterate,
60
+ iterateCount: workbook.calcProperties?.iterateCount,
61
+ iterateDelta: workbook.calcProperties?.iterateDelta
62
+ };
63
+ const properties = {
64
+ date1904
65
+ };
66
+ return {
67
+ worksheets,
68
+ worksheetsByName,
69
+ worksheetsById,
70
+ definedNames,
71
+ tablesByName,
72
+ calcProperties,
73
+ properties
74
+ };
75
+ }
76
+ // ============================================================================
77
+ // Build Worksheet Snapshot
78
+ // ============================================================================
79
+ function buildWorksheetSnapshot(ws, date1904) {
80
+ const cells = new Map();
81
+ const hiddenRows = new Set();
82
+ // Use includeEmpty so we observe the `hidden` flag on rows that have
83
+ // no populated cells — a user may hide an empty row (e.g. filter UI)
84
+ // and SUBTOTAL(1xx,…) still needs to treat that row as hidden.
85
+ ws.eachRow({ includeEmpty: true }, (row, rowNumber) => {
86
+ if (row.hidden) {
87
+ hiddenRows.add(rowNumber);
88
+ }
89
+ row.eachCell((cell, colNumber) => {
90
+ const cellSnapshot = buildCellSnapshot(cell, rowNumber, colNumber, date1904);
91
+ if (cellSnapshot) {
92
+ cells.set((0, workbook_snapshot_1.snapshotCellKey)(rowNumber, colNumber), cellSnapshot);
93
+ }
94
+ });
95
+ });
96
+ const dims = ws.dimensions;
97
+ const dimensions = dims
98
+ ? { top: dims.top, left: dims.left, bottom: dims.bottom, right: dims.right }
99
+ : null;
100
+ const tables = buildTables(ws);
101
+ return {
102
+ id: ws.id,
103
+ name: ws.name,
104
+ dimensions,
105
+ cells,
106
+ hiddenRows,
107
+ tables
108
+ };
109
+ }
110
+ // ============================================================================
111
+ // Build Cell Snapshot
112
+ // ============================================================================
113
+ function buildCellSnapshot(cell, row, col, date1904) {
114
+ const cellType = cell.type;
115
+ // Skip truly empty cells
116
+ if (cellType === types_1.CellValueTypeLike.Null) {
117
+ return null;
118
+ }
119
+ // ── Formula cells ──
120
+ if (cellType === types_1.CellValueTypeLike.Formula) {
121
+ return buildFormulaCellSnapshot(cell, row, col, date1904);
122
+ }
123
+ // ── Non-formula cells ──
124
+ const value = convertCellValue(cell.value, date1904);
125
+ return {
126
+ row,
127
+ col,
128
+ value,
129
+ formulaKind: "none"
130
+ };
131
+ }
132
+ function buildFormulaCellSnapshot(cell, row, col, date1904) {
133
+ const model = cell.model;
134
+ const formula = cell.formula; // triggers shared formula translation for slaves
135
+ if (formula == null) {
136
+ // Formula cell with no parseable formula — capture the cached result
137
+ const cachedResult = convertFormulaResult(cell.result, date1904);
138
+ return {
139
+ row,
140
+ col,
141
+ value: cachedResult,
142
+ formulaKind: "none",
143
+ cachedResult
144
+ };
145
+ }
146
+ // Determine formula kind
147
+ const kind = classifyFormulaKind(model);
148
+ // Capture the cached result from the XLSX
149
+ const cachedResult = convertFormulaResult(cell.result, date1904);
150
+ return {
151
+ row,
152
+ col,
153
+ value: cachedResult,
154
+ formulaKind: kind,
155
+ formula,
156
+ ref: model.ref,
157
+ isDynamicArray: model.isDynamicArray ?? undefined,
158
+ cachedResult
159
+ };
160
+ }
161
+ /**
162
+ * Classify a formula cell's kind based on its model properties.
163
+ */
164
+ function classifyFormulaKind(model) {
165
+ if (model.isDynamicArray) {
166
+ return "dynamic-array";
167
+ }
168
+ if (model.shareType === "array" && model.ref) {
169
+ return "cse";
170
+ }
171
+ if (model.shareType === "shared") {
172
+ // shared-master has formula + ref, shared-slave has sharedFormula
173
+ if (model.formula && model.ref) {
174
+ return "shared-master";
175
+ }
176
+ if (model.sharedFormula) {
177
+ return "shared-slave";
178
+ }
179
+ }
180
+ return "normal";
181
+ }
182
+ // ============================================================================
183
+ // Value Conversion
184
+ // ============================================================================
185
+ /**
186
+ * Convert a live cell value to a snapshot value.
187
+ * - Dates → Excel serial number
188
+ * - Rich text → plain string
189
+ * - Errors → SnapshotErrorValue
190
+ * - All other types pass through
191
+ */
192
+ function convertCellValue(value, date1904) {
193
+ if (value === null || value === undefined) {
194
+ return null;
195
+ }
196
+ if (typeof value === "number") {
197
+ return value;
198
+ }
199
+ if (typeof value === "string") {
200
+ return value;
201
+ }
202
+ if (typeof value === "boolean") {
203
+ return value;
204
+ }
205
+ if (value instanceof Date) {
206
+ return (0, utils_base_1.dateToExcel)(value, date1904);
207
+ }
208
+ if (typeof value === "object" && "error" in value) {
209
+ // Gate the error code through the known set so user-supplied values
210
+ // like `{ error: "anything" }` can't pollute the snapshot. Unknown
211
+ // strings fall back to #VALUE! — matches Excel's default diagnostic
212
+ // when it reads an unrecognised error value from a persisted file.
213
+ const raw = value.error;
214
+ const KNOWN_ERRORS = new Set([
215
+ "#N/A",
216
+ "#NULL!",
217
+ "#DIV/0!",
218
+ "#VALUE!",
219
+ "#REF!",
220
+ "#NAME?",
221
+ "#NUM!",
222
+ "#GETTING_DATA",
223
+ "#CALC!",
224
+ "#SPILL!",
225
+ "#CONNECT!",
226
+ "#BLOCKED!",
227
+ "#UNKNOWN!",
228
+ "#FIELD!",
229
+ "#BUSY!"
230
+ ]);
231
+ const code = KNOWN_ERRORS.has(raw) ? raw : "#VALUE!";
232
+ return { error: code };
233
+ }
234
+ // Rich text → plain string
235
+ if (typeof value === "object" && "richText" in value) {
236
+ return (value.richText || []).map(r => r.text).join("");
237
+ }
238
+ // Hyperlink / other objects with text
239
+ if (typeof value === "object" && "text" in value) {
240
+ return value.text;
241
+ }
242
+ return null;
243
+ }
244
+ /**
245
+ * Convert a formula result to a snapshot value.
246
+ */
247
+ function convertFormulaResult(result, date1904) {
248
+ if (result === undefined || result === null) {
249
+ return null;
250
+ }
251
+ return convertCellValue(result, date1904);
252
+ }
253
+ // ============================================================================
254
+ // Build Tables
255
+ // ============================================================================
256
+ function buildTables(ws) {
257
+ if (!ws.getTables) {
258
+ return [];
259
+ }
260
+ const tables = [];
261
+ for (const t of ws.getTables()) {
262
+ const model = t.table;
263
+ if (!model || !model.tl) {
264
+ continue;
265
+ }
266
+ const columns = (model.columns || []).map(c => ({
267
+ name: c.name
268
+ }));
269
+ tables.push({
270
+ name: model.name || model.displayName || "",
271
+ columns,
272
+ topLeft: { row: model.tl.row, col: model.tl.col },
273
+ dataRowCount: (model.rows || []).length,
274
+ hasHeaderRow: model.headerRow !== false,
275
+ hasTotalsRow: model.totalsRow === true
276
+ });
277
+ }
278
+ return tables;
279
+ }
280
+ // ============================================================================
281
+ // Build Defined Names
282
+ // ============================================================================
283
+ function buildDefinedNames(workbook) {
284
+ const map = new Map();
285
+ if (!workbook.definedNames) {
286
+ return map;
287
+ }
288
+ // Build a sheet-id-to-name lookup for resolving localSheetId → sheet name.
289
+ //
290
+ // `localSheetId` stores the 0-based position in the XLSX-model sheet list,
291
+ // which in this library corresponds to the index in `workbook.worksheets`
292
+ // (the filtered+ordered view, see `workbook.xlsx/xform/book/workbook-xform.ts`
293
+ // line 50-94 where `index` is incremented per rendered sheet).
294
+ //
295
+ // Iterate the array exactly once and capture the position directly — avoids
296
+ // an O(n²) `indexOf` over a fresh array each call. Any caller that has
297
+ // deleted sheets after creating scoped names is responsible for updating
298
+ // `localSheetId` to match the new positions; this layer just reflects the
299
+ // workbook's current state.
300
+ const sheetIdToName = new Map();
301
+ const liveSheets = workbook.worksheets;
302
+ for (let idx = 0; idx < liveSheets.length; idx++) {
303
+ sheetIdToName.set(idx, liveSheets[idx].name);
304
+ }
305
+ // getAllEntries() returns self-contained entries — no second lookup needed.
306
+ const entries = workbook.definedNames.getAllEntries();
307
+ for (const entry of entries) {
308
+ if (!entry.ranges || entry.ranges.length === 0) {
309
+ continue;
310
+ }
311
+ // Convert numeric localSheetId → sheet name string for the snapshot
312
+ let scope;
313
+ if (entry.localSheetId !== undefined) {
314
+ scope = sheetIdToName.get(entry.localSheetId);
315
+ }
316
+ const snapshot = {
317
+ name: entry.name,
318
+ ranges: [...entry.ranges],
319
+ ...(scope ? { scope } : {})
320
+ };
321
+ const key = scope ? (0, workbook_snapshot_1.scopedNameKey)(scope, entry.name) : entry.name.toUpperCase();
322
+ if (!map.has(key)) {
323
+ map.set(key, snapshot);
324
+ }
325
+ }
326
+ return map;
327
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Workbook Snapshot — Immutable data layer for the formula engine.
4
+ *
5
+ * The snapshot captures all workbook state needed for formula compilation
6
+ * and evaluation as plain, read-only data structures. Runtime/compile code
7
+ * must depend only on these types — never on live Workbook/Worksheet/Cell
8
+ * objects.
9
+ *
10
+ * ## Design Principles
11
+ *
12
+ * 1. **Immutable** — all interfaces use `readonly` modifiers. The engine
13
+ * must never mutate snapshot data.
14
+ * 2. **Self-contained** — every piece of information the engine needs
15
+ * (cell values, formula text, table metadata, defined names, calc
16
+ * properties) is captured up front.
17
+ * 3. **No @excel/ imports** — this file defines pure data types. The
18
+ * concrete builder that populates these structures lives in
19
+ * `workbook-adapter.ts` and is the only file that touches live objects.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.snapshotCellKey = snapshotCellKey;
23
+ exports.formulaCellKey = formulaCellKey;
24
+ exports.spillCellKeyFromId = spillCellKeyFromId;
25
+ exports.scopedNameKey = scopedNameKey;
26
+ exports.resolveDefinedName = resolveDefinedName;
27
+ // ============================================================================
28
+ // Cell Key Helpers
29
+ // ============================================================================
30
+ /**
31
+ * Build a snapshot cell key from row and column.
32
+ * This key format is used for the `WorksheetSnapshot.cells` map.
33
+ */
34
+ function snapshotCellKey(row, col) {
35
+ return `${row}:${col}`;
36
+ }
37
+ /**
38
+ * Build a formula cell key that includes the sheet name.
39
+ * Used by the dependency graph and eval session cache.
40
+ */
41
+ function formulaCellKey(sheet, row, col) {
42
+ return `${sheet}!${row}:${col}`;
43
+ }
44
+ /**
45
+ * Build a spill cell key using the worksheet id (stable across renames).
46
+ * Used by the spill engine for persistent tracking.
47
+ */
48
+ function spillCellKeyFromId(worksheetId, row, col) {
49
+ return `ws:${worksheetId}!${row}:${col}`;
50
+ }
51
+ // ============================================================================
52
+ // Defined Name Resolution
53
+ // ============================================================================
54
+ /**
55
+ * Build the key used to store a sheet-scoped defined name.
56
+ * Format: `"SHEETNAME\0NAME"` (null character separator ensures no collisions).
57
+ */
58
+ function scopedNameKey(sheetName, name) {
59
+ return `${sheetName.toUpperCase()}\0${name.toUpperCase()}`;
60
+ }
61
+ /**
62
+ * Resolve a defined name considering scope precedence.
63
+ *
64
+ * Excel name resolution order:
65
+ * 1. Sheet-scoped name on `currentSheet` (if any)
66
+ * 2. Workbook-scoped (global) name
67
+ *
68
+ * @param definedNames - The defined names map from the snapshot
69
+ * @param name - The name to resolve (case-insensitive)
70
+ * @param currentSheet - The sheet where the formula is located
71
+ * @returns The matching DefinedNameSnapshot, or undefined
72
+ */
73
+ function resolveDefinedName(definedNames, name, currentSheet) {
74
+ // 1. Try sheet-scoped name first
75
+ if (currentSheet) {
76
+ const scopedKey = scopedNameKey(currentSheet, name);
77
+ const scoped = definedNames.get(scopedKey);
78
+ if (scoped) {
79
+ return scoped;
80
+ }
81
+ }
82
+ // 2. Fall back to global name
83
+ return definedNames.get(name.toUpperCase());
84
+ }