@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,151 @@
1
+ /**
2
+ * Evaluator — Execute BoundExpr using the RuntimeValue system.
3
+ *
4
+ * The evaluator operates on BoundExpr (from the compile phase),
5
+ * WorkbookSnapshot (from the snapshot phase), and RuntimeValue
6
+ * (the value system).
7
+ */
8
+ import type { BoundExpr } from "../compile/bound-ast.js";
9
+ import type { CompiledFormula } from "../compile/compiled-formula.js";
10
+ import type { WorkbookSnapshot } from "../integration/workbook-snapshot.js";
11
+ import type { RuntimeValue } from "./values.js";
12
+ /**
13
+ * Cached formula evaluation result with both scalar and raw forms.
14
+ * The scalar form is used by dependent formulas (implicit intersection applied).
15
+ * The raw form preserves the full array for dynamic array / CSE materialization.
16
+ */
17
+ interface CachedResult {
18
+ /** Scalar (implicit-intersected, dereferenced) result. */
19
+ readonly scalar: RuntimeValue;
20
+ /** Raw (full array) result. Only differs from scalar for array formulas. */
21
+ readonly raw: RuntimeValue;
22
+ }
23
+ /**
24
+ * Per-calculation mutable state.
25
+ */
26
+ export declare class EvalSession {
27
+ /** Cells currently on the evaluation call stack (circular-ref detection). */
28
+ readonly evaluating: Set<string>;
29
+ /**
30
+ * Unified formula result cache.
31
+ * Each entry holds both the scalar form (for dependents) and the raw form
32
+ * (for materialize). This replaces the previous separate cache/rawCache
33
+ * pattern with a single, self-documenting structure.
34
+ */
35
+ readonly resultCache: Map<string, CachedResult>;
36
+ /** Cache for runtime name resolution (defined names that need parsing). */
37
+ readonly nameCache: Map<string, RuntimeValue>;
38
+ /** Fallback values for circular references during iterative calculation. */
39
+ readonly circularFallback: Map<string, RuntimeValue>;
40
+ /**
41
+ * Live spill map: cell key → (masterKey, row-offset, col-offset).
42
+ *
43
+ * Populated as soon as a dynamic-array formula is evaluated and yields
44
+ * an array result. Downstream formulas that read a cell inside the
45
+ * spill region look the master's cached array up via this map and
46
+ * return the correct element — even before materialize has written
47
+ * the ghost cells to the snapshot.
48
+ *
49
+ * This is the fix for "first-pass `=SUM(A1:A5)` over a `=SEQUENCE(5)`
50
+ * spill" — without the live map, `getCellValue("S", 2, 1)` returned
51
+ * BLANK and SUM only counted the master cell.
52
+ */
53
+ readonly liveSpills: Map<string, {
54
+ masterKey: string;
55
+ rowOffset: number;
56
+ colOffset: number;
57
+ }>;
58
+ /**
59
+ * Runtime dependency recorder — tracks cell accesses made during evaluation.
60
+ *
61
+ * When a formula with `hasDynamicRefs` (INDIRECT/OFFSET) is being evaluated,
62
+ * every `getCellValue` / `buildRangeArray` call records the accessed cell/range
63
+ * key here. After evaluation, these dynamic edges can be merged with the
64
+ * compiled static dependency set to produce a complete dependency graph.
65
+ *
66
+ * Key: formula cell key being evaluated → Set of accessed cell keys.
67
+ * Only populated for formulas that have `hasDynamicRefs === true`.
68
+ */
69
+ readonly dynamicDeps: Map<string, Set<string>>;
70
+ /**
71
+ * The formula cell key currently being recorded (null if recording is off).
72
+ * Set before evaluating a formula with dynamic refs, cleared after.
73
+ */
74
+ recordingKey: string | null;
75
+ /**
76
+ * Current LAMBDA invocation depth. Guards against unbounded recursion
77
+ * (e.g. `LAMBDA(x, x(x))(LAMBDA(x, x(x)))`) that would otherwise overflow
78
+ * the JS call stack. Excel documents a recursion limit of ~256.
79
+ */
80
+ lambdaDepth: number;
81
+ /**
82
+ * AST cache for INDIRECT re-parsing. INDIRECT receives a runtime string
83
+ * describing a reference; re-parsing it per invocation would be wasted
84
+ * work, so we memoise the `bound` expression keyed on the reference
85
+ * text. This belongs to the session (per-calculation lifetime) rather
86
+ * than the snapshot because the bindings depend on the evaluation
87
+ * context.
88
+ */
89
+ readonly indirectAstCache: Map<string, BoundExpr>;
90
+ makeKey(sheet: string, row: number, col: number): string;
91
+ /**
92
+ * Record a cell access for the currently-recording formula.
93
+ */
94
+ recordAccess(sheet: string, row: number, col: number): void;
95
+ }
96
+ /**
97
+ * The evaluation context. Carries the snapshot and compiled formula map
98
+ * for the evaluator to access cell values and resolve names at runtime.
99
+ * Short-lived per-calculation state (caches, iteration flags, etc.) lives
100
+ * on `EvalSession` instead.
101
+ */
102
+ export interface EvalContext {
103
+ /** The workbook snapshot. */
104
+ readonly snapshot: WorkbookSnapshot;
105
+ /** Map from formula cell key to CompiledFormula. */
106
+ readonly compiledFormulas: ReadonlyMap<string, CompiledFormula>;
107
+ /** The current sheet name (for relative references). */
108
+ currentSheet: string;
109
+ /** Current cell address being evaluated. */
110
+ currentAddress?: {
111
+ sheet: string;
112
+ row: number;
113
+ col: number;
114
+ };
115
+ /** Local variable bindings from LET expressions. */
116
+ localBindings?: Map<string, RuntimeValue>;
117
+ }
118
+ /**
119
+ * Evaluate a BoundExpr to produce a RuntimeValue.
120
+ */
121
+ export declare function evaluate(expr: BoundExpr, ctx: EvalContext, session: EvalSession): RuntimeValue;
122
+ /**
123
+ * Evaluate a compiled formula and return its **scalar** result.
124
+ *
125
+ * This is the standard evaluation path for regular (non-array) formulas.
126
+ * The result is:
127
+ * 1. Evaluated from the bound expression tree
128
+ * 2. Implicit-intersected to a single value/reference
129
+ * 3. Dereferenced if it's a reference
130
+ * 4. Cached for subsequent lookups by dependent formulas
131
+ *
132
+ * Use `evaluateFormulaRaw` instead when the full array result is needed
133
+ * (dynamic array formulas, CSE formulas).
134
+ */
135
+ export declare function evaluateFormula(compiled: CompiledFormula, ctx: EvalContext, session: EvalSession): RuntimeValue;
136
+ /**
137
+ * Evaluate a compiled formula and return the **raw** (possibly array) result.
138
+ *
139
+ * This is the evaluation path for dynamic array and CSE formulas where
140
+ * the full array shape must be preserved for spill/distribution.
141
+ *
142
+ * Semantics:
143
+ * - Both scalar and raw forms are stored in `session.resultCache` as a
144
+ * `CachedResult{scalar, raw}`. Dependent scalar formulas see the scalar
145
+ * form; the materialize layer retrieves the raw form.
146
+ * - The return value is the full dereferenced result — may be an ArrayValue
147
+ * with height > 1 or width > 1.
148
+ */
149
+ export declare function evaluateFormulaRaw(compiled: CompiledFormula, ctx: EvalContext, session: EvalSession): RuntimeValue;
150
+ export declare function implicitIntersect(val: RuntimeValue, ctx: EvalContext): RuntimeValue;
151
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Function Registry — Declarative function descriptors and native implementations.
3
+ *
4
+ * Each function is described by a `FunctionDescriptor` that carries metadata
5
+ * about arity and the implementation itself. The evaluator uses this metadata
6
+ * to validate arguments and invoke functions.
7
+ *
8
+ * Special forms (IF, LET, LAMBDA, etc.) are NOT registered here — they
9
+ * are handled directly by the evaluator's special-form dispatch.
10
+ */
11
+ import type { RuntimeValue } from "./values.js";
12
+ /**
13
+ * A function descriptor with metadata and implementation.
14
+ */
15
+ export interface FunctionDescriptor {
16
+ /** Canonical uppercase name. */
17
+ readonly name: string;
18
+ /** Minimum number of arguments. */
19
+ readonly minArity: number;
20
+ /** Maximum number of arguments. Infinity for variadic. */
21
+ readonly maxArity: number;
22
+ /**
23
+ * The function implementation.
24
+ * Receives eagerly evaluated arguments as `RuntimeValue[]`.
25
+ * Returns a `RuntimeValue`.
26
+ */
27
+ readonly invoke: (args: RuntimeValue[]) => RuntimeValue;
28
+ }
29
+ /**
30
+ * Register a function descriptor. The descriptor is stored under its
31
+ * canonical (unprefixed) name only — `_XLFN.` / `_XLFN._XLWS.` prefix
32
+ * variants are resolved dynamically in `lookupFunction`. This keeps the
33
+ * registry small and avoids triple-entry bookkeeping for 200+ functions.
34
+ */
35
+ export declare function registerFunction(desc: FunctionDescriptor): void;
36
+ /**
37
+ * Look up a function by uppercase name. Accepts `_XLFN.` and
38
+ * `_XLFN._XLWS.` prefixed variants by stripping the prefix before lookup
39
+ * (a no-op for plain names, so plain lookups also go through a single
40
+ * Map.get call — avoiding the double-lookup pattern used previously).
41
+ */
42
+ export declare function lookupFunction(name: string): FunctionDescriptor | undefined;
43
+ /**
44
+ * Convenience: define and register an eager function.
45
+ */
46
+ export declare function defineEager(name: string, minArity: number, maxArity: number, invoke: (args: RuntimeValue[]) => RuntimeValue): FunctionDescriptor;
47
+ export declare function ensureRegistryInitialized(): void;
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Runtime Value System — The engine's canonical value representation.
3
+ *
4
+ * Every value that flows through the formula evaluator is a `RuntimeValue`.
5
+ * This is a properly tagged discriminated union that all function
6
+ * implementations operate on directly — no adapter layer.
7
+ *
8
+ * ## Design Principles
9
+ *
10
+ * 1. **No Date objects** — dates are represented as their Excel serial
11
+ * number (a plain `number`). Date formatting is an output concern.
12
+ * 2. **No monkey-patched arrays** — `ArrayValue` is a proper type with
13
+ * explicit `height`, `width`, and optional origin metadata.
14
+ * 3. **Reference is a first-class value** — `ReferenceValue` can flow
15
+ * through the evaluator and be passed to functions.
16
+ * 4. **Error codes are strict** — `ErrorValue` uses a typed code enum.
17
+ * 5. **Lambda is a value** — `LambdaValue` is part of the value union.
18
+ */
19
+ import type { BoundExpr } from "../compile/bound-ast.js";
20
+ import type { ErrorCode } from "../integration/workbook-snapshot.js";
21
+ export declare const enum RVKind {
22
+ /** Empty cell / blank. Numeric value 0, string value "". */
23
+ Blank = 0,
24
+ /** A number (includes dates as serial numbers). */
25
+ Number = 1,
26
+ /** A string. */
27
+ String = 2,
28
+ /** A boolean (TRUE / FALSE). */
29
+ Boolean = 3,
30
+ /** An error value (#N/A, #VALUE!, etc.). */
31
+ Error = 4,
32
+ /** A 2D array of scalar values. */
33
+ Array = 5,
34
+ /** A cell or area reference (lazy — not yet resolved to values). */
35
+ Reference = 6,
36
+ /** A lambda (closure). */
37
+ Lambda = 7
38
+ }
39
+ export interface BlankValue {
40
+ readonly kind: RVKind.Blank;
41
+ }
42
+ export interface NumberValue {
43
+ readonly kind: RVKind.Number;
44
+ readonly value: number;
45
+ }
46
+ export interface StringValue {
47
+ readonly kind: RVKind.String;
48
+ readonly value: string;
49
+ }
50
+ export interface BooleanValue {
51
+ readonly kind: RVKind.Boolean;
52
+ readonly value: boolean;
53
+ }
54
+ export interface ErrorValue {
55
+ readonly kind: RVKind.Error;
56
+ readonly code: ErrorCode;
57
+ }
58
+ /**
59
+ * A 2D array of scalar values.
60
+ *
61
+ * `rows[r][c]` is a `ScalarValue`. Arrays are always rectangular.
62
+ * Origin metadata (for implicit intersection) is carried inline.
63
+ */
64
+ export interface ArrayValue {
65
+ readonly kind: RVKind.Array;
66
+ /** Rows of scalar values. rows[0] is the first row. */
67
+ readonly rows: readonly (readonly ScalarValue[])[];
68
+ /** Number of rows. */
69
+ readonly height: number;
70
+ /** Number of columns. */
71
+ readonly width: number;
72
+ /** Origin row in the worksheet (1-based). Used for implicit intersection. */
73
+ readonly originRow?: number;
74
+ /** Origin column in the worksheet (1-based). Used for implicit intersection. */
75
+ readonly originCol?: number;
76
+ /**
77
+ * Per-cell mask marking cells whose source formula is SUBTOTAL or
78
+ * AGGREGATE. When a range is passed to an outer SUBTOTAL/AGGREGATE
79
+ * call, those cells must be skipped so their results are not
80
+ * double-counted (Excel semantics — standard totals-row behavior).
81
+ *
82
+ * Same shape as `rows`: `subtotalMask[r][c]` is true when the cell
83
+ * should be excluded from outer SUBTOTAL/AGGREGATE aggregation.
84
+ * Omitted when no cell in the array is a SUBTOTAL/AGGREGATE output.
85
+ */
86
+ readonly subtotalMask?: readonly (readonly boolean[])[];
87
+ /**
88
+ * Per-row mask marking rows whose source worksheet row is hidden.
89
+ * Used by SUBTOTAL's 1xx-variant codes (101-111) and by AGGREGATE
90
+ * options 5/7 to skip hidden rows. `hiddenRowMask[r]` is true when
91
+ * row `r` of the array should be excluded under those semantics.
92
+ * Omitted when no row in the array is hidden.
93
+ */
94
+ readonly hiddenRowMask?: readonly boolean[];
95
+ }
96
+ /**
97
+ * The shape of a reference.
98
+ */
99
+ export type RefArea = {
100
+ readonly sheet: string;
101
+ readonly top: number;
102
+ readonly left: number;
103
+ readonly bottom: number;
104
+ readonly right: number;
105
+ };
106
+ /**
107
+ * A reference value that represents one or more areas in the workbook.
108
+ *
109
+ * References are first-class values in the new engine — they can be
110
+ * passed to functions, returned from functions, and stored in variables.
111
+ * They are resolved to actual values lazily when needed.
112
+ */
113
+ export interface ReferenceValue {
114
+ readonly kind: RVKind.Reference;
115
+ /** The areas this reference covers. Usually one, but UNION produces multiple. */
116
+ readonly areas: readonly RefArea[];
117
+ /** Whether this reference originated from a single-cell ref (A1) vs an area ref (A1:A1). */
118
+ readonly singleCell?: boolean;
119
+ }
120
+ /**
121
+ * A lambda closure value.
122
+ */
123
+ export interface LambdaValue {
124
+ readonly kind: RVKind.Lambda;
125
+ /** Parameter names (uppercase). */
126
+ readonly params: readonly string[];
127
+ /** The body expression to evaluate when called. */
128
+ readonly body: BoundExpr;
129
+ /** Captured variable bindings from the enclosing scope. */
130
+ readonly closureBindings?: ReadonlyMap<string, RuntimeValue>;
131
+ }
132
+ /**
133
+ * A scalar value (non-array, non-reference, non-lambda).
134
+ */
135
+ export type ScalarValue = BlankValue | NumberValue | StringValue | BooleanValue | ErrorValue;
136
+ /**
137
+ * Any value that can flow through the evaluator.
138
+ */
139
+ export type RuntimeValue = BlankValue | NumberValue | StringValue | BooleanValue | ErrorValue | ArrayValue | ReferenceValue | LambdaValue;
140
+ /** The singleton blank value. */
141
+ export declare const BLANK: BlankValue;
142
+ /** Common error values. */
143
+ export declare const ERRORS: {
144
+ readonly VALUE: ErrorValue;
145
+ readonly REF: ErrorValue;
146
+ readonly NAME: ErrorValue;
147
+ readonly DIV0: ErrorValue;
148
+ readonly NA: ErrorValue;
149
+ readonly NUM: ErrorValue;
150
+ readonly NULL: ErrorValue;
151
+ readonly SPILL: ErrorValue;
152
+ readonly CALC: ErrorValue;
153
+ };
154
+ export declare function rvNumber(value: number): NumberValue;
155
+ export declare function rvString(value: string): StringValue;
156
+ export declare function rvBoolean(value: boolean): BooleanValue;
157
+ export declare function rvError(code: ErrorCode): ErrorValue;
158
+ export declare function rvArray(rows: ScalarValue[][], originRow?: number, originCol?: number, subtotalMask?: readonly (readonly boolean[])[], hiddenRowMask?: readonly boolean[]): ArrayValue;
159
+ export declare function rvRef(sheet: string, top: number, left: number, bottom: number, right: number): ReferenceValue;
160
+ export declare function rvCellRef(sheet: string, row: number, col: number): ReferenceValue;
161
+ export declare function rvLambda(params: string[], body: BoundExpr, closureBindings?: ReadonlyMap<string, RuntimeValue>): LambdaValue;
162
+ export declare function isError(v: RuntimeValue): v is ErrorValue;
163
+ export declare function isArray(v: RuntimeValue): v is ArrayValue;
164
+ export declare function isLambda(v: RuntimeValue): v is LambdaValue;
165
+ export declare function isScalar(v: RuntimeValue): v is ScalarValue;
166
+ /**
167
+ * Coerce a runtime value to a number.
168
+ * - Blank → 0
169
+ * - Number → itself
170
+ * - Boolean → 1 / 0
171
+ * - String → parse or #VALUE!
172
+ * - Error → propagate
173
+ */
174
+ export declare function toNumberRV(v: RuntimeValue): NumberValue | ErrorValue;
175
+ /**
176
+ * Coerce a runtime value to a string.
177
+ */
178
+ export declare function toStringRV(v: RuntimeValue): string;
179
+ /**
180
+ * Coerce a runtime value to a boolean.
181
+ */
182
+ export declare function toBooleanRV(v: RuntimeValue): BooleanValue | ErrorValue;
183
+ /**
184
+ * Structural equality of scalar values.
185
+ *
186
+ * - Different kinds → false
187
+ * - Number / Boolean / Blank → strict value equality (Blank always equal)
188
+ * - String → case-insensitive comparison (Excel semantics)
189
+ * - Error → not equal (errors do not compare equal to each other)
190
+ */
191
+ /**
192
+ * Three-way compare two scalars that share a kind.
193
+ *
194
+ * Returns a negative number if `a < b`, zero if equal, positive if `a > b`.
195
+ * Returns `NaN` when the kinds differ or cannot be ordered (e.g. errors);
196
+ * callers decide how to surface the incomparability — sort helpers usually
197
+ * skip NaN pairs, while comparison operators route to a kind-priority
198
+ * tiebreak. Strings are compared case-insensitively to match Excel.
199
+ */
200
+ export declare function compareScalarsSameKind(a: ScalarValue, b: ScalarValue): number;
201
+ export declare function scalarEquals(a: ScalarValue, b: ScalarValue): boolean;
202
+ /**
203
+ * Get the top-left scalar from any value (for implicit intersection fallback).
204
+ */
205
+ export declare function topLeft(v: RuntimeValue): ScalarValue;
206
+ /**
207
+ * Convert a SnapshotCellValue to a RuntimeValue.
208
+ */
209
+ export declare function fromSnapshotValue(v: number | string | boolean | {
210
+ error: string;
211
+ } | null): ScalarValue;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * AST Node Types for Formula Parser
3
+ *
4
+ * Defines the Abstract Syntax Tree node types as a proper discriminated union.
5
+ * Each node variant carries only the data relevant to its type.
6
+ */
7
+ export declare const enum NodeType {
8
+ Number = 1,
9
+ String = 2,
10
+ Boolean = 3,
11
+ Error = 4,
12
+ CellRef = 5,
13
+ RangeRef = 6,
14
+ BinaryOp = 7,
15
+ UnaryOp = 8,
16
+ FunctionCall = 9,
17
+ Array = 10,
18
+ Percent = 11,
19
+ Name = 12,
20
+ ColRangeRef = 13,
21
+ RowRangeRef = 14,
22
+ StructuredRef = 15,
23
+ Missing = 16
24
+ }
25
+ export interface NumberNode {
26
+ type: NodeType.Number;
27
+ value: number;
28
+ }
29
+ export interface StringNode {
30
+ type: NodeType.String;
31
+ value: string;
32
+ }
33
+ export interface BooleanNode {
34
+ type: NodeType.Boolean;
35
+ value: boolean;
36
+ }
37
+ export interface ErrorNode {
38
+ type: NodeType.Error;
39
+ value: string;
40
+ }
41
+ export interface CellRefNode {
42
+ type: NodeType.CellRef;
43
+ /** Uppercase column letters, e.g. "A" */
44
+ col: string;
45
+ /** Row number as string, e.g. "1" */
46
+ row: string;
47
+ colAbsolute: boolean;
48
+ rowAbsolute: boolean;
49
+ /** Optional sheet name for cross-sheet references */
50
+ sheet?: string;
51
+ /** Optional end sheet name for 3D references (e.g. Sheet1:Sheet3!A1) */
52
+ endSheet?: string;
53
+ }
54
+ export interface RangeRefNode {
55
+ type: NodeType.RangeRef;
56
+ /** Top-left cell */
57
+ start: CellRefNode;
58
+ /** Bottom-right cell */
59
+ end: CellRefNode;
60
+ /** Sheet name — both start and end share same sheet */
61
+ sheet?: string;
62
+ /** Optional end sheet name for 3D references (e.g. Sheet1:Sheet3!A1:B2) */
63
+ endSheet?: string;
64
+ }
65
+ export interface BinaryOpNode {
66
+ type: NodeType.BinaryOp;
67
+ op: string;
68
+ left: AstNode;
69
+ right: AstNode;
70
+ }
71
+ export interface UnaryOpNode {
72
+ type: NodeType.UnaryOp;
73
+ op: string;
74
+ operand: AstNode;
75
+ }
76
+ export interface FunctionCallNode {
77
+ type: NodeType.FunctionCall;
78
+ name: string;
79
+ args: AstNode[];
80
+ }
81
+ export interface ArrayNode {
82
+ type: NodeType.Array;
83
+ /** rows[i][j] = element */
84
+ rows: AstNode[][];
85
+ }
86
+ export interface PercentNode {
87
+ type: NodeType.Percent;
88
+ operand: AstNode;
89
+ }
90
+ export interface NameNode {
91
+ type: NodeType.Name;
92
+ name: string;
93
+ }
94
+ export interface ColRangeRefNode {
95
+ type: NodeType.ColRangeRef;
96
+ /** Start column (e.g. "A") */
97
+ startCol: string;
98
+ /** End column (e.g. "B") */
99
+ endCol: string;
100
+ /** Optional sheet name */
101
+ sheet?: string;
102
+ /** Optional end sheet name for 3D references */
103
+ endSheet?: string;
104
+ }
105
+ export interface RowRangeRefNode {
106
+ type: NodeType.RowRangeRef;
107
+ /** Start row (1-based) */
108
+ startRow: number;
109
+ /** End row (1-based) */
110
+ endRow: number;
111
+ /** Optional sheet name */
112
+ sheet?: string;
113
+ /** Optional end sheet name for 3D references */
114
+ endSheet?: string;
115
+ }
116
+ export interface StructuredRefNode {
117
+ type: NodeType.StructuredRef;
118
+ /** Table name (empty string for implicit [@Col] syntax) */
119
+ tableName: string;
120
+ /** Column references (e.g. ["Column1", "Column2"] for a column range) */
121
+ columns: string[];
122
+ /** Special items (e.g. ["#Headers", "#Data", "#Totals", "#All", "#This Row"]) */
123
+ specials: string[];
124
+ }
125
+ /** Represents an omitted/missing argument in a function call (e.g., the middle arg in IF(A1,,0)). */
126
+ export interface MissingNode {
127
+ type: NodeType.Missing;
128
+ }
129
+ export type AstNode = NumberNode | StringNode | BooleanNode | ErrorNode | CellRefNode | RangeRefNode | BinaryOpNode | UnaryOpNode | FunctionCallNode | ArrayNode | PercentNode | NameNode | ColRangeRefNode | RowRangeRefNode | StructuredRefNode | MissingNode;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Formula Parser
3
+ *
4
+ * Converts a token stream into an Abstract Syntax Tree (AST).
5
+ * Implements a Pratt parser (top-down operator precedence) for correct
6
+ * handling of operator precedence and associativity.
7
+ *
8
+ * Excel operator precedence (highest to lowest):
9
+ * 1. Unary + / - / %
10
+ * 2. ^ (exponentiation, right-assoc)
11
+ * 3. * /
12
+ * 4. + -
13
+ * 5. & (concatenation)
14
+ * 6. = <> < > <= >= (comparison)
15
+ */
16
+ import { type AstNode } from "./ast.js";
17
+ import { type Token } from "./token-types.js";
18
+ export declare function parse(tokens: Token[]): AstNode;