@allyhub/sdk 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/dist/define.d.ts +4 -0
  2. package/dist/define.js +1 -1
  3. package/dist/node_modules/@allyhub-next/audio/dist/node/index.d.ts +1 -1
  4. package/dist/node_modules/@allyhub-next/audio/dist/node/index.js +1 -1
  5. package/dist/node_modules/@allyhub-next/audio/dist/node/master.d.ts +4 -0
  6. package/dist/node_modules/@allyhub-next/audio/dist/node/master.js +1 -1
  7. package/dist/node_modules/@allyhub-next/audio/package.json +1 -1
  8. package/dist/node_modules/@allyhub-next/chart/dist/chart-xml.js +2 -2
  9. package/dist/node_modules/@allyhub-next/chart/dist/chart.d.ts +14 -5
  10. package/dist/node_modules/@allyhub-next/chart/dist/chart.js +1 -1
  11. package/dist/node_modules/@allyhub-next/chart/package.json +1 -1
  12. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.d.ts +205 -0
  13. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.js +2 -0
  14. package/dist/node_modules/@allyhub-next/formats/dist/data/script.d.ts +4 -1
  15. package/dist/node_modules/@allyhub-next/formats/dist/data/script.js +1 -1
  16. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.d.ts +69 -18
  17. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.js +1 -1
  18. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.d.ts +847 -116
  19. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.js +1 -1
  20. package/dist/node_modules/@allyhub-next/formats/dist/data/website.d.ts +20 -0
  21. package/dist/node_modules/@allyhub-next/formats/dist/data/website.js +2 -0
  22. package/dist/node_modules/@allyhub-next/formats/dist/index.d.ts +3 -0
  23. package/dist/node_modules/@allyhub-next/formats/dist/index.js +1 -1
  24. package/dist/node_modules/@allyhub-next/formats/dist/items.d.ts +1 -1
  25. package/dist/node_modules/@allyhub-next/formats/dist/items.js +1 -1
  26. package/dist/node_modules/@allyhub-next/formats/dist/media-type.d.ts +3 -0
  27. package/dist/node_modules/@allyhub-next/formats/dist/media-type.js +2 -0
  28. package/dist/node_modules/@allyhub-next/formats/dist/schemas.d.ts +501 -38
  29. package/dist/node_modules/@allyhub-next/formats/dist/schemas.js +1 -1
  30. package/dist/node_modules/@allyhub-next/formats/dist/strict.d.ts +2 -0
  31. package/dist/node_modules/@allyhub-next/formats/dist/strict.js +1 -1
  32. package/dist/node_modules/@allyhub-next/formats/package.json +2 -1
  33. package/dist/node_modules/@allyhub-next/ooxml/LICENSE +241 -0
  34. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.d.ts +31 -0
  35. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.js +2 -0
  36. package/dist/node_modules/@allyhub-next/ooxml/dist/color.d.ts +33 -0
  37. package/dist/node_modules/@allyhub-next/ooxml/dist/color.js +2 -0
  38. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.d.ts +13 -0
  39. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.js +2 -0
  40. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.d.ts +79 -0
  41. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.js +2 -0
  42. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.d.ts +132 -0
  43. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.js +2 -0
  44. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.d.ts +28 -0
  45. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.js +2 -0
  46. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.d.ts +4708 -0
  47. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.js +2 -0
  48. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.d.ts +57 -0
  49. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.js +2 -0
  50. package/dist/node_modules/@allyhub-next/ooxml/dist/index.d.ts +10 -0
  51. package/dist/node_modules/@allyhub-next/ooxml/dist/index.js +2 -0
  52. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.d.ts +12 -0
  53. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.js +2 -0
  54. package/dist/node_modules/@allyhub-next/ooxml/dist/node.d.ts +111 -0
  55. package/dist/node_modules/@allyhub-next/ooxml/dist/node.js +2 -0
  56. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.d.ts +45 -0
  57. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.js +2 -0
  58. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.d.ts +48 -0
  59. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.js +2 -0
  60. package/dist/node_modules/@allyhub-next/ooxml/dist/report.d.ts +45 -0
  61. package/dist/node_modules/@allyhub-next/ooxml/dist/report.js +2 -0
  62. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.d.ts +28 -0
  63. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.js +2 -0
  64. package/dist/node_modules/@allyhub-next/ooxml/package.json +26 -0
  65. package/dist/node_modules/@allyhub-next/protocol/dist/account.d.ts +338 -0
  66. package/dist/node_modules/@allyhub-next/protocol/dist/account.js +2 -0
  67. package/dist/node_modules/@allyhub-next/protocol/dist/auth.d.ts +12 -13
  68. package/dist/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  69. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.d.ts +35 -0
  70. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.js +2 -0
  71. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.d.ts +101 -32
  72. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.js +1 -1
  73. package/dist/node_modules/@allyhub-next/protocol/dist/editor.d.ts +79 -5
  74. package/dist/node_modules/@allyhub-next/protocol/dist/editor.js +1 -1
  75. package/dist/node_modules/@allyhub-next/protocol/dist/files.d.ts +2 -2
  76. package/dist/node_modules/@allyhub-next/protocol/dist/index.d.ts +6 -0
  77. package/dist/node_modules/@allyhub-next/protocol/dist/index.js +1 -1
  78. package/dist/node_modules/@allyhub-next/protocol/dist/notes.d.ts +21 -0
  79. package/dist/node_modules/@allyhub-next/protocol/dist/notes.js +1 -1
  80. package/dist/node_modules/@allyhub-next/protocol/dist/open.d.ts +13 -0
  81. package/dist/node_modules/@allyhub-next/protocol/dist/open.js +2 -0
  82. package/dist/node_modules/@allyhub-next/protocol/dist/registry.d.ts +73 -59
  83. package/dist/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  84. package/dist/node_modules/@allyhub-next/protocol/dist/routes.d.ts +1 -1
  85. package/dist/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  86. package/dist/node_modules/@allyhub-next/protocol/dist/shares.d.ts +115 -0
  87. package/dist/node_modules/@allyhub-next/protocol/dist/shares.js +2 -0
  88. package/dist/node_modules/@allyhub-next/protocol/dist/sites.d.ts +293 -0
  89. package/dist/node_modules/@allyhub-next/protocol/dist/sites.js +2 -0
  90. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.d.ts +377 -0
  91. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.js +2 -0
  92. package/dist/node_modules/@allyhub-next/protocol/dist/teams.d.ts +27 -9
  93. package/dist/node_modules/@allyhub-next/protocol/dist/teams.js +1 -1
  94. package/dist/node_modules/@allyhub-next/protocol/dist/tools.d.ts +53 -14
  95. package/dist/node_modules/@allyhub-next/protocol/dist/tools.js +1 -1
  96. package/dist/node_modules/@allyhub-next/protocol/package.json +2 -1
  97. package/dist/node_modules/@allyhub-next/runtimes/package.json +1 -1
  98. package/dist/node_modules/@allyhub-next/runtimes/schemas/runtimes.schema.json +25 -5
  99. package/dist/node_modules/@allyhub-next/scenery/package.json +1 -1
  100. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.d.ts +9 -3
  101. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.js +1 -1
  102. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.d.ts +5 -1
  103. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.js +1 -1
  104. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.d.ts +60 -13
  105. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.js +1 -1
  106. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/aggregate.js +1 -1
  107. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.d.ts +4 -0
  108. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.js +2 -0
  109. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/criteria.js +1 -1
  110. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/database.js +1 -1
  111. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/date.js +1 -1
  112. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.d.ts +27 -1
  113. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.js +1 -1
  114. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.d.ts +16 -0
  115. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.js +2 -0
  116. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.d.ts +18 -1
  117. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.js +1 -1
  118. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/finance.js +1 -1
  119. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.d.ts +2 -0
  120. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.js +1 -1
  121. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/info.js +1 -1
  122. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/kernels.js +1 -1
  123. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/logical.js +1 -1
  124. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/lookup.js +1 -1
  125. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/maths.js +1 -1
  126. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.d.ts +2 -0
  127. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.js +2 -0
  128. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/text.js +1 -1
  129. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.d.ts +38 -0
  130. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.js +2 -0
  131. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.d.ts +19 -0
  132. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.js +2 -0
  133. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.d.ts +49 -0
  134. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.js +2 -0
  135. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.d.ts +82 -0
  136. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.js +2 -0
  137. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.d.ts +6 -1
  138. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.js +1 -1
  139. package/dist/node_modules/@allyhub-next/sheet/dist/chart.js +1 -1
  140. package/dist/node_modules/@allyhub-next/sheet/dist/check.js +1 -1
  141. package/dist/node_modules/@allyhub-next/sheet/dist/diff.d.ts +15 -0
  142. package/dist/node_modules/@allyhub-next/sheet/dist/diff.js +1 -1
  143. package/dist/node_modules/@allyhub-next/sheet/dist/export.d.ts +29 -8
  144. package/dist/node_modules/@allyhub-next/sheet/dist/export.js +3 -4
  145. package/dist/node_modules/@allyhub-next/sheet/dist/file.js +2 -2
  146. package/dist/node_modules/@allyhub-next/sheet/dist/format.d.ts +8 -2
  147. package/dist/node_modules/@allyhub-next/sheet/dist/format.js +1 -1
  148. package/dist/node_modules/@allyhub-next/sheet/dist/html.d.ts +52 -4
  149. package/dist/node_modules/@allyhub-next/sheet/dist/html.js +43 -11
  150. package/dist/node_modules/@allyhub-next/sheet/dist/index.d.ts +7 -3
  151. package/dist/node_modules/@allyhub-next/sheet/dist/index.js +1 -1
  152. package/dist/node_modules/@allyhub-next/sheet/dist/inspect.js +1 -1
  153. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.d.ts +98 -0
  154. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.js +2 -0
  155. package/dist/node_modules/@allyhub-next/sheet/dist/structure.js +1 -1
  156. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.d.ts +32 -0
  157. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.js +2 -0
  158. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.d.ts +3 -0
  159. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.js +2 -0
  160. package/dist/node_modules/@allyhub-next/sheet/dist/values.js +1 -1
  161. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.d.ts +10 -1
  162. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.js +1 -1
  163. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.d.ts +10 -1
  164. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.js +1 -1
  165. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.d.ts +14 -4
  166. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.js +2 -2
  167. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.d.ts +11 -1
  168. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.js +36 -16
  169. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.d.ts +3 -1
  170. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.js +1 -1
  171. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.d.ts +42 -1
  172. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.js +2 -1
  173. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.d.ts +23 -0
  174. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.js +2 -0
  175. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.d.ts +2 -0
  176. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.js +1 -1
  177. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.d.ts +6 -0
  178. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.js +1 -1
  179. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.d.ts +40 -0
  180. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.js +2 -0
  181. package/dist/node_modules/@allyhub-next/sheet/package.json +1 -1
  182. package/dist/node_modules/@allyhub-next/slides-core/dist/animation.js +1 -1
  183. package/dist/node_modules/@allyhub-next/slides-core/dist/api.d.ts +59 -39
  184. package/dist/node_modules/@allyhub-next/slides-core/dist/api.js +2 -2
  185. package/dist/node_modules/@allyhub-next/slides-core/dist/capabilities.js +1 -1
  186. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.d.ts +27 -13
  187. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.js +1 -1
  188. package/dist/node_modules/@allyhub-next/slides-core/dist/check.js +1 -1
  189. package/dist/node_modules/@allyhub-next/slides-core/dist/code.d.ts +33 -0
  190. package/dist/node_modules/@allyhub-next/slides-core/dist/code.js +2 -0
  191. package/dist/node_modules/@allyhub-next/slides-core/dist/components.d.ts +31 -0
  192. package/dist/node_modules/@allyhub-next/slides-core/dist/components.js +2 -0
  193. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.d.ts +179 -16
  194. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.js +1 -1
  195. package/dist/node_modules/@allyhub-next/slides-core/dist/file.d.ts +43 -21
  196. package/dist/node_modules/@allyhub-next/slides-core/dist/file.js +3 -3
  197. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.d.ts +17 -0
  198. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.js +2 -0
  199. package/dist/node_modules/@allyhub-next/slides-core/dist/index.d.ts +5 -1
  200. package/dist/node_modules/@allyhub-next/slides-core/dist/index.js +1 -1
  201. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.d.ts +6 -0
  202. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.js +2 -0
  203. package/dist/node_modules/@allyhub-next/slides-core/dist/measure.js +1 -1
  204. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.d.ts +58 -0
  205. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.js +2 -0
  206. package/dist/node_modules/@allyhub-next/slides-core/dist/model.d.ts +2 -4
  207. package/dist/node_modules/@allyhub-next/slides-core/dist/office.d.ts +17 -1
  208. package/dist/node_modules/@allyhub-next/slides-core/dist/office.js +1 -1
  209. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.d.ts +21 -5
  210. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.js +1 -1
  211. package/dist/node_modules/@allyhub-next/slides-core/dist/script.d.ts +18 -16
  212. package/dist/node_modules/@allyhub-next/slides-core/dist/script.js +2 -2
  213. package/dist/node_modules/@allyhub-next/slides-core/dist/stage.d.ts +51 -53
  214. package/dist/node_modules/@allyhub-next/slides-core/dist/strict.js +1 -1
  215. package/dist/node_modules/@allyhub-next/slides-core/dist/units.d.ts +27 -0
  216. package/dist/node_modules/@allyhub-next/slides-core/dist/units.js +1 -1
  217. package/dist/node_modules/@allyhub-next/slides-core/dist/values.d.ts +7 -0
  218. package/dist/node_modules/@allyhub-next/slides-core/dist/values.js +2 -0
  219. package/dist/node_modules/@allyhub-next/slides-core/package.json +1 -1
  220. package/dist/node_modules/@allyhub-next/video-core/dist/captions.js +6 -6
  221. package/dist/node_modules/@allyhub-next/video-core/dist/fact.d.ts +47 -8
  222. package/dist/node_modules/@allyhub-next/video-core/dist/fact.js +1 -1
  223. package/dist/node_modules/@allyhub-next/video-core/dist/index.d.ts +1 -0
  224. package/dist/node_modules/@allyhub-next/video-core/dist/index.js +1 -1
  225. package/dist/node_modules/@allyhub-next/video-core/dist/marks.d.ts +14 -0
  226. package/dist/node_modules/@allyhub-next/video-core/dist/marks.js +1 -1
  227. package/dist/node_modules/@allyhub-next/video-core/dist/music.d.ts +2 -1
  228. package/dist/node_modules/@allyhub-next/video-core/dist/piece.d.ts +11 -2
  229. package/dist/node_modules/@allyhub-next/video-core/dist/problem.d.ts +4 -0
  230. package/dist/node_modules/@allyhub-next/video-core/dist/problem.js +1 -1
  231. package/dist/node_modules/@allyhub-next/video-core/dist/schema.d.ts +2 -2
  232. package/dist/node_modules/@allyhub-next/video-core/dist/schema.js +1 -1
  233. package/dist/node_modules/@allyhub-next/video-core/dist/script.d.ts +2 -1
  234. package/dist/node_modules/@allyhub-next/video-core/dist/script.js +1 -1
  235. package/dist/node_modules/@allyhub-next/video-core/dist/source.d.ts +7 -0
  236. package/dist/node_modules/@allyhub-next/video-core/dist/source.js +2 -0
  237. package/dist/node_modules/@allyhub-next/video-core/dist/timeline.d.ts +10 -33
  238. package/dist/node_modules/@allyhub-next/video-core/package.json +1 -1
  239. package/dist/slides.d.ts +3 -1
  240. package/dist/slides.js +1 -1
  241. package/docs/README.md +1 -0
  242. package/docs/contract.md +1 -1
  243. package/docs/defaults.md +2 -2
  244. package/docs/layers.md +1 -1
  245. package/docs/project.md +3 -1
  246. package/docs/sheets.md +7 -6
  247. package/docs/slides.md +16 -12
  248. package/docs/sound.md +1 -1
  249. package/docs/websites.md +57 -0
  250. package/package.json +3 -1
  251. package/dist/node_modules/@allyhub-next/slides-core/dist/preset.d.ts +0 -5
  252. package/dist/node_modules/@allyhub-next/slides-core/dist/preset.js +0 -2
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{columnIndex as L,columnLetter as k,readArea as D}from"./address.js";import{chartSize as y}from"./chart.js";export const DEFAULT_COLUMN_WIDTH=64,DEFAULT_ROW_HEIGHT=20;const u=96;export const PAPERS={letter:{width:8.5*u,height:11*u},tabloid:{width:11*u,height:17*u},ledger:{width:17*u,height:11*u},legal:{width:8.5*u,height:14*u},executive:{width:7.25*u,height:10.5*u},a3:{width:297/25.4*u,height:420/25.4*u},a4:{width:210/25.4*u,height:297/25.4*u},a5:{width:148/25.4*u,height:210/25.4*u},b4:{width:257/25.4*u,height:364/25.4*u},b5:{width:182/25.4*u,height:257/25.4*u}},PRINT_DEFAULTS={paper:"a4",orientation:"portrait",margins:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3},scale:100};const N=10;export function columnWidth(o,t){const n=o.spec.columns?.[k(t)]?.width;if(n!==void 0)return n;for(const r of o.tables){const l=r.columns[t-r.at.col]?.spec?.width;if(l!==void 0)return l}return DEFAULT_COLUMN_WIDTH}export const rowHeight=(o,t)=>o.spec.rows?.[String(t+1)]?.height??DEFAULT_ROW_HEIGHT,rowHidden=(o,t,n)=>o.filtered(t).has(n)||t.spec.rows?.[String(n+1)]?.hidden===!0,columnHidden=(o,t)=>o.spec.columns?.[k(t)]?.hidden===!0;export function usedWithCharts(o){let t=o.used;for(const{spec:n,at:r}of o.charts){const{width:l,height:h}=y(n);let f=r.col;for(let c=(n.x??0)+l;c>0;f++)c-=columnWidth(o,f);let s=r.row;for(let c=(n.y??0)+h;c>0;s++)c-=rowHeight(o,s);t={top:0,left:0,bottom:Math.max(t?.bottom??0,s-1),right:Math.max(t?.right??0,f-1)}}return t}function U(o){const t=o.spec.print?.area;if(t!==void 0){const r=t.split(",").map(l=>D(l.slice(l.lastIndexOf("!")+1).replaceAll("$","")));if(r.every(l=>l!==void 0))return r}const n=usedWithCharts(o);return n?[n]:[]}function O(o,t){if(o===void 0)return;const[n,r]=o.split(":").map(t);return n===void 0||r===void 0?void 0:{from:Math.min(n,r),to:Math.max(n,r)}}function E(o){const t=[0];for(const n of o)t.push((t[t.length-1]??0)+n);return t}function v(o,t,n,r,l){const h=E(o),f=[];let s=0;for(;s<o.length;){const c=t-n(s);let i=s+1;for(;i<o.length&&!r.has(i)&&(h[i+1]??0)-(h[s]??0)<=c;)i++;if(i<o.length&&!r.has(i))for(let w=!0;w;){w=!1;const x=h[i]??0;for(const m of l){if(!(m.from<x&&x<m.to)||m.to-m.from>c)continue;let d=i;for(;d>s&&(h[d]??0)>m.from;)d--;d>s&&d<i&&(i=d,w=!0)}}f.push({from:s,to:i}),s=i}return f}function _(o,t,n,r){const l=(s,c,i)=>i===void 0?0:s.filter(w=>w<i).reduce((w,x)=>w+c(x),0),h=o.height,f=s=>columnWidth(o.sheet,s);return{down:v(o.heights,t.height/n,s=>l(o.titleRows,h,o.rows[s]),r?o.rowBreaks:new Set,o.rowReaches),across:v(o.widths,t.width/n,s=>l(o.titleCols,f,o.cols[s]),r?o.colBreaks:new Set,o.colReaches)}}function W(o,t,n,r){const l=t.spec.print,h=[];for(let e=n.top;e<=n.bottom;e++)rowHidden(o,t,e)||h.push(e);const f=[];for(let e=n.left;e<=n.right;e++)columnHidden(t,e)||f.push(e);const s=h.map(r),c=f.map(e=>columnWidth(t,e)),i=(e,a)=>{const p=[];if(e)for(let A=e.from;A<=e.to;A++)a(A)||p.push(A);return p},w=i(O(l?.title_rows,e=>/^\d+$/u.test(e)?Number(e)-1:void 0),e=>rowHidden(o,t,e)),x=i(O(l?.title_cols,L),e=>columnHidden(t,e)),m=(e,a)=>new Set(a.map(p=>e.findIndex(A=>A>=p)).filter(p=>p>0)),d=m(h,(l?.breaks?.rows??[]).map(e=>e-1)),M=m(f,(l?.breaks?.cols??[]).flatMap(e=>{const a=L(e);return a===void 0?[]:[a]})),C=E(s),R=E(c),S=(e,a,p,A,I)=>{let T=e.findIndex(B=>B>=p);T<0&&(T=e.length);const H=(a[T]??0)+A;return{from:H,to:H+I}},g=[],b=[];for(const{spec:e,at:a}of t.charts){const p=y(e);g.push(S(h,C,a.row,e.y??0,p.height)),b.push(S(f,R,a.col,e.x??0,p.width))}return{sheet:t,height:r,rows:h,heights:s,cols:f,widths:c,titleRows:w,titleCols:x,rowBreaks:d,colBreaks:M,rowReaches:g,colReaches:b,rowAt:C,colAt:R}}function F(o,t,n,r){const l=t.rowAt[n.from]??0,h=t.rowAt[n.to]??0,f=t.colAt[r.from]??0,s=t.colAt[r.to]??0;if(t.charts.some(c=>c.left<s&&c.left+c.width>f&&c.top<h&&c.top+c.height>l))return!0;for(let c=n.from;c<n.to;c++)for(let i=r.from;i<r.to;i++)if(o.value(t.sheet,t.rows[c]??0,t.cols[i]??0)!==null)return!0;return!1}export function paginate(o,t={}){const n=t.sheets??o.wb.sheets.filter(h=>h.spec.hidden!==!0),r=[],l=[];for(const h of n){const f=h.spec.print,s=PAPERS[f?.paper??PRINT_DEFAULTS.paper],c=(f?.orientation??PRINT_DEFAULTS.orientation)==="landscape"?{width:s.height,height:s.width}:s,i=m=>(f?.margins?.[m]??PRINT_DEFAULTS.margins[m])*u,w={left:i("left"),right:i("right"),top:i("top"),bottom:i("bottom"),header:i("header"),footer:i("footer")},x={width:Math.max(1,c.width-w.left-w.right),height:Math.max(1,c.height-w.top-w.bottom)};for(const m of U(h)){const d=W(o,h,m,g=>t.height?t.height(h,g):rowHeight(h,g));if(d.rows.length===0||d.cols.length===0)continue;const M=f?.fit;let C=f?.scale??PRINT_DEFAULTS.scale,R=_(d,x,C/100,M===void 0);if(M!==void 0){const g=M.width??1,b=M.height??1,e=a=>(g===0||a.across.length<=g)&&(b===0||a.down.length<=b);if(C=100,R=_(d,x,1,!1),!e(R)){let a=N,p=99,A=_(d,x,a/100,!1);for(;a<p;){const I=Math.ceil((a+p)/2),T=_(d,x,I/100,!1);e(T)?(a=I,A=T):p=I-1}C=a,R=A}}const S={sheet:h,rows:d.rows,heights:d.heights,cols:d.cols,widths:d.widths,titleRows:d.titleRows,titleCols:d.titleCols,rowAt:d.rowAt,colAt:d.colAt,charts:h.charts.map((g,b)=>{const e=d.colReaches[b]??{from:0,to:0},a=d.rowReaches[b]??{from:0,to:0};return{chart:g,left:e.from,top:a.from,width:e.to-e.from,height:a.to-a.from}}),down:R.down,across:R.across,paper:c,margins:w,scale:C/100,...f?.header?{header:f.header}:{},...f?.footer?{footer:f.footer}:{}};r.push(S);for(const g of S.across)for(const b of S.down)F(o,S,b,g)&&l.push({of:S,down:b,across:g,number:l.length+1})}}return{sheets:r,pages:l}}export const pageTitleRows=o=>{const t=o.of.rows[o.down.from];return t===void 0?[]:o.of.titleRows.filter(n=>n<t)},pageTitleCols=o=>{const t=o.of.cols[o.across.from];return t===void 0?[]:o.of.titleCols.filter(n=>n<t)};
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{MAX_COLUMNS as G,MAX_ROWS as H,cellName as v,columnIndex as R,columnLetter as _,rangeName as M,readAddress as y,readArea as A,readAreas as J}from"./address.js";import{chartAfter as Q}from"./chart.js";import{moveFormula as V,relativeKey as Y}from"./formula/move.js";import{parseFormula as z}from"./formula/parse.js";import{printFormula as N}from"./formula/print.js";import{rewriteFormula as B}from"./formula/rewrite.js";import{walk as Z}from"./formula/walk.js";import{readTyped as tt}from"./values.js";import{chartFormula as nt}from"./workbook.js";const $=r=>r.op==="insert-rows"||r.op==="delete-rows"||r.op==="insert-columns"||r.op==="delete-columns",k=r=>r.op==="insert-rows"||r.op==="insert-columns",b=r=>r.op==="insert-rows"||r.op==="delete-rows";function x(r,t){return k(t)?r>=t.at?r+t.count:r:r<t.at?r:r>=t.at+t.count?r-t.count:void 0}function P(r,t){const n=y(r);if(!n)return r;const s=x(b(t)?n.row:n.col,t);if(s!==void 0)return v(b(t)?{...n,row:s}:{...n,col:s})}function K(r,t){return Object.fromEntries(Object.entries(r).flatMap(([n,s])=>{const i=P(n,t);return i===void 0?[]:[[i,s]]}))}const et=r=>b(r)?H:G;function E(r,t,n){const s=et(n);if(k(n)){const e=r>=n.at?r+n.count:r,c=t>=n.at?t+n.count:t;return e>=s?void 0:[e,Math.min(c,s-1)]}const i=n.at+n.count-1;if(r>=n.at&&t<=i)return;const a=r<n.at?r:r>i?r-n.count:n.at,o=t<n.at?t:t>i?t-n.count:n.at-1;return[a,o]}function L(r,t){const n=b(t)?E(r.top,r.bottom,t):E(r.left,r.right,t);if(n)return b(t)?{...r,top:n[0],bottom:n[1]}:{...r,left:n[0],right:n[1]}}function ot(r,t,n,s){let i=0;const a=(o,e)=>{o&&!o.abs&&(i=Math.max(i,Math.abs(o.index-e)))};return Z(r,o=>{o.kind==="ref"&&(t?(a(o.row,n),a(o.row2,n)):(a(o.col,s),a(o.col2,s)))}),i}function st(r,t,n,s){const i=new Set,a=l=>{for(let f=l-s-1;f<=l+s+1;f++)f>=r&&f<=t&&i.add(f)};a(n.at),a(n.at+n.count);const o=[...i].sort((l,f)=>l-f),e=[];let c=r;for(const l of o)l>c&&e.push([c,l-1]),e.push([l,l]),c=l+1;return c<=t&&e.push([c,t]),e}function rt(r,t,n,s,i){const a=z(t);if(!a.ok){const m=i?L(r,s):r;return m?[{area:m,text:t}]:[]}const o=b(s),[e,c]=o?[r.top,r.bottom]:[r.left,r.right],l=ot(a.node,o,r.top,r.left),f=[];let u=!0;for(const[m,d]of st(e,c,s,l)){const w=o?m:r.top,p=o?r.left:m,h=i?x(m,s):m;if(h===void 0)continue;const g=i?x(d,s):d;if(g===void 0)continue;const C=V(a.node,w-r.top,p-r.left),S=B(C,s,n);S!==C&&(u=!1);const q=o?h:r.top,D=o?r.left:h,F=Y(S,q,D),I=f[f.length-1];I?.key===F&&I.to+1===h?I.to=g:f.push({from:h,to:g,key:F,text:N(S)})}return f.map(m=>({area:o?{...r,top:m.from,bottom:m.to}:{...r,left:m.from,right:m.to},text:u&&f.length===1?t:m.text}))}function W(r,t){return r!==null&&typeof r=="object"?{...r,formula:t}:t}const it=r=>{if(typeof r=="string")return r.startsWith("=")?r:void 0;if(!(r===null||typeof r!="object"))return r.formula!==void 0?r.formula.startsWith("=")?r.formula:`=${r.formula}`:typeof r.value=="string"&&r.value.startsWith("=")?r.value:void 0};function O(r,t,n,s){const i=z(r);if(!i.ok)return r;const a=B(i.node,t,n,s);return a===i.node?r:N(a)}function ct(r,t,n,s){const i={},a=$(n)?n:void 0;for(const[o,e]of Object.entries(r)){const c=it(e),l=A(o);if(!l){i[o]=e;continue}const f=s&&a!==void 0;if(o.includes(":")){if(!a){i[o]=c===void 0?e:W(e,O(c,n,t));continue}if(c!==void 0){for(const h of rt(l,c,t,a,f))i[M(h.area)]=W(e,h.text);continue}if(!f){i[o]=e;continue}if(!k(a)){const h=L(l,a);h&&(i[M(h)]=e);continue}const d=b(a),[w,p]=d?[l.top,l.bottom]:[l.left,l.right];for(const[h,g]of[[w,Math.min(p,a.at-1)],[Math.max(w,a.at),p]]){if(h>g)continue;const C=h>=a.at?a.count:0,S=d?{...l,top:h+C,bottom:g+C}:{...l,left:h+C,right:g+C};i[M(S)]=e}continue}const u={row:l.top,col:l.left};let m=u;if(f){const d=x(b(a)?u.row:u.col,a);m=d===void 0?void 0:b(a)?{...u,row:d}:{...u,col:d}}m&&(i[v(m)]=c===void 0?e:W(e,O(c,n,t)))}return i}export function tableShape(r,t){const n=y(r.at);if(!n)return;const s=t[0]??[],i=s.map(e=>e.trim()),a=new Set(i.map(e=>e.toLowerCase()));for(const e of Object.keys(r.columns??{}))a.has(e.toLowerCase())||i.push(e);const o=[];return t.forEach((e,c)=>{c>0&&e.length>0&&o.push(c)}),{at:n,header:s,names:i,places:o}}const T=r=>r.reduce((t,n)=>Math.max(t,n.length),0);function U(r,t,n){const s=Math.max(T(r),1),i=Array.from({length:n},()=>new Array(s).fill(""));return[...r.slice(0,t),...i,...r.slice(t)]}export function freeColumn(r,t="Column"){const n=new Set(r.map(s=>s.toLowerCase()));for(let s=1;;s++){const i=`${t}${String(s)}`;if(!n.has(i.toLowerCase()))return i}}export function uniqueColumn(r,t){const n=new Set(r.map(s=>s.toLowerCase()));if(!n.has(t.toLowerCase()))return t;for(let s=2;;s++){const i=`${t}${String(s)}`;if(!n.has(i.toLowerCase()))return i}}export function withColumnsUpTo(r,t,n){const s=r.map(o=>[...o]),i=s[0]??[];for(s.length===0&&s.push(i);i.length<=n;)i.push(t[i.length]??"");const a=i.length;for(let o=1;o<s.length;o++){const e=s[o];if(e&&e.length>0)for(;e.length<a;)e.push("")}return s}class X{file;rows;edit;after=[];refused;constructor(t,n){this.file=structuredClone(t.file),this.rows=new Map(t.rows),this.edit=n}sheets(){return this.file.sheets}rewrite(t){const n=this.file.sheets[0]?.name??"";if(this.file.names)for(const[s,i]of Object.entries(this.file.names))typeof i=="string"&&i.startsWith("=")&&(this.file.names[s]=O(i,t,n));for(const s of this.file.checks??[])s.formula=O(s.formula,t,n);for(const s of this.sheets())this.rewriteSheet(s,t)}rewriteSheet(t,n){const s=$(n)&&j(t.name,n.sheet);t.cells&&(t.cells=ct(t.cells,t.name,n,s));for(const i of t.tables??[]){for(const a of Object.values(i.columns??{}))a.formula!==void 0&&(a.formula=O(a.formula,n,t.name,i.name));this.rewriteCsv(i.rows,n,t.name,i.name)}for(const i of t.blocks??[])this.rewriteCsv(i.rows,n,t.name);this.rewriteRules(t,n)}freePath(t,n){const s=t.slice(0,t.lastIndexOf("/")+1),i=o=>[...this.rows.keys()].some(e=>j(e,o));let a=`${s}${n}.csv`;for(let o=2;i(a);o++)a=`${s}${n}-${String(o)}.csv`;return a}duplicate(t,n){const s=this.sheets(),i=s.findIndex(f=>j(f.name,t)),a=s[i];if(!a){this.refused="no-sheet";return}const o=structuredClone(a);o.name=n,delete o.hidden;for(const f of Object.values(o.cells??{}))f!==null&&typeof f=="object"&&delete f.name;const e=new Set(s.flatMap(f=>f.tables??[]).map(f=>f.name.toLowerCase())),c=new Set(Object.keys(this.file.names??{}).map(f=>f.toLowerCase())),l=[];for(const f of o.tables??[]){let u=f.name;for(let d=2;;d++){u=`${f.name}${String(d)}`;const w=u.toLowerCase();if(!e.has(w)&&!c.has(w))break}e.add(u.toLowerCase());const m=this.freePath(f.rows,u);this.rows.set(m,this.rows.get(f.rows)??[]),l.push({op:"rename-table",from:f.name,to:u}),f.rows=m,f.name=u}for(const f of o.blocks??[]){const u=f.rows.slice(f.rows.lastIndexOf("/")+1,-4),m=this.freePath(f.rows,u);this.rows.set(m,this.rows.get(f.rows)??[]),f.rows=m}this.file.sheets=[...s.slice(0,i+1),o,...s.slice(i+1)],this.rewriteSheet(o,{op:"rename-sheet",from:t,to:n});for(const f of l)this.rewriteSheet(o,f)}rewriteRules(t,n){const s=e=>typeof e=="string"&&e.startsWith("=")?O(e,n,t.name):e,i=e=>e.value===void 0?e:{...e,value:s(e.value)},a=t.conditional?.map(e=>{switch(e.type){case"cellIs":return{...e,formula:e.formula.map(s)};case"expression":return{...e,formula:O(e.formula.startsWith("=")?e.formula:`=${e.formula}`,n,t.name)};case"dataBar":return{...e,...e.min?{min:i(e.min)}:{},...e.max?{max:i(e.max)}:{}};case"colorScale":return{...e,stops:e.stops.map(i)};case"iconSet":return e.stops?{...e,stops:e.stops.map(i)}:e;default:return e}});a&&(t.conditional=a);const o=t.validations?.map(e=>e.formula?{...e,formula:e.formula.map(s)}:e);o&&(t.validations=o),$(n)&&n.sheet===t.name&&(t.links&&(t.links=K(t.links,n)),t.notes&&(t.notes=K(t.notes,n)),t.pictures&&(t.pictures=t.pictures.flatMap(e=>{const c=P(e.at,n);return c===void 0?[]:[{...e,at:c}]}))),t.charts&&(t.charts=t.charts.map(e=>Q(e,c=>{const l=c.startsWith("="),f=O(nt(c),n,t.name);return l?f:f.slice(1)})))}rewriteCsv(t,n,s,i){const a=this.rows.get(t);if(!a)return;let o;a.forEach((e,c)=>{if(!e.some(f=>f.charCodeAt(0)===61))return;const l=e.map(f=>tt(f).formula===void 0?f:O(f,n,s,i));l.every((f,u)=>f===e[u])||(o??=[...a],o[c]=l)}),o&&this.rows.set(t,o)}tableOn(t,n){const s=b(n),i=[];for(const a of t.tables??[]){const o=this.rows.get(a.rows),e=o&&tableShape(a,o);if(!o||!e){i.push(a);continue}const c=e.at.row,l=e.at.col,f=c+e.places.length,u=l+Math.max(e.names.length,1)-1,[m,d]=s?[c,f]:[l,u];if(!k(n)&&n.at<=m&&n.at+n.count-1>=d){this.after.push({op:"delete-table",name:a.name});continue}const w={...e.at};if(s)if(k(n)){if(n.at<=c)w.row+=n.count;else if(n.at<=f){const p=e.places[n.at-c-1]??o.length;this.rows.set(a.rows,U(o,p,n.count))}}else{const p=n.at+n.count-1;if(p<c)w.row-=n.count;else if(n.at<=c){this.refused="table-header";return}else if(n.at<=f){const h=new Set(e.places.slice(n.at-c-1,p-c));this.rows.set(a.rows,o.filter((g,C)=>!h.has(C)))}}else if(k(n))n.at<=l?w.col+=n.count:n.at<=u&&this.columnsIn(a,e,n.at-l,n.count);else{const p=n.at+n.count-1;if(p<l)w.col-=n.count;else if(n.at<=u){w.col=Math.min(l,n.at);const h=Math.max(0,n.at-l),g=Math.min(e.names.length-1,p-l);this.columnsOut(a,e,h,g)}}a.at=v(w),i.push(a)}t.tables=i,i.length===0&&delete t.tables}columnsIn(t,n,s,i){const a=this.rows.get(t.rows)??[],o=s>0?withColumnsUpTo(a,n.names,s-1):a.map(c=>[...c]),e=[...n.names];o.forEach((c,l)=>{if(l>0&&c.length===0)return;const f=[];for(let u=0;u<i;u++)if(l===0){const m=freeColumn(e);e.push(m),f.push(m)}else f.push("");for(;c.length<s;)c.push("");c.splice(s,0,...f)}),this.rows.set(t.rows,o)}columnsOut(t,n,s,i){const a=n.names.slice(s,i+1),o=this.rows.get(t.rows)??[],e=n.header.length,c=new Set;for(let l=s;l<=i&&l<e;l++)c.add(l);if(c.size>0&&this.rows.set(t.rows,o.map(l=>l.length===0?l:l.filter((f,u)=>!c.has(u)))),t.columns){const l=new Set(a.map(f=>f.toLowerCase()));t.columns=Object.fromEntries(Object.entries(t.columns).filter(([f])=>!l.has(f.toLowerCase()))),Object.keys(t.columns).length===0&&delete t.columns}if(t.key!==void 0&&a.some(l=>l.toLowerCase()===t.key?.toLowerCase())&&delete t.key,t.filter){const l=new Set(a.map(u=>u.toLowerCase())),f=Object.fromEntries(Object.entries(t.filter.columns).filter(([u])=>!l.has(u.toLowerCase())));Object.keys(f).length>0?t.filter={columns:f}:delete t.filter}for(const l of a)this.after.push({op:"delete-column",table:t.name,name:l})}blocksOn(t,n){const s=b(n),i=(t.blocks??[]).flatMap(a=>{const o=y(a.at),e=this.rows.get(a.rows);if(!o||!e)return[a];const c=s?o.row:o.col,l=s?e.length:Math.max(T(e),1),f=c+l-1,u=E(c,f,n);if(!u)return[];const m=s?{...o,row:u[0]}:{...o,col:u[0]};if(k(n)&&n.at>c&&n.at<=f){const d=n.at-c;this.rows.set(a.rows,s?U(e,d,n.count):e.map(w=>{if(w.length===0)return w;const p=[...w];for(;p.length<d;)p.push("");return p.splice(d,0,...new Array(n.count).fill("")),p}))}else if(!k(n)&&n.at<=f){const d=Math.max(n.at,c)-c,w=Math.min(n.at+n.count-1,f)-c;this.rows.set(a.rows,s?e.filter((p,h)=>h<d||h>w):e.map(p=>p.filter((h,g)=>g<d||g>w)))}return[{...a,at:v(m)}]});t.blocks=i,i.length===0&&delete t.blocks}looksOn(t,n){const s=b(n);t.format&&(t.format=t.format.flatMap(o=>{const e=A(o.range);if(!e)return[o];const c=L(e,n);return c?[{...o,range:M(c)}]:[]})),t.format?.length===0&&delete t.format,t.merges&&(t.merges=t.merges.flatMap(o=>{const e=A(o);if(!e)return[o];const c=L(e,n);return c?[M(c)]:[]})),t.merges?.length===0&&delete t.merges;const i=o=>{const e=J(o);if(!e)return o;const c=e.flatMap(l=>{const f=L(l,n);return f?[M(f)]:[]});return c.length===0?void 0:c.join(" ")};if(t.conditional&&(t.conditional=t.conditional.flatMap(o=>{const e=i(o.range);return e===void 0?[]:[{...o,range:e}]})),t.conditional?.length===0&&delete t.conditional,t.validations&&(t.validations=t.validations.flatMap(o=>{const e=i(o.range);return e===void 0?[]:[{...o,range:e}]})),t.validations?.length===0&&delete t.validations,t.charts&&(t.charts=t.charts.map(o=>{const e=y(o.at);if(!e)return o;const c=s?e.row:e.col,l=x(c,n)??n.at;return{...o,at:v(s?{...e,row:l}:{...e,col:l})}})),t.filter){const o=A(t.filter.range),e=o&&L(o,n);if(o&&!e)delete t.filter;else if(e){const c=s?t.filter.columns:Object.fromEntries(Object.entries(t.filter.columns??{}).flatMap(([l,f])=>{const u=R(l),m=u===void 0?void 0:x(u,n);return m===void 0?[]:[[_(m),f]]}));t.filter={range:M(e),...c&&Object.keys(c).length>0?{columns:c}:{}}}}if(t.freeze!==void 0){const o=y(t.freeze);if(o){const e=s?o.row:o.col,c=E(0,e-1,n),l=e===0?0:c?c[1]+1:0;t.freeze=v(s?{...o,row:l}:{...o,col:l})}}const a=(o,e,c)=>{if(!o)return;const l={};for(const[f,u]of Object.entries(o)){const m=e(f),d=m===void 0?void 0:x(m,n);m===void 0?l[f]=u:d!==void 0&&(l[c(d)]=u)}return l};if(s){const o=a(t.rows,e=>/^[1-9]\d*$/u.test(e)?Number(e)-1:void 0,e=>String(e+1));o&&(t.rows=o)}else{const o=a(t.columns,R,_);o&&(t.columns=o)}}run(){const t=this.edit;if($(t)){const n=this.sheets().find(s=>j(s.name,t.sheet));if(!n){this.refused="no-sheet";return}if(this.rewrite(t),this.tableOn(n,t),this.refused)return;this.blocksOn(n,t),this.looksOn(n,t);for(const s of this.after)this.rewrite(s);return}switch(t.op){case"rename-sheet":{this.rewrite(t);const n=this.sheets().find(s=>j(s.name,t.from));n&&(n.name=t.to);return}case"rename-column":{this.renameColumn(t.table,t.from,t.to),this.rewrite(t);return}case"delete-sheet":{const n=this.sheets(),s=n.find(i=>j(i.name,t.name));if(!s){this.refused="no-sheet";return}if(n.filter(i=>i.hidden!==!0).length<=1){this.refused="last-sheet";return}this.rewrite(t);for(const i of s.tables??[])this.rewrite({op:"delete-table",name:i.name});this.file.sheets=n.filter(i=>i!==s);return}default:this.rewrite(t)}}renameColumn(t,n,s){const i=this.sheets().flatMap(c=>c.tables??[]).find(c=>j(c.name,t));if(!i)return;const a=n.toLowerCase(),o=this.rows.get(i.rows),e=o?.[0]?.findIndex(c=>c.trim().toLowerCase()===a)??-1;if(o&&e>=0){const c=[...o[0]??[]];c[e]=s,this.rows.set(i.rows,[c,...o.slice(1)])}if(i.columns){const c=Object.keys(i.columns).find(l=>l.toLowerCase()===a);c!==void 0&&(i.columns=Object.fromEntries(Object.entries(i.columns).map(([l,f])=>[l===c?s:l,f])))}i.key?.toLowerCase()===a&&(i.key=s),i.filter&&(i.filter={columns:Object.fromEntries(Object.entries(i.filter.columns).map(([c,l])=>[c.toLowerCase()===a?s:c,l]))})}}const j=(r,t)=>r.toLowerCase()===t.toLowerCase();export function restructure(r,t){const n=new X(r,t);return n.run(),n.refused?{file:r.file,rows:new Map(r.rows),refused:n.refused}:{file:n.file,rows:n.rows}}export function duplicated(r,t,n){const s=new X(r,{op:"rename-sheet",from:t,to:n});return s.duplicate(t,n),s.refused?{file:r.file,rows:new Map(r.rows),refused:s.refused}:{file:s.file,rows:s.rows}}
2
+ import{MAX_COLUMNS as G,MAX_ROWS as H,cellName as v,columnIndex as R,columnLetter as _,rangeName as M,readAddress as y,readArea as A,readAreas as J}from"./address.js";import{chartAfter as Q}from"./chart.js";import{moveFormula as V,relativeKey as Y}from"./formula/move.js";import{parseFormula as z}from"./formula/parse.js";import{printFormula as N}from"./formula/print.js";import{rewriteFormula as B}from"./formula/rewrite.js";import{walk as Z}from"./formula/walk.js";import{readTyped as tt}from"./values.js";import{chartFormula as nt}from"./workbook.js";const $=r=>r.op==="insert-rows"||r.op==="delete-rows"||r.op==="insert-columns"||r.op==="delete-columns",k=r=>r.op==="insert-rows"||r.op==="insert-columns",b=r=>r.op==="insert-rows"||r.op==="delete-rows";function x(r,t){return k(t)?r>=t.at?r+t.count:r:r<t.at?r:r>=t.at+t.count?r-t.count:void 0}function P(r,t){const n=y(r);if(!n)return r;const s=x(b(t)?n.row:n.col,t);if(s!==void 0)return v(b(t)?{...n,row:s}:{...n,col:s})}function K(r,t){return Object.fromEntries(Object.entries(r).flatMap(([n,s])=>{const i=P(n,t);return i===void 0?[]:[[i,s]]}))}const et=r=>b(r)?H:G;function E(r,t,n){const s=et(n);if(k(n)){const e=r>=n.at?r+n.count:r,c=t>=n.at?t+n.count:t;return e>=s?void 0:[e,Math.min(c,s-1)]}const i=n.at+n.count-1;if(r>=n.at&&t<=i)return;const f=r<n.at?r:r>i?r-n.count:n.at,o=t<n.at?t:t>i?t-n.count:n.at-1;return[f,o]}function L(r,t){const n=b(t)?E(r.top,r.bottom,t):E(r.left,r.right,t);if(n)return b(t)?{...r,top:n[0],bottom:n[1]}:{...r,left:n[0],right:n[1]}}function ot(r,t,n,s){let i=0;const f=(o,e)=>{o&&!o.abs&&(i=Math.max(i,Math.abs(o.index-e)))};return Z(r,o=>{o.kind==="ref"&&(t?(f(o.row,n),f(o.row2,n)):(f(o.col,s),f(o.col2,s)))}),i}function st(r,t,n,s){const i=new Set,f=l=>{for(let a=l-s-1;a<=l+s+1;a++)a>=r&&a<=t&&i.add(a)};f(n.at),f(n.at+n.count);const o=[...i].sort((l,a)=>l-a),e=[];let c=r;for(const l of o)l>c&&e.push([c,l-1]),e.push([l,l]),c=l+1;return c<=t&&e.push([c,t]),e}function rt(r,t,n,s,i){const f=z(t);if(!f.ok){const m=i?L(r,s):r;return m?[{area:m,text:t}]:[]}const o=b(s),[e,c]=o?[r.top,r.bottom]:[r.left,r.right],l=ot(f.node,o,r.top,r.left),a=[];let u=!0;for(const[m,d]of st(e,c,s,l)){const w=o?m:r.top,p=o?r.left:m,h=i?x(m,s):m;if(h===void 0)continue;const g=i?x(d,s):d;if(g===void 0)continue;const C=V(f.node,w-r.top,p-r.left),S=B(C,s,n);S!==C&&(u=!1);const q=o?h:r.top,D=o?r.left:h,F=Y(S,q,D),I=a[a.length-1];I?.key===F&&I.to+1===h?I.to=g:a.push({from:h,to:g,key:F,text:N(S)})}return a.map(m=>({area:o?{...r,top:m.from,bottom:m.to}:{...r,left:m.from,right:m.to},text:u&&a.length===1?t:m.text}))}function W(r,t){return r!==null&&typeof r=="object"?{...r,formula:t}:t}const it=r=>{if(typeof r=="string")return r.startsWith("=")?r:void 0;if(!(r===null||typeof r!="object"))return r.formula!==void 0?r.formula.startsWith("=")?r.formula:`=${r.formula}`:typeof r.value=="string"&&r.value.startsWith("=")?r.value:void 0};function O(r,t,n,s){const i=z(r);if(!i.ok)return r;const f=B(i.node,t,n,s);return f===i.node?r:N(f)}function ct(r,t,n,s){const i={},f=$(n)?n:void 0;for(const[o,e]of Object.entries(r)){const c=it(e),l=A(o);if(!l){i[o]=e;continue}const a=s&&f!==void 0;if(o.includes(":")){if(!f){i[o]=c===void 0?e:W(e,O(c,n,t));continue}if(c!==void 0){for(const h of rt(l,c,t,f,a))i[M(h.area)]=W(e,h.text);continue}if(!a){i[o]=e;continue}if(!k(f)){const h=L(l,f);h&&(i[M(h)]=e);continue}const d=b(f),[w,p]=d?[l.top,l.bottom]:[l.left,l.right];for(const[h,g]of[[w,Math.min(p,f.at-1)],[Math.max(w,f.at),p]]){if(h>g)continue;const C=h>=f.at?f.count:0,S=d?{...l,top:h+C,bottom:g+C}:{...l,left:h+C,right:g+C};i[M(S)]=e}continue}const u={row:l.top,col:l.left};let m=u;if(a){const d=x(b(f)?u.row:u.col,f);m=d===void 0?void 0:b(f)?{...u,row:d}:{...u,col:d}}m&&(i[v(m)]=c===void 0?e:W(e,O(c,n,t)))}return i}export function tableShape(r,t){const n=y(r.at);if(!n)return;const s=t[0]??[],i=s.map(e=>e.trim()),f=new Set(i.map(e=>e.toLowerCase()));for(const e of Object.keys(r.columns??{}))f.has(e.toLowerCase())||i.push(e);const o=[];return t.forEach((e,c)=>{c>0&&e.length>0&&o.push(c)}),{at:n,header:s,names:i,places:o}}const T=r=>r.reduce((t,n)=>Math.max(t,n.length),0);function U(r,t,n){const s=Math.max(T(r),1),i=Array.from({length:n},()=>new Array(s).fill(""));return[...r.slice(0,t),...i,...r.slice(t)]}export function freeColumn(r,t="Column"){const n=new Set(r.map(s=>s.toLowerCase()));for(let s=1;;s++){const i=`${t}${String(s)}`;if(!n.has(i.toLowerCase()))return i}}export function uniqueColumn(r,t){const n=new Set(r.map(s=>s.toLowerCase()));if(!n.has(t.toLowerCase()))return t;for(let s=2;;s++){const i=`${t}${String(s)}`;if(!n.has(i.toLowerCase()))return i}}export function withColumnsUpTo(r,t,n){const s=r.map(o=>[...o]),i=s[0]??[];for(s.length===0&&s.push(i);i.length<=n;)i.push(t[i.length]??"");const f=i.length;for(let o=1;o<s.length;o++){const e=s[o];if(e&&e.length>0)for(;e.length<f;)e.push("")}return s}class X{file;rows;edit;after=[];refused;constructor(t,n){this.file=structuredClone(t.file),this.rows=new Map(t.rows),this.edit=n}sheets(){return this.file.sheets}rewrite(t){const n=this.file.sheets[0]?.name??"";if(this.file.names)for(const[s,i]of Object.entries(this.file.names))typeof i=="string"&&i.startsWith("=")&&(this.file.names[s]=O(i,t,n));for(const s of this.file.checks??[])s.formula=O(s.formula,t,n);for(const s of this.sheets())this.rewriteSheet(s,t)}rewriteSheet(t,n){const s=$(n)&&j(t.name,n.sheet);if(t.names)for(const[i,f]of Object.entries(t.names))typeof f=="string"&&f.startsWith("=")&&(t.names[i]=O(f,n,t.name));t.cells&&(t.cells=ct(t.cells,t.name,n,s));for(const i of t.tables??[]){for(const f of Object.values(i.columns??{}))f.formula!==void 0&&(f.formula=O(f.formula,n,t.name,i.name));this.rewriteCsv(i.rows,n,t.name,i.name)}for(const i of t.blocks??[])this.rewriteCsv(i.rows,n,t.name);this.rewriteRules(t,n)}freePath(t,n){const s=t.slice(0,t.lastIndexOf("/")+1),i=o=>[...this.rows.keys()].some(e=>j(e,o));let f=`${s}${n}.csv`;for(let o=2;i(f);o++)f=`${s}${n}-${String(o)}.csv`;return f}duplicate(t,n){const s=this.sheets(),i=s.findIndex(a=>j(a.name,t)),f=s[i];if(!f){this.refused="no-sheet";return}const o=structuredClone(f);o.name=n,delete o.hidden;for(const a of Object.values(o.cells??{}))a!==null&&typeof a=="object"&&delete a.name;const e=new Set(s.flatMap(a=>a.tables??[]).map(a=>a.name.toLowerCase())),c=new Set(Object.keys(this.file.names??{}).map(a=>a.toLowerCase())),l=[];for(const a of o.tables??[]){let u=a.name;for(let d=2;;d++){u=`${a.name}${String(d)}`;const w=u.toLowerCase();if(!e.has(w)&&!c.has(w))break}e.add(u.toLowerCase());const m=this.freePath(a.rows,u);this.rows.set(m,this.rows.get(a.rows)??[]),l.push({op:"rename-table",from:a.name,to:u}),a.rows=m,a.name=u}for(const a of o.blocks??[]){const u=a.rows.slice(a.rows.lastIndexOf("/")+1,-4),m=this.freePath(a.rows,u);this.rows.set(m,this.rows.get(a.rows)??[]),a.rows=m}this.file.sheets=[...s.slice(0,i+1),o,...s.slice(i+1)],this.rewriteSheet(o,{op:"rename-sheet",from:t,to:n});for(const a of l)this.rewriteSheet(o,a)}rewriteRules(t,n){const s=e=>typeof e=="string"&&e.startsWith("=")?O(e,n,t.name):e,i=e=>e.value===void 0?e:{...e,value:s(e.value)},f=t.conditional?.map(e=>{switch(e.type){case"cellIs":return{...e,formula:e.formula.map(s)};case"expression":return{...e,formula:O(e.formula.startsWith("=")?e.formula:`=${e.formula}`,n,t.name)};case"dataBar":return{...e,...e.min?{min:i(e.min)}:{},...e.max?{max:i(e.max)}:{}};case"colorScale":return{...e,stops:e.stops.map(i)};case"iconSet":return e.stops?{...e,stops:e.stops.map(i)}:e;default:return e}});f&&(t.conditional=f);const o=t.validations?.map(e=>e.formula?{...e,formula:e.formula.map(s)}:e);o&&(t.validations=o),$(n)&&n.sheet===t.name&&(t.links&&(t.links=K(t.links,n)),t.notes&&(t.notes=K(t.notes,n)),t.pictures&&(t.pictures=t.pictures.flatMap(e=>{const c=P(e.at,n);return c===void 0?[]:[{...e,at:c}]}))),t.charts&&(t.charts=t.charts.map(e=>Q(e,c=>{const l=c.startsWith("="),a=O(nt(c),n,t.name);return l?a:a.slice(1)})))}rewriteCsv(t,n,s,i){const f=this.rows.get(t);if(!f)return;let o;f.forEach((e,c)=>{if(!e.some(a=>a.charCodeAt(0)===61))return;const l=e.map(a=>tt(a).formula===void 0?a:O(a,n,s,i));l.every((a,u)=>a===e[u])||(o??=[...f],o[c]=l)}),o&&this.rows.set(t,o)}tableOn(t,n){const s=b(n),i=[];for(const f of t.tables??[]){const o=this.rows.get(f.rows),e=o&&tableShape(f,o);if(!o||!e){i.push(f);continue}const c=e.at.row,l=e.at.col,a=c+e.places.length,u=l+Math.max(e.names.length,1)-1,[m,d]=s?[c,a]:[l,u];if(!k(n)&&n.at<=m&&n.at+n.count-1>=d){this.after.push({op:"delete-table",name:f.name});continue}const w={...e.at};if(s)if(k(n)){if(n.at<=c)w.row+=n.count;else if(n.at<=a){const p=e.places[n.at-c-1]??o.length;this.rows.set(f.rows,U(o,p,n.count))}}else{const p=n.at+n.count-1;if(p<c)w.row-=n.count;else if(n.at<=c){this.refused="table-header";return}else if(n.at<=a){const h=new Set(e.places.slice(n.at-c-1,p-c));this.rows.set(f.rows,o.filter((g,C)=>!h.has(C)))}}else if(k(n))n.at<=l?w.col+=n.count:n.at<=u&&this.columnsIn(f,e,n.at-l,n.count);else{const p=n.at+n.count-1;if(p<l)w.col-=n.count;else if(n.at<=u){w.col=Math.min(l,n.at);const h=Math.max(0,n.at-l),g=Math.min(e.names.length-1,p-l);this.columnsOut(f,e,h,g)}}f.at=v(w),i.push(f)}t.tables=i,i.length===0&&delete t.tables}columnsIn(t,n,s,i){const f=this.rows.get(t.rows)??[],o=s>0?withColumnsUpTo(f,n.names,s-1):f.map(c=>[...c]),e=[...n.names];o.forEach((c,l)=>{if(l>0&&c.length===0)return;const a=[];for(let u=0;u<i;u++)if(l===0){const m=freeColumn(e);e.push(m),a.push(m)}else a.push("");for(;c.length<s;)c.push("");c.splice(s,0,...a)}),this.rows.set(t.rows,o)}columnsOut(t,n,s,i){const f=n.names.slice(s,i+1),o=this.rows.get(t.rows)??[],e=n.header.length,c=new Set;for(let l=s;l<=i&&l<e;l++)c.add(l);if(c.size>0&&this.rows.set(t.rows,o.map(l=>l.length===0?l:l.filter((a,u)=>!c.has(u)))),t.columns){const l=new Set(f.map(a=>a.toLowerCase()));t.columns=Object.fromEntries(Object.entries(t.columns).filter(([a])=>!l.has(a.toLowerCase()))),Object.keys(t.columns).length===0&&delete t.columns}if(t.key!==void 0&&f.some(l=>l.toLowerCase()===t.key?.toLowerCase())&&delete t.key,t.filter){const l=new Set(f.map(u=>u.toLowerCase())),a=Object.fromEntries(Object.entries(t.filter.columns).filter(([u])=>!l.has(u.toLowerCase())));Object.keys(a).length>0?t.filter={columns:a}:delete t.filter}for(const l of f)this.after.push({op:"delete-column",table:t.name,name:l})}blocksOn(t,n){const s=b(n),i=(t.blocks??[]).flatMap(f=>{const o=y(f.at),e=this.rows.get(f.rows);if(!o||!e)return[f];const c=s?o.row:o.col,l=s?e.length:Math.max(T(e),1),a=c+l-1,u=E(c,a,n);if(!u)return[];const m=s?{...o,row:u[0]}:{...o,col:u[0]};if(k(n)&&n.at>c&&n.at<=a){const d=n.at-c;this.rows.set(f.rows,s?U(e,d,n.count):e.map(w=>{if(w.length===0)return w;const p=[...w];for(;p.length<d;)p.push("");return p.splice(d,0,...new Array(n.count).fill("")),p}))}else if(!k(n)&&n.at<=a){const d=Math.max(n.at,c)-c,w=Math.min(n.at+n.count-1,a)-c;this.rows.set(f.rows,s?e.filter((p,h)=>h<d||h>w):e.map(p=>p.filter((h,g)=>g<d||g>w)))}return[{...f,at:v(m)}]});t.blocks=i,i.length===0&&delete t.blocks}looksOn(t,n){const s=b(n);t.format&&(t.format=t.format.flatMap(o=>{const e=A(o.range);if(!e)return[o];const c=L(e,n);return c?[{...o,range:M(c)}]:[]})),t.format?.length===0&&delete t.format,t.merges&&(t.merges=t.merges.flatMap(o=>{const e=A(o);if(!e)return[o];const c=L(e,n);return c?[M(c)]:[]})),t.merges?.length===0&&delete t.merges;const i=o=>{const e=J(o);if(!e)return o;const c=e.flatMap(l=>{const a=L(l,n);return a?[M(a)]:[]});return c.length===0?void 0:c.join(" ")};if(t.conditional&&(t.conditional=t.conditional.flatMap(o=>{const e=i(o.range);return e===void 0?[]:[{...o,range:e}]})),t.conditional?.length===0&&delete t.conditional,t.validations&&(t.validations=t.validations.flatMap(o=>{const e=i(o.range);return e===void 0?[]:[{...o,range:e}]})),t.validations?.length===0&&delete t.validations,t.charts&&(t.charts=t.charts.map(o=>{const e=y(o.at);if(!e)return o;const c=s?e.row:e.col,l=x(c,n)??n.at;return{...o,at:v(s?{...e,row:l}:{...e,col:l})}})),t.filter){const o=A(t.filter.range),e=o&&L(o,n);if(o&&!e)delete t.filter;else if(e){const c=s?t.filter.columns:Object.fromEntries(Object.entries(t.filter.columns??{}).flatMap(([l,a])=>{const u=R(l),m=u===void 0?void 0:x(u,n);return m===void 0?[]:[[_(m),a]]}));t.filter={range:M(e),...c&&Object.keys(c).length>0?{columns:c}:{}}}}if(t.freeze!==void 0){const o=y(t.freeze);if(o){const e=s?o.row:o.col,c=E(0,e-1,n),l=e===0?0:c?c[1]+1:0;t.freeze=v(s?{...o,row:l}:{...o,col:l})}}const f=(o,e,c)=>{if(!o)return;const l={};for(const[a,u]of Object.entries(o)){const m=e(a),d=m===void 0?void 0:x(m,n);m===void 0?l[a]=u:d!==void 0&&(l[c(d)]=u)}return l};if(s){const o=f(t.rows,e=>/^[1-9]\d*$/u.test(e)?Number(e)-1:void 0,e=>String(e+1));o&&(t.rows=o)}else{const o=f(t.columns,R,_);o&&(t.columns=o)}}run(){const t=this.edit;if($(t)){const n=this.sheets().find(s=>j(s.name,t.sheet));if(!n){this.refused="no-sheet";return}if(this.rewrite(t),this.tableOn(n,t),this.refused)return;this.blocksOn(n,t),this.looksOn(n,t);for(const s of this.after)this.rewrite(s);return}switch(t.op){case"rename-sheet":{this.rewrite(t);const n=this.sheets().find(s=>j(s.name,t.from));n&&(n.name=t.to);return}case"rename-column":{this.renameColumn(t.table,t.from,t.to),this.rewrite(t);return}case"delete-sheet":{const n=this.sheets(),s=n.find(i=>j(i.name,t.name));if(!s){this.refused="no-sheet";return}if(n.filter(i=>i.hidden!==!0).length<=1){this.refused="last-sheet";return}this.rewrite(t);for(const i of s.tables??[])this.rewrite({op:"delete-table",name:i.name});this.file.sheets=n.filter(i=>i!==s);return}default:this.rewrite(t)}}renameColumn(t,n,s){const i=this.sheets().flatMap(c=>c.tables??[]).find(c=>j(c.name,t));if(!i)return;const f=n.toLowerCase(),o=this.rows.get(i.rows),e=o?.[0]?.findIndex(c=>c.trim().toLowerCase()===f)??-1;if(o&&e>=0){const c=[...o[0]??[]];c[e]=s,this.rows.set(i.rows,[c,...o.slice(1)])}if(i.columns){const c=Object.keys(i.columns).find(l=>l.toLowerCase()===f);c!==void 0&&(i.columns=Object.fromEntries(Object.entries(i.columns).map(([l,a])=>[l===c?s:l,a])))}i.key?.toLowerCase()===f&&(i.key=s),i.filter&&(i.filter={columns:Object.fromEntries(Object.entries(i.filter.columns).map(([c,l])=>[c.toLowerCase()===f?s:c,l]))})}}const j=(r,t)=>r.toLowerCase()===t.toLowerCase();export function restructure(r,t){const n=new X(r,t);return n.run(),n.refused?{file:r.file,rows:new Map(r.rows),refused:n.refused}:{file:n.file,rows:n.rows}}export function duplicated(r,t,n){const s=new X(r,{op:"rename-sheet",from:t,to:n});return s.duplicate(t,n),s.refused?{file:r.file,rows:new Map(r.rows),refused:s.refused}:{file:s.file,rows:s.rows}}
@@ -0,0 +1,32 @@
1
+ import type { SheetSide } from "@allyhub-next/formats";
2
+ import type { CellLook, Table } from "./workbook.js";
3
+ /** A line of a part: Excel's border style and colour. */
4
+ export interface TableLine {
5
+ style: SheetSide["style"];
6
+ color: string;
7
+ }
8
+ /** One part of a table style: a fill, a font's weight and colour, its lines. */
9
+ export interface TablePart {
10
+ bold?: boolean;
11
+ color?: string;
12
+ fill?: string;
13
+ /** Its outer sides, and `horizontal` and `vertical`, the lines inside it. */
14
+ border?: Partial<Record<"left" | "right" | "top" | "bottom" | "horizontal" | "vertical", TableLine>>;
15
+ }
16
+ export interface TableStyle {
17
+ whole?: TablePart;
18
+ header?: TablePart;
19
+ stripe?: TablePart;
20
+ stripe2?: TablePart;
21
+ }
22
+ /** A table's style unless it names one, as Excel's new table. */
23
+ export declare const DEFAULT_TABLE_STYLE = "TableStyleMedium2";
24
+ /** The style a table is drawn in; undefined for `none` or a name Excel has not. */
25
+ export declare const tableStyleOf: (table: Table) => TableStyle | undefined;
26
+ /**
27
+ * The look a table's style gives a cell of it, under the cell's own.
28
+ * `band` is which stripe the row is, counted over the rows that show
29
+ * (0 the first); undefined for the header.
30
+ */
31
+ export declare function tableStyleLook(style: TableStyle, table: Table, row: number, col: number, band: number | undefined): CellLook;
32
+ //# sourceMappingURL=table-style.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{TABLE_STYLES as S}from"./table-styles.js";export const DEFAULT_TABLE_STYLE="TableStyleMedium2",tableStyleOf=e=>e.spec.style==="none"?void 0:S[e.spec.style??DEFAULT_TABLE_STYLE];export function tableStyleLook(e,m,d,u,b){const{area:n}=m,t={},i={},r=(o,p)=>{if(!o)return;o.bold!==void 0&&(t.bold=o.bold),o.color!==void 0&&(t.color=o.color),o.fill!==void 0&&(t.fill=o.fill);const c=o.border;if(!c)return;const l=(s,L)=>{const h=p[s]?c[s]:c[L];h&&(i[s]=h)};l("left","vertical"),l("right","vertical"),l("top","horizontal"),l("bottom","horizontal")},f={left:u===n.left,right:u===n.right};return r(e.whole,{...f,top:d===n.top,bottom:d===n.bottom}),b===void 0?r(e.header,{...f,top:!0,bottom:!0}):r(b%2===0?e.stripe:e.stripe2,{...f,top:!0,bottom:!0}),Object.keys(i).length>0&&(t.border=i),t}
@@ -0,0 +1,3 @@
1
+ import type { TableStyle } from "./table-style.js";
2
+ export declare const TABLE_STYLES: Readonly<Record<string, TableStyle>>;
3
+ //# sourceMappingURL=table-styles.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 const TABLE_STYLES={TableStyleDark1:{whole:{color:"#FFFFFF",fill:"#737373"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#404040"}},TableStyleDark2:{whole:{color:"#FFFFFF",fill:"#4472C4"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#2F5597"}},TableStyleDark3:{whole:{color:"#FFFFFF",fill:"#ED7D31"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#C55A11"}},TableStyleDark4:{whole:{color:"#FFFFFF",fill:"#A5A5A5"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#7C7C7C"}},TableStyleDark5:{whole:{color:"#FFFFFF",fill:"#FFC000"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#BF9000"}},TableStyleDark6:{whole:{color:"#FFFFFF",fill:"#5B9BD5"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#2E75B6"}},TableStyleDark7:{whole:{color:"#FFFFFF",fill:"#70AD47"},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#FFFFFF"}}},stripe:{fill:"#548235"}},TableStyleDark8:{whole:{fill:"#D9D9D9"},header:{color:"#FFFFFF",fill:"#000000"},stripe:{fill:"#A6A6A6"}},TableStyleDark9:{whole:{fill:"#DAE3F3"},header:{color:"#FFFFFF",fill:"#ED7D31"},stripe:{fill:"#B4C7E7"}},TableStyleDark10:{whole:{fill:"#EDEDED"},header:{color:"#FFFFFF",fill:"#FFC000"},stripe:{fill:"#DBDBDB"}},TableStyleDark11:{whole:{fill:"#DEEBF7"},header:{color:"#FFFFFF",fill:"#70AD47"},stripe:{fill:"#BDD7EE"}},TableStyleLight1:{whole:{color:"#000000",border:{top:{style:"thin",color:"#000000"},bottom:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"thin",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleLight2:{whole:{color:"#2F5597",border:{top:{style:"thin",color:"#4472C4"},bottom:{style:"thin",color:"#4472C4"}}},header:{bold:!0,color:"#2F5597",border:{bottom:{style:"thin",color:"#4472C4"}}},stripe:{fill:"#DAE3F3"}},TableStyleLight3:{whole:{color:"#C55A11",border:{top:{style:"thin",color:"#ED7D31"},bottom:{style:"thin",color:"#ED7D31"}}},header:{bold:!0,color:"#C55A11",border:{bottom:{style:"thin",color:"#ED7D31"}}},stripe:{fill:"#FBE5D6"}},TableStyleLight4:{whole:{color:"#7C7C7C",border:{top:{style:"thin",color:"#A5A5A5"},bottom:{style:"thin",color:"#A5A5A5"}}},header:{bold:!0,color:"#7C7C7C",border:{bottom:{style:"thin",color:"#A5A5A5"}}},stripe:{fill:"#EDEDED"}},TableStyleLight5:{whole:{color:"#BF9000",border:{top:{style:"thin",color:"#FFC000"},bottom:{style:"thin",color:"#FFC000"}}},header:{bold:!0,color:"#BF9000",border:{bottom:{style:"thin",color:"#FFC000"}}},stripe:{fill:"#FFF2CC"}},TableStyleLight6:{whole:{color:"#2E75B6",border:{top:{style:"thin",color:"#5B9BD5"},bottom:{style:"thin",color:"#5B9BD5"}}},header:{bold:!0,color:"#2E75B6",border:{bottom:{style:"thin",color:"#5B9BD5"}}},stripe:{fill:"#DEEBF7"}},TableStyleLight7:{whole:{color:"#548235",border:{top:{style:"thin",color:"#70AD47"},bottom:{style:"thin",color:"#70AD47"}}},header:{bold:!0,color:"#548235",border:{bottom:{style:"thin",color:"#70AD47"}}},stripe:{fill:"#E2F0D9"}},TableStyleLight8:{whole:{color:"#000000",border:{left:{style:"thin",color:"#000000"},right:{style:"thin",color:"#000000"},top:{style:"thin",color:"#000000"},bottom:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#000000"},stripe:{border:{top:{style:"thin",color:"#000000"}}},stripe2:{border:{top:{style:"thin",color:"#000000"}}}},TableStyleLight9:{whole:{color:"#000000",border:{left:{style:"thin",color:"#4472C4"},right:{style:"thin",color:"#4472C4"},top:{style:"thin",color:"#4472C4"},bottom:{style:"thin",color:"#4472C4"}}},header:{bold:!0,color:"#FFFFFF",fill:"#4472C4"},stripe:{border:{top:{style:"thin",color:"#4472C4"}}},stripe2:{border:{top:{style:"thin",color:"#4472C4"}}}},TableStyleLight10:{whole:{color:"#000000",border:{left:{style:"thin",color:"#ED7D31"},right:{style:"thin",color:"#ED7D31"},top:{style:"thin",color:"#ED7D31"},bottom:{style:"thin",color:"#ED7D31"}}},header:{bold:!0,color:"#FFFFFF",fill:"#ED7D31"},stripe:{border:{top:{style:"thin",color:"#ED7D31"}}},stripe2:{border:{top:{style:"thin",color:"#ED7D31"}}}},TableStyleLight11:{whole:{color:"#000000",border:{left:{style:"thin",color:"#A5A5A5"},right:{style:"thin",color:"#A5A5A5"},top:{style:"thin",color:"#A5A5A5"},bottom:{style:"thin",color:"#A5A5A5"}}},header:{bold:!0,color:"#FFFFFF",fill:"#A5A5A5"},stripe:{border:{top:{style:"thin",color:"#A5A5A5"}}},stripe2:{border:{top:{style:"thin",color:"#A5A5A5"}}}},TableStyleLight12:{whole:{color:"#000000",border:{left:{style:"thin",color:"#FFC000"},right:{style:"thin",color:"#FFC000"},top:{style:"thin",color:"#FFC000"},bottom:{style:"thin",color:"#FFC000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#FFC000"},stripe:{border:{top:{style:"thin",color:"#FFC000"}}},stripe2:{border:{top:{style:"thin",color:"#FFC000"}}}},TableStyleLight13:{whole:{color:"#000000",border:{left:{style:"thin",color:"#5B9BD5"},right:{style:"thin",color:"#5B9BD5"},top:{style:"thin",color:"#5B9BD5"},bottom:{style:"thin",color:"#5B9BD5"}}},header:{bold:!0,color:"#FFFFFF",fill:"#5B9BD5"},stripe:{border:{top:{style:"thin",color:"#5B9BD5"}}},stripe2:{border:{top:{style:"thin",color:"#5B9BD5"}}}},TableStyleLight14:{whole:{color:"#000000",border:{left:{style:"thin",color:"#70AD47"},right:{style:"thin",color:"#70AD47"},top:{style:"thin",color:"#70AD47"},bottom:{style:"thin",color:"#70AD47"}}},header:{bold:!0,color:"#FFFFFF",fill:"#70AD47"},stripe:{border:{top:{style:"thin",color:"#70AD47"}}},stripe2:{border:{top:{style:"thin",color:"#70AD47"}}}},TableStyleLight15:{whole:{color:"#000000",border:{left:{style:"thin",color:"#000000"},right:{style:"thin",color:"#000000"},top:{style:"thin",color:"#000000"},bottom:{style:"thin",color:"#000000"},horizontal:{style:"thin",color:"#000000"},vertical:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleLight16:{whole:{color:"#000000",border:{left:{style:"thin",color:"#4472C4"},right:{style:"thin",color:"#4472C4"},top:{style:"thin",color:"#4472C4"},bottom:{style:"thin",color:"#4472C4"},horizontal:{style:"thin",color:"#4472C4"},vertical:{style:"thin",color:"#4472C4"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#4472C4"}}},stripe:{fill:"#DAE3F3"}},TableStyleLight17:{whole:{color:"#000000",border:{left:{style:"thin",color:"#ED7D31"},right:{style:"thin",color:"#ED7D31"},top:{style:"thin",color:"#ED7D31"},bottom:{style:"thin",color:"#ED7D31"},horizontal:{style:"thin",color:"#ED7D31"},vertical:{style:"thin",color:"#ED7D31"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#ED7D31"}}},stripe:{fill:"#FBE5D6"}},TableStyleLight18:{whole:{color:"#000000",border:{left:{style:"thin",color:"#A5A5A5"},right:{style:"thin",color:"#A5A5A5"},top:{style:"thin",color:"#A5A5A5"},bottom:{style:"thin",color:"#A5A5A5"},horizontal:{style:"thin",color:"#A5A5A5"},vertical:{style:"thin",color:"#A5A5A5"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#A5A5A5"}}},stripe:{fill:"#EDEDED"}},TableStyleLight19:{whole:{color:"#000000",border:{left:{style:"thin",color:"#FFC000"},right:{style:"thin",color:"#FFC000"},top:{style:"thin",color:"#FFC000"},bottom:{style:"thin",color:"#FFC000"},horizontal:{style:"thin",color:"#FFC000"},vertical:{style:"thin",color:"#FFC000"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#FFC000"}}},stripe:{fill:"#FFF2CC"}},TableStyleLight20:{whole:{color:"#000000",border:{left:{style:"thin",color:"#5B9BD5"},right:{style:"thin",color:"#5B9BD5"},top:{style:"thin",color:"#5B9BD5"},bottom:{style:"thin",color:"#5B9BD5"},horizontal:{style:"thin",color:"#5B9BD5"},vertical:{style:"thin",color:"#5B9BD5"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#5B9BD5"}}},stripe:{fill:"#DEEBF7"}},TableStyleLight21:{whole:{color:"#000000",border:{left:{style:"thin",color:"#70AD47"},right:{style:"thin",color:"#70AD47"},top:{style:"thin",color:"#70AD47"},bottom:{style:"thin",color:"#70AD47"},horizontal:{style:"thin",color:"#70AD47"},vertical:{style:"thin",color:"#70AD47"}}},header:{bold:!0,color:"#000000",border:{bottom:{style:"medium",color:"#70AD47"}}},stripe:{fill:"#E2F0D9"}},TableStyleMedium1:{whole:{color:"#000000",border:{left:{style:"thin",color:"#000000"},right:{style:"thin",color:"#000000"},top:{style:"thin",color:"#000000"},bottom:{style:"thin",color:"#000000"},horizontal:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#000000"},stripe:{fill:"#D9D9D9"}},TableStyleMedium2:{whole:{color:"#000000",border:{left:{style:"thin",color:"#8FAADC"},right:{style:"thin",color:"#8FAADC"},top:{style:"thin",color:"#8FAADC"},bottom:{style:"thin",color:"#8FAADC"},horizontal:{style:"thin",color:"#8FAADC"}}},header:{bold:!0,color:"#FFFFFF",fill:"#4472C4"},stripe:{fill:"#DAE3F3"}},TableStyleMedium3:{whole:{color:"#000000",border:{left:{style:"thin",color:"#F4B183"},right:{style:"thin",color:"#F4B183"},top:{style:"thin",color:"#F4B183"},bottom:{style:"thin",color:"#F4B183"},horizontal:{style:"thin",color:"#F4B183"}}},header:{bold:!0,color:"#FFFFFF",fill:"#ED7D31"},stripe:{fill:"#FBE5D6"}},TableStyleMedium4:{whole:{color:"#000000",border:{left:{style:"thin",color:"#C9C9C9"},right:{style:"thin",color:"#C9C9C9"},top:{style:"thin",color:"#C9C9C9"},bottom:{style:"thin",color:"#C9C9C9"},horizontal:{style:"thin",color:"#C9C9C9"}}},header:{bold:!0,color:"#FFFFFF",fill:"#A5A5A5"},stripe:{fill:"#EDEDED"}},TableStyleMedium5:{whole:{color:"#000000",border:{left:{style:"thin",color:"#FFD966"},right:{style:"thin",color:"#FFD966"},top:{style:"thin",color:"#FFD966"},bottom:{style:"thin",color:"#FFD966"},horizontal:{style:"thin",color:"#FFD966"}}},header:{bold:!0,color:"#FFFFFF",fill:"#FFC000"},stripe:{fill:"#FFF2CC"}},TableStyleMedium6:{whole:{color:"#000000",border:{left:{style:"thin",color:"#9DC3E6"},right:{style:"thin",color:"#9DC3E6"},top:{style:"thin",color:"#9DC3E6"},bottom:{style:"thin",color:"#9DC3E6"},horizontal:{style:"thin",color:"#9DC3E6"}}},header:{bold:!0,color:"#FFFFFF",fill:"#5B9BD5"},stripe:{fill:"#DEEBF7"}},TableStyleMedium7:{whole:{color:"#000000",border:{left:{style:"thin",color:"#A9D18E"},right:{style:"thin",color:"#A9D18E"},top:{style:"thin",color:"#A9D18E"},bottom:{style:"thin",color:"#A9D18E"},horizontal:{style:"thin",color:"#A9D18E"}}},header:{bold:!0,color:"#FFFFFF",fill:"#70AD47"},stripe:{fill:"#E2F0D9"}},TableStyleMedium8:{whole:{color:"#000000",fill:"#D9D9D9",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#A6A6A6"}},TableStyleMedium9:{whole:{color:"#000000",fill:"#DAE3F3",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#4472C4",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#B4C7E7"}},TableStyleMedium10:{whole:{color:"#000000",fill:"#FBE5D6",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#ED7D31",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#F8CBAD"}},TableStyleMedium11:{whole:{color:"#000000",fill:"#EDEDED",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#A5A5A5",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#DBDBDB"}},TableStyleMedium12:{whole:{color:"#000000",fill:"#FFF2CC",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#FFC000",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#FFE699"}},TableStyleMedium13:{whole:{color:"#000000",fill:"#DEEBF7",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#5B9BD5",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#BDD7EE"}},TableStyleMedium14:{whole:{color:"#000000",fill:"#E2F0D9",border:{horizontal:{style:"thin",color:"#FFFFFF"},vertical:{style:"thin",color:"#FFFFFF"}}},header:{bold:!0,color:"#FFFFFF",fill:"#70AD47",border:{bottom:{style:"thick",color:"#FFFFFF"}}},stripe:{fill:"#C5E0B4"}},TableStyleMedium15:{whole:{color:"#000000",border:{left:{style:"thin",color:"#000000"},right:{style:"thin",color:"#000000"},top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"},horizontal:{style:"thin",color:"#000000"},vertical:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#000000",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium16:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#4472C4",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium17:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#ED7D31",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium18:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#A5A5A5",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium19:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#FFC000",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium20:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#5B9BD5",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium21:{whole:{color:"#000000",border:{top:{style:"medium",color:"#000000"},bottom:{style:"medium",color:"#000000"}}},header:{bold:!0,color:"#FFFFFF",fill:"#70AD47",border:{bottom:{style:"medium",color:"#000000"}}},stripe:{fill:"#D9D9D9"}},TableStyleMedium22:{whole:{color:"#000000",fill:"#D9D9D9",border:{left:{style:"thin",color:"#000000"},right:{style:"thin",color:"#000000"},top:{style:"thin",color:"#000000"},bottom:{style:"thin",color:"#000000"},horizontal:{style:"thin",color:"#000000"},vertical:{style:"thin",color:"#000000"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#A6A6A6"}},TableStyleMedium23:{whole:{color:"#000000",fill:"#DAE3F3",border:{left:{style:"thin",color:"#8FAADC"},right:{style:"thin",color:"#8FAADC"},top:{style:"thin",color:"#8FAADC"},bottom:{style:"thin",color:"#8FAADC"},horizontal:{style:"thin",color:"#8FAADC"},vertical:{style:"thin",color:"#8FAADC"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#B4C7E7"}},TableStyleMedium24:{whole:{color:"#000000",fill:"#FBE5D6",border:{left:{style:"thin",color:"#F4B183"},right:{style:"thin",color:"#F4B183"},top:{style:"thin",color:"#F4B183"},bottom:{style:"thin",color:"#F4B183"},horizontal:{style:"thin",color:"#F4B183"},vertical:{style:"thin",color:"#F4B183"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#F8CBAD"}},TableStyleMedium25:{whole:{color:"#000000",fill:"#EDEDED",border:{left:{style:"thin",color:"#C9C9C9"},right:{style:"thin",color:"#C9C9C9"},top:{style:"thin",color:"#C9C9C9"},bottom:{style:"thin",color:"#C9C9C9"},horizontal:{style:"thin",color:"#C9C9C9"},vertical:{style:"thin",color:"#C9C9C9"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#DBDBDB"}},TableStyleMedium26:{whole:{color:"#000000",fill:"#FFF2CC",border:{left:{style:"thin",color:"#FFD966"},right:{style:"thin",color:"#FFD966"},top:{style:"thin",color:"#FFD966"},bottom:{style:"thin",color:"#FFD966"},horizontal:{style:"thin",color:"#FFD966"},vertical:{style:"thin",color:"#FFD966"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#FFE699"}},TableStyleMedium27:{whole:{color:"#000000",fill:"#DEEBF7",border:{left:{style:"thin",color:"#9DC3E6"},right:{style:"thin",color:"#9DC3E6"},top:{style:"thin",color:"#9DC3E6"},bottom:{style:"thin",color:"#9DC3E6"},horizontal:{style:"thin",color:"#9DC3E6"},vertical:{style:"thin",color:"#9DC3E6"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#BDD7EE"}},TableStyleMedium28:{whole:{color:"#000000",fill:"#E2F0D9",border:{left:{style:"thin",color:"#A9D18E"},right:{style:"thin",color:"#A9D18E"},top:{style:"thin",color:"#A9D18E"},bottom:{style:"thin",color:"#A9D18E"},horizontal:{style:"thin",color:"#A9D18E"},vertical:{style:"thin",color:"#A9D18E"}}},header:{bold:!0,color:"#000000"},stripe:{fill:"#C5E0B4"}}};
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- export class CellError{static all=new Map;code;constructor(t){this.code=t}static of(t){let n=CellError.all.get(t);return n||(n=new CellError(t),CellError.all.set(t,n)),n}toString(){return this.code}toJSON(){return this.code}}export const ERR={NULL:CellError.of("#NULL!"),DIV0:CellError.of("#DIV/0!"),VALUE:CellError.of("#VALUE!"),REF:CellError.of("#REF!"),NAME:CellError.of("#NAME?"),NUM:CellError.of("#NUM!"),NA:CellError.of("#N/A"),SPILL:CellError.of("#SPILL!"),CALC:CellError.of("#CALC!"),CYCLE:CellError.of("#CYCLE!")};const L=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA","#SPILL!","#CALC!","#CYCLE!"];export function errorOf(e){const t=e.toUpperCase(),n=L.find(r=>r===t);return n===void 0?void 0:CellError.of(n)}export class Matrix{rows;cols;data;constructor(t,n,r){this.rows=t,this.cols=n,this.data=r}at(t,n){return this.data[t*this.cols+n]??null}}const i=864e5,p=25569;function y(e){const t=e+p;return t<61?t-1:t}function N(e){const t=Math.floor(e);if(t!==60)return(t<60?t+1:t)-p}export function serialOf(e,t,n){const r=new Date(Date.UTC(2e3,t-1,1));return r.setUTCFullYear(r.getUTCFullYear()-2e3+e),y(Math.floor(r.getTime()/i))+n-1}export function dateOf(e){const t=N(e);if(t===void 0)return{year:1900,month:2,day:29};if(Math.floor(e)===0)return{year:1900,month:1,day:0};const n=new Date(t*i);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}}export function serialOfDate(e){const t=e.getTime(),n=Math.floor(t/i);return y(n)+(t-n*i)/i}export function dateOfSerial(e){const t=N(e);if(t===void 0)return;const n=e-Math.floor(e);return new Date(t*i+Math.round(n*i))}const a=(e,t=2)=>String(e).padStart(t,"0");export function isoOfSerial(e){const{year:t,month:n,day:r}=dateOf(e),s=`${a(t,4)}-${a(n)}-${a(r)}`,o=Math.round((e-Math.floor(e))*86400);if(o===0)return s;const u=o%60;return`${s}T${a(Math.floor(o/3600))}:${a(Math.floor(o/60)%60)}${u===0?"":`:${a(u)}`}`}export function numberText(e){if(e===0)return"0";const t=Number(e.toPrecision(15)),n=Math.floor(Math.log10(Math.abs(t)));if(n>=15||n<-10){const[s="",o="0"]=t.toExponential().split("e"),u=Number(o);return`${s}E${u<0?"-":"+"}${a(Math.abs(u))}`}const r=String(t);return r.includes("e")?t.toFixed(Math.min(20,Math.abs(n)+15)).replace(/0+$/u,""):r}const M=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u,$=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d+)?$/u,b=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/u,E=e=>/^[+-]?\d+$/u.test(e)&&e.replace(/^[+-]?0*/u,"").length>15;function U(e){const t=b.exec(e);if(!t)return;const[n,r,s]=[Number(t[1]),Number(t[2]),Number(t[3])],o=serialOf(n,r,s),u=dateOf(o);if(u.month!==r||u.day!==s)return;if(t[4]===void 0)return{value:o,format:"yyyy-mm-dd"};const[f,l,m]=[Number(t[4]),Number(t[5]),Number(t[6]??0)];if(f>23||l>59||m>59)return;const d=t[7];let h=0;if(d!==void 0&&d!=="Z"){const c=d.replace(":","");h=(c.startsWith("-")?1:-1)*(Number(c.slice(1,3))*60+Number(c.slice(3,5)))/1440}return{value:o+(f*3600+l*60+m)/86400+h,format:t[6]===void 0?"yyyy-mm-dd hh:mm":"yyyy-mm-dd hh:mm:ss"}}export function readTyped(e){if(e==="")return{value:null};if(e.startsWith("'"))return{value:e.slice(1)};if(e.length>1&&e.startsWith("="))return{value:null,formula:e};const t=e.trim();if(t==="")return{value:e};const n=t.toUpperCase();if(n==="TRUE")return{value:!0};if(n==="FALSE")return{value:!1};if(M.test(t))return E(t)?{value:e}:{value:Number(t)};if(t.endsWith("%")){const f=t.slice(0,-1).trim();if(M.test(f))return{value:Number(f)/100,format:f.includes(".")?"0.00%":"0%"}}if($.test(t))return{value:Number(t.replaceAll(",","")),format:t.includes(".")?"#,##0.00":"#,##0"};const r=/^([+-]?)\$(\d[\d,]*(?:\.\d+)?)$/u.exec(t),s=r?.[2]?.replaceAll(",","");if(r&&s!==void 0)return{value:+`${r[1]??""}${s}`,format:t.includes(".")?"$#,##0.00":"$#,##0"};const o=U(t);if(o)return o;const u=errorOf(t);return u?{value:u}:{value:e}}export function writeTyped(e){if(e===null)return"";if(typeof e=="number"){const n=String(e);return E(n)?e.toExponential():n}if(typeof e=="boolean")return e?"TRUE":"FALSE";if(e instanceof CellError)return e.code;const t=readTyped(e);return t.value===e&&t.formula===void 0?e:`'${e}`}
2
+ export class CellError{static all=new Map;code;constructor(t){this.code=t}static of(t){let n=CellError.all.get(t);return n||(n=new CellError(t),CellError.all.set(t,n)),n}toString(){return this.code}toJSON(){return this.code}}export const ERR={NULL:CellError.of("#NULL!"),DIV0:CellError.of("#DIV/0!"),VALUE:CellError.of("#VALUE!"),REF:CellError.of("#REF!"),NAME:CellError.of("#NAME?"),NUM:CellError.of("#NUM!"),NA:CellError.of("#N/A"),SPILL:CellError.of("#SPILL!"),CALC:CellError.of("#CALC!"),CYCLE:CellError.of("#CYCLE!")};const $=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA","#SPILL!","#CALC!","#CYCLE!"];export function errorOf(e){const t=e.toUpperCase(),n=$.find(r=>r===t);return n===void 0?void 0:CellError.of(n)}export class Matrix{rows;cols;data;constructor(t,n,r){this.rows=t,this.cols=n,this.data=r}at(t,n){return this.data[t*this.cols+n]??null}}const i=864e5,p=25569;function y(e){const t=e+p;return t<61?t-1:t}function M(e){const t=Math.floor(e);if(t!==60)return(t<60?t+1:t)-p}export function serialOf(e,t,n){const r=new Date(Date.UTC(2e3,t-1,1));return r.setUTCFullYear(r.getUTCFullYear()-2e3+e),y(Math.floor(r.getTime()/i))+n-1}export function dateOf(e){const t=M(e);if(t===void 0)return{year:1900,month:2,day:29};if(Math.floor(e)===0)return{year:1900,month:1,day:0};const n=new Date(t*i);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}}export function serialOfDate(e){const t=e.getTime(),n=Math.floor(t/i);return y(n)+(t-n*i)/i}export function dateOfSerial(e){const t=M(e);if(t===void 0)return;const n=e-Math.floor(e);return new Date(t*i+Math.round(n*i))}const a=(e,t=2)=>String(e).padStart(t,"0");export function isoOfSerial(e){const{year:t,month:n,day:r}=dateOf(e),s=`${a(t,4)}-${a(n)}-${a(r)}`,o=Math.round((e-Math.floor(e))*86400);if(o===0)return s;const u=o%60;return`${s}T${a(Math.floor(o/3600))}:${a(Math.floor(o/60)%60)}${u===0?"":`:${a(u)}`}`}export function numberText(e){if(e===0)return"0";const t=Number(e.toPrecision(15)),n=Math.floor(Math.log10(Math.abs(t)));if(n>=15||n<-10){const[s="",o="0"]=t.toExponential().split("e"),u=Number(o);return`${s}E${u<0?"-":"+"}${a(Math.abs(u))}`}const r=String(t);return r.includes("e")?t.toFixed(Math.min(20,Math.abs(n)+15)).replace(/0+$/u,""):r}const N=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u,E=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d+)?$/u,L=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/u,b=e=>/^[+-]?\d+$/u.test(e)&&e.replace(/^[+-]?0*/u,"").length>15;function A(e){const t=L.exec(e);if(!t)return;const[n,r,s]=[Number(t[1]),Number(t[2]),Number(t[3])],o=serialOf(n,r,s),u=dateOf(o);if(u.month!==r||u.day!==s)return;if(t[4]===void 0)return{value:o,format:"yyyy-mm-dd"};const[f,d,m]=[Number(t[4]),Number(t[5]),Number(t[6]??0)];if(f>23||d>59||m>59)return;const c=t[7];let h=0;if(c!==void 0&&c!=="Z"){const l=c.replace(":","");h=(l.startsWith("-")?1:-1)*(Number(l.slice(1,3))*60+Number(l.slice(3,5)))/1440}return{value:o+(f*3600+d*60+m)/86400+h,format:t[6]===void 0?"yyyy-mm-dd hh:mm":"yyyy-mm-dd hh:mm:ss"}}function U(e){const t=/^(\d{1,4}):([0-5]?\d)(?::([0-5]?\d))?(?:\s*([AaPp])[Mm]?)?$/u.exec(e)??/^(\d{1,2})()()\s*([AaPp])[Mm]?$/u.exec(e);if(!t)return;const n=Number(t[1]),r=t[2]===void 0||t[2]===""?0:Number(t[2]),s=t[3]===void 0||t[3]===""?0:Number(t[3]),o=t[4]?.toUpperCase();if(o!==void 0)return n<1||n>12?void 0:{value:((n%12+(o==="P"?12:0))*3600+r*60+s)/86400,format:t[3]?"h:mm:ss AM/PM":"h:mm AM/PM"};const u=(n*3600+r*60+s)/86400;return n>=24?{value:u,format:"[h]:mm:ss"}:{value:u,format:t[3]?"h:mm:ss":"h:mm"}}export function readTyped(e){if(e==="")return{value:null};if(e.startsWith("'"))return{value:e.slice(1)};if(e.length>1&&e.startsWith("="))return{value:null,formula:e};const t=e.trim();if(t==="")return{value:e};const n=t.toUpperCase();if(n==="TRUE")return{value:!0};if(n==="FALSE")return{value:!1};if(N.test(t))return b(t)?{value:e}:{value:Number(t)};if(t.endsWith("%")){const d=t.slice(0,-1).trim();if(N.test(d))return{value:Number(d)/100,format:d.includes(".")?"0.00%":"0%"}}if(E.test(t))return{value:Number(t.replaceAll(",","")),format:t.includes(".")?"#,##0.00":"#,##0"};const r=/^([+-]?)\$(\d[\d,]*(?:\.\d+)?)$/u.exec(t),s=r?.[2]?.replaceAll(",","");if(r&&s!==void 0)return{value:+`${r[1]??""}${s}`,format:t.includes(".")?"$#,##0.00":"$#,##0"};const o=A(t);if(o)return o;const u=U(t);if(u)return u;const f=errorOf(t);return f?{value:f}:{value:e}}export function writeTyped(e){if(e===null)return"";if(typeof e=="number"){const n=String(e);return b(n)?e.toExponential():n}if(typeof e=="boolean")return e?"TRUE":"FALSE";if(e instanceof CellError)return e.code;const t=readTyped(e);return t.value===e&&t.formula===void 0?e:`'${e}`}
@@ -157,6 +157,8 @@ export declare class Worksheet {
157
157
  readonly filters: Filter[];
158
158
  /** Its charts, the last on top. */
159
159
  readonly charts: Chart[];
160
+ /** Names that hold on this sheet alone, over the workbook's, in lower case. */
161
+ readonly names: Map<string, DefinedName>;
160
162
  freeze: Place | undefined;
161
163
  /** sheet.ts makes it: what is on it is not changed by hand. */
162
164
  generated: boolean;
@@ -246,6 +248,10 @@ export interface DefinedName {
246
248
  value?: Scalar;
247
249
  formula?: SharedFormula;
248
250
  source: Source;
251
+ /** The sheet it holds on alone; absent: the workbook. */
252
+ sheet?: Worksheet;
253
+ /** Excel's Name Manager does not list it. */
254
+ hidden?: boolean;
249
255
  }
250
256
  export interface Check {
251
257
  name: string;
@@ -269,7 +275,10 @@ export declare class Workbook {
269
275
  respec(file: SheetFile): void;
270
276
  sheet(name: string): Worksheet | undefined;
271
277
  table(name: string): Table | undefined;
272
- name(name: string): DefinedName | undefined;
278
+ /** A defined name as a formula on `sheet` reads it: the sheet's own first, then the workbook's. */
279
+ name(name: string, sheet?: Worksheet): DefinedName | undefined;
280
+ /** Every definition of a name: the workbook's and each sheet's own. */
281
+ definitions(name: string): DefinedName[];
273
282
  get tables(): Table[];
274
283
  addSheet(sheet: Worksheet): void;
275
284
  addTable(table: Table): void;
@@ -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-next/formats";import{MAX_ROWS as B,cellName as H,columnIndex as j,columnLetter as z,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 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 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 r=this.columns[i];if(!r)continue;const l=Math.min(e.bottom,this.last(i));for(let o=Math.max(e.top,this.first(i));o<=l;o++)if(r[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=(a,e)=>a*16384+e;function T(a,e){a.bottom=Math.max(a.bottom,e.bottom),a.right=Math.max(a.right,e.right);for(let t=e.left;t<=e.right;t++){const s=a.columns.get(t);a.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=[];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:r}=t;for(let l=s.top;l<=s.bottom;l++)for(let o=s.left;o<=s.right;o++)this.grid.get(l,o)===void 0&&(this.blanks.has(placeKey(l,o))||(n?this.put(l,o,new FormulaCell(n,this,l,o)):i!=null&&(this.put(l,o,i),r!==void 0&&this.implied.set(placeKey(l,o),r))))}}}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 r=this.ghosts.get(placeKey(n,i));r&&s.add(r)}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[r,l]=this.spillReach().columns.get(e)??[1/0,-1];return[Math.max(t,Math.min(n,r)),Math.min(s,Math.max(i,l))]}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 r=this.ghosts.size===0?void 0:this.spillAt(e,t),l=r&&this.lookAt(r.row,r.col).format;l!==void 0&&(s.format=l),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 m=this.keys.get(placeKey(e,t)),g=m===void 0?void 0:this.spec.cells?.[m];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=a=>(typeof a=="object"?a.separator:void 0)??P;export function filesIn(a,e){const t=filesSeparator(e);return a.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){return this.names.get(e.toLowerCase())}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 r=e.blockAt(t,s);if(r)return{file:r.file,line:r.lines[t-r.area.top]??1};const l=e.keys.get(placeKey(t,s));if(l!==void 0)return{file:E,path:["sheets",n,"cells",l]};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(a){return q.test(a)&&x(a)===void 0&&!/^(?:TRUE|FALSE)$/iu.test(a)&&!/^[Rr](?:\d+)?(?:[Cc]\d*)?$/u.test(a)&&!/^[Cc]\d*$/u.test(a)}const M="made",k=a=>a[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(){for(const[e,t]of Object.entries(this.wb.file.names??{})){const s=this.madeNames.has(e)?[M,"names",e]:["names",e];if(!validName(e)){this.yaml(s,`${e} cannot be a name`);continue}const n={file:k(s),path:s},i=typeof t=="string"&&t.startsWith("=")?{name:e,formula:new SharedFormula(t,0,0,n),source:n}:{name:e,value:typeof t=="string"?A(t).value:t,source:n};this.wb.names.set(e.toLowerCase(),i)}}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 r of e.tables.slice(n+1))v(i.area,r.area)&&this.problems.push({file:E,message:`tables ${i.name} and ${r.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 r=$(n);r?e.merges.push(r):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??{}))j(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,(r,l)=>{this.yaml(r,l)});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,r=[],l=(o,f)=>{const h=this.bound(o,i,f);h&&r.push(h)};if(t.type==="expression"){const o=t.formula.startsWith("=")?t.formula:`=${t.formula}`;l(o,[...s,"formula"])}if(t.type==="cellIs"&&t.formula.forEach((o,f)=>{l(o,[...s,"formula",f])}),t.type==="dataBar")for(const o of["min","max"])l(t[o]?.value,[...s,o,"value"]);(t.type==="colorScale"||t.type==="iconSet")&&t.stops?.forEach((o,f)=>{l(o.value,[...s,"stops",f,"value"])}),e.conditions.push({spec:t,areas:n,formulas:r})}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])),r=t.formula?.length??0,l=t.type!=="list"&&t.type!=="custom"&&(t.operator===void 0||t.operator==="between"||t.operator==="notBetween");!(t.type==="list"&&t.values!==void 0)&&r<(l?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 r=new Map;for(const[o,f]of Object.entries(s.filter.columns??{})){const h=j(o);h===void 0||h<i.left||h>i.right?this.yaml([...n,"columns",o],`${o} is not a column of ${s.filter.range}`):r.set(h,f)}const l=e.tables.find(o=>v(o.area,i));l&&this.yaml(n,`a filter over table ${l.name}: a table has its own`),e.filters.push({area:i,columns:r})}}e.tables.forEach((n,i)=>{const{filter:r}=n.spec;if(r===!1)return;const l=new Map;for(const[o,f]of Object.entries(r?.columns??{})){const h=n.column(o);h?l.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:l})})}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 r=new SharedFormula(n.formula,t,s,i);e.put(t,s,new FormulaCell(r,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),r=this.csv(t.rows,[...s,"rows"],`table ${t.name}`),l=r?.rows??[],o=r?.lines??[],f=l[0],h=o[0]??1,m=new Set,g=f?.length===0?[""]:f??[];g.forEach((u,d)=>{const p=u.trim();p===""&&this.problems.push({file:t.rows,line:h,message:`column ${String(d+1)} has no name`}),m.has(p.toLowerCase())&&this.problems.push({file:t.rows,line:h,message:`two columns are named ${p}`}),m.add(p.toLowerCase()),i.columns.push({name:p,index:i.columns.length,csv:d})});for(const[u,d]of Object.entries(t.columns??{})){const p=i.column(u),S=p??{name:u,index:i.columns.length};p||(d.formula===void 0&&this.yaml([...s,"columns",u],`table ${t.name} has no column ${u}`),i.columns.push(S)),S.spec=d}const c=g.length;for(let u=1;u<l.length;u++){const d=l[u];if(!d||d.length===0)continue;const p=o[u]??u+1;i.places.push(u),i.records.push(d),i.lines.push(p),d.length>c&&this.problems.push({file:t.rows,line:p,message:`this row has ${String(d.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 d=n.col+u.index;e.put(n.row,d,u.name);const p=u.spec?.formula;p!==void 0&&(u.formula=new SharedFormula(p,w,d,{file:k(s),path:[...s,"columns",u.name,"formula"]}),i.rows>0&&e.fills.push({area:{top:w,left:d,bottom:w+i.rows-1,right:d},shared:u.formula})),u.csv!==void 0&&i.records.forEach((S,L)=>{this.typed(e,w+L,d,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((r,l)=>{const o=r[n.csv??0]??"",f=e.lines[l]??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 r=this.csv(s,[...n,"rows"],"a block");if(!r)return;const l=r.rows,o=l.map((g,c)=>r.lines[c]??c+1),f=l.reduce((g,c)=>Math.max(g,c.length),1),h={top:i.row,left:i.col,bottom:i.row+Math.max(l.length,1)-1,right:i.col+f-1},m=this.overlapping(e,h);m&&this.yaml(n,`the block of ${s} overlaps ${m} on ${e.name}`),e.blocks.push({area:h,file:s,lines:o}),l.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,r]of Object.entries(t)){const l=[...s,i],o=$(i);if(!o){this.yaml(l,`${i} is not a cell or a range`);continue}const f=this.overlapping(e,o);if(f&&this.yaml(l,`${i} overlaps ${f}`),i.includes(":")){const h=(o.bottom-o.top+1)*(o.right-o.left+1);h>MAX_FILL_CELLS?this.yaml(l,`${i} is ${String(h)} cells`):this.fill(e,o,r,l)}else n.push([i,r,{row:o.top,col:o.left}])}for(const[i,r,l]of n){const o=[...s,i],f=K(r),h=placeKey(l.row,l.col);e.keys.set(h,i),f.value===null&&f.formula===void 0&&e.blanks.add(h),this.typed(e,l.row,l.col,f,{file:k(o),path:o});const m=r!==null&&typeof r=="object"?r.name:void 0;m!==void 0&&this.cellName(e,l,m,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},r=H(t).replace(/^([A-Z]+)(\d+)$/u,"$$$1$$$2"),l=`='${e.name.replaceAll("'","''")}'!${r}`;this.wb.names.set(s.toLowerCase(),{name:s,formula:new SharedFormula(l,0,0,i),source:i})}fill(e,t,s,n){const i=K(s),r={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,r)})}}function W(a,e,t,s){const n=x(a.at);if(!n){s([...t,"at"],`${a.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},r=(o,f)=>o?.startsWith("=")===!0?i(o,f):void 0,l=r(a.title,[...t,"title"]);return{spec:a,at:n,index:e,...a.categories===void 0?{}:{categories:i(a.categories,[...t,"categories"])},...l?{title:l}:{},series:a.series.map((o,f)=>{const h=[...t,"series",f],m=r(o.name,[...h,"name"]);return{values:i(o.values,[...h,"values"]),...o.x===void 0?{}:{x:i(o.x,[...h,"x"])},...m?{name:m}:{}}})}}export const chartFormula=a=>a.startsWith("=")?a:`=${a}`;function I(a){switch(a.kind){case"error":case"ref":case"structured":case"name":return!0;case"paren":case"postfix":return I(a.arg);case"binary":return a.op===":"||a.op===",";default:return!1}}function K(a){if(a===null)return{value:null};if(typeof a=="string")return A(a);if(typeof a!="object")return{value:a};if(a.formula!==void 0)return{value:null,formula:a.formula.startsWith("=")?a.formula:`=${a.formula}`};const{value:e}=a;return typeof e=="string"?A(e):{value:e??null}}export function readWorkbook(a){const e=D(a.text),t=l=>l[0]===M?void 0:e.lineOf(l);if(!e.file)return{problems:e.problems,lineOf:t};const s=O(e.file,a.generated),n=new Workbook(s.file,a.generated);n.ordinary=s.ordinary;const i=[],r=new N(n,l=>{const o=a.generated?.csv[l]??a.read(l);if(o===void 0)return;const f=R(o);for(const h of f.problems)i.push({file:l,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 r.read(),{workbook:n,problems:[...i,...r.problems],lineOf:t}}export function workbookOf(a){const e=O(a.file,a.generated),t=new Workbook(e.file,a.generated);return t.ordinary=e.ordinary,new N(t,s=>{const n=a.generated?.csv[s];if(n!==void 0)return{rows:R(n).records.map(r=>r.end===r.start?[]:r.fields),lines:[]};const i=a.rows(s);return i&&{rows:i,lines:[]}},()=>{},e.own,e.names).read(),t}export{U as rangeName};
2
+ import{SHEET_CODE as C,SHEET_SEPARATOR as P}from"@allyhub-next/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};
@@ -15,6 +15,8 @@ export interface DrawnPicture {
15
15
  width: number;
16
16
  height: number;
17
17
  name: string;
18
+ /** Its file's path from the sheet's folder, kept as its description so a reader finds it again. */
19
+ path: string;
18
20
  file: string;
19
21
  bytes: Uint8Array;
20
22
  }
@@ -36,9 +38,16 @@ export interface Anchored {
36
38
  width: number;
37
39
  height: number;
38
40
  }
39
- /** Each chart of a drawing where it sits, sizes in pixels. */
41
+ /** A picture of a drawing: its image by relationship, and what it is called. */
42
+ export interface AnchoredPicture extends Anchored {
43
+ name?: string;
44
+ /** Its description: the path of the file it was, when this writer wrote it. */
45
+ descr?: string;
46
+ }
47
+ /** Each chart and picture of a drawing where it sits, sizes in pixels, and how many other things it holds. */
40
48
  export declare function chartAnchors(root: Tag | undefined, columnWidth: (col: number) => number, rowHeight: (row: number) => number): {
41
49
  anchors: Anchored[];
50
+ pictures: AnchoredPicture[];
42
51
  others: number;
43
52
  };
44
53
  //# sourceMappingURL=charts.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{CHART_DEFAULTS as Q,chartSpaceXml as ce}from"@allyhub-next/chart";import{columnLetter as Y}from"../address.js";import{Reference as Z,Union as ae}from"../calc/types.js";import{chartDef as fe,chartSize as de}from"../chart.js";import{sheetPrefix as le}from"../formula/print.js";import{HEAD as ue,attr as C,el as s,flag as ee,numberAttr as P,tag as o,tags as S,textOf as y}from"./xml.js";const he="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",me="http://schemas.openxmlformats.org/drawingml/2006/main",te="http://schemas.openxmlformats.org/drawingml/2006/chart",re="http://schemas.openxmlformats.org/officeDocument/2006/relationships",p=9525,xe=(e,t)=>`${le(e.sheet.name)}$${Y(e.left)}$${String(e.top+1)}${e.single?"":`:$${Y(e.right)}$${String(t+1)}`}`;function k(e,t,r){if(!r?.node)return;const n=e.eval(r.node,{sheet:t,row:0,col:0,dr:0,dc:0}),i=a=>xe(a,Math.min(a.bottom,Math.max(a.top,a.sheet.lastRow)));if(n instanceof Z)return i(n);if(n instanceof ae)return`(${n.parts.map(i).join(",")})`}function ge(e,t,r){if(!r?.node)return!1;const n=e.eval(r.node,{sheet:t,row:0,col:0,dr:0,dc:0});return n instanceof Z&&typeof e.value(n.sheet,n.top,n.left)=="number"}export function chartPart(e,t,r){const n=fe(e,t,r),i={name:f=>k(e,t,r.series[f]?.name),categories:k(e,t,r.categories),numeric:ge(e,t,r.categories),values:f=>k(e,t,r.series[f]?.values)??"",x:f=>k(e,t,r.series[f]?.x??r.categories)},a=k(e,t,r.title);return ce(n,{refs:i,...a===void 0?{}:{titleRef:a}})}const pe=(e,t,r)=>s("xdr:oneCellAnchor",{},s("xdr:from",{},`<xdr:col>${String(e.col)}</xdr:col>`,`<xdr:colOff>${String(Math.round(e.x*p))}</xdr:colOff>`,`<xdr:row>${String(e.row)}</xdr:row>`,`<xdr:rowOff>${String(Math.round((e.y??0)*p))}</xdr:rowOff>`),s("xdr:ext",{cx:Math.round(e.width*p),cy:Math.round(e.height*p)}),s("xdr:pic",{},s("xdr:nvPicPr",{},s("xdr:cNvPr",{id:t,name:e.name}),s("xdr:cNvPicPr",{},s("a:picLocks",{noChangeAspect:!0}))),s("xdr:blipFill",{},s("a:blip",{"xmlns:r":re,"r:embed":`rId${String(r)}`}),s("a:stretch",{},s("a:fillRect"))),s("xdr:spPr",{},s("a:xfrm",{},s("a:off",{x:0,y:0}),s("a:ext",{cx:Math.round(e.width*p),cy:Math.round(e.height*p)})),s("a:prstGeom",{prst:"rect"},s("a:avLst")))),s("xdr:clientData"));export function drawingPart(e,t=[]){const r=(n,i)=>{const{width:a,height:f}=de(n.spec);return s("xdr:oneCellAnchor",{},s("xdr:from",{},`<xdr:col>${String(n.at.col)}</xdr:col>`,`<xdr:colOff>${String(Math.round((n.spec.x??0)*p))}</xdr:colOff>`,`<xdr:row>${String(n.at.row)}</xdr:row>`,`<xdr:rowOff>${String(Math.round((n.spec.y??0)*p))}</xdr:rowOff>`),s("xdr:ext",{cx:Math.round(a*p),cy:Math.round(f*p)}),s("xdr:graphicFrame",{macro:""},s("xdr:nvGraphicFramePr",{},s("xdr:cNvPr",{id:i+2,name:`Chart ${String(i+1)}`}),s("xdr:cNvGraphicFramePr")),s("xdr:xfrm",{},s("a:off",{x:0,y:0}),s("a:ext",{cx:0,cy:0})),s("a:graphic",{},s("a:graphicData",{uri:te},s("c:chart",{"xmlns:c":te,"xmlns:r":re,"r:id":`rId${String(i+1)}`})))),s("xdr:clientData"))};return ue+s("xdr:wsDr",{"xmlns:xdr":he,"xmlns:a":me},...e.map(r),...t.map((n,i)=>pe(n,e.length+i+2,e.length+i+1)))}function G(e){if(Array.isArray(e))return e.map(G).join("");if(typeof e!="object"||e===null)return"";const t=e,r=[];for(const[n,i]of Object.entries(t))n==="t"?r.push(y(i)):typeof i=="object"&&r.push(G(i));return r.join("")}const T=e=>{const t=o(e?.solidFill),r=C(o(t?.srgbClr),"val");return r!==void 0?`#${r.toUpperCase()}`:we[C(o(t?.schemeClr),"val")??""]},we={accent1:"#4472C4",accent2:"#ED7D31",accent3:"#A5A5A5",accent4:"#FFC000",accent5:"#5B9BD5",accent6:"#70AD47"},O=(e,t)=>C(o(e?.[t]),"val"),$=(e,t)=>P(o(e?.[t]),"val"),D=(e,t)=>ee(o(e?.[t]),"val");function ne(e){if(!e)return;const t=o(e.tx),r=o(t?.strRef);if(r)return`=${y(r.f)}`;const n=G(t?.rich);return n===""?void 0:n}function oe(e){if(!e)return;const t=o(e.scaling),r=o(e.numFmt),n=C(r,"formatCode"),i={},a=ne(o(e.title));a!==void 0&&(i.title=a);const f=$(t,"min"),w=$(t,"max"),l=$(e,"majorUnit");return f!==void 0&&(i.min=f),w!==void 0&&(i.max=w),l!==void 0&&l>0&&(i.major=l),D(e,"delete")===!0&&(i.visible=!1),O(t,"orientation")==="maxMin"&&(i.reverse=!0),n!==void 0&&n!=="General"&&ee(r,"sourceLinked")!==!0&&(i.format=n),i}const R=e=>{const t=o(e?.numRef)??o(e?.strRef),r=t?y(t.f):"";return r===""?void 0:r};function be(e,t){const r=R(o(e[t?"yVal":"val"]));if(r===void 0)return"its numbers are written in the chart";const n={values:r},i=o(e.tx),a=R(i);if(a!==void 0)n.name=`=${a}`;else{const g=y(i?.v);g!==""&&(n.name=g)}const f=o(e.spPr),w=o(f?.ln),l=o(e.marker),c=t||l!==void 0,d=T(f)??(c?T(w)??T(o(l?.spPr)):void 0);d!==void 0&&(n.color=d);const h=P(w,"w");if(c&&h!==void 0&&w?.noFill===void 0){const g=Number((h/12700).toFixed(2));g!==Q.lineWidth&&(n.line_width=g)}D(e,"smooth")===!0&&(n.smooth=!0);const m=$(l,"size");m!==void 0&&m!==Q.marker&&(n.marker_size=m);const b=t?R(o(e.xVal)):void 0;b!==void 0&&(n.x=b);const x=t?void 0:R(o(e.cat));return{series:n,...x===void 0?{}:{categories:x}}}function ve(e){const t=O(e,"barDir")==="bar"?"bar":"column",r=O(e,"grouping");return r==="stacked"?`${t}-stacked`:r==="percentStacked"?`${t}-stacked-100`:`${t}-clustered`}function ye(e){const t=O(e,"grouping");return t==="stacked"?"area-stacked":t==="percentStacked"?"area-stacked-100":"area"}export function readChart(e){const t=o(e?.chartSpace),r=o(t?.chart),n=o(r?.plotArea);if(!r||!n)return"it has no plot";const i=Object.entries(n).filter(([u])=>u.endsWith("Chart")),[a]=i;if(!a)return"it has no plot";if(i.length>1||Array.isArray(a[1])&&a[1].length>1)return"it combines several kinds of chart";const[f,w]=a,l=o(w);if(!l)return"it has no plot";const c=S(l.ser),d=f==="scatterChart",h=[];let m;for(const u of c){const A=be(u,d);if(typeof A=="string")return A;h.push(A.series),m??=A.categories}if(h.length===0)return"it has no series";const b=u=>o(o(u.spPr)?.ln)?.noFill!==void 0,x=u=>O(o(u.marker),"symbol")==="none",g=(()=>{switch(f){case"barChart":return ve(l);case"lineChart":return c.every(x)?"line":"line-markers";case"areaChart":return ye(l);case"pieChart":return"pie";case"doughnutChart":return"doughnut";case"scatterChart":return c.every(b)?"scatter":c.some(u=>D(u,"smooth")===!0)?"scatter-smooth":"scatter-lines";default:return}})();if(!g)return`a sheet has no ${f.replace(/Chart$/u,"")} chart`;const U=ne(o(r.title)),I=o(r.legend),j=O(I,"legendPos"),V=o(l.dLbls),v=u=>D(V,u)===!0,se=v("showVal")||v("showPercent")||v("showCatName")||v("showSerName"),H=O(V,"dLblPos"),F=$(l,"gapWidth"),W=$(l,"overlap"),N=$(l,"holeSize"),X=D(l,"varyColors"),B=g==="pie"||g==="doughnut",M={value:S(n.valAx).find((u,A,ie)=>d?A===ie.length-1:!0),category:d?S(n.valAx)[0]:o(n.catAx)??o(n.dateAx)},L=oe(M.value),z=oe(M.category);L&&M.value?.majorGridlines===void 0&&(L.gridlines=!1),z&&M.category?.majorGridlines!==void 0&&(z.gridlines=!0);const E=P(o(o(o(o(t?.txPr)?.p)?.pPr)?.defRPr),"sz"),q=u=>u&&Object.keys(u).length>0?u:void 0,J=q(L),K=q(z);return{type:g,at:"A1",...U===void 0?{}:{title:U},...m===void 0?{}:{categories:m},series:B?h.slice(0,1):h,...I?{legend:j==="b"?"bottom":j==="t"?"top":j==="l"?"left":"right"}:{},...se?{labels:{...v("showVal")?{value:!0}:{},...v("showPercent")?{percentage:!0}:{},...v("showCatName")?{category:!0}:{},...v("showSerName")?{series:!0}:{},...H===void 0?{}:{position:H}}}:{},...F===void 0||F===150?{}:{gap_width:F},...W===void 0||g.includes("stacked")?{}:{overlap:W},...N===void 0||N===50?{}:{hole_size:N},...X===!0&&f==="barChart"?{vary_by_categories:!0}:{},...X===!1&&B?{vary_by_categories:!1}:{},...J?{value_axis:J}:{},...K?{category_axis:K}:{},...E===void 0||E===900?{}:{size:E/100}}}const _=e=>Math.round(e/p);export function chartAnchors(e,t,r){const n=o(e?.wsDr),i=[];let a=0;const f=c=>({col:Number(y(c?.col)),row:Number(y(c?.row)),colOff:_(Number(y(c?.colOff))),rowOff:_(Number(y(c?.rowOff)))}),w=c=>C(o(o(o(o(c.graphicFrame)?.graphic)?.graphicData)?.chart),"id"),l=(c,d,h,m)=>{const b=w(c);if(b===void 0){a+=1;return}i.push({id:b,at:{row:d.row,col:d.col},...d.colOff>0?{x:d.colOff}:{},...d.rowOff>0?{y:d.rowOff}:{},width:h,height:m})};for(const c of S(n?.oneCellAnchor)){const d=o(c.ext);l(c,f(o(c.from)),_(P(d,"cx")??0),_(P(d,"cy")??0))}for(const c of S(n?.twoCellAnchor)){const d=f(o(c.from)),h=f(o(c.to));let m=h.colOff-d.colOff;for(let x=d.col;x<h.col;x++)m+=t(x);let b=h.rowOff-d.rowOff;for(let x=d.row;x<h.row;x++)b+=r(x);l(c,d,m,b)}return{anchors:i,others:a}}
2
+ import{CHART_DEFAULTS as Q,chartSpaceXml as ce}from"@allyhub-next/chart";import{columnLetter as Y}from"../address.js";import{Reference as Z,Union as ae}from"../calc/types.js";import{chartDef as fe,chartSize as de}from"../chart.js";import{sheetPrefix as le}from"../formula/print.js";import{HEAD as ue,attr as y,el as s,flag as ee,numberAttr as M,tag as r,tags as R,textOf as O}from"./xml.js";const he="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",me="http://schemas.openxmlformats.org/drawingml/2006/main",te="http://schemas.openxmlformats.org/drawingml/2006/chart",re="http://schemas.openxmlformats.org/officeDocument/2006/relationships",g=9525,xe=(e,t)=>`${le(e.sheet.name)}$${Y(e.left)}$${String(e.top+1)}${e.single?"":`:$${Y(e.right)}$${String(t+1)}`}`;function _(e,t,n){if(!n?.node)return;const o=e.eval(n.node,{sheet:t,row:0,col:0,dr:0,dc:0}),i=a=>xe(a,Math.min(a.bottom,Math.max(a.top,a.sheet.lastRow)));if(o instanceof Z)return i(o);if(o instanceof ae)return`(${o.parts.map(i).join(",")})`}function pe(e,t,n){if(!n?.node)return!1;const o=e.eval(n.node,{sheet:t,row:0,col:0,dr:0,dc:0});return o instanceof Z&&typeof e.value(o.sheet,o.top,o.left)=="number"}export function chartPart(e,t,n){const o=fe(e,t,n),i={name:l=>_(e,t,n.series[l]?.name),categories:_(e,t,n.categories),numeric:pe(e,t,n.categories),values:l=>_(e,t,n.series[l]?.values)??"",x:l=>_(e,t,n.series[l]?.x??n.categories)},a=_(e,t,n.title);return ce(o,{refs:i,...a===void 0?{}:{titleRef:a}})}const ge=(e,t,n)=>s("xdr:oneCellAnchor",{},s("xdr:from",{},`<xdr:col>${String(e.col)}</xdr:col>`,`<xdr:colOff>${String(Math.round(e.x*g))}</xdr:colOff>`,`<xdr:row>${String(e.row)}</xdr:row>`,`<xdr:rowOff>${String(Math.round((e.y??0)*g))}</xdr:rowOff>`),s("xdr:ext",{cx:Math.round(e.width*g),cy:Math.round(e.height*g)}),s("xdr:pic",{},s("xdr:nvPicPr",{},s("xdr:cNvPr",{id:t,name:e.name,descr:e.path}),s("xdr:cNvPicPr",{},s("a:picLocks",{noChangeAspect:!0}))),s("xdr:blipFill",{},s("a:blip",{"xmlns:r":re,"r:embed":`rId${String(n)}`}),s("a:stretch",{},s("a:fillRect"))),s("xdr:spPr",{},s("a:xfrm",{},s("a:off",{x:0,y:0}),s("a:ext",{cx:Math.round(e.width*g),cy:Math.round(e.height*g)})),s("a:prstGeom",{prst:"rect"},s("a:avLst")))),s("xdr:clientData"));export function drawingPart(e,t=[]){const n=(o,i)=>{const{width:a,height:l}=de(o.spec);return s("xdr:oneCellAnchor",{},s("xdr:from",{},`<xdr:col>${String(o.at.col)}</xdr:col>`,`<xdr:colOff>${String(Math.round((o.spec.x??0)*g))}</xdr:colOff>`,`<xdr:row>${String(o.at.row)}</xdr:row>`,`<xdr:rowOff>${String(Math.round((o.spec.y??0)*g))}</xdr:rowOff>`),s("xdr:ext",{cx:Math.round(a*g),cy:Math.round(l*g)}),s("xdr:graphicFrame",{macro:""},s("xdr:nvGraphicFramePr",{},s("xdr:cNvPr",{id:i+2,name:`Chart ${String(i+1)}`}),s("xdr:cNvGraphicFramePr")),s("xdr:xfrm",{},s("a:off",{x:0,y:0}),s("a:ext",{cx:0,cy:0})),s("a:graphic",{},s("a:graphicData",{uri:te},s("c:chart",{"xmlns:c":te,"xmlns:r":re,"r:id":`rId${String(i+1)}`})))),s("xdr:clientData"))};return ue+s("xdr:wsDr",{"xmlns:xdr":he,"xmlns:a":me},...e.map(n),...t.map((o,i)=>ge(o,e.length+i+2,e.length+i+1)))}function I(e){if(Array.isArray(e))return e.map(I).join("");if(typeof e!="object"||e===null)return"";const t=e,n=[];for(const[o,i]of Object.entries(t))o==="t"?n.push(O(i)):typeof i=="object"&&n.push(I(i));return n.join("")}const V=e=>{const t=r(e?.solidFill),n=y(r(t?.srgbClr),"val");return n!==void 0?`#${n.toUpperCase()}`:we[y(r(t?.schemeClr),"val")??""]},we={accent1:"#4472C4",accent2:"#ED7D31",accent3:"#A5A5A5",accent4:"#FFC000",accent5:"#5B9BD5",accent6:"#70AD47"},$=(e,t)=>y(r(e?.[t]),"val"),A=(e,t)=>M(r(e?.[t]),"val"),F=(e,t)=>ee(r(e?.[t]),"val");function ne(e){if(!e)return;const t=r(e.tx),n=r(t?.strRef);if(n)return`=${O(n.f)}`;const o=I(t?.rich);return o===""?void 0:o}function oe(e){if(!e)return;const t=r(e.scaling),n=r(e.numFmt),o=y(n,"formatCode"),i={},a=ne(r(e.title));a!==void 0&&(i.title=a);const l=A(t,"min"),x=A(t,"max"),u=A(e,"majorUnit");return l!==void 0&&(i.min=l),x!==void 0&&(i.max=x),u!==void 0&&u>0&&(i.major=u),F(e,"delete")===!0&&(i.visible=!1),$(t,"orientation")==="maxMin"&&(i.reverse=!0),o!==void 0&&o!=="General"&&ee(n,"sourceLinked")!==!0&&(i.format=o),i}const j=e=>{const t=r(e?.numRef)??r(e?.strRef),n=t?O(t.f):"";return n===""?void 0:n};function be(e,t){const n=j(r(e[t?"yVal":"val"]));if(n===void 0)return"its numbers are written in the chart";const o={values:n},i=r(e.tx),a=j(i);if(a!==void 0)o.name=`=${a}`;else{const d=O(i?.v);d!==""&&(o.name=d)}const l=r(e.spPr),x=r(l?.ln),u=r(e.marker),w=t||u!==void 0,c=V(l)??(w?V(x)??V(r(u?.spPr)):void 0);c!==void 0&&(o.color=c);const f=M(x,"w");if(w&&f!==void 0&&x?.noFill===void 0){const d=Number((f/12700).toFixed(2));d!==Q.lineWidth&&(o.line_width=d)}F(e,"smooth")===!0&&(o.smooth=!0);const m=A(u,"size");m!==void 0&&m!==Q.marker&&(o.marker_size=m);const v=t?j(r(e.xVal)):void 0;v!==void 0&&(o.x=v);const b=t?void 0:j(r(e.cat));return{series:o,...b===void 0?{}:{categories:b}}}function ve(e){const t=$(e,"barDir")==="bar"?"bar":"column",n=$(e,"grouping");return n==="stacked"?`${t}-stacked`:n==="percentStacked"?`${t}-stacked-100`:`${t}-clustered`}function ye(e){const t=$(e,"grouping");return t==="stacked"?"area-stacked":t==="percentStacked"?"area-stacked-100":"area"}export function readChart(e){const t=r(e?.chartSpace),n=r(t?.chart),o=r(n?.plotArea);if(!n||!o)return"it has no plot";const i=Object.entries(o).filter(([h])=>h.endsWith("Chart")),[a]=i;if(!a)return"it has no plot";if(i.length>1||Array.isArray(a[1])&&a[1].length>1)return"it combines several kinds of chart";const[l,x]=a,u=r(x);if(!u)return"it has no plot";const w=R(u.ser),c=l==="scatterChart",f=[];let m;for(const h of w){const P=be(h,c);if(typeof P=="string")return P;f.push(P.series),m??=P.categories}if(f.length===0)return"it has no series";const v=h=>r(r(h.spPr)?.ln)?.noFill!==void 0,b=h=>$(r(h.marker),"symbol")==="none",d=(()=>{switch(l){case"barChart":return ve(u);case"lineChart":return w.every(b)?"line":"line-markers";case"areaChart":return ye(u);case"pieChart":return"pie";case"doughnutChart":return"doughnut";case"scatterChart":return w.every(v)?"scatter":w.some(h=>F(h,"smooth")===!0)?"scatter-smooth":"scatter-lines";default:return}})();if(!d)return`a sheet has no ${l.replace(/Chart$/u,"")} chart`;const S=ne(r(n.title)),k=r(n.legend),C=$(k,"legendPos"),D=r(u.dLbls),p=h=>F(D,h)===!0,se=p("showVal")||p("showPercent")||p("showCatName")||p("showSerName"),H=$(D,"dLblPos"),z=A(u,"gapWidth"),W=A(u,"overlap"),E=A(u,"holeSize"),X=F(u,"varyColors"),B=d==="pie"||d==="doughnut",N={value:R(o.valAx).find((h,P,ie)=>c?P===ie.length-1:!0),category:c?R(o.valAx)[0]:r(o.catAx)??r(o.dateAx)},G=oe(N.value),T=oe(N.category);G&&N.value?.majorGridlines===void 0&&(G.gridlines=!1),T&&N.category?.majorGridlines!==void 0&&(T.gridlines=!0);const U=M(r(r(r(r(t?.txPr)?.p)?.pPr)?.defRPr),"sz"),q=h=>h&&Object.keys(h).length>0?h:void 0,J=q(G),K=q(T);return{type:d,at:"A1",...S===void 0?{}:{title:S},...m===void 0?{}:{categories:m},series:B?f.slice(0,1):f,...k?{legend:C==="b"?"bottom":C==="t"?"top":C==="l"?"left":"right"}:{},...se?{labels:{...p("showVal")?{value:!0}:{},...p("showPercent")?{percentage:!0}:{},...p("showCatName")?{category:!0}:{},...p("showSerName")?{series:!0}:{},...H===void 0?{}:{position:H}}}:{},...z===void 0||z===150?{}:{gap_width:z},...W===void 0||d.includes("stacked")?{}:{overlap:W},...E===void 0||E===50?{}:{hole_size:E},...X===!0&&l==="barChart"?{vary_by_categories:!0}:{},...X===!1&&B?{vary_by_categories:!1}:{},...J?{value_axis:J}:{},...K?{category_axis:K}:{},...U===void 0||U===900?{}:{size:U/100}}}const L=e=>Math.round(e/g);export function chartAnchors(e,t,n){const o=r(e?.wsDr),i=[],a=[];let l=0;const x=c=>({col:Number(O(c?.col)),row:Number(O(c?.row)),colOff:L(Number(O(c?.colOff))),rowOff:L(Number(O(c?.rowOff)))}),u=c=>y(r(r(r(r(c.graphicFrame)?.graphic)?.graphicData)?.chart),"id"),w=(c,f,m,v)=>{const b={at:{row:f.row,col:f.col},...f.colOff>0?{x:f.colOff}:{},...f.rowOff>0?{y:f.rowOff}:{},width:m,height:v},d=r(c.pic),S=y(r(r(d?.blipFill)?.blip),"embed");if(d&&S!==void 0){const C=r(r(d.nvPicPr)?.cNvPr),D=y(C,"name"),p=y(C,"descr");a.push({id:S,...b,...D===void 0?{}:{name:D},...p===void 0?{}:{descr:p}});return}const k=u(c);if(k===void 0){l+=1;return}i.push({id:k,...b})};for(const c of R(o?.oneCellAnchor)){const f=r(c.ext);w(c,x(r(c.from)),L(M(f,"cx")??0),L(M(f,"cy")??0))}for(const c of R(o?.twoCellAnchor)){const f=x(r(c.from)),m=x(r(c.to));let v=m.colOff-f.colOff;for(let d=f.col;d<m.col;d++)v+=t(d);let b=m.rowOff-f.rowOff;for(let d=f.row;d<m.row;d++)b+=n(d);w(c,f,v,b)}return{anchors:i,pictures:a,others:l}}
@@ -4,8 +4,12 @@ import type { Node, Parsed } from "../formula/ast.js";
4
4
  * is expected. `isRangeName` says whether a name stands for several cells.
5
5
  */
6
6
  export declare function needsArray(node: Node, isRangeName?: (name: string) => boolean): boolean;
7
- /** A formula with the narrowing an ordinary <f> does written out with @. */
8
- export declare function narrowed(n: Node): Node;
7
+ /**
8
+ * A formula with the narrowing an ordinary <f> does written out with @:
9
+ * wherever one value is expected, its whole body too. `isRangeName` says
10
+ * whether a defined name stands for several cells.
11
+ */
12
+ export declare function narrowed(n: Node, isRangeName?: (name: string) => boolean): Node;
9
13
  export interface FileFormulaContext {
10
14
  /** The table the formula is in: the name a bare [@x] leaves out. */
11
15
  table?: string | undefined;
@@ -16,6 +20,12 @@ export interface FileFormulaContext {
16
20
  }
17
21
  /** A formula's text as a file stores it: no =. */
18
22
  export declare const fileFormula: (node: Node, c: FileFormulaContext) => string;
19
- /** A formula as a file stores it, parsed. `array`: it is an array formula, so nothing narrows. */
20
- export declare function readFileFormula(text: string, array: boolean): Parsed;
23
+ /**
24
+ * A formula as a file stores it, parsed. `array`: it is an array formula,
25
+ * so nothing narrows. `isRangeName` says whether a defined name stands for
26
+ * several cells.
27
+ */
28
+ export declare function readFileFormula(text: string, array: boolean, isRangeName?: (name: string) => boolean): Parsed;
29
+ /** Whether a defined name's text, as a file stores it, is several cells. */
30
+ export declare function isRangeText(text: string): boolean;
21
31
  //# sourceMappingURL=formula.d.ts.map
@@ -1,4 +1,4 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{parseFormula as h}from"../formula/parse.js";import{printFormula as w}from"../formula/print.js";import{FUNCTIONS as S}from"../calc/functions/index.js";import{fileName as O,plainName as k}from"./functions.js";function g(r){switch(r.kind){case"ref":return r.col2!==void 0||r.row2!==void 0;case"structured":return!r.thisRow||r.columns.length>1;case"paren":return g(r.arg);case"binary":return r.op===":"||r.op===",";default:return!1}}const n=new Set(["+","-","*","/","^","&","=","<>","<","<=",">",">="]),E=new Set(`BYCOL BYROW CHOOSECOLS CHOOSEROWS DROP EXPAND FILTER HSTACK MAKEARRAY MAP
2
+ import{parseFormula as p}from"../formula/parse.js";import{printFormula as w}from"../formula/print.js";import{FUNCTIONS as S}from"../calc/functions/index.js";import{fileName as k,plainName as O}from"./functions.js";function c(r){switch(r.kind){case"ref":return r.col2!==void 0||r.row2!==void 0;case"structured":return!r.thisRow||r.columns.length>1;case"paren":return c(r.arg);case"binary":return r.op===":"||r.op===",";default:return!1}}const l=new Set(["+","-","*","/","^","&","=","<>","<","<=",">",">="]),y=new Set(`BYCOL BYROW CHOOSECOLS CHOOSEROWS DROP EXPAND FILTER HSTACK MAKEARRAY MAP
3
3
  RANDARRAY SCAN SEQUENCE SORT SORTBY TAKE TEXTSPLIT TOCOL TOROW UNIQUE VSTACK
4
- WRAPCOLS WRAPROWS`.split(/\s+/u)),p=new Set(["IF","IFERROR","IFNA"]),d=r=>S.get(r)?.kind==="scalar";export function needsArray(r,t=()=>!1){const a=e=>g(e)||e.kind==="array"||e.kind==="name"&&t(e.name)||e.kind==="paren"&&a(e.arg),s=e=>{switch(e.kind){case"unary":return e.op==="@"?!1:a(e.arg)||s(e.arg);case"postfix":return e.op==="%"?a(e.arg)||s(e.arg):!1;case"paren":return s(e.arg);case"binary":return n.has(e.op)&&(a(e.left)||a(e.right))?!0:s(e.left)||s(e.right);case"call":return e.name==="LET"||e.name==="LAMBDA"||E.has(e.name)||d(e.name)&&e.args.some(a)||p.has(e.name)&&e.args[0]&&a(e.args[0])?!0:e.args.some(s);case"invoke":return s(e.callee)||e.args.some(s);default:return!1}};return s(r)}export function narrowed(r){const t=a=>a.kind!=="array"&&g(a)?{kind:"unary",op:"@",arg:a}:narrowed(a);switch(r.kind){case"unary":return r.op==="@"?r:{...r,arg:t(r.arg)};case"postfix":return r.op==="%"?{...r,arg:t(r.arg)}:r;case"paren":return{...r,arg:narrowed(r.arg)};case"binary":return n.has(r.op)?{...r,left:t(r.left),right:t(r.right)}:r;case"call":{if(d(r.name))return{...r,args:r.args.map(t)};const[a,...s]=r.args;return p.has(r.name)&&a?{...r,args:[t(a),...s]}:r}default:return r}}const R=(r,t)=>({kind:"call",name:r,written:r,args:t});function y(r,t){return{...r,...r.table===void 0&&t!==void 0?{table:t}:{},sections:r.thisRow?["#This Row"]:r.sections,thisRow:!1}}function f(r,t,a,s){const e=(u,o=!1)=>f(u,t,a,o&&s);switch(r.kind){case"name":{const u=r.name.toLowerCase();return a.has(u)?{...r,name:`_xlpm.${r.name}`}:t.isTable(r.name)?{...r,name:`${r.name}[]`}:r}case"structured":return y(r,t.table);case"unary":return r.op==="@"?s?e(r.arg,!0):R("_xlfn.SINGLE",[e(r.arg)]):{...r,arg:e(r.arg,!0)};case"postfix":return r.op==="#"?R("_xlfn.ANCHORARRAY",[e(r.arg)]):{...r,arg:e(r.arg,!0)};case"paren":return{...r,arg:e(r.arg,!0)};case"binary":return{...r,left:e(r.left,n.has(r.op)),right:e(r.right,n.has(r.op))};case"call":{const u=O(r.name);if(r.name==="LET"||r.name==="LAMBDA"){const o=new Set(a),m=r.args.length-1,A=r.args.map((c,l)=>(r.name==="LAMBDA"||l%2===0)&&l<m&&c.kind==="name"?(o.add(c.name.toLowerCase()),{...c,name:`_xlpm.${c.name}`}):f(c,t,o,!1));return{...r,written:u,args:A}}return{...r,written:u,args:r.args.map(o=>e(o))}}case"invoke":return{...r,callee:e(r.callee),args:r.args.map(u=>e(u))};case"array":return{...r,rows:r.rows.map(u=>u.map(o=>e(o)))};default:return r}}export const fileFormula=(r,t)=>w(f(r,t,new Set,!t.array)).slice(1);function i(r){switch(r.kind){case"name":return r.name.toLowerCase().startsWith("_xlpm.")?{...r,name:r.name.slice(6)}:r;case"structured":return r;case"unary":case"postfix":case"paren":return{...r,arg:i(r.arg)};case"binary":return{...r,left:i(r.left),right:i(r.right)};case"call":{const a=k(r.written).toUpperCase(),s=r.args.map(i),[e]=s;return a==="ANCHORARRAY"&&e&&s.length===1?{kind:"postfix",op:"#",arg:e}:a==="SINGLE"&&e&&s.length===1?{kind:"unary",op:"@",arg:e}:{...r,name:a,written:a,args:s}}case"invoke":return{...r,callee:i(r.callee),args:r.args.map(i)};case"array":return{...r,rows:r.rows.map(t=>t.map(i))};default:return r}}export function readFileFormula(r,t){const a=h(`=${r}`);if(!a.ok)return a;const s=i(a.node);return{ok:!0,node:t?s:narrowed(s)}}
4
+ WRAPCOLS WRAPROWS`.split(/\s+/u)),d=new Set(["IF","IFERROR","IFNA"]),R=r=>S.get(r)?.kind==="scalar";export function needsArray(r,t=()=>!1){const a=e=>c(e)||e.kind==="array"||e.kind==="name"&&t(e.name)||e.kind==="paren"&&a(e.arg);if(r.kind!=="array"&&a(r))return!0;const s=e=>{switch(e.kind){case"unary":return e.op==="@"?!1:a(e.arg)||s(e.arg);case"postfix":return e.op==="%"?a(e.arg)||s(e.arg):!1;case"paren":return s(e.arg);case"binary":return l.has(e.op)&&(a(e.left)||a(e.right))?!0:s(e.left)||s(e.right);case"call":return e.name==="LET"||e.name==="LAMBDA"||y.has(e.name)||R(e.name)&&e.args.some(a)||d.has(e.name)&&e.args[0]&&a(e.args[0])?!0:e.args.some(s);case"invoke":return s(e.callee)||e.args.some(s);default:return!1}};return s(r)}export function narrowed(r,t=()=>!1){const a=e=>e.kind!=="array"&&(c(e)||e.kind==="name"&&t(e.name))?{kind:"unary",op:"@",arg:e}:s(e),s=e=>{switch(e.kind){case"unary":return e.op==="@"?e:{...e,arg:a(e.arg)};case"postfix":return e.op==="%"?{...e,arg:a(e.arg)}:e;case"paren":return{...e,arg:s(e.arg)};case"binary":return l.has(e.op)?{...e,left:a(e.left),right:a(e.right)}:e;case"call":{if(R(e.name))return{...e,args:e.args.map(a)};const[n,...u]=e.args;return d.has(e.name)&&n?{...e,args:[a(n),...u]}:e}default:return e}};return a(r)}const A=(r,t)=>({kind:"call",name:r,written:r,args:t});function E(r,t){return{...r,...r.table===void 0&&t!==void 0?{table:t}:{},sections:r.thisRow?["#This Row"]:r.sections,thisRow:!1}}function g(r,t,a,s){const e=(n,u=!1)=>g(n,t,a,u&&s);switch(r.kind){case"name":{const n=r.name.toLowerCase();return a.has(n)?{...r,name:`_xlpm.${r.name}`}:t.isTable(r.name)?{...r,name:`${r.name}[]`}:r}case"structured":return E(r,t.table);case"unary":return r.op==="@"?s?e(r.arg,!0):A("_xlfn.SINGLE",[e(r.arg)]):{...r,arg:e(r.arg,!0)};case"postfix":return r.op==="#"?A("_xlfn.ANCHORARRAY",[e(r.arg)]):{...r,arg:e(r.arg,!0)};case"paren":return{...r,arg:e(r.arg,!0)};case"binary":return{...r,left:e(r.left,l.has(r.op)),right:e(r.right,l.has(r.op))};case"call":{const n=k(r.name);if(r.name==="LET"||r.name==="LAMBDA"){const u=new Set(a),m=r.args.length-1,h=r.args.map((i,f)=>(r.name==="LAMBDA"||f%2===0)&&f<m&&i.kind==="name"?(u.add(i.name.toLowerCase()),{...i,name:`_xlpm.${i.name}`}):g(i,t,u,!1));return{...r,written:n,args:h}}return{...r,written:n,args:r.args.map(u=>e(u))}}case"invoke":return{...r,callee:e(r.callee),args:r.args.map(n=>e(n))};case"array":return{...r,rows:r.rows.map(n=>n.map(u=>e(u)))};default:return r}}export const fileFormula=(r,t)=>w(g(r,t,new Set,!t.array)).slice(1);function o(r){switch(r.kind){case"name":return r.name.toLowerCase().startsWith("_xlpm.")?{...r,name:r.name.slice(6)}:r;case"structured":return r;case"unary":case"postfix":case"paren":return{...r,arg:o(r.arg)};case"binary":return{...r,left:o(r.left),right:o(r.right)};case"call":{const a=O(r.written).toUpperCase(),s=r.args.map(o),[e]=s;return a==="ANCHORARRAY"&&e&&s.length===1?{kind:"postfix",op:"#",arg:e}:a==="SINGLE"&&e&&s.length===1?{kind:"unary",op:"@",arg:e}:{...r,name:a,written:a,args:s}}case"invoke":return{...r,callee:o(r.callee),args:r.args.map(o)};case"array":return{...r,rows:r.rows.map(t=>t.map(o))};default:return r}}export function readFileFormula(r,t,a){const s=p(`=${r}`);if(!s.ok)return s;const e=o(s.node);return{ok:!0,node:t?e:narrowed(e,a)}}export function isRangeText(r){const t=p(`=${r}`);return t.ok&&c(o(t.node))}
@@ -1,5 +1,15 @@
1
+ /**
2
+ * [MS-XLSX] 2.2.2.1 Functions, "future functions", as Microsoft publishes
3
+ * them (learn.microsoft.com/openspecs/office_standards/ms-xlsx/5d1b6d44,
4
+ * revised 2024-04-16), every entry as its table writes it. Its formula
5
+ * grammar sets ECMA.CEILING, ISO.CEILING, NETWORKDAYS.INTL, WORKDAY.INTL
6
+ * and the FORECAST functions outside the `_xlfn.` group by a misplaced
7
+ * parenthesis; Excel, LibreOffice and the table's own FORECAST entries
8
+ * store all of them with it, so every entry here has it.
9
+ */
10
+ export declare const PUBLISHED_FUTURE_FUNCTIONS = "_xlfn._xlws.FILTER _xlfn._xlws.PY\n_xlfn._xlws.SORT _xlfn.ACOT _xlfn.ACOTH _xlfn.AGGREGATE _xlfn.ARABIC _xlfn.BASE\n_xlfn.BETA.DIST _xlfn.BETA.INV _xlfn.BINOM.DIST _xlfn.BINOM.DIST.RANGE\n_xlfn.BINOM.INV _xlfn.BITAND _xlfn.BITLSHIFT _xlfn.BITOR _xlfn.BITRSHIFT\n_xlfn.BITXOR _xlfn.BYCOL _xlfn.BYROW _xlfn.CEILING.MATH _xlfn.CEILING.PRECISE\n_xlfn.CHISQ.DIST _xlfn.CHISQ.DIST.RT _xlfn.CHISQ.INV _xlfn.CHISQ.INV.RT\n_xlfn.CHISQ.TEST _xlfn.CHOOSECOLS _xlfn.CHOOSEROWS _xlfn.COMBINA _xlfn.CONCAT\n_xlfn.CONFIDENCE.NORM _xlfn.CONFIDENCE.T _xlfn.COT _xlfn.COTH\n_xlfn.COVARIANCE.P _xlfn.COVARIANCE.S _xlfn.CSC _xlfn.CSCH _xlfn.DAYS\n_xlfn.DECIMAL _xlfn.DROP ECMA.CEILING _xlfn.ERF.PRECISE _xlfn.ERFC.PRECISE\n_xlfn.EXPAND _xlfn.EXPON.DIST _xlfn.F.DIST _xlfn.F.DIST.RT _xlfn.F.INV\n_xlfn.F.INV.RT _xlfn.F.TEST _xlfn.FIELDVALUE _xlfn.FILTERXML _xlfn.FLOOR.MATH\n_xlfn.FLOOR.PRECISE _xlfn.FORECAST.ETS _xlfn.FORECAST.ETS.CONFINT\n_xlfn.FORECAST.ETS.SEASONALITY _xlfn.FORECAST.ETS.STAT _xlfn.FORECAST.LINEAR\n_xlfn.FORMULATEXT _xlfn.GAMMA _xlfn.GAMMA.DIST _xlfn.GAMMA.INV\n_xlfn.GAMMALN.PRECISE _xlfn.GAUSS _xlfn.HSTACK _xlfn.HYPGEOM.DIST _xlfn.IFNA\n_xlfn.IFS _xlfn.IMCOSH _xlfn.IMCOT _xlfn.IMCSC _xlfn.IMCSCH _xlfn.IMSEC\n_xlfn.IMSECH _xlfn.IMSINH _xlfn.IMTAN _xlfn.ISFORMULA ISO.CEILING\n_xlfn.ISOMITTED _xlfn.ISOWEEKNUM _xlfn.LAMBDA _xlfn.LET _xlfn.LOGNORM.DIST\n_xlfn.LOGNORM.INV _xlfn.MAKEARRAY _xlfn.MAP _xlfn.MAXIFS _xlfn.MINIFS\n_xlfn.MODE.MULT _xlfn.MODE.SNGL _xlfn.MUNIT _xlfn.NEGBINOM.DIST\nNETWORKDAYS.INTL _xlfn.NORM.DIST _xlfn.NORM.INV _xlfn.NORM.S.DIST\n_xlfn.NORM.S.INV _xlfn.NUMBERVALUE _xlfn.PDURATION _xlfn.PERCENTILE.EXC\n_xlfn.PERCENTILE.INC _xlfn.PERCENTRANK.EXC _xlfn.PERCENTRANK.INC\n_xlfn.PERMUTATIONA _xlfn.PHI _xlfn.POISSON.DIST _xlfn.PQSOURCE\n_xlfn.PYTHON_STR _xlfn.PYTHON_TYPE _xlfn.PYTHON_TYPENAME _xlfn.QUARTILE.EXC\n_xlfn.QUARTILE.INC _xlfn.QUERYSTRING _xlfn.RANDARRAY _xlfn.RANK.AVG\n_xlfn.RANK.EQ _xlfn.REDUCE _xlfn.RRI _xlfn.SCAN _xlfn.SEC _xlfn.SECH\n_xlfn.SEQUENCE _xlfn.SHEET _xlfn.SHEETS _xlfn.SKEW.P _xlfn.SORTBY\n_xlfn.STDEV.P _xlfn.STDEV.S _xlfn.SWITCH _xlfn.T.DIST _xlfn.T.DIST.2T\n_xlfn.T.DIST.RT _xlfn.T.INV _xlfn.T.INV.2T _xlfn.T.TEST _xlfn.TAKE\n_xlfn.TEXTAFTER _xlfn.TEXTBEFORE _xlfn.TEXTJOIN _xlfn.TEXTSPLIT _xlfn.TOCOL\n_xlfn.TOROW _xlfn.UNICHAR _xlfn.UNICODE _xlfn.UNIQUE _xlfn.VAR.P _xlfn.VAR.S\n_xlfn.VSTACK _xlfn.WEBSERVICE _xlfn.WEIBULL.DIST WORKDAY.INTL _xlfn.WRAPCOLS\n_xlfn.WRAPROWS _xlfn.XLOOKUP _xlfn.XOR _xlfn.Z.TEST";
1
11
  /** A function's name as a file stores it. */
2
12
  export declare function fileName(name: string): string;
3
13
  /** A name as a formula writes it, whatever prefix a file stored it under. */
4
- export declare const plainName: (name: string) => string;
14
+ export declare function plainName(name: string): string;
5
15
  //# sourceMappingURL=functions.d.ts.map