@allyhub/sdk 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/define.d.ts +4 -0
  2. package/dist/define.js +1 -1
  3. package/dist/node_modules/@allyhub-next/audio/dist/node/index.d.ts +1 -1
  4. package/dist/node_modules/@allyhub-next/audio/dist/node/index.js +1 -1
  5. package/dist/node_modules/@allyhub-next/audio/dist/node/master.d.ts +4 -0
  6. package/dist/node_modules/@allyhub-next/audio/dist/node/master.js +1 -1
  7. package/dist/node_modules/@allyhub-next/audio/package.json +1 -1
  8. package/dist/node_modules/@allyhub-next/chart/dist/chart-xml.js +2 -2
  9. package/dist/node_modules/@allyhub-next/chart/dist/chart.d.ts +14 -5
  10. package/dist/node_modules/@allyhub-next/chart/dist/chart.js +1 -1
  11. package/dist/node_modules/@allyhub-next/chart/package.json +1 -1
  12. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.d.ts +205 -0
  13. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.js +2 -0
  14. package/dist/node_modules/@allyhub-next/formats/dist/data/script.d.ts +4 -1
  15. package/dist/node_modules/@allyhub-next/formats/dist/data/script.js +1 -1
  16. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.d.ts +248 -18
  17. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.js +1 -1
  18. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.d.ts +1114 -91
  19. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.js +1 -1
  20. package/dist/node_modules/@allyhub-next/formats/dist/data/website.d.ts +20 -0
  21. package/dist/node_modules/@allyhub-next/formats/dist/data/website.js +2 -0
  22. package/dist/node_modules/@allyhub-next/formats/dist/index.d.ts +4 -0
  23. package/dist/node_modules/@allyhub-next/formats/dist/index.js +1 -1
  24. package/dist/node_modules/@allyhub-next/formats/dist/items.d.ts +1 -1
  25. package/dist/node_modules/@allyhub-next/formats/dist/items.js +1 -1
  26. package/dist/node_modules/@allyhub-next/formats/dist/media-type.d.ts +3 -0
  27. package/dist/node_modules/@allyhub-next/formats/dist/media-type.js +2 -0
  28. package/dist/node_modules/@allyhub-next/formats/dist/schemas.d.ts +625 -30
  29. package/dist/node_modules/@allyhub-next/formats/dist/schemas.js +1 -1
  30. package/dist/node_modules/@allyhub-next/formats/dist/strict.d.ts +2 -0
  31. package/dist/node_modules/@allyhub-next/formats/dist/strict.js +1 -1
  32. package/dist/node_modules/@allyhub-next/formats/dist/zip.d.ts +17 -0
  33. package/dist/node_modules/@allyhub-next/formats/dist/zip.js +2 -0
  34. package/dist/node_modules/@allyhub-next/formats/package.json +2 -1
  35. package/dist/node_modules/@allyhub-next/ooxml/LICENSE +241 -0
  36. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.d.ts +31 -0
  37. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.js +2 -0
  38. package/dist/node_modules/@allyhub-next/ooxml/dist/color.d.ts +33 -0
  39. package/dist/node_modules/@allyhub-next/ooxml/dist/color.js +2 -0
  40. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.d.ts +13 -0
  41. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.js +2 -0
  42. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.d.ts +79 -0
  43. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.js +2 -0
  44. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.d.ts +132 -0
  45. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.js +2 -0
  46. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.d.ts +28 -0
  47. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.js +2 -0
  48. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.d.ts +4708 -0
  49. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.js +2 -0
  50. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.d.ts +57 -0
  51. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.js +2 -0
  52. package/dist/node_modules/@allyhub-next/ooxml/dist/index.d.ts +10 -0
  53. package/dist/node_modules/@allyhub-next/ooxml/dist/index.js +2 -0
  54. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.d.ts +12 -0
  55. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.js +2 -0
  56. package/dist/node_modules/@allyhub-next/ooxml/dist/node.d.ts +111 -0
  57. package/dist/node_modules/@allyhub-next/ooxml/dist/node.js +2 -0
  58. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.d.ts +45 -0
  59. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.js +2 -0
  60. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.d.ts +48 -0
  61. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.js +2 -0
  62. package/dist/node_modules/@allyhub-next/ooxml/dist/report.d.ts +45 -0
  63. package/dist/node_modules/@allyhub-next/ooxml/dist/report.js +2 -0
  64. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.d.ts +28 -0
  65. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.js +2 -0
  66. package/dist/node_modules/@allyhub-next/ooxml/package.json +26 -0
  67. package/dist/node_modules/@allyhub-next/protocol/dist/account.d.ts +338 -0
  68. package/dist/node_modules/@allyhub-next/protocol/dist/account.js +2 -0
  69. package/dist/node_modules/@allyhub-next/protocol/dist/auth.d.ts +12 -13
  70. package/dist/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  71. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.d.ts +35 -0
  72. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.js +2 -0
  73. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.d.ts +101 -32
  74. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.js +1 -1
  75. package/dist/node_modules/@allyhub-next/protocol/dist/editor.d.ts +89 -5
  76. package/dist/node_modules/@allyhub-next/protocol/dist/editor.js +1 -1
  77. package/dist/node_modules/@allyhub-next/protocol/dist/files.d.ts +2 -2
  78. package/dist/node_modules/@allyhub-next/protocol/dist/index.d.ts +6 -0
  79. package/dist/node_modules/@allyhub-next/protocol/dist/index.js +1 -1
  80. package/dist/node_modules/@allyhub-next/protocol/dist/notes.d.ts +23 -0
  81. package/dist/node_modules/@allyhub-next/protocol/dist/notes.js +1 -1
  82. package/dist/node_modules/@allyhub-next/protocol/dist/open.d.ts +13 -0
  83. package/dist/node_modules/@allyhub-next/protocol/dist/open.js +2 -0
  84. package/dist/node_modules/@allyhub-next/protocol/dist/registry.d.ts +73 -59
  85. package/dist/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  86. package/dist/node_modules/@allyhub-next/protocol/dist/routes.d.ts +1 -1
  87. package/dist/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  88. package/dist/node_modules/@allyhub-next/protocol/dist/shares.d.ts +115 -0
  89. package/dist/node_modules/@allyhub-next/protocol/dist/shares.js +2 -0
  90. package/dist/node_modules/@allyhub-next/protocol/dist/sites.d.ts +293 -0
  91. package/dist/node_modules/@allyhub-next/protocol/dist/sites.js +2 -0
  92. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.d.ts +377 -0
  93. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.js +2 -0
  94. package/dist/node_modules/@allyhub-next/protocol/dist/teams.d.ts +27 -9
  95. package/dist/node_modules/@allyhub-next/protocol/dist/teams.js +1 -1
  96. package/dist/node_modules/@allyhub-next/protocol/dist/tools.d.ts +53 -14
  97. package/dist/node_modules/@allyhub-next/protocol/dist/tools.js +1 -1
  98. package/dist/node_modules/@allyhub-next/protocol/package.json +2 -1
  99. package/dist/node_modules/@allyhub-next/runtimes/package.json +1 -1
  100. package/dist/node_modules/@allyhub-next/runtimes/schemas/runtimes.schema.json +25 -5
  101. package/dist/node_modules/@allyhub-next/scenery/package.json +1 -1
  102. package/dist/node_modules/@allyhub-next/sheet/dist/api/capabilities.js +1 -1
  103. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.d.ts +1 -0
  104. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.js +1 -1
  105. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.d.ts +83 -0
  106. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.js +2 -0
  107. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.d.ts +40 -1
  108. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.js +1 -1
  109. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.d.ts +9 -3
  110. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.js +1 -1
  111. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.d.ts +5 -1
  112. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.js +1 -1
  113. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.d.ts +60 -13
  114. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.js +1 -1
  115. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/aggregate.js +1 -1
  116. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.d.ts +4 -0
  117. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.js +2 -0
  118. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/criteria.js +1 -1
  119. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/database.js +1 -1
  120. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/date.js +1 -1
  121. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.d.ts +27 -1
  122. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.js +1 -1
  123. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.d.ts +16 -0
  124. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.js +2 -0
  125. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.d.ts +18 -1
  126. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.js +1 -1
  127. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/finance.js +1 -1
  128. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.d.ts +2 -0
  129. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.js +1 -1
  130. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/info.js +1 -1
  131. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/kernels.js +1 -1
  132. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/logical.js +1 -1
  133. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/lookup.js +1 -1
  134. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/maths.js +1 -1
  135. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.d.ts +2 -0
  136. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.js +2 -0
  137. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/text.js +1 -1
  138. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.d.ts +38 -0
  139. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.js +2 -0
  140. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.d.ts +19 -0
  141. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.js +2 -0
  142. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.d.ts +49 -0
  143. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.js +2 -0
  144. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.d.ts +82 -0
  145. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.js +2 -0
  146. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.d.ts +6 -1
  147. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.js +1 -1
  148. package/dist/node_modules/@allyhub-next/sheet/dist/chart.js +1 -1
  149. package/dist/node_modules/@allyhub-next/sheet/dist/check.js +1 -1
  150. package/dist/node_modules/@allyhub-next/sheet/dist/diff.d.ts +15 -0
  151. package/dist/node_modules/@allyhub-next/sheet/dist/diff.js +1 -1
  152. package/dist/node_modules/@allyhub-next/sheet/dist/export.d.ts +29 -8
  153. package/dist/node_modules/@allyhub-next/sheet/dist/export.js +3 -4
  154. package/dist/node_modules/@allyhub-next/sheet/dist/file.js +2 -2
  155. package/dist/node_modules/@allyhub-next/sheet/dist/format.d.ts +8 -2
  156. package/dist/node_modules/@allyhub-next/sheet/dist/format.js +1 -1
  157. package/dist/node_modules/@allyhub-next/sheet/dist/html.d.ts +52 -4
  158. package/dist/node_modules/@allyhub-next/sheet/dist/html.js +43 -11
  159. package/dist/node_modules/@allyhub-next/sheet/dist/index.d.ts +7 -3
  160. package/dist/node_modules/@allyhub-next/sheet/dist/index.js +1 -1
  161. package/dist/node_modules/@allyhub-next/sheet/dist/inspect.js +1 -1
  162. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.d.ts +98 -0
  163. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.js +2 -0
  164. package/dist/node_modules/@allyhub-next/sheet/dist/structure.js +1 -1
  165. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.d.ts +32 -0
  166. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.js +2 -0
  167. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.d.ts +3 -0
  168. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.js +2 -0
  169. package/dist/node_modules/@allyhub-next/sheet/dist/values.js +1 -1
  170. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.d.ts +10 -1
  171. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.js +1 -1
  172. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.d.ts +12 -1
  173. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.js +1 -1
  174. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.d.ts +14 -4
  175. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.js +2 -2
  176. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.d.ts +11 -1
  177. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.js +36 -16
  178. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.d.ts +6 -1
  179. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.js +1 -1
  180. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.d.ts +44 -2
  181. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.js +2 -1
  182. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.d.ts +23 -0
  183. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.js +2 -0
  184. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.d.ts +2 -0
  185. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.js +1 -1
  186. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.d.ts +6 -0
  187. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.js +1 -1
  188. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.d.ts +40 -0
  189. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.js +2 -0
  190. package/dist/node_modules/@allyhub-next/sheet/package.json +1 -1
  191. package/dist/node_modules/@allyhub-next/slides-core/dist/animation.js +1 -1
  192. package/dist/node_modules/@allyhub-next/slides-core/dist/api.d.ts +121 -44
  193. package/dist/node_modules/@allyhub-next/slides-core/dist/api.js +2 -2
  194. package/dist/node_modules/@allyhub-next/slides-core/dist/capabilities.js +1 -1
  195. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.d.ts +50 -13
  196. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.js +1 -1
  197. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-file.js +1 -1
  198. package/dist/node_modules/@allyhub-next/slides-core/dist/check.js +1 -1
  199. package/dist/node_modules/@allyhub-next/slides-core/dist/code.d.ts +33 -0
  200. package/dist/node_modules/@allyhub-next/slides-core/dist/code.js +2 -0
  201. package/dist/node_modules/@allyhub-next/slides-core/dist/components.d.ts +31 -0
  202. package/dist/node_modules/@allyhub-next/slides-core/dist/components.js +2 -0
  203. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.d.ts +188 -5
  204. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.js +1 -1
  205. package/dist/node_modules/@allyhub-next/slides-core/dist/file.d.ts +43 -21
  206. package/dist/node_modules/@allyhub-next/slides-core/dist/file.js +3 -3
  207. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.d.ts +17 -0
  208. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.js +2 -0
  209. package/dist/node_modules/@allyhub-next/slides-core/dist/index.d.ts +5 -0
  210. package/dist/node_modules/@allyhub-next/slides-core/dist/index.js +1 -1
  211. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.d.ts +6 -0
  212. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.js +2 -0
  213. package/dist/node_modules/@allyhub-next/slides-core/dist/measure.js +1 -1
  214. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.d.ts +58 -0
  215. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.js +2 -0
  216. package/dist/node_modules/@allyhub-next/slides-core/dist/model.d.ts +38 -4
  217. package/dist/node_modules/@allyhub-next/slides-core/dist/office.d.ts +27 -1
  218. package/dist/node_modules/@allyhub-next/slides-core/dist/office.js +1 -1
  219. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.d.ts +26 -5
  220. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.js +1 -1
  221. package/dist/node_modules/@allyhub-next/slides-core/dist/script.d.ts +18 -16
  222. package/dist/node_modules/@allyhub-next/slides-core/dist/script.js +2 -2
  223. package/dist/node_modules/@allyhub-next/slides-core/dist/stage.d.ts +51 -53
  224. package/dist/node_modules/@allyhub-next/slides-core/dist/strict.js +1 -1
  225. package/dist/node_modules/@allyhub-next/slides-core/dist/units.d.ts +27 -0
  226. package/dist/node_modules/@allyhub-next/slides-core/dist/units.js +1 -1
  227. package/dist/node_modules/@allyhub-next/slides-core/dist/values.d.ts +7 -0
  228. package/dist/node_modules/@allyhub-next/slides-core/dist/values.js +2 -0
  229. package/dist/node_modules/@allyhub-next/slides-core/package.json +1 -1
  230. package/dist/node_modules/@allyhub-next/video-core/dist/captions.js +6 -6
  231. package/dist/node_modules/@allyhub-next/video-core/dist/fact.d.ts +47 -8
  232. package/dist/node_modules/@allyhub-next/video-core/dist/fact.js +1 -1
  233. package/dist/node_modules/@allyhub-next/video-core/dist/index.d.ts +1 -0
  234. package/dist/node_modules/@allyhub-next/video-core/dist/index.js +1 -1
  235. package/dist/node_modules/@allyhub-next/video-core/dist/marks.d.ts +14 -0
  236. package/dist/node_modules/@allyhub-next/video-core/dist/marks.js +1 -1
  237. package/dist/node_modules/@allyhub-next/video-core/dist/music.d.ts +2 -1
  238. package/dist/node_modules/@allyhub-next/video-core/dist/piece.d.ts +11 -2
  239. package/dist/node_modules/@allyhub-next/video-core/dist/problem.d.ts +4 -0
  240. package/dist/node_modules/@allyhub-next/video-core/dist/problem.js +1 -1
  241. package/dist/node_modules/@allyhub-next/video-core/dist/schema.d.ts +2 -2
  242. package/dist/node_modules/@allyhub-next/video-core/dist/schema.js +1 -1
  243. package/dist/node_modules/@allyhub-next/video-core/dist/script.d.ts +2 -1
  244. package/dist/node_modules/@allyhub-next/video-core/dist/script.js +1 -1
  245. package/dist/node_modules/@allyhub-next/video-core/dist/source.d.ts +7 -0
  246. package/dist/node_modules/@allyhub-next/video-core/dist/source.js +2 -0
  247. package/dist/node_modules/@allyhub-next/video-core/dist/timeline.d.ts +10 -33
  248. package/dist/node_modules/@allyhub-next/video-core/package.json +1 -1
  249. package/dist/sheets.d.ts +1 -1
  250. package/dist/sheets.js +1 -1
  251. package/dist/slides.d.ts +3 -1
  252. package/dist/slides.js +1 -1
  253. package/docs/README.md +1 -0
  254. package/docs/contract.md +1 -1
  255. package/docs/defaults.md +25 -2
  256. package/docs/layers.md +1 -1
  257. package/docs/project.md +3 -1
  258. package/docs/sheets.md +29 -3
  259. package/docs/slides.md +18 -14
  260. package/docs/sound.md +1 -1
  261. package/docs/websites.md +57 -0
  262. package/package.json +3 -1
