@8sheets/data-grid 0.0.0-stage → 1.0.1

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 (292) hide show
  1. package/LICENSE.md +36 -0
  2. package/README.md +52 -2
  3. package/a11y/cell-alt-text.js +1 -0
  4. package/api/overlay.js +1 -0
  5. package/api/serialize.js +1 -0
  6. package/api/skins.js +1 -0
  7. package/api/style-refs.js +1 -0
  8. package/api/watermark-xml.js +2 -0
  9. package/calc/adjust.js +1 -0
  10. package/calc/cell-set.js +1 -0
  11. package/calc/compile.js +1 -0
  12. package/calc/engine.js +1 -0
  13. package/calc/fill-shape.js +2 -0
  14. package/calc/functions/array.js +1 -0
  15. package/calc/functions/database.js +1 -0
  16. package/calc/functions/date.js +1 -0
  17. package/calc/functions/engineering.js +1 -0
  18. package/calc/functions/financial.js +1 -0
  19. package/calc/functions/helpers.js +1 -0
  20. package/calc/functions/index.js +1 -0
  21. package/calc/functions/info.js +1 -0
  22. package/calc/functions/logical.js +1 -0
  23. package/calc/functions/lookup.js +1 -0
  24. package/calc/functions/math.js +1 -0
  25. package/calc/functions/registry.js +1 -0
  26. package/calc/functions/stat.js +1 -0
  27. package/calc/functions/text.js +1 -0
  28. package/calc/parser.js +3 -0
  29. package/calc/values.js +1 -0
  30. package/calcx/ai/client.js +1 -0
  31. package/calcx/ai/functions.js +15 -0
  32. package/calcx/ai/settings.js +1 -0
  33. package/calcx/async.js +1 -0
  34. package/calcx/culture/format-locale.js +1 -0
  35. package/calcx/culture/lcid.js +1 -0
  36. package/calcx/external-read.js +1 -0
  37. package/calcx/external-write.js +3 -0
  38. package/calcx/external.js +1 -0
  39. package/calcx/functions/dynamic.js +1 -0
  40. package/calcx/functions/ets.js +1 -0
  41. package/calcx/functions/index.js +1 -0
  42. package/calcx/functions/misc.js +1 -0
  43. package/calcx/functions/text.js +1 -0
  44. package/calcx/functions/xml.js +1 -0
  45. package/calcx/refresh.js +1 -0
  46. package/cells/auto-merge.js +1 -0
  47. package/cells/axis-limits.js +1 -0
  48. package/cells/axis-ops.js +1 -0
  49. package/cells/background-xml.js +1 -0
  50. package/cells/background.js +1 -0
  51. package/cells/book-css.js +206 -0
  52. package/cells/book-read.js +1 -0
  53. package/cells/book-view.js +1 -0
  54. package/cells/cell-defaults.js +1 -0
  55. package/cells/cell-extras.js +1 -0
  56. package/cells/cell-options-ui.js +1 -0
  57. package/cells/cell-styles-xml.js +1 -0
  58. package/cells/cf-engine.js +1 -0
  59. package/cells/cf-file.js +1 -0
  60. package/cells/cf-paint.js +1 -0
  61. package/cells/consolidate-links.js +1 -0
  62. package/cells/docprops-xml.js +2 -0
  63. package/cells/filter-file.js +1 -0
  64. package/cells/find-engine.js +2 -0
  65. package/cells/find.js +1 -0
  66. package/cells/format-code.js +1 -0
  67. package/cells/format-panes.js +3 -0
  68. package/cells/format-tabs.js +102 -0
  69. package/cells/goto.js +1 -0
  70. package/cells/header-colors.js +1 -0
  71. package/cells/mask.js +1 -0
  72. package/cells/menu-extras.js +1 -0
  73. package/cells/name-box.js +1 -0
  74. package/cells/note-xml.js +1 -0
  75. package/cells/options.js +1 -0
  76. package/cells/outline-column.js +1 -0
  77. package/cells/paint.js +1 -0
  78. package/cells/panes.js +1 -0
  79. package/cells/rich-data-xml.js +2 -0
  80. package/cells/rich-data.js +1 -0
  81. package/cells/rich-runs.js +2 -0
  82. package/cells/rich-values.js +1 -0
  83. package/cells/rich-xml.js +1 -0
  84. package/cells/rounded.js +1 -0
  85. package/cells/sections.js +2 -0
  86. package/cells/selection-modes.js +1 -0
  87. package/cells/style-xml.js +1 -0
  88. package/cells/text-layout.js +8 -0
  89. package/cells/undo-group.js +1 -0
  90. package/cells/validation-alert.js +2 -0
  91. package/cells/view-options.js +1 -0
  92. package/cells/view-xml.js +1 -0
  93. package/celltypes/barcode-tables.js +31 -0
  94. package/celltypes/barcode.js +2 -0
  95. package/celltypes/base.js +1 -0
  96. package/celltypes/cell-buttons.js +1 -0
  97. package/celltypes/cell-types.js +2 -0
  98. package/celltypes/data-object.js +1 -0
  99. package/celltypes/diagonal.js +1 -0
  100. package/celltypes/dropdowns-more.js +13 -0
  101. package/celltypes/dropdowns.js +42 -0
  102. package/celltypes/file-cell.js +2 -0
  103. package/celltypes/glyphs.js +1 -0
  104. package/celltypes/persist.js +2 -0
  105. package/celltypes/range-template.js +2 -0
  106. package/charts/chartex.js +3 -0
  107. package/charts/geo/geo-xml.js +1 -0
  108. package/charts/geo/map-state.js +1 -0
  109. package/charts/patterns.js +1 -0
  110. package/core/address.js +1 -0
  111. package/core/axis.js +1 -0
  112. package/core/base64.js +1 -0
  113. package/core/changes.js +1 -0
  114. package/core/color.js +1 -0
  115. package/core/cond-format.js +1 -0
  116. package/core/custom-views.js +1 -0
  117. package/core/default-names.js +1 -0
  118. package/core/formula-refs.js +1 -0
  119. package/core/formula-store.js +1 -0
  120. package/core/input.js +1 -0
  121. package/core/math.js +1 -0
  122. package/core/numfmt.js +1 -0
  123. package/core/online.js +1 -0
  124. package/core/protection.js +1 -0
  125. package/core/regexp.js +1 -0
  126. package/core/sheet-group.js +1 -0
  127. package/core/sheet.js +1 -0
  128. package/core/sparklines.js +1 -0
  129. package/core/sparse.js +1 -0
  130. package/core/strings.js +1 -0
  131. package/core/styles.js +1 -0
  132. package/core/table-presets.js +7 -0
  133. package/core/tables.js +2 -0
  134. package/core/tsv.js +4 -0
  135. package/core/whatif.js +1 -0
  136. package/core/workbook.js +1 -0
  137. package/datasheets/bind.js +1 -0
  138. package/datasheets/calendar.js +1 -0
  139. package/datasheets/cross.js +1 -0
  140. package/datasheets/data-core.js +1 -0
  141. package/datasheets/data.js +1 -0
  142. package/datasheets/formula.js +1 -0
  143. package/datasheets/gantt-paint.js +1 -0
  144. package/datasheets/gantt-resources.js +1 -0
  145. package/datasheets/gantt-shapes.js +1 -0
  146. package/datasheets/gantt.js +1 -0
  147. package/datasheets/manager.js +1 -0
  148. package/datasheets/path-binding.js +2 -0
  149. package/datasheets/persist-writer.js +2 -0
  150. package/datasheets/persist.js +1 -0
  151. package/datasheets/query-function.js +1 -0
  152. package/datasheets/remote.js +3 -0
  153. package/datasheets/report-entry.js +1 -0
  154. package/datasheets/report.js +1 -0
  155. package/datasheets/rules.js +1 -0
  156. package/datasheets/sort.js +1 -0
  157. package/datasheets/table-sheet.js +1 -0
  158. package/datasheets/view.js +3 -0
  159. package/datasheets/virtual-sheet.js +1 -0
  160. package/datasheets/window.js +1 -0
  161. package/extras/getdata/persist.js +2 -0
  162. package/extras/getdata/rows.js +1 -0
  163. package/extras/getdata/steps.js +1 -0
  164. package/i18n/dom.js +1 -0
  165. package/i18n/en/a11y.js +1 -0
  166. package/i18n/en/cells.js +1 -0
  167. package/i18n/en/charts.js +1 -0
  168. package/i18n/en/common.js +1 -0
  169. package/i18n/en/datasheets.js +1 -0
  170. package/i18n/en/format.js +1 -0
  171. package/i18n/en/misc.js +1 -0
  172. package/i18n/en/pivot.js +1 -0
  173. package/i18n/en/proofing.js +1 -0
  174. package/i18n/en/ribbon.js +1 -0
  175. package/i18n/en/shapes.js +1 -0
  176. package/i18n/en/shell.js +1 -0
  177. package/i18n/en/touch.js +1 -0
  178. package/i18n/en.js +1 -0
  179. package/i18n/index.js +1 -0
  180. package/i18n/key-text.js +1 -0
  181. package/i18n/languages.js +1 -0
  182. package/i18n/pl/a11y.js +1 -0
  183. package/i18n/pl/cells.js +1 -0
  184. package/i18n/pl/charts.js +1 -0
  185. package/i18n/pl/common.js +1 -0
  186. package/i18n/pl/datasheets.js +1 -0
  187. package/i18n/pl/format.js +1 -0
  188. package/i18n/pl/misc.js +1 -0
  189. package/i18n/pl/pivot.js +1 -0
  190. package/i18n/pl/proofing.js +1 -0
  191. package/i18n/pl/ribbon.js +1 -0
  192. package/i18n/pl/shapes.js +1 -0
  193. package/i18n/pl/shell.js +1 -0
  194. package/i18n/pl/touch.js +1 -0
  195. package/i18n/pl.js +1 -0
  196. package/io/client.js +1 -0
  197. package/io/crc32.js +1 -0
  198. package/io/crypto/aes.js +1 -0
  199. package/io/crypto/agile.js +2 -0
  200. package/io/crypto/cfb-read.js +1 -0
  201. package/io/crypto/cfb-write.js +1 -0
  202. package/io/crypto/dataspaces.js +1 -0
  203. package/io/crypto/errors.js +1 -0
  204. package/io/crypto/hash.js +1 -0
  205. package/io/crypto/index.js +1 -0
  206. package/io/crypto/package-read.js +1 -0
  207. package/io/crypto/package-write.js +1 -0
  208. package/io/crypto/spool.js +1 -0
  209. package/io/crypto/standard.js +1 -0
  210. package/io/csv.js +8 -0
  211. package/io/export-blocks.js +1 -0
  212. package/io/foreign-parts.js +1 -0
  213. package/io/foreign-sheets.js +2 -0
  214. package/io/io.worker.js +1 -0
  215. package/io/package-paths.js +1 -0
  216. package/io/plan.js +1 -0
  217. package/io/text-split.js +3 -0
  218. package/io/xlsx-read.js +1 -0
  219. package/io/xlsx-styles.js +2 -0
  220. package/io/xlsx-tail.js +1 -0
  221. package/io/xlsx-write.js +2 -0
  222. package/io/xml-escape.js +1 -0
  223. package/io/xml-scan.js +1 -0
  224. package/io/zip-reader.js +1 -0
  225. package/io/zip-writer.js +1 -0
  226. package/objects/chart-model.js +1 -0
  227. package/objects/dml.js +5 -0
  228. package/objects/drawing-xml.js +1 -0
  229. package/objects/picture-url.js +1 -0
  230. package/package.json +57 -4
  231. package/pivot/engine.js +1 -0
  232. package/pivot/xml.js +2 -0
  233. package/print/page-setup.js +1 -0
  234. package/print/paginate.js +1 -0
  235. package/print/pdf.js +35 -0
  236. package/print/render-page.js +3 -0
  237. package/render/patterns.js +1 -0
  238. package/shapes/form-xml.js +1 -0
  239. package/shapes/watermark.js +1 -0
  240. package/slicers/custom-styles.js +1 -0
  241. package/slicers/date-filters.js +1 -0
  242. package/slicers/format.js +2 -0
  243. package/slicers/pivot-file.js +1 -0
  244. package/slicers/structured.js +1 -0
  245. package/slicers/table-file.js +1 -0
  246. package/slicers/write.js +1 -0
  247. package/sparklines/colors.js +1 -0
  248. package/sparklines/data.js +1 -0
  249. package/sparklines/descriptor.js +1 -0
  250. package/sparklines/excel-paint.js +1 -0
  251. package/sparklines/functions.js +1 -0
  252. package/sparklines/paint-core.js +1 -0
  253. package/sparklines/paint-measure.js +1 -0
  254. package/sparklines/paint-other.js +2 -0
  255. package/sparklines/paint-series.js +1 -0
  256. package/sparklines/paint.js +1 -0
  257. package/sparklines/print.js +1 -0
  258. package/sparklines/rule.js +1 -0
  259. package/table-view/api.js +1 -0
  260. package/table-view/cell-editor.js +1 -0
  261. package/table-view/cell-format.js +1 -0
  262. package/table-view/chrome.js +1 -0
  263. package/table-view/client.js +1 -0
  264. package/table-view/column-drag.js +1 -0
  265. package/table-view/column-input.js +1 -0
  266. package/table-view/column-window.js +1 -0
  267. package/table-view/events.js +1 -0
  268. package/table-view/files.js +1 -0
  269. package/table-view/grid-keys.js +2 -0
  270. package/table-view/index.d.ts +4 -0
  271. package/table-view/index.js +1 -0
  272. package/table-view/labels.js +1 -0
  273. package/table-view/model.js +1 -0
  274. package/table-view/mount.js +1 -0
  275. package/table-view/panel.js +1 -0
  276. package/table-view/pivot.js +1 -0
  277. package/table-view/public.d.ts +841 -0
  278. package/table-view/quick-filter.js +1 -0
  279. package/table-view/reader.worker.js +1 -0
  280. package/table-view/remote.js +1 -0
  281. package/table-view/row-cache.js +1 -0
  282. package/table-view/row-selection.js +1 -0
  283. package/table-view/table-css.js +1207 -0
  284. package/table-view/totals.js +1 -0
  285. package/table-view/version.js +1 -0
  286. package/table-view/worksheet-table.js +1 -0
  287. package/ui/dialogs.js +3 -0
  288. package/ui/dom.js +1 -0
  289. package/ui/icons.js +1 -0
  290. package/ui/menu-base.js +1 -0
  291. package/ui/protection-ui.js +1 -0
  292. package/ui/ui-scale.js +1 -0
