@allyhub/sdk 0.8.0 → 0.9.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 (438) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/NOTICE +46 -49
  3. package/dist/dom.d.ts +1 -209
  4. package/dist/dom.js +1 -1
  5. package/dist/image.d.ts +2 -0
  6. package/dist/image.js +2 -0
  7. package/dist/index.d.ts +1 -21
  8. package/dist/index.js +1 -1
  9. package/dist/media.d.ts +1 -5
  10. package/dist/media.js +1 -1
  11. package/dist/node_modules/@allyhub/audio/dist/levels.d.ts +4 -5
  12. package/dist/node_modules/@allyhub/audio/dist/levels.js +1 -1
  13. package/dist/node_modules/@allyhub/audio/dist/node/ffmpeg.d.ts +1 -6
  14. package/dist/node_modules/@allyhub/audio/dist/node/ffmpeg.js +1 -1
  15. package/dist/node_modules/@allyhub/audio/package.json +1 -1
  16. package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
  17. package/dist/node_modules/@allyhub/chart/dist/chart-xml.d.ts +1 -1
  18. package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +2 -2
  19. package/dist/node_modules/@allyhub/chart/dist/chart.js +1 -1
  20. package/dist/node_modules/@allyhub/chart/package.json +1 -1
  21. package/dist/node_modules/@allyhub/diagnostics/LICENSE +241 -0
  22. package/dist/node_modules/@allyhub/diagnostics/dist/fact.d.ts +37 -0
  23. package/dist/node_modules/@allyhub/diagnostics/dist/fact.js +2 -0
  24. package/dist/node_modules/@allyhub/diagnostics/dist/index.d.ts +4 -0
  25. package/dist/node_modules/@allyhub/diagnostics/dist/index.js +2 -0
  26. package/dist/node_modules/@allyhub/diagnostics/dist/problem.d.ts +43 -0
  27. package/dist/node_modules/@allyhub/diagnostics/dist/problem.js +2 -0
  28. package/dist/node_modules/@allyhub/diagnostics/dist/rules.d.ts +30 -0
  29. package/dist/node_modules/@allyhub/diagnostics/dist/rules.js +2 -0
  30. package/dist/node_modules/@allyhub/diagnostics/package.json +14 -0
  31. package/dist/node_modules/@allyhub/formats/dist/contributed.d.ts +126 -0
  32. package/dist/node_modules/@allyhub/formats/dist/contributed.js +2 -0
  33. package/dist/node_modules/@allyhub/formats/dist/data/faces.d.ts +1 -1
  34. package/dist/node_modules/@allyhub/formats/dist/data/reference.d.ts +7 -12
  35. package/dist/node_modules/@allyhub/formats/dist/data/reference.js +1 -1
  36. package/dist/node_modules/@allyhub/formats/dist/data/script.d.ts +9 -4
  37. package/dist/node_modules/@allyhub/formats/dist/data/script.js +1 -1
  38. package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +20 -82
  39. package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
  40. package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +96 -8
  41. package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
  42. package/dist/node_modules/@allyhub/formats/dist/data/website.d.ts +2 -1
  43. package/dist/node_modules/@allyhub/formats/dist/data/website.js +1 -1
  44. package/dist/node_modules/@allyhub/formats/dist/data/work.d.ts +42 -0
  45. package/dist/node_modules/@allyhub/formats/dist/data/work.js +2 -0
  46. package/dist/node_modules/@allyhub/formats/dist/extension.d.ts +91 -0
  47. package/dist/node_modules/@allyhub/formats/dist/extension.js +2 -0
  48. package/dist/node_modules/@allyhub/formats/dist/files.d.ts +51 -0
  49. package/dist/node_modules/@allyhub/formats/dist/files.js +2 -0
  50. package/dist/node_modules/@allyhub/formats/dist/index.d.ts +5 -1
  51. package/dist/node_modules/@allyhub/formats/dist/index.js +1 -1
  52. package/dist/node_modules/@allyhub/formats/dist/items.d.ts +226 -90
  53. package/dist/node_modules/@allyhub/formats/dist/items.js +1 -1
  54. package/dist/node_modules/@allyhub/formats/dist/layout.d.ts +7 -1
  55. package/dist/node_modules/@allyhub/formats/dist/layout.js +1 -1
  56. package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +46 -42
  57. package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
  58. package/dist/node_modules/@allyhub/formats/package.json +1 -1
  59. package/dist/node_modules/@allyhub/image-draw/LICENSE +241 -0
  60. package/dist/node_modules/@allyhub/image-draw/dist/context.d.ts +5 -0
  61. package/dist/node_modules/@allyhub/image-draw/dist/context.js +2 -0
  62. package/dist/node_modules/@allyhub/image-draw/dist/contrast.d.ts +13 -0
  63. package/dist/node_modules/@allyhub/image-draw/dist/contrast.js +2 -0
  64. package/dist/node_modules/@allyhub/image-draw/dist/env.d.ts +112 -0
  65. package/dist/node_modules/@allyhub/image-draw/dist/env.js +2 -0
  66. package/dist/node_modules/@allyhub/image-draw/dist/errors.d.ts +20 -0
  67. package/dist/node_modules/@allyhub/image-draw/dist/errors.js +2 -0
  68. package/dist/node_modules/@allyhub/image-draw/dist/fonts.d.ts +110 -0
  69. package/dist/node_modules/@allyhub/image-draw/dist/fonts.js +2 -0
  70. package/dist/node_modules/@allyhub/image-draw/dist/guards.d.ts +32 -0
  71. package/dist/node_modules/@allyhub/image-draw/dist/guards.js +2 -0
  72. package/dist/node_modules/@allyhub/image-draw/dist/hash.d.ts +3 -0
  73. package/dist/node_modules/@allyhub/image-draw/dist/hash.js +2 -0
  74. package/dist/node_modules/@allyhub/image-draw/dist/inspect.d.ts +113 -0
  75. package/dist/node_modules/@allyhub/image-draw/dist/inspect.js +3 -0
  76. package/dist/node_modules/@allyhub/image-draw/dist/layer-style.d.ts +151 -0
  77. package/dist/node_modules/@allyhub/image-draw/dist/layer-style.js +2 -0
  78. package/dist/node_modules/@allyhub/image-draw/dist/paint.d.ts +29 -0
  79. package/dist/node_modules/@allyhub/image-draw/dist/paint.js +2 -0
  80. package/dist/node_modules/@allyhub/image-draw/dist/pictures.d.ts +39 -0
  81. package/dist/node_modules/@allyhub/image-draw/dist/pictures.js +2 -0
  82. package/dist/node_modules/@allyhub/image-draw/dist/plan.d.ts +52 -0
  83. package/dist/node_modules/@allyhub/image-draw/dist/plan.js +2 -0
  84. package/dist/node_modules/@allyhub/image-draw/dist/reads.d.ts +145 -0
  85. package/dist/node_modules/@allyhub/image-draw/dist/reads.js +2 -0
  86. package/dist/node_modules/@allyhub/image-draw/dist/shape-path.d.ts +26 -0
  87. package/dist/node_modules/@allyhub/image-draw/dist/shape-path.js +2 -0
  88. package/dist/node_modules/@allyhub/image-draw/dist/stage.d.ts +56 -0
  89. package/dist/node_modules/@allyhub/image-draw/dist/stage.js +2 -0
  90. package/dist/node_modules/@allyhub/image-draw/dist/styles.d.ts +35 -0
  91. package/dist/node_modules/@allyhub/image-draw/dist/styles.js +2 -0
  92. package/dist/node_modules/@allyhub/image-draw/dist/tone.d.ts +53 -0
  93. package/dist/node_modules/@allyhub/image-draw/dist/tone.js +2 -0
  94. package/dist/node_modules/@allyhub/image-draw/package.json +14 -0
  95. package/dist/node_modules/@allyhub/image-measure/LICENSE +241 -0
  96. package/dist/node_modules/@allyhub/image-measure/dist/contrast.d.ts +43 -0
  97. package/dist/node_modules/@allyhub/image-measure/dist/contrast.js +2 -0
  98. package/dist/node_modules/@allyhub/image-measure/dist/layout.d.ts +186 -0
  99. package/dist/node_modules/@allyhub/image-measure/dist/layout.js +5 -0
  100. package/dist/node_modules/@allyhub/image-measure/package.json +14 -0
  101. package/dist/node_modules/@allyhub/image-sdk/LICENSE +241 -0
  102. package/dist/node_modules/@allyhub/image-sdk/dist/adjustment.d.ts +13 -0
  103. package/dist/node_modules/@allyhub/image-sdk/dist/adjustment.js +2 -0
  104. package/dist/{define.d.ts → node_modules/@allyhub/image-sdk/dist/define.d.ts} +21 -4
  105. package/dist/node_modules/@allyhub/image-sdk/dist/define.js +2 -0
  106. package/dist/node_modules/@allyhub/image-sdk/dist/dom.d.ts +210 -0
  107. package/dist/node_modules/@allyhub/image-sdk/dist/dom.js +2 -0
  108. package/dist/node_modules/@allyhub/image-sdk/dist/fill.d.ts +21 -0
  109. package/dist/node_modules/@allyhub/image-sdk/dist/fill.js +2 -0
  110. package/dist/node_modules/@allyhub/image-sdk/dist/group.d.ts +17 -0
  111. package/dist/node_modules/@allyhub/image-sdk/dist/group.js +2 -0
  112. package/dist/node_modules/@allyhub/image-sdk/dist/index.d.ts +166 -0
  113. package/dist/node_modules/@allyhub/image-sdk/dist/index.js +2 -0
  114. package/dist/node_modules/@allyhub/image-sdk/dist/media.d.ts +6 -0
  115. package/dist/node_modules/@allyhub/image-sdk/dist/media.js +2 -0
  116. package/dist/{messages.d.ts → node_modules/@allyhub/image-sdk/dist/messages.d.ts} +1 -1
  117. package/dist/node_modules/@allyhub/image-sdk/dist/picture.d.ts +59 -0
  118. package/dist/node_modules/@allyhub/image-sdk/dist/picture.js +2 -0
  119. package/dist/{props.d.ts → node_modules/@allyhub/image-sdk/dist/props.d.ts} +4 -4
  120. package/dist/node_modules/@allyhub/image-sdk/dist/shape.d.ts +34 -0
  121. package/dist/node_modules/@allyhub/image-sdk/dist/shape.js +2 -0
  122. package/dist/node_modules/@allyhub/image-sdk/dist/stack.d.ts +16 -0
  123. package/dist/node_modules/@allyhub/image-sdk/dist/stack.js +2 -0
  124. package/dist/node_modules/@allyhub/image-sdk/dist/text-layer.d.ts +38 -0
  125. package/dist/node_modules/@allyhub/image-sdk/dist/text-layer.js +2 -0
  126. package/dist/{written.js → node_modules/@allyhub/image-sdk/dist/written.js} +1 -1
  127. package/dist/node_modules/@allyhub/image-sdk/package.json +19 -0
  128. package/dist/node_modules/@allyhub/measure/LICENSE +241 -0
  129. package/dist/node_modules/@allyhub/measure/dist/compare.d.ts +195 -0
  130. package/dist/node_modules/@allyhub/measure/dist/compare.js +2 -0
  131. package/dist/node_modules/@allyhub/measure/dist/grain.d.ts +8 -0
  132. package/dist/node_modules/@allyhub/measure/dist/grain.js +2 -0
  133. package/dist/node_modules/@allyhub/measure/dist/image.d.ts +16 -0
  134. package/dist/node_modules/@allyhub/measure/dist/image.js +2 -0
  135. package/dist/node_modules/@allyhub/measure/dist/index.d.ts +4 -0
  136. package/dist/node_modules/@allyhub/measure/dist/index.js +2 -0
  137. package/dist/node_modules/@allyhub/measure/package.json +13 -0
  138. package/dist/node_modules/@allyhub/ooxml/dist/generated/presets.d.ts +4 -1
  139. package/dist/node_modules/@allyhub/ooxml/dist/generated/presets.js +1 -1
  140. package/dist/node_modules/@allyhub/ooxml/dist/geometry/index.d.ts +15 -1
  141. package/dist/node_modules/@allyhub/ooxml/dist/geometry/index.js +1 -1
  142. package/dist/node_modules/@allyhub/ooxml/package.json +1 -1
  143. package/dist/node_modules/@allyhub/piece/LICENSE +241 -0
  144. package/dist/node_modules/@allyhub/{video-core → piece}/dist/anchors.d.ts +1 -9
  145. package/dist/node_modules/@allyhub/{video-core → piece}/dist/component.js +1 -1
  146. package/dist/node_modules/@allyhub/piece/dist/context.d.ts +39 -0
  147. package/dist/node_modules/@allyhub/piece/dist/context.js +2 -0
  148. package/dist/node_modules/@allyhub/{video-core → piece}/dist/contrast.d.ts +2 -2
  149. package/dist/node_modules/@allyhub/{video-core → piece}/dist/export.d.ts +27 -10
  150. package/dist/node_modules/@allyhub/piece/dist/export.js +2 -0
  151. package/dist/node_modules/@allyhub/{video-core → piece}/dist/formats.d.ts +12 -68
  152. package/dist/node_modules/@allyhub/piece/dist/formats.js +2 -0
  153. package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +104 -0
  154. package/dist/node_modules/@allyhub/piece/dist/index.d.ts +26 -0
  155. package/dist/node_modules/@allyhub/piece/dist/index.js +2 -0
  156. package/dist/node_modules/@allyhub/piece/dist/layer-style.d.ts +1558 -0
  157. package/dist/node_modules/@allyhub/piece/dist/layer-style.js +2 -0
  158. package/dist/node_modules/@allyhub/piece/dist/layer.d.ts +389 -0
  159. package/dist/node_modules/@allyhub/piece/dist/layer.js +2 -0
  160. package/dist/node_modules/@allyhub/piece/dist/layout.d.ts +421 -0
  161. package/dist/node_modules/@allyhub/piece/dist/layout.js +2 -0
  162. package/dist/node_modules/@allyhub/{video-core → piece}/dist/look.d.ts +1 -1
  163. package/dist/node_modules/@allyhub/{video-core → piece}/dist/media.d.ts +39 -9
  164. package/dist/node_modules/@allyhub/{video-core → piece}/dist/media.js +1 -1
  165. package/dist/node_modules/@allyhub/{video-core → piece}/dist/messages.d.ts +6 -0
  166. package/dist/node_modules/@allyhub/piece/dist/names.d.ts +26 -0
  167. package/dist/node_modules/@allyhub/piece/dist/names.js +2 -0
  168. package/dist/node_modules/@allyhub/piece/dist/page/console.d.ts +21 -0
  169. package/dist/node_modules/@allyhub/piece/dist/page/console.js +2 -0
  170. package/dist/node_modules/@allyhub/piece/dist/page/index.d.ts +3 -0
  171. package/dist/node_modules/@allyhub/piece/dist/page/index.js +2 -0
  172. package/dist/node_modules/@allyhub/piece/dist/page/locate.d.ts +4 -0
  173. package/dist/node_modules/@allyhub/piece/dist/page/locate.js +2 -0
  174. package/dist/node_modules/@allyhub/piece/dist/picture.d.ts +62 -0
  175. package/dist/node_modules/@allyhub/piece/dist/picture.js +2 -0
  176. package/dist/node_modules/@allyhub/piece/dist/piece.d.ts +15 -0
  177. package/dist/node_modules/@allyhub/piece/dist/piece.js +2 -0
  178. package/dist/node_modules/@allyhub/{video-core → piece}/dist/script.d.ts +9 -4
  179. package/dist/node_modules/@allyhub/piece/dist/script.js +2 -0
  180. package/dist/node_modules/@allyhub/piece/dist/source.d.ts +131 -0
  181. package/dist/node_modules/@allyhub/piece/dist/stage.d.ts +285 -0
  182. package/dist/node_modules/@allyhub/piece/dist/stage.js +2 -0
  183. package/dist/node_modules/@allyhub/piece/dist/version.d.ts +15 -0
  184. package/dist/node_modules/@allyhub/piece/dist/version.js +2 -0
  185. package/dist/node_modules/@allyhub/{video-core → piece}/dist/voice.d.ts +1 -20
  186. package/dist/node_modules/@allyhub/piece/package.json +18 -0
  187. package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +139 -0
  188. package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
  189. package/dist/node_modules/@allyhub/protocol/dist/app.d.ts +3 -10
  190. package/dist/node_modules/@allyhub/protocol/dist/app.js +1 -1
  191. package/dist/node_modules/@allyhub/protocol/dist/cli.d.ts +12 -1
  192. package/dist/node_modules/@allyhub/protocol/dist/cli.js +1 -1
  193. package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +2 -0
  194. package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
  195. package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +232 -132
  196. package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
  197. package/dist/node_modules/@allyhub/protocol/dist/files.d.ts +2 -0
  198. package/dist/node_modules/@allyhub/protocol/dist/files.js +1 -1
  199. package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +22 -9
  200. package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
  201. package/dist/node_modules/@allyhub/protocol/dist/image.d.ts +8 -0
  202. package/dist/node_modules/@allyhub/protocol/dist/image.js +2 -0
  203. package/dist/node_modules/@allyhub/protocol/dist/index.d.ts +5 -0
  204. package/dist/node_modules/@allyhub/protocol/dist/index.js +1 -1
  205. package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
  206. package/dist/node_modules/@allyhub/protocol/dist/kinds.d.ts +98 -0
  207. package/dist/node_modules/@allyhub/protocol/dist/kinds.js +2 -0
  208. package/dist/node_modules/@allyhub/protocol/dist/mail.d.ts +273 -0
  209. package/dist/node_modules/@allyhub/protocol/dist/mail.js +2 -0
  210. package/dist/node_modules/@allyhub/protocol/dist/notes.d.ts +26 -0
  211. package/dist/node_modules/@allyhub/protocol/dist/notes.js +1 -1
  212. package/dist/node_modules/@allyhub/protocol/dist/peer.d.ts +59 -0
  213. package/dist/node_modules/@allyhub/protocol/dist/peer.js +2 -0
  214. package/dist/node_modules/@allyhub/protocol/dist/place.d.ts +21 -0
  215. package/dist/node_modules/@allyhub/protocol/dist/place.js +2 -0
  216. package/dist/node_modules/@allyhub/protocol/dist/presence.d.ts +125 -0
  217. package/dist/node_modules/@allyhub/protocol/dist/presence.js +2 -0
  218. package/dist/node_modules/@allyhub/protocol/dist/registry.d.ts +1 -1
  219. package/dist/node_modules/@allyhub/protocol/dist/routes.js +1 -1
  220. package/dist/node_modules/@allyhub/protocol/dist/shape.d.ts +35 -0
  221. package/dist/node_modules/@allyhub/protocol/dist/shape.js +2 -0
  222. package/dist/node_modules/@allyhub/protocol/dist/shares.d.ts +2 -8
  223. package/dist/node_modules/@allyhub/protocol/dist/shares.js +1 -1
  224. package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +70 -40
  225. package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
  226. package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +224 -177
  227. package/dist/node_modules/@allyhub/protocol/dist/tools.js +1 -1
  228. package/dist/node_modules/@allyhub/protocol/package.json +1 -1
  229. package/dist/node_modules/@allyhub/runtimes/dist/bundled.js +1 -1
  230. package/dist/node_modules/@allyhub/runtimes/dist/declared.d.ts +14 -0
  231. package/dist/node_modules/@allyhub/runtimes/dist/declared.js +2 -0
  232. package/dist/node_modules/@allyhub/runtimes/dist/ffmpeg.d.ts +15 -0
  233. package/dist/node_modules/@allyhub/runtimes/dist/ffmpeg.js +2 -0
  234. package/dist/node_modules/@allyhub/runtimes/dist/index.d.ts +2 -0
  235. package/dist/node_modules/@allyhub/runtimes/dist/index.js +1 -1
  236. package/dist/node_modules/@allyhub/runtimes/dist/packages.js +3 -3
  237. package/dist/node_modules/@allyhub/runtimes/dist/runtimes.d.ts +1 -0
  238. package/dist/node_modules/@allyhub/runtimes/dist/runtimes.js +1 -1
  239. package/dist/node_modules/@allyhub/runtimes/manifest.json +0 -82
  240. package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
  241. package/dist/node_modules/@allyhub/scenery/dist/define.d.ts +2 -0
  242. package/dist/node_modules/@allyhub/scenery/dist/define.js +1 -1
  243. package/dist/node_modules/@allyhub/scenery/package.json +1 -1
  244. package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
  245. package/dist/node_modules/@allyhub/sheet/dist/api/code.d.ts +4 -4
  246. package/dist/node_modules/@allyhub/sheet/dist/api/code.js +1 -1
  247. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +15 -11
  248. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
  249. package/dist/node_modules/@allyhub/sheet/dist/calc/server.d.ts +1 -1
  250. package/dist/node_modules/@allyhub/sheet/dist/export.js +1 -1
  251. package/dist/node_modules/@allyhub/sheet/dist/file.d.ts +5 -0
  252. package/dist/node_modules/@allyhub/sheet/dist/file.js +1 -1
  253. package/dist/node_modules/@allyhub/sheet/dist/generated.d.ts +5 -19
  254. package/dist/node_modules/@allyhub/sheet/dist/generated.js +1 -1
  255. package/dist/node_modules/@allyhub/sheet/dist/import.d.ts +3 -1
  256. package/dist/node_modules/@allyhub/sheet/dist/import.js +1 -1
  257. package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +3 -4
  258. package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
  259. package/dist/node_modules/@allyhub/sheet/dist/inspect.d.ts +76 -1
  260. package/dist/node_modules/@allyhub/sheet/dist/patch.d.ts +1 -1
  261. package/dist/node_modules/@allyhub/sheet/dist/patch.js +1 -1
  262. package/dist/node_modules/@allyhub/sheet/dist/sdk.d.ts +2 -0
  263. package/dist/node_modules/@allyhub/sheet/dist/sdk.js +2 -0
  264. package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +6 -6
  265. package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
  266. package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.d.ts +2 -0
  267. package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
  268. package/dist/node_modules/@allyhub/sheet/package.json +5 -1
  269. package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +23 -7
  270. package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
  271. package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +44 -4
  272. package/dist/node_modules/@allyhub/slides-core/dist/api.js +2 -2
  273. package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
  274. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +18 -1
  275. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
  276. package/dist/node_modules/@allyhub/slides-core/dist/code.d.ts +1 -1
  277. package/dist/node_modules/@allyhub/slides-core/dist/connect.d.ts +62 -0
  278. package/dist/node_modules/@allyhub/slides-core/dist/connect.js +2 -0
  279. package/dist/node_modules/@allyhub/slides-core/dist/fact.d.ts +208 -0
  280. package/dist/node_modules/@allyhub/slides-core/dist/fact.js +2 -0
  281. package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +4 -4
  282. package/dist/node_modules/@allyhub/slides-core/dist/file.js +2 -2
  283. package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +2 -0
  284. package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
  285. package/dist/node_modules/@allyhub/slides-core/dist/measure.d.ts +4 -2
  286. package/dist/node_modules/@allyhub/slides-core/dist/measure.js +1 -1
  287. package/dist/node_modules/@allyhub/slides-core/dist/merge.d.ts +5 -5
  288. package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
  289. package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +19 -2
  290. package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +1 -1
  291. package/dist/node_modules/@allyhub/slides-core/dist/path.d.ts +1 -1
  292. package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +17 -10
  293. package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
  294. package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +18 -0
  295. package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +2 -0
  296. package/dist/node_modules/@allyhub/slides-core/dist/stage.d.ts +28 -11
  297. package/dist/node_modules/@allyhub/slides-core/dist/units.d.ts +3 -6
  298. package/dist/node_modules/@allyhub/slides-core/dist/units.js +1 -1
  299. package/dist/node_modules/@allyhub/slides-core/package.json +5 -1
  300. package/dist/node_modules/@allyhub/video-core/dist/audio-types.d.ts +1 -2
  301. package/dist/node_modules/@allyhub/video-core/dist/captions.d.ts +1 -10
  302. package/dist/node_modules/@allyhub/video-core/dist/captions.js +1 -1
  303. package/dist/node_modules/@allyhub/video-core/dist/check.d.ts +62 -0
  304. package/dist/node_modules/@allyhub/video-core/dist/check.js +2 -0
  305. package/dist/node_modules/@allyhub/video-core/dist/cut-report.d.ts +2 -2
  306. package/dist/node_modules/@allyhub/video-core/dist/cut-report.js +1 -1
  307. package/dist/node_modules/@allyhub/video-core/dist/edits.d.ts +3 -3
  308. package/dist/node_modules/@allyhub/video-core/dist/edits.js +1 -1
  309. package/dist/node_modules/@allyhub/video-core/dist/fact.d.ts +21 -762
  310. package/dist/node_modules/@allyhub/video-core/dist/fact.js +1 -1
  311. package/dist/node_modules/@allyhub/video-core/dist/footage-motion.d.ts +3 -2
  312. package/dist/node_modules/@allyhub/video-core/dist/footage-motion.js +1 -1
  313. package/dist/node_modules/@allyhub/video-core/dist/index.d.ts +3 -17
  314. package/dist/node_modules/@allyhub/video-core/dist/index.js +1 -1
  315. package/dist/node_modules/@allyhub/video-core/dist/measure.d.ts +72 -423
  316. package/dist/node_modules/@allyhub/video-core/dist/measure.js +1 -4
  317. package/dist/node_modules/@allyhub/video-core/dist/mix-plan.d.ts +44 -0
  318. package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +2 -0
  319. package/dist/node_modules/@allyhub/video-core/dist/motion.d.ts +1 -1
  320. package/dist/node_modules/@allyhub/video-core/dist/piece.d.ts +22 -430
  321. package/dist/node_modules/@allyhub/video-core/dist/piece.js +1 -1
  322. package/dist/node_modules/@allyhub/video-core/dist/placement.d.ts +1 -1
  323. package/dist/node_modules/@allyhub/video-core/dist/schema.d.ts +6 -12
  324. package/dist/node_modules/@allyhub/video-core/dist/schema.js +1 -1
  325. package/dist/node_modules/@allyhub/video-core/dist/script-edit.d.ts +11 -6
  326. package/dist/node_modules/@allyhub/video-core/dist/script-edit.js +1 -1
  327. package/dist/node_modules/@allyhub/video-core/dist/seams.d.ts +2 -3
  328. package/dist/node_modules/@allyhub/video-core/dist/sound-under.d.ts +2 -2
  329. package/dist/node_modules/@allyhub/video-core/dist/sound-under.js +1 -1
  330. package/dist/node_modules/@allyhub/video-core/dist/speech.d.ts +2 -4
  331. package/dist/node_modules/@allyhub/video-core/dist/speech.js +2 -2
  332. package/dist/node_modules/@allyhub/video-core/dist/stage.d.ts +52 -0
  333. package/dist/node_modules/@allyhub/video-core/dist/stage.js +2 -0
  334. package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +18 -136
  335. package/dist/node_modules/@allyhub/video-core/dist/timeline.js +1 -1
  336. package/dist/node_modules/@allyhub/video-core/dist/timing.d.ts +3 -3
  337. package/dist/node_modules/@allyhub/video-core/dist/timing.js +1 -1
  338. package/dist/node_modules/@allyhub/video-core/dist/transcript.d.ts +2 -2
  339. package/dist/node_modules/@allyhub/video-core/dist/transcript.js +1 -1
  340. package/dist/node_modules/@allyhub/video-core/package.json +1 -1
  341. package/dist/node_modules/@allyhub/video-sdk/LICENSE +241 -0
  342. package/dist/node_modules/@allyhub/video-sdk/NOTICE +118 -0
  343. package/dist/{free.d.ts → node_modules/@allyhub/video-sdk/dist/free.d.ts} +14 -10
  344. package/dist/node_modules/@allyhub/video-sdk/dist/free.js +2 -0
  345. package/dist/node_modules/@allyhub/video-sdk/dist/index.d.ts +28 -0
  346. package/dist/node_modules/@allyhub/video-sdk/dist/index.js +2 -0
  347. package/dist/{input.d.ts → node_modules/@allyhub/video-sdk/dist/input.d.ts} +76 -22
  348. package/dist/node_modules/@allyhub/video-sdk/dist/input.js +2 -0
  349. package/dist/{module.d.ts → node_modules/@allyhub/video-sdk/dist/module.d.ts} +6 -4
  350. package/dist/node_modules/@allyhub/video-sdk/dist/module.js +2 -0
  351. package/dist/{parts.d.ts → node_modules/@allyhub/video-sdk/dist/parts.d.ts} +15 -6
  352. package/dist/node_modules/@allyhub/video-sdk/dist/parts.js +2 -0
  353. package/dist/{piece.d.ts → node_modules/@allyhub/video-sdk/dist/piece.d.ts} +26 -16
  354. package/dist/node_modules/@allyhub/video-sdk/dist/piece.js +2 -0
  355. package/dist/node_modules/@allyhub/video-sdk/dist/route.d.ts +46 -0
  356. package/dist/node_modules/@allyhub/video-sdk/dist/route.js +2 -0
  357. package/dist/node_modules/@allyhub/video-sdk/dist/scenery.d.ts +2 -0
  358. package/dist/node_modules/@allyhub/video-sdk/dist/scenery.js +2 -0
  359. package/dist/node_modules/@allyhub/video-sdk/package.json +19 -0
  360. package/dist/scenery.d.ts +1 -1
  361. package/dist/scenery.js +1 -1
  362. package/dist/sheets.d.ts +1 -1
  363. package/dist/sheets.js +1 -1
  364. package/dist/slides.d.ts +1 -9
  365. package/dist/slides.js +1 -1
  366. package/docs/README.md +8 -6
  367. package/docs/batches.md +5 -5
  368. package/docs/contract.md +2 -2
  369. package/docs/defaults.md +278 -20
  370. package/docs/docs.md +77 -63
  371. package/docs/footage.md +7 -7
  372. package/docs/image.md +165 -0
  373. package/docs/layers.md +22 -13
  374. package/docs/modeling.md +4 -4
  375. package/docs/pictures.md +65 -0
  376. package/docs/project.md +51 -31
  377. package/docs/scenery.md +11 -11
  378. package/docs/sheets.md +26 -25
  379. package/docs/slides.md +73 -65
  380. package/docs/sound.md +3 -3
  381. package/docs/speech.md +8 -8
  382. package/docs/video.md +16 -13
  383. package/docs/websites.md +4 -4
  384. package/package.json +7 -2
  385. package/dist/define.js +0 -2
  386. package/dist/free.js +0 -2
  387. package/dist/input.js +0 -2
  388. package/dist/module.js +0 -2
  389. package/dist/node_modules/@allyhub/formats/dist/data/comments.d.ts +0 -94
  390. package/dist/node_modules/@allyhub/formats/dist/data/comments.js +0 -2
  391. package/dist/node_modules/@allyhub/runtimes/pins/onnxruntime-node/package-lock.json +0 -227
  392. package/dist/node_modules/@allyhub/runtimes/pins/onnxruntime-node/package.json +0 -8
  393. package/dist/node_modules/@allyhub/runtimes/pins/sherpa-onnx-node/package-lock.json +0 -105
  394. package/dist/node_modules/@allyhub/runtimes/pins/sherpa-onnx-node/package.json +0 -8
  395. package/dist/node_modules/@allyhub/runtimes/pins/tesseract.js/package-lock.json +0 -128
  396. package/dist/node_modules/@allyhub/runtimes/pins/tesseract.js/package.json +0 -9
  397. package/dist/node_modules/@allyhub/video-core/dist/export.js +0 -2
  398. package/dist/node_modules/@allyhub/video-core/dist/formats.js +0 -2
  399. package/dist/node_modules/@allyhub/video-core/dist/gen.d.ts +0 -37
  400. package/dist/node_modules/@allyhub/video-core/dist/problem.d.ts +0 -278
  401. package/dist/node_modules/@allyhub/video-core/dist/problem.js +0 -2
  402. package/dist/node_modules/@allyhub/video-core/dist/script.js +0 -2
  403. package/dist/node_modules/@allyhub/video-core/dist/source.d.ts +0 -7
  404. package/dist/parts.js +0 -2
  405. package/dist/piece.js +0 -2
  406. /package/dist/node_modules/@allyhub/{sheet → formats}/dist/csv.d.ts +0 -0
  407. /package/dist/node_modules/@allyhub/{sheet → formats}/dist/csv.js +0 -0
  408. /package/dist/{fit.d.ts → node_modules/@allyhub/image-sdk/dist/fit.d.ts} +0 -0
  409. /package/dist/{fit.js → node_modules/@allyhub/image-sdk/dist/fit.js} +0 -0
  410. /package/dist/{messages.js → node_modules/@allyhub/image-sdk/dist/messages.js} +0 -0
  411. /package/dist/{props.js → node_modules/@allyhub/image-sdk/dist/props.js} +0 -0
  412. /package/dist/{text.d.ts → node_modules/@allyhub/image-sdk/dist/text.d.ts} +0 -0
  413. /package/dist/{text.js → node_modules/@allyhub/image-sdk/dist/text.js} +0 -0
  414. /package/dist/{written.d.ts → node_modules/@allyhub/image-sdk/dist/written.d.ts} +0 -0
  415. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/anchors.js +0 -0
  416. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/component.d.ts +0 -0
  417. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/console.d.ts +0 -0
  418. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/console.js +0 -0
  419. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/contrast.js +0 -0
  420. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/gen.js +0 -0
  421. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/look.js +0 -0
  422. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/marks.d.ts +0 -0
  423. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/marks.js +0 -0
  424. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/matrix.d.ts +0 -0
  425. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/matrix.js +0 -0
  426. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/messages.js +0 -0
  427. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/source.js +0 -0
  428. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/voice.js +0 -0
  429. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/words.d.ts +0 -0
  430. /package/dist/node_modules/@allyhub/{video-core → piece}/dist/words.js +0 -0
  431. /package/dist/{anim.d.ts → node_modules/@allyhub/video-sdk/dist/anim.d.ts} +0 -0
  432. /package/dist/{anim.js → node_modules/@allyhub/video-sdk/dist/anim.js} +0 -0
  433. /package/dist/{noise.d.ts → node_modules/@allyhub/video-sdk/dist/noise.d.ts} +0 -0
  434. /package/dist/{noise.js → node_modules/@allyhub/video-sdk/dist/noise.js} +0 -0
  435. /package/dist/{paths.d.ts → node_modules/@allyhub/video-sdk/dist/paths.d.ts} +0 -0
  436. /package/dist/{paths.js → node_modules/@allyhub/video-sdk/dist/paths.js} +0 -0
  437. /package/dist/{phone.d.ts → node_modules/@allyhub/video-sdk/dist/phone.d.ts} +0 -0
  438. /package/dist/{phone.js → node_modules/@allyhub/video-sdk/dist/phone.js} +0 -0