@@ -1,11 +1,32 @@
1
- import { Calc } from "./calc/engine.js";
1
+ import type { Calc } from "./calc/engine.js";
2
+ import { type Scalar } from "./values.js";
2
3
  import type { Table, Worksheet } from "./workbook.js";
3
- /** A sheet as CSV: dates as ISO text, numbers as numbers. */
4
- export declare function csvOf(calc: Calc, sheet: Worksheet): string;
5
- /** A sheet as a Markdown table, values as their formats show them, its first row the head. */
6
- export declare function markdownOf(calc: Calc, sheet: Worksheet): string;
4
+ /** What a value is written as: data, or as its format shows it. */
5
+ export type ValueMode = "data" | "shown";
6
+ export interface ValueOptions {
7
+ /** Default "data" for CSV and JSON, "shown" for Markdown. */
8
+ values?: ValueMode;
9
+ }
10
+ export interface CsvOptions extends ValueOptions {
11
+ /** A UTF-8 byte-order mark first, by which Excel reads the file as UTF-8 (é, €, 中文); default true. */
12
+ bom?: boolean;
13
+ }
14
+ /** A number as Excel keeps it: 15 significant digits, -0 as 0. */
15
+ export declare const excelNumber: (n: number) => number;
16
+ /** A value as one CSV field. */
17
+ export declare function csvText(value: Scalar, code: string | undefined, mode?: ValueMode): string;
18
+ /** A value as JSON holds it: a number, text, true or false, an error's code, or null. */
19
+ export declare function dataValue(value: Scalar, code: string | undefined, mode?: ValueMode): string | number | boolean | null;
20
+ /** A sheet as CSV (RFC 4180: CRLF between records), from A1 to the last cell it uses. */
21
+ export declare function csvOf(calc: Calc, sheet: Worksheet, o?: CsvOptions): string;
22
+ /**
23
+ * A sheet as a Markdown table, its first row the head: values as their
24
+ * formats show them unless `values` is "data"; a column whose values are
25
+ * all numbers is aligned right.
26
+ */
27
+ export declare function markdownOf(calc: Calc, sheet: Worksheet, o?: ValueOptions): string;
7
28
  /** A table's computed rows, by header. */
8
- export declare function tableRows(calc: Calc, table: Table): Record<string, string | number | boolean | null>[];
9
- /** The workbook as data: each sheet's rows, each table's rows by header, each name's value. */
10
- export declare function jsonOf(calc: Calc): Record<string, unknown>;
29
+ export declare function tableRows(calc: Calc, table: Table, o?: ValueOptions): Record<string, string | number | boolean | null>[];
30
+ /** The workbook as data: each sheet's rows, each table's rows by header. */
31
+ export declare function jsonOf(calc: Calc, o?: ValueOptions): Record<string, unknown>;
11
32
  //# sourceMappingURL=export.d.ts.map
