@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,89 @@
1
+ "use strict";
2
+ /**
3
+ * Formula Address Utilities — Shared helpers for address parsing and conversion.
4
+ *
5
+ * These pure functions are used across the compile, runtime, and materialize
6
+ * layers. Centralizing them here eliminates duplication and ensures consistent
7
+ * behavior.
8
+ *
9
+ * ## Design Constraint
10
+ *
11
+ * This module must NOT import from `@excel/utils/col-cache` or any live
12
+ * workbook type. All functions are self-contained.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.colLetterToNumber = colLetterToNumber;
16
+ exports.parseDefinedNameRange = parseDefinedNameRange;
17
+ exports.parseSimpleAddress = parseSimpleAddress;
18
+ exports.parseRefRange = parseRefRange;
19
+ // ============================================================================
20
+ // Column Letter ↔ Number
21
+ // ============================================================================
22
+ /**
23
+ * Convert a column letter string (e.g. "A", "AA", "XFD") to a 1-based number.
24
+ *
25
+ * - `"A"` → 1
26
+ * - `"Z"` → 26
27
+ * - `"AA"` → 27
28
+ * - `"XFD"` → 16384
29
+ */
30
+ function colLetterToNumber(col) {
31
+ let result = 0;
32
+ for (let i = 0; i < col.length; i++) {
33
+ result = result * 26 + (col.charCodeAt(i) - 64); // 'A' = 65
34
+ }
35
+ return result;
36
+ }
37
+ const DEFINED_NAME_RANGE_RE = /^(?:'([^']*(?:''[^']*)*)'|([^!]+))!\$([A-Z]+)\$(\d+)(?::\$([A-Z]+)\$(\d+))?$/;
38
+ /**
39
+ * Parse a defined-name range string like `"Sheet1!$A$1:$B$2"` or `"'Sheet Name'!$C$3"`
40
+ * into a `ParsedNameRange`. Returns `null` if the format is unrecognized.
41
+ */
42
+ function parseDefinedNameRange(rangeStr) {
43
+ const m = DEFINED_NAME_RANGE_RE.exec(rangeStr);
44
+ if (!m) {
45
+ return null;
46
+ }
47
+ // Sheet name: quoted (group 1, with '' unescaping) or unquoted (group 2)
48
+ const sheet = m[1] !== undefined ? m[1].replace(/''/g, "'") : m[2];
49
+ const startCol = colLetterToNumber(m[3]);
50
+ const startRow = parseInt(m[4], 10);
51
+ const endCol = m[5] ? colLetterToNumber(m[5]) : startCol;
52
+ const endRow = m[6] ? parseInt(m[6], 10) : startRow;
53
+ return { sheet, startRow, startCol, endRow, endCol };
54
+ }
55
+ /**
56
+ * Parse a simple cell address like `"A1"`, `"$B$2"`, or `"AA100"`.
57
+ * Dollar signs are stripped. Returns `null` on parse failure.
58
+ */
59
+ function parseSimpleAddress(addr) {
60
+ const m = /^([A-Z]+)(\d+)$/.exec(addr.replace(/\$/g, ""));
61
+ if (!m) {
62
+ return null;
63
+ }
64
+ return {
65
+ row: parseInt(m[2], 10),
66
+ col: colLetterToNumber(m[1])
67
+ };
68
+ }
69
+ /**
70
+ * Parse a cell range string like `"A1:B2"` into a `ParsedRefRange`.
71
+ * Returns `null` if the format is unrecognized.
72
+ */
73
+ function parseRefRange(ref) {
74
+ const parts = ref.split(":");
75
+ if (parts.length !== 2) {
76
+ return null;
77
+ }
78
+ const tl = parseSimpleAddress(parts[0]);
79
+ const br = parseSimpleAddress(parts[1]);
80
+ if (!tl || !br) {
81
+ return null;
82
+ }
83
+ return {
84
+ top: Math.min(tl.row, br.row),
85
+ left: Math.min(tl.col, br.col),
86
+ bottom: Math.max(tl.row, br.row),
87
+ right: Math.max(tl.col, br.col)
88
+ };
89
+ }
@@ -0,0 +1,489 @@
1
+ "use strict";
2
+ /**
3
+ * Binder — Transform raw AST into BoundExpr.
4
+ *
5
+ * The binder performs static symbol resolution:
6
+ * - Cell/range references → BoundCellRef / BoundAreaRef with resolved sheet
7
+ * - Defined names → BoundCellRef / BoundAreaRef (if resolvable) or BoundNameExpr
8
+ * - Structured references → BoundCellRef / BoundAreaRef
9
+ * - Function calls → BoundCall or BoundSpecialCall
10
+ * - 3D references → BoundRef3D
11
+ *
12
+ * The binder operates on snapshot data only — no live workbook objects.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.bind = bind;
16
+ const workbook_snapshot_1 = require("../integration/workbook-snapshot");
17
+ const token_types_1 = require("../syntax/token-types");
18
+ const address_utils_1 = require("./address-utils");
19
+ const bound_ast_1 = require("./bound-ast");
20
+ const structured_ref_utils_1 = require("./structured-ref-utils");
21
+ // ============================================================================
22
+ // Special Form Registry
23
+ // ============================================================================
24
+ const SPECIAL_FORMS = new Set([
25
+ "IF",
26
+ "IFERROR",
27
+ "IFNA",
28
+ "IFS",
29
+ "SWITCH",
30
+ "CHOOSE",
31
+ "LET",
32
+ "LAMBDA",
33
+ "INDIRECT",
34
+ "OFFSET",
35
+ "MAP",
36
+ "REDUCE",
37
+ "SCAN",
38
+ "MAKEARRAY",
39
+ "BYROW",
40
+ "BYCOL"
41
+ ]);
42
+ /**
43
+ * Map prefixed names to their canonical special form name.
44
+ */
45
+ function canonicalSpecialForm(name) {
46
+ const canonical = (0, token_types_1.stripFunctionPrefix)(name);
47
+ if (SPECIAL_FORMS.has(canonical)) {
48
+ return canonical;
49
+ }
50
+ return undefined;
51
+ }
52
+ // ============================================================================
53
+ // Main Bind Function
54
+ // ============================================================================
55
+ /**
56
+ * Bind a raw AST node to produce a BoundExpr.
57
+ *
58
+ * This is the main entry point for the compilation phase. It recursively
59
+ * walks the AST and resolves all symbols against the snapshot.
60
+ */
61
+ function bind(node, ctx) {
62
+ switch (node.type) {
63
+ case 1 /* NodeType.Number */:
64
+ return (0, bound_ast_1.boundLiteral)(node.value);
65
+ case 2 /* NodeType.String */:
66
+ return (0, bound_ast_1.boundLiteral)(node.value);
67
+ case 3 /* NodeType.Boolean */:
68
+ return (0, bound_ast_1.boundLiteral)(node.value);
69
+ case 4 /* NodeType.Error */:
70
+ return (0, bound_ast_1.boundErrorLiteral)(node.value);
71
+ case 16 /* NodeType.Missing */:
72
+ return (0, bound_ast_1.boundLiteral)(null);
73
+ case 5 /* NodeType.CellRef */:
74
+ return bindCellRef(node, ctx);
75
+ case 6 /* NodeType.RangeRef */:
76
+ return bindRangeRef(node, ctx);
77
+ case 13 /* NodeType.ColRangeRef */:
78
+ return bindColRangeRef(node, ctx);
79
+ case 14 /* NodeType.RowRangeRef */:
80
+ return bindRowRangeRef(node, ctx);
81
+ case 7 /* NodeType.BinaryOp */:
82
+ return {
83
+ kind: 7 /* BoundExprKind.BinaryOp */,
84
+ op: node.op,
85
+ left: bind(node.left, ctx),
86
+ right: bind(node.right, ctx)
87
+ };
88
+ case 8 /* NodeType.UnaryOp */:
89
+ return {
90
+ kind: 8 /* BoundExprKind.UnaryOp */,
91
+ op: node.op,
92
+ operand: bind(node.operand, ctx)
93
+ };
94
+ case 11 /* NodeType.Percent */:
95
+ return {
96
+ kind: 9 /* BoundExprKind.Percent */,
97
+ operand: bind(node.operand, ctx)
98
+ };
99
+ case 9 /* NodeType.FunctionCall */:
100
+ return bindFunctionCall(node.name, node.args, ctx);
101
+ case 10 /* NodeType.Array */:
102
+ return {
103
+ kind: 12 /* BoundExprKind.Array */,
104
+ rows: node.rows.map(row => row.map(elem => bind(elem, ctx)))
105
+ };
106
+ case 12 /* NodeType.Name */:
107
+ return bindName(node.name, ctx);
108
+ case 15 /* NodeType.StructuredRef */:
109
+ return bindStructuredRef(node.tableName, node.columns, node.specials, ctx);
110
+ default:
111
+ return assertNever(node);
112
+ }
113
+ }
114
+ /**
115
+ * Exhaustiveness helper: triggers a compile-time error if `bind` misses a
116
+ * discriminated-union variant. At runtime, this path is unreachable.
117
+ */
118
+ function assertNever(x) {
119
+ throw new Error(`unexpected AST node: ${JSON.stringify(x)}`);
120
+ }
121
+ // ============================================================================
122
+ // Cell Reference Binding
123
+ // ============================================================================
124
+ function bindCellRef(node, ctx) {
125
+ const sheet = node.sheet ?? ctx.currentSheet;
126
+ const row = parseInt(node.row, 10);
127
+ const col = (0, address_utils_1.colLetterToNumber)(node.col);
128
+ // Excel's cell coordinate range is 1..1048576 for rows, 1..16384 for
129
+ // columns. The tokenizer enforces these when recognising cell refs,
130
+ // but we re-check here because the same binder runs on defined-name
131
+ // range strings that bypass the tokenizer and could carry arbitrary
132
+ // large values.
133
+ if (row < 1 || row > 1048576 || col < 1 || col > 16384) {
134
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
135
+ }
136
+ // 3D cell reference: Sheet1:Sheet3!A1
137
+ if (node.endSheet) {
138
+ const sheets = getSheetsInRange(ctx.snapshot, sheet, node.endSheet);
139
+ if (!sheets) {
140
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
141
+ }
142
+ const inner = (0, bound_ast_1.boundCellRef)(sheets[0], row, col);
143
+ return {
144
+ kind: 6 /* BoundExprKind.Ref3D */,
145
+ sheets,
146
+ inner
147
+ };
148
+ }
149
+ // Validate sheet exists
150
+ if (!ctx.snapshot.worksheetsByName.has(sheet.toLowerCase())) {
151
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
152
+ }
153
+ return (0, bound_ast_1.boundCellRef)(sheet, row, col);
154
+ }
155
+ function bindRangeRef(node, ctx) {
156
+ const sheet = node.sheet ?? ctx.currentSheet;
157
+ const startRow = parseInt(node.start.row, 10);
158
+ const startCol = (0, address_utils_1.colLetterToNumber)(node.start.col);
159
+ const endRow = parseInt(node.end.row, 10);
160
+ const endCol = (0, address_utils_1.colLetterToNumber)(node.end.col);
161
+ const top = Math.min(startRow, endRow);
162
+ const bottom = Math.max(startRow, endRow);
163
+ const left = Math.min(startCol, endCol);
164
+ const right = Math.max(startCol, endCol);
165
+ // 3D range reference: Sheet1:Sheet3!A1:B2
166
+ if (node.endSheet) {
167
+ const sheets = getSheetsInRange(ctx.snapshot, sheet, node.endSheet);
168
+ if (!sheets) {
169
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
170
+ }
171
+ const inner = (0, bound_ast_1.boundAreaRef)(sheets[0], top, left, bottom, right);
172
+ return {
173
+ kind: 6 /* BoundExprKind.Ref3D */,
174
+ sheets,
175
+ inner
176
+ };
177
+ }
178
+ return (0, bound_ast_1.boundAreaRef)(sheet, top, left, bottom, right);
179
+ }
180
+ function bindColRangeRef(node, ctx) {
181
+ const sheet = node.sheet ?? ctx.currentSheet;
182
+ const startCol = (0, address_utils_1.colLetterToNumber)(node.startCol);
183
+ const endCol = (0, address_utils_1.colLetterToNumber)(node.endCol);
184
+ const leftCol = Math.min(startCol, endCol);
185
+ const rightCol = Math.max(startCol, endCol);
186
+ // Validate sheet exists
187
+ if (!ctx.snapshot.worksheetsByName.has(sheet.toLowerCase())) {
188
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
189
+ }
190
+ // 3D col range: Sheet1:Sheet3!A:B
191
+ if (node.endSheet) {
192
+ const sheets = getSheetsInRange(ctx.snapshot, sheet, node.endSheet);
193
+ if (!sheets) {
194
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
195
+ }
196
+ // Return Ref3D wrapping an area for the full column range
197
+ const inner = (0, bound_ast_1.boundAreaRef)(sheets[0], 1, leftCol, 1048576, rightCol);
198
+ return {
199
+ kind: 6 /* BoundExprKind.Ref3D */,
200
+ sheets,
201
+ inner
202
+ };
203
+ }
204
+ return {
205
+ kind: 4 /* BoundExprKind.ColRangeRef */,
206
+ sheet,
207
+ leftCol,
208
+ rightCol
209
+ };
210
+ }
211
+ function bindRowRangeRef(node, ctx) {
212
+ const sheet = node.sheet ?? ctx.currentSheet;
213
+ const topRow = Math.min(node.startRow, node.endRow);
214
+ const bottomRow = Math.max(node.startRow, node.endRow);
215
+ // Validate sheet exists
216
+ if (!ctx.snapshot.worksheetsByName.has(sheet.toLowerCase())) {
217
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
218
+ }
219
+ // 3D row range: Sheet1:Sheet3!1:5
220
+ if (node.endSheet) {
221
+ const sheets = getSheetsInRange(ctx.snapshot, sheet, node.endSheet);
222
+ if (!sheets) {
223
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
224
+ }
225
+ const inner = (0, bound_ast_1.boundAreaRef)(sheets[0], topRow, 1, bottomRow, 16384);
226
+ return {
227
+ kind: 6 /* BoundExprKind.Ref3D */,
228
+ sheets,
229
+ inner
230
+ };
231
+ }
232
+ return {
233
+ kind: 5 /* BoundExprKind.RowRangeRef */,
234
+ sheet,
235
+ topRow,
236
+ bottomRow
237
+ };
238
+ }
239
+ // ============================================================================
240
+ // Name Binding
241
+ // ============================================================================
242
+ function bindName(name, ctx) {
243
+ // A lambda parameter (or other compile-time local) shadows any
244
+ // workbook-level defined name. Without this short-circuit,
245
+ // `LAMBDA(x, x*2)(10)` would pick up a defined name called `x` that
246
+ // resolves to a cell reference, computing the cell's value × 2
247
+ // instead of the lambda argument × 2.
248
+ if (ctx.localNames && ctx.localNames.has(name.toUpperCase())) {
249
+ return (0, bound_ast_1.boundNameExpr)(name);
250
+ }
251
+ // Try to resolve as a defined name that maps to a cell/range.
252
+ // Respects scope precedence: sheet-local > workbook-global.
253
+ const dn = (0, workbook_snapshot_1.resolveDefinedName)(ctx.snapshot.definedNames, name, ctx.currentSheet);
254
+ if (dn) {
255
+ return resolveDefinedName(dn, ctx);
256
+ }
257
+ // Unresolved — could be a LET-bound local variable, a formula-based name,
258
+ // or a truly unknown name. Return BoundNameExpr for runtime resolution.
259
+ return (0, bound_ast_1.boundNameExpr)(name);
260
+ }
261
+ function resolveDefinedName(dn, ctx) {
262
+ if (dn.ranges.length === 0) {
263
+ return (0, bound_ast_1.boundErrorLiteral)("#NAME?");
264
+ }
265
+ // Multi-area names are not supported
266
+ if (dn.ranges.length > 1) {
267
+ return (0, bound_ast_1.boundErrorLiteral)("#VALUE!");
268
+ }
269
+ const rangeStr = dn.ranges[0];
270
+ // Try to parse as a cell/range reference
271
+ const parsed = (0, address_utils_1.parseDefinedNameRange)(rangeStr);
272
+ if (parsed) {
273
+ // Single cell
274
+ if (parsed.startRow === parsed.endRow && parsed.startCol === parsed.endCol) {
275
+ return (0, bound_ast_1.boundCellRef)(parsed.sheet, parsed.startRow, parsed.startCol);
276
+ }
277
+ // Range
278
+ return (0, bound_ast_1.boundAreaRef)(parsed.sheet, Math.min(parsed.startRow, parsed.endRow), Math.min(parsed.startCol, parsed.endCol), Math.max(parsed.startRow, parsed.endRow), Math.max(parsed.startCol, parsed.endCol));
279
+ }
280
+ // The range string is a formula expression (e.g. "LAMBDA(x,y,x+y)").
281
+ // This must be resolved at runtime since it may produce a lambda or
282
+ // depend on the evaluation context. Return a BoundNameExpr.
283
+ return (0, bound_ast_1.boundNameExpr)(dn.name);
284
+ }
285
+ // ============================================================================
286
+ // Structured Reference Binding
287
+ // ============================================================================
288
+ function bindStructuredRef(tableName, columns, specials, ctx) {
289
+ // If the table name is empty (implicit @) or specials include #This Row,
290
+ // we need runtime context (current cell position) to resolve.
291
+ // Defer to the evaluator.
292
+ const needsRuntime = tableName === "" || specials.includes("#This Row");
293
+ // Find the table in the snapshot
294
+ const table = findTable(ctx.snapshot, tableName);
295
+ if (!table) {
296
+ if (needsRuntime) {
297
+ // Defer to runtime — return BoundStructuredRef
298
+ return {
299
+ kind: 15 /* BoundExprKind.StructuredRef */,
300
+ tableName,
301
+ columns: [...columns],
302
+ specials: [...specials]
303
+ };
304
+ }
305
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
306
+ }
307
+ // If #This Row is present, defer to runtime even if table is found
308
+ if (needsRuntime) {
309
+ return {
310
+ kind: 15 /* BoundExprKind.StructuredRef */,
311
+ tableName: table.table.name,
312
+ columns: [...columns],
313
+ specials: [...specials]
314
+ };
315
+ }
316
+ const resolved = resolveStructuredRefBounds(table, columns, specials);
317
+ if (!resolved) {
318
+ return (0, bound_ast_1.boundErrorLiteral)("#REF!");
319
+ }
320
+ if (resolved.top === resolved.bottom && resolved.left === resolved.right) {
321
+ return (0, bound_ast_1.boundCellRef)(resolved.sheet, resolved.top, resolved.left);
322
+ }
323
+ return (0, bound_ast_1.boundAreaRef)(resolved.sheet, resolved.top, resolved.left, resolved.bottom, resolved.right);
324
+ }
325
+ function findTable(snapshot, tableName) {
326
+ if (!tableName) {
327
+ return null;
328
+ }
329
+ // Use the pre-built tablesByName index for O(1) lookup
330
+ const resolved = snapshot.tablesByName.get(tableName.toLowerCase());
331
+ if (resolved) {
332
+ return { table: resolved.table, sheetName: resolved.sheetName };
333
+ }
334
+ return null;
335
+ }
336
+ function resolveStructuredRefBounds(tw, columns, specials) {
337
+ const t = tw.table;
338
+ const geo = (0, structured_ref_utils_1.buildTableGeometry)(t);
339
+ const colRange = (0, structured_ref_utils_1.resolveStructuredRefColumns)(columns, t, "strict");
340
+ if (colRange === "error") {
341
+ return null;
342
+ }
343
+ const rowRange = (0, structured_ref_utils_1.resolveStructuredRefRows)(specials, geo);
344
+ let rowTop;
345
+ let rowBottom;
346
+ if (rowRange === "error") {
347
+ return null;
348
+ }
349
+ else if (rowRange === "thisRow") {
350
+ // #This Row requires runtime context — use data range as static fallback
351
+ rowTop = geo.dataRowStart;
352
+ rowBottom = geo.dataRowEnd;
353
+ }
354
+ else {
355
+ rowTop = rowRange.rowTop;
356
+ rowBottom = rowRange.rowBottom;
357
+ }
358
+ return {
359
+ sheet: tw.sheetName,
360
+ top: rowTop,
361
+ left: colRange.colLeft,
362
+ bottom: rowBottom,
363
+ right: colRange.colRight
364
+ };
365
+ }
366
+ // ============================================================================
367
+ // Function Call Binding
368
+ // ============================================================================
369
+ function bindFunctionCall(name, args, ctx) {
370
+ const upperName = name.toUpperCase();
371
+ // Check for special forms (lazy evaluation)
372
+ const specialName = canonicalSpecialForm(upperName);
373
+ if (specialName) {
374
+ // LAMBDA is special: bind it into a BoundLambda if possible
375
+ if (specialName === "LAMBDA" && args.length >= 1) {
376
+ return bindLambda(args, ctx);
377
+ }
378
+ // LET has the shape LET(name, value, name, value, …, body). The
379
+ // `name` slots must be treated as pure locals, not resolved against
380
+ // workbook defined names, or e.g. a defined-name `X` pointing at
381
+ // `$A$1` would hijack `LET(X, 5, X+1)` and route the final body to
382
+ // `A1+1` instead of `5+1`. We extend `localNames` to cover every
383
+ // name slot before recursively binding the rest.
384
+ if (specialName === "LET" && args.length >= 3) {
385
+ return bindLet(args, ctx);
386
+ }
387
+ // All other special forms: bind args recursively but wrap as BoundSpecialCall
388
+ const boundArgs = args.map(arg => bind(arg, ctx));
389
+ return (0, bound_ast_1.boundSpecialCall)(specialName, boundArgs);
390
+ }
391
+ // Reference functions that need AST-level access (ROW, COLUMN, ROWS, COLUMNS)
392
+ // are bound as regular calls — the evaluator handles the AST → BoundExpr
393
+ // mapping for these since they work the same way with BoundExpr.
394
+ // Standard eager function call
395
+ const boundArgs = args.map(arg => bind(arg, ctx));
396
+ return (0, bound_ast_1.boundCall)(upperName, boundArgs);
397
+ }
398
+ /**
399
+ * Bind `LET(name1, value1, …, nameN, valueN, body)` with lexical scoping.
400
+ *
401
+ * Even-indexed slots (0, 2, 4, …) are Name AST nodes that introduce new
402
+ * locals. We add each such name to `localNames` progressively — Excel
403
+ * allows later `value_i` expressions to reference earlier LET-bound
404
+ * variables, but NOT the variable being defined on the same slot. The
405
+ * `body` (last arg) sees every local.
406
+ */
407
+ function bindLet(args, ctx) {
408
+ // args = [name1, value1, name2, value2, …, body]; length must be odd.
409
+ if (args.length < 3 || args.length % 2 === 0) {
410
+ return (0, bound_ast_1.boundErrorLiteral)("#VALUE!");
411
+ }
412
+ const locals = ctx.localNames ? new Set(ctx.localNames) : new Set();
413
+ const boundArgs = [];
414
+ for (let i = 0; i + 1 < args.length; i += 2) {
415
+ const nameNode = args[i];
416
+ if (nameNode.type !== 12 /* NodeType.Name */) {
417
+ // Not a Name-shaped slot: preserve whatever the user wrote so the
418
+ // evaluator's own LET implementation can report the error with
419
+ // better context.
420
+ boundArgs.push(bind(nameNode, ctx));
421
+ }
422
+ else {
423
+ // Bind the name slot as a runtime-resolved NameExpr rather than
424
+ // letting `bindName` eagerly pick up a workbook-level defined name.
425
+ boundArgs.push((0, bound_ast_1.boundNameExpr)(nameNode.name));
426
+ }
427
+ // Bind the value expression with locals-so-far in scope.
428
+ const valueCtx = { ...ctx, localNames: new Set(locals) };
429
+ boundArgs.push(bind(args[i + 1], valueCtx));
430
+ // The just-bound name is now available to subsequent value slots
431
+ // and to the body.
432
+ if (nameNode.type === 12 /* NodeType.Name */) {
433
+ locals.add(nameNode.name.toUpperCase());
434
+ }
435
+ }
436
+ const bodyCtx = { ...ctx, localNames: locals };
437
+ boundArgs.push(bind(args[args.length - 1], bodyCtx));
438
+ return (0, bound_ast_1.boundSpecialCall)("LET", boundArgs);
439
+ }
440
+ function bindLambda(args, ctx) {
441
+ if (args.length < 1) {
442
+ return (0, bound_ast_1.boundErrorLiteral)("#VALUE!");
443
+ }
444
+ const paramNodes = args.slice(0, -1);
445
+ const bodyNode = args[args.length - 1];
446
+ const params = [];
447
+ // Detect duplicate parameter names up front. Excel rejects
448
+ // `LAMBDA(x, x, x*2)` with #VALUE! rather than silently letting the
449
+ // second occurrence shadow the first.
450
+ const seen = new Set();
451
+ for (const pNode of paramNodes) {
452
+ if (pNode.type !== 12 /* NodeType.Name */) {
453
+ return (0, bound_ast_1.boundErrorLiteral)("#VALUE!");
454
+ }
455
+ const upper = pNode.name.toUpperCase();
456
+ if (seen.has(upper)) {
457
+ return (0, bound_ast_1.boundErrorLiteral)("#VALUE!");
458
+ }
459
+ seen.add(upper);
460
+ params.push(upper);
461
+ }
462
+ // Extend the local-name scope with the lambda's parameters so nested
463
+ // name lookups inside the body bind to runtime locals rather than
464
+ // same-named workbook defined names.
465
+ const mergedLocals = ctx.localNames ? new Set(ctx.localNames) : new Set();
466
+ for (const p of params) {
467
+ mergedLocals.add(p);
468
+ }
469
+ const bodyCtx = { ...ctx, localNames: mergedLocals };
470
+ return {
471
+ kind: 14 /* BoundExprKind.Lambda */,
472
+ params,
473
+ body: bind(bodyNode, bodyCtx)
474
+ };
475
+ }
476
+ // ============================================================================
477
+ // 3D Reference Helpers
478
+ // ============================================================================
479
+ function getSheetsInRange(snapshot, startSheet, endSheet) {
480
+ const allSheets = snapshot.worksheets;
481
+ const startIdx = allSheets.findIndex(s => s.name.toLowerCase() === startSheet.toLowerCase());
482
+ const endIdx = allSheets.findIndex(s => s.name.toLowerCase() === endSheet.toLowerCase());
483
+ if (startIdx === -1 || endIdx === -1) {
484
+ return null;
485
+ }
486
+ const lo = Math.min(startIdx, endIdx);
487
+ const hi = Math.max(startIdx, endIdx);
488
+ return allSheets.slice(lo, hi + 1).map(s => s.name);
489
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * Bound Expression AST — The output of the compilation (binding) phase.
4
+ *
5
+ * After parsing produces a raw AST, the binder resolves all static symbols:
6
+ * - Defined names → resolved cell/range references or formula expressions
7
+ * - Structured references → resolved cell/range references
8
+ * - Sheet names → validated against the snapshot
9
+ * - Function names → validated against the registry
10
+ *
11
+ * The result is a `BoundExpr` tree where every reference is resolved and
12
+ * every function call is validated. The runtime evaluator only executes
13
+ * `BoundExpr` nodes — it never needs to perform symbol resolution.
14
+ *
15
+ * ## Node Types (compile output)
16
+ *
17
+ * After binding, only these node types exist:
18
+ *
19
+ * - `BoundLiteral` — number, string, boolean, error, null (missing)
20
+ * - `BoundCellRef` — resolved cell reference (sheet + row + col)
21
+ * - `BoundAreaRef` — resolved rectangular range (sheet + bounds)
22
+ * - `BoundColRangeRef` — resolved whole-column range
23
+ * - `BoundRowRangeRef` — resolved whole-row range
24
+ * - `BoundRef3D` — resolved 3D reference (multiple sheets)
25
+ * - `BoundBinaryOp` — binary operation
26
+ * - `BoundUnaryOp` — unary operation (including @)
27
+ * - `BoundPercent` — postfix %
28
+ * - `BoundCall` — function call (eagerly evaluated args)
29
+ * - `BoundSpecialCall` — special form (IF, LET, LAMBDA, etc.) with lazy args
30
+ * - `BoundArray` — array constant {1,2;3,4}
31
+ * - `BoundNameExpr` — UNRESOLVED name (only for names that must be resolved at runtime,
32
+ * e.g. formula-based defined names that produce lambdas, or truly unknown names)
33
+ * - `BoundLambda` — LAMBDA expression (params + body)
34
+ */
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.boundLiteral = boundLiteral;
37
+ exports.boundCellRef = boundCellRef;
38
+ exports.boundAreaRef = boundAreaRef;
39
+ exports.boundCall = boundCall;
40
+ exports.boundSpecialCall = boundSpecialCall;
41
+ exports.boundNameExpr = boundNameExpr;
42
+ exports.boundErrorLiteral = boundErrorLiteral;
43
+ // ============================================================================
44
+ // Constructor Helpers
45
+ // ============================================================================
46
+ function boundLiteral(value, errorCode) {
47
+ return errorCode !== undefined
48
+ ? { kind: 1 /* BoundExprKind.Literal */, value, errorCode }
49
+ : { kind: 1 /* BoundExprKind.Literal */, value };
50
+ }
51
+ function boundCellRef(sheet, row, col) {
52
+ return { kind: 2 /* BoundExprKind.CellRef */, sheet, row, col };
53
+ }
54
+ function boundAreaRef(sheet, top, left, bottom, right) {
55
+ return { kind: 3 /* BoundExprKind.AreaRef */, sheet, top, left, bottom, right };
56
+ }
57
+ function boundCall(name, args) {
58
+ return { kind: 10 /* BoundExprKind.Call */, name, args };
59
+ }
60
+ function boundSpecialCall(name, args) {
61
+ return { kind: 11 /* BoundExprKind.SpecialCall */, name, args };
62
+ }
63
+ function boundNameExpr(name) {
64
+ return { kind: 13 /* BoundExprKind.NameExpr */, name, upperName: name.toUpperCase() };
65
+ }
66
+ function boundErrorLiteral(errorCode) {
67
+ return { kind: 1 /* BoundExprKind.Literal */, value: null, errorCode };
68
+ }