@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
@@ -0,0 +1,2 @@
1
+ import{escapeRegExp as h}from"../core/regexp.js";import{resolveTarget as d}from"../io/package-paths.js";const f="urn:8sheets:celltypes:1",T="urn:8sheets:cells:1",$="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml",x="application/xml",i="customXml/",g=64*1024*1024,y=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`;function w(e,o,s="cellTypes8c"){const t=`${s}${e+1}.xml`,r=`rId8c${s}${e+1}`;return{path:`${i}${t}`,xml:o,override:{partName:`/${i}${t}`,contentType:x},relationship:{id:r,type:$,target:`/${i}${t}`}}}const R=e=>`<Override PartName="${e.partName}" ContentType="${e.contentType}"/>`,v=e=>`<Relationship Id="${e.id}" Type="${e.type}" Target="${e.target}"/>`;function C(e,o,s,t="xl/workbook.xml"){if(!s||s.length===0)return{types:e,rels:o};const r=s.filter(n=>n.override&&!e.includes(`PartName="${n.override.partName}"`)),a=new Set([...o.matchAll(/\bTarget="([^"]+)"/g)].map(n=>d(t,n[1]))),l=s.filter(n=>n.relationship&&!a.has(d(t,n.relationship.target))&&!o.includes(`Id="${n.relationship.id}"`));return{types:e.replace("</Types>",`${r.map(n=>R(n.override)).join("")}</Types>`),rels:o.replace("</Relationships>",`${l.map(n=>v(n.relationship)).join("")}</Relationships>`)}}function E(e,o=g){const s=[];for(const[t,r]of e.entries)!t.startsWith(i)||!t.endsWith(".xml")||t.slice(i.length).includes("/")||/itemProps/i.test(t)||(r.size??0)<=o&&s.push(t);return s}async function N(e){const o=[];for(const s of E(e)){const t=await e.text(s);(t.includes(f)||t.includes(T)||t.includes("urn:8sheets:pivotviews:1"))&&o.push({name:s,text:t})}return o}async function S(e,o,s,t){let r=o,a=s;const l=n=>{r=r.replace(new RegExp(`<Override\\b[^>]*PartName="/${h(n)}"[^>]*/>`,"g"),"")};for(const{name:n}of await N(e)){t.add(n),l(n);const m=n.slice(i.length);a=a.replace(new RegExp(`<Relationship\\b[^>]*Target="[^"]*${h(i+m)}"[^>]*/>`,"g"),"");const c=`${i}_rels/${m}.rels`;if(e.has(c)){t.add(c);for(const u of(await e.text(c)).matchAll(/Target="([^"]+)"/g)){const p=`${i}${u[1].split("/").pop()}`;e.has(p)&&(t.add(p),l(p))}}}return{types:r,rels:a}}const L=()=>`${y}</Relationships>`;export{T as CELLS_NS,f as CELLTYPES_NS,x as CUSTOM_XML_CONTENT_TYPE,$ as CUSTOM_XML_REL,C as addCellTypeEntries,w as cellTypePart,E as customXmlNames,S as dropCellTypeParts,L as emptyRelationships,N as readCellTypeParts};
@@ -0,0 +1,2 @@
1
+ import{BOOL as Z,DIRTY as U,EMPTY as L,ERR as Y,FORMULA as z,KIND_MASK as E,NUM as P,Sheet as q,STR as G}from"../core/sheet.js";import{cellRef as Q,MAX_COLS as v,MAX_ROWS as ee,parseRangeRef as ne,sheetReferencePattern as te}from"../core/address.js";import{sparklineIndex as se}from"../core/sparklines.js";import{paintSparkline as oe}from"../sparklines/excel-paint.js";import{toFileFormula as le}from"../calc/parser.js";import{cssFont as ie}from"../core/styles.js";import{readCellValue as W}from"./dropdowns.js";import{CellType as re,defineCellType as ce,formatted as fe,frame as F,labelOf as ue,oneOf as ae,paintPlain as de,parseJsonCached as pe,safeText as he}from"./base.js";import{pathValue as me}from"./data-object.js";const j=60,ge=2e4,ye=500,be=/^R(?:\[(-?\d{1,7})\])?C(?:\[(-?\d{1,5})\])?$/,ke=/\{([^{}]+)\}/g,Ae={hair:1,thin:1,dotted:1,dashed:1,dashDot:1,dashDotDot:1,medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,double:1,thick:3};function Ce(n,e){const o=e.lastIndexOf("!"),s=o>=0?e.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null,t=s===null?n.sheet:n.sheets.find(l=>l.name.toLowerCase()===s.toLowerCase()),i=ne(o>=0?e.slice(o+1):e);return t&&i?{sheet:t,range:i}:null}function H(n,e){const o=te(e);return n.split(/("(?:[^"]|"")*")/).map((s,t)=>t%2===1?s:s.replace(o,"")).join("")}function V(n,e,o,s){const t=e.kind(o,s);(t&E)!==L&&n.setCell(o,s,t&E,e.value(o,s))}function X(n,e,o,s,t,i){for(const l of o.refs??[]){if(l.sheet)continue;const r=l.rAbs0?l.r0:s+(l.r0??0),y=l.rAbs1?l.r1:s+(l.r1??0),c=l.cAbs0?l.c0:t+(l.c0??0),a=l.cAbs1?l.c1:t+(l.c1??0),p=Math.min(Number.isFinite(y)?y:ee-1,e.maxRow),S=Math.min(Number.isFinite(a)?a:v-1,e.maxCol);for(let C=Math.max(0,r);C<=p;C++)for(let h=Math.max(0,c);h<=S;h++){if(i.left--<=0)return;(n.kind(C,h)&E)===L&&V(n,e,C,h)}}}function Me(n,e,o,s){const{engine:t}=n;if(!t)return null;const i=new q(e.name),l={left:ge};for(const c of o)V(i,e,c.r,c.c);const r=[];for(const c of o){if(!c.isFormula)continue;const a=H(n.editText(e,c.r,c.c).slice(1),e.name),p=le(a);i.setFormula(c.r,c.c,{f:p,typed:!0}),r.push(c),X(i,e,t.template(p,c.r,c.c),c.r,c.c,l)}const y=[];for(const c of s){const a=H(c.spark.source,e.name);y.push({...c,source:a}),X(i,e,t.template(a,c.r,c.c),c.r,c.c,l)}return{sheet:i,formulas:r,lines:y}}function Re(n,e,o,s,t){t==null||t===""?n.setCell(o,s,L,0):typeof t=="number"?n.setCell(o,s,P,t):typeof t=="boolean"?n.setCell(o,s,Z,t?1:0):n.setCell(o,s,G,e.strings.add(String(t)))}function De(n,e){const{engine:o}=e,{sheet:s,formulas:t}=n.copy;for(const i of t)s.setCell(i.r,i.c,z|U|P,0);for(const i of t)try{o.read(s,i.r,i.c)}catch{s.setCell(i.r,i.c,P,0)}}function Se(n,e,o){const s=Ce(n,e);if(!s)return null;const{sheet:t,range:i}=s,l=i.c0,r=i.r0,y=Math.min(i.c1,l+j-1),c=Math.min(i.r1,r+j-1),a=[0],p=[0];for(let u=l;u<=y;u++)a.push(a[a.length-1]+t.cols.sizeOf(u));for(let u=r;u<=c;u++)p.push(p[p.length-1]+t.rows.sizeOf(u));const S=a[a.length-1],C=p[p.length-1];if(S<=0||C<=0)return null;const h=[],O=t.sparklines&&t.sparklines.length>0?se(t):null,T=[];for(let u=r;u<=c;u++)for(let d=l;d<=y;d++){const f=t.mergeAt(u,d);if(f&&(f.r0!==u||f.c0!==d)&&!(u===r&&f.r0<r)&&!(d===l&&f.c0<l))continue;const m=f?Math.min(f.c1,y):d,g=f?Math.min(f.r1,c):u,b=n.styles.list[t.style(u,d)]??n.styles.list[0],A=t.kind(u,d)&E,M=o?.[Q(u,d)],R=t.cellTypes?.get?.(u*16384+d),k=O?.get(u*16384+d);if(A===L&&!b.fill&&!b.borders&&M===void 0&&R===void 0&&k===void 0)continue;const w=W(n,t,u,d);let D=null;M!==void 0?D=`{${M}}`:typeof w=="string"&&A!==Y&&(t.kind(u,d)&z)===0&&w.includes("{")&&(D=w),D!==null&&!D.includes("{")&&(D=null);const K=D===null&&(t.kind(u,d)&z)!==0;k!==void 0&&T.push({r:u,c:d,spark:k}),h.push({r:u,c:d,isFormula:K,spark:k!==void 0,x0:a[d-l],y0:p[u-r],x1:a[m-l+1],y1:p[g-r+1],st:b,value:w,tokens:D,type:R!==void 0&&R.type!=="range"?R:null})}const $=h.some(u=>u.isFormula)||T.length>0?Me(n,t,h,T):null;return{W:S,H:C,cells:h,sheet:t,copy:$}}const _=new Map;function B(n,e){const o=e.source;let s=_.get(o);return(s===void 0||s.id!==F.id||s.book!==n)&&(_.size>=64&&_.clear(),s={id:F.id,book:n,tpl:Se(n,o,e.bindings)},_.set(o,s)),s.tpl}function x(n,e,o,s,t,i){const l=be.exec(n);if(l){const r=t+Number(l[1]??0),y=i+Number(l[2]??0);return r>=0&&y>=0?W(o,s,r,y):null}return e===null?void 0:me(e,n)}function Te(n){return n==null?"":typeof n=="object"?JSON.stringify(n):String(ue(n))}function J(n,e,o,s,t,i){if(n.tokens===null)return n.value;const l=/^\{([^{}]+)\}$/.exec(n.tokens);if(l){const r=x(l[1].trim(),e,o,s,t,i);return r===void 0?"":typeof r=="object"&&r!==null?JSON.stringify(r):r}return n.tokens.replace(ke,(r,y)=>Te(x(y.trim(),e,o,s,t,i)))}function I(n,e,o,s,t,i,l){if(!e)return;const r=Math.max(1,Math.round(l));n.strokeStyle=e.color??"#000000",n.lineWidth=(Ae[e.style]??1)*r,n.setLineDash(e.style==="dotted"||e.style==="hair"?[r,r]:/dash/i.test(e.style)?[3*r,2*r]:[]),n.beginPath(),n.moveTo(o,s),n.lineTo(t,i),n.stroke(),n.setLineDash([])}function Oe(n,e,o){const s=[];for(const t of e.split(`
2
+ `)){let i="";for(const l of t.split(/\s+/)){const r=i===""?l:`${i} ${l}`;i!==""&&n.measureText(r).width>o?(s.push(i),i=l):i=r}s.push(i)}return s}function we(n,e,o,s,t,i,l,r,y){const c=s.fontSize*y;if(c<2.5||e==="")return;const a=2*y;n.font=ie(s,c),n.fillStyle=s.color??F.theme.cellInk;const p=s.hAlign??(typeof o=="number"?"right":typeof o=="boolean"?"center":"left");n.textAlign=p==="right"?"right":p==="center"||p==="centerContinuous"?"center":"left";const S=n.textAlign==="right"?t+l-a:n.textAlign==="center"?t+l/2:t+a,C=s.wrap?Oe(n,e,l-a*2):[e],h=c*1.22,O=s.vAlign??"bottom",T=C.length*h;let N=O==="top"?i+c*1.05:O==="center"?i+(r-T)/2+c*.95:i+r-T+c*.95-2*y;for(const $ of C)n.fillText($,S,N),N+=h;n.textAlign="left"}const Fe=/^(?:(?:'(?:[^']|'')+'|[^'!]+)!)?\$?[A-Za-z]{1,3}\$?\d{1,7}(?::\$?[A-Za-z]{1,3}\$?\d{1,7})?$/;function Ne(n){if(n===null||typeof n!="object"||Array.isArray(n))return;const e={};let o=0;for(const[s,t]of Object.entries(n)){if(o++>=ye)break;/^[A-Z]{1,3}\d{1,7}$/.test(s)&&typeof t=="string"&&t.length<=200&&!/[{}]/.test(t)&&(e[s]=t)}return o>0?Object.freeze(e):void 0}class $e extends re{static typeName="range";static sanitize(e){return{source:typeof e.source=="string"&&e.source.length<=300&&Fe.test(e.source)?e.source:"",fit:ae(e.fit,["stretch"]),bindings:Ne(e.bindings),title:he(e.title,200)}}paint(e,o,s,t,i,l){const r=l?.book??F.book,y=l?.sheet??F.sheet,c=r&&this.options.source?B(r,this.options):null;if(c===null){de(e,o,s,t,i);return}let a=o.w/c.W,p=o.h/c.H;this.options.fit!=="stretch"&&(a=Math.min(a,p),p=a);const S=o.x+(o.w-c.W*a)/2,C=o.y+(o.h-c.H*p)/2,h=Math.min(a,p),O=typeof s=="string"?pe(s):void 0,T=O!==null&&typeof O=="object"?O:null,{row:N,col:$}=F,u=(f,m,g)=>Math.round(m+f*g),{copy:d}=c;if(d!==null){for(const f of c.cells)f.tokens!==null&&Re(d.sheet,r,f.r,f.c,J(f,T,r,y,N,$));d.formulas.length>0&&De(c,r)}for(const f of c.cells){const m=u(f.x0,S,a),g=u(f.y0,C,p),b=u(f.x1,S,a)-m,A=u(f.y1,C,p)-g;if(b<=0||A<=0)continue;const{st:M}=f;M.fill&&(e.fillStyle=M.fill,e.fillRect(m,g,b,A));const R=f.isFormula&&d!==null?W(r,d.sheet,f.r,f.c):J(f,T,r,y,N,$);if(e.save(),e.beginPath(),e.rect(m,g,b,A),e.clip(),f.spark&&d!==null&&r.engine){const w=d.lines.find(D=>D.r===f.r&&D.c===f.c);w&&oe(e,r.engine,d.sheet,{group:w.spark.group,source:w.source},f.r,f.c,m,g,b,A,h)}f.type?f.type.paint(e,{x:m,y:g,w:b,h:A},R,M,h,l):R!==null&&R!==""&&we(e,String(fe(R,M)),R,M,m,g,b,A,h),e.restore();const k=M.borders;k&&(I(e,k.t,m,g,m+b,g,h),I(e,k.b,m,g+A,m+b,g+A,h),I(e,k.l,m,g,m,g+A,h),I(e,k.r,m+b,g,m+b,g+A,h),k.d&&k.down&&I(e,k.d,m,g,m+b,g+A,h),k.d&&k.up&&I(e,k.d,m,g+A,m+b,g,h))}}fitWidth(){const e=F.book&&this.options.source?B(F.book,this.options):null;return e===null?0:e.W}}ce($e);export{$e as RangeTemplateCell,B as template};
@@ -0,0 +1,3 @@
1
+ import{child as i,children as L}from"../io/xml-scan.js";import{NS as X,XML_HEAD as H,parseSpPr as J,parseXml as V,toBool as b,writeSpPr as K}from"../objects/dml.js";import{escapeMarkup as y,xmlLiteralText as M}from"../io/xml-escape.js";import{mapShapesOf as Q}from"./geo/map-state.js";import{GEO_PROVIDER as Z}from"./geo/geo-xml.js";const tt={treemap:"treemap",sunburst:"sunburst",histogram:"clusteredColumn",pareto:"clusteredColumn",boxWhisker:"boxWhisker",waterfall:"waterfall",funnel:"funnel",map:"regionMap"},Lt=e=>e==="funnel"?"cx2":e==="map"?"cx4":"cx1",et={treemap:{pos:"inEnd",seriesName:0,categoryName:1,value:0},sunburst:{pos:"ctr",seriesName:0,categoryName:1,value:0},waterfall:{pos:"outEnd",seriesName:0,categoryName:0,value:1},funnel:{seriesName:0,categoryName:0,value:1}};function at(e){const t=i(e,"geoCache");return t?i(t,"binary")?.t?.trim()?!0:!!i(t,"clear")?.c?.length:!1}const _=e=>e?`<cx:dataLabels${e.pos?` pos="${y(e.pos)}"`:""}><cx:visibility seriesName="${e.seriesName?1:0}" categoryName="${e.categoryName?1:0}" value="${e.value?1:0}"/></cx:dataLabels>`:"";function nt(e,t){switch(e){case"treemap":return'<cx:layoutPr><cx:parentLabelLayout val="overlapping"/></cx:layoutPr>';case"histogram":return'<cx:layoutPr><cx:binning intervalClosed="r"/></cx:layoutPr>';case"pareto":return t.catRef?"<cx:layoutPr><cx:aggregation/></cx:layoutPr>":'<cx:layoutPr><cx:binning intervalClosed="r"/></cx:layoutPr>';case"waterfall":return"<cx:layoutPr><cx:subtotals/></cx:layoutPr>";case"boxWhisker":return'<cx:layoutPr><cx:visibility meanLine="0" meanMarker="1" nonoutliers="0" outliers="1"/><cx:statistics quartileMethod="exclusive"/></cx:layoutPr>';case"map":return'<cx:layoutPr><cx:geography cultureLanguage="en-US" cultureRegion="US" attribution="Powered by Bing"/></cx:layoutPr>';default:return""}}function it(e){const t=(n,o="0")=>({id:o,hidden:!1,kind:"cat",gapWidth:String(n),min:void 0,max:void 0,majorGridlines:!1}),a=(n="1")=>({id:n,hidden:!1,kind:"val",min:void 0,max:void 0,majorGridlines:!0});switch(e){case"histogram":return[t(0),a()];case"pareto":return[t(0),a(),{...a("2"),min:0,max:1,majorGridlines:!1,percent:!0}];case"boxWhisker":return[t(1),a()];case"waterfall":return[t(.5),a()];case"funnel":return[t("0.0599999987","1")];default:return[]}}function st(e){return it(e).map(t=>{const a=t.kind==="cat"?`<cx:catScaling gapWidth="${t.gapWidth}"/>`:`<cx:valScaling${t.max!==void 0?` max="${t.max}"`:""}${t.min!==void 0?` min="${t.min}"`:""}/>`;return`<cx:axis id="${t.id}">${a}${t.percent?'<cx:units unit="percentage"/>':""}${t.majorGridlines?"<cx:majorGridlines/>":""}<cx:tickLabels/></cx:axis>`}).join("")}const W=["parentLabelLayout","regionLabelLayout","visibility","aggregation","binning","geography","statistics","subtotals","extLst"],rt=["connectorLines","meanLine","meanMarker","nonoutliers","outliers"],Rt=(e,t,a)=>e?.[t]===!0||e?.[t]===!1?e[t]:b(e?.[t],a),B=e=>Object.fromEntries(rt.filter(t=>e?.[t]!==void 0).map(t=>[t,b(e[t],!1)?"1":"0"])),ct=e=>`<cx:visibility${Object.entries(B(e)).map(([t,a])=>` ${t}="${a}"`).join("")}/>`;function lt(e){if(e)return{intervalClosed:e.a.intervalClosed??"r",underflow:e.a.underflow,overflow:e.a.overflow,binSize:i(e,"binSize")?.a.val===void 0?void 0:Number(i(e,"binSize").a.val),binCount:i(e,"binCount")?.a.val===void 0?void 0:Number(i(e,"binCount").a.val)}}const ot=(e,t)=>["intervalClosed","underflow","overflow","binSize","binCount"].every(a=>(e?.[a]??null)===(t?.[a]??null)||String(e?.[a])===String(t?.[a]));function ut(e){const t=`intervalClosed="${e.intervalClosed??"r"}"${e.underflow!==void 0?` underflow="${y(e.underflow)}"`:""}${e.overflow!==void 0?` overflow="${y(e.overflow)}"`:""}`,a=e.binSize!==void 0?`<cx:binSize val="${e.binSize}"/>`:e.binCount!==void 0?`<cx:binCount val="${e.binCount}"/>`:"";return a?`<cx:binning ${t}>${a}</cx:binning>`:`<cx:binning ${t}/>`}const ft=e=>e.length?`<cx:subtotals>${[...e].sort((t,a)=>t-a).map(t=>`<cx:idx val="${t}"/>`).join("")}</cx:subtotals>`:"<cx:subtotals/>";function xt(e,t,a){const n=new Map((t?.c??[]).map(l=>[l.n,e.raw(l)]));let o=!1;const c=(l,h)=>{h===null?n.delete(l)&&(o=!0):n.get(l)!==h&&(n.set(l,h),o=!0)},u=i(t,"visibility"),p={...u?.a,...a.visibility};a.visibility!==void 0&&JSON.stringify(B(u?.a))!==JSON.stringify(B(p))&&c("visibility",ct(p)),a.aggregation&&!i(t,"aggregation")?(c("binning",null),c("aggregation","<cx:aggregation/>")):!a.aggregation&&a.binning!==void 0&&(i(t,"aggregation")||!ot(lt(i(t,"binning")),a.binning))&&(c("aggregation",null),c("binning",ut(a.binning)));const s=i(t,"statistics")?.a.quartileMethod??"exclusive";a.quartileMethod&&a.quartileMethod!==s&&c("statistics",`<cx:statistics quartileMethod="${a.quartileMethod}"/>`);const x=L(i(t,"subtotals"),"idx").map(l=>Number(l.a.val));if(a.subtotals&&JSON.stringify([...x].sort((l,h)=>l-h))!==JSON.stringify([...a.subtotals].sort((l,h)=>l-h))&&c("subtotals",ft(a.subtotals)),!o)return null;const m=l=>W.includes(l)?W.indexOf(l):W.length;return`<cx:layoutPr>${[...n].sort((l,h)=>m(l[0])-m(h[0])).map(([,l])=>l).join("")}</cx:layoutPr>`}const dt=e=>e==="treemap"||e==="waterfall"||e==="map";function pt(e,t){const{type:a}=e,n=e.series[0]??{levels:[],values:[]},o=n.catRef?`<cx:strDim type="cat"><cx:f>${y(t(n.catRef))}</cx:f>${gt(n.levels)}</cx:strDim>`:"",u=`<cx:numDim type="${a==="treemap"||a==="sunburst"?"size":a==="map"?"colorVal":"val"}"><cx:f>${y(t(n.valRef??""))}</cx:f>${a==="map"&&n.nameRef?`<cx:nf>${y(t(n.nameRef))}</cx:nf>`:""}${mt(n)}</cx:numDim>`,p=n.nameRef||n.name?`<cx:tx><cx:txData>${n.nameRef?`<cx:f>${y(t(n.nameRef))}</cx:f>`:""}<cx:v>${M(n.name??"")}</cx:v></cx:txData></cx:tx>`:"",s=D=>`{0000000${D}-0000-4000-8000-00000000000${D}}`,x=a==="pareto"?'<cx:axisId val="1"/>':"",m=a==="pareto"?`<cx:series layoutId="paretoLine" ownerIdx="0" uniqueId="${s(1)}"><cx:axisId val="2"/></cx:series>`:"",l='<cx:title pos="t" align="ctr" overlay="0"/>',h=a==="map"?'<cx:legend pos="r" align="min" overlay="0"/>':dt(a)?'<cx:legend pos="t" align="ctr" overlay="0"/>':"";return`${H}<cx:chartSpace xmlns:a="${X.a}" xmlns:r="${X.r}" xmlns:cx="${X.cx}"><cx:chartData><cx:data id="0">${o}${u}</cx:data></cx:chartData><cx:chart>${l}<cx:plotArea><cx:plotAreaRegion><cx:series layoutId="${tt[a]}" uniqueId="${s(0)}">${p}${_(et[a])}<cx:dataId val="0"/>${nt(a,n)}${x}</cx:series>${m}</cx:plotAreaRegion>${st(a)}</cx:plotArea>${h}</cx:chart></cx:chartSpace>`}const gt=e=>(e??[]).map(t=>`<cx:lvl ptCount="${t.length}">${t.map((a,n)=>a==null?"":`<cx:pt idx="${n}">${M(a)}</cx:pt>`).join("")}</cx:lvl>`).join(""),mt=e=>`<cx:lvl ptCount="${e.values.length}" formatCode="${y(e.formatCode??"General")}">${e.values.map((t,a)=>t==null?"":`<cx:pt idx="${a}">${t}</cx:pt>`).join("")}</cx:lvl>`,j=["title","plotArea","legend","extLst"],ht=["chartData","chart","spPr","txPr","clrMapOvr","fmtOvrs","printSettings","extLst"],O=["tx","spPr","valueColors","valueColorPositions","dataPt","dataLabels","dataId","layoutPr","axisId","extLst"],$t=["tx","spPr","txPr","extLst"];class yt{constructor(t,a){this.doc=t,this.bytes=a,this.edits=[]}replace(t,a,n){this.edits.push({s:t,e:a,text:n})}setChild(t,a,n,o){const c=t.c.filter(x=>x.n===a);if(c.length){this.replace(c[0].s,c[c.length-1].e,n);return}if(!n)return;const u=o.indexOf(a),p=t.c.find(x=>o.indexOf(x.n)>u);if(p){this.replace(p.s,p.s,n);return}if(t.o===t.e){const x=this.doc.raw(t),m=/^<([^\s/>]+)/.exec(x)[1];this.replace(t.s,t.e,`${x.replace(/\s*\/>$/,">")}${n}</${m}>`);return}const s=bt(this.bytes,t.e);this.replace(s,s,n)}setAttr(t,a,n){const o=this.doc.openTag(t),c=new RegExp(`\\s${a}="[^"]*"`),u=n==null?"":` ${a}="${y(n)}"`,p=c.test(o)?o.replace(c,u):o.replace(/\s*(\/?)>$/,`${u}$1>`);this.replace(t.s,t.o,p)}result(){const t=new TextEncoder,a=[];let n=0;for(const u of this.edits.sort((p,s)=>p.s-s.s))u.s<n||(a.push(this.bytes.subarray(n,u.s),t.encode(u.text)),n=u.e);a.push(this.bytes.subarray(n));const o=new Uint8Array(a.reduce((u,p)=>u+p.length,0));let c=0;for(const u of a)o.set(u,c),c+=u.length;return new TextDecoder().decode(o)}}function bt(e,t){let a=t-1;for(;a>=0&&e[a]!==60;)a--;return a}const vt=e=>{const t=i(i(e,"tx"),"rich");return t?L(t,"p").map(a=>a.c.filter(n=>n.n==="r").map(n=>i(n,"t")?.t??"").join("")).join(`
2
+ `):i(i(i(e,"tx"),"txData"),"v")?.t};function z(e){return`<cx:tx><cx:rich><a:bodyPr anchor="ctr" anchorCtr="1"/><a:lstStyle/>${String(e).split(`
3
+ `).map(a=>`<a:p><a:pPr algn="ctr" rtl="0"><a:defRPr/></a:pPr><a:r><a:rPr lang="en-US"/><a:t>${M(a)}</a:t></a:r></a:p>`).join("")}</cx:rich></cx:tx>`}function U(e,t,a){const n=t?J(t,a):void 0;return JSON.stringify(I(n))===JSON.stringify(I(e))}const I=e=>{if(!e)return null;const{raw:t,...a}=e;return Object.fromEntries(Object.entries(a).filter(([,n])=>n!==void 0))},G=e=>e?K(e.raw?e:{...e},"cx:spPr"):"";function k(e,t){const a=new TextEncoder().encode(e),n=V(a),o=n.root,c=i(o,"chart"),u=i(c,"plotArea"),p=i(u,"plotAreaRegion"),s=new yt(n,a),x=i(c,"title");t.title===void 0||t.title===null?x&&s.setChild(c,"title","",j):x?(t.title.text!==void 0&&t.title.text!==vt(x)&&s.setChild(x,"tx",z(t.title.text),$t),b(x.a.overlay,!1)!==!!t.title.overlay&&s.setAttr(x,"overlay",t.title.overlay?1:0),t.title.pos&&t.title.pos!==x.a.pos&&s.setAttr(x,"pos",t.title.pos)):s.setChild(c,"title",`<cx:title pos="t" align="ctr" overlay="0">${t.title.text!==void 0?z(t.title.text):""}</cx:title>`,j);const m=i(c,"legend");t.legend?m?((m.a.pos??"t")!==(t.legend.pos??"t")&&s.setAttr(m,"pos",t.legend.pos??"t"),b(m.a.overlay,!1)!==!!t.legend.overlay&&s.setAttr(m,"overlay",t.legend.overlay?1:0)):s.setChild(c,"legend",`<cx:legend pos="${y(t.legend.pos??"t")}" align="ctr" overlay="${t.legend.overlay?1:0}"/>`,j):m&&s.setChild(c,"legend","",j);const l=i(o,"spPr");U(t.spPr,l,n)||s.setChild(o,"spPr",G(t.spPr),ht);const h=!t.source,D=L(i(o,"chartData"),"data");return L(p,"series").forEach((f,A)=>{const r=t.series[A];if(!r)return;const R=D.find(d=>d.a.id===i(f,"dataId")?.a.val);for(const d of R?.c??[]){const g=i(d,"f"),v=d.n==="strDim"?r.catRef:d.n==="numDim"?r.valRef:void 0;g&&v&&g.t!==v&&s.replace(g.s,g.e,`<cx:f>${y(v)}</cx:f>`)}const $=i(i(i(f,"tx"),"txData"),"f");$&&r.nameRef&&$.t!==r.nameRef&&s.replace($.s,$.e,`<cx:f>${y(r.nameRef)}</cx:f>`);const S=i(f,"spPr");U(r.spPr,S,n)||s.setChild(f,"spPr",G(r.spPr),O);const T=L(f,"dataPt").map(d=>({idx:Number(d.a.idx),spPr:I(J(i(d,"spPr"),n))})),Y=(r.dataPts??[]).map(d=>({idx:d.idx,spPr:I(d.spPr)}));if(JSON.stringify(T)!==JSON.stringify(Y)){const d=[...r.dataPts??[]].sort((g,v)=>g.idx-v.idx).map(g=>`<cx:dataPt idx="${g.idx}">${G(g.spPr)}</cx:dataPt>`).join("");s.setChild(f,"dataPt",d,O)}const E=i(i(f,"layoutPr"),"geography"),q=t.type==="map"&&A===0?Q(t)?.binary:null;if(E&&q&&!at(E)){const d=n.openTag(E),g=/^<([^\s/>]+)/.exec(d)[1],v=g.includes(":")?g.slice(0,g.indexOf(":")+1):"";s.replace(E.s,E.e,`${d.replace(/\s*\/?>$/,">")}<${v}geoCache provider="${Z}"><${v}binary>${q}</${v}binary></${v}geoCache></${g}>`)}if(t.type!=="map"){const d=xt(n,i(f,"layoutPr"),r);d&&s.setChild(f,"layoutPr",d,O)}const C=i(f,"dataLabels"),N=i(C,"visibility"),F=C?{pos:C.a.pos,seriesName:b(N?.a.seriesName,!1),categoryName:b(N?.a.categoryName,!1),value:b(N?.a.value,!1)}:null,P=r.dataLabels?{pos:r.dataLabels.pos,seriesName:b(r.dataLabels.visibility?.seriesName,!1),categoryName:b(r.dataLabels.visibility?.categoryName,!1),value:b(r.dataLabels.visibility?.value,!1)}:null;!h&&JSON.stringify(F)!==JSON.stringify(P)&&(P?C&&N?(s.replace(N.s,N.e,`<cx:visibility seriesName="${P.seriesName?1:0}" categoryName="${P.categoryName?1:0}" value="${P.value?1:0}"/>`),C.a.pos!==P.pos&&s.setAttr(C,"pos",P.pos)):s.setChild(f,"dataLabels",_(P),O):s.setChild(f,"dataLabels","",O))}),L(u,"axis").forEach((f,A)=>{const r=t.axes?.[A];if(!r)return;b(f.a.hidden,!1)!==!!r.hidden&&s.setAttr(f,"hidden",r.hidden?1:void 0);const R=i(f,"catScaling");R&&r.gapWidth!==void 0&&R.a.gapWidth!==String(r.gapWidth)&&s.setAttr(R,"gapWidth",r.gapWidth);const $=i(f,"valScaling");if($){const w=$.a.min===void 0?void 0:Number($.a.min),T=$.a.max===void 0?void 0:Number($.a.max);(w!==r.min||T!==r.max)&&s.replace($.s,$.e,`<cx:valScaling${r.max!==void 0?` max="${r.max}"`:""}${r.min!==void 0?` min="${r.min}"`:""}/>`)}const S=i(f,"majorGridlines");if(!!S!=!!r.majorGridlines)if(S)s.replace(S.s,S.e,"");else{const w=i(f,"tickLabels")??i(f,"numFmt")??i(f,"spPr");w&&s.replace(w.s,w.s,"<cx:majorGridlines/>")}}),s.result()}function Et(e,t=a=>a){return e.source&&!e.dirty?e.source:e.source?k(e.source,e):k(pt(e,t),e)}export{tt as CHARTEX_LAYOUT,it as chartExAxes,Rt as chartExFlag,Lt as chartExRequires,Et as writeChartExPart};
@@ -0,0 +1 @@
1
+ import{bytesToBase64 as h}from"../../core/base64.js";import{escapeMarkup as o}from"../../io/xml-escape.js";const $="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",P="{E9337A44-BEBE-4D9F-B70C-5C5E7DAFC167}",E="http://schemas.microsoft.com/office/drawing/2014/chartex",m=t=>t<0?-2*t-1:2*t;function Q(t){let e="",i=0,c=0,n=0;const r=t.length/2,g=t[0]===t[t.length-2]&&t[1]===t[t.length-1];for(let a=0;a<=(g?r-1:r);a++){const u=a===r?0:a,x=Math.round(t[u*2]*1e5),y=Math.round(t[u*2+1]*1e5);if(a>0&&a<r&&x===i&&y===c)continue;const l=m(x-i),d=m(y-c);let p=(l+d)*(l+d+1)/2+d;for(;p>=32;)e+=$[32|p%32],p=Math.floor(p/32);e+=$[p],i=x,c=y,n++}return{text:e,count:n}}const s=t=>String(Math.round(t*1e6)/1e6);function R(t){const e=t.polygons.map((g,a)=>{const u=g.map(Q);return`<cx:geoPolygon numPoints="${u.reduce((y,l)=>y+l.count,0)}" polygonId="${o(t.id)}${String(a).padStart(4,"0")}" pcaRings="${u.length},${u.map(y=>y.text).join(",")}"/>`}).join(""),[i,c,n,r]=t.box;return`<cx:geoDataEntityQueryResult><cx:geoDataEntityQuery entityType="${t.type}" entityId="${o(t.id)}"/><cx:geoData entityName="${o(t.name)}" entityId="${o(t.id)}" east="${s(n>180?n-360:n)}" west="${s(i)}" north="${s(r)}" south="${s(c)}"><cx:geoPolygons>${e}</cx:geoPolygons><cx:copyrights><cx:copyright>Natural Earth</cx:copyright></cx:copyrights></cx:geoData></cx:geoDataEntityQueryResult>`}function C(t){const e=Object.entries(t.query).map(([c,n])=>` ${c}="${o(n)}"`).join(""),i=Object.entries(t.address).map(([c,n])=>` ${c}="${o(n)}"`).join("");return`<cx:geoLocationQueryResult><cx:geoLocationQuery${e} entityType="${t.type}"/><cx:geoLocations><cx:geoLocation latitude="${s(t.lat)}" longitude="${s(t.lon)}" entityName="${o(t.name)}" entityType="${t.type}"><cx:address${i}/></cx:geoLocation></cx:geoLocations></cx:geoLocationQueryResult>`}const D=t=>`<cx:geoDataPointToEntityQueryResult><cx:geoDataPointQuery entityType="${t.type}" latitude="${s(t.lat)}" longitude="${s(t.lon)}"/><cx:geoDataPointToEntityQuery entityType="${t.type}" entityId="${o(t.entityId)}"/></cx:geoDataPointToEntityQueryResult>`,T=t=>`<cx:geoChildEntitiesQueryResult><cx:geoChildEntitiesQuery entityId="${o(t.parentId)}"><cx:geoChildTypes>${t.types.map(e=>`<cx:entityType>${e}</cx:entityType>`).join("")}</cx:geoChildTypes></cx:geoChildEntitiesQuery><cx:geoChildEntities>${t.entities.map(e=>`<cx:geoHierarchyEntity entityName="${o(e.name)}" entityId="${o(e.id)}" entityType="${e.type}"/>`).join("")}</cx:geoChildEntities></cx:geoChildEntitiesQueryResult>`;function w({locations:t=[],entities:e=[],children:i=[]}){return`<cx:clear xmlns:cx="${E}"><cx:geoLocationQueryResults>${t.map(C).join("")}</cx:geoLocationQueryResults><cx:geoDataEntityQueryResults>${e.map(R).join("")}</cx:geoDataEntityQueryResults><cx:geoDataPointToEntityQueryResults>${t.map(D).join("")}</cx:geoDataPointToEntityQueryResults><cx:geoChildEntitiesQueryResults>${i.map(T).join("")}</cx:geoChildEntitiesQueryResults></cx:clear>`}async function I(t){const e=new Blob([t]).stream().pipeThrough(new CompressionStream("deflate-raw"));return h(new Uint8Array(await new Response(e).arrayBuffer()))}export{P as GEO_PROVIDER,Q as encodeRing,w as geoCacheXml,I as packGeoCache};
@@ -0,0 +1 @@
1
+ const t=new WeakMap,p=e=>e.series?.[0]??e,s=e=>t.get(p(e));export{p as keyOf,s as mapShapesOf,t as mapStates};
@@ -0,0 +1 @@
1
+ const s={pct5:"8000000008000000",pct10:"8800000088000000",pct20:"8800220088002200",pct25:"8822882288228822",pct30:"AA44AA11AA44AA11",pct40:"AA44AA44AA44AA44",pct50:"AA55AA55AA55AA55",pct60:"EE55BB55EE55BB55",pct70:"EEBBEEBBEEBBEEBB",pct75:"DDFF77FFDDFF77FF",pct80:"FF77FFDDFF77FFDD",pct90:"FF7FFFF7FF7FFFF7",horz:"FF000000FF000000",vert:"8888888888888888",ltHorz:"FF00000000000000",ltVert:"8080808080808080",dkHorz:"FFFF0000FFFF0000",dkVert:"CCCCCCCCCCCCCCCC",narHorz:"FF00FF00FF00FF00",narVert:"AAAAAAAAAAAAAAAA",dashHorz:"F00000000F000000",dashVert:"8080808008080808",cross:"FF888888FF888888",dnDiag:"8040201008040201",upDiag:"0102040810204080",ltDnDiag:"8844221188442211",ltUpDiag:"1122448811224488",dkDnDiag:"CC663399CC663399",dkUpDiag:"3366CC993366CC99",wdDnDiag:"C1E070381C0E0783",wdUpDiag:"83070E1C3870E0C1",dashDnDiag:"8040000008040000",dashUpDiag:"0102000010200000",diagCross:"8142241818244281",smCheck:"CC33CC3333CC33CC",lgCheck:"F0F0F0F00F0F0F0F",smGrid:"FF888888FF888888",lgGrid:"FF80808080808080",dotGrid:"AA00800080008000",smConfetti:"8004402001100208",lgConfetti:"C0C81C0C30B03303",horzBrick:"FF808080FF080808",diagBrick:"8040201018244281",solidDmnd:"10387CFE7C381000",openDmnd:"8142241818244281",dotDmnd:"8000200008000200",plaid:"AA55AA55F0F0F0F0",sphere:"38447EFEFE7E4438",weave:"8850220508442241",divot:"0020100810200000",shingle:"0102841848201008",wave:"0018244281000000",trellis:"FF99FF66FF99FF66",zigZag:"8142241881422418"},p=Object.keys(s),i=new Map,d=(e,n)=>{if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(e,n);if(typeof document>"u")return null;const F=document.createElement("canvas");return F.width=e,F.height=n,F};function D(e,n,F,a){const c=s[n];if(!c||!e.createPattern)return F;const o=`${n}|${F}|${a}`;let t=i.get(o);if(!t){if(t=d(8,8),!t)return F;const r=t.getContext("2d");a&&(r.fillStyle=a,r.fillRect(0,0,8,8)),r.fillStyle=F;for(let C=0;C<8;C++){const l=parseInt(c.slice(C*2,C*2+2),16);for(let A=0;A<8;A++)l&128>>A&&r.fillRect(A,C,1,1)}i.size>256&&i.clear(),i.set(o,t)}return e.createPattern(t,"repeat")}export{p as PATTERN_NAMES,D as patternStyle};
@@ -0,0 +1 @@
1
+ const E=1048576,W=16384,S=[];function p(n){let e=S[n];if(e!==void 0)return e;e="";for(let t=n+1;t>0;t=Math.floor((t-1)/26))e=String.fromCharCode(65+(t-1)%26)+e;return S[n]=e,e}function a(n){let e=0;for(let t=0;t<n.length;t++){const r=n.charCodeAt(t)&223;if(r<65||r>90)return-1;e=e*26+(r-64)}return e-1}function A(n,e){return p(e)+(n+1)}const M=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;function h(n){const e=M.exec(n.trim());if(!e)return null;const t=a(e[1]),r=Number(e[2])-1;return t<0||t>=16384||r>=1048576?null:{row:r,col:t}}function z(n){const e=n.trim().split(":");if(e.length>2||!e[0])return null;const t=(o,c)=>{const l=/^\$?[A-Za-z]{1,3}$/.test(o)?a(o.replace("$","")):-1,s=/^\$?[A-Za-z]{1,3}$/.test(c)?a(c.replace("$","")):-1;if(l>=0&&s>=0&&l<16384&&s<16384)return{r0:0,c0:Math.min(l,s),r1:1048575,c1:Math.max(l,s)};const i=/^\$?[0-9]+$/.test(o)?Number(o.replace("$",""))-1:-1,f=/^\$?[0-9]+$/.test(c)?Number(c.replace("$",""))-1:-1;return i>=0&&f>=0&&i<1048576&&f<1048576?{r0:Math.min(i,f),c0:0,r1:Math.max(i,f),c1:16383}:null},r=h(e[0]);if(e.length===1)return r?{r0:r.row,c0:r.col,r1:r.row,c1:r.col}:null;const u=h(e[1]);return r&&u?{r0:Math.min(r.row,u.row),c0:Math.min(r.col,u.col),r1:Math.max(r.row,u.row),c1:Math.max(r.col,u.col)}:t(e[0],e[1])}function Z({r0:n,c0:e,r1:t,c1:r}){if(n===0&&t===1048575)return`${p(e)}:${p(r)}`;if(e===0&&r===16383)return`${n+1}:${t+1}`;const u=A(n,e);return n===t&&e===r?u:`${u}:${A(t,r)}`}const C=/[\x00-\x2d\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]/,d=/[\s\p{C}]/u,R=/^[\p{Nd}.]/u,_=/^([A-Za-z]{1,3})(\p{Nd}+)$/u,g=/^([A-Za-z]{1,3}\p{Nd}+)\.+([A-Za-z]{1,3}\p{Nd}+)$/u,L=/^R(\p{Nd}+)/iu,N=/^R?C(\p{Nd}+)/iu,O=/^[0-9]+$/,x=(n,e)=>!O.test(n)||Number(n)>=1&&Number(n)<=e;function $(n){const e=_.exec(n);return e!==null&&a(e[1])<16384&&x(e[2],1048576)}function m(n,e=!1){const t=String(n??"");if(t===""||C.test(t)||d.test(t)||R.test(t))return!0;const r=t.toUpperCase();if(r==="TRUE"||r==="FALSE"||r==="R"||r==="C"||r==="RC")return!0;if(!e){if($(t))return!0;const c=g.exec(t);if(c&&$(c[1])&&$(c[2]))return!0}const u=L.exec(t);if(u&&x(u[1],1048576))return e||t[u[0].length]!==".";const o=N.exec(t);return o&&x(o[1],16384)?e||t[o[0].length]!==".":!1}function X(n,{book:e=null,last:t=null,r1c1:r=!1,always:u=!1}={}){const o=String(n??""),c=`${e!=null?`[${e}]`:""}${o}${t!=null?`:${t}`:""}`;return u||(o!==""||e===null||e===void 0)&&m(o,r)||t!=null&&m(t,r)||e!=null&&(C.test(e)||d.test(e))?`'${c.replace(/'/g,"''")}'`:c}const F=String.raw`[A-Za-z_\u0080-￿][\w.\u0080-￿]*`,I=(n,e)=>`${X(n,e)}!`;function w(n){const e=String(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/'/g,"''");return new RegExp(`(?:'${e}'|(?<![\\p{L}\\p{N}_.'\\]\\u0080-\\u{10FFFF}])${e})!`,"giu")}function q(n,e,t){const r=I(t);return String(n).replace(w(e),()=>r)}function P(n){const e=String(n??"");return e.length>1&&e[0]==="'"&&e[e.length-1]==="'"?e.slice(1,-1).replace(/''/g,"'"):e}export{W as MAX_COLS,E as MAX_ROWS,F as PLAIN_SHEET,A as cellRef,a as colIndex,p as colName,h as parseCellRef,z as parseRangeRef,X as quoteSheetName,Z as rangeRef,q as renameSheetInFormula,m as sheetNeedsQuotes,I as sheetPrefix,w as sheetReferencePattern,P as unquoteSheetName};
package/core/axis.js ADDED
@@ -0,0 +1 @@
1
+ const o=65535;class u{constructor(t,i){this.count=t,this.defaultSize=i,this.sizes=null,this.tree=null,this.hiddenSizes=null,this.autoFlags=null,this.topBit=1<<31-Math.clz32(t),this.delta=0,this.watcher=null,this.version=0}setDefaultSize(t){if(this.tree)throw new Error("Default size must be set before custom sizes");this.defaultSize=t,this.version++}changeDefaultSize(t){if(t!==this.defaultSize){if(this.defaultSize=t,this.version++,this.sizes!==null){this.tree.fill(0);let i=0;for(let s=0;s<this.count;s++){const n=this.sizes[s];n!==65535&&(i+=n-t,this.tree[s+1]+=n-t)}for(let s=1;s<=this.count;s++){const n=s+(s&-s);n<=this.count&&(this.tree[n]+=this.tree[s])}this.delta=i}this.watcher?.axisResized()}}get total(){return this.count*this.defaultSize+this.delta}sizeOf(t){if(this.sizes===null)return this.defaultSize;const i=this.sizes[t];return i===65535||i===void 0?this.defaultSize:i}isCustom(t){return this.sizes!==null&&t<this.count&&this.sizes[t]!==65535}isHidden(t){return this.hiddenSizes!==null&&this.hiddenSizes.has(t)}isAuto(t){return this.autoFlags!==null&&this.autoFlags[t]===1}setSize(t,i,s=!1){s&&this.autoFlags===null&&(this.autoFlags=new Uint8Array(this.count)),this.autoFlags!==null&&(this.autoFlags[t]=s?1:0),i=Math.max(0,Math.min(65534,Math.round(i))),this.sizes===null&&(this.sizes=new Uint16Array(this.count).fill(65535),this.tree=new Int32Array(this.count+1));const n=this.sizeOf(t);this.sizes[t]=i;const h=i-n;if(h!==0){this.version++,this.delta+=h;for(let e=t+1;e<=this.count;e+=e&-e)this.tree[e]+=h;this.watcher?.axisResized()}}setHidden(t,i){if(i){if(this.isHidden(t))return;this.hiddenSizes===null&&(this.hiddenSizes=new Map),this.hiddenSizes.set(t,this.isCustom(t)?this.sizeOf(t):-1),this.setSize(t,0),this.watcher?.axisHiddenChanged()}else if(this.isHidden(t)){const s=this.hiddenSizes.get(t);this.hiddenSizes.delete(t),this.setSize(t,s<=0?this.defaultSize:s),this.watcher?.axisHiddenChanged()}}offsetOf(t){let i=t*this.defaultSize;if(this.tree!==null)for(let s=Math.min(t,this.count);s>0;s-=s&-s)i+=this.tree[s];return i}indexAt(t){if(t<=0&&this.tree===null)return 0;if(this.tree===null){const h=Math.floor(t/this.defaultSize);return h>=this.count?this.count-1:h}let i=0,s=t;const n=this.defaultSize;for(let h=this.topBit;h>0;h>>=1){const e=i+h;if(e<=this.count){const l=h*n+this.tree[e];l<=s&&(i=e,s-=l)}}return i>=this.count?this.count-1:i}reshaped(t=this.count,i=this.defaultSize){const s=new u(t,i);if(this.sizes!==null){const n=Math.min(t,this.count);for(let h=0;h<n;h++)this.sizes[h]!==65535&&s.setSize(h,this.sizes[h],this.isAuto(h))}if(this.hiddenSizes!==null)for(const[n,h]of this.hiddenSizes)n<t&&(s.hiddenSizes??=new Map,s.hiddenSizes.set(n,h));return s}shifted(t,i){const s=new u(this.count,this.defaultSize);if(this.sizes===null)return s;const n=new Uint16Array(this.count).fill(65535);i>0?(n.set(this.sizes.subarray(0,t)),n.set(this.sizes.subarray(t,this.count-i),t+i)):(n.set(this.sizes.subarray(0,t)),n.set(this.sizes.subarray(t-i),t)),s.sizes=n,s.tree=new Int32Array(this.count+1);let h=0;for(let e=0;e<this.count;e++){const l=n[e];if(l===65535)continue;const r=l-this.defaultSize;h+=r,s.tree[e+1]+=r}for(let e=1;e<=this.count;e++){const l=e+(e&-e);l<=this.count&&(s.tree[l]+=s.tree[e])}if(s.delta=h,this.hiddenSizes!==null){s.hiddenSizes=new Map;for(const[e,l]of this.hiddenSizes)e<t?s.hiddenSizes.set(e,l):(i>0||e>=t-i)&&s.hiddenSizes.set(e+i,l)}if(this.autoFlags!==null){const e=new Uint8Array(this.count);i>0?(e.set(this.autoFlags.subarray(0,t)),e.set(this.autoFlags.subarray(t,this.count-i),t+i)):(e.set(this.autoFlags.subarray(0,t)),e.set(this.autoFlags.subarray(t-i),t)),s.autoFlags=e}return s}*customEntries(){if(this.sizes!==null)for(let t=0;t<this.count;t++)this.sizes[t]!==65535&&(yield t)}}export{u as Axis};
package/core/base64.js ADDED
@@ -0,0 +1 @@
1
+ const o=32768;function a(r){const e=ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r);let n="";for(let t=0;t<e.length;t+=32768)n+=String.fromCharCode.apply(null,e.subarray(t,t+32768));return btoa(n)}function f(r){const e=atob(r),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}export{f as base64ToBytes,a as bytesToBase64};
@@ -0,0 +1 @@
1
+ import{FORMULA as x,KIND_MASK as M,STR as y}from"./sheet.js";const i=16384;class m{constructor(){this.cells=new Map,this.rows={inserted:[],deleted:[]},this.cols={inserted:[],deleted:[]}}}const v=(s,t)=>(s?.f??s?.sf??null)===(t?.f??t?.sf??null);function T(s,t,n){const{cells:e}=t.changes;for(let c=0;c<n.count;c++){const a=n.rows[c],o=n.cols[c],r=a*i+o;let l=e.get(r);l===void 0&&(l={kind:n.kinds[c],value:n.values[c],formula:n.kinds[c]&x?n.formulas?.get(c):void 0},e.set(r,l));const u=t.kind(a,o)&-97;u===l.kind&&t.value(a,o)===l.value&&(!(u&x)||v(t.formula(a,o),l.formula))&&e.delete(r)}}function A(s){return s.changes===null&&(s.changes=new m),s.changes}function I(s){s.changes=null}function C(s,t){const n=[];for(const e of s){const c=e.at+e.count;if(t.n>0)e.at>=t.at?n.push({at:e.at+t.n,count:e.count}):c>t.at?n.push({at:e.at,count:e.count+t.n}):n.push(e);else{const a=t.at-t.n;if(c<=t.at)n.push(e);else if(e.at>=a)n.push({at:e.at+t.n,count:e.count});else{const o=Math.max(0,t.at-e.at)+Math.max(0,c-a);o>0&&n.push({at:Math.min(e.at,t.at),count:o})}}}return n}function K(s,t,n){const e=s.changes;if(e===null)return!1;for(const c of(t==="row"?e.rows:e.cols).inserted)if(n>=c.at&&n<c.at+c.count)return!0;return!1}function R(s,t){const n=s.changes;if(n===null)return null;const e={cells:n.cells,rows:n.rows,cols:n.cols},c=u=>()=>{const k={cells:n.cells,rows:n.rows,cols:n.cols};return Object.assign(n,u),c(k)},a=t.axis==="row"?"rows":"cols",o=n[a],r=C(o.inserted,t);n[a]=t.n>0?{inserted:[...r,{at:t.at,count:t.n}],deleted:o.deleted}:{inserted:r,deleted:[...o.deleted,{at:t.at,count:-t.n}]};const l=new Map;for(const[u,k]of n.cells){let d=Math.floor(u/i),h=u-d*i;const f=t.axis==="row"?d:h;let w=f;if(t.n>0)f>=t.at&&(w=f+t.n);else if(f>=t.at-t.n)w=f+t.n;else if(f>=t.at)continue;t.axis==="row"?d=w:h=w,l.set(d*i+h,k)}return n.cells=l,c(e)}const g=(s,t,n)=>!s||t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1;function S(s,t,n=null){const e=t.changes;if(e===null)return[];const c=(o,r)=>{const l=o&M;return l===0?null:l===y?s.strings.get(r):l===3?r!==0:r},a=[];for(const[o,r]of e.cells){const l=Math.floor(o/i),u=o-l*i;g(n,l,u)&&a.push({row:l,col:u,oldValue:c(r.kind,r.value),newValue:c(t.kind(l,u),t.value(l,u))})}return a.sort((o,r)=>o.row-r.row||o.col-r.col)}const E=(s,t,n)=>s.changes!==null&&s.changes.cells.has(t*i+n);function F(s,t=null){const n=s.changes;if(n!==null){if(t===null){s.changes=new m;return}for(const e of[...n.cells.keys()]){const c=Math.floor(e/i);g(t,c,e-c*i)&&n.cells.delete(e)}}}export{m as ChangeTracker,F as clearDirty,S as getDirtyCells,E as isDirtyCell,K as isInsertedAxis,T as noteChanges,R as noteStructure,A as startTracking,I as stopTracking};
package/core/color.js ADDED
@@ -0,0 +1 @@
1
+ const d=s=>{const n=parseInt(String(s).replace("#",""),16);return[n>>16,n>>8&255,n&255]},f=s=>`#${s.map(n=>n.toString(16).padStart(2,"0")).join("").toUpperCase()}`;function g(s,n){const o=r=>Math.round(n>=0?r+(255-r)*n:r*(1+n));return f(d(s).map(o))}function M(s,n){let[o,r,a]=d(s).map(t=>t/255);const i=Math.max(o,r,a),c=Math.min(o,r,a);let m=0,h=0,e=(i+c)/2;if(i!==c){const t=i-c;h=e>.5?t/(2-i-c):t/(i+c),m=i===o?(r-a)/t+(r<a?6:0):i===r?(a-o)/t+2:(o-r)/t+4,m/=6}e=n<0?e*(1+n):e+(1-e)*n;const x=(t,u,p)=>{const l=p<0?p+1:p>1?p-1:p;return l<1/6?t+(u-t)*6*l:l<1/2?u:l<2/3?t+(u-t)*(2/3-l)*6:t};if(h===0)o=r=a=e;else{const t=e<.5?e*(1+h):e+h-e*h,u=2*e-t;o=x(u,t,m+1/3),r=x(u,t,m),a=x(u,t,m-1/3)}return f([o,r,a].map(t=>Math.round(t*255)))}export{M as shade,g as tint};
@@ -0,0 +1 @@
1
+ import{parseRangeRef as S}from"./address.js";import{BOOL as x,ERRORS as A,KIND_MASK as C,NUM as h,STR as R}from"./sheet.js";import{formatGeneral as O,getFormatter as T}from"./numfmt.js";function q(l){return l.split(/\s+/).map(S).filter(Boolean)}import{CondFormats as U,cfEffectAt as W,evaluatorOf as b,iconAt as D}from"../cells/cf-engine.js";function M(l,n,e){const a=l.validations;if(!a)return null;for(const t of a)if(t._ranges===void 0&&(t._ranges=q(t.sqref)),t._ranges.some(s=>n>=s.r0&&n<=s.r1&&e>=s.c0&&e<=s.c1))return t;return null}function E(l,n,e,a,t){const s=e.formula1.trim();if(s.startsWith('"'))return s.slice(1,-1).split(",").map(o=>o.trim());const p=l.engine;let u=p.template(s,a,t).fn(a,t,n);return u&&u.sheet&&(u=p.toArr(u)),u&&u.data?u.data.filter(o=>o!==null):[]}function _(l,n,e,a,t){return L(l,n,e,a,t).map(s=>s.text)}function L(l,n,e,a,t){const s=e.formula1.trim(),p=()=>E(l,n,e,a,t).map(r=>({text:String(r),value:r}));if(s.startsWith('"'))return p();const m=l.engine.template(s,a,t).fn(a,t,n);if(!m||!m.sheet)return p();const u=[],o=m.sheet;for(let r=m.r0;r<=Math.min(m.r1,o.maxRow);r++)for(let f=m.c0;f<=Math.min(m.c1,o.maxCol);f++){const g=o.kind(r,f)&C;if(g===0)continue;const i=o.value(r,f),c=l.styles.get(o.style(r,f)).numFmt;g===h?u.push({text:c==="General"?O(i):T(c).number(i).replace(/\u0001.?\u0001/g," ").trim(),value:i}):g===R?u.push({text:l.strings.get(i),value:l.strings.get(i)}):g===x?u.push({text:i?"TRUE":"FALSE",value:i!==0}):u.push({text:A[i]??"#N/A",value:null})}return u}function I(l,n,e,a,t,s,p,m){if(e.type==="none"||e.type===void 0)return!0;if(s===0)return e.allowBlank;const u=l.engine,o=i=>{if(!i)return null;const c=u.template(i,a,t),y=u.legacy;u.legacy=!0;try{const d=c.fn(a,t,n);return d&&d.sheet?u.refAuto(d,a,t):d}finally{u.legacy=y}};if(e.type==="list"){const i=E(l,n,e,a,t);return s===h&&i.some(c=>(typeof c=="number"?c:Number(c))===p)?!0:i.map(c=>String(c).toLowerCase()).includes(String(m).toLowerCase())}if(e.type==="custom"){const i=[n.kind(a,t),n.value(a,t),n.maxRow,n.maxCol],c=s===R?l.strings.add(String(m)):s===x?p?1:0:p;n.setCell(a,t,s,c);try{const y=o(e.formula1);return y===!0||typeof y=="number"&&y!==0}finally{n.setCell(a,t,i[0],i[1]),n.maxRow=i[2],n.maxCol=i[3]}}let r;if(e.type==="textLength")r=String(m).length;else if(s!==h||(r=p,e.type==="whole"&&!Number.isInteger(r)))return!1;const f=o(e.formula1),g=o(e.formula2);switch(e.operator){case"notBetween":return r<f||r>g;case"equal":return r===f;case"notEqual":return r!==f;case"greaterThan":return r>f;case"lessThan":return r<f;case"greaterThanOrEqual":return r>=f;case"lessThanOrEqual":return r<=f;default:return r>=f&&r<=g}}export{x as BOOL,U as CondFormats,R as STR,W as cfEffectAt,b as evaluatorOf,D as iconAt,L as listEntries,_ as listItems,E as listValues,q as rangesOf,I as validateEntry,M as validationAt};
@@ -0,0 +1 @@
1
+ import{colName as h,parseRangeRef as m,quoteSheetName as v,rangeRef as w}from"./address.js";import{escapeMarkup as $,xmlAttr as V,xmlText as b}from"../io/xml-escape.js";import{unescapeOoxml as N,unescapeXml as A,unescapeXstring as H}from"../io/xml-scan.js";function y(){const t=globalThis.crypto?.getRandomValues?crypto.getRandomValues(new Uint8Array(16)):Uint8Array.from({length:16},()=>Math.floor(Math.random()*256));t[6]=t[6]&15|64,t[8]=t[8]&63|128;const i=[...t].map(n=>n.toString(16).padStart(2,"0").toUpperCase()).join("");return`{${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}}`}const p=t=>t.hiddenSizes?[...t.hiddenSizes.keys()].sort((i,n)=>i-n):[];function I(t,{print:i,rowCol:n},e){const r=t.filteredRows??new Set;return{sheet:t,hiddenRows:n?p(t.rows).filter(o=>!r.has(o)):null,hiddenCols:n?p(t.cols):null,filter:n&&t.autoFilter?{...t.autoFilter,columns:new Map(t.autoFilter.columns),filtered:[...r]}:null,zoom:t.zoom||1,showGridlines:t.showGridlines!==!1,frozen:{rows:t.frozenRows||0,cols:t.frozenCols||0},selection:e?{row:e.row,col:e.col,sqref:e.ranges.map(w).join(" ")}:t.viewSelection??null,pageSetup:i&&t.pageSetup?structuredClone(t.pageSetup):null}}function G(t,i,{print:n=!0,rowCol:e=!0}={},r=null){return{name:i,guid:y(),print:n,rowCol:e,activeSheet:t.activeSheet,sheets:t.sheets.filter(o=>!o.isChartSheet).map(o=>I(o,{print:n,rowCol:e},o===t.sheet?r:null))}}function P(t,i){for(const n of i.sheets){const{sheet:e}=n;if(t.sheets.includes(e)){if(i.rowCol&&n.hiddenRows){const r=new Set(n.hiddenRows),o=e.filteredRows??new Set;for(const s of p(e.rows))!r.has(s)&&!o.has(s)&&e.rows.setHidden(s,!1);for(const s of r)e.rows.setHidden(s,!0);const l=new Set(n.hiddenCols??[]);for(const s of p(e.cols))l.has(s)||e.cols.setHidden(s,!1);for(const s of l)e.cols.setHidden(s,!0);if(e.colsChanged=!0,n.filter){for(const s of o)e.rows.setHidden(s,!1);e.autoFilter={...n.filter,columns:new Map(n.filter.columns)},delete e.autoFilter.filtered,e.filteredRows=new Set(n.filter.filtered);for(const s of e.filteredRows)e.rows.setHidden(s,!0);e.filterChanged=!0}}e.zoom=n.zoom,e.showGridlines=n.showGridlines,e.frozenRows=n.frozen.rows,e.frozenCols=n.frozen.cols,e.viewChanged=!0,i.print&&n.pageSetup&&(e.pageSetup=structuredClone(n.pageSetup),e.pageSetupChanged=!0),n.selection&&(e.viewSelection=n.selection),e.revision++}}return i.activeSheet>=0&&i.activeSheet<t.sheets.length&&(t.activeSheet=i.activeSheet),t.dirty=!0,t.sheet.viewSelection??null}const f=t=>`Z_${t.replace(/[{}]/g,"").replace(/-/g,"_")}_`;function C(t,i){const n=[];for(let e=0;e<t.length;e++){let r=e;for(;r+1<t.length&&t[r+1]===t[r]+1;)r++;n.push(i?[`$${h(t[e])}`,`$${h(t[r])}`]:[`$${t[e]+1}`,`$${t[r]+1}`]),e=r}return n}function M(t){const i=[];for(const n of t.customViews??[])for(const e of n.sheets){const r=t.sheets.indexOf(e.sheet);if(r<0)continue;const o=v(e.sheet.name);e.hiddenRows?.length&&i.push({name:`${f(n.guid)}.wvu.Rows`,localSheetId:r,text:C(e.hiddenRows,!1).map(([l,s])=>`${o}!${l}:${s}`).join(",")}),e.hiddenCols?.length&&i.push({name:`${f(n.guid)}.wvu.Cols`,localSheetId:r,text:C(e.hiddenCols,!0).map(([l,s])=>`${o}!${l}:${s}`).join(",")}),n.print&&e.pageSetup?.printAreas?.length&&i.push({name:`${f(n.guid)}.wvu.PrintArea`,localSheetId:r,text:e.pageSetup.printAreas.map(l=>`${o}!${w(l).replace(/([A-Z]+)(\d+)/g,"$$$1$$$2")}`).join(",")}),e.filter&&i.push({name:`${f(n.guid)}.wvu.FilterData`,localSheetId:r,text:`${o}!${w(e.filter).replace(/([A-Z]+)(\d+)/g,"$$$1$$$2")}`})}return i}function q(t){const i=t.customViews??[];return i.length===0?"":`<customWorkbookViews>${i.map(e=>`<customWorkbookView name="${V(e.name)}" guid="${e.guid}"${e.print?"":' includePrintSettings="0"'}${e.rowCol?"":' includeHiddenRowCol="0"'} windowWidth="${e.windowWidth??1440}" windowHeight="${e.windowHeight??900}" activeSheetId="${$(t.sheets[e.activeSheet]?.name??"")}"/>`).join("")}</customWorkbookViews>`}function k(t){if(!t)return"";const i=t.margins??{},n=(l,s)=>Number.isFinite(l)?l/72:s,e=`<pageMargins left="${n(i.left,.7)}" right="${n(i.right,.7)}" top="${n(i.top,.75)}" bottom="${n(i.bottom,.75)}" header="${n(i.header,.3)}" footer="${n(i.footer,.3)}"/>`,r=`<pageSetup${t.paperSize?` paperSize="${t.paperSize}"`:""}${t.scale&&t.scale!==100?` scale="${t.scale}"`:""}${t.orientation?` orientation="${t.orientation}"`:""}/>`,o=t.header?.odd||t.footer?.odd?`<headerFooter>${t.header?.odd?`<oddHeader>${b(t.header.odd)}</oddHeader>`:""}${t.footer?.odd?`<oddFooter>${b(t.footer.odd)}</oddFooter>`:""}</headerFooter>`:"";return e+r+o}function L(t,i,n=()=>""){const e=[];for(const r of t.customViews??[]){const o=r.sheets.find(a=>a.sheet===i);if(!o)continue;const l=o.frozen.rows||o.frozen.cols?`<pane${o.frozen.cols?` xSplit="${o.frozen.cols}"`:""}${o.frozen.rows?` ySplit="${o.frozen.rows}"`:""} topLeftCell="${h(o.frozen.cols)}${o.frozen.rows+1}" activePane="${o.frozen.rows&&o.frozen.cols?"bottomRight":o.frozen.rows?"bottomLeft":"topRight"}" state="frozen"/>`:"",s=o.selection?`<selection${l?` pane="${o.frozen.rows&&o.frozen.cols?"bottomRight":o.frozen.rows?"bottomLeft":"topRight"}"`:""} activeCell="${h(o.selection.col)}${o.selection.row+1}" sqref="${$(o.selection.sqref)}"/>`:"",d=`guid="${r.guid}"${o.zoom!==1?` scale="${Math.round(o.zoom*100)}"`:""}${o.showGridlines?"":' showGridLines="0"'}${r.print&&o.pageSetup?.printAreas?.length?' printArea="1"':""}${o.filter?' filter="1" showAutoFilter="1"':""}${o.hiddenRows?.length?' hiddenRows="1"':""}${o.hiddenCols?.length?' hiddenColumns="1"':""}`;e.push(`<customSheetView ${d}>${l}${s}${r.print?k(o.pageSetup):""}${o.filter?n(o.filter):""}</customSheetView>`)}return e.length?`<customSheetViews>${e.join("")}</customSheetViews>`:""}function Z(t,i,n){let e=t.replace(/<customWorkbookViews\b[\s\S]*?<\/customWorkbookViews>|<customWorkbookViews\b[^>]*\/>/,"");if(e=e.replace(/<definedName\b[^>]*name="Z_[^"]*\.wvu\.[A-Za-z]+"[^>]*>[\s\S]*?<\/definedName>/g,""),e=e.replace(/<definedNames>\s*<\/definedNames>/,""),i){i=i.replace(/\u0001([^\u0001]*)\u0001/g,(o,l)=>{const s=A(l),d=[...e.matchAll(/<sheet\b[^>]*>/g)].map(a=>a[0]).find(a=>{const c=/\bname="([^"]*)"/.exec(a)?.[1];return c!==void 0&&H(c)===s});return/\bsheetId="(\d+)"/.exec(d??"")?.[1]??"1"});const r=/<(?:pivotCaches|smartTagPr|smartTagTypes|webPublishing|fileRecoveryPr|webPublishObjects|extLst)\b|<\/workbook>/.exec(e);e=e.slice(0,r.index)+i+e.slice(r.index)}if(n.length){const r=n.map(o=>`<definedName name="${o.name}" hidden="1" localSheetId="${o.localSheetId}">${$(o.text)}</definedName>`).join("");if(/<definedNames>/.test(e))e=e.replace("<definedNames>",`<definedNames>${r}`);else{const o=/<calcPr\b|<oleSize\b|<customWorkbookViews\b|<pivotCaches\b|<extLst\b|<\/workbook>/.exec(e);e=`${e.slice(0,o.index)}<definedNames>${r}</definedNames>${e.slice(o.index)}`}}return e}function R(t){const i=[],n=[];for(const e of String(t).split(",")){const r=e.slice(e.lastIndexOf("!")+1).replace(/\$/g,"");let o=/^(\d+):(\d+)$/.exec(r);if(o)for(let l=Number(o[1])-1;l<=Number(o[2])-1;l++)i.push(l);if(o=/^([A-Z]+):([A-Z]+)$/.exec(r),o){const l=m(`${o[1]}1`).c0,s=m(`${o[2]}1`).c0;for(let d=l;d<=s;d++)n.push(d)}}return{rows:i,cols:n}}function O(t,i,n,e=[]){i?.length&&(t.customViews=i.map(r=>{const o=f(r.guid),l=Math.max(0,e.findIndex(d=>String(d.sheetId)===String(r.activeSheetId))),s=[];return t.sheets.forEach((d,a)=>{const c=(d.fileSheetViews??[]).find(u=>u.guid===r.guid);if(!c)return;const g=u=>(n??[]).find(z=>z.localSheetId===a&&z.name===`${o}.wvu.${u}`),S=g("Rows"),x=g("Cols");s.push({sheet:d,hiddenRows:S?R(S.text).rows:[],hiddenCols:x?R(x.text).cols:[],filter:null,zoom:c.scale?Number(c.scale)/100:1,showGridlines:c.showGridLines!=="0",frozen:{rows:c.ySplit?Number(c.ySplit):0,cols:c.xSplit?Number(c.xSplit):0},selection:c.activeCell?(()=>{const u=m(c.activeCell);return u?{row:u.r0,col:u.c0,sqref:c.sqref??c.activeCell}:null})():null,pageSetup:null})}),{name:N(r.name),guid:r.guid,print:r.includePrintSettings!=="0",rowCol:r.includeHiddenRowCol!=="0",activeSheet:l,sheets:s,windowWidth:r.windowWidth,windowHeight:r.windowHeight}}))}export{O as adoptCustomViews,P as applyView,G as captureView,L as customSheetViewsXml,q as customWorkbookViewsXml,y as newGuid,Z as patchCustomViews,M as viewNameEntries};
@@ -0,0 +1 @@
1
+ import{t as o}from"../i18n/index.js";const l=()=>o("name|Book"),s=()=>`${l()}1`,c=()=>o("name|Sheet"),p=()=>o("name|Table"),a=()=>o("name|Column");function x(t){const e=`${a()}1`;if(!t.has(e.toLowerCase()))return e;let n=2;for(;t.has(`${e}${n}`.toLowerCase());)n++;return`${e}${n}`}function u(t){let e=1;for(;t.has(`${a()}${e}`.toLowerCase());)e++;return`${a()}${e}`}const h=()=>o("name|Total"),i=()=>o("name|PivotTable"),w=()=>o("name|Chart");function b(t,e,n=1,m=""){let r=n;for(;e(`${t}${m}${r}`);)r++;return`${t}${m}${r}`}export{l as bookStem,w as chartStem,a as columnStem,u as freeColumnName,s as newBookName,x as newColumnName,b as nextName,i as pivotTableStem,c as sheetStem,p as tableStem,h as totalLabel};
@@ -0,0 +1 @@
1
+ import{colIndex as F,colName as z,MAX_COLS as v,MAX_ROWS as O}from"./address.js";const U=/"(?:[^"]|"")*"|'(?:[^']|'')*'|(\$?)([A-Za-z]{1,3})(\$?)(\d{1,7})(?![A-Za-z0-9_(.])|(\$?)(\d{1,7}):(\$?)(\d{1,7})(?![A-Za-z0-9_(.])|(\$?)([A-Za-z]{1,3}):(\$?)([A-Za-z]{1,3})(?![A-Za-z0-9_(.])/g;function Z(i,e,u){if(e)return null;const n=F(i)+u;return n<0||n>=v?-1:n}function m(i,e,u){if(e)return null;const n=i-1+u;return n<0||n>=O?-1:n}function M(i,e,u){return e===0&&u===0?i:i.replace(U,(n,_,p,l,A,N,c,a,C,R,f,d,E,$,o)=>{if(p!==void 0){const s=$>0?o[$-1]:"";if(/[A-Za-z0-9_]/.test(s)||s==="."&&o[$-2]!==":"||F(p)>=v||Number(A)>O||Number(A)===0)return n;const r=Z(p,_==="$",u),t=m(Number(A),l==="$",e);return r===-1||t===-1?"#REF!":`${_}${r===null?p.toUpperCase():z(r)}${l}${t===null?A:t+1}`}if(c!==void 0){const s=$>0?o[$-1]:"";if(/[A-Za-z0-9_.]/.test(s))return n;const r=m(Number(c),N==="$",e),t=m(Number(C),a==="$",e);return r===-1||t===-1?"#REF!":`${N}${r===null?c:r+1}:${a}${t===null?C:t+1}`}if(f!==void 0){const s=$>0?o[$-1]:"";if(/[A-Za-z0-9_.]/.test(s))return n;const r=Z(f,R==="$",u),t=Z(E,d==="$",u);return r===-1||t===-1?"#REF!":`${R}${r===null?f.toUpperCase():z(r)}:${d}${t===null?E.toUpperCase():z(t)}`}return n})}export{M as translateFormula};
@@ -0,0 +1 @@
1
+ import{MAX_COLS as d}from"./address.js";import{CHUNK_BITS as c,CHUNK_MASK as a,CHUNK_SIZE as m}from"./sheet.js";class p{constructor(){this.ids=new Int32Array(m),this.n=0}}class I{constructor(){this.columns=[],this.infos=[void 0],this.uses=new Int32Array(64),this.free=[],this.size=0,this.lastInfo=void 0,this.lastId=0}static from(s){const t=new I;if(s)for(const[e,n]of s)t.set(e,n);return t}at(s,t){const e=this.columns[t];if(e===void 0)return;const n=e[s>>>c];if(n===void 0)return;const i=n.ids[s&a];return i===0?void 0:this.infos[i]}put(s,t,e){if(e==null){this.remove(s,t);return}let n=this.columns[t];n===void 0&&(n=[],this.columns[t]=n);const i=s>>>c;let f=n[i];f===void 0&&(f=new p,n[i]=f);const o=s&a,{ids:r}=f,{infos:h}=this,u=r[o];if(u!==0&&h[u]===e)return;let l;e===this.lastInfo&&h[this.lastId]===e?l=this.lastId:o>0&&r[o-1]!==0&&h[r[o-1]]===e?l=r[o-1]:l=this._add(e),this.lastInfo=e,this.lastId=l,r[o]=l,this.uses[l]++,u===0?(f.n++,this.size++):this._release(u)}remove(s,t){const e=this.columns[t];if(e===void 0)return!1;const n=s>>>c,i=e[n];if(i===void 0)return!1;const f=s&a,o=i.ids[f];return o===0?!1:(i.ids[f]=0,this._release(o),this.size--,--i.n===0&&(e[n]=void 0),!0)}_add(s){const t=this.free.length>0?this.free.pop():this.infos.length;if(this.infos[t]=s,t>=this.uses.length){const e=new Int32Array(this.uses.length*2);e.set(this.uses),this.uses=e}return this.uses[t]=0,t}_release(s){--this.uses[s]===0&&(this.infos[s]=void 0,this.free.push(s),this.lastId===s&&(this.lastInfo=void 0,this.lastId=0))}forEachCell(s){const{columns:t}=this;for(let e=0;e<t.length;e++){const n=t[e];if(n!==void 0)for(let i=0;i<n.length;i++){const f=n[i];if(f===void 0)continue;const{ids:o}=f,r=i<<c;for(let h=0;h<m;h++){const u=o[h];u!==0&&s(r+h,e,this.infos[u])}}}}*descriptors(){const{infos:s}=this;for(let t=1;t<s.length;t++)s[t]!==void 0&&(yield s[t])}copy(){const s=new I;return s.columns=this.columns.map(t=>t.map(e=>{if(e===void 0)return;const n=new p;return n.ids.set(e.ids),n.n=e.n,n})),s.infos=this.infos.slice(),s.uses=this.uses.slice(),s.free=this.free.slice(),s.size=this.size,s}get(s){const t=Math.floor(s/d);return this.at(t,s-t*d)}has(s){return this.get(s)!==void 0}set(s,t){const e=Math.floor(s/d);return this.put(e,s-e*d,t),this}delete(s){const t=Math.floor(s/d);return this.remove(t,s-t*d)}clear(){this.columns=[],this.infos=[void 0],this.uses=new Int32Array(64),this.free=[],this.size=0,this.lastInfo=void 0,this.lastId=0}*entries(){const{columns:s}=this;for(let t=0;t<s.length;t++){const e=s[t];if(e!==void 0)for(let n=0;n<e.length;n++){const i=e[n];if(i===void 0)continue;const f=n<<c;for(let o=0;o<m;o++){const r=i.ids[o];r!==0&&(yield[(f+o)*d+t,this.infos[r]])}}}}*keys(){for(const[s]of this.entries())yield s}*values(){for(const[,s]of this.entries())yield s}forEach(s,t){for(const[e,n]of this.entries())s.call(t,n,e,this)}[Symbol.iterator](){return this.entries()}}export{I as FormulaStore};
package/core/input.js ADDED
@@ -0,0 +1 @@
1
+ import{BOOL as g,EMPTY as w,FORMULA as A,NUM as s,STR as k}from"./sheet.js";import{partsToSerial as i}from"./numfmt.js";const C=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],O=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/,P=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,U=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)[eE][+-]?\d+$/,I=/^[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)?(?:\.\d*)?%$/,y="(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d*)?|\\.\\d+",D=/^([+-]?)[€£¥]\s?([+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d*)?)$/;let $={symbol:"$",symbolFirst:!0};function B(t){$={symbol:t.symbol,symbolFirst:t.symbolFirst}}const L=t=>`"${t.replace(/"/g,"")}"`;function S(t){const e=t?"#,##0.00":"#,##0",n=L($.symbol);return $.symbolFirst?`${n}${e}_);[Red]\\(${n}${e}\\)`:`${e} ${n}`}function Y(t,e){return e===2?t%4===0&&(t%100!==0||t%400===0||t===1900)?29:28:[4,6,9,11].includes(e)?30:31}const d=t=>t.length<=2?(Number(t)<30?2e3:1900)+Number(t):Number(t),m=(t,e,n)=>t>=1900&&t<=9999&&e>=1&&e<=12&&n>=1&&n<=Y(t,e),M=t=>{const e=t.toLowerCase().replace(/\.$/,"");if(e.length<3)return 0;const n=C.indexOf(e.slice(0,3));return n<0?0:new Intl.DateTimeFormat("en-US",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,n,15))).toLowerCase().startsWith(e)?n+1:0},p=()=>new Date().getFullYear(),b=(t,e,n)=>t===1900&&e===2&&n===29?60:i(t,e,n);function F(t){let e;if(e=/^(\d{1,2})([/-])(\d{1,2})\2(\d{1,4})$/.exec(t)){const[n,r,u]=[Number(e[1]),Number(e[3]),d(e[4])];return m(u,n,r)?{value:b(u,n,r),format:"m/d/yyyy"}:null}if(e=/^(\d{4})([/-])(\d{1,2})\2(\d{1,2})$/.exec(t)){const[n,r,u]=[Number(e[1]),Number(e[3]),Number(e[4])];return m(n,r,u)?{value:b(n,r,u),format:"m/d/yyyy"}:null}if(e=/^(\d{1,2})[/-](\d{1,2})$/.exec(t)){const[n,r,u]=[Number(e[1]),Number(e[2]),p()];if(m(u,n,r))return{value:b(u,n,r),format:"d-mmm"};const o=d(e[2]);return e[2].length!==1&&m(o,n,1)?{value:i(o,n,1),format:"mmm-yy"}:null}if(e=/^(\d{1,2})[-\s]+([A-Za-z]+\.?)(?:[-\s,]+(\d{2}|\d{4}))?$/.exec(t)){const n=M(e[2]),r=Number(e[1]),u=e[3]?d(e[3]):p();return n&&m(u,n,r)?{value:b(u,n,r),format:e[3]?"d-mmm-yy":"d-mmm"}:null}if(e=/^([A-Za-z]+\.?)[-\s]+(\d{1,4})(?:,?\s*(\d{2}|\d{4}))?$/.exec(t)){const n=M(e[1]);if(!n)return null;const r=Number(e[2]);if(e[3]){const o=d(e[3]);return m(o,n,r)&&e[2].length<=2?{value:i(o,n,r),format:"d-mmm-yy"}:null}if(e[2].length<=2&&m(p(),n,r))return{value:i(p(),n,r),format:"d-mmm"};const u=d(e[2]);return m(u,n,1)&&e[2].length!==3?{value:i(u,n,1),format:"mmm-yy"}:null}return null}function R(t){let e=/^(\d{1,4}):(\d{1,2})(?::(\d{1,2}))?\s*([AaPp][Mm]?)?$/.exec(t),n,r=0,u=0,o;if(e)[n,r,u]=[Number(e[1]),Number(e[2]),Number(e[3]??0)],o=e[4];else if(e=/^(\d{1,2})\s*([AaPp][Mm]?)$/.exec(t))n=Number(e[1]),o=e[2];else return null;if(r>59||u>59)return null;if(o){if(n<1||n>12)return null;const a=o[0].toLowerCase()==="p";n=n%12+(a?12:0)}const l=(n*3600+r*60+u)/86400;return o?{value:l,format:e[3]!==void 0?"h:mm:ss AM/PM":"h:mm AM/PM"}:n>=24?{value:l,format:"[h]:mm:ss"}:{value:l,format:e[3]!==void 0?"h:mm:ss":"h:mm"}}function j(t){const e=/^(.+?)\s+(\d{1,2}(?::\d{1,2}(?::\d{1,2})?)?\s*(?:[AaPp][Mm]?)?)$/.exec(t);if(!e||!/:|[AaPp]/.test(e[2]))return null;const n=F(e[1]),r=R(e[2]);return!n||!r||r.value>=1?null:{value:n.value+r.value,format:"m/d/yyyy h:mm"}}function Z(t){const e=/^([+-]?)(\d+) (\d+)\/(\d+)$/.exec(t);if(!e)return null;const n=Number(e[4]);if(n===0)return null;const r=(Number(e[2])+Number(e[3])/n)*(e[1]==="-"?-1:1),u="?".repeat(Math.min(3,e[4].length));return{value:r,format:`# ${u}/${u}`}}function N(t){let e=0,n="";for(const r of t.replace(/,/g,""))r>="0"&&r<="9"?((e>0||r!=="0")&&e++,n+=e>15?"0":r):((r==="e"||r==="E")&&(e=-1/0),n+=r);return Number(n)}const c=N;function G(t){if(t==="")return{kind:w};if(t[0]==="="&&t.length>1)return{kind:A,formula:t.slice(1)};if(t[0]==="'")return{kind:k,text:t.slice(1)};const e=t.trim(),n=e.toUpperCase();if(n==="TRUE")return{kind:g,value:1};if(n==="FALSE")return{kind:g,value:0};let r;if(O.test(e))return{kind:s,value:N(e)};if(P.test(e))return{kind:s,value:c(e),format:e.includes(".")?"#,##0.00":"#,##0"};if(U.test(e))return{kind:s,value:N(e),format:"0.00E+00"};if(I.test(e)&&/\d/.test(e)){const f=e.slice(0,-1);return{kind:s,value:c(f)/100,format:/\.\d/.test(f)?"0.00%":"0%"}}if(r=/^\((\d{1,3}(?:,\d{3})+(?:\.\d*)?|\d+(?:\.\d*)?|\.\d+)\)$/.exec(e))return{kind:s,value:-c(r[1]),...r[1].includes(",")?{format:r[1].includes(".")?"#,##0.00":"#,##0"}:{}};const u=$.symbol.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=(f,E,T)=>{const x=c(E)*(f==="-"||T?-1:1);return{kind:s,value:x,format:S(/\.\d/.test(E))}};if(r=new RegExp(`^([+-]?)${u}\\s?([+-]?)(${y})$`).exec(e))return o(r[1]||r[2],r[3]);if(r=new RegExp(`^([+-]?)(${y})\\s?${u}$`).exec(e))return o(r[1],r[2]);if((r=new RegExp(`^\\(${u}\\s?(${y})\\)$`).exec(e))||(r=new RegExp(`^\\((${y})\\s?${u}\\)$`).exec(e)))return o("",r[1],!0);if(r=D.exec(e))return{kind:s,value:c(r[2])*(r[1]==="-"?-1:1)};const l=Z(e);if(l)return{kind:s,...l};const a=F(e);if(a)return{kind:s,...a};const v=R(e);if(v)return{kind:s,...v};const h=j(e);return h?{kind:s,...h}:{kind:k,text:t}}export{G as parseInput,B as setEntryCurrency};
package/core/math.js ADDED
@@ -0,0 +1 @@
1
+ const c=(a,t,m)=>Math.max(t,Math.min(m,a));export{c as clamp};
package/core/numfmt.js ADDED
@@ -0,0 +1 @@
1
+ import{calendarParts as X,dbnumDigits as Z,dbnumPlaces as H,eraAt as R,erasOf as P,hijriLocale as K,localeData as Q,mapDigits as V,numeralDigits as v,parseLocaleBracket as ee}from"../calcx/culture/format-locale.js";const y={decimal:".",group:",",months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortMonths:null,shortDays:null,shortDate:"m/d/yyyy",longDate:"dddd, mmmm d, yyyy",longTime:"h:mm:ss AM/PM",amDesignator:"AM",pmDesignator:"PM",tag:null,eras:null,numerals:null};function ge(t){Object.assign(y,t),G.clear()}const D="",be={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yyyy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yyyy h:mm",37:"#,##0_);(#,##0)",38:"#,##0_);[Red](#,##0)",39:"#,##0.00_);(#,##0.00)",40:"#,##0.00_);[Red](#,##0.00)",41:'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',42:'_($* #,##0_);_($* \\(#,##0\\);_($* "-"_);_(@_)',43:'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',44:'_($* #,##0.00_);_($* \\(#,##0.00\\);_($* "-"??_);_(@_)',45:"mm:ss",46:"[h]:mm:ss",47:"mm:ss.0",48:"##0.0E+0",49:"@"},B={black:"#000000",blue:"#0000FF",cyan:"#00FFFF",green:"#00FF00",magenta:"#FF00FF",red:"#FF0000",white:"#FFFFFF",yellow:"#FFFF00"},te=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"];function U(t){const s=[[]];let n=s[0];const o=e=>{const i=n[n.length-1];i&&i.k==="lit"?i.s+=e:n.push({k:"lit",s:e})};for(let e=0;e<t.length;e++){const i=t[e];if((i==="G"||i==="g")&&t.slice(e,e+7).toLowerCase()==="general"){o("General"),e+=6;continue}switch(i){case";":n=[],s.push(n);break;case'"':{const a=t.indexOf('"',e+1);o(a<0?t.slice(e+1):t.slice(e+1,a)),e=a<0?t.length:a;break}case"\\":e+1<t.length&&o(t[++e]);break;case"_":e++,o(" ");break;case"*":n.push({k:"fill",c:t[++e]??" "});break;case"[":{const a=t.indexOf("]",e);if(a<0){o(i);break}const l=t.slice(e+1,a);e=a;const f=l.toLowerCase();if(/^dbnum[1-4]$/.test(f)){n.push({k:"dbnum",n:Number(f[5])});break}if(/^h+$/.test(f)||/^m+$/.test(f)||/^s+$/.test(f))n.push({k:"elapsed",c:f[0],n:f.length});else if(B[f])n.push({k:"color",v:B[f]});else if(/^color\s*\d+$/.test(f)){const d=te[Number(f.replace(/\D/g,""))-1];d&&n.push({k:"color",v:`#${d}`})}else if(/^(<=|>=|<>|<|>|=)\s*-?[\d.]+/.test(l)){const d=/^(<=|>=|<>|<|>|=)\s*(-?[\d.]+(?:[eE][+-]?\d+)?)/.exec(l);n.push({k:"cond",op:d[1],v:Number(d[2])})}else if(l[0]==="$"){const d=ee(l);d?.currency&&o(d.currency),d&&(d.tag||d.calendar||d.numerals||d.system||d.gannen)&&n.push({k:"loc",info:d})}break}case"@":n.push({k:"text"});break;case"#":case"0":case"?":n.push({k:"d",c:i});break;case".":n.push({k:"point"});break;case",":n.push({k:"comma"});break;case"%":n.push({k:"pct"});break;case"/":n.push({k:"slash"});break;case"E":case"e":{const a=t[e+1];if((a==="+"||a==="-")&&/[0#?]/.test(t[e+2]??""))n.push({k:"exp",plus:a==="+",upper:i==="E"}),e++;else if(i==="e"){let l=1;for(;t[e+l]==="e";)l++;n.push({k:"date",c:"e",n:l}),e+=l-1}else o(i);break}case"y":case"Y":case"m":case"M":case"d":case"D":case"h":case"H":case"s":case"S":{const a=i.toLowerCase();let l=1;for(;t[e+l]?.toLowerCase()===a;)l++;n.push({k:"date",c:a,n:l}),e+=l-1;break}case"g":case"G":case"b":case"B":{const a=i.toLowerCase();if(a==="b"&&t[e+1]==="2"){n.push({k:"hijri"}),e++;break}let l=1;for(;t[e+l]?.toLowerCase()===a;)l++;n.push({k:"date",c:a,n:l}),e+=l-1;break}case"A":case"a":{const a=t.slice(e,e+5).toUpperCase();if(/^AAA/.test(a)){let l=3;for(;t[e+l]?.toLowerCase()==="a";)l++;n.push({k:"date",c:"a",n:l}),e+=l-1}else a==="AM/PM"?(n.push({k:"ampm",long:!0}),e+=4):a.startsWith("A/P")?(n.push({k:"ampm",long:!1,lower:i==="a"}),e+=2):o(i);break}default:o(i)}}return s}function se(t){const s={tokens:t,color:null,cond:null,isDate:!1,isText:!1,isNum:!1,isGeneral:!1},n=[];for(const e of t)e.k==="color"?s.color=e.v:e.k==="cond"?s.cond=e:e.k==="loc"?s.loc=e.info:e.k==="dbnum"?s.dbnum=e.n:e.k==="hijri"?s.hijri=!0:n.push(e);if(s.loc?.system){n.length=0;for(const e of U(s.loc.system==="date"?y.longDate:y.longTime)[0])n.push(e)}s.tokens=n;const o=n.filter(e=>e.k==="lit").map(e=>e.s).join("");if(s.isDate=n.some(e=>e.k==="date"||e.k==="elapsed"||e.k==="ampm"),s.isText=n.some(e=>e.k==="text"),s.isNum=!s.isDate&&n.some(e=>e.k==="d"),/general/i.test(o)){s.isGeneral=!0;for(const e of n)e.k==="lit"&&(e.s=e.s.replace(/general/i,""))}return s.isDate?oe(s):s.isNum&&le(s),s.digits=ie(s),s}const ne=t=>t.op==="<"&&t.v<=0||t.op==="<="&&t.v<0||t.op==="="&&t.v<0;function q(t,s){const n=I(s);return t.dbnum?H(n,t.dbnum,t.loc?.tag??y.tag)??n:n}function ie(t){if(t.dbnum){const s=Z(t.dbnum,t.loc?.tag??y.tag);if(s)return s}return t.loc?.numerals>1?v(t.loc.numerals):y.numerals??null}function oe(t){if(t.tokens.some(e=>e.k==="date"&&e.c==="g")&&P(t.loc,y)){let e=!1;for(const i of t.tokens)i.k==="date"&&i.c==="g"?e=!0:e&&i.k==="date"&&i.c==="y"&&(i.c="e",i.n=2)}const s=t.tokens;let n=null;for(let e=0;e<s.length;e++){const i=s[e];if(i.k==="date"&&i.c==="m"&&i.n<=2){let a=null;for(let l=e+1;l<s.length;l++)if(s[l].k!=="lit"){a=s[l];break}(n==="h"||a&&a.k==="date"&&a.c==="s"||a&&a.k==="elapsed"&&a.c==="s")&&(i.c="n"),n=null}else i.k==="date"&&i.c==="h"||i.k==="elapsed"&&i.c==="h"?n="h":(i.k==="date"||i.k==="elapsed")&&(n=null)}t.hour12=s.some(e=>e.k==="ampm"),t.subDigits=0;const o=[];for(let e=0;e<s.length;e++){const i=s[e];if(i.k==="point"&&s[e+1]?.k==="d"){let a=0;for(;s[e+1+a]?.k==="d";)a++;o.push({k:"sub",n:a}),t.subDigits=Math.max(t.subDigits,a),e+=a}else i.k==="point"?o.push({k:"lit",s:"."}):i.k==="slash"?o.push({k:"lit",s:"/"}):i.k==="comma"?o.push({k:"lit",s:","}):i.k==="d"?o.push({k:"lit",s:i.c}):i.k==="pct"?o.push({k:"lit",s:"%"}):o.push(i)}t.tokens=o}function le(t){const s=t.tokens;let n=-1,o=-1,e=-1,i=-1,a=-1;s.forEach((c,k)=>{c.k==="d"?(o<0&&(o=k),n=k):c.k==="point"&&e<0?e=k:c.k==="exp"&&i<0?i=k:c.k==="slash"&&a<0&&o>=0&&(a=k)});let l=0,f=0,d=!1;const b=[];for(let c=0;c<s.length;c++){const k=s[c];if(k.k==="pct")l++,b.push({k:"lit",s:"%"});else if(k.k==="comma"){let m=!1;for(let h=c+1;h<s.length;h++){if(s[h].k==="d"){m=!0;break}if(s[h].k!=="comma")break}m&&c>o&&(e<0||c<e)?d=!0:c>o&&c<=n+8&&!m?f++:b.push({k:"lit",s:","})}else k.k==="slash"&&c!==a?b.push({k:"lit",s:"/"}):k.k==="point"&&c!==e?b.push({k:"lit",s:"."}):b.push(k)}t.tokens=b,t.pct=l,t.scale=f,t.grouping=d,t.fraction=a>=0,t.scientific=i>=0;let u="int";const p={int:0,dec:0,exp:0,num:0,den:0};let g="";for(const c of b)c.k==="point"?u="dec":c.k==="exp"?u="exp":c.k==="slash"?u="den":c.k==="d"?(c.part=u,p[u]++,u==="den"&&(g+=c.c)):c.k==="lit"&&u==="den"&&/^\d+$/.test(c.s)&&(g+=c.s);if(t.fraction){let k=b.findIndex(h=>h.k==="slash")-1,m=!1;for(;k>=0;){const h=b[k];if(h.k==="d")h.part="num",p.num++,p.int--,m=!0;else if(m)break;k--}t.fixedDen=/^\d+$/.test(g)?Number(g):0,t.denDigits=p.den}t.counts=p}function j(t,s){if(Number.isInteger(t)&&t<1e15)return{int:t===0?"":String(t),dec:"0".repeat(s)};const n=t.toExponential(14),o=n.indexOf("e"),e=n[0]+n.slice(2,o),a=Number(n.slice(o+1))+1+s;let l,f=!1;if(a<0?l="":a>=e.length?l=e+"0".repeat(a-e.length):(f=e.charCodeAt(a)>=53,l=e.slice(0,a)),f){let g=l.length-1;const c=l.split("");for(;g>=0;)if(c[g]==="9")c[g]="0",g--;else{c[g]=String.fromCharCode(c[g].charCodeAt(0)+1);break}l=c.join(""),g<0&&(l="1"+l)}const b=l.length-s;let u,p;return b<=0?(u="",p="0".repeat(-b)+l):(u=l.slice(0,b),p=l.slice(b)),u=u.replace(/^0+/,""),{int:u,dec:p}}function ae(t){if(t.length<=3)return t;let s="",n=t.length%3;for(n>0&&(s=t.slice(0,n));n<t.length;n+=3)s+=(s?y.group:"")+t.slice(n,n+3);return s}function re(t,s){if(s.fixedDen>0)return[Math.round(t*s.fixedDen),s.fixedDen];const n=10**s.denDigits-1;let[o,e,i,a]=[0,1,1,0],l=t;for(let f=0;f<32;f++){const d=Math.floor(l),b=d*i+o,u=d*a+e;if(u>n)break;[o,e,i,a]=[i,a,b,u];const p=l-d;if(p<1e-10)break;l=1/p}return[i,a||1]}function ce(t,s){let n=s;t.pct&&(n*=100**t.pct),t.scale&&(n/=1e3**t.scale);const{counts:o}=t;let e="",i="",a="",l=!1,f="",d="";if(t.fraction){const r=o.int>0?Math.floor(n):0,[F,M]=re(n-r,t);let S=r,w=F;w===M&&o.int>0&&(S+=1,w=0),e=S===0?w===0&&o.int>0?"0":"":String(S),f=w===0&&o.int>0?"":String(w),d=w===0&&o.int>0?"":String(M)}else if(t.scientific){let r=n===0?0:Math.floor(Math.log10(n));const F=Math.max(o.int,1);F>1&&(r=Math.floor(r/F)*F);let M=j(n/10**r,o.dec);M.int.length>F&&(r+=F>1?F:1,M=j(n/10**r,o.dec)),e=n===0&&F>1?"0".repeat(F):M.int,i=M.dec,l=r<0,a=String(Math.abs(r))}else{const r=j(n,o.dec);e=r.int,i=r.dec}let b=i.length,u="";const p=t.tokens,g=[];for(const r of p)r.k==="d"&&r.part==="int"&&g.push(r);const c=new Map;let k=e.length-1;for(let r=g.length-1;r>=0;r--){const F=g[r];if(k>=0){let M=e[k--];r===0&&k>=0&&(M=e.slice(0,k+1)+M,k=-1),c.set(F,M)}else c.set(F,F.c==="0"?"0":F.c==="?"?" ":"")}if(t.grouping&&g.length){let r="";for(const S of g)r+=c.get(S);const F=/^ */.exec(r)[0],M=ae(r.slice(F.length));c.forEach((S,w)=>c.set(w,"")),c.set(g[0],F+M)}const m=[];for(const r of p)r.k==="d"&&r.part==="dec"&&m.push(r);for(let r=m.length-1;r>=0&&!(m[r].c==="0"||i[r]!=="0");r--)b=r;let h=0,C=0;const x=p.filter(r=>r.k==="d"&&r.part==="exp").length,$=a.padStart(x,"0");let L=0;const O=p.filter(r=>r.k==="d"&&r.part==="num").length,T=f.padStart(O," ");let A=0;const N=p.filter(r=>r.k==="d"&&r.part==="den").length,E=d.padEnd(N," "),W=t.fraction&&f==="";for(const r of p)switch(r.k){case"lit":u+=r.s===""?"":r.s;break;case"fill":u+=D+r.c+D;break;case"point":g.length===0&&!t.fraction&&!t.scientific&&e!=="0"&&!u.includes(y.decimal)&&(u+=e),u+=y.decimal;break;case"exp":u+=(r.upper?"E":"e")+(l?"-":r.plus?"+":"");break;case"slash":u+=W?" ":"/";break;case"d":switch(r.part){case"int":u+=c.get(r);break;case"dec":{const F=h++;F<b?u+=i[F]:r.c==="?"?u+=" ":r.c==="0"&&(u+="0");break}case"exp":C===0&&(u+=$),C++;break;case"num":{L===0?u+=T.slice(0,T.length-O+1):u+=T[T.length-O+L],L++;break}case"den":{A<N&&(u+=E[A]),A++,A===N&&E.length>N&&(u+=E.slice(N));break}default:}break;default:}return u}function fe(t){let s=Math.floor(t),n=t-s,o=Math.round(n*864e5);o>=864e5&&(s+=1,o-=864e5);let e,i,a;if(s===0)e=1900,i=1,a=0;else if(s===60)e=1900,i=2,a=29;else{const f=(s<60?s+1:s)-25569+719468,d=Math.floor(f/146097),b=f-d*146097,u=Math.floor((b-Math.floor(b/1460)+Math.floor(b/36524)-Math.floor(b/146096))/365),p=b-(365*u+Math.floor(u/4)-Math.floor(u/100)),g=Math.floor((5*p+2)/153);a=p-Math.floor((153*g+2)/5)+1,i=g<10?g+3:g-9,e=u+d*400+(i<=2?1:0)}const l=s===0?6:(s-1)%7;return{year:e,month:i,day:a,weekday:l,ms:o,serial:t}}function Fe(t,s){const n=t.trim().split(/[^0-9]+/).filter(Boolean).map(Number);if(n.length!==3)return null;const o=f=>n[s.indexOf(f)];let e=o("Y");const i=o("M"),a=o("D");if(e<100&&(e+=e<30?2e3:1900),!(i>=1&&i<=12&&a>=1&&a<=new Date(Date.UTC(e,i,0)).getUTCDate()))return null;const l=ue(e,i,a);return Number.isFinite(l)?l:null}function ue(t,s,n){const o=s<=2?t-1:t,e=s<=2?s+9:s-3,i=Math.floor(o/400),a=o-i*400,l=Math.floor((153*e+2)/5)+n-1,f=a*365+Math.floor(a/4)-Math.floor(a/100)+l,d=i*146097+f-719468+25569;return d<61?d-1:d}const _=t=>t<10?"0"+t:String(t);function J(t,s){const n=86400*10**(t.subDigits??0);s=Math.round(s*n)/n;const o=fe(s),e=o.ms;let i=Math.floor(e/1e3);const a=e-i*1e3;let l="";t.subDigits>0?(l=(a/1e3).toFixed(t.subDigits).slice(2),l.length===0&&(l="")):a>=500&&(i+=1);let f=Math.floor(i/3600);const d=Math.floor(i%3600/60),b=i%60;f>=24&&(f=23);const u=t.hour12?f%12===0?12:f%12:f,{loc:p}=t,g=t.hijri&&!p?.tag,c=p?.tag?Q(p.tag):g?K():y,k=p?.calendar||g?X(g?"hijri":p.calendar,s,o,p?.tag??null)??o:o;let m="";for(const h of t.tokens)switch(h.k){case"lit":m+=h.s;break;case"fill":m+=D+h.c+D;break;case"date":switch(h.c){case"y":m+=h.n<=2?_(k.year%100):String(k.year);break;case"e":{const C=P(p,y);if(C===null){m+=String(k.year);break}const x=o.year-R(C,s).firstYear+1;x===1&&p?.gannen?m+="元":m+=h.n===1?x:_(x);break}case"g":{const C=P(p,y);if(C===null)break;const x=R(C,s);m+=h.n===1?x.symbol:h.n===2?x.abbreviation:x.name;break}case"b":{const C=p?.tag?o.year:o.year+543;m+=h.n<=2?_(C%100):String(C);break}case"a":m+=h.n===3?c.shortDays?.[o.weekday]??c.days[o.weekday].slice(0,3):c.days[o.weekday];break;case"m":h.n===1?m+=k.month:h.n===2?m+=_(k.month):k.monthName?m+=h.n===5?k.monthName[0]:k.monthName:h.n===3?m+=c.shortMonths?.[k.month-1]??c.months[k.month-1].slice(0,3):h.n===5?m+=c.months[k.month-1][0]:m+=c.months[k.month-1];break;case"d":h.n===1?m+=k.day:h.n===2?m+=_(k.day):h.n===3?m+=c.shortDays?.[o.weekday]??c.days[o.weekday].slice(0,3):m+=c.days[o.weekday];break;case"h":m+=h.n===1?u:_(u);break;case"n":m+=h.n===1?d:_(d);break;case"s":m+=h.n===1?b:_(b);break;default:}break;case"elapsed":{const x=Math.floor(s)*86400+i,$=h.c==="h"?Math.floor(x/3600):h.c==="m"?Math.floor(x/60):x;m+=String($).padStart(h.n,"0");break}case"ampm":h.long?m+=f<12?p?.tag?c.am:y.amDesignator:p?.tag?c.pm:y.pmDesignator:m+=h.lower?f<12?"a":"p":f<12?"A":"P";break;case"sub":m+=y.decimal+l.slice(0,h.n);break;default:}return m}function I(t,s=11){if(t===0)return"0";const n=Math.abs(t);let o;if(Number.isInteger(t)&&n<1e11)o=String(t);else if(n>=1e11||n<1e-9){const e=t.toExponential(Math.max(s-6,0)),i=e.indexOf("e");let a=e.slice(0,i);a.includes(".")&&(a=a.replace(/\.?0+$/,""));const l=Number(e.slice(i+1)),f=Math.abs(l);o=`${a}E${l<0?"-":"+"}${f<10?"0":""}${f}`}else{const e=n>=1?Math.floor(Math.log10(n))+1:1,i=Math.max(s-e-(n<1?1:0),0),a=n<1?-Math.floor(Math.log10(n))-1:0;o=Number(t.toPrecision(15)).toFixed(Math.min(Math.max(i,0),20)),a>=i&&i>=0&&Number(o)===0&&(o=t.toExponential(s-6)),o.includes(".")&&(o=o.replace(/\.?0+$/,""))}return y.decimal==="."?o:o.replace(".",y.decimal)}class he{constructor(s){this.code=s;const n=U(s);this.sections=n.slice(0,4).map(se);const o=this.sections[0];if(this.general=this.sections.length===1&&o.isGeneral&&!o.dbnum&&o.tokens.every(e=>e.k==="lit"&&e.s===""),this.isDate=this.sections.some(e=>e.isDate),this.isText=this.sections.length===1&&o.isText,this.sections.some(e=>e.digits)){const e=this.number;this.number=i=>{const a=this.sections[this._pick(i)],l=e.call(this,i);return a.digits?V(l,a.digits):l}}}_pick(s){const n=this.sections;if(n[0].cond!==null||n[1]&&n[1].cond!==null){for(let i=0;i<Math.min(n.length,3);i++){const a=n[i].cond;if(a===null){if(i===n.length-1||i===2||n[i].isText&&i===3)return i;continue}if(ke(a,s))return i}return Math.min(n.length-1,2)}const e=n.length>1&&n.length<4&&n[n.length-1].isText?n.length-1:n.length;return e===1?0:e===2?s<0?1:0:s>0?0:s<0?1:2}number(s){if(this.general)return I(s);const n=this._pick(s),o=this.sections[n],e=this.sections[0].cond!==null||this.sections[1]&&this.sections[1].cond!==null,i=s<0&&(o.cond!==null?!ne(o.cond):n===0||e);if(o.isDate){const l=s<0&&n>0?-s:s;return Y(o,l)?"#".repeat(8):l<0?`-${J(o,-l)}`:J(o,l)}if(o.isNum){const l=ce(o,Math.abs(s));return i&&de(l)?"-"+l:l}if(o.isGeneral){let l="";for(const f of o.tokens)f.k==="lit"?l+=f.s===""?q(o,Math.abs(s)):f.s.replace("",q(o,Math.abs(s))):f.k==="fill"&&(l+=D+f.c+D);return s<0&&n===0?"-"+l:l}let a=i?"-":"";for(const l of o.tokens)l.k==="lit"?a+=l.s:l.k==="fill"?a+=D+l.c+D:l.k==="pct"?a+="%":l.k==="text"&&(a+=I(Math.abs(s)));return a}dateOverflow(s){if(this.general)return!1;const n=this._pick(s),o=this.sections[n];return!!o.isDate&&Y(o,s<0&&n>0?-s:s)}text(s){const n=this.sections,o=n.length===4?n[3]:n.length===1&&n[0].isText?n[0]:null;if(o===null)return s;let e="";for(const i of o.tokens)i.k==="lit"?e+=i.s:i.k==="text"?e+=s:i.k==="fill"&&(e+=D+i.c+D);return e}color(s){return this.sections[this._pick(s)].color}}const me=2958466;function Y(t,s){return t.tokens.some(o=>o.k==="date"||o.k==="ampm")?s<0||s>=me:!1}function de(t){for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);if(n>=49&&n<=57)return!0}return!1}function ke(t,s){switch(t.op){case"<":return s<t.v;case"<=":return s<=t.v;case">":return s>t.v;case">=":return s>=t.v;case"=":return s===t.v;default:return s!==t.v}}const G=new Map;function z(t){let s=G.get(t);return s===void 0&&(s=new he(t==="m/d/yyyy"?y.shortDate:t==="m/d/yyyy h:mm"?`${y.shortDate} h:mm`:t),G.set(t,s)),s}function ye(t,s){return z(t).number(s)}function xe(t){return z("#,##0").number(t)}export{be as BUILTIN_FORMATS,D as FILL_MARK,Fe as dateSerial,xe as formatCount,I as formatGeneral,ye as formatNumber,z as getFormatter,ue as partsToSerial,fe as serialToParts,ge as setNumberLocale};
package/core/online.js ADDED
@@ -0,0 +1 @@
1
+ let r=!0;const l=()=>r;function s(t){r=t!==!1}function c(t){if(r)return!0;const e=globalThis.location?.origin;if(!e||e==="null")return!1;try{const o=new URL(t,e);return`${{"ws:":"http:","wss:":"https:"}[o.protocol]??o.protocol}//${o.host}`===e}catch{return!1}}const a="Features that reach other sites are turned off here.";export{a as OFFLINE_MESSAGE,c as mayReach,l as onlineAllowed,s as setOnlineAllowed};
@@ -0,0 +1 @@
1
+ import{MAX_COLS as d0,MAX_ROWS as i0}from"./address.js";import{base64ToBytes as u0,bytesToBase64 as J}from"./base64.js";const c0=new Int32Array([1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591]),d=new Int32Array(160);function o0(a){const e=a.length,c=e+17+127>>7<<7,t=new Uint8Array(c);t.set(a),t[e]=128;const n=e*8;t[c-4]=n>>>24,t[c-3]=n>>>16,t[c-2]=n>>>8,t[c-1]=n;let r=1779033703,s=4089235720,o=3144134277,m=2227873595,p=1013904242,R=4271175723,T=2773480762,E=1595750129,O=1359893119,V=2917565137,v=2600822924,I=725511199,P=528734635,_=4215389547,$=1541459225,j=327033209;for(let C=0;C<c;C+=128){for(let l=0;l<32;l++){const f=C+l*4;d[l]=t[f]<<24|t[f+1]<<16|t[f+2]<<8|t[f+3]}for(let l=32;l<160;l+=2){const f=d[l-30],A=d[l-29],X=(f>>>1|A<<31)^(f>>>8|A<<24)^f>>>7,G=(A>>>1|f<<31)^(A>>>8|f<<24)^(A>>>7|f<<25),w=d[l-4],y=d[l-3],Y=(w>>>19|y<<13)^(y>>>29|w<<3)^w>>>6,q=(y>>>19|w<<13)^(w>>>29|y<<3)^(y>>>6|w<<26),L=(d[l-31]>>>0)+(G>>>0)+(d[l-13]>>>0)+(q>>>0);d[l+1]=L|0,d[l]=d[l-32]+X+d[l-14]+Y+Math.floor(L/4294967296)|0}let b=r,i=s,g=o,H=m,M=p,U=R,D=T,K=E,u=O,h=V,k=v,B=I,F=P,N=_,W=$,z=j;for(let l=0;l<160;l+=2){const f=(u>>>14|h<<18)^(u>>>18|h<<14)^(h>>>9|u<<23),A=(h>>>14|u<<18)^(h>>>18|u<<14)^(u>>>9|h<<23),X=u&k^~u&F,G=h&B^~h&N,w=(z>>>0)+(A>>>0)+(G>>>0)+(c0[l+1]>>>0)+(d[l+1]>>>0),y=W+f+X+c0[l]+d[l]+Math.floor(w/4294967296)|0,Y=(b>>>28|i<<4)^(i>>>2|b<<30)^(i>>>7|b<<25),q=(i>>>28|b<<4)^(b>>>2|i<<30)^(b>>>7|i<<25),L=b&g^b&M^g&M,f0=i&H^i&U^H&U,e0=(q>>>0)+(f0>>>0),b0=Y+L+Math.floor(e0/4294967296)|0;W=F,z=N,F=k,N=B,k=u,B=h;const t0=(K>>>0)+(w>>>0);u=D+y+Math.floor(t0/4294967296)|0,h=t0|0,D=M,K=U,M=g,U=H,g=b,H=i;const a0=(w>>>0)+(e0>>>0);b=y+b0+Math.floor(a0/4294967296)|0,i=a0|0}const S=(l,f)=>(l>>>0)+(f>>>0);let x=S(s,i);s=x|0,r=r+b+Math.floor(x/4294967296)|0,x=S(m,H),m=x|0,o=o+g+Math.floor(x/4294967296)|0,x=S(R,U),R=x|0,p=p+M+Math.floor(x/4294967296)|0,x=S(E,K),E=x|0,T=T+D+Math.floor(x/4294967296)|0,x=S(V,h),V=x|0,O=O+u+Math.floor(x/4294967296)|0,x=S(I,B),I=x|0,v=v+k+Math.floor(x/4294967296)|0,x=S(_,N),_=x|0,P=P+F+Math.floor(x/4294967296)|0,x=S(j,z),j=x|0,$=$+W+Math.floor(x/4294967296)|0}const Z=new Uint8Array(64),r0=new DataView(Z.buffer);return[r,s,o,m,p,R,T,E,O,V,v,I,P,_,$,j].forEach((C,b)=>r0.setInt32(b*4,C)),Z}function h0(a){const e=new Uint8Array(a.length*2);for(let c=0;c<a.length;c++){const t=a.charCodeAt(c);e[c*2]=t&255,e[c*2+1]=t>>8}return e}const Q=(a,e)=>{const c=new Uint8Array(a.length+e.length);return c.set(a),c.set(e,a.length),c},s0={"SHA-1":"SHA-1","SHA-256":"SHA-256","SHA-384":"SHA-384"};async function l0(a,e,c,t){const n=a==="SHA-512"?async o=>o0(o):async o=>new Uint8Array(await crypto.subtle.digest(s0[a],o));let r=await n(Q(e,h0(c)));const s=new Uint8Array(4);if(a==="SHA-512"){for(let o=0;o<t;o++)o>0&&o%8192===0&&await new Promise(m=>{setTimeout(m)}),s[0]=o,s[1]=o>>>8,s[2]=o>>>16,s[3]=o>>>24,r=o0(Q(r,s));return r}for(let o=0;o<t;o++)s[0]=o,s[1]=o>>>8,s[2]=o>>>16,s[3]=o>>>24,r=await n(Q(r,s));return r}function m0(a){let e=0;for(let c=a.length-1;c>=0;c--)e=e>>14&1|e<<1&32767,e^=a.charCodeAt(c)&255;return e=e>>14&1|e<<1&32767,e^=a.length,e^=52811,e.toString(16).toUpperCase().padStart(4,"0")}const x0=1e5;async function C0(a,e=""){const c=crypto.getRandomValues(new Uint8Array(16)),t=await l0("SHA-512",c,a,x0),n=r=>e?`${e}${r[0].toUpperCase()}${r.slice(1)}`:r;return{[n("algorithmName")]:"SHA-512",[n("hashValue")]:J(t),[n("saltValue")]:J(c),[n("spinCount")]:String(x0)}}const w0=["algorithmName","hashValue","saltValue","spinCount","password"];function g0(a,e=""){return a?!!(e?a[`${e}HashValue`]??a[`${e}Password`]:a.hashValue??a.password):!1}async function H0(a,e,c=""){const t=s=>c?a[`${c}${s[0].toUpperCase()}${s.slice(1)}`]:a[s],n=t("hashValue");if(n){const s=t("algorithmName")??"SHA-512";if(s!=="SHA-512"&&!s0[s])return!1;const o=await l0(s,u0(t("saltValue")??""),e,Number(t("spinCount")??0));return J(o)===n}const r=t("password");return r?r.toUpperCase()===m0(e):!0}const M0=a=>Object.fromEntries(Object.entries(a).filter(([e])=>!w0.includes(e))),p0=[["selectLockedCells","Select locked cells",!0],["selectUnlockedCells","Select unlocked cells",!0],["formatCells","Format cells",!1],["formatColumns","Format columns",!1],["formatRows","Format rows",!1],["insertColumns","Insert columns",!1],["insertRows","Insert rows",!1],["insertHyperlinks","Insert hyperlinks",!1],["deleteColumns","Delete columns",!1],["deleteRows","Delete rows",!1],["sort","Sort",!1],["autoFilter","Use AutoFilter",!1],["pivotTables","Use PivotTable reports",!1],["objects","Edit objects",!1],["scenarios","Edit scenarios",!1]],S0=new Set(["formatCells","formatColumns","formatRows","insertColumns","insertRows","insertHyperlinks","deleteColumns","deleteRows","sort","autoFilter","pivotTables"]);function U0(a){const e={},c=new Set(p0.map(([t])=>t));for(const[t,n]of Object.entries(a??{}))e[t]=c.has(t)&&typeof n=="boolean"?n?"0":"1":n;return e}function R0(a,e){const c=a.protection;if(!c)return!0;const t=c[e];return t===void 0?!S0.has(e):t==="0"||t==="false"}const n0=(a,e)=>a.styles.get(e).unlocked===!0;function T0(a,e,c){if(!e.protection)return!0;for(const t of c){const n=t.r1>e.maxRow,r=t.c1>e.maxCol;if((n||r)&&t.r0===0&&t.r1===i0-1&&!e.colStyles?.size||(n||r)&&t.c0===0&&t.c1===d0-1&&!e.rowStyles?.size)return!1;const s=Math.min(t.r1,Math.max(e.maxRow,t.r0)),o=Math.min(t.c1,Math.max(e.maxCol,t.c0));for(let m=t.r0;m<=s;m++)for(let p=t.c0;p<=o;p++)if(!n0(a,e.style(m,p)))return!1;if((t.r1>s||t.c1>o)&&!n0(a,e.style(t.r1,t.c1)))return!1}return!0}const E0=a=>{const e=a.protection?.lockStructure;return e==="1"||e==="true"};export{p0 as SHEET_OPTIONS,x0 as SPIN_COUNT,R0 as allows,g0 as hasPassword,C0 as hashPassword,m0 as legacyHash,U0 as protectionOptions,T0 as rangesEditable,o0 as sha512,E0 as structureLocked,H0 as verifyPassword,M0 as withoutPassword};
package/core/regexp.js ADDED
@@ -0,0 +1 @@
1
+ const p=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");export{p as escapeRegExp};
@@ -0,0 +1 @@
1
+ function h(e){const t=e.selectedSheets??null;return t?e.sheets.filter(s=>t.has(s)||s===e.sheet):[e.sheet]}export{h as selectedSheets};
package/core/sheet.js ADDED
@@ -0,0 +1 @@
1
+ import{Axis as A}from"./axis.js";import{MAX_COLS as v,MAX_ROWS as R}from"./address.js";import{FormulaStore as S}from"./formula-store.js";const u=10,M=1<<u,m=M-1,G=0,U=1,P=2,H=3,V=4,Y=8,j=16,W=32,X=64,L=7,Z=15,b=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA","#SPILL!","#CALC!","#BUSY!","#CONNECT!","#BLOCKED!","#FIELD!","#UNKNOWN!"];class O{constructor(){this.kinds=new Uint8Array(M),this.values=new Float64Array(M),this.styles=null}}let K=1;class q{constructor(t){this.uid=K++,this.name=t,this.rowExtras=null,this.colExtras=null,this.valueMeta=null,this.columns=[],this.maxRow=-1,this.maxCol=-1,this.rows=new A(R,16),this.cols=new A(v,65),this._formulas=new S,this.spills=null,this.rowStyles=null,this.colStyles=null,this.merges=[],this.cellTypes=null,this.sparkRules=null,this.cellDropdowns=null,this.cellTags=null,this.cellPicOpts=null,this.cellButtons=null,this.cellStates=null,this.changes=null,this.autoMerges=null,this.background=null,this.outlineColumn=null,this.split=null,this.frozenTrailingRows=0,this.frozenTrailingCols=0,this.axisSizing=null,this.hideZeros=!1,this.mergeIndex=null,this.frozenRows=0,this.frozenCols=0,this.showGridlines=!0,this.zoom=1,this.sourceId=null,this.revision=0}_chunk(t,s){const e=this.columns[s];return e===void 0?void 0:e[t>>>u]}_ensure(t,s){let e=this.columns[s];e===void 0&&(e=[],this.columns[s]=e);const n=t>>>u;let i=e[n];return i===void 0&&(i=new O,e[n]=i),i}kind(t,s){const e=this._chunk(t,s);return e===void 0?0:e.kinds[t&m]}value(t,s){const e=this._chunk(t,s);return e===void 0?0:e.values[t&m]}style(t,s){const e=this._chunk(t,s);if(e!==void 0&&e.styles!==null){const n=e.styles[t&m];if(n!==0)return n}if(this.rowStyles!==null){const n=this.rowStyles.get(t);if(n!==void 0)return n}if(this.colStyles!==null){const n=this.colStyles.get(s);if(n!==void 0)return n}return 0}cellStyle(t,s){const e=this._chunk(t,s);return e===void 0||e.styles===null?0:e.styles[t&m]}get formulas(){return this._formulas}set formulas(t){this._formulas=t instanceof S?t:S.from(t)}formula(t,s){return this._formulas.at(t,s)}setCell(t,s,e,n){const i=this._ensure(t,s),l=t&m;i.kinds[l]=e,i.values[l]=n,t>this.maxRow&&(this.maxRow=t),s>this.maxCol&&(this.maxCol=s)}setStyle(t,s,e){const n=this._ensure(t,s);if(n.styles===null){if(e===0)return;n.styles=new Uint16Array(M)}n.styles[t&m]=e,t>this.maxRow&&(this.maxRow=t),s>this.maxCol&&(this.maxCol=s)}setFormula(t,s,e){e?this._formulas.put(t,s,e):this._formulas.remove(t,s)}applyBatch(t){const{rows:s,cols:e,kinds:n,values:i,styles:l,count:o}=t;let h=-1,f=-1,d=null,k=this.maxRow,g=this.maxCol;for(let r=0;r<o;r++){const a=s[r],c=e[r],y=a>>>u;(c!==h||y!==f)&&(d=this._ensure(a,c),h=c,f=y);const p=a&m;d.kinds[p]=n[r],d.values[p]=i[r];const _=l[r];_!==0&&(d.styles===null&&(d.styles=new Uint16Array(M)),d.styles[p]=_),c>g&&(g=c)}if(o>0&&s[o-1]>k&&(k=s[o-1]),this.maxRow=k,this.maxCol=g,t.formulas){const r=this._formulas;for(const[a,c]of t.formulas)r.set(a,c)}if(t.valueMeta){this.valueMeta===null&&(this.valueMeta=new Map);for(const[r,a]of t.valueMeta)this.valueMeta.set(r,a)}this.revision++}addMerge(t){this.merges.push(t),this.mergeIndex=null}removeMergesIn(t){const s=this.merges.length;this.merges=this.merges.filter(e=>!D(e,t)),this.merges.length!==s&&(this.mergeIndex=null)}_buildMergeIndex(){const t=new Map;for(const s of this.merges)for(let e=s.r0>>>u;e<=s.r1>>>u;e++){const n=t.get(e);n?n.push(s):t.set(e,[s])}this.mergeIndex=t}mergeAt(t,s){if(this.merges.length===0)return null;this.mergeIndex===null&&this._buildMergeIndex();const e=this.mergeIndex.get(t>>>u);if(e===void 0)return null;for(let n=0;n<e.length;n++){const i=e[n];if(t>=i.r0&&t<=i.r1&&s>=i.c0&&s<=i.c1)return i}return null}mergesInRows(t,s){if(this.merges.length===0)return[];this.mergeIndex===null&&this._buildMergeIndex();const e=new Set;for(let n=t>>>u;n<=s>>>u;n++){const i=this.mergeIndex.get(n);if(i)for(const l of i)l.r1>=t&&l.r0<=s&&e.add(l)}return[...e]}jumpRow(t,s,e){const n=this.columns[s],i=e>0?R-1:0;if(t===i)return t;const l=h=>{const f=n===void 0?void 0:n[h>>>u];return f!==void 0&&(f.kinds[h&m]&15)!==0};let o=t+e;if(l(t)&&l(o)){for(;o!==i&&l(o+e);)o+=e;return o}for(;o>=0&&o<R;){const h=n===void 0?void 0:n[o>>>u];if(h===void 0){const f=e>0?(o>>>u)+1<<u:(o>>>u<<u)-1;if(f<0||f>=R)return i;o=f;continue}if((h.kinds[o&m]&15)!==0)return o;o+=e}return i}jumpCol(t,s,e){const n=e>0?v-1:0;if(s===n)return s;const i=h=>(this.kind(t,h)&15)!==0;let l=s+e;if(i(s)&&i(l)){for(;l!==n&&i(l+e);)l+=e;return l}const o=e>0?this.maxCol:0;for(;l!==n;){if(i(l))return l;if(e>0&&l>o)return n;l+=e}return n}aggregate(t){let s=0,e=0,n=0,i=1/0,l=-1/0;for(const{r0:o,c0:h,r1:f,c1:d}of t){const k=Math.min(d,this.maxCol),g=Math.min(f,this.maxRow);for(let r=h;r<=k;r++){const a=this.columns[r];if(a!==void 0)for(let c=o>>>u;c<=g>>>u;c++){const y=a[c];if(y===void 0)continue;const p=c<<u,_=Math.max(o-p,0),N=Math.min(g-p,m),{kinds:T,values:E}=y;for(let I=_;I<=N;I++){const w=T[I]&L;if(w!==0&&(n++,w===U)){const C=E[I];s+=C,e++,C<i&&(i=C),C>l&&(l=C)}}}}}return{sum:s,numeric:e,filled:n,min:i,max:l}}}function D(x,t){return x.r0<=t.r1&&x.r1>=t.r0&&x.c0<=t.c1&&x.c1>=t.c0}export{H as BOOL,u as CHUNK_BITS,m as CHUNK_MASK,M as CHUNK_SIZE,Z as CONTENT_MASK,W as DIRTY,G as EMPTY,V as ERR,b as ERRORS,X as EVALUATING,Y as FORMULA,L as KIND_MASK,U as NUM,j as SPILL,P as STR,q as Sheet,D as rangesTouch};
@@ -0,0 +1 @@
1
+ import{cellRef as C,parseCellRef as E,parseRangeRef as G,sheetPrefix as O}from"./address.js";import{child as y,children as T,parseTree as R}from"../io/xml-scan.js";import{escapeMarkup as d}from"../io/xml-escape.js";const b=new TextEncoder,u=e=>e==="1"||e==="true";function _(e,i){const r=e.indexOf("sparklineGroups");if(r<0)return[];const o=e.lastIndexOf("<",r),l=e.indexOf("sparklineGroups>",r+16);if(o<0||l<0)return[];const s=e.slice(o,l+16);let t;try{t=R(b.encode(`<r xmlns:x14="x" xmlns:xm="m">${s}</r>`))}catch{return[]}const h=y(t,"sparklineGroups");return T(h,"sparklineGroup").map(a=>{const n=a.a,p={},c=(f,L)=>{const A=y(a,f),w=i(A)??L;return A&&w&&(p[f]={hex:w,attrs:Object.entries(A.a??{}).map(([M,v])=>`${M}="${d(v)}"`).join(" ")}),w},m=f=>f===void 0||f===""||!Number.isFinite(Number(f))?void 0:Number(f),k=c("colorSeries","#376092"),$=c("colorNegative","#D00000"),x=c("colorMarkers","#D00000");return{type:n.type??"line",markers:u(n.markers),high:u(n.high),low:u(n.low),first:u(n.first),last:u(n.last),negative:u(n.negative),lineWeight:Number(n.lineWeight??.75),seriesColor:k,negativeColor:$,markerColor:x,axisColor:c("colorAxis","#000000"),firstColor:c("colorFirst",x),lastColor:c("colorLast",x),highColor:c("colorHigh",x),lowColor:c("colorLow",x),displayXAxis:u(n.displayXAxis),displayHidden:u(n.displayHidden),rightToLeft:u(n.rightToLeft),displayEmptyCellsAs:n.displayEmptyCellsAs??"zero",dateAxis:u(n.dateAxis),dateRange:y(a,"f")?.t??null,minAxisType:n.minAxisType??"individual",maxAxisType:n.maxAxisType??"individual",manualMin:m(n.manualMin),manualMax:m(n.manualMax),rawColors:p,items:T(y(a,"sparklines"),"sparkline").map(f=>({source:y(f,"f")?.t??"",cell:y(f,"sqref")?.t??""}))}})}const F=[["colorSeries","seriesColor"],["colorNegative","negativeColor"],["colorAxis","axisColor"],["colorMarkers","markerColor"],["colorFirst","firstColor"],["colorLast","lastColor"],["colorHigh","highColor"],["colorLow","lowColor"]],I=e=>`FF${String(e).slice(1,7).toUpperCase()}`;function S(e){const i=[];e.manualMax!==void 0&&e.maxAxisType==="custom"&&i.push(`manualMax="${e.manualMax}"`),e.manualMin!==void 0&&e.minAxisType==="custom"&&i.push(`manualMin="${e.manualMin}"`),e.lineWeight!==void 0&&e.lineWeight!==.75&&i.push(`lineWeight="${e.lineWeight}"`),e.type!=="line"&&i.push(`type="${d(e.type)}"`),e.dateAxis&&e.dateRange&&i.push('dateAxis="1"'),i.push(`displayEmptyCellsAs="${d(e.displayEmptyCellsAs??"gap")}"`);for(const s of["markers","high","low","first","last","negative","displayXAxis","displayHidden"])e[s]&&i.push(`${s}="1"`);e.minAxisType&&e.minAxisType!=="individual"&&i.push(`minAxisType="${d(e.minAxisType)}"`),e.maxAxisType&&e.maxAxisType!=="individual"&&i.push(`maxAxisType="${d(e.maxAxisType)}"`),e.rightToLeft&&i.push('rightToLeft="1"');const r=F.map(([s,t])=>{const h=e[t]??(t==="axisColor"?"#000000":e.markerColor),a=e.rawColors?.[s];return`<x14:${s} ${a&&a.hex===h&&a.attrs?a.attrs:`rgb="${I(h)}"`}/>`}).join(""),o=e.dateAxis&&e.dateRange?`<xm:f>${d(e.dateRange)}</xm:f>`:"",l=e.items.map(s=>`<x14:sparkline><xm:f>${d(s.source)}</xm:f><xm:sqref>${d(s.cell)}</xm:sqref></x14:sparkline>`).join("");return`<x14:sparklineGroup ${i.join(" ")}>${r}${o}<x14:sparklines>${l}</x14:sparklines></x14:sparklineGroup>`}function N(e){return e.length===0?"":`<ext xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" uri="{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"><x14:sparklineGroups xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">${e.map(S).join("")}</x14:sparklineGroups></ext>`}function H(e,i){const r=e.replace(/<ext\b[^>]*>\s*<x14:sparklineGroups[\s\S]*?<\/x14:sparklineGroups>\s*<\/ext>/,""),o=N(i),l=/<\/extLst>\s*(?:<\/worksheet>\s*)?$/.exec(r);if(!o)return l?r.replace(/<extLst>\s*<\/extLst>(\s*(?:<\/worksheet>\s*)?)$/,"$1"):r;if(l)return`${r.slice(0,l.index)}${o}${r.slice(l.index)}`;const s=r.lastIndexOf("</worksheet>"),t=`<extLst>${o}</extLst>`;return s>=0?r.slice(0,s)+t+r.slice(s):r+t}function X(e){if(e._sparkIndex&&e._sparkIndexOf===e.sparklines)return e._sparkIndex;const i=new Map;for(const r of e.sparklines??[])for(const o of r.items){const l=E(o.cell);l&&i.set(l.row*16384+l.col,{group:r,source:o.source})}return e._sparkIndex=i,e._sparkIndexOf=e.sparklines,i}function q(e,i,r,o){const l=[],s=G(r.replace(/^.*!/,"").replace(/\$/g,""));if(s===null)return!1;const t=s.r1-s.r0+1,h=s.c1-s.c0+1,a=r.includes("!")?r.slice(0,r.lastIndexOf("!")+1):O(e.name);if(o.r0!==o.r1&&o.c0!==o.c1)return!1;const n=[];for(let m=o.r0;m<=o.r1;m++)for(let k=o.c0;k<=o.c1;k++)n.push([m,k]);const p=n.length,c=p===1||(o.r1>o.r0?t===p:h!==p);return p>1&&t!==p&&h!==p?!1:(n.forEach(([m,k],$)=>{let x;p===1?x=`${C(s.r0,s.c0)}:${C(s.r1,s.c1)}`:c?x=`${C(s.r0+$,s.c0)}:${C(s.r0+$,s.c1)}`:x=`${C(s.r0,s.c0+$)}:${C(s.r1,s.c0+$)}`,l.push({source:`${a}${x}`,cell:C(m,k)})}),e.sparklines=[...e.sparklines??[],{type:i,markers:!1,high:!1,low:!1,first:!1,last:!1,negative:i==="stacked",lineWeight:.75,seriesColor:"#156082",negativeColor:"#C00000",markerColor:"#C00000",axisColor:"#000000",firstColor:"#C00000",lastColor:"#C00000",highColor:"#C00000",lowColor:"#C00000",displayEmptyCellsAs:"gap",minAxisType:"individual",maxAxisType:"individual",items:l}],e.sparklinesChanged=!0,!0)}export{q as addSparkline,_ as parseSparklines,H as patchSparklines,X as sparklineIndex,N as sparklinesXml};
package/core/sparse.js ADDED
@@ -0,0 +1 @@
1
+ const H=16384,y=["cellTypes","cellDropdowns","cellTags","cellButtons"],k=new Set,U=(n,o)=>n*16384+o,b=[];function L(n,{moved:o=!0}={}){y.includes(n)||y.push(n),o||k.add(n)}const v=n=>{for(const o of y)if(n[o])return!0;return!1};function M(n){const o={};for(const t of y)o[t]=n[t]??null;return o}const C=n=>o=>{const t=C(M(o));for(const c of y)o[c]=n[c];return o.cellTypesChanged=!0,t},m=()=>m,N=n=>C(M(n)),O=n=>M(n);function V(n,o,t,c,p=2e6){const i=C(M(n)),r=new Map(n[o]??[]);let a=0;for(const{r0:l,c0:e,r1:s,c1:d}of t){const x=Math.min(s,Math.max(n.maxRow,l)),f=Math.min(d,Math.max(n.maxCol,e));for(let u=l;u<=x&&a<p;u++)for(let w=e;w<=f&&a<p;w++,a++)c===void 0?r.delete(u*16384+w):r.set(u*16384+w,c)}return n[o]=r.size>0?r:null,n.cellTypesChanged=!0,i}function B(n,o,t){return t>0?n>=o?n+t:n:n>=o-t?n+t:n>=o?-1:n}function W(n,o){if(!v(n))return m;const t=C(M(n)),c=o.axis==="row";for(const p of y){if(k.has(p))continue;const i=n[p];if(!i)continue;const r=new Map;for(const[a,l]of i){const e=Math.floor(a/16384),s=a-e*16384,d=c?s:e;if(o.span&&(d<o.span[0]||d>o.span[1])){r.set(a,l);continue}const x=B(c?e:s,o.at,o.n);x<0||r.set(c?x*16384+s:e*16384+x,l)}n[p]=r.size>0?r:null}return n.cellTypesChanged=!0,t}function X(n,o,t,c,p,i,r="row"){if(!v(n))return m;const a=C(M(n));for(const l of y){if(k.has(l))continue;const e=n[l];if(!e)continue;const s=new Map;for(const[d,x]of e){const f=Math.floor(d/16384),u=d-f*16384;f>=o&&f<=t&&u>=c&&u<=p?s.set(r==="row"?(o+i[f-o])*16384+u:f*16384+c+i[u-c],x):s.set(d,x)}n[l]=s}return n.cellTypesChanged=!0,a}function j(n,o,t,c,{cut:p=!1,transpose:i=!1}={}){if(!v(n)&&!v(o))return m;const r=C(M(o)),a=n===o?null:C(M(n)),l=t.r1-t.r0+1,e=t.c1-t.c0+1,s=c.r1-c.r0+1,d=c.c1-c.c0+1;for(const f of y){const u=n[f],w=o[f];if(!u&&!w)continue;const T=[];if(u)for(const[E,K]of u){const Y=Math.floor(E/16384),S=E-Y*16384;Y>=t.r0&&Y<=t.r1&&S>=t.c0&&S<=t.c1&&T.push([Y-t.r0,S-t.c0,K])}const h=new Map(w??[]);if(p&&n===o)for(const[E,K]of T)h.delete((t.r0+E)*16384+t.c0+K);for(let E=c.r0;E<=c.r1;E++)for(let K=c.c0;K<=c.c1;K++)h.delete(E*16384+K);if(T.length>0){const E=i?e:l,K=i?l:e;for(let Y=0;Y+E<=s||Y===0;Y+=E)for(let S=0;S+K<=d||S===0;S+=K)for(const[z,R,D]of T){const _=c.r0+Y+(i?R:z),A=c.c0+S+(i?z:R);h.set(_*16384+A,D)}}if(o[f]=h.size>0?h:null,p&&n!==o&&u){const E=new Map(u);for(const[K,Y]of T)E.delete((t.r0+K)*16384+t.c0+Y);n[f]=E.size>0?E:null}}if(o.cellTypesChanged=!0,n.cellTypesChanged=!0,a===null)return r;const x=(f,u)=>w=>x(f(o),u(n))??w;return x(r,a)}function q(n,o,t){if(!v(n))return m;const c=C(M(n)),p=o.r1-o.r0+1,i=o.c1-o.c0+1;for(const r of y){const a=n[r];if(!a)continue;const l=new Map(a);for(let e=t.r0;e<=t.r1;e++)for(let s=t.c0;s<=t.c1;s++){if(e>=o.r0&&e<=o.r1&&s>=o.c0&&s<=o.c1)continue;const d=o.r0+((e-o.r0)%p+p)%p,x=o.c0+((s-o.c0)%i+i)%i,f=a.get(d*16384+x);f===void 0?l.delete(e*16384+s):l.set(e*16384+s,f)}n[r]=l.size>0?l:null}return n.cellTypesChanged=!0,c}export{j as copySparseBlock,q as fillSparse,m as noUndo,X as permuteSparse,L as registerSparseMap,V as setSparse,b as sheetRenameHooks,W as shiftSparse,U as sparseKey,O as sparseState,N as sparseUndo};
@@ -0,0 +1 @@
1
+ const o=new TextDecoder,n=16384,l=n-1;class c{constructor(){this.pages=[],this.importedCount=0,this.rich=null,this.extras=[],this.extraIndex=null,this.cacheKeys=new Int32Array(n).fill(-1),this.cacheValues=new Array(n),this.lastPage=null}get size(){return this.importedCount+this.extras.length}addPage(e,t){const s=t.length-1;this.pages.push({start:this.importedCount,count:s,bytes:e,offsets:t}),this.importedCount+=s}_pageOf(e){const t=this.lastPage;if(t!==null&&e>=t.start&&e<t.start+t.count)return t;const s=this.pages;let i=0,r=s.length-1;for(;i<r;){const a=i+r+1>>>1;s[a].start<=e?i=a:r=a-1}return this.lastPage=s[i],s[i]}get(e){if(e>=this.importedCount)return this.extras[e-this.importedCount]??"";const t=e&l;if(this.cacheKeys[t]===e)return this.cacheValues[t];const s=this._pageOf(e),i=e-s.start,r=u(s.bytes,s.offsets[i],s.offsets[i+1]);return this.cacheKeys[t]=e,this.cacheValues[t]=r,r}add(e){this.extraIndex===null&&(this.extraIndex=new Map);let t=this.extraIndex.get(e);return t===void 0&&(t=this.extras.length,this.extras.push(e),this.extraIndex.set(e,t)),this.importedCount+t}addRich(e,t){if(!t||t.length===0)return this.add(e);this.extraIndex===null&&(this.extraIndex=new Map);const s=`\0rich${JSON.stringify(t)}\0${e}`;let i=this.extraIndex.get(s);return i===void 0&&(i=this.extras.length,this.extras.push(e),this.extraIndex.set(s,i),this.rich??=new Map,this.rich.set(this.importedCount+i,t)),this.importedCount+i}}function u(h,e,t){const s=t-e;if(s===0)return"";if(s<=48){let i=!0;for(let r=e;r<t;r++)if(h[r]>=128){i=!1;break}if(i)return String.fromCharCode.apply(null,h.subarray(e,t))}return o.decode(h.subarray(e,t))}export{c as StringTable,u as decodeBytes};
package/core/styles.js ADDED
@@ -0,0 +1 @@
1
+ const u='"Aptos Narrow","Calibri","Carlito","Arial Narrow","Helvetica Neue",Arial,sans-serif',h="Aptos Narrow",g=12;function d(){return{fontName:h,fontSize:12,bold:!1,italic:!1,underline:0,strike:!1,color:null,fill:null,borders:null,numFmt:"General",hAlign:null,vAlign:null,wrap:!1,indent:0,rotation:0,shrink:!1}}const x=["pattern","gradient","quotePrefix","vertAlign","namedStyle","unlocked","hiddenFormula","readingOrder","justifyLastLine"];function c(r){return JSON.stringify(r,(e,i)=>e[0]==="_"?void 0:i)}class A{constructor(){this.list=[d()],this.index=null,this.sourceCount=0,this.deriveCache=new Map,this.hasButtons=!1,this.hasExt=!1}get(e){return this.list[e]??this.list[0]}load(e){this.list=e.length?e:[d()],this.sourceCount=e.length,this.index=null,this.hasExt=!1,this.hasButtons=!1,this.deriveCache.clear()}intern(e){if(this.index===null){this.index=new Map;for(let n=this.list.length-1;n>=0;n--)this.index.set(c(this.list[n]),n)}const i=c(e);let l=this.index.get(i);if(l===void 0){if(l=this.list.length,l>=65535)throw new Error("Too many cell formats");this.list.push(e),this.index.set(i,l)}return l}derive(e,i,l=JSON.stringify(i)){let n=this.deriveCache.get(l);n===void 0&&(n=new Map,this.deriveCache.set(l,n));let o=n.get(e);if(o===void 0){const f=this.get(e),s={...f,...i};for(const t of Object.keys(s))t[0]==="_"&&delete s[t];if(i.ext!==void 0){const t={...f.ext??{},...i.ext??{}};for(const a of Object.keys(t))t[a]===null&&delete t[a];Object.keys(t).length>0?(s.ext=t,t.buttons!==void 0&&(this.hasButtons=!0),this.hasExt=!0):delete s.ext}for(const t of x)(s[t]===null||s[t]===void 0||s[t]===!1)&&delete s[t];o=this.intern(s),n.set(e,o)}return o}}function b(r,e){const i=r.fontName===h?u:`"${r.fontName}",${u}`;return`${r.italic?"italic ":""}${r.bold?"bold ":""}${e}px ${i}`}export{h as DEFAULT_FONT,g as DEFAULT_SIZE,u as FONT_FALLBACK,A as StyleTable,b as cssFont,d as defaultStyle};