package/LICENSE.md ADDED
@@ -0,0 +1,36 @@
1
+ # 8sheets npm Package Licence
2
+
3
+ > Version 1.0, 17 November 2026. It covers the packages published on npm: 8sheets Spreadsheet (`8sheets`, `@8sheets/core`, `@8sheets/react`, `@8sheets/vue`, `@8sheets/angular`) and 8sheets Data Grid (`@8sheets/data-grid`, `@8sheets/data-grid-react`, `@8sheets/data-grid-vue`, `@8sheets/data-grid-angular`). One paid licence covers both products. The full terms of the paid licence, the 8sheets Source Licence, are at https://8sheets.com/licence/; prices are at https://8sheets.com/pricing/.
4
+
5
+ Copyright (c) 2026 8cells Jarosław Kaczmarski. All rights reserved. This is commercial software. It is not open source.
6
+
7
+ ## 1. Evaluation
8
+
9
+ You may install this package and use it free of charge to evaluate 8sheets: in development, in tests, in prototypes and in demos that you do not offer to anyone as a product or service.
10
+
11
+ ## 2. Use in a product
12
+
13
+ Any other use needs a paid licence, bought at https://8sheets.com/pricing/. This includes using the package in an application, website, service or system that you deploy or make available to its users, including your own employees. The licence you buy decides who may use your product:
14
+
15
+ - **Internal** (999 USD, once per company): your product is used only inside your company.
16
+ - **SaaS / OEM** (2,999 USD, once per company): your product is offered to people outside your company.
17
+ - **Enterprise** (priced in a separate agreement): any use, under that agreement.
18
+
19
+ Each licence covers every developer and every deployment of the company that holds it. There is no licence key. Once you hold a licence, the 8sheets Source Licence (https://8sheets.com/licence/) governs your use of this package and replaces sections 1 and 3 of this file.
20
+
21
+ ## 3. Restrictions
22
+
23
+ Without a licence that allows it, you may not:
24
+
25
+ 1. use the package in production, in a product or for a customer;
26
+ 2. publish, sell, sublicense or redistribute the package or any part of it on its own, or as a component, SDK or library for other developers;
27
+ 3. reverse engineer, decompile or de-minify the package, except as far as the law allows despite this restriction;
28
+ 4. remove or change copyright and licence notices.
29
+
30
+ ## 4. Third-party components
31
+
32
+ The package includes data and artwork under their own licences (icons, map data, dictionaries and thesauri). Their notices are in the files next to that data (`*.NOTICE.txt`, `*.LICENSE.txt`, `charts/geo/NOTICE`) and listed at https://8sheets.com/notices/. Those terms apply to those parts.
33
+
34
+ ## 5. No warranty
35
+
36
+ The package is provided "as is", without warranty of any kind. To the extent the law allows, 8cells Jarosław Kaczmarski is not liable for any damages arising from its use.
package/README.md CHANGED
@@ -1,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # 8sheets Data Grid
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A data grid for the web in plain JavaScript modules with no runtime dependencies. Open a CSV or Excel file, or pass your records, and search, filter, sort, group, total, pivot and export them as CSV, Excel or PDF. Files are read in a Worker as a stream, the page keeps a bounded DOM, and a million records stay responsive. Server data plugs in through a query contract, so search, filters and totals cover the whole result.
4
+
5
+ This is version 1.0.1. Components for [React](https://www.npmjs.com/package/@8sheets/data-grid-react), [Vue](https://www.npmjs.com/package/@8sheets/data-grid-vue) and [Angular](https://www.npmjs.com/package/@8sheets/data-grid-angular) build on it. For a full Excel-compatible workbook, see the Spreadsheet, [`@8sheets/core`](https://www.npmjs.com/package/@8sheets/core).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @8sheets/data-grid
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```js
16
+ import { mountTable } from '@8sheets/data-grid';
17
+
18
+ const grid = await mountTable(document.querySelector('#orders'), {
19
+ title: 'Orders',
20
+ fields: [
21
+ { name: 'Region', type: 'string' },
22
+ { name: 'Units', type: 'number' },
23
+ { name: 'Price', type: 'number', format: '#,##0.00' },
24
+ { name: 'Revenue', type: 'number', formula: '[@Units]*[@Price]', format: '#,##0.00' },
25
+ ],
26
+ data: [{ Region: 'East', Units: 2, Price: 24 }],
27
+ onChange: (change) => console.log(change.action),
28
+ });
29
+ await grid.setState({ ...grid.getState(), groups: [{ field: 'Region' }], total: { field: 'Revenue', agg: 'sum' } });
30
+ const xlsx = await grid.exportResults('xlsx');
31
+ grid.destroy();
32
+ ```
33
+
34
+ The element needs a height. The grid brings its own stylesheet, scoped to the element. Pass `file` to open a local file, or `dataSource: remoteTableSource({ queryUrl, exportUrl, detailUrl, updateUrl })` for server data. `VERSION` is the release.
35
+
36
+ ## Bundlers
37
+
38
+ The grid finds its Worker and stylesheet next to its own modules, with `new URL('./…', import.meta.url)`, so Vite, webpack and Next.js copy them into your build. The Worker is an ES module.
39
+
40
+ - **Vite:** set `worker: { format: 'es' }`. Before Vite 8, also add `optimizeDeps: { exclude: ['@8sheets/data-grid'] }`: the older pre-bundling moves the modules away from their Worker.
41
+ - **Angular CLI:** see [@8sheets/data-grid-angular](https://www.npmjs.com/package/@8sheets/data-grid-angular), which serves this package as static files.
42
+ - **No bundler:** serve the package folder and import `table-view/index.js` from it.
43
+
44
+ The package holds the files the grid can load, engine code included (file reading and writing, number formats, PDF). Parts load on demand: a page that never opens an Excel file or exports a PDF never downloads that code.
45
+
46
+ ## Documentation
47
+
48
+ - [Data Grid docs](https://8sheets.com/docs/data-grid/): [getting started](https://8sheets.com/docs/data-grid/developers/), [recipes](https://8sheets.com/docs/data-grid/recipes/) and the [API reference](https://8sheets.com/docs/data-grid/api/).
49
+ - [Changelog](https://8sheets.com/docs/data-grid/changelog/). TypeScript declarations ship with the package.
50
+
51
+ ## Licence
52
+
53
+ 8sheets is commercial software, not open source. You may install it and try it for free, to evaluate it. Using it in a product, or deploying it for your users or your own staff, needs a licence from [8sheets.com/pricing](https://8sheets.com/pricing/): **Internal** 999 USD or **SaaS / OEM** 2,999 USD, each paid once per company and covering every developer and every deployment, or **Enterprise**, quoted. One licence covers both 8sheets products, Spreadsheet and Data Grid. There is no licence key and nothing in the package checks for one. The terms are in `LICENSE.md` and, once you hold a licence, the [8sheets Source Licence](https://8sheets.com/licence/).
@@ -0,0 +1 @@
1
+ import{registerSparseMap as u,setSparse as f}from"../core/sparse.js";import{registerSection as p}from"../cells/sections.js";const i="cellAltText",s=16384,a=2e3;u(i),p(i,{sheet:{save(r){const e=r[i];if(!(!e||e.size===0))return[...e].map(([t,n])=>[Math.floor(t/s),t%s,n])},load(r,e){if(!Array.isArray(e))return;const t=new Map;for(const n of e){if(!Array.isArray(n)||n.length!==3)continue;const[o,l,c]=n;!Number.isInteger(o)||!Number.isInteger(l)||o<0||l<0||l>=s||o>=1048576||typeof c!="string"||c===""||t.set(o*s+l,c.slice(0,a))}r[i]=t.size>0?t:null}}});function g(r,e,t){return r[i]?.get(e*s+t)??null}function x(r,e){return r.replace(/\{value\}/g,e)}function y(r,e,t){const n=typeof t=="string"&&t.trim()!==""?t.slice(0,a):void 0;r.transact("alt-text",o=>f(o.sheet,i,e,n))}export{g as cellAltText,y as setCellAltText,x as spokenAltText};
package/api/overlay.js ADDED
@@ -0,0 +1 @@
1
+ let t=null;function r(){return t??document.body}function l(e){t=e}const o=new Set;function a(e){o.add(e)}function c(){const e=[...o];o.clear();for(const n of e)n()}export{a as onPageRelease,r as overlayRoot,c as releasePage,l as setOverlayRoot};
@@ -0,0 +1 @@
1
+ import{BOOL as E,CHUNK_BITS as X,CHUNK_MASK as Y,CHUNK_SIZE as J,ERR as M,ERRORS as j,FORMULA as G,KIND_MASK as L,NUM as I,SPILL as Z,STR as N,Sheet as U}from"../core/sheet.js";import{MAX_COLS as v}from"../core/address.js";import{defaultStyle as b}from"../core/styles.js";import{Workbook as k}from"../core/workbook.js";import{Engine as ee}from"../calc/engine.js";const T="8sheets",_=1,ne=new Set(["uid","name","columns","maxRow","maxCol","rows","cols","formulas","spills","rowStyles","colStyles","merges","mergeIndex","frozenRows","frozenCols","showGridlines","zoom","sourceId","sourceIndex","revision","hidden","tabColor","rtl"]),te=new Set(["apiObjects","cfEval","structureOps","dataBindings","report","isVirtual","split","onRefresh","onRejected","recorder"]),B={cf:"cfChanged",comments:"commentsChanged",hyperlinks:"hyperlinksChanged",validations:"validationsChanged",pageSetup:"pageSetupChanged",protection:"protectionChanged",scenarios:"scenariosChanged",sparklines:"sparklinesChanged",threads:"threadsChanged",autoFilter:"filterChanged",cellTypes:"cellTypesChanged"},D=new Map;function ze(e,n){D.set(e,n)}const se=new U(""),re=e=>{if(e===null||typeof e!="object")return!0;const n=Object.getPrototypeOf(e);return n===Object.prototype||n===null};function m(e,n,t){if(e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean")return e;if(e===void 0)return;if(typeof e=="function"){n?.push(`${t}: a function was left out`);return}if(Array.isArray(e))return e.map((i,s)=>m(i,n,`${t}[${s}]`)??null);if(e instanceof Map)return{$map:[...e].map(([i,s],o)=>[m(i,n,t),m(s,n,`${t}.${o}`)??null])};if(e instanceof Set)return{$set:[...e].map(i=>m(i,n,t))};if(ArrayBuffer.isView(e))return{$typed:e.constructor.name,v:[...e]};if(e instanceof Date)return{$date:e.toISOString()};if(!re(e)){if(typeof e.toJSON=="function")return m(e.toJSON(),n,t);n?.push(`${t}: a ${e.constructor?.name??"class"} instance was left out`);return}if("$map"in e||"$set"in e)throw new Error(`${t}: a key starting with $ can't be stored`);const r={};for(const i of Object.keys(e)){if(i[0]==="_")continue;const s=m(e[i],n,`${t}.${i}`);s!==void 0&&(r[i]=s)}return r}const ie={Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function h(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(h);if(e.$map)return new Map(e.$map.map(([t,r])=>[h(t),h(r)]));if(e.$set)return new Set(e.$set.map(h));if(e.$typed)return ie[e.$typed].from(e.v);if(e.$date)return new Date(e.$date);const n={};for(const t of Object.keys(e))n[t]=h(e[t]);return n}function K(e){const n={size:e.defaultSize};if(e.sizes!==null){const t=[],{sizes:r}=e;for(let i=0;i<r.length;i++){if(!e.isCustom(i)||e.isHidden(i))continue;const s=r[i],o=e.isAuto(i);let f=i;for(;f+1<r.length&&r[f+1]===s&&e.isCustom(f+1)&&!e.isHidden(f+1)&&e.isAuto(f+1)===o;)f++;t.push(o?[i,f-i+1,s,1]:[i,f-i+1,s]),i=f}t.length&&(n.runs=t)}return e.hiddenSizes!==null&&e.hiddenSizes.size>0&&(n.hidden=[...e.hiddenSizes]),n}function V(e,n){if(n){n.size!==void 0&&n.size!==e.defaultSize&&e.setDefaultSize(n.size);for(const[t,r,i,s]of n.runs??[])for(let o=t;o<t+r;o++)e.setSize(o,i,s===1);for(const[t,r]of n.hidden??[])r>=0&&e.setSize(t,r),e.setHidden(t,!0)}}const oe=16;function le(e){const n={};for(const t of Object.keys(e))t!=="tpl"&&t[0]!=="_"&&(n[t]=e[t]);return n}function P(e,n,t){switch(n&L){case I:return t;case N:return e.strings.get(t);case E:return t!==0;case M:return{e:j[t]??"#N/A"};default:return null}}function fe(e,n,t,r,i){const s=[],o=[];let f=null,c=-2,d=-1,l=0,u=-1;const{formulas:y}=n,{rich:a}=e.strings,S=i.styles===!1,C=i.formulas===!1;for(let p=0;p<r.length;p++){const H=r[p];if(H===void 0)continue;const Q=p*J,{kinds:W,values:$,styles:A}=H;for(let g=0;g<J;g++){const O=W[g],w=Q+g;if(A!==null&&!S&&A[g]!==0&&(A[g]===l&&w===u+1?u=w:(l!==0&&o.push([d,u-d+1,l]),d=w,u=w,l=A[g])),O===0||O&Z)continue;let z;if(O&G){const x=y.get(w*v+t),R=P(e,O,$[g]);x&&!C?(z={f:le(x)},R!==null&&(z.v=R)):z=R}else(O&L)===N?(z=e.strings.get($[g]),a!==null&&a.has($[g])&&(z={s:z,rich:a.get($[g])})):z=P(e,O,$[g]);const F=w-c-1;if(f===null||F>oe)f={r:w,v:[]},s.push(f);else for(let x=0;x<F;x++)f.v.push(null);f.v.push(z),c=w}}return l!==0&&o.push([d,u-d+1,l]),{blocks:s,styles:o}}function ce(e,n,t,r){for(const{r:i,v:s}of r){let o=null,f=-1;for(let d=0;d<s.length;d++){const l=s[d];if(l===null)continue;const u=i+d,y=u>>>X;y!==f&&(o=n._ensure(u,t),f=y);const a=u&Y;if(typeof l=="number")o.kinds[a]=I,o.values[a]=l;else if(typeof l=="string")o.kinds[a]=N,o.values[a]=e.strings.add(l);else if(typeof l=="boolean")o.kinds[a]=E,o.values[a]=l?1:0;else if(l.e!==void 0)o.kinds[a]=M,o.values[a]=Math.max(0,j.indexOf(l.e));else if(l.s!==void 0){const S=e.strings.add(l.s);o.kinds[a]=N,o.values[a]=S,e.strings.rich??=new Map,e.strings.rich.set(S,l.rich)}else if(l.f!==void 0){let S=G,C=0;const p=l.v;typeof p=="number"?(S|=I,C=p):typeof p=="string"?(S|=N,C=e.strings.add(p)):typeof p=="boolean"?(S|=E,C=p?1:0):p&&p.e!==void 0&&(S|=M,C=Math.max(0,j.indexOf(p.e))),o.kinds[a]=S,o.values[a]=C,n.setFormula(u,t,typeof l.f=="string"?{f:l.f,typed:!0}:l.f)}}const c=i+s.length-1;c>n.maxRow&&(n.maxRow=c)}t>n.maxCol&&(n.maxCol=t)}function ue(e,n,t){for(const[r,i,s]of t)for(let o=r;o<r+i;o++)e.setStyle(o,n,s)}function q(e,n){const t={};for(const r of Object.keys(e)){if(r[0]==="_")continue;const i=e[r];i!==n[r]&&!(typeof i=="object"&&i!==null&&JSON.stringify(i)===JSON.stringify(n[r]))&&(t[r]=i)}return t}function ae(e,n,t,r,i){const s={name:n.name};n.hidden&&(s.hidden=!0),n.hidden&&n.veryHidden&&(s.veryHidden=!0),n.tabColor&&(s.tabColor=n.tabColor),n.rtl&&(s.rtl=!0),n.zoom!==1&&(s.zoom=n.zoom),n.frozenRows&&(s.frozenRows=n.frozenRows),n.frozenCols&&(s.frozenCols=n.frozenCols),n.showGridlines===!1&&(s.showGridlines=!1),s.rows=K(n.rows),s.cols=K(n.cols),n.rowStyles?.size&&(s.rowStyles=[...n.rowStyles]),n.colStyles?.size&&(s.colStyles=[...n.colStyles]),n.merges.length&&(s.merges=n.merges.map(({r0:l,c0:u,r1:y,c1:a})=>[l,u,y,a]));const o=[],f=[];n.columns.forEach((l,u)=>{if(r.cells===!1)return;const{blocks:y,styles:a}=fe(e,n,u,l,r);y.length&&o.push({c:u,blocks:y}),a.length&&f.push({c:u,runs:a})}),o.length&&(s.cells=o),f.length&&(s.styles=f);const c={};for(const l of Object.keys(n)){if(ne.has(l)||te.has(l)||l[0]==="_"||l.endsWith("Changed"))continue;const u=n[l];if(u==null||u===se[l])continue;const y=m(u,i,`${n.name}.${l}`);y!==void 0&&(c[l]=y)}Object.keys(c).length&&(s.features=c);const d=t?.objectsOf?.(n);if(d?.length){const l=m(d.map(de),i,`${n.name}.objects`);l.length&&(s.objects=l)}return s}function de(e){const{bitmap:n,blob:t,canvas:r,modelEpoch:i,...s}=e;return t&&(s.imageType=t.type),s}function Oe(e,n=null,t={}){const r=t.warnings??[],i=b(),s={format:T,version:_};s.activeSheet=e.activeSheet,e.fileName&&(s.fileName=e.fileName),e.themeInfo?s.theme=m(e.themeInfo,r,"theme"):e.theme&&(s.themeColors=e.theme);const o=e.styles.list;s.styles=o.length===1&&Object.keys(q(o[0],i)).length===0?[]:o.map(c=>q(c,i)),e.dxfs?.length&&(s.dxfs=m(e.dxfs,r,"dxfs")),e.persons?.length&&(s.persons=m(e.persons,r,"persons")),e.protection&&(s.protection=m(e.protection,r,"protection")),e.calcMode&&(s.calcMode=e.calcMode),e.getDataQueries&&(s.queries=m(e.getDataQueries,r,"queries")),e.customData&&(s.custom=m(e.customData,r,"custom"));const f=e.engine;if(f&&(f.manual&&(s.manualCalc=!0),f.names.size&&(s.names=[...f.names].map(([c,d])=>{const l=c.indexOf("!");return{name:d.name??(l>=0?c.slice(l+1):c),text:d.text,...l>=0?{sheet:Number(c.slice(0,l))}:{}}})),f.tables.size&&(s.tables=[...f.tables.values()].map(c=>{const{sheet:d,source:l,part:u,id:y,isNew:a,dirty:S,...C}=c;return{...m(C,r,`table ${c.name}`),sheet:e.sheets.indexOf(d)}}))),s.sheets=e.sheets.map(c=>ae(e,c,n,t,r)),n?.extrasToJSON){const c=n.extrasToJSON(r);c&&(s.extras=c)}return r.length&&(s.warnings=r),s}function me(e,n){n.hidden&&(e.hidden=!0),n.hidden&&n.veryHidden&&(e.veryHidden=!0),n.tabColor&&(e.tabColor=n.tabColor,e.tabColorChanged=!0),n.rtl&&(e.rtl=!0),n.zoom&&(e.zoom=n.zoom),e.frozenRows=n.frozenRows??0,e.frozenCols=n.frozenCols??0,n.showGridlines===!1&&(e.showGridlines=!1),V(e.rows,n.rows),V(e.cols,n.cols),(n.cols?.runs||n.cols?.hidden)&&(e.colsChanged=!0),n.rowStyles&&(e.rowStyles=new Map(n.rowStyles)),n.colStyles&&(e.colStyles=new Map(n.colStyles)),n.merges&&(e.merges=n.merges.map(([t,r,i,s])=>({r0:t,c0:r,r1:i,c1:s}))),e.viewChanged=!0;for(const[t,r]of Object.entries(n.features??{})){const i=h(r);e[t]=D.has(t)?D.get(t)(i):i,B[t]&&(e[B[t]]=!0)}}function pe(e,n){const t=b();n.styles?.length&&e.styles.load(n.styles.map(r=>({...t,...r}))),n.dxfs&&(e.dxfs=h(n.dxfs),e.sourceDxfs=0),n.persons&&(e.persons=h(n.persons),e.personsChanged=!0),n.protection&&(e.protection=h(n.protection),e.protectionChanged=!0),n.calcMode&&(e.calcMode=n.calcMode,e.calcModeChanged=!0),n.queries&&(e.getDataQueries=h(n.queries)),n.custom&&(e.customData=h(n.custom)),n.fileName&&(e.fileName=n.fileName),n.themeColors&&(e.theme=n.themeColors)}function ye(e,n,t={}){const{engine:r}=e;e.formulasEdited=!0,e.activeSheet=Math.min(n.activeSheet??0,e.sheets.length-1),r.sheetsChanged(),n.manualCalc&&(r.manual=!0),r.setNames((n.names??[]).map(i=>({name:i.name,text:i.text,localSheetId:i.sheet}))),n.names?.length&&(e.namesChanged=!0),r.setTables((n.tables??[]).map(i=>{const{sheet:s,...o}=i;return{...h(o),sheet:e.sheets[s],isNew:!0,dirty:!0}})),r.buildGraph({fullCalc:t.recalculate===!0}),e.dirty=!1}function $e(e,n={}){if(e?.format!==T)throw new Error(`This isn't ${T} JSON`);if(e.version>_)throw new Error(`This JSON has version ${e.version}; this code reads up to ${_}`);const t=new k;return t.engine=new ee(t),pe(t,n.styles===!1?{...e,styles:[]}:e),t.sheets=e.sheets.map(r=>new U(r.name)),e.sheets.forEach((r,i)=>{const s=t.sheets[i];me(s,r);for(const o of r.cells??[])ce(t,s,o.c,o.blocks);if(n.styles!==!1)for(const o of r.styles??[])ue(s,o.c,o.runs);if(r.styles?.length)for(const o of r.styles)o.c>s.maxCol&&(s.maxCol=o.c)}),ye(t,e,n),t}export{T as FORMAT_NAME,_ as FORMAT_VERSION,pe as applyBookMeta,me as applySheetMeta,$e as bookFromJSON,Oe as bookToJSON,h as decodeData,m as encodeData,ye as finishLoad,ze as registerFeatureReviver};
package/api/skins.js ADDED
@@ -0,0 +1 @@
1
+ const i=(e,f,n,a,r)=>({headerBg:e,headerInk:f,headerLine:n,headerActiveBg:a,headerActiveInk:r}),t={white:{base:"light",tokens:{chrome:"#ffffff",panel:"#ffffff","panel-line":"#d4d4d4",bar:"#ffffff","bar-line":"#d4d4d4",menu:"#ffffff",field:"#ffffff","sheet-active-bg":"#ffffff"},grid:i("#ffffff","#444444","#d4d4d4","#e1e1e1","#217346")},"light-gray":{base:"light",tokens:{chrome:"#f1f1f1",panel:"#f8f8f8","panel-line":"#c6c6c6",bar:"#f1f1f1","bar-line":"#c6c6c6",menu:"#ffffff",field:"#ffffff","sheet-active-bg":"#ffffff"},grid:i("#f1f1f1","#444444","#c6c6c6","#d4d4d4","#217346")},"dark-gray":{base:"light",tokens:{chrome:"#b9b9b9",panel:"#d6d6d6","panel-line":"#9a9a9a",bar:"#b9b9b9","bar-line":"#9a9a9a",menu:"#f0f0f0",field:"#f4f4f4","field-line":"#9a9a9a","ink-soft":"#3f3f3f",hover:"rgba(0, 0, 0, 0.1)","sheet-active-bg":"#f4f4f4"},grid:i("#b9b9b9","#262626","#9a9a9a","#8f8f8f","#ffffff")},colorful:{base:"light",tokens:{chrome:"#e6e6e6",panel:"#f5f5f5","panel-line":"#c6c6c6",bar:"#e6e6e6","bar-line":"#c6c6c6",menu:"#ffffff",field:"#ffffff",accent:"#217346","accent-ink":"#185c37","sheet-active-ink":"#185c37"},grid:{...i("#e6e6e6","#444444","#c6c6c6","#cfe3d6","#185c37"),accent:"#217346",headerFullBg:"#217346",selectionFill:"rgba(33, 115, 70, 0.12)"},titleBar:{background:"#217346",color:"#ffffff"}},black:{base:"dark",tokens:{chrome:"#000000",panel:"#1a1a1a","panel-line":"#333333",bar:"#0d0d0d","bar-line":"#333333",menu:"#1f1f1f",field:"#262626","field-line":"#3a3a3a",ink:"#f2f2f2","ink-soft":"#c8c8c8"},grid:{headerBg:"#000000",headerInk:"#f2f2f2",headerLine:"#333333",headerActiveBg:"#444444",headerActiveInk:"#ffffff"}},slate:{base:"dark",tokens:{chrome:"#26303a",panel:"#2f3b47","panel-line":"#45525f",bar:"#222b34","bar-line":"#45525f",menu:"#2f3b47",field:"#374553","field-line":"#4c5a68",ink:"#eef2f6","ink-soft":"#c0cbd6",accent:"#2f81c7","accent-ink":"#7fc1f5","sheet-active-ink":"#1f5f96"},grid:{headerBg:"#26303a",headerInk:"#dbe3ea",headerLine:"#45525f",headerActiveBg:"#3d5266",headerActiveInk:"#ffffff",accent:"#2f81c7",headerFullBg:"#2f81c7",selectionFill:"rgba(47, 129, 199, 0.14)"}}};function l(e,f,n){for(const a of e){for(const r of Object.keys(n?.tokens??{}))a.style.removeProperty(`--${r}`);for(const[r,o]of Object.entries(f?.tokens??{}))a.style.setProperty(`--${r}`,o)}}const c=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function d(e){if(typeof e=="string"){if(Object.hasOwn(t,e)||["dark","light","auto"].includes(e))return;throw new RangeError(`There is no chrome "${e}". Choose dark, light, auto, or one of: ${Object.keys(t).join(", ")}`)}if(!c(e))throw new RangeError("chrome must be dark, light, auto, a skin name or a skin object");if(e.base!==void 0&&e.base!=="light"&&e.base!=="dark")throw new RangeError(`A skin's base is light or dark, not "${e.base}"`);for(const f of["tokens","grid","titleBar"])if(e[f]!==void 0){if(!c(e[f]))throw new RangeError(`A skin's ${f} must be an object of colors`);for(const[n,a]of Object.entries(e[f]))if(a!==void 0&&typeof a!="string")throw new RangeError(`A skin's ${f}.${n} must be a color string`)}}export{t as SKINS,l as applySkinTokens,d as checkChrome};
@@ -0,0 +1 @@
1
+ const u=(t,e)=>t&&e&&t.hex?.toUpperCase()===String(e).toUpperCase();function c(t,e){return!t||t.a.theme===void 0||!e?null:{t:Number(t.a.theme),tint:t.a.tint?Number(t.a.tint):0,hex:e}}function h(t,e){return t&&u(t,e??"#000000")?`theme="${t.t}"${t.tint?` tint="${t.tint}"`:""}`:`rgb="FF${(e??"#000000").slice(1)}"`}function x(t,e){const s=t.fonts[Number(e.fontId??0)],r=t.fills[Number(e.fillId??0)],n=t.borders[Number(e.borderId??0)];return!s&&!r&&!n?null:{...s,...r,...n?{border:n}:{}}}function b(t,e,s){const r=e(t,"color"),n=c(r,s(r)),o=e(t,"scheme")?.a.val;return!n&&!o?null:{...n?{color:n}:{},...o==="major"||o==="minor"?{font:o}:{}}}function T(t,e,s){const r=e(t,"patternFill");if(!r)return null;const n=e(r,"fgColor"),o=e(r,"bgColor");if(r.a.patternType==="solid"){const a=n?.a.theme!==void 0?n:o,f=c(a,s(a));return f?{fill:f}:null}const l=c(o,s(o)),i=c(n,s(n));return l||i?{...l?{fill:l}:{},...i?{patternFg:i}:{}}:null}function g(t,e,s){const r={};let n=!1;for(const[o,l]of[["left","l"],["right","r"],["top","t"],["bottom","b"],["diagonal","d"]]){const i=e(e(t,o),"color"),a=c(i,s(i));a&&(r[l]=a,n=!0)}return n?r:null}const m="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",p="application/vnd.openxmlformats-officedocument.theme+xml",d="xl/theme/theme1.xml";async function y(t,e,s){let{types:r,rels:n}=e;const o=/<Relationship\b[^>]*\/theme"[^>]*\/>/.exec(n);let l=e.part??null;if(!o)n=n.replace("</Relationships>",`<Relationship Id="rIdTheme8c" Type="${m}" Target="theme/theme1.xml"/></Relationships>`),l=d;else if(l===null){const i=/Target="([^"]+)"/.exec(o[0])[1];l=i.startsWith("/")?i.slice(1):`xl/${i}`}return r.includes(`PartName="/${l}"`)||(r=r.replace("</Types>",`<Override PartName="/${l}" ContentType="${p}"/></Types>`)),await t.addBytes(l,s),e.handled?.add(l),{types:r,rels:n}}export{g as borderRefs,h as colorAttrs,T as fillRefs,b as fontRefs,x as readStyleRefs,c as refFromNode,u as refLive,y as writeThemePart};
@@ -0,0 +1,2 @@
1
+ import{base64ToBytes as W,bytesToBase64 as q}from"../core/base64.js";import{relationshipTarget as k,relsPathOf as d,resolveTarget as C,sheetPartsByName as b}from"../io/package-paths.js";const j="application/vnd.openxmlformats-officedocument.vmlDrawing",y="http://schemas.openxmlformats.org/officeDocument/2006/relationships",v={"image/png":"png","image/jpeg":"jpeg","image/gif":"gif","image/bmp":"bmp"},P={png:"image/png",jpeg:"image/jpeg",jpg:"image/jpeg",gif:"image/gif",bmp:"image/bmp"},R=' gain="19661f" blacklevel="22938f"',T=e=>`xl/drawings/vmlDrawingHF8c${e+1}.vml`,U="rIdWatermark8c";function w(e){const n=/^data:(image\/[\w+.-]+);base64,(.*)$/s.exec(e??"");return n?{mime:n[1],bytes:W(n[2])}:null}function H(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length>24&&n.getUint32(0)===2303741511)return{width:n.getUint32(16),height:n.getUint32(20)};if(e.length>10&&e[0]===71&&e[1]===73)return{width:n.getUint16(6,!0),height:n.getUint16(8,!0)};if(e.length>26&&e[0]===66&&e[1]===77)return{width:n.getInt32(18,!0),height:Math.abs(n.getInt32(22,!0))};if(e[0]===255&&e[1]===216){let t=2;for(;t+9<e.length;){if(e[t]!==255)return null;const i=e[t+1];if(i>=192&&i<=207&&i!==196&&i!==200&&i!==204)return{width:n.getUint16(t+7),height:n.getUint16(t+5)};t+=2+n.getUint16(t+2)}}return null}function I(e){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_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"/><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"/><v:f eqn="sum @0 1 0"/><v:f eqn="sum 0 0 @1"/><v:f eqn="prod @2 1 2"/><v:f eqn="prod @3 21600 pixelWidth"/><v:f eqn="prod @3 21600 pixelHeight"/><v:f eqn="sum @0 0 1"/><v:f eqn="prod @6 1 2"/><v:f eqn="prod @7 21600 pixelWidth"/><v:f eqn="sum @8 21600 0"/><v:f eqn="prod @7 21600 pixelHeight"/><v:f eqn="sum @10 21600 0"/></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/><o:lock v:ext="edit" aspectratio="t"/></v:shapetype>'+e.map(({id:n,rid:t,width:i,height:r,washout:o},c)=>`<v:shape id="${n}" o:spid="_x0000_s${1025+c}" type="#_x0000_t75" style="position:absolute;margin-left:0;margin-top:0;width:${i}pt;height:${r}pt;z-index:1"><v:imagedata o:relid="${t}" o:title="Watermark"${o?R:""}/><o:lock v:ext="edit" rotation="t"/></v:shape>`).join("")+"</xml>"}function L(e){const n=[];return e.sheets.forEach((t,i)=>{if(!t.printWatermarkChanged)return;const r=w(t.printWatermark?.url),o=Object.entries(t.headerPictures??{});if((!r||!v[r.mime])&&o.length===0)return;const c=T(i),m=a=>Math.round(a*.75*100)/100,g=[],x=[],f=(a,s,l)=>{if(!l||!v[l.mime])return;const p=`rId${g.length+1}`,u=`xl/media/watermark8c${i+1}${a==="CH"?"":a}.${v[l.mime]}`,h=H(l.bytes)??{width:400,height:300};g.push({id:a,rid:p,width:s.width??m(h.width),height:s.height??m(h.height),washout:(s.opacity??1)<.75}),x.push(`<Relationship Id="${p}" Type="${y}/image" Target="../media/${u.split("/").pop()}"/>`),n.push({path:u,xml:l.bytes,override:{partName:`/${u}`,contentType:l.mime},relationship:null})};r&&f("CH",t.printWatermark,r);for(const[a,s]of o)f(a,s,w(s.url));n.push({path:c,xml:I(g),override:{partName:`/${c}`,contentType:j},relationship:null},{path:d(c),xml:`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${x.join("")}</Relationships>`,override:null,relationship:null})}),n}function N(e,n){if(!e.printWatermarkChanged)return null;const t=w(e.printWatermark?.url)!==null||Object.keys(e.headerPictures??{}).length>0;return{rid:t?U:null,vml:t?T(n):null}}function O(e,n){const t=(e??"").replace(/&G/g,"").replace(/&C(?=&[LR]|$)/,"");if(!n)return t;if(t.includes("&C"))return t.replace("&C","&C&G");const i=t.indexOf("&R");return i>=0?`${t.slice(0,i)}&C&G${t.slice(i)}`:/^&L/.test(t)||t===""?`${t}&C&G`:`&C&G${t}`}async function S(e,n){const t=n.sheets.filter(r=>r.headerPictureRid);if(t.length===0)return;const i=await b(e);for(const r of t){const o=i.get(r.name);if(!o||!e.has(d(o)))continue;const c=k(await e.text(d(o)),r.headerPictureRid);if(!c)continue;const m=C(o,c);if(!e.has(m)||!e.has(d(m)))continue;const g=await e.text(d(m)),x=await e.text(m);for(const f of x.matchAll(/<v:shape\b[^>]*\bid="([LCR][HF](?:FIRST|EVEN)?)"[\s\S]*?<\/v:shape>/g)){const a=f[0],s=/o:relid="([^"]+)"/.exec(a)?.[1];if(!s)continue;const l=k(g,s),p=l&&C(m,l);if(!p||!e.has(p))continue;const u=P[p.split(".").pop().toLowerCase()];if(!u)continue;const h=/width:([\d.]+)pt;\s*height:([\d.]+)pt/.exec(a),$={url:`data:${u};base64,${q(await e.bytes(p))}`,opacity:/gain=/.test(a)?.25:1,width:h?Number(h[1]):void 0,height:h?Number(h[2]):void 0};f[1]==="CH"?r.printWatermark={...$,fit:"center",onScreen:!1}:(r.headerPictures??={})[f[1]]=$}}}export{H as imageSize,S as loadWatermarks,L as watermarkParts,N as watermarkPlan,O as withHeaderPicture};
package/calc/adjust.js ADDED
@@ -0,0 +1 @@
1
+ import{colName as j,MAX_COLS as E,MAX_ROWS as S}from"../core/address.js";import{tokenize as O}from"./parser.js";function N(e,s,r){return e<s?e:r>0?e+r:e<s-r?null:e+r}function x(e,s,r,o,b){if(o>0){const R=e>=r?e+o:e,k=s>=r?Math.min(s+o,b-1):s;return R>=b?null:[R,k]}const $=r-o;if(e>=r&&s<$)return null;const y=e<r?e:e<$?r:e+o,u=s<r?s:s<$?r-1:s+o;return[y,u]}const M=(e,s,r,o)=>`${r?"$":""}${j(e)}${o?"$":""}${s+1}`;function X(e,s,r,o){const b=(i,h)=>!s.span||i>=s.span[0]&&h<=s.span[1];let $;try{$=O(e)}catch{return e}const y=o.toUpperCase(),u=s.axis==="row";let R="",k=0;const v=(i,h,d)=>{R+=e.slice(k,i)+d,k=h};for(let i=0;i<$.length;i++){const h=$[i];let d=r,c=null,A=i;h.t==="sheet"&&(c=h,d=h.v.book===null&&h.v.sheet2===null&&h.v.sheet.toUpperCase()===y,A=i+1);const l=$[A];if(l===void 0)break;if(l.t==="cell"){const t=l.v,m=$[A+1],f=$[A+2];if(m?.t==="op"&&m.v===":"&&f?.t==="cell"){const n=f.v,F=u?[Math.min(t.c,n.c),Math.max(t.c,n.c)]:[Math.min(t.r,n.r),Math.max(t.r,n.r)];if(d&&b(F[0],F[1])){const p=c?e.slice(c.s,c.e):"",a=u?x(Math.min(t.r,n.r),Math.max(t.r,n.r),s.at,s.n,S):x(Math.min(t.c,n.c),Math.max(t.c,n.c),s.at,s.n,E),C=c?c.s:l.s;if(a===null)v(C,f.e,"#REF!");else if(u){const w=t.r<=n.r;v(C,f.e,`${p}${M(t.c,w?a[0]:a[1],t.cAbs,t.rAbs)}:${M(n.c,w?a[1]:a[0],n.cAbs,n.rAbs)}`)}else{const w=t.c<=n.c;v(C,f.e,`${p}${M(w?a[0]:a[1],t.r,t.cAbs,t.rAbs)}:${M(w?a[1]:a[0],n.r,n.cAbs,n.rAbs)}`)}}i=A+2;continue}if(d&&b(u?t.c:t.r,u?t.c:t.r)){const n=N(u?t.r:t.c,s.at,s.n),F=u?S:E,p=c?c.s:l.s,a=c?e.slice(c.s,c.e):"";n===null||n>=F?v(p,l.e,"#REF!"):v(p,l.e,a+(u?M(t.c,n,t.cAbs,t.rAbs):M(n,t.r,t.cAbs,t.rAbs)))}i=A}else if(l.t==="rows"&&u&&d&&!s.span){const t=l.v,m=x(t.r0,t.r1,s.at,s.n,S),f=c?c.s:l.s,n=c?e.slice(c.s,c.e):"";m===null?v(f,l.e,"#REF!"):v(f,l.e,`${n}${t.a0?"$":""}${m[0]+1}:${t.a1?"$":""}${m[1]+1}`),i=A}else if(l.t==="cols"&&!u&&d&&!s.span){const t=l.v,m=x(t.c0,t.c1,s.at,s.n,E),f=c?c.s:l.s,n=c?e.slice(c.s,c.e):"";m===null?v(f,l.e,"#REF!"):v(f,l.e,`${n}${t.a0?"$":""}${j(m[0])}:${t.a1?"$":""}${j(m[1])}`),i=A}else c&&(i=A-1)}return R+e.slice(k)}function _(e,s){const r=s.axis==="row",o=r?x(e.r0,e.r1,s.at,s.n,S):x(e.c0,e.c1,s.at,s.n,E);return o===null?null:r?{...e,r0:o[0],r1:o[1]}:{...e,c0:o[0],c1:o[1]}}export{X as adjustFormula,_ as adjustRange,M as cellText};
@@ -0,0 +1 @@
1
+ import{CHUNK_BITS as f,CHUNK_MASK as r}from"../core/sheet.js";const h=r+1>>>5;class b{constructor(){this.columns=[],this.size=0}add(e,i){let t=this.columns[i];t===void 0&&(t=[],this.columns[i]=t);const n=e>>>f;let s=t[n];s===void 0&&(s=new Uint32Array(h),t[n]=s);const o=e&r,c=1<<(o&31);(s[o>>>5]&c)===0&&(s[o>>>5]|=c,this.size++)}delete(e,i){const t=this.columns[i]?.[e>>>f];if(t===void 0)return!1;const n=e&r,s=1<<(n&31);return(t[n>>>5]&s)===0?!1:(t[n>>>5]&=~s,this.size--,!0)}has(e,i){const t=this.columns[i]?.[e>>>f];if(t===void 0)return!1;const n=e&r;return(t[n>>>5]&1<<(n&31))!==0}forEach(e){const{columns:i}=this;for(let t=0;t<i.length;t++){const n=i[t];if(n!==void 0)for(let s=0;s<n.length;s++){const o=n[s];if(o===void 0)continue;const c=s<<f;for(let l=0;l<h;l++){let u=o[l];for(;u!==0;){const d=u&-u;u^=d,e(c+(l<<5)+(31-Math.clz32(d)),t)}}}}}}export{b as CellSet};
@@ -0,0 +1 @@
1
+ import{MAX_COLS as A,MAX_ROWS as d}from"../core/address.js";import{Arr as x,compareValues as C,ERR as m,Lambda as w,num as L,OMITTED as M,Ref as y,RefList as g,str as V,XlError as b}from"./values.js";import{FUNCS as E}from"./functions/registry.js";const R=5e-16;class N{constructor(e){this.cx=e,this.refs=[],this.names=[],this.tables=[],this.isVolatile=!1,this.mayArray=!1,this.external=!1,this.arrayCtx=!1,this.scopes=[],this.slots=0,this.rangeSlots=new Set}compileTop(e){const i=this.any(e),{slots:n,cx:a}=this;return n===0?i:(c,t,s)=>{const r=a.frame;a.frame=new Array(n);try{return i(c,t,s)}finally{a.frame=r}}}sheetOf(e){const{cx:i}=this;if(e==null)return t=>t;if(e.book!==null&&e.book!==void 0){const t=i.externalSheet?.(e.book,e.sheet)??null;return t===null&&(this.external=!0),()=>t}const n=e.sheet;let a=-1,c=null;return()=>(a!==i.sheetGen&&(c=i.sheetByName(n),a=i.sheetGen),c)}cellRefClosure(e){const i=this.sheetOf(e.sheet),{rAbs:n,cAbs:a,r:c,c:t}=e;return this.refs.push({sheet:e.sheet,rAbs0:n,r0:c,rAbs1:n,r1:c,cAbs0:a,c0:t,cAbs1:a,c1:t}),e.sheet?.sheet2?this.sheet3d(e.sheet,(s,r,o)=>{const h=n?c:r+c,u=a?t:o+t;return new y(s,h,u,h,u)}):(s,r,o)=>{const h=n?c:s+c,u=a?t:r+t,f=i(o);return f===null||h<0||u<0||h>=d||u>=A?m.REF:new y(f,h,u,h,u)}}sheet3d(e,i){const{cx:n}=this;return(a,c)=>{const t=n.sheetsBetween(e.sheet,e.sheet2);return t===null?m.REF:new g(t.map(s=>i(s,a,c)))}}rangeClosure(e){const{a:i,b:n}=e,a=this.sheetOf(e.sheet);this.refs.push({sheet:e.sheet,rAbs0:i.rAbs,r0:i.r,rAbs1:n.rAbs,r1:n.r,cAbs0:i.cAbs,c0:i.c,cAbs1:n.cAbs,c1:n.c});const c=(t,s,r)=>{const o=i.rAbs?i.r:s+i.r,h=i.cAbs?i.c:r+i.c,u=n.rAbs?n.r:s+n.r,f=n.cAbs?n.c:r+n.c;return o<0||h<0||u<0||f<0||o>=d||u>=d||h>=A||f>=A?m.REF:new y(t,Math.min(o,u),Math.min(h,f),Math.max(o,u),Math.max(h,f))};return e.sheet?.sheet2?this.sheet3d(e.sheet,c):(t,s,r)=>{const o=a(r);return o===null?m.REF:c(o,t,s)}}rowsClosure(e){const i=this.sheetOf(e.sheet);return this.refs.push({sheet:e.sheet,rAbs0:e.a0,r0:e.r0,rAbs1:e.a1,r1:e.r1,cAbs0:!0,c0:0,cAbs1:!0,c1:A-1}),(n,a,c)=>{const t=e.a0?e.r0:n+e.r0,s=e.a1?e.r1:n+e.r1,r=i(c);return r===null||t<0||s<0||t>=d||s>=d?m.REF:new y(r,Math.min(t,s),0,Math.max(t,s),A-1)}}colsClosure(e){const i=this.sheetOf(e.sheet);return this.refs.push({sheet:e.sheet,rAbs0:!0,r0:0,rAbs1:!0,r1:d-1,cAbs0:e.a0,c0:e.c0,cAbs1:e.a1,c1:e.c1}),(n,a,c)=>{const t=e.a0?e.c0:a+e.c0,s=e.a1?e.c1:a+e.c1,r=i(c);return r===null||t<0||s<0||t>=A||s>=A?m.REF:new y(r,0,Math.min(t,s),d-1,Math.max(t,s))}}any(e){const{cx:i}=this;switch(e.t){case"lit":{const n=e.v;return()=>n}case"omit":return()=>M;case"paren":return this.any(e.e);case"cell":return this.cellRefClosure(e);case"range":return this.rangeClosure(e);case"rows":return this.rowsClosure(e);case"cols":return this.colsClosure(e);case"array":{const n=x.of2D(e.rows);return()=>n}case"union":{const n=e.items.map(a=>this.any(a));return(a,c,t)=>{const s=[];for(const r of n){const o=r(a,c,t);if(o instanceof y)s.push(o);else if(o instanceof g)s.push(...o.refs);else return o instanceof b?o:m.VALUE}return new g(s)}}case"intersect":{const n=this.any(e.l),a=this.any(e.r);return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);if(r instanceof b)return r;if(o instanceof b)return o;if(!(r instanceof y)||!(o instanceof y)||r.sheet!==o.sheet)return m.VALUE;const h=Math.max(r.r0,o.r0),u=Math.min(r.r1,o.r1),f=Math.max(r.c0,o.c0),l=Math.min(r.c1,o.c1);return h>u||f>l?m.NULL:new y(r.sheet,h,f,u,l)}}case"rangeOp":{const n=this.any(e.l),a=this.any(e.r);return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);return r instanceof b?r:o instanceof b?o:!(r instanceof y)||!(o instanceof y)||r.sheet!==o.sheet?m.REF:new y(r.sheet,Math.min(r.r0,o.r0),Math.min(r.c0,o.c0),Math.max(r.r1,o.r1),Math.max(r.c1,o.c1))}}case"implicit":{const n=this.any(e.e);return(a,c,t)=>{const s=n(a,c,t);return s instanceof y?s.isCell?i.read(s.sheet,s.r0,s.c0):i.intersect(s,a,c):s instanceof x?s.data[0]:s}}case"spillRef":{const n=this.any(e.e);return(a,c,t)=>{const s=n(a,c,t);return s instanceof y?i.spillRange(s):m.REF}}case"name":return this.nameNode(e);case"table":return this.tables.push({name:e.name,spec:e.spec}),(n,a,c)=>i.resolveTable(e.name,e.spec,n,a,c);case"call":return this.call(e);case"apply":{const n=this.any(e.fn),a=e.args.map(c=>this.any(c));return(c,t,s)=>{const r=n(c,t,s);return r instanceof b?r:r instanceof w?i.invoke(r,a.map(o=>o(c,t,s)),c,t,s):m.VALUE}}default:return this.value(e)}}nameNode(e){const{cx:i}=this,n=this.lookupVar(e.name);if(n!==null){const s=n;return()=>i.frame[s]}this.names.push(e.name);const a=e.name,c=e.sheet?this.sheetOf(e.sheet):s=>s,t=e.sheet?void 0:E.get(a.toUpperCase());if(t!==void 0){const s=new w([],null,null);return s.native=t,s.label=a.toUpperCase(),(r,o,h)=>{const u=i.evalName(a,r,o,h);return u===m.NAME?s:u}}return(s,r,o)=>i.evalName(a,s,r,c(o)??o)}lookupVar(e){const i=e.toUpperCase();for(let n=this.scopes.length-1;n>=0;n--){const a=this.scopes[n].get(i);if(a!==void 0)return a}return null}deref(e){const{cx:i}=this;return this.arrayCtx?(n,a,c)=>{const t=e(n,a,c);return t instanceof y||t instanceof g?i.refToValue(t):t}:(n,a,c)=>{const t=e(n,a,c);return t instanceof y||t instanceof g?i.refAuto(t,n,a):t}}value(e){const{cx:i}=this;switch(e.t){case"lit":{const n=e.v;return()=>n}case"paren":return this.value(e.e);case"cell":{const{rAbs:n,cAbs:a,r:c,c:t}=e;if(this.refs.push({sheet:e.sheet,rAbs0:n,r0:c,rAbs1:n,r1:c,cAbs0:a,c0:t,cAbs1:a,c1:t}),e.sheet?.sheet2)return()=>m.VALUE;const s=e.sheet?this.sheetOf(e.sheet):null;return s===null?!n&&!a?(r,o,h)=>{const u=r+c,f=o+t;return u<0||f<0||u>=d||f>=A?m.REF:i.read(h,u,f)}:(r,o,h)=>{const u=n?c:r+c,f=a?t:o+t;return u<0||f<0||u>=d||f>=A?m.REF:i.read(h,u,f)}:(r,o,h)=>{const u=n?c:r+c,f=a?t:o+t,l=s(h);return l===null||u<0||f<0||u>=d||f>=A?m.REF:i.read(l,u,f)}}case"range":case"rows":case"cols":return this.arrayCtx||(this.mayArray=!0),this.deref(this.any(e));case"neg":{const n=this.value(e.e);return(a,c,t)=>{const s=n(a,c,t);return typeof s=="number"?-s:i.unary(s,r=>-r)}}case"pct":{const n=this.value(e.e);return(a,c,t)=>{const s=n(a,c,t);return typeof s=="number"?s/100:i.unary(s,r=>r/100)}}case"bin":return this.binary(e);default:return!this.arrayCtx&&this.mayYieldRange(e)&&(this.mayArray=!0),this.deref(this.any(e))}}mayYieldRange(e){switch(e.t){case"paren":return this.mayYieldRange(e.e);case"range":case"rows":case"cols":case"union":case"rangeOp":case"intersect":case"spillRef":case"apply":return!0;case"table":return!/^\[\[#This Row\],\[[^\]]+\]\]$/i.test(e.spec);case"name":{if(e.sheet)return!0;const i=this.lookupVar(e.name);return i!==null?this.rangeSlots.has(i):this.cx.nameMayYieldRange?.(e.name)??!0}case"call":{if(e.name==="LET"||e.name==="LAMBDA"||this.lookupVar(e.name)!==null)return!0;const i=E.get(e.name);return i===void 0||i.refResult?!0:i.passes?e.args.some((n,a)=>i.passes(a,e.args.length)&&this.mayYieldRange(n)):!1}default:return!1}}binary(e){const{cx:i}=this,n=this.value(e.l),a=this.value(e.r);switch(e.op){case"+":return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);if(typeof r=="number"&&typeof o=="number"){const h=r+o;return Math.abs(h)<Math.abs(r)*R?0:h}return i.slowBin("+",r,o)};case"-":return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);if(typeof r=="number"&&typeof o=="number"){const h=r-o;return Math.abs(h)<Math.abs(r)*R?0:h}return i.slowBin("-",r,o)};case"*":return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);return typeof r=="number"&&typeof o=="number"?r*o:i.slowBin("*",r,o)};case"/":return(c,t,s)=>{const r=n(c,t,s),o=a(c,t,s);return typeof r=="number"&&typeof o=="number"&&o!==0?r/o:i.slowBin("/",r,o)};case"^":return(c,t,s)=>i.slowBin("^",n(c,t,s),a(c,t,s));case"&":return(c,t,s)=>i.slowBin("&",n(c,t,s),a(c,t,s));default:{const c=e.op;return(t,s,r)=>i.slowBin(c,n(t,s,r),a(t,s,r))}}}call(e){const{cx:i}=this,{name:n,args:a}=e;if(n==="LET")return this.compileLet(a);if(n==="LAMBDA")return this.compileLambda(a);const c=this.lookupVar(n);if(c!==null){const s=c,r=a.map(o=>this.any(o));return(o,h,u)=>{const f=i.frame[s];return f instanceof w?i.invoke(f,r.map(l=>l(o,h,u)),o,h,u):m.VALUE}}const t=E.get(n);if(t===void 0){this.names.push(n);const s=a.map(r=>this.any(r));return(r,o,h)=>{const u=i.evalName(n,r,o,h);return u instanceof w?i.invoke(u,s.map(f=>f(r,o,h)),r,o,h):m.NAME}}if((a.length<t.min||a.length>t.max)&&!(a.length===1&&a[0].t==="omit"&&t.min===0))return()=>m.VALUE;if(t.volatile&&(this.isVolatile=!0),t.notInExcel&&(this.notInExcel=!0),t.frozen&&(this.external=!0),t.kind==="lazy"||t.kind==="raw"){const s=this.arrayCtx;t.array&&(this.arrayCtx=!0);const r=a.map(h=>this.any(h));this.arrayCtx=s;const{fn:o}=t;return t.kind==="lazy"?(h,u,f)=>{try{return o(i,r,h,u,f)}catch(l){if(l instanceof b)return l;throw l}}:(h,u,f)=>{const l=new Array(r.length);for(let p=0;p<r.length;p++)l[p]=r[p](h,u,f);try{return o(i,l,h,u,f)}catch(p){if(p instanceof b)return p;throw p}}}return this.lifted(t,a)}lifted(e,i){const{cx:n}=this,{fn:a,errors:c}=e,t=i.map(r=>r.t==="omit"?()=>M:this.value(r)),s=t.length;if(s===1){const r=t[0];return(o,h,u)=>{const f=r(o,h,u);if(f instanceof x)return n.liftArr(a,[f],c);if(!c&&f instanceof b)return f;try{return a(f)}catch(l){if(l instanceof b)return l;throw l}}}if(s===2){const[r,o]=t;return(h,u,f)=>{const l=r(h,u,f),p=o(h,u,f);if(l instanceof x||p instanceof x)return n.liftArr(a,[l,p],c);if(!c){if(l instanceof b)return l;if(p instanceof b)return p}try{return a(l,p)}catch(v){if(v instanceof b)return v;throw v}}}return(r,o,h)=>{const u=new Array(s);let f=!1;for(let l=0;l<s;l++){const p=t[l](r,o,h);u[l]=p,p instanceof x&&(f=!0)}if(f)return n.liftArr(a,u,c);if(!c){for(let l=0;l<s;l++)if(u[l]instanceof b)return u[l]}try{return a(...u)}catch(l){if(l instanceof b)return l;throw l}}}compileLet(e){const{cx:i}=this;if(e.length<3||e.length%2===0)return()=>m.VALUE;const n=new Map;this.scopes.push(n);const a=[];for(let t=0;t+1<e.length;t+=2){const s=e[t];if(s.t!=="name")return this.scopes.pop(),()=>m.VALUE;const r=this.any(e[t+1]),o=this.slots++;this.mayYieldRange(e[t+1])&&this.rangeSlots.add(o),n.set(s.name.toUpperCase(),o),a.push(o,r)}const c=this.any(e[e.length-1]);return this.scopes.pop(),(t,s,r)=>{for(let o=0;o<a.length;o+=2)i.frame[a[o]]=a[o+1](t,s,r);return c(t,s,r)}}compileLambda(e){const{cx:i}=this;if(e.length===0)return()=>m.VALUE;const n=new Map;this.scopes.push(n);const a=[];for(let t=0;t<e.length-1;t++){const s=e[t];if(s.t!=="name")return this.scopes.pop(),()=>m.VALUE;const r=this.slots++;this.rangeSlots.add(r),n.set(s.name.toUpperCase(),r),a.push(r)}const c=this.any(e[e.length-1]);return this.scopes.pop(),()=>new w(a,c,i.frame)}}export{N as Compiler,C as compareValues,L as num,V as str};
package/calc/engine.js ADDED
@@ -0,0 +1 @@
1
+ import{resolveStructuredSpec as yt}from"../slicers/structured.js";import{Arr as C,compareValues as v,ERR as k,ERR_BY_INDEX as Y,Lambda as kt,num as S,power as _t,Ref as q,RefList as $,RichValue as O,str as rt,XlError as x}from"./values.js";import{entityVm as at,richValueAt as gt}from"../cells/rich-values.js";import{Compiler as lt}from"./compile.js";import{FormulaSyntaxError as W,Parser as j,templateKey as bt,tokenize as z,toDisplayFormula as Mt}from"./parser.js";import{BOOL as G,CHUNK_BITS as E,CHUNK_MASK as T,CONTENT_MASK as ot,DIRTY as w,EMPTY as Q,EVALUATING as X,FORMULA as R,KIND_MASK as V,NUM as U,SPILL as H,STR as B,ERR as N}from"../core/sheet.js";import{colName as ct,MAX_COLS as M,MAX_ROWS as J,parseRangeRef as P}from"../core/address.js";import{CellSet as wt}from"./cell-set.js";import{isRowBelow as At}from"./fill-shape.js";import"./functions/index.js";const Z=Symbol("pending"),ht=200,Ct=4096,xt=64,tt=2147483647,D=4;class et{constructor(){this.n=0,this.data=new Int32Array(D*8)}push(t,e,s,n){if((this.n+1)*D>this.data.length){const a=new Int32Array(this.data.length*2);a.set(this.data),this.data=a}const i=this.n++*D,r=this.data;r[i]=t,r[i+1]=e,r[i+2]=s,r[i+3]=n}}function Tt(m,t){if(!m.valueMeta.has(t))return;const e=new Map(m.valueMeta);e.delete(t),m.valueMeta=e.size>0?e:null}function ft(m,t,e){if(m.valueMeta?.get(t)===e)return;const s=new Map(m.valueMeta??[]);s.set(t,e),m.valueMeta=s}function st(m,t){let e=m.get(t);return e===void 0&&(e=new wt,m.set(t,e)),e}class Rt{constructor(){this.buckets=[],this.wide=[],this.all=new et,this.allCols=[]}}class Bt{constructor(t){this.book=t,this.sheetGen=0,this.sheetMap=new Map,this.deps=new Map,this.templates=new Map,this.lastOwn={row:-2,col:-1,text:"",tpl:{cacheKey:void 0}},this.frame=null,this.depth=0,this.legacy=!1,this.pendingSheet=null,this.pendingRow=0,this.pendingCol=0,this.circular=null,this.evalStack=new Int32Array(3*256),this.evalTop=0,this.cycleLow=tt,this.iterate=null,this.cycleFound=[],this.cycleMembers=null,this.iterating=!1,this.sliceMs=10,this.syncLimit=4e3,this.externalLinks=null,this.names=new Map,this.nameTemplates=new Map,this.tables=new Map,this.volatile=new Map,this.visibilityReaders=new Map,this.styleReaders=new Map,this.wakePending=0,this.queue=new Int32Array(4096),this.qHead=0,this.qLen=0,this.sheetsByUid=new Map,this.running=!1,this.timer=0,this.manual=!1,this.graphReady=!0,this.pendingChanges=[],this.waiters=[],this.onChange=null,this.dataTables=[],this.tablesDirty=!1,this.inTables=!1,this.tablesForced=!1,this.onProgress=null,this.lookupCache=new Map,this.colRevisions=new Map,this.channel=null,this.sheetsChanged()}orderChanged(){this.sheetsChanged(),this.has3D&&this.rebuild()}sheetsChanged(){this.sheetGen++,this.sheetMap.clear(),this.sheetsByUid.clear();for(const t of this.book.sheets)this.sheetMap.set(t.name.toUpperCase(),t),this.sheetsByUid.set(t.uid,t),t.rows.watcher=this,t.cols.watcher=this}sheetByName(t){return this.sheetMap.get(t.toUpperCase())??null}externalSheet(t,e){return this.externalLinks?.sheet(t,e)??null}sheetsBetween(t,e){const{sheets:s}=this.book,n=s.findIndex(r=>r.name.toUpperCase()===t.toUpperCase()),i=s.findIndex(r=>r.name.toUpperCase()===e.toUpperCase());return n<0||i<0?null:s.slice(Math.min(n,i),Math.max(n,i)+1)}setNames(t){this.names.clear(),this.nameTemplates.clear();for(const e of t){const s=e.localSheetId!==void 0?`${e.localSheetId}!${e.name.toUpperCase()}`:e.name.toUpperCase();this.names.set(s,{text:e.text,name:e.name,hidden:e.hidden,comment:e.comment})}}setTables(t){this.tables.clear();for(const e of t)this.tables.set(e.name.toUpperCase(),e)}template(t,e,s){let n;try{n=z(t)}catch(a){if(a instanceof W)return this._broken(t);throw a}const i=bt(n,e,s);let r=this.templates.get(i);if(r===void 0){try{const a=new j(n,e,s).parse();r=this._compile(a)}catch(a){if(!(a instanceof W))throw a;r=this._broken(t)}r.cacheKey=i,this.templates.set(i,r)}return r}_ownTemplate(t,e,s){const n=this.lastOwn;let i;return n.row===e-1&&n.col===s&&this.templates.get(n.tpl.cacheKey)===n.tpl&&At(n.text,t)?i=n.tpl:i=this.template(t,e,s),n.row=e,n.col=s,n.text=t,n.tpl=i,i}_compile(t){const e=new lt(this);return{fn:e.compileTop(t),refs:e.refs,names:e.names,tables:e.tables,isVolatile:e.isVolatile,notInExcel:e.notInExcel===!0,mayArray:e.mayArray,external:e.external}}_broken(){return{invalid:!0,fn:()=>k.NAME,refs:[],names:[],tables:[],isVolatile:!1,mayArray:!1,external:!0}}validate(t){it(new j(z(t),0,0).parse())}_templateFor(t,e,s,n){if(n.tpl!==void 0)return n.tpl;let i;return n.t==="dataTable"?i=this._dataTableTemplate():n.f!==void 0&&n.base===void 0?i=this._ownTemplate(n.f,e,s):n.f!==void 0?i=this.template(n.f,Math.floor(n.base/M),n.base%M):n.sf!==void 0?i=this.template(n.sf,Math.floor(n.base/M),n.base%M):i=this._broken(),n.tpl=i,i}_index(t){let e=this.deps.get(t);return e===void 0&&(e=new Rt,this.deps.set(t,e)),e}_addDep(t,e,s,n,i,r,a,o){const l=this._index(t),c=r.uid<<14|o;if(i-s>=xt){l.all.push(a,c,e,n),l.allCols.push(s,i);return}if(n-e>=Ct){for(let p=s;p<=i;p++){let f=l.wide[p];f===void 0&&(f=new et,l.wide[p]=f),f.push(a,c,e,n)}return}const u=e>>>E,d=n>>>E;for(let p=s;p<=i;p++){let f=l.buckets[p];f===void 0&&(f=[],l.buckets[p]=f);for(let h=u;h<=d;h++){let y=f[h];y===void 0&&(y=new et,f[h]=y),y.push(a,c,e,n)}}}register(t,e,s,n){const i=this._templateFor(t,e,s,n);if(i.external)return i;for(const r of i.refs)this._addRefDep(r,t,e,s);for(const r of i.names)this._addNameDeps(r,t,e,s);for(const r of i.tables)this._addTableDep(r,t,e,s);return i.isVolatile&&st(this.volatile,t).add(e,s),i.readsVisibility??=/SUBTOTAL|AGGREGATE|SPARK_/i.test(n.f??n.sf??""),i.readsVisibility&&st(this.visibilityReaders,t).add(e,s),i.readsStyles??=/SPARK_BLOCK/i.test(n.f??n.sf??""),i.readsStyles&&st(this.styleReaders,t).add(e,s),i}_addRefDep(t,e,s,n){const i=t.rAbs0?t.r0:s+t.r0,r=t.rAbs1?t.r1:s+t.r1,a=t.cAbs0?t.c0:n+t.c0,o=t.cAbs1?t.c1:n+t.c1,l=Math.max(0,Math.min(i,r)),c=Math.min(J-1,Math.max(i,r)),u=Math.max(0,Math.min(a,o)),d=Math.min(M-1,Math.max(a,o));if(l>c||u>d)return;if(t.sheet?.sheet2&&(t.sheet.book===null||t.sheet.book===void 0)){this.has3D=!0;for(const f of this.sheetsBetween(t.sheet.sheet,t.sheet.sheet2)??[])this._addDep(f,l,u,c,d,e,s,n);return}if(t.sheet?.book!==null&&t.sheet?.book!==void 0)return;const p=t.sheet?this.sheetByName(t.sheet.sheet):e;p&&this._addDep(p,l,u,c,d,e,s,n)}_addNameDeps(t,e,s,n){const i=this._nameTemplate(t,e);if(i!==null){for(const r of i.refs)this._addRefDep(r,e,s,n);for(const r of i.names)r.toUpperCase()!==t.toUpperCase()&&this._addNameDeps(r,e,s,n)}}_addTableDep(t,e,s,n){const i=this.resolveTable(t.name,t.spec,s,n,e);i instanceof q&&this._addDep(i.sheet,i.r0,i.c0,i.r1,i.c1,e,s,n)}rebuild(){this.has3D=!1,this.deps.clear(),this.volatile.clear(),this.visibilityReaders.clear(),this.styleReaders.clear(),this.lookupCache.clear(),this.qHead=0,this.qLen=0,this.cycleFound=[],this.cycleMembers=null,this.sheetGen++,this.buildGraph({fullCalc:!0})}buildGraph({fullCalc:t=!1,onDone:e}={}){this.graphReady=!1,this.dataTables=[],t&&(this.tablesDirty=!0);const s=this,n=this.book.sheets.map(c=>[c,c.formulas]);let i=0,r=0,a=0,o=0;const l=()=>{const c=performance.now()+s.sliceMs;let u=0;for(;i<n.length;i++,r=0,a=0,o=0){const[p,f]=n[i],{columns:h}=f;for(;r<h.length;r++,a=0,o=0){const y=h[r];if(y!==void 0)for(;a<y.length;a++,o=0){const _=y[a];if(_===void 0)continue;const{ids:g}=_,b=a<<E;for(;o<=T;o++){const L=g[o];if(L===0)continue;const A=f.infos[L],I=b+o;A.t==="dataTable"&&s.dataTables.push({sheet:p,row:I,col:r,info:A});const F=s.register(p,I,r,A);if(s._initFormula(p,I,r,A,F,t),++u%256===0&&performance.now()>c){o++,s.onProgress?.({preparing:!0}),s._later(l);return}}}}}s.graphReady=!0;const d=s.pendingChanges;s.pendingChanges=[];for(const[p,f,h,y]of d)s.cellsChanged(p,f,h,y);s._schedule(),e?.()};l()}_initFormula(t,e,s,n,i,r){const a=t._chunk(e,s);if(a===void 0)return;const o=e&T;if(n.t==="array"&&n.ref&&this._markArrayChildren(t,e,s,n),i.external)return;const l=a.kinds[o];(r||i.isVolatile||(l&V)===Q||i.notInExcel&&(l&V)===N)&&(a.kinds[o]=l|w,this._enqueue(t,e,s))}_markArrayChildren(t,e,s,n){const i=P(n.ref);if(i!==null){t.spills||(t.spills=new Map),t.spills.set(e*M+s,{...i,blocked:!1,fixed:!n.cm});for(let r=i.r0;r<=i.r1;r++)for(let a=i.c0;a<=i.c1;a++){if(r===e&&a===s)continue;const o=t._ensure(r,a);o.kinds[r&T]|=H}}}_enqueue(t,e,s){if(this.qLen+3>this.queue.length)if(this.qHead>this.queue.length>>>1)this.queue.copyWithin(0,this.qHead,this.qLen),this.qLen-=this.qHead,this.qHead=0;else{const n=new Int32Array(this.queue.length*2);n.set(this.queue),this.queue=n}this.queue[this.qLen++]=t.uid,this.queue[this.qLen++]=e,this.queue[this.qLen++]=s}_dirtyFrom(t,e,s,n,i){const r=[t,e,s,n,i];for(;r.length>0;){const a=r.pop(),o=r.pop(),l=r.pop(),c=r.pop(),u=r.pop(),d=this.deps.get(u);if(d===void 0)continue;const p=(y,_)=>{const g=this.sheetsByUid.get(_>>>14);if(g===void 0)return;const b=_&16383,L=g._chunk(y,b);if(L===void 0)return;const A=y&T,I=L.kinds[A];(I&R)===0||(I&w)!==0||(L.kinds[A]=I|w,this._enqueue(g,y,b),r.push(g,b,b,y,y))},f=o>>>E,h=a>>>E;for(let y=c;y<=l;y++){const _=d.buckets[y];if(_!==void 0)for(let b=f;b<=h;b++){const L=_[b];if(L===void 0)continue;const{data:A}=L,I=L.n*D;for(let F=0;F<I;F+=D)a>=A[F+2]&&o<=A[F+3]&&p(A[F],A[F+1])}const g=d.wide[y];if(g!==void 0){const{data:b}=g,L=g.n*D;for(let A=0;A<L;A+=D)a>=b[A+2]&&o<=b[A+3]&&p(b[A],b[A+1])}}if(d.all.n>0){const{data:y}=d.all;for(let _=0;_<d.all.n;_++){const g=_*D;a>=y[g+2]&&o<=y[g+3]&&l>=d.allCols[_*2]&&c<=d.allCols[_*2+1]&&p(y[g],y[g+1])}}}}cellsChanged(t,e,s,n){if(n===0)return;if(this.inTables||(this.tablesDirty=!0),!this.graphReady){this.pendingChanges.push([t,e.slice(0,n),s.slice(0,n),n]);return}this.lookupCache.clear();const i=new Map;for(let r=0;r<n;r++){const a=e[r],o=s[r],l=i.get(o);l===void 0?i.set(o,[a,a]):(a<l[0]&&(l[0]=a),a>l[1]&&(l[1]=a));const c=t._chunk(a,o);if(c===void 0)continue;const u=a&T,d=c.kinds[u];if(d&R){const p=t.formula(a,o);p&&(this.register(t,a,o,p),d&w||(c.kinds[u]=d|w,this._enqueue(t,a,o)))}t.spills&&this._spillTouched(t,a,o)}for(const[r,a]of i)this._dirtyFrom(t,r,r,a[0],a[1]);this._markVolatile(),this._schedule()}_spillTouched(t,e,s){const n=e*M+s;for(const[i,r]of t.spills){const a=Math.floor(i/M),o=i-a*M;if(i===n){(t.kind(a,o)&R)===0&&(this._clearSpill(t,r,a,o),t.spills.delete(i));continue}if(e>=r.r0&&e<=r.r1&&s>=r.c0&&s<=r.c1){const l=t._chunk(a,o);if(l===void 0)continue;const c=a&T,u=l.kinds[c];u&R&&!(u&w)&&(l.kinds[c]=u|w,this._enqueue(t,a,o),this._dirtyFrom(t,o,o,a,a))}}}_markVolatile(){for(const[t,e]of this.volatile)e.forEach((s,n)=>{const i=t._chunk(s,n);if(i===void 0)return;const r=s&T,a=i.kinds[r];if(!(a&R)){e.delete(s,n);return}a&w||(i.kinds[r]=a|w,this._enqueue(t,s,n),this._dirtyFrom(t,n,n,s,s))})}get pending(){return(this.qLen-this.qHead)/3}_later(t){if(this._next=t,typeof MessageChannel>"u"){setTimeout(()=>this._tick(),0);return}this.channel===null&&(this.channel=new MessageChannel,this.channel.port1.onmessage=()=>this._tick()),this.channel.port2.postMessage(0)}_tick(){const t=this._next;this._next=null,t?.(),this._next===null&&this.channel!==null&&(this.channel.port1.close(),this.channel=null)}_schedule(){if(this.manual||this.inTables||this.running||!this.graphReady)return;if(this.pending===0){this._finish();return}const t=this.pending;if(t<=this.syncLimit&&(this._slice(this.syncLimit===1/0?1/0:this.sliceMs),this.pending===0)){this._finish();return}this.running=!0,this._total=t;const e=()=>{this._slice(this.sliceMs),this.pending>0?(this.onProgress?.({remaining:this.pending,total:Math.max(this._total,this.pending)}),this._later(e)):(this.running=!1,this._finish())};this._later(e)}_slice(t){const e=t!==1/0;let s=e?performance.now():0;const n=s+t;let i=1,r=1;for(;this.qHead<this.qLen;){const a=this.queue[this.qHead++],o=this.queue[this.qHead++],l=this.queue[this.qHead++],c=this.sheetsByUid.get(a);if(c!==void 0&&(this._run(c,o,l),e&&--r===0)){const u=performance.now();if(u>n)break;i=u-s<.5?Math.min(i*2,16):1,r=i,s=u}}this.qHead>=this.qLen&&(this.qHead=0,this.qLen=0)}_finish(){for(;this.cycleFound.length>0;)this._iterateCycles();const t=this.tablesForced;this.tablesForced=!1,this.tablesDirty&&this.dataTables.length>0&&(!this.skipTables||t)&&(this.tablesDirty=!1,this._computeDataTables()),this.onChange?.();const e=this.waiters;this.waiters=[];for(const s of e)s()}_dataTableTemplate(){const t=this;return{fn:(s,n,i)=>t._plainValue(i,s,n),refs:[],names:[],tables:[],isVolatile:!1,mayArray:!1}}_plainValue(t,e,s){const n=t.value(e,s);switch(t.kind(e,s)&V){case U:return n;case B:return this.book.strings.get(n);case G:return n!==0;case N:return Y[n];default:return null}}_writePlain(t,e,s,n){const i=t.kind(e,s)&R;n==null?t.setCell(e,s,i|U,0):typeof n=="number"?Number.isFinite(n)?t.setCell(e,s,i|U,n):t.setCell(e,s,i|N,k.NUM.index):typeof n=="boolean"?t.setCell(e,s,i|G,n?1:0):n instanceof x?t.setCell(e,s,i|N,n.index):t.setCell(e,s,i|B,this.book.strings.add(String(n)))}_setInputs(t,e){const s=new Uint32Array(e.length),n=new Uint32Array(e.length);e.forEach((i,r)=>{t.setCell(i.row,i.col,i.kind,i.value),s[r]=i.row,n[r]=i.col}),this.cellsChanged(t,s,n,e.length),this._slice(1/0)}evaluateWith(t,e,s){const n=e.map(({row:r,col:a})=>({row:r,col:a,kind:t.kind(r,a)&(V|R),value:t.value(r,a)})),i=this.inTables;this.inTables=!0;try{return this._setInputs(t,e.map(({row:r,col:a,text:o})=>{const l=Number(o);return o!==""&&Number.isFinite(l)?{row:r,col:a,kind:U,value:l}:{row:r,col:a,kind:B,value:this.book.strings.add(String(o))}})),s()}finally{this._setInputs(t,n),this.inTables=i}}_computeDataTables(){this.inTables=!0;const t=this.dataTables.filter(e=>e.sheet.formula(e.row,e.col)===e.info&&this.book.sheets.includes(e.sheet));this.dataTables=t;try{for(const e of t)this._computeDataTable(e)}finally{this.inTables=!1}}_computeDataTable({sheet:t,info:e}){const s=P(e.ref),n=P(e.r1??"");if(!s||!n)return;const i=e.r2?P(e.r2):null,r=e.dt2D==="1"||e.dt2D==="true",a=e.dtr==="1"||e.dtr==="true",o=(h,y)=>({kind:t.kind(h,y)&V,value:t.value(h,y)}),c=[n,i].filter(Boolean).map(h=>({row:h.r0,col:h.c0,kind:t.kind(h.r0,h.c0)&(V|R),value:t.value(h.r0,h.c0)})),u=[];for(let h=s.r0;h<=s.r1;h++)for(let y=s.c0;y<=s.c1;y++){let _,g;r?(_=[{row:n.r0,col:n.c0,...o(s.r0-1,y)},{row:i.r0,col:i.c0,...o(h,s.c0-1)}],g=[s.r0-1,s.c0-1]):a?(_=[{row:n.r0,col:n.c0,...o(s.r0-1,y)}],g=[h,s.c0-1]):(_=[{row:n.r0,col:n.c0,...o(h,s.c0-1)}],g=[s.r0-1,y]),this._setInputs(t,_);let b=this.read(t,g[0],g[1]);b instanceof C&&(b=b.data[0]),u.push(h,y,b)}this._setInputs(t,c);const d=u.length/3,p=new Uint32Array(d),f=new Uint32Array(d);for(let h=0;h<d;h++)p[h]=u[h*3],f[h]=u[h*3+1],this._writePlain(t,p[h],f[h],u[h*3+2]);this.cellsChanged(t,p,f,d),this._slice(1/0),t.revision++}dataTableAt(t,e,s){for(const n of this.dataTables){if(n.sheet!==t)continue;const i=P(n.info.ref);if(i&&e>=i.r0&&e<=i.r1&&s>=i.c0&&s<=i.c1)return n}return null}calculateNow(){const{manual:t,skipTables:e}=this;this.manual=!1,this.skipTables=!1,this.tablesDirty=!0,this.tablesForced=!0,this._markVolatile(),this._markCycles(),this._schedule(),this.manual=t,this.skipTables=e}whenIdle(){return this.pending===0&&this.graphReady&&!this.running?Promise.resolve():new Promise(t=>{this.waiters.push(t),this._schedule()})}_iterateCycles(){const t=this.cycleFound;this.cycleFound=[];const e=new Map,s=(a,o,l)=>{let c=e.get(a.uid);c===void 0&&(c=new Map,e.set(a.uid,c)),c.set(o*M+l,[a,o,l])};for(let a=0;a<t.length;a+=3)s(t[a],t[a+1],t[a+2]);const n=[];for(const a of this.book.sheets){const o=e.get(a.uid);o&&n.push(...[...o.keys()].sort((l,c)=>l-c).map(l=>o.get(l)))}this.cycleMembers??=new Map;for(const a of n)this.cycleMembers.set(`${a[0].uid}:${a[1]}:${a[2]}`,a);const{count:i,delta:r}=this.iterate;for(let a=1;a<=i;a++){let o=0;for(const[l,c,u]of n){const d=l._chunk(c,u);if(d===void 0)continue;const p=c&T;if(!(d.kinds[p]&R))continue;const f=d.values[p];d.kinds[p]|=w,this.iterating=!0,this._run(l,c,u),this.iterating=!1;const h=Math.abs(d.values[p]-f);h>o&&(o=h)}if(this.onProgress?.({iteration:a,iterations:i}),o<r)break}for(const[a,o,l]of n)this._dirtyFrom(a,l,l,o,o);for(const[a,o,l]of n){const c=a._chunk(o,l);c!==void 0&&(c.kinds[o&T]&=~w)}this._slice(1/0)}_markCycles(){if(!(this.iterate===null||this.cycleMembers===null))for(const[t,e,s]of this.cycleMembers.values()){const n=t._chunk(e,s);n===void 0||!(n.kinds[e&T]&R)||(n.kinds[e&T]|=w,this._enqueue(t,e,s))}}_run(t,e,s){const n=[t,e,s];for(;n.length>0;){const i=n[n.length-1],r=n[n.length-2],a=n[n.length-3];try{this.depth=0,this.evalTop=0,this.cycleLow=tt,this._calc(a,r,i),n.length-=3}catch(o){if(o!==Z)throw o;n.push(this.pendingSheet,this.pendingRow,this.pendingCol)}}}_calc(t,e,s){const n=t._chunk(e,s);if(n===void 0)return;const i=e&T,r=n.kinds[i];if(!(r&w))return;if(r&X){this.circular={sheet:t,row:e,col:s},this.iterating||this._cycleHit(t.uid,e,s);return}if(this.depth>=ht)throw this.pendingSheet=t,this.pendingRow=e,this.pendingCol=s,Z;const a=t.formula(e,s);if(a===void 0||!(r&R)){n.kinds[i]=r&~w;return}const o=this._templateFor(t,e,s,a);if(o.external){n.kinds[i]=r&~w;return}n.kinds[i]=r|X;const l=this.evalTop;l+3>this.evalStack.length&&this._growEvalStack(),this.evalStack[l]=t.uid,this.evalStack[l+1]=e,this.evalStack[l+2]=s,this.evalTop=l+3;const c=this.cycleLow;this.cycleLow=tt;const u=this.legacy,d=this.frame,p=a.typed!==!0&&a.t!=="array";this.legacy=p,this.depth++;let f;try{f=o.fn(e,s,t)}catch(y){if(n.kinds[i]&=~X,this.depth--,this.legacy=u,this.frame=d,this.evalTop=l,this.cycleLow=c,y===Z)throw y;y instanceof x?f=y:(console.error("Formula evaluation failed",y),f=k.VALUE),this._store(t,n,i,e,s,f,a,p);return}this.depth--,this.legacy=u,this.frame=d,this.evalTop=l;const h=this.cycleLow;if(this.cycleLow=h<l&&h<c?h:c,h<=l){if(this.iterate!==null){n.kinds[i]=r&~(w|X),this.cycleFound.push(t,e,s);return}f=0}this._store(t,n,i,e,s,f,a,p)}_cycleHit(t,e,s){const n=this.evalStack;for(let i=this.evalTop-3;i>=0;i-=3)if(n[i]===t&&n[i+1]===e&&n[i+2]===s){i<this.cycleLow&&(this.cycleLow=i);return}}_growEvalStack(){const t=new Int32Array(this.evalStack.length*2);t.set(this.evalStack),this.evalStack=t}_store(t,e,s,n,i,r,a,o){let l=r;(l instanceof q||l instanceof $)&&(l=o?this.refAuto(l,n,i):this.refToValue(l)),l instanceof kt&&(l=k.CALC),l instanceof C?a.t==="array"&&!a.cm&&a.ref?l=this._fillFixedArray(t,n,i,a,l):o||l.rows===1&&l.cols===1?(l=l.data[0],t.spills&&this._releaseSpill(t,n,i)):l=this._spill(t,n,i,a,l):t.spills&&!(a.t==="array"&&!a.cm)&&this._releaseSpill(t,n,i),a.t==="array"&&!a.cm&&a.ref&&!(r instanceof C)&&(l=this._fillFixedArray(t,n,i,a,C.filled(1,1,l)));let c=R,u=0;typeof l=="number"?Number.isFinite(l)?(c|=U,u=l):(c|=N,u=k.NUM.index):typeof l=="string"?(c|=B,u=this.book.strings.add(l)):typeof l=="boolean"?(c|=G,u=l?1:0):l instanceof x?(c|=N,u=l.index):l instanceof O?(c|=N,u=k.VALUE.index):c|=U,l instanceof O?ft(t,n*M+i,at(this.book,l.index)):t.valueMeta!==null&&((e.kinds[s]&ot)!==c||e.values[s]!==u)&&!/IMAGE\(/i.test(a.f??a.sf??"")&&Tt(t,n*M+i),e.kinds[s]=c,e.values[s]=u,n>t.maxRow&&(t.maxRow=n),i>t.maxCol&&(t.maxCol=i)}_writeArrayCell(t,e,s,n){let i=H,r=0;typeof n=="number"?(i|=Number.isFinite(n)?U:N,r=Number.isFinite(n)?n:k.NUM.index):typeof n=="string"?(i|=B,r=this.book.strings.add(n)):typeof n=="boolean"?(i|=G,r=n?1:0):n instanceof x?(i|=N,r=n.index):n==null?i|=U:(i|=N,r=k.VALUE.index,n instanceof O&&ft(t,e*M+s,at(this.book,n.index))),t.setCell(e,s,i,r)}_fillFixedArray(t,e,s,n,i){const r=P(n.ref);if(r===null)return i.data[0];t.spills||(t.spills=new Map),t.spills.set(e*M+s,{...r,blocked:!1,fixed:!0});const a=(l,c)=>{const u=i.rows===1?0:l,d=i.cols===1?0:c;return u>=i.rows||d>=i.cols?k.NA:i.get(u,d)};for(let l=r.r0;l<=r.r1;l++)for(let c=r.c0;c<=r.c1;c++)l===e&&c===s||this._writeArrayCell(t,l,c,a(l-r.r0,c-r.c0));this._dirtyFrom(t,r.c0,r.c1,r.r0,r.r1);const o=a(e-r.r0,s-r.c0);return o===null?0:o}_spill(t,e,s,n,i){const r=e*M+s;t.spills||(t.spills=new Map);const a=t.spills.get(r),o=e+i.rows-1,l=s+i.cols-1,c={r0:e,c0:s,r1:o,c1:l,blocked:!1,fixed:!1},u=(f,h)=>a&&f>=a.r0&&f<=a.r1&&h>=a.c0&&h<=a.c1;let d=o>=J||l>=M;if(!d)t:for(let f=e;f<=o;f++)for(let h=s;h<=l;h++){if(f===e&&h===s)continue;const y=t.kind(f,h);if((y&ot)!==0&&!(y&H&&u(f,h))){d=!0;break t}if(t.merges.length>0&&t.mergeAt(f,h)){d=!0;break t}}if(d)return a&&!a.blocked&&this._clearSpill(t,a,e,s),c.blocked=!0,c.r1=Math.min(o,J-1),c.c1=Math.min(l,M-1),t.spills.set(r,c),k.SPILL;if(a&&!a.blocked){for(let f=a.r0;f<=a.r1;f++)for(let h=a.c0;h<=a.c1;h++)f>=c.r0&&f<=c.r1&&h>=c.c0&&h<=c.c1||(t.kind(f,h)&H)!==0&&t.setCell(f,h,Q,0);this._dirtyFrom(t,a.c0,a.c1,a.r0,a.r1)}t.spills.set(r,c);for(let f=e;f<=o;f++)for(let h=s;h<=l;h++)f===e&&h===s||this._writeArrayCell(t,f,h,i.get(f-e,h-s));n.t="array",n.ref=`${ut(s)}${e+1}:${ut(l)}${o+1}`,n.cm=1,delete n.raw,this._dirtyFrom(t,s,l,e,o);const p=i.data[0];return p===null?0:p}_clearSpill(t,e,s,n){for(let i=e.r0;i<=e.r1;i++)for(let r=e.c0;r<=e.c1;r++)i===s&&r===n||(t.kind(i,r)&H)!==0&&t.setCell(i,r,Q,0);this._dirtyFrom(t,e.c0,e.c1,e.r0,e.r1)}_releaseSpill(t,e,s){const n=e*M+s,i=t.spills.get(n);if(i===void 0)return;i.blocked||this._clearSpill(t,i,e,s),t.spills.delete(n);const r=t.formula(e,s);r&&r.typed&&(delete r.ref,delete r.cm,delete r.t)}spillMaster(t,e,s){if(!t.spills)return null;for(const[n,i]of t.spills)if(!i.blocked&&e>=i.r0&&e<=i.r1&&s>=i.c0&&s<=i.c1){const r=Math.floor(n/M);return{row:r,col:n-r*M,rect:i}}return null}spillRange(t){const{sheet:e,r0:s,c0:n}=t;this.read(e,s,n);const i=e.spills?.get(s*M+n);return!i||i.blocked?k.REF:new q(e,i.r0,i.c0,i.r1,i.c1)}read(t,e,s){const n=t.columns[s];if(n===void 0)return null;const i=n[e>>>E];if(i===void 0)return null;const r=e&T;let a=i.kinds[r];if(a===0)return null;switch(a&w&&(this._calc(t,e,s),a=i.kinds[r]),a&V){case U:return i.values[r];case B:return this.book.strings.get(i.values[r]);case G:return i.values[r]!==0;case N:{if(t.valueMeta!==null&&this.book.richValues){const o=gt(this.book,t,e,s);if(o!==null)return o}return Y[i.values[r]]??k.NA}default:return null}}refToValue(t){return t instanceof $?t.refs.length===1?this.refToValue(t.refs[0]):k.VALUE:t.isCell?this.read(t.sheet,t.r0,t.c0):this.toArr(t)}refAuto(t,e,s){return t instanceof $?t.refs.length===1?this.refAuto(t.refs[0],e,s):k.VALUE:t.isCell?this.read(t.sheet,t.r0,t.c0):this.legacy?this.intersect(t,e,s):this.toArr(t)}intersect(t,e,s){return t.cols===1&&e>=t.r0&&e<=t.r1?this.read(t.sheet,e,t.c0):t.rows===1&&s>=t.c0&&s<=t.c1?this.read(t.sheet,t.r0,s):k.VALUE}trim(t){const{sheet:e}=t;return{r0:t.r0,c0:t.c0,r1:Math.min(t.r1,Math.max(e.maxRow,t.r0)),c1:Math.min(t.c1,Math.max(e.maxCol,t.c0))}}toArr(t){if(t instanceof C)return t;if(t instanceof q){const{r0:e,c0:s,r1:n,c1:i}=this.trim(t),r=n-e+1,a=i-s+1,o=new Array(r*a);let l=0;for(let c=e;c<=n;c++)for(let u=s;u<=i;u++)o[l++]=this.read(t.sheet,c,u);return new C(r,a,o)}if(t instanceof $){if(t.refs.length===1)return this.toArr(t.refs[0]);throw k.VALUE}if(t instanceof x)throw t;return new C(1,1,[t])}scalar(t,e,s){return t instanceof q?t.isCell?this.read(t.sheet,t.r0,t.c0):this.intersect(t,e,s):t instanceof $?k.VALUE:t instanceof C?t.data[0]:t}scan(t,e){const{sheet:s}=t,n=Math.min(t.c1,s.maxCol),i=Math.min(t.r1,s.maxRow);for(let r=t.c0;r<=n;r++){const a=s.columns[r];if(a!==void 0)for(let o=t.r0>>>E;o<=i>>>E;o++){const l=a[o];if(l===void 0)continue;const c=o<<E,u=Math.max(t.r0-c,0),d=Math.min(i-c,T),{kinds:p}=l;for(let f=u;f<=d;f++){if(p[f]===0)continue;const h=this.read(s,c+f,r);h!==null&&e(h,c+f,r)}}}}sumRange(t,e){const{sheet:s}=t,n=Math.min(t.c1,s.maxCol),i=Math.min(t.r1,s.maxRow);let{sum:r,count:a}=e;for(let o=t.c0;o<=n;o++){const l=s.columns[o];if(l!==void 0)for(let c=t.r0>>>E;c<=i>>>E;c++){const u=l[c];if(u===void 0)continue;const d=c<<E,p=Math.max(t.r0-d,0),f=Math.min(i-d,T),{kinds:h,values:y}=u;for(let _=p;_<=f;_++){let g=h[_];if(g===0)continue;g&w&&(this._calc(s,d+_,o),g=h[_]);const b=g&V;if(b===U)r+=y[_],a++;else if(b===N)throw Y[y[_]]}}}e.sum=r,e.count=a}unary(t,e){if(t instanceof x)return t;if(t instanceof C)return new C(t.rows,t.cols,t.data.map(s=>{try{return s instanceof x?s:e(S(s))}catch(n){return n}}));try{return e(S(t))}catch(s){if(s instanceof x)return s;throw s}}slowBin(t,e,s){if(e instanceof C||s instanceof C)return this._binArr(t,e,s);if(e instanceof x)return e;if(s instanceof x)return s;try{return dt(t,e,s)}catch(n){if(n instanceof x)return n;throw n}}_binArr(t,e,s){const n=e instanceof C?e:null,i=s instanceof C?s:null,r=Math.max(n?n.rows:1,i?i.rows:1),a=Math.max(n?n.cols:1,i?i.cols:1),o=new Array(r*a);for(let l=0;l<r;l++)for(let c=0;c<a;c++){const u=nt(e,l,c),d=nt(s,l,c);let p;if(u instanceof x)p=u;else if(d instanceof x)p=d;else try{p=dt(t,u,d)}catch(f){p=f}o[l*a+c]=p}return new C(r,a,o)}liftArr(t,e,s){let n=1,i=1;for(const l of e)l instanceof C&&(l.rows>n&&(n=l.rows),l.cols>i&&(i=l.cols));const r=new Array(n*i),a=e.length,o=new Array(a);for(let l=0;l<n;l++)for(let c=0;c<i;c++){let u=null;for(let d=0;d<a;d++){const p=nt(e[d],l,c);o[d]=p,!s&&u===null&&p instanceof x&&(u=p)}if(u!==null){r[l*i+c]=u;continue}try{r[l*i+c]=t(...o)}catch(d){if(d instanceof x)r[l*i+c]=d;else throw d}}return new C(n,i,r)}invoke(t,e,s,n,i){if(t.native)return this._invokeNative(t.native,e,s,n,i);const r=t.frame?t.frame.slice():[],{params:a}=t;if(e.length>a.length)return k.VALUE;for(let l=0;l<a.length;l++)r[a[l]]=l<e.length?e[l]:void 0;const o=this.frame;if(this.frame=r,this.depth++,this.depth>=ht*4)return this.depth--,this.frame=o,k.NUM;try{return t.body(s,n,i)}finally{this.depth--,this.frame=o}}_invokeNative(t,e,s,n,i){if(e.length<t.min||e.length>t.max)return k.VALUE;try{if(t.kind==="raw")return t.fn(this,e,s,n,i);if(t.kind==="lazy")return t.fn(this,e.map(a=>()=>a),s,n,i);const r=e.map(a=>a instanceof q||a instanceof $?this.refToValue(a):a);if(r.some(a=>a instanceof C))return this.liftArr(t.fn,r,t.errors);if(!t.errors){for(const a of r)if(a instanceof x)return a}return t.fn(...r)}catch(r){if(r instanceof x)return r;throw r}}_nameEntry(t,e){const s=t.toUpperCase();if(e){const i=this.book.sheets.indexOf(e),r=this.names.get(`${i}!${s}`);if(r)return{key:`${i}!${s}`,entry:r}}const n=this.names.get(s);return n?{key:s,entry:n}:null}_nameTemplate(t,e){const s=this._nameEntry(t,e);if(s===null)return null;let n=this.nameTemplates.get(s.key);if(n===void 0){try{n=this._compile(new j(z(s.entry.text),0,0).parse())}catch(i){if(!(i instanceof W))throw i;n=this._broken()}this.nameTemplates.set(s.key,n)}return n}nameMayYieldRange(t){const e=t.toUpperCase(),s=[];for(const[n,i]of this.names)(n===e||n.endsWith(`!${e}`))&&s.push(i);if(s.length===0||(this._rangeNames??=new Set,this._rangeNames.has(e)))return!0;this._rangeNames.add(e);try{return s.some(n=>{try{return new lt(this).mayYieldRange(new j(z(n.text),0,0).parse())}catch(i){if(i instanceof W)return!1;throw i}})}finally{this._rangeNames.delete(e)}}evalName(t,e,s,n){const i=this._nameTemplate(t,n);return i===null?k.NAME:i.fn(e,s,n)}tableSpecToA1(t,e,s){const n=mt(t,e,s);if(!(n instanceof q))return null;const i=/#This Row|^\[\s*@/i.test(e),r=(a,o)=>i?`${ct(o)}${a+1}`:`$${ct(o)}$${a+1}`;return n.isCell?r(n.r0,n.c0):`${r(n.r0,n.c0)}:${r(n.r1,n.c1)}`}resolveTable(t,e,s,n,i){let r=t?this.tables.get(t.toUpperCase()):null;if(!t){for(const a of this.tables.values())if(a.sheet===i&&s>=a.r0&&s<=a.r1&&n>=a.c0&&n<=a.c1){r=a;break}}return r?mt(r,e,s):k.REF}exactIndex(t){const e=`${t.sheet.uid}:${t.r0}:${t.c0}:${t.r1}:${t.c1}`;let s=this.lookupCache.get(e);if(s!==void 0)return s;s=new Map;const n=t.cols===1;return this.scan(t,(i,r,a)=>{const o=typeof i=="string"?`s${i.toLowerCase()}`:typeof i=="number"?i:`b${i}`;if(i instanceof x)return;const l=n?r-t.r0:a-t.c0,c=s.get(o);(c===void 0||l<c)&&s.set(o,l)}),this.lookupCache.set(e,s),s}visibilityChanged(){this._wakeReaders(this.visibilityReaders)}presentationChanged(){this._wakeLater(2)}axisHiddenChanged(){this._wakeLater(1)}axisResized(){this._wakeLater(2)}_wakeLater(t){(t===1?this.visibilityReaders:this.styleReaders).size!==0&&(this.wakePending===0&&queueMicrotask(()=>{const e=this.wakePending;this.wakePending=0,e&1&&this._wakeReaders(this.visibilityReaders),e&2&&this._wakeReaders(this.styleReaders)}),this.wakePending|=t)}_wakeReaders(t){if(!this.graphReady||t.size===0)return;let e=!1;for(const[s,n]of t)n.forEach((i,r)=>{const a=s._chunk(i,r);if(a===void 0)return;const o=i&T,l=a.kinds[o];if(!(l&R)){n.delete(i,r);return}l&w||(a.kinds[o]=l|w,this._enqueue(s,i,r)),this._dirtyFrom(s,r,r,i,i),e=!0});e&&this._schedule()}isSubtotalCell(t,e,s){if((t.kind(e,s)&R)===0)return!1;const n=t.formula(e,s),i=n?.f??n?.sf??"";return/^\s*(_xlfn\.)?(SUBTOTAL|AGGREGATE)\(/i.test(i)}displayFormula(t){return Mt(t)}}function ut(m){let t="";for(let e=m+1;e>0;e=Math.floor((e-1)/26))t=String.fromCharCode(65+(e-1)%26)+t;return t}function nt(m,t,e){if(!(m instanceof C))return m;const s=m.rows===1?0:t,n=m.cols===1?0:e;return s>=m.rows||n>=m.cols?k.NA:m.data[s*m.cols+n]}function dt(m,t,e){if((t instanceof O||e instanceof O)&&m!=="="&&m!=="<>"&&m!=="&")throw k.VALUE;switch(m){case"+":{const s=S(t),n=s+S(e);return Math.abs(n)<Math.abs(s)*pt?0:K(n)}case"-":{const s=S(t),n=s-S(e);return Math.abs(n)<Math.abs(s)*pt?0:K(n)}case"*":return K(S(t)*S(e));case"/":{const s=S(t),n=S(e);if(n===0)throw k.DIV0;return K(s/n)}case"^":{const s=S(t),n=S(e);if(s===0&&n===0)throw k.NUM;if(s===0&&n<0)throw k.DIV0;const i=_t(s,n);if(Number.isNaN(i))throw k.NUM;return K(i)}case"&":return rt(t)+rt(e);case"=":return v(t,e)===0;case"<>":return v(t,e)!==0;case"<":return v(t,e)<0;case">":return v(t,e)>0;case"<=":return v(t,e)<=0;case">=":return v(t,e)>=0;default:throw k.VALUE}}const pt=5e-16;function K(m){if(!Number.isFinite(m))throw k.NUM;return m}function mt(m,t,e){const s=yt(m,t,e);return s==="REF"?k.REF:s==="VALUE"?k.VALUE:new q(m.sheet,s.top,s.left,s.bottom,s.right)}const Lt={COUNTIF:[0],COUNTIFS:["even",0],SUMIF:[0,2],SUMIFS:[0,"odd",1],AVERAGEIF:[0,2],AVERAGEIFS:[0,"odd",1],MAXIFS:[0,"odd",1],MINIFS:[0,"odd",1],COUNTBLANK:[0],RANK:[1],"RANK.EQ":[1],"RANK.AVG":[1]};function St(m,t){for(let e=0;e<m.length;e++){const s=m[e];if(s===t||s==="odd"&&t>=m[e+1]&&t%2===1||s==="even"&&t>=m[e+1]&&t%2===0)return!0}return!1}function it(m){if(!(m===null||typeof m!="object")){if(Array.isArray(m)){for(const t of m)it(t);return}if(m.t==="call"){const t=Lt[String(m.name).replace(/^_xl(?:fn|ws)\./i,"").toUpperCase()];t&&m.args.forEach((e,s)=>{if(e?.t==="array"&&St(t,s))throw new Error(`${m.name} takes a range here`)})}for(const t of Object.values(m))t!==null&&typeof t=="object"&&it(t)}}export{Bt as Engine};
@@ -0,0 +1,2 @@
1
+ import{MAX_COLS as g,MAX_ROWS as m}from"../core/address.js";const d=t=>t>=48&&t<=57,A=t=>t>=65&&t<=90||t>=97&&t<=122,p=new Set([...`+-*/^&=<>%(),;:{}@!
2
+ \r `].map(t=>t.charCodeAt(0)));function w(t,i,n){let r=0;for(let e=i;e<n;e++)r=r*26+((t.charCodeAt(e)&223)-64);return r-1}function a(t,i,n){let r=0;for(let e=i;e<n;e++)r=r*10+t.charCodeAt(e)-48;return r}function C(t,i){let n=i;for(;n<t.length&&d(t.charCodeAt(n));)n++;return n}function R(t,i,n){if(t.charCodeAt(i)===48||n-i>7)return!1;let r=i-1;r>=0&&t.charCodeAt(r)===36&&r--;let e=r+1;for(;e>0&&A(t.charCodeAt(e-1));)e--;const f=r+1-e;if(f<1||f>3||w(t,e,r+1)>=g)return!1;let l=e-1;if(l>=0&&t.charCodeAt(l)===36&&l--,l>=0&&!p.has(t.charCodeAt(l)))return!1;if(n===t.length)return!0;const c=t.charCodeAt(n);return!(A(c)||c===95||c===46||c===92||c>=128||c===40||c===33||c===91)}function O(t,i){const n=t.length,r=i.length;let e=0,f=0,l=!1,c=!1;for(;e<n&&f<r;){const s=t.charCodeAt(e);if(!l&&!c&&d(s)&&!(e>0&&d(t.charCodeAt(e-1)))){const o=C(t,e);if(R(t,e,o)){if(t.charCodeAt(e-1)!==36){const h=C(i,f),u=a(t,e,o)+1;if(h-f!==o-e||u>m||a(i,f,h)!==u)return!1;e=o,f=h;continue}}else if((e>0&&t.charCodeAt(e-1)===36?t.charCodeAt(e-2):t.charCodeAt(e-1))===58||t.charCodeAt(o)===58||t.charCodeAt(o)===36&&t.charCodeAt(o+1)===58)return!1}if(s!==i.charCodeAt(f))return!1;if(s===34&&!c)l=!l;else if(s===39&&!l)c=!c;else if(s===91&&!l&&!c)return!1;e++,f++}return e===n&&f===r}export{O as isRowBelow};
@@ -0,0 +1 @@
1
+ import{setCategory as j}from"./registry.js";import{lift as _,raw as m}from"./registry.js";import{Arr as p,bool as D,compareValues as G,ERR as A,num as E,OMITTED as L,Ref as N,str as K,XlError as M}from"../values.js";j("Lookup & Reference");const C=r=>r===void 0||r===L,R=(r,t,s,c,o)=>C(t)?o:Math.trunc(E(r.scalar(t,s,c))),U=(r,t,s,c,o)=>C(t)?o:D(r.scalar(t,s,c)),O=r=>Array.from({length:r.rows},(t,s)=>r.data.slice(s*r.cols,(s+1)*r.cols)),T=r=>Array.from({length:r.cols},(t,s)=>Array.from({length:r.rows},(c,o)=>r.get(o,s))),g=r=>r===null?0:r;_("SEQUENCE",1,4,(r,t,s,c)=>{const o=Math.trunc(E(r)),n=t===void 0||t===L?1:Math.trunc(E(t)),e=s===void 0||s===L?1:E(s),a=c===void 0||c===L?1:E(c);if(o<0||n<0)throw A.VALUE;if(o===0||n===0)throw A.CALC;if(o*n>1<<27)throw A.NUM;const f=new Array(o*n);for(let l=0;l<f.length;l++)f[l]=e+l*a;return new p(o,n,f)}),_("RANDARRAY",0,5,(r,t,s,c,o)=>{const n=r===void 0||r===L?1:Math.trunc(E(r)),e=t===void 0||t===L?1:Math.trunc(E(t)),a=s===void 0||s===L?0:E(s),f=c===void 0||c===L?1:E(c),l=o===void 0||o===L?!1:D(o);if(n<0||e<0||a>f)throw A.VALUE;if(n===0||e===0)throw A.CALC;const i=new Array(n*e);for(let d=0;d<i.length;d++)i[d]=l?Math.ceil(a)+Math.floor(Math.random()*(Math.floor(f)-Math.ceil(a)+1)):a+Math.random()*(f-a);return new p(n,e,i)},{volatile:!0}),m("FILTER",2,3,(r,t,s,c)=>{const o=r.toArr(t[0]),n=r.toArr(t[1]),e=n.cols===1&&n.rows===o.rows,a=n.rows===1&&n.cols===o.cols;if(!e&&!a)throw A.VALUE;const f=n.data.map(u=>{if(u instanceof M)throw u;return u===null?!1:D(u)}),l=e?O(o).filter((u,h)=>f[h]):null,i=e?null:T(o).filter((u,h)=>f[h]);if(e?l.length===0:i.length===0){if(C(t[2]))throw A.CALC;return t[2]}if(e)return p.of2D(l.map(u=>u.map(g)));const w=new p(o.rows,i.length,new Array(o.rows*i.length));return i.forEach((u,h)=>u.forEach((y,V)=>{w.data[V*i.length+h]=g(y)})),w},{array:!0,passes:r=>r===2});function b(r,t){const s=r[0].length,c=Array.from({length:s},(o,n)=>n);return c.sort((o,n)=>{for(let e=0;e<r.length;e++){const a=r[e][o],f=r[e][n],l=a==null||a instanceof M,i=f==null||f instanceof M;if(l||i){if(l&&i)continue;return l?1:-1}const d=G(a,f);if(d!==0)return d*t[e]}return o-n}),c}m("SORT",1,4,(r,t,s,c)=>{const o=r.toArr(t[0]),n=U(r,t[3],s,c,!1),e=C(t[1])?[1]:r.toArr(t[1]).data.map(h=>Math.trunc(E(h))),a=C(t[2])?e.map(()=>1):r.toArr(t[2]).data.map(h=>E(h));if(a.length!==e.length||a.some(h=>h!==1&&h!==-1))throw A.VALUE;const f=n?T(o):O(o),l=n?o.rows:o.cols;for(const h of e)if(h<1||h>l)throw A.VALUE;const i=e.map(h=>f.map(y=>y[h-1])),w=b(i,a).map(h=>f[h]);if(!n)return p.of2D(w.map(h=>h.map(g)));const u=new Array(o.rows*o.cols);return w.forEach((h,y)=>h.forEach((V,W)=>{u[W*o.cols+y]=g(V)})),new p(o.rows,o.cols,u)},{array:!0}),m("SORTBY",2,255,(r,t,s,c)=>{const o=r.toArr(t[0]),n=[],e=[];let a=1;for(;a<t.length;){const w=r.toArr(t[a]),u=a+1<t.length&&!C(t[a+1])&&!(t[a+1]instanceof N)&&!(t[a+1]instanceof p);let h=1,y=1;if(u?(h=E(r.scalar(t[a+1],s,c)),y=2):a+1<t.length&&C(t[a+1])&&(y=2),h!==1&&h!==-1)throw A.VALUE;n.push(w),e.push(h),a+=y}const f=n[0].cols===1;for(const w of n)if(f?w.rows!==o.rows||w.cols!==1:w.cols!==o.cols||w.rows!==1)throw A.VALUE;const l=b(n.map(w=>w.data),e);if(f){const w=O(o);return p.of2D(l.map(u=>w[u].map(g)))}const i=T(o),d=new Array(o.rows*o.cols);return l.forEach((w,u)=>i[w].forEach((h,y)=>{d[y*o.cols+u]=g(h)})),new p(o.rows,o.cols,d)},{array:!0});const k=r=>r.map(t=>t===null?"\0":typeof t=="string"?`s${t.toLowerCase()}`:t instanceof M?`e${t.code}`:`${typeof t}${t}`).join("");m("UNIQUE",1,3,(r,t,s,c)=>{const o=r.toArr(t[0]),n=U(r,t[1],s,c,!1),e=U(r,t[2],s,c,!1),a=n?T(o):O(o),f=new Map;for(const w of a){const u=k(w);f.set(u,(f.get(u)??0)+1)}const l=new Set,i=[];for(const w of a){const u=k(w);(e?f.get(u)!==1:l.has(u))||(l.add(u),i.push(w))}if(i.length===0)throw A.CALC;if(!n)return p.of2D(i.map(w=>w.map(g)));const d=new Array(o.rows*i.length);return i.forEach((w,u)=>w.forEach((h,y)=>{d[y*i.length+u]=g(h)})),new p(o.rows,i.length,d)},{array:!0}),m("TRANSPOSE",1,1,(r,t)=>{const s=r.toArr(t[0]),c=new Array(s.data.length);for(let o=0;o<s.rows;o++)for(let n=0;n<s.cols;n++)c[n*s.rows+o]=g(s.get(o,n));return new p(s.cols,s.rows,c)},{array:!0});function I(r,t,s){const c=t.map(f=>r.toArr(f));if(!s){const f=Math.max(...c.map(i=>i.cols)),l=[];for(const i of c)for(let d=0;d<i.rows;d++){const w=new Array(f);for(let u=0;u<f;u++)w[u]=u<i.cols?g(i.get(d,u)):A.NA;l.push(w)}return p.of2D(l)}const o=Math.max(...c.map(f=>f.rows)),n=c.reduce((f,l)=>f+l.cols,0),e=new Array(o*n);let a=0;for(const f of c){for(let l=0;l<f.cols;l++)for(let i=0;i<o;i++)e[i*n+a+l]=i<f.rows?g(f.get(i,l)):A.NA;a+=f.cols}return new p(o,n,e)}m("VSTACK",1,254,(r,t)=>I(r,t,!1),{array:!0}),m("HSTACK",1,254,(r,t)=>I(r,t,!0),{array:!0});function H(r,t,s,c,o){const n=s-t+1,e=o-c+1,a=new Array(n*e);for(let f=0;f<n;f++)for(let l=0;l<e;l++)a[f*e+l]=g(r.get(t+f,c+l));return new p(n,e,a)}m("TAKE",2,3,(r,t,s,c)=>{const o=r.toArr(t[0]),n=R(r,t[1],s,c,o.rows),e=R(r,t[2],s,c,o.cols);if(n===0||e===0)throw A.CALC;const a=Math.min(Math.abs(n),o.rows),f=Math.min(Math.abs(e),o.cols),l=n<0?o.rows-a:0,i=e<0?o.cols-f:0;return H(o,l,l+a-1,i,i+f-1)},{array:!0}),m("DROP",2,3,(r,t,s,c)=>{const o=r.toArr(t[0]),n=R(r,t[1],s,c,0),e=R(r,t[2],s,c,0),a=o.rows-Math.abs(n),f=o.cols-Math.abs(e);if(a<=0||f<=0)throw A.CALC;const l=n>0?n:0,i=e>0?e:0;return H(o,l,l+a-1,i,i+f-1)},{array:!0}),m("EXPAND",2,4,(r,t,s,c)=>{const o=r.toArr(t[0]),n=R(r,t[1],s,c,o.rows),e=R(r,t[2],s,c,o.cols),a=C(t[3])?A.NA:r.scalar(t[3],s,c);if(n<o.rows||e<o.cols)throw A.VALUE;const f=new Array(n*e);for(let l=0;l<n;l++)for(let i=0;i<e;i++)f[l*e+i]=l<o.rows&&i<o.cols?g(o.get(l,i)):a;return new p(n,e,f)},{array:!0});function F(r,t,s,c,o){const n=r.toArr(t[0]),e=o?O(n):T(n),a=[];for(let l=1;l<t.length;l++)for(const i of r.toArr(t[l]).data){const d=Math.trunc(E(i)),w=d<0?e.length+d:d-1;if(d===0||w<0||w>=e.length)throw A.VALUE;a.push(e[w])}if(o)return p.of2D(a.map(l=>l.map(g)));const f=new Array(n.rows*a.length);return a.forEach((l,i)=>l.forEach((d,w)=>{f[w*a.length+i]=g(d)})),new p(n.rows,a.length,f)}m("CHOOSEROWS",2,255,(r,t,s,c)=>F(r,t,s,c,!0),{array:!0}),m("CHOOSECOLS",2,255,(r,t,s,c)=>F(r,t,s,c,!1),{array:!0});function P(r,t,s,c){const o=r.toArr(t[0]),n=R(r,t[1],s,c,0),e=U(r,t[2],s,c,!1);if(n<0||n>3)throw A.VALUE;const a=[],f=l=>{(n===1||n===3)&&l===null||(n===2||n===3)&&l instanceof M||a.push(g(l))};if(e)for(let l=0;l<o.cols;l++)for(let i=0;i<o.rows;i++)f(o.get(i,l));else for(const l of o.data)f(l);if(a.length===0)throw A.CALC;return a}m("TOCOL",1,3,(r,t,s,c)=>p.column(P(r,t,s,c)),{array:!0}),m("TOROW",1,3,(r,t,s,c)=>p.row(P(r,t,s,c)),{array:!0});function $(r,t,s,c,o){const n=r.toArr(t[0]);if(n.rows>1&&n.cols>1)throw A.VALUE;const e=R(r,t[1],s,c,0);if(e<1)throw A.NUM;const a=C(t[2])?A.NA:r.scalar(t[2],s,c),f=n.data.length,l=Math.ceil(f/e),i=o?l:e,d=o?e:l,w=new Array(i*d);for(let u=0;u<i*d;u++){const h=u<f?g(n.data[u]):a;o?w[u]=h:w[u%e*d+Math.floor(u/e)]=h}return new p(i,d,w)}m("WRAPROWS",2,3,(r,t,s,c)=>$(r,t,s,c,!0),{array:!0}),m("WRAPCOLS",2,3,(r,t,s,c)=>$(r,t,s,c,!1),{array:!0});function S(r,t,s,c){if(!(t instanceof N))return t;const o=r.trim(t);let{r0:n,c0:e}=t,a=s&2?o.r1:t.r1,f=c&2?o.c1:t.c1;s&2&&o.r1<n&&(a=n),c&2&&o.c1<e&&(f=e);const l=(u,h)=>t.sheet.kind(u,h)!==0,i=u=>{for(let h=e;h<=f;h++)if(l(u,h))return!0;return!1},d=u=>{for(let h=n;h<=a;h++)if(l(h,u))return!0;return!1};if(s&1)for(;n<a&&!i(n);)n++;if(s&2)for(;a>n&&!i(a);)a--;if(c&1)for(;e<f&&!d(e);)e++;if(c&2)for(;f>e&&!d(f);)f--;if(s?n===a&&!i(n):c?e===f&&!d(e):!1)throw A.REF;return new N(t.sheet,n,e,a,f)}m("TRIMRANGE",1,3,(r,t,s,c)=>{const o=n=>{const e=t[n]===void 0||t[n]===null?3:R(r,t[n],s,c,3);if(e<0||e>3)throw A.VALUE;return e};return S(r,t[0],o(1),o(2))},{refResult:!0}),m("_TRO_ALL",1,1,(r,t)=>S(r,t[0],3,3),{refResult:!0,category:"Hidden"}),m("_TRO_LEADING",1,1,(r,t)=>S(r,t[0],1,1),{refResult:!0,category:"Hidden"}),m("_TRO_TRAILING",1,1,(r,t)=>S(r,t[0],2,2),{refResult:!0,category:"Hidden"}),m("ARRAYTOTEXT",1,2,(r,t,s,c)=>{const o=r.toArr(t[0]),n=R(r,t[1],s,c,0)===1,e=a=>a===null?"":typeof a=="string"?n?`"${a.replace(/"/g,'""')}"`:a:a instanceof M?a.code:K(a);return n?`{${O(o).map(a=>a.map(e).join(",")).join(";")}}`:o.data.map(e).join(", ")},{array:!0}),m("PERCENTOF",2,2,(r,t)=>{const s=o=>{let n=0;for(const e of r.toArr(o).data){if(e instanceof M)throw e;typeof e=="number"&&(n+=e)}return n},c=s(t[1]);if(c===0)throw A.DIV0;return s(t[0])/c},{array:!0}),m("SINGLE",1,1,(r,t,s,c)=>{const o=r.scalar(t[0],s,c);return o===null?0:o}),m("ANCHORARRAY",1,1,(r,t)=>t[0]instanceof N?r.spillRange(t[0]):A.REF,{refResult:!0});
@@ -0,0 +1 @@
1
+ import{setCategory as R}from"./registry.js";import{raw as g}from"./registry.js";import{checked as L,ERR as d,OMITTED as A,Ref as b,RefList as N,textToNumber as k,XlError as V}from"../values.js";import{makeCriteria as O,scalarOf as I}from"./helpers.js";R("Database");function y(e){if(e instanceof V)throw e;const t=e instanceof N&&e.refs.length===1?e.refs[0]:e;if(!(t instanceof b))throw d.VALUE;return t}function C(e){return e===null||e instanceof V?"":(typeof e=="string"?e:String(e)).toLowerCase()}function S(e,t){const r=new Map,{c1:s}=e.trim(t);for(let o=t.c0;o<=s;o++){const n=C(e.read(t.sheet,t.r0,o));n!==""&&!r.has(n)&&r.set(n,o)}return r}function P(e,t,r,s,o,n,i){if(s===A||s===void 0){if(i)return null;throw d.VALUE}const c=I(e,s,o,n);if(typeof c=="number"){const f=Math.trunc(c);if(f<1||f>t.cols)throw d.VALUE;return t.c0+f-1}const h=typeof c=="string"?r.get(c.toLowerCase()):void 0;if(h===void 0)throw d.VALUE;return h}function q(e){const t=typeof e=="string"&&!/^[<>=]/.test(e)&&k(e)===null&&!/^(true|false)$/i.test(e);return O(t?`${e}*`:e)}function G(e,t,r){const{sheet:s,r0:o,c0:n}=t,i=e.trim(t),c=[];for(let f=n;f<=i.c1;f++){const u=C(e.read(s,o,f));u!==""&&c.push([f,r.get(u)])}if(t.r1>i.r1)return null;const h=[];for(let f=o+1;f<=i.r1;f++){const u=[];let m=!0;for(const[E,D]of c){const l=e.read(s,f,E);if(l!==null){if(D===void 0){m=!1;break}u.push([D,q(l)])}}if(m){if(u.length===0)return null;h.push(u)}}return h}function w(e,t,r,s,o,n){const i=y(t[0]),c=y(t[2]),h=S(e,i),f=P(e,i,h,t[1],r,s,o),u=G(e,c,h),{sheet:m}=i,E=e.trim(i).r1,D=l=>u===null||u.some(T=>T.every(([U,M])=>M(e.read(m,l,U))));for(let l=i.r0+1;l<=E;l++)D(l)&&n(f===null?null:e.read(m,l,f))}function X(e,t,r,s){const o=[];return w(e,t,r,s,!1,n=>{if(n instanceof V)throw n;typeof n=="number"&&o.push(n)}),o}const a=(e,t)=>g(e,3,3,(r,s,o,n)=>L(t(X(r,s,o,n))));function p(e,t){const r=e.length;if(r<(t?1:2))throw d.DIV0;const s=e.reduce((o,n)=>o+n,0)/r;return e.reduce((o,n)=>o+(n-s)**2,0)/(t?r:r-1)}a("DAVERAGE",e=>{if(e.length===0)throw d.DIV0;return e.reduce((t,r)=>t+r,0)/e.length}),a("DMAX",e=>e.length===0?0:e.reduce((t,r)=>r>t?r:t)),a("DMIN",e=>e.length===0?0:e.reduce((t,r)=>r<t?r:t)),a("DPRODUCT",e=>e.length===0?0:e.reduce((t,r)=>t*r,1)),a("DSTDEV",e=>Math.sqrt(p(e,!1))),a("DSTDEVP",e=>Math.sqrt(p(e,!0))),a("DSUM",e=>e.reduce((t,r)=>t+r,0)),a("DVAR",e=>p(e,!1)),a("DVARP",e=>p(e,!0)),g("DCOUNT",3,3,(e,t,r,s)=>{const o=t[1]===A;let n=0;return w(e,t,r,s,!0,i=>{(o||typeof i=="number")&&n++}),n}),g("DCOUNTA",3,3,(e,t,r,s)=>{const o=t[1]===A;let n=0;return w(e,t,r,s,!0,i=>{(o||i!==null)&&n++}),n}),g("DGET",3,3,(e,t,r,s)=>{let o=0,n=null;if(w(e,t,r,s,!1,i=>{o++,n=i}),o===0)throw d.VALUE;if(o>1)throw d.NUM;return n===null?0:n});
@@ -0,0 +1 @@
1
+ import{setCategory as g}from"./registry.js";import{alias as k,lift as i,raw as p}from"./registry.js";import{Arr as I,ERR as f,num as u,OMITTED as C,Ref as K,RefList as F,str as H,XlError as O}from"../values.js";import{partsToSerial as M,serialToParts as h}from"../../core/numfmt.js";import{eachValue as j}from"./helpers.js";import{parseInput as $}from"../../core/input.js";import{NUM as z}from"../../core/sheet.js";import{days360 as B,yearFrac as X}from"./financial.js";g("Date & Time");const y=t=>t===void 0||t===C,D=2958465;function c(t){const e=Math.floor(u(t));if(e<0||e>D)throw f.NUM;return e}function Z(t,e,n){let r=t;if(r>=0&&r<1900&&(r+=1900),r<0||r>9999)throw f.NUM;const o=r*12+(e-1),s=Math.floor(o/12),a=o-s*12+1,l=M(s,a,1)+n-1;if(l<0||l>D)throw f.NUM;return l}i("DATE",3,3,(t,e,n)=>Z(Math.trunc(u(t)),Math.trunc(u(e)),Math.trunc(u(n)))),i("YEAR",1,1,t=>h(c(t)).year),i("MONTH",1,1,t=>h(c(t)).month),i("DAY",1,1,t=>h(c(t)).day);const T=t=>{const e=u(t);if(e<0)throw f.NUM;return Math.round((e-Math.floor(e))*86400)};i("HOUR",1,1,t=>Math.floor(T(t)/3600)%24),i("MINUTE",1,1,t=>Math.floor(T(t)%3600/60)),i("SECOND",1,1,t=>T(t)%60),i("TIME",3,3,(t,e,n)=>{const r=Math.trunc(u(t))*3600+Math.trunc(u(e))*60+Math.trunc(u(n));if(r<0)throw f.NUM;return r%86400/86400});const b=()=>{const t=new Date;return{whole:M(t.getFullYear(),t.getMonth()+1,t.getDate()),frac:(t.getHours()*3600+t.getMinutes()*60+t.getSeconds()+t.getMilliseconds()/1e3)/86400}};i("NOW",0,0,()=>{const t=b();return t.whole+t.frac},{volatile:!0}),i("TODAY",0,0,()=>b().whole,{volatile:!0});const R={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12};function L(t){const e=t.trim(),n=$(e);if(n.kind===z&&n.format&&/[ymd]/i.test(n.format))return n.value;let r=/^(\d{1,2})[-\s]([A-Za-z]{3,})[-\s,]*(\d{2,4})?$/.exec(e);if(r){const o=R[r[2].slice(0,3).toLowerCase()];if(o){const s=r[3]?Number(r[3])<100?2e3+Number(r[3]):Number(r[3]):new Date().getFullYear();return M(s,o,Number(r[1]))}}if(r=/^([A-Za-z]{3,})\s+(\d{1,2})(?:,?\s*(\d{2,4}))?$/.exec(e),r){const o=R[r[1].slice(0,3).toLowerCase()];if(o){const s=r[3]?Number(r[3])<100?2e3+Number(r[3]):Number(r[3]):new Date().getFullYear();return M(s,o,Number(r[2]))}}return null}i("DATEVALUE",1,1,t=>{if(typeof t!="string")throw f.VALUE;const e=t.split(/\s+\d{1,2}:\d{2}/)[0],n=L(e);if(n===null)throw f.VALUE;return Math.floor(n)}),i("TIMEVALUE",1,1,t=>{if(typeof t!="string")throw f.VALUE;const e=/(\d{1,2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?\s*(am|pm|a|p)?/i.exec(t);if(!e)throw f.VALUE;let n=Number(e[1]);if(e[4]){const r=e[4][0].toLowerCase()==="p";if(n>12)throw f.VALUE;n=n%12+(r?12:0)}return(n*3600+Number(e[2])*60+Number(e[3]??0))/86400%1}),i("DAYS",2,2,(t,e)=>c(t)-c(e)),i("DAYS360",2,3,(t,e,n)=>B(c(t),c(e),y(n)?!1:!!u(n)));function q(t,e){const n=h(t),r=n.year*12+(n.month-1)+e,o=Math.floor(r/12),s=r-o*12+1;if(o<1900||o>9999)throw f.NUM;const a=E(o,s);return M(o,s,Math.min(n.day,a))}function E(t,e){return e===2?t===1900||t%4===0&&(t%100!==0||t%400===0)?29:28:[31,28,31,30,31,30,31,31,30,31,30,31][e-1]}i("EDATE",2,2,(t,e)=>q(c(t),Math.trunc(u(e)))),i("EOMONTH",2,2,(t,e)=>{const n=h(c(t)),r=n.year*12+(n.month-1)+Math.trunc(u(e)),o=Math.floor(r/12),s=r-o*12+1;if(o<1900||o>9999)throw f.NUM;return M(o,s,E(o,s))}),i("WEEKDAY",1,2,(t,e)=>{const n=c(t),r=y(e)?1:Math.trunc(u(e)),o=h(n).weekday,s={1:0,2:1,3:1,11:1,12:2,13:3,14:4,15:5,16:6,17:0}[r];if(s===void 0)throw f.NUM;const a=(o-s+7)%7;return r===3?a:a+1}),i("ISOWEEKNUM",1,1,t=>S(c(t)));function S(t){const e=(h(t).weekday+6)%7,n=t-e+3,r=h(n).year;return Math.floor((n-M(r,1,1))/7)+1}i("WEEKNUM",1,2,(t,e)=>{const n=c(t),r=y(e)?1:Math.trunc(u(e));if(r===21)return S(n);const o={1:0,2:1,11:1,12:2,13:3,14:4,15:5,16:6,17:0}[r];if(o===void 0)throw f.NUM;const s=M(h(n).year,1,1),a=(h(s).weekday-o+7)%7;return Math.floor((n-s+a)/7)+1});function A(t){if(y(t)||t===null)return[!1,!1,!1,!1,!1,!0,!0];if(typeof t=="string"){if(!/^[01]{7}$/.test(t))throw f.VALUE;return[...t].map(r=>r==="1")}const e=Math.trunc(u(t)),n=new Array(7).fill(!1);if(e>=1&&e<=7)n[(e+4)%7]=!0,n[(e+5)%7]=!0;else if(e>=11&&e<=17)n[e-11]=!0;else throw f.NUM;return n}function U(t,e){const n=new Set;return y(e)||e===null||j(t,e,r=>{if(r instanceof O)throw r;if(typeof r=="number")n.add(Math.floor(r));else if(typeof r=="string"){const o=L(r);if(o===null)throw f.VALUE;n.add(Math.floor(o))}}),n}const Y=(t,e)=>e[(h(t).weekday+6)%7];function V(t,e,n,r){const o=e>=t?1:-1,s=Math.min(t,e),a=Math.max(t,e),l=n.filter(d=>!d).length,w=a-s+1;let m=Math.floor(w/7)*l;for(let d=s+Math.floor(w/7)*7;d<=a;d++)Y(d,n)||m++;for(const d of r)d>=s&&d<=a&&!Y(d,n)&&m--;return m*o}const N=(t,e,n,r)=>{const o=t.scalar(e,n,r);if(o instanceof O)throw o;if(typeof o=="string"){const s=L(o);if(s===null)throw f.VALUE;return Math.floor(s)}return c(o)};p("NETWORKDAYS",2,3,(t,e,n,r)=>V(N(t,e[0],n,r),N(t,e[1],n,r),A(void 0),U(t,e[2]))),p("NETWORKDAYS.INTL",2,4,(t,e,n,r)=>V(N(t,e[0],n,r),N(t,e[1],n,r),A(y(e[2])?void 0:t.scalar(e[2],n,r)),U(t,e[3])));function W(t,e,n,r){const o=Math.trunc(e),s=o<0?-1:1;let a=Math.abs(o),l=t;if(n.every(Boolean))throw f.VALUE;for(;a>0;){if(l+=s,l<0||l>D)throw f.NUM;!Y(l,n)&&!r.has(l)&&a--}return l}p("WORKDAY",2,3,(t,e,n,r)=>W(N(t,e[0],n,r),u(t.scalar(e[1],n,r)),A(void 0),U(t,e[2]))),p("WORKDAY.INTL",2,4,(t,e,n,r)=>W(N(t,e[0],n,r),u(t.scalar(e[1],n,r)),A(y(e[2])?void 0:t.scalar(e[2],n,r)),U(t,e[3]))),i("YEARFRAC",2,3,(t,e,n)=>{const r=y(n)?0:Math.trunc(u(n));if(r<0||r>4)throw f.NUM;return X(c(t),c(e),r)}),i("DATEDIF",3,3,(t,e,n)=>{const r=c(t),o=c(e);if(r>o)throw f.NUM;const s=h(r),a=h(o),l=H(n).toUpperCase();let w=(a.year-s.year)*12+a.month-s.month;switch(a.day<s.day&&w--,l){case"D":return o-r;case"M":return w;case"Y":return Math.floor(w/12);case"YM":return w%12;case"YD":{let m=a.year;return(a.month<s.month||a.month===s.month&&a.day<s.day)&&m--,o-M(m,s.month,Math.min(s.day,E(m,s.month)))}case"MD":{if(a.day>=s.day)return a.day-s.day;const m=a.month===1?12:a.month-1,d=a.month===1?a.year-1:a.year;return E(d,m)-s.day+a.day}default:throw f.NUM}});export{I as Arr,K as Ref,F as RefList,k as alias};
@@ -0,0 +1 @@
1
+ import{setCategory as Nt}from"./registry.js";import{lift as f,raw as gt}from"./registry.js";import{checked as T,ERR as u,num as dt,numberToText as wt,OMITTED as P,opt as O,str as R,XlError as yt}from"../values.js";import{eachValue as Tt}from"./helpers.js";Nt("Engineering");const M=t=>{if(typeof t=="boolean")throw u.VALUE;return dt(t)},B=t=>Number(t.toPrecision(15)),$={2:10,8:30,16:40},Rt={2:/^[01]*$/,8:/^[0-7]*$/,16:/^[0-9a-fA-F]*$/};function St(t,e){if(typeof t=="boolean")throw u.VALUE;const n=R(t);if(n.length>10||!Rt[e].test(n))throw u.NUM;if(n==="")return 0;const o=parseInt(n,e);return o>=2**($[e]-1)?o-2**$[e]:o}function Lt(t,e,n){const o=n===void 0||n===P?null:Math.trunc(M(n)),r=$[e];if(t<-(2**(r-1))||t>=2**(r-1))throw u.NUM;if(t<0)return(t+2**r).toString(e).toUpperCase();const s=t.toString(e).toUpperCase();if(o===null)return s;if(o<1||o>10||s.length>o)throw u.NUM;return s.padStart(o,"0")}const Q=[["BIN",2],["OCT",8],["DEC",10],["HEX",16]];for(const[t,e]of Q){const n=e===10?o=>Math.trunc(M(o)):o=>St(o,e);for(const[o,r]of Q)t!==o&&(r===10?f(`${t}2DEC`,1,1,n):f(`${t}2${o}`,1,2,(s,c)=>Lt(n(s),r,c)))}const v=2**48-1,q=t=>{const e=M(t);if(!Number.isInteger(e)||e<0||e>v)throw u.NUM;return e},z=(t,e)=>f(t,2,2,(n,o)=>{const r=q(n),s=q(o);return Number(e(BigInt(r),BigInt(s)))});z("BITAND",(t,e)=>t&e),z("BITOR",(t,e)=>t|e),z("BITXOR",(t,e)=>t^e);function x(t,e,n){const o=q(t),r=M(e);if(!Number.isInteger(r)||Math.abs(r)>53)throw u.NUM;const s=r*n;if(s<=0)return Math.floor(o/2**-s);const c=o*2**s;if(c>v)throw u.NUM;return c}f("BITLSHIFT",2,2,(t,e)=>x(t,e,1)),f("BITRSHIFT",2,2,(t,e)=>x(t,e,-1)),f("DELTA",1,2,(t,e)=>M(t)===M(O(e,0))?1:0),f("GESTEP",1,2,(t,e)=>M(t)>=M(O(e,0))?1:0);function tt(t){let e=t;for(let n=200;n>=1;n--)e=t+n/2/e;return Math.exp(-t*t)/(Math.sqrt(Math.PI)*e)}function S(t){const e=Math.abs(t);if(e>=6)return Math.sign(t);if(e>=2.5)return Math.sign(t)*(1-tt(e));let n=e,o=e;for(let r=1;n>o*1e-17;r++)n*=2*e*e/(2*r+1),o+=n;return Math.sign(t)*2*Math.exp(-e*e)*o/Math.sqrt(Math.PI)}function _(t){return t<0?2-_(-t):t<1?1-S(t):t>=27?0:tt(t)}f("ERF",1,2,(t,e)=>{const n=S(M(t));return e===void 0||e===P?n:S(M(e))-n}),f("ERF.PRECISE",1,1,t=>S(M(t))),f("ERFC",1,1,t=>_(M(t))),f("ERFC.PRECISE",1,1,t=>_(M(t)));const Ut=40,et=1e10,N=1e-10,nt=2**27,Ct=709.7,At=22250738585072014e-324,k=t=>Math.abs(t)<At?0:t;function F(t){const e=Math.abs(t);if(e<3.75){const o=t/3.75,r=o*o;return 1+r*(3.5156229+r*(3.0899424+r*(1.2067492+r*(.2659732+r*(.0360768+r*.0045813)))))}const n=3.75/e;return Math.exp(e)/Math.sqrt(e)*(.39894228+n*(.01328592+n*(.00225319+n*(-.00157565+n*(.00916281+n*(-.02057706+n*(.02635537+n*(-.01647633+n*.00392377))))))))}function ot(t){const e=Math.abs(t);let n;if(e<3.75){const o=t/3.75,r=o*o;n=e*(.5+r*(.87890594+r*(.51498869+r*(.15084934+r*(.02658733+r*(.00301532+r*32411e-8))))))}else{const o=3.75/e,r=.02282967+o*(-.02895312+o*(.01787654-o*.00420059));n=.39894228+o*(-.03988024+o*(-.00362018+o*(.00163801+o*(-.01031555+o*r)))),n*=Math.exp(e)/Math.sqrt(e)}return t<0?-n:n}function rt(t){if(t<=2){const n=t*t/4;return-Math.log(t/2)*F(t)+(-.57721566+n*(.4227842+n*(.23069756+n*(.0348859+n*(.00262698+n*(1075e-7+n*74e-7))))))}const e=2/t;return k(Math.exp(-t)/Math.sqrt(t))*(1.25331414+e*(-.07832358+e*(.02189568+e*(-.01062446+e*(.00587872+e*(-.0025154+e*53208e-8))))))}function st(t){if(t<=2){const n=t*t/4;return Math.log(t/2)*ot(t)+1/t*(1+n*(.15443144+n*(-.67278579+n*(-.18156897+n*(-.01919402+n*(-.00110404+n*-4686e-8))))))}const e=2/t;return k(Math.exp(-t)/Math.sqrt(t))*(1.25331414+e*(.23498619+e*(-.0365562+e*(.01504268+e*(-.00780353+e*(.00325614+e*-68245e-8))))))}function H(t){const e=Math.abs(t);if(e<8){const i=t*t;return(57568490574+i*(-13362590354+i*(6516196407e-1+i*(-1121442418e-2+i*(77392.33017+i*-184.9052456)))))/(57568490411+i*(1029532985+i*(9494680718e-3+i*(59272.64853+i*(267.8532712+i*1)))))}const n=8/e,o=n*n,r=e-.785398164,s=1+o*(-.001098628267+o*(2734510407e-14+o*(-2073370639e-15+o*2093887211e-16))),c=-.01562499995+o*(.0001430488765+o*(-6911147651e-15+o*(7621095161e-16-o*934935152e-16)));return Math.sqrt(.636619772/e)*(Math.cos(r)*s-n*Math.sin(r)*c)}function G(t){const e=Math.abs(t);if(e<8){const a=t*t;return t*(72362614232+a*(-7895059235+a*(2423968531e-1+a*(-2972611439e-3+a*(15704.4826+a*-30.16036606)))))/(144725228442+a*(2300535178+a*(1858330474e-2+a*(99447.43394+a*(376.9991397+a*1)))))}const n=8/e,o=n*n,r=e-2.356194491,s=1+o*(.00183105+o*(-3516396496e-14+o*(-3516396496e-14+o*(2457520174e-15+o*-240337019e-15)))),c=.04687499995+o*(-.0002002690873+o*(8449199096e-15+o*(-88228987e-14+o*105787412e-15))),i=Math.sqrt(.636619772/e)*(Math.cos(r)*s-n*Math.sin(r)*c);return t<0?-i:i}function ct(t){if(t<8){const c=t*t;return(-2957821389+c*(7062834065+c*(-5123598036e-1+c*(1087988129e-2+c*(-86327.92757+c*228.4622733)))))/(40076544269+c*(7452499648e-1+c*(7189466438e-3+c*(47447.2647+c*(226.1030244+c*1)))))+.636619772*H(t)*Math.log(t)}const e=8/t,n=e*e,o=t-.785398164,r=1+n*(-.001098628627+n*(2734510407e-14+n*(-2073370639e-15+n*2093887211e-16))),s=-.01562499995+n*(.0001430488765+n*(-6911147651e-15+n*(7621095161e-16+n*-934945152e-16)));return Math.sqrt(.636619772/t)*(Math.sin(o)*r+e*Math.cos(o)*s)}function it(t){if(t<8){const c=t*t;return t*(-4900604943e3+c*(127527439e4+c*(-51534381390+c*(7349264551e-1+c*(-4237922726e-3+c*8511.937935)))))/(249958057e5+c*(424441966400+c*(3733650367+c*(2245904002e-2+c*(102042.605+c*(354.9632885+c))))))+.636619772*(G(t)*Math.log(t)-1/t)}const e=8/t,n=e*e,o=t-2.356194491,r=1+n*(.00183105+n*(-3516396496e-14+n*(2457520174e-15+n*-240337019e-15))),s=.04687499995+n*(-.0002002690873+n*(8449199096e-15+n*(-88228987e-14+n*105787412e-15)));return Math.sqrt(.636619772/t)*(Math.sin(o)*r+e*Math.cos(o)*s)}const at=t=>t+Math.trunc(Math.sqrt(Ut*t)),ut=(t,e)=>e>1e6&&2*t<e;function bt(t,e){if(Math.abs(t)>Ct)throw u.NUM;if(e===0)return F(t);if(e===1)return ot(t);if(t===0||ut(Math.abs(t),e))return 0;const n=2/Math.abs(t);let o=0,r=1,s=0;for(let c=2*at(e);c>0;c--){const i=o+c*n*r;o=r,r=i,Math.abs(r)>et&&(s*=N,r*=N,o*=N),c===e&&(s=o)}return s*=F(t)/r,t<0&&e%2===1?-s:s}function Pt(t,e){if(Math.abs(t)>=nt)throw u.NUM;if(e===0)return H(t);if(e===1)return G(t);const n=Math.abs(t);if(n===0||ut(n,e))return 0;const o=2/n;let r;if(n>e){let s=H(n),c=G(n);for(let i=1;i<e;i++){const a=i*o*c-s;s=c,c=a}r=c}else{let s=!1,c=0,i=0,a=1;r=0;for(let g=2*Math.trunc(at(e)/2);g>0;g--){const b=g*o*a-i;i=a,a=b,Math.abs(a)>et&&(a*=N,i*=N,r*=N,c*=N),s&&(c+=a),s=!s,g===e&&(r=i)}r/=2*c-a}return t<0&&e%2===1?-r:r}function Ot(t,e){if(t<=0||t>=nt)throw u.NUM;if(e===0)return ct(t);if(e===1)return it(t);const n=2/t;let o=ct(t),r=it(t);for(let s=1;s<e&&Number.isFinite(r);s++){const c=s*n*r-o;o=r,r=c}return r}function Bt(t,e){if(t<=0)throw u.NUM;if(e===0)return rt(t);if(e===1)return st(t);const n=2/t;let o=rt(t),r=st(t);for(let s=1;s<e&&Number.isFinite(r);s++){if(o===0&&r===0)return 0;const c=o+k(s*n*r);o=r,r=c}return r}const L=(t,e)=>f(t,2,2,(n,o)=>{const r=M(n),s=Math.trunc(M(o));if(s<0)throw u.NUM;return T(e(r,s))});L("BESSELI",bt),L("BESSELJ",Pt),L("BESSELK",Bt),L("BESSELY",Ot);const V=String.raw`(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?`,$t=new RegExp(`^[+-]?${V}$`),qt=new RegExp(`^(?:([+-]?${V})(?=[+-]))?([+-]?)(${V})?([ij])$`);function I(t){if(t instanceof yt)throw t;if(typeof t=="boolean")throw u.VALUE;if(t==null||t===P)return{z:[0,0],suffix:null};if(typeof t=="number")return{z:[t,0],suffix:null};const e=R(t);let n=0,o=0,r=null;if($t.test(e))n=Number(e);else{const s=qt.exec(e);if(s===null)throw u.NUM;s[1]!==void 0&&(n=Number(s[1])),o=(s[2]==="-"?-1:1)*(s[3]===void 0?1:Number(s[3])),[,,,,r]=s}if(!Number.isFinite(n)||!Number.isFinite(o))throw u.NUM;return{z:[n,o],suffix:r}}function D(t){const e=wt(t),n=/^(-?)(\d)(?:\.(\d+))?E-(\d+)$/.exec(e);if(!n)return e;const o=`0.${"0".repeat(Number(n[4])-1)}${n[2]}${n[3]??""}`;return o.length<=21?n[1]+o:e}function d([t,e],n){const o=B(T(t)),r=B(T(e));if(r===0)return D(o);const s=r===1?"":r===-1?"-":D(r);return o===0?`${s}${n}`:`${D(o)}${r>0?"+":""}${s}${n}`}function Y(t,e){if(t!==null&&e!==null&&t!==e)throw u.VALUE;return t??e}const zt=([t,e],[n,o])=>[t+n,e+o],_t=([t,e],[n,o])=>[t*n-e*o,t*o+e*n];function kt([t,e],[n,o]){const r=n*n+o*o;if(r===0)throw u.NUM;return[(t*n+e*o)/r,(e*n-t*o)/r]}const m=t=>(Math.exp(t)-Math.exp(-t))/2,p=t=>(Math.exp(t)+Math.exp(-t))/2,Ft=([t,e])=>[Math.sin(t)*p(e),Math.cos(t)*m(e)],Ht=([t,e])=>[Math.cos(t)*p(e),-Math.sin(t)*m(e)],Gt=([t,e])=>{const n=Math.sin(e);return[m(t)*Math.cos(e),(Math.exp(t)*n+Math.exp(-t)*n)/2]},Vt=([t,e])=>[p(t)*Math.cos(e),m(t)*Math.sin(e)];function j([t,e]){if(t===0&&e===0)throw u.NUM;return[Math.log(Math.hypot(t,e)),Math.atan2(e,t)]}const Dt=[1,0];f("COMPLEX",2,3,(t,e,n)=>{const o=M(t),r=M(e),s=O(n,"i");if(s!=="i"&&s!=="j")throw u.VALUE;return d([o,r],s)});const U=(t,e)=>f(t,1,1,n=>T(e(I(n).z)));U("IMABS",([t,e])=>Math.hypot(t,e)),U("IMAGINARY",([,t])=>t),U("IMREAL",([t])=>t),U("IMARGUMENT",([t,e])=>{if(t===0&&e===0)throw u.DIV0;return Math.atan2(e,t)});const h=(t,e)=>f(t,1,1,n=>{const{z:o,suffix:r}=I(n);return d(e(o),r??"i")});h("IMCONJUGATE",([t,e])=>[t,-e]),h("IMCOS",Ht),h("IMCOSH",Vt),h("IMCOT",([t,e])=>{const n=p(2*e)-Math.cos(2*t);return[Math.sin(2*t)/n,-m(2*e)/n]}),h("IMCSC",([t,e])=>{const n=(p(2*e)-Math.cos(2*t))/2;return[Math.sin(t)*(p(e)/n),-Math.cos(t)*(m(e)/n)]}),h("IMCSCH",([t,e])=>{const n=Math.sin(e),o=m(t),r=o*o+n*n;return[o*Math.cos(e)/r,-p(t)*n/r]}),h("IMEXP",([t,e])=>[Math.exp(t)*Math.cos(e),Math.exp(t)*Math.sin(e)]),h("IMLN",j),h("IMLOG10",t=>j(t).map(e=>e/Math.LN10)),h("IMLOG2",t=>j(t).map(e=>e/Math.LN2)),h("IMSEC",([t,e])=>{const n=(p(2*e)+Math.cos(2*t))/2;return[Math.cos(t)*p(e)/n,Math.sin(t)*m(e)/n]}),h("IMSECH",([t,e])=>{const n=Math.cos(e),o=m(t),r=o*o+n*n;return[p(t)*n/r,-o*Math.sin(e)/r]}),h("IMSIN",Ft),h("IMSINH",Gt),h("IMSQRT",([t,e])=>{const n=Math.sqrt(Math.hypot(t,e)),o=Math.atan2(e,t)/2;return[n*Math.cos(o),n*Math.sin(o)]}),h("IMTAN",([t,e])=>{const n=Math.cos(2*t)+p(2*e);return[Math.sin(2*t)/n,m(2*e)/n]}),f("IMDIV",2,2,(t,e)=>{const n=I(t),o=I(e);return d(kt(n.z,o.z),Y(n.suffix,o.suffix)??"i")}),f("IMSUB",2,2,(t,e)=>{const n=I(t),o=I(e);return d([n.z[0]-o.z[0],n.z[1]-o.z[1]],Y(n.suffix,o.suffix)??"i")}),f("IMPOWER",2,2,(t,e)=>{const{z:[n,o],suffix:r}=I(t),s=M(e);if(n===0&&o===0){if(s<=0)throw u.NUM;return"0"}const c=Math.hypot(n,o)**s,i=Math.atan2(o,n)*s;return d([c*Math.cos(i),c*Math.sin(i)],r??"i")});const ft=(t,e,n,o)=>gt(t,1,255,(r,s)=>{let c=e,i=null,a=!1;for(const g of s)Tt(r,g,b=>{const Z=I(b);i=Y(i,Z.suffix),c=n(c,Z.z),a=!0});return a?d(c,i??"i"):o});ft("IMSUM",[0,0],zt,"0"),ft("IMPRODUCT",Dt,_t,"0");const X=new Map;function l(t,e){for(const[n,o,r=1]of e)for(const s of o.split(" ")){const c=s.endsWith("*");X.set(c?s.slice(0,-1):s,{group:t,factor:n,prefix:c,power:r})}}const w=.0254,y=.3048,J=.9144,C=1609.344,A=1852,K=9460730472580800,W=w/72,E=231*w**3;l("mass",[[1,"g*"],[14593.9029372064,"sg"],[453.59237,"lbm"],[1660538782e-33,"u*"],[28.349523125,"ozm"],[.06479891,"grain"],[45359.237,"cwt shweight"],[50802.34544,"uk_cwt lcwt hweight"],[6350.29318,"stone"],[907184.74,"ton"],[10160469088e-4,"uk_ton LTON brton"]]),l("distance",[[1,"m*"],[C,"mi"],[A,"Nmi"],[w,"in"],[y,"ft"],[J,"yd"],[1e-10,"ang*"],[1.143,"ell"],[K,"ly*"],[0x6da012f93c9a8c,"parsec pc"],[W,"Picapt Pica"],[w/6,"pica"],[5280*1200/3937,"survey_mi"]]),l("time",[[31557600,"yr"],[86400,"day d"],[3600,"hr"],[60,"mn min"],[1,"sec* s*"]]),l("pressure",[[1,"Pa* p*"],[101325,"atm* at*"],[133.322,"mmHg*"],[6894.75729316836,"psi*"],[101325/760,"Torr*"]]),l("force",[[1,"N*"],[1e-5,"dyn* dy*"],[4.4482216152605,"lbf"],[.00980665,"pond*"]]),l("energy",[[1,"J*"],[1e-7,"e*"],[4.184,"c*"],[4.1868,"cal*"],[1602176487e-28,"eV* ev*"],[268451953769617e-8,"HPh hh"],[3600,"Wh* wh*"],[1.3558179483314,"flb"],[1055.05585262,"BTU btu"]]),l("power",[[745.69987158227,"HP h"],[735.49875,"PS"],[1,"W* w*"]]),l("magnetism",[[1,"T*"],[1e-4,"ga*"]]),l("volume",[[E/768,"tsp"],[5e-6,"tspm"],[E/256,"tbs"],[E/128,"oz"],[E/16,"cup"],[E/8,"pt us_pt"],[.00056826125,"uk_pt"],[E/4,"qt"],[.0011365225,"uk_qt"],[E,"gal"],[.00454609,"uk_gal"],[.001,"l* L* lt*"],[1e-30,"ang3* ang^3*",3],[42*E,"barrel"],[.03523907016688,"bushel"],[y**3,"ft3 ft^3"],[w**3,"in3 in^3"],[K**3,"ly3 ly^3"],[1,"m3* m^3*",3],[C**3,"mi3 mi^3"],[J**3,"yd3 yd^3"],[A**3,"Nmi3 Nmi^3"],[W**3,"Picapt3 Picapt^3 Pica3 Pica^3"],[100*y**3,"GRT regton"],[40*y**3,"MTON"]]),l("area",[[4046.8564224,"uk_acre"],[43560*(1200/3937)**2,"us_acre"],[1e-20,"ang2* ang^2*",2],[100,"ar*"],[y**2,"ft2 ft^2"],[1e4,"ha"],[w**2,"in2 in^2"],[K**2,"ly2 ly^2"],[1,"m2* m^2*",2],[2500,"Morgen"],[C**2,"mi2 mi^2"],[A**2,"Nmi2 Nmi^2"],[W**2,"Picapt2 Picapt^2 Pica2 Pica^2"],[J**2,"yd2 yd^2"]]),l("information",[[1,"bit*"],[8,"byte*"]]),l("speed",[[6080*y/3600,"admkn"],[A/3600,"kn"],[1/3600,"m/h* m/hr*"],[1,"m/s* m/sec*"],[C/3600,"mph"]]);const Yt=new Map([["Y",1e24],["Z",1e21],["E",1e18],["P",1e15],["T",1e12],["G",1e9],["M",1e6],["k",1e3],["h",100],["da",10],["e",10],["d",.1],["c",.01],["m",.001],["u",1e-6],["n",1e-9],["p",1e-12],["f",1e-15],["a",1e-18],["z",1e-21],["y",1e-24]]),Mt=new Map([["Yi",2**80],["Zi",2**70],["Ei",2**60],["Pi",2**50],["Ti",2**40],["Gi",2**30],["Mi",2**20],["ki",2**10]]),ht=[1,0],lt=[1.8,32],pt=[1,273.15],mt=new Map([["C",ht],["cel",ht],["F",lt],["fah",lt],["K",pt],["kel",pt],["Rank",[1.8,491.67]],["Reau",[.8,0]]]),It=t=>Math.abs(t)<1e-12?0:t;function jt(t,[e,n],[o,r]){const s=o/e;return It(t*s+It(r-n*s))}function Et(t){if(mt.has(t))return{group:"temperature",temperature:mt.get(t)};const e=X.get(t);if(e!==void 0)return e;for(const n of[2,1]){const o=X.get(t.slice(n));if(o===void 0||!o.prefix)continue;const r=t.slice(0,n),s=Yt.get(r);if(s!==void 0)return{group:o.group,factor:o.factor*s**o.power};if(o.group==="information"&&Mt.has(r))return{group:o.group,factor:o.factor*Mt.get(r)}}return null}f("CONVERT",3,3,(t,e,n)=>{const o=M(t),r=R(e),s=R(n),c=Et(r),i=Et(s);if(c===null||i===null||c.group!==i.group)throw u.NA;if(r===s)return o;const a=c.group==="temperature"?jt(o,c.temperature,i.temperature):o*c.factor/i.factor;return B(T(a))});
@@ -0,0 +1 @@
1
+ import{setCategory as Ot}from"./registry.js";import{lift as Nt,raw as B}from"./registry.js";import{Arr as vt,bool as mt,checked as X,ERR as N,num as h,opt as R,Ref as Ut,RefList as Ft,XlError as Vt}from"../values.js";import{scalarOf as dt}from"./helpers.js";import{partsToSerial as rt,serialToParts as x}from"../../core/numfmt.js";Ot("Financial");const kt=2958465,pt=1e-7,yt=200,y=(t,n,s,o)=>Nt(t,n,s,(...e)=>X(o(...e))),p=t=>{if(!t)throw N.NUM},m=t=>{if(typeof t=="boolean")throw N.VALUE;return h(t)},G=t=>h(R(t,0))!==0?1:0;function D(t){const n=Math.trunc(m(t));if(n<0||n>kt)throw N.VALUE;return n}function F(t){const n=Math.trunc(m(R(t,0)));return p(n>=0&&n<=4),n}function z(t){const n=Math.trunc(m(t));return p(n===1||n===2||n===4),n}const J=t=>t%4===0&&(t%100!==0||t%400===0),ct=(t,n)=>n===2?J(t)?29:28:n===4||n===6||n===9||n===11?30:31;function Z(t){const n=x(t);return n.day>=ct(n.year,n.month)}function P(t,n,s){const o=x(t),e=o.year*12+o.month-1+n,r=Math.floor(e/12),a=e-r*12+1,c=ct(r,a);return rt(r,a,s?c:Math.min(o.day,c))}function $(t,n,s=!1){const o=x(t),e=x(n);let r=o.day,a=e.day;if(s)r===31&&(r=30),a===31&&(a=30);else{const c=f=>f.month===2&&f.day>=ct(f.year,2);c(o)&&(c(e)&&(a=30),r=30),a===31&&r>=30&&(a=30),r===31&&(r=30)}return(e.year-o.year)*360+(e.month-o.month)*30+a-r}const V=(t,n,s)=>s===0?$(t,n):s===4?$(t,n,!0):n-t;function St(t,n){const s=x(t),o=x(n);if(s.year===o.year)return(n-t)/(J(s.year)?366:365);if(o.year===s.year+1&&(s.month>o.month||s.month===o.month&&s.day>=o.day)){const r=J(s.year)&&t<=rt(s.year,2,29)||J(o.year)&&n>=rt(o.year,2,29);return(n-t)/(r?366:365)}let e=0;for(let r=s.year;r<=o.year;r++)e+=J(r)?366:365;return(n-t)/(e/(o.year-s.year+1))}function _(t,n,s=0){const o=Math.trunc(Math.min(t,n)),e=Math.trunc(Math.max(t,n));switch(s){case 1:return St(o,e);case 2:return(e-o)/360;case 3:return(e-o)/365;case 4:return $(o,e,!0)/360;default:return $(o,e)/360}}function at(t,n,s,o){const e=Z(n),r=12/s;let a=1;for(;P(n,-a*r,e)>t;)a++;const c=P(n,-a*r,e),f=P(n,(1-a)*r,e),i=V(c,t,o),u=o===1?f-c:(o===3?365:360)/s,l=o===0||o===4?u-i:f-t;return{n:a,pcd:c,ncd:f,a:i,e:u,dsc:l,f:s}}function tt(t,n,s,o){const e=D(t),r=D(n),a=z(s),c=F(o);return p(e<r),at(e,r,a,c)}function nt(t,n,s=-1){const o=.001*Math.max(1,Math.abs(t(n))),e=u=>Math.abs(t(u))<=o;let r=n;for(let u=0;u<yt;u++){const l=t(r);if(l===0)return r;const M=Math.min(1e-6*(1+Math.abs(r)),(r-s)/2),d=r-l*2*M/(t(r+M)-t(r-M));if(!Number.isFinite(d)||d<=s)break;if(Math.abs(d-r)<pt&&e(d))return d;r=d}let a=n,c=n+.01*(1+Math.abs(n)),f=t(a),i=t(c);for(let u=0;u<yt;u++){if(i===0)return c;let l=c-i*(c-a)/(i-f);if(l<=s&&(l=(c+s)/2),!Number.isFinite(l))break;if(Math.abs(l-c)<pt&&e(l))return l;a=c,f=i,c=l,i=t(c)}throw N.NUM}const K=(t,n)=>(1+t)**n,ot=(t,n)=>t===0?n:(t>-1?Math.expm1(n*Math.log1p(t)):K(t,n)-1)/t,ft=(t,n,s,o,e)=>-(o*K(t,n)+s*(1+t*e)*ot(t,n)),Yt=(t,n,s,o,e)=>-(o+s*(1+t*e)*ot(t,n))/K(t,n),et=(t,n,s,o,e)=>-(o+s*K(t,n))/((1+t*e)*ot(t,n));function st(t,n,s,o,e,r){const a=et(t,s,o,e,r);return n===1?r?0:-o*t:(r?ft(t,n-2,a,o,1)-a:ft(t,n-1,a,o,0))*t}function It(t,n,s,o,e,r){const a=[h(t),h(n),h(s),h(o),h(R(e,0)),G(r)];return p(a[1]>=1&&a[1]<a[2]+1),a}y("PMT",3,5,(t,n,s,o,e)=>et(h(t),h(n),h(s),h(R(o,0)),G(e))),y("PV",3,5,(t,n,s,o,e)=>Yt(h(t),h(n),h(s),h(R(o,0)),G(e))),y("FV",3,5,(t,n,s,o,e)=>ft(h(t),h(n),h(s),h(R(o,0)),G(e))),y("IPMT",4,6,(...t)=>st(...It(...t))),y("PPMT",4,6,(...t)=>{const[n,s,o,e,r,a]=It(...t);return et(n,o,e,r,a)-st(n,s,o,e,r,a)}),y("NPER",3,5,(t,n,s,o,e)=>{const r=h(t),a=h(n),c=h(s),f=h(R(o,0)),i=G(e);if(r===0){if(a===0)throw N.DIV0;return-(c+f)/a}const u=a*(1+r*i);return Math.log((u-f*r)/(u+c*r))/Math.log1p(r)}),y("RATE",3,6,(t,n,s,o,e,r)=>{const a=h(t),c=h(n),f=h(s),i=h(R(o,0)),u=G(e),l=h(R(r,.1));p(a>0&&l>-1);const M=nt(d=>f*K(d,a)+c*(1+d*u)*ot(d,a)+i,l);return p(M>-1+1e-6),M}),y("ISPMT",4,4,(t,n,s,o)=>{const e=h(s);if(e===0)throw N.DIV0;return h(o)*h(t)*(h(n)/e-1)}),y("PDURATION",3,3,(t,n,s)=>{const[o,e,r]=[h(t),h(n),h(s)];return p(o>0&&e>0&&r>0),(Math.log(r)-Math.log(e))/Math.log1p(o)}),y("RRI",3,3,(t,n,s)=>{const[o,e,r]=[h(t),h(n),h(s)];return p(o>0&&e!==0&&e*r>=0),(r/e)**(1/o)-1});function Dt(t,n,s,o,e,r,a){const c=m(t),f=Math.trunc(m(n)),i=m(s),u=Math.trunc(m(o)),l=Math.trunc(m(e)),M=Math.trunc(m(r));p(c>0&&f>0&&i>0&&u>=1&&l>=u&&l<=f&&(M===0||M===1));let d=0;for(let I=u;I<=l;I++)d+=a(c,I,f,i,M);return d}y("CUMIPMT",6,6,(...t)=>Dt(...t,(n,s,o,e,r)=>st(n,s,o,e,0,r))),y("CUMPRINC",6,6,(...t)=>Dt(...t,(n,s,o,e,r)=>et(n,o,e,0,r)-st(n,s,o,e,0,r)));function q(t,n){const s=[],o=e=>{for(const r of t.toArr(e).data)if(typeof r=="number")s.push(r);else if(r instanceof Vt)throw r};return n instanceof Ft?n.refs.forEach(o):n instanceof Ut||n instanceof vt?o(n):s.push(h(n)),s}const H=(t,n,s,o)=>h(dt(t,n,s,o)),it=t=>t.some(n=>n>0)&&t.some(n=>n<0),bt=99;function Et(t,n,s){const o=q(t,n),e=q(t,s).map(D);return p(o.length===e.length&&o.length>0),p(e.every(r=>r>=e[0])),[o,e.map(r=>(r-e[0])/365)]}function Q(t,n,s){let o=0;for(let e=0;e<t.length;e++)o+=t[e]/(1+s)**n[e];return o}B("NPV",2,255,(t,n,s,o)=>{const e=H(t,n[0],s,o);if(e===-1)throw N.DIV0;let r=0,a=1;for(let c=1;c<n.length;c++)for(const f of q(t,n[c]))r+=f/(1+e)**a++;return X(r)},{array:!0}),B("IRR",1,2,(t,n,s,o)=>{const e=q(t,n[0]),r=H(t,R(n[1],.1),s,o);return p(r>-1&&it(e)),nt(a=>{let c=0;for(let f=0;f<e.length;f++)c+=e[f]/(1+a)**f;return c},r)},{array:!0}),B("MIRR",3,3,(t,n,s,o)=>{const e=q(t,n[0]),r=H(t,n[1],s,o),a=H(t,n[2],s,o);if(r===-1||a===-1||!it(e))throw N.DIV0;const c=e.length-1;let f=0,i=0;return e.forEach((u,l)=>{u>0?f+=u*(1+a)**(c-l):i+=u/(1+r)**l}),X((f/-i)**(1/c)-1)},{array:!0}),B("XNPV",3,3,(t,n,s,o)=>{const e=H(t,n[0],s,o),[r,a]=Et(t,n[1],n[2]);return p(e>=0),X(Q(r,a,e))},{array:!0});function Bt(t,n,s){const o=t[0],e=u=>u*o>=0,r=s===0?1e-5:s,a=Q(t,n,0)*o>0;let c=0,f=r,i=0;if(a){p(Math.abs(r)<1);const u=-Math.abs(r);e(Q(t,n,u))?[c,f]=[-1,u]:[c,f]=[u,0]}else for(p(r>0),e(Q(t,n,f))||(i=1);!e(Q(t,n,f));)c=f,f*=2,i++,p(i<=bt);for(;++i<=bt;){const u=(c+f)/2,l=Q(t,n,u);if(e(l)?f=u:c=u,f-c<=1e-8*(Math.abs(u)+.5)&&(!a||Math.abs(l)<=2e-8*Math.abs(o)))return u}throw N.NUM}B("XIRR",2,3,(t,n,s,o)=>{const[e,r]=Et(t,n[0],n[1]),a=H(t,R(n[2],.1),s,o);return p(a>-1&&it(e)),X(Bt(e,r,a))},{array:!0}),B("FVSCHEDULE",2,2,(t,n,s,o)=>{let e=m(dt(t,n[0],s,o));for(const r of q(t,n[1]))e*=1+r;return X(e)},{array:!0}),y("SLN",3,3,(t,n,s)=>{const o=h(s);if(o===0)throw N.DIV0;return(h(t)-h(n))/o}),y("SYD",4,4,(t,n,s,o)=>{const[e,r]=[h(s),h(o)];return p(e>0&&r>0&&r<=e),(h(t)-h(n))*(e-r+1)*2/(e*(e+1))}),y("DB",4,5,(t,n,s,o,e)=>{const r=h(t),a=h(n),c=h(s),f=Math.trunc(h(o)),i=Math.trunc(h(R(e,12)));if(p(r>=0&&a>=0&&c>0&&f>=1&&i>=1&&i<=12),p(f<=(i===12?c:c+1)),a>=r)return 0;const u=Math.round((1-(a/r)**(1/c))*1e3)/1e3;let l=r*u*i/12;if(f===1)return l;let M=0;for(let d=2;d<=Math.min(f,c);d++)M=(r-l)*u,l+=M;return f>c?(r-l)*u*(12-i)/12:M});function ut(t,n,s,o,e){let r=e/s,a;r>=1?(r=1,a=o===1?t:0):a=t*(1-r)**(o-1);const c=t*(1-r)**o;return Math.max(a-Math.max(c,n),0)}y("DDB",4,5,(t,n,s,o,e)=>{const[r,a,c,f]=[h(t),h(n),h(s),h(o)],i=h(R(e,2));return p(r>=0&&a>=0&&c>0&&f>0&&f<=c&&i>0),ut(r,a,c,f,i)});function Rt(t,n,s,o,e,r){const a=Math.ceil(e);let c=t-n,f=0,i=!1,u=0;for(let l=1;l<=a;l++){let M=f;if(!i){const d=ut(t,n,s,l,r);f=c/(o-(l-1)),i=f>d,M=i?f:d,i||(c-=d)}u+=l===a?M*(e+1-a):M}return u}y("VDB",5,7,(t,n,s,o,e,r,a)=>{let c=h(t);const f=h(n),i=h(s);let u=h(o),l=h(e);const M=h(R(r,2)),d=mt(R(a,!1));if(p(c>=0&&f>=0&&i>0&&u>=0&&l>=u&&l<=i&&M>=0),d){const E=Math.floor(u),b=Math.ceil(l);let g=0;for(let A=E+1;A<=b;A++){let C=ut(c,f,i,A,M);A===E+1?C*=Math.min(l,E+1)-u:A===b&&(C*=l+1-b),g+=C}return g}let I=i;return u!==Math.floor(u)&&M>1&&u>=i/2&&(l-=u-i/2,u=i/2,I+=1),c-=Rt(c,f,i,I,u,M),Rt(c,f,i,i-u,l-u,M)});function At(t,n,s,o,e,r,a){const c={cost:m(t),bought:D(n),firstEnd:D(s),salvage:m(o),per:Math.trunc(m(e)),rate:m(r),basis:F(a)};return p(c.basis!==2&&c.cost>=0&&c.salvage>=0&&c.salvage<=c.cost),p(c.per>=0&&c.rate>0&&c.bought<=c.firstEnd),c.frac=_(c.bought,c.firstEnd,c.basis),c}y("AMORLINC",6,7,(...t)=>{const{cost:n,salvage:s,per:o,rate:e,frac:r}=At(...t),a=n*e,c=r*a,f=Math.trunc((n-s-c)/a);return o===0?c:o<=f?a:o===f+1?n-s-a*f-c:0}),y("AMORDEGRC",6,7,(...t)=>{const{cost:n,salvage:s,per:o,rate:e,frac:r}=At(...t),a=1/e,c=(M,d)=>a>=M&&a<=d;p(c(3,4)||c(5,6)||a>6);const f=e*(c(3,4)?1.5:c(5,6)?2:2.5);let i=Math.round(r*f*n),u=n-i,l=u-s;for(let M=0;M<o;M++){if(i=Math.round(f*u),l-=i,l<0)return o-M===1?Math.round(u*.5):0;u-=i}return i}),y("EFFECT",2,2,(t,n)=>{const s=m(t),o=Math.trunc(m(n));return p(s>0&&o>=1),(1+s/o)**o-1}),y("NOMINAL",2,2,(t,n)=>{const s=m(t),o=Math.trunc(m(n));return p(s>0&&o>=1),o*((1+s)**(1/o)-1)});function Ct(t,n,s){const o=m(t),e=Math.trunc(m(n));if(p(e>=0),e===0)throw N.DIV0;const r=Math.trunc(o);return r+s(o-r,e,10**Math.ceil(Math.log10(e)))}y("DOLLARDE",2,2,(t,n)=>Ct(t,n,(s,o,e)=>s*e/o)),y("DOLLARFR",2,2,(t,n)=>Ct(t,n,(s,o,e)=>s*o/e));function lt(t,n,s,o){const e=D(t),r=D(n),a=m(s);return p(e<r&&r<=P(e,12,!1)&&a>0),o(a,r-e)}y("TBILLEQ",3,3,(t,n,s)=>lt(t,n,s,(o,e)=>365*o/(360-o*e))),y("TBILLPRICE",3,3,(t,n,s)=>lt(t,n,s,(o,e)=>100*(1-o*e/360))),y("TBILLYIELD",3,3,(t,n,s)=>lt(t,n,s,(o,e)=>(100-o)/o*360/e)),y("ACCRINT",6,8,(t,n,s,o,e,r,a,c)=>{const f=D(t),i=D(n),u=D(s),l=m(o),M=m(R(e,1e3)),d=z(r),I=F(a),E=mt(R(c,!0));p(l>0&&M>0&&f<u);const b=!E&&u>i?i:f,g=12/d,A=Z(i);let C=0;for(;P(i,C*g,A)>b;)C--;for(;P(i,(C+1)*g,A)<=b;)C++;let U=0;for(;P(i,C*g,A)<u;C++){const L=P(i,C*g,A),v=P(i,(C+1)*g,A),T=I===1?v-L:(I===3?365:360)/d;U+=V(Math.max(L,b),Math.min(v,u),I)/T}return M*l*U/d}),y("ACCRINTM",3,5,(t,n,s,o,e)=>{const r=D(t),a=D(n),c=m(s),f=m(R(o,1e3)),i=F(e);return p(c>0&&f>0&&r<a),f*c*_(r,a,i)});const j=(t,n)=>y(t,3,4,(s,o,e,r)=>n(tt(s,o,e,r)));j("COUPDAYBS",t=>t.a),j("COUPDAYS",t=>t.e),j("COUPDAYSNC",t=>t.dsc),j("COUPNCD",t=>t.ncd),j("COUPNUM",t=>t.n),j("COUPPCD",t=>t.pcd);const W=(t,n)=>y(t,4,5,(s,o,e,r,a)=>{const c=D(s),f=D(o),i=m(e),u=m(r),l=F(a);return p(c<f&&i>0&&u>0),n(i,u,_(c,f,l))});W("DISC",(t,n,s)=>(n-t)/n/s),W("INTRATE",(t,n,s)=>(n-t)/t/s),W("RECEIVED",(t,n,s)=>{const o=1-n*s;return p(o>0),t/o}),W("PRICEDISC",(t,n,s)=>n*(1-t*s)),W("YIELDDISC",(t,n,s)=>(n/t-1)/s);const gt=(t,n,s)=>y(t,5,6,(o,e,r,a,c,f)=>{const i=D(o),u=D(e),l=D(r),M=m(a),d=m(c),I=F(f);return p(i<u&&l<i&&M>=0&&n(d)),s(M,d,_(l,u,I),_(l,i,I),_(i,u,I))});gt("PRICEMAT",t=>t>=0,(t,n,s,o,e)=>(100+s*t*100)/(1+e*n)-o*t*100),gt("YIELDMAT",t=>t>0,(t,n,s,o,e)=>{const r=n/100+o*t;return(1+s*t-r)/r/e});function Pt(t,n,s,o){const e=100*n/t.f,r=t.dsc/t.e;if(t.n===1)return(o+e)/(1+s/t.f*r)-e*t.a/t.e;const a=1+s/t.f;let c=o/a**(t.n-1+r);for(let f=0;f<t.n;f++)c+=e/a**(f+r);return c-e*t.a/t.e}y("PRICE",6,7,(t,n,s,o,e,r,a)=>{const c=m(s),f=m(o),i=m(e),u=tt(t,n,r,a);return p(c>=0&&f>=0&&i>0),Pt(u,c,f,i)}),y("YIELD",6,7,(t,n,s,o,e,r,a)=>{const c=m(s),f=m(o),i=m(e),u=tt(t,n,r,a);if(p(c>=0&&f>0&&i>0),u.n===1){const l=c/u.f,M=f/100+u.a/u.e*l;return(i/100+l-M)/M*(u.f*u.e/u.dsc)}return nt(l=>Pt(u,c,l,i)-f,.1,-u.f)});function Lt(t,n,s,o,e,r){const a=m(s),c=m(o),f=tt(t,n,e,r);p(a>=0&&c>=0);const i=1+c/f.f,u=100*a/f.f,l=f.dsc/f.e;let M=0,d=0;for(let I=0;I<f.n;I++){const E=I+l,b=(I===f.n-1?u+100:u)/i**E;M+=E*b,d+=b}return[M/d/f.f,i]}y("DURATION",5,6,(...t)=>Lt(...t)[0]),y("MDURATION",5,6,(...t)=>{const[n,s]=Lt(...t);return n/s});function Tt(t,n,s,o,e,r,a,c){const f=D(t),i=D(n),u=D(s),l=D(o),M=m(e),d=m(r),I=z(a),E=F(c);p(i>l&&l>f&&f>u&&M>=0&&d>0);const b=at(f,l,I,E),g=b.n===1?V(f,l,E):b.dsc,A=at(l,i,I,E).n,C=Z(l),U=12/I;let L=0,v=0;for(let k=0,w=l;;k++){const O=P(l,-(k+1)*U,C),S=E===1?w-O:b.e;L+=(O>u?S:V(u,w,E))/S;const ht=Math.max(u,O),Mt=Math.min(f,w);if(Mt>ht&&(v+=V(ht,Mt,E)/S),O<=u)break;w=O}const T=100*M/I,Y=b.n-1+g/b.e;return k=>{const w=1+k/I;let O=d/w**(A+Y)+T*L/w**Y;for(let S=1;S<=A;S++)O+=T/w**(S+Y);return O-T*v}}y("ODDFPRICE",8,9,(t,n,s,o,e,r,a,c,f)=>{const i=m(r),u=Tt(t,n,s,o,e,a,c,f);return p(i>=0),u(i)}),y("ODDFYIELD",8,9,(t,n,s,o,e,r,a,c,f)=>{const i=m(r),u=Tt(t,n,s,o,e,a,c,f);return p(i>0),nt(l=>u(l)-i,.1,-z(c))});function wt(t,n,s,o,e,r,a){const c=D(t),f=D(n),i=D(s),u=m(o),l=m(e),M=z(r),d=F(a);p(f>c&&c>i&&u>=0&&l>0);const I=12/M,E=Z(i);let b=0,g=0,A=0;for(let U=0;;U++){const L=P(i,U*I,E),v=P(i,(U+1)*I,E),T=d===0||d===4?360/M:v-L,Y=v>=f,k=Y?V(L,f,d):T;b+=k/T,v<c?g+=k/T:L<c&&(g+=V(L,c,d)/T);const w=Math.max(c,L),O=Math.min(f,v);if(O>w&&(A+=V(w,O,d)/T),Y)break}const C=100*u/M;return{income:l+b*C,interest:g*C,toGo:A,f:M}}y("ODDLPRICE",7,8,(t,n,s,o,e,r,a,c)=>{const f=m(e),i=wt(t,n,s,o,r,a,c);return p(f>=0),i.income/(1+i.toGo*f/i.f)-i.interest}),y("ODDLYIELD",7,8,(t,n,s,o,e,r,a,c)=>{const f=m(e),i=wt(t,n,s,o,r,a,c);p(f>0);const u=f+i.interest;return(i.income-u)/u*(i.f/i.toGo)});export{$ as days360,_ as yearFrac};
@@ -0,0 +1 @@
1
+ import{Arr as a,bool as A,compareText as R,ERR as h,num as b,OMITTED as l,Ref as y,RefList as m,RichValue as x,str as L,textToNumber as w,XlError as c}from"../values.js";function d(n,r,o){if(r instanceof y)n.scan(r,o);else if(r instanceof m)for(const t of r.refs)n.scan(t,o);else if(r instanceof a)for(const t of r.data)o(t);else r!==l&&r!==void 0&&o(r)}function T(n,r){const o=[];for(const t of r)t instanceof y||t instanceof m||t instanceof a?d(n,t,s=>{if(typeof s=="number")o.push(s);else{if(s instanceof c)throw s;if(s instanceof x)throw h.VALUE}}):t!==l&&t!==void 0&&t!==null?o.push(b(t)):(t===l||t===null)&&o.push(0);return o}function U(n,r){const o=[];for(const t of r)if(t instanceof y||t instanceof m||t instanceof a){const s=!(t instanceof a);d(n,t,f=>{if(typeof f=="number")o.push(f);else if(typeof f=="boolean"&&s)o.push(f?1:0);else if(typeof f=="string")o.push(0);else{if(f instanceof c)throw f;if(f instanceof x)throw h.VALUE}})}else t!==l&&t!==void 0&&t!==null&&o.push(b(t));return o}function g(n,r){return n.toArr(r).data}function C(n,r,o){const t=g(n,r),s=g(n,o);if(t.length!==s.length)throw h.NA;const f=[],u=[];for(let e=0;e<t.length;e++){if(t[e]instanceof c)throw t[e];if(s[e]instanceof c)throw s[e];typeof t[e]=="number"&&typeof s[e]=="number"&&(f.push(t[e]),u.push(s[e]))}return[f,u]}function S(n,r,o,t){const s=n.scalar(r,o,t);if(s instanceof c)throw s;return s}function E(n){let r="^";for(let o=0;o<n.length;o++){const t=n[o];t==="~"&&(n[o+1]==="*"||n[o+1]==="?"||n[o+1]==="~")?r+=n[++o].replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):t==="*"?r+="[\\s\\S]*":t==="?"?r+="[\\s\\S]":r+=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return new RegExp(`${r}$`,"i")}const $=n=>/[*?~]/.test(n);function V(n){if(n instanceof c)return e=>e===n;if(typeof n=="number")return e=>e===n||typeof e=="string"&&w(e)===n;if(typeof n=="boolean")return e=>e===n;if(n==null||n===l)return e=>e===0||e===null;const r=String(n),o=/^(<=|>=|<>|<|>|=)([\s\S]*)$/.exec(r),t=o?o[1]:"=",s=o?o[2]:r,f=w(s);if(f!==null)switch(t){case"=":return e=>e===f||typeof e=="string"&&w(e)===f;case"<>":return e=>!(e===f||typeof e=="string"&&w(e)===f);case"<":return e=>typeof e=="number"&&e<f;case"<=":return e=>typeof e=="number"&&e<=f;case">":return e=>typeof e=="number"&&e>f;default:return e=>typeof e=="number"&&e>=f}const u=s.toUpperCase();if(u==="TRUE"||u==="FALSE"){const e=u==="TRUE";return t==="<>"?i=>i!==e:i=>i===e}if(t==="="||t==="<>"){if(s==="")return t==="="?i=>i===null:i=>i!==null;if($(s)){const i=E(s);return t==="="?p=>typeof p=="string"&&i.test(p):p=>!(typeof p=="string"&&i.test(p))}const e=s.toLowerCase();return t==="="?i=>typeof i=="string"&&i.toLowerCase()===e:i=>!(typeof i=="string"&&i.toLowerCase()===e)}return e=>{if(typeof e!="string")return!1;const i=R(e,s);return t==="<"?i<0:t==="<="?i<=0:t===">"?i>0:i>=0}}function O(n,r){const o=n.toArr(r),t=[];for(let s=0;s<o.rows;s++){const f=[];for(let u=0;u<o.cols;u++){const e=o.get(s,u);if(typeof e!="number")throw e instanceof c?e:h.VALUE;f.push(e)}t.push(f)}return t}export{a as Arr,h as ERR,l as OMITTED,y as Ref,m as RefList,c as XlError,A as bool,T as collectNumbers,U as collectNumbersA,d as eachValue,g as flat,$ as hasWildcards,V as makeCriteria,O as matrixOf,b as num,C as pairedNumbers,S as scalarOf,L as str,E as wildcardRegex};
@@ -0,0 +1 @@
1
+ import"./math.js";import"./logical.js";import"./lookup.js";import"./array.js";import"./text.js";import"./date.js";import"./info.js";import"./stat.js";import"./financial.js";import"./engineering.js";import"./database.js";import"../../celltypes/barcode.js";import"../../calcx/functions/index.js";import"../../sparklines/functions.js";
@@ -0,0 +1 @@
1
+ import{setCategory as I}from"./registry.js";import{lift as m,raw as f}from"./registry.js";import{Arr as R,ERR as o,Lambda as S,num as y,OMITTED as A,Ref as i,RefList as p,RichValue as L,XlError as E}from"../values.js";import{CONTENT_MASK as w,FORMULA as g}from"../../core/sheet.js";import{cellRef as b,colName as T,sheetPrefix as O}from"../../core/address.js";import{newBookName as k}from"../../core/default-names.js";import{str as d}from"../values.js";I("Information");const s=(e,t)=>m(e,1,1,t,{errors:!0});s("ISERROR",e=>e instanceof E),s("ISERR",e=>e instanceof E&&e!==o.NA),s("ISNA",e=>e===o.NA),s("ISNUMBER",e=>typeof e=="number"),s("ISTEXT",e=>typeof e=="string"),s("ISNONTEXT",e=>typeof e!="string"),s("ISLOGICAL",e=>typeof e=="boolean"),s("ISBLANK",e=>e==null),m("ISEVEN",1,1,e=>Math.trunc(y(e))%2===0),m("ISODD",1,1,e=>Math.trunc(y(e))%2!==0),f("ISREF",1,1,(e,t)=>t[0]instanceof i||t[0]instanceof p),f("ISFORMULA",1,1,(e,t)=>{const r=t[0];if(!(r instanceof i))throw o.VALUE;return(r.sheet.kind(r.r0,r.c0)&g)!==0}),m("N",1,1,e=>{if(typeof e=="number")return e;if(typeof e=="boolean")return e?1:0;if(e instanceof L)throw o.VALUE;return 0}),m("NA",0,0,()=>o.NA),s("ERROR.TYPE",e=>{if(!(e instanceof E))throw o.NA;return{"#NULL!":1,"#DIV/0!":2,"#VALUE!":3,"#REF!":4,"#NAME?":5,"#NUM!":6,"#N/A":7,"#GETTING_DATA":8,"#SPILL!":9,"#FIELD!":13,"#CALC!":14}[e.code]}),f("TYPE",1,1,(e,t)=>{const r=t[0]instanceof i&&t[0].isCell?e.read(t[0].sheet,t[0].r0,t[0].c0):t[0];return r instanceof i||r instanceof p||r instanceof R?64:r===null||typeof r=="number"?1:typeof r=="string"?2:typeof r=="boolean"?4:r instanceof E?16:r instanceof S||r instanceof L?128:1}),f("SHEET",0,1,(e,t,r,u,c)=>{if(t.length===0||t[0]===A)return e.book.sheets.indexOf(c)+1;if(t[0]instanceof i)return e.book.sheets.indexOf(t[0].sheet)+1;if(typeof t[0]=="string"){const h=e.sheetByName(t[0]);if(!h)throw o.NA;return e.book.sheets.indexOf(h)+1}throw o.VALUE}),f("SHEETS",0,1,(e,t)=>{if(t.length===0||t[0]===A)return e.book.sheets.length;if(t[0]instanceof p)return new Set(t[0].refs.map(r=>r.sheet)).size;if(t[0]instanceof i)return 1;throw o.REF}),f("INFO",1,1,(e,t,r,u)=>{switch(d(e.scalar(t[0],r,u)).toLowerCase()){case"numfile":return e.book.sheets.length;case"recalc":return e.manual?"Manual":"Automatic";case"release":return"16.0";case"system":return"mac";case"origin":return"$A:$A$1";case"directory":return"";default:throw o.VALUE}}),f("CELL",1,2,(e,t,r,u,c)=>{const h=d(e.scalar(t[0],r,u)).toLowerCase(),n=t[1]===void 0||t[1]===A?new i(c,r,u,r,u):t[1];if(!(n instanceof i))throw o.VALUE;const a=e.read(n.sheet,n.r0,n.c0),l=e.book.styles.get(n.sheet.style(n.r0,n.c0));switch(h){case"address":{const N=`$${T(n.c0)}$${n.r0+1}`;return n.sheet===c?N:`${O(n.sheet.name,{book:e.book.fileName??k()})}${N}`}case"col":return n.c0+1;case"row":return n.r0+1;case"contents":return a===null?0:a;case"filename":return"";case"type":return a===null?"b":typeof a=="string"?"l":"v";case"width":return Math.round(n.sheet.cols.sizeOf(n.c0)/6);case"color":return/\[red\]/i.test(l.numFmt)?1:0;case"format":return F(l.numFmt);case"parentheses":return/\(/.test(l.numFmt)?1:0;case"prefix":return typeof a=="string"?l.hAlign==="right"?'"':l.hAlign==="center"?"^":"'":"";case"protect":return 1;default:throw o.VALUE}});function F(e){return e==="General"?"G":e==="0"?"F0":e==="#,##0"?",0":e==="0.00"?"F2":e==="#,##0.00"?",2":/%/.test(e)?`P${(/\.(0+)/.exec(e)?.[1]??"").length}`:/E\+/i.test(e)?"S2":/[ymd]/i.test(e)?"D1":"G"}export{w as CONTENT_MASK,b as cellRef};
@@ -0,0 +1 @@
1
+ import{setCategory as D}from"./registry.js";import{lazy as N,lift as U,raw as h}from"./registry.js";import{Arr as l,bool as T,ERR as d,Lambda as B,OMITTED as R,Ref as b,RefList as F,XlError as m}from"../values.js";import{compareValues as Y}from"../values.js";import{eachValue as W}from"./helpers.js";D("Logical");for(const n of["LET","LAMBDA"])N(n,0,255,()=>{throw new Error(`${n} compiles directly`)});U("TRUE",0,0,()=>!0),U("FALSE",0,0,()=>!1),U("NOT",1,1,n=>!T(n));function k(n,t,r){let o=!1;for(const s of t)if(s instanceof b||s instanceof F||s instanceof l)W(n,s,e=>{if(e instanceof m)throw e;(typeof e=="number"||typeof e=="boolean")&&(o=!0,r(typeof e=="number"?e!==0:e))});else{if(s instanceof m)throw s;typeof s=="string"&&!/^(TRUE|FALSE)$/i.test(s)||(s!==R&&s!==null?(o=!0,r(T(s))):s===R&&(o=!0,r(!1)))}if(!o)throw d.VALUE}h("AND",1,255,(n,t)=>{let r=!0;return k(n,t,o=>{o||(r=!1)}),r},{array:!0}),h("OR",1,255,(n,t)=>{let r=!1;return k(n,t,o=>{o&&(r=!0)}),r},{array:!0}),h("XOR",1,255,(n,t)=>{let r=!1;return k(n,t,o=>{o&&(r=!r)}),r},{array:!0});const p=(n,t,r,o)=>t instanceof b?t.isCell?n.read(t.sheet,t.r0,t.c0):n.refAuto(t,r,o):t instanceof F?d.VALUE:t;function V(n){if(n instanceof m)throw n;return T(n)}function X(n,t,r,o,s,e,f){const a=r?r(s,e,f):!0,i=o?o(s,e,f):!1,c=p(n,a,s,e),u=p(n,i,s,e),M=Math.max(t.rows,c instanceof l?c.rows:1,u instanceof l?u.rows:1),L=Math.max(t.cols,c instanceof l?c.cols:1,u instanceof l?u.cols:1),g=(A,y,O)=>{if(!(A instanceof l))return A;const w=A.rows===1?0:y,S=A.cols===1?0:O;return w<A.rows&&S<A.cols?A.get(w,S):d.NA},C=new Array(M*L);for(let A=0;A<M;A++)for(let y=0;y<L;y++){const O=g(t,A,y);let w;if(O instanceof m)w=O;else try{w=T(O)?g(c,A,y):g(u,A,y)}catch(S){w=S}C[A*L+y]=w===R?0:w}return new l(M,L,C)}N("IF",2,3,(n,t,r,o,s)=>{const e=p(n,t[0](r,o,s),r,o);if(e instanceof l)return X(n,e,t[1],t[2],r,o,s);if(V(e)){const a=t[1](r,o,s);return a===R?0:a}if(t.length<3)return!1;const f=t[2](r,o,s);return f===R?0:f},{passes:n=>n>0}),N("IFS",2,254,(n,t,r,o,s)=>{if(t.length%2!==0)throw d.NA;for(let e=0;e<t.length;e+=2){const f=p(n,t[e](r,o,s),r,o),a=f instanceof l?f.data[0]:f;if(V(a))return t[e+1](r,o,s)}throw d.NA},{passes:n=>n%2===1}),N("IFERROR",2,2,(n,t,r,o,s)=>{let e=p(n,t[0](r,o,s),r,o);if(e instanceof l){const f=p(n,t[1](r,o,s),r,o);return new l(e.rows,e.cols,e.data.map(a=>a instanceof m?f instanceof l?f.data[0]:f:a))}return e instanceof m&&(e=t[1](r,o,s)),e===R?"":e},{passes:()=>!0}),N("IFNA",2,2,(n,t,r,o,s)=>{const e=p(n,t[0](r,o,s),r,o);if(e instanceof l){const f=p(n,t[1](r,o,s),r,o);return new l(e.rows,e.cols,e.data.map(a=>a===d.NA?f instanceof l?f.data[0]:f:a))}return e===d.NA?t[1](r,o,s):e},{passes:()=>!0}),N("SWITCH",3,255,(n,t,r,o,s)=>{const e=i=>{const c=p(n,i(r,o,s),r,o);return c instanceof l?c.data[0]:c},f=e(t[0]);if(f instanceof m)throw f;let a=1;for(;a+1<t.length;a+=2){const i=e(t[a]);if(i instanceof m)throw i;if(typeof i==typeof f&&Y(i,f)===0)return t[a+1](r,o,s)}if(a<t.length)return t[a](r,o,s);throw d.NA},{passes:(n,t)=>n>1&&(n%2===0||n===t-1)});const I=n=>{if(n instanceof m)throw n;if(!(n instanceof B))throw d.VALUE;return n},E=(n,t,r,o)=>{const s=t instanceof b?n.refAuto(t,r,o):t;return s instanceof l?s.data[0]:s};h("MAP",2,255,(n,t,r,o,s)=>{const e=I(t[t.length-1]),f=t.slice(0,-1).map(u=>n.toArr(u)),{rows:a,cols:i}=f[0],c=new Array(a*i);for(let u=0;u<c.length;u++){const M=n.invoke(e,f.map(L=>L.data[u]??d.NA),r,o,s);c[u]=E(n,M,r,o)}return new l(a,i,c)}),h("REDUCE",2,3,(n,t,r,o,s)=>{const e=t.length===3,f=I(t[t.length-1]),a=n.toArr(t[e?1:0]).data;let i=e?t[0]:a[0];for(let c=e?0:1;c<a.length;c++)i=n.invoke(f,[i,a[c]],r,o,s);return i}),h("SCAN",2,3,(n,t,r,o,s)=>{const e=t.length===3,f=I(t[t.length-1]),a=n.toArr(t[e?1:0]);let i=e?E(n,t[0],r,o):a.data[0];const c=new Array(a.data.length);for(let u=0;u<a.data.length;u++){if(u===0&&!e){c[0]=i;continue}i=E(n,n.invoke(f,[i,a.data[u]],r,o,s),r,o),c[u]=i}return new l(a.rows,a.cols,c)}),h("BYROW",2,2,(n,t,r,o,s)=>{const e=n.toArr(t[0]),f=I(t[1]),a=new Array(e.rows);for(let i=0;i<e.rows;i++){const c=new l(1,e.cols,e.data.slice(i*e.cols,(i+1)*e.cols));a[i]=E(n,n.invoke(f,[c],r,o,s),r,o)}return new l(e.rows,1,a)}),h("BYCOL",2,2,(n,t,r,o,s)=>{const e=n.toArr(t[0]),f=I(t[1]),a=new Array(e.cols);for(let i=0;i<e.cols;i++){const c=new Array(e.rows);for(let u=0;u<e.rows;u++)c[u]=e.get(u,i);a[i]=E(n,n.invoke(f,[new l(e.rows,1,c)],r,o,s),r,o)}return new l(1,e.cols,a)}),h("MAKEARRAY",3,3,(n,t,r,o,s)=>{const e=Math.trunc(E(n,t[0],r,o)),f=Math.trunc(E(n,t[1],r,o)),a=I(t[2]);if(!(e>=1)||!(f>=1))throw d.VALUE;const i=new Array(e*f);for(let c=0;c<e;c++)for(let u=0;u<f;u++)i[c*f+u]=E(n,n.invoke(a,[c+1,u+1],r,o,s),r,o);return new l(e,f,i)}),h("ISOMITTED",1,1,(n,t)=>t[0]===void 0||t[0]===R);
@@ -0,0 +1 @@
1
+ import{setCategory as H}from"./registry.js";import{lazy as K,raw as E}from"./registry.js";import{Arr as p,compareValues as F,ERR as w,num as m,OMITTED as B,Ref as A,RefList as T,str as I,XlError as O}from"../values.js";import{hasWildcards as W,scalarOf as y,wildcardRegex as j}from"./helpers.js";import{colName as z,MAX_COLS as C,MAX_ROWS as _,parseRangeRef as G,sheetPrefix as P}from"../../core/address.js";import{FORMULA as Y}from"../../core/sheet.js";H("Lookup & Reference");const q=64,R=n=>n===void 0||n===B;function M(n,t){if(t instanceof O)throw t;if(t instanceof A){const r=n.trim(t),s=t.cols===1,e=t.rows===1,i=s?t.rows:e?t.cols:t.rows*t.cols;if(s)return{ref:t,length:i,usedLength:r.r1-t.r0+1,at:f=>n.read(t.sheet,t.r0+f,t.c0)};if(e)return{ref:t,length:i,usedLength:r.c1-t.c0+1,at:f=>n.read(t.sheet,t.r0,t.c0+f)};const o=n.toArr(t);return{length:o.data.length,usedLength:o.data.length,at:f=>o.data[f]}}return t instanceof p?{length:t.data.length,usedLength:t.data.length,at:r=>t.data[r]}:{length:1,usedLength:1,at:()=>t}}const U=(n,t)=>typeof n==typeof t;function V(n,t,r,s,e=!1){if(r==null&&(r=0),typeof r=="string"&&s&&W(r)){const i=j(r);if(e)for(let o=t.usedLength-1;o>=0;o--){const f=t.at(o);if(typeof f=="string"&&i.test(f))return o}else for(let o=0;o<t.usedLength;o++){const f=t.at(o);if(typeof f=="string"&&i.test(f))return o}return-1}if(!e&&t.ref&&t.usedLength>q){const i=n.exactIndex(t.ref),o=typeof r=="string"?`s${r.toLowerCase()}`:typeof r=="number"?r:`b${r}`,f=i.get(o);return f===void 0?-1:f}if(e){for(let i=t.usedLength-1;i>=0;i--){const o=t.at(i);if(o!==null&&U(o,r)&&F(o,r)===0)return i}return-1}for(let i=0;i<t.usedLength;i++){const o=t.at(i);if(o!==null&&U(o,r)&&F(o,r)===0)return i}return-1}function S(n,t){let r=0,s=n.usedLength-1,e=-1;for(;r<=s;){let i=r+s>>>1,o=i;for(;o<=s;){const f=n.at(o);if(f!==null&&U(f,t))break;o++}if(o>s){s=i-1;continue}i=o,F(n.at(i),t)<=0?(e=i,r=i+1):s=i-1}return e}function J(n,t){let r=-1;for(let s=0;s<n.usedLength;s++){const e=n.at(s);if(!(e===null||!U(e,t)))if(F(e,t)>=0)r=s;else break}return r}E("MATCH",2,3,(n,t,r,s)=>{const e=y(n,t[0],r,s),i=R(t[2])?1:m(n.scalar(t[2],r,s)),o=t[1]instanceof A&&!(t[1].rows===1||t[1].cols===1)?null:t[1];if(o===null)throw w.NA;if(o instanceof p&&o.rows>1&&o.cols>1)throw w.NA;const f=M(n,o);let c;if(i===0?c=V(n,f,e,!0):i>0?c=S(f,e===null?0:e):c=J(f,e===null?0:e),c<0)throw w.NA;return c+1},{array:!0});function X(n,t,r,s,e){const i=y(n,t[0],r,s);if(t[1]instanceof O)throw t[1];const o=Math.trunc(m(n.scalar(t[2],r,s))),f=R(t[3])?!0:!!m(n.scalar(t[3],r,s));if(o<1)throw w.VALUE;const c=t[1],h=i===null?0:i;let a,l;if(c instanceof A)if(e){if(o>c.cols)throw w.REF;a=M(n,new A(c.sheet,c.r0,c.c0,c.r1,c.c0)),l=g=>n.read(c.sheet,c.r0+g,c.c0+o-1)}else{if(o>c.rows)throw w.REF;a=M(n,new A(c.sheet,c.r0,c.c0,c.r0,c.c1)),l=g=>n.read(c.sheet,c.r0+o-1,c.c0+g)}else{const g=n.toArr(c),b=e?g.rows:g.cols;if(o>(e?g.cols:g.rows))throw w.REF;a={length:b,usedLength:b,at:L=>e?g.get(L,0):g.get(0,L)},l=L=>e?g.get(L,o-1):g.get(o-1,L)}const u=f?S(a,h):V(n,a,h,!0);if(u<0)throw w.NA;const d=l(u);return d===null?0:d}E("VLOOKUP",3,4,(n,t,r,s)=>X(n,t,r,s,!0),{array:!0}),E("HLOOKUP",3,4,(n,t,r,s)=>X(n,t,r,s,!1),{array:!0}),E("LOOKUP",2,3,(n,t,r,s)=>{const e=y(n,t[0],r,s),i=e===null?0:e;let o=t[1],f=R(t[2])?null:t[2];if(f===null){const l=n.toArr(o);l.rows>=l.cols?(o=new p(l.rows,1,Array.from({length:l.rows},(u,d)=>l.get(d,0))),f=new p(l.rows,1,Array.from({length:l.rows},(u,d)=>l.get(d,l.cols-1)))):(o=new p(1,l.cols,Array.from({length:l.cols},(u,d)=>l.get(0,d))),f=new p(1,l.cols,Array.from({length:l.cols},(u,d)=>l.get(l.rows-1,d))))}const c=M(n,o),h=S(c,i);if(h<0)throw w.NA;const a=M(n,f).at(h);return a===null?0:a},{array:!0});function k(n,t,r,s,e){const i=r===null?0:r;if(e===2||e===-2){const a=e===2;let l=0,u=t.usedLength-1,d=-1,g=-1,b=-1;for(;l<=u;){const L=l+u>>>1,N=F(t.at(L),i);if(N===0){d=L;break}(a?N<0:N>0)?(a?g=L:b=L,l=L+1):(a?b=L:g=L,u=L-1)}return d>=0?d:s===-1?g:s===1?b:-1}const o=e===-1;if(s===0)return V(n,t,i,!1,o);if(s===2)return V(n,t,i,!0,o);let f=-1,c=null;const h=t.usedLength;for(let a=0;a<h;a++){const l=o?h-1-a:a,u=t.at(l);if(u===null||!U(u,i))continue;const d=F(u,i);if(d===0)return l;(s===-1&&d<0&&(f<0||F(u,c)>0)||s===1&&d>0&&(f<0||F(u,c)<0))&&(f=l,c=u)}return f}function Q(n,t){const r=n.length;for(let s=0;s<r;s++){const e=t<0?r-1-s:s;if(n.at(e)===null)return e}return-1}E("XMATCH",2,4,(n,t,r,s)=>{const e=y(n,t[0],r,s),i=R(t[2])?0:Math.trunc(m(n.scalar(t[2],r,s))),o=R(t[3])?1:Math.trunc(m(n.scalar(t[3],r,s)));if(![0,-1,1,2].includes(i)||![1,-1,2,-2].includes(o))throw w.VALUE;const f=k(n,M(n,t[1]),e,i,o);if(f<0)throw w.NA;return f+1},{array:!0}),E("XLOOKUP",3,6,(n,t,r,s)=>{const e=y(n,t[0],r,s),i=R(t[4])?0:Math.trunc(m(n.scalar(t[4],r,s))),o=R(t[5])?1:Math.trunc(m(n.scalar(t[5],r,s)));if(![0,-1,1,2].includes(i)||![1,-1,2,-2].includes(o))throw w.VALUE;if(t[1]instanceof O)throw t[1];const f=t[1]instanceof A?t[1].rows:n.toArr(t[1]).rows,c=t[1]instanceof A?t[1].cols:n.toArr(t[1]).cols;if(f>1&&c>1)throw w.VALUE;const h=R(t[0])?Q(M(n,t[1]),o):k(n,M(n,t[1]),e,i,o);if(h<0){if(R(t[3]))throw w.NA;return t[3]}const a=c===1,l=t[2];if(l instanceof A)return a?new A(l.sheet,l.r0+h,l.c0,l.r0+h,l.c1):new A(l.sheet,l.r0,l.c0+h,l.r1,l.c0+h);const u=n.toArr(l);return a?u.cols===1?u.get(h,0):new p(1,u.cols,u.data.slice(h*u.cols,(h+1)*u.cols)):u.rows===1?u.get(0,h):new p(u.rows,1,Array.from({length:u.rows},(d,g)=>u.get(g,h)))},{array:!0,refResult:!0}),E("INDEX",2,4,(n,t,r,s)=>{let e=t[0];if(e instanceof O)throw e;const i=R(t[1])?0:Math.trunc(m(n.scalar(t[1],r,s))),o=R(t[2])?0:Math.trunc(m(n.scalar(t[2],r,s)));if(e instanceof T){const a=R(t[3])?1:Math.trunc(m(n.scalar(t[3],r,s)));if(a<1||a>e.refs.length)throw w.REF;e=e.refs[a-1]}if(i<0||o<0)throw w.VALUE;if(e instanceof A){let a=i,l=o;if((t.length===2||R(t[2]))&&e.rows===1&&e.cols>1&&(l=a,a=0),a>e.rows||l>e.cols)throw w.REF;const u=a===0?e.r0:e.r0+a-1,d=a===0?e.r1:u,g=l===0?e.c0:e.c0+l-1,b=l===0?e.c1:g;return new A(e.sheet,u,g,d,b)}const f=n.toArr(e);let c=i,h=o;if(t.length===2&&f.rows===1&&(h=c,c=0,h===0))return f;if(t.length===2&&f.cols===1&&(h=1),c>f.rows||h>f.cols)throw w.REF;return c===0&&h===0?f:c===0?new p(f.rows,1,Array.from({length:f.rows},(a,l)=>f.get(l,h-1))):h===0?new p(1,f.cols,f.data.slice((c-1)*f.cols,c*f.cols)):f.get(c-1,h-1)},{array:!0,refResult:!0}),E("OFFSET",3,5,(n,t,r,s)=>{const e=t[0];if(e instanceof O)throw e;if(!(e instanceof A))throw w.VALUE;const i=Math.trunc(m(n.scalar(t[1],r,s))),o=Math.trunc(m(n.scalar(t[2],r,s))),f=R(t[3])?e.rows:Math.trunc(m(n.scalar(t[3],r,s))),c=R(t[4])?e.cols:Math.trunc(m(n.scalar(t[4],r,s)));if(f===0||c===0)throw w.REF;const h=e.r0+i+(f<0?f+1:0),a=e.c0+o+(c<0?c+1:0),l=h+Math.abs(f)-1,u=a+Math.abs(c)-1;if(h<0||a<0||l>=_||u>=C)throw w.REF;return new A(e.sheet,h,a,l,u)},{volatile:!0,refResult:!0}),E("INDIRECT",1,2,(n,t,r,s,e)=>{const i=I(y(n,t[0],r,s)).trim(),o=R(t[1])?!0:!!y(n,t[1],r,s);let f=e,c=i;const h=i.lastIndexOf("!");if(h>=0){if(f=n.sheetByName(i.slice(0,h).replace(/^'|'$/g,"").replace(/''/g,"'")),f===null)throw w.REF;c=i.slice(h+1)}if(!o){const u=/^R(\[-?\d+\]|\d+)?C(\[-?\d+\]|\d+)?(?::R(\[-?\d+\]|\d+)?C(\[-?\d+\]|\d+)?)?$/i.exec(c);if(!u)throw w.REF;const d=($,D)=>$===void 0?D:$[0]==="["?D+Number($.slice(1,-1)):Number($)-1,g=d(u[1],r),b=d(u[2],s),L=u[3]===void 0&&u[4]===void 0?g:d(u[3],r),N=u[3]===void 0&&u[4]===void 0?b:d(u[4],s);if(g<0||b<0||L>=_||N>=C)throw w.REF;return new A(f,Math.min(g,L),Math.min(b,N),Math.max(g,L),Math.max(b,N))}const a=G(c.replace(/\$/g,""));if(a!==null)return new A(f,a.r0,a.c0,a.r1,a.c1);const l=n.evalName(c,r,s,f);if(l instanceof A)return l;throw w.REF},{volatile:!0,refResult:!0}),E("ROW",0,1,(n,t,r)=>{if(t.length===0||R(t[0]))return r+1;const s=t[0];if(s instanceof O)throw s;if(!(s instanceof A))throw w.VALUE;return s.rows===1?s.r0+1:new p(s.rows,1,Array.from({length:s.rows},(e,i)=>s.r0+i+1))}),E("COLUMN",0,1,(n,t,r,s)=>{if(t.length===0||R(t[0]))return s+1;const e=t[0];if(e instanceof O)throw e;if(!(e instanceof A))throw w.VALUE;return e.cols===1?e.c0+1:new p(1,e.cols,Array.from({length:e.cols},(i,o)=>e.c0+o+1))}),E("ROWS",1,1,(n,t)=>{const r=t[0];if(r instanceof O)throw r;if(r instanceof A||r instanceof p)return r.rows;if(r instanceof T)throw w.REF;return 1}),E("COLUMNS",1,1,(n,t)=>{const r=t[0];if(r instanceof O)throw r;if(r instanceof A||r instanceof p)return r.cols;if(r instanceof T)throw w.REF;return 1}),E("AREAS",1,1,(n,t)=>{if(t[0]instanceof O)throw t[0];if(t[0]instanceof T)return t[0].refs.length;if(t[0]instanceof A)return 1;throw w.VALUE}),E("ADDRESS",2,5,(n,t,r,s)=>{const e=Math.trunc(m(n.scalar(t[0],r,s))),i=Math.trunc(m(n.scalar(t[1],r,s))),o=R(t[2])?1:Math.trunc(m(n.scalar(t[2],r,s))),f=R(t[3])?!0:!!n.scalar(t[3],r,s),c=R(t[4])?null:I(n.scalar(t[4],r,s));if(e<1||i<1||e>_||i>C||o<1||o>4)throw w.VALUE;const h=o===1||o===2,a=o===1||o===3,l=f?`${a?"$":""}${z(i-1)}${h?"$":""}${e}`:`R${h?e:`[${e}]`}C${a?i:`[${i}]`}`;if(c===null)return l;if(c==="")return`!${l}`;const u=/^\[([^\]]*)\](.*)$/.exec(c);return`${u?P(u[2],{book:u[1]}):P(c)}${l}`}),K("CHOOSE",2,255,(n,t,r,s,e)=>{const i=n.scalar(t[0](r,s,e),r,s);if(i instanceof O)throw i;const o=Math.trunc(m(i));if(o<1||o>=t.length)throw w.VALUE;return t[o](r,s,e)},{passes:n=>n>0}),E("FORMULATEXT",1,1,(n,t)=>{const r=t[0];if(!(r instanceof A))throw w.NA;if((r.sheet.kind(r.r0,r.c0)&Y)===0)throw w.NA;if(r.sheet.protection&&n.book.styles.get(r.sheet.style(r.r0,r.c0)).hiddenFormula)throw w.NA;return n.book.editText(r.sheet,r.r0,r.c0)}),E("HYPERLINK",1,2,(n,t,r,s)=>{const e=R(t[1])?t[0]:t[1],i=n.scalar(e,r,s);return i===null?0:i}),E("GETPIVOTDATA",2,255,()=>{throw w.REF});
@@ -0,0 +1 @@
1
+ import{setCategory as z}from"./registry.js";import{alias as J,lift as u,raw as m}from"./registry.js";import{Arr as d,bool as K,checked as L,ERR as c,int as b,num as i,OMITTED as A,opt as Z,power as $,Ref as p,RefList as O,str as F,XlError as V}from"../values.js";import{collectNumbers as q,eachValue as x,makeCriteria as tt,matrixOf as R}from"./helpers.js";z("Math & Trig");const l=(t,r)=>u(t,1,1,o=>L(r(i(o))));l("ABS",Math.abs),l("ACOS",t=>{if(t<-1||t>1)throw c.NUM;return Math.acos(t)}),l("ACOSH",t=>{if(t<1)throw c.NUM;return Math.acosh(t)}),l("ACOT",t=>Math.PI/2-Math.atan(t)),l("ACOTH",t=>{if(Math.abs(t)<=1)throw c.NUM;return .5*Math.log((t+1)/(t-1))}),l("ASIN",t=>{if(t<-1||t>1)throw c.NUM;return Math.asin(t)}),l("ASINH",Math.asinh),l("ATAN",Math.atan),l("ATANH",t=>{if(t<=-1||t>=1)throw c.NUM;return Math.atanh(t)}),l("COS",Math.cos),l("COSH",Math.cosh),l("COT",t=>{if(t===0)throw c.DIV0;return 1/Math.tan(t)}),l("COTH",t=>{if(t===0)throw c.DIV0;return 1/Math.tanh(t)}),l("CSC",t=>{if(t===0)throw c.DIV0;return 1/Math.sin(t)}),l("CSCH",t=>{if(t===0)throw c.DIV0;return 1/Math.sinh(t)}),l("DEGREES",t=>t*180/Math.PI),l("EXP",Math.exp),l("INT",Math.floor),l("LN",t=>{if(t<=0)throw c.NUM;return Math.log(t)}),l("LOG10",t=>{if(t<=0)throw c.NUM;return Math.log10(t)}),l("RADIANS",t=>t*Math.PI/180),l("SEC",t=>1/Math.cos(t)),l("SECH",t=>1/Math.cosh(t)),l("SIGN",Math.sign),l("SIN",Math.sin),l("SINH",Math.sinh),l("SQRT",t=>{if(t<0)throw c.NUM;return Math.sqrt(t)}),l("SQRTPI",t=>{if(t<0)throw c.NUM;return Math.sqrt(t*Math.PI)}),l("TAN",Math.tan),l("TANH",Math.tanh),u("ATAN2",2,2,(t,r)=>{const o=i(t),n=i(r);if(o===0&&n===0)throw c.DIV0;return Math.atan2(n,o)}),u("LOG",1,2,(t,r)=>{const o=i(t),n=r===void 0||r===A?10:i(r);if(o<=0||n<=0)throw c.NUM;if(n===1)throw c.DIV0;return n===10?Math.log10(o):Math.log(o)/Math.log(n)}),u("PI",0,0,()=>Math.PI),u("POWER",2,2,(t,r)=>{const o=i(t),n=i(r);if(o===0&&n===0)throw c.NUM;if(o===0&&n<0)throw c.DIV0;return L($(o,n))}),u("MOD",2,2,(t,r)=>{const o=i(t),n=i(r);if(n===0)throw c.DIV0;if(Math.abs(o/n)>=2**40)throw c.NUM;return L(o-n*Math.floor(o/n))}),u("QUOTIENT",2,2,(t,r)=>{const o=i(r);if(o===0)throw c.DIV0;return Math.trunc(i(t)/o)});function k(t,r){if(!Number.isFinite(t))throw c.NUM;r>15&&(r=15);const o=10**Math.abs(r),n=r>=0?Math.abs(t)*o:Math.abs(t)/o,e=Number(n.toPrecision(15)),s=Math.floor(e+.5),f=r>=0?s/o:s*o;return t<0?-f:f}function y(t,r,o){r>15&&(r=15);const n=10**Math.abs(r),e=r>=0?Math.abs(t)*n:Math.abs(t)/n,s=Number(e.toPrecision(15)),f=o?Math.ceil(s):Math.floor(s),a=r>=0?f/n:f*n;return t<0?-a:a}u("ROUND",2,2,(t,r)=>k(i(t),b(r))),u("ROUNDUP",2,2,(t,r)=>y(i(t),b(r),!0)),u("ROUNDDOWN",2,2,(t,r)=>y(i(t),b(r),!1)),u("TRUNC",1,2,(t,r)=>y(i(t),r===void 0||r===A?0:b(r),!1)),u("EVEN",1,1,t=>{const r=i(t),o=Math.ceil(Number((Math.abs(r)/2).toPrecision(15)))*2;return r<0?-o:o}),u("ODD",1,1,t=>{const r=Math.abs(i(t));let o=Math.ceil(Number(r.toPrecision(15)));return o%2===0&&(o+=1),i(t)<0?-o:o}),u("MROUND",2,2,(t,r)=>{const o=i(t),n=i(r);if(n===0)return 0;if(o*n<0)throw c.NUM;return k(o/n,0)*n});function g(t,r){const o=Number((t/r).toPrecision(15));return Math.ceil(o)*r}function S(t,r){const o=Number((t/r).toPrecision(15));return Math.floor(o)*r}u("CEILING",2,2,(t,r)=>{const o=i(t),n=i(r);if(n===0)return 0;if(o>0&&n<0)throw c.NUM;return o<0&&n<0?-g(-o,-n):g(o,n)}),u("FLOOR",2,2,(t,r)=>{const o=i(t),n=i(r);if(n===0){if(o===0)return 0;throw c.DIV0}if(o>0&&n<0)throw c.NUM;return o<0&&n<0?-S(-o,-n):S(o,n)}),u("CEILING.MATH",1,3,(t,r,o)=>{const n=i(t),e=Math.abs(r===void 0||r===A?1:i(r))||0;if(e===0)return 0;const s=o===void 0||o===A?0:i(o);return n<0&&s!==0?-g(-n,e):g(n,e)}),u("FLOOR.MATH",1,3,(t,r,o)=>{const n=i(t),e=Math.abs(r===void 0||r===A?1:i(r))||0;if(e===0)return 0;const s=o===void 0||o===A?0:i(o);return n<0&&s!==0?-S(-n,e):S(n,e)}),u("CEILING.PRECISE",1,2,(t,r)=>{const o=Math.abs(r===void 0||r===A?1:i(r));return o===0?0:g(i(t),o)}),J("ISO.CEILING","CEILING.PRECISE"),u("FLOOR.PRECISE",1,2,(t,r)=>{const o=Math.abs(r===void 0||r===A?1:i(r));return o===0?0:S(i(t),o)});function rt(t){if(t<0)throw c.NUM;if(t>170)throw c.NUM;let r=1;for(let o=2;o<=t;o++)r*=o;return r}u("FACT",1,1,t=>rt(Math.floor(i(t)))),u("FACTDOUBLE",1,1,t=>{const r=Math.floor(i(t));if(r<-1)throw c.NUM;let o=1;for(let n=r;n>1;n-=2)o*=n;return L(o)});function P(t,r){if(r<0||t<0||r>t)throw c.NUM;const o=Math.min(r,t-r);let n=1;for(let e=1;e<=o;e++)n=n*(t-o+e)/e;return L(Math.round(n))}u("COMBIN",2,2,(t,r)=>P(Math.trunc(i(t)),Math.trunc(i(r)))),u("COMBINA",2,2,(t,r)=>{const o=Math.trunc(i(t)),n=Math.trunc(i(r));if(o<0||n<0)throw c.NUM;return o===0&&n===0?1:o===0?0:P(o+n-1,n)});function j(t,r){for(;r!==0;)[t,r]=[r,t%r];return t}const H=(t,r)=>{const o=[];for(const n of r)if(n instanceof p||n instanceof O||n instanceof d)x(t,n,e=>{if(e instanceof V)throw e;if(typeof e=="number"){if(e<0)throw c.NUM;o.push(Math.trunc(e))}else if(typeof e=="string")throw c.VALUE});else{const e=Math.trunc(i(n));if(e<0)throw c.NUM;o.push(e)}return o};m("GCD",1,255,(t,r)=>H(t,r).reduce(j,0)),m("LCM",1,255,(t,r)=>{let o=1;for(const n of H(t,r)){if(n===0)return 0;o=o/j(o,n)*n}return L(o)}),m("MULTINOMIAL",1,255,(t,r)=>{const o=H(t,r);let n=0,e=1;for(const s of o)n+=s,e*=P(n,s);return L(e)}),u("ARABIC",1,1,t=>{const r=F(t).trim().toUpperCase();if(r==="")return 0;const o=r[0]==="-",n=o?r.slice(1):r,e={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};let s=0;for(let f=0;f<n.length;f++){const a=e[n[f]];if(a===void 0)throw c.VALUE;const h=e[n[f+1]]??0;s+=a<h?-a:a}return o?-s:s}),u("ROMAN",1,2,(t,r)=>{const o=Math.trunc(i(t)),n=r===void 0||r===A?0:typeof r=="boolean"?r?0:4:Math.trunc(i(r));if(o<0||o>3999)throw c.VALUE;if(n<0||n>4)throw c.VALUE;if(o===0)return"";const e={0:[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],1:[[1e3,"M"],[950,"LM"],[900,"CM"],[500,"D"],[450,"LD"],[400,"CD"],[100,"C"],[95,"VC"],[90,"XC"],[50,"L"],[45,"VL"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],2:[[1e3,"M"],[990,"XM"],[950,"LM"],[900,"CM"],[500,"D"],[490,"XD"],[450,"LD"],[400,"CD"],[100,"C"],[99,"IC"],[95,"VC"],[90,"XC"],[50,"L"],[49,"IL"],[45,"VL"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],3:[[1e3,"M"],[995,"VM"],[990,"XM"],[950,"LM"],[900,"CM"],[500,"D"],[495,"VD"],[490,"XD"],[450,"LD"],[400,"CD"],[100,"C"],[99,"IC"],[95,"VC"],[90,"XC"],[50,"L"],[49,"IL"],[45,"VL"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],4:[[1e3,"M"],[999,"IM"],[995,"VM"],[990,"XM"],[950,"LM"],[900,"CM"],[500,"D"],[499,"ID"],[495,"VD"],[490,"XD"],[450,"LD"],[400,"CD"],[100,"C"],[99,"IC"],[95,"VC"],[90,"XC"],[50,"L"],[49,"IL"],[45,"VL"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]]};let s=o,f="";for(const[a,h]of e[n])for(;s>=a;)f+=h,s-=a;return f}),u("BASE",2,3,(t,r,o)=>{const n=Math.trunc(i(t)),e=Math.trunc(i(r)),s=o===void 0||o===A?0:Math.trunc(i(o));if(n<0||n>=2**53||e<2||e>36||s<0||s>255)throw c.NUM;return n.toString(e).toUpperCase().padStart(s,"0")}),u("DECIMAL",2,2,(t,r)=>{const o=F(t).trim().toLowerCase(),n=Math.trunc(i(r));if(n<2||n>36||o.length>255)throw c.NUM;let e=0;for(const s of o){const f=parseInt(s,36);if(Number.isNaN(f)||f>=n)throw c.NUM;e=e*n+f}return L(e)}),u("RAND",0,0,()=>Math.random(),{volatile:!0}),u("RANDBETWEEN",2,2,(t,r)=>{const o=Math.ceil(i(t)),n=Math.floor(i(r));if(o>n)throw c.NUM;return o+Math.floor(Math.random()*(n-o+1))},{volatile:!0}),m("SUM",1,255,(t,r)=>{let o=0;const n={sum:0,count:0};for(const e of r)if(typeof e=="number")o+=e;else if(e instanceof p)t.sumRange(e,n);else if(e instanceof O)for(const s of e.refs)t.sumRange(s,n);else if(e instanceof d){for(const s of e.data)if(typeof s=="number")o+=s;else if(s instanceof V)throw s}else e!==null&&e!==A&&(o+=i(e));return L(o+n.sum)}),m("PRODUCT",1,255,(t,r)=>{let o=1,n=!1;for(const e of q(t,r))o*=e,n=!0;return n?L(o):0}),m("SUMSQ",1,255,(t,r)=>L(q(t,r).reduce((o,n)=>o+n*n,0)));function nt(t,r,o,n){return{row:t.r0+(o-r.r0),col:t.c0+(n-r.c0)}}function G(t,r,o){const[n,e]=o[0],s=n.rows,f=n.cols;for(const[N]of o)if(N.rows!==s||N.cols!==f)throw c.VALUE;let a=0,h=0;const M=(N,E)=>{for(let U=1;U<o.length;U++){const[C,D]=o[U];if(!D(t.read(C.sheet,C.r0+(N-n.r0),C.c0+(E-n.c0))))return!1}return!0},w=e(null),I=(N,E,U)=>{if(!(!e(N)||!M(E,U))&&(h++,r!==null)){const C=nt(r,n,E,U),D=t.read(r.sheet,C.row,C.col);if(D instanceof V)throw D;typeof D=="number"&&(a+=D)}};if(w){const N=Math.min(n.r1,Math.max(n.sheet.maxRow,n.r0)),E=Math.min(n.c1,Math.max(n.sheet.maxCol,n.c0));for(let U=n.c0;U<=E;U++)for(let C=n.r0;C<=N;C++)I(t.read(n.sheet,C,U),C,U)}else t.scan(n,I);return{sum:a,count:h}}const T=t=>{if(t instanceof V)throw t;if(!(t instanceof p))throw c.VALUE;return t},Q=(t,r,o,n)=>{const e=t.scalar(r,o,n);return tt(e)};m("SUMIF",2,3,(t,r,o,n)=>{const e=T(r[0]),s=r[2]===void 0||r[2]===A?e:T(r[2]);return G(t,s,[[e,Q(t,r[1],o,n)]]).sum}),m("SUMIFS",3,255,(t,r,o,n)=>{if(r.length%2===0)throw c.VALUE;const e=[];for(let f=1;f<r.length;f+=2)e.push([T(r[f]),Q(t,r[f+1],o,n)]);const s=T(r[0]);if(s.rows!==e[0][0].rows||s.cols!==e[0][0].cols)throw c.VALUE;return G(t,s,e).sum}),m("SUMPRODUCT",1,255,(t,r)=>{const o=r.map(a=>{if(a instanceof V)throw a;return t.toArr(a)}),{rows:n,cols:e}=o[0];for(const a of o)if(a.rows!==n||a.cols!==e)throw c.VALUE;let s=0;const f=n*e;for(let a=0;a<f;a++){let h=1;for(const M of o){const w=M.data[a];if(w instanceof V)throw w;h*=typeof w=="number"?w:0}s+=h}return L(s)},{array:!0});const ot=(t,r,o)=>{const n=t.toArr(r),e=t.toArr(o);if(n.rows!==e.rows||n.cols!==e.cols)throw c.NA;return[n.data,e.data]},v=(t,r)=>m(t,2,2,(o,n)=>{const[e,s]=ot(o,n[0],n[1]);let f=0;for(let a=0;a<e.length;a++){if(e[a]instanceof V)throw e[a];if(s[a]instanceof V)throw s[a];typeof e[a]=="number"&&typeof s[a]=="number"&&(f+=r(e[a],s[a]))}return L(f)},{array:!0});v("SUMX2MY2",(t,r)=>t*t-r*r),v("SUMX2PY2",(t,r)=>t*t+r*r),v("SUMXMY2",(t,r)=>(t-r)**2),m("SERIESSUM",4,4,(t,r,o,n)=>{const e=i(t.scalar(r[0],o,n)),s=i(t.scalar(r[1],o,n)),f=i(t.scalar(r[2],o,n));let a=0,h=0;for(const M of t.toArr(r[3]).data)a+=i(M)*e**(s+h*f),h++;return L(a)});function W(t,r,o,n,e){const{sheet:s}=r;t.scan(r,(f,a,h)=>{if(!(!o&&(s.rows.isHidden(a)||s.filteredRows?.has(a)))&&!t.isSubtotalCell(s,a,h)){if(f instanceof V){if(n)return;throw f}e.push(f)}})}function Y(t,r,o){const n=r.length,e=()=>r.reduce((a,h)=>a+h,0),s=()=>e()/n,f=a=>{const h=s();return r.reduce((M,w)=>M+(w-h)**2,0)/(a?n:n-1)};switch(t){case 1:if(n===0)throw c.DIV0;return s();case 2:return n;case 3:return o.length;case 4:return n===0?0:Math.max(...r);case 5:return n===0?0:Math.min(...r);case 6:return n===0?0:r.reduce((a,h)=>a*h,1);case 7:if(n<2)throw c.DIV0;return Math.sqrt(f(!1));case 8:if(n===0)throw c.DIV0;return Math.sqrt(f(!0));case 9:return e();case 10:if(n<2)throw c.DIV0;return f(!1);case 11:if(n===0)throw c.DIV0;return f(!0);default:throw c.VALUE}}m("SUBTOTAL",2,255,(t,r,o,n)=>{const e=Math.trunc(i(t.scalar(r[0],o,n))),s=e>=1&&e<=11,f=e>100?e-100:e;if(f<1||f>11)throw c.VALUE;const a=[];for(let h=1;h<r.length;h++){const M=r[h]instanceof O?r[h].refs:[r[h]];for(const w of M){if(!(w instanceof p))throw c.VALUE;W(t,w,s,!1,a)}}return Y(f,a.filter(h=>typeof h=="number"),a)});function X(t,r){const o=t.length;if(o===0||r<0||r>1)throw c.NUM;const n=r*(o-1),e=Math.floor(n),s=n-e;return s===0?t[e]:t[e]+s*(t[e+1]-t[e])}function B(t,r){const o=t.length,n=r*(o+1)-1;if(r<=0||r>=1||n<0||n>o-1)throw c.NUM;const e=Math.floor(n),s=n-e;return s===0?t[e]:t[e]+s*(t[e+1]-t[e])}m("AGGREGATE",3,255,(t,r,o,n)=>{const e=Math.trunc(i(t.scalar(r[0],o,n))),s=Math.trunc(i(t.scalar(r[1],o,n)));if(s<0||s>7)throw c.VALUE;const f=s===1||s===3||s===5||s===7,a=s===2||s===3||s===6||s===7,h=I=>{const N=[],E=I instanceof O?I.refs:[I];for(const U of E)if(U instanceof p)W(t,U,!f,a,N);else if(U instanceof d)for(const C of U.data)if(C instanceof V){if(!a)throw C}else C!==null&&N.push(C);else if(U instanceof V){if(!a)throw U}else U!==A&&U!==null&&U!==void 0&&N.push(i(U));return N};if(e>=1&&e<=11){const I=[];for(let N=2;N<r.length;N++){if(r[N]instanceof d)throw c.VALUE;I.push(...h(r[N]))}return Y(e,I.filter(N=>typeof N=="number"),I)}const M=h(r[2]).filter(I=>typeof I=="number").sort((I,N)=>I-N),w=i(t.scalar(r[3],o,n));switch(e){case 12:return X(M,.5);case 13:return _(M);case 14:{const I=Math.ceil(w);if(I<1||I>M.length)throw c.NUM;return M[M.length-I]}case 15:{const I=Math.ceil(w);if(I<1||I>M.length)throw c.NUM;return M[I-1]}case 16:return X(M,w);case 17:return X(M,w/4);case 18:return B(M,w);case 19:return B(M,w/4);default:throw c.VALUE}},{array:!0});function _(t){const r=new Map;let o=null,n=1;for(const e of t){const s=(r.get(e)??0)+1;r.set(e,s),s>n&&(n=s,o=e)}if(o===null)throw c.NA;return o}function et(t){const r=t.length,o=t.map(e=>e.slice());let n=1;for(let e=0;e<r;e++){let s=e;for(let f=e+1;f<r;f++)Math.abs(o[f][e])>Math.abs(o[s][e])&&(s=f);if(o[s][e]===0)return 0;s!==e&&([o[s],o[e]]=[o[e],o[s]],n=-n),n*=o[e][e];for(let f=e+1;f<r;f++){const a=o[f][e]/o[e][e];for(let h=e;h<r;h++)o[f][h]-=a*o[e][h]}}return n}m("MDETERM",1,1,(t,r)=>{const o=R(t,r[0]);if(o.length!==o[0].length)throw c.VALUE;return et(o)},{array:!0}),m("MINVERSE",1,1,(t,r)=>{const o=R(t,r[0]),n=o.length;if(n!==o[0].length)throw c.VALUE;const e=o.map((s,f)=>[...s,...s.map((a,h)=>f===h?1:0)]);for(let s=0;s<n;s++){let f=s;for(let h=s+1;h<n;h++)Math.abs(e[h][s])>Math.abs(e[f][s])&&(f=h);if(Math.abs(e[f][s])<1e-300)throw c.NUM;[e[f],e[s]]=[e[s],e[f]];const a=e[s][s];for(let h=0;h<2*n;h++)e[s][h]/=a;for(let h=0;h<n;h++){if(h===s)continue;const M=e[h][s];for(let w=0;w<2*n;w++)e[h][w]-=M*e[s][w]}}return d.of2D(e.map(s=>s.slice(n)))},{array:!0}),m("MMULT",2,2,(t,r)=>{const o=R(t,r[0]),n=R(t,r[1]);if(o[0].length!==n.length)throw c.VALUE;const e=[];for(let s=0;s<o.length;s++){const f=[];for(let a=0;a<n[0].length;a++){let h=0;for(let M=0;M<n.length;M++)h+=o[s][M]*n[M][a];f.push(h)}e.push(f)}return d.of2D(e)},{array:!0}),u("MUNIT",1,1,t=>{const r=Math.trunc(i(t));if(r<1)throw c.VALUE;const o=new Array(r*r).fill(0);for(let n=0;n<r;n++)o[n*r+n]=1;return new d(r,r,o)});export{K as bool,_ as modeOf,Z as opt,B as percentileExc,X as percentileInc,G as sumIfs};
@@ -0,0 +1 @@
1
+ const c=new Map,x=255,r=new Map;let i="Other";const u=["Financial","Logical","Text","Date & Time","Lookup & Reference","Math & Trig","Statistical","Engineering","Information","Database","Barcode","Sparkline"];function d(t){i=t}const y=t=>[...r.get(t)??[]].sort();function f(t,e=i){r.has(e)||r.set(e,new Set),r.get(e).add(t)}function s(t,e,o,n,a,l={}){const{category:p,...g}=l;f(e,p),c.set(e,{kind:t,min:o,max:n??x,fn:a,...g})}function S(t){c.delete(t);for(const e of r.values())e.delete(t)}const w=(t,e,o,n,a)=>s("lift",t,e,o,n,a),C=(t,e,o,n,a)=>s("raw",t,e,o,n,a),F=(t,e,o,n,a)=>s("lazy",t,e,o,n,a);function M(t,e){f(t),c.set(t,c.get(e))}export{u as CATEGORIES,c as FUNCS,M as alias,y as categoryFunctions,S as forgetFunction,F as lazy,w as lift,C as raw,d as setCategory};