@allyhub/sdk 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/define.d.ts +4 -0
  2. package/dist/define.js +1 -1
  3. package/dist/node_modules/@allyhub-next/audio/dist/node/index.d.ts +1 -1
  4. package/dist/node_modules/@allyhub-next/audio/dist/node/index.js +1 -1
  5. package/dist/node_modules/@allyhub-next/audio/dist/node/master.d.ts +4 -0
  6. package/dist/node_modules/@allyhub-next/audio/dist/node/master.js +1 -1
  7. package/dist/node_modules/@allyhub-next/audio/package.json +1 -1
  8. package/dist/node_modules/@allyhub-next/chart/dist/chart-xml.js +2 -2
  9. package/dist/node_modules/@allyhub-next/chart/dist/chart.d.ts +14 -5
  10. package/dist/node_modules/@allyhub-next/chart/dist/chart.js +1 -1
  11. package/dist/node_modules/@allyhub-next/chart/package.json +1 -1
  12. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.d.ts +205 -0
  13. package/dist/node_modules/@allyhub-next/formats/dist/data/deck-code.js +2 -0
  14. package/dist/node_modules/@allyhub-next/formats/dist/data/script.d.ts +4 -1
  15. package/dist/node_modules/@allyhub-next/formats/dist/data/script.js +1 -1
  16. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.d.ts +248 -18
  17. package/dist/node_modules/@allyhub-next/formats/dist/data/sheet.js +1 -1
  18. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.d.ts +1114 -91
  19. package/dist/node_modules/@allyhub-next/formats/dist/data/slides.js +1 -1
  20. package/dist/node_modules/@allyhub-next/formats/dist/data/website.d.ts +20 -0
  21. package/dist/node_modules/@allyhub-next/formats/dist/data/website.js +2 -0
  22. package/dist/node_modules/@allyhub-next/formats/dist/index.d.ts +4 -0
  23. package/dist/node_modules/@allyhub-next/formats/dist/index.js +1 -1
  24. package/dist/node_modules/@allyhub-next/formats/dist/items.d.ts +1 -1
  25. package/dist/node_modules/@allyhub-next/formats/dist/items.js +1 -1
  26. package/dist/node_modules/@allyhub-next/formats/dist/media-type.d.ts +3 -0
  27. package/dist/node_modules/@allyhub-next/formats/dist/media-type.js +2 -0
  28. package/dist/node_modules/@allyhub-next/formats/dist/schemas.d.ts +625 -30
  29. package/dist/node_modules/@allyhub-next/formats/dist/schemas.js +1 -1
  30. package/dist/node_modules/@allyhub-next/formats/dist/strict.d.ts +2 -0
  31. package/dist/node_modules/@allyhub-next/formats/dist/strict.js +1 -1
  32. package/dist/node_modules/@allyhub-next/formats/dist/zip.d.ts +17 -0
  33. package/dist/node_modules/@allyhub-next/formats/dist/zip.js +2 -0
  34. package/dist/node_modules/@allyhub-next/formats/package.json +2 -1
  35. package/dist/node_modules/@allyhub-next/ooxml/LICENSE +241 -0
  36. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.d.ts +31 -0
  37. package/dist/node_modules/@allyhub-next/ooxml/dist/brightness.js +2 -0
  38. package/dist/node_modules/@allyhub-next/ooxml/dist/color.d.ts +33 -0
  39. package/dist/node_modules/@allyhub-next/ooxml/dist/color.js +2 -0
  40. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.d.ts +13 -0
  41. package/dist/node_modules/@allyhub-next/ooxml/dist/enums.js +2 -0
  42. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.d.ts +79 -0
  43. package/dist/node_modules/@allyhub-next/ooxml/dist/ext.js +2 -0
  44. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.d.ts +132 -0
  45. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/enums.js +2 -0
  46. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.d.ts +28 -0
  47. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/presets.js +2 -0
  48. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.d.ts +4708 -0
  49. package/dist/node_modules/@allyhub-next/ooxml/dist/generated/spec.js +2 -0
  50. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.d.ts +57 -0
  51. package/dist/node_modules/@allyhub-next/ooxml/dist/geometry/index.js +2 -0
  52. package/dist/node_modules/@allyhub-next/ooxml/dist/index.d.ts +10 -0
  53. package/dist/node_modules/@allyhub-next/ooxml/dist/index.js +2 -0
  54. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.d.ts +12 -0
  55. package/dist/node_modules/@allyhub-next/ooxml/dist/mce.js +2 -0
  56. package/dist/node_modules/@allyhub-next/ooxml/dist/node.d.ts +111 -0
  57. package/dist/node_modules/@allyhub-next/ooxml/dist/node.js +2 -0
  58. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.d.ts +45 -0
  59. package/dist/node_modules/@allyhub-next/ooxml/dist/ns.js +2 -0
  60. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.d.ts +48 -0
  61. package/dist/node_modules/@allyhub-next/ooxml/dist/opc.js +2 -0
  62. package/dist/node_modules/@allyhub-next/ooxml/dist/report.d.ts +45 -0
  63. package/dist/node_modules/@allyhub-next/ooxml/dist/report.js +2 -0
  64. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.d.ts +28 -0
  65. package/dist/node_modules/@allyhub-next/ooxml/dist/xml.js +2 -0
  66. package/dist/node_modules/@allyhub-next/ooxml/package.json +26 -0
  67. package/dist/node_modules/@allyhub-next/protocol/dist/account.d.ts +338 -0
  68. package/dist/node_modules/@allyhub-next/protocol/dist/account.js +2 -0
  69. package/dist/node_modules/@allyhub-next/protocol/dist/auth.d.ts +12 -13
  70. package/dist/node_modules/@allyhub-next/protocol/dist/auth.js +1 -1
  71. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.d.ts +35 -0
  72. package/dist/node_modules/@allyhub-next/protocol/dist/blobs.js +2 -0
  73. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.d.ts +101 -32
  74. package/dist/node_modules/@allyhub-next/protocol/dist/cloud.js +1 -1
  75. package/dist/node_modules/@allyhub-next/protocol/dist/editor.d.ts +89 -5
  76. package/dist/node_modules/@allyhub-next/protocol/dist/editor.js +1 -1
  77. package/dist/node_modules/@allyhub-next/protocol/dist/files.d.ts +2 -2
  78. package/dist/node_modules/@allyhub-next/protocol/dist/index.d.ts +6 -0
  79. package/dist/node_modules/@allyhub-next/protocol/dist/index.js +1 -1
  80. package/dist/node_modules/@allyhub-next/protocol/dist/notes.d.ts +23 -0
  81. package/dist/node_modules/@allyhub-next/protocol/dist/notes.js +1 -1
  82. package/dist/node_modules/@allyhub-next/protocol/dist/open.d.ts +13 -0
  83. package/dist/node_modules/@allyhub-next/protocol/dist/open.js +2 -0
  84. package/dist/node_modules/@allyhub-next/protocol/dist/registry.d.ts +73 -59
  85. package/dist/node_modules/@allyhub-next/protocol/dist/registry.js +1 -1
  86. package/dist/node_modules/@allyhub-next/protocol/dist/routes.d.ts +1 -1
  87. package/dist/node_modules/@allyhub-next/protocol/dist/routes.js +1 -1
  88. package/dist/node_modules/@allyhub-next/protocol/dist/shares.d.ts +115 -0
  89. package/dist/node_modules/@allyhub-next/protocol/dist/shares.js +2 -0
  90. package/dist/node_modules/@allyhub-next/protocol/dist/sites.d.ts +293 -0
  91. package/dist/node_modules/@allyhub-next/protocol/dist/sites.js +2 -0
  92. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.d.ts +377 -0
  93. package/dist/node_modules/@allyhub-next/protocol/dist/snapshots.js +2 -0
  94. package/dist/node_modules/@allyhub-next/protocol/dist/teams.d.ts +27 -9
  95. package/dist/node_modules/@allyhub-next/protocol/dist/teams.js +1 -1
  96. package/dist/node_modules/@allyhub-next/protocol/dist/tools.d.ts +53 -14
  97. package/dist/node_modules/@allyhub-next/protocol/dist/tools.js +1 -1
  98. package/dist/node_modules/@allyhub-next/protocol/package.json +2 -1
  99. package/dist/node_modules/@allyhub-next/runtimes/package.json +1 -1
  100. package/dist/node_modules/@allyhub-next/runtimes/schemas/runtimes.schema.json +25 -5
  101. package/dist/node_modules/@allyhub-next/scenery/package.json +1 -1
  102. package/dist/node_modules/@allyhub-next/sheet/dist/api/capabilities.js +1 -1
  103. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.d.ts +1 -0
  104. package/dist/node_modules/@allyhub-next/sheet/dist/api/index.js +1 -1
  105. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.d.ts +83 -0
  106. package/dist/node_modules/@allyhub-next/sheet/dist/api/page.js +2 -0
  107. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.d.ts +40 -1
  108. package/dist/node_modules/@allyhub-next/sheet/dist/api/workbook.js +1 -1
  109. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.d.ts +9 -3
  110. package/dist/node_modules/@allyhub-next/sheet/dist/calc/analyse.js +1 -1
  111. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.d.ts +5 -1
  112. package/dist/node_modules/@allyhub-next/sheet/dist/calc/coerce.js +1 -1
  113. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.d.ts +60 -13
  114. package/dist/node_modules/@allyhub-next/sheet/dist/calc/engine.js +1 -1
  115. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/aggregate.js +1 -1
  116. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.d.ts +4 -0
  117. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/convert.js +2 -0
  118. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/criteria.js +1 -1
  119. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/database.js +1 -1
  120. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/date.js +1 -1
  121. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.d.ts +27 -1
  122. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/define.js +1 -1
  123. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.d.ts +16 -0
  124. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/delimiters.js +2 -0
  125. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.d.ts +18 -1
  126. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/dynamic.js +1 -1
  127. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/finance.js +1 -1
  128. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.d.ts +2 -0
  129. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/index.js +1 -1
  130. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/info.js +1 -1
  131. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/kernels.js +1 -1
  132. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/logical.js +1 -1
  133. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/lookup.js +1 -1
  134. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/maths.js +1 -1
  135. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.d.ts +2 -0
  136. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/modern.js +2 -0
  137. package/dist/node_modules/@allyhub-next/sheet/dist/calc/functions/text.js +1 -1
  138. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.d.ts +38 -0
  139. package/dist/node_modules/@allyhub-next/sheet/dist/calc/graph.js +2 -0
  140. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.d.ts +19 -0
  141. package/dist/node_modules/@allyhub-next/sheet/dist/calc/indexes.js +2 -0
  142. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.d.ts +49 -0
  143. package/dist/node_modules/@allyhub-next/sheet/dist/calc/remote.js +2 -0
  144. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.d.ts +82 -0
  145. package/dist/node_modules/@allyhub-next/sheet/dist/calc/server.js +2 -0
  146. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.d.ts +6 -1
  147. package/dist/node_modules/@allyhub-next/sheet/dist/calc/types.js +1 -1
  148. package/dist/node_modules/@allyhub-next/sheet/dist/chart.js +1 -1
  149. package/dist/node_modules/@allyhub-next/sheet/dist/check.js +1 -1
  150. package/dist/node_modules/@allyhub-next/sheet/dist/diff.d.ts +15 -0
  151. package/dist/node_modules/@allyhub-next/sheet/dist/diff.js +1 -1
  152. package/dist/node_modules/@allyhub-next/sheet/dist/export.d.ts +29 -8
  153. package/dist/node_modules/@allyhub-next/sheet/dist/export.js +3 -4
  154. package/dist/node_modules/@allyhub-next/sheet/dist/file.js +2 -2
  155. package/dist/node_modules/@allyhub-next/sheet/dist/format.d.ts +8 -2
  156. package/dist/node_modules/@allyhub-next/sheet/dist/format.js +1 -1
  157. package/dist/node_modules/@allyhub-next/sheet/dist/html.d.ts +52 -4
  158. package/dist/node_modules/@allyhub-next/sheet/dist/html.js +43 -11
  159. package/dist/node_modules/@allyhub-next/sheet/dist/index.d.ts +7 -3
  160. package/dist/node_modules/@allyhub-next/sheet/dist/index.js +1 -1
  161. package/dist/node_modules/@allyhub-next/sheet/dist/inspect.js +1 -1
  162. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.d.ts +98 -0
  163. package/dist/node_modules/@allyhub-next/sheet/dist/paginate.js +2 -0
  164. package/dist/node_modules/@allyhub-next/sheet/dist/structure.js +1 -1
  165. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.d.ts +32 -0
  166. package/dist/node_modules/@allyhub-next/sheet/dist/table-style.js +2 -0
  167. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.d.ts +3 -0
  168. package/dist/node_modules/@allyhub-next/sheet/dist/table-styles.js +2 -0
  169. package/dist/node_modules/@allyhub-next/sheet/dist/values.js +1 -1
  170. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.d.ts +10 -1
  171. package/dist/node_modules/@allyhub-next/sheet/dist/workbook.js +1 -1
  172. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.d.ts +12 -1
  173. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/charts.js +1 -1
  174. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.d.ts +14 -4
  175. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/formula.js +2 -2
  176. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.d.ts +11 -1
  177. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/functions.js +36 -16
  178. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.d.ts +6 -1
  179. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/import.js +1 -1
  180. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.d.ts +44 -2
  181. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/read.js +2 -1
  182. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.d.ts +23 -0
  183. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/sax.js +2 -0
  184. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.d.ts +2 -0
  185. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/styles.js +1 -1
  186. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.d.ts +6 -0
  187. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/write.js +1 -1
  188. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.d.ts +40 -0
  189. package/dist/node_modules/@allyhub-next/sheet/dist/xlsx/zip.js +2 -0
  190. package/dist/node_modules/@allyhub-next/sheet/package.json +1 -1
  191. package/dist/node_modules/@allyhub-next/slides-core/dist/animation.js +1 -1
  192. package/dist/node_modules/@allyhub-next/slides-core/dist/api.d.ts +121 -44
  193. package/dist/node_modules/@allyhub-next/slides-core/dist/api.js +2 -2
  194. package/dist/node_modules/@allyhub-next/slides-core/dist/capabilities.js +1 -1
  195. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.d.ts +50 -13
  196. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-api.js +1 -1
  197. package/dist/node_modules/@allyhub-next/slides-core/dist/chart-file.js +1 -1
  198. package/dist/node_modules/@allyhub-next/slides-core/dist/check.js +1 -1
  199. package/dist/node_modules/@allyhub-next/slides-core/dist/code.d.ts +33 -0
  200. package/dist/node_modules/@allyhub-next/slides-core/dist/code.js +2 -0
  201. package/dist/node_modules/@allyhub-next/slides-core/dist/components.d.ts +31 -0
  202. package/dist/node_modules/@allyhub-next/slides-core/dist/components.js +2 -0
  203. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.d.ts +188 -5
  204. package/dist/node_modules/@allyhub-next/slides-core/dist/enums.js +1 -1
  205. package/dist/node_modules/@allyhub-next/slides-core/dist/file.d.ts +43 -21
  206. package/dist/node_modules/@allyhub-next/slides-core/dist/file.js +3 -3
  207. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.d.ts +17 -0
  208. package/dist/node_modules/@allyhub-next/slides-core/dist/identity.js +2 -0
  209. package/dist/node_modules/@allyhub-next/slides-core/dist/index.d.ts +5 -0
  210. package/dist/node_modules/@allyhub-next/slides-core/dist/index.js +1 -1
  211. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.d.ts +6 -0
  212. package/dist/node_modules/@allyhub-next/slides-core/dist/lang.js +2 -0
  213. package/dist/node_modules/@allyhub-next/slides-core/dist/measure.js +1 -1
  214. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.d.ts +58 -0
  215. package/dist/node_modules/@allyhub-next/slides-core/dist/merge.js +2 -0
  216. package/dist/node_modules/@allyhub-next/slides-core/dist/model.d.ts +38 -4
  217. package/dist/node_modules/@allyhub-next/slides-core/dist/office.d.ts +27 -1
  218. package/dist/node_modules/@allyhub-next/slides-core/dist/office.js +1 -1
  219. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.d.ts +26 -5
  220. package/dist/node_modules/@allyhub-next/slides-core/dist/resolve.js +1 -1
  221. package/dist/node_modules/@allyhub-next/slides-core/dist/script.d.ts +18 -16
  222. package/dist/node_modules/@allyhub-next/slides-core/dist/script.js +2 -2
  223. package/dist/node_modules/@allyhub-next/slides-core/dist/stage.d.ts +51 -53
  224. package/dist/node_modules/@allyhub-next/slides-core/dist/strict.js +1 -1
  225. package/dist/node_modules/@allyhub-next/slides-core/dist/units.d.ts +27 -0
  226. package/dist/node_modules/@allyhub-next/slides-core/dist/units.js +1 -1
  227. package/dist/node_modules/@allyhub-next/slides-core/dist/values.d.ts +7 -0
  228. package/dist/node_modules/@allyhub-next/slides-core/dist/values.js +2 -0
  229. package/dist/node_modules/@allyhub-next/slides-core/package.json +1 -1
  230. package/dist/node_modules/@allyhub-next/video-core/dist/captions.js +6 -6
  231. package/dist/node_modules/@allyhub-next/video-core/dist/fact.d.ts +47 -8
  232. package/dist/node_modules/@allyhub-next/video-core/dist/fact.js +1 -1
  233. package/dist/node_modules/@allyhub-next/video-core/dist/index.d.ts +1 -0
  234. package/dist/node_modules/@allyhub-next/video-core/dist/index.js +1 -1
  235. package/dist/node_modules/@allyhub-next/video-core/dist/marks.d.ts +14 -0
  236. package/dist/node_modules/@allyhub-next/video-core/dist/marks.js +1 -1
  237. package/dist/node_modules/@allyhub-next/video-core/dist/music.d.ts +2 -1
  238. package/dist/node_modules/@allyhub-next/video-core/dist/piece.d.ts +11 -2
  239. package/dist/node_modules/@allyhub-next/video-core/dist/problem.d.ts +4 -0
  240. package/dist/node_modules/@allyhub-next/video-core/dist/problem.js +1 -1
  241. package/dist/node_modules/@allyhub-next/video-core/dist/schema.d.ts +2 -2
  242. package/dist/node_modules/@allyhub-next/video-core/dist/schema.js +1 -1
  243. package/dist/node_modules/@allyhub-next/video-core/dist/script.d.ts +2 -1
  244. package/dist/node_modules/@allyhub-next/video-core/dist/script.js +1 -1
  245. package/dist/node_modules/@allyhub-next/video-core/dist/source.d.ts +7 -0
  246. package/dist/node_modules/@allyhub-next/video-core/dist/source.js +2 -0
  247. package/dist/node_modules/@allyhub-next/video-core/dist/timeline.d.ts +10 -33
  248. package/dist/node_modules/@allyhub-next/video-core/package.json +1 -1
  249. package/dist/sheets.d.ts +1 -1
  250. package/dist/sheets.js +1 -1
  251. package/dist/slides.d.ts +3 -1
  252. package/dist/slides.js +1 -1
  253. package/docs/README.md +1 -0
  254. package/docs/contract.md +1 -1
  255. package/docs/defaults.md +25 -2
  256. package/docs/layers.md +1 -1
  257. package/docs/project.md +3 -1
  258. package/docs/sheets.md +29 -3
  259. package/docs/slides.md +18 -14
  260. package/docs/sound.md +1 -1
  261. package/docs/websites.md +57 -0
  262. package/package.json +3 -1
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_DATA as G,SHEET_FILE as Q}from"@allyhub-next/formats";import{cellName as $,columnLetter as A,contains as z,overlaps as D,rangeName as x,readAddress as Z,readArea as ee}from"../address.js";import{rectangles as _}from"../api/rectangles.js";import{chartAfter as te}from"../chart.js";import{analyse as oe}from"../calc/analyse.js";import{FUNCTIONS as ne}from"../calc/functions/index.js";import{checkWorkbook as se}from"../check.js";import{writeCsv as I}from"../csv.js";import{isDateCode as W}from"../format.js";import{moveFormula as re,relativeKey as B}from"../formula/move.js";import{printFormula as M,sheetPrefix as ie}from"../formula/print.js";import{mapNode as le,walk as N}from"../formula/walk.js";import{CellError as T,isoOfSerial as fe,readTyped as F,writeTyped as P}from"../values.js";import{FormulaCell as ae,placeKey as g,validName as R}from"../workbook.js";import{writeYaml as ce}from"../write.js";import{readFileFormula as ue}from"./formula.js";import{hasDate as H}from"./numfmt.js";import{placesLine as J,readXlsx as de}from"./read.js";const K=100,he=.5,q=1462;export const COMPARE_TOLERANCE=1e-9;const me=f=>f.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",b=f=>Object.keys(f).length===0,V=(f,e)=>`${String(f)} ${e}${f===1?"":"s"}`,C=f=>({row:f.row,col:f.col});function X(f,e){const o=e.toLowerCase();return le(f,n=>n.kind!=="structured"||n.table?.toLowerCase()!==o?n:Object.fromEntries(Object.entries(n).filter(([i])=>i!=="table")))}function Y(f){return f.headers===0?"has no header row":f.columns.length!==f.ref.right-f.ref.left+1||!R(f.name)?"cannot be held as a table":new Set(f.columns.map(e=>e.name.toLowerCase())).size===f.columns.length?void 0:"has two columns of one name"}function U(f,e,o){let n;const i=new Set;N(f,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(r=>{r.kind==="name"&&i.add(r.name.toLowerCase())})});const s=t=>i.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return N(f,t=>{n===void 0&&(t.kind==="call"&&!ne.has(t.name)&&(s(t.written.toLowerCase())||(n=`no function ${t.name}`)),t.kind==="name"&&!s(t.name.toLowerCase())&&(n=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!s(t.table.toLowerCase())&&(n=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?n="it reads another workbook":e.has(t.sheet.toLowerCase())||(n=`no sheet ${t.sheet}`)))}),n}function pe(f){const e=new Set(f.book.sheets.map(o=>o.name.toLowerCase()));for(const o of f.book.sheets){const n=new Map,i=(t,r)=>{const l=n.get(r),c=$(t);l?l.push(c):n.set(r,[c])},s=[];for(const t of o.cells){if(t.unread!==void 0){i(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const r=U(t.node,e,f);r!==void 0?(delete t.node,i(t,r)):(f.carried.set(t,o),t.array&&x(t.array)!==$(t)&&s.push(t))}we(f,o,s);for(const[t,r]of n)f.lost.push(`${o.name}: ${V(r.length,"formula")} kept as ${r.length===1?"its value":"their values"}, as ${t} (${J(r)})`)}}function we(f,e,o){if(o.length===0)return;const n=new Set;for(const i of o){const{array:s}=i;if(s)for(const t of e.cells)t!==i&&!t.node&&z(s,t.row,t.col)&&n.add(t)}e.cells=e.cells.filter(i=>!n.has(i));for(const i of n)f.spilled.set(i,e)}function O(f,e){const{value:o}=e;if(!f.book.date1904||typeof o!="number")return o;const n=f.book.looks[e.style]?.format;return W(n)&&n!==void 0&&H(n)?o+q:o}function j(f,e){if(typeof f!="number"||e===void 0||!W(e)||!H(e)||f<1)return;const o=fe(f);return F(o).value===f?o:void 0}const ge=(f,e)=>j(f,e)??P(f??null);function ke(f,e){const o=j(f,e);return o!==void 0?o:f==null?null:typeof f=="number"||typeof f=="boolean"?f:P(f)}function be(f){const e={top:1/0,left:1/0,bottom:-1,right:-1};for(const{row:o,col:n}of f)e.top=Math.min(e.top,o),e.left=Math.min(e.left,n),e.bottom=Math.max(e.bottom,o),e.right=Math.max(e.right,n);return e}class ye{ctx;read;byPlace=new Map;inTables=new Set;columnLooks=new Map;rowLooks=new Map;lookDone=new Set;tables=[];areas=[];filtered=[];constructor(e,o){this.ctx=e,this.read=o;for(const n of o.cells)this.byPlace.set(g(n.row,n.col),n)}look(e){return this.ctx.book.looks[e.style]??{}}code(e){return this.look(e).format}text(e){return e.node?M(e.node):ge(O(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book,n=e.cells.reduce((s,t)=>Math.max(s,t.col),-1);for(const s of e.columns){if(s.style===void 0)continue;const t=o[s.style];if(!(!t||b(t)))for(let r=s.min;r<=Math.min(s.max,n);r++)this.columnLooks.set(r,t)}for(const s of e.rows){const t=s.style===void 0?void 0:o[s.style];t&&!b(t)&&this.rowLooks.set(s.row,t)}const i=(s,t)=>Object.keys(t).every(r=>r in s);for(const s of e.cells){const t=this.look(s),r=this.columnLooks.get(s.col);r&&!i(t,r)&&this.columnLooks.delete(s.col);const l=this.rowLooks.get(s.row);l&&!i(t,l)&&this.rowLooks.delete(s.row)}}ownLook(e){const o={...this.columnLooks.get(e.col),...this.rowLooks.get(e.row)},n={};for(const[s,t]of Object.entries(this.look(e)))JSON.stringify(t)!==JSON.stringify(o[s])&&(n[s]=t);const i=n.format;if(typeof i=="string"){const s=e.node?void 0:j(O(this.ctx,e),i);s!==void 0&&F(s).format===i&&delete n.format}return n}columnFormula(e,o,n){const i=new Map,s=n-o+1;for(let r=o;r<=n;r++){const l=this.byPlace.get(g(r,e));if(!l||l.value===void 0&&!l.node||l.value===null&&!l.node)return;if(!l.node)continue;l.key??=B(l.node,l.row,l.col);const c=i.get(l.key);c?c.n+=1:i.set(l.key,{n:1,cell:l})}let t;for(const r of i.values())(!t||r.n>t.n)&&(t=r);return t&&t.n*2>s?t.cell:void 0}table(e){const{read:o,ctx:n}=this,i=h=>n.lost.push(`${o.name}: table ${e.name} ${h}`),s=e.ref.right-e.ref.left+1,t=Y(e);if(t!==void 0)return i(`${t}, so its cells are kept and it is no table`),!1;const r=e.ref.top,l=r+1,c=e.ref.bottom-e.totals;e.totals>0&&i("has a totals row, kept as plain cells under it");const a=e.columns.map((h,m)=>c>=l?this.columnFormula(e.ref.left+m,l,c):void 0),u=h=>{const m=a[h];if(!m)return!1;for(let k=l;k<=c;k++)if(this.byPlace.get(g(k,e.ref.left+h))?.key!==m.key)return!1;return!0};let d=s;for(;d>1&&u(d-1);)d-=1;const w=[e.columns.slice(0,d).map(h=>h.name)],p={};for(let h=l;h<=c;h++){const m=[];for(let k=0;k<d;k++){const y=this.byPlace.get(g(h,e.ref.left+k)),v=a[k];y?v&&y.key===v.key?m.push(""):y.node?m.push(M(X(y.node,e.name))):m.push(this.text(y)):m.push("")}w.push(m)}for(let h=e.ref.top;h<=c;h++)for(let m=e.ref.left;m<=e.ref.right;m++)this.inTables.add(g(h,m));e.columns.forEach((h,m)=>{const k=e.ref.left+m,y=this.columnLook(k,l,c),v=a[m];v?.node&&(y.formula=M(X(re(v.node,l-v.row,0),e.name))),b(y)||(p[h.name]=y)});const L=this.path(e.name);n.files.set(L,I(w));const E=new Map;for(const[h,m]of e.filter?.columns??[]){const k=e.columns[h]?.name;k!==void 0&&E.set(k,m)}return(e.filter?.unread??0)>0&&i(`has ${V(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:$({row:r,col:e.ref.left}),rows:L,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...b(p)?{}:{columns:p},...e.filter===void 0?{filter:!1}:E.size>0?{filter:{columns:Object.fromEntries(E)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:c}),this.areas.push({...e.ref,bottom:c}),!0}columnLook(e,o,n){let i,s={};for(let t=o;t<=n;t++){const r=this.byPlace.get(g(t,e)),l=r?this.ownLook(r):{},c=JSON.stringify(l);if(i===void 0)i=c,s=l;else if(i!==c)return{}}if(b(s))return{};for(let t=o;t<=n;t++)this.lookDone.add(g(t,e));return{...s}}path(e){const o=`${G}/${me(e)}`;let n=`${o}.csv`;for(let i=2;this.ctx.files.has(n);i++)n=`${o}-${String(i)}.csv`;return n}loose(){const e=[],o=[];for(const n of this.read.cells)this.inTables.has(g(n.row,n.col))||(n.node?e.push(n):n.value!==void 0&&n.value!==null&&o.push(n));return{formulas:e,typed:o}}blockAreas(e,o){const n=new Map;e.forEach((a,u)=>n.set(g(a.row,a.col),u));const i=e.map((a,u)=>u),s=a=>{let u=a;for(;i[u]!==u;){const d=i[i[u]??u]??u;i[u]=d,u=d}return u};e.forEach((a,u)=>{for(const d of[n.get(g(a.row,a.col-1)),n.get(g(a.row-1,a.col))])d!==void 0&&(i[s(u)]=s(d))});const t=new Map;e.forEach((a,u)=>{const d=s(u),w=t.get(d);w?w.push(a):t.set(d,[a])});const r=[],l=a=>!r.some(u=>D(u,a))&&!this.areas.some(u=>D(u,a))&&!o.some(u=>z(a,u.row,u.col)),c=a=>(a.bottom-a.top+1)*(a.right-a.left+1);for(const a of t.values()){const u=be(a);if(!(c(u)<K)){if(a.length/c(u)>=he&&l(u)){r.push(u);continue}for(const d of _(a.map(C)))c(d)>=K&&l(d)&&r.push(d)}}return r.sort((a,u)=>a.top-u.top||a.left-u.left)}cells(e){const{formulas:o,typed:n}=this.loose(),i=this.blockAreas(n,o),s=l=>i.some(c=>z(c,l.row,l.col));i.length>0&&(e.blocks=i.map(l=>{const c=[];for(let u=l.top;u<=l.bottom;u++){const d=[];for(let w=l.left;w<=l.right;w++){const p=this.byPlace.get(g(u,w));d.push(p?this.text(p):"")}c.push(d)}const a=this.path(this.read.name);return this.ctx.files.set(a,I(c)),{at:$({row:l.top,col:l.left}),rows:a}}));const t=[],r=new Map;for(const l of o){if(!l.node)continue;l.key??=B(l.node,l.row,l.col);const c=r.get(l.key);c?c.push(l):r.set(l.key,[l])}for(const l of r.values())for(const c of _(l.map(C))){const a=this.byPlace.get(g(c.top,c.left));a?.node&&t.push([{row:c.top,col:c.left},x(c),M(a.node)])}for(const l of n)i.length>0&&s(l)||t.push([C(l),$(l),ke(O(this.ctx,l),this.code(l))]);t.sort(([l],[c])=>l.row-c.row||l.col-c.col),t.length>0&&(e.cells=Object.fromEntries(t.map(([,l,c])=>[l,c])))}formats(e){const o=new Map;for(const i of this.read.cells){if(this.lookDone.has(g(i.row,i.col)))continue;const s=this.ownLook(i);if(b(s))continue;const t=JSON.stringify(s),r=o.get(t);r?r.places.push(C(i)):o.set(t,{look:s,places:[C(i)]})}const n=[];for(const{look:i,places:s}of o.values())for(const t of _(s))n.push({range:x(t),...i});n.length>0&&(e.format=n)}columns(e){const{read:o}=this,n=new Map,i=o.cells.reduce((t,r)=>Math.max(t,r.col),0),s=[];for(const t of o.columns)if(!(t.width===void 0&&t.hidden!==!0)){t.max>i&&s.push(A(Math.max(t.min,i+1)));for(let r=t.min;r<=Math.min(t.max,i);r++)n.set(r,{...t.width===void 0?{}:{width:t.width},...t.hidden===!0?{hidden:!0}:{}})}for(const[t,r]of this.columnLooks)n.set(t,{...n.get(t),...r});n.size>0&&(e.columns=Object.fromEntries([...n.keys()].sort((t,r)=>t-r).map(t=>[A(t),n.get(t)??{}]))),s.some(Boolean)&&o.columns.some(t=>t.max>i&&t.hidden===!0)&&this.ctx.lost.push(`${o.name}: the size of the columns past its last used one`)}rows(e){const o={};for(const n of this.read.rows){const i=this.rowLooks.get(n.row),s=this.filtered.some(r=>n.row>r.top&&n.row<=r.bottom),t={...n.height===void 0?{}:{height:n.height},...n.hidden===!0&&!s?{hidden:!0}:{},...i};b(t)||(o[String(n.row+1)]=t)}b(o)||(e.rows=o)}build(){const{read:e}=this;this.baseLooks();for(const n of e.tables)this.table(n);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=$(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells(o),e.merges.length>0&&(o.merges=e.merges.map(x)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(n=>this.chart(n))),o}chart(e){return te(e,o=>{const n=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${n}`:n})}chartReference(e){const o=e.lastIndexOf("!"),i=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),s=ee(e.slice(o+1).replaceAll("$",""));if(!s)return e;const t=this.ctx.book.sheets.find(r=>r.name.toLowerCase()===i.toLowerCase());for(const r of t?.tables??[]){const l=r.ref.top+1,a=s.left===s.right&&s.top===l&&s.bottom===r.ref.bottom&&s.left>=r.ref.left&&s.left<=r.ref.right?r.columns[s.left-r.ref.left]:void 0;if(a&&this.ctx.tables.has(r.name.toLowerCase()))return`${r.name}[${a.name}]`}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${x(s)}`}filter(e){const{filter:o}=this.read;if(!o)return;const n={};for(const[i,s]of o.columns)n[A(o.ref.left+i)]=s;e.filter={range:x(o.ref),...b(n)?{}:{columns:n}},o.unread===0&&!b(n)&&this.filtered.push(o.ref)}}function $e(f){const e={},{book:o,lost:n}=f,i=new Set(o.sheets.map(r=>r.name.toLowerCase())),s=new Set,t=new Set;for(const r of o.names){if(r.name.startsWith("_xlnm.")){r.name==="_xlnm.Print_Area"?t.add("print areas"):r.name==="_xlnm.Print_Titles"?t.add("print titles"):r.name!=="_xlnm._FilterDatabase"&&n.push(`Excel's name ${r.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(r.name))continue;const l=r.name.toLowerCase();if(!R(r.name)||f.tables.has(l)){n.push(`the name ${r.name}, which cannot be held here`);continue}if(s.has(l)){n.push(`a second name ${r.name}, for one sheet: names here are the workbook's`);continue}const c=xe(r.text);if(c!==void 0)e[r.name]=typeof c=="string"?P(c):c,s.add(l),f.names.add(l);else{const a=ue(r.text,!0),u=a.ok?U(a.node,i):"it could not be read";if(!a.ok||u!==void 0||ve(a.node)){n.push(`the name ${r.name} (${r.text})${u===void 0?"":`: ${u}`}`);continue}e[r.name]=M(a.node),s.add(l),f.names.add(l)}r.sheet!==void 0&&n.push(`the name ${r.name} belonging to one sheet: here it is the workbook's`)}return t.size>0&&n.push([...t].join(" and ")),e}function Le(f,e){const o={},n=new Map;for(const[i,s]of Object.entries(e))typeof s=="string"&&s.startsWith("=")&&n.set(s.slice(1).replaceAll("$","").toLowerCase(),i);for(const i of f.book.sheets)for(const s of i.scenarios){const t={};let r=!0;for(const{at:l,value:c}of s.cells){const a=Z(l),u=a&&i.cells.find(p=>p.row===a.row&&p.col===a.col);String(u?.value??"")!==c&&(r=!1);const d=n.get(`${ie(i.name)}${l}`.toLowerCase())??n.get(l.toLowerCase()),w=F(c);d===void 0?f.lost.push(`${i.name}: scenario ${s.name}'s cell ${l}, which has no name`):t[d]=typeof w.value=="number"?w.value:c}!r&&!b(t)&&(o[s.name]={...o[s.name],...t})}return o}function ve(f){let e=!1;return N(f,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function xe(f){const e=f.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const S=f=>f instanceof T?f.code:f??null;export function sameValue(f,e,o){if(typeof f=="number"&&typeof e=="number")return f===e?!0:Math.abs(f-e)<=Math.max(Math.abs(f),Math.abs(e))*o;if(f instanceof T||e instanceof T)return f?.code===e?.code;if(f===null||e===null){const n=f??e;return n===null||n===""||n===0||n===!1}return f===e}function Me(f,e){const o=[];for(const s of e.sheets)for(const t of s.formulas)t.shared.node&&oe(e,t.shared).volatile&&o.push(t);const n=new Set(o),i=[...o];for(;;){const s=i.pop();if(!s)return n;for(const t of f.readers(s.sheet,s.row,s.col))n.has(t)||(n.add(t),i.push(t))}}function Ce(f,e,o,n){const i={formulas:0,same:0,uncached:0,moving:0,differences:[]},s=Me(o,e);for(const[t,r]of f.carried){if(!t.node)continue;const l=e.sheet(r.name);if(!l)continue;i.formulas+=1;const c=l.at(t.row,t.col);if(c instanceof ae&&s.has(c)){i.moving+=1;continue}const a=O(f,t);if(a===void 0){i.uncached+=1;continue}const u=o.value(l,t.row,t.col);sameValue(a,u,n)?i.same+=1:i.differences.push({sheet:r.name,cell:$(t),formula:M(t.node),file:S(a),engine:S(u)})}for(const[t,r]of f.spilled){const l=e.sheet(r.name);if(!l)continue;i.formulas+=1;const c=l.spillAt(t.row,t.col);if(c&&s.has(c)){i.moving+=1;continue}const a=O(f,t),u=o.value(l,t.row,t.col);a===void 0?i.uncached+=1:sameValue(a,u,n)?i.same+=1:i.differences.push({sheet:r.name,cell:$(t),formula:c?`${$(c)}#`:"",file:S(a),engine:S(u)})}return i}function Oe(f,e){const o=new Map,n=[];for(const i of f){const s=e.find(l=>i.startsWith(`${l}: `));if(s===void 0){n.push(i);continue}const t=i.slice(s.length+2),r=o.get(t);r?r.push(s):o.set(t,[s])}for(const[i,s]of o)n.push(s.length===1?`${s[0]??""}: ${i}`:`${i}, on ${String(s.length)} sheets (${J(s)})`);return n}export function importXlsx(f,e){const o=de(f);if(o.sheets.length===0)throw new Error("It holds no sheets.");const n={book:o,files:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(p=>p.tables.filter(L=>Y(L)===void 0).map(L=>L.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&n.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(q)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&n.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const i=$e(n);pe(n);const s=o.sheets.map(p=>new ye(n,p).build()),t=Le(n,i),r={title:e.name,...b(i)?{}:{names:i},sheets:s,...b(t)?{}:{scenarios:t}},l=ce(r),c=new Map([[Q,l],...n.files]),a=se({text:l,read:p=>c.get(p)}),{workbook:u,calc:d,problems:w}=a;return{files:c,lost:Oe(n.lost,o.sheets.map(p=>p.name)),problems:w,compared:u&&d?Ce(n,u,d,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:n.tables.size}}
2
+ import{SHEET_DATA as re,SHEET_FILE as ie,SHEET_FILES as j,SHEET_NOTE_AUTHOR as le,SHEET_PICTURE_HEIGHT as P,SHEET_SEPARATOR as fe}from"@allyhub-next/formats";import{cellName as y,columnLetter as M,contains as T,overlaps as A,rangeName as v,readAddress as ae,readArea as W}from"../address.js";import{rectangles as O}from"../api/rectangles.js";import{chartAfter as ce}from"../chart.js";import{analyse as ue}from"../calc/analyse.js";import{FUNCTIONS as he}from"../calc/functions/index.js";import{checkWorkbook as de}from"../check.js";import{writeCsv as me}from"../csv.js";import{pictureSize as pe}from"../files.js";import{isDateCode as z}from"../format.js";import{moveFormula as we,relativeKey as B}from"../formula/move.js";import{printFormula as E,sheetPrefix as U}from"../formula/print.js";import{mapNode as ge,walk as H}from"../formula/walk.js";import{CellError as N,isoOfSerial as ke,readTyped as F,writeTyped as I}from"../values.js";import{FormulaCell as be,validName as V}from"../workbook.js";import{writeYaml as ye}from"../write.js";import{readFileFormula as $e}from"./formula.js";import{hasDate as q}from"./numfmt.js";import{placesLine as D,readXlsx as xe}from"./read.js";import{LISTS_SHEET as Le}from"./write.js";const J=100,ve=.5,K=1462,Z=64,X=1e4;export const COMPARE_TOLERANCE=1e-9;const Y=a=>a.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",k=a=>{for(const e in a)if(Object.hasOwn(a,e))return!1;return!0},G=(a,e)=>`${String(a)} ${e}${a===1?"":"s"}`,S=a=>({row:a.row,col:a.col});function Q(a){return a===""||a.length>255||/^[/\\]|^[A-Za-z]:|\\|\0/u.test(a)?!1:a.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}class Ee{cells;starts;first;constructor(e){let o=!0;for(let t=1;t<e.length&&o;t++){const n=e[t-1],r=e[t];n&&r&&(r.row<n.row||r.row===n.row&&r.col<=n.col)&&(o=!1)}if(!o){e.sort((t,n)=>t.row-n.row||t.col-n.col);for(let t=e.length-1;t>0;t--){const n=e[t-1],r=e[t];r&&n?.row===r.row&&n.col===r.col&&e.splice(t-1,1)}}this.cells=e;const s=e[0]?.row??0,l=e[e.length-1]?.row??-1;this.first=s,this.starts=new Int32Array(Math.max(0,l-s+2));let i=0;for(let t=0;t<this.starts.length;t++){for(;i<e.length&&(e[i]?.row??0)<s+t;)i++;this.starts[t]=i}}get(e,o){const s=e-this.first;if(s<0||s>=this.starts.length-1)return;let l=this.starts[s]??0,i=(this.starts[s+1]??0)-1;for(;l<=i;){const t=l+i>>1,n=this.cells[t];if(!n)return;if(n.col===o)return n;n.col<o?l=t+1:i=t-1}}}class ee{list=[];add(e){this.list.push(e)}has(e,o){for(const s of this.list)if(T(s,e,o))return!0;return!1}}function te(a,e){const o=e.toLowerCase();return ge(a,s=>s.kind!=="structured"||s.table?.toLowerCase()!==o?s:Object.fromEntries(Object.entries(s).filter(([l])=>l!=="table")))}function oe(a){return a.headers===0?"has no header row":a.columns.length!==a.ref.right-a.ref.left+1||!V(a.name)?"cannot be held as a table":new Set(a.columns.map(e=>e.name.toLowerCase())).size===a.columns.length?void 0:"has two columns of one name"}function ne(a,e,o){let s;const l=new Set;H(a,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(n=>{n.kind==="name"&&l.add(n.name.toLowerCase())})});const i=t=>l.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return H(a,t=>{s===void 0&&(t.kind==="call"&&!he.has(t.name)&&(i(t.written.toLowerCase())||(s=`no function ${t.name}`)),t.kind==="name"&&!i(t.name.toLowerCase())&&(s=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!i(t.table.toLowerCase())&&(s=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?s="it reads another workbook":e.has(t.sheet.toLowerCase())||(s=`no sheet ${t.sheet}`)))}),s}function Se(a){const e=new Set(a.book.sheets.map(o=>o.name.toLowerCase()));for(const o of a.book.sheets){const s=new Map,l=(t,n)=>{const r=s.get(n),f=y(t);r?r.push(f):s.set(n,[f])},i=[];for(const t of o.cells){if(t.unread!==void 0){l(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const n=ne(t.node,e,a);n!==void 0?(delete t.node,l(t,n)):(a.carried.set(t,o),t.array&&v(t.array)!==y(t)&&i.push(t))}Ce(a,o,i);for(const[t,n]of s)a.lost.push(`${o.name}: ${G(n.length,"formula")} kept as ${n.length===1?"its value":"their values"}, as ${t} (${D(n)})`)}}function Ce(a,e,o){if(o.length===0)return;const s=new Set;for(const l of o){const{array:i}=l;if(i)for(const t of e.cells)t!==l&&!t.node&&T(i,t.row,t.col)&&s.add(t)}e.cells=e.cells.filter(l=>!s.has(l));for(const l of s)a.spilled.set(l,e)}function C(a,e){const{value:o}=e;if(!a.book.date1904||typeof o!="number")return o;const s=a.book.looks[e.style]?.format;return z(s)&&s!==void 0&&q(s)?o+K:o}function R(a,e){if(typeof a!="number"||e===void 0||!z(e)||!q(e)||a<1)return;const o=ke(a);return F(o).value===a?o:void 0}const Me=(a,e)=>R(a,e)??I(a??null);function Oe(a,e){const o=R(a,e);return o!==void 0?o:a==null?null:typeof a=="number"||typeof a=="boolean"?a:I(a)}function _e(a){const e=[];for(let n=0;n<a.length;n++){const r=a[n];if(!r)continue;const f=e[e.length-1];f?.row===r.row&&f.right===r.col-1?(f.right=r.col,f.last=n):e.push({row:r.row,left:r.col,right:r.col,first:n,last:n})}const o=e.map((n,r)=>r),s=n=>{let r=n;for(;o[r]!==r;){const f=o[o[r]??r]??r;o[r]=f,r=f}return r};let l=0,i=0;for(let n=0;n<e.length;n++){const r=e[n];if(r){n>0&&e[n-1]?.row!==r.row&&(l=e[n-1]?.row===r.row-1?i:n,i=n);for(let f=l;f<i;f++){const c=e[f];c?.row===r.row-1&&c.right>=r.left&&c.left<=r.right&&(o[s(n)]=s(f))}}}const t=new Map;return e.forEach((n,r)=>{const f=s(r),c=t.get(f),u=n.right-n.left+1;c?(c.box.top=Math.min(c.box.top,n.row),c.box.bottom=Math.max(c.box.bottom,n.row),c.box.left=Math.min(c.box.left,n.left),c.box.right=Math.max(c.box.right,n.right),c.count+=u,c.runs.push(r)):t.set(f,{box:{top:n.row,bottom:n.row,left:n.left,right:n.right},count:u,runs:[r]})}),[...t.values()].map(n=>({box:n.box,count:n.count,cells:()=>n.runs.flatMap(r=>{const f=e[r];return f?a.slice(f.first,f.last+1):[]})}))}const se=a=>JSON.stringify(a);class Te{ctx;read;cells;inTables=new ee;columnLooks=new Map;rowLooks=new Map;lookDone=new ee;tables=[];areas=[];filtered=[];ownLooks=new Map;fileColumns=new Map;pictured=new Map;over=[];constructor(e,o){this.ctx=e,this.read=o,this.cells=new Ee(o.cells)}at(e,o){return this.cells.get(e,o)}look(e){return this.ctx.book.looks[e.style]??{}}code(e){return this.look(e).format}text(e){return e.node?E(e.node):Me(C(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book;let s=-1;for(const i of e.cells)i.col>s&&(s=i.col);for(const i of e.columns){if(i.style===void 0)continue;const t=o[i.style];if(!(!t||k(t)))for(let n=i.min;n<=Math.min(i.max,s);n++)this.columnLooks.set(n,t)}for(const i of e.rows){const t=i.style===void 0?void 0:o[i.style];t&&!k(t)&&this.rowLooks.set(i.row,t)}const l=(i,t)=>{for(const n in t)if(!(n in i))return!1;return!0};for(const i of e.cells){const t=this.look(i),n=this.columnLooks.get(i.col);n&&!l(t,n)&&this.columnLooks.delete(i.col);const r=this.rowLooks.get(i.row);r&&!l(t,r)&&this.rowLooks.delete(i.row)}}ownLook(e){const o=this.columnLooks.get(e.col),s=this.rowLooks.get(e.row),l=this.look(e),i=l.format!==void 0&&z(l.format);if(!o&&!s&&!i){let f=this.ownLooks.get(e.style);return f||(f={look:l,key:se(l)},this.ownLooks.set(e.style,f)),f}const t={...o,...s},n={};for(const[f,c]of Object.entries(l))JSON.stringify(c)!==JSON.stringify(t[f])&&(n[f]=c);const r=n.format;if(typeof r=="string"){const f=e.node?void 0:R(C(this.ctx,e),r);f!==void 0&&F(f).format===r&&delete n.format}return{look:n,key:se(n)}}columnFormula(e,o,s){const l=new Map,i=s-o+1;for(let n=o;n<=s;n++){const r=this.at(n,e);if(!r||r.value===void 0&&!r.node||r.value===null&&!r.node)return;if(!r.node)continue;r.key??=B(r.node,r.row,r.col);const f=l.get(r.key);f?f.n+=1:l.set(r.key,{n:1,cell:r})}let t;for(const n of l.values())(!t||n.n>t.n)&&(t=n);return t&&t.n*2>i?t.cell:void 0}csv(e,o){const s=[];for(let l=0;l<e;l+=X){const i=[];for(let t=l;t<Math.min(e,l+X);t++)i.push(o(t));s.push(me(i))}return s.join("")}table(e){const{read:o,ctx:s}=this,l=p=>s.lost.push(`${o.name}: table ${e.name} ${p}`),i=e.ref.right-e.ref.left+1,t=oe(e);if(t!==void 0)return l(`${t}, so its cells are kept and it is no table`),!1;const n=e.ref.top,r=n+1,f=e.ref.bottom-e.totals;e.totals>0&&l("has a totals row, kept as plain cells under it");const c=e.columns.map((p,d)=>f>=r?this.columnFormula(e.ref.left+d,r,f):void 0),u=p=>{const d=c[p];if(!d)return!1;for(let g=r;g<=f;g++)if(this.at(g,e.ref.left+p)?.key!==d.key)return!1;return!0};let h=i;for(;h>1&&u(h-1);)h-=1;const w={},m=this.path(e.name);s.files.set(m,this.csv(f-r+2,p=>{if(p===0)return e.columns.slice(0,h).map(b=>b.name);const d=r+p-1,g=[];for(let b=0;b<h;b++){const x=this.at(d,e.ref.left+b),L=c[b];x?L&&x.key===L.key?g.push(""):x.node?g.push(E(te(x.node,e.name))):g.push(this.text(x)):g.push("")}return g})),this.inTables.add({...e.ref,bottom:f}),e.columns.forEach((p,d)=>{const g=e.ref.left+d,b=this.columnLook(g,r,f),x=c[d];x?.node&&(b.formula=E(te(we(x.node,r-x.row,0),e.name)));const L=this.fileColumns.get(g);L!==void 0&&r<=f&&(b.files=L===P?!0:{height:L}),k(b)||(w[p.name]=b)});const $=new Map;for(const[p,d]of e.filter?.columns??[]){const g=e.columns[p]?.name;g!==void 0&&$.set(g,d)}return(e.filter?.unread??0)>0&&l(`has ${G(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:y({row:n,col:e.ref.left}),rows:m,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...k(w)?{}:{columns:w},...e.filter===void 0?{filter:!1}:$.size>0?{filter:{columns:Object.fromEntries($)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:f}),this.areas.push({...e.ref,bottom:f}),!0}columnLook(e,o,s){let l,i={};for(let t=o;t<=s;t++){const n=this.at(t,e),r=n?this.ownLook(n):{look:{},key:"{}"};if(l===void 0)l=r.key,i=r.look;else if(l!==r.key)return{}}return k(i)?{}:(this.lookDone.add({top:o,bottom:s,left:e,right:e}),{...i})}path(e){const o=`${re}/${Y(e)}`;let s=`${o}.csv`;for(let l=2;this.ctx.files.has(s);l++)s=`${o}-${String(l)}.csv`;return s}loose(){const e=[],o=[];for(const s of this.read.cells)this.inTables.has(s.row,s.col)||(s.node?e.push(s):s.value!==void 0&&s.value!==null&&o.push(s));return{formulas:e,typed:o}}blockAreas(e,o){const s=[],l=O(o.map(S)),i=n=>!s.some(r=>A(r,n))&&!this.areas.some(r=>A(r,n))&&!l.some(r=>A(r,n)),t=n=>(n.bottom-n.top+1)*(n.right-n.left+1);for(const n of _e(e)){const{box:r}=n;if(!(t(r)<J)){if(n.count/t(r)>=ve&&i(r)){s.push(r);continue}for(const f of O(n.cells().map(S)))t(f)>=J&&i(f)&&s.push(f)}}return s.sort((n,r)=>n.top-r.top||n.left-r.left)}cells_(e){const{formulas:o,typed:s}=this.loose(),l=this.blockAreas(s,o),i=r=>l.some(f=>T(f,r.row,r.col));l.length>0&&(e.blocks=l.map(r=>{const f=this.path(this.read.name);return this.ctx.files.set(f,this.csv(r.bottom-r.top+1,c=>{const u=[];for(let h=r.left;h<=r.right;h++){const w=this.at(r.top+c,h);u.push(w?this.text(w):"")}return u})),{at:y({row:r.top,col:r.left}),rows:f}}));const t=[],n=new Map;for(const r of o){if(!r.node)continue;r.key??=B(r.node,r.row,r.col);const f=n.get(r.key);f?f.push(r):n.set(r.key,[r])}for(const r of n.values())for(const f of O(r.map(S))){const c=this.at(f.top,f.left);c?.node&&t.push([{row:f.top,col:f.left},v(f),E(c.node)])}for(const r of s)l.length>0&&i(r)||t.push([S(r),y(r),Oe(C(this.ctx,r),this.code(r))]);t.sort(([r],[f])=>r.row-f.row||r.col-f.col),t.length>0&&(e.cells=Object.fromEntries(t.map(([,r,f])=>[r,f])))}formats(e){const o=new Map,s=this.lookDone.list.length>0;for(const i of this.read.cells){if(s&&this.lookDone.has(i.row,i.col))continue;const t=this.ownLook(i);if(k(t.look))continue;const n=o.get(t.key);n?n.places.push(S(i)):o.set(t.key,{look:t.look,places:[S(i)]})}const l=[];for(const{look:i,places:t}of o.values())for(const n of O(t))l.push({range:v(n),...i});l.length>0&&(e.format=l)}columns(e){const{read:o}=this,s=new Map;let l=0;for(const t of o.cells)t.col>l&&(l=t.col);const i=[];for(const t of o.columns){if(t.width===void 0&&t.hidden!==!0&&t.level===void 0)continue;const n=t.max-Math.max(t.min,l+1)+1>Z?Math.max(l,t.min+Z-1):t.max;n<t.max&&i.push(`${M(n+1)}:${M(t.max)}`);for(let r=t.min;r<=n;r++)s.set(r,{...t.width===void 0?{}:{width:t.width},...t.hidden===!0?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}})}for(const[t,n]of this.columnLooks)s.set(t,{...s.get(t),...n});for(const[t,n]of this.fileColumns)this.tableColumn(t)||s.set(t,{...s.get(t),files:n===P?!0:{height:n}});s.size>0&&(e.columns=Object.fromEntries([...s.keys()].sort((t,n)=>t-n).map(t=>[M(t),s.get(t)??{}]))),i.length>0&&this.ctx.lost.push(`${o.name}: the size of columns ${D(i)}, past those that hold anything`)}tableColumn(e){return this.areas.some(o=>e>=o.left&&e<=o.right)}rows(e){const o={};for(const s of this.read.rows){const l=this.rowLooks.get(s.row),i=this.filtered.some(r=>s.row>r.top&&s.row<=r.bottom),t=s.height!==void 0&&this.pictured.get(s.row)!==s.height?s.height:void 0,n={...t===void 0?{}:{height:t},...s.hidden===!0&&!i?{hidden:!0}:{},...s.level===void 0?{}:{level:s.level},...l};k(n)||(o[String(s.row+1)]=n)}k(o)||(e.rows=o)}assetPath(e,o){const s=t=>{const n=this.ctx.assets.get(t);return!n||Ae(n,o.bytes)};if(e!==void 0&&Q(e)&&s(e))return e;const l=Y((o.name??"picture").replace(/\.[A-Za-z0-9]+$/u,""));let i=`${j}/${l}.${o.type}`;for(let t=2;!s(i);t++)i=`${j}/${l}-${String(t)}.${o.type}`;return i}pictures(){const e=this.over;for(const o of this.read.pictures){const s=this.at(o.row,o.col),l=typeof s?.value=="string"?s.value:"";if(o.y===void 0&&o.descr!==void 0&&Q(o.descr)&&l.split(fe).includes(o.descr)&&o.descr!==void 0){this.ctx.assets.set(o.descr,o.bytes),this.fileColumns.set(o.col,Math.max(this.fileColumns.get(o.col)??0,o.height)),this.pictured.set(o.row,Math.max(this.pictured.get(o.row)??0,o.height));continue}const t=this.assetPath(o.descr,o);this.ctx.assets.set(t,o.bytes);const n=pe(o.bytes),r=n?.width===o.width&&n.height===o.height;e.push({file:t,at:y({row:o.row,col:o.col}),...o.x===void 0?{}:{x:o.x},...o.y===void 0?{}:{y:o.y},...r?{}:{width:o.width,height:o.height}})}}build(){const{read:e}=this;this.baseLooks(),this.pictures();for(const s of e.tables)this.table(s);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=y(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells_(o),e.merges.length>0&&(o.merges=e.merges.map(v)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(s=>this.chart(s))),this.over.length>0&&(o.pictures=this.over),k(e.links)||(o.links=e.links),e.notes.length>0&&(o.notes=Object.fromEntries(e.notes.map(s=>[s.ref,s.author===void 0||s.author===le?s.text:{text:s.text,author:s.author}]))),e.print&&(o.print=e.print),e.protect===!0&&(o.protect=!0),o}chart(e){return ce(e,o=>{const s=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${s}`:s})}chartReference(e){const o=e.lastIndexOf("!"),l=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),i=W(e.slice(o+1).replaceAll("$",""));if(!i)return e;const t=this.ctx.book.sheets.find(n=>n.name.toLowerCase()===l.toLowerCase());for(const n of t?.tables??[]){const r=n.ref.top+1,c=i.left===i.right&&i.top===r&&i.bottom===n.ref.bottom&&i.left>=n.ref.left&&i.left<=n.ref.right?n.columns[i.left-n.ref.left]:void 0;if(c&&this.ctx.tables.has(n.name.toLowerCase()))return`${n.name}[${c.name}]`}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${v(i)}`}filter(e){const{filter:o}=this.read;if(!o)return;const s={};for(const[l,i]of o.columns)s[M(o.ref.left+l)]=i;e.filter={range:v(o.ref),...k(s)?{}:{columns:s}},o.unread===0&&!k(s)&&this.filtered.push(o.ref)}}const Ae=(a,e)=>a.length===e.length&&a.every((o,s)=>o===e[s]),ze=new Set(["_xlnm._FilterDatabase","_xlnm.Print_Area","_xlnm.Print_Titles"]);function He(a){const e={},o=[],s=new Map,{book:l,lost:i}=a,t=new Set(l.sheets.map(f=>f.name.toLowerCase())),n=new Set,r=f=>{const c=Ie(f.text);if(c!==void 0)return typeof c=="string"?I(c):c;const u=$e(f.text,!0),h=u.ok?ne(u.node,t):"it could not be read";if(!u.ok||h!==void 0||Fe(u.node)){i.push(`the name ${f.name} (${f.text})${h===void 0?"":`: ${h}`}`);return}return E(u.node)};for(const f of l.names){if(f.name.startsWith("_xlnm.")){ze.has(f.name)||i.push(`Excel's name ${f.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(f.name))continue;const c=f.name.toLowerCase(),u=f.sheet===void 0?"":String(f.sheet);if(!V(f.name)||a.tables.has(c)){i.push(`the name ${f.name}, which cannot be held here`);continue}if(n.has(`${u}|${c}`)){i.push(`a second name ${f.name}${u===""?"":` of ${l.sheets[f.sheet??0]?.name??""}`}`);continue}const h=r(f);if(h!==void 0)if(n.add(`${u}|${c}`),a.names.add(c),f.sheet===void 0)e[f.name]=h,f.hidden===!0&&o.push(f.name);else{const w=s.get(f.sheet)??{names:{},hidden:[]};w.names[f.name]=h,f.hidden===!0&&w.hidden.push(f.name),s.set(f.sheet,w)}}return{names:e,hidden:o,sheets:s}}function Ne(a,e){const o={},s=new Map;for(const[l,i]of Object.entries(e))typeof i=="string"&&i.startsWith("=")&&s.set(i.slice(1).replaceAll("$","").toLowerCase(),l);for(const l of a.book.sheets)for(const i of l.scenarios){const t={};let n=!0;for(const{at:r,value:f}of i.cells){const c=ae(r),u=c&&l.cells.find(m=>m.row===c.row&&m.col===c.col);String(u?.value??"")!==f&&(n=!1);const h=s.get(`${U(l.name)}${r}`.toLowerCase())??s.get(r.toLowerCase()),w=F(f);h===void 0?a.lost.push(`${l.name}: scenario ${i.name}'s cell ${r}, which has no name`):t[h]=typeof w.value=="number"?w.value:f}!n&&!k(t)&&(o[i.name]={...o[i.name],...t})}return o}function Fe(a){let e=!1;return H(a,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function Ie(a){const e=a.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const De=new RegExp(`^${Le.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?: \\(\\d+\\))?$`,"u");function Re(a){const e=a.sheets.find(i=>i.state==="veryHidden"&&De.test(i.name));if(!e)return;const o=U(e.name).toLowerCase(),s=i=>{const t=i.replace(/^=/u,"");if(!t.toLowerCase().startsWith(o))return;const n=W(t.slice(o.length).replaceAll("$",""));if(!n||n.left!==n.right)return;const r=[];for(let f=n.top;f<=n.bottom;f++){const c=e.cells.find(u=>u.row===f&&u.col===n.left);r.push(typeof c?.value=="string"?c.value:"")}return r};for(const i of a.sheets)i.validations=i.validations.map(t=>{const[n]=t.formula??[],r=t.type==="list"&&typeof n=="string"?s(n):void 0;if(!r)return t;const f={...t,values:r};return delete f.formula,f});const l=a.sheets.indexOf(e);a.sheets=a.sheets.filter(i=>i!==e),a.names=a.names.flatMap(i=>i.sheet===void 0||i.sheet<l?[i]:i.sheet===l?[]:[{...i,sheet:i.sheet-1}])}const _=a=>a instanceof N?a.code:a??null;export function sameValue(a,e,o){if(typeof a=="number"&&typeof e=="number")return a===e?!0:Math.abs(a-e)<=Math.max(Math.abs(a),Math.abs(e))*o;if(a instanceof N||e instanceof N)return a?.code===e?.code;if(a===null||e===null){const s=a??e;return s===null||s===""||s===0||s===!1}return a===e}function je(a,e){const o=[];for(const i of e.sheets)for(const t of i.formulas)t.shared.node&&ue(e,t.shared,i).volatile&&o.push(t);const s=new Set(o),l=[...o];for(;;){const i=l.pop();if(!i)return s;for(const t of a.readers(i.sheet,i.row,i.col))s.has(t)||(s.add(t),l.push(t))}}function Pe(a,e,o,s){const l={formulas:0,same:0,uncached:0,moving:0,differences:[]},i=je(o,e);for(const[t,n]of a.carried){if(!t.node)continue;const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.at(t.row,t.col);if(f instanceof be&&i.has(f)){l.moving+=1;continue}const c=C(a,t);if(c===void 0){l.uncached+=1;continue}const u=o.value(r,t.row,t.col);sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:E(t.node),file:_(c),engine:_(u)})}for(const[t,n]of a.spilled){const r=e.sheet(n.name);if(!r)continue;l.formulas+=1;const f=r.spillAt(t.row,t.col);if(f&&i.has(f)){l.moving+=1;continue}const c=C(a,t),u=o.value(r,t.row,t.col);c===void 0?l.uncached+=1:sameValue(c,u,s)?l.same+=1:l.differences.push({sheet:n.name,cell:y(t),formula:f?`${y(f)}#`:"",file:_(c),engine:_(u)})}return l}function We(a,e){const o=new Map,s=[];for(const l of a){const i=e.find(r=>l.startsWith(`${r}: `));if(i===void 0){s.push(l);continue}const t=l.slice(i.length+2),n=o.get(t);n?n.push(i):o.set(t,[i])}for(const[l,i]of o)s.push(i.length===1?`${i[0]??""}: ${l}`:`${l}, on ${String(i.length)} sheets (${D(i)})`);return s}export function importXlsx(a,e){const o=xe(a,e.zip);if(Re(o),o.sheets.length===0)throw new Error("It holds no sheets.");const s={book:o,files:new Map,assets:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(m=>m.tables.filter($=>oe($)===void 0).map($=>$.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&s.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(K)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&s.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const l=He(s);Se(s);const i=o.sheets.map((m,$)=>{const p=new Te(s,m).build(),d=l.sheets.get($);return d&&!k(d.names)&&(p.names=d.names),d&&d.hidden.length>0&&(p.hidden_names=d.hidden),p}),t=Ne(s,l.names),n={title:o.title??e.name,...k(l.names)?{}:{names:l.names},...l.hidden.length>0?{hidden_names:l.hidden}:{},sheets:i,...k(t)?{}:{scenarios:t}},r=ye(n),f=new Map([[ie,r],...s.files]),c=de({text:r,read:m=>f.get(m),exists:m=>f.has(m)||s.assets.has(m)}),{workbook:u,calc:h,problems:w}=c;return{files:f,assets:s.assets,lost:We(s.lost,o.sheets.map(m=>m.name)),problems:w,compared:u&&h?Pe(s,u,h,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:s.tables.size}}
@@ -1,4 +1,5 @@
1
- import type { SheetConditional, SheetFilterColumn, SheetValidation } from "@allyhub-next/formats";
1
+ import { type ZipLimits } from "@allyhub-next/formats";
2
+ import type { SheetConditional, SheetFilterColumn, SheetHeaderFooter, SheetPrint, SheetValidation } from "@allyhub-next/formats";
2
3
  import { type Area, type Place } from "../address.js";
