@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,137 @@
1
+ /**
2
+ * Compiled Formula — The output of the full compilation pipeline.
3
+ *
4
+ * A `CompiledFormula` packages together:
5
+ * - The original `FormulaInstance` metadata
6
+ * - The bound expression tree (from the binder)
7
+ * - Static dependency information
8
+ * - Metadata flags (volatile, dynamic refs, etc.)
9
+ *
10
+ * ## Static Dependency Extraction
11
+ *
12
+ * Dependencies are extracted from the `BoundExpr` tree. Since names and
13
+ * structured refs are already resolved by the binder, the dependency
14
+ * extraction is a simple tree walk that collects `BoundCellRef` and
15
+ * `BoundAreaRef` nodes.
16
+ *
17
+ * Runtime-dependent references (INDIRECT, OFFSET) cannot be captured
18
+ * statically — the `hasDynamicRefs` flag marks formulas that may have
19
+ * additional runtime dependencies. Those functions re-parse their dynamic
20
+ * arguments at evaluation time using their own parser invocation (the raw
21
+ * AST is not retained on the CompiledFormula).
22
+ */
23
+ import type { FormulaInstance } from "../integration/formula-instance.js";
24
+ import type { WorkbookSnapshot } from "../integration/workbook-snapshot.js";
25
+ import type { AstNode } from "../syntax/ast.js";
26
+ import type { BoundExpr } from "./bound-ast.js";
27
+ /**
28
+ * The complete compiled representation of a formula.
29
+ */
30
+ export interface CompiledFormula {
31
+ /** The original formula instance metadata. */
32
+ readonly instance: FormulaInstance;
33
+ /** The bound expression tree (the evaluator executes this). */
34
+ readonly bound: BoundExpr;
35
+ /** Statically extractable dependencies. */
36
+ readonly staticDeps: StaticDependencySet;
37
+ /** Whether this formula uses volatile functions (RAND, NOW, etc.). */
38
+ readonly isVolatile: boolean;
39
+ /** Whether this formula contains INDIRECT/OFFSET (runtime-dependent refs). */
40
+ readonly hasDynamicRefs: boolean;
41
+ /** Whether this formula contains any lambda expressions. */
42
+ readonly containsLambda: boolean;
43
+ /**
44
+ * Whether the top-level function is a known dynamic array function
45
+ * (FILTER, SORT, UNIQUE, SEQUENCE, etc.). Determined once at compile
46
+ * time — consumers should use this flag instead of re-checking the AST
47
+ * or bound expression.
48
+ */
49
+ readonly isDynamicArrayFunction: boolean;
50
+ /**
51
+ * Whether the top-level function is SUBTOTAL or AGGREGATE. When an
52
+ * outer SUBTOTAL/AGGREGATE range aggregates a cell whose formula is
53
+ * itself a SUBTOTAL/AGGREGATE call, that cell must be skipped so its
54
+ * result is not double-counted. This flag lets `buildRangeArray`
55
+ * mark those cells with the array's `subtotalMask`.
56
+ */
57
+ readonly isSubtotalOutput: boolean;
58
+ }
59
+ /**
60
+ * A single cell dependency.
61
+ */
62
+ export interface CellDep {
63
+ readonly sheet: string;
64
+ readonly row: number;
65
+ readonly col: number;
66
+ }
67
+ /**
68
+ * A rectangular area dependency.
69
+ */
70
+ export interface AreaDep {
71
+ readonly sheet: string;
72
+ readonly top: number;
73
+ readonly left: number;
74
+ readonly bottom: number;
75
+ readonly right: number;
76
+ }
77
+ /**
78
+ * All statically extractable dependencies of a formula.
79
+ */
80
+ export interface StaticDependencySet {
81
+ /** Individual cell references. */
82
+ readonly cells: readonly CellDep[];
83
+ /** Range references. */
84
+ readonly areas: readonly AreaDep[];
85
+ }
86
+ /**
87
+ * Callback to resolve a defined name into its parsed/bound expression
88
+ * for dependency extraction. Returns the bound expression if the name
89
+ * resolves to a formula, or undefined if it can't be resolved.
90
+ */
91
+ export type NameDepResolver = (name: string) => {
92
+ deps: StaticDependencySet;
93
+ hasDynamicRefs: boolean;
94
+ /**
95
+ * Whether the defined-name's formula (transitively) uses a volatile
96
+ * function like NOW/RAND/OFFSET/INDIRECT. The resolver must propagate
97
+ * this so the OUTER formula inherits volatility — otherwise the
98
+ * session result cache would hold stale values across calc runs.
99
+ */
100
+ isVolatile: boolean;
101
+ } | undefined;
102
+ /**
103
+ * Extract static dependencies from a bound expression tree.
104
+ *
105
+ * @param expr - The bound expression tree to analyze
106
+ * @param snapshot - Optional snapshot for resolving structured references
107
+ * @param nameResolver - Optional resolver for formula-based defined name dependencies
108
+ */
109
+ export declare function extractStaticDeps(expr: BoundExpr, snapshot?: WorkbookSnapshot, nameResolver?: NameDepResolver): StaticDependencySet;
110
+ /**
111
+ * Check if the formula's top-level expression is a known dynamic array
112
+ * function. Checks both the raw AST (for prefixed names like `_XLFN.FILTER`)
113
+ * and the bound expression (for the canonical uppercase name).
114
+ */
115
+ export declare function detectDynamicArrayFunction(ast: AstNode, bound: BoundExpr): boolean;
116
+ /**
117
+ * Check if the formula's top-level expression is SUBTOTAL or AGGREGATE.
118
+ *
119
+ * Excel's SUBTOTAL/AGGREGATE functions deliberately skip any cell whose
120
+ * own source formula is itself a SUBTOTAL or AGGREGATE call — this is
121
+ * what makes the classic "totals row inside a filtered range" case not
122
+ * double-count. `buildRangeArray` reads this flag off the compiled
123
+ * formula to decide whether to set `subtotalMask[r][c]`.
124
+ */
125
+ export declare function detectSubtotalOutput(ast: AstNode, bound: BoundExpr): boolean;
126
+ /**
127
+ * Analyze a bound expression for volatile functions and dynamic references.
128
+ *
129
+ * @param nameResolver - Optional; if a NameExpr resolves to a formula-based
130
+ * defined name containing INDIRECT/OFFSET, the outer formula inherits
131
+ * `hasDynamicRefs = true`.
132
+ */
133
+ export declare function analyzeExpr(expr: BoundExpr, nameResolver?: NameDepResolver): {
134
+ isVolatile: boolean;
135
+ hasDynamicRefs: boolean;
136
+ containsLambda: boolean;
137
+ };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Dependency Graph for Formula Calculation
3
+ *
4
+ * Builds a dependency graph from compiled formulas' static dependencies,
5
+ * then produces a topological evaluation order with circular reference
6
+ * detection.
7
+ *
8
+ * Key exports:
9
+ * - `buildDependencyGraphFromDeps()` — build graph from CompiledFormula static deps
10
+ * - `topologicalSort()` — produce evaluation order, detecting circular refs
11
+ */
12
+ /**
13
+ * The dependency graph structure.
14
+ *
15
+ * - `dependsOn`: formula cell key → set of cell keys it reads from
16
+ * - `dependedBy`: cell key → set of formula cell keys that read from it
17
+ * - `formulaKeys`: ordered list of all formula cell keys
18
+ * - `circularKeys`: set of formula cell keys involved in circular references
19
+ */
20
+ export interface DependencyGraph {
21
+ /** Forward edges: formula → cells it depends on */
22
+ readonly dependsOn: ReadonlyMap<string, ReadonlySet<string>>;
23
+ /** Reverse edges: cell → formulas that depend on it */
24
+ readonly dependedBy: ReadonlyMap<string, ReadonlySet<string>>;
25
+ /** All formula cell keys in insertion order */
26
+ readonly formulaKeys: readonly string[];
27
+ /** Formula cell keys that are part of a circular reference cycle */
28
+ readonly circularKeys: ReadonlySet<string>;
29
+ }
30
+ /**
31
+ * Build a dependency graph from compiled formulas' static dependencies.
32
+ *
33
+ * Operates on the already-resolved `StaticDependencySet` from each compiled
34
+ * formula. Since names and structured references are already resolved by
35
+ * the binder, the dependency edges are complete.
36
+ *
37
+ * @param compiled - Map from formula cell key to compiled formula with static deps
38
+ * @param producerMap - Optional map from cell key → formula key that produces
39
+ * that cell's value (via CSE distribution or dynamic-array spill). Allows
40
+ * dependency edges to be added to the producer even when the target cell
41
+ * isn't itself a formula.
42
+ * @returns The complete dependency graph
43
+ */
44
+ export declare function buildDependencyGraphFromDeps(compiled: ReadonlyMap<string, {
45
+ instance: {
46
+ sheetName: string;
47
+ row: number;
48
+ col: number;
49
+ isDynamicArray?: boolean;
50
+ };
51
+ /**
52
+ * Whether this formula's top-level function is a known dynamic-
53
+ * array producer (SEQUENCE / FILTER / SORT / …). Used to collapse
54
+ * downstream `A1:A5`-style range dependencies into a single edge
55
+ * on the master so dependency ordering stays correct on the first
56
+ * calc pass (before ghost cells exist in the snapshot).
57
+ */
58
+ isDynamicArrayFunction?: boolean;
59
+ staticDeps: {
60
+ cells: readonly {
61
+ sheet: string;
62
+ row: number;
63
+ col: number;
64
+ }[];
65
+ areas: readonly {
66
+ sheet: string;
67
+ top: number;
68
+ left: number;
69
+ bottom: number;
70
+ right: number;
71
+ }[];
72
+ };
73
+ }>, producerMap?: ReadonlyMap<string, string>): DependencyGraph;
74
+ /**
75
+ * Merge runtime-discovered dynamic dependencies into a dependency graph.
76
+ *
77
+ * After evaluating formulas that contain INDIRECT/OFFSET, the runtime
78
+ * dependency recorder has collected the actual cell accesses. This function
79
+ * incorporates those dynamic edges into the graph and re-detects cycles.
80
+ *
81
+ * Returns a new graph if edges were added, or the original graph if no
82
+ * dynamic deps were recorded.
83
+ */
84
+ export declare function mergeDynamicDeps(graph: DependencyGraph, dynamicDeps: ReadonlyMap<string, ReadonlySet<string>>): {
85
+ graph: DependencyGraph;
86
+ changed: boolean;
87
+ };
88
+ /**
89
+ * Produce a topological evaluation order for formula cells using Kahn's algorithm.
90
+ * Cells with no dependencies are evaluated first. Circular references are
91
+ * appended at the end in their original order.
92
+ */
93
+ export declare function topologicalSort(graph: DependencyGraph): string[];
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Shared utilities for structured reference (table) row-range resolution.
3
+ *
4
+ * The row-range logic for structured references is needed in three places:
5
+ * - binder (compile-time range resolution)
6
+ * - compiled-formula (static dependency extraction)
7
+ * - evaluator (runtime evaluation)
8
+ *
9
+ * This module provides the canonical implementation to avoid triplication.
10
+ */
11
+ /**
12
+ * Minimum subset of table snapshot fields required to derive geometry
13
+ * and resolve structured-reference columns.
14
+ *
15
+ * Declared structurally (not as a nominal import of `TableSnapshot`) so
16
+ * this module stays dependency-free and can serve both compile- and
17
+ * runtime-side callers that carry their own table-shape types.
18
+ */
19
+ export interface TableLike {
20
+ readonly topLeft: {
21
+ readonly row: number;
22
+ readonly col: number;
23
+ };
24
+ readonly dataRowCount: number;
25
+ readonly hasHeaderRow: boolean;
26
+ readonly hasTotalsRow: boolean;
27
+ readonly columns: readonly {
28
+ readonly name: string;
29
+ }[];
30
+ }
31
+ /**
32
+ * Table geometry needed for structured ref resolution.
33
+ */
34
+ export interface TableGeometry {
35
+ /** Top-left row of the table (including header if present). */
36
+ readonly topLeftRow: number;
37
+ /** First row of the data body. */
38
+ readonly dataRowStart: number;
39
+ /** Last row of the data body. */
40
+ readonly dataRowEnd: number;
41
+ /** Whether the table has a header row. */
42
+ readonly hasHeaderRow: boolean;
43
+ /** Whether the table has a totals row. */
44
+ readonly hasTotalsRow: boolean;
45
+ }
46
+ /**
47
+ * Derive `TableGeometry` from a table's snapshot fields.
48
+ *
49
+ * The data row range excludes the header (if any) but also excludes the
50
+ * totals row — totals, when present, occupy `dataRowEnd + 1`.
51
+ */
52
+ export declare function buildTableGeometry(table: TableLike): TableGeometry;
53
+ /**
54
+ * Resolve a list of structured-reference column names to a contiguous
55
+ * column range `[colLeft, colRight]` in absolute sheet coordinates.
56
+ *
57
+ * @param columns - Requested column names (case-insensitive match).
58
+ * @param table - Table whose columns are searched.
59
+ * @param mode -
60
+ * - `"strict"` — return `"error"` if any name is missing (used by
61
+ * binder and evaluator — unknown columns are `#REF!` errors).
62
+ * - `"permissive"` — ignore missing names; if ALL names are missing,
63
+ * falls back to the full table width (used by static-deps extraction,
64
+ * where a conservative over-estimate is acceptable).
65
+ * @returns `{ colLeft, colRight }`, or `"error"` in strict mode when a
66
+ * column name is not found. If `columns` is empty, returns the full
67
+ * table width.
68
+ */
69
+ export declare function resolveStructuredRefColumns(columns: readonly string[], table: TableLike, mode: "strict" | "permissive"): {
70
+ colLeft: number;
71
+ colRight: number;
72
+ } | "error";
73
+ /**
74
+ * Result of resolving structured reference specials to a row range.
75
+ *
76
+ * - `{rowTop, rowBottom}` — resolved range
77
+ * - `"thisRow"` — the `#This Row` special was used; caller must resolve
78
+ * using the current cell address
79
+ * - `"error"` — invalid special combination (e.g., #Totals on a table
80
+ * without a totals row)
81
+ */
82
+ export type StructuredRefRowRange = {
83
+ rowTop: number;
84
+ rowBottom: number;
85
+ } | "thisRow" | "error";
86
+ /**
87
+ * Resolve structured reference specials to a row range.
88
+ *
89
+ * This is the single source of truth for the mapping from
90
+ * `#All`, `#Headers`, `#Data`, `#Totals`, `#This Row` (and their
91
+ * combinations) to concrete row numbers.
92
+ */
93
+ export declare function resolveStructuredRefRows(specials: readonly string[], geo: TableGeometry): StructuredRefRowRange;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Formula-syntax probe slot.
3
+ *
4
+ * ## What this is
5
+ *
6
+ * `DefinedNames` (in the excel module) needs a way to tell whether a raw
7
+ * defined-name text like `OFFSET(Sheet1!$A$1,0,0,3,1)` is a parseable
8
+ * formula or opaque content to preserve verbatim. The only authoritative
9
+ * answer comes from the formula tokenizer + parser, which ship in the
10
+ * `@cj-tech-master/excelts/formula` subpath and are an opt-in
11
+ * dependency.
12
+ *
13
+ * This file is a tiny passive registration slot — a single `let` with
14
+ * a getter/setter pair — carrying **no** formula-engine code. Importing
15
+ * `DefinedNames` pulls in this slot (~0.5 KB minified) but never drags
16
+ * in the tokenizer, parser, or evaluator.
17
+ *
18
+ * ## Classification semantics
19
+ *
20
+ * - **No probe installed** (default): `DefinedNames` classifies any
21
+ * non-range, non-wrapper text as **opaque**. The `rawText` is
22
+ * preserved so XLSX round-trip bytes are stable; the entry simply
23
+ * cannot be evaluated — which is correct, because no formula engine
24
+ * is available anyway.
25
+ *
26
+ * - **Probe installed** (after `installFormulaEngine()`): `DefinedNames`
27
+ * classifies strictly. Parseable text becomes `formula`, unparseable
28
+ * text becomes `opaque`.
29
+ *
30
+ * ## Why the slot lives in the formula module
31
+ *
32
+ * Module dependency direction: `excel` may import from `formula`
33
+ * (layer 4 → layer 3), but `formula` must not import from `excel`. The
34
+ * probe slot is a *formula-module concept* (it wraps a formula
35
+ * tokenizer+parser) that excel consults; keeping it here preserves the
36
+ * one-way dependency.
37
+ *
38
+ * ## Construction-time injection is also supported
39
+ *
40
+ * `Workbook` and `DefinedNames` each accept an explicit
41
+ * `formulaSyntaxProbe` option. That is the preferred API for callers
42
+ * who want deterministic, per-instance behaviour (e.g. a test that
43
+ * needs a specific probe without touching process-global state). The
44
+ * default-probe slot here is the convenience layer for
45
+ * `installFormulaEngine()` — call it once at startup and every
46
+ * subsequent `new Workbook()` picks up strict classification
47
+ * automatically.
48
+ *
49
+ * ## Lookup timing
50
+ *
51
+ * `DefinedNames` reads the default probe lazily, at the moment `model`
52
+ * is assigned (i.e. during XLSX parsing). This means the common
53
+ * sequence
54
+ *
55
+ * ```ts
56
+ * const wb = new Workbook();
57
+ * installFormulaEngine(); // later
58
+ * await wb.xlsx.load(buffer); // sees the installed probe
59
+ * ```
60
+ *
61
+ * works correctly — the probe installed before `load()` is the one
62
+ * used, regardless of when `Workbook` itself was constructed.
63
+ */
64
+ export type SyntaxProbe = (text: string) => boolean;
65
+ /**
66
+ * Install (or clear) the process-wide default syntax probe.
67
+ *
68
+ * Called from `installFormulaEngine()` in `./install`. Passing `null`
69
+ * uninstalls the probe — symmetric with the formula-engine registry and
70
+ * useful for tests that exercise the "no probe" classification path.
71
+ */
72
+ export declare function setDefaultSyntaxProbe(probe: SyntaxProbe | null): void;
73
+ /**
74
+ * Retrieve the currently-installed default probe, or `null` if none is
75
+ * installed. Consumers (chiefly `DefinedNames`) should treat `null` as
76
+ * a signal to use conservative (opaque) classification rather than
77
+ * guessing.
78
+ */
79
+ export declare function getDefaultSyntaxProbe(): SyntaxProbe | null;
@@ -0,0 +1,4 @@
1
+ /** Set the workbook-wide `date1904` mode for the current calculation session. */
2
+ export declare function setDate1904(v: boolean): void;
3
+ /** Read the workbook-wide `date1904` mode. */
4
+ export declare function isDate1904(): boolean;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Shared helpers for native function implementations.
3
+ *
4
+ * Centralizes small utilities that were previously duplicated across multiple
5
+ * function files (math, statistical, financial, text, date, engineering,
6
+ * conditional, dynamic-array, database, lookup). None of these change runtime
7
+ * semantics — they are the canonical extractions of the identical helpers that
8
+ * appeared in several modules.
9
+ */
10
+ import type { RuntimeValue, ScalarValue, NumberValue, ErrorValue, ArrayValue } from "../runtime/values.js";
11
+ /**
12
+ * Return the error value if `v` (as a scalar, extracted via `topLeft`) is an
13
+ * error; otherwise return `null`. Used by text / date / engineering functions
14
+ * for the standard "propagate first-arg error" pattern.
15
+ */
16
+ export declare function checkError(v: RuntimeValue): ErrorValue | null;
17
+ /**
18
+ * Coerce a single RuntimeValue argument to a number. Applies `topLeft` first
19
+ * so that a 1×1 (or arbitrary) array yields its top-left scalar before
20
+ * numeric coercion. Matches the semantics formerly found as `argToNumber` in
21
+ * `math.ts` and `numArg(args, idx)` in `statistical.ts`.
22
+ */
23
+ export declare function argToNumber(arg: RuntimeValue): NumberValue | ErrorValue;
24
+ /**
25
+ * Flatten a list of arguments into a sequence of numeric values (or errors).
26
+ *
27
+ * Array arguments contribute only their `Number` and `Error` cells — booleans,
28
+ * strings, and blanks inside arrays are skipped (Excel range semantics).
29
+ * Direct scalar arguments are coerced via `toNumberRV`, except for direct
30
+ * `Blank` scalars which are skipped (Excel aggregate semantics).
31
+ *
32
+ * Returns a list of `NumberValue | ErrorValue`. Callers that need raw
33
+ * `number[]` after an error check should map `.value` themselves.
34
+ */
35
+ export declare function flattenNumbers(args: RuntimeValue[]): (NumberValue | ErrorValue)[];
36
+ /**
37
+ * Flatten all cells from the arguments into a flat list of ScalarValue,
38
+ * preserving every cell (including blanks, errors, booleans, strings).
39
+ * Direct scalar arguments are projected via `topLeft`.
40
+ */
41
+ export declare function flattenAll(args: RuntimeValue[]): ScalarValue[];
42
+ /**
43
+ * Return the first `ErrorValue` in a list of `NumberValue | ErrorValue`,
44
+ * or `null` if none is present.
45
+ */
46
+ export declare function firstError(values: readonly (NumberValue | ErrorValue)[]): ErrorValue | null;
47
+ /**
48
+ * Narrow a RuntimeValue to an ArrayValue, returning `null` if it is not an
49
+ * array. Used by conditional / database / lookup / dynamic-array families.
50
+ */
51
+ export declare function asArray(v: RuntimeValue): ArrayValue | null;
52
+ /**
53
+ * Safe cell accessor for ArrayValue — returns `BLANK` for out-of-bounds (r, c).
54
+ */
55
+ export declare function getCell(arr: ArrayValue, r: number, c: number): ScalarValue;
56
+ /**
57
+ * Return `true` if `s` contains an unescaped `*` or `?`. Excel uses `~` as
58
+ * the escape character, so `~*` and `~?` are literals while `*` and `?` at
59
+ * any other position are wildcards. `~~` is an escaped tilde.
60
+ *
61
+ * Centralised here so every wildcard-consuming function (SEARCH, MATCH,
62
+ * XLOOKUP, SUMIF/COUNTIF/…) agrees on whether a criterion should trigger
63
+ * the wildcard code path.
64
+ */
65
+ export declare function hasUnescapedWildcard(s: string): boolean;
66
+ /**
67
+ * Convert an Excel wildcard pattern to a JavaScript regex source. Rules:
68
+ * `*` → `.*`
69
+ * `?` → `.`
70
+ * `~*` → literal `*`
71
+ * `~?` → literal `?`
72
+ * `~~` → literal `~`
73
+ * `~x` → literal `x` (any other character after `~` is treated literally,
74
+ * matching Excel's tolerant behaviour)
75
+ * everything else → regex-escaped literal
76
+ *
77
+ * Callers typically wrap the result in `^…$` and use the `i` flag for
78
+ * case-insensitive matching.
79
+ */
80
+ export declare function excelWildcardToRegex(s: string): string;
81
+ /**
82
+ * Strip `~` escape characters from an Excel criteria string so the remaining
83
+ * text can be used for a literal comparison. `~*` → `*`, `~?` → `?`,
84
+ * `~~` → `~`, etc. Only used when the caller has already determined that the
85
+ * pattern contains no unescaped wildcards.
86
+ */
87
+ export declare function unescapeExcelWildcard(s: string): string;
88
+ /**
89
+ * Replace every cell marked by the array's `subtotalMask` with BLANK so an
90
+ * outer SUBTOTAL/AGGREGATE call does not double-count the inner aggregate's
91
+ * result. Only ArrayValue args carrying a mask are rewritten; scalars and
92
+ * arrays without masks pass through unchanged.
93
+ *
94
+ * Excel behavior: SUBTOTAL and AGGREGATE deliberately skip any cell whose
95
+ * own formula is itself SUBTOTAL or AGGREGATE — this is how the classic
96
+ * "totals row inside a filtered range" case works without double-counting.
97
+ */
98
+ export declare function stripSubtotalMaskedCells(args: RuntimeValue[]): RuntimeValue[];
99
+ /**
100
+ * Replace every cell in a hidden row with BLANK so aggregate functions
101
+ * drop them during flattening. Callers: SUBTOTAL's 1xx-variant codes
102
+ * (101-111) and AGGREGATE with option 5 or 7.
103
+ *
104
+ * Only ArrayValue args carrying a hiddenRowMask are rewritten.
105
+ */
106
+ export declare function stripHiddenRowCells(args: RuntimeValue[]): RuntimeValue[];
107
+ /**
108
+ * Replace every error cell inside ArrayValue args with BLANK so
109
+ * aggregate functions simply skip them during flattening. Callers:
110
+ * AGGREGATE with option 2, 3, 6, or 7.
111
+ *
112
+ * Direct scalar error args are left alone — AGGREGATE's caller
113
+ * already passes them as scalars; our aggregators will surface them
114
+ * as-is, which matches Excel when a direct literal is an error.
115
+ *
116
+ * This is distinct from the standard error-propagation path: arrays
117
+ * that contain errors normally propagate those errors out of the
118
+ * aggregate. With option 2/3/6/7, errors inside the *arrays* are
119
+ * deliberately ignored.
120
+ */
121
+ export declare function stripErrorCells(args: RuntimeValue[]): RuntimeValue[];
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Conditional Aggregate Functions — Native RuntimeValue Implementation
3
+ */
4
+ import type { RuntimeValue, ScalarValue } from "../runtime/values.js";
5
+ /**
6
+ * Build a criteria predicate from a ScalarValue.
7
+ * Matches Excel SUMIF/COUNTIF criteria semantics:
8
+ * - number → exact numeric match
9
+ * - boolean → exact boolean match
10
+ * - string with operator prefix (">5", "<=10", "<>abc") → comparison
11
+ * - string with wildcards (* ?) → pattern match
12
+ * - plain string → case-insensitive exact match (or numeric if parseable)
13
+ */
14
+ export declare function buildCriteriaPredicateRV(criteria: ScalarValue): (v: ScalarValue) => boolean;
15
+ /**
16
+ * Scan a criteria string for an unescaped `*` or `?`. A backslash-style
17
+ * escape in Excel is `~`; so `~*` and `~?` are literals, while `*` and `?`
18
+ * on their own or at a position not preceded by `~` count as wildcards.
19
+ */
20
+ export declare function fnSUMIF(args: RuntimeValue[]): RuntimeValue;
21
+ export declare function fnSUMIFS(args: RuntimeValue[]): RuntimeValue;
22
+ export declare function fnCOUNTIF(args: RuntimeValue[]): RuntimeValue;
23
+ export declare function fnCOUNTIFS(args: RuntimeValue[]): RuntimeValue;
24
+ export declare function fnAVERAGEIF(args: RuntimeValue[]): RuntimeValue;
25
+ export declare function fnAVERAGEIFS(args: RuntimeValue[]): RuntimeValue;
26
+ export declare function fnMAXIFS(args: RuntimeValue[]): RuntimeValue;
27
+ export declare function fnMINIFS(args: RuntimeValue[]): RuntimeValue;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Database Functions — Native RuntimeValue Implementation
3
+ */
4
+ import type { RuntimeValue } from "../runtime/values.js";
5
+ export declare function fnDSUM(args: RuntimeValue[]): RuntimeValue;
6
+ export declare function fnDAVERAGE(args: RuntimeValue[]): RuntimeValue;
7
+ export declare function fnDCOUNT(args: RuntimeValue[]): RuntimeValue;
8
+ export declare function fnDMAX(args: RuntimeValue[]): RuntimeValue;
9
+ export declare function fnDMIN(args: RuntimeValue[]): RuntimeValue;
10
+ export declare function fnDPRODUCT(args: RuntimeValue[]): RuntimeValue;
11
+ export declare function fnDGET(args: RuntimeValue[]): RuntimeValue;
12
+ /**
13
+ * DCOUNTA(database, field, criteria) — count non-empty cells that match
14
+ * the criteria, in the specified field. Unlike DCOUNT (numeric-only),
15
+ * DCOUNTA counts any non-blank cell including text and booleans.
16
+ */
17
+ export declare function fnDCOUNTA(args: RuntimeValue[]): RuntimeValue;
18
+ /**
19
+ * DSTDEV(database, field, criteria) — sample standard deviation of
20
+ * numeric cells matching criteria in the specified field.
21
+ */
22
+ export declare function fnDSTDEV(args: RuntimeValue[]): RuntimeValue;
23
+ /**
24
+ * DSTDEVP(database, field, criteria) — population standard deviation
25
+ * of numeric cells matching criteria.
26
+ */
27
+ export declare function fnDSTDEVP(args: RuntimeValue[]): RuntimeValue;
28
+ /**
29
+ * DVAR(database, field, criteria) — sample variance of matching numeric
30
+ * cells.
31
+ */
32
+ export declare function fnDVAR(args: RuntimeValue[]): RuntimeValue;
33
+ /**
34
+ * DVARP(database, field, criteria) — population variance of matching
35
+ * numeric cells.
36
+ */
37
+ export declare function fnDVARP(args: RuntimeValue[]): RuntimeValue;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Date / Time Functions — Native RuntimeValue implementation.
3
+ *
4
+ * All Date objects returned by `excelToDate()` represent an Excel serial on
5
+ * the UTC timeline (midnight UTC for the corresponding date). Consequently
6
+ * every field accessor must be the UTC variant (`getUTCFullYear`,
7
+ * `getUTCMonth`, …) and every `Date` constructed from y/m/d components must
8
+ * be built with `Date.UTC(...)`. Using local-time accessors would make
9
+ * results depend on the host timezone — e.g. `YEAR(DATE(2024,1,1))` would
10
+ * return 2023 when evaluated on a machine west of UTC at midnight UTC.
11
+ *
12
+ * Exceptions (intentionally use local time):
13
+ * - `TODAY` / `NOW` — read the user's wall clock, which is genuinely in the
14
+ * local timezone. The Excel serial is then constructed using
15
+ * `Date.UTC(year, month, day)` so that the resulting serial round-trips
16
+ * correctly through `excelToDate()`.
17
+ */
18
+ import type { RuntimeValue } from "../runtime/values.js";
19
+ type NativeFn = (args: RuntimeValue[]) => RuntimeValue;
20
+ /**
21
+ * TODAY — today's date (at the user's local timezone).
22
+ *
23
+ * The user's concept of "today" is based on their wall clock, so we read
24
+ * local-time fields from `new Date()`. The resulting y/m/d components are
25
+ * then packed into a UTC serial so downstream date arithmetic is consistent.
26
+ */
27
+ export declare const fnTODAY: NativeFn;
28
+ /**
29
+ * NOW — current date and time.
30
+ *
31
+ * Excel stores the result as an untimezoned serial, but the user expects
32
+ * their local wall-clock reading. `dateToExcel(new Date())` effectively
33
+ * takes `Date.now()` in UTC-ms; any conversion to the user's timezone
34
+ * would require tz metadata we do not have. We therefore keep the current
35
+ * UTC-ms based conversion, matching historical behaviour.
36
+ */
37
+ export declare const fnNOW: NativeFn;
38
+ export declare const fnYEAR: NativeFn;
39
+ export declare const fnMONTH: NativeFn;
40
+ export declare const fnDAY: NativeFn;
41
+ export declare const fnDATE: NativeFn;
42
+ export declare const fnTIME: NativeFn;
43
+ export declare const fnHOUR: NativeFn;
44
+ export declare const fnMINUTE: NativeFn;
45
+ export declare const fnSECOND: NativeFn;
46
+ export declare const fnWEEKDAY: NativeFn;
47
+ export declare const fnEOMONTH: NativeFn;
48
+ export declare const fnEDATE: NativeFn;
49
+ export declare const fnDATEDIF: NativeFn;
50
+ export declare const fnDAYS: NativeFn;
51
+ export declare const fnISOWEEKNUM: NativeFn;
52
+ export declare const fnWEEKNUM: NativeFn;
53
+ export declare const fnNETWORKDAYS: NativeFn;
54
+ export declare const fnWORKDAY: NativeFn;
55
+ export declare const fnYEARFRAC: NativeFn;
56
+ export declare const fnDATEVALUE: NativeFn;
57
+ export declare const fnTIMEVALUE: NativeFn;
58
+ export declare const fnDAYS360: NativeFn;
59
+ export declare const fnNETWORKDAYS_INTL: NativeFn;
60
+ export declare const fnWORKDAY_INTL: NativeFn;
61
+ export {};