@@ -1,3 +1,3 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{readDataFile as c}from"@allyhub/formats";import{LineCounter as p,isMap as m,isScalar as f,parseDocument as d,visit as g}from"yaml";export const ENTRY="sheet.yaml";export function dataFilesOf(i){const{file:t}=readSheetFile(i);return[...new Set(t?.sheets.flatMap(s=>[...(s.tables??[]).map(n=>n.rows),...(s.blocks??[]).map(n=>n.rows)])??[])]}function h(i){const t=[];return g(i,{Map(s,n){if(!m(n))return;const a=new Set;for(const o of n.items){const e=f(o.key)?String(o.key.value):void 0;if(e!==void 0)if(a.has(e)){const r=f(o.key)?o.key.range?.[0]??0:0;t.push({at:r,key:e})}else a.add(e)}}}),t}export function readSheetFile(i){const t=new p,s=d(i,{lineCounter:t,uniqueKeys:!1}),n=e=>{for(let r=e.length;r>=0;r--){const u=s.getIn(e.slice(0,r),!0)?.range?.[0];if(u!==void 0)return t.linePos(u).line}},a=h(s);if(s.errors.length>0||a.length>0)return{problems:[...s.errors.map(e=>({file:ENTRY,line:t.linePos(e.pos[0]).line,message:`not YAML: ${e.message.split(`
2
+ import{readDataFile as c}from"@allyhub/formats";import{LineCounter as p,isMap as d,isScalar as f,parseDocument as m,visit as h}from"yaml";export const ENTRY="sheet.yaml",CODE="sheet.ts",codeOf=i=>readSheetFile(i).file?.code;export function dataFilesOf(i){const{file:t}=readSheetFile(i);return[...new Set(t?.sheets.flatMap(s=>[...(s.tables??[]).map(n=>n.rows),...(s.blocks??[]).map(n=>n.rows)])??[])]}function g(i){const t=[];return h(i,{Map(s,n){if(!d(n))return;const a=new Set;for(const o of n.items){const e=f(o.key)?String(o.key.value):void 0;if(e!==void 0)if(a.has(e)){const r=f(o.key)?o.key.range?.[0]??0:0;t.push({at:r,key:e})}else a.add(e)}}}),t}export function readSheetFile(i){const t=new p,s=m(i,{lineCounter:t,uniqueKeys:!1}),n=e=>{for(let r=e.length;r>=0;r--){const u=s.getIn(e.slice(0,r),!0)?.range?.[0];if(u!==void 0)return t.linePos(u).line}},a=g(s);if(s.errors.length>0||a.length>0)return{problems:[...s.errors.map(e=>({file:ENTRY,line:t.linePos(e.pos[0]).line,message:`not YAML: ${e.message.split(`
3
3
  `)[0]??""}`})),...a.map(e=>({file:ENTRY,line:t.linePos(e.at).line,message:`not YAML: Map keys must be unique (${e.key})`}))],lineOf:n};const o=c("sheet",s.toJS()??{});return o.ok?{file:o.value,problems:[],lineOf:n}:{problems:o.problems.map(e=>{const r=n(e.path===""?[]:e.path.split(".").map(l=>/^\d+$/u.test(l)?Number(l):l));return{file:ENTRY,...r===void 0?{}:{line:r},message:`${e.path===""?"":`${e.path}: `}${e.message}`}}),lineOf:n}}
@@ -1,36 +1,22 @@
1
- import { type SheetFile, type SheetWorksheet } from "@allyhub/formats";
1
+ import { type SheetFile, type SheetWorksheet, type GeneratedSheets } from "@allyhub/formats";
2
2
  import type { BookEdit } from "./edit.js";
3
3
  /** Where a generated CSV file is named, so it never stands for one on disk. */
4
4
  export declare const GENERATED = "sheet.ts/";
5
- export interface GeneratedSheets {
6
- /** The sheets it makes, in the order it made them, as sheet.yaml would hold them. */
7
- sheets: SheetWorksheet[];
8
- /** Names it defines. */
9
- names?: NonNullable<SheetFile["names"]>;
10
- /** Its tables' and blocks' rows, as CSV text, by the paths its sheets name. */
11
- csv: Record<string, string>;
12
- /** Numbers it typed that neither its data nor its code holds. */
13
- typed?: {
14
- sheet: string;
15
- cell: string;
16
- value: number;
17
- }[];
18
- }
19
5
  export interface MergedFile {
20
6
  file: SheetFile;
21
7
  /** How many of its sheets, the first ones, are sheet.yaml's. */
22
8
  own: number;
23
- /** Names that are sheet.ts's. */
9
+ /** Names that are the code's. */
24
10
  names: ReadonlySet<string>;
25
- /** Sheets sheet.ts makes that sheet.yaml holds: sheet.yaml's stand. */
11
+ /** Sheets the code makes that sheet.yaml holds: sheet.yaml's stand. */
26
12
  ordinary: string[];
27
13
  }
28
- /** sheet.yaml with what sheet.ts makes after it. */
14
+ /** sheet.yaml with what its code makes after it. */
29
15
  export declare function withGenerated(file: SheetFile, generated: GeneratedSheets | undefined): MergedFile;
30
16
  /**
31
17
  * A generated sheet as an ordinary one: its spec in sheet.yaml and its rows in
32
18
  * CSV files of their own, where `taken` says no file stands. From then on
33
- * sheet.yaml holds that name, so what sheet.ts makes of it is left out; taking
19
+ * sheet.yaml holds that name, so what the code makes of it is left out; taking
34
20
  * the sheet out of sheet.yaml gives it back to the code.
35
21
  */
36
22
  export declare function ordinarySheet(book: {
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_CODE as v,SHEET_DATA as w}from"@allyhub/formats";import{readCsv as d}from"./csv.js";export const GENERATED=`${v}/`;const l=e=>e.toLowerCase();export function withGenerated(e,n){const a=e.sheets.length;if(!n)return{file:e,own:a,names:new Set,ordinary:[]};const m=new Set(e.sheets.map(s=>l(s.name))),t=n.sheets.filter(s=>!m.has(l(s.name))),c=n.sheets.filter(s=>m.has(l(s.name))).map(s=>s.name),f=new Set(Object.keys(e.names??{}).map(l)),r=Object.entries(n.names??{}).filter(([s])=>!f.has(l(s)));return{file:{...e,sheets:[...e.sheets,...t],...r.length===0?{}:{names:{...e.names,...Object.fromEntries(r)}}},own:a,names:new Set(r.map(([s])=>s)),ordinary:c}}const b=e=>[...(e.tables??[]).map(n=>n.rows),...(e.blocks??[]).map(n=>n.rows)],E=e=>e.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-|-$/gu,"");export function ordinarySheet(e,n,a,m=()=>!1){const t=n.sheets.find(o=>l(o.name)===l(a));if(!t)return{rows:new Map,cells:[],whole:!1,refused:"no-sheet"};const c=new Map,f=new Map;for(const o of b(t)){const p=n.csv[o];if(p===void 0)continue;const h=E(`${t.name} ${o.split("/").pop()??""}`).replace(/-csv$/u,"");let u=`${w}/${h}.csv`;for(let i=2;m(u)||c.has(u);i++)u=`${w}/${h}-${String(i)}.csv`;f.set(o,u),c.set(u,d(p).records.map(i=>i.end===i.start?[]:i.fields))}const r=o=>f.get(o)??o,s=structuredClone(t);for(const o of s.tables??[])o.rows=r(o.rows);for(const o of s.blocks??[])o.rows=r(o.rows);return{file:{...e.file,sheets:[...e.file.sheets,s]},rows:c,cells:[],whole:!0}}export function typedNumbers(e,n){const a=[],m=t=>typeof t=="number"?t:t!==null&&typeof t=="object"?t.value:void 0;for(const t of e){for(const[c,f]of Object.entries(t.cells??{})){const r=m(f);typeof r=="number"&&a.push({sheet:t.name,cell:c,value:r})}for(const c of b(t))d(n[c]??"").records.forEach(f=>{for(const r of f.fields){const s=Number(r);r.trim()!==""&&Number.isFinite(s)&&a.push({sheet:t.name,file:c,value:s})}})}return a}
2
+ import"@allyhub/formats";import{readCsv as w}from"@allyhub/formats";import{CODE as b}from"./file.js";export const GENERATED=`${b}/`;const l=e=>e.toLowerCase();export function withGenerated(e,n){const a=e.sheets.length;if(!n)return{file:e,own:a,names:new Set,ordinary:[]};const m=new Set(e.sheets.map(s=>l(s.name))),t=n.sheets.filter(s=>!m.has(l(s.name))),c=n.sheets.filter(s=>m.has(l(s.name))).map(s=>s.name),f=new Set(Object.keys(e.names??{}).map(l)),r=Object.entries(n.names??{}).filter(([s])=>!f.has(l(s)));return{file:{...e,sheets:[...e.sheets,...t],...r.length===0?{}:{names:{...e.names,...Object.fromEntries(r)}}},own:a,names:new Set(r.map(([s])=>s)),ordinary:c}}const d=e=>[...(e.tables??[]).map(n=>n.rows),...(e.blocks??[]).map(n=>n.rows)],v=e=>e.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-|-$/gu,"");export function ordinarySheet(e,n,a,m=()=>!1){const t=n.sheets.find(o=>l(o.name)===l(a));if(!t)return{rows:new Map,cells:[],whole:!1,refused:"no-sheet"};const c=new Map,f=new Map;for(const o of d(t)){const u=n.csv[o];if(u===void 0)continue;const h=v(`${t.name} ${o.split("/").pop()??""}`).replace(/-csv$/u,"");let p=`${h}.csv`;for(let i=2;m(p)||c.has(p);i++)p=`${h}-${String(i)}.csv`;f.set(o,p),c.set(p,w(u).records.map(i=>i.end===i.start?[]:i.fields))}const r=o=>f.get(o)??o,s=structuredClone(t);for(const o of s.tables??[])o.rows=r(o.rows);for(const o of s.blocks??[])o.rows=r(o.rows);return{file:{...e.file,sheets:[...e.file.sheets,s]},rows:c,cells:[],whole:!0}}export function typedNumbers(e,n){const a=[],m=t=>typeof t=="number"?t:t!==null&&typeof t=="object"?t.value:void 0;for(const t of e){for(const[c,f]of Object.entries(t.cells??{})){const r=m(f);typeof r=="number"&&a.push({sheet:t.name,cell:c,value:r})}for(const c of d(t))w(n[c]??"").records.forEach(f=>{for(const r of f.fields){const s=Number(r);r.trim()!==""&&Number.isFinite(s)&&a.push({sheet:t.name,file:c,value:s})}})}return a}
@@ -7,5 +7,7 @@ export interface ImportedSheet {
7
7
  rows: number;
8
8
  }
9
9
  /** A sheet of a file's rows; `name` is what its table and title are called. */
10
- export declare function importRows(name: string, text: string, delimiter: "," | "\t"): ImportedSheet;
10
+ export declare function importRows(name: string, text: string, delimiter: "," | "\t",
11
+ /** Whether a file is beside the sheet's file already, by its path from its folder: the rows take another name. */
12
+ taken?: (path: string) => boolean): ImportedSheet;
11
13
  //# sourceMappingURL=import.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{readCsv as m,writeCsv as c}from"./csv.js";import{validName as p}from"./workbook.js";import{writeYaml as w}from"./write.js";const f=r=>{const e=r.replace(/[^\p{L}\p{N}_]+/gu,"_").replace(/^_+|_+$/gu,"");return p(e)?e:`t_${e||"rows"}`};export function importRows(r,e,n){const t=m(e,n),o=t.problems[0];if(o)throw new Error(`line ${String(o.line)}: ${o.message}`);const s=t.records.map(i=>i.fields);if(s.length===0)throw new Error("the file holds no rows");const a=f(r),l=`data/${a.toLowerCase()}.csv`;return{text:w({title:r,sheets:[{name:"Sheet1",freeze:"A2",tables:[{name:a,at:"A1",rows:l}]}]}),path:l,csv:n===","&&t.dialect.finalNewline?e:c(s),rows:s.length-1}}
2
+ import{readCsv as p,writeCsv as w}from"@allyhub/formats";import{validName as f}from"./workbook.js";import{writeYaml as h}from"./write.js";const g=r=>{const e=r.replace(/[^\p{L}\p{N}_]+/gu,"_").replace(/^_+|_+$/gu,"");return f(e)?e:`t_${e||"rows"}`};export function importRows(r,e,a,c=()=>!1){const s=p(e,a),n=s.problems[0];if(n)throw new Error(`line ${String(n.line)}: ${n.message}`);const l=s.records.map(o=>o.fields);if(l.length===0)throw new Error("the file holds no rows");const i=g(r),m=i.toLowerCase();let t=`${m}.csv`;for(let o=2;c(t);o++)t=`${m}-${String(o)}.csv`;return{text:h({title:r,sheets:[{name:"Sheet1",freeze:"A2",tables:[{name:i,at:"A1",rows:t}]}]}),path:t,csv:a===","&&s.dialect.finalNewline?e:w(l),rows:l.length-1}}
@@ -1,12 +1,11 @@
1
1
  export * from "./address.js";
2
- export { DEFAULT_DIALECT, csvField, csvRecord, csvRows, fromTsv, readCsv, toTsv, writeCsv, type CsvDialect, type CsvProblem, type CsvRecord, type ParsedCsv, } from "./csv.js";
3
2
  export { patchCsv } from "./patch.js";
4
3
  export * from "./values.js";
5
4
  export * from "./workbook.js";
6
5
  export * from "./calc/remote.js";
7
6
  export * from "./calc/server.js";
8
- export { dataFilesOf, readSheetFile, type SheetProblem } from "./file.js";
9
- export { GENERATED, ordinarySheet, typedNumbers, withGenerated, type GeneratedSheets, type MergedFile, } from "./generated.js";
7
+ export { CODE as SHEET_CODE, ENTRY as SHEET_ENTRY, codeOf, dataFilesOf, readSheetFile, type SheetProblem, } from "./file.js";
8
+ export { GENERATED, ordinarySheet, typedNumbers, withGenerated, type MergedFile, } from "./generated.js";
10
9
  export { applyScenario, cellOfName, scenarioNames, scenariosByCell, type ScenarioCell, type SheetScenarios, } from "./scenario.js";
11
10
  export { fileCells, hasFiles, isPicture, pictureHeight, pictureSize, type FileCell, } from "./files.js";
12
11
  export * from "./formula/ast.js";
@@ -37,6 +36,6 @@ export { Rules, colorBetween, compareValues, holds, iconShape, type IconShape, t
37
36
  export { choicesIn, invalidCells, joinChoices, listValues, separatorOf, valid, type InvalidCell, } from "./validate.js";
38
37
  export { freeColumn, restructure, tableShape, uniqueColumn, withColumnsUpTo, type BookValues, type RefusedEdit, type Restructured, type TableShape, } from "./structure.js";
39
38
  export { SHEET_CHART_DEFAULTS, chartAfter, chartDataRange, chartDef, chartOfRange, chartPlace, chartSize, chartSvg, readDataRange, type ChartSvgOptions, type NewChart, } from "./chart.js";
40
- export { INSPECT_DEFAULTS, SHEET_FACT_KINDS, inspectWorkbook, type InspectOptions, type SheetFactKind, type SheetFinding, } from "./inspect.js";
39
+ export { INSPECT_DEFAULTS, SHEET_FACT_KINDS, inspectWorkbook, type InspectOptions, type SheetFactData, type SheetFactKind, type SheetFinding, } from "./inspect.js";
41
40
  export { DIFF_DEFAULTS, diffWorkbooks, type CellChange as DiffCell, type DiffKind, type DiffOptions, type DiffSide, type SheetDiff, type TableDiff, type WorkbookDiff, } from "./diff.js";
42
41
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- export*from"./address.js";export{DEFAULT_DIALECT,csvField,csvRecord,csvRows,fromTsv,readCsv,toTsv,writeCsv}from"./csv.js";export{patchCsv}from"./patch.js";export*from"./values.js";export*from"./workbook.js";export*from"./calc/remote.js";export*from"./calc/server.js";export{dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,csvText,dataValue,excelNumber,jsonOf,markdownOf,tableRows}from"./export.js";export{generalForms,generalText,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,headerFooterHtml,sheetHtml,SheetPrint}from"./html.js";export{PAPERS,PRINT_DEFAULTS,paginate}from"./paginate.js";export{DEFAULT_TABLE_STYLE,tableStyleLook,tableStyleOf}from"./table-style.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./arrange.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
2
+ export*from"./address.js";export{patchCsv}from"./patch.js";export*from"./values.js";export*from"./workbook.js";export*from"./calc/remote.js";export*from"./calc/server.js";export{CODE as SHEET_CODE,ENTRY as SHEET_ENTRY,codeOf,dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,csvText,dataValue,excelNumber,jsonOf,markdownOf,tableRows}from"./export.js";export{generalForms,generalText,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,headerFooterHtml,sheetHtml,SheetPrint}from"./html.js";export{PAPERS,PRINT_DEFAULTS,paginate}from"./paginate.js";export{DEFAULT_TABLE_STYLE,tableStyleLook,tableStyleOf}from"./table-style.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./arrange.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
@@ -1,5 +1,80 @@
1
- import type { SheetFactData } from "@allyhub/formats";
2
1
  import type { Calc } from "./calc/engine.js";
2
+ /**
3
+ * What each kind of a workbook's facts measures: `allyhub inspect`'s, never
4
+ * problems. Each kind is the sheet extension's (its manifest's
5
+ * `contributes.facts`, with what it says).
6
+ */
7
+ export interface SheetFactData {
8
+ /** A cell whose value is an error. */
9
+ "sheet-error": {
10
+ sheet: string;
11
+ cell: string;
12
+ code: string;
13
+ formula?: string;
14
+ /** None of what it reads is an error: the error starts here. */
15
+ origin: boolean;
16
+ };
17
+ /** Numbers written into a formula. */
18
+ "sheet-number": {
19
+ sheet: string;
20
+ /** The cell its formula is written for. */
21
+ cell: string;
22
+ /** How many cells hold this formula. */
23
+ cells: number;
24
+ formula: string;
25
+ /** Each number, and the operator or function it is given to. */
26
+ numbers: {
27
+ value: number;
28
+ in: string;
29
+ }[];
30
+ };
31
+ /** A cell between neighbours that agree, unlike them. */
32
+ "sheet-unlike": {
33
+ sheet: string;
34
+ cell: string;
35
+ /** What it holds: its formula, or its value. */
36
+ holds: string;
37
+ /** What the neighbours hold, as the first of them reads. */
38
+ neighbour: string;
39
+ along: "column" | "row";
40
+ /** How many cells together read alike either side. */
41
+ run: number;
42
+ };
43
+ /** A cell of a calculated column set apart from its formula. */
44
+ "sheet-exception": {
45
+ sheet: string;
46
+ table: string;
47
+ column: string;
48
+ cell: string;
49
+ text: string;
50
+ };
51
+ /** An input nothing reads. */
52
+ "sheet-unused": {
53
+ /** A defined name, a typed cell, or a table's column (with --all). */
54
+ what: "name" | "cell" | "column";
55
+ name: string;
56
+ sheet?: string;
57
+ value?: string;
58
+ };
59
+ /** A cell that breaks its data validation. */
60
+ "sheet-invalid": {
61
+ sheet: string;
62
+ cell: string;
63
+ value: string | number | boolean | null;
64
+ rule: string;
65
+ range: string;
66
+ };
67
+ /** A number the sheet's code typed that neither its data nor its code holds: what it computed, where a formula should. */
68
+ "sheet-typed": {
69
+ sheet: string;
70
+ cell: string;
71
+ value: number;
72
+ };
73
+ /** A sheet its code makes and sheet.yaml holds too: sheet.yaml's stands. */
74
+ "sheet-ordinary": {
75
+ sheet: string;
76
+ };
77
+ }
3
78
  export type SheetFactKind = keyof SheetFactData;
4
79
  export type SheetFinding = {
5
80
  [K in SheetFactKind]: {
@@ -1,4 +1,4 @@
1
- import { type ParsedCsv } from "./csv.js";
1
+ import { type ParsedCsv } from "@allyhub/formats";
2
2
  /** The file `csv` was read from, written again with `rows`, its first the header. */
3
3
  export declare function patchCsv(csv: ParsedCsv, rows: readonly (readonly string[])[]): string;
4
4
  //# sourceMappingURL=patch.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{csvRecord as y}from"./csv.js";const k=(c,t)=>{if(c.length===0)return"";const n=[];for(let o=0;o<t;o++)n.push(c[o]??"");return n.join("\0")},b=(c,t)=>k(c.end===c.start?[]:c.fields,t);export function patchCsv(c,t){const{dialect:n,records:o,source:u}=c,a=t.reduce((e,l)=>Math.max(e,l.length),0);if(t.length===0)return n.bom?"\uFEFF":"";const g=new Map;for(const e of o)g.set(e.fields,e);const h=new Set,i=new Array(t.length);t.forEach((e,l)=>{const s=g.get(e);s&&!h.has(s)&&(h.add(s),i[l]=u.slice(s.start,s.end))});let r;t.forEach((e,l)=>{if(i[l]!==void 0)return;if(!r){r=new Map;for(const f of o){if(h.has(f)||f.fields.length>a)continue;const m=b(f,a),p=r.get(m);p?p.push(f):r.set(m,[f])}}const s=r.get(k(e,a))?.shift();if(s){i[l]=u.slice(s.start,s.end);return}const d=[...e];for(;d.length<a;)d.push("");i[l]=e.length===0?"":y(d,n.delimiter)});const w=n.finalNewline||i[i.length-1]==="";return`${n.bom?"\uFEFF":""}${i.join(n.newline)}${w?n.newline:""}`}
2
+ import{csvRecord as y}from"@allyhub/formats";const k=(c,t)=>{if(c.length===0)return"";const n=[];for(let o=0;o<t;o++)n.push(c[o]??"");return n.join("\0")},b=(c,t)=>k(c.end===c.start?[]:c.fields,t);export function patchCsv(c,t){const{dialect:n,records:o,source:u}=c,a=t.reduce((e,l)=>Math.max(e,l.length),0);if(t.length===0)return n.bom?"\uFEFF":"";const g=new Map;for(const e of o)g.set(e.fields,e);const h=new Set,i=new Array(t.length);t.forEach((e,l)=>{const s=g.get(e);s&&!h.has(s)&&(h.add(s),i[l]=u.slice(s.start,s.end))});let r;t.forEach((e,l)=>{if(i[l]!==void 0)return;if(!r){r=new Map;for(const f of o){if(h.has(f)||f.fields.length>a)continue;const m=b(f,a),p=r.get(m);p?p.push(f):r.set(m,[f])}}const s=r.get(k(e,a))?.shift();if(s){i[l]=u.slice(s.start,s.end);return}const d=[...e];for(;d.length<a;)d.push("");i[l]=e.length===0?"":y(d,n.delimiter)});const w=n.finalNewline||i[i.length-1]==="";return`${n.bom?"\uFEFF":""}${i.join(n.newline)}${w?n.newline:""}`}
@@ -0,0 +1,2 @@
1
+ export { Alignment, AreaChart, AutoFilter, BLOCK_CELLS, BarChart, Comment, Image, PageMargins, PageSetup, Border, CAPABILITIES, Cell, CellIsRule, ChartBase, Color, ColorScaleRule, ColumnDimension, ConditionalFormattingList, DataBarRule, DataLabelList, DataValidation, DataValidationList, DefinedName, DefinedNameDict, DifferentialStyle, DoughnutChart, Font, FormulaRule, GraphicalProperties, IconSetRule, Legend, LineChart, LineProperties, Marker, NumericAxis, PatternFill, PieChart, Reference, RowDimension, Rule, Scaling, ScatterChart, Series, Side, Table, TableList, TextAxis, Workbook, Worksheet, column_index_from_string, coordinate_to_tuple, get_column_letter, load_workbook, range_boundaries, workbook, type AlignmentOptions, type BarChartOptions, type BorderOptions, type CellIsRuleOptions, type CellValue, type SheetCodeBuild, type SheetCodeContext, type ChartData, type ColorScaleRuleOptions, type DataBarRuleOptions, type DataValidationOptions, type DifferentialStyleOptions, type FontOptions, type FormulaRuleOptions, type LoadOptions, type PatternFillOptions, type ReferenceOptions, type RuleOptions, type SeriesOptions, type SideOptions, type TableInput, type TableOptions, } from "./api/index.js";
2
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ export{Alignment,AreaChart,AutoFilter,BLOCK_CELLS,BarChart,Comment,Image,PageMargins,PageSetup,Border,CAPABILITIES,Cell,CellIsRule,ChartBase,Color,ColorScaleRule,ColumnDimension,ConditionalFormattingList,DataBarRule,DataLabelList,DataValidation,DataValidationList,DefinedName,DefinedNameDict,DifferentialStyle,DoughnutChart,Font,FormulaRule,GraphicalProperties,IconSetRule,Legend,LineChart,LineProperties,Marker,NumericAxis,PatternFill,PieChart,Reference,RowDimension,Rule,Scaling,ScatterChart,Series,Side,Table,TableList,TextAxis,Workbook,Worksheet,column_index_from_string,coordinate_to_tuple,get_column_letter,load_workbook,range_boundaries,workbook}from"./api/index.js";
@@ -1,7 +1,7 @@
1
1
  import type { SheetChart, SheetConditional, SheetFile, SheetFilesColumn, SheetFilterColumn, SheetFormatEntry, SheetTable, SheetTableColumn, SheetValidation, SheetWorksheet } from "@allyhub/formats";
2
2
  import { rangeName, type Area, type Place } from "./address.js";
3
3
  import { type SheetProblem, type YamlPath } from "./file.js";
4
- import { type GeneratedSheets } from "./generated.js";
4
+ import { type GeneratedSheets } from "@allyhub/formats";
5
5
  import type { Node, ParseError } from "./formula/ast.js";
6
6
  import { CellError, type Matrix, type Scalar } from "./values.js";
7
7
  /** Where a value is written. */
@@ -160,7 +160,7 @@ export declare class Worksheet {
160
160
  /** Names that hold on this sheet alone, over the workbook's, in lower case. */
161
161
  readonly names: Map<string, DefinedName>;
162
162
  freeze: Place | undefined;
163
- /** sheet.ts makes it: what is on it is not changed by hand. */
163
+ /** The sheet's code makes it: what is on it is not changed by hand. */
164
164
  generated: boolean;
165
165
  private readonly grid;
166
166
  private expanded;
@@ -266,9 +266,9 @@ export declare class Workbook {
266
266
  private readonly bySheet;
267
267
  private readonly byTable;
268
268
  file: SheetFile;
269
- /** What sheet.ts makes: `file` holds it too. */
269
+ /** What the sheet's code makes: `file` holds it too. */
270
270
  readonly generated: GeneratedSheets | undefined;
271
- /** Sheets sheet.ts makes that sheet.yaml holds: sheet.yaml's stand. */
271
+ /** Sheets the code makes that sheet.yaml holds: sheet.yaml's stand. */
272
272
  ordinary: readonly string[];
273
273
  constructor(file: SheetFile, generated?: GeneratedSheets);
274
274
  /** sheet.yaml after an edit that changed no sheet, table or fill: the looks and the keys. */
@@ -291,7 +291,7 @@ export interface WorkbookFiles {
291
291
  text: string;
292
292
  /** A file's text, from the sheet's folder; undefined when it is not there. */
293
293
  read: (path: string) => string | undefined;
294
- /** What its sheet.ts makes. */
294
+ /** What its code makes. */
295
295
  generated?: GeneratedSheets | undefined;
296
296
  /** Whether a file is there, from the sheet's folder: what a `files` column names is looked for. */
297
297
  exists?: ((path: string) => boolean) | undefined;
@@ -301,7 +301,7 @@ export interface WorkbookValues {
301
301
  file: SheetFile;
302
302
  /** A CSV file's rows, from the sheet's folder; undefined when it is not there. */
303
303
  rows: (path: string) => CsvRows | undefined;
304
- /** What its sheet.ts makes. */
304
+ /** What its code makes. */
305
305
  generated?: GeneratedSheets | undefined;
306
306
  }
307
307
  export interface ReadWorkbook {
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_CODE as C,SHEET_SEPARATOR as P}from"@allyhub/formats";import{MAX_ROWS as B,cellName as H,columnIndex as z,columnLetter as j,contains as y,overlaps as v,rangeName as U,readAddress as x,readArea as $,readAreas as _}from"./address.js";import{readCsv as R}from"./csv.js";import{ENTRY as E,readSheetFile as D}from"./file.js";import{withGenerated as O}from"./generated.js";import{moveFormula as G}from"./formula/move.js";import{parseFormula as X}from"./formula/parse.js";import{printFormula as Y}from"./formula/print.js";import{readTyped as S}from"./values.js";export class SharedFormula{node;error;analysis;text;row;col;source;constructor(e,t,s,n){this.text=e,this.row=t,this.col=s,this.source=n;const i=X(e);i.ok?this.node=i.node:this.error=i.error}}export class FormulaCell{value=null;array;spill;blocked;state=1;mark=0;shared;sheet;row;col;constructor(e,t,s,n){this.shared=e,this.sheet=t,this.row=s,this.col=n}get moved(){const{node:e,row:t,col:s}=this.shared;if(!e)throw new Error(`${this.shared.text} does not parse.`);return G(e,this.row-t,this.col-s)}get text(){const{node:e,text:t,row:s,col:n}=this.shared;return!e||s===this.row&&n===this.col?t:Y(this.moved)}}class Z{columns=[];firsts=[];lasts=[];formulas=[];get(e,t){return this.columns[t]?.[e]}set(e,t,s){let n=this.columns[t];n||(n=[],this.columns[t]=n,this.firsts[t]=e,this.lasts[t]=e),n[e]instanceof FormulaCell&&(this.formulas[t]=(this.formulas[t]??1)-1),s instanceof FormulaCell&&(this.formulas[t]=(this.formulas[t]??0)+1),n[e]=s,e<(this.firsts[t]??e)&&(this.firsts[t]=e),e>(this.lasts[t]??e)&&(this.lasts[t]=e)}get width(){return this.columns.length}holds(e,t,s){const n=Math.min(e.right,this.columns.length-1);for(let i=e.left;i<=n;i++){const a=this.columns[i];if(!a)continue;const r=Math.min(e.bottom,this.last(i));for(let o=Math.max(e.top,this.first(i));o<=r;o++)if(a[o]!==void 0&&!(o===t&&i===s))return!0}return!1}first(e){return this.firsts[e]??1/0}last(e){return this.lasts[e]??-1}hasFormulas(e){return(this.formulas[e]??0)>0}}export class Table{columns=[];rows=0;lines=[];places=[];records=[];name;sheet;at;file;spec;constructor(e,t,s,n,i){this.name=e,this.sheet=t,this.at=s,this.file=n,this.spec=i}get area(){return{top:this.at.row,left:this.at.col,bottom:this.at.row+this.rows,right:this.at.col+Math.max(this.columns.length,1)-1}}get data(){const e=this.area;return{...e,top:e.top+1}}column(e){const t=e.toLowerCase();return this.columns.find(s=>s.name.toLowerCase()===t)}}export const placeKey=(l,e)=>l*16384+e;function T(l,e){l.bottom=Math.max(l.bottom,e.bottom),l.right=Math.max(l.right,e.right);for(let t=e.left;t<=e.right;t++){const s=l.columns.get(t);l.columns.set(t,[Math.min(s?.[0]??e.top,e.top),Math.max(s?.[1]??e.bottom,e.bottom)])}}export class Worksheet{tables=[];blocks=[];merges=[];formulas=new Set;implied=new Map;keys=new Map;fills=[];blanks=new Set;conditions=[];validations=[];filters=[];charts=[];names=new Map;freeze;generated=!1;grid=new Z;expanded=!1;lowest=-1;ghosts=new Map;spills=new Set;stopped=new Set;reach;lookAreas;name;index;spec;constructor(e,t,s){this.name=e,this.index=t,this.spec=s}respec(e){const t=e.charts!==this.spec.charts;this.spec=e,this.lookAreas=void 0,t&&(this.charts.length=0,e.charts?.forEach((s,n)=>{const i=W(s,n,[],()=>{});i&&this.charts.push(i)}))}put(e,t,s){s instanceof FormulaCell&&this.formulas.add(s),this.grid.set(e,t,s),e>this.lowest&&(this.lowest=e)}replace(e,t,s){this.expand();const n=this.grid.get(e,t);n instanceof FormulaCell&&this.formulas.delete(n),s instanceof FormulaCell&&this.formulas.add(s),this.grid.set(e,t,s),e>this.lowest&&(this.lowest=e)}expand(){if(!this.expanded){this.expanded=!0;for(let e=this.fills.length-1;e>=0;e--){const t=this.fills[e];if(!t)continue;const{area:s,shared:n,value:i,format:a}=t;for(let r=s.top;r<=s.bottom;r++)for(let o=s.left;o<=s.right;o++)this.grid.get(r,o)===void 0&&(this.blanks.has(placeKey(r,o))||(n?this.put(r,o,new FormulaCell(n,this,r,o)):i!=null&&(this.put(r,o,i),a!==void 0&&this.implied.set(placeKey(r,o),a))))}}}at(e,t){return this.expand(),this.grid.get(e,t)}spillAt(e,t){return this.ghosts.size===0?void 0:this.ghosts.get(placeKey(e,t))}holds(e,t){return this.expand(),this.grid.holds(e,t.row,t.col)}spillsIn(e){if(this.spills.size===0)return[];if((e.bottom-e.top+1)*(e.right-e.left+1)>=this.spills.size)return[...this.spills].filter(n=>n.spill!==void 0&&v(n.spill,e));const s=new Set;for(let n=e.top;n<=e.bottom;n++)for(let i=e.left;i<=e.right;i++){const a=this.ghosts.get(placeKey(n,i));a&&s.add(a)}return[...s]}blockedBy(e){if(this.stopped.size===0)return[];const t=[];for(const s of this.stopped)s.blocked&&v(s.blocked,e)&&t.push(s);return t}placeSpill(e,t){e.spill=t,this.spills.add(e);for(let s=t.top;s<=t.bottom;s++)for(let n=t.left;n<=t.right;n++)(s!==e.row||n!==e.col)&&this.ghosts.set(placeKey(s,n),e);this.reach&&T(this.reach,t)}blockSpill(e,t){e.blocked=t,this.stopped.add(e)}clearSpill(e){const t=e.spill;if(t)for(let s=t.top;s<=t.bottom;s++)for(let n=t.left;n<=t.right;n++)this.ghosts.get(placeKey(s,n))===e&&this.ghosts.delete(placeKey(s,n));e.spill=void 0,e.blocked=void 0,this.spills.delete(e),this.stopped.delete(e)}clearSpills(){for(const e of[...this.spills,...this.stopped])e.spill=void 0,e.blocked=void 0;this.spills.clear(),this.stopped.clear(),this.ghosts.clear(),this.reach=void 0}tighten(){this.reach=void 0}spillReach(){if(this.reach)return this.reach;const e={columns:new Map,bottom:-1,right:-1};for(const{spill:t}of this.spills)t&&T(e,t);return this.reach=e,e}hasFormulas(e){return this.expand(),this.grid.hasFormulas(e)}span(e,t,s){this.expand();const n=this.grid.first(e),i=this.grid.last(e);if(this.spills.size===0)return[Math.max(t,n),Math.min(s,i)];const[a,r]=this.spillReach().columns.get(e)??[1/0,-1];return[Math.max(t,Math.min(n,a)),Math.min(s,Math.max(i,r))]}get columnsUsed(){return this.expand(),this.spills.size===0?this.grid.width:Math.max(this.grid.width,this.spillReach().right+1)}get lastRow(){return this.expand(),this.spills.size===0?this.lowest:Math.max(this.lowest,this.spillReach().bottom)}get used(){const e=this.lastRow,t=this.columnsUsed-1;return e<0||t<0?void 0:{top:0,left:0,bottom:e,right:t}}tableAt(e,t){return this.tables.find(s=>y(s.area,e,t))}blockAt(e,t){return this.blocks.find(s=>y(s.area,e,t))}looks(){if(this.lookAreas)return this.lookAreas;const e=[];for(const s of this.spec.format??[]){const n=$(s.range);n&&e.push({area:n,entry:s})}const t=[];for(const[s,n]of Object.entries(this.spec.cells??{})){if(!s.includes(":")||n===null||typeof n!="object")continue;const i=$(s);i&&t.push({area:i,entry:n})}return this.lookAreas={formats:e,ranges:t},this.lookAreas}styledAreas(){const{formats:e,ranges:t}=this.looks();return[...e,...t.filter(s=>Object.keys(s.entry).some(n=>F.has(n)))]}lookAt(e,t){const s={},n=c=>{if(c)for(const[b,w]of Object.entries(c))F.has(b)&&w!==void 0&&(s[b]=b==="border"?{...s.border,...w}:w)},i=this.implied.get(placeKey(e,t));i!==void 0&&(s.format=i);const a=this.ghosts.size===0?void 0:this.spillAt(e,t),r=a&&this.lookAt(a.row,a.col).format;r!==void 0&&(s.format=r),this.spec.columns&&n(this.spec.columns[j(t)]),this.spec.rows&&n(this.spec.rows[String(e+1)]);const o=this.tableAt(e,t);o&&e>o.at.row&&n(o.columns[t-o.at.col]?.spec);const{formats:f,ranges:h}=this.looks();for(const c of f)y(c.area,e,t)&&n(c.entry);for(const c of h)y(c.area,e,t)&&n(c.entry);const d=this.keys.get(placeKey(e,t)),g=d===void 0?void 0:this.spec.cells?.[d];if(g!==null&&typeof g=="object"&&n(g),s.border){const c=Object.entries(s.border).filter(([,b])=>b?.style!=="none");c.length===0?delete s.border:s.border=Object.fromEntries(c)}return s}mergeAt(e,t){return this.merges.find(s=>y(s,e,t))}validationAt(e,t){return this.validations.find(s=>s.areas.some(n=>y(n,e,t)))}filterHeadAt(e,t){return this.filters.find(s=>e===s.area.top&&t>=s.area.left&&t<=s.area.right)}filterAt(e,t){return this.filters.find(s=>y(s.area,e,t))}filesAt(e,t){const s=this.tableAt(e,t);if(s&&e>s.at.row){const n=s.columns[t-s.at.col]?.spec?.files;if(n!==void 0)return n}return s?.at.row===e?void 0:this.spec.columns?.[j(t)]?.files}}export const filesSeparator=l=>(typeof l=="object"?l.separator:void 0)??P;export function filesIn(l,e){const t=filesSeparator(e);return l.split(t.trim()===""?t:t.trim()).map(s=>s.trim()).filter(s=>s!=="")}const F=new Set(["bold","italic","underline","strike","font","size","color","fill","align","valign","wrap","shrink","indent","rotation","border","format"]);export class Workbook{title;sheets=[];names=new Map;checks=[];bySheet=new Map;byTable=new Map;file;generated;ordinary=[];constructor(e,t){this.file=e,this.title=e.title,this.generated=t}respec(e){this.file=O(e,this.generated).file,this.title=e.title,this.sheets.forEach(t=>{const s=e.sheets.find(n=>n.name===t.name);s&&t.respec(s)})}sheet(e){return this.bySheet.get(e.toLowerCase())}table(e){return this.byTable.get(e.toLowerCase())}name(e,t){const s=e.toLowerCase();return(t?.names.size?t.names.get(s):void 0)??this.names.get(s)}definitions(e){const t=e.toLowerCase(),s=[],n=this.names.get(t);n&&s.push(n);for(const i of this.sheets){const a=i.names.get(t);a&&s.push(a)}return s}get tables(){return[...this.byTable.values()]}addSheet(e){this.sheets.push(e),this.bySheet.set(e.name.toLowerCase(),e)}addTable(e){e.sheet.tables.push(e),this.byTable.set(e.name.toLowerCase(),e)}sourceOf(e,t,s){if(e.generated)return{file:C};const n=this.sheets.indexOf(e),i=e.tableAt(t,s);if(i){const o=i.columns[s-i.at.col],f=t-i.at.row-1,h=o?.csv!==void 0&&(i.records[f]?.[o.csv]??"")!=="";return f>=0&&o?.formula&&!h?o.formula.source:{file:i.file,line:f<0?1:i.lines[f]??1}}const a=e.blockAt(t,s);if(a)return{file:a.file,line:a.lines[t-a.area.top]??1};const r=e.keys.get(placeKey(t,s));if(r!==void 0)return{file:E,path:["sheets",n,"cells",r]};for(const o of Object.keys(e.spec.cells??{})){if(!o.includes(":"))continue;const f=$(o);if(f&&y(f,t,s))return{file:E,path:["sheets",n,"cells",o]}}}}export const MAX_FILL_CELLS=5e6;const q=/^[\p{L}_\\][\p{L}\p{N}_.\\?]*$/u;export function validName(l){return q.test(l)&&x(l)===void 0&&!/^(?:TRUE|FALSE)$/iu.test(l)&&!/^[Rr](?:\d+)?(?:[Cc]\d*)?$/u.test(l)&&!/^[Cc]\d*$/u.test(l)}const M="made",k=l=>l[0]===M?C:E;class N{problems=[];wb;read_;lineOf;own;madeNames;constructor(e,t,s,n,i){this.wb=e,this.read_=t,this.lineOf=s,this.own=n,this.madeNames=i}yaml(e,t){const s=this.lineOf(e);this.problems.push({file:k(e),...s===void 0?{}:{line:s},message:t})}sheetPath(e){return e<this.own?["sheets",e]:[M,"sheets",e-this.own]}read(){const{file:e}=this.wb;e.sheets.forEach((t,s)=>{const n=this.sheetPath(s);if(this.wb.sheet(t.name)){this.yaml([...n,"name"],`two sheets are named ${t.name}`);return}(/[\\/?*[\]:]/u.test(t.name)||t.name.length>31)&&this.yaml([...n,"name"],`${t.name} cannot be a sheet's name: at most 31 characters, none of \\ / ? * [ ] :`);const i=new Worksheet(t.name,this.wb.sheets.length,t);i.generated=s>=this.own,this.wb.addSheet(i)}),this.names();for(const[t,s]of e.sheets.entries()){const n=this.wb.sheets[t];n?.spec===s&&this.sheet(n,this.sheetPath(t))}e.checks?.forEach((t,s)=>{const n={file:E,path:["checks",s,"formula"]};this.wb.checks.push({name:t.name,formula:new SharedFormula(t.formula,0,0,n),source:n})})}names(){const{file:e}=this.wb;this.namesOf(e.names,e.hidden_names,t=>this.madeNames.has(t)?[M,"names",t]:["names",t],this.wb.names,void 0),e.sheets.forEach((t,s)=>{const n=this.wb.sheets[s];n?.spec===t&&this.namesOf(t.names,t.hidden_names,i=>[...this.sheetPath(s),"names",i],n.names,n)})}namesOf(e,t,s,n,i){const a=new Set(t?.map(r=>r.toLowerCase()));for(const[r,o]of Object.entries(e??{})){const f=s(r);if(!validName(r)){this.yaml(f,`${r} cannot be a name`);continue}const h={file:k(f),path:f},d=typeof o=="string"&&o.startsWith("=")?{name:r,formula:new SharedFormula(o,0,0,h),source:h}:{name:r,value:typeof o=="string"?S(o).value:o,source:h};i&&(d.sheet=i),a.has(r.toLowerCase())&&(d.hidden=!0),n.set(r.toLowerCase(),d)}}sheet(e,t){const{spec:s}=e;if(s.freeze!==void 0){const n=x(s.freeze);n?e.freeze=n:this.yaml([...t,"freeze"],`${s.freeze} is not a cell`)}s.tables?.forEach((n,i)=>{this.table(e,n,[...t,"tables",i])});for(const[n,i]of e.tables.entries())for(const a of e.tables.slice(n+1))v(i.area,a.area)&&this.problems.push({file:E,message:`tables ${i.name} and ${a.name} overlap on ${e.name}`});s.blocks?.forEach((n,i)=>{this.block(e,n.at,n.rows,[...t,"blocks",i])}),this.cells(e,s.cells??{},[...t,"cells"]),s.merges?.forEach((n,i)=>{const a=$(n);a?e.merges.push(a):this.yaml([...t,"merges",i],`${n} is not a range`)}),s.format?.forEach((n,i)=>{$(n.range)||this.yaml([...t,"format",i,"range"],`${n.range} is not a range`)}),s.conditional?.forEach((n,i)=>{this.condition(e,n,[...t,"conditional",i])}),s.validations?.forEach((n,i)=>{this.validation(e,n,[...t,"validations",i])}),this.filters(e,t),s.charts?.forEach((n,i)=>{this.chart(e,n,i,[...t,"charts",i])});for(const n of Object.keys(s.columns??{}))z(n)===void 0&&this.yaml([...t,"columns",n],`${n} is not a column`);for(const n of Object.keys(s.rows??{}))(!/^[1-9]\d*$/u.test(n)||Number(n)>B)&&this.yaml([...t,"rows",n],`${n} is not a row`)}chart(e,t,s,n){const i=W(t,s,n,(a,r)=>{this.yaml(a,r)});i&&e.charts.push(i)}bound(e,t,s){if(!(typeof e!="string"||!e.startsWith("=")||e.length<2))return new SharedFormula(e,t?.top??0,t?.left??0,{file:k(s),path:s})}condition(e,t,s){const n=_(t.range);if(!n){this.yaml([...s,"range"],`${t.range} is not a range`);return}const[i]=n,a=[],r=(o,f)=>{const h=this.bound(o,i,f);h&&a.push(h)};if(t.type==="expression"){const o=t.formula.startsWith("=")?t.formula:`=${t.formula}`;r(o,[...s,"formula"])}if(t.type==="cellIs"&&t.formula.forEach((o,f)=>{r(o,[...s,"formula",f])}),t.type==="dataBar")for(const o of["min","max"])r(t[o]?.value,[...s,o,"value"]);(t.type==="colorScale"||t.type==="iconSet")&&t.stops?.forEach((o,f)=>{r(o.value,[...s,"stops",f,"value"])}),e.conditions.push({spec:t,areas:n,formulas:a})}validation(e,t,s){const n=_(t.range);if(!n){this.yaml([...s,"range"],`${t.range} is not a range`);return}const i=(t.formula??[]).map((o,f)=>this.bound(o,n[0],[...s,"formula",f])),a=t.formula?.length??0,r=t.type!=="list"&&t.type!=="custom"&&(t.operator===void 0||t.operator==="between"||t.operator==="notBetween");!(t.type==="list"&&t.values!==void 0)&&a<(r?2:1)&&this.yaml(s,`a ${t.type} validation needs its bounds`),e.validations.push({spec:t,areas:n,formulas:i})}filters(e,t){const{spec:s}=e;if(s.filter){const n=[...t,"filter"],i=$(s.filter.range);if(!i)this.yaml([...n,"range"],`${s.filter.range} is not a range`);else{const a=new Map;for(const[o,f]of Object.entries(s.filter.columns??{})){const h=z(o);h===void 0||h<i.left||h>i.right?this.yaml([...n,"columns",o],`${o} is not a column of ${s.filter.range}`):a.set(h,f)}const r=e.tables.find(o=>v(o.area,i));r&&this.yaml(n,`a filter over table ${r.name}: a table has its own`),e.filters.push({area:i,columns:a})}}e.tables.forEach((n,i)=>{const{filter:a}=n.spec;if(a===!1)return;const r=new Map;for(const[o,f]of Object.entries(a?.columns??{})){const h=n.column(o);h?r.set(n.at.col+h.index,f):this.yaml([...t,"tables",i,"filter","columns",o],`table ${n.name} has no column ${o}`)}e.filters.push({area:n.area,table:n,columns:r})})}csv(e,t,s){const n=this.read_(e);return n||this.yaml(t,`${s}: ${e} is not there`),n}overlapping(e,t){const s=e.tables.find(i=>v(i.area,t));if(s)return`table ${s.name}`;const n=e.blocks.find(i=>v(i.area,t));return n?`the block of ${n.file}`:void 0}typed(e,t,s,n,i){if(n.formula!==void 0){const a=new SharedFormula(n.formula,t,s,i);e.put(t,s,new FormulaCell(a,e,t,s));return}n.value!==null&&(e.put(t,s,n.value),n.format!==void 0&&e.implied.set(placeKey(t,s),n.format))}table(e,t,s){const n=x(t.at);if(!n){this.yaml([...s,"at"],`${t.at} is not a cell`);return}if(!validName(t.name)){this.yaml([...s,"name"],`${t.name} cannot be a table's name`);return}if(this.wb.table(t.name)){this.yaml([...s,"name"],`two tables are named ${t.name}`);return}this.wb.name(t.name)&&this.yaml([...s,"name"],`${t.name} is a defined name and a table's`);const i=new Table(t.name,e,n,t.rows,t),a=this.csv(t.rows,[...s,"rows"],`table ${t.name}`),r=a?.rows??[],o=a?.lines??[],f=r[0],h=o[0]??1,d=new Set,g=f?.length===0?[""]:f??[];g.forEach((u,m)=>{const p=u.trim();p===""&&this.problems.push({file:t.rows,line:h,message:`column ${String(m+1)} has no name`}),d.has(p.toLowerCase())&&this.problems.push({file:t.rows,line:h,message:`two columns are named ${p}`}),d.add(p.toLowerCase()),i.columns.push({name:p,index:i.columns.length,csv:m})});for(const[u,m]of Object.entries(t.columns??{})){const p=i.column(u),A=p??{name:u,index:i.columns.length};p||(m.formula===void 0&&this.yaml([...s,"columns",u],`table ${t.name} has no column ${u}`),i.columns.push(A)),A.spec=m}const c=g.length;for(let u=1;u<r.length;u++){const m=r[u];if(!m||m.length===0)continue;const p=o[u]??u+1;i.places.push(u),i.records.push(m),i.lines.push(p),m.length>c&&this.problems.push({file:t.rows,line:p,message:`this row has ${String(m.length)} fields and the header ${String(c)}`})}i.rows=i.records.length;const b=this.overlapping(e,i.area);b&&this.yaml(s,`table ${t.name} overlaps ${b} on ${e.name}`),this.wb.addTable(i),this.tableKey(i,s);const w=n.row+1;i.columns.forEach(u=>{const m=n.col+u.index;e.put(n.row,m,u.name);const p=u.spec?.formula;p!==void 0&&(u.formula=new SharedFormula(p,w,m,{file:k(s),path:[...s,"columns",u.name,"formula"]}),i.rows>0&&e.fills.push({area:{top:w,left:m,bottom:w+i.rows-1,right:m},shared:u.formula})),u.csv!==void 0&&i.records.forEach((A,L)=>{this.typed(e,w+L,m,S(A[u.csv??0]??""),{file:t.rows,line:i.lines[L]??1})})})}tableKey(e,t){const{key:s}=e.spec;if(s===void 0)return;const n=e.column(s);if(n?.csv===void 0){this.yaml([...t,"key"],`table ${e.name} has no column ${s} in ${e.file}`);return}const i=new Set;e.records.forEach((a,r)=>{const o=a[n.csv??0]??"",f=e.lines[r]??1;o===""?this.problems.push({file:e.file,line:f,message:`this row has no ${s}, table ${e.name}'s key`}):i.has(o)&&this.problems.push({file:e.file,line:f,message:`two rows have the key ${o}`}),i.add(o)})}block(e,t,s,n){const i=x(t);if(!i){this.yaml([...n,"at"],`${t} is not a cell`);return}const a=this.csv(s,[...n,"rows"],"a block");if(!a)return;const r=a.rows,o=r.map((g,c)=>a.lines[c]??c+1),f=r.reduce((g,c)=>Math.max(g,c.length),1),h={top:i.row,left:i.col,bottom:i.row+Math.max(r.length,1)-1,right:i.col+f-1},d=this.overlapping(e,h);d&&this.yaml(n,`the block of ${s} overlaps ${d} on ${e.name}`),e.blocks.push({area:h,file:s,lines:o}),r.forEach((g,c)=>{g.forEach((b,w)=>{this.typed(e,i.row+c,i.col+w,S(b),{file:s,line:o[c]??c+1})})})}cells(e,t,s){const n=[];for(const[i,a]of Object.entries(t)){const r=[...s,i],o=$(i);if(!o){this.yaml(r,`${i} is not a cell or a range`);continue}const f=this.overlapping(e,o);if(f&&this.yaml(r,`${i} overlaps ${f}`),i.includes(":")){const h=(o.bottom-o.top+1)*(o.right-o.left+1);h>MAX_FILL_CELLS?this.yaml(r,`${i} is ${String(h)} cells`):this.fill(e,o,a,r)}else n.push([i,a,{row:o.top,col:o.left}])}for(const[i,a,r]of n){const o=[...s,i],f=K(a),h=placeKey(r.row,r.col);e.keys.set(h,i),f.value===null&&f.formula===void 0&&e.blanks.add(h),this.typed(e,r.row,r.col,f,{file:k(o),path:o});const d=a!==null&&typeof a=="object"?a.name:void 0;d!==void 0&&this.cellName(e,r,d,o)}}cellName(e,t,s,n){if(!validName(s)){this.yaml(n,`${s} cannot be a name`);return}if(this.wb.name(s)){this.yaml(n,`two places are named ${s}`);return}const i={file:k(n),path:n},a=H(t).replace(/^([A-Z]+)(\d+)$/u,"$$$1$$$2"),r=`='${e.name.replaceAll("'","''")}'!${a}`;this.wb.names.set(s.toLowerCase(),{name:s,formula:new SharedFormula(r,0,0,i),source:i})}fill(e,t,s,n){const i=K(s),a={file:k(n),path:n};e.fills.push(i.formula===void 0?{area:t,value:i.value,...i.format===void 0?{}:{format:i.format}}:{area:t,shared:new SharedFormula(i.formula,t.top,t.left,a)})}}function W(l,e,t,s){const n=x(l.at);if(!n){s([...t,"at"],`${l.at} is not a cell`);return}const i=(o,f)=>{const h=new SharedFormula(chartFormula(o),0,0,{file:k(f),path:f});return h.node&&!I(h.node)&&s(f,`${o} is not a range or a table's column`),h},a=(o,f)=>o?.startsWith("=")===!0?i(o,f):void 0,r=a(l.title,[...t,"title"]);return{spec:l,at:n,index:e,...l.categories===void 0?{}:{categories:i(l.categories,[...t,"categories"])},...r?{title:r}:{},series:l.series.map((o,f)=>{const h=[...t,"series",f],d=a(o.name,[...h,"name"]);return{values:i(o.values,[...h,"values"]),...o.x===void 0?{}:{x:i(o.x,[...h,"x"])},...d?{name:d}:{}}})}}export const chartFormula=l=>l.startsWith("=")?l:`=${l}`;function I(l){switch(l.kind){case"error":case"ref":case"structured":case"name":return!0;case"paren":case"postfix":return I(l.arg);case"binary":return l.op===":"||l.op===",";default:return!1}}function K(l){if(l===null)return{value:null};if(typeof l=="string")return S(l);if(typeof l!="object")return{value:l};if(l.formula!==void 0)return{value:null,formula:l.formula.startsWith("=")?l.formula:`=${l.formula}`};const{value:e}=l;return typeof e=="string"?S(e):{value:e??null}}export function readWorkbook(l){const e=D(l.text),t=r=>r[0]===M?void 0:e.lineOf(r);if(!e.file)return{problems:e.problems,lineOf:t};const s=O(e.file,l.generated),n=new Workbook(s.file,l.generated);n.ordinary=s.ordinary;const i=[],a=new N(n,r=>{const o=l.generated?.csv[r]??l.read(r);if(o===void 0)return;const f=R(o);for(const h of f.problems)i.push({file:r,line:h.line,message:h.message});return{rows:f.records.map(h=>h.end===h.start?[]:h.fields),lines:f.records.map(h=>h.line)}},t,s.own,s.names);return a.read(),{workbook:n,problems:[...i,...a.problems],lineOf:t}}export function workbookOf(l){const e=O(l.file,l.generated),t=new Workbook(e.file,l.generated);return t.ordinary=e.ordinary,new N(t,s=>{const n=l.generated?.csv[s];if(n!==void 0)return{rows:R(n).records.map(a=>a.end===a.start?[]:a.fields),lines:[]};const i=l.rows(s);return i&&{rows:i,lines:[]}},()=>{},e.own,e.names).read(),t}export{U as rangeName};
2
+ import{SHEET_SEPARATOR as P}from"@allyhub/formats";import{MAX_ROWS as B,cellName as U,columnIndex as C,columnLetter as z,contains as y,overlaps as v,rangeName as D,readAddress as x,readArea as $,readAreas as j}from"./address.js";import{readCsv as _}from"@allyhub/formats";import{CODE as R,ENTRY as E,readSheetFile as G}from"./file.js";import{withGenerated as O}from"./generated.js";import"@allyhub/formats";import{moveFormula as H}from"./formula/move.js";import{parseFormula as X}from"./formula/parse.js";import{printFormula as Y}from"./formula/print.js";import{readTyped as A}from"./values.js";export class SharedFormula{node;error;analysis;text;row;col;source;constructor(e,t,s,n){this.text=e,this.row=t,this.col=s,this.source=n;const i=X(e);i.ok?this.node=i.node:this.error=i.error}}export class FormulaCell{value=null;array;spill;blocked;state=1;mark=0;shared;sheet;row;col;constructor(e,t,s,n){this.shared=e,this.sheet=t,this.row=s,this.col=n}get moved(){const{node:e,row:t,col:s}=this.shared;if(!e)throw new Error(`${this.shared.text} does not parse.`);return H(e,this.row-t,this.col-s)}get text(){const{node:e,text:t,row:s,col:n}=this.shared;return!e||s===this.row&&n===this.col?t:Y(this.moved)}}class Z{columns=[];firsts=[];lasts=[];formulas=[];get(e,t){return this.columns[t]?.[e]}set(e,t,s){let n=this.columns[t];n||(n=[],this.columns[t]=n,this.firsts[t]=e,this.lasts[t]=e),n[e]instanceof FormulaCell&&(this.formulas[t]=(this.formulas[t]??1)-1),s instanceof FormulaCell&&(this.formulas[t]=(this.formulas[t]??0)+1),n[e]=s,e<(this.firsts[t]??e)&&(this.firsts[t]=e),e>(this.lasts[t]??e)&&(this.lasts[t]=e)}get width(){return this.columns.length}holds(e,t,s){const n=Math.min(e.right,this.columns.length-1);for(let i=e.left;i<=n;i++){const a=this.columns[i];if(!a)continue;const r=Math.min(e.bottom,this.last(i));for(let o=Math.max(e.top,this.first(i));o<=r;o++)if(a[o]!==void 0&&!(o===t&&i===s))return!0}return!1}first(e){return this.firsts[e]??1/0}last(e){return this.lasts[e]??-1}hasFormulas(e){return(this.formulas[e]??0)>0}}export class Table{columns=[];rows=0;lines=[];places=[];records=[];name;sheet;at;file;spec;constructor(e,t,s,n,i){this.name=e,this.sheet=t,this.at=s,this.file=n,this.spec=i}get area(){return{top:this.at.row,left:this.at.col,bottom:this.at.row+this.rows,right:this.at.col+Math.max(this.columns.length,1)-1}}get data(){const e=this.area;return{...e,top:e.top+1}}column(e){const t=e.toLowerCase();return this.columns.find(s=>s.name.toLowerCase()===t)}}export const placeKey=(l,e)=>l*16384+e;function F(l,e){l.bottom=Math.max(l.bottom,e.bottom),l.right=Math.max(l.right,e.right);for(let t=e.left;t<=e.right;t++){const s=l.columns.get(t);l.columns.set(t,[Math.min(s?.[0]??e.top,e.top),Math.max(s?.[1]??e.bottom,e.bottom)])}}export class Worksheet{tables=[];blocks=[];merges=[];formulas=new Set;implied=new Map;keys=new Map;fills=[];blanks=new Set;conditions=[];validations=[];filters=[];charts=[];names=new Map;freeze;generated=!1;grid=new Z;expanded=!1;lowest=-1;ghosts=new Map;spills=new Set;stopped=new Set;reach;lookAreas;name;index;spec;constructor(e,t,s){this.name=e,this.index=t,this.spec=s}respec(e){const t=e.charts!==this.spec.charts;this.spec=e,this.lookAreas=void 0,t&&(this.charts.length=0,e.charts?.forEach((s,n)=>{const i=W(s,n,[],()=>{});i&&this.charts.push(i)}))}put(e,t,s){s instanceof FormulaCell&&this.formulas.add(s),this.grid.set(e,t,s),e>this.lowest&&(this.lowest=e)}replace(e,t,s){this.expand();const n=this.grid.get(e,t);n instanceof FormulaCell&&this.formulas.delete(n),s instanceof FormulaCell&&this.formulas.add(s),this.grid.set(e,t,s),e>this.lowest&&(this.lowest=e)}expand(){if(!this.expanded){this.expanded=!0;for(let e=this.fills.length-1;e>=0;e--){const t=this.fills[e];if(!t)continue;const{area:s,shared:n,value:i,format:a}=t;for(let r=s.top;r<=s.bottom;r++)for(let o=s.left;o<=s.right;o++)this.grid.get(r,o)===void 0&&(this.blanks.has(placeKey(r,o))||(n?this.put(r,o,new FormulaCell(n,this,r,o)):i!=null&&(this.put(r,o,i),a!==void 0&&this.implied.set(placeKey(r,o),a))))}}}at(e,t){return this.expand(),this.grid.get(e,t)}spillAt(e,t){return this.ghosts.size===0?void 0:this.ghosts.get(placeKey(e,t))}holds(e,t){return this.expand(),this.grid.holds(e,t.row,t.col)}spillsIn(e){if(this.spills.size===0)return[];if((e.bottom-e.top+1)*(e.right-e.left+1)>=this.spills.size)return[...this.spills].filter(n=>n.spill!==void 0&&v(n.spill,e));const s=new Set;for(let n=e.top;n<=e.bottom;n++)for(let i=e.left;i<=e.right;i++){const a=this.ghosts.get(placeKey(n,i));a&&s.add(a)}return[...s]}blockedBy(e){if(this.stopped.size===0)return[];const t=[];for(const s of this.stopped)s.blocked&&v(s.blocked,e)&&t.push(s);return t}placeSpill(e,t){e.spill=t,this.spills.add(e);for(let s=t.top;s<=t.bottom;s++)for(let n=t.left;n<=t.right;n++)(s!==e.row||n!==e.col)&&this.ghosts.set(placeKey(s,n),e);this.reach&&F(this.reach,t)}blockSpill(e,t){e.blocked=t,this.stopped.add(e)}clearSpill(e){const t=e.spill;if(t)for(let s=t.top;s<=t.bottom;s++)for(let n=t.left;n<=t.right;n++)this.ghosts.get(placeKey(s,n))===e&&this.ghosts.delete(placeKey(s,n));e.spill=void 0,e.blocked=void 0,this.spills.delete(e),this.stopped.delete(e)}clearSpills(){for(const e of[...this.spills,...this.stopped])e.spill=void 0,e.blocked=void 0;this.spills.clear(),this.stopped.clear(),this.ghosts.clear(),this.reach=void 0}tighten(){this.reach=void 0}spillReach(){if(this.reach)return this.reach;const e={columns:new Map,bottom:-1,right:-1};for(const{spill:t}of this.spills)t&&F(e,t);return this.reach=e,e}hasFormulas(e){return this.expand(),this.grid.hasFormulas(e)}span(e,t,s){this.expand();const n=this.grid.first(e),i=this.grid.last(e);if(this.spills.size===0)return[Math.max(t,n),Math.min(s,i)];const[a,r]=this.spillReach().columns.get(e)??[1/0,-1];return[Math.max(t,Math.min(n,a)),Math.min(s,Math.max(i,r))]}get columnsUsed(){return this.expand(),this.spills.size===0?this.grid.width:Math.max(this.grid.width,this.spillReach().right+1)}get lastRow(){return this.expand(),this.spills.size===0?this.lowest:Math.max(this.lowest,this.spillReach().bottom)}get used(){const e=this.lastRow,t=this.columnsUsed-1;return e<0||t<0?void 0:{top:0,left:0,bottom:e,right:t}}tableAt(e,t){return this.tables.find(s=>y(s.area,e,t))}blockAt(e,t){return this.blocks.find(s=>y(s.area,e,t))}looks(){if(this.lookAreas)return this.lookAreas;const e=[];for(const s of this.spec.format??[]){const n=$(s.range);n&&e.push({area:n,entry:s})}const t=[];for(const[s,n]of Object.entries(this.spec.cells??{})){if(!s.includes(":")||n===null||typeof n!="object")continue;const i=$(s);i&&t.push({area:i,entry:n})}return this.lookAreas={formats:e,ranges:t},this.lookAreas}styledAreas(){const{formats:e,ranges:t}=this.looks();return[...e,...t.filter(s=>Object.keys(s.entry).some(n=>N.has(n)))]}lookAt(e,t){const s={},n=c=>{if(c)for(const[b,w]of Object.entries(c))N.has(b)&&w!==void 0&&(s[b]=b==="border"?{...s.border,...w}:w)},i=this.implied.get(placeKey(e,t));i!==void 0&&(s.format=i);const a=this.ghosts.size===0?void 0:this.spillAt(e,t),r=a&&this.lookAt(a.row,a.col).format;r!==void 0&&(s.format=r),this.spec.columns&&n(this.spec.columns[z(t)]),this.spec.rows&&n(this.spec.rows[String(e+1)]);const o=this.tableAt(e,t);o&&e>o.at.row&&n(o.columns[t-o.at.col]?.spec);const{formats:f,ranges:h}=this.looks();for(const c of f)y(c.area,e,t)&&n(c.entry);for(const c of h)y(c.area,e,t)&&n(c.entry);const d=this.keys.get(placeKey(e,t)),g=d===void 0?void 0:this.spec.cells?.[d];if(g!==null&&typeof g=="object"&&n(g),s.border){const c=Object.entries(s.border).filter(([,b])=>b?.style!=="none");c.length===0?delete s.border:s.border=Object.fromEntries(c)}return s}mergeAt(e,t){return this.merges.find(s=>y(s,e,t))}validationAt(e,t){return this.validations.find(s=>s.areas.some(n=>y(n,e,t)))}filterHeadAt(e,t){return this.filters.find(s=>e===s.area.top&&t>=s.area.left&&t<=s.area.right)}filterAt(e,t){return this.filters.find(s=>y(s.area,e,t))}filesAt(e,t){const s=this.tableAt(e,t);if(s&&e>s.at.row){const n=s.columns[t-s.at.col]?.spec?.files;if(n!==void 0)return n}return s?.at.row===e?void 0:this.spec.columns?.[z(t)]?.files}}export const filesSeparator=l=>(typeof l=="object"?l.separator:void 0)??P;export function filesIn(l,e){const t=filesSeparator(e);return l.split(t.trim()===""?t:t.trim()).map(s=>s.trim()).filter(s=>s!=="")}const N=new Set(["bold","italic","underline","strike","font","size","color","fill","align","valign","wrap","shrink","indent","rotation","border","format"]);export class Workbook{title;sheets=[];names=new Map;checks=[];bySheet=new Map;byTable=new Map;file;generated;ordinary=[];constructor(e,t){this.file=e,this.title=e.title,this.generated=t}respec(e){this.file=O(e,this.generated).file,this.title=e.title,this.sheets.forEach(t=>{const s=e.sheets.find(n=>n.name===t.name);s&&t.respec(s)})}sheet(e){return this.bySheet.get(e.toLowerCase())}table(e){return this.byTable.get(e.toLowerCase())}name(e,t){const s=e.toLowerCase();return(t?.names.size?t.names.get(s):void 0)??this.names.get(s)}definitions(e){const t=e.toLowerCase(),s=[],n=this.names.get(t);n&&s.push(n);for(const i of this.sheets){const a=i.names.get(t);a&&s.push(a)}return s}get tables(){return[...this.byTable.values()]}addSheet(e){this.sheets.push(e),this.bySheet.set(e.name.toLowerCase(),e)}addTable(e){e.sheet.tables.push(e),this.byTable.set(e.name.toLowerCase(),e)}sourceOf(e,t,s){if(e.generated)return{file:R};const n=this.sheets.indexOf(e),i=e.tableAt(t,s);if(i){const o=i.columns[s-i.at.col],f=t-i.at.row-1,h=o?.csv!==void 0&&(i.records[f]?.[o.csv]??"")!=="";return f>=0&&o?.formula&&!h?o.formula.source:{file:i.file,line:f<0?1:i.lines[f]??1}}const a=e.blockAt(t,s);if(a)return{file:a.file,line:a.lines[t-a.area.top]??1};const r=e.keys.get(placeKey(t,s));if(r!==void 0)return{file:E,path:["sheets",n,"cells",r]};for(const o of Object.keys(e.spec.cells??{})){if(!o.includes(":"))continue;const f=$(o);if(f&&y(f,t,s))return{file:E,path:["sheets",n,"cells",o]}}}}export const MAX_FILL_CELLS=5e6;const q=/^[\p{L}_\\][\p{L}\p{N}_.\\?]*$/u;export function validName(l){return q.test(l)&&x(l)===void 0&&!/^(?:TRUE|FALSE)$/iu.test(l)&&!/^[Rr](?:\d+)?(?:[Cc]\d*)?$/u.test(l)&&!/^[Cc]\d*$/u.test(l)}const M="made",k=l=>l[0]===M?R:E;class T{problems=[];wb;read_;lineOf;own;madeNames;constructor(e,t,s,n,i){this.wb=e,this.read_=t,this.lineOf=s,this.own=n,this.madeNames=i}yaml(e,t){const s=this.lineOf(e);this.problems.push({file:k(e),...s===void 0?{}:{line:s},message:t})}sheetPath(e){return e<this.own?["sheets",e]:[M,"sheets",e-this.own]}read(){const{file:e}=this.wb;e.sheets.forEach((t,s)=>{const n=this.sheetPath(s);if(this.wb.sheet(t.name)){this.yaml([...n,"name"],`two sheets are named ${t.name}`);return}(/[\\/?*[\]:]/u.test(t.name)||t.name.length>31)&&this.yaml([...n,"name"],`${t.name} cannot be a sheet's name: at most 31 characters, none of \\ / ? * [ ] :`);const i=new Worksheet(t.name,this.wb.sheets.length,t);i.generated=s>=this.own,this.wb.addSheet(i)}),this.names();for(const[t,s]of e.sheets.entries()){const n=this.wb.sheets[t];n?.spec===s&&this.sheet(n,this.sheetPath(t))}e.checks?.forEach((t,s)=>{const n={file:E,path:["checks",s,"formula"]};this.wb.checks.push({name:t.name,formula:new SharedFormula(t.formula,0,0,n),source:n})})}names(){const{file:e}=this.wb;this.namesOf(e.names,e.hidden_names,t=>this.madeNames.has(t)?[M,"names",t]:["names",t],this.wb.names,void 0),e.sheets.forEach((t,s)=>{const n=this.wb.sheets[s];n?.spec===t&&this.namesOf(t.names,t.hidden_names,i=>[...this.sheetPath(s),"names",i],n.names,n)})}namesOf(e,t,s,n,i){const a=new Set(t?.map(r=>r.toLowerCase()));for(const[r,o]of Object.entries(e??{})){const f=s(r);if(!validName(r)){this.yaml(f,`${r} cannot be a name`);continue}const h={file:k(f),path:f},d=typeof o=="string"&&o.startsWith("=")?{name:r,formula:new SharedFormula(o,0,0,h),source:h}:{name:r,value:typeof o=="string"?A(o).value:o,source:h};i&&(d.sheet=i),a.has(r.toLowerCase())&&(d.hidden=!0),n.set(r.toLowerCase(),d)}}sheet(e,t){const{spec:s}=e;if(s.freeze!==void 0){const n=x(s.freeze);n?e.freeze=n:this.yaml([...t,"freeze"],`${s.freeze} is not a cell`)}s.tables?.forEach((n,i)=>{this.table(e,n,[...t,"tables",i])});for(const[n,i]of e.tables.entries())for(const a of e.tables.slice(n+1))v(i.area,a.area)&&this.problems.push({file:E,message:`tables ${i.name} and ${a.name} overlap on ${e.name}`});s.blocks?.forEach((n,i)=>{this.block(e,n.at,n.rows,[...t,"blocks",i])}),this.cells(e,s.cells??{},[...t,"cells"]),s.merges?.forEach((n,i)=>{const a=$(n);a?e.merges.push(a):this.yaml([...t,"merges",i],`${n} is not a range`)}),s.format?.forEach((n,i)=>{$(n.range)||this.yaml([...t,"format",i,"range"],`${n.range} is not a range`)}),s.conditional?.forEach((n,i)=>{this.condition(e,n,[...t,"conditional",i])}),s.validations?.forEach((n,i)=>{this.validation(e,n,[...t,"validations",i])}),this.filters(e,t),s.charts?.forEach((n,i)=>{this.chart(e,n,i,[...t,"charts",i])});for(const n of Object.keys(s.columns??{}))C(n)===void 0&&this.yaml([...t,"columns",n],`${n} is not a column`);for(const n of Object.keys(s.rows??{}))(!/^[1-9]\d*$/u.test(n)||Number(n)>B)&&this.yaml([...t,"rows",n],`${n} is not a row`)}chart(e,t,s,n){const i=W(t,s,n,(a,r)=>{this.yaml(a,r)});i&&e.charts.push(i)}bound(e,t,s){if(!(typeof e!="string"||!e.startsWith("=")||e.length<2))return new SharedFormula(e,t?.top??0,t?.left??0,{file:k(s),path:s})}condition(e,t,s){const n=j(t.range);if(!n){this.yaml([...s,"range"],`${t.range} is not a range`);return}const[i]=n,a=[],r=(o,f)=>{const h=this.bound(o,i,f);h&&a.push(h)};if(t.type==="expression"){const o=t.formula.startsWith("=")?t.formula:`=${t.formula}`;r(o,[...s,"formula"])}if(t.type==="cellIs"&&t.formula.forEach((o,f)=>{r(o,[...s,"formula",f])}),t.type==="dataBar")for(const o of["min","max"])r(t[o]?.value,[...s,o,"value"]);(t.type==="colorScale"||t.type==="iconSet")&&t.stops?.forEach((o,f)=>{r(o.value,[...s,"stops",f,"value"])}),e.conditions.push({spec:t,areas:n,formulas:a})}validation(e,t,s){const n=j(t.range);if(!n){this.yaml([...s,"range"],`${t.range} is not a range`);return}const i=(t.formula??[]).map((o,f)=>this.bound(o,n[0],[...s,"formula",f])),a=t.formula?.length??0,r=t.type!=="list"&&t.type!=="custom"&&(t.operator===void 0||t.operator==="between"||t.operator==="notBetween");!(t.type==="list"&&t.values!==void 0)&&a<(r?2:1)&&this.yaml(s,`a ${t.type} validation needs its bounds`),e.validations.push({spec:t,areas:n,formulas:i})}filters(e,t){const{spec:s}=e;if(s.filter){const n=[...t,"filter"],i=$(s.filter.range);if(!i)this.yaml([...n,"range"],`${s.filter.range} is not a range`);else{const a=new Map;for(const[o,f]of Object.entries(s.filter.columns??{})){const h=C(o);h===void 0||h<i.left||h>i.right?this.yaml([...n,"columns",o],`${o} is not a column of ${s.filter.range}`):a.set(h,f)}const r=e.tables.find(o=>v(o.area,i));r&&this.yaml(n,`a filter over table ${r.name}: a table has its own`),e.filters.push({area:i,columns:a})}}e.tables.forEach((n,i)=>{const{filter:a}=n.spec;if(a===!1)return;const r=new Map;for(const[o,f]of Object.entries(a?.columns??{})){const h=n.column(o);h?r.set(n.at.col+h.index,f):this.yaml([...t,"tables",i,"filter","columns",o],`table ${n.name} has no column ${o}`)}e.filters.push({area:n.area,table:n,columns:r})})}csv(e,t,s){const n=this.read_(e);return n||this.yaml(t,`${s}: ${e} is not there`),n}overlapping(e,t){const s=e.tables.find(i=>v(i.area,t));if(s)return`table ${s.name}`;const n=e.blocks.find(i=>v(i.area,t));return n?`the block of ${n.file}`:void 0}typed(e,t,s,n,i){if(n.formula!==void 0){const a=new SharedFormula(n.formula,t,s,i);e.put(t,s,new FormulaCell(a,e,t,s));return}n.value!==null&&(e.put(t,s,n.value),n.format!==void 0&&e.implied.set(placeKey(t,s),n.format))}table(e,t,s){const n=x(t.at);if(!n){this.yaml([...s,"at"],`${t.at} is not a cell`);return}if(!validName(t.name)){this.yaml([...s,"name"],`${t.name} cannot be a table's name`);return}if(this.wb.table(t.name)){this.yaml([...s,"name"],`two tables are named ${t.name}`);return}this.wb.name(t.name)&&this.yaml([...s,"name"],`${t.name} is a defined name and a table's`);const i=new Table(t.name,e,n,t.rows,t),a=this.csv(t.rows,[...s,"rows"],`table ${t.name}`),r=a?.rows??[],o=a?.lines??[],f=r[0],h=o[0]??1,d=new Set,g=f?.length===0?[""]:f??[];g.forEach((u,m)=>{const p=u.trim();p===""&&this.problems.push({file:t.rows,line:h,message:`column ${String(m+1)} has no name`}),d.has(p.toLowerCase())&&this.problems.push({file:t.rows,line:h,message:`two columns are named ${p}`}),d.add(p.toLowerCase()),i.columns.push({name:p,index:i.columns.length,csv:m})});for(const[u,m]of Object.entries(t.columns??{})){const p=i.column(u),S=p??{name:u,index:i.columns.length};p||(m.formula===void 0&&this.yaml([...s,"columns",u],`table ${t.name} has no column ${u}`),i.columns.push(S)),S.spec=m}const c=g.length;for(let u=1;u<r.length;u++){const m=r[u];if(!m||m.length===0)continue;const p=o[u]??u+1;i.places.push(u),i.records.push(m),i.lines.push(p),m.length>c&&this.problems.push({file:t.rows,line:p,message:`this row has ${String(m.length)} fields and the header ${String(c)}`})}i.rows=i.records.length;const b=this.overlapping(e,i.area);b&&this.yaml(s,`table ${t.name} overlaps ${b} on ${e.name}`),this.wb.addTable(i),this.tableKey(i,s);const w=n.row+1;i.columns.forEach(u=>{const m=n.col+u.index;e.put(n.row,m,u.name);const p=u.spec?.formula;p!==void 0&&(u.formula=new SharedFormula(p,w,m,{file:k(s),path:[...s,"columns",u.name,"formula"]}),i.rows>0&&e.fills.push({area:{top:w,left:m,bottom:w+i.rows-1,right:m},shared:u.formula})),u.csv!==void 0&&i.records.forEach((S,L)=>{this.typed(e,w+L,m,A(S[u.csv??0]??""),{file:t.rows,line:i.lines[L]??1})})})}tableKey(e,t){const{key:s}=e.spec;if(s===void 0)return;const n=e.column(s);if(n?.csv===void 0){this.yaml([...t,"key"],`table ${e.name} has no column ${s} in ${e.file}`);return}const i=new Set;e.records.forEach((a,r)=>{const o=a[n.csv??0]??"",f=e.lines[r]??1;o===""?this.problems.push({file:e.file,line:f,message:`this row has no ${s}, table ${e.name}'s key`}):i.has(o)&&this.problems.push({file:e.file,line:f,message:`two rows have the key ${o}`}),i.add(o)})}block(e,t,s,n){const i=x(t);if(!i){this.yaml([...n,"at"],`${t} is not a cell`);return}const a=this.csv(s,[...n,"rows"],"a block");if(!a)return;const r=a.rows,o=r.map((g,c)=>a.lines[c]??c+1),f=r.reduce((g,c)=>Math.max(g,c.length),1),h={top:i.row,left:i.col,bottom:i.row+Math.max(r.length,1)-1,right:i.col+f-1},d=this.overlapping(e,h);d&&this.yaml(n,`the block of ${s} overlaps ${d} on ${e.name}`),e.blocks.push({area:h,file:s,lines:o}),r.forEach((g,c)=>{g.forEach((b,w)=>{this.typed(e,i.row+c,i.col+w,A(b),{file:s,line:o[c]??c+1})})})}cells(e,t,s){const n=[];for(const[i,a]of Object.entries(t)){const r=[...s,i],o=$(i);if(!o){this.yaml(r,`${i} is not a cell or a range`);continue}const f=this.overlapping(e,o);if(f&&this.yaml(r,`${i} overlaps ${f}`),i.includes(":")){const h=(o.bottom-o.top+1)*(o.right-o.left+1);h>MAX_FILL_CELLS?this.yaml(r,`${i} is ${String(h)} cells`):this.fill(e,o,a,r)}else n.push([i,a,{row:o.top,col:o.left}])}for(const[i,a,r]of n){const o=[...s,i],f=K(a),h=placeKey(r.row,r.col);e.keys.set(h,i),f.value===null&&f.formula===void 0&&e.blanks.add(h),this.typed(e,r.row,r.col,f,{file:k(o),path:o});const d=a!==null&&typeof a=="object"?a.name:void 0;d!==void 0&&this.cellName(e,r,d,o)}}cellName(e,t,s,n){if(!validName(s)){this.yaml(n,`${s} cannot be a name`);return}if(this.wb.name(s)){this.yaml(n,`two places are named ${s}`);return}const i={file:k(n),path:n},a=U(t).replace(/^([A-Z]+)(\d+)$/u,"$$$1$$$2"),r=`='${e.name.replaceAll("'","''")}'!${a}`;this.wb.names.set(s.toLowerCase(),{name:s,formula:new SharedFormula(r,0,0,i),source:i})}fill(e,t,s,n){const i=K(s),a={file:k(n),path:n};e.fills.push(i.formula===void 0?{area:t,value:i.value,...i.format===void 0?{}:{format:i.format}}:{area:t,shared:new SharedFormula(i.formula,t.top,t.left,a)})}}function W(l,e,t,s){const n=x(l.at);if(!n){s([...t,"at"],`${l.at} is not a cell`);return}const i=(o,f)=>{const h=new SharedFormula(chartFormula(o),0,0,{file:k(f),path:f});return h.node&&!I(h.node)&&s(f,`${o} is not a range or a table's column`),h},a=(o,f)=>o?.startsWith("=")===!0?i(o,f):void 0,r=a(l.title,[...t,"title"]);return{spec:l,at:n,index:e,...l.categories===void 0?{}:{categories:i(l.categories,[...t,"categories"])},...r?{title:r}:{},series:l.series.map((o,f)=>{const h=[...t,"series",f],d=a(o.name,[...h,"name"]);return{values:i(o.values,[...h,"values"]),...o.x===void 0?{}:{x:i(o.x,[...h,"x"])},...d?{name:d}:{}}})}}export const chartFormula=l=>l.startsWith("=")?l:`=${l}`;function I(l){switch(l.kind){case"error":case"ref":case"structured":case"name":return!0;case"paren":case"postfix":return I(l.arg);case"binary":return l.op===":"||l.op===",";default:return!1}}function K(l){if(l===null)return{value:null};if(typeof l=="string")return A(l);if(typeof l!="object")return{value:l};if(l.formula!==void 0)return{value:null,formula:l.formula.startsWith("=")?l.formula:`=${l.formula}`};const{value:e}=l;return typeof e=="string"?A(e):{value:e??null}}export function readWorkbook(l){const e=G(l.text),t=r=>r[0]===M?void 0:e.lineOf(r);if(!e.file)return{problems:e.problems,lineOf:t};const s=O(e.file,l.generated),n=new Workbook(s.file,l.generated);n.ordinary=s.ordinary;const i=[],a=new T(n,r=>{const o=l.generated?.csv[r]??l.read(r);if(o===void 0)return;const f=_(o);for(const h of f.problems)i.push({file:r,line:h.line,message:h.message});return{rows:f.records.map(h=>h.end===h.start?[]:h.fields),lines:f.records.map(h=>h.line)}},t,s.own,s.names);return a.read(),{workbook:n,problems:[...i,...a.problems],lineOf:t}}export function workbookOf(l){const e=O(l.file,l.generated),t=new Workbook(e.file,l.generated);return t.ordinary=e.ordinary,new T(t,s=>{const n=l.generated?.csv[s];if(n!==void 0)return{rows:_(n).records.map(a=>a.end===a.start?[]:a.fields),lines:[]};const i=l.rows(s);return i&&{rows:i,lines:[]}},()=>{},e.own,e.names).read(),t}export{D as rangeName};
@@ -41,6 +41,8 @@ export interface ImportOptions {
41
41
  tolerance?: number;
42
42
  /** What the file may unzip to; ZIP_LIMITS unless it says. */
43
43
  zip?: Partial<ZipLimits>;
44
+ /** Whether a file is there already, by its path from the sheet's folder: a file made beside it takes another name. */
45
+ taken?: (path: string) => boolean;
44
46
  }
45
47
  /** Whether a value the engine gives is what a file cached. */
46
48
  export declare function sameValue(a: Scalar, b: Scalar, tolerance: number): boolean;
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_DATA as re,SHEET_FILE as ie,SHEET_FILES as j,SHEET_NOTE_AUTHOR as le,SHEET_PICTURE_HEIGHT as P,SHEET_SEPARATOR as fe}from"@allyhub/formats";import{cellName as y,columnLetter as M,contains as T,overlaps as A,rangeName as v,readAddress as ae,readArea as W}from"../address.js";import{rectangles as O}from"../api/rectangles.js";import{chartAfter as ce}from"../chart.js";import{analyse as ue}from"../calc/analyse.js";import{FUNCTIONS as he}from"../calc/functions/index.js";import{checkWorkbook as de}from"../check.js";import{writeCsv as me}from"../csv.js";import{pictureSize as pe}from"../files.js";import{isDateCode as z}from"../format.js";import{moveFormula as we,relativeKey as B}from"../formula/move.js";import{printFormula as E,sheetPrefix as U}from"../formula/print.js";import{mapNode as ge,walk as H}from"../formula/walk.js";import{CellError as N,isoOfSerial as ke,readTyped as F,writeTyped as I}from"../values.js";import{FormulaCell as be,validName as V}from"../workbook.js";import{writeYaml as ye}from"../write.js";import{readFileFormula as $e}from"./formula.js";import{hasDate as q}from"./numfmt.js";import{placesLine as D,readXlsx as xe}from"./read.js";import{LISTS_SHEET as Le}from"./write.js";const J=100,ve=.5,K=1462,Z=64,X=1e4;export const COMPARE_TOLERANCE=1e-9;const Y=a=>a.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",k=a=>{for(const e in a)if(Object.hasOwn(a,e))return!1;return!0},G=(a,e)=>`${String(a)} ${e}${a===1?"":"s"}`,S=a=>({row:a.row,col:a.col});function Q(a){return a===""||a.length>255||/^[/\\]|^[A-Za-z]:|\\|\0/u.test(a)?!1:a.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}class Ee{cells;starts;first;constructor(e){let o=!0;for(let t=1;t<e.length&&o;t++){const n=e[t-1],r=e[t];n&&r&&(r.row<n.row||r.row===n.row&&r.col<=n.col)&&(o=!1)}if(!o){e.sort((t,n)=>t.row-n.row||t.col-n.col);for(let t=e.length-1;t>0;t--){const n=e[t-1],r=e[t];r&&n?.row===r.row&&n.col===r.col&&e.splice(t-1,1)}}this.cells=e;const s=e[0]?.row??0,l=e[e.length-1]?.row??-1;this.first=s,this.starts=new Int32Array(Math.max(0,l-s+2));let i=0;for(let t=0;t<this.starts.length;t++){for(;i<e.length&&(e[i]?.row??0)<s+t;)i++;this.starts[t]=i}}get(e,o){const s=e-this.first;if(s<0||s>=this.starts.length-1)return;let l=this.starts[s]??0,i=(this.starts[s+1]??0)-1;for(;l<=i;){const t=l+i>>1,n=this.cells[t];if(!n)return;if(n.col===o)return n;n.col<o?l=t+1:i=t-1}}}class ee{list=[];add(e){this.list.push(e)}has(e,o){for(const s of this.list)if(T(s,e,o))return!0;return!1}}function te(a,e){const o=e.toLowerCase();return ge(a,s=>s.kind!=="structured"||s.table?.toLowerCase()!==o?s:Object.fromEntries(Object.entries(s).filter(([l])=>l!=="table")))}function oe(a){return a.headers===0?"has no header row":a.columns.length!==a.ref.right-a.ref.left+1||!V(a.name)?"cannot be held as a table":new Set(a.columns.map(e=>e.name.toLowerCase())).size===a.columns.length?void 0:"has two columns of one name"}function ne(a,e,o){let s;const l=new Set;H(a,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(n=>{n.kind==="name"&&l.add(n.name.toLowerCase())})});const i=t=>l.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return H(a,t=>{s===void 0&&(t.kind==="call"&&!he.has(t.name)&&(i(t.written.toLowerCase())||(s=`no function ${t.name}`)),t.kind==="name"&&!i(t.name.toLowerCase())&&(s=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!i(t.table.toLowerCase())&&(s=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?s="it reads another workbook":e.has(t.sheet.toLowerCase())||(s=`no sheet ${t.sheet}`)))}),s}function Se(a){const e=new Set(a.book.sheets.map(o=>o.name.toLowerCase()));for(const o of a.book.sheets){const s=new Map,l=(t,n)=>{const r=s.get(n),f=y(t);r?r.push(f):s.set(n,[f])},i=[];for(const t of o.cells){if(t.unread!==void 0){l(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const n=ne(t.node,e,a);n!==void 0?(delete t.node,l(t,n)):(a.carried.set(t,o),t.array&&v(t.array)!==y(t)&&i.push(t))}Ce(a,o,i);for(const[t,n]of s)a.lost.push(`${o.name}: ${G(n.length,"formula")} kept as ${n.length===1?"its value":"their values"}, as ${t} (${D(n)})`)}}function Ce(a,e,o){if(o.length===0)return;const s=new Set;for(const l of o){const{array:i}=l;if(i)for(const t of e.cells)t!==l&&!t.node&&T(i,t.row,t.col)&&s.add(t)}e.cells=e.cells.filter(l=>!s.has(l));for(const l of s)a.spilled.set(l,e)}function C(a,e){const{value:o}=e;if(!a.book.date1904||typeof o!="number")return o;const s=a.book.looks[e.style]?.format;return z(s)&&s!==void 0&&q(s)?o+K:o}function R(a,e){if(typeof a!="number"||e===void 0||!z(e)||!q(e)||a<1)return;const o=ke(a);return F(o).value===a?o:void 0}const Me=(a,e)=>R(a,e)??I(a??null);function Oe(a,e){const o=R(a,e);return o!==void 0?o:a==null?null:typeof a=="number"||typeof a=="boolean"?a:I(a)}function _e(a){const e=[];for(let n=0;n<a.length;n++){const r=a[n];if(!r)continue;const f=e[e.length-1];f?.row===r.row&&f.right===r.col-1?(f.right=r.col,f.last=n):e.push({row:r.row,left:r.col,right:r.col,first:n,last:n})}const o=e.map((n,r)=>r),s=n=>{let r=n;for(;o[r]!==r;){const f=o[o[r]??r]??r;o[r]=f,r=f}return r};let l=0,i=0;for(let n=0;n<e.length;n++){const r=e[n];if(r){n>0&&e[n-1]?.row!==r.row&&(l=e[n-1]?.row===r.row-1?i:n,i=n);for(let f=l;f<i;f++){const c=e[f];c?.row===r.row-1&&c.right>=r.left&&c.left<=r.right&&(o[s(n)]=s(f))}}}const t=new Map;return e.forEach((n,r)=>{const f=s(r),c=t.get(f),u=n.right-n.left+1;c?(c.box.top=Math.min(c.box.top,n.row),c.box.bottom=Math.max(c.box.bottom,n.row),c.box.left=Math.min(c.box.left,n.left),c.box.right=Math.max(c.box.right,n.right),c.count+=u,c.runs.push(r)):t.set(f,{box:{top:n.row,bottom:n.row,left:n.left,right:n.right},count:u,runs:[r]})}),[...t.values()].map(n=>({box:n.box,count:n.count,cells:()=>n.runs.flatMap(r=>{const f=e[r];return f?a.slice(f.first,f.last+1):[]})}))}const se=a=>JSON.stringify(a);class Te{ctx;read;cells;inTables=new ee;columnLooks=new Map;rowLooks=new Map;lookDone=new ee;tables=[];areas=[];filtered=[];ownLooks=new Map;fileColumns=new Map;pictured=new Map;over=[];constructor(e,o){this.ctx=e,this.read=o,this.cells=new Ee(o.cells)}at(e,o){return this.cells.get(e,o)}look(e){return this.ctx.book.looks[e.style]??{}}code(e){return this.look(e).format}text(e){return e.node?E(e.node):Me(C(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book;let s=-1;for(const i of e.cells)i.col>s&&(s=i.col);for(const i of e.columns){if(i.style===void 0)continue;const t=o[i.style];if(!(!t||k(t)))for(let n=i.min;n<=Math.min(i.max,s);n++)this.columnLooks.set(n,t)}for(const i of e.rows){const t=i.style===void 0?void 0:o[i.style];t&&!k(t)&&this.rowLooks.set(i.row,t)}const l=(i,t)=>{for(const n in t)if(!(n in i))return!1;return!0};for(const i of e.cells){const t=this.look(i),n=this.columnLooks.get(i.col);n&&!l(t,n)&&this.columnLooks.delete(i.col);const r=this.rowLooks.get(i.row);r&&!l(t,r)&&this.rowLooks.delete(i.row)}}ownLook(e){const o=this.columnLooks.get(e.col),s=this.rowLooks.get(e.row),l=this.look(e),i=l.format!==void 0&&z(l.format);if(!o&&!s&&!i){let f=this.ownLooks.get(e.style);return f||(f={look:l,key:se(l)},this.ownLooks.set(e.style,f)),f}const t={...o,...s},n={};for(const[f,c]of Object.entries(l))JSON.stringify(c)!==JSON.stringify(t[f])&&(n[f]=c);const r=n.format;if(typeof r=="string"){const f=e.node?void 0:R(C(this.ctx,e),r);f!==void 0&&F(f).format===r&&delete n.format}return{look:n,key:se(n)}}columnFormula(e,o,s){const l=new Map,i=s-o+1;for(let n=o;n<=s;n++){const r=this.at(n,e);if(!r||r.value===void 0&&!r.node||r.value===null&&!r.node)return;if(!r.node)continue;r.key??=B(r.node,r.row,r.col);const f=l.get(r.key);f?f.n+=1:l.set(r.key,{n:1,cell:r})}let t;for(const n of l.values())(!t||n.n>t.n)&&(t=n);return t&&t.n*2>i?t.cell:void 0}csv(e,o){const s=[];for(let l=0;l<e;l+=X){const i=[];for(let t=l;t<Math.min(e,l+X);t++)i.push(o(t));s.push(me(i))}return s.join("")}table(e){const{read:o,ctx:s}=this,l=p=>s.lost.push(`${o.name}: table ${e.name} ${p}`),i=e.ref.right-e.ref.left+1,t=oe(e);if(t!==void 0)return l(`${t}, so its cells are kept and it is no table`),!1;const n=e.ref.top,r=n+1,f=e.ref.bottom-e.totals;e.totals>0&&l("has a totals row, kept as plain cells under it");const c=e.columns.map((p,d)=>f>=r?this.columnFormula(e.ref.left+d,r,f):void 0),u=p=>{const d=c[p];if(!d)return!1;for(let g=r;g<=f;g++)if(this.at(g,e.ref.left+p)?.key!==d.key)return!1;return!0};let h=i;for(;h>1&&u(h-1);)h-=1;const w={},m=this.path(e.name);s.files.set(m,this.csv(f-r+2,p=>{if(p===0)return e.columns.slice(0,h).map(b=>b.name);const d=r+p-1,g=[];for(let b=0;b<h;b++){const x=this.at(d,e.ref.left+b),L=c[b];x?L&&x.key===L.key?g.push(""):x.node?g.push(E(te(x.node,e.name))):g.push(this.text(x)):g.push("")}return g})),this.inTables.add({...e.ref,bottom:f}),e.columns.forEach((p,d)=>{const g=e.ref.left+d,b=this.columnLook(g,r,f),x=c[d];x?.node&&(b.formula=E(te(we(x.node,r-x.row,0),e.name)));const L=this.fileColumns.get(g);L!==void 0&&r<=f&&(b.files=L===P?!0:{height:L}),k(b)||(w[p.name]=b)});const $=new Map;for(const[p,d]of e.filter?.columns??[]){const g=e.columns[p]?.name;g!==void 0&&$.set(g,d)}return(e.filter?.unread??0)>0&&l(`has ${G(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:y({row:n,col:e.ref.left}),rows:m,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...k(w)?{}:{columns:w},...e.filter===void 0?{filter:!1}:$.size>0?{filter:{columns:Object.fromEntries($)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:f}),this.areas.push({...e.ref,bottom:f}),!0}columnLook(e,o,s){let l,i={};for(let t=o;t<=s;t++){const n=this.at(t,e),r=n?this.ownLook(n):{look:{},key:"{}"};if(l===void 0)l=r.key,i=r.look;else if(l!==r.key)return{}}return k(i)?{}:(this.lookDone.add({top:o,bottom:s,left:e,right:e}),{...i})}path(e){const o=`${re}/${Y(e)}`;let s=`${o}.csv`;for(let l=2;this.ctx.files.has(s);l++)s=`${o}-${String(l)}.csv`;return s}loose(){const e=[],o=[];for(const s of this.read.cells)this.inTables.has(s.row,s.col)||(s.node?e.push(s):s.value!==void 0&&s.value!==null&&o.push(s));return{formulas:e,typed:o}}blockAreas(e,o){const s=[],l=O(o.map(S)),i=n=>!s.some(r=>A(r,n))&&!this.areas.some(r=>A(r,n))&&!l.some(r=>A(r,n)),t=n=>(n.bottom-n.top+1)*(n.right-n.left+1);for(const n of _e(e)){const{box:r}=n;if(!(t(r)<J)){if(n.count/t(r)>=ve&&i(r)){s.push(r);continue}for(const f of O(n.cells().map(S)))t(f)>=J&&i(f)&&s.push(f)}}return s.sort((n,r)=>n.top-r.top||n.left-r.left)}cells_(e){const{formulas:o,typed:s}=this.loose(),l=this.blockAreas(s,o),i=r=>l.some(f=>T(f,r.row,r.col));l.length>0&&(e.blocks=l.map(r=>{const f=this.path(this.read.name);return this.ctx.files.set(f,this.csv(r.bottom-r.top+1,c=>{const u=[];for(let h=r.left;h<=r.right;h++){const w=this.at(r.top+c,h);u.push(w?this.text(w):"")}return u})),{at:y({row:r.top,col:r.left}),rows:f}}));const t=[],n=new Map;for(const r of o){if(!r.node)continue;r.key??=B(r.node,r.row,r.col);const f=n.get(r.key);f?f.push(r):n.set(r.key,[r])}for(const r of n.values())for(const f of O(r.map(S))){const c=this.at(f.top,f.left);c?.node&&t.push([{row:f.top,col:f.left},v(f),E(c.node)])}for(const r of s)l.length>0&&i(r)||t.push([S(r),y(r),Oe(C(this.ctx,r),this.code(r))]);t.sort(([r],[f])=>r.row-f.row||r.col-f.col),t.length>0&&(e.cells=Object.fromEntries(t.map(([,r,f])=>[r,f])))}formats(e){const o=new Map,s=this.lookDone.list.length>0;for(const i of this.read.cells){if(s&&this.lookDone.has(i.row,i.col))continue;const t=this.ownLook(i);if(k(t.look))continue;const n=o.get(t.key);n?n.places.push(S(i)):o.set(t.key,{look:t.look,places:[S(i)]})}const l=[];for(const{look:i,places:t}of o.values())for(const n of O(t))l.push({range:v(n),...i});l.length>0&&(e.format=l)}columns(e){const{read:o}=this,s=new Map;let l=0;for(const t of o.cells)t.col>l&&(l=t.col);const i=[];for(const t of o.columns){if(t.width===void 0&&t.hidden!==!0&&t.level===void 0)continue;const n=t.max-Math.max(t.min,l+1)+1>Z?Math.max(l,t.min+Z-1):t.max;n<t.max&&i.push(`${M(n+1)}:${M(t.max)}`);for(let r=t.min;r<=n;r++)s.set(r,{...t.width===void 0?{}:{width:t.width},...t.hidden===!0?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}})}for(const[t,n]of this.columnLooks)s.set(t,{...s.get(t),...n});for(const[t,n]of this.fileColumns)this.tableColumn(t)||s.set(t,{...s.get(t),files:n===P?!0:{height:n}});s.size>0&&(e.columns=Object.fromEntries([...s.keys()].sort((t,n)=>t-n).map(t=>[M(t),s.get(t)??{}]))),i.length>0&&this.ctx.lost.push(`${o.name}: the size of columns ${D(i)}, past those that hold anything`)}tableColumn(e){return this.areas.some(o=>e>=o.left&&e<=o.right)}rows(e){const o={};for(const s of this.read.rows){const l=this.rowLooks.get(s.row),i=this.filtered.some(r=>s.row>r.top&&s.row<=r.bottom),t=s.height!==void 0&&this.pictured.get(s.row)!==s.height?s.height:void 0,n={...t===void 0?{}:{height:t},...s.hidden===!0&&!i?{hidden:!0}:{},...s.level===void 0?{}:{level:s.level},...l};k(n)||(o[String(s.row+1)]=n)}k(o)||(e.rows=o)}assetPath(e,o){const s=t=>{const n=this.ctx.assets.get(t);return!n||Ae(n,o.bytes)};if(e!==void 0&&Q(e)&&s(e))return e;const l=Y((o.name??"picture").replace(/\.[A-Za-z0-9]+$/u,""));let i=`${j}/${l}.${o.type}`;for(let t=2;!s(i);t++)i=`${j}/${l}-${String(t)}.${o.type}`;return i}pictures(){const e=this.over;for(const o of this.read.pictures){const s=this.at(o.row,o.col),l=typeof s?.value=="string"?s.value:"";if(o.y===void 0&&o.descr!==void 0&&Q(o.descr)&&l.split(fe).includes(o.descr)&&o.descr!==void 0){this.ctx.assets.set(o.descr,o.bytes),this.fileColumns.set(o.col,Math.max(this.fileColumns.get(o.col)??0,o.height)),this.pictured.set(o.row,Math.max(this.pictured.get(o.row)??0,o.height));continue}const t=this.assetPath(o.descr,o);this.ctx.assets.set(t,o.bytes);const n=pe(o.bytes),r=n?.width===o.width&&n.height===o.height;e.push({file:t,at:y({row:o.row,col:o.col}),...o.x===void 0?{}:{x:o.x},...o.y===void 0?{}:{y:o.y},...r?{}:{width:o.width,height:o.height}})}}build(){const{read:e}=this;this.baseLooks(),this.pictures();for(const s of e.tables)this.table(s);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=y(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells_(o),e.merges.length>0&&(o.merges=e.merges.map(v)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(s=>this.chart(s))),this.over.length>0&&(o.pictures=this.over),k(e.links)||(o.links=e.links),e.notes.length>0&&(o.notes=Object.fromEntries(e.notes.map(s=>[s.ref,s.author===void 0||s.author===le?s.text:{text:s.text,author:s.author}]))),e.print&&(o.print=e.print),e.protect===!0&&(o.protect=!0),o}chart(e){return ce(e,o=>{const s=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${s}`:s})}chartReference(e){const o=e.lastIndexOf("!"),l=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),i=W(e.slice(o+1).replaceAll("$",""));if(!i)return e;const t=this.ctx.book.sheets.find(n=>n.name.toLowerCase()===l.toLowerCase());for(const n of t?.tables??[]){const r=n.ref.top+1,c=i.left===i.right&&i.top===r&&i.bottom===n.ref.bottom&&i.left>=n.ref.left&&i.left<=n.ref.right?n.columns[i.left-n.ref.left]:void 0;if(c&&this.ctx.tables.has(n.name.toLowerCase()))return`${n.name}[${c.name}]`}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${v(i)}`}filter(e){const{filter:o}=this.read;if(!o)return;const s={};for(const[l,i]of o.columns)s[M(o.ref.left+l)]=i;e.filter={range:v(o.ref),...k(s)?{}:{columns:s}},o.unread===0&&!k(s)&&this.filtered.push(o.ref)}}const Ae=(a,e)=>a.length===e.length&&a.every((o,s)=>o===e[s]),ze=new Set(["_xlnm._FilterDatabase","_xlnm.Print_Area","_xlnm.Print_Titles"]);function He(a){const e={},o=[],s=new Map,{book:l,lost:i}=a,t=new Set(l.sheets.map(f=>f.name.toLowerCase())),n=new Set,r=f=>{const c=Ie(f.text);if(c!==void 0)return typeof c=="string"?I(c):c;const u=$e(f.text,!0),h=u.ok?ne(u.node,t):"it could not be read";if(!u.ok||h!==void 0||Fe(u.node)){i.push(`the name ${f.name} (${f.text})${h===void 0?"":`: ${h}`}`);return}return E(u.node)};for(const f of l.names){if(f.name.startsWith("_xlnm.")){ze.has(f.name)||i.push(`Excel's name ${f.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(f.name))continue;const c=f.name.toLowerCase(),u=f.sheet===void 0?"":String(f.sheet);if(!V(f.name)||a.tables.has(c)){i.push(`the name ${f.name}, which cannot be held here`);continue}if(n.has(`${u}|${c}`)){i.push(`a second name ${f.name}${u===""?"":` of ${l.sheets[f.sheet??0]?.name??""}`}`);continue}const h=r(f);if(h!==void 0)if(n.add(`${u}|${c}`),a.names.add(c),f.sheet===void 0)e[f.name]=h,f.hidden===!0&&o.push(f.name);else{const w=s.get(f.sheet)??{names:{},hidden:[]};w.names[f.name]=h,f.hidden===!0&&w.hidden.push(f.name),s.set(f.sheet,w)}}return{names:e,hidden:o,sheets:s}}function Ne(a,e){const o={},s=new Map;for(const[l,i]of Object.entries(e))typeof i=="string"&&i.startsWith("=")&&s.set(i.slice(1).replaceAll("$","").toLowerCase(),l);for(const l of a.book.sheets)for(const i of l.scenarios){const t={};let n=!0;for(const{at:r,value:f}of i.cells){const c=ae(r),u=c&&l.cells.find(m=>m.row===c.row&&m.col===c.col);String(u?.value??"")!==f&&(n=!1);const h=s.get(`${U(l.name)}${r}`.toLowerCase())??s.get(r.toLowerCase()),w=F(f);h===void 0?a.lost.push(`${l.name}: scenario ${i.name}'s cell ${r}, which has no name`):t[h]=typeof w.value=="number"?w.value:f}!n&&!k(t)&&(o[i.name]={...o[i.name],...t})}return o}function Fe(a){let e=!1;return H(a,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function Ie(a){const e=a.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const De=new RegExp(`^${Le.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?: \\(\\d+\\))?$`,"u");function Re(a){const e=a.sheets.find(i=>i.state==="veryHidden"&&De.test(i.name));if(!e)return;const o=U(e.name).toLowerCase(),s=i=>{const t=i.replace(/^=/u,"");if(!t.toLowerCase().startsWith(o))return;const n=W(t.slice(o.length).replaceAll("$",""));if(!n||n.left!==n.right)return;const r=[];for(let f=n.top;f<=n.bottom;f++){const c=e.cells.find(u=>u.row===f&&u.col===n.left);r.push(typeof c?.value=="string"?c.value:"")}return r};for(const i of a.sheets)i.validations=i.validations.map(t=>{const[n]=t.formula??[],r=t.type==="list"&&typeof n=="string"?s(n):void 0;if(!r)return t;const f={...t,values:r};return delete f.formula,f});const l=a.sheets.indexOf(e);a.sheets=a.sheets.filter(i=>i!==e),a.names=a.names.flatMap(i=>i.sheet===void 0||i.sheet<l?[i]:i.sheet===l?[]:[{...i,sheet:i.sheet-1}])}const _=a=>a instanceof N?a.code:a??null;export function sameValue(a,e,o){if(typeof a=="number"&&typeof e=="number")return a===e?!0:Math.abs(a-e)<=Math.max(Math.abs(a),Math.abs(e))*o;if(a instanceof N||e instanceof N)return a?.code===e?.code;if(a===null||e===null){const s=a??e;return s===null||s===""||s===0||s===!1}return a===e}function je(a,e){const o=[];for(const i of e.sheets)for(const t of i.formulas)t.shared.node&&ue(e,t.shared,i).volatile&&o.push(t);const s=new Set(o),l=[...o];for(;;){const i=l.pop();if(!i)return s;for(const t of a.readers(i.sheet,i.row,i.col))s.has(t)||(s.add(t),l.push(t))}}function Pe(a,e,o,s){const l={formulas:0,same:0,uncached:0,moving:0,differences:[]},i=je(o,e);for(const[t,n]of a.carried){if(!t.node)continue;const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.at(t.row,t.col);if(f instanceof be&&i.has(f)){l.moving+=1;continue}const c=C(a,t);if(c===void 0){l.uncached+=1;continue}const u=o.value(r,t.row,t.col);sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:E(t.node),file:_(c),engine:_(u)})}for(const[t,n]of a.spilled){const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.spillAt(t.row,t.col);if(f&&i.has(f)){l.moving+=1;continue}const c=C(a,t),u=o.value(r,t.row,t.col);c===void 0?l.uncached+=1:sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:f?`${y(f)}#`:"",file:_(c),engine:_(u)})}return l}function We(a,e){const o=new Map,s=[];for(const l of a){const i=e.find(r=>l.startsWith(`${r}: `));if(i===void 0){s.push(l);continue}const t=l.slice(i.length+2),n=o.get(t);n?n.push(i):o.set(t,[i])}for(const[l,i]of o)s.push(i.length===1?`${i[0]??""}: ${l}`:`${l}, on ${String(i.length)} sheets (${D(i)})`);return s}export function importXlsx(a,e){const o=xe(a,e.zip);if(Re(o),o.sheets.length===0)throw new Error("It holds no sheets.");const s={book:o,files:new Map,assets:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(m=>m.tables.filter($=>oe($)===void 0).map($=>$.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&s.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(K)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&s.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const l=He(s);Se(s);const i=o.sheets.map((m,$)=>{const p=new Te(s,m).build(),d=l.sheets.get($);return d&&!k(d.names)&&(p.names=d.names),d&&d.hidden.length>0&&(p.hidden_names=d.hidden),p}),t=Ne(s,l.names),n={title:o.title??e.name,...k(l.names)?{}:{names:l.names},...l.hidden.length>0?{hidden_names:l.hidden}:{},sheets:i,...k(t)?{}:{scenarios:t}},r=ye(n),f=new Map([[ie,r],...s.files]),c=de({text:r,read:m=>f.get(m),exists:m=>f.has(m)||s.assets.has(m)}),{workbook:u,calc:h,problems:w}=c;return{files:f,assets:s.assets,lost:We(s.lost,o.sheets.map(m=>m.name)),problems:w,compared:u&&h?Pe(s,u,h,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:s.tables.size}}
2
+ import{SHEET_FILE as se,SHEET_NOTE_AUTHOR as re,SHEET_PICTURE_HEIGHT as D,SHEET_SEPARATOR as ie}from"@allyhub/formats";import{cellName as y,columnLetter as M,contains as T,overlaps as A,rangeName as v,readAddress as le,readArea as P}from"../address.js";import{rectangles as O}from"../api/rectangles.js";import{chartAfter as fe}from"../chart.js";import{analyse as ae}from"../calc/analyse.js";import{FUNCTIONS as ce}from"../calc/functions/index.js";import{checkWorkbook as ue}from"../check.js";import{writeCsv as he}from"@allyhub/formats";import{pictureSize as de}from"../files.js";import{isDateCode as z}from"../format.js";import{moveFormula as me,relativeKey as W}from"../formula/move.js";import{printFormula as C,sheetPrefix as B}from"../formula/print.js";import{mapNode as pe,walk as N}from"../formula/walk.js";import{CellError as H,isoOfSerial as we,readTyped as F,writeTyped as I}from"../values.js";import{FormulaCell as ge,validName as U}from"../workbook.js";import{writeYaml as ke}from"../write.js";import{readFileFormula as be}from"./formula.js";import{hasDate as V}from"./numfmt.js";import{placesLine as R,readXlsx as ye}from"./read.js";import{LISTS_SHEET as $e}from"./write.js";const q=100,xe=.5,J=1462,K=64,Z=1e4;export const COMPARE_TOLERANCE=1e-9;const X=a=>a.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",k=a=>{for(const e in a)if(Object.hasOwn(a,e))return!1;return!0},Y=(a,e)=>`${String(a)} ${e}${a===1?"":"s"}`,S=a=>({row:a.row,col:a.col});function G(a){return a===""||a.length>255||/^[/\\]|^[A-Za-z]:|\\|\0/u.test(a)?!1:a.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}class Le{cells;starts;first;constructor(e){let o=!0;for(let t=1;t<e.length&&o;t++){const n=e[t-1],r=e[t];n&&r&&(r.row<n.row||r.row===n.row&&r.col<=n.col)&&(o=!1)}if(!o){e.sort((t,n)=>t.row-n.row||t.col-n.col);for(let t=e.length-1;t>0;t--){const n=e[t-1],r=e[t];r&&n?.row===r.row&&n.col===r.col&&e.splice(t-1,1)}}this.cells=e;const s=e[0]?.row??0,l=e[e.length-1]?.row??-1;this.first=s,this.starts=new Int32Array(Math.max(0,l-s+2));let i=0;for(let t=0;t<this.starts.length;t++){for(;i<e.length&&(e[i]?.row??0)<s+t;)i++;this.starts[t]=i}}get(e,o){const s=e-this.first;if(s<0||s>=this.starts.length-1)return;let l=this.starts[s]??0,i=(this.starts[s+1]??0)-1;for(;l<=i;){const t=l+i>>1,n=this.cells[t];if(!n)return;if(n.col===o)return n;n.col<o?l=t+1:i=t-1}}}class Q{list=[];add(e){this.list.push(e)}has(e,o){for(const s of this.list)if(T(s,e,o))return!0;return!1}}function ee(a,e){const o=e.toLowerCase();return pe(a,s=>s.kind!=="structured"||s.table?.toLowerCase()!==o?s:Object.fromEntries(Object.entries(s).filter(([l])=>l!=="table")))}function te(a){return a.headers===0?"has no header row":a.columns.length!==a.ref.right-a.ref.left+1||!U(a.name)?"cannot be held as a table":new Set(a.columns.map(e=>e.name.toLowerCase())).size===a.columns.length?void 0:"has two columns of one name"}function oe(a,e,o){let s;const l=new Set;N(a,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(n=>{n.kind==="name"&&l.add(n.name.toLowerCase())})});const i=t=>l.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return N(a,t=>{s===void 0&&(t.kind==="call"&&!ce.has(t.name)&&(i(t.written.toLowerCase())||(s=`no function ${t.name}`)),t.kind==="name"&&!i(t.name.toLowerCase())&&(s=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!i(t.table.toLowerCase())&&(s=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?s="it reads another workbook":e.has(t.sheet.toLowerCase())||(s=`no sheet ${t.sheet}`)))}),s}function ve(a){const e=new Set(a.book.sheets.map(o=>o.name.toLowerCase()));for(const o of a.book.sheets){const s=new Map,l=(t,n)=>{const r=s.get(n),f=y(t);r?r.push(f):s.set(n,[f])},i=[];for(const t of o.cells){if(t.unread!==void 0){l(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const n=oe(t.node,e,a);n!==void 0?(delete t.node,l(t,n)):(a.carried.set(t,o),t.array&&v(t.array)!==y(t)&&i.push(t))}Ce(a,o,i);for(const[t,n]of s)a.lost.push(`${o.name}: ${Y(n.length,"formula")} kept as ${n.length===1?"its value":"their values"}, as ${t} (${R(n)})`)}}function Ce(a,e,o){if(o.length===0)return;const s=new Set;for(const l of o){const{array:i}=l;if(i)for(const t of e.cells)t!==l&&!t.node&&T(i,t.row,t.col)&&s.add(t)}e.cells=e.cells.filter(l=>!s.has(l));for(const l of s)a.spilled.set(l,e)}function E(a,e){const{value:o}=e;if(!a.book.date1904||typeof o!="number")return o;const s=a.book.looks[e.style]?.format;return z(s)&&s!==void 0&&V(s)?o+J:o}function j(a,e){if(typeof a!="number"||e===void 0||!z(e)||!V(e)||a<1)return;const o=we(a);return F(o).value===a?o:void 0}const Se=(a,e)=>j(a,e)??I(a??null);function Ee(a,e){const o=j(a,e);return o!==void 0?o:a==null?null:typeof a=="number"||typeof a=="boolean"?a:I(a)}function Me(a){const e=[];for(let n=0;n<a.length;n++){const r=a[n];if(!r)continue;const f=e[e.length-1];f?.row===r.row&&f.right===r.col-1?(f.right=r.col,f.last=n):e.push({row:r.row,left:r.col,right:r.col,first:n,last:n})}const o=e.map((n,r)=>r),s=n=>{let r=n;for(;o[r]!==r;){const f=o[o[r]??r]??r;o[r]=f,r=f}return r};let l=0,i=0;for(let n=0;n<e.length;n++){const r=e[n];if(r){n>0&&e[n-1]?.row!==r.row&&(l=e[n-1]?.row===r.row-1?i:n,i=n);for(let f=l;f<i;f++){const c=e[f];c?.row===r.row-1&&c.right>=r.left&&c.left<=r.right&&(o[s(n)]=s(f))}}}const t=new Map;return e.forEach((n,r)=>{const f=s(r),c=t.get(f),u=n.right-n.left+1;c?(c.box.top=Math.min(c.box.top,n.row),c.box.bottom=Math.max(c.box.bottom,n.row),c.box.left=Math.min(c.box.left,n.left),c.box.right=Math.max(c.box.right,n.right),c.count+=u,c.runs.push(r)):t.set(f,{box:{top:n.row,bottom:n.row,left:n.left,right:n.right},count:u,runs:[r]})}),[...t.values()].map(n=>({box:n.box,count:n.count,cells:()=>n.runs.flatMap(r=>{const f=e[r];return f?a.slice(f.first,f.last+1):[]})}))}const ne=a=>JSON.stringify(a);class Oe{ctx;read;cells;inTables=new Q;columnLooks=new Map;rowLooks=new Map;lookDone=new Q;tables=[];areas=[];filtered=[];ownLooks=new Map;fileColumns=new Map;pictured=new Map;over=[];constructor(e,o){this.ctx=e,this.read=o,this.cells=new Le(o.cells)}at(e,o){return this.cells.get(e,o)}look(e){return this.ctx.book.looks[e.style]??{}}code(e){return this.look(e).format}text(e){return e.node?C(e.node):Se(E(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book;let s=-1;for(const i of e.cells)i.col>s&&(s=i.col);for(const i of e.columns){if(i.style===void 0)continue;const t=o[i.style];if(!(!t||k(t)))for(let n=i.min;n<=Math.min(i.max,s);n++)this.columnLooks.set(n,t)}for(const i of e.rows){const t=i.style===void 0?void 0:o[i.style];t&&!k(t)&&this.rowLooks.set(i.row,t)}const l=(i,t)=>{for(const n in t)if(!(n in i))return!1;return!0};for(const i of e.cells){const t=this.look(i),n=this.columnLooks.get(i.col);n&&!l(t,n)&&this.columnLooks.delete(i.col);const r=this.rowLooks.get(i.row);r&&!l(t,r)&&this.rowLooks.delete(i.row)}}ownLook(e){const o=this.columnLooks.get(e.col),s=this.rowLooks.get(e.row),l=this.look(e),i=l.format!==void 0&&z(l.format);if(!o&&!s&&!i){let f=this.ownLooks.get(e.style);return f||(f={look:l,key:ne(l)},this.ownLooks.set(e.style,f)),f}const t={...o,...s},n={};for(const[f,c]of Object.entries(l))JSON.stringify(c)!==JSON.stringify(t[f])&&(n[f]=c);const r=n.format;if(typeof r=="string"){const f=e.node?void 0:j(E(this.ctx,e),r);f!==void 0&&F(f).format===r&&delete n.format}return{look:n,key:ne(n)}}columnFormula(e,o,s){const l=new Map,i=s-o+1;for(let n=o;n<=s;n++){const r=this.at(n,e);if(!r||r.value===void 0&&!r.node||r.value===null&&!r.node)return;if(!r.node)continue;r.key??=W(r.node,r.row,r.col);const f=l.get(r.key);f?f.n+=1:l.set(r.key,{n:1,cell:r})}let t;for(const n of l.values())(!t||n.n>t.n)&&(t=n);return t&&t.n*2>i?t.cell:void 0}csv(e,o){const s=[];for(let l=0;l<e;l+=Z){const i=[];for(let t=l;t<Math.min(e,l+Z);t++)i.push(o(t));s.push(he(i))}return s.join("")}table(e){const{read:o,ctx:s}=this,l=p=>s.lost.push(`${o.name}: table ${e.name} ${p}`),i=e.ref.right-e.ref.left+1,t=te(e);if(t!==void 0)return l(`${t}, so its cells are kept and it is no table`),!1;const n=e.ref.top,r=n+1,f=e.ref.bottom-e.totals;e.totals>0&&l("has a totals row, kept as plain cells under it");const c=e.columns.map((p,d)=>f>=r?this.columnFormula(e.ref.left+d,r,f):void 0),u=p=>{const d=c[p];if(!d)return!1;for(let g=r;g<=f;g++)if(this.at(g,e.ref.left+p)?.key!==d.key)return!1;return!0};let h=i;for(;h>1&&u(h-1);)h-=1;const w={},m=this.path(e.name);s.files.set(m,this.csv(f-r+2,p=>{if(p===0)return e.columns.slice(0,h).map(b=>b.name);const d=r+p-1,g=[];for(let b=0;b<h;b++){const x=this.at(d,e.ref.left+b),L=c[b];x?L&&x.key===L.key?g.push(""):x.node?g.push(C(ee(x.node,e.name))):g.push(this.text(x)):g.push("")}return g})),this.inTables.add({...e.ref,bottom:f}),e.columns.forEach((p,d)=>{const g=e.ref.left+d,b=this.columnLook(g,r,f),x=c[d];x?.node&&(b.formula=C(ee(me(x.node,r-x.row,0),e.name)));const L=this.fileColumns.get(g);L!==void 0&&r<=f&&(b.files=L===D?!0:{height:L}),k(b)||(w[p.name]=b)});const $=new Map;for(const[p,d]of e.filter?.columns??[]){const g=e.columns[p]?.name;g!==void 0&&$.set(g,d)}return(e.filter?.unread??0)>0&&l(`has ${Y(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:y({row:n,col:e.ref.left}),rows:m,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...k(w)?{}:{columns:w},...e.filter===void 0?{filter:!1}:$.size>0?{filter:{columns:Object.fromEntries($)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:f}),this.areas.push({...e.ref,bottom:f}),!0}columnLook(e,o,s){let l,i={};for(let t=o;t<=s;t++){const n=this.at(t,e),r=n?this.ownLook(n):{look:{},key:"{}"};if(l===void 0)l=r.key,i=r.look;else if(l!==r.key)return{}}return k(i)?{}:(this.lookDone.add({top:o,bottom:s,left:e,right:e}),{...i})}path(e){const o=X(e);let s=`${o}.csv`;for(let l=2;this.ctx.files.has(s)||this.ctx.taken(s);l++)s=`${o}-${String(l)}.csv`;return s}loose(){const e=[],o=[];for(const s of this.read.cells)this.inTables.has(s.row,s.col)||(s.node?e.push(s):s.value!==void 0&&s.value!==null&&o.push(s));return{formulas:e,typed:o}}blockAreas(e,o){const s=[],l=O(o.map(S)),i=n=>!s.some(r=>A(r,n))&&!this.areas.some(r=>A(r,n))&&!l.some(r=>A(r,n)),t=n=>(n.bottom-n.top+1)*(n.right-n.left+1);for(const n of Me(e)){const{box:r}=n;if(!(t(r)<q)){if(n.count/t(r)>=xe&&i(r)){s.push(r);continue}for(const f of O(n.cells().map(S)))t(f)>=q&&i(f)&&s.push(f)}}return s.sort((n,r)=>n.top-r.top||n.left-r.left)}cells_(e){const{formulas:o,typed:s}=this.loose(),l=this.blockAreas(s,o),i=r=>l.some(f=>T(f,r.row,r.col));l.length>0&&(e.blocks=l.map(r=>{const f=this.path(this.read.name);return this.ctx.files.set(f,this.csv(r.bottom-r.top+1,c=>{const u=[];for(let h=r.left;h<=r.right;h++){const w=this.at(r.top+c,h);u.push(w?this.text(w):"")}return u})),{at:y({row:r.top,col:r.left}),rows:f}}));const t=[],n=new Map;for(const r of o){if(!r.node)continue;r.key??=W(r.node,r.row,r.col);const f=n.get(r.key);f?f.push(r):n.set(r.key,[r])}for(const r of n.values())for(const f of O(r.map(S))){const c=this.at(f.top,f.left);c?.node&&t.push([{row:f.top,col:f.left},v(f),C(c.node)])}for(const r of s)l.length>0&&i(r)||t.push([S(r),y(r),Ee(E(this.ctx,r),this.code(r))]);t.sort(([r],[f])=>r.row-f.row||r.col-f.col),t.length>0&&(e.cells=Object.fromEntries(t.map(([,r,f])=>[r,f])))}formats(e){const o=new Map,s=this.lookDone.list.length>0;for(const i of this.read.cells){if(s&&this.lookDone.has(i.row,i.col))continue;const t=this.ownLook(i);if(k(t.look))continue;const n=o.get(t.key);n?n.places.push(S(i)):o.set(t.key,{look:t.look,places:[S(i)]})}const l=[];for(const{look:i,places:t}of o.values())for(const n of O(t))l.push({range:v(n),...i});l.length>0&&(e.format=l)}columns(e){const{read:o}=this,s=new Map;let l=0;for(const t of o.cells)t.col>l&&(l=t.col);const i=[];for(const t of o.columns){if(t.width===void 0&&t.hidden!==!0&&t.level===void 0)continue;const n=t.max-Math.max(t.min,l+1)+1>K?Math.max(l,t.min+K-1):t.max;n<t.max&&i.push(`${M(n+1)}:${M(t.max)}`);for(let r=t.min;r<=n;r++)s.set(r,{...t.width===void 0?{}:{width:t.width},...t.hidden===!0?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}})}for(const[t,n]of this.columnLooks)s.set(t,{...s.get(t),...n});for(const[t,n]of this.fileColumns)this.tableColumn(t)||s.set(t,{...s.get(t),files:n===D?!0:{height:n}});s.size>0&&(e.columns=Object.fromEntries([...s.keys()].sort((t,n)=>t-n).map(t=>[M(t),s.get(t)??{}]))),i.length>0&&this.ctx.lost.push(`${o.name}: the size of columns ${R(i)}, past those that hold anything`)}tableColumn(e){return this.areas.some(o=>e>=o.left&&e<=o.right)}rows(e){const o={};for(const s of this.read.rows){const l=this.rowLooks.get(s.row),i=this.filtered.some(r=>s.row>r.top&&s.row<=r.bottom),t=s.height!==void 0&&this.pictured.get(s.row)!==s.height?s.height:void 0,n={...t===void 0?{}:{height:t},...s.hidden===!0&&!i?{hidden:!0}:{},...s.level===void 0?{}:{level:s.level},...l};k(n)||(o[String(s.row+1)]=n)}k(o)||(e.rows=o)}assetPath(e,o){const s=t=>{const n=this.ctx.assets.get(t);return n?_e(n,o.bytes):!this.ctx.taken(t)};if(e!==void 0&&G(e)&&s(e))return e;const l=X((o.name??"picture").replace(/\.[A-Za-z0-9]+$/u,""));let i=`${l}.${o.type}`;for(let t=2;!s(i);t++)i=`${l}-${String(t)}.${o.type}`;return i}pictures(){const e=this.over;for(const o of this.read.pictures){const s=this.at(o.row,o.col),l=typeof s?.value=="string"?s.value:"";if(o.y===void 0&&o.descr!==void 0&&G(o.descr)&&l.split(ie).includes(o.descr)&&o.descr!==void 0){this.ctx.assets.set(o.descr,o.bytes),this.fileColumns.set(o.col,Math.max(this.fileColumns.get(o.col)??0,o.height)),this.pictured.set(o.row,Math.max(this.pictured.get(o.row)??0,o.height));continue}const t=this.assetPath(o.descr,o);this.ctx.assets.set(t,o.bytes);const n=de(o.bytes),r=n?.width===o.width&&n.height===o.height;e.push({file:t,at:y({row:o.row,col:o.col}),...o.x===void 0?{}:{x:o.x},...o.y===void 0?{}:{y:o.y},...r?{}:{width:o.width,height:o.height}})}}build(){const{read:e}=this;this.baseLooks(),this.pictures();for(const s of e.tables)this.table(s);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=y(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells_(o),e.merges.length>0&&(o.merges=e.merges.map(v)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(s=>this.chart(s))),this.over.length>0&&(o.pictures=this.over),k(e.links)||(o.links=e.links),e.notes.length>0&&(o.notes=Object.fromEntries(e.notes.map(s=>[s.ref,s.author===void 0||s.author===re?s.text:{text:s.text,author:s.author}]))),e.print&&(o.print=e.print),e.protect===!0&&(o.protect=!0),o}chart(e){return fe(e,o=>{const s=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${s}`:s})}chartReference(e){const o=e.lastIndexOf("!"),l=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),i=P(e.slice(o+1).replaceAll("$",""));if(!i)return e;const t=this.ctx.book.sheets.find(n=>n.name.toLowerCase()===l.toLowerCase());for(const n of t?.tables??[]){const r=n.ref.top+1,c=i.left===i.right&&i.top===r&&i.bottom===n.ref.bottom&&i.left>=n.ref.left&&i.left<=n.ref.right?n.columns[i.left-n.ref.left]:void 0;if(c&&this.ctx.tables.has(n.name.toLowerCase()))return`${n.name}[${c.name}]`}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${v(i)}`}filter(e){const{filter:o}=this.read;if(!o)return;const s={};for(const[l,i]of o.columns)s[M(o.ref.left+l)]=i;e.filter={range:v(o.ref),...k(s)?{}:{columns:s}},o.unread===0&&!k(s)&&this.filtered.push(o.ref)}}const _e=(a,e)=>a.length===e.length&&a.every((o,s)=>o===e[s]),Te=new Set(["_xlnm._FilterDatabase","_xlnm.Print_Area","_xlnm.Print_Titles"]);function Ae(a){const e={},o=[],s=new Map,{book:l,lost:i}=a,t=new Set(l.sheets.map(f=>f.name.toLowerCase())),n=new Set,r=f=>{const c=He(f.text);if(c!==void 0)return typeof c=="string"?I(c):c;const u=be(f.text,!0),h=u.ok?oe(u.node,t):"it could not be read";if(!u.ok||h!==void 0||Ne(u.node)){i.push(`the name ${f.name} (${f.text})${h===void 0?"":`: ${h}`}`);return}return C(u.node)};for(const f of l.names){if(f.name.startsWith("_xlnm.")){Te.has(f.name)||i.push(`Excel's name ${f.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(f.name))continue;const c=f.name.toLowerCase(),u=f.sheet===void 0?"":String(f.sheet);if(!U(f.name)||a.tables.has(c)){i.push(`the name ${f.name}, which cannot be held here`);continue}if(n.has(`${u}|${c}`)){i.push(`a second name ${f.name}${u===""?"":` of ${l.sheets[f.sheet??0]?.name??""}`}`);continue}const h=r(f);if(h!==void 0)if(n.add(`${u}|${c}`),a.names.add(c),f.sheet===void 0)e[f.name]=h,f.hidden===!0&&o.push(f.name);else{const w=s.get(f.sheet)??{names:{},hidden:[]};w.names[f.name]=h,f.hidden===!0&&w.hidden.push(f.name),s.set(f.sheet,w)}}return{names:e,hidden:o,sheets:s}}function ze(a,e){const o={},s=new Map;for(const[l,i]of Object.entries(e))typeof i=="string"&&i.startsWith("=")&&s.set(i.slice(1).replaceAll("$","").toLowerCase(),l);for(const l of a.book.sheets)for(const i of l.scenarios){const t={};let n=!0;for(const{at:r,value:f}of i.cells){const c=le(r),u=c&&l.cells.find(m=>m.row===c.row&&m.col===c.col);String(u?.value??"")!==f&&(n=!1);const h=s.get(`${B(l.name)}${r}`.toLowerCase())??s.get(r.toLowerCase()),w=F(f);h===void 0?a.lost.push(`${l.name}: scenario ${i.name}'s cell ${r}, which has no name`):t[h]=typeof w.value=="number"?w.value:f}!n&&!k(t)&&(o[i.name]={...o[i.name],...t})}return o}function Ne(a){let e=!1;return N(a,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function He(a){const e=a.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const Fe=new RegExp(`^${$e.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?: \\(\\d+\\))?$`,"u");function Ie(a){const e=a.sheets.find(i=>i.state==="veryHidden"&&Fe.test(i.name));if(!e)return;const o=B(e.name).toLowerCase(),s=i=>{const t=i.replace(/^=/u,"");if(!t.toLowerCase().startsWith(o))return;const n=P(t.slice(o.length).replaceAll("$",""));if(!n||n.left!==n.right)return;const r=[];for(let f=n.top;f<=n.bottom;f++){const c=e.cells.find(u=>u.row===f&&u.col===n.left);r.push(typeof c?.value=="string"?c.value:"")}return r};for(const i of a.sheets)i.validations=i.validations.map(t=>{const[n]=t.formula??[],r=t.type==="list"&&typeof n=="string"?s(n):void 0;if(!r)return t;const f={...t,values:r};return delete f.formula,f});const l=a.sheets.indexOf(e);a.sheets=a.sheets.filter(i=>i!==e),a.names=a.names.flatMap(i=>i.sheet===void 0||i.sheet<l?[i]:i.sheet===l?[]:[{...i,sheet:i.sheet-1}])}const _=a=>a instanceof H?a.code:a??null;export function sameValue(a,e,o){if(typeof a=="number"&&typeof e=="number")return a===e?!0:Math.abs(a-e)<=Math.max(Math.abs(a),Math.abs(e))*o;if(a instanceof H||e instanceof H)return a?.code===e?.code;if(a===null||e===null){const s=a??e;return s===null||s===""||s===0||s===!1}return a===e}function Re(a,e){const o=[];for(const i of e.sheets)for(const t of i.formulas)t.shared.node&&ae(e,t.shared,i).volatile&&o.push(t);const s=new Set(o),l=[...o];for(;;){const i=l.pop();if(!i)return s;for(const t of a.readers(i.sheet,i.row,i.col))s.has(t)||(s.add(t),l.push(t))}}function je(a,e,o,s){const l={formulas:0,same:0,uncached:0,moving:0,differences:[]},i=Re(o,e);for(const[t,n]of a.carried){if(!t.node)continue;const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.at(t.row,t.col);if(f instanceof ge&&i.has(f)){l.moving+=1;continue}const c=E(a,t);if(c===void 0){l.uncached+=1;continue}const u=o.value(r,t.row,t.col);sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:C(t.node),file:_(c),engine:_(u)})}for(const[t,n]of a.spilled){const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.spillAt(t.row,t.col);if(f&&i.has(f)){l.moving+=1;continue}const c=E(a,t),u=o.value(r,t.row,t.col);c===void 0?l.uncached+=1:sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:f?`${y(f)}#`:"",file:_(c),engine:_(u)})}return l}function De(a,e){const o=new Map,s=[];for(const l of a){const i=e.find(r=>l.startsWith(`${r}: `));if(i===void 0){s.push(l);continue}const t=l.slice(i.length+2),n=o.get(t);n?n.push(i):o.set(t,[i])}for(const[l,i]of o)s.push(i.length===1?`${i[0]??""}: ${l}`:`${l}, on ${String(i.length)} sheets (${R(i)})`);return s}export function importXlsx(a,e){const o=ye(a,e.zip);if(Ie(o),o.sheets.length===0)throw new Error("It holds no sheets.");const s={book:o,taken:e.taken??(()=>!1),files:new Map,assets:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(m=>m.tables.filter($=>te($)===void 0).map($=>$.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&s.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(J)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&s.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const l=Ae(s);ve(s);const i=o.sheets.map((m,$)=>{const p=new Oe(s,m).build(),d=l.sheets.get($);return d&&!k(d.names)&&(p.names=d.names),d&&d.hidden.length>0&&(p.hidden_names=d.hidden),p}),t=ze(s,l.names),n={title:o.title??e.name,...k(l.names)?{}:{names:l.names},...l.hidden.length>0?{hidden_names:l.hidden}:{},sheets:i,...k(t)?{}:{scenarios:t}},r=ke(n),f=new Map([[se,r],...s.files]),c=ue({text:r,read:m=>f.get(m),exists:m=>f.has(m)||s.assets.has(m)}),{workbook:u,calc:h,problems:w}=c;return{files:f,assets:s.assets,lost:De(s.lost,o.sheets.map(m=>m.name)),problems:w,compared:u&&h?je(s,u,h,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:s.tables.size}}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allyhub/sheet",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,6 +11,10 @@
11
11
  "types": "./dist/api/index.d.ts",
12
12
  "default": "./dist/api/index.js"
13
13
  },
14
+ "./sdk": {
15
+ "types": "./dist/sdk.d.ts",
16
+ "default": "./dist/sdk.js"
17
+ },
14
18
  "./xlsx": {
15
19
  "types": "./dist/xlsx/index.d.ts",
16
20
  "default": "./dist/xlsx/index.js"
@@ -62,27 +62,43 @@ export interface SlideClock {
62
62
  /** Each step's still, seconds into the slide: step 0 first, the last the slide's. */
63
63
  rests: number[];
64
64
  }
65
- /** An animation as slides.yaml has it, with its defaults; undefined for a path that does not read. */
65
+ /** An animation as the slides file has it, with its defaults; undefined for a path that does not read. */
66
66
  export declare function resolveAnimation(a: AnimationFile): ResolvedAnimation | undefined;
67
67
  /**
68
- * A slide's clock. `settle` is how long what moves by its own code takes:
69
- * a step that brings on one of `moving` (a component) rests no sooner than
70
- * that after it comes on, and a slide with nothing animated rests at it.
68
+ * A slide's clock. `moving` is how long each shape that moves by its own
69
+ * code (a component) takes, by name: a step that brings one on rests no
70
+ * sooner than that after it comes on, and one with no entrance moves from
71
+ * the slide's start. `settle` is the window of a slide with nothing
72
+ * animated: it rests at it, or once what moves has.
71
73
  * A click's animations start `frame` after the last rest, so a still never
72
74
  * shows what the next click brings. `lead` is the transition's: what is
73
75
  * on the slide starts when it is over.
74
76
  */
75
- export declare function slideClock(animations: readonly ResolvedAnimation[], moving: readonly string[], settle: number, frame?: number, lead?: number): SlideClock;
76
- /** A slide's window on the stage's clock when nothing on it is animated, seconds: what moves in its components has settled by then. */
77
+ export declare function slideClock(animations: readonly ResolvedAnimation[], moving: ReadonlyMap<string, number>, settle: number, frame?: number, lead?: number): SlideClock;
78
+ /** A slide's window on the stage's clock when nothing on it is animated, seconds; and how long a component moves unless its `dur` says. */
77
79
  export declare const SLIDE_SECONDS = 4;
80
+ /** How long a component moves, seconds from when it comes on: its own `dur`, else SLIDE_SECONDS. */
81
+ export declare const componentSeconds: (c: {
82
+ dur?: number;
83
+ }) => number;
78
84
  /** The stage's frame rate for a deck: the grid a slide's still is on. */
79
85
  export declare const DECK_FPS = 30;
86
+ /**
87
+ * Whether `t`, seconds into a slide, is still its transition of `lead`
88
+ * seconds. A slide's time is stage time less its start, a sum over the
89
+ * slides before it, which can fall a hair short of the transition's end,
90
+ * where what comes on with the slide starts: within a millionth of a
91
+ * second (far under a frame), the transition is over.
92
+ */
93
+ export declare const inTransition: (t: number, lead: number) => boolean;
80
94
  /** A slide's clock as the stage and the exports go by: on the frame grid, the first slide with no transition. */
81
95
  export declare function clockOf(slide: {
82
96
  animations: readonly ResolvedAnimation[];
83
97
  shapes: readonly {
84
98
  name: string;
85
- component?: unknown;
99
+ component?: {
100
+ dur?: number;
101
+ };
86
102
  }[];
87
103
  transition?: ResolvedTransition;
88
104
  }, first: boolean): SlideClock & {