3
4
  import type { Node } from "../formula/ast.js";
4
5
  import { type Scalar } from "../values.js";
@@ -31,6 +32,8 @@ export interface ReadColumn {
31
32
  width?: number;
32
33
  hidden?: boolean;
33
34
  style?: number;
35
+ /** Its outline level. */
36
+ level?: number;
34
37
  }
35
38
  export interface ReadRow {
36
39
  row: number;
@@ -38,6 +41,8 @@ export interface ReadRow {
38
41
  height?: number;
39
42
  hidden?: boolean;
40
43
  style?: number;
44
+ /** Its outline level. */
45
+ level?: number;
41
46
  }
42
47
  /** A filter's columns by their place in it, and those that say what this cannot read. */
43
48
  export interface ReadFilter {
@@ -58,6 +63,27 @@ export interface ReadTable {
58
63
  /** Its filter buttons; nothing when it has none. */
59
64
  filter?: ReadFilter;
60
65
  }
66
+ /** A Note on a cell. */
67
+ export interface ReadNote {
68
+ ref: string;
69
+ text: string;
70
+ author?: string;
71
+ }
72
+ /** A picture of a sheet's drawing, with its image. */
73
+ export interface ReadPicture {
74
+ row: number;
75
+ col: number;
76
+ x?: number;
77
+ y?: number;
78
+ width: number;
79
+ height: number;
80
+ name?: string;
81
+ /** Its description: the file it was, when AllyHub wrote it. */
82
+ descr?: string;
83
+ /** Its image, and the extension its part has. */
84
+ bytes: Uint8Array;
85
+ type: string;
86
+ }
61
87
  export interface ReadSheet {
62
88
  name: string;
63
89
  state: "visible" | "hidden" | "veryHidden";
@@ -86,6 +112,14 @@ export interface ReadSheet {
86
112
  value: string;
87
113
  }[];
88
114
  }[];
115
+ /** By address (a range for a link over several cells): an address on the web, or `#Sheet!A1`. */
116
+ links: Record<string, string>;
117
+ notes: ReadNote[];
118
+ pictures: ReadPicture[];
119
+ /** Protect Sheet is on. */
120
+ protect?: boolean;
121
+ /** Page Layout. */
122
+ print?: SheetPrint;
89
123
  }
90
124
  export interface ReadName {
91
125
  name: string;
@@ -93,6 +127,8 @@ export interface ReadName {
93
127
  text: string;
94
128
  /** The sheet it belongs to, by its place; absent: the workbook. */
95
129
  sheet?: number;
130
+ /** Excel's Name Manager does not list it. */
131
+ hidden?: boolean;
96
132
  }
97
133
  export interface ReadBook {
98
134
  sheets: ReadSheet[];
@@ -107,11 +143,17 @@ export interface ReadBook {
107
143
  name?: string;
108
144
  size?: number;
109
145
  };
146
+ /** Its title, from its document properties. */
147
+ title?: string;
110
148
  /** What this model holds nothing of, a line each. */
111
149
  lost: string[];
112
150
  }
113
151
  /** Places as a line: the first few and how many more. */
114
152
  export declare function placesLine(places: readonly string[]): string;
153
+ /** Where Excel's grid ends, as an error says it. */
154
+ export declare const GRID_END: string;
155
+ /** Excel's header or footer codes as its three parts: &L, &C, &R; what comes before any is the centre's. */
156
+ export declare function readHeaderFooter(text: string): SheetHeaderFooter;
115
157
  /** What a .xlsx, .xlsm or .xltx file holds. */
116
- export declare function readXlsx(bytes: Uint8Array): ReadBook;
158
+ export declare function readXlsx(bytes: Uint8Array, zip?: Partial<ZipLimits>): ReadBook;
117
159
  //# sourceMappingURL=read.d.ts.map
@@ -1,2 +1,3 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{strFromU8 as ie,unzipSync as ae}from"fflate";import{SHEET_ICONS as le,SHEET_OPERATORS as ce,SHEET_VALIDATIONS as de}from"@allyhub-next/formats";import{cellName as J,readAddress as K,readArea as z,readAreas as Q}from"../address.js";import{SHEET_CHART_DEFAULTS as Y}from"../chart.js";import{moveFormula as ue,relativeKey as fe}from"../formula/move.js";import{printFormula as Z}from"../formula/print.js";import{ERR as me,errorOf as he,serialOfDate as pe}from"../values.js";import{OFFICE_THEME as be,colorOf as C,paletteOf as ee,themeColors as ge}from"./colors.js";import{chartAnchors as xe,readChart as ye}from"./charts.js";import{readFileFormula as P}from"./formula.js";import{BUILTIN_FORMATS as we}from"./numfmt.js";import{attr as d,flag as k,numberAttr as x,readXml as ve,readXstring as L,tag as l,tags as b,textOf as F}from"./xml.js";const te=7,ke=o=>Math.floor((256*o+Math.floor(128/te))/256*te),$e=o=>Math.round(o*4/3),B=5;export function placesLine(o){const e=o.slice(0,B).join(", ");return o.length>B?`${e} and ${String(o.length-B)} more`:e}const H=(o,e,t=`${e}s`)=>`${String(o)} ${o===1?e:t}`;class Se{parts;names;constructor(e){this.parts=ae(e),this.names=Object.keys(this.parts)}has(e){return this.parts[e]!==void 0}text(e){const t=this.parts[e];return t?ie(t):void 0}xml(e){const t=this.text(e);return t===void 0?void 0:ve(t)}rels(e){const t=e.lastIndexOf("/"),n=`${e.slice(0,t+1)}_rels/${e.slice(t+1)}.rels`,s=this.xml(n);return b(l(s?.Relationships)?.Relationship).map(r=>{const a=d(r,"Type")??"",c=d(r,"Target")??"",i=d(r,"TargetMode")==="External";return{id:d(r,"Id")??"",type:a.slice(a.lastIndexOf("/")+1),target:i?c:Te(e,c),external:i}})}count(e){return this.names.filter(t=>e.test(t)).length}}function Te(o,e){if(e.startsWith("/"))return e.slice(1);const t=o.split("/").slice(0,-1);for(const n of e.split("/"))n===".."?t.pop():n!=="."&&t.push(n);return t.join("/")}function Ee(o,e){const t=e===void 0?void 0:o.xml(e);return b(l(t?.sst)?.si).map(n=>{const s=b(n.r);return s.length>0?{text:L(s.map(r=>F(r.t)).join("")),rich:!0}:{text:L(F(n.t)),rich:!1}})}function M(o,e){const t=o[e];if(t===void 0)return!1;const n=d(l(t),"val");return n===void 0||n!=="0"&&n!=="false"}const Oe=new Set(["double","singleAccounting","doubleAccounting"]);function Ie(o,e,t){const n={},s=(i,m)=>d(l(i?.[m]),"val");if(M(o,"b")&&(n.bold=!0),M(o,"i")&&(n.italic=!0),M(o,"strike")&&(n.strike=!0),M(o,"u")){const i=s(o,"u");n.underline=i!==void 0&&Oe.has(i)?i:!0}const r=s(o,"name");r!==void 0&&r!==s(e,"name")&&(n.font=r);const a=s(o,"sz");a!==void 0&&a!==s(e,"sz")&&(n.size=Number(a));const c=C(l(o.color),t);return c!==void 0&&c!==C(l(e?.color),t)&&(n.color=c),n}function Ae(o,e){const t=l(o.patternFill),n=d(t,"patternType");if(n===void 0||n==="none")return;const s=C(l(t?.fgColor),e),r=C(l(t?.bgColor),e);return n==="solid"&&s!==void 0?s:{pattern:n,...s===void 0?{}:{color:s},...r===void 0?{}:{background:r}}}function ne(o,e){const t={};for(const n of["left","right","top","bottom"]){const s=l(o[n]),r=d(s,"style");if(r===void 0||r==="none")continue;const a=C(l(s?.color),e);t[n]={style:r,...a===void 0?{}:{color:a}}}return Object.keys(t).length===0?void 0:t}function Ce(o){const e={},t=d(o,"horizontal");t!==void 0&&t!=="general"&&(e.align=t);const n=d(o,"vertical");n!==void 0&&n!=="bottom"&&(e.valign=n),k(o,"wrapText")===!0&&(e.wrap=!0),k(o,"shrinkToFit")===!0&&(e.shrink=!0);const s=x(o,"indent");s!==void 0&&s>0&&(e.indent=s);const r=x(o,"textRotation");return r!==void 0&&r>0&&r<=180&&(e.rotation=r),e}function Fe(o,e){const t={},n=l(o.font);if(n){const i=(f,u)=>{n[f]!==void 0&&(t[u]=M(n,f))};i("b","bold"),i("i","italic"),i("strike","strike"),n.u!==void 0&&(t.underline=M(n,"u"));const m=C(l(n.color),e);m!==void 0&&(t.color=m)}const s=l(l(o.fill)?.patternFill),r=C(l(s?.bgColor),e)??C(l(s?.fgColor),e);r!==void 0&&(t.fill=r);const a=l(o.border),c=a&&ne(a,e);return c!==void 0&&(t.border=c),t}function Re(o,e){const t=l(o?.styleSheet),n=ee(e,t),s=new Map(b(l(t?.numFmts)?.numFmt).map(p=>[x(p,"numFmtId")??-1,d(p,"formatCode")??"General"])),r=b(l(t?.fonts)?.font),a=b(l(t?.fills)?.fill),c=b(l(t?.borders)?.border),i=b(l(t?.cellXfs)?.xf),m=r[x(i[0],"fontId")??0],f=new Set;a.some(p=>p.gradientFill!==void 0)&&f.add("gradient fills");const u=i.map(p=>{const y={},$=r[x(p,"fontId")??0];$&&(Object.assign(y,Ie($,m,n)),$.vertAlign!==void 0&&f.add("superscript and subscript"));const T=a[x(p,"fillId")??0],O=T&&Ae(T,n);O!==void 0&&(y.fill=O);const R=c[x(p,"borderId")??0],I=R&&ne(R,n);I!==void 0&&(y.border=I),R&&d(l(R.diagonal),"style")!==void 0&&f.add("diagonal borders");const w=l(p.alignment);w&&(Object.assign(y,Ce(w)),x(w,"textRotation")===255&&f.add("vertical text"));const S=x(p,"numFmtId")??0,A=s.get(S)??we[S];return A!==void 0&&A!=="General"&&(y.format=A),y}),h=d(l(m?.name),"val"),v=d(l(m?.sz),"val");return{looks:u,dxfs:b(l(t?.dxfs)?.dxf).map(p=>Fe(p,n)),font:{...h===void 0?{}:{name:h},...v===void 0?{}:{size:Number(v)}},lost:[...f]}}function oe(o){const e=new Map;let t=0;for(const n of b(o.filterColumn)){const s=x(n,"colId")??0,r=l(n.filters);if(!r){Object.keys(n).some(c=>c!=="colId"&&c!=="hiddenButton")&&(t+=1);continue}if(r.dateGroupItem!==void 0){t+=1;continue}const a=b(r.filter).map(c=>L(d(c,"val")??""));e.set(s,{...a.length===0?{}:{values:a},...k(r,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:t}}function Le(o){const e=l(o?.table),t=z(d(e,"ref")??""),n=d(e,"displayName")??d(e,"name");if(!t||n===void 0)return;const s=l(e?.tableStyleInfo),r=l(e?.autoFilter);return{name:n,ref:t,headers:x(e,"headerRowCount")??1,totals:x(e,"totalsRowCount")??0,columns:b(l(e?.tableColumns)?.tableColumn).map(a=>({name:L(d(a,"name")??"").trim(),calculated:a.calculatedColumnFormula!==void 0})),style:d(s,"name")??"none",...r?{filter:oe(r)}:{}}}function W(o){const e=o.trim();if(e==="")return;const t=/^"((?:[^"]|"")*)"$/u.exec(e);if(t)return(t[1]??"").replaceAll('""','"');const n=Number(e);if(!Number.isNaN(n))return n;const s=P(e,!0);return s.ok?Z(s.node):void 0}const re=o=>o!==void 0&&ce.includes(o);function q(o){const e=d(o,"type")??"num",t=d(o,"val"),n=t===void 0?void 0:W(t);return{at:e,...n===void 0?{}:{value:n}}}const Ne=le;function je(o,e,t,n){const s=d(o,"type")??"",r={range:e,...k(o,"stopIfTrue")===!0?{stop:!0}:{}},a=x(o,"dxfId"),c=a===void 0?{}:t[a]??{},i={...c.bold===void 0?{}:{bold:c.bold},...c.italic===void 0?{}:{italic:c.italic},...c.underline===void 0?{}:{underline:c.underline!==!1},...c.strike===void 0?{}:{strike:c.strike},...c.color===void 0?{}:{color:c.color},...typeof c.fill=="string"?{fill:c.fill}:{},...c.border===void 0?{}:{border:c.border}},m=o.formula,f=(Array.isArray(m)?m:m===void 0?[]:[m]).map(F);switch(s){case"cellIs":{const u=d(o,"operator"),h=f.flatMap(v=>{const p=W(v);return p===void 0?[]:[p]});return!re(u)||h.length===0?`a cellIs rule of ${u??"no operator"}`:{...r,...i,type:"cellIs",operator:u,formula:h}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const u=d(o,"text");return u===void 0?`a ${s} rule with no text`:{...r,...i,type:"containsText",...s==="containsText"?{}:{operator:s==="notContainsText"?"notContains":s},text:L(u)}}case"duplicateValues":case"uniqueValues":return{...r,...i,type:s};case"top10":return{...r,...i,type:"top10",rank:x(o,"rank")??10,...k(o,"percent")===!0?{percent:!0}:{},...k(o,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return{...r,...i,type:"aboveAverage",...k(o,"aboveAverage")===!1?{below:!0}:{},...k(o,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const u=f[0]===void 0?void 0:P(f[0],!0);return u?.ok?{...r,...i,type:"expression",formula:Z(u.node)}:"an expression rule that cannot be read"}case"dataBar":{const u=l(o.dataBar),h=C(l(u?.color),n),[v,p]=b(u?.cfvo).map(q);return h===void 0?"a data bar with no colour":{...r,type:"dataBar",color:h,...v&&v.at!=="min"?{min:v}:{},...p&&p.at!=="max"?{max:p}:{},...k(u,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const u=l(o.colorScale),h=b(u?.cfvo).map(q),v=b(u?.color).map(y=>C(y,n)),p=h.flatMap((y,$)=>{const T=v[$];return T===void 0?[]:[{...y,color:T}]});return p.length<2?"a colour scale with too few stops":{...r,type:"colorScale",stops:p.slice(0,3)}}case"iconSet":{const u=l(o.iconSet),h=d(u,"iconSet")??"3TrafficLights1";if(!Ne.includes(h))return`the icon set ${h}`;const v=b(u?.cfvo).map(q);return{...r,type:"iconSet",icons:h,...v.length>=3?{stops:v.slice(0,5)}:{},...k(u,"reverse")===!0?{reverse:!0}:{},...k(u,"showValue")===!1?{show:!1}:{}}}default:return`a ${s} rule`}}function Me(o,e,t){const n=[],s=[];for(const r of b(o.conditionalFormatting)){const a=d(r,"sqref")??"";if(!Q(a)){s.push(`a rule on ${a}`);continue}for(const c of b(r.cfRule)){const i=je(c,a,e,t);typeof i=="string"?s.push(`${i} on ${a}`):n.push({priority:x(c,"priority")??0,rule:i})}}return{rules:n.sort((r,a)=>r.priority-a.priority).map(r=>r.rule),unread:s}}const De=de;function Ve(o){const e=[],t=[];for(const n of b(l(o.dataValidations)?.dataValidation)){const s=d(n,"sqref")??"",r=d(n,"type")??"none";if(r==="none"&&d(n,"prompt")===void 0)continue;if(!De.includes(r)||!Q(s)){t.push(`a ${r} rule on ${s}`);continue}const a=F(n.formula1),c=F(n.formula2),i=/^"((?:[^"]|"")*)"$/u.exec(a.trim()),m=r==="list"&&i?(i[1]??"").replaceAll('""','"').split(","):void 0,f=[a,c].flatMap(T=>{const O=W(T);return O===void 0?[]:[O]}),u=d(n,"operator"),h=T=>Object.fromEntries(Object.entries(T).filter(([,O])=>O!==void 0)),v=h({title:d(n,"promptTitle"),message:d(n,"prompt")}),p=h({style:d(n,"errorStyle"),title:d(n,"errorTitle"),message:d(n,"error")}),y=k(n,"showInputMessage")!==!0,$=k(n,"showErrorMessage")!==!0;e.push({range:s,type:r,...re(u)&&u!=="between"?{operator:u}:{},...m?{values:m}:{formula:f},...k(n,"allowBlank")===!0?{}:{blank:!1},...k(n,"showDropDown")===!0?{dropdown:!1}:{},...y||Object.keys(v).length>0?{prompt:{...v,...y?{show:!1}:{}}}:{},...$||Object.keys(p).length>0?{error:{...p,...$?{show:!1}:{}}}:{}})}return{rules:e,unread:t}}function U(o,e){const t=P(o,e);return t.ok?{node:t.node}:{unread:o}}class ze{cells=[];rich=[];masters=new Map;strings;constructor(e){this.strings=e}value(e,t){const n=d(e,"t")??"n",s=e.v;if(n==="inlineStr"){const a=l(e.is),c=b(a?.r);return c.length>0?{value:L(c.map(i=>F(i.t)).join("")),rich:!0}:{value:L(F(a?.t))}}if(s===void 0)return{value:void 0};const r=F(s);switch(n){case"s":{const a=this.strings[Number(r)];return a?{value:a.text,...a.rich?{rich:!0}:{}}:{value:""}}case"str":return{value:L(r)};case"b":return{value:r.trim()==="1"||r.trim()==="true"};case"e":return{value:he(r.trim())??me.VALUE};case"d":{const a=new Date(r.trim());return{value:Number.isNaN(a.getTime())?r:pe(a)}}default:{if(r.trim()==="")return{value:void 0};const a=Number(r);if(Number.isNaN(a))throw new Error(`${t} says it holds a number and holds ${r}.`);return{value:a}}}}formula(e,t,n,s){const r=e.f;if(r===void 0)return;const a=l(r),c=d(a,"t")??"normal",i=F(r);if(c==="dataTable"){s.unread=`a data table's {=TABLE(${d(a,"r1")??""})}`;return}if(c==="array"){const m=e.cm!==void 0;Object.assign(s,U(i,!0));const f=z(d(a,"ref")??"");f&&(s.array=f),m&&(s.dynamic=!0);return}if(c==="shared"){const m=d(a,"si")??"";if(i!==""){const u=U(i,!1);this.masters.set(m,{node:u.node,unread:u.unread,row:t,col:n,key:u.node?fe(u.node,t,n):"",dynamicArray:!1}),Object.assign(s,u),u.node&&(s.key=this.masters.get(m)?.key??"");return}const f=this.masters.get(m);if(!f){s.unread=`a shared formula of a group that has no first cell (${m})`;return}f.node?(s.node=ue(f.node,t-f.row,n-f.col),s.key=f.key):f.unread!==void 0&&(s.unread=f.unread);return}i!==""&&Object.assign(s,U(i,!1))}readRows(e){let t=0;for(const n of e){const s=x(n,"r"),r=s===void 0?t:s-1;t=r+1;let a=0;for(const c of b(n.c)){const i=d(c,"r"),f=(i===void 0?void 0:K(i))?.col??a;a=f+1;const u=i??J({row:r,col:f}),{value:h,rich:v}=this.value(c,u),p={row:r,col:f,value:h,style:x(c,"s")??0};v===!0&&(p.rich=!0,this.rich.push(u)),this.formula(c,r,f,p),this.cells.push(p)}}}}function He(o,e,t){const n=[],s=i=>n.push(`${o}: ${i}`);t.length>0&&s(`${H(t.length,"cell")} of rich text, kept as plain text (${placesLine(t)})`);const r=b(l(e.hyperlinks)?.hyperlink);r.length>0&&s(`${H(r.length,"hyperlink")} (${placesLine(r.map(i=>d(i,"ref")??""))})`),e.sortState!==void 0&&s("a sort"),k(l(e.sheetProtection),"sheet")===!0&&s("protection"),e.protectedRanges!==void 0&&s("protected ranges"),e.headerFooter!==void 0&&F(e.headerFooter).trim()!==""&&s("its print header and footer"),l(e.headerFooter)?.oddHeader!==void 0&&s("its print header"),l(e.headerFooter)?.oddFooter!==void 0&&s("its print footer"),(e.rowBreaks!==void 0||e.colBreaks!==void 0)&&s("its page breaks"),e.oleObjects!==void 0&&s("embedded objects"),e.controls!==void 0&&s("form controls"),e.dataConsolidate!==void 0&&s("a consolidation"),e.customSheetViews!==void 0&&s("custom views"),b(l(e.sheetViews)?.sheetView).some(i=>d(l(i.pane),"state")==="split")&&s("a split, not frozen, window");const c=JSON.stringify(e.extLst??"");return c.includes("sparklineGroups")&&s("sparklines"),X(e.extLst)&&s("conditional formats of Excel 2010 and later"),c.includes("dataValidations")&&s("data validations of Excel 2010 and later"),c.includes("slicerList")&&s("slicers"),n}function X(o){if(typeof o!="object"||o===null)return!1;if(Array.isArray(o))return o.some(X);const e=o;return b(e.cfRule).some(t=>d(t,"type")!=="dataBar")&&e.cfRule!==void 0?!0:Object.values(e).some(X)}function _e(o){const e=[],t=(n,s,r)=>{const a=o.count(n);a>0&&e.push(H(a,s,r))};return o.has("xl/vbaProject.bin")&&e.push("VBA macros"),t(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),t(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),t(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),t(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet"),t(/^xl\/media\//u,"image"),t(/^xl\/embeddings\//u,"embedded object"),t(/^xl\/comments\d*\.xml$/u,"sheet's comments","sheets' comments"),t(/^xl\/threadedComments\//u,"sheet's threaded comments","sheets' threaded comments"),t(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),t(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),t(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),t(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),t(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),o.has("xl/connections.xml")&&e.push("data connections"),o.names.some(n=>n.startsWith("xl/richData/"))&&e.push("rich values (data types, pictures in cells)"),o.names.some(n=>/^customXml\/item\d+\.xml$/u.test(n)&&(o.text(n)??"").includes("DataMashup"))&&e.push("Power Query queries"),e}function Pe(o,e,t,n,s,r,a){const c=o.xml(e),i=l(c?.worksheet);if(!i)throw new Error(`${e} is not a worksheet.`);const m=new ze(s);m.readRows(b(l(i.sheetData)?.row));const f=b(l(i.cols)?.col).map(g=>{const E=x(g,"width"),D=x(g,"style");return{min:(x(g,"min")??1)-1,max:(x(g,"max")??1)-1,...E===void 0||k(g,"customWidth")===!1?{}:{width:ke(E)},...k(g,"hidden")===!0?{hidden:!0}:{},...D===void 0||D===0?{}:{style:D}}}),u=[];let h=b(l(i.cols)?.col).some(g=>(x(g,"outlineLevel")??0)>0);b(l(i.sheetData)?.row).forEach((g,E)=>{const D=(x(g,"r")??E+1)-1;(x(g,"outlineLevel")??0)>0&&(h=!0);const G=x(g,"ht"),_=x(g,"s"),V={row:D};G!==void 0&&k(g,"customHeight")===!0&&(V.height=$e(G)),k(g,"hidden")===!0&&(V.hidden=!0),_!==void 0&&_!==0&&k(g,"customFormat")===!0&&(V.style=_),Object.keys(V).length>1&&u.push(V)});const v=b(l(i.mergeCells)?.mergeCell).flatMap(g=>{const E=z(d(g,"ref")??"");return E?[E]:[]}),p=b(l(i.sheetViews)?.sheetView)[0],y=l(p?.pane);let $;const T=d(y,"state");if(T==="frozen"||T==="frozenSplit"){const g=K(d(p,"topLeftCell")??"A1")??{row:0,col:0};$={row:g.row+(x(y,"ySplit")??0),col:g.col+(x(y,"xSplit")??0)}}const O=o.rels(e).filter(g=>g.type==="table").flatMap(g=>{const E=Le(o.xml(g.target));return E?[E]:[]}),R=C(l(l(i.sheetPr)?.tabColor),r),I=He(t,i,m.rich);h&&I.push(`${t}: its grouped rows or columns, left ungrouped`);const w=Me(i,a,r),S=Ve(i);for(const g of w.unread)I.push(`${t}: a conditional format, ${g}`);for(const g of S.unread)I.push(`${t}: a data validation, ${g}`);const A=l(i.autoFilter),j=z(d(A,"ref")??""),N=A&&j?{ref:j,...oe(A)}:void 0;N&&N.unread>0&&I.push(`${t}: ${H(N.unread,"filter")} by condition on ${d(A,"ref")??""}, its rows left as they were hidden`);const se=qe(o,e,t,f,u,I);return{sheet:{name:t,state:n,cells:m.cells,merges:v,...$?{freeze:$}:{},...d(p,"showGridLines")==="0"?{gridlines:!1}:{},...R===void 0?{}:{tab:R},columns:f,rows:u,tables:O,conditional:w.rules,validations:S.rules,scenarios:b(l(i.scenarios)?.scenario).map(g=>({name:d(g,"name")??"",cells:b(g.inputCells).map(E=>({at:d(E,"r")??"",value:d(E,"val")??""}))})),...N?{filter:N}:{},charts:se},lost:I}}const Be=64,We=20;function qe(o,e,t,n,s,r){const a=m=>n.find(f=>m>=f.min&&m<=f.max)?.width??Be,c=m=>s.find(f=>f.row===m)?.height??We,i=[];for(const m of o.rels(e).filter(f=>f.type==="drawing")){const{anchors:f}=xe(o.xml(m.target),a,c),u=o.rels(m.target);for(const h of f){const v=u.find($=>$.id===h.id),p=ye(v?o.xml(v.target):void 0),y=J(h.at);if(typeof p=="string"){r.push(`${t}: the chart at ${y}, as ${p}`);continue}i.push({...p,at:y,...h.x===void 0?{}:{x:h.x},...h.y===void 0?{}:{y:h.y},...h.width===Y.width?{}:{width:h.width},...h.height===Y.height?{}:{height:h.height}})}}return i}export function readXlsx(o){let e;try{e=new Se(o)}catch{throw new Error("It is not a zip file, as an .xlsx file is.")}const n=e.rels("").find(w=>w.type==="officeDocument")?.target??"xl/workbook.xml";if(n.endsWith(".bin"))throw new Error("It is a binary workbook (.xlsb): save it as .xlsx.");const s=e.xml(n),r=l(s?.workbook);if(!r)throw new Error("It has no workbook part.");const a=e.rels(n),c=w=>a.find(S=>S.type===w)?.target,i=(()=>{const w=c("theme");return w===void 0?void 0:e.text(w)})(),m=i===void 0?be:ge(i),f=c("styles"),u=f===void 0?void 0:e.xml(f),h=Re(u,m),v=ee(m,l(u?.styleSheet)),p=Ee(e,c("sharedStrings")),y=[..._e(e)];for(const w of h.lost)y.push(w);const $=l(r.workbookPr),T=l(r.calcPr);k(T,"iterate")===!0&&y.push("iterative calculation");const O=l(r.workbookProtection);(k(O,"lockStructure")===!0||k(O,"lockWindows")===!0)&&y.push("the workbook's protection"),r.fileSharing!==void 0&&y.push("its write protection");const R=[],I=new Map(a.map(w=>[w.id,w]));for(const w of b(l(r.sheets)?.sheet)){const S=I.get(d(w,"id")??""),A=L(d(w,"name")??"");if(S?.type!=="worksheet"){S?.type!=="chartsheet"&&S?.type!=="dialogsheet"&&y.push(`${A}: a sheet of a kind this cannot read`);continue}const j=d(w,"state"),N=Pe(e,S.target,A,j==="hidden"||j==="veryHidden"?j:"visible",p,v,h.dxfs);R.push(N.sheet),y.push(...N.lost)}return{sheets:R,names:b(l(r.definedNames)?.definedName).map(w=>{const S=x(w,"localSheetId");return{name:d(w,"name")??"",text:L(F(w)),...S===void 0?{}:{sheet:S}}}),looks:h.looks,dxfs:h.dxfs,date1904:k($,"date1904")===!0,font:h.font,lost:y}}
2
+ import{ZipLimitError as ve}from"@allyhub-next/formats";import{SHEET_ICONS as Se,SHEET_MARGINS as de,SHEET_OPERATORS as Ce,SHEET_PAPERS as Ee,SHEET_VALIDATIONS as Ne}from"@allyhub-next/formats";import{MAX_COLUMNS as q,MAX_ROWS as K,cellName as Y,columnLetter as Ae,readAddress as Oe,readArea as G,readAreas as ee}from"../address.js";import{SHEET_CHART_DEFAULTS as ce}from"../chart.js";import{moveFormula as Te,relativeKey as Ie}from"../formula/move.js";import{printFormula as fe}from"../formula/print.js";import{ERR as Le,errorOf as Re,serialOfDate as Me}from"../values.js";import{OFFICE_THEME as Fe,colorOf as F,paletteOf as le,themeColors as De}from"./colors.js";import{chartAnchors as je,readChart as Pe}from"./charts.js";import{isRangeText as ze,readFileFormula as te}from"./formula.js";import{BUILTIN_FORMATS as _e}from"./numfmt.js";import{XmlStream as ue}from"./sax.js";import{attr as u,flag as v,numberAttr as k,readXml as he,readXstring as A,tag as d,tags as x,textOf as E}from"./xml.js";import{ZipIn as He}from"./zip.js";const pe=7,Ve=r=>Math.floor((256*r+Math.floor(128/pe))/256*pe),Ue=r=>Math.round(r*4/3),ne=5;export function placesLine(r){const e=r.slice(0,ne).join(", ");return r.length>ne?`${e} and ${String(r.length-ne)} more`:e}const H=(r,e,t=`${e}s`)=>`${String(r)} ${r===1?e:t}`;export const GRID_END=`Excel's grid ends at ${Ae(q-1)}${String(K)} (${K.toLocaleString("en-US")} rows, ${q.toLocaleString("en-US")} columns)`;function We(r,e){let t=0,n=0;const o=r.length;for(;t<o;t++){const i=r.charCodeAt(t),c=i>=65&&i<=90,a=i>=97&&i<=122;if(!c&&!a)break;n=n*26+(c?i-64:i-96)}if(t===0||t===o)return;let s=0;for(let i=t;i<o;i++){const c=r.charCodeAt(i);if(c<48||c>57)return;s=s*10+c-48}if(s!==0){if(t>3||n>q||s>K)throw new Error(`${e} has a cell at ${r}, and ${GRID_END}.`);return{row:s-1,col:n-1}}}class Be{zip;constructor(e,t){this.zip=new He(e,t)}get names(){return this.zip.names}has(e){return this.zip.has(e)}text(e){return this.zip.text(e)}bytes(e){return this.zip.bytesOf(e)}xml(e){const t=this.text(e);return t===void 0?void 0:he(t)}stream(e,t){const n=this.zip.streamText(e,o=>{t.push(o)});return n&&t.end(),n}rels(e){const t=e.lastIndexOf("/"),n=`${e.slice(0,t+1)}_rels/${e.slice(t+1)}.rels`,o=this.xml(n);return x(d(o?.Relationships)?.Relationship).map(s=>{const i=u(s,"Type")??"",c=u(s,"Target")??"",a=u(s,"TargetMode")==="External";return{id:u(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?c:Xe(e,c),external:a}})}count(e){return this.names.filter(t=>e.test(t)).length}}function Xe(r,e){if(e.startsWith("/"))return e.slice(1);const t=r.split("/").slice(0,-1);for(const n of e.split("/"))n===".."?t.pop():n!=="."&&t.push(n);return t.join("/")}function qe(r,e){const t=[];if(e===void 0)return t;let n,o=0,s=!1;const i={open(c){if(c==="si"){n={text:"",rich:!1};return}if(n){if(o>0||c==="rPh"||c==="phoneticPr"||c==="extLst"){o+=1;return}c==="r"&&(n.rich=!0),c==="t"&&(s=!0)}},close(c){if(o>0){o-=1;return}if(c==="si"){n&&t.push({...n,text:A(n.text)}),n=void 0;return}c==="t"&&(s=!1)},text(c){n&&s&&o===0&&(n.text+=c)}};return r.stream(e,new ue(i)),t}function W(r,e){const t=r[e];if(t===void 0)return!1;const n=u(d(t),"val");return n===void 0||n!=="0"&&n!=="false"}const Ge=new Set(["double","singleAccounting","doubleAccounting"]);function Ze(r,e,t){const n={},o=(a,l)=>u(d(a?.[l]),"val");if(W(r,"b")&&(n.bold=!0),W(r,"i")&&(n.italic=!0),W(r,"strike")&&(n.strike=!0),W(r,"u")){const a=o(r,"u");n.underline=a!==void 0&&Ge.has(a)?a:!0}const s=o(r,"name");s!==void 0&&s!==o(e,"name")&&(n.font=s);const i=o(r,"sz");i!==void 0&&i!==o(e,"sz")&&(n.size=Number(i));const c=F(d(r.color),t);return c!==void 0&&c!==F(d(e?.color),t)&&(n.color=c),n}function Je(r,e){const t=d(r.patternFill),n=u(t,"patternType");if(n===void 0||n==="none")return;const o=F(d(t?.fgColor),e),s=F(d(t?.bgColor),e);return n==="solid"&&o!==void 0?o:{pattern:n,...o===void 0?{}:{color:o},...s===void 0?{}:{background:s}}}function me(r,e){const t={};for(const n of["left","right","top","bottom"]){const o=d(r[n]),s=u(o,"style");if(s===void 0||s==="none")continue;const i=F(d(o?.color),e);t[n]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(t).length===0?void 0:t}function Ke(r){const e={},t=u(r,"horizontal");t!==void 0&&t!=="general"&&(e.align=t);const n=u(r,"vertical");n!==void 0&&n!=="bottom"&&(e.valign=n),v(r,"wrapText")===!0&&(e.wrap=!0),v(r,"shrinkToFit")===!0&&(e.shrink=!0);const o=k(r,"indent");o!==void 0&&o>0&&(e.indent=o);const s=k(r,"textRotation");return s!==void 0&&s>0&&s<=180&&(e.rotation=s),e}function ge(r,e){const t={},n=d(r.font);if(n){const a=(f,p)=>{n[f]!==void 0&&(t[p]=W(n,f))};a("b","bold"),a("i","italic"),a("strike","strike"),n.u!==void 0&&(t.underline=W(n,"u"));const l=F(d(n.color),e);l!==void 0&&(t.color=l)}const o=d(d(r.fill)?.patternFill),s=F(d(o?.bgColor),e)??F(d(o?.fgColor),e);s!==void 0&&(t.fill=s);const i=d(r.border),c=i&&me(i,e);return c!==void 0&&(t.border=c),t}function Qe(r,e){const t=d(r?.styleSheet),n=le(e,t),o=new Map(x(d(t?.numFmts)?.numFmt).map(w=>[k(w,"numFmtId")??-1,u(w,"formatCode")??"General"])),s=x(d(t?.fonts)?.font),i=x(d(t?.fills)?.fill),c=x(d(t?.borders)?.border),a=x(d(t?.cellXfs)?.xf),l=s[k(a[0],"fontId")??0],f=new Set;i.some(w=>w.gradientFill!==void 0)&&f.add("gradient fills");const p=a.map(w=>{const m={},$=s[k(w,"fontId")??0];$&&(Object.assign(m,Ze($,l,n)),$.vertAlign!==void 0&&f.add("superscript and subscript"));const S=i[k(w,"fillId")??0],O=S&&Je(S,n);O!==void 0&&(m.fill=O);const T=c[k(w,"borderId")??0],z=T&&me(T,n);z!==void 0&&(m.border=z),T&&u(d(T.diagonal),"style")!==void 0&&f.add("diagonal borders");const D=d(w.alignment);D&&(Object.assign(m,Ke(D)),k(D,"textRotation")===255&&f.add("vertical text"));const I=k(w,"numFmtId")??0,M=o.get(I)??_e[I];return M!==void 0&&M!=="General"&&(m.format=M),m}),h=u(d(l?.name),"val"),b=u(d(l?.sz),"val");return{looks:p,dxfs:x(d(t?.dxfs)?.dxf).map(w=>ge(w,n)),font:{...h===void 0?{}:{name:h},...b===void 0?{}:{size:Number(b)}},lost:[...f]}}function be(r){const e=new Map;let t=0;for(const n of x(r.filterColumn)){const o=k(n,"colId")??0,s=d(n.filters);if(!s){Object.keys(n).some(c=>c!=="colId"&&c!=="hiddenButton")&&(t+=1);continue}if(s.dateGroupItem!==void 0){t+=1;continue}const i=x(s.filter).map(c=>A(u(c,"val")??""));e.set(o,{...i.length===0?{}:{values:i},...v(s,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:t}}function Ye(r){const e=d(r?.table),t=G(u(e,"ref")??""),n=u(e,"displayName")??u(e,"name");if(!t||n===void 0)return;const o=d(e?.tableStyleInfo),s=d(e?.autoFilter);return{name:n,ref:t,headers:k(e,"headerRowCount")??1,totals:k(e,"totalsRowCount")??0,columns:x(d(e?.tableColumns)?.tableColumn).map(i=>({name:A(u(i,"name")??"").trim(),calculated:i.calculatedColumnFormula!==void 0})),style:u(o,"name")??"none",...s?{filter:be(s)}:{}}}function oe(r){const e=r.trim();if(e==="")return;const t=/^"((?:[^"]|"")*)"$/u.exec(e);if(t)return(t[1]??"").replaceAll('""','"');const n=Number(e);if(!Number.isNaN(n))return n;const o=te(e,!0);return o.ok?fe(o.node):void 0}const xe=r=>r!==void 0&&Ce.includes(r);function re(r){const e=u(r,"type")??"num",t=u(r,"val")??(r.f===void 0?void 0:E(r.f)),n=t===void 0?void 0:oe(t);return{at:e,...n===void 0?{}:{value:n}}}const et=Se,tt=r=>{const e=r.formula??r.f;return(Array.isArray(e)?e:e===void 0?[]:[e]).map(E)};function nt(r,e,t,n){const o=u(r,"type")??"",s={range:e,...v(r,"stopIfTrue")===!0?{stop:!0}:{}},i={...t.bold===void 0?{}:{bold:t.bold},...t.italic===void 0?{}:{italic:t.italic},...t.underline===void 0?{}:{underline:t.underline!==!1},...t.strike===void 0?{}:{strike:t.strike},...t.color===void 0?{}:{color:t.color},...typeof t.fill=="string"?{fill:t.fill}:{},...t.border===void 0?{}:{border:t.border}},c=tt(r);switch(o){case"cellIs":{const a=u(r,"operator"),l=c.flatMap(f=>{const p=oe(f);return p===void 0?[]:[p]});return!xe(a)||l.length===0?`a cellIs rule of ${a??"no operator"}`:{...s,...i,type:"cellIs",operator:a,formula:l}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const a=u(r,"text");return a===void 0?`a ${o} rule with no text`:{...s,...i,type:"containsText",...o==="containsText"?{}:{operator:o==="notContainsText"?"notContains":o},text:A(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:o};case"top10":return{...s,...i,type:"top10",rank:k(r,"rank")??10,...v(r,"percent")===!0?{percent:!0}:{},...v(r,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return{...s,...i,type:"aboveAverage",...v(r,"aboveAverage")===!1?{below:!0}:{},...v(r,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=c[0]===void 0?void 0:te(c[0],!0);return a?.ok?{...s,...i,type:"expression",formula:fe(a.node)}:"an expression rule that cannot be read"}case"dataBar":{const a=d(r.dataBar),l=F(d(a?.color??a?.fillColor),n),[f,p]=x(a?.cfvo).map(re);return l===void 0?"a data bar with no colour":{...s,type:"dataBar",color:l,...f&&f.at!=="min"?{min:f}:{},...p&&p.at!=="max"?{max:p}:{},...v(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(r.colorScale),l=x(a?.cfvo).map(re),f=x(a?.color).map(h=>F(h,n)),p=l.flatMap((h,b)=>{const w=f[b];return w===void 0?[]:[{...h,color:w}]});return p.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:p.slice(0,3)}}case"iconSet":{const a=d(r.iconSet),l=u(a,"iconSet")??"3TrafficLights1";if(!et.includes(l))return`the icon set ${l}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const f=x(a?.cfvo).map(re);return{...s,type:"iconSet",icons:l,...f.length>=3?{stops:f.slice(0,5)}:{},...v(a,"reverse")===!0?{reverse:!0}:{},...v(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${o} rule`}}const we={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},ye=(r,e)=>x(d(r.extLst)?.ext).find(t=>u(t,"uri")?.toUpperCase()===e.toUpperCase());function ot(r,e,t){const n=[],o=[],s=new Set,i=(a,l,f)=>{const p=nt(a,l,f,t);typeof p=="string"?o.push(`${p} on ${l}`):n.push({priority:k(a,"priority")??0,rule:p})};for(const a of x(r.conditionalFormatting)){const l=u(a,"sqref")??"";if(!ee(l)){o.push(`a rule on ${l}`);continue}for(const f of x(a.cfRule)){const p=E(d(d(f.extLst)?.ext)?.id);p!==""&&s.add(p.toUpperCase());const h=k(f,"dxfId");i(f,l,h===void 0?{}:e[h]??{})}}const c=d(ye(r,we.conditional)?.conditionalFormattings);for(const a of x(c?.conditionalFormatting)){const l=E(a.sqref).trim();for(const f of x(a.cfRule)){if(s.has((u(f,"id")??"").toUpperCase()))continue;if(!ee(l)){o.push(`a rule on ${l}`);continue}const p=d(f.dxf);i(f,l,p?ge(p,t):{})}}return{rules:n.sort((a,l)=>a.priority-l.priority).map(a=>a.rule),unread:o}}const rt=Ne;function $e(r,e,t,n){const o=u(r,"type")??"none";if(o==="none"&&u(r,"prompt")===void 0)return;if(!rt.includes(o)||!ee(e))return`a ${o} rule on ${e}`;const s=/^"((?:[^"]|"")*)"$/u.exec(t.trim()),i=o==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,c=[t,n].flatMap(w=>{const m=oe(w);return m===void 0?[]:[m]}),a=u(r,"operator"),l=w=>Object.fromEntries(Object.entries(w).filter(([,m])=>m!==void 0)),f=l({title:u(r,"promptTitle"),message:u(r,"prompt")}),p=l({style:u(r,"errorStyle"),title:u(r,"errorTitle"),message:u(r,"error")}),h=v(r,"showInputMessage")!==!0,b=v(r,"showErrorMessage")!==!0;return{range:e,type:o,...xe(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:c},...v(r,"allowBlank")===!0?{}:{blank:!1},...v(r,"showDropDown")===!0?{dropdown:!1}:{},...h||Object.keys(f).length>0?{prompt:{...f,...h?{show:!1}:{}}}:{},...b||Object.keys(p).length>0?{error:{...p,...b?{show:!1}:{}}}:{}}}function st(r){const e=[],t=[],n=s=>{typeof s=="string"?t.push(s):s&&e.push(s)};for(const s of x(d(r.dataValidations)?.dataValidation))n($e(s,u(s,"sqref")??"",E(s.formula1),E(s.formula2)));const o=d(ye(r,we.validations)?.dataValidations);for(const s of x(o?.dataValidation))n($e(s,E(s.sqref).trim(),E(d(s.formula1)?.f),E(d(s.formula2)?.f)));return{rules:e,unread:t}}function it(r){const e=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r);if(!e)return;const t=e[1]==="",n=t?1899:Number(e[1]),o=t?12:Number(e[2]),s=t?30:Number(e[3]),i=Number(e[4]??0)*3600+Number(e[5]??0)*60+Number(e[6]??0)+Number(e[7]??0),c=new Date(Date.UTC(n,o-1,s)+i*1e3);if(Number.isNaN(c.getTime()))return;const a=Me(c);return t?a-Math.floor(a):a}function se(r,e,t){const n=te(r,e,t);return n.ok?{node:n.node}:{unread:r}}class at{cells=[];rows=[];rich=[];outlined=!1;rest=[];xml;masters=new Map;strings;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(e,t,n){this.strings=e,this.name=t,this.isRangeName=n,this.xml=new ue(this),this.xml.capture=this.rest}open(e,t){if(!this.inData){e==="sheetData"&&(this.inData=!0,this.xml.capture=void 0);return}const n=this.cell;if(n){if(this.skip>0){this.skip+=1;return}switch(e){case"v":this.target="v",this.buffer="";return;case"f":n.f={...t,text:""},this.target="f",this.buffer="";return;case"is":n.inline={text:"",rich:!1};return;case"r":n.inline&&(n.inline.rich=!0);return;case"t":n.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:return}}e==="row"?this.openRow(t):e==="c"&&(this.cell={r:t.r,s:t.s,t:t.t,cm:t.cm,v:void 0,f:void 0,inline:void 0})}close(e){if(!this.inData)return;const t=this.cell;if(!t){e==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(e===this.target){e==="v"?t.v=this.buffer:e==="f"&&t.f?t.f.text=this.buffer:t.inline&&(t.inline.text+=this.buffer),this.target=void 0;return}e==="c"&&(this.cell=void 0,this.readCell(t))}text(e){this.target!==void 0&&this.skip===0&&(this.buffer+=e)}openRow(e){const t=e.r,n=t===void 0?void 0:Number(t);if(n!==void 0&&Number.isInteger(n)&&n>K)throw new Error(`${this.name} has a row ${t??""}, and ${GRID_END}.`);const o=n!==void 0&&Number.isInteger(n)&&n>0?n-1:this.nextRow;this.row=o,this.nextRow=o+1,this.nextCol=0;const s={row:o},i=e.ht===void 0?void 0:Number(e.ht),c=f=>f==="1"||f==="true";i!==void 0&&Number.isFinite(i)&&c(e.customHeight)&&(s.height=Ue(i)),c(e.hidden)&&(s.hidden=!0);const a=e.s===void 0?void 0:Number(e.s);a!==void 0&&a!==0&&c(e.customFormat)&&(s.style=a);const l=Number(e.outlineLevel??0);l>0&&(s.level=Math.min(7,l),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(e,t){const n=e.t??"n";if(n==="inlineStr"){const s=e.inline;return s?{value:A(s.text),...s.rich?{rich:!0}:{}}:{value:e.v===void 0?"":A(e.v)}}const o=e.v;if(o===void 0)return{value:void 0};switch(n){case"s":{const s=this.strings[Number(o)];return s?{value:s.text,...s.rich?{rich:!0}:{}}:{value:""}}case"str":return{value:A(o)};case"b":return{value:o.trim()==="1"||o.trim()==="true"};case"e":return{value:Re(o.trim())??Le.VALUE};case"d":return{value:it(o.trim())??o};default:{if(o.trim()==="")return{value:void 0};const s=Number(o);if(Number.isNaN(s))throw new Error(`${t} says it holds a number and holds ${o}.`);return{value:s}}}}formula(e,t,n,o){const s=e.f;if(s===void 0)return;const i=s.t??"normal",c=s.text;if(i==="dataTable"){o.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(o,se(c,!0,this.isRangeName));const a=G(s.ref??"");a&&(o.array=a),e.cm!==void 0&&(o.dynamic=!0);return}if(i==="shared"){const a=s.si??"";if(c!==""){const f=se(c,!1,this.isRangeName),p=f.node?Ie(f.node,t,n):"";this.masters.set(a,{node:f.node,unread:f.unread,row:t,col:n,key:p}),Object.assign(o,f),f.node&&(o.key=p);return}const l=this.masters.get(a);if(!l){o.unread=`a shared formula of a group that has no first cell (${a})`;return}l.node?(o.node=Te(l.node,t-l.row,n-l.col),o.key=l.key):l.unread!==void 0&&(o.unread=l.unread);return}c!==""&&Object.assign(o,se(c,!1,this.isRangeName))}readCell(e){const t=e.r===void 0?void 0:We(e.r,this.name),n=t?.row??this.row,o=t?.col??this.nextCol;if(o>=q)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=o+1;const s=e.r??Y({row:n,col:o}),{value:i,rich:c}=this.value(e,s),a={row:n,col:o,value:i,style:e.s===void 0?0:Number(e.s)||0};c===!0&&(a.rich=!0,this.rich.push(s)),this.formula(e,n,o,a),this.cells.push(a)}}function dt(r,e,t){const n=[],o=p=>n.push(`${r}: ${p}`);t.length>0&&o(`${H(t.length,"cell")} of rich text, kept as plain text (${placesLine(t)})`);const s=x(d(e.hyperlinks)?.hyperlink).filter(p=>u(p,"tooltip")!==void 0);s.length>0&&o(`the tooltips of ${H(s.length,"link")} (${placesLine(s.map(p=>u(p,"ref")??""))})`),e.sortState!==void 0&&o("a sort");const i=d(e.sheetProtection);v(i,"sheet")===!0&&(u(i,"password")!==void 0||u(i,"hashValue")!==void 0)&&o("its protection's password: it is protected with none"),e.protectedRanges!==void 0&&o("protected ranges");const c=d(e.headerFooter);(c?.evenHeader!==void 0||c?.evenFooter!==void 0||c?.firstHeader!==void 0||c?.firstFooter!==void 0)&&o("its print header and footer of the first or even pages");const a=d(e.printOptions);a&&["gridLines","headings","horizontalCentered","verticalCentered"].some(p=>v(a,p)===!0)&&o("its print options (gridlines, headings, centring)"),(e.rowBreaks!==void 0||e.colBreaks!==void 0)&&o("its page breaks"),e.oleObjects!==void 0&&o("embedded objects"),e.controls!==void 0&&o("form controls"),e.dataConsolidate!==void 0&&o("a consolidation"),e.customSheetViews!==void 0&&o("custom views"),x(d(e.sheetViews)?.sheetView).some(p=>u(d(p.pane),"state")==="split")&&o("a split, not frozen, window");const f=JSON.stringify(e.extLst??"");return f.includes("sparklineGroups")&&o("sparklines"),f.includes("slicerList")&&o("slicers"),n}function ct(r,e){const t=[],n=(s,i,c)=>{const a=r.count(s);a>0&&t.push(H(a,i,c))};r.has("xl/vbaProject.bin")&&t.push("VBA macros"),n(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),n(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),n(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),n(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet");const o=r.names.filter(s=>s.startsWith("xl/media/")&&!e.has(s)).length;return o>0&&t.push(H(o,"image")),n(/^xl\/embeddings\//u,"embedded object"),n(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),n(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),n(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),n(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),n(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),r.has("xl/connections.xml")&&t.push("data connections"),r.names.some(s=>s.startsWith("xl/richData/"))&&t.push("rich values (data types, pictures in cells)"),r.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(r.text(s)??"").includes("DataMashup"))&&t.push("Power Query queries"),t}export function readHeaderFooter(r){const e={left:"",center:"",right:""};let t="center",n=new Set;for(let o=0;o<r.length;o++){const s=r[o],i=r[o+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){t=i==="L"?"left":i==="C"?"center":"right",n=new Set([...n,t]),o+=1;continue}if(s==="&"&&i==="&"){e[t]+="&&",o+=1;continue}e[t]+=s??""}return Object.fromEntries(Object.entries(e).filter(([o,s])=>s!==""||n.has(o)))}const ft=new Map(Object.entries(Ee).map(([r,e])=>[e,r]));function lt(r,e,t){const n={},o=d(r.pageSetup),s=u(o,"orientation");(s==="portrait"||s==="landscape")&&(n.orientation=s);const i=k(o,"paperSize");if(i!==void 0){const h=ft.get(i);h?n.paper=h:t.push(`${e}: its paper size, Excel's number ${String(i)}`)}v(d(d(r.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(n.fit={width:k(o,"fitToWidth")??1,height:k(o,"fitToHeight")??1});const c=d(r.pageMargins),a={};for(const h of Object.keys(de)){const b=k(c,h);b!==void 0&&b!==de[h]&&(a[h]=b)}Object.keys(a).length>0&&(n.margins=a);const l=d(r.headerFooter),f=E(l?.oddHeader),p=E(l?.oddFooter);return f!==""&&(n.header=readHeaderFooter(A(f))),p!==""&&(n.footer=readHeaderFooter(A(p))),n}function ut(r,e,t,n,o){const s=r.rels(e),i=new Map;for(const a of s.filter(l=>l.type==="comments")){const l=d(r.xml(a.target)?.comments),f=d(l?.authors)?.author,p=(Array.isArray(f)?f:f===void 0?[]:[f]).map(h=>A(E(h)));for(const h of x(d(l?.commentList)?.comment)){const b=u(h,"ref")??"",w=d(h.text),m=x(w?.r),$=A(m.length>0?m.map(O=>E(O.t)).join(""):E(w?.t)),S=p[k(h,"authorId")??-1];b!==""&&$!==""&&i.set(b,{ref:b,text:$,...S===void 0||S===""?{}:{author:S}})}}let c=0;for(const a of s.filter(l=>l.type==="threadedComment")){const l=d(r.xml(a.target)?.ThreadedComments),f=new Map;for(const p of x(l?.threadedComment)){const h=u(p,"ref")??"",b=A(E(p.text)),w=f.get(h)??{texts:[]};if(w.texts.length===0){const m=n.get(u(p,"personId")??"");m!==void 0&&(w.author=m)}w.texts.push(b),f.set(h,w)}for(const[p,h]of f)c+=1,i.set(p,{ref:p,text:h.texts.join(`
3
+ `),...h.author===void 0?{}:{author:h.author}})}return c>0&&o.push(`${t}: ${H(c,"threaded comment")}, kept as notes, replies after the first line`),[...i.values()]}function ht(r,e,t,n,o,s,i,c,a,l){const f=new at(o,t,a);if(!r.stream(e,f.xml))throw new Error(`${e} is not in the file.`);const p=he(f.rest.join("")),h=d(p.worksheet);if(!h)throw new Error(`${e} is not a worksheet.`);const b=x(d(h.cols)?.col).map(y=>{const C=k(y,"width"),R=k(y,"style"),P=k(y,"outlineLevel")??0,L=(k(y,"min")??1)-1,ie=(k(y,"max")??1)-1;if(ie>=q)throw new Error(`${t} sets a column past its last, and ${GRID_END}.`);const ae=v(y,"customWidth"),Q=C===void 0?void 0:Ve(C);return{min:L,max:ie,...Q!==void 0&&(ae===!0||ae===void 0&&Q!==ke)?{width:Q}:{},...v(y,"hidden")===!0?{hidden:!0}:{},...R===void 0||R===0?{}:{style:R},...P>0?{level:Math.min(7,P)}:{}}}),w=x(d(h.mergeCells)?.mergeCell).flatMap(y=>{const C=G(u(y,"ref")??"");return C?[C]:[]}),m=x(d(h.sheetViews)?.sheetView)[0],$=d(m?.pane);let S;const O=u($,"state");if(O==="frozen"||O==="frozenSplit"){const y=Oe(u(m,"topLeftCell")??"A1")??{row:0,col:0};S={row:y.row+(k($,"ySplit")??0),col:y.col+(k($,"xSplit")??0)}}const T=r.rels(e),z=T.filter(y=>y.type==="table").flatMap(y=>{const C=Ye(r.xml(y.target));return C?[C]:[]}),D=F(d(d(h.sheetPr)?.tabColor),s),I=dt(t,h,f.rich),M=ot(h,i,s),B=st(h);for(const y of M.unread)I.push(`${t}: a conditional format, ${y}`);for(const y of B.unread)I.push(`${t}: a data validation, ${y}`);const V=d(h.autoFilter),Z=G(u(V,"ref")??""),j=V&&Z?{ref:Z,...be(V)}:void 0;j&&j.unread>0&&I.push(`${t}: ${H(j.unread,"filter")} by condition on ${u(V,"ref")??""}, its rows left as they were hidden`);const{charts:X,pictures:J}=mt(r,e,t,b,f.rows,I,l),U={},g=new Map(T.map(y=>[y.id,y]));for(const y of x(d(h.hyperlinks)?.hyperlink)){const C=u(y,"ref");if(C===void 0)continue;const R=u(y,"location"),P=u(y,"id"),L=P===void 0?void 0:g.get(P)?.target;L!==void 0?U[C]=R===void 0?L:`${L}#${R}`:R!==void 0&&(U[C]=`#${R}`)}const N=d(h.sheetProtection),_=lt(h,t,I);return{sheet:{name:t,state:n,cells:f.cells,merges:w,...S?{freeze:S}:{},...u(m,"showGridLines")==="0"?{gridlines:!1}:{},...D===void 0?{}:{tab:D},columns:b,rows:f.rows,tables:z,conditional:M.rules,validations:B.rules,scenarios:x(d(h.scenarios)?.scenario).map(y=>({name:u(y,"name")??"",cells:x(y.inputCells).map(C=>({at:u(C,"r")??"",value:u(C,"val")??""}))})),...j?{filter:j}:{},charts:X,links:U,notes:ut(r,e,t,c,I),pictures:J,...v(N,"sheet")===!0?{protect:!0}:{},...Object.keys(_).length>0?{print:_}:{}},lost:I}}const ke=64,pt=20;function mt(r,e,t,n,o,s,i){const c=h=>n.find(b=>h>=b.min&&h<=b.max)?.width??ke,a=new Map(o.map(h=>[h.row,h.height])),l=h=>a.get(h)??pt,f=[],p=[];for(const h of r.rels(e).filter(b=>b.type==="drawing")){const b=je(r.xml(h.target),c,l),w=r.rels(h.target);for(const m of b.anchors){const $=w.find(T=>T.id===m.id),S=Pe($?r.xml($.target):void 0),O=Y(m.at);if(typeof S=="string"){s.push(`${t}: the chart at ${O}, as ${S}`);continue}f.push({...S,at:O,...m.x===void 0?{}:{x:m.x},...m.y===void 0?{}:{y:m.y},...m.width===ce.width?{}:{width:m.width},...m.height===ce.height?{}:{height:m.height}})}for(const m of b.pictures){const $=w.find(T=>T.id===m.id),S=$&&!$.external?r.bytes($.target):void 0;if(!$||!S){s.push(`${t}: the picture at ${Y(m.at)}, whose image is not in the file`);continue}i.add($.target);const O=$.target.slice($.target.lastIndexOf(".")+1).toLowerCase();p.push({row:m.at.row,col:m.at.col,...m.x===void 0?{}:{x:m.x},...m.y===void 0?{}:{y:m.y},width:m.width,height:m.height,...m.name===void 0?{}:{name:m.name},...m.descr===void 0?{}:{descr:m.descr},bytes:S,type:O})}b.others>0&&s.push(`${t}: ${H(b.others,"shape")} of its drawing`)}return{charts:f,pictures:p}}function gt(r,e,t){for(const n of r){if(n.sheet===void 0)continue;const o=e[n.sheet];if(!o)continue;const s=n.text.split(",").map(i=>i.slice(i.lastIndexOf("!")+1).replaceAll("$",""));if(n.name==="_xlnm.Print_Area"){const[i]=s;s.length>1&&t.push(`${o.name}: its print area's ranges after the first`),i!==void 0&&G(i)&&(o.print={...o.print,area:i})}else if(n.name==="_xlnm.Print_Titles")for(const i of s)/^\d+:\d+$/u.test(i)?o.print={...o.print,title_rows:i}:/^[A-Za-z]+:[A-Za-z]+$/u.test(i)&&(o.print={...o.print,title_cols:i})}}export function readXlsx(r,e){let t;try{t=new Be(r,e)}catch(g){throw g instanceof ve?g:new Error("It is not a zip file, as an .xlsx file is.")}const n=t.rels(""),o=n.find(g=>g.type==="officeDocument")?.target??"xl/workbook.xml";if(o.endsWith(".bin"))throw new Error("It is a binary workbook (.xlsb): save it as .xlsx.");const s=t.xml(o),i=d(s?.workbook);if(!i)throw new Error("It has no workbook part.");const c=t.rels(o),a=g=>c.find(N=>N.type===g)?.target,l=(()=>{const g=a("theme");return g===void 0?void 0:t.text(g)})(),f=l===void 0?Fe:De(l),p=a("styles"),h=p===void 0?void 0:t.xml(p),b=Qe(h,f),w=le(f,d(h?.styleSheet)),m=qe(t,a("sharedStrings")),$=[];for(const g of b.lost)$.push(g);const S=d(i.workbookPr),O=d(i.calcPr);v(O,"iterate")===!0&&$.push("iterative calculation");const T=d(i.workbookProtection);(v(T,"lockStructure")===!0||v(T,"lockWindows")===!0)&&$.push("the workbook's protection"),i.fileSharing!==void 0&&$.push("its write protection");const z=new Map,D=a("person");if(D!==void 0)for(const g of x(d(t.xml(D)?.personList)?.person))z.set(u(g,"id")??"",A(u(g,"displayName")??""));const I=x(d(i.definedNames)?.definedName).map(g=>{const N=k(g,"localSheetId");return{name:u(g,"name")??"",text:A(E(g)),...N===void 0?{}:{sheet:N},...v(g,"hidden")===!0?{hidden:!0}:{}}}),M=[],B=new Set,V=new Map(c.map(g=>[g.id,g])),Z=x(d(i.sheets)?.sheet);for(const[g,N]of Z.entries()){const _=V.get(u(N,"id")??""),y=A(u(N,"name")??"");if(_?.type!=="worksheet"){_?.type!=="chartsheet"&&_?.type!=="dialogsheet"&&$.push(`${y}: a sheet of a kind this cannot read`);continue}const C=new Map;for(const L of I)(L.sheet===void 0||L.sheet===g)&&(L.sheet!==void 0||!C.has(L.name.toLowerCase()))&&C.set(L.name.toLowerCase(),ze(L.text));const R=u(N,"state"),P=ht(t,_.target,y,R==="hidden"||R==="veryHidden"?R:"visible",m,w,b.dxfs,z,L=>C.get(L.toLowerCase())===!0,B);M[g]=P.sheet,$.push(...P.lost)}gt(I,M,$);const j=n.find(g=>g.type==="core-properties")?.target,X=j===void 0?void 0:E(d(t.xml(j)?.coreProperties)?.title).trim(),J=M.filter(g=>g!==void 0),U=new Map;return M.forEach((g,N)=>{g!==void 0&&U.set(N,J.indexOf(g))}),{sheets:J,names:I.flatMap(g=>{if(g.sheet===void 0)return[g];const N=U.get(g.sheet);return N===void 0?[]:[{...g,sheet:N}]}),looks:b.looks,dxfs:b.dxfs,date1904:v(S,"date1904")===!0,font:b.font,...X===void 0||X===""?{}:{title:X},lost:[...ct(t,B),...$]}}
@@ -0,0 +1,23 @@
1
+ export type XmlAttrs = Record<string, string>;
2
+ export interface XmlHandler {
3
+ open(name: string, attrs: XmlAttrs, empty: boolean): void;
4
+ close(name: string): void;
5
+ /** Text, its entities read. */
6
+ text(text: string): void;
7
+ }
8
+ /** Text with its entities read. */
9
+ export declare function unescapeXml(text: string): string;
10
+ /** An XML stream: text pushed in pieces, events out as soon as each is whole. */
11
+ export declare class XmlStream {
12
+ /** When set, the source text of each token is kept here as it is read. */
13
+ capture: string[] | undefined;
14
+ private buffer;
15
+ private readonly handler;
16
+ private depth;
17
+ constructor(handler: XmlHandler);
18
+ push(text: string): void;
19
+ end(): void;
20
+ private emitText;
21
+ private run;
22
+ }
23
+ //# sourceMappingURL=sax.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ const b={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};export function unescapeXml(r){return r.includes("&")?r.replace(/&(#x[0-9A-Fa-f]+|#\d+|[A-Za-z]+);/gu,(e,o)=>o.startsWith("#x")?String.fromCodePoint(Number.parseInt(o.slice(2),16)):o.startsWith("#")?String.fromCodePoint(Number.parseInt(o.slice(1),10)):b[o]??e):r}const d=r=>{const e=r.indexOf(":");return e<0?r:r.slice(e+1)},p=r=>r===32||r===9||r===10||r===13;function x(r,e,o){let i=0;const t=r.length;for(;i<t&&!p(r.charCodeAt(i));)i++;const f=d(r.slice(0,i)),c={};for(;i<t;){for(;i<t&&p(r.charCodeAt(i));)i++;if(i>=t)break;const h=r.indexOf("=",i);if(h<0)throw new Error(`An attribute of <${f}> has no value.`);const u=r.slice(i,h).trim();let l=h+1;for(;l<t&&p(r.charCodeAt(l));)l++;const a=r[l];if(a!=='"'&&a!=="'")throw new Error(`An attribute of <${f}> is not quoted.`);const s=r.indexOf(a,l+1);if(s<0)throw new Error(`An attribute of <${f}> is not closed.`);u!=="xmlns"&&!u.startsWith("xmlns:")&&(c[d(u)]=unescapeXml(r.slice(l+1,s))),i=s+1}return e.open(f,c,o),f}export class XmlStream{capture;buffer="";handler;depth=0;constructor(e){this.handler=e}push(e){this.buffer=this.buffer===""?e:this.buffer+e,this.run()}end(){if(this.run(),this.buffer.trim()!=="")throw new Error("The XML ends inside a tag or a comment.");if(this.depth>0)throw new Error("The XML ends before its elements do.")}emitText(e){e!==""&&(this.capture?.push(e),this.handler.text(unescapeXml(e)))}run(){const e=this.buffer,o=e.length;let i=0;for(;;){const t=e.indexOf("<",i);if(t<0){const s=e.lastIndexOf("&"),n=s>=i&&!e.includes(";",s)?s:o;this.emitText(e.slice(i,n)),i=n;break}t>i&&this.emitText(e.slice(i,t)),i=t;const f=e.charCodeAt(t+1);if(Number.isNaN(f))break;if(f===33){if(e.startsWith("<!--",t)){const n=e.indexOf("-->",t+4);if(n<0)break;this.capture?.push(e.slice(t,n+3)),i=n+3;continue}if(e.startsWith("<![CDATA[",t)){const n=e.indexOf("]]>",t+9);if(n<0)break;this.capture?.push(e.slice(t,n+3)),this.handler.text(e.slice(t+9,n)),i=n+3;continue}if(o-t<9)break;const s=e.indexOf(">",t);if(s<0)break;if(e.lastIndexOf("[",s)>t){const n=e.indexOf("]>",t);if(n<0)break;i=n+2}else i=s+1;continue}if(f===63){const s=e.indexOf("?>",t+2);if(s<0)break;this.capture?.push(e.slice(t,s+2)),i=s+2;continue}if(f===47){const s=e.indexOf(">",t+2);if(s<0)break;this.capture?.push(e.slice(t,s+1)),this.depth-=1,this.handler.close(d(e.slice(t+2,s).trim())),i=s+1;continue}let c=t+1,h=0;for(;c<o;c++){const s=e.charCodeAt(c);if(h!==0)s===h&&(h=0);else if(s===34||s===39)h=s;else if(s===62)break}if(c>=o)break;const u=e.charCodeAt(c-1)===47,l=e.slice(t,c+1),a=x(e.slice(t+1,u?c-1:c),this.handler,u);this.capture?.push(l),u?this.handler.close(a):this.depth+=1,i=c+1}this.buffer=i>=o?"":e.slice(i)}}
@@ -18,6 +18,8 @@ export declare class Styles {
18
18
  xf(look: CellLook): number;
19
19
  /** The differential format of what a rule gives a cell. */
20
20
  dxf(look: CellLook): number;
21
+ /** What a rule gives a cell, as an element of its own: Excel 2010's rules hold theirs. */
22
+ dxfXml(look: CellLook, name: string): string;
21
23
  xml(): string;
22
24
  }
23
25
  //# sourceMappingURL=styles.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{FIRST_CUSTOM as p,builtinId as g}from"./numfmt.js";import{NS as y,el as e}from"./xml.js";export const DEFAULT_FONT={name:"Calibri",size:11};const s=t=>`FF${t.slice(1).toUpperCase()}`;class l{items=[];index=new Map;add(n){const r=this.index.get(n);if(r!==void 0)return r;const i=this.items.length;return this.items.push(n),this.index.set(n,i),i}}function b(t){const{underline:n}=t;return e("font",{},t.bold===!0?"<b/>":"",t.italic===!0?"<i/>":"",t.strike===!0?"<strike/>":"",n===!0||n==="single"?"<u/>":n?e("u",{val:n}):"",e("sz",{val:t.size??DEFAULT_FONT.size}),t.color===void 0?e("color",{theme:1}):e("color",{rgb:s(t.color)}),e("name",{val:t.font??DEFAULT_FONT.name}),e("family",{val:2}),t.font===void 0?e("scheme",{val:"minor"}):"")}function x(t){const{pattern:n,color:r,background:i}=typeof t=="string"?{pattern:"solid",color:t,background:void 0}:t;return e("fill",{},e("patternFill",{patternType:n},r===void 0?"":e("fgColor",{rgb:s(r)}),i===void 0?n==="solid"?e("bgColor",{indexed:64}):"":e("bgColor",{rgb:s(i)})))}function f(t,n){return n?e(t,{style:n.style},n.color===void 0?e("color",{auto:1}):e("color",{rgb:s(n.color)})):e(t)}function h(t){return e("border",{},f("left",t.left),f("right",t.right),f("top",t.top),f("bottom",t.bottom),e("diagonal"))}function F(t){const{underline:n}=t,r=[t.bold===void 0?"":e("b",{val:t.bold}),t.italic===void 0?"":e("i",{val:t.italic}),t.strike===void 0?"":e("strike",{val:t.strike}),n===!0?"<u/>":"",t.color===void 0?"":e("color",{rgb:s(t.color)})].join(""),{fill:i,border:d}=t;return e("dxf",{},r===""?"":e("font",{},r),typeof i=="string"?e("fill",{},e("patternFill",{},e("bgColor",{rgb:s(i)}))):"",d?h(d):"")}const I=t=>t<0?90-t:t;function v(t){const n={horizontal:t.align,vertical:t.valign,textRotation:t.rotation===void 0?void 0:I(t.rotation),wrapText:t.wrap===!0?!0:void 0,indent:t.indent,shrinkToFit:t.shrink===!0?!0:void 0};return Object.values(n).every(r=>r===void 0)?"":e("alignment",n)}export class Styles{fonts=new l;fills=new l;borders=new l;formats=new Map;xfs=new l;byLook=new Map;dxfs=new l;constructor(){this.fonts.add(b({})),this.fills.add(e("fill",{},e("patternFill",{patternType:"none"}))),this.fills.add(e("fill",{},e("patternFill",{patternType:"gray125"}))),this.borders.add(e("border",{},e("left"),e("right"),e("top"),e("bottom"),e("diagonal"))),this.xfs.add(e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0,xfId:0}))}format(n){if(n===void 0)return 0;const r=g(n);if(r!==void 0)return r;let i=this.formats.get(n);return i===void 0&&(i=p+this.formats.size,this.formats.set(n,i)),i}xf(n){const r=JSON.stringify(n),i=this.byLook.get(r);if(i!==void 0)return i;const d=this.format(n.format),o=this.fonts.add(b(n)),a=n.fill===void 0?0:this.fills.add(x(n.fill)),u=n.border===void 0?0:this.borders.add(h(n.border)),c=v(n),m=this.xfs.add(e("xf",{numFmtId:d,fontId:o,fillId:a,borderId:u,xfId:0,applyNumberFormat:d===0?void 0:!0,applyFont:o===0?void 0:!0,applyFill:a===0?void 0:!0,applyBorder:u===0?void 0:!0,applyAlignment:c===""?void 0:!0},c));return this.byLook.set(r,m),m}dxf(n){return this.dxfs.add(F(n))}xml(){const n=(i,d)=>e(i,{count:d.length},...d),r=[...this.formats].map(([i,d])=>e("numFmt",{numFmtId:d,formatCode:i}));return e("styleSheet",{xmlns:y.main},r.length>0?n("numFmts",r):"",n("fonts",this.fonts.items),n("fills",this.fills.items),n("borders",this.borders.items),n("cellStyleXfs",[e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0})]),n("cellXfs",this.xfs.items),n("cellStyles",[e("cellStyle",{name:"Normal",xfId:0,builtinId:0})]),this.dxfs.items.length===0?e("dxfs",{count:0}):n("dxfs",this.dxfs.items),e("tableStyles",{count:0,defaultTableStyle:"TableStyleMedium2",defaultPivotStyle:"PivotStyleLight16"}))}}
2
+ import{FIRST_CUSTOM as g,builtinId as y}from"./numfmt.js";import{NS as x,el as n}from"./xml.js";export const DEFAULT_FONT={name:"Calibri",size:11};const s=t=>`FF${t.slice(1).toUpperCase()}`;class f{items=[];index=new Map;add(e){const i=this.index.get(e);if(i!==void 0)return i;const r=this.items.length;return this.items.push(e),this.index.set(e,r),r}}function b(t){const{underline:e}=t;return n("font",{},t.bold===!0?"<b/>":"",t.italic===!0?"<i/>":"",t.strike===!0?"<strike/>":"",e===!0||e==="single"?"<u/>":e?n("u",{val:e}):"",n("sz",{val:t.size??DEFAULT_FONT.size}),t.color===void 0?n("color",{theme:1}):n("color",{rgb:s(t.color)}),n("name",{val:t.font??DEFAULT_FONT.name}),n("family",{val:2}),t.font===void 0?n("scheme",{val:"minor"}):"")}function F(t){const{pattern:e,color:i,background:r}=typeof t=="string"?{pattern:"solid",color:t,background:void 0}:t;return n("fill",{},n("patternFill",{patternType:e},i===void 0?"":n("fgColor",{rgb:s(i)}),r===void 0?e==="solid"?n("bgColor",{indexed:64}):"":n("bgColor",{rgb:s(r)})))}function o(t,e){return e?n(t,{style:e.style},e.color===void 0?n("color",{auto:1}):n("color",{rgb:s(e.color)})):n(t)}function h(t){return n("border",{},o("left",t.left),o("right",t.right),o("top",t.top),o("bottom",t.bottom),n("diagonal"))}function p(t,e="dxf"){const{underline:i}=t,r=[t.bold===void 0?"":n("b",{val:t.bold}),t.italic===void 0?"":n("i",{val:t.italic}),t.strike===void 0?"":n("strike",{val:t.strike}),i===!0?"<u/>":"",t.color===void 0?"":n("color",{rgb:s(t.color)})].join(""),{fill:d,border:l}=t;return n(e,{},r===""?"":n("font",{},r),typeof d=="string"?n("fill",{},n("patternFill",{},n("bgColor",{rgb:s(d)}))):"",l?h(l):"")}const I=t=>t<0?90-t:t;function v(t){const e={horizontal:t.align,vertical:t.valign,textRotation:t.rotation===void 0?void 0:I(t.rotation),wrapText:t.wrap===!0?!0:void 0,indent:t.indent,shrinkToFit:t.shrink===!0?!0:void 0};return Object.values(e).every(i=>i===void 0)?"":n("alignment",e)}export class Styles{fonts=new f;fills=new f;borders=new f;formats=new Map;xfs=new f;byLook=new Map;dxfs=new f;constructor(){this.fonts.add(b({})),this.fills.add(n("fill",{},n("patternFill",{patternType:"none"}))),this.fills.add(n("fill",{},n("patternFill",{patternType:"gray125"}))),this.borders.add(n("border",{},n("left"),n("right"),n("top"),n("bottom"),n("diagonal"))),this.xfs.add(n("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0,xfId:0}))}format(e){if(e===void 0)return 0;const i=y(e);if(i!==void 0)return i;let r=this.formats.get(e);return r===void 0&&(r=g+this.formats.size,this.formats.set(e,r)),r}xf(e){const i=JSON.stringify(e),r=this.byLook.get(i);if(r!==void 0)return r;const d=this.format(e.format),l=this.fonts.add(b(e)),a=e.fill===void 0?0:this.fills.add(F(e.fill)),u=e.border===void 0?0:this.borders.add(h(e.border)),m=v(e),c=this.xfs.add(n("xf",{numFmtId:d,fontId:l,fillId:a,borderId:u,xfId:0,applyNumberFormat:d===0?void 0:!0,applyFont:l===0?void 0:!0,applyFill:a===0?void 0:!0,applyBorder:u===0?void 0:!0,applyAlignment:m===""?void 0:!0},m));return this.byLook.set(i,c),c}dxf(e){return this.dxfs.add(p(e))}dxfXml(e,i){return p(e,i)}xml(){const e=(r,d)=>n(r,{count:d.length},d.join("")),i=[...this.formats].map(([r,d])=>n("numFmt",{numFmtId:d,formatCode:r}));return n("styleSheet",{xmlns:x.main},i.length>0?e("numFmts",i):"",e("fonts",this.fonts.items),e("fills",this.fills.items),e("borders",this.borders.items),e("cellStyleXfs",[n("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0})]),e("cellXfs",this.xfs.items),e("cellStyles",[n("cellStyle",{name:"Normal",xfId:0,builtinId:0})]),this.dxfs.items.length===0?n("dxfs",{count:0}):e("dxfs",this.dxfs.items),n("tableStyles",{count:0,defaultTableStyle:"TableStyleMedium2",defaultPivotStyle:"PivotStyleLight16"}))}}
@@ -1,6 +1,12 @@
1
1
  import type { Calc } from "../calc/engine.js";
2
2
  /** A table's style when sheet.yaml names none. */
3
3
  export declare const DEFAULT_TABLE_STYLE = "TableStyleMedium2";
4
+ /**
5
+ * The very hidden sheet a list's choices are written in when a validation
6
+ * cannot spell them out: one holds a comma, a quote, or all of them more
7
+ * than 255 characters. A reader finds the choices again by this name.
8
+ */
9
+ export declare const LISTS_SHEET = "AllyHub lists";
4
10
  export interface WriteOptions {
5
11
  /** false leaves out what formulas compute: the file has to be computed by what opens it. */
6
12
  cached?: boolean;
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{zipSync as se}from"fflate";import{cellName as R,columnIndex as ne,columnLetter as Y,rangeName as E}from"../address.js";import{parseFormula as oe}from"../formula/parse.js";import{sheetPrefix as re}from"../formula/print.js";import{fileCells as ie,isPicture as ae,pictureHeight as le,pictureSize as ce}from"../files.js";import{scenariosByCell as de}from"../scenario.js";import{CellError as P,readTyped as he}from"../values.js";import{FormulaCell as me}from"../workbook.js";import{chartPart as fe,drawingPart as ue}from"./charts.js";import{fileFormula as O,needsArray as V}from"./formula.js";import{Styles as pe}from"./styles.js";import{THEME_XML as ge}from"./theme.js";import{HEAD as g,NS as y,el as o,xstring as x}from"./xml.js";const $={sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},w=`${y.rel}/`,G=new Date(1980,0,1),xe=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2";const $e=64,we=7,be=l=>Math.min(255,Math.floor(l/we*256)/256),ye=l=>Math.min(409.5,l*3/4),z=32767,B=255,Se=2e5,ke=o("metadata",{xmlns:y.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},o("metadataTypes",{count:1},o("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),o("futureMetadata",{name:"XLDAPR",count:1},o("bk",{},o("extLst",{},o("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},o("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),o("cellMetadata",{count:1},o("bk",{},o("rc",{t:1,v:0}))));class ve{index=new Map;count=0;of(t){this.count+=1;let e=this.index.get(t);return e===void 0&&(e=this.index.size,this.index.set(t,e)),e}xml(){const t=[...this.index.keys()].map(e=>`<si><t${/^\s|\s$|\n/u.test(e)?' xml:space="preserve"':""}>${x(e)}</t></si>`);return o("sst",{xmlns:y.main,count:this.count,uniqueCount:this.index.size},...t)}}const H=l=>x(l),Te="Base case";function Ce(l){const t=new Map;for(const n of l.scenarios)for(const r of n.cells)t.set(R(r),r);const e=(n,r)=>o("inputCells",{r:R(n),val:r===null||r instanceof P?"":typeof r=="boolean"?r?"1":"0":String(r)}),s=(n,r)=>o("scenario",{name:n,locked:!0,count:r.length,user:"AllyHub"},...r);return o("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},s(Te,[...t.values()].map(n=>e(n,n.base))),...l.scenarios.map(n=>s(n.name,n.cells.map(r=>e(r,r.value)))))}function Ae(l,t,e,s){const n=[];let r=0;for(const{row:d,col:h,paths:a,column:i}of ie(l,t)){let c=0;const u=le(i);for(const S of a){const b=ae(S)?e?.(S):void 0,k=b&&ce(b);if(!b||!k){r+=1;continue}const M=Math.round(k.width/k.height*u);n.push({row:d,col:h,x:c,width:M,height:u,name:S.split("/").pop()??S,file:`.${k.type==="jpeg"?"jpg":k.type}`,bytes:b}),c+=M+4}}return r>0&&s.push(`${l.name}: ${String(r)} file${r===1?"":"s"} in a cell, which stay${r===1?"s":""} a name`),n}class Ee{arrays=!1;places=new Map;sheet;calc;styles;strings;wb;cached;left;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;constructor(t,e,s,n,r,d,h=[],a){this.sheet=t,this.calc=e,this.wb=e.wb,this.styles=s,this.strings=n,this.cached=r,this.left=d,this.isTable=c=>this.wb.table(c)!==void 0,this.isRangeName=c=>{const u=this.wb.name(c)?.formula?.node;return this.isTable(c)||u!==void 0&&V({kind:"unary",op:"-",arg:u})},this.hiddenRows=e.filtered(t),this.scenarios=a,this.drawn=t.charts.length>0||h.length>0;const i=new Map;for(const c of h)i.set(c.row,Math.max(i.get(c.row)??0,c.height));this.tall=i}add(t,e){let s=this.places.get(t);s||(s=new Set,this.places.set(t,s)),s.add(e)}gather(){const{sheet:t}=this;for(let e=0;e<t.columnsUsed;e++){const[s,n]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let r=s;r<=n;r++)(t.at(r,e)!==void 0||t.spillAt(r,e))&&this.add(r,e)}for(const{area:e}of t.styledAreas()){const s=(e.bottom-e.top+1)*(e.right-e.left+1);if(s>Se){this.left.push(`${t.name}!${E(e)}: its look on the cells that hold something, ${String(s)} cells being too many to write empty`);continue}for(let n=e.top;n<=e.bottom;n++)for(let r=e.left;r<=e.right;r++)this.add(n,r)}for(const e of t.keys.keys())this.add(Math.floor(e/16384),e%16384)}styleOf(t,e){const s=this.sheet.lookAt(t,e);return Object.keys(s).length===0?void 0:this.styles.xf(s)}held(t,e){return e.length<=z?e:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(z)} characters, of its ${String(e.length)}`),e.slice(0,z))}value(t,e,s){return s===null?o("c",{r:t,s:e}):typeof s=="number"?`<c r="${t}"${p(e)}><v>${String(s)}</v></c>`:typeof s=="boolean"?`<c r="${t}"${p(e)} t="b"><v>${s?"1":"0"}</v></c>`:s instanceof P?Z(s)?`<c r="${t}"${p(e)} t="e"><v>${s.code}</v></c>`:`<c r="${t}"${p(e)} t="s"><v>${String(this.strings.of(s.code))}</v></c>`:`<c r="${t}"${p(e)} t="s"><v>${String(this.strings.of(this.held(t,s)))}</v></c>`}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,e,s){const n=this.calc.value(s.sheet,s.row,s.col),{node:r}=s.shared;if(!r)return`<c r="${t}"${p(e)} t="e"><v>#NAME?</v></c>`;const d=s.moved,h=s.array!==void 0||s.blocked!==void 0||V(d,this.isRangeName),a=O(d,{table:this.table(s),isTable:this.isTable,array:h});let i=`<f>${H(a)}</f>`,c="";if(h){this.arrays=!0;const u=s.spill??{top:s.row,left:s.col,bottom:s.row,right:s.col};i=`<f t="array" ref="${E(u)}">${H(a)}</f>`,c=' cm="1"'}return this.cached?n===null||typeof n=="number"?`<c r="${t}"${p(e)}${c}>${i}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${p(e)} t="b"${c}>${i}<v>${n?"1":"0"}</v></c>`:n instanceof P?Z(n)?`<c r="${t}"${p(e)} t="e"${c}>${i}<v>${n.code}</v></c>`:`<c r="${t}"${p(e)}${c}>${i}<v>0</v></c>`:`<c r="${t}"${p(e)} t="str"${c}>${i}<v>${x(this.held(t,n))}</v></c>`:`<c r="${t}"${p(e)}${c}>${i}</c>`}cell(t,e){const s=R({row:t,col:e}),n=this.styleOf(t,e),r=this.sheet.at(t,e);return r instanceof me?this.formula(s,n,r):r===void 0&&this.sheet.spillAt(t,e)&&this.cached?this.value(s,n,this.calc.value(this.sheet,t,e)):this.value(s,n,r??null)}columns(){const{sheet:t}=this,{spec:e}=t,s=new Map,n=new Map;for(const a of t.tables)for(const i of a.columns)i.spec?.width!==void 0&&n.set(a.at.col+i.index,i.spec.width);const r=new Set(n.keys()),d=new Map;for(const[a,i]of Object.entries(e.columns??{})){const c=ne(a);c!==void 0&&(d.set(c,i),r.add(c))}for(const a of r){const i=d.get(a),c=i?.width??n.get(a),u=J(i);s.set(a,o("col",{min:a+1,max:a+1,width:be(c??$e),style:u===void 0?void 0:this.styles.xf(u),hidden:i?.hidden===!0?!0:void 0,customWidth:c===void 0?void 0:!0}))}const h=[...s.keys()].sort((a,i)=>a-i).map(a=>s.get(a)??"");return h.length===0?"":o("cols",{},...h)}rowAttrs(t){const e=this.sheet.spec.rows?.[String(t+1)],s=J(e),n=e?.height??this.tall.get(t);return{r:t+1,s:s===void 0?void 0:this.styles.xf(s),customFormat:s===void 0?void 0:!0,ht:n===void 0?void 0:ye(n),customHeight:n===void 0?void 0:!0,hidden:e?.hidden===!0||this.hiddenRows.has(t)?!0:void 0}}rows(){const{sheet:t}=this,e=new Set(this.places.keys());for(const n of Object.keys(t.spec.rows??{}))e.add(Number(n)-1);for(const n of this.hiddenRows)e.add(n);const s=[];for(const n of[...e].sort((r,d)=>r-d)){const r=[...this.places.get(n)??[]].sort((a,i)=>a-i),d=o("row",this.rowAttrs(n)).slice(4,-2);if(r.length===0){s.push(`<row${d}/>`);continue}let h=`<row${d}>`;for(const a of r)h+=this.cell(n,a);s.push(`${h}</row>`)}return s.join("")}view(t){const{freeze:e}=this.sheet;let s="";if(e&&(e.row>0||e.col>0)){const n=e.row>0&&e.col>0?"bottomRight":e.row>0?"bottomLeft":"topRight";s=o("pane",{xSplit:e.col>0?e.col:void 0,ySplit:e.row>0?e.row:void 0,topLeftCell:R(e),activePane:n,state:"frozen"})}return o("sheetViews",{},o("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},s))}write(t,e){const{sheet:s}=this;this.gather();const n=_e(this.places),r=this.rows(),d=s.merges.map(i=>o("mergeCell",{ref:E(i)})),h=s.tables.map((i,c)=>o("tablePart",{"r:id":`rId${String(c+1)}`}));return{xml:g+o("worksheet",{xmlns:y.main,"xmlns:r":y.rel},s.spec.tab===void 0?"":o("sheetPr",{},o("tabColor",{rgb:`FF${s.spec.tab.slice(1).toUpperCase()}`})),o("dimension",{ref:n?E(n):"A1"}),this.view(t),o("sheetFormatPr",{defaultRowHeight:15}),this.columns(),r===""?o("sheetData"):`<sheetData>${r}</sheetData>`,this.scenarios?Ce(this.scenarios):"",this.sheetFilter(),d.length>0?o("mergeCells",{count:d.length},...d):"",...s.conditions.map((i,c)=>this.condition(i,c+1)),this.validations(),o("pageMargins",{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3}),this.drawn?o("drawing",{"r:id":`rId${String(h.length+1)}`}):"",h.length>0?o("tableParts",{count:h.length},...h):""),tables:s.tables.map((i,c)=>this.tableXml(i,e+c))}}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const s=he(t);return typeof s.value=="number"&&s.formula===void 0?String(s.value):`"${t.replaceAll('"','""')}"`}const e=oe(t);return e.ok?O(e.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t){return o("cfvo",{type:t.at,val:t.value===void 0?void 0:typeof t.value=="number"?t.value:this.bound(t.value)})}condition(t,e){const{spec:s}=t,n=s.range,r=(i,...c)=>o("conditionalFormatting",{sqref:n},o("cfRule",{...i,priority:e,stopIfTrue:s.stop===!0?!0:void 0},...c)),d=()=>{const i=Me(s);return Object.keys(i).length===0?void 0:this.styles.dxf(i)},h=t.areas[0],a=h?R({row:h.top,col:h.left}):"A1";switch(s.type){case"cellIs":return r({type:"cellIs",dxfId:d(),operator:s.operator},...s.formula.map(i=>o("formula",{},x(this.bound(i)))));case"containsText":{const i=s.operator??"contains",c=`"${s.text.replaceAll('"','""')}"`,u=i==="contains"?`NOT(ISERROR(SEARCH(${c},${a})))`:i==="notContains"?`ISERROR(SEARCH(${c},${a}))`:i==="beginsWith"?`LEFT(${a},LEN(${c}))=${c}`:`RIGHT(${a},LEN(${c}))=${c}`;return r({type:i==="contains"?"containsText":i==="notContains"?"notContainsText":i,dxfId:d(),operator:i==="contains"?"containsText":i,text:s.text},o("formula",{},x(u)))}case"duplicateValues":case"uniqueValues":return r({type:s.type,dxfId:d()});case"top10":return r({type:"top10",dxfId:d(),percent:s.percent===!0?!0:void 0,bottom:s.bottom===!0?!0:void 0,rank:s.rank});case"aboveAverage":return r({type:"aboveAverage",dxfId:d(),aboveAverage:s.below===!0?!1:void 0,equalAverage:s.equal===!0?!0:void 0});case"expression":return r({type:"expression",dxfId:d()},o("formula",{},x(this.bound(s.formula.startsWith("=")?s.formula:`=${s.formula}`))));case"dataBar":return r({type:"dataBar"},o("dataBar",{showValue:s.show===!1?!1:void 0},this.cfvo(s.min??{at:"min"}),this.cfvo(s.max??{at:"max"}),o("color",{rgb:K(s.color)})));case"colorScale":return r({type:"colorScale"},o("colorScale",{},...s.stops.map(i=>this.cfvo(i)),...s.stops.map(i=>o("color",{rgb:K(i.color)}))));case"iconSet":{const i=Number.parseInt(s.icons,10),c=s.stops??Array.from({length:i},(u,S)=>({at:"percent",value:Math.round(S*100/i)}));return r({type:"iconSet"},o("iconSet",{iconSet:s.icons,showValue:s.show===!1?!1:void 0,reverse:s.reverse===!0?!0:void 0},...c.map(u=>this.cfvo(u))))}}}validation(t){const{spec:e}=t;let s="";if(e.values){const h=e.values.join(",");(h.length>B||e.values.some(a=>a.includes(",")))&&this.left.push(`${this.sheet.name}!${e.range}: a list a file's cell cannot spell out, its values longer than ${String(B)} characters or holding a comma`),s=`"${h.slice(0,B)}"`}else s=this.bound(e.formula?.[0]);const n=this.bound(e.formula?.[1]),{error:r,prompt:d}=e;return e.multiple===!0&&this.left.push(`${this.sheet.name}!${e.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`),o("dataValidation",{type:e.type,errorStyle:r?.style===void 0||r.style==="stop"?void 0:r.style,operator:e.operator===void 0||e.operator==="between"?void 0:e.operator,allowBlank:e.blank===!1?void 0:!0,showDropDown:e.dropdown===!1?!0:void 0,showInputMessage:d?.show===!1?void 0:!0,showErrorMessage:r?.show===!1||e.multiple===!0?void 0:!0,errorTitle:r?.title,error:r?.message,promptTitle:d?.title,prompt:d?.message,sqref:e.range},s===""?"":o("formula1",{},x(s)),n===""?"":o("formula2",{},x(n)))}validations(){const t=this.sheet.validations;return t.length===0?"":o("dataValidations",{count:t.length},...t.map(e=>this.validation(e)))}filterColumns(t){return[...t.columns.entries()].sort(([e],[s])=>e-s).map(([e,s])=>Ie(e-t.area.left,s))}sheetFilter(){const t=this.sheet.filters.find(e=>!e.table);return t?o("autoFilter",{ref:E(t.area)},...this.filterColumns(t)):""}columnFormula(t,e){if(!e?.node)return"";const s=V(e.node,this.isRangeName),n=O(e.node,{table:t.name,isTable:this.isTable,array:s});return o("calculatedColumnFormula",{array:s?!0:void 0},H(n))}tableXml(t,e){const s=t.area,n=E({...s,bottom:Math.max(s.bottom,s.top+1)}),r=t.spec.style??DEFAULT_TABLE_STYLE,d=this.sheet.filters.find(h=>h.table===t);return g+o("table",{xmlns:y.main,id:e,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},d?o("autoFilter",{ref:n},...this.filterColumns(d)):"",o("tableColumns",{count:t.columns.length},...t.columns.map((h,a)=>o("tableColumn",{id:a+1,name:h.name},this.columnFormula(t,h.formula)))),r==="none"?o("tableStyleInfo",{showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}):o("tableStyleInfo",{name:r,showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}))}}const K=l=>`FF${l.slice(1).toUpperCase()}`;function Me(l){if(l.type==="dataBar"||l.type==="colorScale"||l.type==="iconSet")return{};const t={};for(const e of["bold","italic","underline","strike","color","fill","border"])l[e]!==void 0&&(t[e]=l[e]);return t}function Ie(l,t){return o("filterColumn",{colId:l},o("filters",{blank:t.blanks===!0?!0:void 0},...(t.values??[]).map(e=>o("filter",{val:e}))))}const p=l=>l===void 0?"":` s="${String(l)}"`,Z=l=>l.code!=="#CYCLE!";function _e(l){let t;for(const[e,s]of l)for(const n of s)t?(t.top=Math.min(t.top,e),t.bottom=Math.max(t.bottom,e),t.left=Math.min(t.left,n),t.right=Math.max(t.right,n)):t={top:e,bottom:e,left:n,right:n};return t}const Re=new Set(["width","height","hidden"]);function J(l){if(!l)return;const t=Object.fromEntries(Object.entries(l).filter(([e])=>!Re.has(e)));return Object.keys(t).length===0?void 0:t}const D=l=>g+o("Relationships",{xmlns:y.pkg},...l.map(([t,e],s)=>o("Relationship",{Id:`rId${String(s+1)}`,Type:t,Target:e})));function Le(l,t){const e=l.name(t);if(!e)return;const s=e.formula?.node;if(s)return O(s,{isTable:r=>l.table(r)!==void 0,array:!0});const{value:n}=e;return n==null?'""':typeof n=="string"?`"${n.replaceAll('"','""')}"`:typeof n=="boolean"?n?"TRUE":"FALSE":n instanceof P?n.code:String(n)}const Fe=(l,t)=>l.length===t.length&&l.every((e,s)=>e===t[s]),Pe=l=>`$${Y(l.left)}$${String(l.top+1)}:$${Y(l.right)}$${String(l.bottom+1)}`;export function writeXlsx(l,t={}){const e=l.wb,s=[];e.checks.length>0&&s.push(`${String(e.checks.length)} check${e.checks.length===1?"":"s"}: a file has no such thing`);const n=de(l);s.push(...n.left);const r=new pe,d=new ve,h=new TextEncoder,a={},i=[["/xl/workbook.xml",$.sheet]],c=Math.max(0,e.sheets.findIndex(m=>m.spec.hidden!==!0));let u=1,S=!1;const b=new Map;let k=0,M=0;for(const[m,f]of e.sheets.entries()){const v=String(m+1),T=Ae(f,l,t.file,s),q=new Ee(f,l,r,d,t.cached!==!1,s,T,n.sheets.find(C=>C.sheet===f)),U=q.write(m===c,u);S||=q.arrays,a[`xl/worksheets/sheet${v}.xml`]=U.xml,i.push([`/xl/worksheets/sheet${v}.xml`,$.worksheet]);const L=[];for(const C of U.tables){const A=`table${String(u)}.xml`;u+=1,a[`xl/tables/${A}`]=C,i.push([`/xl/tables/${A}`,$.table]),L.push([`${w}table`,`../tables/${A}`])}if(f.charts.length>0||T.length>0){k+=1;const C=`drawing${String(k)}.xml`;a[`xl/drawings/${C}`]=ue(f.charts,T),i.push([`/xl/drawings/${C}`,$.drawing]),L.push([`${w}drawing`,`../drawings/${C}`]);const A=f.charts.map(_=>{M+=1;const F=`chart${String(M)}.xml`;return a[`xl/charts/${F}`]=fe(l,f,_),i.push([`/xl/charts/${F}`,$.chart]),[`${w}chart`,`../charts/${F}`]});for(const _ of T){const W=[...b].find(([,te])=>Fe(te,_.bytes))?.[0]??`image${String(b.size+1)}${_.file}`;b.set(W,_.bytes),A.push([`${w}image`,`../media/${W}`])}a[`xl/drawings/_rels/${C}.rels`]=D(A)}L.length>0&&(a[`xl/worksheets/_rels/sheet${v}.xml.rels`]=D(L))}const Q=e.sheets.length,I=e.sheets.map((m,f)=>[`${w}worksheet`,`worksheets/sheet${String(f+1)}.xml`]);I.push([`${w}theme`,"theme/theme1.xml"]),I.push([`${w}styles`,"styles.xml"]),I.push([`${w}sharedStrings`,"sharedStrings.xml"]),S&&(I.push([`${w}sheetMetadata`,"metadata.xml"]),a["xl/metadata.xml"]=g+ke,i.push(["/xl/metadata.xml",$.metadata]));const N=[...e.names.values()].flatMap(m=>{const f=Le(e,m.name);return f===void 0?[]:[o("definedName",{name:m.name},x(f))]});e.sheets.forEach((m,f)=>{const v=m.filters.find(T=>!T.table);v&&N.push(o("definedName",{name:"_xlnm._FilterDatabase",localSheetId:f,hidden:!0},x(`${re(m.name)}${Pe(v.area)}`)))}),a["xl/workbook.xml"]=g+o("workbook",{xmlns:y.main,"xmlns:r":y.rel},o("workbookPr",{}),o("bookViews",{},o("workbookView",{activeTab:c===0?void 0:c})),o("sheets",{},...e.sheets.map((m,f)=>o("sheet",{name:m.name,sheetId:f+1,state:m.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(f+1)}`}))),N.length>0?o("definedNames",{},...N):"",o("calcPr",{calcId:xe,fullCalcOnLoad:!0})),a["xl/_rels/workbook.xml.rels"]=D(I),a["xl/styles.xml"]=g+r.xml(),a["xl/sharedStrings.xml"]=g+d.xml(),a["xl/theme/theme1.xml"]=g+ge,a["docProps/core.xml"]=g+o("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},e.title===void 0?"":o("dc:title",{},x(e.title))),a["docProps/app.xml"]=g+o("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},o("Application",{},"AllyHub")),a["_rels/.rels"]=D([[`${w}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${w}extended-properties`,"docProps/app.xml"]]),i.push(["/xl/styles.xml",$.styles],["/xl/sharedStrings.xml",$.strings],["/xl/theme/theme1.xml",$.theme],["/docProps/core.xml",$.core],["/docProps/app.xml",$.app]),a["[Content_Types].xml"]=g+o("Types",{xmlns:y.types},o("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),o("Default",{Extension:"xml",ContentType:"application/xml"}),...[...new Set([...b.keys()].map(m=>m.split(".").pop()??""))].sort().map(m=>o("Default",{Extension:m,ContentType:`image/${m==="jpg"?"jpeg":m}`})),...i.map(([m,f])=>o("Override",{PartName:m,ContentType:f})));const X=["[Content_Types].xml","_rels/.rels","docProps/app.xml","docProps/core.xml","xl/workbook.xml","xl/_rels/workbook.xml.rels",...Array.from({length:Q},(m,f)=>`xl/worksheets/sheet${String(f+1)}.xml`)],ee=[...X,...Object.keys(a).filter(m=>!X.includes(m)).sort()],j={};for(const m of ee)j[m]=[h.encode(a[m]??""),{mtime:G}];for(const[m,f]of[...b].sort(([v],[T])=>v.localeCompare(T)))j[`xl/media/${m}`]=[f,{mtime:G}];return{bytes:se(j),left:s}}
2
+ import{SHEET_MARGINS as pe,SHEET_NOTE_AUTHOR as K,SHEET_PAPERS as we}from"@allyhub-next/formats";import{MAX_COLUMNS as Q,MAX_ROWS as ee,cellName as _,columnIndex as xe,columnLetter as D,rangeName as M,readAddress as te,readArea as ge}from"../address.js";import{parseFormula as $e}from"../formula/parse.js";import{sheetPrefix as X}from"../formula/print.js";import{walk as ye}from"../formula/walk.js";import{fileCells as be,isPicture as ve,pictureHeight as Se,pictureSize as se}from"../files.js";import{scenariosByCell as ke}from"../scenario.js";import{CellError as P,readTyped as Ae}from"../values.js";import{FormulaCell as Ce}from"../workbook.js";import{chartPart as Ee,drawingPart as Te}from"./charts.js";import{fileFormula as N,needsArray as B}from"./formula.js";import{GRID_END as W}from"./read.js";import{Styles as Me}from"./styles.js";import{THEME_XML as Re}from"./theme.js";import{HEAD as S,NS as k,el as o,xstring as x}from"./xml.js";import{ZipOut as _e}from"./zip.js";const A={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},v=`${k.rel}/`,ne="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",oe="http://schemas.microsoft.com/office/excel/2006/main",re={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},je=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const Le=64,Oe=7,Fe=a=>Math.min(255,Math.floor(a/Oe*256)/256),Ie=a=>Math.min(409.5,a*3/4),q=32767,De=255,Pe=2e5,Ne=o("metadata",{xmlns:k.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},o("metadataTypes",{count:1},o("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),o("futureMetadata",{name:"XLDAPR",count:1},o("bk",{},o("extLst",{},o("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},o("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),o("cellMetadata",{count:1},o("bk",{},o("rc",{t:1,v:0}))));class Ve{index=new Map;count=0;of(t){this.count+=1;let s=this.index.get(t);return s===void 0&&(s=this.index.size,this.index.set(t,s)),s}write(t){t.write(`${S}<sst xmlns="${k.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const s of this.index.keys()){const e=/^\s|\s$|\n/u.test(s);t.write(`<si><t${e?' xml:space="preserve"':""}>${x(s)}</t></si>`)}t.write("</sst>"),t.end()}}function ze(a){for(const t in a)if(Object.hasOwn(a,t))return!1;return!0}const He=a=>o("x",a).slice(2,-2),Ue="Base case";function Xe(a){const t=new Map;for(const n of a.scenarios)for(const r of n.cells)t.set(_(r),r);const s=(n,r)=>o("inputCells",{r:_(n),val:r===null||r instanceof P?"":typeof r=="boolean"?r?"1":"0":String(r)}),e=(n,r)=>o("scenario",{name:n,locked:!0,count:r.length,user:"AllyHub"},r.join(""));return o("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ue,[...t.values()].map(n=>s(n,n.base))),...a.scenarios.map(n=>e(n.name,n.cells.map(r=>s(r,r.value)))))}function Be(a,t,s,e){const n=[];let r=0;for(const{row:l,col:h,paths:c,column:i}of be(a,t)){let d=0;const f=Se(i);for(const m of c){const u=ve(m)?s?.(m):void 0,$=u&&se(u);if(!u||!$){r+=1;continue}const T=Math.round($.width/$.height*f);n.push({row:l,col:h,x:d,width:T,height:f,name:m.split("/").pop()??m,path:m,file:`.${$.type==="jpeg"?"jpg":$.type}`,bytes:u}),d+=T+4}}for(const l of a.spec.pictures??[]){const h=te(l.at),c=s?.(l.file),i=c&&se(c);if(!h||!c||!i)continue;const d=i.width/i.height,f=l.width??(l.height===void 0?i.width:l.height*d);n.push({row:h.row,col:h.col,x:l.x??0,y:l.y??0,width:Math.round(f),height:Math.round(l.height??f/d),name:l.file.split("/").pop()??l.file,path:l.file,file:`.${i.type==="jpeg"?"jpg":i.type}`,bytes:c})}return r>0&&e.push(`${a.name}: ${String(r)} file${r===1?"":"s"} in a cell, which stay${r===1?"s":""} a name`),n}class We{name;columns=[];known=new Map;constructor(t){let s=LISTS_SHEET;for(let e=2;t.sheet(s);e++)s=`${LISTS_SHEET} (${String(e)})`;this.name=s}place(t){const s=JSON.stringify(t);let e=this.known.get(s);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(s,e));const n=D(e);return`${X(this.name)}$${n}$1:$${n}$${String(Math.max(1,t.length))}`}xml(t){const s=[],e=Math.max(0,...this.columns.map(n=>n.length));for(let n=0;n<e;n++){let r=`<row r="${String(n+1)}">`;this.columns.forEach((l,h)=>{const c=l[n];c!==void 0&&(r+=`<c r="${_({row:n,col:h})}" t="s"><v>${String(t.of(c))}</v></c>`)}),s.push(`${r}</row>`)}return`${S}<worksheet xmlns="${k.main}" xmlns:r="${k.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${s.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class qe{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,s){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const n=new Int32Array(this.size*2);n.set(this.cols),this.cols=n}this.rows[this.size]=t,this.cols[this.size]=s,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let s=1/0,e=-1,n=1/0,r=-1;for(let i=0;i<t;i++){const d=this.rows[i]??0,f=this.cols[i]??0;d<s&&(s=d),d>e&&(e=d),f<n&&(n=f),f>r&&(r=f)}const l=new Uint32Array(e-s+2);for(let i=0;i<t;i++){const d=(this.rows[i]??0)-s+1;l[d]=(l[d]??0)+1}for(let i=1;i<l.length;i++)l[i]=(l[i]??0)+(l[i-1]??0);const h=l.slice(0,-1),c=new Int32Array(t);for(let i=0;i<t;i++){const d=(this.rows[i]??0)-s,f=h[d]??0;c[f]=this.cols[i]??0,h[d]=f+1}return{start:l,cols:c,top:s,used:{top:s,bottom:e,left:n,right:r}}}}function Ge(a,t){if(!a)return!1;let s=!1;const e=t.toLowerCase();return ye(a,n=>{(n.kind==="ref"||n.kind==="name")&&n.sheet!==void 0&&n.sheet.toLowerCase()!==e&&(s=!0)}),s}const Ye=(a,t)=>`{00000000-0000-4000-8000-${(a*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class Ze{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];shapes=new Map;groups=new Map;constructor(t,s,e,n,r,l,h,c,i=[],d){this.sheet=t,this.calc=s,this.wb=s.wb,this.styles=e,this.strings=n,this.cached=r,this.left=l,this.lists=h,this.index=c,this.isTable=m=>this.wb.table(m)!==void 0,this.isRangeName=m=>{const u=this.wb.name(m,t)?.formula?.node;return this.isTable(m)||u!==void 0&&B({kind:"unary",op:"-",arg:u})},this.hiddenRows=s.filtered(t),this.scenarios=d,this.drawn=t.charts.length>0||i.length>0;const f=new Map;for(const m of i)m.y===void 0&&f.set(m.row,Math.max(f.get(m.row)??0,m.height));this.tall=f}grid(){const{sheet:t}=this;if(t.lastRow>=ee)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${W}: an Excel file cannot hold it.`);if(t.columnsUsed>Q)throw new Error(`${t.name} reaches past column ${D(Q-1)}, and ${W}: an Excel file cannot hold it.`);for(const s of Object.keys(t.spec.rows??{}))if(Number(s)>ee)throw new Error(`${t.name} sets row ${s}, and ${W}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,s=new qe;for(let e=0;e<t.columnsUsed;e++){const[n,r]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let l=n;l<=r;l++)(t.at(l,e)!==void 0||t.spillAt(l,e))&&s.add(l,e)}for(const{area:e}of t.styledAreas()){const n=(e.bottom-e.top+1)*(e.right-e.left+1);if(n>Pe){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(n)} cells being too many to write empty`);continue}for(let r=e.top;r<=e.bottom;r++)for(let l=e.left;l<=e.right;l++)s.add(r,l)}for(const e of t.keys.keys())s.add(Math.floor(e/16384),e%16384);return s.byRow()}styleOf(t,s){const e=this.sheet.lookAt(t,s);return ze(e)?void 0:this.styles.xf(e)}held(t,s){return s.length<=q?s:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(q)} characters, of its ${String(s.length)}`),s.slice(0,q))}value(t,s,e){return e===null?`<c r="${t}"${C(s)}/>`:typeof e=="number"?`<c r="${t}"${C(s)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${C(s)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?ce(e)?`<c r="${t}"${C(s)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${C(s)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${C(s)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,s,e){const n=this.calc.value(e.sheet,e.row,e.col),{shared:r}=e,{node:l}=r;if(!l)return`<c r="${t}"${C(s)} t="e"><v>#NAME?</v></c>`;let h=this.shapes.get(r);h===void 0&&(h=B(l,this.isRangeName),this.shapes.set(r,h));const c=e.array!==void 0||e.blocked!==void 0||h;let i=c?void 0:this.groups.get(r);i?.written===!1&&(e.row!==i.ref.top||e.col!==i.ref.left)&&(i=void 0);let d,f="";if(i?.written===!0)d=`<f t="shared" si="${String(i.si)}"/>`;else{const m=N(e.moved,{table:this.table(e),isTable:this.isTable,array:c});d=i?`<f t="shared" ref="${M(i.ref)}" si="${String(i.si)}">${x(m)}</f>`:`<f>${x(m)}</f>`,i&&(i.written=!0),c&&(d=this.arrayFormula(e,m))}return c&&(this.arrays=!0,f=' cm="1"'),this.cached?n===null||typeof n=="number"?`<c r="${t}"${C(s)}${f}>${d}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${C(s)} t="b"${f}>${d}<v>${n?"1":"0"}</v></c>`:n instanceof P?ce(n)?`<c r="${t}"${C(s)} t="e"${f}>${d}<v>${n.code}</v></c>`:`<c r="${t}"${C(s)}${f}>${d}<v>0</v></c>`:`<c r="${t}"${C(s)} t="str"${f}>${d}<v>${x(this.held(t,n))}</v></c>`:`<c r="${t}"${C(s)}${f}>${d}</c>`}arrayFormula(t,s){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${x(s)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const n=t.get(e.shared);if(!n)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:r}=n;e.row<r.top&&(r.top=e.row),e.row>r.bottom&&(r.bottom=e.row),e.col<r.left&&(r.left=e.col),e.col>r.right&&(r.right=e.col),(e.row<n.first.row||e.row===n.first.row&&e.col<n.first.col)&&(n.first=e),n.n+=1}}let s=0;for(const[e,{area:n,first:r,n:l}]of t)l>1&&r.row===n.top&&r.col===n.left&&(this.groups.set(e,{si:s,ref:n,written:!1}),s+=1)}cell(t,s){const e=_({row:t,col:s}),n=this.styleOf(t,s),r=this.sheet.at(t,s);return r instanceof Ce?this.formula(e,n,r):r===void 0&&this.cached&&this.sheet.spillAt(t,s)?this.value(e,n,this.calc.value(this.sheet,t,s)):this.value(e,n,r??null)}columns(){const{sheet:t}=this,{spec:s}=t,e=new Map,n=new Map;for(const c of t.tables)for(const i of c.columns)i.spec?.width!==void 0&&n.set(c.at.col+i.index,i.spec.width);const r=new Set(n.keys()),l=new Map;for(const[c,i]of Object.entries(s.columns??{})){const d=xe(c);d!==void 0&&(l.set(d,i),r.add(d))}for(const c of r){const i=l.get(c),d=i?.width??n.get(c),f=de(i);e.set(c,o("col",{min:c+1,max:c+1,width:Fe(d??Le),style:f===void 0?void 0:this.styles.xf(f),hidden:i?.hidden===!0?!0:void 0,customWidth:d===void 0?void 0:!0,outlineLevel:i?.level}))}const h=[...e.keys()].sort((c,i)=>c-i).map(c=>e.get(c)??"");return h.length===0?"":`<cols>${h.join("")}</cols>`}rowAttrs(t){const s=this.sheet.spec.rows?.[String(t+1)],e=de(s),n=s?.height??this.tall.get(t);return He({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:n===void 0?void 0:Ie(n),customHeight:n===void 0?void 0:!0,hidden:s?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:s?.level})}rows(t,s){const{sheet:e}=this,n=new Set(this.hiddenRows);for(const d of Object.keys(e.spec.rows??{}))n.add(Number(d)-1);const{start:r,cols:l,top:h}=s;let c=s.used?h:1/0,i=s.used?s.used.bottom:-1;for(const d of n)d<c&&(c=d),d>i&&(i=d);for(let d=Math.max(0,c);d<=i;d++){const f=d-h,m=f>=0&&f<r.length-1?r[f]??0:0,u=f>=0&&f<r.length-1?r[f+1]??0:0;if(m===u&&!n.has(d))continue;if(m===u){t.write(`<row${this.rowAttrs(d)}/>`);continue}const $=l.subarray(m,u).sort();let T=`<row${this.rowAttrs(d)}>`,y=-1;for(const b of $)b!==y&&(y=b,T+=this.cell(d,b));t.write(`${T}</row>`)}}view(t){const{freeze:s}=this.sheet;let e="";if(s&&(s.row>0||s.col>0)){const n=s.row>0&&s.col>0?"bottomRight":s.row>0?"bottomLeft":"topRight";e=o("pane",{xSplit:s.col>0?s.col:void 0,ySplit:s.row>0?s.row:void 0,topLeftCell:_(s),activePane:n,state:"frozen"})}return o("sheetViews",{},o("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,s,e){const{sheet:n}=this;this.grid();const r=this.gather();this.shareFormulas();const l=n.tables.map((y,b)=>o("tablePart",{"r:id":`rId${String(b+1)}`})),{print:h}=n.spec,c=h?.fit,i=Object.keys(n.spec.notes??{}).length>0;t.write(`${S}<worksheet xmlns="${k.main}" xmlns:r="${k.rel}">`+(n.spec.tab===void 0&&c===void 0?"":o("sheetPr",{},n.spec.tab===void 0?"":o("tabColor",{rgb:`FF${n.spec.tab.slice(1).toUpperCase()}`}),c===void 0?"":o("pageSetUpPr",{fitToPage:!0})))+o("dimension",{ref:r.used?M(r.used):"A1"})+this.view(s)+o("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ie(n.spec.rows),outlineLevelCol:ie(n.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,r);const d=l.length+1+(this.drawn?1:0)+(i?2:0);let f=0;const m=Object.entries(n.spec.links??{}).map(([y,b])=>b.startsWith("#")?o("hyperlink",{ref:y,location:b.slice(1)}):o("hyperlink",{ref:y,"r:id":`rId${String(d+f++)}`})),u=n.merges.map(y=>o("mergeCell",{ref:M(y)})),$=n.conditions.map((y,b)=>this.condition(y,b+1)).join(""),T=this.validations();return t.write("</sheetData>"+(n.spec.protect===!0?o("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Xe(this.scenarios):"")+this.sheetFilter()+(u.length>0?o("mergeCells",{count:u.length},u.join("")):"")+$+T+(m.length>0?o("hyperlinks",{},m.join("")):"")+o("pageMargins",{...pe,...h?.margins})+(h?.orientation!==void 0||h?.paper!==void 0||c!==void 0?o("pageSetup",{paperSize:h?.paper===void 0?void 0:we[h.paper],fitToWidth:c?.width,fitToHeight:c?.height,orientation:h?.orientation}):"")+(h?.header||h?.footer?o("headerFooter",{},h.header?o("oddHeader",{},x(ae(h.header))):"",h.footer?o("oddFooter",{},x(ae(h.footer))):""):"")+(this.drawn?o("drawing",{"r:id":`rId${String(l.length+1)}`}):"")+(i?o("legacyDrawing",{"r:id":`rId${String(l.length+(this.drawn?2:1))}`}):"")+(l.length>0?o("tableParts",{count:l.length},l.join("")):"")+this.extensions()+"</worksheet>"),t.end(),n.tables.map((y,b)=>this.tableXml(y,e+b))}extensions(){const t=[];return this.newerRules.length>0&&t.push(o("ext",{uri:re.conditional,"xmlns:x14":ne},o("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(o("ext",{uri:re.validations,"xmlns:x14":ne},o("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":oe},this.newerValidations.join("")))),t.length===0?"":o("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Ae(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const s=$e(t);return s.ok?N(s.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,s){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return s?o("x14:cfvo",{type:t.at},e===void 0?"":o("xm:f",{},x(e))):o("cfvo",{type:t.at,val:e})}crosses(t){return t.some(s=>Ge(s?.node,this.sheet.name))}condition(t,s){const{spec:e}=t,n=e.range,r=e.type!=="dataBar"&&this.crosses(t.formulas),l=(f,m,...u)=>{if(!r){const $=Object.keys(m).length===0?void 0:this.styles.dxf(m);return o("conditionalFormatting",{sqref:n},o("cfRule",{...f,dxfId:$,priority:s,stopIfTrue:e.stop===!0?!0:void 0},...u))}return this.newerRules.push(o("x14:conditionalFormatting",{"xmlns:xm":oe},o("x14:cfRule",{...f,priority:s,stopIfTrue:e.stop===!0?!0:void 0,id:Ye(this.index,s)},...u.map($=>$.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(m).length===0?"":this.styles.dxfXml(m,"x14:dxf")),o("xm:sqref",{},n))),""},h=et(e),c=t.areas[0],i=c?_({row:c.top,col:c.left}):"A1",d=f=>o("formula",{},x(f));switch(e.type){case"cellIs":return l({type:"cellIs",operator:e.operator},h,...e.formula.map(f=>d(this.bound(f))));case"containsText":{const f=e.operator??"contains",m=`"${e.text.replaceAll('"','""')}"`,u=f==="contains"?`NOT(ISERROR(SEARCH(${m},${i})))`:f==="notContains"?`ISERROR(SEARCH(${m},${i}))`:f==="beginsWith"?`LEFT(${i},LEN(${m}))=${m}`:`RIGHT(${i},LEN(${m}))=${m}`;return l({type:f==="contains"?"containsText":f==="notContains"?"notContainsText":f,operator:f==="contains"?"containsText":f,text:e.text},h,d(u))}case"duplicateValues":case"uniqueValues":return l({type:e.type},h);case"top10":return l({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},h);case"aboveAverage":return l({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},h);case"expression":return l({type:"expression"},h,d(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return l({type:"dataBar"},{},o("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),o("color",{rgb:le(e.color)})));case"colorScale":{const f=r?"x14:":"";return l({type:"colorScale"},{},o(`${f}colorScale`,{},...e.stops.map(m=>this.cfvo(m,r)),...e.stops.map(m=>o(`${f}color`,{rgb:le(m.color)}))))}case"iconSet":{const f=Number.parseInt(e.icons,10),m=e.stops??Array.from({length:f},(u,$)=>({at:"percent",value:Math.round($*100/f)}));return l({type:"iconSet"},{},o(r?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...m.map(u=>this.cfvo(u,r))))}}}validation(t){const{spec:s}=t;let e="",n=this.crosses(t.formulas);if(s.values){const i=s.values.join(",");i.length>De||s.values.some(d=>d.includes(",")||d.includes('"'))?(e=this.lists.place(s.values),n=!0):e=`"${i}"`}else e=this.bound(s.formula?.[0]);const r=this.bound(s.formula?.[1]),{error:l,prompt:h}=s;s.multiple===!0&&this.left.push(`${this.sheet.name}!${s.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const c={type:s.type,errorStyle:l?.style===void 0||l.style==="stop"?void 0:l.style,operator:s.operator===void 0||s.operator==="between"?void 0:s.operator,allowBlank:s.blank===!1?void 0:!0,showDropDown:s.dropdown===!1?!0:void 0,showInputMessage:h?.show===!1?void 0:!0,showErrorMessage:l?.show===!1||s.multiple===!0?void 0:!0,errorTitle:l?.title,error:l?.message,promptTitle:h?.title,prompt:h?.message};return n?(this.newerValidations.push(o("x14:dataValidation",c,e===""?"":o("x14:formula1",{},o("xm:f",{},x(e))),r===""?"":o("x14:formula2",{},o("xm:f",{},x(r))),o("xm:sqref",{},s.range))),""):o("dataValidation",{...c,sqref:s.range},e===""?"":o("formula1",{},x(e)),r===""?"":o("formula2",{},x(r)))}validations(){const t=this.sheet.validations.map(s=>this.validation(s)).filter(s=>s!=="");return t.length===0?"":o("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([s],[e])=>s-e).map(([s,e])=>tt(s-t.area.left,e))}sheetFilter(){const t=this.sheet.filters.find(s=>!s.table);return t?o("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,s){if(!s?.node)return"";const e=B(s.node,this.isRangeName),n=N(s.node,{table:t.name,isTable:this.isTable,array:e});return o("calculatedColumnFormula",{array:e?!0:void 0},x(n))}tableXml(t,s){const e=t.area,n=M({...e,bottom:Math.max(e.bottom,e.top+1)}),r=t.spec.style??DEFAULT_TABLE_STYLE,l=this.sheet.filters.find(h=>h.table===t);return S+o("table",{xmlns:k.main,id:s,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},l?o("autoFilter",{ref:n},...this.filterColumns(l)):"",o("tableColumns",{count:t.columns.length},t.columns.map((h,c)=>o("tableColumn",{id:c+1,name:h.name},this.columnFormula(t,h.formula))).join("")),r==="none"?o("tableStyleInfo",{showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}):o("tableStyleInfo",{name:r,showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}))}}const ie=a=>{let t;for(const s of Object.values(a??{}))s.level!==void 0&&(t=Math.max(t??0,s.level));return t},ae=a=>[a.left===void 0?"":`&L${a.left}`,a.center===void 0?"":`&C${a.center}`,a.right===void 0?"":`&R${a.right}`].join(""),Je=a=>typeof a=="string"?{text:a,author:K}:{text:a.text,author:a.author??K};function Ke(a){const t=a.map(([e,n])=>({ref:e,...Je(n)})),s=[...new Set(t.map(e=>e.author))];return S+o("comments",{xmlns:k.main},o("authors",{},s.map(e=>o("author",{},x(e))).join("")),o("commentList",{},t.map(e=>o("comment",{ref:e.ref,authorId:s.indexOf(e.author)},o("text",{},o("r",{},o("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},x(e.text)))))).join("")))}function Qe(a){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${a.flatMap(([s],e)=>{const n=te(s);return n?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(n.col+1)}, 15, ${String(n.row)}, 2, ${String(n.col+3)}, 15, ${String(n.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(n.row)}</x:Row><x:Column>${String(n.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const le=a=>`FF${a.slice(1).toUpperCase()}`;function et(a){if(a.type==="dataBar"||a.type==="colorScale"||a.type==="iconSet")return{};const t={};for(const s of["bold","italic","underline","strike","color","fill","border"])a[s]!==void 0&&(t[s]=a[s]);return t}function tt(a,t){return o("filterColumn",{colId:a},o("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(s=>o("filter",{val:s})).join("")))}const C=a=>a===void 0?"":` s="${String(a)}"`,ce=a=>a.code!=="#CYCLE!",st=new Set(["width","height","hidden"]);function de(a){if(!a)return;const t=Object.fromEntries(Object.entries(a).filter(([s])=>!st.has(s)));return Object.keys(t).length===0?void 0:t}const V=a=>S+o("Relationships",{xmlns:k.pkg},a.map(([t,s,e],n)=>o("Relationship",{Id:`rId${String(n+1)}`,Type:t,Target:s,TargetMode:e})).join(""));function nt(a,t){const s=t.formula?.node;if(s)return N(s,{isTable:n=>a.table(n)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof P?e.code:String(e)}const ot=(a,t)=>a.length===t.length&&a.every((s,e)=>s===t[e]),he=a=>`$${D(a.left)}$${String(a.top+1)}:$${D(a.right)}$${String(a.bottom+1)}`;function rt(a){const t=[],s=(e,n)=>o("definedName",{name:e.name,localSheetId:n,hidden:e.hidden===!0?!0:void 0},x(nt(a,e)));for(const e of a.names.values())t.push(s(e));return a.sheets.forEach((e,n)=>{for(const d of e.names.values())t.push(s(d,n));const r=e.filters.find(d=>!d.table);r&&t.push(o("definedName",{name:"_xlnm._FilterDatabase",localSheetId:n,hidden:!0},x(`${X(e.name)}${he(r.area)}`)));const l=X(e.name),h=e.spec.print,c=h?.area===void 0?void 0:ge(h.area);c&&t.push(o("definedName",{name:"_xlnm.Print_Area",localSheetId:n},x(`${l}${he(c)}`)));const i=[h?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),h?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(d=>d===void 0?[]:[`${l}${d}`]);i.length>0&&t.push(o("definedName",{name:"_xlnm.Print_Titles",localSheetId:n},x(i.join(","))))}),t}export function writeXlsx(a,t={}){const s=a.wb,e=[];s.checks.length>0&&e.push(`${String(s.checks.length)} check${s.checks.length===1?"":"s"}: a file has no such thing`);const n=ke(a);e.push(...n.left);const r=new Me,l=new Ve,h=new We(s),c=new _e,i=[["/xl/workbook.xml",A.sheet]],d=Math.max(0,s.sheets.findIndex(p=>p.spec.hidden!==!0));let f=1,m=!1;const u=new Map;let $=0,T=0,y=0;for(const[p,w]of s.sheets.entries()){const H=String(p+1),O=Be(w,a,t.file,e),F=w.charts.filter(({spec:g})=>[g.categories,...g.series.flatMap(E=>[E.values,E.x])].some(E=>E?.endsWith("#"))).length;F>0&&e.push(`${w.name}: ${String(F)} chart${F===1?"":"s"} on a spill: ${F===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const Z=new Ze(w,a,r,l,t.cached!==!1,e,h,p,O,n.sheets.find(g=>g.sheet===w)),me=Z.write(c.part(`xl/worksheets/sheet${H}.xml`),p===d,f);m||=Z.arrays,i.push([`/xl/worksheets/sheet${H}.xml`,A.worksheet]);const R=[];for(const g of me){const E=`table${String(f)}.xml`;f+=1,c.add(`xl/tables/${E}`,g),i.push([`/xl/tables/${E}`,A.table]),R.push([`${v}table`,`../tables/${E}`])}if(w.charts.length>0||O.length>0){$+=1;const g=`drawing${String($)}.xml`;c.add(`xl/drawings/${g}`,Te(w.charts,O)),i.push([`/xl/drawings/${g}`,A.drawing]),R.push([`${v}drawing`,`../drawings/${g}`]);const E=w.charts.map(L=>{T+=1;const I=`chart${String(T)}.xml`;return c.add(`xl/charts/${I}`,Ee(a,w,L)),i.push([`/xl/charts/${I}`,A.chart]),[`${v}chart`,`../charts/${I}`]});for(const L of O){const J=[...u].find(([,ue])=>ot(ue,L.bytes))?.[0]??`image${String(u.size+1)}${L.file}`;u.set(J,L.bytes),E.push([`${v}image`,`../media/${J}`])}c.add(`xl/drawings/_rels/${g}.rels`,V(E))}const U=Object.entries(w.spec.notes??{});if(U.length>0){y+=1;const g=String(y);c.add(`xl/comments${g}.xml`,Ke(U)),i.push([`/xl/comments${g}.xml`,A.comments]),c.add(`xl/drawings/vmlDrawing${g}.vml`,Qe(U)),R.push([`${v}vmlDrawing`,`../drawings/vmlDrawing${g}.vml`]),R.push([`${v}comments`,`../comments${g}.xml`])}for(const g of Object.values(w.spec.links??{}))g.startsWith("#")||R.push([`${v}hyperlink`,g,"External"]);R.length>0&&c.add(`xl/worksheets/_rels/sheet${H}.xml.rels`,V(R))}const b=s.sheets.length,z=h.columns.length>0;if(z){const p=`xl/worksheets/sheet${String(b+1)}.xml`;c.add(p,h.xml(l)),i.push([`/${p}`,A.worksheet])}const j=[...s.sheets,...z?[void 0]:[]].map((p,w)=>[`${v}worksheet`,`worksheets/sheet${String(w+1)}.xml`]);j.push([`${v}theme`,"theme/theme1.xml"]),j.push([`${v}styles`,"styles.xml"]),j.push([`${v}sharedStrings`,"sharedStrings.xml"]),m&&(j.push([`${v}sheetMetadata`,"metadata.xml"]),i.push(["/xl/metadata.xml",A.metadata]));const G=rt(s),Y=s.sheets.map((p,w)=>o("sheet",{name:p.name,sheetId:w+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(w+1)}`}));z&&Y.push(o("sheet",{name:h.name,sheetId:b+1,state:"veryHidden","r:id":`rId${String(b+1)}`})),c.add("xl/workbook.xml",S+o("workbook",{xmlns:k.main,"xmlns:r":k.rel},o("workbookPr",{}),o("bookViews",{},o("workbookView",{activeTab:d===0?void 0:d})),o("sheets",{},Y.join("")),G.length>0?o("definedNames",{},G.join("")):"",o("calcPr",{calcId:je,fullCalcOnLoad:!0}))),c.add("xl/_rels/workbook.xml.rels",V(j)),c.add("xl/styles.xml",S+r.xml()),l.write(c.part("xl/sharedStrings.xml")),c.add("xl/theme/theme1.xml",S+Re),m&&c.add("xl/metadata.xml",S+Ne),c.add("docProps/core.xml",S+o("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},s.title===void 0?"":o("dc:title",{},x(s.title)))),c.add("docProps/app.xml",S+o("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},o("Application",{},"AllyHub"))),c.add("_rels/.rels",V([[`${v}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${v}extended-properties`,"docProps/app.xml"]])),i.push(["/xl/styles.xml",A.styles],["/xl/sharedStrings.xml",A.strings],["/xl/theme/theme1.xml",A.theme],["/docProps/core.xml",A.core],["/docProps/app.xml",A.app]);const fe=[...u].sort(([p],[w])=>p.localeCompare(w));for(const[p,w]of fe)c.add(`xl/media/${p}`,w);return c.add("[Content_Types].xml",S+o("Types",{xmlns:k.types},o("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),o("Default",{Extension:"xml",ContentType:"application/xml"}),y>0?o("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...u.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>o("Default",{Extension:p,ContentType:`image/${p==="jpg"?"jpeg":p}`})).join(""),i.map(([p,w])=>o("Override",{PartName:p,ContentType:w})).join(""))),{bytes:c.finish(),left:e}}