@allyhub/sdk 0.6.0 → 0.7.1

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 (262) hide show
  1. package/dist/define.d.ts +4 -0
  2. package/dist/define.js +1 -1
  3. package/dist/node_modules/@allyhub-next/audio/dist/node/index.d.ts +1 -1
  4. package/dist/node_modules/@allyhub-next/audio/dist/node/index.js +1 -1
  5. package/dist/node_modules/@allyhub-next/audio/dist/node/master.d.ts +4 -0
  6. package/dist/node_modules/@allyhub-next/audio/dist/node/master.js +1 -1
  7. package/dist/node_modules/@allyhub-next/audio/package.json +1 -1
  8. package/dist/node_modules/@allyhub-next/chart/dist/chart-xml.js +2 -2
  9. package/dist/node_modules/@allyhub-next/chart/dist/chart.d.ts +14 -5
  10. package/dist/node_modules/@allyhub-next/chart/dist/chart.js +1 -1
  11. package/dist/node_modules/@allyhub-next/chart/package.json +1 -1
  12. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.d.ts +205 -0
  13. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.js +2 -0
  14. package/dist/node_modules/@allyhub-next/formats/dist/data/script.d.ts +4 -1
  15. package/dist/node_modules/@allyhub-next/formats/dist/data/script.js +1 -1
  16. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.d.ts +69 -18
  17. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.js +1 -1
  18. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.d.ts +847 -116
  19. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.js +1 -1
  20. package/dist/node_modules/@allyhub-next/formats/dist/data/website.d.ts +20 -0
  21. package/dist/node_modules/@allyhub-next/formats/dist/data/website.js +2 -0
  22. package/dist/node_modules/@allyhub-next/formats/dist/index.d.ts +3 -0
  23. package/dist/node_modules/@allyhub-next/formats/dist/index.js +1 -1
  24. package/dist/node_modules/@allyhub-next/formats/dist/items.d.ts +1 -1
  25. package/dist/node_modules/@allyhub-next/formats/dist/items.js +1 -1
  26. package/dist/node_modules/@allyhub-next/formats/dist/media-type.d.ts +3 -0
  27. package/dist/node_modules/@allyhub-next/formats/dist/media-type.js +2 -0
  28. package/dist/node_modules/@allyhub-next/formats/dist/schemas.d.ts +501 -38
  29. package/dist/node_modules/@allyhub-next/formats/dist/schemas.js +1 -1
  30. package/dist/node_modules/@allyhub-next/formats/dist/strict.d.ts +2 -0
  31. package/dist/node_modules/@allyhub-next/formats/dist/strict.js +1 -1
  32. package/dist/node_modules/@allyhub-next/formats/package.json +2 -1
  33. package/dist/node_modules/@allyhub-next/ooxml/LICENSE +241 -0
  34. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.d.ts +31 -0
  35. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.js +2 -0
  36. package/dist/node_modules/@allyhub-next/ooxml/dist/color.d.ts +33 -0
  37. package/dist/node_modules/@allyhub-next/ooxml/dist/color.js +2 -0
  38. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.d.ts +13 -0
  39. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.js +2 -0
  40. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.d.ts +79 -0
  41. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.js +2 -0
  42. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.d.ts +132 -0
  43. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.js +2 -0
  44. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.d.ts +28 -0
  45. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.js +2 -0
  46. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.d.ts +4708 -0
  47. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.js +2 -0
  48. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.d.ts +57 -0
  49. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.js +2 -0
  50. package/dist/node_modules/@allyhub-next/ooxml/dist/index.d.ts +10 -0
  51. package/dist/node_modules/@allyhub-next/ooxml/dist/index.js +2 -0
  52. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.d.ts +12 -0
  53. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.js +2 -0
  54. package/dist/node_modules/@allyhub-next/ooxml/dist/node.d.ts +111 -0
  55. package/dist/node_modules/@allyhub-next/ooxml/dist/node.js +2 -0
  56. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.d.ts +45 -0
  57. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.js +2 -0
  58. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.d.ts +48 -0
  59. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.js +2 -0
  60. package/dist/node_modules/@allyhub-next/ooxml/dist/report.d.ts +45 -0
  61. package/dist/node_modules/@allyhub-next/ooxml/dist/report.js +2 -0
  62. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.d.ts +28 -0
  63. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.js +2 -0
  64. package/dist/node_modules/@allyhub-next/ooxml/package.json +26 -0
  65. package/dist/node_modules/@allyhub-next/protocol/dist/account.d.ts +338 -0
  66. package/dist/node_modules/@allyhub-next/protocol/dist/account.js +2 -0
  67. package/dist/node_modules/@allyhub-next/protocol/dist/auth.d.ts +12 -13
  68. package/dist/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  69. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.d.ts +35 -0
  70. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.js +2 -0
  71. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.d.ts +101 -32
  72. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.js +1 -1
  73. package/dist/node_modules/@allyhub-next/protocol/dist/editor.d.ts +79 -5
  74. package/dist/node_modules/@allyhub-next/protocol/dist/editor.js +1 -1
  75. package/dist/node_modules/@allyhub-next/protocol/dist/files.d.ts +2 -2
  76. package/dist/node_modules/@allyhub-next/protocol/dist/index.d.ts +6 -0
  77. package/dist/node_modules/@allyhub-next/protocol/dist/index.js +1 -1
  78. package/dist/node_modules/@allyhub-next/protocol/dist/notes.d.ts +21 -0
  79. package/dist/node_modules/@allyhub-next/protocol/dist/notes.js +1 -1
  80. package/dist/node_modules/@allyhub-next/protocol/dist/open.d.ts +13 -0
  81. package/dist/node_modules/@allyhub-next/protocol/dist/open.js +2 -0
  82. package/dist/node_modules/@allyhub-next/protocol/dist/registry.d.ts +73 -59
  83. package/dist/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  84. package/dist/node_modules/@allyhub-next/protocol/dist/routes.d.ts +1 -1
  85. package/dist/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  86. package/dist/node_modules/@allyhub-next/protocol/dist/shares.d.ts +115 -0
  87. package/dist/node_modules/@allyhub-next/protocol/dist/shares.js +2 -0
  88. package/dist/node_modules/@allyhub-next/protocol/dist/sites.d.ts +293 -0
  89. package/dist/node_modules/@allyhub-next/protocol/dist/sites.js +2 -0
  90. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.d.ts +396 -0
  91. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.js +2 -0
  92. package/dist/node_modules/@allyhub-next/protocol/dist/teams.d.ts +27 -9
  93. package/dist/node_modules/@allyhub-next/protocol/dist/teams.js +1 -1
  94. package/dist/node_modules/@allyhub-next/protocol/dist/tools.d.ts +53 -14
  95. package/dist/node_modules/@allyhub-next/protocol/dist/tools.js +1 -1
  96. package/dist/node_modules/@allyhub-next/protocol/package.json +2 -1
  97. package/dist/node_modules/@allyhub-next/runtimes/dist/download.d.ts +19 -1
  98. package/dist/node_modules/@allyhub-next/runtimes/dist/download.js +1 -1
  99. package/dist/node_modules/@allyhub-next/runtimes/dist/index.d.ts +2 -2
  100. package/dist/node_modules/@allyhub-next/runtimes/dist/index.js +1 -1
  101. package/dist/node_modules/@allyhub-next/runtimes/dist/lock.d.ts +6 -0
  102. package/dist/node_modules/@allyhub-next/runtimes/dist/lock.js +1 -1
  103. package/dist/node_modules/@allyhub-next/runtimes/dist/packages.d.ts +19 -2
  104. package/dist/node_modules/@allyhub-next/runtimes/dist/packages.js +3 -3
  105. package/dist/node_modules/@allyhub-next/runtimes/dist/runtimes.d.ts +3 -0
  106. package/dist/node_modules/@allyhub-next/runtimes/dist/runtimes.js +3 -3
  107. package/dist/node_modules/@allyhub-next/runtimes/package.json +1 -1
  108. package/dist/node_modules/@allyhub-next/runtimes/schemas/runtimes.schema.json +25 -5
  109. package/dist/node_modules/@allyhub-next/scenery/package.json +1 -1
  110. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.d.ts +9 -3
  111. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.js +1 -1
  112. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.d.ts +5 -1
  113. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.js +1 -1
  114. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.d.ts +60 -13
  115. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.js +1 -1
  116. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/aggregate.js +1 -1
  117. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.d.ts +4 -0
  118. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.js +2 -0
  119. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/criteria.js +1 -1
  120. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/database.js +1 -1
  121. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/date.js +1 -1
  122. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.d.ts +27 -1
  123. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.js +1 -1
  124. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.d.ts +16 -0
  125. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.js +2 -0
  126. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.d.ts +18 -1
  127. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.js +1 -1
  128. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/finance.js +1 -1
  129. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.d.ts +2 -0
  130. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.js +1 -1
  131. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/info.js +1 -1
  132. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/kernels.js +1 -1
  133. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/logical.js +1 -1
  134. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/lookup.js +1 -1
  135. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/maths.js +1 -1
  136. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.d.ts +2 -0
  137. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.js +2 -0
  138. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/text.js +1 -1
  139. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.d.ts +38 -0
  140. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.js +2 -0
  141. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.d.ts +19 -0
  142. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.js +2 -0
  143. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.d.ts +49 -0
  144. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.js +2 -0
  145. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.d.ts +82 -0
  146. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.js +2 -0
  147. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.d.ts +6 -1
  148. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.js +1 -1
  149. package/dist/node_modules/@allyhub-next/sheet/dist/chart.js +1 -1
  150. package/dist/node_modules/@allyhub-next/sheet/dist/check.js +1 -1
  151. package/dist/node_modules/@allyhub-next/sheet/dist/diff.d.ts +15 -0
  152. package/dist/node_modules/@allyhub-next/sheet/dist/diff.js +1 -1
  153. package/dist/node_modules/@allyhub-next/sheet/dist/export.d.ts +29 -8
  154. package/dist/node_modules/@allyhub-next/sheet/dist/export.js +3 -4
  155. package/dist/node_modules/@allyhub-next/sheet/dist/file.js +2 -2
  156. package/dist/node_modules/@allyhub-next/sheet/dist/format.d.ts +8 -2
  157. package/dist/node_modules/@allyhub-next/sheet/dist/format.js +1 -1
  158. package/dist/node_modules/@allyhub-next/sheet/dist/html.d.ts +52 -4
  159. package/dist/node_modules/@allyhub-next/sheet/dist/html.js +43 -11
  160. package/dist/node_modules/@allyhub-next/sheet/dist/index.d.ts +7 -3
  161. package/dist/node_modules/@allyhub-next/sheet/dist/index.js +1 -1
  162. package/dist/node_modules/@allyhub-next/sheet/dist/inspect.js +1 -1
  163. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.d.ts +98 -0
  164. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.js +2 -0
  165. package/dist/node_modules/@allyhub-next/sheet/dist/structure.js +1 -1
  166. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.d.ts +32 -0
  167. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.js +2 -0
  168. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.d.ts +3 -0
  169. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.js +2 -0
  170. package/dist/node_modules/@allyhub-next/sheet/dist/values.js +1 -1
  171. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.d.ts +10 -1
  172. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.js +1 -1
  173. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.d.ts +10 -1
  174. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.js +1 -1
  175. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.d.ts +14 -4
  176. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.js +2 -2
  177. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.d.ts +11 -1
  178. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.js +36 -16
  179. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.d.ts +3 -1
  180. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.js +1 -1
  181. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.d.ts +42 -1
  182. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.js +2 -1
  183. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.d.ts +23 -0
  184. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.js +2 -0
  185. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.d.ts +2 -0
  186. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.js +1 -1
  187. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.d.ts +6 -0
  188. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.js +1 -1
  189. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.d.ts +40 -0
  190. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.js +2 -0
  191. package/dist/node_modules/@allyhub-next/sheet/package.json +1 -1
  192. package/dist/node_modules/@allyhub-next/slides-core/dist/animation.js +1 -1
  193. package/dist/node_modules/@allyhub-next/slides-core/dist/api.d.ts +59 -39
  194. package/dist/node_modules/@allyhub-next/slides-core/dist/api.js +2 -2
  195. package/dist/node_modules/@allyhub-next/slides-core/dist/capabilities.js +1 -1
  196. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.d.ts +27 -13
  197. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.js +1 -1
  198. package/dist/node_modules/@allyhub-next/slides-core/dist/check.js +1 -1
  199. package/dist/node_modules/@allyhub-next/slides-core/dist/code.d.ts +33 -0
  200. package/dist/node_modules/@allyhub-next/slides-core/dist/code.js +2 -0
  201. package/dist/node_modules/@allyhub-next/slides-core/dist/components.d.ts +31 -0
  202. package/dist/node_modules/@allyhub-next/slides-core/dist/components.js +2 -0
  203. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.d.ts +179 -16
  204. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.js +1 -1
  205. package/dist/node_modules/@allyhub-next/slides-core/dist/file.d.ts +43 -21
  206. package/dist/node_modules/@allyhub-next/slides-core/dist/file.js +3 -3
  207. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.d.ts +17 -0
  208. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.js +2 -0
  209. package/dist/node_modules/@allyhub-next/slides-core/dist/index.d.ts +5 -1
  210. package/dist/node_modules/@allyhub-next/slides-core/dist/index.js +1 -1
  211. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.d.ts +6 -0
  212. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.js +2 -0
  213. package/dist/node_modules/@allyhub-next/slides-core/dist/measure.js +1 -1
  214. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.d.ts +58 -0
  215. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.js +2 -0
  216. package/dist/node_modules/@allyhub-next/slides-core/dist/model.d.ts +2 -4
  217. package/dist/node_modules/@allyhub-next/slides-core/dist/office.d.ts +17 -1
  218. package/dist/node_modules/@allyhub-next/slides-core/dist/office.js +1 -1
  219. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.d.ts +21 -5
  220. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.js +1 -1
  221. package/dist/node_modules/@allyhub-next/slides-core/dist/script.d.ts +18 -16
  222. package/dist/node_modules/@allyhub-next/slides-core/dist/script.js +2 -2
  223. package/dist/node_modules/@allyhub-next/slides-core/dist/stage.d.ts +51 -53
  224. package/dist/node_modules/@allyhub-next/slides-core/dist/strict.js +1 -1
  225. package/dist/node_modules/@allyhub-next/slides-core/dist/units.d.ts +27 -0
  226. package/dist/node_modules/@allyhub-next/slides-core/dist/units.js +1 -1
  227. package/dist/node_modules/@allyhub-next/slides-core/dist/values.d.ts +7 -0
  228. package/dist/node_modules/@allyhub-next/slides-core/dist/values.js +2 -0
  229. package/dist/node_modules/@allyhub-next/slides-core/package.json +1 -1
  230. package/dist/node_modules/@allyhub-next/video-core/dist/captions.js +6 -6
  231. package/dist/node_modules/@allyhub-next/video-core/dist/fact.d.ts +47 -8
  232. package/dist/node_modules/@allyhub-next/video-core/dist/fact.js +1 -1
  233. package/dist/node_modules/@allyhub-next/video-core/dist/index.d.ts +1 -0
  234. package/dist/node_modules/@allyhub-next/video-core/dist/index.js +1 -1
  235. package/dist/node_modules/@allyhub-next/video-core/dist/marks.d.ts +14 -0
  236. package/dist/node_modules/@allyhub-next/video-core/dist/marks.js +1 -1
  237. package/dist/node_modules/@allyhub-next/video-core/dist/music.d.ts +2 -1
  238. package/dist/node_modules/@allyhub-next/video-core/dist/piece.d.ts +11 -2
  239. package/dist/node_modules/@allyhub-next/video-core/dist/problem.d.ts +4 -0
  240. package/dist/node_modules/@allyhub-next/video-core/dist/problem.js +1 -1
  241. package/dist/node_modules/@allyhub-next/video-core/dist/schema.d.ts +2 -2
  242. package/dist/node_modules/@allyhub-next/video-core/dist/schema.js +1 -1
  243. package/dist/node_modules/@allyhub-next/video-core/dist/script.d.ts +2 -1
  244. package/dist/node_modules/@allyhub-next/video-core/dist/script.js +1 -1
  245. package/dist/node_modules/@allyhub-next/video-core/dist/source.d.ts +7 -0
  246. package/dist/node_modules/@allyhub-next/video-core/dist/source.js +2 -0
  247. package/dist/node_modules/@allyhub-next/video-core/dist/timeline.d.ts +10 -33
  248. package/dist/node_modules/@allyhub-next/video-core/package.json +1 -1
  249. package/dist/slides.d.ts +3 -1
  250. package/dist/slides.js +1 -1
  251. package/docs/README.md +1 -0
  252. package/docs/contract.md +1 -1
  253. package/docs/defaults.md +2 -2
  254. package/docs/layers.md +1 -1
  255. package/docs/project.md +3 -1
  256. package/docs/sheets.md +7 -6
  257. package/docs/slides.md +16 -12
  258. package/docs/sound.md +1 -1
  259. package/docs/websites.md +57 -0
  260. package/package.json +3 -1
  261. package/dist/node_modules/@allyhub-next/slides-core/dist/preset.d.ts +0 -5
  262. package/dist/node_modules/@allyhub-next/slides-core/dist/preset.js +0 -2
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{MAX_COLUMNS as A,MAX_ROWS as M,overlaps as L}from"../address.js";import{CellError as m,ERR as f,Matrix as d,serialOfDate as U}from"../values.js";import{filteredRows as N}from"../filter.js";import{FormulaCell as b,SharedFormula as F,placeKey as _}from"../workbook.js";import{analyse as V}from"./analyse.js";import{binary as k,mapBoth as I,toNumber as T}from"./coerce.js";import{FUNCTIONS as B}from"./functions/index.js";import{Lambda as S,MISSING as O,Missing as x,Reference as u,Union as g}from"./types.js";export function seededRandom(h){let t=2166136261;for(let e=0;e<h.length;e++)t=Math.imul(t^h.charCodeAt(e),16777619);return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}const $=new Set,W=/\b(?:SUBTOTAL|AGGREGATE)\(/iu,D=2e3,z=32,R=12,G=(h,t)=>!h||!t?h===t:h.rows!==t.rows||h.cols!==t.cols?!1:h.data.every((e,s)=>e===t.data[s]),H=(h,t)=>h.row<t.row||h.row===t.row&&h.col<t.col;class P{cells=new Set;reference;constructor(t){this.reference=t}}export class Calc{cycles=[];computed=0;nowSerial;random;pass=0;stack=[];inCycle=new Set;namesAt=new Set;dependents=new Map;watches=new Map;watchesAt=new Map;wideWatches=[];graph=!1;moved=[];unsettled=new Set;hiddenBy=new Map;volatiles=new Set;indexes=new Map;wb;constructor(t,e={}){this.wb=t;const{now:s,random:n}=e;this.nowSerial=()=>U(s??new Date),this.random=n??Math.random;for(const o of t.sheets)o.expand()}allCells(){return this.wb.sheets.flatMap(t=>[...t.formulas])}filtered(t){return this.hiddenBy.get(t)??$}calculate(){this.hiddenBy.clear();for(const e of this.wb.sheets)e.clearSpills();this.moved=[],this.unsettled.clear();const t=this.allCells();for(const e of t)e.state=1;return this.cycles=[],this.inCycle.clear(),this.run(t),this.applyFilters(t),this}applyFilters(t){for(const e of this.wb.sheets){if(e.filters.every(n=>n.columns.size===0))continue;const s=N(e,this);s.size>0&&this.hiddenBy.set(e,s)}if(this.hiddenBy.size!==0&&t.some(e=>W.test(e.shared.text))){for(const e of t)e.state=1;this.cycles=[],this.inCycle.clear(),this.run([...t])}}value(t,e,s){return this.read(t,e,s)}read(t,e,s){const n=t.at(e,s);return n===void 0?this.ghost(t,e,s):typeof n!="object"||n instanceof m?n:(n.state===1?this.compute(n):n.state===2&&this.circular(n),n.value)}ghost(t,e,s){const n=t.spillAt(e,s);if(!n)return null;if(n.state===1)this.compute(n);else if(n.state===2)return this.circular(n),null;const{array:o}=n;return o&&t.spillAt(e,s)===n?o.at(e-n.row,s-n.col):null}circular(t){const e=this.stack.indexOf(t),s=e<0?[t]:this.stack.slice(e);s.some(n=>this.inCycle.has(n))||this.cycles.push(s);for(const n of s)this.inCycle.add(n)}run(t){this.indexes.clear(),this.computed=0;for(const e of this.order(t))e.state===1&&this.compute(e);this.spread()}spread(){for(let t=0;this.moved.length>0;t++){const e=this.moved;if(this.moved=[],t>=R*2)break;if(t>=R)for(const{sheet:o,area:r}of e)for(const i of o.spillsIn(r))this.unsettled.add(i);this.build();const s=new Set,n=[...this.unsettled];for(const{sheet:o,area:r}of e)n.push(...this.readersIn(o,r),...o.blockedBy(r));for(;;){const o=n.pop();if(!o)break;s.has(o)||(s.add(o),n.push(...this.readers(o.sheet,o.row,o.col)))}if(s.size!==0){for(const o of s)o.state=1,this.inCycle.delete(o);this.cycles=this.cycles.filter(o=>!o.some(r=>s.has(r))),this.indexes.clear();for(const o of this.order([...s]))o.state===1&&this.compute(o)}}for(const t of this.wb.sheets)t.tighten()}spillOut(t,e){const{sheet:s,row:n,col:o}=t,r={top:n,left:o,bottom:n+e.rows-1,right:o+e.cols-1},i=s.spillsIn(r).filter(c=>c!==t);if(r.bottom>=M||r.right>=A||s.holds(r,t)||s.tables.some(c=>L(c.area,r))||s.merges.some(c=>L(c,r))||i.some(c=>H(c,t)))return s.blockSpill(t,r),!1;for(const c of i)this.evict(c,r);return s.placeSpill(t,r),!0}evict(t,e){const{sheet:s,spill:n}=t;n&&(s.clearSpill(t),s.blockSpill(t,e),t.array=void 0,t.value=f.SPILL,this.moved.push({sheet:s,area:n}))}analysisOf(t){return t.analysis??=V(this.wb,t)}readsOf(t){const e=[],s=v(t);for(const n of this.analysisOf(t.shared).reads){const o=n.kind==="ref"?this.resolveRef(n,s):this.structured(n,s);o instanceof u?e.push(o):o instanceof g&&e.push(...o.parts)}return e}readsOfFormula(t,e){const s=[],n={sheet:e,row:t.row,col:t.col,dr:0,dc:0};for(const o of this.analysisOf(t).reads){const r=o.kind==="ref"?this.resolveRef(o,n):this.structured(o,n);r instanceof u?s.push(r):r instanceof g&&s.push(...r.parts)}return s}order(t){this.pass+=1;const{pass:e}=this,s=[],n=new Set,o=[],r=i=>{i.mark=e,o.push({cell:i,reads:this.pending(i,n),next:0})};for(const i of t)if(i.mark!==e)for(r(i);;){const a=o[o.length-1];if(!a)break;const c=a.reads[a.next];a.next+=1,c===void 0?(s.push(a.cell),o.pop()):c.mark!==e&&c.state===1&&r(c)}return s}pending(t,e){const s=[];for(const n of this.readsOf(t)){const{sheet:o}=n;if(n.single){const i=o.at(n.top,n.left);i instanceof b&&s.push(i);continue}if(e.has(n.key))continue;e.add(n.key);const r=Math.min(n.right,o.columnsUsed-1);for(let i=n.left;i<=r;i++){if(!o.hasFormulas(i))continue;const[a,c]=o.span(i,n.top,n.bottom);for(let l=a;l<=c;l++){const p=o.at(l,i);p instanceof b&&s.push(p)}}}return s}compute(t){if(this.stack.length>=D){t.value=f.CALC,t.state=0;return}t.state=2,this.stack.push(t),this.computed+=1;const{node:e}=t.shared,s=e?this.top(this.eval(e,v(t))):f.NAME;this.stack.pop(),this.unsettled.has(t)&&!this.inCycle.has(t)&&(this.inCycle.add(t),this.cycles.push([t])),this.settleResult(t,s),t.state=0}settleResult(t,e){const{sheet:s}=t,n=t.spill,o=t.array;if(s.clearSpill(t),t.array=void 0,e instanceof d){const i=j(e);i.rows*i.cols<=1||this.spillOut(t,i)?(t.array=i,t.value=i.at(0,0)??0):t.value=f.SPILL}else t.value=e;this.inCycle.has(t)&&(s.clearSpill(t),t.value=f.CYCLE,t.array=void 0);const r=t.spill;(!G(o,t.array)||!q(n,r))&&(n&&this.moved.push({sheet:s,area:n}),r&&this.moved.push({sheet:s,area:r}))}top(t){const e=this.flat(t);return e===null?0:e}flat(t){return t instanceof u?t.single?this.read(t.sheet,t.top,t.left):this.matrix(t):t instanceof g?f.VALUE:t instanceof S?f.CALC:t instanceof x?null:t}matrix(t){const e=t.bottom===M-1?Math.min(t.bottom,t.sheet.lastRow):t.bottom,s=t.right===A-1?Math.min(t.right,t.sheet.columnsUsed-1):t.right,n=Math.max(0,e-t.top+1),o=Math.max(0,s-t.left+1),r=new Array(n*o);for(let i=0;i<n;i++)for(let a=0;a<o;a++)r[i*o+a]=this.read(t.sheet,t.top+i,t.left+a);return new d(n,o,r)}each(t,e){const{sheet:s}=t,n=Math.min(t.right,s.columnsUsed-1);for(let o=t.left;o<=n;o++){const[r,i]=s.span(o,t.top,t.bottom);for(let a=r;a<=i;a++){const c=s.at(a,o);if(c===void 0){s.spillAt(a,o)&&e(this.read(s,a,o),a,o);continue}e(typeof c=="object"&&!(c instanceof m)?this.read(s,a,o):c,a,o)}}}evaluate(t,e){const{node:s}=t;return s?this.top(this.eval(s,{sheet:e,row:t.row,col:t.col,dr:0,dc:0})):f.NAME}evaluateAt(t,e,s,n){const{node:o}=t;return o?this.top(this.eval(o,{sheet:e,row:s,col:n,dr:s-t.row,dc:n-t.col})):f.NAME}bound(t,e,s){const n=t.abs?t.index:t.index+e;return n<0||n>=s?void 0:n}resolveRef(t,e){const s=t.sheet===void 0?e.sheet:this.wb.sheet(t.sheet);if(!s)return f.REF;let n=0,o=A-1,r=0,i=M-1;if(t.col){const a=this.bound(t.col,e.dc,A),c=this.bound(t.col2??t.col,e.dc,A);if(a===void 0||c===void 0)return f.REF;n=Math.min(a,c),o=Math.max(a,c)}if(t.row){const a=this.bound(t.row,e.dr,M),c=this.bound(t.row2??t.row,e.dr,M);if(a===void 0||c===void 0)return f.REF;r=Math.min(a,c),i=Math.max(a,c)}if(t.lastSheet!==void 0){const a=this.wb.sheet(t.lastSheet);if(!a)return f.REF;const[c,l]=[Math.min(s.index,a.index),Math.max(s.index,a.index)];return new g(this.wb.sheets.slice(c,l+1).map(p=>new u(p,r,n,i,o)))}return new u(s,r,n,i,o)}structured(t,e){const s=t.table===void 0?e.sheet.tableAt(e.row,e.col):this.wb.table(t.table);return s?X(s,t,e):t.table===void 0?f.REF:f.NAME}nameValue(t,e){const s=t.toLowerCase();for(let r=e.scope;r;r=r.parent){const i=r.names.get(s);if(i!==void 0)return i}const n=this.wb.name(t);if(n){if(!n.formula)return n.value??null;const{node:r}=n.formula;if(!r)return f.NAME;if(this.namesAt.has(s))return f.CYCLE;this.namesAt.add(s);try{return this.eval(r,{sheet:e.sheet,row:0,col:0,dr:0,dc:0})}finally{this.namesAt.delete(s)}}const o=this.wb.table(t);if(o){const{top:r,left:i,bottom:a,right:c}=o.data;return new u(o.sheet,r,i,a,c)}return f.NAME}intersect(t,e){return!(t instanceof u)||t.single?t:t.cols===1&&e.row>=t.top&&e.row<=t.bottom?new u(t.sheet,e.row,t.left,e.row,t.left):t.rows===1&&e.col>=t.left&&e.col<=t.right?new u(t.sheet,t.top,e.col,t.top,e.col):f.VALUE}unary(t,e){const s=this.flat(t);return s instanceof d?new d(s.rows,s.cols,s.data.map(e)):e(s)}operate(t,e,s){const n=this.flat(e),o=this.flat(s);if(n instanceof d||o instanceof d){const r=(i,a)=>k(t,i,a);return I(n instanceof d?n:new d(1,1,[n]),o instanceof d?o:new d(1,1,[o]),r)}return k(t,n,o)}rangeOf(t,e){return t instanceof m?t:e instanceof m?e:!(t instanceof u)||!(e instanceof u)||t.sheet!==e.sheet?f.REF:new u(t.sheet,Math.min(t.top,e.top),Math.min(t.left,e.left),Math.max(t.bottom,e.bottom),Math.max(t.right,e.right))}intersection(t,e){if(t instanceof m)return t;if(e instanceof m)return e;if(!(t instanceof u)||!(e instanceof u))return f.REF;const s=Math.max(t.top,e.top),n=Math.max(t.left,e.left),o=Math.min(t.bottom,e.bottom),r=Math.min(t.right,e.right);return t.sheet!==e.sheet||s>o||n>r?f.NULL:new u(t.sheet,s,n,o,r)}union(t,e){if(t instanceof m)return t;if(e instanceof m)return e;const s=o=>o instanceof u?[o]:o instanceof g?o.parts:[],n=[...s(t),...s(e)];return n.length===0?f.VALUE:new g(n)}eval(t,e){switch(t.kind){case"number":case"string":case"boolean":return t.value;case"error":return m.of(t.code);case"missing":return O;case"ref":return this.resolveRef(t,e);case"structured":return this.structured(t,e);case"name":return this.nameValue(t.name,e);case"paren":return this.eval(t.arg,e);case"unary":{const s=this.eval(t.arg,e);return t.op==="@"?this.intersect(s,e):t.op==="+"?s:this.unary(s,n=>k("*",n,-1))}case"postfix":{const s=this.eval(t.arg,e);if(t.op==="%")return this.unary(s,n=>k("/",n,100));if(s instanceof u&&s.single){const n=s.sheet.at(s.top,s.left);if(n instanceof b){this.read(s.sheet,s.top,s.left);const{spill:o}=n;if(o)return new u(s.sheet,o.top,o.left,o.bottom,o.right);if(n.array)return s}}return f.REF}case"binary":{const s=this.eval(t.left,e),n=this.eval(t.right,e);return t.op===":"?this.rangeOf(s,n):t.op===" "?this.intersection(s,n):t.op===","?this.union(s,n):this.operate(t.op,s,n)}case"array":return new d(t.rows.length,t.rows[0]?.length??0,t.rows.flatMap(s=>s.map(n=>{const o=this.eval(n,e);return o instanceof d||o instanceof u||o instanceof g||o instanceof S||o instanceof x?f.VALUE:o})));case"invoke":{const s=this.eval(t.callee,e);return s instanceof S?this.invoke(s,t.args,e):s instanceof m?s:f.VALUE}case"call":return this.call(t.name,t.args,e)}}invoke(t,e,s){return this.apply(t,e.map(n=>this.eval(n,s)))}apply(t,e){if(e.length>t.params.length)return f.VALUE;const s=new Map;return t.params.forEach((n,o)=>{s.set(n,e[o]??O)}),this.eval(t.body,{...t.frame,scope:{names:s,...t.frame.scope?{parent:t.frame.scope}:{}}})}call(t,e,s){const n=B.get(t);if(!n){const i=this.nameValue(t,s);return i instanceof S?this.invoke(i,e,s):f.NAME}const o={calc:this,frame:s};if(e.length<n.min||e.length>n.max)return f.VALUE;if(n.kind==="lazy")return n.call(e,o);const r=e.map(i=>this.eval(i,s));return n.kind==="raw"?n.call(r,o):this.lifted(n.call,n.errors===!0,r)}lifted(t,e,s){const n=s.map(l=>l instanceof x?void 0:this.flat(l)),o=l=>{if(!e){for(const p of l)if(p instanceof m)return p}return t(...l)};if(!n.some(l=>l instanceof d))return o(n);const r=n.filter(l=>l instanceof d),i=Math.max(...r.map(l=>l.rows)),a=Math.max(...r.map(l=>l.cols)),c=new Array(i*a);for(let l=0;l<i;l++)for(let p=0;p<a;p++)c[l*a+p]=o(n.map(w=>{if(!(w instanceof d))return w;const E=w.rows===1?0:l,y=w.cols===1?0:p;return E<w.rows&&y<w.cols?w.at(E,y):f.NA}));return new d(i,a,c)}scalar(t,e){if(t instanceof x)return null;if(t instanceof u){const s=this.intersect(t,e);return s instanceof u?this.read(s.sheet,s.top,s.left):f.VALUE}return t instanceof d?t.at(0,0):t instanceof g||t instanceof S?f.VALUE:t}recalculate(){const t=this.allCells().filter(e=>this.analysisOf(e.shared).volatile);return this.mark(t),this}key(t,e,s){return`${String(t.index)}:${String(_(e,s))}`}addEdges(t){this.analysisOf(t.shared).volatile&&this.volatiles.add(t);for(const e of this.readsOf(t))if(e.single){const s=this.key(e.sheet,e.top,e.left);let n=this.dependents.get(s);n||(n=new Set,this.dependents.set(s,n)),n.add(t)}else{let s=this.watches.get(e.key);if(!s)if(s=new P(e),this.watches.set(e.key,s),e.cols>z)this.wideWatches.push(s);else for(let n=e.left;n<=e.right;n++){const o=`${String(e.sheet.index)}:${String(n)}`,r=this.watchesAt.get(o);r?r.push(s):this.watchesAt.set(o,[s])}s.cells.add(t)}}removeEdges(t){this.volatiles.delete(t);for(const e of this.readsOf(t))e.single?this.dependents.get(this.key(e.sheet,e.top,e.left))?.delete(t):this.watches.get(e.key)?.cells.delete(t)}build(){if(!this.graph){this.graph=!0;for(const t of this.allCells())this.addEdges(t)}}readersIn(t,e){const s=new Set,n=e.right;for(let i=e.top;i<=e.bottom;i++)for(let a=e.left;a<=n;a++)for(const c of this.dependents.get(this.key(t,i,a))??[])s.add(c);const o=new Set,r=i=>{if(o.has(i))return;o.add(i);const{reference:a,cells:c}=i;if(a.sheet===t&&L(a,e))for(const l of c)s.add(l)};this.wideWatches.forEach(r);for(let i=e.left;i<=n;i++)this.watchesAt.get(`${String(t.index)}:${String(i)}`)?.forEach(r);return[...s]}readers(t,e,s){this.build();const n=new Set(this.dependents.get(this.key(t,e,s))),o=`${String(t.index)}:${String(s)}`,r=this.watchesAt.get(o)??[];for(const i of[r,this.wideWatches])for(const{reference:a,cells:c}of i)if(a.sheet===t&&e>=a.top&&e<=a.bottom&&s>=a.left&&s<=a.right)for(const l of c)n.add(l);return[...n]}precedents(t){return this.readsOf(t)}mark(t){this.build();const e=new Set(t),s=[...t];for(;;){const n=s.pop();if(!n)break;for(const o of this.readers(n.sheet,n.row,n.col))e.has(o)||(e.add(o),s.push(o))}this.settle(e)}settle(t){for(const e of t)e.state=1,this.inCycle.delete(e);this.cycles=this.cycles.filter(e=>!e.some(s=>t.has(s))),this.run([...t])}set(t,e,s,n){const o=typeof n=="string"&&n.length>1&&n.startsWith("=")?new b(new F(n,e,s,{file:""}),t,e,s):void 0;this.change([{sheet:t,row:e,col:s,slot:o??n??void 0}])}prepare(){this.build()}change(t){this.build();const e=new Set,s=[...this.unsettled];this.unsettled.clear();for(const{sheet:n,row:o,col:r,slot:i}of t){const a=n.at(o,r);a instanceof b&&(this.removeEdges(a),e.delete(a),a.spill&&this.moved.push({sheet:n,area:a.spill}),n.clearSpill(a));const c=n.spillAt(o,r);c&&s.push(c),s.push(...n.blockedBy({top:o,left:r,bottom:o,right:r})),n.replace(o,r,i),i instanceof b&&(this.addEdges(i),e.add(i))}for(const{sheet:n,row:o,col:r}of t)s.push(...this.readers(n,o,r));for(s.push(...this.volatiles);;){const n=s.pop();if(!n)break;e.has(n)||(e.add(n),s.push(...this.readers(n.sheet,n.row,n.col)))}this.settle(e)}setName(t,e){const s=this.wb.name(t);if(!s)throw new Error(`There is no name ${t}.`);s.value=e,delete s.formula;const n=t.toLowerCase();this.mark(this.allCells().filter(o=>this.analysisOf(o.shared).names.has(n)))}numberOf(t){return T(t)}}const q=(h,t)=>h?.top===t?.top&&h?.left===t?.left&&h?.bottom===t?.bottom&&h?.right===t?.right;function j(h){return h.data.some(t=>t===null)?new d(h.rows,h.cols,h.data.map(t=>t??0)):h}function v(h){return{sheet:h.sheet,row:h.row,col:h.col,dr:h.row-h.shared.row,dc:h.col-h.shared.col}}function X(h,t,e){const{sheet:s}=h,n=h.area;let o=n.left,r=n.right;const[i,a]=t.columns;if(i!==void 0){const y=h.column(i),C=a===void 0?y:h.column(a);if(!y||!C)return f.REF;o=n.left+Math.min(y.index,C.index),r=n.left+Math.max(y.index,C.index)}if(t.thisRow)return e.sheet!==s||e.row<=n.top||e.row>n.bottom?f.VALUE:new u(s,e.row,o,e.row,r);const c=t.sections;if(c.includes("#Totals"))return f.REF;const l=c.includes("#All")||c.includes("#Headers"),p=c.length===0||c.includes("#All")||c.includes("#Data"),w=l?n.top:n.top+1,E=p?n.bottom:n.top;return new u(s,w,o,E,r)}
2
+ import{MAX_COLUMNS as E,MAX_ROWS as k,overlaps as O}from"../address.js";import{CellError as m,ERR as h,Matrix as p,serialOfDate as _}from"../values.js";import{filteredRows as B}from"../filter.js";import{FormulaCell as y,SharedFormula as I}from"../workbook.js";import{analyse as z}from"./analyse.js";import{Graph as T}from"./graph.js";import{fromWire as G,matrixFromWire as D,matrixToWire as W,toWire as P}from"./remote.js";import{RangeCache as U}from"./indexes.js";import{binary as S,mapBoth as H,toNumber as q}from"./coerce.js";import{FUNCTIONS as v}from"./functions/index.js";import{fillsGroup as j,paramAt as X}from"./functions/define.js";import{Lambda as M,MISSING as F,Missing as x,Reference as u,Union as b}from"./types.js";export function seededRandom(l){let t=2166136261;for(let e=0;e<l.length;e++)t=Math.imul(t^l.charCodeAt(e),16777619);return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}const Y=new Set,Z=/\b(?:SUBTOTAL|AGGREGATE)\(/iu,$=2e3,N=12,J=(l,t)=>!l||!t?l===t:l.rows!==t.rows||l.cols!==t.cols?!1:l.data.every((e,s)=>e===t.data[s]),K=(l,t)=>l.row<t.row||l.row===t.row&&l.col<t.col;export class Calc{cycles=[];computed=0;nowSerial;random;pass=0;stack=[];inCycle=new Set;namesAt=new Set;graph=new T({readsOf:t=>this.readsOf(t),readsAt:(t,e,s,n)=>this.readsAt(t,e,s,n)});graphMade=!1;reports;replica;settled=new Set;moved=[];unsettled=new Set;hiddenBy=new Map;volatiles=new Set;indexes=new U;results=new U;wb;constructor(t,e={}){this.wb=t;const{now:s,random:n}=e;this.reports=e.report===!0,this.replica=e.replica===!0,this.nowSerial=()=>_(s??new Date),this.random=n??Math.random;for(const o of t.sheets)o.expand()}allCells(){return this.wb.sheets.flatMap(t=>[...t.formulas])}filtered(t){return this.hiddenBy.get(t)??Y}calculate(){if(this.replica){for(const e of this.wb.sheets)e.clearSpills();for(const e of this.allCells())e.state=0;return this}this.hiddenBy.clear(),this.indexes.clear(),this.results.clear();for(const e of this.wb.sheets)e.clearSpills();this.moved=[],this.unsettled.clear();const t=this.allCells();for(const e of t)e.state=1;return this.cycles=[],this.inCycle.clear(),this.run(t),this.applyFilters(t),this}applyFilters(t){for(const e of this.wb.sheets){if(e.filters.every(n=>n.columns.size===0))continue;const s=B(e,this);s.size>0&&this.hiddenBy.set(e,s)}if(this.hiddenBy.size!==0&&t.some(e=>Z.test(e.shared.text))){for(const e of t)e.state=1;this.cycles=[],this.inCycle.clear(),this.run([...t])}}value(t,e,s){return this.read(t,e,s)}read(t,e,s){const n=t.at(e,s);return n===void 0?this.ghost(t,e,s):typeof n!="object"||n instanceof m?n:(n.state===1?this.compute(n):n.state===2&&this.circular(n),n.value)}ghost(t,e,s){const n=t.spillAt(e,s);if(!n)return null;if(n.state===1)this.compute(n);else if(n.state===2)return this.circular(n),null;const{array:o}=n;return o&&t.spillAt(e,s)===n?o.at(e-n.row,s-n.col):null}circular(t){const e=this.stack.indexOf(t),s=e<0?[t]:this.stack.slice(e);s.some(n=>this.inCycle.has(n))||this.cycles.push(s);for(const n of s)this.inCycle.add(n)}forget(t,e){this.indexes.changed(t,e),this.results.changed(t,e)}run(t){for(const e of t){const{sheet:s,row:n,col:o}=e;this.forget(s,{top:n,left:o,bottom:n,right:o}),e.spill&&this.forget(s,e.spill)}this.computed=0;for(const e of this.order(t))e.state===1&&this.compute(e);this.spread()}spread(){for(let t=0;this.moved.length>0;t++){const e=this.moved;if(this.moved=[],t>=N*2)break;if(t>=N)for(const{sheet:o,area:r}of e)for(const i of o.spillsIn(r))this.unsettled.add(i);this.build();const s=new Set,n=[...this.unsettled];for(const{sheet:o,area:r}of e)n.push(...this.readersIn(o,r),...o.blockedBy(r));for(;;){const o=n.pop();if(!o)break;s.has(o)||(s.add(o),n.push(...this.readers(o.sheet,o.row,o.col)))}if(s.size!==0){for(const o of s)o.state=1,this.inCycle.delete(o);this.cycles=this.cycles.filter(o=>!o.some(r=>s.has(r))),this.indexes.clear(),this.results.clear();for(const o of this.order([...s]))o.state===1&&this.compute(o)}}for(const t of this.wb.sheets)t.tighten()}spillOut(t,e){const{sheet:s,row:n,col:o}=t,r={top:n,left:o,bottom:n+e.rows-1,right:o+e.cols-1},i=s.spillsIn(r).filter(c=>c!==t);if(r.bottom>=k||r.right>=E||s.holds(r,t)||s.tables.some(c=>O(c.area,r))||s.merges.some(c=>O(c,r))||i.some(c=>K(c,t)))return s.blockSpill(t,r),!1;for(const c of i)this.evict(c,r);return s.placeSpill(t,r),!0}evict(t,e){const{sheet:s,spill:n}=t;n&&(s.clearSpill(t),s.blockSpill(t,e),t.array=void 0,t.value=h.SPILL,this.moved.push({sheet:s,area:n}),this.reports&&this.settled.add(t))}analysisOf(t){return t.analysis??=z(this.wb,t)}readsOf(t){const e=[],s=V(t);for(const n of this.analysisOf(t.shared).reads){const o=n.kind==="ref"?this.resolveRef(n,s):this.structured(n,s);o instanceof u?e.push(o):o instanceof b&&e.push(...o.parts)}return e}readsAt(t,e,s,n){const o={sheet:e,row:s,col:n,dr:s-t.row,dc:n-t.col},r=[];for(const i of this.analysisOf(t).reads){const a=i.kind==="ref"?this.resolveRef(i,o):this.structured(i,o);a instanceof u?r.push(a):a instanceof b?r.push(...a.parts):r.push(void 0)}return r}readsOfFormula(t,e){const s=[],n={sheet:e,row:t.row,col:t.col,dr:0,dc:0};for(const o of this.analysisOf(t).reads){const r=o.kind==="ref"?this.resolveRef(o,n):this.structured(o,n);r instanceof u?s.push(r):r instanceof b&&s.push(...r.parts)}return s}order(t){this.pass+=1;const{pass:e}=this,s=[],n=new Set,o=[],r=i=>{i.mark=e,o.push({cell:i,reads:this.pending(i,n),next:0})};for(const i of t)if(i.mark!==e)for(r(i);;){const a=o[o.length-1];if(!a)break;const c=a.reads[a.next];a.next+=1,c===void 0?(s.push(a.cell),o.pop()):c.mark!==e&&c.state===1&&r(c)}return s}pending(t,e){const s=[];for(const n of this.readsOf(t)){const{sheet:o}=n;if(n.single){const i=o.at(n.top,n.left);i instanceof y&&s.push(i);continue}if(e.has(n.key))continue;e.add(n.key);const r=Math.min(n.right,o.columnsUsed-1);for(let i=n.left;i<=r;i++){if(!o.hasFormulas(i))continue;const[a,c]=o.span(i,n.top,n.bottom);for(let f=a;f<=c;f++){const d=o.at(f,i);d instanceof y&&s.push(d)}}}return s}compute(t){if(this.stack.length>=$){t.value=h.CALC,t.state=0;return}t.state=2,this.stack.push(t),this.computed+=1;const{node:e}=t.shared,s=e?this.top(this.eval(e,V(t))):h.NAME;this.stack.pop(),this.unsettled.has(t)&&!this.inCycle.has(t)&&(this.inCycle.add(t),this.cycles.push([t])),this.settleResult(t,s),t.state=0,this.reports&&this.settled.add(t)}settleResult(t,e){const{sheet:s}=t,n=t.spill,o=t.array;if(s.clearSpill(t),t.array=void 0,e instanceof p){const i=tt(e);i.rows*i.cols<=1||this.spillOut(t,i)?(t.array=i,t.value=i.at(0,0)??0):t.value=h.SPILL}else t.value=e;this.inCycle.has(t)&&(s.clearSpill(t),t.value=h.CYCLE,t.array=void 0);const r=t.spill;(!J(o,t.array)||!Q(n,r))&&(n&&this.moved.push({sheet:s,area:n}),r&&this.moved.push({sheet:s,area:r}))}top(t){const e=this.flat(t);return e===null?0:e}flat(t){return t instanceof u?t.single?this.read(t.sheet,t.top,t.left):this.matrix(t):t instanceof b?h.VALUE:t instanceof M?h.CALC:t instanceof x?null:t}matrix(t){const e=t.bottom===k-1?Math.min(t.bottom,t.sheet.lastRow):t.bottom,s=t.right===E-1?Math.min(t.right,t.sheet.columnsUsed-1):t.right,n=Math.max(0,e-t.top+1),o=Math.max(0,s-t.left+1),r=new Array(n*o);for(let i=0;i<n;i++)for(let a=0;a<o;a++)r[i*o+a]=this.read(t.sheet,t.top+i,t.left+a);return new p(n,o,r)}each(t,e){const{sheet:s}=t,n=Math.min(t.right,s.columnsUsed-1);for(let o=t.left;o<=n;o++){const[r,i]=s.span(o,t.top,t.bottom);for(let a=r;a<=i;a++){const c=s.at(a,o);if(c===void 0){s.spillAt(a,o)&&e(this.read(s,a,o),a,o);continue}e(typeof c=="object"&&!(c instanceof m)?this.read(s,a,o):c,a,o)}}}evaluate(t,e){const{node:s}=t;return s?this.top(this.eval(s,{sheet:e,row:t.row,col:t.col,dr:0,dc:0})):h.NAME}evaluateAt(t,e,s,n){const{node:o}=t;return o?this.top(this.eval(o,{sheet:e,row:s,col:n,dr:s-t.row,dc:n-t.col})):h.NAME}bound(t,e,s){const n=t.abs?t.index:t.index+e;return n<0||n>=s?void 0:n}resolveRef(t,e){const s=t.sheet===void 0?e.sheet:this.wb.sheet(t.sheet);if(!s)return h.REF;let n=0,o=E-1,r=0,i=k-1;if(t.col){const a=this.bound(t.col,e.dc,E),c=this.bound(t.col2??t.col,e.dc,E);if(a===void 0||c===void 0)return h.REF;n=Math.min(a,c),o=Math.max(a,c)}if(t.row){const a=this.bound(t.row,e.dr,k),c=this.bound(t.row2??t.row,e.dr,k);if(a===void 0||c===void 0)return h.REF;r=Math.min(a,c),i=Math.max(a,c)}if(t.lastSheet!==void 0){const a=this.wb.sheet(t.lastSheet);if(!a)return h.REF;const[c,f]=[Math.min(s.index,a.index),Math.max(s.index,a.index)];return new b(this.wb.sheets.slice(c,f+1).map(d=>new u(d,r,n,i,o)))}return new u(s,r,n,i,o)}structured(t,e){const s=t.table===void 0?e.sheet.tableAt(e.row,e.col):this.wb.table(t.table);return s?et(s,t,e):t.table===void 0?h.REF:h.NAME}nameValue(t,e,s){const n=t.toLowerCase();if(s===void 0)for(let c=e.scope;c;c=c.parent){const f=c.names.get(n);if(f!==void 0)return f}const o=s===void 0?e.sheet:this.wb.sheet(s);if(!o)return h.REF;const r=this.wb.name(t,o);if(r){if(!r.formula)return r.value??null;const{node:c}=r.formula;if(!c)return h.NAME;if(this.namesAt.has(n))return h.CYCLE;this.namesAt.add(n);try{return this.eval(c,{sheet:e.sheet,row:0,col:0,dr:0,dc:0})}finally{this.namesAt.delete(n)}}const i=this.wb.table(t);if(i){const{top:c,left:f,bottom:d,right:g}=i.data;return new u(i.sheet,c,f,d,g)}const a=v.get(t.toUpperCase());return a&&a.kind!=="lazy"?st(a,t,e):h.NAME}intersect(t,e){return!(t instanceof u)||t.single?t:t.cols===1&&e.row>=t.top&&e.row<=t.bottom?new u(t.sheet,e.row,t.left,e.row,t.left):t.rows===1&&e.col>=t.left&&e.col<=t.right?new u(t.sheet,t.top,e.col,t.top,e.col):h.VALUE}unary(t,e){const s=this.flat(t);return s instanceof p?new p(s.rows,s.cols,s.data.map(e)):e(s)}operate(t,e,s){const n=this.flat(e),o=this.flat(s);if(n instanceof p||o instanceof p){const r=(i,a)=>S(t,i,a);return H(n instanceof p?n:new p(1,1,[n]),o instanceof p?o:new p(1,1,[o]),r)}return S(t,n,o)}rangeOf(t,e){return t instanceof m?t:e instanceof m?e:!(t instanceof u)||!(e instanceof u)||t.sheet!==e.sheet?h.REF:new u(t.sheet,Math.min(t.top,e.top),Math.min(t.left,e.left),Math.max(t.bottom,e.bottom),Math.max(t.right,e.right))}intersection(t,e){if(t instanceof m)return t;if(e instanceof m)return e;if(!(t instanceof u)||!(e instanceof u))return h.REF;const s=Math.max(t.top,e.top),n=Math.max(t.left,e.left),o=Math.min(t.bottom,e.bottom),r=Math.min(t.right,e.right);return t.sheet!==e.sheet||s>o||n>r?h.NULL:new u(t.sheet,s,n,o,r)}union(t,e){if(t instanceof m)return t;if(e instanceof m)return e;const s=o=>o instanceof u?[o]:o instanceof b?o.parts:[],n=[...s(t),...s(e)];return n.length===0?h.VALUE:new b(n)}eval(t,e){switch(t.kind){case"number":case"string":case"boolean":return t.value;case"error":return m.of(t.code);case"missing":return F;case"ref":return this.resolveRef(t,e);case"structured":return this.structured(t,e);case"name":return this.nameValue(t.name,e,t.sheet);case"paren":return this.eval(t.arg,e);case"unary":{const s=this.eval(t.arg,e);return t.op==="@"?this.intersect(s,e):t.op==="+"?s:this.unary(s,n=>S("*",n,-1))}case"postfix":{const s=this.eval(t.arg,e);if(t.op==="%")return this.unary(s,n=>S("/",n,100));if(s instanceof u&&s.single){const n=s.sheet.at(s.top,s.left);if(n instanceof y){this.read(s.sheet,s.top,s.left);const{spill:o}=n;if(o)return new u(s.sheet,o.top,o.left,o.bottom,o.right);if(n.array)return s}}return h.REF}case"binary":{const s=this.eval(t.left,e),n=this.eval(t.right,e);return t.op===":"?this.rangeOf(s,n):t.op===" "?this.intersection(s,n):t.op===","?this.union(s,n):this.operate(t.op,s,n)}case"array":return new p(t.rows.length,t.rows[0]?.length??0,t.rows.flatMap(s=>s.map(n=>{const o=this.eval(n,e);return o instanceof p||o instanceof u||o instanceof b||o instanceof M||o instanceof x?h.VALUE:o})));case"invoke":{const s=this.eval(t.callee,e);return s instanceof M?this.invoke(s,t.args,e):s instanceof m?s:h.VALUE}case"call":return this.call(t.name,t.args,e)}}invoke(t,e,s){return this.apply(t,e.map(n=>this.eval(n,s)))}apply(t,e){if(t.named!==void 0){const n=v.get(t.named);return!n||n.kind==="lazy"?h.NAME:e.length<n.min||e.length>n.max?h.VALUE:this.applyFunction(n,e,t.frame)}if(e.length>t.params.length)return h.VALUE;const s=new Map;return t.params.forEach((n,o)=>{s.set(n,e[o]??F)}),this.eval(t.body,{...t.frame,scope:{names:s,...t.frame.scope?{parent:t.frame.scope}:{}}})}call(t,e,s){const n=v.get(t);if(!n){const o=this.nameValue(t,s);return o instanceof M?this.invoke(o,e,s):h.NAME}return e.length<n.min||e.length>n.max?h.VALUE:n.kind==="lazy"?n.call(e,{calc:this,frame:s}):this.applyFunction(n,e.map(o=>this.eval(o,s)),s)}applyFunction(t,e,s){const n={calc:this,frame:s};if(t.kind==="lazy")return h.VALUE;if(t.kind==="raw")return j(t.params,e.length)?this.over(e,r=>X(t.params,r)==="value",r=>t.call(r,n)):h.VALUE;const o=t.errors===!0;return this.over(e,()=>!0,r=>{const i=r.map(a=>a instanceof x?void 0:a);if(!o){for(const a of i)if(a instanceof m)return a}return t.call(...i)})}over(t,e,s){const n=[],o=new Map;for(const[f,d]of t.entries()){if(!e(f)||d instanceof x){n.push(d);continue}const g=this.flat(d);g instanceof p&&o.set(f,g),n.push(g)}if(o.size===0)return s(n);const r=[...o.values()],i=Math.max(...r.map(f=>f.rows)),a=Math.max(...r.map(f=>f.cols));if(i===0||a===0)return h.CALC;const c=new Array(i*a);for(let f=0;f<i;f++)for(let d=0;d<a;d++){const g=n.map((C,A)=>{const w=o.get(A);if(!w)return C;const L=w.rows===1?0:f,R=w.cols===1?0:d;return L<w.rows&&R<w.cols?w.at(L,R):h.NA});c[f*a+d]=this.element(s(g))}return new p(i,a,c)}element(t){const e=this.flat(t);return e instanceof p?e.rows>0&&e.cols>0?e.at(0,0):h.CALC:e}scalar(t,e){if(t instanceof x)return null;if(t instanceof u){const s=this.intersect(t,e);return s instanceof u?this.read(s.sheet,s.top,s.left):h.VALUE}return t instanceof p?t.at(0,0):t instanceof b||t instanceof M?h.VALUE:t}recalculate(){if(this.replica)return this;const t=this.allCells().filter(e=>this.analysisOf(e.shared).volatile);return this.mark(t),this}build(){if(this.graphMade)return;this.graphMade=!0;const t=this.allCells();for(const e of t)this.analysisOf(e.shared).volatile&&this.volatiles.add(e);this.graph.build(t)}addEdges(t){this.analysisOf(t.shared).volatile&&this.volatiles.add(t),this.graph.add(t)}removeEdges(t){this.volatiles.delete(t),this.graph.remove(t)}readersIn(t,e){return this.graph.readersIn(t,e)}readers(t,e,s){return this.build(),this.graph.readers(t,e,s)}precedents(t){return this.readsOf(t)}mark(t){this.build();const e=new Set(t),s=[...t];for(;;){const n=s.pop();if(!n)break;for(const o of this.readers(n.sheet,n.row,n.col))e.has(o)||(e.add(o),s.push(o))}this.settle(e)}settle(t){for(const e of t)e.state=1,this.inCycle.delete(e);this.cycles=this.cycles.filter(e=>!e.some(s=>t.has(s))),this.run([...t])}set(t,e,s,n){const o=typeof n=="string"&&n.length>1&&n.startsWith("=")?new y(new I(n,e,s,{file:""}),t,e,s):void 0;this.change([{sheet:t,row:e,col:s,slot:o??n??void 0}])}prepare(){this.build()}change(t){if(this.replica){for(const{sheet:o,row:r,col:i,slot:a}of t){const c=o.at(r,i);c instanceof y&&o.clearSpill(c),o.replace(r,i,a),a instanceof y&&(a.state=0)}return}this.build();const e=new Set,s=[...this.unsettled];this.unsettled.clear();const n=new Set;for(const{sheet:o,row:r,col:i,slot:a}of t){const c=o.at(r,i);c instanceof y&&(n.add(c),this.inCycle.delete(c),this.removeEdges(c),e.delete(c),c.spill&&this.moved.push({sheet:o,area:c.spill}),o.clearSpill(c));const f=o.spillAt(r,i);f&&s.push(f),s.push(...o.blockedBy({top:r,left:i,bottom:r,right:i})),o.replace(r,i,a),this.forget(o,{top:r,left:i,bottom:r,right:i}),a instanceof y&&(this.addEdges(a),e.add(a))}n.size>0&&(this.cycles=this.cycles.filter(o=>!o.some(r=>n.has(r))));for(const{sheet:o,row:r,col:i}of t)s.push(...this.readers(o,r,i));for(s.push(...this.volatiles);;){const o=s.pop();if(!o)break;e.has(o)||(e.add(o),s.push(...this.readers(o.sheet,o.row,o.col)))}this.settle(e)}setName(t,e){const s=this.wb.name(t);if(!s)throw new Error(`There is no name ${t}.`);s.value=e,delete s.formula;const n=t.toLowerCase();this.mark(this.allCells().filter(o=>this.analysisOf(o.shared).names.has(n)))}takeComputed(){const t=[];for(const e of this.settled)t.push({sheet:e.sheet.index,row:e.row,col:e.col,value:P(e.value),...e.array?{array:W(e.array)}:{},...e.spill?{spill:e.spill}:{},...e.blocked?{blocked:e.blocked}:{}});return this.settled.clear(),{cells:t,cycles:this.cycles.map(e=>e.map(s=>({sheet:s.sheet.index,row:s.row,col:s.col}))),hidden:[...this.hiddenBy].map(([e,s])=>({sheet:e.index,rows:[...s]}))}}receive(t){for(const s of t.cells){const n=this.wb.sheets[s.sheet],o=n?.at(s.row,s.col);!n||!(o instanceof y)||(n.clearSpill(o),o.value=G(s.value),o.array=s.array?D(s.array):void 0,s.spill&&n.placeSpill(o,s.spill),s.blocked&&n.blockSpill(o,s.blocked),o.state=0)}this.cycles=t.cycles.flatMap(s=>{const n=s.flatMap(o=>{const r=this.wb.sheets[o.sheet]?.at(o.row,o.col);return r instanceof y?[r]:[]});return n.length>0?[n]:[]});const e=new Map(this.hiddenBy);this.hiddenBy.clear();for(const{sheet:s,rows:n}of t.hidden){const o=this.wb.sheets[s];if(!o)continue;const r=e.get(o),i=r?.size===n.length&&n.every(a=>r.has(a));this.hiddenBy.set(o,i?r:new Set(n))}for(const s of this.wb.sheets)s.tighten()}numberOf(t){return q(t)}}const Q=(l,t)=>l?.top===t?.top&&l?.left===t?.left&&l?.bottom===t?.bottom&&l?.right===t?.right;function tt(l){return l.data.some(t=>t===null)?new p(l.rows,l.cols,l.data.map(t=>t??0)):l}function V(l){return{sheet:l.sheet,row:l.row,col:l.col,dr:l.row-l.shared.row,dc:l.col-l.shared.col}}function et(l,t,e){const{sheet:s}=l,n=l.area;let o=n.left,r=n.right;const[i,a]=t.columns;if(i!==void 0){const A=l.column(i),w=a===void 0?A:l.column(a);if(!A||!w)return h.REF;o=n.left+Math.min(A.index,w.index),r=n.left+Math.max(A.index,w.index)}if(t.thisRow)return e.sheet!==s||e.row<=n.top||e.row>n.bottom?h.VALUE:new u(s,e.row,o,e.row,r);const c=t.sections;if(c.includes("#Totals"))return h.REF;const f=c.includes("#All")||c.includes("#Headers"),d=c.length===0||c.includes("#All")||c.includes("#Data"),g=f?n.top:n.top+1,C=d?n.bottom:n.top;return new u(s,g,o,C,r)}function st(l,t,e){return new M([],{kind:"call",name:l.name,written:t,args:[]},e,l.name)}
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{MAX_ROWS as b}from"../../address.js";import{CellError as s,ERR as m,Matrix as g}from"../../values.js";import{FormulaCell as D}from"../../workbook.js";import{finite as E,snap as w}from"../coerce.js";import{Reference as R,Union as y}from"../types.js";import{FUNCTIONS as I,cellsOf as P,eachArg as O,many as c,numbersOf as h,numbersOfA as M,raw as i}from"./define.js";function V(n){let t=0;for(const e of n)t=w(t+e,t,e);return t}i("SUM",1,c,(n,t)=>{let e=0,o;return O(n,t,(f,l)=>{if(!o){if(typeof f=="number")e=w(e+f,e,f);else if(f instanceof s)o=f;else if(l){const a=h([f],t);a instanceof s?o=a:e+=a[0]??0}}}),o??E(e)}),i("AVERAGE",1,c,(n,t)=>{const e=h(n,t);return e instanceof s?e:e.length===0?m.DIV0:V(e)/e.length}),i("AVERAGEA",1,c,(n,t)=>{const e=M(n,t);return e instanceof s?e:e.length===0?m.DIV0:V(e)/e.length}),i("COUNT",1,c,(n,t)=>{let e=0;return O(n,t,(o,f)=>{typeof o=="number"?e+=1:f&&!(o instanceof s)&&o!==null&&(h([o],t)instanceof s||(e+=1))}),e}),i("COUNTA",1,c,(n,t)=>{let e=0;return O(n,t,()=>{e+=1}),e}),i("COUNTBLANK",1,1,(n,t)=>{const e=n[0];if(e instanceof s)return e;if(e instanceof R){let f=0;return t.calc.each(e,l=>{l!==""&&(f+=1)}),e.rows*e.cols-f}const o=t.calc.flat(e);return o instanceof g?o.data.filter(f=>f===null||f==="").length:o===null||o===""?1:0});const C=n=>t=>{if(t instanceof s)return t;if(t.length===0)return 0;let e=t[0]??0;for(const o of t)e=n(e,o);return e},N=C((n,t)=>t<n?t:n),L=C((n,t)=>t>n?t:n);i("MIN",1,c,(n,t)=>N(h(n,t))),i("MAX",1,c,(n,t)=>L(h(n,t))),i("MINA",1,c,(n,t)=>N(M(n,t))),i("MAXA",1,c,(n,t)=>L(M(n,t))),i("PRODUCT",1,c,(n,t)=>{const e=h(n,t);return e instanceof s?e:e.length===0?0:E(e.reduce((o,f)=>o*f,1))}),i("SUMSQ",1,c,(n,t)=>{const e=h(n,t);return e instanceof s?e:E(V(e.map(o=>o*o)))}),i("SUMPRODUCT",1,c,(n,t)=>{const e=n.map(r=>P(r,t)),o=e[0];if(o===void 0||o instanceof s)return o??m.VALUE;let{rows:f}=o;const{cols:l}=o,a=r=>r.reference&&r.reference.bottom<b-1?r.reference.rows:r.rows;for(const r of e){if(r instanceof s)return r;if(r.cols!==l||a(r)!==a(o))return m.VALUE;f=Math.min(f,r.rows)}let d=0;for(let r=0;r<f;r++)for(let U=0;U<l;U++){let T=1;for(const p of e){const A=p.at(r,U);if(A instanceof s)return A;T*=typeof A=="number"?A:0}d+=T}return E(d)});const k={1:"AVERAGE",2:"COUNT",3:"COUNTA",4:"MAX",5:"MIN",6:"PRODUCT",7:"STDEV.S",8:"STDEV.P",9:"SUM",10:"VAR.S",11:"VAR.P"};function B(n){if(!(n instanceof D))return!1;const{node:t}=n.shared;return t?.kind==="call"&&t.name==="SUBTOTAL"}i("SUBTOTAL",2,c,(n,t)=>{const e=t.calc.scalar(n[0],t.frame);if(e instanceof s)return e;if(typeof e!="number")return m.VALUE;const o=e<100,f=k[o?e:e-100],l=f===void 0?void 0:I.get(f);if(l?.kind!=="raw")return m.VALUE;const a=[],d=r=>{const U=u=>r.sheet.spec.rows?.[String(u+1)]?.hidden===!0,T=Math.min(r.bottom,r.sheet.lastRow),p=[],A=t.calc.filtered(r.sheet);for(let u=r.top;u<=T;u++)if(!A.has(u)&&!(!o&&U(u)))for(let S=r.left;S<=r.right;S++)p.push(B(r.sheet.at(u,S))?null:t.calc.read(r.sheet,u,S));a.push(new g(p.length,1,p))};for(const r of n.slice(1)){if(r instanceof s)return r;if(r instanceof R)d(r);else if(r instanceof y)r.parts.forEach(d);else return m.VALUE}return l.call(a,t)});
2
+ import{MAX_ROWS as L}from"../../address.js";import{CellError as s,ERR as u,Matrix as V}from"../../values.js";import{FormulaCell as b}from"../../workbook.js";import{finite as S,snap as g}from"../coerce.js";import{Reference as w,Union as D}from"../types.js";import{FUNCTIONS as I,cellsOf as y,eachArg as E,numbersOf as h,numbersOfA as O,raw as i}from"./define.js";function M(n){let t=0;for(const e of n)t=g(t+e,t,e);return t}i("SUM","(r)",(n,t)=>{let e=0,o;return E(n,t,(f,c)=>{if(!o){if(typeof f=="number")e=g(e+f,e,f);else if(f instanceof s)o=f;else if(c){const l=h([f],t);l instanceof s?o=l:e+=l[0]??0}}}),o??S(e)}),i("AVERAGE","(r)",(n,t)=>{const e=h(n,t);return e instanceof s?e:e.length===0?u.DIV0:M(e)/e.length}),i("AVERAGEA","(r)",(n,t)=>{const e=O(n,t);return e instanceof s?e:e.length===0?u.DIV0:M(e)/e.length}),i("COUNT","(r)",(n,t)=>{let e=0;return E(n,t,(o,f)=>{typeof o=="number"?e+=1:f&&!(o instanceof s)&&o!==null&&(h([o],t)instanceof s||(e+=1))}),e}),i("COUNTA","(r)",(n,t)=>{let e=0;return E(n,t,()=>{e+=1}),e}),i("COUNTBLANK","r",(n,t)=>{const e=n[0];if(e instanceof s)return e;if(e instanceof w){let f=0;return t.calc.each(e,c=>{c!==""&&(f+=1)}),e.rows*e.cols-f}const o=t.calc.flat(e);return o instanceof V?o.data.filter(f=>f===null||f==="").length:o===null||o===""?1:0});const R=n=>t=>{if(t instanceof s)return t;if(t.length===0)return 0;let e=t[0]??0;for(const o of t)e=n(e,o);return e},C=R((n,t)=>t<n?t:n),N=R((n,t)=>t>n?t:n);i("MIN","(r)",(n,t)=>C(h(n,t))),i("MAX","(r)",(n,t)=>N(h(n,t))),i("MINA","(r)",(n,t)=>C(O(n,t))),i("MAXA","(r)",(n,t)=>N(O(n,t))),i("PRODUCT","(r)",(n,t)=>{const e=h(n,t);return e instanceof s?e:e.length===0?0:S(e.reduce((o,f)=>o*f,1))}),i("SUMSQ","(r)",(n,t)=>{const e=h(n,t);return e instanceof s?e:S(M(e.map(o=>o*o)))}),i("SUMPRODUCT","(r)",(n,t)=>{const e=n.map(r=>y(r,t)),o=e[0];if(o===void 0||o instanceof s)return o??u.VALUE;let{rows:f}=o;const{cols:c}=o,l=r=>r.reference&&r.reference.bottom<L-1?r.reference.rows:r.rows;for(const r of e){if(r instanceof s)return r;if(r.cols!==c||l(r)!==l(o))return u.VALUE;f=Math.min(f,r.rows)}let A=0;for(let r=0;r<f;r++)for(let d=0;d<c;d++){let p=1;for(const U of e){const m=U.at(r,d);if(m instanceof s)return m;p*=typeof m=="number"?m:0}A+=p}return S(A)});const P={1:"AVERAGE",2:"COUNT",3:"COUNTA",4:"MAX",5:"MIN",6:"PRODUCT",7:"STDEV.S",8:"STDEV.P",9:"SUM",10:"VAR.S",11:"VAR.P"};function k(n){if(!(n instanceof b))return!1;const{node:t}=n.shared;return t?.kind==="call"&&t.name==="SUBTOTAL"}i("SUBTOTAL","v(r)",(n,t)=>{const e=t.calc.scalar(n[0],t.frame);if(e instanceof s)return e;if(typeof e!="number")return u.VALUE;const o=e<100,f=P[o?e:e-100],c=f===void 0?void 0:I.get(f);if(c?.kind!=="raw")return u.VALUE;const l=[],A=r=>{const d=a=>r.sheet.spec.rows?.[String(a+1)]?.hidden===!0,p=Math.min(r.bottom,r.sheet.lastRow),U=[],m=t.calc.filtered(r.sheet);for(let a=r.top;a<=p;a++)if(!m.has(a)&&!(!o&&d(a)))for(let T=r.left;T<=r.right;T++)U.push(k(r.sheet.at(a,T))?null:t.calc.read(r.sheet,a,T));l.push(new V(U.length,1,U))};for(const r of n.slice(1)){if(r instanceof s)return r;if(r instanceof w)A(r);else if(r instanceof D)r.parts.forEach(A);else return u.VALUE}return c.call(l,t)});
@@ -0,0 +1,4 @@
1
+ import { CellError } from "../../values.js";
2
+ /** A number from one unit to another; #N/A for an unknown unit or two of different quantities. */
3
+ export declare function convert(value: number, from: string, to: string): number | CellError;
4
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{CellError as b,ERR as l}from"../../values.js";import{toNumber as I,toText as v}from"../coerce.js";import{scalar as w}from"./define.js";const u=.0254,s=12*u,d=3*s,_=5280*s,g=1852,h=9460730472580800,k=u/72,f=453.59237,E=9.80665,P=f/1e3*E,K=s*P,q=231*u**3/128,R=.00454609,T=101325,O=550*K,N=new Map;function t(a,i){for(const o of a)N.set(o,i)}const e=(a,i)=>({quantity:a,factor:i,prefix:1});t(["g"],e("mass",1)),t(["sg"],{quantity:"mass",factor:P*1e3/s}),t(["lbm"],{quantity:"mass",factor:f}),t(["u"],e("mass",1660538782e-33)),t(["ozm"],{quantity:"mass",factor:f/16}),t(["grain"],{quantity:"mass",factor:f/7e3}),t(["cwt","shweight"],{quantity:"mass",factor:100*f}),t(["uk_cwt","lcwt","hweight"],{quantity:"mass",factor:112*f}),t(["stone"],{quantity:"mass",factor:14*f}),t(["ton"],{quantity:"mass",factor:2e3*f}),t(["uk_ton","LTON","brton"],{quantity:"mass",factor:2240*f}),t(["m"],e("distance",1)),t(["mi"],{quantity:"distance",factor:_}),t(["Nmi"],{quantity:"distance",factor:g}),t(["in"],{quantity:"distance",factor:u}),t(["ft"],{quantity:"distance",factor:s}),t(["yd"],{quantity:"distance",factor:d}),t(["ang"],e("distance",1e-10)),t(["ell"],{quantity:"distance",factor:45*u}),t(["ly"],e("distance",h)),t(["parsec","pc"],e("distance",648e3/Math.PI*149597870700)),t(["Picapt","Pica"],{quantity:"distance",factor:k}),t(["pica"],{quantity:"distance",factor:u/6}),t(["survey_mi"],{quantity:"distance",factor:6336e3/3937}),t(["yr"],{quantity:"time",factor:365.25*86400}),t(["day","d"],{quantity:"time",factor:86400}),t(["hr"],{quantity:"time",factor:3600}),t(["mn","min"],{quantity:"time",factor:60}),t(["sec","s"],e("time",1)),t(["Pa","p"],e("pressure",1)),t(["atm","at"],e("pressure",T)),t(["mmHg"],e("pressure",T/760)),t(["psi"],{quantity:"pressure",factor:P/u**2}),t(["Torr"],{quantity:"pressure",factor:T/760}),t(["N"],e("force",1)),t(["dyn","dy"],e("force",1e-5)),t(["lbf"],{quantity:"force",factor:P}),t(["pond"],e("force",E/1e3)),t(["J"],e("energy",1)),t(["e"],e("energy",1e-7)),t(["c"],e("energy",4.184)),t(["cal"],e("energy",4.1868)),t(["eV","ev"],e("energy",1602176487e-28)),t(["HPh","hh"],{quantity:"energy",factor:O*3600}),t(["Wh","wh"],e("energy",3600)),t(["flb"],{quantity:"energy",factor:K}),t(["BTU","btu"],{quantity:"energy",factor:1055.05585262}),t(["HP","h"],{quantity:"power",factor:O}),t(["PS"],{quantity:"power",factor:75*E}),t(["W","w"],e("power",1)),t(["T"],e("magnetism",1)),t(["ga"],e("magnetism",1e-4));const y=(a,i,o=!1)=>{t(a,{quantity:"volume",factor:i**3,...o?{prefix:3}:{}})};t(["tsp"],{quantity:"volume",factor:q/6}),t(["tspm"],{quantity:"volume",factor:5e-6}),t(["tbs"],{quantity:"volume",factor:q/2}),t(["oz"],{quantity:"volume",factor:q}),t(["cup"],{quantity:"volume",factor:8*q}),t(["pt","us_pt"],{quantity:"volume",factor:16*q}),t(["uk_pt"],{quantity:"volume",factor:R/8}),t(["qt"],{quantity:"volume",factor:32*q}),t(["uk_qt"],{quantity:"volume",factor:R/4}),t(["gal"],{quantity:"volume",factor:128*q}),t(["uk_gal"],{quantity:"volume",factor:R}),t(["l","L","lt"],e("volume",.001)),t(["barrel"],{quantity:"volume",factor:5376*q}),t(["bushel"],{quantity:"volume",factor:2150.42*u**3}),t(["GRT","regton"],{quantity:"volume",factor:100*s**3}),t(["MTON"],{quantity:"volume",factor:40*s**3}),y(["m3","m^3"],1,!0),y(["ang3","ang^3"],1e-10,!0),y(["ft3","ft^3"],s),y(["in3","in^3"],u),y(["ly3","ly^3"],h),y(["mi3","mi^3"],_),y(["yd3","yd^3"],d),y(["Nmi3","Nmi^3"],g),y(["Pica3","Picapt3","Pica^3","Picapt^3"],k);const m=(a,i,o=!1)=>{t(a,{quantity:"area",factor:i**2,...o?{prefix:2}:{}})};t(["uk_acre"],{quantity:"area",factor:4840*d**2}),t(["us_acre"],{quantity:"area",factor:43560*(1200/3937)**2}),t(["ar"],e("area",100)),t(["ha"],{quantity:"area",factor:1e4}),t(["Morgen"],{quantity:"area",factor:2500}),m(["m2","m^2"],1,!0),m(["ang2","ang^2"],1e-10,!0),m(["ft2","ft^2"],s),m(["in2","in^2"],u),m(["ly2","ly^2"],h),m(["mi2","mi^2"],_),m(["yd2","yd^2"],d),m(["Nmi2","Nmi^2"],g),m(["Pica2","Picapt2","Pica^2","Picapt^2"],k),t(["bit"],{quantity:"information",factor:1,prefix:1,binary:!0}),t(["byte"],{quantity:"information",factor:8,prefix:1,binary:!0}),t(["admkn"],{quantity:"speed",factor:6080*s/3600}),t(["kn"],{quantity:"speed",factor:g/3600}),t(["m/h","m/hr"],e("speed",1/3600)),t(["m/s","m/sec"],e("speed",1)),t(["mph"],{quantity:"speed",factor:_/3600});const U={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,h:100,da:10,e:10,d:.1,c:.01,m:.001,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24},L={Yi:2**80,Zi:2**70,Ei:2**60,Pi:2**50,Ti:2**40,Gi:2**30,Mi:2**20,ki:2**10},A={C:{toK:a=>a+273.15,fromK:a=>a-273.15},F:{toK:a=>(a-32)*5/9+273.15,fromK:a=>(a-273.15)*9/5+32},K:{toK:a=>a,fromK:a=>a},Rank:{toK:a=>a*5/9,fromK:a=>a*9/5},Reau:{toK:a=>a*5/4+273.15,fromK:a=>(a-273.15)*4/5}},M={C:"C",cel:"C",F:"F",fah:"F",K:"K",kel:"K",Rank:"Rank",Reau:"Reau"};function C(a){const i=M[a];if(i!==void 0)return{kind:"temperature",scale:i,times:1};const o=N.get(a);if(o)return{kind:"unit",quantity:o.quantity,factor:o.factor};for(const[n,r]of Object.entries(U)){if(!a.startsWith(n))continue;const c=a.slice(n.length);if(M[c]==="K")return{kind:"temperature",scale:"K",times:r};const p=N.get(c);if(p?.prefix!==void 0)return{kind:"unit",quantity:p.quantity,factor:p.factor*r**p.prefix}}for(const[n,r]of Object.entries(L)){if(!a.startsWith(n))continue;const c=N.get(a.slice(n.length));if(c?.binary===!0)return{kind:"unit",quantity:c.quantity,factor:c.factor*r}}}export function convert(a,i,o){const n=C(i),r=C(o);if(!n||!r)return l.NA;if(n.kind==="temperature"||r.kind==="temperature"){if(n.kind!=="temperature"||r.kind!=="temperature")return l.NA;const c=A[n.scale],p=A[r.scale];return!c||!p?l.NA:p.fromK(c.toK(a*n.times))/r.times}return n.quantity!==r.quantity?l.NA:a*n.factor/r.factor}w("CONVERT",3,3,(a,i,o)=>{const n=I(a),r=v(i),c=v(o);return n instanceof b?n:r instanceof b?r:c instanceof b?c:convert(n,r,c)});
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{CellError as d,ERR as g,Matrix as U}from"../../values.js";import{compare as W,numberOfText as A,sameNumber as N}from"../coerce.js";import{Reference as R}from"../types.js";import{cellsOf as h,many as w,raw as p}from"./define.js";export function indexKey(e){if(typeof e=="number")return`n${String(Number(e.toPrecision(15)))}`;if(typeof e=="string")return`t${e.toUpperCase()}`;if(typeof e=="boolean")return e?"bT":"bF"}export function wildcard(e){let n="";for(let t=0;t<e.length;t++){const s=e.charAt(t);s==="~"&&/[*?~]/u.test(e.charAt(t+1))?(t+=1,n+=e.charAt(t).replace(/[*?]/u,"\\$&")):s==="*"?n+="[\\s\\S]*":s==="?"?n+="[\\s\\S]":n+=s.replace(/[.+^${}()|[\]\\/-]/gu,"\\$&")}const r=new RegExp(`^${n}$`,"iu");return t=>r.test(t)}export const hasWildcard=e=>/[*?~]/u.test(e);function b(e){return n=>{if(typeof n=="number")return N(n,e);if(typeof n!="string")return!1;const r=A(n);return r!==void 0&&N(r,e)}}function q(e,n){const r=t=>e===">"?t>0:e===">="?t>=0:e==="<"?t<0:t<=0;return t=>typeof t==typeof n&&r(W(t,n))}export function criterion(e){if(e===null)return{test:b(0),key:"n0"};if(typeof e=="number")return{test:b(e),key:`n${String(Number(e.toPrecision(15)))}`};if(typeof e=="boolean")return{test:o=>o===e,key:e?"bT":"bF"};if(e instanceof d)return{test:o=>o===e};const n=/^(<>|>=|<=|=|>|<)/u.exec(e),r=n?.[1]??"=",t=n?e.slice(r.length):e,s=o=>o===null;if(t==="")return r==="="?{test:n?s:o=>o===null||o===""}:r==="<>"?{test:o=>o!==null}:{test:()=>!1};const c=A(t),f=/^(?:TRUE|FALSE)$/iu.test(t)?t.toUpperCase()==="TRUE":void 0,l=c??f;if(r==="="||r==="<>"){let o,i;if(c!==void 0)o=b(c),i=indexKey(c);else if(f!==void 0)o=u=>u===f,i=indexKey(f);else if(t.startsWith("#"))o=u=>u instanceof d&&u.code===t.toUpperCase();else if(hasWildcard(t)){const u=wildcard(t);o=a=>typeof a=="string"&&u(a)}else{const u=t.toUpperCase();o=a=>typeof a=="string"&&a.toUpperCase()===u,i=indexKey(t)}return r==="="?i===void 0?{test:o}:{test:o,key:i}:{test:u=>!o(u)}}return{test:q(r,l??t)}}function D(e,n){const r=e.reference;if(r?.cols!==1||e.rows<64)return;const t=`crit:${r.key}`,s=n.calc.indexes.get(t);if(s)return s;const c=new Map;for(let f=0;f<e.rows;f++){const l=e.at(f,0),o=i=>{if(i===void 0)return;const u=c.get(i);u?u.push(f):c.set(i,[f])};if(o(indexKey(l)),typeof l=="string"){const i=A(l);i!==void 0&&o(indexKey(i))}}return n.calc.indexes.set(t,c),c}function I(e,n){const r=n.calc.scalar(e,n.frame);return criterion(r)}function T(e,n){const r=[];for(let s=0;s+1<e.length;s+=2){const c=h(e[s],n);if(c instanceof d)return c;const f=I(e[s+1],n);if(f instanceof d)return f;r.push({cells:c,crit:f})}const t=r[0]?.cells;return t&&r.some(s=>!V(s.cells,t))?g.VALUE:r}const V=(e,n)=>e.cols===n.cols&&(e.reference?.rows??e.rows)===(n.reference?.rows??n.rows);function F(e,n,r){const t=e[0];if(!t)return;const s=e.slice(1),c=(o,i)=>s.every(u=>u.crit.test(u.cells.at(o,i))),f=t.crit.key===void 0?void 0:D(t.cells,n);if(f&&t.crit.key!==void 0){for(const o of f.get(t.crit.key)??[])c(o,0)&&r(o,0);return}const l=Math.max(...e.map(o=>o.cells.rows));for(let o=0;o<l;o++)for(let i=0;i<t.cells.cols;i++)t.crit.test(t.cells.at(o,i))&&c(o,i)&&r(o,i)}function K(e,n){return e instanceof R?(e.rows-n.rows)*e.cols:0}function O(e,n,r,t){let s;return F(n,r,(c,f)=>{if(s)return;const l=e.at(c,f);l instanceof d?s=l:typeof l=="number"&&t(l)}),s}function X(e,n){const r=h(e[0],n);if(r instanceof d)return r;const t=e[2];return t===void 0?r:h(t,n)}const L=e=>(n,r)=>{const t=h(n[0],r);if(t instanceof d)return t;const s=I(n[1],r);if(s instanceof d)return s;const c=X(n,r);if(c instanceof d)return c;const f=[];return O(c,[{cells:t,crit:s}],r,o=>{f.push(o)})??e(f)},x=e=>(n,r)=>{if(n.length%2===0)return g.VALUE;const t=h(n[0],r);if(t instanceof d)return t;const s=T(n.slice(1),r);if(s instanceof d)return s;const c=s[0]?.cells;if(c&&!V(t,c))return g.VALUE;const f=[];return O(t,s,r,o=>{f.push(o)})??e(f)},m=(e,n)=>(r,t)=>{const s=new Map;for(const[i,u]of r.entries()){if(!e(i)||!(u instanceof U||u instanceof R&&!u.single))continue;const a=h(u,t);if(a instanceof d)return a;s.set(i,a)}if(s.size===0)return n(r,t);const c=[...s.values()],f=Math.max(...c.map(i=>i.rows)),l=Math.max(...c.map(i=>i.cols)),o=[];for(let i=0;i<f;i++)for(let u=0;u<l;u++){const a=r.map((G,P)=>{const y=s.get(P);if(!y)return G;const $=y.rows===1?0:i,C=y.cols===1?0:u;return $<y.rows&&C<y.cols?y.at($,C):g.NA}),S=n(a,t);o.push(S instanceof U?S.at(0,0):S)}return new U(f,l,o)},k=e=>e===1,E=e=>e>=2&&e%2===0,j=e=>e%2===1,M=e=>e.reduce((n,r)=>n+r,0),z=e=>e.length===0?g.DIV0:M(e)/e.length,B=e=>e.length===0?0:e.reduce((n,r)=>r<n?r:n),H=e=>e.length===0?0:e.reduce((n,r)=>r>n?r:n);p("SUMIF",2,3,m(k,L(M))),p("AVERAGEIF",2,3,m(k,L(z))),p("SUMIFS",3,w,m(E,x(M))),p("AVERAGEIFS",3,w,m(E,x(z))),p("MINIFS",3,w,m(E,x(B))),p("MAXIFS",3,w,m(E,x(H))),p("COUNTIF",2,2,m(k,(e,n)=>{const r=h(e[0],n);if(r instanceof d)return r;const t=I(e[1],n);if(t instanceof d)return t;let s=0;return F([{cells:r,crit:t}],n,()=>{s+=1}),s+(t.test(null)?K(e[0],r):0)})),p("COUNTIFS",2,w,m(j,(e,n)=>{if(e.length%2===1)return g.VALUE;const r=T(e,n);if(r instanceof d)return r;let t=0;return F(r,n,()=>{t+=1}),t}));
2
+ import{CellError as l,ERR as I}from"../../values.js";import{compare as R,numberOfText as S,sameNumber as b}from"../coerce.js";import{Missing as T,Reference as A}from"../types.js";import{indexKeyOf as k}from"../indexes.js";import{cellsOf as h,raw as p}from"./define.js";export function indexKey(e){if(typeof e=="number")return`n${String(Number(e.toPrecision(15)))}`;if(typeof e=="string")return`t${e.toUpperCase()}`;if(typeof e=="boolean")return e?"bT":"bF"}export function wildcard(e){let r="";for(let t=0;t<e.length;t++){const o=e.charAt(t);o==="~"&&/[*?~]/u.test(e.charAt(t+1))?(t+=1,r+=e.charAt(t).replace(/[*?]/u,"\\$&")):o==="*"?r+="[\\s\\S]*":o==="?"?r+="[\\s\\S]":r+=o.replace(/[.+^${}()|[\]\\/-]/gu,"\\$&")}const n=new RegExp(`^${r}$`,"iu");return t=>n.test(t)}export const hasWildcard=e=>/[*?~]/u.test(e);function g(e){return r=>{if(typeof r=="number")return b(r,e);if(typeof r!="string")return!1;const n=S(r);return n!==void 0&&b(n,e)}}function w(e,r){const n=t=>e===">"?t>0:e===">="?t>=0:e==="<"?t<0:t<=0;return t=>typeof t==typeof r&&n(R(t,r))}export function criterion(e){if(e===null)return{test:g(0),key:"n0"};if(typeof e=="number")return{test:g(e),key:`n${String(Number(e.toPrecision(15)))}`};if(typeof e=="boolean")return{test:s=>s===e,key:e?"bT":"bF"};if(e instanceof l)return{test:s=>s===e};const r=/^(<>|>=|<=|=|>|<)/u.exec(e),n=r?.[1]??"=",t=r?e.slice(n.length):e,o=s=>s===null;if(t==="")return n==="="?{test:r?o:s=>s===null||s===""}:n==="<>"?{test:s=>s!==null}:{test:()=>!1};const i=S(t),c=/^(?:TRUE|FALSE)$/iu.test(t)?t.toUpperCase()==="TRUE":void 0,f=i??c;if(n==="="||n==="<>"){let s,u;if(i!==void 0)s=g(i),u=indexKey(i);else if(c!==void 0)s=d=>d===c,u=indexKey(c);else if(t.startsWith("#"))s=d=>d instanceof l&&d.code===t.toUpperCase();else if(hasWildcard(t)){const d=wildcard(t);s=m=>typeof m=="string"&&d(m)}else{const d=t.toUpperCase();s=m=>typeof m=="string"&&m.toUpperCase()===d,u=indexKey(t)}return n==="="?u===void 0?{test:s}:{test:s,key:u}:{test:d=>!s(d)}}return{test:w(n,f??t)}}function O(e,r){const n=e.reference;if(!(n?.cols!==1||e.rows<64))return r.calc.indexes.of(k("crit",n),[n],()=>{const t=new Map,o=(i,c)=>{if(i===void 0)return;const f=t.get(i);f?f.push(c):t.set(i,[c])};for(let i=0;i<e.rows;i++){const c=e.at(i,0);if(o(indexKey(c),i),typeof c=="string"){const f=S(c);f!==void 0&&o(indexKey(f),i)}}return t})}function F(e,r){const n=r.calc.scalar(e,r.frame);return criterion(n)}function $(e,r){const n=[];for(let o=0;o+1<e.length;o+=2){const i=h(e[o],r);if(i instanceof l)return i;const c=F(e[o+1],r);if(c instanceof l)return c;n.push({cells:i,crit:c})}const t=n[0]?.cells;return t&&n.some(o=>!x(o.cells,t))?I.VALUE:n}const x=(e,r)=>e.cols===r.cols&&(e.reference?.rows??e.rows)===(r.reference?.rows??r.rows);function E(e,r,n){const t=e[0];if(!t)return;let o,i;for(const f of e){if(f.crit.key===void 0)continue;const s=O(f.cells,r);if(!s)continue;const u=s.get(f.crit.key)??[];(o===void 0||u.length<o.length)&&(o=u,i=f)}if(o!==void 0){const f=e.filter(s=>s!==i);for(const s of o)f.every(u=>u.crit.test(u.cells.at(s,0)))&&n(s,0);return}const c=Math.max(...e.map(f=>f.cells.rows));for(let f=0;f<c;f++)for(let s=0;s<t.cells.cols;s++)e.every(u=>u.crit.test(u.cells.at(f,s)))&&n(f,s)}function V(e,r){return e instanceof A?(e.rows-r.rows)*e.cols:0}function M(e,r,n,t){let o;return E(r,n,(i,c)=>{if(o)return;const f=e.at(i,c);f instanceof l?o=f:typeof f=="number"&&t(f)}),o}function G(e,r){const n=h(e[0],r);if(n instanceof l)return n;const t=e[2];return t===void 0?n:h(t,r)}const C=e=>(r,n)=>{const t=h(r[0],n);if(t instanceof l)return t;const o=F(r[1],n);if(o instanceof l)return o;const i=G(r,n);if(i instanceof l)return i;const c=[];return M(i,[{cells:t,crit:o}],n,s=>{c.push(s)})??e(c)},y=e=>(r,n)=>{const t=h(r[0],n);if(t instanceof l)return t;const o=$(r.slice(1),n);if(o instanceof l)return o;const i=o[0]?.cells;if(i&&!x(t,i))return I.VALUE;const c=[];return M(t,o,n,s=>{c.push(s)})??e(c)},a=(e,r)=>(n,t)=>{const o=[],i=[e];for(const u of n)if(u instanceof A)o.push(u),i.push(`r${u.key}`);else if(u instanceof T)i.push("-");else if(u instanceof l)i.push(`e${u.code}`);else if(u===null||typeof u!="object")i.push(`${typeof u}:${String(u)}`);else return r(n,t);if(o.length===0)return r(n,t);const c=i.join("\0"),f=t.calc.results.get(c);if(f!==void 0)return f;const s=r(n,t);return(s===null||typeof s!="object"||s instanceof l)&&t.calc.results.set(c,o,s),s},U=e=>e.reduce((r,n)=>r+n,0),N=e=>e.length===0?I.DIV0:U(e)/e.length,j=e=>e.length===0?0:e.reduce((r,n)=>n<r?n:r),v=e=>e.length===0?0:e.reduce((r,n)=>n>r?n:r);p("SUMIF","rv?r",a("SUMIF",C(U))),p("AVERAGEIF","rv?r",a("AVERAGEIF",C(N))),p("SUMIFS","r(rv)",a("SUMIFS",y(U))),p("AVERAGEIFS","r(rv)",a("AVERAGEIFS",y(N))),p("MINIFS","r(rv)",a("MINIFS",y(j))),p("MAXIFS","r(rv)",a("MAXIFS",y(v))),p("COUNTIF","rv",a("COUNTIF",(e,r)=>{const n=h(e[0],r);if(n instanceof l)return n;const t=F(e[1],r);if(t instanceof l)return t;let o=0;return E([{cells:n,crit:t}],r,()=>{o+=1}),o+(t.test(null)?V(e[0],n):0)})),p("COUNTIFS","(rv)",a("COUNTIFS",(e,r)=>{const n=$(e,r);if(n instanceof l)return n;let t=0;return E(n,r,()=>{t+=1}),t}));
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{CellError as s,ERR as c}from"../../values.js";import{compare as U,toText as E}from"../coerce.js";import{FUNCTIONS as p,cellsOf as h,raw as u}from"./define.js";import{criterion as T}from"./criteria.js";function w(n,e){const t=[];for(let o=0;o<n.cols;o++){const f=E(n.at(0,o));if(f instanceof s)return f;t.push(f.toLowerCase())}const r=[];for(let o=1;o<n.rows;o++){let f=e.rows<2;for(let i=1;i<e.rows&&!f;i++){let l=!0;for(let m=0;m<e.cols&&l;m++){const D=e.at(i,m);if(D===null||D==="")continue;const d=E(e.at(0,m));if(d instanceof s)return d;const V=t.indexOf(d.toLowerCase());if(V<0){l=!1;continue}const A=T(D);if(A instanceof s)return A;A.test(n.at(o,V))||(l=!1)}l&&(f=!0)}f&&r.push(o)}return r}function R(n,e){if(typeof e=="number"){const r=Math.trunc(e)-1;return r<0||r>=n.cols?c.VALUE:r}const t=E(e);if(t instanceof s)return t;for(let r=0;r<n.cols;r++){const o=n.at(0,r);if(typeof o=="string"&&U(o,t)===0)return r}return c.VALUE}function a(n,e){const t=h(n[0],e);if(t instanceof s)return t;const r=h(n[2],e);if(r instanceof s)return r;const o=w(t,r);if(o instanceof s)return o;const f=n[1];if(f===void 0)return{list:o.map(()=>null),db:t};const i=R(t,e.calc.scalar(f,e.frame));return i instanceof s?i:{list:o.map(l=>t.at(l,i)),db:t}}function S(n,e){u(n,3,3,(t,r)=>{const o=a(t,r);if(o instanceof s)return o;const f=p.get(e);if(f?.kind!=="raw")return c.VALUE;const i=o.list.filter(l=>typeof l=="number");return f.call([...i.length>0?i:[0]],r)})}for(const[n,e]of[["DSUM","SUM"],["DMAX","MAX"],["DMIN","MIN"],["DPRODUCT","PRODUCT"]])S(n,e);for(const[n,e]of[["DAVERAGE","AVERAGE"],["DSTDEV","STDEV.S"],["DSTDEVP","STDEV.P"],["DVAR","VAR.S"],["DVARP","VAR.P"]])u(n,3,3,(t,r)=>{const o=a(t,r);if(o instanceof s)return o;const f=p.get(e);if(f?.kind!=="raw")return c.VALUE;const i=o.list.filter(l=>typeof l=="number");return i.length===0?c.DIV0:f.call(i,r)});u("DCOUNT",2,3,(n,e)=>{const t=a(n.length===2?[n[0],void 0,n[1]]:n,e);return t instanceof s?t:t.list.filter(r=>typeof r=="number").length}),u("DCOUNTA",2,3,(n,e)=>{const t=a(n.length===2?[n[0],void 0,n[1]]:n,e);return t instanceof s?t:t.list.filter(r=>r!==null).length}),u("DGET",3,3,(n,e)=>{const t=a(n,e);return t instanceof s?t:t.list.length===0?c.VALUE:t.list.length>1?c.NUM:t.list[0]??null});
2
+ import{CellError as s,ERR as c}from"../../values.js";import{compare as U,toText as E}from"../coerce.js";import{FUNCTIONS as p,cellsOf as h,raw as u}from"./define.js";import{criterion as T}from"./criteria.js";function w(n,e){const t=[];for(let o=0;o<n.cols;o++){const f=E(n.at(0,o));if(f instanceof s)return f;t.push(f.toLowerCase())}const r=[];for(let o=1;o<n.rows;o++){let f=e.rows<2;for(let i=1;i<e.rows&&!f;i++){let l=!0;for(let m=0;m<e.cols&&l;m++){const D=e.at(i,m);if(D===null||D==="")continue;const d=E(e.at(0,m));if(d instanceof s)return d;const V=t.indexOf(d.toLowerCase());if(V<0){l=!1;continue}const A=T(D);if(A instanceof s)return A;A.test(n.at(o,V))||(l=!1)}l&&(f=!0)}f&&r.push(o)}return r}function R(n,e){if(typeof e=="number"){const r=Math.trunc(e)-1;return r<0||r>=n.cols?c.VALUE:r}const t=E(e);if(t instanceof s)return t;for(let r=0;r<n.cols;r++){const o=n.at(0,r);if(typeof o=="string"&&U(o,t)===0)return r}return c.VALUE}function a(n,e){const t=h(n[0],e);if(t instanceof s)return t;const r=h(n[2],e);if(r instanceof s)return r;const o=w(t,r);if(o instanceof s)return o;const f=n[1];if(f===void 0)return{list:o.map(()=>null),db:t};const i=R(t,e.calc.scalar(f,e.frame));return i instanceof s?i:{list:o.map(l=>t.at(l,i)),db:t}}function S(n,e){u(n,"rvr",(t,r)=>{const o=a(t,r);if(o instanceof s)return o;const f=p.get(e);if(f?.kind!=="raw")return c.VALUE;const i=o.list.filter(l=>typeof l=="number");return f.call([...i.length>0?i:[0]],r)})}for(const[n,e]of[["DSUM","SUM"],["DMAX","MAX"],["DMIN","MIN"],["DPRODUCT","PRODUCT"]])S(n,e);for(const[n,e]of[["DAVERAGE","AVERAGE"],["DSTDEV","STDEV.S"],["DSTDEVP","STDEV.P"],["DVAR","VAR.S"],["DVARP","VAR.P"]])u(n,"rvr",(t,r)=>{const o=a(t,r);if(o instanceof s)return o;const f=p.get(e);if(f?.kind!=="raw")return c.VALUE;const i=o.list.filter(l=>typeof l=="number");return i.length===0?c.DIV0:f.call(i,r)});u("DCOUNT","rv?r",(n,e)=>{const t=a(n.length===2?[n[0],void 0,n[1]]:n,e);return t instanceof s?t:t.list.filter(r=>typeof r=="number").length}),u("DCOUNTA","rv?r",(n,e)=>{const t=a(n.length===2?[n[0],void 0,n[1]]:n,e);return t instanceof s?t:t.list.filter(r=>r!==null).length}),u("DGET","rvr",(n,e)=>{const t=a(n,e);return t instanceof s?t:t.list.length===0?c.VALUE:t.list.length>1?c.NUM:t.list[0]??null});
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{parseDate as B,parseTime as H,parseValue as I}from"numfmt";import{CellError as c,ERR as i,dateOf as h,serialOf as U}from"../../values.js";import{toBool as X,toNumber as m,toText as Y}from"../coerce.js";import{Missing as O}from"../types.js";import{number as V,numbersOf as b,raw as p,scalar as l}from"./define.js";const d=r=>{const n=m(r);return n instanceof c?n:n<0?i.NUM:Math.floor(n)},R=r=>r%4===0&&r%100!==0||r%400===0,A=(r,n)=>n===2?R(r)?29:28:[4,6,9,11].includes(n)?30:31,W=r=>r.month===2&&r.day===A(r.year,2);l("DATE",3,3,V((r=0,n=1,e=1)=>{const t=Math.trunc(r);if(t<0||t>9999)return i.NUM;const o=U(t<1900?t+1900:t,Math.trunc(n),Math.trunc(e));return o<0?i.NUM:o})),l("TIME",3,3,V((r=0,n=0,e=0)=>{const t=Math.trunc(r)*3600+Math.trunc(n)*60+Math.trunc(e);return t<0?i.NUM:t%86400/86400})),l("YEAR",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).year}),l("MONTH",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).month}),l("DAY",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).day});const L=r=>{const n=m(r);return n instanceof c?n:n<0?i.NUM:Math.round((n-Math.floor(n))*86400)%86400};l("HOUR",1,1,r=>{const n=L(r);return n instanceof c?n:Math.floor(n/3600)}),l("MINUTE",1,1,r=>{const n=L(r);return n instanceof c?n:Math.floor(n/60)%60}),l("SECOND",1,1,r=>{const n=L(r);return n instanceof c?n:n%60}),l("DATEVALUE",1,1,r=>{const n=Y(r);if(n instanceof c)return n;const e=B(n)??I(n);return typeof e?.value=="number"?Math.floor(e.value):i.VALUE}),l("TIMEVALUE",1,1,r=>{const n=Y(r);if(n instanceof c)return n;const e=H(n)??I(n);return typeof e?.value!="number"?i.VALUE:e.value-Math.floor(e.value)});const D=r=>(r%7+6)%7;l("WEEKDAY",1,2,(r,n)=>{const e=d(r);if(e instanceof c)return e;const t=n==null?1:m(n);if(t instanceof c)return t;const o=D(e);return t===1?o+1:t===2?(o+6)%7+1:t===3?(o+6)%7:t>=11&&t<=17?(o+7-(t-10)%7)%7+1:i.NUM});const k=r=>{const n=(D(r)+6)%7,e=r-n+3,{year:t}=h(e);return Math.floor((e-U(t,1,1))/7)+1};l("ISOWEEKNUM",1,1,r=>{const n=d(r);return n instanceof c?n:k(n)}),l("WEEKNUM",1,2,(r,n)=>{const e=d(r);if(e instanceof c)return e;const t=n==null?1:m(n);if(t instanceof c)return t;if(t===21)return k(e);const o=t===1?0:t===2?1:t>=11&&t<=17?(t-10)%7:-1;if(o<0)return i.NUM;const a=U(h(e).year,1,1),s=(D(a)+7-o)%7;return Math.floor((e-a+s)/7)+1});const S=(r,n)=>{const{year:e,month:t,day:o}=h(r),a=e*12+t-1+n,s=Math.floor(a/12),f=a-s*12+1;return U(s,f,Math.min(o,A(s,f)))};l("EDATE",2,2,(r,n)=>{const e=d(r),t=m(n);if(e instanceof c)return e;if(t instanceof c)return t;const o=S(e,Math.trunc(t));return o<0?i.NUM:o}),l("EOMONTH",2,2,(r,n)=>{const e=d(r),t=m(n);if(e instanceof c)return e;if(t instanceof c)return t;const o=h(S(e,Math.trunc(t))),a=U(o.year,o.month,A(o.year,o.month));return a<0?i.NUM:a}),l("DAYS",2,2,(r,n)=>{const e=d(r),t=d(n);return e instanceof c?e:t instanceof c?t:e-t}),l("DATEDIF",3,3,(r,n,e)=>{const t=d(r),o=d(n),a=Y(e);if(t instanceof c)return t;if(o instanceof c)return o;if(a instanceof c)return a;if(t>o)return i.NUM;const s=h(t),f=h(o),u=(f.year-s.year)*12+f.month-s.month-(f.day<s.day?1:0);switch(a.toUpperCase()){case"D":return o-t;case"M":return u;case"Y":return Math.floor(u/12);case"YM":return u%12;case"MD":{if(f.day>=s.day)return f.day-s.day;const y=f.month===1?12:f.month-1,N=f.month===1?f.year-1:f.year;return A(N,y)-s.day+f.day}case"YD":{const y=f.year-s.year-(u%12<0?1:0),N=Math.floor(u/12),M=S(t,N*12);return y>=0?o-M:i.NUM}default:return i.NUM}});function K(r,n,e){const t=h(r),o=h(n);let a=t.day,s=o.day,f=o.month,u=o.year;return e?(a=Math.min(a,30),s=Math.min(s,30)):(a===A(t.year,t.month)&&(a=30),s===31&&(a<30?(s=1,f+=1,f>12&&(f=1,u+=1)):s=30)),(u-t.year)*360+(f-t.month)*30+s-a}l("DAYS360",2,3,(r,n,e)=>{const t=d(r),o=d(n),a=e===void 0?!1:X(e);return t instanceof c?t:o instanceof c?o:a instanceof c?a:K(t,o,a)});export function yearFrac(r,n,e){const[t,o]=r<=n?[r,n]:[n,r],a=h(t),s=h(o),f=o-t;switch(e){case 0:{let u=a.day,y=s.day;return W(a)&&(W(s)&&(y=30),u=30),y===31&&u>=30&&(y=30),u===31&&(u=30),((s.year-a.year)*360+(s.month-a.month)*30+y-u)/360}case 2:return f/360;case 3:return f/365;case 4:return K(t,o,!0)/360;default:{if(a.year===s.year||s.year===a.year+1&&(a.month>s.month||a.month===s.month&&a.day>=s.day)){let M;if(a.year===s.year)M=R(a.year);else{const E=w=>R(w)?U(w,2,29):1/0;M=E(a.year)>=t&&E(a.year)<=o||E(s.year)>=t&&E(s.year)<=o}return f/(M?366:365)}const y=s.year-a.year+1,N=U(s.year+1,1,1)-U(a.year,1,1);return f/(N/y)}}}l("YEARFRAC",2,3,(r,n,e)=>{const t=d(r),o=d(n),a=e==null?0:m(e);if(t instanceof c)return t;if(o instanceof c)return o;if(a instanceof c)return a;const s=Math.trunc(a);return s<0||s>4?i.NUM:yearFrac(t,o,s)});function x(r){const n=(...t)=>[0,1,2,3,4,5,6].map(o=>t.includes(o));if(r==null)return n(0,6);if(typeof r=="string"){if(!/^[01]{7}$/u.test(r)||r==="1111111")return i.VALUE;const t=r.split("").map(o=>o==="1");return[t[6]??!1,...t.slice(0,6)]}const e=m(r);return e instanceof c?e:e>=1&&e<=7?n((e+5)%7,(e+6)%7):e>=11&&e<=17?n(e-11):i.NUM}function _(r,n){if(r===void 0||r instanceof O)return new Set;const e=b([r],n);return e instanceof c?e:new Set(e.map(t=>Math.floor(t)))}function j(r,n,e,t){const o=r<=n?1:-1;let a=0;for(let s=r;o>0?s<=n:s>=n;s+=o)e[D(s)]!==!0&&!t.has(s)&&(a+=o);return a}function P(r,n,e,t){if(e.every(Boolean))return i.VALUE;const o=n<0?-1:1;let a=r;for(let s=Math.abs(n);s>0;)a+=o,e[D(a)]!==!0&&!t.has(a)&&(s-=1);return a<0?i.NUM:a}const v=r=>(n,e)=>{const t=d(e.calc.scalar(n[0],e.frame)),o=d(e.calc.scalar(n[1],e.frame));if(t instanceof c)return t;if(o instanceof c)return o;const a=r?n[2]:void 0,s=x(a===void 0||a instanceof O?void 0:e.calc.scalar(a,e.frame));if(s instanceof c)return s;const f=_(n[r?3:2],e);return f instanceof c?f:j(t,o,s,f)},F=r=>(n,e)=>{const t=d(e.calc.scalar(n[0],e.frame)),o=m(e.calc.scalar(n[1],e.frame));if(t instanceof c)return t;if(o instanceof c)return o;const a=r?n[2]:void 0,s=x(a===void 0||a instanceof O?void 0:e.calc.scalar(a,e.frame));if(s instanceof c)return s;const f=_(n[r?3:2],e);return f instanceof c?f:P(t,Math.trunc(o),s,f)};p("NETWORKDAYS",2,3,v(!1)),p("NETWORKDAYS.INTL",2,4,v(!0)),p("WORKDAY",2,3,F(!1)),p("WORKDAY.INTL",2,4,F(!0)),p("NOW",0,0,(r,n)=>n.calc.nowSerial(),{volatile:!0}),p("TODAY",0,0,(r,n)=>Math.floor(n.calc.nowSerial()),{volatile:!0});function $(r,n,e){const t=e[0]??0;let o=0;return n.forEach((a,s)=>{o+=a/(1+r)**(((e[s]??t)-t)/365)}),o}const C=(r,n)=>{const e=b([r[0]],n);if(e instanceof c)return e;const t=b([r[1]],n);return t instanceof c?t:e.length!==t.length||e.length===0?i.NUM:{values:e,dates:t.map(Math.floor)}};p("XNPV",3,3,(r,n)=>{const e=m(n.calc.scalar(r[0],n.frame));if(e instanceof c)return e;const t=C(r.slice(1),n);return t instanceof c?t:e<=0?i.NUM:$(e,t.values,t.dates)}),p("XIRR",2,3,(r,n)=>{const e=C(r,n);if(e instanceof c)return e;const{values:t,dates:o}=e;if(!t.some(u=>u>0)||!t.some(u=>u<0))return i.NUM;const a=r[2]===void 0||r[2]instanceof O?.1:m(n.calc.scalar(r[2],n.frame));if(a instanceof c)return a;const s=o[0]??0;let f=a;for(let u=0;u<100;u++){let y=0,N=0;t.forEach((E,w)=>{const T=((o[w]??s)-s)/365;y+=E/(1+f)**T,N-=T*E/(1+f)**(T+1)});const M=f-y/N;if(!Number.isFinite(M))return i.NUM;if(Math.abs(M-f)<1e-10)return M;f=M<=-1?(f-1)/2:M}return i.NUM});
2
+ import{parseDate as B,parseTime as H,parseValue as S}from"numfmt";import{CellError as c,ERR as i,dateOf as h,serialOf as U}from"../../values.js";import{toBool as X,toNumber as m,toText as T}from"../coerce.js";import{Missing as O}from"../types.js";import{number as I,numbersOf as Y,raw as p,scalar as l}from"./define.js";const j=2958465,d=r=>{const n=m(r);return n instanceof c?n:n<0||n>=j+1?i.NUM:Math.floor(n)},b=r=>r%4===0&&r%100!==0||r%400===0,A=(r,n)=>n===2?b(r)?29:28:[4,6,9,11].includes(n)?30:31,V=r=>r.month===2&&r.day===A(r.year,2);l("DATE",3,3,I((r=0,n=1,e=1)=>{const t=Math.trunc(r);if(t<0||t>9999)return i.NUM;const o=U(t<1900?t+1900:t,Math.trunc(n),Math.trunc(e));return o<0?i.NUM:o})),l("TIME",3,3,I((r=0,n=0,e=0)=>{const t=Math.trunc(r)*3600+Math.trunc(n)*60+Math.trunc(e);return t<0?i.NUM:t%86400/86400})),l("YEAR",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).year}),l("MONTH",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).month}),l("DAY",1,1,r=>{const n=d(r);return n instanceof c?n:h(n).day});const R=r=>{const n=m(r);return n instanceof c?n:n<0?i.NUM:Math.round((n-Math.floor(n))*86400)%86400};l("HOUR",1,1,r=>{const n=R(r);return n instanceof c?n:Math.floor(n/3600)}),l("MINUTE",1,1,r=>{const n=R(r);return n instanceof c?n:Math.floor(n/60)%60}),l("SECOND",1,1,r=>{const n=R(r);return n instanceof c?n:n%60}),l("DATEVALUE",1,1,r=>{const n=T(r);if(n instanceof c)return n;const e=B(n)??S(n);return typeof e?.value=="number"?Math.floor(e.value):i.VALUE}),l("TIMEVALUE",1,1,r=>{const n=T(r);if(n instanceof c)return n;const e=H(n)??S(n);return typeof e?.value!="number"?i.VALUE:e.value-Math.floor(e.value)});const D=r=>(r%7+6)%7;l("WEEKDAY",1,2,(r,n)=>{const e=d(r);if(e instanceof c)return e;const t=n==null?1:m(n);if(t instanceof c)return t;const o=D(e);return t===1?o+1:t===2?(o+6)%7+1:t===3?(o+6)%7:t>=11&&t<=17?(o+7-(t-10)%7)%7+1:i.NUM});const W=r=>{const n=(D(r)+6)%7,e=r-n+3,{year:t}=h(e);return Math.floor((e-U(t,1,1))/7)+1};l("ISOWEEKNUM",1,1,r=>{const n=d(r);return n instanceof c?n:W(n)}),l("WEEKNUM",1,2,(r,n)=>{const e=d(r);if(e instanceof c)return e;const t=n==null?1:m(n);if(t instanceof c)return t;if(t===21)return W(e);const o=t===1?0:t===2?1:t>=11&&t<=17?(t-10)%7:-1;if(o<0)return i.NUM;const a=U(h(e).year,1,1),s=(D(a)+7-o)%7;return Math.floor((e-a+s)/7)+1});const L=(r,n)=>{const{year:e,month:t,day:o}=h(r),a=e*12+t-1+n,s=Math.floor(a/12),f=a-s*12+1;return U(s,f,Math.min(o,A(s,f)))};l("EDATE",2,2,(r,n)=>{const e=d(r),t=m(n);if(e instanceof c)return e;if(t instanceof c)return t;const o=L(e,Math.trunc(t));return o<0?i.NUM:o}),l("EOMONTH",2,2,(r,n)=>{const e=d(r),t=m(n);if(e instanceof c)return e;if(t instanceof c)return t;const o=h(L(e,Math.trunc(t))),a=U(o.year,o.month,A(o.year,o.month));return a<0?i.NUM:a}),l("DAYS",2,2,(r,n)=>{const e=d(r),t=d(n);return e instanceof c?e:t instanceof c?t:e-t}),l("DATEDIF",3,3,(r,n,e)=>{const t=d(r),o=d(n),a=T(e);if(t instanceof c)return t;if(o instanceof c)return o;if(a instanceof c)return a;if(t>o)return i.NUM;const s=h(t),f=h(o),u=(f.year-s.year)*12+f.month-s.month-(f.day<s.day?1:0);switch(a.toUpperCase()){case"D":return o-t;case"M":return u;case"Y":return Math.floor(u/12);case"YM":return u%12;case"MD":{if(f.day>=s.day)return f.day-s.day;const y=f.month===1?12:f.month-1,N=f.month===1?f.year-1:f.year;return A(N,y)-s.day+f.day}case"YD":{const y=f.year-s.year-(u%12<0?1:0),N=Math.floor(u/12),M=L(t,N*12);return y>=0?o-M:i.NUM}default:return i.NUM}});function _(r,n,e){const t=h(r),o=h(n);let a=t.day,s=o.day,f=o.month,u=o.year;return e?(a=Math.min(a,30),s=Math.min(s,30)):(a===A(t.year,t.month)&&(a=30),s===31&&(a<30?(s=1,f+=1,f>12&&(f=1,u+=1)):s=30)),(u-t.year)*360+(f-t.month)*30+s-a}l("DAYS360",2,3,(r,n,e)=>{const t=d(r),o=d(n),a=e===void 0?!1:X(e);return t instanceof c?t:o instanceof c?o:a instanceof c?a:_(t,o,a)});export function yearFrac(r,n,e){const[t,o]=r<=n?[r,n]:[n,r],a=h(t),s=h(o),f=o-t;switch(e){case 0:{let u=a.day,y=s.day;return V(a)&&(V(s)&&(y=30),u=30),y===31&&u>=30&&(y=30),u===31&&(u=30),((s.year-a.year)*360+(s.month-a.month)*30+y-u)/360}case 2:return f/360;case 3:return f/365;case 4:return _(t,o,!0)/360;default:{if(a.year===s.year||s.year===a.year+1&&(a.month>s.month||a.month===s.month&&a.day>=s.day)){let M;if(a.year===s.year)M=b(a.year);else{const E=w=>b(w)?U(w,2,29):1/0;M=E(a.year)>=t&&E(a.year)<=o||E(s.year)>=t&&E(s.year)<=o}return f/(M?366:365)}const y=s.year-a.year+1,N=U(s.year+1,1,1)-U(a.year,1,1);return f/(N/y)}}}l("YEARFRAC",2,3,(r,n,e)=>{const t=d(r),o=d(n),a=e==null?0:m(e);if(t instanceof c)return t;if(o instanceof c)return o;if(a instanceof c)return a;const s=Math.trunc(a);return s<0||s>4?i.NUM:yearFrac(t,o,s)});function k(r){const n=(...t)=>[0,1,2,3,4,5,6].map(o=>t.includes(o));if(r==null)return n(0,6);if(typeof r=="string"){if(!/^[01]{7}$/u.test(r)||r==="1111111")return i.VALUE;const t=r.split("").map(o=>o==="1");return[t[6]??!1,...t.slice(0,6)]}const e=m(r);return e instanceof c?e:e>=1&&e<=7?n((e+5)%7,(e+6)%7):e>=11&&e<=17?n(e-11):i.NUM}function K(r,n){if(r===void 0||r instanceof O)return new Set;const e=Y([r],n);return e instanceof c?e:new Set(e.map(t=>Math.floor(t)))}function P(r,n,e,t){const o=r<=n?1:-1;let a=0;for(let s=r;o>0?s<=n:s>=n;s+=o)e[D(s)]!==!0&&!t.has(s)&&(a+=o);return a}function $(r,n,e,t){if(e.every(Boolean))return i.VALUE;const o=n<0?-1:1;let a=r;for(let s=Math.abs(n);s>0;)a+=o,e[D(a)]!==!0&&!t.has(a)&&(s-=1);return a<0?i.NUM:a}const x=r=>(n,e)=>{const t=d(e.calc.scalar(n[0],e.frame)),o=d(e.calc.scalar(n[1],e.frame));if(t instanceof c)return t;if(o instanceof c)return o;const a=r?n[2]:void 0,s=k(a===void 0||a instanceof O?void 0:e.calc.scalar(a,e.frame));if(s instanceof c)return s;const f=K(n[r?3:2],e);return f instanceof c?f:P(t,o,s,f)},F=r=>(n,e)=>{const t=d(e.calc.scalar(n[0],e.frame)),o=m(e.calc.scalar(n[1],e.frame));if(t instanceof c)return t;if(o instanceof c)return o;const a=r?n[2]:void 0,s=k(a===void 0||a instanceof O?void 0:e.calc.scalar(a,e.frame));if(s instanceof c)return s;const f=K(n[r?3:2],e);return f instanceof c?f:$(t,Math.trunc(o),s,f)};p("NETWORKDAYS","vv?r",x(!1)),p("NETWORKDAYS.INTL","vv?vr",x(!0)),p("WORKDAY","vv?r",F(!1)),p("WORKDAY.INTL","vv?vr",F(!0)),p("NOW","",(r,n)=>n.calc.nowSerial(),{volatile:!0}),p("TODAY","",(r,n)=>Math.floor(n.calc.nowSerial()),{volatile:!0});function g(r,n,e){const t=e[0]??0;let o=0;return n.forEach((a,s)=>{o+=a/(1+r)**(((e[s]??t)-t)/365)}),o}const C=(r,n)=>{const e=Y([r[0]],n);if(e instanceof c)return e;const t=Y([r[1]],n);return t instanceof c?t:e.length!==t.length||e.length===0?i.NUM:{values:e,dates:t.map(Math.floor)}};p("XNPV","vrr",(r,n)=>{const e=m(n.calc.scalar(r[0],n.frame));if(e instanceof c)return e;const t=C(r.slice(1),n);return t instanceof c?t:e<=0?i.NUM:g(e,t.values,t.dates)}),p("XIRR","rr?v",(r,n)=>{const e=C(r,n);if(e instanceof c)return e;const{values:t,dates:o}=e;if(!t.some(u=>u>0)||!t.some(u=>u<0))return i.NUM;const a=r[2]===void 0||r[2]instanceof O?.1:m(n.calc.scalar(r[2],n.frame));if(a instanceof c)return a;const s=o[0]??0;let f=a;for(let u=0;u<100;u++){let y=0,N=0;t.forEach((E,w)=>{const v=((o[w]??s)-s)/365;y+=E/(1+f)**v,N-=v*E/(1+f)**(v+1)});const M=f-y/N;if(!Number.isFinite(M))return i.NUM;if(Math.abs(M-f)<1e-10)return M;f=M<=-1?(f-1)/2:M}return i.NUM});
@@ -15,6 +15,15 @@ interface Base {
15
15
  /** Where it comes from: this repository, or @formulajs/formulajs. */
16
16
  from: "allyhub" | "formulajs";
17
17
  }