@@ -1,6 +1,5 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import"./calc/engine.js";import{csvRecord as i}from"./csv.js";import{dataValue as a,shownValue as m}from"./format.js";const p=(r,t,e,o)=>m(r.value(t,e,o),t.lookAt(e,o).format),u=(r,t,e,o)=>a(r.value(t,e,o),t.lookAt(e,o).format);function f(r,t){const e=r.used;if(!e)return[];const o=[];for(let s=0;s<=e.bottom;s++){const n=[];for(let c=0;c<=e.right;c++)n.push(t(s,c));o.push(n)}return o}export function csvOf(r,t){return f(t,(o,s)=>{const n=u(r,t,o,s);return n===null?"":typeof n=="boolean"?n?"TRUE":"FALSE":String(n)}).map(o=>`${i(o)}
3
- `).join("")}const w=r=>r.replaceAll("|","\\|").replaceAll(`
4
- `,"<br>");export function markdownOf(r,t){const e=f(t,(c,l)=>p(r,t,c,l)),[o,...s]=e;if(!o)return"";const n=c=>`| ${c.map(w).join(" | ")} |`;return`${[n(o),n(o.map(()=>"---")),...s.map(n)].join(`
2
+ import{writeCsv as S}from"./csv.js";import{isDateCode as k,shownValue as b}from"./format.js";import{CellError as w,dateOf as j}from"./values.js";const y=t=>(t.split(";")[0]??"").replace(/"[^"]*"|\\.|_.|\*./gu,"").replace(/\[(?![hms]+\])[^\]]*\]/giu,""),h=new Map;function _(t){if(t===void 0)return;if(h.has(t))return h.get(t);let n;if(k(t)){const r=y(t).toLowerCase(),o=/\[(h+|m+|s+)\]/u.test(r),e=[...r.matchAll(/\[?([ydhms])\1*\]?|am\/pm|a\/p/gu)].map(c=>c[0]);let s=!1,i=!1,u=!1;for(const[c,a]of e.entries()){const f=a.replace(/[[\]]/gu,"")[0];if(f==="y"||f==="d")s=!0;else if(f==="h"||a.includes("/"))i=!0;else if(f==="s")i=!0,u=!0;else if(f==="m"){const l=e[c-1]?.replace(/[[\]]/gu,"")[0],m=e[c+1]?.replace(/[[\]]/gu,"")[0];a.startsWith("[")||l==="h"||m==="s"?i=!0:s=!0}}o?n={kind:"duration",seconds:u}:s&&i?n={kind:"datetime",seconds:u}:i?n={kind:"time",seconds:u}:s&&(n={kind:"date",seconds:!1})}return h.set(t,n),n}const $=864e5,A=2958465,d=(t,n=2)=>String(t).padStart(n,"0");export const excelNumber=t=>t===0?0:Number(t.toPrecision(15));function x(t,n,r=2){const o=Math.floor(t/1e3),e=t%1e3;let s=`${d(Math.floor(o/3600),r)}:${d(Math.floor(o/60)%60)}`;return(n||o%60!==0||e!==0)&&(s+=`:${d(o%60)}`),e!==0&&(s+=`.${d(e,3).replace(/0+$/u,"")}`),s}function T(t){const n=t<0?"-":"";let r=Math.abs(t);const o=Math.floor(r/36e5);r-=o*36e5;const e=Math.floor(r/6e4);r-=e*6e4;const s=[o>0?`${String(o)}H`:"",e>0?`${String(e)}M`:"",r>0?`${String(r/1e3)}S`:""].join("");return`${n}PT${s||"0S"}`}function M(t,n,r){const o=Math.round(t*$);if(n.kind==="duration")return r==="json"?T(o):`${o<0?"-":""}${x(Math.abs(o),n.seconds,1)}`;if(t<0||t>=A+1)return;const e=Math.floor(o/$),s=x(o-e*$,n.seconds||r==="json");if(e===0||n.kind==="time")return s;if(e===60)return;const{year:i,month:u,day:c}=j(e),a=`${d(i,4)}-${d(u)}-${d(c)}`;return n.kind==="date"?a:`${a}${r==="json"?"T":" "}${s}`}export function csvText(t,n,r="data"){if(t===null)return"";if(r==="shown")return b(t,n);if(typeof t=="boolean")return t?"TRUE":"FALSE";if(t instanceof w)return t.code;if(typeof t=="string")return t;const o=_(n);return(o&&M(t,o,"csv"))??String(excelNumber(t))}export function dataValue(t,n,r="data"){if(t===null)return null;if(r==="shown")return b(t,n);if(t instanceof w)return t.code;if(typeof t!="number")return t;const o=_(n);return(o&&M(t,o,"json"))??excelNumber(t)}const p=(t,n,r)=>t.lookAt(n,r).format;function g(t,n){const r=t.used;if(!r)return[];const o=[];for(let e=0;e<=r.bottom;e++){const s=[];for(let i=0;i<=r.right;i++)s.push(n(e,i));o.push(s)}return o}export function csvOf(t,n,r={}){const o=g(n,(e,s)=>csvText(t.value(n,e,s),p(n,e,s),r.values));return S(o,{delimiter:",",newline:`\r
3
+ `,bom:r.bom??!0,finalNewline:!0})}const E=t=>t.replaceAll("|","\\|").replace(/\r?\n/gu,"<br>");export function markdownOf(t,n,r={}){const o=r.values??"shown",e=[],s=g(n,(f,l)=>{const m=t.value(n,f,l);return f>0&&m!==null&&(e[l]=(e[l]??!0)&&typeof m=="number"),csvText(m,p(n,f,l),o)}),[i,...u]=s;if(!i)return"";const c=f=>`| ${f.map(E).join(" | ")} |`,a=i.map((f,l)=>e[l]===!0?"---:":"---");return`${[c(i),`| ${a.join(" | ")} |`,...u.map(c)].join(`
5
4
  `)}
6
- `}export function tableRows(r,t){const{sheet:e,at:o}=t,s=[];for(let n=0;n<t.rows;n++){const c={};for(const l of t.columns)c[l.name]=u(r,e,o.row+1+n,o.col+l.index);s.push(c)}return s}export function jsonOf(r){const{wb:t}=r,e={};for(const o of t.sheets){const s={};for(const n of o.tables)s[n.name]=tableRows(r,n);e[o.name]={rows:f(o,(n,c)=>u(r,o,n,c)),...o.tables.length>0?{tables:s}:{}}}return{...t.title===void 0?{}:{title:t.title},sheets:e}}
5
+ `}export function tableRows(t,n,r={}){const{sheet:o,at:e}=n,s=[];for(let i=0;i<n.rows;i++){const u={};for(const c of n.columns){const a=e.row+1+i,f=e.col+c.index;u[c.name]=dataValue(t.value(o,a,f),p(o,a,f),r.values)}s.push(u)}return s}export function jsonOf(t,n={}){const{wb:r}=t,o={};for(const e of r.sheets){const s={};for(const i of e.tables)s[i.name]=tableRows(t,i,n);o[e.name]={rows:g(e,(i,u)=>dataValue(t.value(e,i,u),p(e,i,u),n.values)),...e.tables.length>0?{tables:s}:{}}}return{...r.title===void 0?{}:{title:r.title},sheets:o}}
@@ -1,3 +1,3 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{readDataFile as m}from"@allyhub-next/formats";import{LineCounter as u,parseDocument as f}from"yaml";export const ENTRY="sheet.yaml";export function dataFilesOf(l){const{file:o}=readSheetFile(l);return[...new Set(o?.sheets.flatMap(n=>[...(n.tables??[]).map(t=>t.rows),...(n.blocks??[]).map(t=>t.rows)])??[])]}export function readSheetFile(l){const o=new u,n=f(l,{lineCounter:o}),t=e=>{for(let r=e.length;r>=0;r--){const a=n.getIn(e.slice(0,r),!0)?.range?.[0];if(a!==void 0)return o.linePos(a).line}};if(n.errors.length>0)return{problems:n.errors.map(e=>({file:ENTRY,line:o.linePos(e.pos[0]).line,message:`not YAML: ${e.message.split(`
3
- `)[0]??""}`})),lineOf:t};const i=m("sheet",n.toJS()??{});return i.ok?{file:i.value,problems:[],lineOf:t}:{problems:i.problems.map(e=>{const r=t(e.path===""?[]:e.path.split(".").map(s=>/^\d+$/u.test(s)?Number(s):s));return{file:ENTRY,...r===void 0?{}:{line:r},message:`${e.path===""?"":`${e.path}: `}${e.message}`}}),lineOf:t}}
2
+ import{readDataFile as c}from"@allyhub-next/formats";import{LineCounter as p,isMap as m,isScalar as f,parseDocument as d,visit as g}from"yaml";export const ENTRY="sheet.yaml";export function dataFilesOf(i){const{file:t}=readSheetFile(i);return[...new Set(t?.sheets.flatMap(s=>[...(s.tables??[]).map(n=>n.rows),...(s.blocks??[]).map(n=>n.rows)])??[])]}function h(i){const t=[];return g(i,{Map(s,n){if(!m(n))return;const a=new Set;for(const o of n.items){const e=f(o.key)?String(o.key.value):void 0;if(e!==void 0)if(a.has(e)){const r=f(o.key)?o.key.range?.[0]??0:0;t.push({at:r,key:e})}else a.add(e)}}}),t}export function readSheetFile(i){const t=new p,s=d(i,{lineCounter:t,uniqueKeys:!1}),n=e=>{for(let r=e.length;r>=0;r--){const u=s.getIn(e.slice(0,r),!0)?.range?.[0];if(u!==void 0)return t.linePos(u).line}},a=h(s);if(s.errors.length>0||a.length>0)return{problems:[...s.errors.map(e=>({file:ENTRY,line:t.linePos(e.pos[0]).line,message:`not YAML: ${e.message.split(`
3
+ `)[0]??""}`})),...a.map(e=>({file:ENTRY,line:t.linePos(e.at).line,message:`not YAML: Map keys must be unique (${e.key})`}))],lineOf:n};const o=c("sheet",s.toJS()??{});return o.ok?{file:o.value,problems:[],lineOf:n}:{problems:o.problems.map(e=>{const r=n(e.path===""?[]:e.path.split(".").map(l=>/^\d+$/u.test(l)?Number(l):l));return{file:ENTRY,...r===void 0?{}:{line:r},message:`${e.path===""?"":`${e.path}: `}${e.message}`}}),lineOf:n}}
@@ -1,9 +1,15 @@
1
1
  import { type Scalar } from "./values.js";
2
+ /**
3
+ * What General can show a number as, widest first: as it is (at most 11
4
+ * characters), then with fewer digits, then with an exponent. A cell shows
5
+ * the first that fits it; none is ####.
6
+ */
7
+ export declare function generalForms(value: number): string[];
8
+ /** A number as General shows it, in a cell as wide as `fits` allows when it is given: undefined when nothing fits (####). */
9
+ export declare function generalText(value: number, fits?: (text: string) => boolean): string | undefined;
2
10
  /** A value through a number format; General without one. */
3
11
  export declare function shownValue(value: Scalar, code?: string): string;
4
12
  /** The colour a number format gives a value, as [Red] does. */
5
13
  export declare function shownColor(value: Scalar, code?: string): string | undefined;
6
14
  export declare const isDateCode: (code: string | undefined) => boolean;
7
- /** A value as data: a date as ISO text, an error as its code. */
8
- export declare function dataValue(value: Scalar, code: string | undefined): string | number | boolean | null;
9
15
  //# sourceMappingURL=format.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{format as e,formatColor as s,isDateFormat as p,isValidFormat as o}from"numfmt";import{CellError as f,isoOfSerial as m,numberText as i}from"./values.js";export function shownValue(r,n){if(r===null)return"";if(r instanceof f)return r.code;if(typeof r=="boolean")return r?"TRUE":"FALSE";const t=n??"General";if(typeof r=="string")return n!==void 0&&o(n)?e(n,r):r;if(t==="General"||!o(t))return i(r);try{return e(t,r)}catch{return i(r)}}export function shownColor(r,n){if(typeof r!="number"||n===void 0||!o(n))return;const t=s(n,r);return typeof t=="string"?t:void 0}export const isDateCode=r=>r!==void 0&&o(r)&&p(r);export function dataValue(r,n){return r instanceof f?r.code:typeof r=="number"&&isDateCode(n)?m(r):r}
2
+ import{format as i,formatColor as p,isDateFormat as u,isValidFormat as f}from"numfmt";import{CellError as l,numberText as s}from"./values.js";export function generalForms(n){const r=i("General",n),t=[r];for(let e=10;e>=1;e--){const o=i("General",Number(n.toPrecision(e)));o.length<(t[t.length-1]??r).length&&t.push(o)}for(let e=5;e>=0;e--){const o=n.toExponential(e).replace(/e([+-])(\d)$/u,"E$10$2").replace(/e/u,"E");o.length<(t[t.length-1]??r).length&&t.push(o)}return t}export function generalText(n,r){const t=generalForms(n);return r?t.find(r):t[0]}export function shownValue(n,r){if(n===null)return"";if(n instanceof l)return n.code;if(typeof n=="boolean")return n?"TRUE":"FALSE";const t=r??"General";if(typeof n=="string")return r!==void 0&&f(r)?i(r,n):n;if(t==="General"||!f(t))return generalText(n)??s(n);try{return i(t,n)}catch{return generalText(n)??s(n)}}export function shownColor(n,r){if(typeof n!="number"||r===void 0||!f(r))return;const t=p(r,n);return typeof t=="string"?t:void 0}export const isDateCode=n=>n!==void 0&&f(n)&&u(n);
@@ -1,9 +1,8 @@
1
1
  import { type Area } from "./address.js";
2
2
  import type { Calc } from "./calc/engine.js";
3
+ import { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, type PrintJob } from "./paginate.js";
3
4
  import { type Worksheet } from "./workbook.js";
4
- /** A cell of a size nothing sets. */
5
- export declare const DEFAULT_COLUMN_WIDTH = 64;
6
- export declare const DEFAULT_ROW_HEIGHT = 20;
5
+ export { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT };
7
6
  export interface SheetHtmlOptions {
8
7
  /** The sheets drawn; default every one that is not hidden. */
9
8
  sheets?: readonly Worksheet[];
@@ -29,6 +28,55 @@ export interface SheetHtml {
29
28
  /** What `rows` and `columns` left out, a line per sheet. */
30
29
  cut: string[];
31
30
  }
32
- /** A workbook's sheets as one page of HTML. */
31
+ /** A workbook's sheets as one page of HTML, as a person sees them: for a picture, and frames. */
33
32
  export declare function sheetHtml(calc: Calc, o?: SheetHtmlOptions): SheetHtml;
33
+ /** What a header's or footer's codes name, for one page. */
34
+ export interface PageFields {
35
+ page: number;
36
+ pages: number;
37
+ sheet: string;
38
+ /** The workbook's file name, &F. */
39
+ file: string;
40
+ /** When it is printed, for &D and &T. */
41
+ date: Date;
42
+ }
43
+ /**
44
+ * A header's or footer's section as HTML: Excel's codes, &P and &N (with
45
+ * +n or -n), &D, &T, &F, &A, &Z, &&, &B, &I, &U, &E, &S, &X, &Y, a font
46
+ * (&"name,style"), a size (&14) and a colour (&KFF0000). A picture (&G)
47
+ * draws nothing.
48
+ */
49
+ export declare function headerFooterHtml(text: string, f: PageFields): string;
50
+ export interface PrintHtmlOptions {
51
+ css?: string;
52
+ font?: string;
53
+ /** The workbook's file name, a header's &F. */
54
+ name: string;
55
+ /** When it is printed, a header's &D and &T. */
56
+ date: Date;
57
+ }
58
+ /**
59
+ * A workbook on paper: its pages, laid out once, and any stretch of them
60
+ * as one HTML page that prints them. What drawing a sheet needs (its
61
+ * pictures, its tables' stripes, its charts) is read once for every
62
+ * stretch.
63
+ */
64
+ export declare class SheetPrint {
65
+ readonly job: PrintJob;
66
+ private readonly calc;
67
+ private readonly drawers;
68
+ private readonly file;
69
+ constructor(calc: Calc, o?: {
70
+ sheets?: readonly Worksheet[];
71
+ file?: SheetHtmlOptions["file"];
72
+ });
73
+ private drawer;
74
+ /**
75
+ * Pages `from` to before `to` as one HTML page that prints them: each
76
+ * the paper's size, its header and footer in its margins, its title rows
77
+ * and columns, then its own, scaled, and the charts that fall in them.
78
+ */
79
+ html(from: number, to: number, o: PrintHtmlOptions): string;
80
+ private page;
81
+ }
34
82
  //# sourceMappingURL=html.d.ts.map
@@ -1,20 +1,52 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{formatColor as T,isValidFormat as B}from"numfmt";import{cellName as E,columnLetter as C,contains as I,overlaps as N}from"./address.js";import{chartDef as _,chartPlace as P,chartSize as H,chartSvg as G}from"./chart.js";import{fileCells as U,isPicture as V,pictureHeight as W,pictureSize as q}from"./files.js";import{shownValue as k}from"./format.js";import{Rules as K,iconShape as J}from"./rules.js";import{CellError as Q}from"./values.js";import{placeKey as z}from"./workbook.js";export const DEFAULT_COLUMN_WIDTH=64,DEFAULT_ROW_HEIGHT=20;const X={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},Y=i=>{let t="";for(let n=0;n<i.length;n+=32768)t+=String.fromCharCode(...i.subarray(n,n+32768));return btoa(t)},y=i=>i.replace(/[&<>"]/gu,t=>X[t]??t),Z={thin:"1px solid",medium:"2px solid",thick:"3px solid",double:"3px double",hair:"1px dotted",dotted:"1px dotted",dashed:"1px dashed",dashDot:"1px dashed",dashDotDot:"1px dashed",mediumDashed:"2px dashed",mediumDashDot:"2px dashed",mediumDashDotDot:"2px dashed",slantDashDot:"2px dashed"},tt={left:"left",center:"center",right:"right",justify:"justify",distributed:"justify",centerContinuous:"center",fill:"left"},et={top:"top",center:"middle",justify:"middle",distributed:"middle"};function nt(i){if(typeof i=="number")return"right";if(typeof i=="boolean"||i instanceof Q)return"center"}const ot={up:"▲","up-right":"◥",right:"▶","down-right":"◢",down:"▼",circle:"●",flag:"⚑",check:"✔",bang:"!",cross:"✖",triangle:"▲",diamond:"◆",bars:"▮",quarter:"◔"};function it(i){const{shape:t,color:n,level:e}=J(i.set,i.index),o=(ot[t]??"●").repeat(t==="bars"?e??1:1);return`<span style="float:left;color:${n}">${o}</span>`}function st(i,t,n){const e=[];i.bold===!0&&e.push("font-weight:bold"),i.italic===!0&&e.push("font-style:italic");const o=[i.underline?"underline":"",i.strike===!0?"line-through":""].filter(Boolean);o.length>0&&e.push(`text-decoration:${o.join(" ")}`),i.font!==void 0&&e.push(`font-family:"${i.font.replace(/["\\]/gu,"")}",var(--font)`),i.size!==void 0&&e.push(`font-size:${String(i.size)}pt`);const r=i.color??(typeof t=="number"&&n!==void 0&&B(n)?T(n,t)??void 0:void 0);typeof r=="string"&&e.push(`color:${r}`);const{fill:s}=i;if(typeof s=="string")e.push(`background:${s}`);else if(s){const c=s.color??s.background;c!==void 0&&e.push(`background:${c}`)}const a=(i.align===void 0||i.align==="general"?void 0:tt[i.align])??nt(t);a!==void 0&&e.push(`text-align:${a}`);const d=i.valign===void 0?void 0:et[i.valign];d!==void 0&&e.push(`vertical-align:${d}`),i.wrap===!0&&e.push("white-space:pre-wrap","overflow-wrap:anywhere"),i.indent!==void 0&&e.push(`padding-left:${String(3+i.indent*9)}px`);for(const c of["left","right","top","bottom"]){const h=i.border?.[c];h&&e.push(`border-${c}:${Z[h.style]??"1px solid"} ${h.color??"#000"}`)}return e.join(";")}class rt{classes=new Map;calc;cut=[];drawnFiles=new Map;pages=[];widest=0;o;rules;constructor(t,n){this.calc=t,this.o=n}classOf(t){if(t==="")return"";let n=this.classes.get(t);return n||(n=`s${String(this.classes.size)}`,this.classes.set(t,n)),n}shown(t,n,e){const o=[];for(let r=t;r<=n;r++)e(r)||o.push(r);return o}spans(t,n,e){const o=new Map,r=new Set;for(const s of t.merges){const a=n.filter(p=>p>=s.top&&p<=s.bottom),d=e.filter(p=>p>=s.left&&p<=s.right),[c]=a,[h]=d;if(!(c===void 0||h===void 0)){for(const p of a)for(const l of d)r.add(`${String(p)}:${String(l)}`);r.delete(`${String(c)}:${String(h)}`),o.set(`${String(c)}:${String(h)}`,{rows:a.length,cols:d.length})}}return{spans:o,covered:r}}width(t,n){const e=C(n),o=t.spec.columns?.[e]?.width;if(o!==void 0)return o;for(const r of t.tables){const s=r.columns[n-r.at.col]?.spec?.width;if(s!==void 0)return s}return DEFAULT_COLUMN_WIDTH}cell(t,n,e,o,r){const s=this.calc.value(t,n,e),a=this.rules?.at(n,e),d={...t.lookAt(n,e),...a?.look,...a?.scale===void 0?{}:{fill:a.scale}},c=d.format,h=t.tables.some($=>n===$.at.row&&I($.area,n,e));let p=st(d,s,c);if(a?.bar){const $=`${String(Math.round(a.bar.share*100))}%`;p=[p,`background:linear-gradient(90deg,${a.bar.color} ${$},transparent ${$})`].filter(Boolean).join(";")}h&&(p=[p,d.bold===void 0?"font-weight:bold":"","border-bottom:1px solid #000"].filter(Boolean).join(";"));const l=typeof s=="string"&&d.wrap!==!0&&r&&!o,u=[this.classOf(p),l?"over":""].filter(Boolean).join(" "),g=[u===""?"":` class="${u}"`,o&&o.rows>1?` rowspan="${String(o.rows)}"`:"",o&&o.cols>1?` colspan="${String(o.cols)}"`:""].join(""),m=a?.icon?it(a.icon):"",w=this.pictures(t).get(z(n,e))??(a?.bare===!0?"":y(k(s,c)));return`<td${g}>${m}${w}</td>`}pictures(t){const n=this.drawnFiles.get(t);if(n)return n.cells;const e=new Map,o=new Map,r=this.o.file;for(const{row:s,col:a,paths:d,column:c}of r?U(t,this.calc):[]){const h=W(c),p=d.map(l=>{const u=V(l)?r?.(l):void 0,g=u&&q(u);if(!u||!g)return y(l);o.set(s,Math.max(o.get(s)??0,h));const m=Y(u);return`<img src="data:image/${g.type};base64,${m}" alt="${y(l)}" style="height:${String(h)}px">`});e.set(z(s,a),p.join(" "))}return this.drawnFiles.set(t,{cells:e,rows:o}),e}sheet(t,n){const{o:e}=this,o=e.area??this.withCharts(t,t.used??{top:0,left:0,bottom:0,right:0}),r=this.calc.filtered(t);this.rules=t.conditions.length>0?new K(t,this.calc):void 0;const s=this.shown(o.top,o.bottom,f=>r.has(f)||t.spec.rows?.[String(f+1)]?.hidden===!0),a=this.shown(o.left,o.right,f=>t.spec.columns?.[C(f)]?.hidden===!0),d=s.slice(0,e.rows??s.length),c=a.slice(0,e.columns??a.length);if(d.length<s.length||c.length<a.length){const f=d[d.length-1]??o.top,x=c[c.length-1]??o.left;this.cut.push(`${t.name}: drew ${E({row:o.top,col:o.left})}:${E({row:f,col:x})} of ${String(s.length)} rows and ${String(a.length)} columns`)}const{spans:h,covered:p}=this.spans(t,d,c),l=e.headings===!0,u=c.map(f=>this.width(t,f)),g=44,m=u.reduce((f,x)=>f+x,0)+(l?g:0),b=[l?`<col style="width:${String(g)}px">`:"",...u.map(f=>`<col style="width:${String(f)}px">`)].join(""),w=[];l&&w.push(`<thead><tr><th></th>${c.map(f=>`<th>${C(f)}</th>`).join("")}</tr></thead>`),w.push("<tbody>");for(const f of d){this.pictures(t);const x=t.spec.rows?.[String(f+1)]?.height??this.drawnFiles.get(t)?.rows.get(f);w.push(`<tr${x===void 0?"":` style="height:${String(x)}px"`}>`),l&&w.push(`<th>${String(f+1)}</th>`),c.forEach((M,L)=>{const A=`${String(f)}:${String(M)}`;if(p.has(A))return;const v=c[L+1],O=v!==void 0&&t.at(f,v)===void 0&&!p.has(`${String(f)}:${String(v)}`);w.push(this.cell(t,f,M,h.get(A),O))}),w.push("</tr>")}w.push("</tbody>"),this.widest=Math.max(this.widest,m);const $=this.charts(t,d,c,u,l?g:0),j=`p${String(n)}`,S=m>690,D=S?m<=1020:!0,R=D?S?1123:794:m+104,F=D?S?794:1123:794;this.pages.push(`<section class="sheet" style="page:${j}"><style>@page ${j}{size:${String(R)}px ${String(F)}px;margin:48px}</style><h2>${y(t.name)}</h2><div class="book"><table class="${l?t.spec.gridlines===!1?"edged":"edged grid":""}" style="width:${String(m)}px"><colgroup>${b}</colgroup>${w.join("")}</table>${$}</div></section>`)}withCharts(t,n){const e={...n};for(const{spec:o,at:r}of t.charts){const{width:s,height:a}=H(o);let d=r.col;for(let h=(o.x??0)+s;h>0;d++)h-=this.width(t,d);let c=r.row;for(let h=(o.y??0)+a;h>0;c++)h-=this.rowHeight(t,c);e.bottom=Math.max(e.bottom,c-1),e.right=Math.max(e.right,d-1)}return e}rowHeight(t,n){return t.spec.rows?.[String(n+1)]?.height??DEFAULT_ROW_HEIGHT}charts(t,n,e,o,r){const[s]=n,[a]=e;if(t.charts.length===0||s===void 0||a===void 0)return"";const d=r>0?DEFAULT_ROW_HEIGHT:0,c={top:s,left:a,bottom:n[n.length-1]??s,right:e[e.length-1]??a},h=l=>{let u=d;for(const g of n){if(g>=l)break;u+=this.rowHeight(t,g)}return u},p=l=>{let u=r;return e.forEach((g,m)=>{g<l&&(u+=o[m]??0)}),u};return t.charts.filter(l=>{const{width:u,height:g}=H(l.spec),m=Math.ceil(u/DEFAULT_COLUMN_WIDTH),b=Math.ceil(g/DEFAULT_ROW_HEIGHT);return N(c,{top:l.at.row,left:l.at.col,bottom:l.at.row+b,right:l.at.col+m})}).map(l=>{const{left:u,top:g,width:m,height:b}=P(l.spec,h,p);return`<div class="chart" style="left:${String(u)}px;top:${String(g)}px">${G(_(this.calc,t,l),m,b,{font:"var(--font)"})}</div>`}).join("")}page(){const{o:t}=this,n=[...this.classes].map(([o,r])=>`.${r}{${o}}`),e=(t.sheets?.length??2)>1&&t.area===void 0;return`<!doctype html><html><head><meta charset="utf-8"><style>
3
- ${t.css??""}
4
- :root{--font:${t.font===void 0?"":`"${t.font}",`}Carlito,Calibri,Arial,sans-serif}
2
+ import{formatColor as O,isValidFormat as P}from"numfmt";import{cellName as T,columnLetter as _}from"./address.js";import{chartDef as U,chartPlace as k,chartSize as q,chartSvg as V}from"./chart.js";import{fileCells as K,isPicture as Y,pictureHeight as X,pictureSize as Z}from"./files.js";import{generalForms as J,shownValue as Q}from"./format.js";import{DEFAULT_COLUMN_WIDTH as tt,DEFAULT_ROW_HEIGHT as D,columnHidden as N,columnWidth as M,pageTitleCols as et,pageTitleRows as nt,rowHeight as st,rowHidden as H,paginate as it,usedWithCharts as ot}from"./paginate.js";import{Rules as rt,iconShape as lt}from"./rules.js";import{tableStyleLook as at,tableStyleOf as dt}from"./table-style.js";import{CellError as ct}from"./values.js";import{placeKey as I}from"./workbook.js";export{tt as DEFAULT_COLUMN_WIDTH,D as DEFAULT_ROW_HEIGHT};const ht={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},ft=o=>{let t="";for(let e=0;e<o.length;e+=32768)t+=String.fromCharCode(...o.subarray(e,e+32768));return btoa(t)},v=o=>o.replace(/[&<>"]/gu,t=>ht[t]??t),gt={thin:"1px solid",medium:"2px solid",thick:"3px solid",double:"3px double",hair:"1px dotted",dotted:"1px dotted",dashed:"1px dashed",dashDot:"1px dashed",dashDotDot:"1px dashed",mediumDashed:"2px dashed",mediumDashDot:"2px dashed",mediumDashDotDot:"2px dashed",slantDashDot:"2px dashed"},pt={left:"left",center:"center",right:"right",justify:"justify",distributed:"justify",centerContinuous:"center",fill:"left"},ut={top:"top",center:"middle",justify:"middle",distributed:"middle"};function mt(o){if(typeof o=="number")return"right";if(typeof o=="boolean"||o instanceof ct)return"center"}const $t={up:"▲","up-right":"◥",right:"▶","down-right":"◢",down:"▼",circle:"●",flag:"⚑",check:"✔",bang:"!",cross:"✖",triangle:"▲",diamond:"◆",bars:"▮",quarter:"◔"};function wt(o){const{shape:t,color:e,level:i}=lt(o.set,o.index),l=($t[t]??"●").repeat(t==="bars"?i??1:1);return`<span style="float:left;color:${e}">${l}</span>`}function bt(o,t,e){const i=[];o.bold===!0&&i.push("font-weight:bold"),o.italic===!0&&i.push("font-style:italic");const l=[o.underline?"underline":"",o.strike===!0?"line-through":""].filter(Boolean);l.length>0&&i.push(`text-decoration:${l.join(" ")}`),o.font!==void 0&&i.push(`font-family:"${o.font.replace(/["\\]/gu,"")}",var(--font)`),o.size!==void 0&&i.push(`font-size:${String(o.size)}pt`);const r=(typeof t=="number"&&e!==void 0&&P(e)?O(e,t)??void 0:void 0)??o.color;typeof r=="string"&&i.push(`color:${r}`);const{fill:d}=o;if(typeof d=="string")i.push(`background:${d}`);else if(d){const s=d.color??d.background;s!==void 0&&i.push(`background:${s}`)}const f=(o.align===void 0||o.align==="general"?void 0:pt[o.align])??mt(t);f!==void 0&&i.push(`text-align:${f}`);const c=o.valign===void 0?void 0:ut[o.valign];c!==void 0&&i.push(`vertical-align:${c}`),o.wrap===!0&&i.push("white-space:pre-wrap","overflow-wrap:anywhere"),o.indent!==void 0&&i.push(`padding-left:${String(3+o.indent*9)}px`);for(const s of["left","right","top","bottom"]){const n=o.border?.[s];n&&n.style!=="none"&&i.push(`border-${s}:${gt[n.style]??"1px solid"} ${n.color??"#000"}`)}return i.join(";")}class L{names=new Map;of(t){if(t==="")return"";let e=this.names.get(t);return e||(e=`s${String(this.names.size)}`,this.names.set(t,e)),e}css(){return[...this.names].map(([t,e])=>`.${e}{${t}}`).join(`
3
+ `)}}class W{calc;sheet;rules;read;drawnFiles;bands=new Map;svgs=new Map;constructor(t,e,i){this.calc=t,this.sheet=e,this.read=i,this.rules=e.conditions.length>0?new rt(e,t):void 0}files(){if(this.drawnFiles)return this.drawnFiles;const t=new Map,e=new Map,i=this.read;for(const{row:l,col:r,paths:d,column:f}of i?K(this.sheet,this.calc):[]){const c=X(f),s=d.map(n=>{const a=Y(n)?i?.(n):void 0,h=a&&Z(a);return!a||!h?v(n):(e.set(l,Math.max(e.get(l)??0,c)),`<img src="data:image/${h.type};base64,${ft(a)}" alt="${v(n)}" style="height:${String(c)}px">`)});t.set(I(l,r),s.join(" "))}return this.drawnFiles={cells:t,rows:e},this.drawnFiles}height(t){return this.sheet.spec.rows?.[String(t+1)]?.height??this.files().rows.get(t)??D}band(t,e){if(e===t.at.row)return;let i=this.bands.get(t);if(!i){i=new Map;let l=0;for(let r=t.at.row+1;r<=t.area.bottom;r++)H(this.calc,this.sheet,r)||i.set(r,l++);this.bands.set(t,i)}return i.get(e)??0}cell(t,e,i,l,r){const{sheet:d}=this,f=this.calc.value(d,t,e),c=this.rules?.at(t,e),s=d.lookAt(t,e),n=d.tableAt(t,e),a=n&&dt(n),h=n&&a?at(a,n,t,e,this.band(n,t)):void 0,g={...h,...s,...c?.look,...c?.scale===void 0?{}:{fill:c.scale}};(h?.border||s.border)&&(g.border={...h?.border,...s.border,...c?.look?.border});const w=g.format;let m=bt(g,f,w);if(c?.bar){const C=`${String(Math.round(c.bar.share*100))}%`;m=[m,`background:linear-gradient(90deg,${c.bar.color} ${C},transparent ${C})`].filter(Boolean).join(";")}const p=this.files().cells.get(I(t,e)),y=c?.icon?wt(c.icon):"",x=p??(c?.bare===!0?"":v(Q(f,w))),b=typeof f=="string"&&g.wrap!==!0&&l&&!i,S=typeof f=="number"&&!p&&y===""&&x!=="",F=S&&(w===void 0||w==="General"),j=[r.of(m),b?"over":"",S?"n":""].filter(Boolean).join(" ");return`<td${[j===""?"":` class="${j}"`,F?` data-g="${v(J(f).slice(1).join(" "))}"`:"",i&&i.rows>1?` rowspan="${String(i.rows)}"`:"",i&&i.cols>1?` colspan="${String(i.cols)}"`:""].join("")}>${y}${x}</td>`}spans(t,e){const i=new Map,l=new Set;for(const r of this.sheet.merges){const d=t.filter(n=>n>=r.top&&n<=r.bottom),f=e.filter(n=>n>=r.left&&n<=r.right),[c]=d,[s]=f;if(!(c===void 0||s===void 0)){for(const n of d)for(const a of f)l.add(`${String(n)}:${String(a)}`);l.delete(`${String(c)}:${String(s)}`),i.set(`${String(c)}:${String(s)}`,{rows:d.length,cols:f.length})}}return{spans:i,covered:l}}table(t,e,i,l){const{sheet:r}=this,{spans:d,covered:f}=this.spans(t,e),c=e.map(h=>M(r,h)),s=l.headings?B:0,n=c.reduce((h,g)=>h+g,0)+s,a=[`<table class="${l.className??""}" style="width:${String(n)}px"><colgroup>`,l.headings?`<col style="width:${String(s)}px">`:"",...c.map(h=>`<col style="width:${String(h)}px">`),"</colgroup>"];l.headings&&a.push(`<thead><tr><th></th>${e.map(h=>`<th>${_(h)}</th>`).join("")}</tr></thead>`),a.push("<tbody>");for(const h of t)a.push(`<tr style="height:${String(this.height(h))}px">`),l.headings&&a.push(`<th>${String(h+1)}</th>`),e.forEach((g,w)=>{const m=`${String(h)}:${String(g)}`;if(f.has(m))return;const p=e[w+1],y=p!==void 0&&r.at(h,p)===void 0&&!f.has(`${String(h)}:${String(p)}`);a.push(this.cell(h,g,d.get(m),y,i))}),a.push("</tr>");return a.push("</tbody></table>"),{html:a.join(""),width:n}}svg(t){let e=this.svgs.get(t);if(e===void 0){const{width:i,height:l}=q(t.spec);e=V(U(this.calc,this.sheet,t),i,l,{font:"var(--font)"}),this.svgs.set(t,e)}return e}charts(t,e,i){const{sheet:l}=this;if(l.charts.length===0||t.length===0||e.length===0)return"";const r=(s,n)=>{const a=new Map;let h=0;for(const g of s)a.set(g,h),h+=n(g);return{at:a,sum:h}},d=r(t,s=>this.height(s)),f=r(e,s=>M(l,s)),c=(s,n,a,h)=>{const g=s[0]??0;if(a<g){let m=0;for(let p=a;p<g;p++)m-=h(p);return m}const w=s.find(m=>m>=a);return w===void 0?1/0:n.get(w)??0};return l.charts.map(s=>{const n=k(s.spec,h=>c(t,d.at,h,g=>H(this.calc,l,g)?0:st(l,g)),h=>c(e,f.at,h,g=>N(l,g)?0:M(l,g)));return n.left<f.sum&&n.left+n.width>0&&n.top<d.sum&&n.top+n.height>0?`<div class="chart" style="left:${String(i.left+n.left)}px;top:${String(i.top+n.top)}px">${this.svg(s)}</div>`:""}).join("")}}const B=44,yt=`
4
+ (() => {
5
+ const fit = () => {
6
+ const cells = Array.from(document.querySelectorAll("td.n"));
7
+ const over = cells.filter((td) => td.scrollWidth > td.clientWidth);
8
+ for (const td of over) {
9
+ const room = td.clientWidth;
10
+ const fits = (t) => { td.textContent = t; return td.scrollWidth <= room; };
11
+ const g = td.dataset.g;
12
+ // General's shorter forms, from the engine (generalForms), widest first.
13
+ if (g !== undefined && g !== "" && g.split(" ").some(fits)) continue;
14
+ td.textContent = "#";
15
+ const style = getComputedStyle(td);
16
+ const inner = room - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
17
+ const range = document.createRange();
18
+ range.selectNodeContents(td);
19
+ const one = range.getBoundingClientRect().width || 1;
20
+ td.textContent = "#".repeat(Math.max(1, Math.floor(inner / one)));
21
+ }
22
+ return true;
23
+ };
24
+ window.allyhubReady = new Promise((r) => addEventListener("load", r, { once: true })).then(() => document.fonts.ready).then(fit);
25
+ })();
26
+ `;function G(o,t,e){return`<!doctype html><html><head><meta charset="utf-8"><style>
27
+ ${o.css??""}
28
+ :root{--font:${o.font===void 0?"":`"${o.font}",`}Carlito,Calibri,"Noto Sans SC",Arial,sans-serif}
5
29
  *{box-sizing:border-box}
6
30
  html,body{margin:0;background:#fff;color:#000}
7
31
  body{font:11pt/1.2 var(--font)}
8
- .sheet{break-after:page}
9
- .sheet:last-child{break-after:auto}
10
- h2{font:bold 12pt var(--font);margin:0 0 8px;${e?"":"display:none"}}
11
32
  table{table-layout:fixed;border-collapse:collapse}
12
- td,th{height:${String(DEFAULT_ROW_HEIGHT)}px;padding:0 3px;overflow:hidden;white-space:pre;vertical-align:bottom}
33
+ td,th{height:${String(D)}px;padding:0 3px;overflow:hidden;white-space:pre;vertical-align:bottom}
13
34
  td.over{overflow:visible}
14
- .book{position:relative;width:max-content;overflow:hidden}
15
35
  .chart{position:absolute;line-height:0}
16
36
  .grid td{border:1px solid #e3e3e3}
17
37
  .edged th{border:1px solid #e3e3e3;background:#f5f5f5;color:#555;font-weight:normal;text-align:center;vertical-align:middle;font-size:9pt}
18
- ${n.join(`
19
- `)}
20
- </style></head><body>${this.pages.join("")}</body></html>`}}export function sheetHtml(i,t={}){const n=t.sheets??i.wb.sheets.filter(o=>o.spec.hidden!==!0),e=new rt(i,{...t,sheets:n});return n.forEach((o,r)=>{e.sheet(o,r)}),{html:e.page(),width:e.widest,cut:e.cut}}
38
+ ${t}
39
+ </style><script>${yt}<\/script></head><body>${e}</body></html>`}export function sheetHtml(o,t={}){const e=t.sheets??o.wb.sheets.filter(s=>s.spec.hidden!==!0),i=new L,l=[];let r=0;const d=e.length>1&&t.area===void 0,f=e.map(s=>{const n=new W(o,s,t.file),a=t.area??ot(s)??{top:0,left:0,bottom:0,right:0},h=[];for(let b=a.top;b<=a.bottom;b++)H(o,s,b)||h.push(b);const g=[];for(let b=a.left;b<=a.right;b++)N(s,b)||g.push(b);const w=h.slice(0,t.rows??h.length),m=g.slice(0,t.columns??g.length);if(w.length<h.length||m.length<g.length){const b=w[w.length-1]??a.top,S=m[m.length-1]??a.left;l.push(`${s.name}: drew ${T({row:a.top,col:a.left})}:${T({row:b,col:S})} of ${String(h.length)} rows and ${String(g.length)} columns`)}const p=t.headings===!0,y=n.table(w,m,i,{headings:p,className:p?s.spec.gridlines===!1?"edged":"edged grid":""});r=Math.max(r,y.width);const x=n.charts(w,m,{left:p?B:0,top:p?D:0});return`<section class="sheet">${d?`<h2>${v(s.name)}</h2>`:""}<div class="book">${y.html}${x}</div></section>`});return{html:G(t,`h2{font:bold 12pt var(--font);margin:0 0 8px}
40
+ .sheet+.sheet{margin-top:24px}
41
+ .book{position:relative;width:max-content;overflow:hidden}
42
+ ${i.css()}`,f.join("")),width:r,cut:l}}const z=o=>String(o).padStart(2,"0");export function headerFooterHtml(o,t){let e="",i=0;const l=d=>{e+=`<span style="${d}">`,i++},r={B:"font-weight:bold",I:"font-style:italic",U:"text-decoration:underline",E:"text-decoration:underline double",S:"text-decoration:line-through",X:"vertical-align:super;font-size:smaller",Y:"vertical-align:sub;font-size:smaller"};for(let d=0;d<o.length;d++){const f=o[d]??"";if(f!=="&"){e+=v(f);continue}const c=o[d+1]??"",s=c.toUpperCase();if(d++,c==="&")e+="&amp;";else if(s==="P"||s==="N"){const n=/^[+-]\d+/u.exec(o.slice(d+1)),a=s==="P"?t.page:t.pages;e+=String(a+(n?Number(n[0]):0)),n&&(d+=n[0].length)}else if(s==="D")e+=`${String(t.date.getFullYear())}-${z(t.date.getMonth()+1)}-${z(t.date.getDate())}`;else if(s==="T")e+=`${z(t.date.getHours())}:${z(t.date.getMinutes())}`;else if(s==="F"||s==="Z")e+=v(t.file);else if(s==="A")e+=v(t.sheet);else{if(s==="G")continue;if(r[s]!==void 0)l(r[s]);else if(c==='"'){const n=o.indexOf('"',d+1),[a="",h=""]=o.slice(d+1,n<0?o.length:n).split(",");d=n<0?o.length:n;const g=[a==="-"||a===""?"":`font-family:"${a.replace(/["\\]/gu,"")}",var(--font)`,/bold/iu.test(h)?"font-weight:bold":"",/italic/iu.test(h)?"font-style:italic":""].filter(Boolean).join(";");g!==""&&l(g)}else if(/\d/u.test(c)){const n=/^\d+/u.exec(o.slice(d))?.[0]??c;d+=n.length-1,l(`font-size:${n}pt`)}else if(s==="K"){const n=o.slice(d+1,d+7);d+=6,/^[0-9A-Fa-f]{6}$/u.test(n)&&l(`color:#${n}`)}}}return e+"</span>".repeat(i)}const u=o=>`${String(Math.round(o*1e3)/1e3)}px`;export class SheetPrint{job;calc;drawers=new Map;file;constructor(t,e={}){this.calc=t,this.file=e.file,this.job=it(t,{...e.sheets?{sheets:e.sheets}:{},height:(i,l)=>this.drawer(i).height(l)})}drawer(t){let e=this.drawers.get(t);return e||(e=new W(this.calc,t,this.file),this.drawers.set(t,e)),e}html(t,e,i){const l=new L,r=new Map,d=[];for(const c of this.job.pages.slice(t,e)){const{of:s}=c,n=`${u(s.paper.width)} ${u(s.paper.height)}`;let a=r.get(n);a===void 0&&(a=`paper${String(r.size)}`,r.set(n,a)),d.push(this.page(c,l,a,i))}const f=[...r].map(([c,s])=>`@page ${s}{size:${c};margin:0}`).join(`
43
+ `);return G(i,`${f}
44
+ .page{position:relative;overflow:hidden;break-after:page}
45
+ .page:last-child{break-after:auto}
46
+ .body,.charts{position:absolute;overflow:hidden}
47
+ .scaled{position:absolute;left:0;top:0;transform-origin:0 0}
48
+ .hf{position:absolute;display:flex;white-space:pre;font-size:11pt;line-height:1.2}
49
+ .hf>div{flex:1 1 0;overflow:visible}
50
+ .hf>.c{text-align:center}
51
+ .hf>.r{text-align:right}
52
+ ${l.css()}`,d.join(""))}page(t,e,i,l){const{of:r}=t,d=this.drawer(r.sheet),{margins:f,scale:c}=r,s=nt(t),n=et(t),a=r.rows.slice(t.down.from,t.down.to),h=r.cols.slice(t.across.from,t.across.to),g=d.table([...s,...a],[...n,...h],e,{headings:!1}),w=s.reduce(($,A)=>$+d.height(A),0),m=n.reduce(($,A)=>$+M(r.sheet,A),0),p=r.rowAt[t.down.from]??0,y=r.colAt[t.across.from]??0,x=(r.rowAt[t.down.to]??0)-p,b=(r.colAt[t.across.to]??0)-y,S=r.charts.filter($=>$.left<y+b&&$.left+$.width>y&&$.top<p+x&&$.top+$.height>p).map($=>`<div class="chart" style="left:${u($.left-y)};top:${u($.top-p)}">${d.svg($.chart)}</div>`).join(""),F=S===""?"":`<div class="charts" style="left:${u(m)};top:${u(w)};width:${u(b)};height:${u(x)}">${S}</div>`,j=r.paper.width-f.left-f.right,R=r.paper.height-f.top-f.bottom,C={page:t.number,pages:this.job.pages.length,sheet:r.sheet.name,file:l.name,date:l.date},E=($,A)=>$?`<div class="hf" style="left:${u(f.left)};right:${u(f.right)};${A}"><div>${headerFooterHtml($.left??"",C)}</div><div class="c">${headerFooterHtml($.center??"",C)}</div><div class="r">${headerFooterHtml($.right??"",C)}</div></div>`:"";return`<section class="page" style="page:${i};width:${u(r.paper.width)};height:${u(r.paper.height)}">`+E(r.header,`top:${u(f.header)}`)+`<div class="body" style="left:${u(f.left)};top:${u(f.top)};width:${u(j)};height:${u(R)}"><div class="scaled" style="width:${u(j/c)};height:${u(R/c)}${c===1?"":`;transform:scale(${String(c)})`}">`+g.html+F+"</div></div>"+E(r.footer,`bottom:${u(f.footer)}`)+"</section>"}}
@@ -3,6 +3,8 @@ export { DEFAULT_DIALECT, csvField, csvRecord, csvRows, fromTsv, readCsv, toTsv,
3
3
  export { patchCsv } from "./patch.js";
4
4
  export * from "./values.js";
5
5
  export * from "./workbook.js";
6
+ export * from "./calc/remote.js";
7
+ export * from "./calc/server.js";
6
8
  export { dataFilesOf, readSheetFile, type SheetProblem } from "./file.js";
7
9
  export { GENERATED, ordinarySheet, typedNumbers, withGenerated, type GeneratedSheets, type MergedFile, } from "./generated.js";
8
10
  export { applyScenario, cellOfName, scenarioNames, scenariosByCell, type ScenarioCell, type SheetScenarios, } from "./scenario.js";
@@ -17,9 +19,11 @@ export { analyse, type Analysis } from "./calc/analyse.js";
17
19
  export { FUNCTIONS } from "./calc/functions/index.js";
18
20
  export { Reference } from "./calc/types.js";
19
21
  export { checkWorkbook, placeName, type CheckedWorkbook } from "./check.js";
20
- export { csvOf, jsonOf, markdownOf, tableRows } from "./export.js";
21
- export { dataValue, isDateCode, shownColor, shownValue } from "./format.js";
22
- export { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, sheetHtml, type SheetHtml, type SheetHtmlOptions, } from "./html.js";
22
+ export { csvOf, csvText, dataValue, excelNumber, jsonOf, markdownOf, tableRows, type CsvOptions, type ValueMode, type ValueOptions, } from "./export.js";
23
+ export { generalForms, generalText, isDateCode, shownColor, shownValue, } from "./format.js";
24
+ export { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, headerFooterHtml, sheetHtml, SheetPrint, type PageFields, type PrintHtmlOptions, type SheetHtml, type SheetHtmlOptions, } from "./html.js";
25
+ export { PAPERS, PRINT_DEFAULTS, paginate, type PaginateOptions, type PrintJob, type PrintedPage, type SheetPages, } from "./paginate.js";
26
+ export { DEFAULT_TABLE_STYLE, tableStyleLook, tableStyleOf, type TablePart, type TableStyle, } from "./table-style.js";
23
27
  export { PROFILE_TOP, profileTable, type ColumnProfile } from "./profile.js";
24
28
  export { importRows, type ImportedSheet } from "./import.js";
25
29
  export { patchYaml, writeYaml } from "./write.js";
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- export*from"./address.js";export{DEFAULT_DIALECT,csvField,csvRecord,csvRows,fromTsv,readCsv,toTsv,writeCsv}from"./csv.js";export{patchCsv}from"./patch.js";export*from"./values.js";export*from"./workbook.js";export{dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,jsonOf,markdownOf,tableRows}from"./export.js";export{dataValue,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,sheetHtml}from"./html.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./arrange.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
2
+ export*from"./address.js";export{DEFAULT_DIALECT,csvField,csvRecord,csvRows,fromTsv,readCsv,toTsv,writeCsv}from"./csv.js";export{patchCsv}from"./patch.js";export*from"./values.js";export*from"./workbook.js";export*from"./calc/remote.js";export*from"./calc/server.js";export{dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,csvText,dataValue,excelNumber,jsonOf,markdownOf,tableRows}from"./export.js";export{generalForms,generalText,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,headerFooterHtml,sheetHtml,SheetPrint}from"./html.js";export{PAPERS,PRINT_DEFAULTS,paginate}from"./paginate.js";export{DEFAULT_TABLE_STYLE,tableStyleLook,tableStyleOf}from"./table-style.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./arrange.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{cellName as g}from"./address.js";import"./calc/types.js";import{analyse as y}from"./calc/analyse.js";import{dataValue as S,shownValue as x}from"./format.js";import{relativeKey as _}from"./formula/move.js";import{exceptionsOf as C}from"./edit.js";import{invalidCells as F}from"./validate.js";import{CellError as E}from"./values.js";import{FormulaCell as v}from"./workbook.js";export const SHEET_FACT_KINDS=["sheet-error","sheet-number","sheet-unlike","sheet-exception","sheet-unused","sheet-invalid","sheet-typed","sheet-ordinary"],INSPECT_DEFAULTS={plain:[0,1,-1],around:1};function w(o){const s=new Map;for(const t of o.formulas){const n=s.get(t.shared);n?(n.count+=1,(t.row<n.first.row||t.row===n.first.row&&t.col<n.first.col)&&(n.first=t)):s.set(t.shared,{shared:t.shared,first:t,count:1})}return[...s.values()].sort((t,n)=>t.first.row-n.first.row||t.first.col-n.first.col)}function k(o,s,t){switch(o.kind){case"number":t.push({value:o.value,in:s});return;case"unary":o.op==="-"&&o.arg.kind==="number"?t.push({value:-o.arg.value,in:s}):k(o.arg,o.op,t);return;case"postfix":k(o.arg,o.op,t);return;case"paren":k(o.arg,s,t);return;case"binary":k(o.left,o.op,t),k(o.right,o.op,t);return;case"array":for(const n of o.rows)for(const l of n)k(l,"{}",t);return;case"call":for(const n of o.args)k(n,o.name,t);return;case"invoke":k(o.callee,s,t);for(const n of o.args)k(n,"LAMBDA",t);return;default:return}}function N(o,s){const t={error:!1};for(const n of o.precedents(s))if(o.each(n,l=>{l instanceof E&&(t.error=!0)}),t.error)return!1;return!0}const b=new WeakMap;function A(o){const s=b.get(o);if(s!==void 0)return s;const t=o.node?_(o.node,o.row,o.col):o.text;return b.set(o,t),t}const I=(o,s)=>o instanceof v?o.text:x(o,s);function M(o,s,t){const n=[],l=(r,e)=>{if(r<0||e<0)return;const u=o.at(r,e);return u instanceof v?A(u.shared):void 0},c=(r,e,u,i)=>{const a=u==="column"?1:0,f=u==="row"?1:0,h=o.at(r,e);if(h===void 0||h instanceof v&&A(h.shared)===i)return;for(let d=1;d<=s;d++)if(l(r-a*d,e-f*d)!==i||l(r+a*d,e+f*d)!==i)return;if(t.has(r*16384+e))return;let m=s*2;for(let d=s+1;l(r-a*d,e-f*d)===i;d++)m+=1;for(let d=s+1;l(r+a*d,e+f*d)===i;d++)m+=1;const p=o.at(r-a,e-f);n.push({sheet:o.name,cell:g({row:r,col:e}),holds:I(h,o.lookAt(r,e).format),neighbour:p instanceof v?p.text:"",along:u,run:m})};for(const r of o.formulas){const e=A(r.shared);c(r.row+1,r.col,"column",e),c(r.row,r.col+1,"row",e)}return n.sort((r,e)=>T(r.cell,e.cell))}const T=(o,s)=>o.length-s.length||o.localeCompare(s,"en",{numeric:!0});function R(o,s){const t=[],n=(c,r)=>{c&&t.push(...o.readsOfFormula(c,r))};for(const c of s.sheets){for(const r of c.conditions)for(const e of r.formulas)n(e,c);for(const r of c.validations)for(const e of r.formulas)n(e,c);for(const r of c.charts){n(r.title,c),n(r.categories,c);for(const e of r.series)n(e.values,c),n(e.x,c),n(e.name,c)}}const l=s.sheets[0];if(l){for(const c of s.checks)n(c.formula,l);for(const c of s.names.values())n(c.formula,l)}return t}function D(o){const s=new Set,t=n=>{if(n)for(const l of y(o,n).names)s.add(l)};for(const n of o.sheets){for(const{shared:l}of w(n))t(l);for(const l of n.conditions)l.formulas.forEach(t);for(const l of n.validations)l.formulas.forEach(t);for(const l of n.charts){t(l.title),t(l.categories);for(const c of l.series)t(c.values),t(c.x),t(c.name)}}for(const n of o.checks)t(n.formula);return s}function K(o,s,t){const n=[],l=D(s);for(const e of s.names.values())l.has(e.name.toLowerCase())||n.push({what:"name",name:e.name,value:e.formula?.text??x(e.value??null)});const c=R(o,s),r=(e,u,i)=>c.some(a=>a.sheet===e&&u>=a.top&&u<=a.bottom&&i>=a.left&&i<=a.right)||o.readers(e,u,i).length>0;for(const e of s.sheets){for(let u=0;u<e.columnsUsed;u++){const[i,a]=e.span(u,0,Number.MAX_SAFE_INTEGER);for(let f=i;f<=a;f++){const h=e.at(f,u);typeof h=="number"&&(e.tableAt(f,u)||e.blockAt(f,u)||r(e,f,u)||n.push({what:"cell",sheet:e.name,name:g({row:f,col:u}),value:x(h,e.lookAt(f,u).format)}))}}if(t)for(const u of e.tables)for(const i of u.columns){const a=u.at.col+i.index,{top:f,bottom:h}=u.data;let m=!1;for(let p=f;p<=h&&!m;p++)m=r(e,p,a);m||n.push({what:"column",sheet:e.name,name:`${u.name}[${i.name}]`})}}return n}export function inspectWorkbook(o,s={}){const{wb:t}=o,n=new Set(s.plain??INSPECT_DEFAULTS.plain),l=Math.max(1,s.around??INSPECT_DEFAULTS.around),c=s.all===!0,r=[];for(const e of t.sheets){const u=[...e.formulas].sort((a,f)=>a.row-f.row||a.col-f.col);for(const a of u){const{value:f}=a;f instanceof E&&r.push({kind:"sheet-error",data:{sheet:e.name,cell:g(a),code:f.code,formula:a.text,origin:N(o,a)}})}for(let a=0;a<e.columnsUsed;a++){const[f,h]=e.span(a,0,Number.MAX_SAFE_INTEGER);for(let m=f;m<=h;m++){const p=e.at(m,a);p instanceof E&&r.push({kind:"sheet-error",data:{sheet:e.name,cell:g({row:m,col:a}),code:p.code,origin:!0}})}}for(const{shared:a,first:f,count:h}of w(e)){if(!a.node)continue;const m=[];k(a.node,"=",m);const p=c?m:m.filter(d=>!n.has(d.value));p.length>0&&r.push({kind:"sheet-number",data:{sheet:e.name,cell:g(f),cells:h,formula:f.text,numbers:p}})}const i=new Set;for(const a of e.tables)for(const f of C(a))i.add(f.row*16384+f.col),r.push({kind:"sheet-exception",data:{sheet:e.name,table:a.name,column:f.column,cell:g(f),text:f.text}});for(const a of M(e,l,i))r.push({kind:"sheet-unlike",data:a})}for(const e of K(o,t,c))r.push({kind:"sheet-unused",data:e});for(const e of F(t,o))r.push({kind:"sheet-invalid",data:{sheet:e.sheet,cell:g(e),value:S(e.value,void 0),rule:e.type,range:e.range}});for(const e of t.generated?.typed??[])t.sheet(e.sheet)?.generated===!0&&r.push({kind:"sheet-typed",data:e});for(const e of t.ordinary)r.push({kind:"sheet-ordinary",data:{sheet:e}});return r}
2
+ import{cellName as g}from"./address.js";import"./calc/types.js";import{analyse as y}from"./calc/analyse.js";import{dataValue as S}from"./export.js";import{shownValue as x}from"./format.js";import{relativeKey as _}from"./formula/move.js";import{exceptionsOf as C}from"./edit.js";import{invalidCells as F}from"./validate.js";import{CellError as E}from"./values.js";import{FormulaCell as v}from"./workbook.js";export const SHEET_FACT_KINDS=["sheet-error","sheet-number","sheet-unlike","sheet-exception","sheet-unused","sheet-invalid","sheet-typed","sheet-ordinary"],INSPECT_DEFAULTS={plain:[0,1,-1],around:1};function w(o){const s=new Map;for(const t of o.formulas){const n=s.get(t.shared);n?(n.count+=1,(t.row<n.first.row||t.row===n.first.row&&t.col<n.first.col)&&(n.first=t)):s.set(t.shared,{shared:t.shared,first:t,count:1})}return[...s.values()].sort((t,n)=>t.first.row-n.first.row||t.first.col-n.first.col)}function k(o,s,t){switch(o.kind){case"number":t.push({value:o.value,in:s});return;case"unary":o.op==="-"&&o.arg.kind==="number"?t.push({value:-o.arg.value,in:s}):k(o.arg,o.op,t);return;case"postfix":k(o.arg,o.op,t);return;case"paren":k(o.arg,s,t);return;case"binary":k(o.left,o.op,t),k(o.right,o.op,t);return;case"array":for(const n of o.rows)for(const l of n)k(l,"{}",t);return;case"call":for(const n of o.args)k(n,o.name,t);return;case"invoke":k(o.callee,s,t);for(const n of o.args)k(n,"LAMBDA",t);return;default:return}}function N(o,s){const t={error:!1};for(const n of o.precedents(s))if(o.each(n,l=>{l instanceof E&&(t.error=!0)}),t.error)return!1;return!0}const b=new WeakMap;function A(o){const s=b.get(o);if(s!==void 0)return s;const t=o.node?_(o.node,o.row,o.col):o.text;return b.set(o,t),t}const I=(o,s)=>o instanceof v?o.text:x(o,s);function M(o,s,t){const n=[],l=(r,e)=>{if(r<0||e<0)return;const u=o.at(r,e);return u instanceof v?A(u.shared):void 0},c=(r,e,u,i)=>{const f=u==="column"?1:0,a=u==="row"?1:0,h=o.at(r,e);if(h===void 0||h instanceof v&&A(h.shared)===i)return;for(let d=1;d<=s;d++)if(l(r-f*d,e-a*d)!==i||l(r+f*d,e+a*d)!==i)return;if(t.has(r*16384+e))return;let m=s*2;for(let d=s+1;l(r-f*d,e-a*d)===i;d++)m+=1;for(let d=s+1;l(r+f*d,e+a*d)===i;d++)m+=1;const p=o.at(r-f,e-a);n.push({sheet:o.name,cell:g({row:r,col:e}),holds:I(h,o.lookAt(r,e).format),neighbour:p instanceof v?p.text:"",along:u,run:m})};for(const r of o.formulas){const e=A(r.shared);c(r.row+1,r.col,"column",e),c(r.row,r.col+1,"row",e)}return n.sort((r,e)=>T(r.cell,e.cell))}const T=(o,s)=>o.length-s.length||o.localeCompare(s,"en",{numeric:!0});function R(o,s){const t=[],n=(c,r)=>{c&&t.push(...o.readsOfFormula(c,r))};for(const c of s.sheets){for(const r of c.conditions)for(const e of r.formulas)n(e,c);for(const r of c.validations)for(const e of r.formulas)n(e,c);for(const r of c.charts){n(r.title,c),n(r.categories,c);for(const e of r.series)n(e.values,c),n(e.x,c),n(e.name,c)}}const l=s.sheets[0];if(l){for(const c of s.checks)n(c.formula,l);for(const c of s.names.values())n(c.formula,l)}return t}function D(o){const s=new Set,t=n=>{if(n)for(const l of y(o,n).names)s.add(l)};for(const n of o.sheets){for(const{shared:l}of w(n))t(l);for(const l of n.conditions)l.formulas.forEach(t);for(const l of n.validations)l.formulas.forEach(t);for(const l of n.charts){t(l.title),t(l.categories);for(const c of l.series)t(c.values),t(c.x),t(c.name)}}for(const n of o.checks)t(n.formula);return s}function K(o,s,t){const n=[],l=D(s);for(const e of s.names.values())l.has(e.name.toLowerCase())||n.push({what:"name",name:e.name,value:e.formula?.text??x(e.value??null)});const c=R(o,s),r=(e,u,i)=>c.some(f=>f.sheet===e&&u>=f.top&&u<=f.bottom&&i>=f.left&&i<=f.right)||o.readers(e,u,i).length>0;for(const e of s.sheets){for(let u=0;u<e.columnsUsed;u++){const[i,f]=e.span(u,0,Number.MAX_SAFE_INTEGER);for(let a=i;a<=f;a++){const h=e.at(a,u);typeof h=="number"&&(e.tableAt(a,u)||e.blockAt(a,u)||r(e,a,u)||n.push({what:"cell",sheet:e.name,name:g({row:a,col:u}),value:x(h,e.lookAt(a,u).format)}))}}if(t)for(const u of e.tables)for(const i of u.columns){const f=u.at.col+i.index,{top:a,bottom:h}=u.data;let m=!1;for(let p=a;p<=h&&!m;p++)m=r(e,p,f);m||n.push({what:"column",sheet:e.name,name:`${u.name}[${i.name}]`})}}return n}export function inspectWorkbook(o,s={}){const{wb:t}=o,n=new Set(s.plain??INSPECT_DEFAULTS.plain),l=Math.max(1,s.around??INSPECT_DEFAULTS.around),c=s.all===!0,r=[];for(const e of t.sheets){const u=[...e.formulas].sort((f,a)=>f.row-a.row||f.col-a.col);for(const f of u){const{value:a}=f;a instanceof E&&r.push({kind:"sheet-error",data:{sheet:e.name,cell:g(f),code:a.code,formula:f.text,origin:N(o,f)}})}for(let f=0;f<e.columnsUsed;f++){const[a,h]=e.span(f,0,Number.MAX_SAFE_INTEGER);for(let m=a;m<=h;m++){const p=e.at(m,f);p instanceof E&&r.push({kind:"sheet-error",data:{sheet:e.name,cell:g({row:m,col:f}),code:p.code,origin:!0}})}}for(const{shared:f,first:a,count:h}of w(e)){if(!f.node)continue;const m=[];k(f.node,"=",m);const p=c?m:m.filter(d=>!n.has(d.value));p.length>0&&r.push({kind:"sheet-number",data:{sheet:e.name,cell:g(a),cells:h,formula:a.text,numbers:p}})}const i=new Set;for(const f of e.tables)for(const a of C(f))i.add(a.row*16384+a.col),r.push({kind:"sheet-exception",data:{sheet:e.name,table:f.name,column:a.column,cell:g(a),text:a.text}});for(const f of M(e,l,i))r.push({kind:"sheet-unlike",data:f})}for(const e of K(o,t,c))r.push({kind:"sheet-unused",data:e});for(const e of F(t,o))r.push({kind:"sheet-invalid",data:{sheet:e.sheet,cell:g(e),value:S(e.value,void 0),rule:e.type,range:e.range}});for(const e of t.generated?.typed??[])t.sheet(e.sheet)?.generated===!0&&r.push({kind:"sheet-typed",data:e});for(const e of t.ordinary)r.push({kind:"sheet-ordinary",data:{sheet:e}});return r}
@@ -0,0 +1,98 @@
1
+ import type { SheetHeaderFooter, SheetPrint } from "@allyhub-next/formats";
2
+ import { type Area } from "./address.js";
3
+ import type { Calc } from "./calc/engine.js";
4
+ import type { Chart, Worksheet } from "./workbook.js";
5
+ /** A column and a row nothing sizes, px: Excel's 8.43 characters and 15 points. */
6
+ export declare const DEFAULT_COLUMN_WIDTH = 64;
7
+ export declare const DEFAULT_ROW_HEIGHT = 20;
8
+ /** Paper, portrait, px. */
9
+ export declare const PAPERS: Readonly<Record<NonNullable<SheetPrint["paper"]>, {
10
+ width: number;
11
+ height: number;
12
+ }>>;
13
+ /** How a sheet prints when `print` does not say: A4, Excel's Normal margins (inches), 100%. */
14
+ export declare const PRINT_DEFAULTS: {
15
+ readonly paper: "a4";
16
+ readonly orientation: "portrait";
17
+ readonly margins: {
18
+ readonly left: 0.7;
19
+ readonly right: 0.7;
20
+ readonly top: 0.75;
21
+ readonly bottom: 0.75;
22
+ readonly header: 0.3;
23
+ readonly footer: 0.3;
24
+ };
25
+ readonly scale: 100;
26
+ };
27
+ /** A stretch of a sheet's rows or columns that show, by index: from, and to before. */
28
+ export interface Span {
29
+ from: number;
30
+ to: number;
31
+ }
32
+ /** One sheet as it prints. */
33
+ export interface SheetPages {
34
+ sheet: Worksheet;
35
+ /** The rows and columns that show in its print area, in order, and their sizes, px. */
36
+ rows: readonly number[];
37
+ heights: readonly number[];
38
+ cols: readonly number[];
39
+ widths: readonly number[];
40
+ /** Where each of them starts, px from the area's first; one more for where the last ends. */
41
+ rowAt: readonly number[];
42
+ colAt: readonly number[];
43
+ /** Its charts, px from the area's first row and column that show. */
44
+ charts: readonly PlacedChart[];
45
+ /** Rows and columns repeated on each page that comes after them. */
46
+ titleRows: readonly number[];
47
+ titleCols: readonly number[];
48
+ /** Pages down and across. */
49
+ down: readonly Span[];
50
+ across: readonly Span[];
51
+ /** Paper, oriented, and its margins, px. */
52
+ paper: {
53
+ width: number;
54
+ height: number;
55
+ };
56
+ margins: Readonly<Record<keyof typeof PRINT_DEFAULTS.margins, number>>;
57
+ /** 1 is 100%. */
58
+ scale: number;
59
+ header?: SheetHeaderFooter;
60
+ footer?: SheetHeaderFooter;
61
+ }
62
+ /** A chart where it lies, px from a print area's first row and column that show. */
63
+ export interface PlacedChart {
64
+ chart: Chart;
65
+ left: number;
66
+ top: number;
67
+ width: number;
68
+ height: number;
69
+ }
70
+ /** A page: which sheet, which of its rows and columns, its number from 1. */
71
+ export interface PrintedPage {
72
+ of: SheetPages;
73
+ down: Span;
74
+ across: Span;
75
+ number: number;
76
+ }
77
+ export interface PrintJob {
78
+ sheets: SheetPages[];
79
+ pages: PrintedPage[];
80
+ }
81
+ export interface PaginateOptions {
82
+ /** The sheets printed; default every one that is not hidden. */
83
+ sheets?: readonly Worksheet[];
84
+ /** A row's height as drawn, px; default its own (pictures in a cell make a row taller). */
85
+ height?: (sheet: Worksheet, row: number) => number;
86
+ }
87
+ export declare function columnWidth(sheet: Worksheet, col: number): number;
88
+ export declare const rowHeight: (sheet: Worksheet, row: number) => number;
89
+ export declare const rowHidden: (calc: Calc, sheet: Worksheet, row: number) => boolean;
90
+ export declare const columnHidden: (sheet: Worksheet, col: number) => boolean;
91
+ /** What a sheet uses, with the cells its charts reach. */
92
+ export declare function usedWithCharts(sheet: Worksheet): Area | undefined;
93
+ /** A workbook's sheets on paper: every page, numbered through the workbook. */
94
+ export declare function paginate(calc: Calc, o?: PaginateOptions): PrintJob;
95
+ /** The rows a page repeats over its own: the title rows before its first. */
96
+ export declare const pageTitleRows: (page: PrintedPage) => number[];
97
+ export declare const pageTitleCols: (page: PrintedPage) => number[];
98
+ //# sourceMappingURL=paginate.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{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 q,MAX_ROWS as D,cellName as S,columnIndex as R,columnLetter as _,rangeName as x,readAddress as y,readArea as A,readAreas as G}from"./address.js";import{chartAfter as H}from"./chart.js";import{moveFormula as J,relativeKey as Q}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 V}from"./formula/walk.js";import{readTyped as Y}from"./values.js";import{chartFormula as Z}from"./workbook.js";const E=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 v(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}const tt=r=>b(r)?D:q;function $(r,t,n){const s=tt(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)?$(r.top,r.bottom,t):$(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 nt(r,t,n,s){let i=0;const a=(o,e)=>{o&&!o.abs&&(i=Math.max(i,Math.abs(o.index-e)))};return V(r,o=>{o.kind==="ref"&&(t?(a(o.row,n),a(o.row2,n)):(a(o.col,s),a(o.col2,s)))}),i}function et(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 ot(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=nt(a.node,o,r.top,r.left),f=[];let u=!0;for(const[m,d]of et(e,c,s,l)){const w=o?m:r.top,p=o?r.left:m,h=i?v(m,s):m;if(h===void 0)continue;const g=i?v(d,s):d;if(g===void 0)continue;const C=J(a.node,w-r.top,p-r.left),j=B(C,s,n);j!==C&&(u=!1);const U=o?h:r.top,X=o?r.left:h,F=Q(j,U,X),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(j)})}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 st=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 rt(r,t,n,s){const i={},a=E(n)?n:void 0;for(const[o,e]of Object.entries(r)){const c=st(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 ot(l,c,t,a,f))i[x(h.area)]=W(e,h.text);continue}if(!f){i[o]=e;continue}if(!k(a)){const h=L(l,a);h&&(i[x(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,j=d?{...l,top:h+C,bottom:g+C}:{...l,left:h+C,right:g+C};i[x(j)]=e}continue}const u={row:l.top,col:l.left};let m=u;if(f){const d=v(b(a)?u.row:u.col,a);m=d===void 0?void 0:b(a)?{...u,row:d}:{...u,col:d}}m&&(i[S(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 P=r=>r.reduce((t,n)=>Math.max(t,n.length),0);function K(r,t,n){const s=Math.max(P(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 T{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=E(n)&&M(t.name,n.sheet);t.cells&&(t.cells=rt(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=>M(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=>M(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),t.charts&&(t.charts=t.charts.map(e=>H(e,c=>{const l=c.startsWith("="),f=O(Z(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=>Y(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,K(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=S(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(P(e),1),f=c+l-1,u=$(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?K(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:S(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:x(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?[x(c)]:[]})),t.merges?.length===0&&delete t.merges;const i=o=>{const e=G(o);if(!e)return o;const c=e.flatMap(l=>{const f=L(l,n);return f?[x(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=v(c,n)??n.at;return{...o,at:S(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:v(u,n);return m===void 0?[]:[[_(m),f]]}));t.filter={range:x(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=$(0,e-1,n),l=e===0?0:c?c[1]+1:0;t.freeze=S(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:v(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(E(t)){const n=this.sheets().find(s=>M(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=>M(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=>M(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=>M(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 M=(r,t)=>r.toLowerCase()===t.toLowerCase();export function restructure(r,t){const n=new T(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 T(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}}