@allyhub/sdk 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +248 -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 +1114 -91
  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 +4 -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 +625 -30
  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/dist/zip.d.ts +17 -0
  33. package/dist/node_modules/@allyhub-next/formats/dist/zip.js +2 -0
  34. package/dist/node_modules/@allyhub-next/formats/package.json +2 -1
  35. package/dist/node_modules/@allyhub-next/ooxml/LICENSE +241 -0
  36. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.d.ts +31 -0
  37. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.js +2 -0
  38. package/dist/node_modules/@allyhub-next/ooxml/dist/color.d.ts +33 -0
  39. package/dist/node_modules/@allyhub-next/ooxml/dist/color.js +2 -0
  40. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.d.ts +13 -0
  41. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.js +2 -0
  42. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.d.ts +79 -0
  43. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.js +2 -0
  44. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.d.ts +132 -0
  45. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.js +2 -0
  46. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.d.ts +28 -0
  47. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.js +2 -0
  48. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.d.ts +4708 -0
  49. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.js +2 -0
  50. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.d.ts +57 -0
  51. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.js +2 -0
  52. package/dist/node_modules/@allyhub-next/ooxml/dist/index.d.ts +10 -0
  53. package/dist/node_modules/@allyhub-next/ooxml/dist/index.js +2 -0
  54. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.d.ts +12 -0
  55. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.js +2 -0
  56. package/dist/node_modules/@allyhub-next/ooxml/dist/node.d.ts +111 -0
  57. package/dist/node_modules/@allyhub-next/ooxml/dist/node.js +2 -0
  58. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.d.ts +45 -0
  59. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.js +2 -0
  60. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.d.ts +48 -0
  61. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.js +2 -0
  62. package/dist/node_modules/@allyhub-next/ooxml/dist/report.d.ts +45 -0
  63. package/dist/node_modules/@allyhub-next/ooxml/dist/report.js +2 -0
  64. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.d.ts +28 -0
  65. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.js +2 -0
  66. package/dist/node_modules/@allyhub-next/ooxml/package.json +26 -0
  67. package/dist/node_modules/@allyhub-next/protocol/dist/account.d.ts +338 -0
  68. package/dist/node_modules/@allyhub-next/protocol/dist/account.js +2 -0
  69. package/dist/node_modules/@allyhub-next/protocol/dist/auth.d.ts +12 -13
  70. package/dist/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  71. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.d.ts +35 -0
  72. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.js +2 -0
  73. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.d.ts +101 -32
  74. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.js +1 -1
  75. package/dist/node_modules/@allyhub-next/protocol/dist/editor.d.ts +89 -5
  76. package/dist/node_modules/@allyhub-next/protocol/dist/editor.js +1 -1
  77. package/dist/node_modules/@allyhub-next/protocol/dist/files.d.ts +2 -2
  78. package/dist/node_modules/@allyhub-next/protocol/dist/index.d.ts +6 -0
  79. package/dist/node_modules/@allyhub-next/protocol/dist/index.js +1 -1
  80. package/dist/node_modules/@allyhub-next/protocol/dist/notes.d.ts +23 -0
  81. package/dist/node_modules/@allyhub-next/protocol/dist/notes.js +1 -1
  82. package/dist/node_modules/@allyhub-next/protocol/dist/open.d.ts +13 -0
  83. package/dist/node_modules/@allyhub-next/protocol/dist/open.js +2 -0
  84. package/dist/node_modules/@allyhub-next/protocol/dist/registry.d.ts +73 -59
  85. package/dist/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  86. package/dist/node_modules/@allyhub-next/protocol/dist/routes.d.ts +1 -1
  87. package/dist/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  88. package/dist/node_modules/@allyhub-next/protocol/dist/shares.d.ts +115 -0
  89. package/dist/node_modules/@allyhub-next/protocol/dist/shares.js +2 -0
  90. package/dist/node_modules/@allyhub-next/protocol/dist/sites.d.ts +293 -0
  91. package/dist/node_modules/@allyhub-next/protocol/dist/sites.js +2 -0
  92. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.d.ts +377 -0
  93. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.js +2 -0
  94. package/dist/node_modules/@allyhub-next/protocol/dist/teams.d.ts +27 -9
  95. package/dist/node_modules/@allyhub-next/protocol/dist/teams.js +1 -1
  96. package/dist/node_modules/@allyhub-next/protocol/dist/tools.d.ts +53 -14
  97. package/dist/node_modules/@allyhub-next/protocol/dist/tools.js +1 -1
  98. package/dist/node_modules/@allyhub-next/protocol/package.json +2 -1
  99. package/dist/node_modules/@allyhub-next/runtimes/package.json +1 -1
  100. package/dist/node_modules/@allyhub-next/runtimes/schemas/runtimes.schema.json +25 -5
  101. package/dist/node_modules/@allyhub-next/scenery/package.json +1 -1
  102. package/dist/node_modules/@allyhub-next/sheet/dist/api/capabilities.js +1 -1
  103. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.d.ts +1 -0
  104. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.js +1 -1
  105. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.d.ts +83 -0
  106. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.js +2 -0
  107. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.d.ts +40 -1
  108. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.js +1 -1
  109. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.d.ts +9 -3
  110. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.js +1 -1
  111. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.d.ts +5 -1
  112. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.js +1 -1
  113. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.d.ts +60 -13
  114. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.js +1 -1
  115. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/aggregate.js +1 -1
  116. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.d.ts +4 -0
  117. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.js +2 -0
  118. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/criteria.js +1 -1
  119. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/database.js +1 -1
  120. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/date.js +1 -1
  121. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.d.ts +27 -1
  122. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.js +1 -1
  123. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.d.ts +16 -0
  124. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.js +2 -0
  125. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.d.ts +18 -1
  126. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.js +1 -1
  127. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/finance.js +1 -1
  128. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.d.ts +2 -0
  129. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.js +1 -1
  130. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/info.js +1 -1
  131. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/kernels.js +1 -1
  132. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/logical.js +1 -1
  133. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/lookup.js +1 -1
  134. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/maths.js +1 -1
  135. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.d.ts +2 -0
  136. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.js +2 -0
  137. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/text.js +1 -1
  138. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.d.ts +38 -0
  139. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.js +2 -0
  140. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.d.ts +19 -0
  141. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.js +2 -0
  142. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.d.ts +49 -0
  143. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.js +2 -0
  144. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.d.ts +82 -0
  145. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.js +2 -0
  146. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.d.ts +6 -1
  147. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.js +1 -1
  148. package/dist/node_modules/@allyhub-next/sheet/dist/chart.js +1 -1
  149. package/dist/node_modules/@allyhub-next/sheet/dist/check.js +1 -1
  150. package/dist/node_modules/@allyhub-next/sheet/dist/diff.d.ts +15 -0
  151. package/dist/node_modules/@allyhub-next/sheet/dist/diff.js +1 -1
  152. package/dist/node_modules/@allyhub-next/sheet/dist/export.d.ts +29 -8
  153. package/dist/node_modules/@allyhub-next/sheet/dist/export.js +3 -4
  154. package/dist/node_modules/@allyhub-next/sheet/dist/file.js +2 -2
  155. package/dist/node_modules/@allyhub-next/sheet/dist/format.d.ts +8 -2
  156. package/dist/node_modules/@allyhub-next/sheet/dist/format.js +1 -1
  157. package/dist/node_modules/@allyhub-next/sheet/dist/html.d.ts +52 -4
  158. package/dist/node_modules/@allyhub-next/sheet/dist/html.js +43 -11
  159. package/dist/node_modules/@allyhub-next/sheet/dist/index.d.ts +7 -3
  160. package/dist/node_modules/@allyhub-next/sheet/dist/index.js +1 -1
  161. package/dist/node_modules/@allyhub-next/sheet/dist/inspect.js +1 -1
  162. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.d.ts +98 -0
  163. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.js +2 -0
  164. package/dist/node_modules/@allyhub-next/sheet/dist/structure.js +1 -1
  165. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.d.ts +32 -0
  166. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.js +2 -0
  167. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.d.ts +3 -0
  168. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.js +2 -0
  169. package/dist/node_modules/@allyhub-next/sheet/dist/values.js +1 -1
  170. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.d.ts +10 -1
  171. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.js +1 -1
  172. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.d.ts +12 -1
  173. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.js +1 -1
  174. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.d.ts +14 -4
  175. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.js +2 -2
  176. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.d.ts +11 -1
  177. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.js +36 -16
  178. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.d.ts +6 -1
  179. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.js +1 -1
  180. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.d.ts +44 -2
  181. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.js +2 -1
  182. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.d.ts +23 -0
  183. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.js +2 -0
  184. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.d.ts +2 -0
  185. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.js +1 -1
  186. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.d.ts +6 -0
  187. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.js +1 -1
  188. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.d.ts +40 -0
  189. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.js +2 -0
  190. package/dist/node_modules/@allyhub-next/sheet/package.json +1 -1
  191. package/dist/node_modules/@allyhub-next/slides-core/dist/animation.js +1 -1
  192. package/dist/node_modules/@allyhub-next/slides-core/dist/api.d.ts +121 -44
  193. package/dist/node_modules/@allyhub-next/slides-core/dist/api.js +2 -2
  194. package/dist/node_modules/@allyhub-next/slides-core/dist/capabilities.js +1 -1
  195. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.d.ts +50 -13
  196. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.js +1 -1
  197. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-file.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 +188 -5
  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 -0
  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 +38 -4
  217. package/dist/node_modules/@allyhub-next/slides-core/dist/office.d.ts +27 -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 +26 -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/sheets.d.ts +1 -1
  250. package/dist/sheets.js +1 -1
  251. package/dist/slides.d.ts +3 -1
  252. package/dist/slides.js +1 -1
  253. package/docs/README.md +1 -0
  254. package/docs/contract.md +1 -1
  255. package/docs/defaults.md +25 -2
  256. package/docs/layers.md +1 -1
  257. package/docs/project.md +3 -1
  258. package/docs/sheets.md +29 -3
  259. package/docs/slides.md +18 -14
  260. package/docs/sound.md +1 -1
  261. package/docs/websites.md +57 -0
  262. package/package.json +3 -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 a,ERR as l,Matrix as R}from"../../values.js";import{toBool as q,toNumber as A}from"../coerce.js";import{Reference as P,Union as ot}from"../types.js";import{FUNCTIONS as ct,alias as O,cellsOf as B,eachRow as ft,many as y,number as U,numbersOf as T,raw as N,scalar as S}from"./define.js";import{besselI as it,besselJ as at,besselK as ut,besselY as lt,betaI as K,gammaQ as ht,normalCdf as mt}from"./special.js";const X=2**48;function H(e,r){const[t="0",n="0"]=e.toExponential().split("e");return+`${t}e${String(Number(n)+r)}`}const Mt=e=>Number(e.toPrecision(15));function G(e,r,t){const n=Math.trunc(r),s=Math.abs(Mt(e)),o=H(s,n);if(o>=2**53)return e;const c=H(t(o),-n);return e<0?-c:c}S("ROUND",2,2,U((e=0,r=0)=>G(e,r,t=>Math.floor(t+.5)))),S("ROUNDUP",2,2,U((e=0,r=0)=>G(e,r,Math.ceil))),S("ROUNDDOWN",2,2,U((e=0,r=0)=>G(e,r,Math.floor))),S("MOD",2,2,U((e=0,r=0)=>{if(r===0)return l.DIV0;const t=e%r;return t!==0&&t<0!=r<0?t+r:t})),S("QUOTIENT",2,2,U((e=0,r=0)=>r===0?l.DIV0:Math.trunc(e/r))),S("POWER",2,2,U((e=0,r=0)=>{if(e===0&&r===0)return l.NUM;if(e===0&&r<0)return l.DIV0;const t=e**r;return Number.isFinite(t)?t:l.NUM})),S("LOG",1,2,(e,r)=>{const t=A(e),n=r==null?10:A(r);return t instanceof a?t:n instanceof a?n:t<=0||n<=0?l.NUM:n===1?l.DIV0:n===10?Math.log10(t):n===2?Math.log2(t):Math.log(t)/Math.log(n)});function v(e,r){let[t,n]=[e,r];for(;n!==0;)[t,n]=[n,t%n];return t}function Y(e,r){const t=T(e,r);if(t instanceof a)return t;const n=t.map(Math.trunc);return n.some(s=>s<0||s>=2**53)?l.NUM:n}N("GCD",1,y,(e,r)=>{const t=Y(e,r);return t instanceof a?t:t.reduce(v,0)}),N("LCM",1,y,(e,r)=>{const t=Y(e,r);if(t instanceof a)return t;if(t.includes(0))return 0;const n=t.reduce((s,o)=>s*o/v(s,o),1);return Number.isFinite(n)?n:l.NUM}),S("BASE",2,3,U((e=0,r=0,t=Number.NaN)=>{const n=Math.trunc(e),s=Math.trunc(r),o=Number.isNaN(t)?0:Math.trunc(t);return n<0||n>=2**53||s<2||s>36||o<0||o>255?l.NUM:n.toString(s).toUpperCase().padStart(o,"0")}));const dt="MDCLXVI",z=[1e3,500,100,50,10,5,1];function Nt(e,r){const t=i=>z[i]??1,n=i=>dt.charAt(i),s=z.length-1;let o=e,c="";for(let i=0;i<=s/2;i++){const f=2*i,u=Math.floor(o/t(f));if(u%5===4){const h=u===4?f-1:f-2;let m=f,M=0;for(;M<r&&m<s;)M+=1,t(h)-t(m+1)<=o?m+=1:M=r;c+=n(m)+n(h),o+=t(m)-t(h)}else u>4&&(c+=n(f-1)),c+=n(f).repeat(u%5),o%=t(f)}return c}S("ROMAN",1,2,(e,r)=>{const t=A(e);if(t instanceof a)return t;let n=0;if(typeof r=="boolean")n=r?0:4;else if(r!=null){const o=A(r);if(o instanceof a)return o;n=Math.trunc(o)}const s=Math.trunc(t);return s<0||s>3999||n<0||n>4?l.VALUE:Nt(s,n)});function k(e){return!Number.isInteger(e)||e<0||e>=X?l.NUM:BigInt(e)}for(const[e,r]of[["BITAND",(t,n)=>t&n],["BITOR",(t,n)=>t|n],["BITXOR",(t,n)=>t^n]])S(e,2,2,U((t=0,n=0)=>{const s=k(t),o=k(n);return s instanceof a?s:o instanceof a?o:Number(r(s,o))}));for(const[e,r]of[["BITLSHIFT",1],["BITRSHIFT",-1]])S(e,2,2,U((t=0,n=0)=>{const s=k(t);if(s instanceof a)return s;const o=Math.trunc(n)*r;if(Math.abs(o)>53)return l.NUM;const c=o>=0?s<<BigInt(o):s>>BigInt(-o);return c>=BigInt(X)?l.NUM:Number(c)}));for(const[e,r,t]of[["BESSELJ",at,!1],["BESSELI",it,!1],["BESSELY",lt,!0],["BESSELK",ut,!0]])S(e,2,2,U((n=0,s=0)=>{const o=Math.trunc(s);if(o<0||t&&n<=0)return l.NUM;const c=r(o,n);return Number.isFinite(c)?c:l.NUM}));S("SLN",3,3,U((e=0,r=0,t=0)=>t===0?l.DIV0:(e-r)/t)),N("GEOMEAN",1,y,(e,r)=>{const t=T(e,r);return t instanceof a?t:t.length===0||t.some(n=>n<=0)?l.NUM:Math.exp(t.reduce((n,s)=>n+Math.log(s),0)/t.length)}),N("HARMEAN",1,y,(e,r)=>{const t=T(e,r);return t instanceof a?t:t.length===0||t.some(n=>n<=0)?l.NUM:t.length/t.reduce((n,s)=>n+1/s,0)}),N("KURT",1,y,(e,r)=>{const t=T(e,r);if(t instanceof a)return t;const n=t.length;if(n<4)return l.DIV0;const s=t.reduce((i,f)=>i+f,0)/n,o=t.reduce((i,f)=>i+(f-s)**2,0)/(n-1);if(o===0)return l.DIV0;const c=t.reduce((i,f)=>i+(f-s)**4,0)/o**2;return n*(n+1)/((n-1)*(n-2)*(n-3))*c-3*(n-1)**2/((n-2)*(n-3))});function W(e,r){const t=[];let n;return ft(e,r,(s,o)=>{if(!n){if(s instanceof a)n=s;else if(typeof s=="number")t.push(s);else if(o&&s!==null){const c=A(s);c instanceof a?n=c:t.push(c)}}}),n??t}N("MODE.SNGL",1,y,(e,r)=>{const t=W(e,r);if(t instanceof a)return t;const n=new Map;for(const c of t)n.set(c,(n.get(c)??0)+1);let s,o=1;for(const[c,i]of n)i>o&&(s=c,o=i);return s??l.NA}),O("MODE","MODE.SNGL"),N("MODE.MULT",1,y,(e,r)=>{const t=W(e,r);if(t instanceof a)return t;const n=new Map;for(const c of t)n.set(c,(n.get(c)??0)+1);let s=0;for(const c of n.values())s=Math.max(s,c);if(s<2)return l.NA;const o=[...n].filter(([,c])=>c===s).map(([c])=>c);return new R(o.length,1,o)});function pt(e,r){const t=r*(e.length-1),n=Math.floor(t),s=e[n]??0,o=e[n+1]??s;return s+(t-n)*(o-s)}N("QUARTILE.INC",2,2,(e,r)=>{const t=T([e[0]],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[1],r.frame));if(n instanceof a)return n;const s=Math.trunc(n);return t.length===0||s<0||s>4?l.NUM:pt([...t].sort((o,c)=>o-c),s/4)}),O("QUARTILE","QUARTILE.INC");function Z(e,r){const t=A(r.calc.scalar(e[0],r.frame));if(t instanceof a)return t;const n=T([e[1]],r);if(n instanceof a)return n;const s=e[2]===void 0?0:A(r.calc.scalar(e[2],r.frame));if(s instanceof a)return s;const o=n.filter(c=>c===t).length;return o===0?l.NA:{before:n.filter(c=>s===0?c>t:c<t).length,ties:o}}N("RANK.EQ",2,3,(e,r)=>{const t=Z(e,r);return t instanceof a?t:t.before+1}),N("RANK.AVG",2,3,(e,r)=>{const t=Z(e,r);return t instanceof a?t:t.before+(t.ties+1)/2}),O("RANK","RANK.EQ");function w(e,r){const t=B(e,r);if(t instanceof a)return t;const n=[];for(let s=0;s<t.rows;s++){const o=[];for(let c=0;c<t.cols;c++){const i=t.at(s,c);if(i instanceof a)return i;if(typeof i!="number")return l.VALUE;o.push(i)}n.push(o)}return n}const _=e=>new R(e.length,e[0]?.length??0,e.flat());function Et(e,r){const t=r[0]?.length??0;return e.map(n=>Array.from({length:t},(s,o)=>n.reduce((c,i,f)=>c+i*(r[f]?.[o]??0),0)))}N("MMULT",2,2,(e,r)=>{const t=w(e[0],r),n=w(e[1],r);return t instanceof a?t:n instanceof a?n:(t[0]?.length??0)!==n.length?l.VALUE:_(Et(t,n))});function x(e){const r=e.length,t=e.map((o,c)=>[...o,...Array.from({length:r},(i,f)=>c===f?1:0)]),n=(o,c)=>t[o]?.[c]??0;let s=1;for(let o=0;o<r;o++){let c=o;for(let f=o+1;f<r;f++)Math.abs(n(f,o))>Math.abs(n(c,o))&&(c=f);if(n(c,o)===0)return{determinant:0};if(c!==o){const[f=[],u=[]]=[t[o],t[c]];t[o]=u,t[c]=f,s=-s}const i=n(o,o);s*=i,t[o]=(t[o]??[]).map(f=>f/i);for(let f=0;f<r;f++){if(f===o)continue;const u=n(f,o),h=t[o]??[];t[f]=(t[f]??[]).map((m,M)=>m-u*(h[M]??0))}}return{determinant:s,inverse:t.map(o=>o.slice(r))}}const J=e=>e.length>0&&e.every(r=>r.length===e.length);N("MDETERM",1,1,(e,r)=>{const t=w(e[0],r);return t instanceof a?t:J(t)?x(t).determinant:l.VALUE}),N("MINVERSE",1,1,(e,r)=>{const t=w(e[0],r);if(t instanceof a)return t;if(!J(t))return l.VALUE;const{inverse:n}=x(t);return n?_(n):l.NUM}),S("MUNIT",1,1,U((e=0)=>{const r=Math.trunc(e);return r<1||r>73?l.VALUE:_(Array.from({length:r},(t,n)=>Array.from({length:r},(s,o)=>n===o?1:0)))}));function F(e,r,t){const n=B(e,t),s=B(r,t);if(n instanceof a)return n;if(s instanceof a)return s;if(n.rows*n.cols!==s.rows*s.cols)return l.NA;const o=[],c=[];for(let i=0;i<n.rows;i++)for(let f=0;f<n.cols;f++){const u=n.at(i,f),h=s.rows===n.rows?s.at(i,f):s.at(f,i);if(u instanceof a)return u;if(h instanceof a)return h;typeof u=="number"&&typeof h=="number"&&(o.push(u),c.push(h))}return{xs:o,ys:c}}for(const[e,r]of[["SUMX2MY2",(t,n)=>t*t-n*n],["SUMX2PY2",(t,n)=>t*t+n*n],["SUMXMY2",(t,n)=>(t-n)**2]])N(e,2,2,(t,n)=>{const s=F(t[0],t[1],n);return s instanceof a?s:s.xs.length===0?l.DIV0:s.xs.reduce((o,c,i)=>o+r(c,s.ys[i]??0),0)});N("SERIESSUM",4,4,(e,r)=>{const[t,n,s]=e.slice(0,3).map(c=>A(r.calc.scalar(c,r.frame)));if(t instanceof a)return t;if(n instanceof a)return n;if(s instanceof a)return s;const o=T([e[3]],r);return o instanceof a?o:o.reduce((c,i,f)=>c+i*(t??0)**((n??0)+f*(s??0)),0)}),N("FREQUENCY",2,2,(e,r)=>{const t=T([e[0]],r),n=T([e[1]],r);if(t instanceof a)return t;if(n instanceof a)return n;const s=n.map((c,i)=>({b:c,i})).sort((c,i)=>c.b-i.b),o=new Array(n.length+1).fill(0);for(const c of t){const i=s.find(u=>c<=u.b),f=i?i.i:n.length;o[f]=(o[f]??0)+1}return new R(o.length,1,o)}),N("PROB",3,4,(e,r)=>{const t=F(e[0],e[1],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[2],r.frame));if(n instanceof a)return n;const s=e[3]===void 0?n:A(r.calc.scalar(e[3],r.frame));if(s instanceof a)return s;const o=t.ys.reduce((c,i)=>c+i,0);return t.ys.some(c=>c<=0||c>1)||Math.abs(o-1)>1e-12?l.NUM:t.xs.reduce((c,i,f)=>i>=n&&i<=s?c+(t.ys[f]??0):c,0)});const $=e=>e.reduce((r,t)=>r+t,0);function j(e,r,t){const n=r.map(u=>t?[...u,1]:[...u]),s=n[0]?.length??0,o=Array.from({length:s},(u,h)=>Array.from({length:s},(m,M)=>n.reduce((E,g)=>E+(g[h]??0)*(g[M]??0),0))),{inverse:c}=x(o);if(!c)return;const i=Array.from({length:s},(u,h)=>n.reduce((m,M,E)=>m+(M[h]??0)*(e[E]??0),0)),f=c.map(u=>u.reduce((h,m,M)=>h+m*(i[M]??0),0));return t?f:[...f,0]}function tt(e,r,t){const n=w(e[0],r);if(n instanceof a)return n;const s=n.length===1,o=n.flat();if(t&&o.some(h=>h<=0))return l.NUM;const c=t?o.map(Math.log):o,i=e[1];if(i===void 0||!C(i))return{ys:c,xs:o.map((h,m)=>[m+1]),byRow:s};const f=w(i,r);if(f instanceof a)return f;const u=f[0]?.length??0;return s?u!==c.length?l.REF:{ys:c,xs:Array.from({length:u},(h,m)=>f.map(M=>M[m]??0)),byRow:s}:f.length!==c.length?l.REF:{ys:c,xs:f,byRow:s}}const C=e=>e instanceof P||e instanceof R||typeof e=="number",nt=(e,r)=>e===void 0||!C(e)&&typeof e!="boolean"?!0:q(r.calc.scalar(e,r.frame));function et(e){return(r,t)=>{const n=tt(r,t,e);if(n instanceof a)return n;const s=nt(r[3],t);if(s instanceof a)return s;const o=j(n.ys,n.xs,s);if(!o)return l.NUM;const c=r[2];let i=n.xs;if(c!==void 0&&C(c)){const u=w(c,t);if(u instanceof a)return u;const h=n.xs[0]?.length??1,m=u[0]?.length??0;i=n.byRow||h===1&&u.length===1?Array.from({length:m},(M,E)=>u.map(g=>g[E]??0)):u}const f=i.map(u=>{const h=u.reduce((m,M,E)=>m+M*(o[E]??0),0)+(o[u.length]??0);return e?Math.exp(h):h});return n.byRow?new R(1,f.length,f):new R(f.length,1,f)}}N("TREND",1,4,et(!1)),N("GROWTH",1,4,et(!0));function gt(e,r,t,n){const s=r.map(p=>n?[...p,1]:[...p]),o=s[0]?.length??0,{inverse:c}=x(Array.from({length:o},(p,d)=>Array.from({length:o},(b,D)=>s.reduce((st,Q)=>st+(Q[d]??0)*(Q[D]??0),0))));if(!c)return;const i=r.map(p=>p.reduce((d,b,D)=>d+b*(t[D]??0),0)+(t[p.length]??0)),f=e.reduce((p,d,b)=>p+(d-(i[b]??0))**2,0),u=n?$(e)/e.length:0,h=e.reduce((p,d)=>p+(d-u)**2,0),m=h-f,M=e.length-o,E=M>0?f/M:0,g=c.map((p,d)=>Math.sqrt(Math.max(0,(p[d]??0)*E))),I=r[0]?.length??0;return{errors:g,r2:h===0?1:m/h,sey:Math.sqrt(E),f:M>0&&f>0?m/I/(f/M):0,df:M,ssreg:m,ssresid:f}}function rt(e){return(r,t)=>{const n=tt(r,t,e);if(n instanceof a)return n;const s=nt(r[2],t);if(s instanceof a)return s;const o=j(n.ys,n.xs,s);if(!o)return l.NUM;const i=[...o.slice(0,-1).reverse(),o[o.length-1]??0],f=e?i.map(Math.exp):i,u=r[3],h=u===void 0||!At(u)?!1:q(t.calc.scalar(u,t.frame));if(h instanceof a)return h;if(!h)return new R(1,f.length,f);const m=gt(n.ys,n.xs,o,s);if(!m)return l.NUM;const M=f.length,E=I=>[...I,...new Array(M-I.length).fill(l.NA)],g=s?[...m.errors.slice(0,-1).reverse(),m.errors[m.errors.length-1]??0]:[...[...m.errors].reverse(),l.NA];return new R(5,M,[...f,...g,...E([m.r2,m.sey]),...E([m.f,m.df]),...E([m.ssreg,m.ssresid])])}}const At=e=>C(e)||typeof e=="boolean";N("LINEST",1,4,rt(!1)),N("LOGEST",1,4,rt(!0));const V=e=>$(e)/e.length,L=e=>{const r=V(e);return e.reduce((t,n)=>t+(n-r)**2,0)/(e.length-1)};N("CHISQ.TEST",2,2,(e,r)=>{const t=w(e[0],r),n=w(e[1],r);if(t instanceof a)return t;if(n instanceof a)return n;const s=t.length,o=t[0]?.length??0;if(n.length!==s||(n[0]?.length??0)!==o)return l.NA;if(s*o<2)return l.NA;let c=0;for(let f=0;f<s;f++)for(let u=0;u<o;u++){const h=n[f]?.[u]??0;if(h<0)return l.NUM;if(h===0)return l.DIV0;c+=((t[f]?.[u]??0)-h)**2/h}const i=s>1&&o>1?(s-1)*(o-1):s>1?s-1:o-1;return ht(i/2,c/2)}),O("CHITEST","CHISQ.TEST"),N("T.TEST",4,4,(e,r)=>{const t=A(r.calc.scalar(e[2],r.frame)),n=A(r.calc.scalar(e[3],r.frame));if(t instanceof a)return t;if(n instanceof a)return n;const s=Math.trunc(t),o=Math.trunc(n);if(s!==1&&s!==2||o<1||o>3)return l.NUM;let c,i;if(o===1){const u=F(e[0],e[1],r);if(u instanceof a)return u;const h=u.xs.map((m,M)=>m-(u.ys[M]??0));if(h.length<2)return l.DIV0;c=V(h)/Math.sqrt(L(h)/h.length),i=h.length-1}else{const u=T([e[0]],r),h=T([e[1]],r);if(u instanceof a)return u;if(h instanceof a)return h;if(u.length<2||h.length<2)return l.DIV0;const[m,M,E,g]=[L(u),L(h),u.length,h.length],I=Math.abs(V(u)-V(h));if(o===2){i=E+g-2;const p=((E-1)*m+(g-1)*M)/i;c=I/Math.sqrt(p*(1/E+1/g))}else{const p=m/E,d=M/g;c=I/Math.sqrt(p+d),i=(p+d)**2/(p**2/(E-1)+d**2/(g-1))}}return Number.isFinite(c)?K(i/2,.5,i/(i+c*c))*s/2:l.DIV0}),O("TTEST","T.TEST"),N("F.TEST",2,2,(e,r)=>{const t=T([e[0]],r),n=T([e[1]],r);if(t instanceof a)return t;if(n instanceof a)return n;if(t.length<2||n.length<2)return l.DIV0;const[s,o]=[L(t),L(n)];if(s===0||o===0)return l.DIV0;const c=s/o,[i,f]=[t.length-1,n.length-1],u=K(f/2,i/2,f/(i*c+f));return 2*Math.min(u,1-u)}),O("FTEST","F.TEST"),N("Z.TEST",2,3,(e,r)=>{const t=T([e[0]],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[1],r.frame));if(n instanceof a)return n;if(t.length===0)return l.NA;const s=e[2]===void 0?t.length<2?l.DIV0:Math.sqrt(L(t)):A(r.calc.scalar(e[2],r.frame));return s instanceof a?s:s===0?l.DIV0:1-mt((V(t)-n)/(s/Math.sqrt(t.length)))}),O("ZTEST","Z.TEST");const Tt={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",12:"MEDIAN",13:"MODE.SNGL",14:"LARGE",15:"SMALL",16:"PERCENTILE.INC",17:"QUARTILE.INC",18:"PERCENTILE.EXC",19:"QUARTILE.EXC"};N("AGGREGATE",3,y,(e,r)=>{const t=A(r.calc.scalar(e[0],r.frame)),n=A(r.calc.scalar(e[1],r.frame));if(t instanceof a)return t;if(n instanceof a)return n;const s=Tt[Math.trunc(t)],o=s===void 0?void 0:ct.get(s);if(o?.kind!=="raw")return l.VALUE;const c=![2,3,6,7].includes(Math.trunc(n)),i=[1,3,5,7].includes(Math.trunc(n)),f=M=>{const E=M instanceof ot?M.parts:[M],g=[];for(const p of E)if(p instanceof P){const d=p;for(let b=d.top;b<=Math.min(d.bottom,d.sheet.lastRow);b++)if(!(i&&(d.sheet.spec.rows?.[String(b+1)]?.hidden===!0||r.calc.filtered(d.sheet).has(b))))for(let D=d.left;D<=d.right;D++)g.push(r.calc.read(d.sheet,b,D))}else{const d=r.calc.flat(p);d instanceof R?g.push(...d.data):g.push(d)}const I=c?g:g.filter(p=>!(p instanceof a));return new R(I.length,1,I)},u=Math.trunc(t)>=14,h=e.slice(2),m=u?[f(h[0]),...h.slice(1)]:h.map(f);return o.call(m,r)});
2
+ import{CellError as a,ERR as l,Matrix as R}from"../../values.js";import{toBool as _,toNumber as A}from"../coerce.js";import{Reference as Q,Union as st}from"../types.js";import{FUNCTIONS as ot,alias as O,cellsOf as v,eachRow as ct,number as U,numbersOf as S,raw as N,scalar as T}from"./define.js";import{besselI as it,besselJ as ft,besselK as at,besselY as ut,betaI as q,gammaQ as lt,normalCdf as ht}from"./special.js";const P=2**48;function K(e,r){const[t="0",n="0"]=e.toExponential().split("e");return+`${t}e${String(Number(n)+r)}`}const Mt=e=>Number(e.toPrecision(15));function C(e,r,t){const n=Math.trunc(r),s=Math.abs(Mt(e)),o=K(s,n);if(o>=2**53)return e;const c=K(t(o),-n);return e<0?-c:c}T("ROUND",2,2,U((e=0,r=0)=>C(e,r,t=>Math.floor(t+.5)))),T("ROUNDUP",2,2,U((e=0,r=0)=>C(e,r,Math.ceil))),T("ROUNDDOWN",2,2,U((e=0,r=0)=>C(e,r,Math.floor))),T("MOD",2,2,U((e=0,r=0)=>{if(r===0)return l.DIV0;const t=e%r;return t!==0&&t<0!=r<0?t+r:t})),T("QUOTIENT",2,2,U((e=0,r=0)=>r===0?l.DIV0:Math.trunc(e/r))),T("POWER",2,2,U((e=0,r=0)=>{if(e===0&&r===0)return l.NUM;if(e===0&&r<0)return l.DIV0;const t=e**r;return Number.isFinite(t)?t:l.NUM})),T("LOG",1,2,(e,r)=>{const t=A(e),n=r==null?10:A(r);return t instanceof a?t:n instanceof a?n:t<=0||n<=0?l.NUM:n===1?l.DIV0:n===10?Math.log10(t):n===2?Math.log2(t):Math.log(t)/Math.log(n)});function X(e,r){let[t,n]=[e,r];for(;n!==0;)[t,n]=[n,t%n];return t}function H(e,r){const t=S(e,r);if(t instanceof a)return t;const n=t.map(Math.trunc);return n.some(s=>s<0||s>=2**53)?l.NUM:n}N("GCD","(r)",(e,r)=>{const t=H(e,r);return t instanceof a?t:t.reduce(X,0)}),N("LCM","(r)",(e,r)=>{const t=H(e,r);if(t instanceof a)return t;if(t.includes(0))return 0;const n=t.reduce((s,o)=>s*o/X(s,o),1);return Number.isFinite(n)?n:l.NUM}),T("BASE",2,3,U((e=0,r=0,t=Number.NaN)=>{const n=Math.trunc(e),s=Math.trunc(r),o=Number.isNaN(t)?0:Math.trunc(t);return n<0||n>=2**53||s<2||s>36||o<0||o>255?l.NUM:n.toString(s).toUpperCase().padStart(o,"0")}));const mt="MDCLXVI",Y=[1e3,500,100,50,10,5,1];function Nt(e,r){const t=f=>Y[f]??1,n=f=>mt.charAt(f),s=Y.length-1;let o=e,c="";for(let f=0;f<=s/2;f++){const i=2*f,u=Math.floor(o/t(i));if(u%5===4){const h=u===4?i-1:i-2;let M=i,m=0;for(;m<r&&M<s;)m+=1,t(h)-t(M+1)<=o?M+=1:m=r;c+=n(M)+n(h),o+=t(M)-t(h)}else u>4&&(c+=n(i-1)),c+=n(i).repeat(u%5),o%=t(i)}return c}T("ROMAN",1,2,(e,r)=>{const t=A(e);if(t instanceof a)return t;let n=0;if(typeof r=="boolean")n=r?0:4;else if(r!=null){const o=A(r);if(o instanceof a)return o;n=Math.trunc(o)}const s=Math.trunc(t);return s<0||s>3999||n<0||n>4?l.VALUE:Nt(s,n)});function B(e){return!Number.isInteger(e)||e<0||e>=P?l.NUM:BigInt(e)}for(const[e,r]of[["BITAND",(t,n)=>t&n],["BITOR",(t,n)=>t|n],["BITXOR",(t,n)=>t^n]])T(e,2,2,U((t=0,n=0)=>{const s=B(t),o=B(n);return s instanceof a?s:o instanceof a?o:Number(r(s,o))}));for(const[e,r]of[["BITLSHIFT",1],["BITRSHIFT",-1]])T(e,2,2,U((t=0,n=0)=>{const s=B(t);if(s instanceof a)return s;const o=Math.trunc(n)*r;if(Math.abs(o)>53)return l.NUM;const c=o>=0?s<<BigInt(o):s>>BigInt(-o);return c>=BigInt(P)?l.NUM:Number(c)}));for(const[e,r,t]of[["BESSELJ",ft,!1],["BESSELI",it,!1],["BESSELY",ut,!0],["BESSELK",at,!0]])T(e,2,2,U((n=0,s=0)=>{const o=Math.trunc(s);if(o<0||t&&n<=0)return l.NUM;const c=r(o,n);return Number.isFinite(c)?c:l.NUM}));T("SLN",3,3,U((e=0,r=0,t=0)=>t===0?l.DIV0:(e-r)/t)),N("GEOMEAN","(r)",(e,r)=>{const t=S(e,r);return t instanceof a?t:t.length===0||t.some(n=>n<=0)?l.NUM:Math.exp(t.reduce((n,s)=>n+Math.log(s),0)/t.length)}),N("HARMEAN","(r)",(e,r)=>{const t=S(e,r);return t instanceof a?t:t.length===0||t.some(n=>n<=0)?l.NUM:t.length/t.reduce((n,s)=>n+1/s,0)}),N("KURT","(r)",(e,r)=>{const t=S(e,r);if(t instanceof a)return t;const n=t.length;if(n<4)return l.DIV0;const s=t.reduce((f,i)=>f+i,0)/n,o=t.reduce((f,i)=>f+(i-s)**2,0)/(n-1);if(o===0)return l.DIV0;const c=t.reduce((f,i)=>f+(i-s)**4,0)/o**2;return n*(n+1)/((n-1)*(n-2)*(n-3))*c-3*(n-1)**2/((n-2)*(n-3))});function z(e,r){const t=[];let n;return ct(e,r,(s,o)=>{if(!n){if(s instanceof a)n=s;else if(typeof s=="number")t.push(s);else if(o&&s!==null){const c=A(s);c instanceof a?n=c:t.push(c)}}}),n??t}N("MODE.SNGL","(r)",(e,r)=>{const t=z(e,r);if(t instanceof a)return t;const n=new Map;for(const c of t)n.set(c,(n.get(c)??0)+1);let s,o=1;for(const[c,f]of n)f>o&&(s=c,o=f);return s??l.NA}),O("MODE","MODE.SNGL"),N("MODE.MULT","(r)",(e,r)=>{const t=z(e,r);if(t instanceof a)return t;const n=new Map;for(const c of t)n.set(c,(n.get(c)??0)+1);let s=0;for(const c of n.values())s=Math.max(s,c);if(s<2)return l.NA;const o=[...n].filter(([,c])=>c===s).map(([c])=>c);return new R(o.length,1,o)});function dt(e,r){const t=r*(e.length-1),n=Math.floor(t),s=e[n]??0,o=e[n+1]??s;return s+(t-n)*(o-s)}N("QUARTILE.INC","rv",(e,r)=>{const t=S([e[0]],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[1],r.frame));if(n instanceof a)return n;const s=Math.trunc(n);return t.length===0||s<0||s>4?l.NUM:dt([...t].sort((o,c)=>o-c),s/4)}),O("QUARTILE","QUARTILE.INC");function W(e,r){const t=A(r.calc.scalar(e[0],r.frame));if(t instanceof a)return t;const n=S([e[1]],r);if(n instanceof a)return n;const s=e[2]===void 0?0:A(r.calc.scalar(e[2],r.frame));if(s instanceof a)return s;const o=n.filter(c=>c===t).length;return o===0?l.NA:{before:n.filter(c=>s===0?c>t:c<t).length,ties:o}}N("RANK.EQ","vr?v",(e,r)=>{const t=W(e,r);return t instanceof a?t:t.before+1}),N("RANK.AVG","vr?v",(e,r)=>{const t=W(e,r);return t instanceof a?t:t.before+(t.ties+1)/2}),O("RANK","RANK.EQ");function L(e,r){const t=v(e,r);if(t instanceof a)return t;const n=[];for(let s=0;s<t.rows;s++){const o=[];for(let c=0;c<t.cols;c++){const f=t.at(s,c);if(f instanceof a)return f;if(typeof f!="number")return l.VALUE;o.push(f)}n.push(o)}return n}const F=e=>new R(e.length,e[0]?.length??0,e.flat());function pt(e,r){const t=r[0]?.length??0;return e.map(n=>Array.from({length:t},(s,o)=>n.reduce((c,f,i)=>c+f*(r[i]?.[o]??0),0)))}N("MMULT","rr",(e,r)=>{const t=L(e[0],r),n=L(e[1],r);return t instanceof a?t:n instanceof a?n:(t[0]?.length??0)!==n.length?l.VALUE:F(pt(t,n))});function V(e){const r=e.length,t=e.map((o,c)=>[...o,...Array.from({length:r},(f,i)=>c===i?1:0)]),n=(o,c)=>t[o]?.[c]??0;let s=1;for(let o=0;o<r;o++){let c=o;for(let i=o+1;i<r;i++)Math.abs(n(i,o))>Math.abs(n(c,o))&&(c=i);if(n(c,o)===0)return{determinant:0};if(c!==o){const[i=[],u=[]]=[t[o],t[c]];t[o]=u,t[c]=i,s=-s}const f=n(o,o);s*=f,t[o]=(t[o]??[]).map(i=>i/f);for(let i=0;i<r;i++){if(i===o)continue;const u=n(i,o),h=t[o]??[];t[i]=(t[i]??[]).map((M,m)=>M-u*(h[m]??0))}}return{determinant:s,inverse:t.map(o=>o.slice(r))}}const Z=e=>e.length>0&&e.every(r=>r.length===e.length);N("MDETERM","r",(e,r)=>{const t=L(e[0],r);return t instanceof a?t:Z(t)?V(t).determinant:l.VALUE}),N("MINVERSE","r",(e,r)=>{const t=L(e[0],r);if(t instanceof a)return t;if(!Z(t))return l.VALUE;const{inverse:n}=V(t);return n?F(n):l.NUM}),T("MUNIT",1,1,U((e=0)=>{const r=Math.trunc(e);return r<1||r>73?l.VALUE:F(Array.from({length:r},(t,n)=>Array.from({length:r},(s,o)=>n===o?1:0)))}));function G(e,r,t){const n=v(e,t),s=v(r,t);if(n instanceof a)return n;if(s instanceof a)return s;if(n.rows*n.cols!==s.rows*s.cols)return l.NA;const o=[],c=[];for(let f=0;f<n.rows;f++)for(let i=0;i<n.cols;i++){const u=n.at(f,i),h=s.rows===n.rows?s.at(f,i):s.at(i,f);if(u instanceof a)return u;if(h instanceof a)return h;typeof u=="number"&&typeof h=="number"&&(o.push(u),c.push(h))}return{xs:o,ys:c}}for(const[e,r]of[["SUMX2MY2",(t,n)=>t*t-n*n],["SUMX2PY2",(t,n)=>t*t+n*n],["SUMXMY2",(t,n)=>(t-n)**2]])N(e,"rr",(t,n)=>{const s=G(t[0],t[1],n);return s instanceof a?s:s.xs.length===0?l.DIV0:s.xs.reduce((o,c,f)=>o+r(c,s.ys[f]??0),0)});N("SERIESSUM","vvvr",(e,r)=>{const[t,n,s]=e.slice(0,3).map(c=>A(r.calc.scalar(c,r.frame)));if(t instanceof a)return t;if(n instanceof a)return n;if(s instanceof a)return s;const o=S([e[3]],r);return o instanceof a?o:o.reduce((c,f,i)=>c+f*(t??0)**((n??0)+i*(s??0)),0)}),N("FREQUENCY","rr",(e,r)=>{const t=S([e[0]],r),n=S([e[1]],r);if(t instanceof a)return t;if(n instanceof a)return n;const s=n.map((c,f)=>({b:c,i:f})).sort((c,f)=>c.b-f.b),o=new Array(n.length+1).fill(0);for(const c of t){const f=s.find(u=>c<=u.b),i=f?f.i:n.length;o[i]=(o[i]??0)+1}return new R(o.length,1,o)}),N("PROB","rrv?v",(e,r)=>{const t=G(e[0],e[1],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[2],r.frame));if(n instanceof a)return n;const s=e[3]===void 0?n:A(r.calc.scalar(e[3],r.frame));if(s instanceof a)return s;const o=t.ys.reduce((c,f)=>c+f,0);return t.ys.some(c=>c<=0||c>1)||Math.abs(o-1)>1e-12?l.NUM:t.xs.reduce((c,f,i)=>f>=n&&f<=s?c+(t.ys[i]??0):c,0)});const J=e=>e.reduce((r,t)=>r+t,0);function $(e,r,t){const n=r.map(u=>t?[...u,1]:[...u]),s=n[0]?.length??0,o=Array.from({length:s},(u,h)=>Array.from({length:s},(M,m)=>n.reduce((E,g)=>E+(g[h]??0)*(g[m]??0),0))),{inverse:c}=V(o);if(!c)return;const f=Array.from({length:s},(u,h)=>n.reduce((M,m,E)=>M+(m[h]??0)*(e[E]??0),0)),i=c.map(u=>u.reduce((h,M,m)=>h+M*(f[m]??0),0));return t?i:[...i,0]}function j(e,r,t){const n=L(e[0],r);if(n instanceof a)return n;const s=n.length===1,o=n.flat();if(t&&o.some(h=>h<=0))return l.NUM;const c=t?o.map(Math.log):o,f=e[1];if(f===void 0||!x(f))return{ys:c,xs:o.map((h,M)=>[M+1]),byRow:s};const i=L(f,r);if(i instanceof a)return i;const u=i[0]?.length??0;return s?u!==c.length?l.REF:{ys:c,xs:Array.from({length:u},(h,M)=>i.map(m=>m[M]??0)),byRow:s}:i.length!==c.length?l.REF:{ys:c,xs:i,byRow:s}}const x=e=>e instanceof Q||e instanceof R||typeof e=="number",tt=(e,r)=>e===void 0||!x(e)&&typeof e!="boolean"?!0:_(r.calc.scalar(e,r.frame));function nt(e){return(r,t)=>{const n=j(r,t,e);if(n instanceof a)return n;const s=tt(r[3],t);if(s instanceof a)return s;const o=$(n.ys,n.xs,s);if(!o)return l.NUM;const c=r[2];let f=n.xs;if(c!==void 0&&x(c)){const u=L(c,t);if(u instanceof a)return u;const h=n.xs[0]?.length??1,M=u[0]?.length??0;f=n.byRow||h===1&&u.length===1?Array.from({length:M},(m,E)=>u.map(g=>g[E]??0)):u}const i=f.map(u=>{const h=u.reduce((M,m,E)=>M+m*(o[E]??0),0)+(o[u.length]??0);return e?Math.exp(h):h});return n.byRow?new R(1,i.length,i):new R(i.length,1,i)}}N("TREND","r?rrv",nt(!1)),N("GROWTH","r?rrv",nt(!0));function Et(e,r,t,n){const s=r.map(p=>n?[...p,1]:[...p]),o=s[0]?.length??0,{inverse:c}=V(Array.from({length:o},(p,d)=>Array.from({length:o},(b,D)=>s.reduce((rt,k)=>rt+(k[d]??0)*(k[D]??0),0))));if(!c)return;const f=r.map(p=>p.reduce((d,b,D)=>d+b*(t[D]??0),0)+(t[p.length]??0)),i=e.reduce((p,d,b)=>p+(d-(f[b]??0))**2,0),u=n?J(e)/e.length:0,h=e.reduce((p,d)=>p+(d-u)**2,0),M=h-i,m=e.length-o,E=m>0?i/m:0,g=c.map((p,d)=>Math.sqrt(Math.max(0,(p[d]??0)*E))),I=r[0]?.length??0;return{errors:g,r2:h===0?1:M/h,sey:Math.sqrt(E),f:m>0&&i>0?M/I/(i/m):0,df:m,ssreg:M,ssresid:i}}function et(e){return(r,t)=>{const n=j(r,t,e);if(n instanceof a)return n;const s=tt(r[2],t);if(s instanceof a)return s;const o=$(n.ys,n.xs,s);if(!o)return l.NUM;const f=[...o.slice(0,-1).reverse(),o[o.length-1]??0],i=e?f.map(Math.exp):f,u=r[3],h=u===void 0||!gt(u)?!1:_(t.calc.scalar(u,t.frame));if(h instanceof a)return h;if(!h)return new R(1,i.length,i);const M=Et(n.ys,n.xs,o,s);if(!M)return l.NUM;const m=i.length,E=I=>[...I,...new Array(m-I.length).fill(l.NA)],g=s?[...M.errors.slice(0,-1).reverse(),M.errors[M.errors.length-1]??0]:[...[...M.errors].reverse(),l.NA];return new R(5,m,[...i,...g,...E([M.r2,M.sey]),...E([M.f,M.df]),...E([M.ssreg,M.ssresid])])}}const gt=e=>x(e)||typeof e=="boolean";N("LINEST","r?rvv",et(!1)),N("LOGEST","r?rvv",et(!0));const y=e=>J(e)/e.length,w=e=>{const r=y(e);return e.reduce((t,n)=>t+(n-r)**2,0)/(e.length-1)};N("CHISQ.TEST","rr",(e,r)=>{const t=L(e[0],r),n=L(e[1],r);if(t instanceof a)return t;if(n instanceof a)return n;const s=t.length,o=t[0]?.length??0;if(n.length!==s||(n[0]?.length??0)!==o)return l.NA;if(s*o<2)return l.NA;let c=0;for(let i=0;i<s;i++)for(let u=0;u<o;u++){const h=n[i]?.[u]??0;if(h<0)return l.NUM;if(h===0)return l.DIV0;c+=((t[i]?.[u]??0)-h)**2/h}const f=s>1&&o>1?(s-1)*(o-1):s>1?s-1:o-1;return lt(f/2,c/2)}),O("CHITEST","CHISQ.TEST"),N("T.TEST","rrvv",(e,r)=>{const t=A(r.calc.scalar(e[2],r.frame)),n=A(r.calc.scalar(e[3],r.frame));if(t instanceof a)return t;if(n instanceof a)return n;const s=Math.trunc(t),o=Math.trunc(n);if(s!==1&&s!==2||o<1||o>3)return l.NUM;let c,f;if(o===1){const u=G(e[0],e[1],r);if(u instanceof a)return u;const h=u.xs.map((M,m)=>M-(u.ys[m]??0));if(h.length<2)return l.DIV0;c=y(h)/Math.sqrt(w(h)/h.length),f=h.length-1}else{const u=S([e[0]],r),h=S([e[1]],r);if(u instanceof a)return u;if(h instanceof a)return h;if(u.length<2||h.length<2)return l.DIV0;const[M,m,E,g]=[w(u),w(h),u.length,h.length],I=Math.abs(y(u)-y(h));if(o===2){f=E+g-2;const p=((E-1)*M+(g-1)*m)/f;c=I/Math.sqrt(p*(1/E+1/g))}else{const p=M/E,d=m/g;c=I/Math.sqrt(p+d),f=(p+d)**2/(p**2/(E-1)+d**2/(g-1))}}return Number.isFinite(c)?q(f/2,.5,f/(f+c*c))*s/2:l.DIV0}),O("TTEST","T.TEST"),N("F.TEST","rr",(e,r)=>{const t=S([e[0]],r),n=S([e[1]],r);if(t instanceof a)return t;if(n instanceof a)return n;if(t.length<2||n.length<2)return l.DIV0;const[s,o]=[w(t),w(n)];if(s===0||o===0)return l.DIV0;const c=s/o,[f,i]=[t.length-1,n.length-1],u=q(i/2,f/2,i/(f*c+i));return 2*Math.min(u,1-u)}),O("FTEST","F.TEST"),N("Z.TEST","rv?v",(e,r)=>{const t=S([e[0]],r);if(t instanceof a)return t;const n=A(r.calc.scalar(e[1],r.frame));if(n instanceof a)return n;if(t.length===0)return l.NA;const s=e[2]===void 0?t.length<2?l.DIV0:Math.sqrt(w(t)):A(r.calc.scalar(e[2],r.frame));return s instanceof a?s:s===0?l.DIV0:1-ht((y(t)-n)/(s/Math.sqrt(t.length)))}),O("ZTEST","Z.TEST");const At={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",12:"MEDIAN",13:"MODE.SNGL",14:"LARGE",15:"SMALL",16:"PERCENTILE.INC",17:"QUARTILE.INC",18:"PERCENTILE.EXC",19:"QUARTILE.EXC"};N("AGGREGATE","vv(r)",(e,r)=>{const t=A(r.calc.scalar(e[0],r.frame)),n=A(r.calc.scalar(e[1],r.frame));if(t instanceof a)return t;if(n instanceof a)return n;const s=At[Math.trunc(t)],o=s===void 0?void 0:ot.get(s);if(o===void 0)return l.VALUE;const c=![2,3,6,7].includes(Math.trunc(n)),f=[1,3,5,7].includes(Math.trunc(n)),i=m=>{const E=m instanceof st?m.parts:[m],g=[];for(const p of E)if(p instanceof Q){const d=p;for(let b=d.top;b<=Math.min(d.bottom,d.sheet.lastRow);b++)if(!(f&&(d.sheet.spec.rows?.[String(b+1)]?.hidden===!0||r.calc.filtered(d.sheet).has(b))))for(let D=d.left;D<=d.right;D++)g.push(r.calc.read(d.sheet,b,D))}else{const d=r.calc.flat(p);d instanceof R?g.push(...d.data):g.push(d)}const I=c?g:g.filter(p=>!(p instanceof a));return new R(I.length,1,I)},u=Math.trunc(t)>=14,h=e.slice(2),M=u?[i(h[0]),...h.slice(1)]:h.map(i);return r.calc.applyFunction(o,M,r.frame)}),T("FACT",1,1,U(e=>{if(e<0)return l.NUM;let r=1;for(let t=2;t<=Math.trunc(e);t++)r*=t;return Number.isFinite(r)?r:l.NUM})),T("FACTDOUBLE",1,1,U(e=>{if(e<0)return l.NUM;let r=1;for(let t=Math.trunc(e);t>1;t-=2)r*=t;return Number.isFinite(r)?r:l.NUM})),T("ATAN2",2,2,U((e,r)=>e===0&&r===0?l.DIV0:Math.atan2(r,e)));for(const[e,r]of[["LARGE",!0],["SMALL",!1]])N(e,"rv",(t,n)=>{const s=S([t[0]],n);if(s instanceof a)return s;const o=A(t[1]);if(o instanceof a)return o;const c=Math.ceil(o);return c<1||c>s.length?l.NUM:(s.sort((f,i)=>r?i-f:f-i),s[c-1]??l.NUM)});
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=modern.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 i,ERR as y,Matrix as X}from"../../values.js";import{toNumber as G,toText as F}from"../coerce.js";import{Lambda as H,Missing as N,Reference as J}from"../types.js";import{FUNCTIONS as K,cellsOf as x,raw as T,scalar as Q}from"./define.js";import{compareBy as $,included as cn,indexes as ln,keyOf as Z,matrixOf as nn,numberOf as U,oneOf as D,rowsOfCells as S}from"./dynamic.js";function W(n,t,o){const e=F(n);if(e instanceof i)return e;const r=t==null?0:G(t);if(r instanceof i)return r;if(r!==0&&r!==1)return y.VALUE;try{return new RegExp(e,`${r===1?"i":""}${o?"g":""}`)}catch{return y.VALUE}}Q("REGEXTEST",2,3,(n,t,o)=>{const e=F(n);if(e instanceof i)return e;const r=W(t,o,!1);return r instanceof i?r:r.test(e)}),T("REGEXEXTRACT","vv?vv",(n,t)=>{const o=F(n[0]instanceof N?null:n[0]);if(o instanceof i)return o;const e=U(n[2],t,0);if(e instanceof i)return e;const r=n[3]instanceof N?void 0:n[3],s=W(n[1],r,e===1);if(s instanceof i)return s;if(e===0)return s.exec(o)?.[0]??y.NA;if(e===1){const l=[...o.matchAll(s)].map(c=>c[0]);return l.length===0?y.NA:new X(l.length,1,l)}if(e===2){const l=s.exec(o);if(!l)return y.NA;const c=l.slice(1).map(f=>f??"");return c.length===0?y.NA:new X(1,c.length,c)}return y.VALUE}),Q("REGEXREPLACE",3,5,(n,t,o,e,r)=>{const s=F(n),l=F(o);if(s instanceof i)return s;if(l instanceof i)return l;const c=e==null?0:G(e);if(c instanceof i)return c;const f=W(t,r,!0);if(f instanceof i)return f;const h=Math.trunc(c);if(h===0)return s.replace(f,l);const a=[...s.matchAll(f)],m=h>0?a[h-1]:a[a.length+h];if(!m)return s;const d=new RegExp(f.source,f.flags.replace("g","")),p=m.index;return s.slice(0,p)+m[0].replace(d,l)+s.slice(p+m[0].length)}),T("PERCENTOF","rr",(n,t)=>{const o=K.get("SUM");if(!o)return y.NAME;const e=G(D(t.calc.applyFunction(o,[n[0]],t.frame),t)),r=G(D(t.calc.applyFunction(o,[n[1]],t.frame),t));return e instanceof i?e:r instanceof i?r:r===0?y.DIV0:e/r}),T("TRIMRANGE","r?vv",(n,t)=>{const o=n[0];if(!(o instanceof J))return o instanceof i?o:y.VALUE;const e=U(n[1],t,3),r=U(n[2],t,3);if(e instanceof i)return e;if(r instanceof i)return r;const s=t.calc.matrix(o),l=d=>Array.from({length:s.cols},(p,u)=>s.at(d,u)).every(p=>p===null),c=d=>Array.from({length:s.rows},(p,u)=>s.at(u,d)).every(p=>p===null);let f=0,h=s.rows-1,a=0,m=s.cols-1;if(e===1||e===3)for(;f<=h&&l(f);)f++;if(e===2||e===3)for(;h>=f&&l(h);)h--;if(r===1||r===3)for(;a<=m&&c(a);)a++;if(r===2||r===3)for(;m>=a&&c(m);)m--;return f>h||a>m?y.REF:new J(o.sheet,o.top+f,o.left+a,o.top+h,o.left+m)});function en(n,t,o){const e=new Map;for(const r of o){const s=n[r]?.[t]??null,l=Z(s),c=e.get(l);c?c.records.push(r):e.set(l,{key:s,records:[r],children:[]})}return[...e.values()]}function Y(n,t,o,e,r,s){const l=(a,m)=>a.sort((d,p)=>{for(const u of r){const w="field"in u?u.field===m?$(d.key,p.key,u.down):0:$(u.value(d.records),u.value(p.records),u.down);if(w!==0)return w}return 0}),c=[],f=e<0,h=Math.abs(e);if(s){const a=new Map;for(const d of o){const u=(n[d]??[]).slice(0,t).map(Z).join("\0"),w=a.get(u);w?w.records.push(d):a.set(u,{key:null,records:[d],children:[]})}const m=[...a.values()].sort((d,p)=>{for(const u of r){const w="field"in u?$(n[d.records[0]??0]?.[u.field]??null,n[p.records[0]??0]?.[u.field]??null,u.down):$(u.value(d.records),u.value(p.records),u.down);if(w!==0)return w}return 0});for(const d of m)c.push({kind:"leaf",keys:(n[d.records[0]??0]??[]).slice(0,t),records:d.records})}else{const a=(m,d,p)=>{for(const u of l(m,d)){const w=[...p,u.key];if(d===t-1){c.push({kind:"leaf",keys:w,records:u.records});continue}const R={kind:"subtotal",keys:[...w,...Array(t-w.length).fill(null)],records:u.records},k=d<h-1;k&&f&&c.push(R),a(en(n,d+1,u.records),d+1,w),k&&!f&&c.push(R)}};a(en(n,0,o),0,[])}if(h>=1){const a={kind:"total",keys:["Total",...Array(t-1).fill(null)],records:[...o]};f?c.unshift(a):c.push(a)}return c}function tn(n,t,o,e){const r=f=>new X(f.length,1,[...f]),s=n.named===void 0?void 0:K.get(n.named),c=(s?s.min>=2:n.params.length>=2)?[r(t),r(o)]:[r(t)];return D(e.calc.apply(n,c),e)}function on(n,t,o){if(n===void 0||n instanceof N){const r=t[0]??[],s=t[1]??[];return{has:r.length>0&&r.every(c=>typeof c=="string")&&s.some(c=>typeof c=="number"),show:!1,named:!1}}const e=U(n,o,0);return e instanceof i?e:[0,1,2,3].includes(e)?{has:e===1||e===3,show:e===2||e===3,named:e===2}:y.VALUE}function rn(n,t,o,e){const r=Array.from({length:t},(c,f)=>f);if(n===void 0||n instanceof N)return r;const s=x(n,e);if(s instanceof i)return s;if(s.rows*s.cols!==t+o)return y.VALUE;const l=[];for(const c of r){const f=c+o,h=s.cols===1?s.at(f,0):s.at(0,f),a=cn(h);if(a instanceof i)return a;a&&l.push(c)}return l}function j(n,t,o,e){const r=n===void 0||n instanceof N?[]:ln(n,e,1);if(r instanceof i)return r;const s=[];for(const l of r){const c=Math.abs(l)-1,f=l<0;if(c<0)return y.VALUE;if(c<t)s.push({field:c,down:f});else{const h=o(c-t);if(!h)return y.VALUE;s.push({value:h,down:f})}}for(let l=0;l<t;l++)s.some(c=>"field"in c&&c.field===l)||s.push({field:l,down:!1});return s}const q=(n,t,o)=>U(n,t,o);T("GROUPBY","rrr?vvrrv",(n,t)=>{const o=x(n[0],t),e=x(n[1],t),r=n[2];if(o instanceof i)return o;if(e instanceof i)return e;if(!(r instanceof H))return y.VALUE;if(o.rows!==e.rows)return y.VALUE;const s=o.cols===0?[]:S(o),l=S(e),c=on(n[3],l,t);if(c instanceof i)return c;const f=c.has?1:0,h=s.slice(f),a=l.slice(f),m=q(n[4],t,1);if(m instanceof i)return m;const d=U(n[7],t,0);if(d instanceof i)return d;const p=rn(n[6],h.length,f,t);if(p instanceof i)return p;if(p.length===0)return y.CALC;const u=o.cols,w=e.cols,R=E=>a.map(A=>A[E]??null),k=Array.from({length:w},(E,A)=>R(A)),b=E=>p.map(A=>k[E]?.[A]??null),C=(E,A)=>tn(r,A.map(_=>k[E]?.[_]??null),b(E),t),L=j(n[5],u,E=>E<w?A=>C(E,A):void 0,t);if(L instanceof i)return L;const I=Y(h,u,p,m,L,d===1),O=[];c.show&&O.push([...Array.from({length:u},(E,A)=>c.named?`Row Field ${String(A+1)}`:s[0]?.[A]??null),...Array.from({length:w},(E,A)=>c.named?`Value ${String(A+1)}`:l[0]?.[A]??null)]);for(const E of I)O.push([...E.keys,...Array.from({length:w},(A,_)=>C(_,E.records))]);return nn(O)}),T("PIVOTBY","rrrr?vvrvrrv",(n,t)=>{const o=x(n[0],t),e=x(n[1],t),r=x(n[2],t),s=n[3];if(o instanceof i)return o;if(e instanceof i)return e;if(r instanceof i)return r;if(!(s instanceof H))return y.VALUE;if(o.rows!==r.rows||e.rows!==r.rows)return y.VALUE;const l=S(o),c=S(e),f=S(r),h=on(n[4],f,t);if(h instanceof i)return h;const a=h.has?1:0,m=l.slice(a),d=c.slice(a),p=f.slice(a),u=q(n[5],t,1),w=q(n[7],t,1),R=U(n[10],t,0);if(u instanceof i)return u;if(w instanceof i)return w;if(R instanceof i)return R;const k=rn(n[9],p.length,a,t);if(k instanceof i)return k;if(k.length===0)return y.CALC;const b=r.cols,C=j(n[6],o.cols,()=>{},t),L=j(n[8],e.cols,()=>{},t);if(C instanceof i)return C;if(L instanceof i)return L;const I=Y(m,o.cols,k,u,C,!1),O=Y(d,e.cols,k,w,L,!1),E=(v,g)=>{const M=new Set(g);return v.filter(V=>M.has(V))},A=(v,g)=>p[g]?.[v]??null,_=(v,g,M)=>{const V=E(g.records,M.records);if(V.length===0)return null;const sn=R===1?g.records:R===2?k:M.records;return tn(s,V.map(P=>A(v,P)),sn.map(P=>A(v,P)),t)},z=o.cols,B=[];for(let v=0;v<e.cols;v++)B.push([...Array(z).fill(null),...O.flatMap(g=>Array.from({length:b},(M,V)=>V===0?g.keys[v]??null:null))]);(b>1||h.show)&&B.push([...Array.from({length:z},(v,g)=>h.show?l[0]?.[g]??null:null),...O.flatMap(()=>Array.from({length:b},(v,g)=>h.has?f[0]?.[g]??null:`Value ${String(g+1)}`))]);for(const v of I)B.push([...v.keys,...O.flatMap(g=>Array.from({length:b},(M,V)=>_(V,v,g)))]);return nn(B)});
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{format as M,isValidFormat as D}from"numfmt";import{CellError as i,ERR as d}from"../../values.js";import{numberOfText as V,toBool as $,toNumber as h,toText as l}from"../coerce.js";import{alias as F,cellsOf as H,eachRow as N,many as C,number as x,raw as b,scalar as u}from"./define.js";import{wildcard as S}from"./criteria.js";const p=n=>r=>{const t=l(r);return t instanceof i?t:n(t)},m=(n,r)=>{if(n===void 0)return r;const t=h(n);return t instanceof i?t:t<0?d.VALUE:Math.trunc(t)},O=(n,r)=>Array.from(n,t=>{const e=r(t);return e.length===t.length?e:t}).join(""),I=n=>O(n,r=>r.toUpperCase()),R=n=>O(n,r=>r.toLowerCase());u("LEFT",1,2,(n,r)=>{const t=l(n),e=m(r,1);return t instanceof i?t:e instanceof i?e:t.slice(0,e)}),u("RIGHT",1,2,(n,r)=>{const t=l(n),e=m(r,1);return t instanceof i?t:e instanceof i?e:e===0?"":t.slice(-e)}),u("MID",3,3,(n,r,t)=>{const e=l(n),s=h(r),o=m(t,0);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(s<1)return d.VALUE;const c=Math.trunc(s)-1;return e.slice(c,c+o)}),u("LEN",1,1,p(n=>n.length)),u("LOWER",1,1,p(R)),u("UPPER",1,1,p(I)),u("PROPER",1,1,p(n=>R(n).replace(/(^|[^\p{L}])(\p{L})/gu,(r,t,e)=>`${t}${I(e)}`))),u("TRIM",1,1,p(n=>n.replace(/ +/gu," ").replace(/^ | $/gu,""))),u("CLEAN",1,1,p(n=>n.replace(/[\u0000-\u001f]/gu,""))),u("T",1,1,n=>typeof n=="string"?n:""),u("EXACT",2,2,(n,r)=>{const t=l(n),e=l(r);return t instanceof i?t:e instanceof i?e:t===e}),u("REPT",2,2,(n,r)=>{const t=l(n),e=m(r,0);return t instanceof i?t:e instanceof i?e:t.length*e>32767?d.VALUE:t.repeat(e)}),u("CHAR",1,1,x(n=>{const r=Math.trunc(n);return r<1||r>255?d.VALUE:X(r)})),u("UNICHAR",1,1,x(n=>{const r=Math.trunc(n);return r<1||r>1114111?d.VALUE:String.fromCodePoint(r)})),u("CODE",1,1,p(n=>n===""?d.VALUE:n.charCodeAt(0))),u("UNICODE",1,1,p(n=>n.codePointAt(0)??d.VALUE));const B="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";function X(n){return n>=128&&n<160?B.charAt(n-128):String.fromCharCode(n)}b("CONCAT",1,C,(n,r)=>{let t="",e;return N(n,r,s=>{if(e)return;const o=l(s);o instanceof i?e=o:t+=o}),e??t}),u("CONCATENATE",1,C,(...n)=>{let r="";for(const t of n){const e=l(t);if(e instanceof i)return e;r+=e}return r}),b("TEXTJOIN",3,C,(n,r)=>{const[t,e,...s]=n,o=H(t??"",r);if(o instanceof i)return o;const c=[];for(let E=0;E<o.rows;E++)for(let L=0;L<o.cols;L++){const g=l(o.at(E,L));if(g instanceof i)return g;c.push(g)}const a=$(r.calc.scalar(e??!0,r.frame));if(a instanceof i)return a;const f=[];let A;if(N(s,r,E=>{if(A)return;const L=l(E);L instanceof i?A=L:(!a||L!=="")&&f.push(L)}),A)return A;let U=f[0]??"";for(let E=1;E<f.length;E++)U+=`${c.length>0?c[(E-1)%c.length]??"":""}${f[E]??""}`;return U}),u("SUBSTITUTE",3,4,(n,r,t,e)=>{const s=l(n),o=l(r),c=l(t);if(s instanceof i)return s;if(o instanceof i)return o;if(c instanceof i)return c;if(o==="")return s;if(e===void 0)return s.split(o).join(c);const a=h(e);if(a instanceof i)return a;if(a<1)return d.VALUE;let f=-1;for(let A=0;A<Math.trunc(a);A++)if(f=s.indexOf(o,f+1),f<0)return s;return`${s.slice(0,f)}${c}${s.slice(f+o.length)}`}),u("REPLACE",4,4,(n,r,t,e)=>{const s=l(n),o=h(r),c=m(t,0),a=l(e);if(s instanceof i)return s;if(o instanceof i)return o;if(c instanceof i)return c;if(a instanceof i)return a;if(o<1)return d.VALUE;const f=Math.trunc(o)-1;return`${s.slice(0,f)}${a}${s.slice(f+c)}`}),u("FIND",2,3,(n,r,t)=>{const e=l(n),s=l(r),o=t===void 0?1:h(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(o<1||o>s.length+1)return d.VALUE;const c=s.indexOf(e,Math.trunc(o)-1);return c<0?d.VALUE:c+1}),u("SEARCH",2,3,(n,r,t)=>{const e=l(n),s=l(r),o=t===void 0?1:h(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(o<1||o>s.length+1)return d.VALUE;const c=Math.trunc(o)-1,a=S(`${e}*`);for(let f=c;f<=s.length;f++)if(a(s.slice(f)))return f+1;return d.VALUE}),u("VALUE",1,1,n=>typeof n=="number"?n:n==null?0:typeof n!="string"?d.VALUE:V(n)??d.VALUE),u("NUMBERVALUE",1,3,(n,r,t)=>{const e=l(n),s=l(r??"."),o=l(t??",");if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;const c=e.replace(/\s/gu,"").split(o).join("").replace(s,".");if(c==="")return 0;const a=/%*$/u.exec(c)?.[0].length??0,f=Number(c.slice(0,c.length-a));return Number.isNaN(f)?d.VALUE:f/100**a}),u("TEXT",2,2,(n,r)=>{const t=l(r);if(t instanceof i)return t;if(!D(t))return d.VALUE;if(typeof n=="boolean")return n?"TRUE":"FALSE";const e=typeof n=="string"?V(n)??n:n??0;if(e instanceof i)return e;try{return M(t,e)}catch{return d.VALUE}});function y(n,r,t){const e=t?"#,##0":"0",s=r>0?`.${"0".repeat(r)}`:"";return M(`${e}${s}`,n)}const P=(n,r)=>{const t=10**r;return Math.sign(n)*Math.round(Math.abs(n)*t+1e-9)/t};u("FIXED",1,3,(n,r,t)=>{const e=h(n),s=r==null?2:h(r),o=t===void 0?!1:$(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;const c=Math.trunc(s);return y(P(e,c),Math.max(0,c),!o)}),u("DOLLAR",1,2,(n,r)=>{const t=h(n),e=r==null?2:h(r);if(t instanceof i)return t;if(e instanceof i)return e;const s=Math.trunc(e),o=y(Math.abs(P(t,s)),Math.max(0,s),!0);return t<0?`($${o})`:`$${o}`});function j(n,r,t,e,s){const o=e?R(n):n,c=e?R(r):r,a=[];for(let f=o.indexOf(c);f>=0&&c!=="";)a.push({at:f,length:c.length}),f=o.indexOf(c,f+c.length);return t>0?(s&&a.push({at:n.length,length:0}),a[t-1]):(s&&a.unshift({at:0,length:0}),a[a.length+t])}function w(n){return(...r)=>{const[t,e,s,o,c,a]=r,f=l(t),A=l(e),U=s==null?1:h(s),E=o==null?0:h(o),L=c==null?0:h(c);if(f instanceof i)return f;if(A instanceof i)return A;if(U instanceof i)return U;if(E instanceof i)return E;if(L instanceof i)return L;const g=Math.trunc(U);if(g===0||Math.abs(g)>Math.max(f.length,1))return d.VALUE;if(A==="")return g>0===(n==="before")?"":f;const T=j(f,A,g,E===1,L===1);return T?n==="before"?f.slice(0,T.at):f.slice(T.at+T.length):a===void 0?d.NA:a}}u("TEXTBEFORE",2,6,w("before"),{errors:!0}),u("TEXTAFTER",2,6,w("after"),{errors:!0}),u("HYPERLINK",1,2,(n,r)=>r===void 0?n??null:r),u("ENCODEURL",1,1,p(n=>encodeURIComponent(n)));for(const n of["LEN","LEFT","RIGHT","MID","FIND","SEARCH","REPLACE"])F(`${n}B`,n);
2
+ import{format as $,isValidFormat as D}from"numfmt";import{CellError as i,ERR as l}from"../../values.js";import{numberOfText as N,toBool as b,toNumber as p,toText as u}from"../coerce.js";import{Missing as F}from"../types.js";import{alias as H,cellsOf as S,eachRow as x,many as B,number as I,numberArg as V,raw as C,scalar as f}from"./define.js";import{wildcard as X}from"./criteria.js";import{delimiters as j,eachLetter as k,lowerLetters as G,occurrences as _}from"./delimiters.js";const L=n=>r=>{const t=u(r);return t instanceof i?t:n(t)},T=(n,r)=>{if(n===void 0)return r;const t=p(n);return t instanceof i?t:t<0?l.VALUE:Math.trunc(t)},O=n=>k(n,r=>r.toUpperCase()),y=G;f("LEFT",1,2,(n,r)=>{const t=u(n),e=T(r,1);return t instanceof i?t:e instanceof i?e:t.slice(0,e)}),f("RIGHT",1,2,(n,r)=>{const t=u(n),e=T(r,1);return t instanceof i?t:e instanceof i?e:e===0?"":t.slice(-e)}),f("MID",3,3,(n,r,t)=>{const e=u(n),s=p(r),o=T(t,0);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(s<1)return l.VALUE;const c=Math.trunc(s)-1;return e.slice(c,c+o)}),f("LEN",1,1,L(n=>n.length)),f("LOWER",1,1,L(y)),f("UPPER",1,1,L(O)),f("PROPER",1,1,L(n=>y(n).replace(/(^|[^\p{L}])(\p{L})/gu,(r,t,e)=>`${t}${O(e)}`))),f("TRIM",1,1,L(n=>n.replace(/ +/gu," ").replace(/^ | $/gu,""))),f("CLEAN",1,1,L(n=>n.replace(/[\u0000-\u001f]/gu,""))),f("T",1,1,n=>typeof n=="string"?n:""),f("EXACT",2,2,(n,r)=>{const t=u(n),e=u(r);return t instanceof i?t:e instanceof i?e:t===e}),f("REPT",2,2,(n,r)=>{const t=u(n),e=T(r,0);return t instanceof i?t:e instanceof i?e:t.length*e>32767?l.VALUE:t.repeat(e)}),f("CHAR",1,1,I(n=>{const r=Math.trunc(n);return r<1||r>255?l.VALUE:K(r)})),f("UNICHAR",1,1,I(n=>{const r=Math.trunc(n);return r<1||r>1114111?l.VALUE:String.fromCodePoint(r)})),f("CODE",1,1,L(n=>n===""?l.VALUE:n.charCodeAt(0))),f("UNICODE",1,1,L(n=>n.codePointAt(0)??l.VALUE));const J="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";function K(n){return n>=128&&n<160?J.charAt(n-128):String.fromCharCode(n)}C("CONCAT","(r)",(n,r)=>{let t="",e;return x(n,r,s=>{if(e)return;const o=u(s);o instanceof i?e=o:t+=o}),e??t}),f("CONCATENATE",1,B,(...n)=>{let r="";for(const t of n){const e=u(t);if(e instanceof i)return e;r+=e}return r}),C("TEXTJOIN","rv(r)",(n,r)=>{const[t,e,...s]=n,o=S(t??"",r);if(o instanceof i)return o;const c=[];for(let h=0;h<o.rows;h++)for(let A=0;A<o.cols;A++){const m=u(o.at(h,A));if(m instanceof i)return m;c.push(m)}const E=b(r.calc.scalar(e??!0,r.frame));if(E instanceof i)return E;const a=[];let d;if(x(s,r,h=>{if(d)return;const A=u(h);A instanceof i?d=A:(!E||A!=="")&&a.push(A)}),d)return d;let g=a[0]??"";for(let h=1;h<a.length;h++)g+=`${c.length>0?c[(h-1)%c.length]??"":""}${a[h]??""}`;return g}),f("SUBSTITUTE",3,4,(n,r,t,e)=>{const s=u(n),o=u(r),c=u(t);if(s instanceof i)return s;if(o instanceof i)return o;if(c instanceof i)return c;if(o==="")return s;if(e===void 0)return s.split(o).join(c);const E=p(e);if(E instanceof i)return E;if(E<1)return l.VALUE;let a=-1;for(let d=0;d<Math.trunc(E);d++)if(a=s.indexOf(o,a+1),a<0)return s;return`${s.slice(0,a)}${c}${s.slice(a+o.length)}`}),f("REPLACE",4,4,(n,r,t,e)=>{const s=u(n),o=p(r),c=T(t,0),E=u(e);if(s instanceof i)return s;if(o instanceof i)return o;if(c instanceof i)return c;if(E instanceof i)return E;if(o<1)return l.VALUE;const a=Math.trunc(o)-1;return`${s.slice(0,a)}${E}${s.slice(a+c)}`}),f("FIND",2,3,(n,r,t)=>{const e=u(n),s=u(r),o=t===void 0?1:p(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(o<1||o>s.length+1)return l.VALUE;const c=s.indexOf(e,Math.trunc(o)-1);return c<0?l.VALUE:c+1}),f("SEARCH",2,3,(n,r,t)=>{const e=u(n),s=u(r),o=t===void 0?1:p(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;if(o<1||o>s.length+1)return l.VALUE;const c=Math.trunc(o)-1,E=X(`${e}*`);for(let a=c;a<=s.length;a++)if(E(s.slice(a)))return a+1;return l.VALUE}),f("VALUE",1,1,n=>typeof n=="number"?n:n==null?0:typeof n!="string"?l.VALUE:N(n)??l.VALUE),f("NUMBERVALUE",1,3,(n,r,t)=>{const e=u(n),s=u(r??"."),o=u(t??",");if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;const c=e.replace(/\s/gu,"").split(o).join("").replace(s,".");if(c==="")return 0;const E=/%*$/u.exec(c)?.[0].length??0,a=Number(c.slice(0,c.length-E));return Number.isNaN(a)?l.VALUE:a/100**E}),f("TEXT",2,2,(n,r)=>{const t=u(r);if(t instanceof i)return t;if(!D(t))return l.VALUE;if(typeof n=="boolean")return n?"TRUE":"FALSE";const e=typeof n=="string"?N(n)??n:n??0;if(e instanceof i)return e;try{return $(t,e)}catch{return l.VALUE}});function v(n,r,t){const e=t?"#,##0":"0",s=r>0?`.${"0".repeat(r)}`:"";return $(`${e}${s}`,n)}const P=(n,r)=>{const t=10**r;return Math.sign(n)*Math.round(Math.abs(n)*t+1e-9)/t};f("FIXED",1,3,(n,r,t)=>{const e=p(n),s=r==null?2:p(r),o=t===void 0?!1:b(t);if(e instanceof i)return e;if(s instanceof i)return s;if(o instanceof i)return o;const c=Math.trunc(s);return v(P(e,c),Math.max(0,c),!o)}),f("DOLLAR",1,2,(n,r)=>{const t=p(n),e=r==null?2:p(r);if(t instanceof i)return t;if(e instanceof i)return e;const s=Math.trunc(e),o=v(Math.abs(P(t,s)),Math.max(0,s),!0);return t<0?`($${o})`:`$${o}`});function W(n,r,t,e,s){const o=_(n,r,e);return t>0?(s&&o.push({at:n.length,length:0}),o[t-1]):(s&&o.unshift({at:0,length:0}),o[o.length+t])}function w(n){return(r,t)=>{const[e,s,o,c,E,a]=r.map(U=>U instanceof F?void 0:U),d=u(e??null),g=j(s,t),h=V(o,1),A=V(c,0),m=V(E,0);if(d instanceof i)return d;if(g instanceof i)return g;if(h instanceof i)return h;if(A instanceof i)return A;if(m instanceof i)return m;const R=Math.trunc(h);if(R===0||Math.abs(R)>Math.max(d.length,1))return l.VALUE;if(g.length>0&&g.every(U=>U===""))return R>0===(n==="before")?"":d;const M=W(d,g,R,A===1,m===1);return M?n==="before"?d.slice(0,M.at):d.slice(M.at+M.length):a===void 0?l.NA:a}}C("TEXTBEFORE","vr?vvvv",w("before")),C("TEXTAFTER","vr?vvvv",w("after")),f("HYPERLINK",1,2,(n,r)=>r===void 0?n??null:r),f("ENCODEURL",1,1,L(n=>encodeURIComponent(n)));for(const n of["LEN","LEFT","RIGHT","MID","FIND","SEARCH","REPLACE"])H(`${n}B`,n);
@@ -0,0 +1,38 @@
1
+ import { type Area } from "../address.js";
2
+ import { FormulaCell, type SharedFormula, type Worksheet } from "../workbook.js";
3
+ import type { Reference } from "./types.js";
4
+ /** Where a group's references read, given a place in it, for the graph. */
5
+ export interface GraphSource {
6
+ /** What a formula cell reads. */
7
+ readsOf: (cell: FormulaCell) => Reference[];
8
+ /** What a formula reads evaluated at a place, one entry a reference it holds; undefined where one gives no place. */
9
+ readsAt: (shared: SharedFormula, sheet: Worksheet, row: number, col: number) => (Reference | undefined)[];
10
+ }
11
+ export declare class Graph {
12
+ /** Formula cells by the single place each reads. */
13
+ private readonly single;
14
+ private readonly ranges;
15
+ /** Edges by the sheet and column they read, and those too wide to list so. */
16
+ private readonly byColumn;
17
+ private readonly wide;
18
+ private readonly source;
19
+ constructor(source: GraphSource);
20
+ /** Makes the graph of every formula cell, a filled formula as a group. */
21
+ build(cells: readonly FormulaCell[]): void;
22
+ /** A cell's own edges: one written alone, or put in after the graph was made. */
23
+ add(cell: FormulaCell): void;
24
+ /** Takes a cell's own edges away; a group's cell stops being read as one once it is no longer its formula's. */
25
+ remove(cell: FormulaCell): void;
26
+ /** Every formula cell that reads a place of `area` on `sheet`. */
27
+ readersIn(sheet: Worksheet, area: Area): FormulaCell[];
28
+ /** Every formula cell that reads a place. */
29
+ readers(sheet: Worksheet, row: number, col: number): FormulaCell[];
30
+ private list;
31
+ /**
32
+ * A group's edges, when each of its references moves as a fill moves it:
33
+ * measured at its first cell and a row and a column on, and checked at its
34
+ * last. False, and nothing added, when one does not.
35
+ */
36
+ private addGroup;
37
+ }
38
+ //# sourceMappingURL=graph.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{overlaps as B}from"../address.js";import{FormulaCell as F,placeKey as C}from"../workbook.js";const K=32;class L{cells=new Set;reference;constructor(e){this.reference=e}footprint(){return{sheet:this.reference.sheet,area:this.reference}}visit(e,o,s){if(this.reference.sheet===e&&B(this.reference,o))for(const t of this.cells)s(t)}}class N{s;constructor(e){this.s=e}footprint(){const{s:e}=this;return{sheet:e.reads,area:{top:e.t+e.kt*e.group.top,bottom:e.b+e.kb*e.group.bottom,left:e.l+e.kl*e.group.left,right:e.r+e.kr*e.group.right}}}visit(e,o,s){const{s:t}=this;if(e!==t.reads)return;const r=O(t.group.top,t.group.bottom,t.t,t.kt,t.b,t.kb,o.top,o.bottom);if(!r)return;const i=O(t.group.left,t.group.right,t.l,t.kl,t.r,t.kr,o.left,o.right);if(i)for(let c=r[0];c<=r[1];c++)for(let h=i[0];h<=i[1];h++){const n=t.on.at(c,h);n instanceof F&&n.shared===t.shared&&s(n)}}}function O(d,e,o,s,t,r,i,c){let h=d,n=e;if(s===1)n=Math.min(n,c-o);else if(o>c)return;if(r===1)h=Math.max(h,i-t);else if(t<i)return;return h<=n?[h,n]:void 0}export class Graph{single=new Map;ranges=new Map;byColumn=new Map;wide=[];source;constructor(e){this.source=e}build(e){const o=new Map;for(const s of e){const t=o.get(s.shared);t?t.push(s):o.set(s.shared,[s])}for(const[s,t]of o)if(t.length<2||!this.addGroup(s,t))for(const r of t)this.add(r)}add(e){for(const o of this.source.readsOf(e))if(o.single){let s=this.single.get(o.sheet);s||(s=new Map,this.single.set(o.sheet,s));const t=C(o.top,o.left);let r=s.get(t);r||(r=new Set,s.set(t,r)),r.add(e)}else{let s=this.ranges.get(o.key);s||(s=new L(o),this.ranges.set(o.key,s),this.list(s)),s.cells.add(e)}}remove(e){for(const o of this.source.readsOf(e))o.single?this.single.get(o.sheet)?.get(C(o.top,o.left))?.delete(e):this.ranges.get(o.key)?.cells.delete(e)}readersIn(e,o){const s=new Set,t=n=>{s.add(n)},r=this.single.get(e);if(r)for(let n=o.top;n<=o.bottom;n++)for(let g=o.left;g<=o.right;g++)for(const f of r.get(C(n,g))??[])s.add(f);const i=new Set,c=n=>{i.has(n)||(i.add(n),n.visit(e,o,t))};for(const n of this.wide)c(n);const h=this.byColumn.get(e);if(h)for(let n=o.left;n<=o.right;n++)h.get(n)?.forEach(c);return[...s]}readers(e,o,s){return this.readersIn(e,{top:o,left:s,bottom:o,right:s})}list(e){const{sheet:o,area:s}=e.footprint();if(s.right-s.left+1>K){this.wide.push(e);return}let t=this.byColumn.get(o);t||(t=new Map,this.byColumn.set(o,t));for(let r=s.left;r<=s.right;r++){const i=t.get(r);i?i.push(e):t.set(r,[e])}}addGroup(e,o){const s=o[0]?.sheet;if(!s||o.some(f=>f.sheet!==s))return!1;const t={top:1/0,bottom:-1/0,left:1/0,right:-1/0};for(const f of o)t.top=Math.min(t.top,f.row),t.bottom=Math.max(t.bottom,f.row),t.left=Math.min(t.left,f.col),t.right=Math.max(t.right,f.col);const r=(f,l)=>this.source.readsAt(e,s,f,l),i=r(t.top,t.left),c=t.bottom>t.top?r(t.top+1,t.left):i,h=t.right>t.left?r(t.top,t.left+1):i,n=r(t.bottom,t.right);if(c.length!==i.length||h.length!==i.length||n.length!==i.length)return!1;const g=[];for(let f=0;f<i.length;f++){const l=i[f],p=c[f],a=h[f],u=n[f];if(!l||!p||!a||!u||p.sheet!==l.sheet||a.sheet!==l.sheet||u.sheet!==l.sheet)return!1;const m=(z,A)=>{const M=z-A;return M===0||M===1?M:void 0},I=t.bottom>t.top,S=t.right>t.left,b=I?m(p.top,l.top):0,w=I?m(p.bottom,l.bottom):0,k=S?m(a.left,l.left):0,y=S?m(a.right,l.right):0;if(b===void 0||w===void 0||k===void 0||y===void 0)return!1;const v=l.top-b*t.top,x=l.bottom-w*t.top,G=l.left-k*t.left,E=l.right-y*t.left;if(u.top!==v+b*t.bottom||u.bottom!==x+w*t.bottom||u.left!==G+k*t.right||u.right!==E+y*t.right)return!1;g.push(new N({shared:e,on:s,group:t,reads:l.sheet,t:v,kt:b,b:x,kb:w,l:G,kl:k,r:E,kr:y}))}for(const f of g)this.list(f);return!0}}
@@ -0,0 +1,19 @@
1
+ import { type Area } from "../address.js";
2
+ import type { Worksheet } from "../workbook.js";
3
+ import type { Reference } from "./types.js";
4
+ export type Index = Map<string, number[]>;
5
+ export declare class RangeCache<T> {
6
+ private readonly kept;
7
+ /** What `key` names, worked out over the ranges `over` read, once while they stay as they are. */
8
+ of(key: string, over: readonly Reference[], build: () => T): T;
9
+ /** What `key` names, if it is kept. */
10
+ get(key: string): T | undefined;
11
+ /** Keeps what `key` names, worked out over the ranges `over` read. */
12
+ set(key: string, over: readonly Reference[], value: T): void;
13
+ /** Forgets what read cells that changed. */
14
+ changed(sheet: Worksheet, area: Area): void;
15
+ clear(): void;
16
+ }
17
+ /** A range's index for a use (`find`, `crit`). */
18
+ export declare const indexKeyOf: (use: string, ref: Reference) => string;
19
+ //# sourceMappingURL=indexes.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{overlaps as i}from"../address.js";const h=t=>({top:t.top,left:t.left,bottom:t.bottom,right:t.right});export class RangeCache{kept=new Map;of(e,o,a){const s=this.kept.get(e);if(s)return s.value;const r=a();return this.kept.set(e,{over:o.map(p=>({sheet:p.sheet,area:h(p)})),value:r}),r}get(e){return this.kept.get(e)?.value}set(e,o,a){this.kept.set(e,{over:o.map(s=>({sheet:s.sheet,area:h(s)})),value:a})}changed(e,o){if(this.kept.size!==0)for(const[a,s]of this.kept)s.over.some(r=>r.sheet===e&&i(r.area,o))&&this.kept.delete(a)}clear(){this.kept.clear()}}export const indexKeyOf=(t,e)=>`${t}:${e.key}`;
@@ -0,0 +1,49 @@
1
+ import type { Area } from "../address.js";
2
+ import { Matrix, type Scalar } from "../values.js";
3
+ /** A value as plain data. */
4
+ export type WireScalar = number | string | boolean | null | {
5
+ error: string;
6
+ };
7
+ /** A formula cell as a pass left it. */
8
+ export interface WireCell {
9
+ sheet: number;
10
+ row: number;
11
+ col: number;
12
+ value: WireScalar;
13
+ array?: {
14
+ rows: number;
15
+ cols: number;
16
+ data: WireScalar[];
17
+ };
18
+ spill?: Area;
19
+ blocked?: Area;
20
+ }
21
+ /** What a pass computed, since the last one was sent. */
22
+ export interface Computed {
23
+ cells: WireCell[];
24
+ /** Each circular reference, as its cells. */
25
+ cycles: {
26
+ sheet: number;
27
+ row: number;
28
+ col: number;
29
+ }[][];
30
+ /** The rows filters hide, by sheet: every sheet that has some. */
31
+ hidden: {
32
+ sheet: number;
33
+ rows: number[];
34
+ }[];
35
+ }
36
+ export declare const toWire: (v: Scalar) => WireScalar;
37
+ /** A value from plain data; an error code that is none is #VALUE!. */
38
+ export declare function fromWire(v: WireScalar): Scalar;
39
+ export declare const matrixToWire: (m: Matrix) => {
40
+ rows: number;
41
+ cols: number;
42
+ data: WireScalar[];
43
+ };
44
+ export declare const matrixFromWire: (m: {
45
+ rows: number;
46
+ cols: number;
47
+ data: WireScalar[];
48
+ }) => Matrix;
49
+ //# sourceMappingURL=remote.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 o,ERR as t,Matrix as e,errorOf as a}from"../values.js";export const toWire=r=>r instanceof o?{error:r.code}:r;export function fromWire(r){return r===null||typeof r!="object"?r:a(r.error)??t.VALUE}export const matrixToWire=r=>({rows:r.rows,cols:r.cols,data:r.data.map(toWire)}),matrixFromWire=r=>new e(r.rows,r.cols,r.data.map(fromWire));
@@ -0,0 +1,82 @@
1
+ import type { SheetFile } from "@allyhub-next/formats";
2
+ import type { BookEdit } from "../edit.js";
3
+ import type { GeneratedSheets } from "../generated.js";
4
+ import { type CsvRows, type Workbook } from "../workbook.js";
5
+ import { Calc } from "./engine.js";
6
+ import type { Computed } from "./remote.js";
7
+ /** A changed cell as plain data, which crosses postMessage. */
8
+ export interface CellEdit {
9
+ /** The sheet's place in the workbook. */
10
+ sheet: number;
11
+ row: number;
12
+ col: number;
13
+ /** What it now holds, as typed; absent: empty. */
14
+ input?: string;
15
+ /** A table's calculated column whose formula it holds again. */
16
+ column?: {
17
+ table: string;
18
+ name: string;
19
+ };
20
+ /** sheet.yaml's key for it now; null: it has none. */
21
+ key?: string | null;
22
+ /** The CSV record of a table's row, now. */
23
+ record?: {
24
+ table: string;
25
+ index: number;
26
+ fields: string[];
27
+ };
28
+ }
29
+ /** An edit's changed cells, as plain data. */
30
+ export declare function cellEditsOf(edit: BookEdit): CellEdit[];
31
+ /**
32
+ * Changed cells put in a model and computed, or, for a replica, put in to
33
+ * wait for what a calculation elsewhere computes: sheet.yaml's keys, a
34
+ * table's records, the format a value typed implies, and the cell itself.
35
+ */
36
+ export declare function applyCellEdits(wb: Workbook, calc: Calc, cells: readonly CellEdit[], file?: SheetFile): void;
37
+ /** What a workbook is opened from. */
38
+ export interface Opening {
39
+ file: SheetFile;
40
+ rows: readonly (readonly [string, CsvRows])[];
41
+ /** What RAND is seeded with. */
42
+ seed: string;
43
+ generated?: GeneratedSheets;
44
+ /** The scenario on show. */
45
+ scenario?: string;
46
+ }
47
+ /** A model made from what its files say, computing or a replica. */
48
+ export declare function openWorkbook(o: Opening, mode?: {
49
+ report?: boolean;
50
+ replica?: boolean;
51
+ }): {
52
+ workbook: Workbook;
53
+ calc: Calc;
54
+ };
55
+ /**
56
+ * What a calculation elsewhere is told. Each opening starts a generation;
57
+ * what is said of an earlier one is left unanswered, and its answers are
58
+ * dropped by the page.
59
+ */
60
+ export type CalcRequest = ({
61
+ kind: "open";
62
+ generation: number;
63
+ } & Opening) | {
64
+ kind: "cells";
65
+ generation: number;
66
+ cells: CellEdit[];
67
+ file?: SheetFile;
68
+ } | {
69
+ kind: "recalculate";
70
+ generation: number;
71
+ };
72
+ export interface CalcReply {
73
+ generation: number;
74
+ computed: Computed;
75
+ }
76
+ /** The calculation a worker runs: a request in, what it computed out. */
77
+ export declare class CalcServer {
78
+ private model;
79
+ private generation;
80
+ handle(r: CalcRequest): CalcReply | undefined;
81
+ }
82
+ //# sourceMappingURL=server.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{applyScenario as p}from"../scenario.js";import{readTyped as h}from"../values.js";import{FormulaCell as m,SharedFormula as k,placeKey as y,workbookOf as b}from"../workbook.js";import{Calc as g,seededRandom as w}from"./engine.js";export function cellEditsOf(o){return o.cells.map(e=>{const r=e.column?e.sheet.tables.flatMap(t=>t.columns.map(i=>({table:t.name,col:i}))).find(t=>t.col.formula===e.column):void 0;return{sheet:e.sheet.index,row:e.row,col:e.col,...e.input===void 0?{}:{input:e.input},...r?{column:{table:r.table,name:r.col.name}}:{},...e.key===void 0?{}:{key:e.key},...e.record?{record:{table:e.record.table.name,index:e.record.index,fields:e.record.fields}}:{}}})}export function applyCellEdits(o,e,r,t){t&&o.respec(t);const i=[];for(const n of r){const l=o.sheets[n.sheet];if(!l)continue;const{row:d,col:a}=n,c=y(d,a);if(n.key===null?l.keys.delete(c):n.key!==void 0&&l.keys.set(c,n.key),n.record){const u=o.table(n.record.table);u&&(u.records[n.record.index]=n.record.fields)}l.implied.delete(c);const f=n.column?o.table(n.column.table)?.columns.find(u=>u.name===n.column?.name)?.formula:void 0;if(f){i.push({sheet:l,row:d,col:a,slot:new m(f,l,d,a)});continue}const s=h(n.input??"");s.format!==void 0&&l.implied.set(c,s.format),i.push({sheet:l,row:d,col:a,slot:s.formula===void 0?s.value??void 0:new m(new k(s.formula,d,a,{file:""}),l,d,a)})}e.change(i)}export function openWorkbook(o,e={}){const r=new Map(o.rows),t=b({file:o.file,rows:n=>r.get(n),generated:o.generated});o.scenario!==void 0&&p(t,o.scenario);const i=new g(t,{random:w(o.seed),...e}).calculate();return{workbook:t,calc:i}}export class CalcServer{model;generation=-1;handle(e){if(e.kind==="open")this.model=openWorkbook(e,{report:!0}),this.generation=e.generation;else{if(e.generation!==this.generation||!this.model)return;e.kind==="cells"?applyCellEdits(this.model.workbook,this.model.calc,e.cells,e.file):this.model.calc.recalculate()}return{generation:this.generation,computed:this.model.calc.takeComputed()}}}
@@ -24,7 +24,12 @@ export declare class Lambda {
24
24
  readonly params: readonly string[];
25
25
  readonly body: Node;
26
26
  readonly frame: Frame;
27
- constructor(params: readonly string[], body: Node, frame: Frame);
27
+ /**
28
+ * A function named alone (SUM in GROUPBY(…,SUM)), called with whatever
29
+ * it is given, as many arguments as the function takes.
30
+ */
31
+ readonly named: string | undefined;
32
+ constructor(params: readonly string[], body: Node, frame: Frame, named?: string);
28
33
  }
29
34
  /** A function's argument left empty. */
30
35
  export declare class Missing {
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- export class Reference{sheet;top;left;bottom;right;constructor(t,i,r,e,o){this.sheet=t,this.top=i,this.left=r,this.bottom=e,this.right=o}get rows(){return this.bottom-this.top+1}get cols(){return this.right-this.left+1}get single(){return this.top===this.bottom&&this.left===this.right}get key(){return`${String(this.sheet.index)}!${String(this.top)},${String(this.left)}:${String(this.bottom)},${String(this.right)}`}}export class Union{parts;constructor(t){this.parts=t}}export class Lambda{params;body;frame;constructor(t,i,r){this.params=t,this.body=i,this.frame=r}}export class Missing{missing=!0}export const MISSING=new Missing;
2
+ export class Reference{sheet;top;left;bottom;right;constructor(t,i,r,e,o){this.sheet=t,this.top=i,this.left=r,this.bottom=e,this.right=o}get rows(){return this.bottom-this.top+1}get cols(){return this.right-this.left+1}get single(){return this.top===this.bottom&&this.left===this.right}get key(){return`${String(this.sheet.index)}!${String(this.top)},${String(this.left)}:${String(this.bottom)},${String(this.right)}`}}export class Union{parts;constructor(t){this.parts=t}}export class Lambda{params;body;frame;named;constructor(t,i,r,e){this.params=t,this.body=i,this.frame=r,this.named=e}}export class Missing{missing=!0}export const MISSING=new Missing;
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{chartDrawing as B,isRound as F,isScatter as R}from"@allyhub-next/chart";import{cellName as U,columnLetter as q,contains as I,rangeName as j,readAddress as V,readArea as W}from"./address.js";import{Reference as N,Union as G}from"./calc/types.js";import{shownValue as J}from"./format.js";import{sheetPrefix as D}from"./formula/print.js";import{CellError as K,Matrix as T}from"./values.js";export const SHEET_CHART_DEFAULTS={width:480,height:288,size:9,titleSize:14,ink:"#595959",pixelsToPoints:.75};const Q={dk1:"#000000",lt1:"#FFFFFF",dk2:"#44546A",lt2:"#E7E6E6",accent1:"#4472C4",accent2:"#ED7D31",accent3:"#A5A5A5",accent4:"#FFC000",accent5:"#5B9BD5",accent6:"#70AD47",hlink:"#0563C1",folHlink:"#954F72"},k=e=>typeof e=="string"?Q[e]??"#000000":e.rgb;function z(e,o,n){const{node:t}=n;if(!t)return[];const i=e.eval(t,{sheet:o,row:0,col:0,dr:0,dc:0}),s=u=>{const a=u.sheet,h=e.filtered(a),m=[],x=Math.min(u.bottom,a.lastRow),g=Math.min(u.right,a.columnsUsed-1);for(let c=u.top;c<=x;c++)if(!(h.has(c)||a.spec.rows?.[String(c+1)]?.hidden===!0))for(let l=u.left;l<=g;l++)a.spec.columns?.[q(l)]?.hidden!==!0&&m.push({value:e.value(a,c,l),sheet:a,row:c,col:l});return m};if(i instanceof N)return s(i);if(i instanceof G)return i.parts.flatMap(s);if(i instanceof T)return i.data.map(u=>({value:u}));const r=e.flat(i);return r instanceof T?r.data.map(u=>({value:u})):[{value:r}]}const E=e=>{if(e.value===null)return"";const o=e.sheet&&e.row!==void 0&&e.col!==void 0?e.sheet.lookAt(e.row,e.col).format:void 0;return J(e.value,o)};function H(e){return typeof e=="number"?Number.isFinite(e)?e:null:e===null||e instanceof K?null:typeof e=="boolean"&&e?1:0}const P=e=>e&&{...e.min===void 0?{}:{minimum_scale:e.min},...e.max===void 0?{}:{maximum_scale:e.max},...e.major===void 0?{}:{major_unit:e.major},...e.gridlines===void 0?{}:{has_major_gridlines:e.gridlines},...e.visible===void 0?{}:{visible:e.visible},...e.format===void 0?{}:{number_format:e.format},...e.reverse===void 0?{}:{reverse_order:e.reverse},...e.title===void 0||e.title===""?{}:{title:e.title}},C=e=>e===void 0?void 0:{rgb:e};function X(e){if(e===void 0||e===!1)return;if(e===!0)return{show_value:!0};const o=typeof e.color=="string"?C(e.color):void 0;return{...e.value===void 0?{}:{show_value:e.value},...e.percentage===void 0?{}:{show_percentage:e.percentage},...e.category===void 0?{}:{show_category_name:e.category},...e.series===void 0?{}:{show_series_name:e.series},...e.format===void 0?{}:{number_format:e.format},...e.position===void 0?{}:{position:e.position},...e.size===void 0?{}:{size:e.size},...o?{color:o}:{}}}const Y=e=>{const o=e.find(n=>n.sheet);return o?.sheet&&o.row!==void 0&&o.col!==void 0?o.sheet.lookAt(o.row,o.col).format:void 0};export function chartDef(e,o,n){const{spec:t}=n,i=R(t.type),s=n.categories?z(e,o,n.categories):void 0,r=n.series.map((l,b)=>{const p=t.series[b],v=z(e,o,l.values),$=l.name?z(e,o,l.name)[0]:void 0,A=l.x?z(e,o,l.x):i?s:void 0,w=p.format??Y(v),y=C(p.color);return{name:($?E($):p.name)??`Series${String(b+1)}`,values:v.map(f=>H(f.value)),...A?{x:A.map(f=>H(f.value))}:{},...w===void 0?{}:{number_format:w},...y?{color:y}:{},...p.smooth===void 0?{}:{smooth:p.smooth},...p.line_width===void 0?{}:{line_width:p.line_width},...p.marker_size===void 0?{}:{marker_size:p.marker_size}}}),u=Math.max(0,...r.map(l=>l.values.length)),a=s?s.map(E):Array.from({length:u},(l,b)=>String(b+1)),h=n.title?z(e,o,n.title)[0]:void 0,m=h?E(h):t.title,x=X(t.labels),g=P(t.value_axis),c=P(t.category_axis);return{type:t.type,categories:a,series:r,...m===void 0||m===""?{}:{title:m},...t.legend===void 0?{}:{legend:t.legend},...x?{labels:x}:{},...t.gap_width===void 0?{}:{gap_width:t.gap_width},...t.overlap===void 0?{}:{overlap:t.overlap},...t.vary_by_categories===void 0?{}:{vary_by_categories:t.vary_by_categories},...t.hole_size===void 0?{}:{hole_size:t.hole_size},...g?{value_axis:g}:{},...c?{category_axis:c}:{},font_size:t.size??SHEET_CHART_DEFAULTS.size,title_size:t.title_size??SHEET_CHART_DEFAULTS.titleSize,font_color:C(t.color)??{rgb:SHEET_CHART_DEFAULTS.ink}}}export const chartSize=e=>({width:e.width??SHEET_CHART_DEFAULTS.width,height:e.height??SHEET_CHART_DEFAULTS.height});const Z={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},O=e=>e.replace(/[&<>"]/gu,o=>Z[o]??o),d=e=>String(Number(e.toFixed(3)));function L(e){const o=e.fill===void 0?"none":k(e.fill),n=e.width>0?k(e.color):"none";return`<path d="${O(e.d)}" fill="${o}" stroke="${n}" stroke-width="${d(e.width)}" stroke-linejoin="round"/>`}function ee(e){const o=[];for(const n of[...e.grid,...e.shapes])o.push(L(n));for(const n of[...e.boxes,...e.keys])o.push(`<rect x="${d(n.x)}" y="${d(n.y)}" width="${d(n.width)}" height="${d(n.height)}" fill="${k(n.color)}"/>`);for(const n of[...e.axes,...e.lines])o.push(L(n));for(const n of e.dots)o.push(`<circle cx="${d(n.x)}" cy="${d(n.y)}" r="${d(n.r)}" fill="${k(n.color)}"/>`);for(const n of e.words){const t=n.rotate===void 0?"":` transform="rotate(${d(n.rotate)} ${d(n.x)} ${d(n.y)})"`;o.push(`<text x="${d(n.x)}" y="${d(n.y)}" font-size="${d(n.size)}" text-anchor="${n.anchor}" dominant-baseline="central" fill="${k(n.color)}"${t}>${O(n.text)}</text>`)}return o.join("")}export function chartSvg(e,o,n,t={}){const i=SHEET_CHART_DEFAULTS.pixelsToPoints,s=o*i,r=n*i,u=t.font??"Carlito, Calibri, Arial, sans-serif",a=t.paper??"#FFFFFF",h=t.edge??"#D9D9D9";return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d(s)} ${d(r)}" width="${d(o)}" height="${d(n)}" font-family="${O(u)}"><rect x="0.375" y="0.375" width="${d(s-.75)}" height="${d(r-.75)}" fill="${a}" stroke="${h==="none"?"none":h}" stroke-width="0.75"/>${ee(B(e,s,r))}</svg>`}export function chartAfter(e,o){const n=i=>i?.startsWith("=")===!0?o(i):i,t=n(e.title);return{...e,...t===void 0?{}:{title:t},...e.categories===void 0?{}:{categories:o(e.categories)},series:e.series.map(i=>{const s=n(i.name);return{...i,values:o(i.values),...i.x===void 0?{}:{x:o(i.x)},...s===void 0?{}:{name:s}}})}}function te(e,o,n,t){if(t){const i=t.data;if(n.top===i.top&&n.bottom===i.bottom&&n.left===n.right){const s=t.columns[n.left-t.at.col];if(s)return`${t.name}[${s.name}]`}}return`${o===e?"":D(o.name)}${j(n)}`}const ne=(e,o,n,t)=>typeof e.value(o,n,t)=="number",oe=(e,o,n,t)=>{const i=e.value(o,n,t);if(typeof i=="string")return!0;const s=o.lookAt(n,t).format;return typeof i=="number"&&s!==void 0&&/[ymd]/iu.test(s)};export function chartOfRange(e,o,n,t,i){const s=t.bottom-t.top+1,r=t.right-t.left+1,u=o.tables.find(f=>I(f.area,t.top,t.left)),a=f=>te(n,o,f,u),h=R(i),m=s>1&&Array.from({length:r},(f,_)=>t.left+_).some(f=>!ne(e,o,t.top,f)),x=r>1&&(h||Array.from({length:s-(m?1:0)},(f,_)=>_).every(f=>oe(e,o,t.top+(m?1:0)+f,t.left)||e.value(o,t.top+(m?1:0)+f,t.left)===null)),g=t.top+(m?1:0),c=t.left+(x?1:0);if(g>t.bottom||c>t.right)return;const l=!h&&!F(i)&&t.right-c>t.bottom-g,b=[],p=(f,_)=>e.value(o,f,_)===null?void 0:`=${o===n?"":D(o.name)}${U({row:f,col:_})}`,v=l?{first:g,last:t.bottom}:{first:c,last:t.right};for(let f=v.first;f<=v.last;f++){const _=l?{top:f,left:c,bottom:f,right:t.right}:{top:g,left:f,bottom:t.bottom,right:f},M=l?x?p(f,t.left):void 0:m?p(t.top,f):void 0;b.push({values:a(_),...M===void 0?{}:{name:M}})}const $=l?m?{top:t.top,left:c,bottom:t.top,right:t.right}:void 0:x?{top:g,left:t.left,bottom:t.bottom,right:t.left}:void 0,A=b.length>1&&!F(i),w=F(i)?b.slice(0,1):b,y=w.length===1?w[0]?.name:void 0;return{type:i,...$?{categories:a($)}:{},series:w,...A||F(i)?{legend:"bottom"}:{},...y===void 0?{}:{title:y}}}function S(e,o,n){if(!n?.node)return;const t=e.eval(n.node,{sheet:o,row:0,col:0,dr:0,dc:0});return t instanceof N?{sheet:t.sheet,area:{top:t.top,left:t.left,bottom:Math.min(t.bottom,Math.max(t.top,t.sheet.lastRow)),right:t.right}}:void 0}export function chartDataRange(e,o,n){const t=[S(e,o,n.categories),...n.series.flatMap(r=>[S(e,o,r.values),S(e,o,r.name),S(e,o,r.x)])].filter(r=>r!==void 0),i=t[0];if(!i||t.some(r=>r.sheet!==i.sheet))return;const s={top:Math.min(...t.map(r=>r.area.top)),left:Math.min(...t.map(r=>r.area.left)),bottom:Math.max(...t.map(r=>r.area.bottom)),right:Math.max(...t.map(r=>r.area.right))};return`${i.sheet===o?"":D(i.sheet.name)}${j(s)}`}export function readDataRange(e,o,n){const t=n.lastIndexOf("!"),i=t<0?void 0:n.slice(0,t).replace(/^'|'$/gu,""),s=i===void 0?o:e.wb.sheet(i.replaceAll("''","'")),r=W(n.slice(t+1).replaceAll("$",""));return s&&r?{sheet:s,area:r}:void 0}export function chartPlace(e,o,n){const t=V(e.at)??{row:0,col:0};return{left:n(t.col)+(e.x??0),top:o(t.row)+(e.y??0),...chartSize(e)}}
2
+ import{chartDrawing as B,colorRgb as U,isRound as F,isScatter as R}from"@allyhub-next/chart";import{cellName as q,columnLetter as I,contains as V,rangeName as j,readAddress as W,readArea as G}from"./address.js";import{Reference as N,Union as J}from"./calc/types.js";import{shownValue as K}from"./format.js";import{sheetPrefix as D}from"./formula/print.js";import{CellError as Q,Matrix as T}from"./values.js";export const SHEET_CHART_DEFAULTS={width:480,height:288,size:9,titleSize:14,ink:"#595959",pixelsToPoints:.75};const X={dk1:"#000000",lt1:"#FFFFFF",dk2:"#44546A",lt2:"#E7E6E6",accent1:"#4472C4",accent2:"#ED7D31",accent3:"#A5A5A5",accent4:"#FFC000",accent5:"#5B9BD5",accent6:"#70AD47",hlink:"#0563C1",folHlink:"#954F72"},k=e=>U(e,X);function z(e,o,n){const{node:t}=n;if(!t)return[];const i=e.eval(t,{sheet:o,row:0,col:0,dr:0,dc:0}),s=u=>{const a=u.sheet,p=e.filtered(a),m=[],x=Math.min(u.bottom,a.lastRow),g=Math.min(u.right,a.columnsUsed-1);for(let c=u.top;c<=x;c++)if(!(p.has(c)||a.spec.rows?.[String(c+1)]?.hidden===!0))for(let d=u.left;d<=g;d++)a.spec.columns?.[I(d)]?.hidden!==!0&&m.push({value:e.value(a,c,d),sheet:a,row:c,col:d});return m};if(i instanceof N)return s(i);if(i instanceof J)return i.parts.flatMap(s);if(i instanceof T)return i.data.map(u=>({value:u}));const r=e.flat(i);return r instanceof T?r.data.map(u=>({value:u})):[{value:r}]}const E=e=>{if(e.value===null)return"";const o=e.sheet&&e.row!==void 0&&e.col!==void 0?e.sheet.lookAt(e.row,e.col).format:void 0;return K(e.value,o)};function H(e){return typeof e=="number"?Number.isFinite(e)?e:null:e===null||e instanceof Q?null:typeof e=="boolean"&&e?1:0}const P=e=>e&&{...e.min===void 0?{}:{minimum_scale:e.min},...e.max===void 0?{}:{maximum_scale:e.max},...e.major===void 0?{}:{major_unit:e.major},...e.gridlines===void 0?{}:{has_major_gridlines:e.gridlines},...e.visible===void 0?{}:{visible:e.visible},...e.format===void 0?{}:{number_format:e.format},...e.reverse===void 0?{}:{reverse_order:e.reverse},...e.title===void 0||e.title===""?{}:{title:e.title}},C=e=>e===void 0?void 0:{rgb:e};function Y(e){if(e===void 0||e===!1)return;if(e===!0)return{show_value:!0};const o=typeof e.color=="string"?C(e.color):void 0;return{...e.value===void 0?{}:{show_value:e.value},...e.percentage===void 0?{}:{show_percentage:e.percentage},...e.category===void 0?{}:{show_category_name:e.category},...e.series===void 0?{}:{show_series_name:e.series},...e.format===void 0?{}:{number_format:e.format},...e.position===void 0?{}:{position:e.position},...e.size===void 0?{}:{size:e.size},...o?{color:o}:{}}}const Z=e=>{const o=e.find(n=>n.sheet);return o?.sheet&&o.row!==void 0&&o.col!==void 0?o.sheet.lookAt(o.row,o.col).format:void 0};export function chartDef(e,o,n){const{spec:t}=n,i=R(t.type),s=n.categories?z(e,o,n.categories):void 0,r=n.series.map((d,b)=>{const h=t.series[b],v=z(e,o,d.values),$=d.name?z(e,o,d.name)[0]:void 0,A=d.x?z(e,o,d.x):i?s:void 0,w=h.format??Z(v),y=C(h.color);return{name:($?E($):h.name)??`Series${String(b+1)}`,values:v.map(f=>H(f.value)),...A?{x:A.map(f=>H(f.value))}:{},...w===void 0?{}:{number_format:w},...y?{color:y}:{},...h.smooth===void 0?{}:{smooth:h.smooth},...h.line_width===void 0?{}:{line_width:h.line_width},...h.marker_size===void 0?{}:{marker_size:h.marker_size}}}),u=Math.max(0,...r.map(d=>d.values.length)),a=s?s.map(E):Array.from({length:u},(d,b)=>String(b+1)),p=n.title?z(e,o,n.title)[0]:void 0,m=p?E(p):t.title,x=Y(t.labels),g=P(t.value_axis),c=P(t.category_axis);return{type:t.type,categories:a,series:r,...m===void 0||m===""?{}:{title:m},...t.legend===void 0?{}:{legend:t.legend},...x?{labels:x}:{},...t.gap_width===void 0?{}:{gap_width:t.gap_width},...t.overlap===void 0?{}:{overlap:t.overlap},...t.vary_by_categories===void 0?{}:{vary_by_categories:t.vary_by_categories},...t.hole_size===void 0?{}:{hole_size:t.hole_size},...g?{value_axis:g}:{},...c?{category_axis:c}:{},font_size:t.size??SHEET_CHART_DEFAULTS.size,title_size:t.title_size??SHEET_CHART_DEFAULTS.titleSize,font_color:C(t.color)??{rgb:SHEET_CHART_DEFAULTS.ink}}}export const chartSize=e=>({width:e.width??SHEET_CHART_DEFAULTS.width,height:e.height??SHEET_CHART_DEFAULTS.height});const ee={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},O=e=>e.replace(/[&<>"]/gu,o=>ee[o]??o),l=e=>String(Number(e.toFixed(3)));function L(e){const o=e.fill===void 0?"none":k(e.fill),n=e.width>0?k(e.color):"none";return`<path d="${O(e.d)}" fill="${o}" stroke="${n}" stroke-width="${l(e.width)}" stroke-linejoin="round"/>`}function te(e){const o=[];for(const n of[...e.grid,...e.shapes])o.push(L(n));for(const n of[...e.boxes,...e.keys])o.push(`<rect x="${l(n.x)}" y="${l(n.y)}" width="${l(n.width)}" height="${l(n.height)}" fill="${k(n.color)}"/>`);for(const n of[...e.axes,...e.lines])o.push(L(n));for(const n of e.dots)o.push(`<circle cx="${l(n.x)}" cy="${l(n.y)}" r="${l(n.r)}" fill="${k(n.color)}"/>`);for(const n of e.words){const t=n.rotate===void 0?"":` transform="rotate(${l(n.rotate)} ${l(n.x)} ${l(n.y)})"`;o.push(`<text x="${l(n.x)}" y="${l(n.y)}" font-size="${l(n.size)}" text-anchor="${n.anchor}" dominant-baseline="central" fill="${k(n.color)}"${t}>${O(n.text)}</text>`)}return o.join("")}export function chartSvg(e,o,n,t={}){const i=SHEET_CHART_DEFAULTS.pixelsToPoints,s=o*i,r=n*i,u=t.font??"Carlito, Calibri, Arial, sans-serif",a=t.paper??"#FFFFFF",p=t.edge??"#D9D9D9";return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${l(s)} ${l(r)}" width="${l(o)}" height="${l(n)}" font-family="${O(u)}"><rect x="0.375" y="0.375" width="${l(s-.75)}" height="${l(r-.75)}" fill="${a}" stroke="${p==="none"?"none":p}" stroke-width="0.75"/>${te(B(e,s,r))}</svg>`}export function chartAfter(e,o){const n=i=>i?.startsWith("=")===!0?o(i):i,t=n(e.title);return{...e,...t===void 0?{}:{title:t},...e.categories===void 0?{}:{categories:o(e.categories)},series:e.series.map(i=>{const s=n(i.name);return{...i,values:o(i.values),...i.x===void 0?{}:{x:o(i.x)},...s===void 0?{}:{name:s}}})}}function ne(e,o,n,t){if(t){const i=t.data;if(n.top===i.top&&n.bottom===i.bottom&&n.left===n.right){const s=t.columns[n.left-t.at.col];if(s)return`${t.name}[${s.name}]`}}return`${o===e?"":D(o.name)}${j(n)}`}const oe=(e,o,n,t)=>typeof e.value(o,n,t)=="number",ie=(e,o,n,t)=>{const i=e.value(o,n,t);if(typeof i=="string")return!0;const s=o.lookAt(n,t).format;return typeof i=="number"&&s!==void 0&&/[ymd]/iu.test(s)};export function chartOfRange(e,o,n,t,i){const s=t.bottom-t.top+1,r=t.right-t.left+1,u=o.tables.find(f=>V(f.area,t.top,t.left)),a=f=>ne(n,o,f,u),p=R(i),m=s>1&&Array.from({length:r},(f,_)=>t.left+_).some(f=>!oe(e,o,t.top,f)),x=r>1&&(p||Array.from({length:s-(m?1:0)},(f,_)=>_).every(f=>ie(e,o,t.top+(m?1:0)+f,t.left)||e.value(o,t.top+(m?1:0)+f,t.left)===null)),g=t.top+(m?1:0),c=t.left+(x?1:0);if(g>t.bottom||c>t.right)return;const d=!p&&!F(i)&&t.right-c>t.bottom-g,b=[],h=(f,_)=>e.value(o,f,_)===null?void 0:`=${o===n?"":D(o.name)}${q({row:f,col:_})}`,v=d?{first:g,last:t.bottom}:{first:c,last:t.right};for(let f=v.first;f<=v.last;f++){const _=d?{top:f,left:c,bottom:f,right:t.right}:{top:g,left:f,bottom:t.bottom,right:f},M=d?x?h(f,t.left):void 0:m?h(t.top,f):void 0;b.push({values:a(_),...M===void 0?{}:{name:M}})}const $=d?m?{top:t.top,left:c,bottom:t.top,right:t.right}:void 0:x?{top:g,left:t.left,bottom:t.bottom,right:t.left}:void 0,A=b.length>1&&!F(i),w=F(i)?b.slice(0,1):b,y=w.length===1?w[0]?.name:void 0;return{type:i,...$?{categories:a($)}:{},series:w,...A||F(i)?{legend:"bottom"}:{},...y===void 0?{}:{title:y}}}function S(e,o,n){if(!n?.node)return;const t=e.eval(n.node,{sheet:o,row:0,col:0,dr:0,dc:0});return t instanceof N?{sheet:t.sheet,area:{top:t.top,left:t.left,bottom:Math.min(t.bottom,Math.max(t.top,t.sheet.lastRow)),right:t.right}}:void 0}export function chartDataRange(e,o,n){const t=[S(e,o,n.categories),...n.series.flatMap(r=>[S(e,o,r.values),S(e,o,r.name),S(e,o,r.x)])].filter(r=>r!==void 0),i=t[0];if(!i||t.some(r=>r.sheet!==i.sheet))return;const s={top:Math.min(...t.map(r=>r.area.top)),left:Math.min(...t.map(r=>r.area.left)),bottom:Math.max(...t.map(r=>r.area.bottom)),right:Math.max(...t.map(r=>r.area.right))};return`${i.sheet===o?"":D(i.sheet.name)}${j(s)}`}export function readDataRange(e,o,n){const t=n.lastIndexOf("!"),i=t<0?void 0:n.slice(0,t).replace(/^'|'$/gu,""),s=i===void 0?o:e.wb.sheet(i.replaceAll("''","'")),r=G(n.slice(t+1).replaceAll("$",""));return s&&r?{sheet:s,area:r}:void 0}export function chartPlace(e,o,n){const t=W(e.at)??{row:0,col:0};return{left:n(t.col)+(e.x??0),top:o(t.row)+(e.y??0),...chartSize(e)}}
@@ -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 d,rangeName as b}from"./address.js";import{ERR as p,Matrix as w,CellError as m}from"./values.js";import{analyse as $}from"./calc/analyse.js";import{Calc as k}from"./calc/engine.js";import{toBool as g}from"./calc/coerce.js";import{ENTRY as l}from"./file.js";import{fileCells as x}from"./files.js";import{applyScenario as y}from"./scenario.js";import{readWorkbook as S}from"./workbook.js";class O{problems;wb;lineOf;constructor(t,e){this.wb=t,this.problems=[...e.problems],this.lineOf=e.lineOf}at(t,e){const o=t.line??(t.path===void 0?void 0:this.lineOf(t.path));this.problems.push({file:t.file===""?l:t.file,...o===void 0?{}:{line:o},message:e})}formulas(){const t=new Map;for(const e of this.wb.sheets){for(const o of e.formulas)t.set(o.shared,e);for(const o of e.tables)for(const n of o.columns)n.formula&&t.set(n.formula,e);for(const o of e.conditions)for(const n of o.formulas)t.set(n,e);for(const o of e.validations)for(const n of o.formulas)n&&t.set(n,e);for(const o of e.charts){o.title&&t.set(o.title,e),o.categories&&t.set(o.categories,e);for(const n of o.series)t.set(n.values,e),n.x&&t.set(n.x,e),n.name&&t.set(n.name,e)}}for(const e of this.wb.names.values())e.formula&&t.set(e.formula,void 0);for(const e of this.wb.checks)t.set(e.formula,void 0);return t}formulaProblems(){for(const[t,e]of this.formulas()){const o=s=>{this.at(t.source,`${t.text}: ${s}`)};if(t.error){o(`does not parse: ${t.error.message}`);continue}const n=$(this.wb,t);t.analysis=n;for(const s of new Set(n.unknownNames))o(`there is no name ${s}`);for(const s of new Set(n.unknownFunctions))o(`there is no function ${s}`);for(const s of n.arguments)o(`${s.name} takes ${s.min===s.max?String(s.min):`${String(s.min)} to ${String(s.max)}`} arguments and is given ${String(s.given)}`);for(const s of n.reads){if(s.kind==="ref"){for(const r of[s.sheet,s.lastSheet])r!==void 0&&!this.wb.sheet(r)&&o(`there is no sheet ${r}`);continue}const f=s.table===void 0?e?.tableAt(t.row,t.col):this.wb.table(s.table);if(!f){o(s.table===void 0?"a column named with no table, outside a table":`there is no table ${s.table}`);continue}for(const r of s.columns)f.column(r)||o(`table ${f.name} has no column ${r}; it has ${f.columns.map(c=>c.name).join(", ")}`)}}}cycles(t){for(const e of t.cycles){const o=e.reduce((r,c,h)=>{const a=e[r];return a&&(c.row<a.row||c.row===a.row&&c.col<a.col)?h:r},0),n=[...e.slice(o),...e.slice(0,o)],s=n[0];if(!s)continue;const f=[...n,s].map(r=>`${r.sheet.name}!${d(r)}`).join(" → ");this.at(s.shared.source,`a circular reference: ${f}`)}}scenarios(){const{scenarios:t}=this.wb.file;for(const[e,o]of Object.entries(t??{}))for(const n of Object.keys(o))this.wb.name(n)||this.at({file:l,path:["scenarios",e,n]},`scenario ${e} sets ${n}, and there is no name ${n}`)}files(t,e){for(const o of this.wb.sheets)for(const{row:n,col:s,paths:f}of x(o,t))for(const r of f)e(r)||this.at(this.wb.sourceOf(o,n,s)??{file:l},`${placeName(o,n,s)} names ${r}, which is not there`)}checks(t){const e=this.wb.sheets[0];if(e)for(const o of this.wb.checks){if(!o.formula.node)continue;const n=t.evaluate(o.formula,e),s=u(n);s!==void 0&&this.at(o.source,`check "${o.name}" does not hold: ${o.formula.text} is ${s}`)}}}function u(i){if(i instanceof w){for(const e of i.data){const o=u(e);if(o!==void 0)return o}return}if(i instanceof m)return i.code;const t=g(i);return t instanceof m?p.VALUE.code:t?void 0:"FALSE"}export function checkWorkbook(i,t={}){const e=S(i),{workbook:o}=e;if(!o)return{problems:e.problems};const n=new O(o,e);n.scenarios(),t.scenario!==void 0&&y(o,t.scenario);const s=new k(o,t);return n.formulaProblems(),s.calculate(),n.cycles(s),n.checks(s),i.exists&&n.files(s,i.exists),{workbook:o,calc:s,problems:n.problems}}export const placeName=(i,t,e)=>`${i.name}!${b({top:t,left:e,bottom:t,right:e})}`;
2
+ import{cellName as d,rangeName as b}from"./address.js";import{ERR as p,Matrix as $,CellError as m}from"./values.js";import{analyse as w}from"./calc/analyse.js";import{Calc as g}from"./calc/engine.js";import{toBool as k}from"./calc/coerce.js";import{ENTRY as l}from"./file.js";import{fileCells as S}from"./files.js";import{applyScenario as x}from"./scenario.js";import{readWorkbook as v}from"./workbook.js";class y{problems;wb;lineOf;constructor(t,o){this.wb=t,this.problems=[...o.problems],this.lineOf=o.lineOf}at(t,o){const e=t.line??(t.path===void 0?void 0:this.lineOf(t.path));this.problems.push({file:t.file===""?l:t.file,...e===void 0?{}:{line:e},message:o})}formulas(){const t=new Map;for(const o of this.wb.sheets){for(const e of o.formulas)t.set(e.shared,o);for(const e of o.names.values())e.formula&&t.set(e.formula,o);for(const e of o.tables)for(const s of e.columns)s.formula&&t.set(s.formula,o);for(const e of o.conditions)for(const s of e.formulas)t.set(s,o);for(const e of o.validations)for(const s of e.formulas)s&&t.set(s,o);for(const e of o.charts){e.title&&t.set(e.title,o),e.categories&&t.set(e.categories,o);for(const s of e.series)t.set(s.values,o),s.x&&t.set(s.x,o),s.name&&t.set(s.name,o)}}for(const o of this.wb.names.values())o.formula&&t.set(o.formula,void 0);for(const o of this.wb.checks)t.set(o.formula,void 0);return t}formulaProblems(){for(const[t,o]of this.formulas()){const e=n=>{this.at(t.source,`${t.text}: ${n}`)};if(t.error){e(`does not parse: ${t.error.message}`);continue}const s=w(this.wb,t,o);t.analysis=s;for(const n of new Set(s.unknownNames))e(`there is no name ${n}`);for(const n of new Set(s.unknownFunctions))e(`there is no function ${n}`);for(const n of s.arguments)e(n.group===void 0?`${n.name} takes ${n.min===n.max?String(n.min):`${String(n.min)} to ${String(n.max)}`} arguments and is given ${String(n.given)}`:`${n.name} takes its last arguments in groups of ${String(n.group)} and is given ${String(n.given)}, which leaves one short`);for(const n of s.reads){if(n.kind==="ref"){for(const r of[n.sheet,n.lastSheet])r!==void 0&&!this.wb.sheet(r)&&e(`there is no sheet ${r}`);continue}const f=n.table===void 0?o?.tableAt(t.row,t.col):this.wb.table(n.table);if(!f){e(n.table===void 0?"a column named with no table, outside a table":`there is no table ${n.table}`);continue}for(const r of n.columns)f.column(r)||e(`table ${f.name} has no column ${r}; it has ${f.columns.map(a=>a.name).join(", ")}`)}}}cycles(t){for(const o of t.cycles){const e=o.reduce((r,a,h)=>{const c=o[r];return c&&(a.row<c.row||a.row===c.row&&a.col<c.col)?h:r},0),s=[...o.slice(e),...o.slice(0,e)],n=s[0];if(!n)continue;const f=[...s,n].map(r=>`${r.sheet.name}!${d(r)}`).join(" → ");this.at(n.shared.source,`a circular reference: ${f}`)}}scenarios(){const{scenarios:t}=this.wb.file;for(const[o,e]of Object.entries(t??{}))for(const s of Object.keys(e))this.wb.name(s)||this.at({file:l,path:["scenarios",o,s]},`scenario ${o} sets ${s}, and there is no name ${s}`)}files(t,o){for(const e of this.wb.sheets)for(const{row:s,col:n,paths:f}of S(e,t))for(const r of f)o(r)||this.at(this.wb.sourceOf(e,s,n)??{file:l},`${placeName(e,s,n)} names ${r}, which is not there`);for(const e of this.wb.sheets)for(const s of e.spec.pictures??[])o(s.file)||this.at({file:l},`${e.name} has a picture ${s.file}, which is not there`)}checks(t){const o=this.wb.sheets[0];if(o)for(const e of this.wb.checks){if(!e.formula.node)continue;const s=t.evaluate(e.formula,o),n=u(s);n!==void 0&&this.at(e.source,`check "${e.name}" does not hold: ${e.formula.text} is ${n}`)}}}function u(i){if(i instanceof $){for(const o of i.data){const e=u(o);if(e!==void 0)return e}return}if(i instanceof m)return i.code;const t=k(i);return t instanceof m?p.VALUE.code:t?void 0:"FALSE"}export function checkWorkbook(i,t={}){const o=v(i),{workbook:e}=o;if(!e)return{problems:o.problems};const s=new y(e,o);s.scenarios(),t.scenario!==void 0&&x(e,t.scenario);const n=new g(e,t);return s.formulaProblems(),n.calculate(),s.cycles(n),s.checks(n),i.exists&&s.files(n,i.exists),{workbook:e,calc:n,problems:s.problems}}export const placeName=(i,t,o)=>`${i.name}!${b({top:t,left:o,bottom:t,right:o})}`;
@@ -39,14 +39,29 @@ export interface TableDiff {
39
39
  columnsAdded: string[];
40
40
  columnsRemoved: string[];
41
41
  }
42
+ /** What changed outside the cells: how a sheet prints, its notes, links, rules, pictures, sizes. */
43
+ export interface PartChange {
44
+ /** The sheet it is of; absent: the workbook's. */
45
+ sheet?: string;
46
+ /** Which part: `print`, `notes`, `links`, `validations`, `conditional`, `pictures`, `protect`, `freeze`, `merges`, `filter`, `columns`, `rows`, `view`, `title`, `hidden names`. */
47
+ part: string;
48
+ /** Which of it: a note's or a link's cell, a column's letter, a row's number. */
49
+ key?: string;
50
+ /** What it was and is, as JSON (a note's or a link's text as it is); absent: none. */
51
+ was?: string;
52
+ now?: string;
53
+ }
42
54
  export interface WorkbookDiff {
43
55
  sheets: SheetDiff[];
44
56
  tables: TableDiff[];
57
+ /** The workbook's names, and each sheet's own as `Sheet!name`. */
45
58
  names: {
46
59
  name: string;
47
60
  was?: string;
48
61
  now?: string;
49
62
  }[];
63
+ /** What changed outside the cells. */
64
+ parts: PartChange[];
50
65
  /** Sheets whose charts differ. */
51
66
  charts: string[];
52
67
  cells: CellChange[];
@@ -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{dataValue as D,shownValue as b}from"./format.js";import{CellError as y}from"./values.js";import{FormulaCell as M}from"./workbook.js";export const DIFF_DEFAULTS={tolerance:0};const J=(a,e)=>{if(a!=="written")return e};function U(a){const{row:e,col:t}=a;return JSON.stringify(a.moved,(s,c)=>(s==="col"||s==="col2"||s==="row"||s==="row2")&&typeof c=="object"&&c!==null&&c.abs===!1?[c.index-(s.startsWith("col")?t:e)]:J(s,c))}function j(a,e,t){if(a===e)return!0;if(typeof a=="number"&&typeof e=="number"){const s=Math.max(Math.abs(a),Math.abs(e));return Math.abs(a-e)<=t*s}return a instanceof y&&e instanceof y?a.code===e.code:!1}function A(a,e,t,s){const c=a.value(e,t,s),r=e.lookAt(t,s).format,o=e.at(t,s);return{cell:N({row:t,col:s}),value:D(c,r),shown:b(c,r),...o instanceof M?{formula:o.text}:{}}}const S=(a,e,t)=>{const s=a.at(e,t);return s instanceof M&&s.shared.node?U(s):void 0},O=(a,e,t)=>a.at(e,t)!==void 0||a.spillAt(e,t)!==void 0;class C{out={sheets:[],tables:[],names:[],charts:[],cells:[],counts:{value:0,formula:0,both:0,added:0,removed:0}};a;b;tolerance;constructor(e,t,s){this.a=e,this.b=t,this.tolerance=s}push(e){this.out.counts[e.kind]+=1,this.out.cells.push(e)}cell(e,t,s){const c=this.a.value(e.sheet,e.row,e.col),r=this.b.value(t.sheet,t.row,t.col),o=O(e.sheet,e.row,e.col),i=O(t.sheet,t.row,t.col);if(!o&&!i)return;const u=t.sheet.name,l=()=>({was:A(this.a,e.sheet,e.row,e.col),now:A(this.b,t.sheet,t.row,t.col)});if(!o){this.push({...s,sheet:u,kind:"added",now:l().now});return}if(!i){this.push({...s,sheet:u,kind:"removed",was:l().was});return}const h=j(c,r,this.tolerance),w=S(e.sheet,e.row,e.col)===S(t.sheet,t.row,t.col);if(h&&w)return;const v=w?"value":h?"formula":"both";this.push({...s,sheet:u,kind:v,...l()})}loose(e,t){const s=(o,i,u)=>o.tableAt(i,u)!==void 0,c=Math.max(e.lastRow,t.lastRow),r=Math.max(e.columnsUsed,t.columnsUsed)-1;for(let o=0;o<=r;o++){const[i,u]=E(e,t,o,c);for(let l=i;l<=u;l++)s(e,l,o)||s(t,l,o)||this.cell({sheet:e,row:l,col:o},{sheet:t,row:l,col:o},{})}}table(e,t){const s=t.spec.key??e.spec.key,c=e.column(s??""),r=t.column(s??""),o=(n,f,p)=>{const d=new Map;if(p){for(let m=0;m<n.rows;m++){const F=f.value(n.sheet,n.at.row+1+m,n.at.col+p.index),x=b(F);if(x===""||d.has(x))return;d.set(x,m)}return d}},i=o(e,this.a,c),u=o(t,this.b,r),l=i&&u?{from:i,to:u}:void 0,h=[];if(l){for(const[n,f]of l.from)h.push([f,l.to.get(n),n]);for(const[n,f]of l.to)l.from.has(n)||h.push([void 0,f,n])}else for(let n=0;n<Math.max(e.rows,t.rows);n++)h.push([n<e.rows?n:void 0,n<t.rows?n:void 0,String(n+1)]);const w=[],v=[],R=t.columns.filter(n=>e.column(n.name));for(const[n,f,p]of h)if(n===void 0)w.push(p);else if(f===void 0)v.push(p);else for(const d of R){const m=e.column(d.name);m&&this.cell({sheet:e.sheet,row:e.at.row+1+n,col:e.at.col+m.index},{sheet:t.sheet,row:t.at.row+1+f,col:t.at.col+d.index},{table:t.name,column:d.name,...l?{key:p}:{}})}const k=t.columns.filter(n=>!e.column(n.name)).map(n=>n.name),g=e.columns.filter(n=>!t.column(n.name)).map(n=>n.name);(w.length+v.length+k.length+g.length>0||l)&&this.out.tables.push({sheet:t.sheet.name,name:t.name,by:l?"key":"position",...l&&s!==void 0?{key:s}:{},rowsAdded:w,rowsRemoved:v,columnsAdded:k,columnsRemoved:g})}names(e,t){const s=(r,o)=>{const i=r.name(o);if(i)return i.formula?.text??b(i.value??null)},c=new Set([...e.names.values(),...t.names.values()].map(r=>r.name));for(const r of[...c].sort()){const o=s(e,r),i=s(t,r);o!==i&&this.out.names.push({name:r,...o===void 0?{}:{was:o},...i===void 0?{}:{now:i}})}}run(){const{wb:e}=this.a,{wb:t}=this.b;this.names(e,t);for(const s of e.sheets)t.sheet(s.name)||this.out.sheets.push({name:s.name,added:!1,removed:!0});for(const s of t.sheets){const c=e.sheet(s.name);if(!c){this.out.sheets.push({name:s.name,added:!0,removed:!1});continue}this.loose(c,s);for(const r of s.tables){const o=e.table(r.name);o?this.table(o,r):this.out.tables.push({sheet:s.name,name:r.name,by:"position",rowsAdded:[String(r.rows)],rowsRemoved:[],columnsAdded:r.columns.map(i=>i.name),columnsRemoved:[]})}JSON.stringify(c.spec.charts??[])!==JSON.stringify(s.spec.charts??[])&&this.out.charts.push(s.name)}return this.out}}function E(a,e,t,s){const[c,r]=a.span(t,0,s),[o,i]=e.span(t,0,s);return[Math.min(c,o),Math.max(r,i)]}export function diffWorkbooks(a,e,t={}){return new C(a,e,t.tolerance??DIFF_DEFAULTS.tolerance).run()}
2
+ import{SHEET_MARGINS as F,SHEET_NOTE_AUTHOR as H}from"@allyhub-next/formats";import{cellName as U,readAddress as A}from"./address.js";import{dataValue as _}from"./export.js";import{shownValue as j}from"./format.js";import{sheetPrefix as S}from"./formula/print.js";import{CellError as M}from"./values.js";import{FormulaCell as N}from"./workbook.js";export const DIFF_DEFAULTS={tolerance:0};const I=(o,e)=>{if(o!=="written")return e};function J(o){const{row:e,col:n}=o;return JSON.stringify(o.moved,(t,s)=>(t==="col"||t==="col2"||t==="row"||t==="row2")&&typeof s=="object"&&s!==null&&s.abs===!1?[s.index-(t.startsWith("col")?n:e)]:I(t,s))}function P(o,e,n){if(o===e)return!0;if(typeof o=="number"&&typeof e=="number"){const t=Math.max(Math.abs(o),Math.abs(e));return Math.abs(o-e)<=n*t}return o instanceof M&&e instanceof M?o.code===e.code:!1}function E(o,e,n,t){const s=o.value(e,n,t),i=e.lookAt(n,t).format,r=e.at(n,t);return{cell:U({row:n,col:t}),value:_(s,i),shown:j(s,i),...r instanceof N?{formula:r.text}:{}}}const R=(o,e,n)=>{const t=o.at(e,n);return t instanceof N&&t.shared.node?J(t):void 0},T=(o,e,n)=>o.at(e,n)!==void 0||o.spillAt(e,n)!==void 0;class D{out={sheets:[],tables:[],names:[],parts:[],charts:[],cells:[],counts:{value:0,formula:0,both:0,added:0,removed:0}};a;b;tolerance;constructor(e,n,t){this.a=e,this.b=n,this.tolerance=t}push(e){this.out.counts[e.kind]+=1,this.out.cells.push(e)}cell(e,n,t){const s=this.a.value(e.sheet,e.row,e.col),i=this.b.value(n.sheet,n.row,n.col),r=T(e.sheet,e.row,e.col),d=T(n.sheet,n.row,n.col);if(!r&&!d)return;const u=n.sheet.name,c=()=>({was:E(this.a,e.sheet,e.row,e.col),now:E(this.b,n.sheet,n.row,n.col)});if(!r){this.push({...t,sheet:u,kind:"added",now:c().now});return}if(!d){this.push({...t,sheet:u,kind:"removed",was:c().was});return}const f=P(s,i,this.tolerance),l=R(e.sheet,e.row,e.col)===R(n.sheet,n.row,n.col);if(f&&l)return;const h=l?"value":f?"formula":"both";this.push({...t,sheet:u,kind:h,...c()})}loose(e,n){const t=(r,d,u)=>r.tableAt(d,u)!==void 0,s=Math.max(e.lastRow,n.lastRow),i=Math.max(e.columnsUsed,n.columnsUsed)-1;for(let r=0;r<=i;r++){const[d,u]=W(e,n,r,s);for(let c=d;c<=u;c++)t(e,c,r)||t(n,c,r)||this.cell({sheet:e,row:c,col:r},{sheet:n,row:c,col:r},{})}}table(e,n){const t=n.spec.key??e.spec.key,s=e.column(t??""),i=n.column(t??""),r=(a,m,g)=>{const w=new Map;if(g){for(let p=0;p<a.rows;p++){const C=m.value(a.sheet,a.at.row+1+p,a.at.col+g.index),v=j(C);if(v===""||w.has(v))return;w.set(v,p)}return w}},d=r(e,this.a,s),u=r(n,this.b,i),c=d&&u?{from:d,to:u}:void 0,f=[];if(c){for(const[a,m]of c.from)f.push([m,c.to.get(a),a]);for(const[a,m]of c.to)c.from.has(a)||f.push([void 0,m,a])}else for(let a=0;a<Math.max(e.rows,n.rows);a++)f.push([a<e.rows?a:void 0,a<n.rows?a:void 0,String(a+1)]);const l=[],h=[],y=n.columns.filter(a=>e.column(a.name));for(const[a,m,g]of f)if(a===void 0)l.push(g);else if(m===void 0)h.push(g);else for(const w of y){const p=e.column(w.name);p&&this.cell({sheet:e.sheet,row:e.at.row+1+a,col:e.at.col+p.index},{sheet:n.sheet,row:n.at.row+1+m,col:n.at.col+w.index},{table:n.name,column:w.name,...c?{key:g}:{}})}const k=n.columns.filter(a=>!e.column(a.name)).map(a=>a.name),x=e.columns.filter(a=>!n.column(a.name)).map(a=>a.name);(l.length+h.length+k.length+x.length>0||c)&&this.out.tables.push({sheet:n.sheet.name,name:n.name,by:c?"key":"position",...c&&t!==void 0?{key:t}:{},rowsAdded:l,rowsRemoved:h,columnsAdded:k,columnsRemoved:x})}names(e,n){const t=u=>{const c=new Map;for(const f of u.names.values())c.set(f.name.toLowerCase(),f);for(const f of u.sheets)for(const l of f.names.values())c.set(`${S(f.name)}${l.name}`.toLowerCase(),l);return c},s=u=>u&&(u.formula?.text??j(u.value??null)),i=t(e),r=t(n),d=new Map;for(const[u,c]of[...i,...r])d.set(u,c.sheet?`${S(c.sheet.name)}${c.name}`:c.name);for(const u of[...d.keys()].sort()){const c=s(i.get(u)),f=s(r.get(u));c!==f&&this.out.names.push({name:d.get(u)??u,...c===void 0?{}:{was:c},...f===void 0?{}:{now:f}});const l=k=>k===void 0?void 0:k.hidden===!0,h=l(i.get(u)),y=l(r.get(u));h!==void 0&&y!==void 0&&h!==y&&this.out.parts.push({part:"hidden names",key:d.get(u)??u,was:String(h),now:String(y)})}}part(e){this.out.parts.push(e)}whole(e,n,t,s){const i=b(t),r=b(s);i!==r&&this.part({...e===void 0?{}:{sheet:e},part:n,...i===void 0?{}:{was:i},...r===void 0?{}:{now:r}})}keyed(e,n,t,s,i=b){const r=new Set([...Object.keys(t??{}),...Object.keys(s??{})]);for(const d of[...r].sort(L)){const u=i(t?.[d]),c=i(s?.[d]);u!==c&&this.part({sheet:e,part:n,key:d,...u===void 0?{}:{was:u},...c===void 0?{}:{now:c}})}}listed(e,n,t,s,i=!0){const r=d=>d===void 0||d.length===0?void 0:i?d:d.map(u=>b(u)??"").sort();this.whole(e,n,r(t),r(s))}sheetParts(e,n){const t=e.spec,s=n.spec,i=n.name;this.whole(i,"print",$(t.print),$(s.print)),this.keyed(i,"notes",t.notes,s.notes,V),this.keyed(i,"links",t.links,s.links,r=>typeof r=="string"?r:void 0),this.listed(i,"validations",t.validations,s.validations,!1),this.listed(i,"conditional",t.conditional,s.conditional),this.listed(i,"pictures",t.pictures,s.pictures),this.whole(i,"protect",t.protect===!0||void 0,s.protect===!0||void 0),this.whole(i,"freeze",t.freeze,s.freeze),this.listed(i,"merges",t.merges,s.merges,!1),this.whole(i,"filter",t.filter,s.filter),this.keyed(i,"columns",O(t.columns),O(s.columns)),this.keyed(i,"rows",O(t.rows),O(s.rows)),this.whole(i,"view",z(t),z(s))}run(){const{wb:e}=this.a,{wb:n}=this.b;this.names(e,n),this.whole(void 0,"title",e.title,n.title);for(const t of e.sheets)n.sheet(t.name)||this.out.sheets.push({name:t.name,added:!1,removed:!0});for(const t of n.sheets){const s=e.sheet(t.name);if(!s){this.out.sheets.push({name:t.name,added:!0,removed:!1});continue}this.loose(s,t),this.sheetParts(s,t);for(const i of t.tables){const r=e.table(i.name);r?this.table(r,i):this.out.tables.push({sheet:t.name,name:i.name,by:"position",rowsAdded:[String(i.rows)],rowsRemoved:[],columnsAdded:i.columns.map(d=>d.name),columnsRemoved:[]})}JSON.stringify(s.spec.charts??[])!==JSON.stringify(t.spec.charts??[])&&this.out.charts.push(t.name)}return this.out}}function b(o){if(o!==void 0)return JSON.stringify(o,(e,n)=>n!==null&&typeof n=="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n).sort(([t],[s])=>t<s?-1:t>s?1:0)):n)}function L(o,e){const n=A(o),t=A(e);if(n&&t)return n.row-t.row||n.col-t.col;const s=Number(o),i=Number(e);return Number.isInteger(s)&&Number.isInteger(i)?s-i:o.length-e.length||(o<e?-1:o>e?1:0)}function V(o){if(typeof o=="string")return o;if(o===null||typeof o!="object")return;const e=o;return e.author===void 0||e.author===H?e.text:`${e.text} (${e.author})`}function $(o){if(!o)return;const e=Object.fromEntries(Object.entries(o.margins??{}).filter(([t,s])=>F[t]!==s)),n={...o};return Object.keys(e).length>0?n.margins=e:delete n.margins,Object.keys(n).length>0?n:void 0}function O(o){if(!o)return;const e={};for(const[n,t]of Object.entries(o)){const s={..."width"in t&&t.width!==void 0?{width:t.width}:{},..."height"in t&&t.height!==void 0?{height:t.height}:{},...t.hidden===!0?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}};Object.keys(s).length>0&&(e[n]=s)}return e}const z=o=>{const e={...o.hidden===!0?{hidden:!0}:{},...o.tab===void 0?{}:{tab:o.tab.toUpperCase()},...o.gridlines===!1?{gridlines:!1}:{}};return Object.keys(e).length>0?e:void 0};function W(o,e,n,t){const[s,i]=o.span(n,0,t),[r,d]=e.span(n,0,t);return[Math.min(s,r),Math.max(i,d)]}export function diffWorkbooks(o,e,n={}){return new D(o,e,n.tolerance??DIFF_DEFAULTS.tolerance).run()}