18
+ /** How a parameter is taken: a single value, lifted over an array given to it, or the value whole. */
19
+ export type ParamKind = "value" | "whole";
20
+ /** A raw function's parameters, read from its signature (`params`). */
21
+ export interface Params {
22
+ /** The parameters in order, before any that repeat. */
23
+ readonly fixed: readonly ParamKind[];
24
+ /** Parameters that repeat after the fixed ones, as SUMIFS's range and criterion. */
25
+ readonly group: readonly ParamKind[];
26
+ }
18
27
  export type FunctionDef = Base & ({
19
28
  kind: "scalar";
20
29
  call: (...args: (Scalar | undefined)[]) => Scalar;
@@ -22,6 +31,8 @@ export type FunctionDef = Base & ({
22
31
  errors?: boolean;
23
32
  } | {
24
33
  kind: "raw";
34
+ params: Params;
35
+ /** A parameter taken as a single value arrives as a Scalar, or Missing when left empty. */
25
36
  call: (args: readonly Value[], c: Call) => Value;
26
37
  } | {
27
38
  kind: "lazy";
@@ -30,12 +41,27 @@ export type FunctionDef = Base & ({
30
41
  export declare const FUNCTIONS: Map<string, FunctionDef>;
31
42
  /** A function that takes any number of arguments from `min`. */
32
43
  export declare const many = 255;
44
+ /**
45
+ * A signature, a letter per parameter: `v` a single value, `r` the value
46
+ * whole. A `?` marks where the optional ones start; a group in parentheses
47
+ * at the end repeats, once at least unless a `?` comes before it. SUMIFS is
48
+ * `r(rv)`, VLOOKUP `vrv?v`, CONCAT `(r)`, NOW ``.
49
+ */
50
+ export declare function signature(text: string): Params & {
51
+ min: number;
52
+ max: number;
53
+ };
54
+ /** How the parameter at `i` is taken. */
55
+ export declare function paramAt(p: Params, i: number): ParamKind;
56
+ /** Whether `count` arguments fill a repeating group whole, as Excel asks. */
57
+ export declare function fillsGroup(p: Params, count: number): boolean;
33
58
  export declare function scalar(name: string, min: number, max: number, call: (...args: (Scalar | undefined)[]) => Scalar, o?: {
34
59
  errors?: boolean;
35
60
  volatile?: boolean;
36
61
  from?: Base["from"];
37
62
  }): void;
38
- export declare function raw(name: string, min: number, max: number, call: (args: readonly Value[], c: Call) => Value, o?: {
63
+ /** A function that takes some arguments whole, by its signature (`signature`). */
64
+ export declare function raw(name: string, params: string, call: (args: readonly Value[], c: Call) => Value, o?: {
39
65
  volatile?: boolean;
40
66
  from?: Base["from"];
41
67
  }): void;
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{CellError as a,ERR as c,Matrix as u}from"../../values.js";import{toBool as h,toNumber as l,toText as b}from"../coerce.js";import{Lambda as i,Missing as p,Reference as m,Union as x}from"../types.js";export const FUNCTIONS=new Map;const d=255;export const many=d;export function scalar(e,r,o,n,t={}){FUNCTIONS.set(e,{name:e,min:r,max:o,kind:"scalar",call:n,from:t.from??"allyhub",...t.errors===!0?{errors:!0}:{},...t.volatile===!0?{volatile:!0}:{}})}export function raw(e,r,o,n,t={}){FUNCTIONS.set(e,{name:e,min:r,max:o,kind:"raw",call:n,from:t.from??"allyhub",...t.volatile===!0?{volatile:!0}:{}})}export function lazy(e,r,o,n){FUNCTIONS.set(e,{name:e,min:r,max:o,kind:"lazy",call:n,from:"allyhub"})}export function alias(e,r){const o=FUNCTIONS.get(r);o&&FUNCTIONS.set(e,{...o,name:e})}export function cellsOf(e,r){if(e instanceof a)return e;if(e instanceof x)return c.VALUE;if(e instanceof m){const n=Math.min(e.bottom,e.sheet.lastRow);return{rows:Math.max(0,n-e.top+1),cols:e.cols,at:(t,f)=>r.calc.read(e.sheet,e.top+t,e.left+f),reference:e}}if(e instanceof u)return{rows:e.rows,cols:e.cols,at:(n,t)=>e.at(n,t)};if(e instanceof i)return c.VALUE;const o=e instanceof p?null:e;return{rows:1,cols:1,at:()=>o}}export function eachArg(e,r,o){for(const n of e)if(n instanceof m)r.calc.each(n,t=>{o(t,!1)});else if(n instanceof x)for(const t of n.parts)r.calc.each(t,f=>{o(f,!1)});else if(n instanceof u)for(const t of n.data)t!==null&&o(t,!1);else n instanceof p?o(null,!0):n instanceof i?o(c.VALUE,!0):o(n,!0)}export function eachRow(e,r,o){const n=t=>{for(const f of r.calc.matrix(t).data)o(f,!1)};for(const t of e)if(t instanceof m)n(t);else if(t instanceof x)t.parts.forEach(n);else if(t instanceof u)for(const f of t.data)o(f,!1);else t instanceof p?o(null,!0):t instanceof i?o(c.VALUE,!0):o(t,!0)}export function numbersOf(e,r){const o=[];let n;return eachArg(e,r,(t,f)=>{if(!n){if(t instanceof a)n=t;else if(typeof t=="number")o.push(t);else if(f){const s=l(t);s instanceof a?n=s:o.push(s)}}}),n??o}export function numbersOfA(e,r){const o=[];let n;return eachArg(e,r,(t,f)=>{if(!n)if(t instanceof a)n=t;else if(typeof t=="number")o.push(t);else if(typeof t=="boolean")o.push(t?1:0);else if(f){const s=l(t);s instanceof a?n=s:o.push(s)}else typeof t=="string"&&o.push(0)}),n??o}export const number=e=>(...r)=>{const o=[];for(const n of r){const t=l(n);if(t instanceof a)return t;o.push(t)}return e(...o)};export function textArg(e){return b(e)}export function boolArg(e,r){return e==null?r:h(e)}export function numberArg(e,r){return e===void 0?r:l(e)}
2
+ import{CellError as l,ERR as a,Matrix as i}from"../../values.js";import{toBool as w,toNumber as c,toText as A}from"../coerce.js";import{Lambda as h,Missing as p,Reference as g,Union as x}from"../types.js";export const FUNCTIONS=new Map;const d=255;export const many=d;export function signature(e){const r=/^([vr?]*)(?:\(([vr]+)\))?$/u.exec(e),t=r?.[1];if(t===void 0||(t.match(/\?/gu)??[]).length>1)throw new Error(`"${e}" is not a signature.`);const o=m=>Array.from({length:m.length},(y,b)=>m.charAt(b)==="v"?"value":"whole"),n=o(t.replace("?","")),f=o(r?.[2]??""),s=t.indexOf("?"),u=s>=0?s:n.length+f.length;return{fixed:n,group:f,min:u,max:f.length>0?d:n.length}}export function paramAt(e,r){return r<e.fixed.length?e.fixed[r]??"whole":e.group.length===0?"whole":e.group[(r-e.fixed.length)%e.group.length]??"whole"}export function fillsGroup(e,r){return e.group.length===0||r<=e.fixed.length?!0:(r-e.fixed.length)%e.group.length===0}export function scalar(e,r,t,o,n={}){FUNCTIONS.set(e,{name:e,min:r,max:t,kind:"scalar",call:o,from:n.from??"allyhub",...n.errors===!0?{errors:!0}:{},...n.volatile===!0?{volatile:!0}:{}})}export function raw(e,r,t,o={}){const{min:n,max:f,fixed:s,group:u}=signature(r);FUNCTIONS.set(e,{name:e,min:n,max:f,kind:"raw",params:{fixed:s,group:u},call:t,from:o.from??"allyhub",...o.volatile===!0?{volatile:!0}:{}})}export function lazy(e,r,t,o){FUNCTIONS.set(e,{name:e,min:r,max:t,kind:"lazy",call:o,from:"allyhub"})}export function alias(e,r){const t=FUNCTIONS.get(r);t&&FUNCTIONS.set(e,{...t,name:e})}export function cellsOf(e,r){if(e instanceof l)return e;if(e instanceof x)return a.VALUE;if(e instanceof g){const o=Math.min(e.bottom,e.sheet.lastRow);return{rows:Math.max(0,o-e.top+1),cols:e.cols,at:(n,f)=>r.calc.read(e.sheet,e.top+n,e.left+f),reference:e}}if(e instanceof i)return{rows:e.rows,cols:e.cols,at:(o,n)=>e.at(o,n)};if(e instanceof h)return a.VALUE;const t=e instanceof p?null:e;return{rows:1,cols:1,at:()=>t}}export function eachArg(e,r,t){for(const o of e)if(o instanceof g)r.calc.each(o,n=>{t(n,!1)});else if(o instanceof x)for(const n of o.parts)r.calc.each(n,f=>{t(f,!1)});else if(o instanceof i)for(const n of o.data)n!==null&&t(n,!1);else o instanceof p?t(null,!0):o instanceof h?t(a.VALUE,!0):t(o,!0)}export function eachRow(e,r,t){const o=n=>{for(const f of r.calc.matrix(n).data)t(f,!1)};for(const n of e)if(n instanceof g)o(n);else if(n instanceof x)n.parts.forEach(o);else if(n instanceof i)for(const f of n.data)t(f,!1);else n instanceof p?t(null,!0):n instanceof h?t(a.VALUE,!0):t(n,!0)}export function numbersOf(e,r){const t=[];let o;return eachArg(e,r,(n,f)=>{if(!o){if(n instanceof l)o=n;else if(typeof n=="number")t.push(n);else if(f){const s=c(n);s instanceof l?o=s:t.push(s)}}}),o??t}export function numbersOfA(e,r){const t=[];let o;return eachArg(e,r,(n,f)=>{if(!o)if(n instanceof l)o=n;else if(typeof n=="number")t.push(n);else if(typeof n=="boolean")t.push(n?1:0);else if(f){const s=c(n);s instanceof l?o=s:t.push(s)}else typeof n=="string"&&t.push(0)}),o??t}export const number=e=>(...r)=>{const t=[];for(const o of r){const n=c(o);if(n instanceof l)return n;t.push(n)}return e(...t)};export function textArg(e){return A(e)}export function boolArg(e,r){return e==null?r:w(e)}export function numberArg(e,r){return e===void 0?r:c(e)}
@@ -0,0 +1,16 @@
1
+ import { CellError } from "../../values.js";
2
+ import { type Value } from "../types.js";
3
+ import { type Call } from "./define.js";
4
+ /** Case changed a letter at a time, so a place in the result is the same place in the text: ß stays ß, where toUpperCase makes SS. */
5
+ export declare const eachLetter: (s: string, change: (c: string) => string) => string;
6
+ export declare const lowerLetters: (s: string) => string;
7
+ /** The delimiters given: a text, or every text of a range or an array, row by row; empty cells are none. */
8
+ export declare function delimiters(v: Value | undefined, c: Call): string[] | CellError;
9
+ /** Where any of the delimiters occurs in the text, left to right without overlapping; at one place the longest. */
10
+ export declare function occurrences(text: string, by: readonly string[], ignoreCase: boolean): {
11
+ at: number;
12
+ length: number;
13
+ }[];
14
+ /** Text apart at any of the delimiters. */
15
+ export declare function splitAt(text: string, by: readonly string[], ignoreCase: boolean): string[];
16
+ //# sourceMappingURL=delimiters.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{CellError as c}from"../../values.js";import{toText as u}from"../coerce.js";import{Missing as h}from"../types.js";import{cellsOf as p}from"./define.js";export const eachLetter=(t,s)=>Array.from(t,e=>{const n=s(e);return n.length===e.length?n:e}).join(""),lowerLetters=t=>eachLetter(t,s=>s.toLowerCase());export function delimiters(t,s){if(t===void 0||t instanceof h)return[];const e=p(t,s);if(e instanceof c)return e;const n=[];for(let i=0;i<e.rows;i++)for(let o=0;o<e.cols;o++){const l=e.at(i,o);if(l===null)continue;const r=u(l);if(r instanceof c)return r;n.push(r)}return n}export function occurrences(t,s,e){const n=e?lowerLetters(t):t,i=(e?s.map(lowerLetters):[...s]).filter(r=>r!=="").sort((r,f)=>f.length-r.length),o=[];if(i.length===0)return o;let l=0;for(;l<t.length;){const r=i.find(f=>n.startsWith(f,l));r===void 0?l+=1:(o.push({at:l,length:r.length}),l+=r.length)}return o}export function splitAt(t,s,e){const n=[];let i=0;for(const o of occurrences(t,s,e))n.push(t.slice(i,o.at)),i=o.at+o.length;return n.push(t.slice(i)),n}
@@ -1,2 +1,19 @@
1
- export {};
1
+ import { CellError, Matrix, type Scalar } from "../../values.js";
2
+ import { type Value } from "../types.js";
3
+ import { type Call, type Cells } from "./define.js";
4
+ export declare const rowsOfCells: (m: Cells) => Scalar[][];
5
+ export declare const matrixOf: (rows: readonly (readonly Scalar[])[]) => Matrix;
6
+ export declare const transposed: (rows: readonly (readonly Scalar[])[]) => Scalar[][];
7
+ export declare function numberOf(v: Value | undefined, c: Call, otherwise: number): number | CellError;
8
+ export declare function boolOf(v: Value | undefined, c: Call, otherwise: boolean): boolean | CellError;
9
+ /** A list of whole numbers: one, or a row or a column of them. */
10
+ export declare function indexes(v: Value | undefined, c: Call, otherwise: number): number[] | CellError;
11
+ /** Two lines in Excel's order: blanks last either way. */
12
+ export declare function compareBy(a: Scalar, b: Scalar, descending: boolean): number;
13
+ /** Whether a value keeps its row or column in FILTER. */
14
+ export declare function included(v: Scalar): boolean | CellError;
15
+ /** A value as a key: Excel's UNIQUE takes letters whatever their case. */
16
+ export declare const keyOf: (v: Scalar) => string;
17
+ /** What a LAMBDA gave for one cell: a single value. */
18
+ export declare const oneOf: (v: Value, c: Call) => Scalar;
2
19
  //# sourceMappingURL=dynamic.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{MAX_COLUMNS as Q,MAX_ROWS as j}from"../../address.js";import{compareForSort as q}from"../../sort.js";import{CellError as u,ERR as a,Matrix as E}from"../../values.js";import{toBool as G,toNumber as k,toText as z}from"../coerce.js";import{Lambda as x,Missing as N}from"../types.js";import{cellsOf as m,many as M,raw as w}from"./define.js";const J=5e6,C=n=>Array.from({length:n.rows},(o,e)=>Array.from({length:n.cols},(t,r)=>n.at(e,r))),U=n=>{const o=n[0]?.length??0;return new E(n.length,o,n.flat())},L=n=>{const o=n[0]?.length??0;return Array.from({length:o},(e,t)=>n.map(r=>r[t]??null))};function O(n,o){if(!(n===void 0||n instanceof N))return o.calc.scalar(n,o.frame)}function A(n,o,e){const t=O(n,o);return t==null?e:k(t)}function S(n,o,e){const t=O(n,o);return t==null?e:G(t)}function g(n,o,e){if(n===void 0||n instanceof N)return[e];const t=m(n,o);if(t instanceof u)return t;const r=[];for(let s=0;s<t.rows;s++)for(let f=0;f<t.cols;f++){const i=k(t.at(s,f));if(i instanceof u)return i;r.push(Math.trunc(i))}return r}const T=n=>n===null||n==="";function W(n,o,e){if(T(n)||T(o))return T(n)&&T(o)?0:T(n)?1:-1;const t=q(n,o);return e?-t:t}function Z(n){return n instanceof u?n:n===null?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:a.VALUE}w("FILTER",2,3,(n,o)=>{const e=m(n[0],o),t=m(n[1],o);if(e instanceof u)return e;if(t instanceof u)return t;if(t.rows>1&&t.cols>1)return a.VALUE;const r=t.cols===1&&t.rows===e.rows?!0:t.rows===1&&t.cols===e.cols?!1:void 0;if(r===void 0)return a.VALUE;const s=C(e),f=r?s:L(s),i=[];for(let c=0;c<f.length;c++){const l=Z(r?t.at(c,0):t.at(0,c));if(l instanceof u)return l;l&&i.push(f[c]??[])}return i.length===0?n[2]===void 0||n[2]instanceof N?a.CALC:n[2]:U(r?i:L(i))}),w("SORT",1,4,(n,o)=>{const e=m(n[0],o);if(e instanceof u)return e;const t=g(n[1],o,1);if(t instanceof u)return t;const r=g(n[2],o,1);if(r instanceof u)return r;const s=S(n[3],o,!1);if(s instanceof u)return s;const f=C(e),i=s?L(f):f,c=i[0]?.length??0;if(r.length!==1&&r.length!==t.length)return a.VALUE;if(t.some(h=>h<1||h>c))return a.VALUE;if(r.some(h=>h!==1&&h!==-1))return a.VALUE;const l=i.map((h,d)=>({line:h,index:d})).sort((h,d)=>{for(const[y,p]of t.entries()){const R=r[r.length===1?0:y]??1,V=W(h.line[p-1]??null,d.line[p-1]??null,R<0);if(V!==0)return V}return h.index-d.index}).map(h=>h.line);return U(s?L(l):l)}),w("SORTBY",2,M,(n,o)=>{const e=m(n[0],o);if(e instanceof u)return e;const t=[];let r;for(let c=1;c<n.length;c+=2){const l=m(n[c],o);if(l instanceof u)return l;if(l.rows>1&&l.cols>1)return a.VALUE;const h=l.cols===1&&l.rows===e.rows,d=l.rows===1&&l.cols===e.cols;if(!h&&!d)return a.VALUE;const y=r??h;if(y?!h:!d)return a.VALUE;r=y;const p=A(n[c+1],o,1);if(p instanceof u)return p;if(p!==1&&p!==-1)return a.VALUE;t.push({values:C(l).flat(),descending:p<0})}const s=C(e),i=(r===!1?L(s):s).map((c,l)=>({line:c,index:l})).sort((c,l)=>{for(const{values:h,descending:d}of t){const y=W(h[c.index]??null,h[l.index]??null,d);if(y!==0)return y}return c.index-l.index}).map(c=>c.line);return U(r===!1?L(i):i)});const v=n=>n instanceof u?`e${n.code}`:typeof n=="string"?`s${n.toLowerCase()}`:`${typeof n}${String(n)}`;w("UNIQUE",1,3,(n,o)=>{const e=m(n[0],o);if(e instanceof u)return e;const t=S(n[1],o,!1);if(t instanceof u)return t;const r=S(n[2],o,!1);if(r instanceof u)return r;const s=C(e),f=t?L(s):s,i=new Map;for(const l of f){const h=l.map(v).join("\0"),d=i.get(h);d?d.count+=1:i.set(h,{line:l,count:1})}const c=[...i.values()].filter(l=>!r||l.count===1).map(l=>l.line);return c.length===0?a.CALC:U(t?L(c):c)});function _(n,o){if(n instanceof u)return n;if(o instanceof u)return o;const e=Math.trunc(n),t=Math.trunc(o);return e<0||t<0?a.VALUE:e===0||t===0?a.CALC:e>j||t>Q||e*t>J?a.VALUE:{rows:e,cols:t}}w("SEQUENCE",1,4,(n,o)=>{const e=_(A(n[0],o,1),A(n[1],o,1));if(e instanceof u)return e;const t=A(n[2],o,1);if(t instanceof u)return t;const r=A(n[3],o,1);if(r instanceof u)return r;const s=new Array(e.rows*e.cols);for(let f=0;f<s.length;f++)s[f]=t+f*r;return new E(e.rows,e.cols,s)}),w("RANDARRAY",0,5,(n,o)=>{const e=_(A(n[0],o,1),A(n[1],o,1));if(e instanceof u)return e;const t=A(n[2],o,0);if(t instanceof u)return t;const r=A(n[3],o,1);if(r instanceof u)return r;const s=S(n[4],o,!1);if(s instanceof u)return s;if(t>r)return a.VALUE;if(s&&(!Number.isInteger(t)||!Number.isInteger(r)))return a.VALUE;const f=new Array(e.rows*e.cols);for(let i=0;i<f.length;i++){const c=o.calc.random();f[i]=s?t+Math.floor(c*(r-t+1)):t+c*(r-t)}return new E(e.rows,e.cols,f)},{volatile:!0});function P(n,o){if(n===void 0||n instanceof N)return[];const e=m(n,o);if(e instanceof u)return e;const t=[];for(const r of C(e).flat()){if(r===null)continue;const s=z(r);if(s instanceof u)return s;t.push(s)}return t}function B(n,o,e){const t=e?n.toLowerCase():n,r=(e?o.map(c=>c.toLowerCase()):[...o]).sort((c,l)=>l.length-c.length),s=[];let f=0,i=0;for(;i<n.length;){const c=r.find(l=>l!==""&&t.startsWith(l,i));c===void 0?i+=1:(s.push(n.slice(f,i)),i+=c.length,f=i)}return s.push(n.slice(f)),s}w("TEXTSPLIT",2,6,(n,o)=>{const e=O(n[0],o);if(e instanceof u)return e;const t=z(e??"");if(t instanceof u)return t;const r=P(n[1],o);if(r instanceof u)return r;const s=P(n[2],o);if(s instanceof u)return s;if(r.length===0&&s.length===0)return a.VALUE;if(r.includes("")||s.includes(""))return a.VALUE;const f=S(n[3],o,!1);if(f instanceof u)return f;const i=A(n[4],o,0);if(i instanceof u)return i;const c=O(n[5],o)??a.NA,l=i===1,d=(s.length===0?[t]:B(t,s,l)).filter(p=>!(f&&p==="")).map(p=>{const R=r.length===0?[p]:B(p,r,l);return f?R.filter(V=>V!==""):R}),y=Math.max(0,...d.map(p=>p.length));return d.length===0||y===0?a.CALC:U(d.map(p=>Array.from({length:y},(R,V)=>p[V]??c)))});const b=(n,o)=>{const e=o.calc.flat(n);return e instanceof E?e.at(0,0):e};w("MAP",2,M,(n,o)=>{const e=n[n.length-1];if(!(e instanceof x))return a.VALUE;const t=[];for(const c of n.slice(0,-1)){const l=m(c,o);if(l instanceof u)return l;t.push(l)}const r=t[0];if(!r)return a.VALUE;const{rows:s,cols:f}=r;if(t.some(c=>c.rows!==s||c.cols!==f))return a.VALUE;const i=new Array(s*f);for(let c=0;c<s;c++)for(let l=0;l<f;l++)i[c*f+l]=b(o.calc.apply(e,t.map(h=>h.at(c,l))),o);return new E(s,f,i)});function I(n,o){const e=n.length===3,t=n[n.length-1];if(!(t instanceof x))return a.VALUE;const r=m(n[e?1:0],o);return r instanceof u?r:{start:e?O(n[0],o)??null:r.at(0,0),cells:r,fn:t}}w("REDUCE",2,3,(n,o)=>{const e=I(n,o);if(e instanceof u)return e;const{cells:t,fn:r}=e,s=n.length===3?0:1;let f=e.start;for(let i=s;i<t.rows*t.cols;i++)f=b(o.calc.apply(r,[f,t.at(Math.floor(i/t.cols),i%t.cols)]),o);return f}),w("SCAN",2,3,(n,o)=>{const e=I(n,o);if(e instanceof u)return e;const{cells:t,fn:r}=e,s=t.rows*t.cols,f=n.length===3?0:1,i=new Array(s);let c=e.start;f===1&&(i[0]=c);for(let l=f;l<s;l++)c=b(o.calc.apply(r,[c,t.at(Math.floor(l/t.cols),l%t.cols)]),o),i[l]=c;return new E(t.rows,t.cols,i)});const Y=n=>(o,e)=>{const t=m(o[0],e);if(t instanceof u)return t;const r=o[1];if(!(r instanceof x))return a.VALUE;const s=C(t),i=(n?s:L(s)).map(c=>b(e.calc.apply(r,[n?new E(1,c.length,c):new E(c.length,1,c)]),e));return n?new E(i.length,1,i):new E(1,i.length,i)};w("BYROW",2,2,Y(!0)),w("BYCOL",2,2,Y(!1)),w("MAKEARRAY",3,3,(n,o)=>{const e=_(A(n[0],o,1),A(n[1],o,1));if(e instanceof u)return e;const t=n[2];if(!(t instanceof x))return a.VALUE;const r=new Array(e.rows*e.cols);for(let s=0;s<e.rows;s++)for(let f=0;f<e.cols;f++)r[s*e.cols+f]=b(o.calc.apply(t,[s+1,f+1]),o);return new E(e.rows,e.cols,r)});function D(n){return(o,e)=>{const t=[];for(const f of o){const i=m(f,e);if(i instanceof u)return i;const c=C(i);t.push(n?c:L(c))}const r=Math.max(0,...t.map(f=>f[0]?.length??0)),s=t.flatMap(f=>f.map(i=>Array.from({length:r},(c,l)=>l<i.length?i[l]??null:a.NA)));return s.length===0?a.CALC:U(n?s:L(s))}}w("VSTACK",1,M,D(!0)),w("HSTACK",1,M,D(!1));function K(n,o,e){const t=Math.min(n,Math.abs(o));return e?o>=0?[0,t]:[n-t,n]:o>=0?[t,n]:[0,n-t]}function X(n){return(o,e)=>{const t=m(o[0],e);if(t instanceof u)return t;const r=d=>d===void 0||d instanceof N,s=A(o[1],e,n?t.rows:0);if(s instanceof u)return s;const f=A(o[2],e,n?t.cols:0);if(f instanceof u)return f;if(n&&!r(o[1])&&Math.trunc(s)===0)return a.CALC;if(n&&!r(o[2])&&Math.trunc(f)===0)return a.CALC;const[i,c]=K(t.rows,Math.trunc(s),n),[l,h]=K(t.cols,Math.trunc(f),n);return c<=i||h<=l?a.CALC:U(C(t).slice(i,c).map(d=>d.slice(l,h)))}}w("TAKE",2,3,X(!0)),w("DROP",2,3,X(!1));function $(n){return(o,e)=>{const t=m(o[0],e);if(t instanceof u)return t;const r=A(o[1],e,0);if(r instanceof u)return r;const s=S(o[2],e,!1);if(s instanceof u)return s;if(![0,1,2,3].includes(r))return a.VALUE;const f=C(t),c=(s?L(f):f).flat().filter(l=>!((r===1||r===3)&&l===null||(r===2||r===3)&&l instanceof u));return c.length===0?a.CALC:n?new E(c.length,1,c):new E(1,c.length,c)}}w("TOCOL",1,3,$(!0)),w("TOROW",1,3,$(!1));function H(n){return(o,e)=>{const t=m(o[0],e);if(t instanceof u)return t;const r=C(t),s=n?r:L(r),f=[];for(const i of o.slice(1)){const c=g(i,e,1);if(c instanceof u)return c;for(const l of c){const h=s[l>0?l-1:s.length+l];if(l===0||!h)return a.VALUE;f.push(h)}}return U(n?f:L(f))}}w("CHOOSEROWS",2,M,H(!0)),w("CHOOSECOLS",2,M,H(!1)),w("EXPAND",2,4,(n,o)=>{const e=m(n[0],o);if(e instanceof u)return e;const t=_(A(n[1],o,e.rows),A(n[2],o,e.cols));if(t instanceof u)return t;if(t.rows<e.rows||t.cols<e.cols)return a.VALUE;const r=O(n[3],o)??a.NA,s=new Array(t.rows*t.cols);for(let f=0;f<t.rows;f++)for(let i=0;i<t.cols;i++)s[f*t.cols+i]=f<e.rows&&i<e.cols?e.at(f,i):r;return new E(t.rows,t.cols,s)});function F(n){return(o,e)=>{const t=m(o[0],e);if(t instanceof u)return t;if(t.rows>1&&t.cols>1)return a.VALUE;const r=A(o[1],e,1);if(r instanceof u)return r;const s=Math.trunc(r);if(s<1)return a.NUM;const f=O(o[2],e)??a.NA,i=C(t).flat(),c=[];for(let l=0;l<i.length;l+=s)c.push(Array.from({length:s},(h,d)=>l+d<i.length?i[l+d]??null:f));return U(n?c:L(c))}}w("WRAPROWS",2,3,F(!0)),w("WRAPCOLS",2,3,F(!1));
2
+ import{MAX_COLUMNS as P,MAX_ROWS as B}from"../../address.js";import{compareForSort as I}from"../../sort.js";import{CellError as u,ERR as a,Matrix as m}from"../../values.js";import{toBool as Y,toNumber as x,toText as D}from"../coerce.js";import{Lambda as O,Missing as V}from"../types.js";import{cellsOf as w,raw as p}from"./define.js";import{delimiters as S,splitAt as R}from"./delimiters.js";const K=5e6;export const rowsOfCells=n=>Array.from({length:n.rows},(e,r)=>Array.from({length:n.cols},(t,o)=>n.at(r,o))),matrixOf=n=>{const e=n[0]?.length??0;return new m(n.length,e,n.flat())},transposed=n=>{const e=n[0]?.length??0;return Array.from({length:e},(r,t)=>n.map(o=>o[t]??null))};function E(n,e){if(!(n===void 0||n instanceof V))return e.calc.scalar(n,e.frame)}export function numberOf(n,e,r){const t=E(n,e);return t==null?r:x(t)}export function boolOf(n,e,r){const t=E(n,e);return t==null?r:Y(t)}export function indexes(n,e,r){if(n===void 0||n instanceof V)return[r];const t=w(n,e);if(t instanceof u)return t;const o=[];for(let s=0;s<t.rows;s++)for(let c=0;c<t.cols;c++){const i=x(t.at(s,c));if(i instanceof u)return i;o.push(Math.trunc(i))}return o}const U=n=>n===null||n==="";export function compareBy(n,e,r){if(U(n)||U(e))return U(n)&&U(e)?0:U(n)?1:-1;const t=I(n,e);return r?-t:t}export function included(n){return n instanceof u?n:n===null?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:a.VALUE}p("FILTER","rr?r",(n,e)=>{const r=w(n[0],e),t=w(n[1],e);if(r instanceof u)return r;if(t instanceof u)return t;if(t.rows>1&&t.cols>1)return a.VALUE;const o=t.cols===1&&t.rows===r.rows?!0:t.rows===1&&t.cols===r.cols?!1:void 0;if(o===void 0)return a.VALUE;const s=rowsOfCells(r),c=o?s:transposed(s),i=[];for(let f=0;f<c.length;f++){const l=included(o?t.at(f,0):t.at(0,f));if(l instanceof u)return l;l&&i.push(c[f]??[])}return i.length===0?n[2]===void 0||n[2]instanceof V?a.CALC:n[2]:matrixOf(o?i:transposed(i))}),p("SORT","r?rrr",(n,e)=>{const r=w(n[0],e);if(r instanceof u)return r;const t=indexes(n[1],e,1);if(t instanceof u)return t;const o=indexes(n[2],e,1);if(o instanceof u)return o;const s=boolOf(n[3],e,!1);if(s instanceof u)return s;const c=rowsOfCells(r),i=s?transposed(c):c,f=i[0]?.length??0;if(o.length!==1&&o.length!==t.length)return a.VALUE;if(t.some(h=>h<1||h>f))return a.VALUE;if(o.some(h=>h!==1&&h!==-1))return a.VALUE;const l=i.map((h,A)=>({line:h,index:A})).sort((h,A)=>{for(const[L,d]of t.entries()){const y=o[o.length===1?0:L]??1,C=compareBy(h.line[d-1]??null,A.line[d-1]??null,y<0);if(C!==0)return C}return h.index-A.index}).map(h=>h.line);return matrixOf(s?transposed(l):l)}),p("SORTBY","r(r)",(n,e)=>{const r=w(n[0],e);if(r instanceof u)return r;const t=[];let o;for(let f=1;f<n.length;f+=2){const l=w(n[f],e);if(l instanceof u)return l;if(l.rows>1&&l.cols>1)return a.VALUE;const h=l.cols===1&&l.rows===r.rows,A=l.rows===1&&l.cols===r.cols;if(!h&&!A)return a.VALUE;const L=o??h;if(L?!h:!A)return a.VALUE;o=L;const d=numberOf(n[f+1],e,1);if(d instanceof u)return d;if(d!==1&&d!==-1)return a.VALUE;t.push({values:rowsOfCells(l).flat(),descending:d<0})}const s=rowsOfCells(r),i=(o===!1?transposed(s):s).map((f,l)=>({line:f,index:l})).sort((f,l)=>{for(const{values:h,descending:A}of t){const L=compareBy(h[f.index]??null,h[l.index]??null,A);if(L!==0)return L}return f.index-l.index}).map(f=>f.line);return matrixOf(o===!1?transposed(i):i)});export const keyOf=n=>n instanceof u?`e${n.code}`:typeof n=="string"?`s${n.toLowerCase()}`:`${typeof n}${String(n)}`;p("UNIQUE","r?rr",(n,e)=>{const r=w(n[0],e);if(r instanceof u)return r;const t=boolOf(n[1],e,!1);if(t instanceof u)return t;const o=boolOf(n[2],e,!1);if(o instanceof u)return o;const s=rowsOfCells(r),c=t?transposed(s):s,i=new Map;for(const l of c){const h=l.map(keyOf).join("\0"),A=i.get(h);A?A.count+=1:i.set(h,{line:l,count:1})}const f=[...i.values()].filter(l=>!o||l.count===1).map(l=>l.line);return f.length===0?a.CALC:matrixOf(t?transposed(f):f)});function M(n,e){if(n instanceof u)return n;if(e instanceof u)return e;const r=Math.trunc(n),t=Math.trunc(e);return r<0||t<0?a.VALUE:r===0||t===0?a.CALC:r>B||t>P||r*t>K?a.VALUE:{rows:r,cols:t}}p("SEQUENCE","r?rrr",(n,e)=>{const r=M(numberOf(n[0],e,1),numberOf(n[1],e,1));if(r instanceof u)return r;const t=numberOf(n[2],e,1);if(t instanceof u)return t;const o=numberOf(n[3],e,1);if(o instanceof u)return o;const s=new Array(r.rows*r.cols);for(let c=0;c<s.length;c++)s[c]=t+c*o;return new m(r.rows,r.cols,s)}),p("RANDARRAY","?rrrrr",(n,e)=>{const r=M(numberOf(n[0],e,1),numberOf(n[1],e,1));if(r instanceof u)return r;const t=numberOf(n[2],e,0);if(t instanceof u)return t;const o=numberOf(n[3],e,1);if(o instanceof u)return o;const s=boolOf(n[4],e,!1);if(s instanceof u)return s;if(t>o)return a.VALUE;if(s&&(!Number.isInteger(t)||!Number.isInteger(o)))return a.VALUE;const c=new Array(r.rows*r.cols);for(let i=0;i<c.length;i++){const f=e.calc.random();c[i]=s?t+Math.floor(f*(o-t+1)):t+f*(o-t)}return new m(r.rows,r.cols,c)},{volatile:!0}),p("TEXTSPLIT","vr?rvvv",(n,e)=>{const r=E(n[0],e);if(r instanceof u)return r;const t=D(r??"");if(t instanceof u)return t;const o=S(n[1],e);if(o instanceof u)return o;const s=S(n[2],e);if(s instanceof u)return s;if(o.length===0&&s.length===0)return a.VALUE;if(o.includes("")||s.includes(""))return a.VALUE;const c=boolOf(n[3],e,!1);if(c instanceof u)return c;const i=numberOf(n[4],e,0);if(i instanceof u)return i;const f=E(n[5],e)??a.NA,l=i===1,A=(s.length===0?[t]:R(t,s,l)).filter(d=>!(c&&d==="")).map(d=>{const y=o.length===0?[d]:R(d,o,l);return c?y.filter(C=>C!==""):y}),L=Math.max(0,...A.map(d=>d.length));return A.length===0||L===0?a.CALC:matrixOf(A.map(d=>Array.from({length:L},(y,C)=>d[C]??f)))});export const oneOf=(n,e)=>{const r=e.calc.flat(n);return r instanceof m?r.at(0,0):r};p("MAP","r(r)",(n,e)=>{const r=n[n.length-1];if(!(r instanceof O))return a.VALUE;const t=[];for(const f of n.slice(0,-1)){const l=w(f,e);if(l instanceof u)return l;t.push(l)}const o=t[0];if(!o)return a.VALUE;const{rows:s,cols:c}=o;if(t.some(f=>f.rows!==s||f.cols!==c))return a.VALUE;const i=new Array(s*c);for(let f=0;f<s;f++)for(let l=0;l<c;l++)i[f*c+l]=oneOf(e.calc.apply(r,t.map(h=>h.at(f,l))),e);return new m(s,c,i)});function N(n,e){const r=n.length===3,t=n[n.length-1];if(!(t instanceof O))return a.VALUE;const o=w(n[r?1:0],e);return o instanceof u?o:{start:r?E(n[0],e)??null:o.at(0,0),cells:o,fn:t}}p("REDUCE","rr?r",(n,e)=>{const r=N(n,e);if(r instanceof u)return r;const{cells:t,fn:o}=r,s=n.length===3?0:1;let c=r.start;for(let i=s;i<t.rows*t.cols;i++)c=oneOf(e.calc.apply(o,[c,t.at(Math.floor(i/t.cols),i%t.cols)]),e);return c}),p("SCAN","rr?r",(n,e)=>{const r=N(n,e);if(r instanceof u)return r;const{cells:t,fn:o}=r,s=t.rows*t.cols,c=n.length===3?0:1,i=new Array(s);let f=r.start;c===1&&(i[0]=f);for(let l=c;l<s;l++)f=oneOf(e.calc.apply(o,[f,t.at(Math.floor(l/t.cols),l%t.cols)]),e),i[l]=f;return new m(t.rows,t.cols,i)});const T=n=>(e,r)=>{const t=w(e[0],r);if(t instanceof u)return t;const o=e[1];if(!(o instanceof O))return a.VALUE;const s=rowsOfCells(t),i=(n?s:transposed(s)).map(f=>oneOf(r.calc.apply(o,[n?new m(1,f.length,f):new m(f.length,1,f)]),r));return n?new m(i.length,1,i):new m(1,i.length,i)};p("BYROW","rr",T(!0)),p("BYCOL","rr",T(!1)),p("MAKEARRAY","rrr",(n,e)=>{const r=M(numberOf(n[0],e,1),numberOf(n[1],e,1));if(r instanceof u)return r;const t=n[2];if(!(t instanceof O))return a.VALUE;const o=new Array(r.rows*r.cols);for(let s=0;s<r.rows;s++)for(let c=0;c<r.cols;c++)o[s*r.cols+c]=oneOf(e.calc.apply(t,[s+1,c+1]),e);return new m(r.rows,r.cols,o)});function b(n){return(e,r)=>{const t=[];for(const c of e){const i=w(c,r);if(i instanceof u)return i;const f=rowsOfCells(i);t.push(n?f:transposed(f))}const o=Math.max(0,...t.map(c=>c[0]?.length??0)),s=t.flatMap(c=>c.map(i=>Array.from({length:o},(f,l)=>l<i.length?i[l]??null:a.NA)));return s.length===0?a.CALC:matrixOf(n?s:transposed(s))}}p("VSTACK","(r)",b(!0)),p("HSTACK","(r)",b(!1));function _(n,e,r){const t=Math.min(n,Math.abs(e));return r?e>=0?[0,t]:[n-t,n]:e>=0?[t,n]:[0,n-t]}function k(n){return(e,r)=>{const t=w(e[0],r);if(t instanceof u)return t;const o=A=>A===void 0||A instanceof V,s=numberOf(e[1],r,n?t.rows:0);if(s instanceof u)return s;const c=numberOf(e[2],r,n?t.cols:0);if(c instanceof u)return c;if(n&&!o(e[1])&&Math.trunc(s)===0)return a.CALC;if(n&&!o(e[2])&&Math.trunc(c)===0)return a.CALC;const[i,f]=_(t.rows,Math.trunc(s),n),[l,h]=_(t.cols,Math.trunc(c),n);return f<=i||h<=l?a.CALC:matrixOf(rowsOfCells(t).slice(i,f).map(A=>A.slice(l,h)))}}p("TAKE","rr?r",k(!0)),p("DROP","rr?r",k(!1));function z(n){return(e,r)=>{const t=w(e[0],r);if(t instanceof u)return t;const o=numberOf(e[1],r,0);if(o instanceof u)return o;const s=boolOf(e[2],r,!1);if(s instanceof u)return s;if(![0,1,2,3].includes(o))return a.VALUE;const c=rowsOfCells(t),f=(s?transposed(c):c).flat().filter(l=>!((o===1||o===3)&&l===null||(o===2||o===3)&&l instanceof u));return f.length===0?a.CALC:n?new m(f.length,1,f):new m(1,f.length,f)}}p("TOCOL","r?rr",z(!0)),p("TOROW","r?rr",z(!1));function g(n){return(e,r)=>{const t=w(e[0],r);if(t instanceof u)return t;const o=rowsOfCells(t),s=n?o:transposed(o),c=[];for(const i of e.slice(1)){const f=indexes(i,r,1);if(f instanceof u)return f;for(const l of f){const h=s[l>0?l-1:s.length+l];if(l===0||!h)return a.VALUE;c.push(h)}}return matrixOf(n?c:transposed(c))}}p("CHOOSEROWS","r(r)",g(!0)),p("CHOOSECOLS","r(r)",g(!1)),p("EXPAND","rr?rr",(n,e)=>{const r=w(n[0],e);if(r instanceof u)return r;const t=M(numberOf(n[1],e,r.rows),numberOf(n[2],e,r.cols));if(t instanceof u)return t;if(t.rows<r.rows||t.cols<r.cols)return a.VALUE;const o=E(n[3],e)??a.NA,s=new Array(t.rows*t.cols);for(let c=0;c<t.rows;c++)for(let i=0;i<t.cols;i++)s[c*t.cols+i]=c<r.rows&&i<r.cols?r.at(c,i):o;return new m(t.rows,t.cols,s)});function W(n){return(e,r)=>{const t=w(e[0],r);if(t instanceof u)return t;if(t.rows>1&&t.cols>1)return a.VALUE;const o=numberOf(e[1],r,1);if(o instanceof u)return o;const s=Math.trunc(o);if(s<1)return a.NUM;const c=E(e[2],r)??a.NA,i=rowsOfCells(t).flat(),f=[];for(let l=0;l<i.length;l+=s)f.push(Array.from({length:s},(h,A)=>l+A<i.length?i[l+A]??null:c));return matrixOf(n?f:transposed(f))}}p("WRAPROWS","rr?r",W(!0)),p("WRAPCOLS","rr?r",W(!1));
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{CellError as I,ERR as N,dateOf as g,serialOf as x}from"../../values.js";import{toBool as B,toNumber as H}from"../coerce.js";import{yearFrac as C}from"./date.js";import{number as J,scalar as O}from"./define.js";const F=(o,e)=>g(x(o,e+1,0)).day,T=(o,e,n)=>n===0||n===4?Math.round(C(o,e,n)*360):e-o;function A(o,e,n){const t=g(o),c=t.year*12+t.month-1+e,s=Math.floor(c/12),i=c-s*12+1,u=F(s,i);return x(s,i,n?u:Math.min(t.day,u))}const S=o=>{const e=g(o);return e.day===F(e.year,e.month)};function w(o,e,n,t){const c=12/n,s=S(e);let i=0,u=e;for(;u>o;)i+=1,u=A(e,-c*i,s);const a=A(e,-c*(i-1),s),l=t===1?a-u:t===3?365/n:360/n,f=T(u,o,t);return{previous:u,next:a,count:i,period:l,since:f,until:t===0||t===4?l-f:a-o}}function R(o,e){const n=[];for(const[t,c]of e.entries()){const s=o[t],i=s==null?c??0:H(s);if(i instanceof I)return i;n.push(i)}return n}const P=o=>Number.isInteger(o)&&o>=0&&o<=4,L=o=>o===1||o===2||o===4;function D(o,e,n,t){O(o,e,n.length,(...c)=>{const s=R(c,n);if(s instanceof I)return s;const[i=0,u=0,...a]=s,l=Math.trunc(i),f=Math.trunc(u),h=Math.trunc(a[a.length-1]??0);return l>=f||!P(h)?N.NUM:t(l,f,...a.slice(0,-1),h)})}const r=void 0;for(const[o,e]of[["COUPDAYBS",n=>n.since],["COUPDAYS",n=>n.period],["COUPDAYSNC",n=>n.until],["COUPNCD",n=>n.next],["COUPNUM",n=>n.count],["COUPPCD",n=>n.previous]])D(o,3,[r,r,r,0],(n,t,c=0,s=0)=>L(c)?e(w(n,t,c,s)):N.NUM);function Y(o,e,n,t,c,s,i){const u=w(o,e,s,i),a=100*n/s,l=u.until/u.period;if(u.count===1)return(c+a)/(1+l*t/s)-a*u.since/u.period;let f=c/(1+t/s)**(u.count-1+l);for(let h=1;h<=u.count;h++)f+=a/(1+t/s)**(h-1+l);return f-a*u.since/u.period}D("PRICE",6,[r,r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0,i=0)=>n<0||t<0||c<=0||!L(s)?N.NUM:Y(o,e,n,t,c,s,i)),D("YIELD",6,[r,r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0,i=0)=>{if(n<0||t<=0||c<=0||!L(s))return N.NUM;let u=-.99,a=1;for(;Y(o,e,n,a,c,s,i)>t&&a<1e6;)a*=2;for(let l=0;l<200;l++){const f=(u+a)/2;Y(o,e,n,f,c,s,i)>t?u=f:a=f}return(u+a)/2});function b(o,e,n,t,c,s){const i=w(o,e,c,s),u=i.until/i.period;let a=0,l=0;for(let f=1;f<=i.count;f++){const h=f-1+u,M=(100*n/c+(f===i.count?100:0))/(1+t/c)**h;a+=h*M,l+=M}return a/l/c}D("DURATION",5,[r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0)=>n<0||t<0||!L(c)?N.NUM:b(o,e,n,t,c,s)),D("MDURATION",5,[r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0)=>n<0||t<0||!L(c)?N.NUM:b(o,e,n,t,c,s)/(1+t/c)),D("DISC",4,[r,r,r,r,0],(o,e,n=0,t=0,c=0)=>n<=0||t<=0?N.NUM:(t-n)/t/C(o,e,c)),D("INTRATE",4,[r,r,r,r,0],(o,e,n=0,t=0,c=0)=>n<=0||t<=0?N.NUM:(t-n)/n/C(o,e,c)),D("RECEIVED",4,[r,r,r,r,0],(o,e,n=0,t=0,c=0)=>{const s=1-t*C(o,e,c);return n<=0||t<=0||s<=0?N.NUM:n/s}),D("PRICEDISC",4,[r,r,r,r,0],(o,e,n=0,t=0,c=0)=>n<=0||t<=0?N.NUM:t*(1-n*C(o,e,c))),D("YIELDDISC",4,[r,r,r,r,0],(o,e,n=0,t=0,c=0)=>n<=0||t<=0?N.NUM:(t-n)/n/C(o,e,c));function v(o,e){O(o,3,3,J((n=0,t=0,c=0)=>{const s=Math.trunc(n),i=Math.trunc(t);return s>=i||c<=0||i>A(s,12,!1)?N.NUM:e(i-s,c)}))}v("TBILLPRICE",(o,e)=>{const n=100*(1-e*o/360);return n<=0?N.NUM:n}),v("TBILLYIELD",(o,e)=>(100-e)/e*360/o),v("TBILLEQ",(o,e)=>{if(o<=182)return 365*e/(360-e*o);const n=100*(1-e*o/360),t=o/365,c=t*t-(2*t-1)*(1-100/n);return(-t+Math.sqrt(c))/(t-.5)}),O("ACCRINTM",3,5,(...o)=>{const e=R(o,[r,r,r,1e3,0]);if(e instanceof I)return e;const[n=0,t=0,c=0,s=0,i=0]=e,u=Math.trunc(n),a=Math.trunc(t);return u>=a||c<=0||s<=0||!P(i)?N.NUM:s*c*C(u,a,i)}),O("ACCRINT",6,8,(...o)=>{const e=R(o.slice(0,7),[r,r,r,r,1e3,r,0]);if(e instanceof I)return e;const[n=0,t=0,c=0,s=0,i=0,u=0,a=0]=e,l=o[7]===void 0?!0:B(o[7]);if(l instanceof I)return l;const f=Math.trunc(n),h=Math.trunc(c),M=Math.trunc(t);if(f>=h||s<=0||i<=0||!L(u)||!P(a))return N.NUM;const m=12/u;let d=M,U=M;for(let E=1;d>f;E++)d=A(M,-m*E,!1);let p=0;for(;d<h;){U=A(d,m,!1);const E=l?Math.max(f,d):Math.max(d,M<=h?M:f),k=Math.min(h,U),z=a===1?U-d:a===3?365/u:360/u;k>E&&(p+=T(E,k,a)/z),d=U}return i*s*p/u}),O("VDB",5,7,(...o)=>{const e=R(o.slice(0,6),[r,r,r,r,r,2]);if(e instanceof I)return e;const[n=0,t=0,c=0,s=0,i=0,u=0]=e,a=o[6]===void 0?!1:B(o[6]);if(a instanceof I)return a;if(n<0||t<0||c<=0||s<0||i>c||s>i||u<=0)return N.NUM;let l=n,f=0;const h=Math.ceil(i);for(let M=1;M<=h;M++){const m=Math.min(l*u/c,Math.max(0,l-t)),d=c-M+1,U=(l-t)/d,p=a?m:Math.max(m,U),E=Math.min(i,M)-Math.max(s,M-1);E>0&&(f+=p*E),l-=p}return f});const V=(o,e,n,t,c)=>({whole:C(n,e,c),accrued:C(n,o,c),left:C(o,e,c),rate:t});D("PRICEMAT",5,[r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0)=>{const i=Math.trunc(n);if(i>=o||t<0||c<0)return N.NUM;const{whole:u,accrued:a,left:l}=V(o,e,i,t,s);return(100+u*t*100)/(1+l*c)-a*t*100}),D("YIELDMAT",5,[r,r,r,r,r,0],(o,e,n=0,t=0,c=0,s=0)=>{const i=Math.trunc(n);if(i>=o||t<0||c<=0)return N.NUM;const{whole:u,accrued:a,left:l}=V(o,e,i,t,s);return((1+u*t)/(c/100+a*t)-1)/l});function G(o,e,n,t,c){const s=12/t,i=S(e),u={held:0,accrued:0,left:0,count:0};let a=0,l=e;for(;l>o;){a+=1;const f=A(e,-s*a,i),h=c===1?l-f:c===3?365/t:360/t,M=Math.max(f,o),m=l,d=(U,p)=>p>U?T(U,p,c)/h:0;u.held+=d(M,m),u.accrued+=d(M,Math.min(n,m)),u.left+=d(Math.max(n,M),m),u.count+=1,l=f}return u}function K(o,e,n,t,c,s,i,u,a){const l=100*c/u,f=w(t,e,u,a).count+1,h=G(n,t,o,u,a),M=1+s/u,m=h.left;let d=i/M**(f-1+m);d+=l*h.held/M**m;for(let U=2;U<=f;U++)d+=l/M**(U-1+m);return d-l*h.accrued}function W(o,e,n){let t=n;for(let c=0;c<100;c++){const s=o(t),i=s-e;if(Math.abs(i)<1e-10)return t;const u=(o(t+1e-6)-s)/1e-6;if(u===0||!Number.isFinite(u))return;t-=i/u,t<=-1&&(t=-.99)}}function Q(o,e){O(o,8,9,(...n)=>{const t=R(n,[r,r,r,r,r,r,r,r,0]);if(t instanceof I)return t;const[c=0,s=0,i=0,u=0,a=0,l=0,f=0,h=0]=t,M=Math.trunc(t[8]??0),m=Math.trunc(c),d=Math.trunc(s),U=Math.trunc(i),p=Math.trunc(u);return!P(M)||!L(h)||!(d>p&&p>m&&m>U)||a<0||l<0||f<=0?N.NUM:e(E=>K(m,d,U,p,a,E,f,h,M),l)})}Q("ODDFPRICE",(o,e)=>o(e)),Q("ODDFYIELD",(o,e)=>W(o,e,.1)??N.NUM);function j(o,e){O(o,7,8,(...n)=>{const t=R(n,[r,r,r,r,r,r,r,0]);if(t instanceof I)return t;const[c=0,s=0,i=0,u=0,a=0,l=0,f=0]=t,h=Math.trunc(t[7]??0),M=Math.trunc(c),m=Math.trunc(s),d=Math.trunc(i);return!P(h)||!L(f)||!(m>M&&M>d)||u<0||a<0||l<=0?N.NUM:e({odd:G(d,m,M,f,h),coupon:100*u/f,last:a,red:l,f})})}j("ODDLPRICE",({odd:o,coupon:e,last:n,red:t,f:c})=>(t+o.held*e)/(1+o.left*n/c)-o.accrued*e),j("ODDLYIELD",({odd:o,coupon:e,last:n,red:t,f:c})=>{const s=n+o.accrued*e;return(t+o.held*e-s)/s*c/o.left}),O("AMORLINC",6,7,(...o)=>{const e=R(o,[r,r,r,r,r,r,0]);if(e instanceof I)return e;const[n=0,t=0,c=0,s=0,i=0,u=0]=e,a=Math.trunc(e[6]??0),l=Math.trunc(i);if(!P(a)||a===2||n<0||s<0||s>n||l<0||u<=0||t>c)return N.NUM;const f=n*u,h=C(Math.trunc(t),Math.trunc(c),a)*f,M=Math.trunc((n-s-h)/f);return l===0?h:l<=M?f:l===M+1?n-s-f*M-h:0}),O("AMORDEGRC",6,7,(...o)=>{const e=R(o,[r,r,r,r,r,r,0]);if(e instanceof I)return e;const[n=0,t=0,c=0,s=0,i=0,u=0]=e,a=Math.trunc(e[6]??0),l=Math.trunc(i);if(!P(a)||a===2||n<0||s<0||s>n||l<0||u<=0||t>c)return N.NUM;const f=1/u,h=f<3?1:f<5?1.5:f<=6?2:2.5,M=u*h;let m=Math.round(C(Math.trunc(t),Math.trunc(c),a)*M*n);if(l===0)return m;let d=n-m,U=d-s;for(let p=0;p<l;p++){if(m=Math.round(M*d),U-=m,U<0)return l-p<=1?Math.round(d*.5):0;d-=m}return m});
2
+ import{CellError as C,ERR as N,dateOf as F,serialOf as G}from"../../values.js";import{toBool as Q,toNumber as $}from"../coerce.js";import{yearFrac as E}from"./date.js";import{number as A,scalar as D}from"./define.js";const j=(t,r)=>F(G(t,r+1,0)).day,B=(t,r,o)=>o===0||o===4?Math.round(E(t,r,o)*360):r-t;function w(t,r,o){const n=F(t),c=n.year*12+n.month-1+r,e=Math.floor(c/12),i=c-e*12+1,u=j(e,i);return G(e,i,o?u:Math.min(n.day,u))}const v=t=>{const r=F(t);return r.day===j(r.year,r.month)};function g(t,r,o,n){const c=12/o,e=v(r);let i=0,u=r;for(;u>t;)i+=1,u=w(r,-c*i,e);const a=w(r,-c*(i-1),e),l=n===1?a-u:n===3?365/o:360/o,f=B(u,t,n);return{previous:u,next:a,count:i,period:l,since:f,until:n===0||n===4?l-f:a-t}}function R(t,r){const o=[];for(const[n,c]of r.entries()){const e=t[n],i=e==null?c??0:$(e);if(i instanceof C)return i;o.push(i)}return o}const L=t=>Number.isInteger(t)&&t>=0&&t<=4,p=t=>t===1||t===2||t===4;function P(t,r,o,n){D(t,r,o.length,(...c)=>{const e=R(c,o);if(e instanceof C)return e;const[i=0,u=0,...a]=e,l=Math.trunc(i),f=Math.trunc(u),h=Math.trunc(a[a.length-1]??0);return l>=f||!L(h)?N.NUM:n(l,f,...a.slice(0,-1),h)})}const s=void 0;for(const[t,r]of[["COUPDAYBS",o=>o.since],["COUPDAYS",o=>o.period],["COUPDAYSNC",o=>o.until],["COUPNCD",o=>o.next],["COUPNUM",o=>o.count],["COUPPCD",o=>o.previous]])P(t,3,[s,s,s,0],(o,n,c=0,e=0)=>p(c)?r(g(o,n,c,e)):N.NUM);function S(t,r,o,n,c,e,i){const u=g(t,r,e,i),a=100*o/e,l=u.until/u.period;if(u.count===1)return(c+a)/(1+l*n/e)-a*u.since/u.period;let f=c/(1+n/e)**(u.count-1+l);for(let h=1;h<=u.count;h++)f+=a/(1+n/e)**(h-1+l);return f-a*u.since/u.period}P("PRICE",6,[s,s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0,i=0)=>o<0||n<0||c<=0||!p(e)?N.NUM:S(t,r,o,n,c,e,i)),P("YIELD",6,[s,s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0,i=0)=>{if(o<0||n<=0||c<=0||!p(e))return N.NUM;let u=-.99,a=1;for(;S(t,r,o,a,c,e,i)>n&&a<1e6;)a*=2;for(let l=0;l<200;l++){const f=(u+a)/2;S(t,r,o,f,c,e,i)>n?u=f:a=f}return(u+a)/2});function z(t,r,o,n,c,e){const i=g(t,r,c,e),u=i.until/i.period;let a=0,l=0;for(let f=1;f<=i.count;f++){const h=f-1+u,M=(100*o/c+(f===i.count?100:0))/(1+n/c)**h;a+=h*M,l+=M}return a/l/c}P("DURATION",5,[s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0)=>o<0||n<0||!p(c)?N.NUM:z(t,r,o,n,c,e)),P("MDURATION",5,[s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0)=>o<0||n<0||!p(c)?N.NUM:z(t,r,o,n,c,e)/(1+n/c)),P("DISC",4,[s,s,s,s,0],(t,r,o=0,n=0,c=0)=>o<=0||n<=0?N.NUM:(n-o)/n/E(t,r,c)),P("INTRATE",4,[s,s,s,s,0],(t,r,o=0,n=0,c=0)=>o<=0||n<=0?N.NUM:(n-o)/o/E(t,r,c)),P("RECEIVED",4,[s,s,s,s,0],(t,r,o=0,n=0,c=0)=>{const e=1-n*E(t,r,c);return o<=0||n<=0||e<=0?N.NUM:o/e}),P("PRICEDISC",4,[s,s,s,s,0],(t,r,o=0,n=0,c=0)=>o<=0||n<=0?N.NUM:n*(1-o*E(t,r,c))),P("YIELDDISC",4,[s,s,s,s,0],(t,r,o=0,n=0,c=0)=>o<=0||n<=0?N.NUM:(n-o)/o/E(t,r,c));function k(t,r){D(t,3,3,A((o=0,n=0,c=0)=>{const e=Math.trunc(o),i=Math.trunc(n);return e>=i||c<=0||i>w(e,12,!1)?N.NUM:r(i-e,c)}))}k("TBILLPRICE",(t,r)=>{const o=100*(1-r*t/360);return o<=0?N.NUM:o}),k("TBILLYIELD",(t,r)=>(100-r)/r*360/t),k("TBILLEQ",(t,r)=>{if(t<=182)return 365*r/(360-r*t);const o=100*(1-r*t/360),n=t/365,c=n*n-(2*n-1)*(1-100/o);return(-n+Math.sqrt(c))/(n-.5)}),D("ACCRINTM",3,5,(...t)=>{const r=R(t,[s,s,s,1e3,0]);if(r instanceof C)return r;const[o=0,n=0,c=0,e=0,i=0]=r,u=Math.trunc(o),a=Math.trunc(n);return u>=a||c<=0||e<=0||!L(i)?N.NUM:e*c*E(u,a,i)}),D("ACCRINT",6,8,(...t)=>{const r=R(t.slice(0,7),[s,s,s,s,1e3,s,0]);if(r instanceof C)return r;const[o=0,n=0,c=0,e=0,i=0,u=0,a=0]=r,l=t[7]===void 0?!0:Q(t[7]);if(l instanceof C)return l;const f=Math.trunc(o),h=Math.trunc(c),M=Math.trunc(n);if(f>=h||e<=0||i<=0||!p(u)||!L(a))return N.NUM;const m=12/u;let d=M,U=M;for(let O=1;d>f;O++)d=w(M,-m*O,!1);let I=0;for(;d<h;){U=w(d,m,!1);const O=l?Math.max(f,d):Math.max(d,M<=h?M:f),V=Math.min(h,U),_=a===1?U-d:a===3?365/u:360/u;V>O&&(I+=B(O,V,a)/_),d=U}return i*e*I/u});const H=(t,r)=>(1+t)**r,Y=t=>t!==0?1:0,T=t=>Number.isFinite(t)?t:N.NUM;function b(t,r,o,n,c){if(t===0)return-(o+n)/r;const e=H(t,r);return-(o*e+n)*t/((1+t*c)*(e-1))}function x(t,r,o,n,c){if(t===0)return-(n+o*r);const e=H(t,r);return-(n*e+o*(1+t*c)*(e-1)/t)}function J(t,r,o,n,c,e){if(r<1||r>o)return N.NUM;if(e===1&&r===1)return 0;const i=b(t,o,n,c,e),u=e===1?x(t,r-2,i,n,1)-i:x(t,r-1,i,n,0);return T(u*t)}D("PMT",3,5,A((t,r,o,n=0,c=0)=>r===0?N.NUM:T(b(t,r,o,n,Y(c))))),D("FV",3,5,A((t,r,o,n=0,c=0)=>T(x(t,r,o,n,Y(c))))),D("IPMT",4,6,A((t,r,o,n,c=0,e=0)=>J(t,r,o,n,c,Y(e)))),D("PPMT",4,6,A((t,r,o,n,c=0,e=0)=>{const i=Y(e),u=J(t,r,o,n,c,i);return u instanceof C?u:T(b(t,o,n,c,i)-u)})),D("DB",4,5,A((t,r,o,n,c=12)=>{const e=Math.trunc(n);if(t<0||r<0||o<=0||e<=0)return N.NUM;if(c<=0||c>12||e>o+1)return N.NUM;const i=t===0?0:Math.round((1-(r/t)**(1/o))*1e3)/1e3;let u=0,a=0;for(let l=1;l<=e;l++)a=l===1?t*i*c/12:l===o+1?(t-u)*i*(12-c)/12:(t-u)*i,u+=a;return T(a)})),D("VDB",5,7,(...t)=>{const r=R(t.slice(0,6),[s,s,s,s,s,2]);if(r instanceof C)return r;const[o=0,n=0,c=0,e=0,i=0,u=0]=r,a=t[6]===void 0?!1:Q(t[6]);if(a instanceof C)return a;if(o<0||n<0||c<=0||e<0||i>c||e>i||u<=0)return N.NUM;let l=o,f=0;const h=Math.ceil(i);for(let M=1;M<=h;M++){const m=Math.min(l*u/c,Math.max(0,l-n)),d=c-M+1,U=(l-n)/d,I=a?m:Math.max(m,U),O=Math.min(i,M)-Math.max(e,M-1);O>0&&(f+=I*O),l-=I}return f});const K=(t,r,o,n,c)=>({whole:E(o,r,c),accrued:E(o,t,c),left:E(t,r,c),rate:n});P("PRICEMAT",5,[s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0)=>{const i=Math.trunc(o);if(i>=t||n<0||c<0)return N.NUM;const{whole:u,accrued:a,left:l}=K(t,r,i,n,e);return(100+u*n*100)/(1+l*c)-a*n*100}),P("YIELDMAT",5,[s,s,s,s,s,0],(t,r,o=0,n=0,c=0,e=0)=>{const i=Math.trunc(o);if(i>=t||n<0||c<=0)return N.NUM;const{whole:u,accrued:a,left:l}=K(t,r,i,n,e);return((1+u*n)/(c/100+a*n)-1)/l});function W(t,r,o,n,c){const e=12/n,i=v(r),u={held:0,accrued:0,left:0,count:0};let a=0,l=r;for(;l>t;){a+=1;const f=w(r,-e*a,i),h=c===1?l-f:c===3?365/n:360/n,M=Math.max(f,t),m=l,d=(U,I)=>I>U?B(U,I,c)/h:0;u.held+=d(M,m),u.accrued+=d(M,Math.min(o,m)),u.left+=d(Math.max(o,M),m),u.count+=1,l=f}return u}function q(t,r,o,n,c,e,i,u,a){const l=100*c/u,f=g(n,r,u,a).count+1,h=W(o,n,t,u,a),M=1+e/u,m=h.left;let d=i/M**(f-1+m);d+=l*h.held/M**m;for(let U=2;U<=f;U++)d+=l/M**(U-1+m);return d-l*h.accrued}function y(t,r,o){let n=o;for(let c=0;c<100;c++){const e=t(n),i=e-r;if(Math.abs(i)<1e-10)return n;const u=(t(n+1e-6)-e)/1e-6;if(u===0||!Number.isFinite(u))return;n-=i/u,n<=-1&&(n=-.99)}}function X(t,r){D(t,8,9,(...o)=>{const n=R(o,[s,s,s,s,s,s,s,s,0]);if(n instanceof C)return n;const[c=0,e=0,i=0,u=0,a=0,l=0,f=0,h=0]=n,M=Math.trunc(n[8]??0),m=Math.trunc(c),d=Math.trunc(e),U=Math.trunc(i),I=Math.trunc(u);return!L(M)||!p(h)||!(d>I&&I>m&&m>U)||a<0||l<0||f<=0?N.NUM:r(O=>q(m,d,U,I,a,O,f,h,M),l)})}X("ODDFPRICE",(t,r)=>t(r)),X("ODDFYIELD",(t,r)=>y(t,r,.1)??N.NUM);function Z(t,r){D(t,7,8,(...o)=>{const n=R(o,[s,s,s,s,s,s,s,0]);if(n instanceof C)return n;const[c=0,e=0,i=0,u=0,a=0,l=0,f=0]=n,h=Math.trunc(n[7]??0),M=Math.trunc(c),m=Math.trunc(e),d=Math.trunc(i);return!L(h)||!p(f)||!(m>M&&M>d)||u<0||a<0||l<=0?N.NUM:r({odd:W(d,m,M,f,h),coupon:100*u/f,last:a,red:l,f})})}Z("ODDLPRICE",({odd:t,coupon:r,last:o,red:n,f:c})=>(n+t.held*r)/(1+t.left*o/c)-t.accrued*r),Z("ODDLYIELD",({odd:t,coupon:r,last:o,red:n,f:c})=>{const e=o+t.accrued*r;return(n+t.held*r-e)/e*c/t.left}),D("AMORLINC",6,7,(...t)=>{const r=R(t,[s,s,s,s,s,s,0]);if(r instanceof C)return r;const[o=0,n=0,c=0,e=0,i=0,u=0]=r,a=Math.trunc(r[6]??0),l=Math.trunc(i);if(!L(a)||a===2||o<0||e<0||e>o||l<0||u<=0||n>c)return N.NUM;const f=o*u,h=E(Math.trunc(n),Math.trunc(c),a)*f,M=Math.trunc((o-e-h)/f);return l===0?h:l<=M?f:l===M+1?o-e-f*M-h:0}),D("AMORDEGRC",6,7,(...t)=>{const r=R(t,[s,s,s,s,s,s,0]);if(r instanceof C)return r;const[o=0,n=0,c=0,e=0,i=0,u=0]=r,a=Math.trunc(r[6]??0),l=Math.trunc(i);if(!L(a)||a===2||o<0||e<0||e>o||l<0||u<=0||n>c)return N.NUM;const f=1/u,h=f<3?1:f<5?1.5:f<=6?2:2.5,M=u*h;let m=Math.round(E(Math.trunc(n),Math.trunc(c),a)*M*o);if(l===0)return m;let d=o-m,U=d-e;for(let I=0;I<l;I++){if(m=Math.round(M*d),U-=m,U<0)return l-I<=1?Math.round(d*.5):0;d-=m}return m});
@@ -8,6 +8,8 @@ import "./info.js";
8
8
  import "./kernels.js";
9
9
  import "./distributions.js";
10
10
  import "./maths.js";
11
+ import "./convert.js";
12
+ import "./modern.js";
11
13
  import "./finance.js";
12
14
  import "./database.js";
13
15
  import "./dynamic.js";
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import"./logical.js";import"./aggregate.js";import"./criteria.js";import"./lookup.js";import"./text.js";import"./date.js";import"./info.js";import"./kernels.js";import"./distributions.js";import"./maths.js";import"./finance.js";import"./database.js";import"./dynamic.js";export{FUNCTIONS}from"./define.js";
2
+ import"./logical.js";import"./aggregate.js";import"./criteria.js";import"./lookup.js";import"./text.js";import"./date.js";import"./info.js";import"./kernels.js";import"./distributions.js";import"./maths.js";import"./convert.js";import"./modern.js";import"./finance.js";import"./database.js";import"./dynamic.js";export{FUNCTIONS}from"./define.js";
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{cellName as N}from"../../address.js";import{CellError as s,ERR as n,Matrix as R}from"../../values.js";import{FormulaCell as p}from"../../workbook.js";import{toNumber as L,toText as d}from"../coerce.js";import{Lambda as I,Reference as l,Union as y}from"../types.js";import{lazy as u,raw as m,scalar as c}from"./define.js";const f=(e,t)=>{c(e,1,1,r=>t(r),{errors:!0})};f("ISBLANK",e=>e==null),f("ISNUMBER",e=>typeof e=="number"),f("ISTEXT",e=>typeof e=="string"),f("ISNONTEXT",e=>typeof e!="string"),f("ISLOGICAL",e=>typeof e=="boolean"),f("ISERROR",e=>e instanceof s),f("ISERR",e=>e instanceof s&&e!==n.NA),f("ISNA",e=>e===n.NA);const E=(e,t)=>{const r=L(e);return r instanceof s?r:Math.abs(Math.trunc(r))%2===t};c("ISEVEN",1,1,e=>E(e,0)),c("ISODD",1,1,e=>E(e,1)),c("N",1,1,e=>typeof e=="number"?e:typeof e=="boolean"?e?1:0:e instanceof s?e:0,{errors:!0}),m("NA",0,0,()=>n.NA),m("TYPE",1,1,(e,t)=>{const r=t.calc.flat(e[0]);return r instanceof R?64:typeof r=="number"||r===null?1:typeof r=="string"?2:typeof r=="boolean"?4:16});const S=[n.NULL,n.DIV0,n.VALUE,n.REF,n.NAME,n.NUM,n.NA];c("ERROR.TYPE",1,1,e=>{const t=e instanceof s?S.indexOf(e):-1;return t<0?n.NA:t+1},{errors:!0}),u("ISREF",1,1,(e,t)=>{const r=e[0];if(!r)return!1;const o=t.calc.eval(r,t.frame);return o instanceof l||o instanceof y});const A=e=>e instanceof l?e.sheet.at(e.top,e.left):void 0;u("ISFORMULA",1,1,(e,t)=>{const r=e[0];if(!r)return n.VALUE;const o=t.calc.eval(r,t.frame);return o instanceof I?n.VALUE:A(o)instanceof p}),u("FORMULATEXT",1,1,(e,t)=>{const r=e[0];if(!r)return n.VALUE;const o=A(t.calc.eval(r,t.frame));return o instanceof p?o.text:n.NA}),m("CELL",1,2,(e,t)=>{const r=d(t.calc.scalar(e[0],t.frame));if(r instanceof s)return r;const o=e[1],a=o instanceof l?o:new l(t.frame.sheet,t.frame.row,t.frame.col,t.frame.row,t.frame.col),i=t.calc.read(a.sheet,a.top,a.left);switch(r.toLowerCase()){case"row":return a.top+1;case"col":return a.left+1;case"address":return N({row:a.top,col:a.left}).replace(/^([A-Z]+)(\d+)$/u,"$$$1$$$2");case"contents":return i;case"type":return i===null?"b":typeof i=="string"?"l":"v";default:return n.VALUE}});
2
+ import{cellName as N}from"../../address.js";import{CellError as s,ERR as n,Matrix as R}from"../../values.js";import{FormulaCell as p}from"../../workbook.js";import{toNumber as L,toText as d}from"../coerce.js";import{Lambda as I,Reference as l,Union as y}from"../types.js";import{lazy as u,raw as m,scalar as c}from"./define.js";const f=(e,r)=>{c(e,1,1,t=>r(t),{errors:!0})};f("ISBLANK",e=>e==null),f("ISNUMBER",e=>typeof e=="number"),f("ISTEXT",e=>typeof e=="string"),f("ISNONTEXT",e=>typeof e!="string"),f("ISLOGICAL",e=>typeof e=="boolean"),f("ISERROR",e=>e instanceof s),f("ISERR",e=>e instanceof s&&e!==n.NA),f("ISNA",e=>e===n.NA);const E=(e,r)=>{const t=L(e);return t instanceof s?t:Math.abs(Math.trunc(t))%2===r};c("ISEVEN",1,1,e=>E(e,0)),c("ISODD",1,1,e=>E(e,1)),c("N",1,1,e=>typeof e=="number"?e:typeof e=="boolean"?e?1:0:e instanceof s?e:0,{errors:!0}),m("NA","",()=>n.NA),m("TYPE","r",(e,r)=>{const t=r.calc.flat(e[0]);return t instanceof R?64:typeof t=="number"||t===null?1:typeof t=="string"?2:typeof t=="boolean"?4:16});const S=[n.NULL,n.DIV0,n.VALUE,n.REF,n.NAME,n.NUM,n.NA];c("ERROR.TYPE",1,1,e=>{const r=e instanceof s?S.indexOf(e):-1;return r<0?n.NA:r+1},{errors:!0}),u("ISREF",1,1,(e,r)=>{const t=e[0];if(!t)return!1;const o=r.calc.eval(t,r.frame);return o instanceof l||o instanceof y});const A=e=>e instanceof l?e.sheet.at(e.top,e.left):void 0;u("ISFORMULA",1,1,(e,r)=>{const t=e[0];if(!t)return n.VALUE;const o=r.calc.eval(t,r.frame);return o instanceof I?n.VALUE:A(o)instanceof p}),u("FORMULATEXT",1,1,(e,r)=>{const t=e[0];if(!t)return n.VALUE;const o=A(r.calc.eval(t,r.frame));return o instanceof p?o.text:n.NA}),m("CELL","v?r",(e,r)=>{const t=d(r.calc.scalar(e[0],r.frame));if(t instanceof s)return t;const o=e[1],a=o instanceof l?o:new l(r.frame.sheet,r.frame.row,r.frame.col,r.frame.row,r.frame.col),i=r.calc.read(a.sheet,a.top,a.left);switch(t.toLowerCase()){case"row":return a.top+1;case"col":return a.left+1;case"address":return N({row:a.top,col:a.left}).replace(/^([A-Z]+)(\d+)$/u,"$$$1$$$2");case"contents":return i;case"type":return i===null?"b":typeof i=="string"?"l":"v";default:return n.VALUE}});