@8sheets/data-grid 1.0.2 → 1.1.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 (136) hide show
  1. package/README.md +1 -1
  2. package/api/serialize.js +1 -1
  3. package/api/theme-core.js +2 -0
  4. package/calc/adjust.js +1 -1
  5. package/calc/compile.js +1 -1
  6. package/calc/engine.js +1 -1
  7. package/calc/functions/array.js +1 -1
  8. package/calc/functions/database.js +1 -1
  9. package/calc/functions/date.js +1 -1
  10. package/calc/functions/financial.js +1 -1
  11. package/calc/functions/helpers.js +1 -1
  12. package/calc/functions/info.js +1 -1
  13. package/calc/functions/logical.js +1 -1
  14. package/calc/functions/lookup.js +1 -1
  15. package/calc/functions/math.js +1 -1
  16. package/calc/functions/stat.js +1 -1
  17. package/calc/functions/text.js +1 -1
  18. package/calc/parser.js +3 -3
  19. package/calc/values.js +1 -1
  20. package/calcx/async.js +1 -1
  21. package/calcx/culture/custom.js +1 -0
  22. package/calcx/culture/format-locale.js +1 -1
  23. package/calcx/culture/separators.js +1 -0
  24. package/calcx/functions/dynamic.js +1 -1
  25. package/calcx/functions/ets.js +1 -1
  26. package/calcx/functions/misc.js +1 -1
  27. package/calcx/lang/convert.js +1 -0
  28. package/cells/axis-ops.js +1 -1
  29. package/cells/block.js +1 -0
  30. package/cells/book-css.js +2 -2
  31. package/cells/cell-defaults.js +1 -1
  32. package/cells/cf-engine.js +1 -1
  33. package/cells/consolidate-links.js +1 -1
  34. package/cells/find-engine.js +2 -2
  35. package/cells/format-panes.js +3 -3
  36. package/cells/format-tabs.js +2 -2
  37. package/cells/outline-column.js +1 -1
  38. package/cells/panes.js +1 -1
  39. package/cells/rich-runs.js +2 -2
  40. package/cells/rich-values.js +1 -1
  41. package/cells/selection-modes.js +1 -1
  42. package/cells/shift-check.js +1 -0
  43. package/cells/table-rows.js +1 -0
  44. package/cells/text-layout.js +9 -8
  45. package/cells/ui-kit.js +15 -0
  46. package/cells/view-options.js +1 -1
  47. package/celltypes/cell-types.js +2 -2
  48. package/celltypes/diagonal.js +1 -1
  49. package/celltypes/dropdowns.js +3 -2
  50. package/celltypes/file-cell.js +2 -2
  51. package/celltypes/range-template.js +2 -2
  52. package/core/autofill.js +1 -1
  53. package/core/axis-styles.js +1 -0
  54. package/core/axis.js +1 -1
  55. package/core/cell-type-rules.js +1 -0
  56. package/core/changes.js +1 -1
  57. package/core/cond-format.js +1 -1
  58. package/core/culture.js +1 -0
  59. package/core/formula-refs.js +1 -1
  60. package/core/input.js +1 -1
  61. package/core/merge.js +1 -0
  62. package/core/numfmt.js +1 -1
  63. package/core/region-input.js +1 -0
  64. package/core/row-fit.js +1 -0
  65. package/core/sheet.js +1 -1
  66. package/core/sparse.js +1 -1
  67. package/core/structure.js +1 -0
  68. package/core/styles.js +1 -1
  69. package/core/tables.js +2 -2
  70. package/core/validation-ranges.js +1 -0
  71. package/core/whatif.js +1 -1
  72. package/core/workbook.js +1 -1
  73. package/datasheets/data-core.js +1 -1
  74. package/datasheets/gantt-paint.js +1 -1
  75. package/datasheets/manager.js +1 -1
  76. package/datasheets/path-binding.js +2 -2
  77. package/datasheets/rules.js +1 -1
  78. package/datasheets/view.js +2 -2
  79. package/i18n/dom.js +1 -1
  80. package/i18n/en/cells.js +1 -1
  81. package/i18n/en/format.js +1 -1
  82. package/i18n/en/misc.js +1 -1
  83. package/i18n/en/shell.js +2 -2
  84. package/i18n/pl/cells.js +1 -1
  85. package/i18n/pl/format.js +1 -1
  86. package/i18n/pl/misc.js +1 -1
  87. package/i18n/pl/shell.js +2 -2
  88. package/io/client.js +1 -1
  89. package/io/csv.js +8 -8
  90. package/io/plan.js +1 -1
  91. package/io/text-split.js +3 -3
  92. package/io/xlsx-read.js +1 -1
  93. package/io/xlsx-write.js +1 -1
  94. package/io/xml-scan.js +2 -1
  95. package/io/zip-reader.js +1 -1
  96. package/objects/chart-model.js +1 -1
  97. package/package.json +1 -1
  98. package/pivot/engine.js +1 -1
  99. package/pivot/xml.js +2 -2
  100. package/print/paginate.js +1 -1
  101. package/print/render-page.js +3 -3
  102. package/slicers/format.js +2 -2
  103. package/slicers/structured.js +1 -1
  104. package/table-view/api.js +1 -1
  105. package/table-view/cell-editor.js +2 -1
  106. package/table-view/chart.js +1 -0
  107. package/table-view/column-drag.js +1 -1
  108. package/table-view/context-menu.js +1 -0
  109. package/table-view/editors.js +1 -0
  110. package/table-view/events.js +1 -1
  111. package/table-view/files.js +1 -1
  112. package/table-view/fill-handle.js +1 -0
  113. package/table-view/filter-builder.js +1 -0
  114. package/table-view/find.js +1 -0
  115. package/table-view/grid-keys.js +2 -2
  116. package/table-view/labels-de.js +1 -0
  117. package/table-view/labels-es.js +1 -0
  118. package/table-view/labels-fr.js +1 -0
  119. package/table-view/labels-ja.js +1 -0
  120. package/table-view/labels.js +1 -1
  121. package/table-view/model.js +1 -1
  122. package/table-view/mount.js +1 -1
  123. package/table-view/panel.js +1 -1
  124. package/table-view/pivot-spec.js +1 -0
  125. package/table-view/pivot.js +1 -1
  126. package/table-view/public.d.ts +277 -28
  127. package/table-view/reader.worker.js +1 -1
  128. package/table-view/remote.js +1 -1
  129. package/table-view/row-drag.js +1 -0
  130. package/table-view/sparkline.js +1 -0
  131. package/table-view/state-check.js +1 -0
  132. package/table-view/table-css.js +380 -0
  133. package/table-view/version.js +1 -1
  134. package/ui/dialogs.js +3 -3
  135. package/ui/menu-base.js +1 -1
  136. package/ui/protection-ui.js +1 -1
@@ -1,4 +1,4 @@
1
- import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,ERR as st,ERRORS as lt,FORMULA as it,KIND_MASK as V,NUM as ct,STR as ut}from"../core/sheet.js";import{MAX_COLS as dt,MAX_ROWS as pt,parseRangeRef as ft}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as mt,validationAt as ht}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as yt}from"../cells/validation-alert.js";import{t as C}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Xt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const gt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,a){const r=t.kind(n,a)&V;if(r===at)return null;const o=t.value(n,a);return r===ct?o:r===ut?e.strings.get(o):r===ot?o!==0:r===st?lt[o]??"#N/A":null}function vt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:a=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!a&&(o.kind(t,n)&it)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function bt(e,t,n,a,r){const{book:o}=e,{sheet:u}=o,i=ht(u,t,n);if(!i||!i.showError)return!0;const l=xt(a);if(mt(o,u,i,t,n,l.kind??0,l.value,l.text??a))return!0;const s=()=>{};return yt(e,i,{retry:s,cancel:s,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:s}),!1}function kt(e,t,n,a,{format:r,overFormula:o=!1}={}){return!H(e,t,n,{overFormula:o})||!bt(e,t,n,a,()=>q(e,t,n,a,r))?!1:q(e,t,n,a,r)}function q(e,t,n,a,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",s=>{o.setInput(s,t,n,a),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const a=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,a};function wt(e,{r0:t,c0:n,r1:a,c1:r}){const o=t===0&&a===pt-1,u=n===0&&r===dt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):a,c1:u?Math.max(e.maxCol,25):r}}function Jt(e,t,n,a){const r=e.sheet,o=t.map(i=>wt(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>gt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const s of o)for(let x=s.r0;x<=s.r1;x++)for(let y=s.c0;y<=s.c1;y++)a===null?l.delete(P(x,y)):l.set(P(x,y),a);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function Qt(e,t={}){if(!W.includes(e))return null;const n={type:e},a=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(a("min"),a("max"),a("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const a=e.cellDropdowns;if(!a)return null;const r=e.mergeAt(t,n);return a.get(r?P(r.r0,r.c0):P(t,n))??null}function Zt(e){const{sheet:t,sel:n,grid:a}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=a.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Ct=`
1
+ import{allUndo as dt}from"../cells/block.js";import{writeCellTypes as pt}from"../core/cell-type-rules.js";import{formulaEntryLimit as ft}from"../calc/parser.js";import{overlayRoot as ht}from"../api/overlay.js";import{BOOL as mt,EMPTY as yt,ERR as gt,ERRORS as xt,FORMULA as vt,KIND_MASK as Z,NUM as bt,STR as wt}from"../core/sheet.js";import{MAX_COLS as kt,MAX_ROWS as Ct,parseRangeRef as Dt}from"../core/address.js";import{partsToSerial as N,serialToParts as P}from"../core/numfmt.js";import{validateEntry as St,validationAt as Lt}from"../core/cond-format.js";import{parseInput as Et}from"../core/input.js";import{askAboutInvalid as At}from"../cells/validation-alert.js";import{t as k}from"../i18n/index.js";const z=(e,t)=>e*16384+t,G=["calendar","time","month","datetime","color","slider","calculator","list"],j=new Map;function pe(e,t){G.includes(e)||G.push(e),j.set(e,t)}const Ft=2e5,tt=5e3,K={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function Y(e,t,n,o){const r=t.kind(n,o)&Z;if(r===yt)return null;const s=t.value(n,o);return r===bt?s:r===wt?e.strings.get(s):r===mt?s!==0:r===gt?xt[s]??"#N/A":null}function Mt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function V(e,t,n,{overFormula:o=!1}={}){const{book:r}=e,{sheet:s}=r;return e.loading?!1:s.protection&&!r.styles.get(s.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!o&&(s.kind(t,n)&vt)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function Tt(e,t,n,o,r){const{book:s}=e,{sheet:u}=s,i=Lt(u,t,n);if(!i||!i.showError)return!0;const l=Et(o);if(St(s,u,i,t,n,l.kind??0,l.value,l.text??o))return!0;const a=()=>{};return At(e,i,{retry:a,cancel:a,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:a}),!1}function Rt(e,t,n,o,{format:r,overFormula:s=!1}={}){if(!V(e,t,n,{overFormula:s}))return!1;if(o.startsWith("=")&&e.book.styles.get(e.book.sheet.style(t,n)).numFmt!=="@"){const u=ft(o.slice(1));if(u)return e.shell.setStatus(k(u)),!1}return Tt(e,t,n,o,()=>et(e,t,n,o,r))?et(e,t,n,o,r):!1}function et(e,t,n,o,r){const{book:s,grid:u,controller:i}=e,l=s.sheet;return s.transact("entry",a=>{s.setInput(a,t,n,o),r&&s.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,s.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const q=(e,t)=>n=>{const o=q(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,o};function It(e,{r0:t,c0:n,r1:o,c1:r}){const s=t===0&&o===Ct-1,u=n===0&&r===kt-1;return{r0:t,c0:n,r1:s?Math.max(e.maxRow,999):o,c1:u?Math.max(e.maxCol,25):r}}function fe(e,t,n,o){const r=e.sheet;if(n==="cellTypes")return e.transact("cell type",i=>{const l=i.sheet,a=l.cellTypes,y=l.cellTypeRules;return pt(l,t,o),l.cellTypes===a&&l.cellTypeRules===y?null:dt([q(n,a),q("cellTypeRules",y)])}),!0;const s=t.map(i=>It(r,i));let u=0;for(const i of s)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>Ft?!1:(e.transact("cell type",()=>{const i=q(n,r[n]??null),l=new Map(r[n]??[]);for(const a of s)for(let y=a.r0;y<=a.r1;y++)for(let x=a.c0;x<=a.c1;x++)o===null?l.delete(z(y,x)):l.set(z(y,x),o);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function he(e,t={}){if(!G.includes(e))return null;const n={type:e},o=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(o("min"),o("max"),o("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,tt).filter(Array.isArray).map(r=>r.slice(0,50).map(s=>typeof s=="number"?s:String(s).slice(0,1e3))))),j.get(e)?.sanitize?.(t,n),Object.freeze(n)}function nt(e,t,n){const o=e.cellDropdowns;if(!o)return null;const r=e.mergeAt(t,n);return o.get(r?z(r.r0,r.c0):z(t,n))??null}function me(e){const{sheet:t,sel:n,grid:o}=e;if(!t.cellDropdowns||!nt(t,n.row,n.col))return null;const r=o.cellRect(n.row,n.col),s=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-s,size:s}}const rt="ct-popup-style",$t=`
2
2
  .ct-popup { position: fixed; z-index: 60; padding: 8px; border-radius: 8px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: var(--shadow); font: 12px -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; outline: none; max-width: calc(100vw - 16px); }
3
3
  .ct-popup button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 0; cursor: default; }
4
4
  .ct-popup button:where(:not(.ct-btn)):hover:not(:disabled) { background: var(--hover); }
@@ -38,5 +38,6 @@ import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,E
38
38
  .ct-item:hover { background: var(--hover); }
39
39
  .ct-item.ct-cursor { background: var(--pressed); }
40
40
  .ct-mark { width: 12px; text-align: center; }
41
+ .ct-count { padding: 4px 8px 0; color: var(--ink-soft); font-size: 11px; }
41
42
  .ct-value { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
42
- `;function Dt(){if(document.getElementById(J))return;const e=document.createElement("style");e.id=J,e.textContent=Ct,document.head.append(e)}const f=(e,t={},...n)=>{const a=document.createElement(e);for(const[r,o]of Object.entries(t))r==="class"?a.className=o:r==="text"?a.textContent=o:r.startsWith("aria")||r==="role"?a.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,o):a[r]=o;return a.append(...n.filter(r=>r!=null)),a};let E=null;const te=()=>E!==null;function ee(e,t){E!==null&&(E.keepOpen=e,E.onClose=t)}function Et(e){E!==null&&(E.mode=e?"float":"confine")}function ne(){E!==null&&E.mode!=="float"&&L(!1)}function L(e=!0){if(E===null)return;const{el:t,app:n,onDocPointer:a,onClose:r}=E;E=null,r?.(),document.removeEventListener("pointerdown",a,!0),t.remove(),e&&n.controller.focusGrid()}function S(e,t,n,a,r){L(!1),Dt(),e.grid.ensureVisible(t,n);const o=f("div",{class:"ct-popup",role:"dialog",ariaLabel:C(a),tabIndex:-1}),u=l=>{!o.contains(l.target)&&!E?.keepOpen?.(l)&&L(!1)};E={el:o,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),o.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),L();else if(l.key==="Tab"){const s=[...o.querySelectorAll('button, input, [tabindex="0"]')].filter(y=>!y.disabled&&y.tabIndex>=0&&y.offsetParent!==null);if(s.length===0)return;const x=s.indexOf(document.activeElement);l.preventDefault(),s[(x+(l.shiftKey?-1:1)+s.length)%s.length].focus()}}),rt().append(o);const i=r(o);return St(e,t,n,o),(i??o).focus({preventScroll:!0}),o}function At(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,o=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=o,l=Math.max(60,i?r:o);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const x=n.querySelector(".ct-list");x&&(x.style.maxHeight=`${Math.max(30,l-18)}px`)}const s=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-s}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function St(e,t,n,a){const r=e.grid.host.getBoundingClientRect(),o=e.grid.domRect(e.grid.cellRect(t,n));if(E?.mode==="confine"){At(r,o,a);return}const u=a.getBoundingClientRect(),i=2,l=r.top+o.y+o.h+i,s=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+o.y-u.height-i);a.style.top=`${s}px`,a.style.left=`${Math.max(8,Math.min(r.left+o.x,window.innerWidth-u.width-8))}px`}function M(e,t,n,a,r){const o=kt(e,t,n,a,{...r,overFormula:!0});return o&&L(),o}const $=(e,t,n=null)=>f("div",{class:"ct-foot"},n,f("button",{class:"ct-btn",type:"button",text:C("Cancel"),onclick:()=>L()}),f("button",{class:"ct-btn ct-primary",type:"button",text:C("OK"),onclick:t})),_=["January","February","March","April","May","June","July","August","September","October","November","December"],Ft=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],N=61;function O(){const e=new Date;return I(e.getFullYear(),e.getMonth()+1,e.getDate())}const Q=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function T(e,t,n){const{book:a}=e,r=U(a,a.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Lt=(e,t)=>(t===12?I(e+1,1,1):I(e,t+1,1))-I(e,t,1);function Z(e,t,n,{min:a=N,max:r=1/0,marked:o=null}={}){const u=f("div"),i=Math.max(N,a),l=h=>Math.min(r,Math.max(i,h));let s=l(e);const x=e,y=O(),c=h=>{const k=R(s),m=I(k.year,k.month,1),D=m-R(m).weekday,b=d=>{const w=k.year*12+k.month-1+d,A=Math.floor(w/12),F=w%12+1;s=l(I(A,F,Math.min(k.day,Lt(A,F)))),c(h),n?.(s)},v=f("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${C(_[k.month-1])} ${k.year}`});for(const d of Ft)v.append(f("div",{class:"ct-dow",text:C(d)}));let g=null;for(let d=0;d<42;d++){const w=D+d;if(w<N){v.append(f("div"));continue}const A=w<i||w>r,F=R(w),Y=w===s,z=f("button",{class:`ct-cell${F.month!==k.month||A?" ct-out":""}${w===y?" ct-today":""}${(o?o(w):Math.floor(x)===w)?" ct-on":""}`,disabled:A,type:"button",text:String(F.day),tabIndex:Y?0:-1,role:"gridcell",ariaLabel:`${F.year}-${String(F.month).padStart(2,"0")}-${String(F.day).padStart(2,"0")}`,onclick:()=>t(w)});Y&&(g=z),v.append(z)}v.addEventListener("keydown",d=>{const w={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[d.key];if(w!==void 0)d.preventDefault(),s=l(s+w),c(!0),n?.(s);else if(d.key==="PageUp"||d.key==="PageDown")d.preventDefault(),b((d.key==="PageUp"?-1:1)*(d.shiftKey?12:1));else if(d.key==="Home"||d.key==="End"){d.preventDefault();const A=R(s).weekday;s=l(s+(d.key==="Home"?-A:6-A)),c(!0),n?.(s)}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(s))});const p=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:C("Previous month"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:`${C(_[k.month-1])} ${k.year}`}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:C("Next month"),tabIndex:-1,onclick:()=>b(1)}));u.replaceChildren(p,v),u.focusCell=g,h&&g?.focus({preventScroll:!0})};return c(!1),u}function tt(e){const t=(i,l,s)=>f("input",{type:"number",min:0,max:l,value:String(s),ariaLabel:C(i),onfocus(){this.select()},onkeydown(x){if(x.key==="ArrowUp"||x.key==="ArrowDown"){x.preventDefault();const y=Number(this.value)+(x.key==="ArrowUp"?1:-1);this.value=String(y>l?0:y<0?l:y)}}}),n=t("Hours",23,e.h),a=t("Minutes",59,e.m),r=t("Seconds",59,e.s),o=f("div",{class:"ct-time"},n,f("span",{text:":"}),a,f("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:o,first:n,read:()=>(u(n,23)*3600+u(a,59)*60+u(r,59))/86400}}function Mt(e,t,n,a){const r=T(e,t,n)??O();S(e,t,n,"Date picker",o=>{const u=s=>M(e,t,n,String(s),{format:a.format??B.calendar}),i=Z(Math.floor(r),u,void 0,{min:a.minDate,max:a.maxDate}),l=f("button",{class:"ct-btn",type:"button",text:C("Today"),onclick:()=>u(O())});return o.append(i,f("div",{class:"ct-foot"},l)),i.focusCell})}function It(e,t,n,a){const r=T(e,t,n),o=r===null?null:R(r).ms,u=new Date,i=o===null?{h:u.getHours(),m:u.getMinutes(),s:0}:Q(o);S(e,t,n,"Time picker",l=>{const s=tt(i),x=()=>M(e,t,n,String(s.read()),{format:a.format??B.time});return s.wrap.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),x())}),l.append(s.wrap,$(e,x)),s.first})}function Rt(e,t,n,a){const r=T(e,t,n),o=R(r!==null&&r>=N?r:O()),u=a.startYear??1901,i=a.stopYear??9999;let l=Math.max(u,Math.min(i,o.year)),s=o.month-1;S(e,t,n,"Month picker",x=>{const y=k=>M(e,t,n,String(I(l,k+1,1)),{format:a.format??B.month}),c=f("div"),h=k=>{const m=f("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let D=null;_.forEach((g,p)=>{const d=f("button",{class:`ct-cell${l===o.year&&p===o.month-1&&r!==null?" ct-on":""}`,type:"button",text:C(g).slice(0,3),ariaLabel:`${C(g)} ${l}`,tabIndex:p===s?0:-1,onclick:()=>y(p)});p===s&&(D=d),m.append(d)});const b=g=>{l=Math.max(u,Math.min(i,l+g)),h(!0)};m.addEventListener("keydown",g=>{const p={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[g.key];if(p!==void 0){g.preventDefault();const d=s+p;d<0?(s=d+12,b(-1)):d>11?(s=d-12,b(1)):(s=d,h(!0))}else g.key==="PageUp"||g.key==="PageDown"?(g.preventDefault(),b(g.key==="PageUp"?-1:1)):(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),y(s))});const v=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:C("Previous year"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:String(l)}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:C("Next year"),tabIndex:-1,onclick:()=>b(1)}));c.replaceChildren(v,m),c.focusCell=D,k&&D?.focus({preventScroll:!0})};return h(!1),x.append(c),c.focusCell})}function Tt(e,t,n,a){const r=T(e,t,n),o=new Date,u=r!==null&&r>=N?Math.floor(r):O(),i=r!==null?Q(R(r).ms):{h:o.getHours(),m:o.getMinutes(),s:0};S(e,t,n,"Date and time picker",l=>{let s=u;const x=tt(i),y=()=>M(e,t,n,String(s+x.read()),{format:a.format??B.datetime}),c=Z(s,h=>{s=h,x.first.focus()},h=>{s=h},{min:a.minDate,max:a.maxDate});return x.wrap.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),y())}),x.wrap.style.marginTop="8px",l.append(c,x.wrap,$(e,y)),c.focusCell})}const $t=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Nt(e,t,n,a){const r=a.palette??$t,{book:o}=e,u=U(o,o.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;S(e,t,n,"Color picker",l=>{let s=Math.max(0,r.indexOf(i));const x=m=>{if(a.target===void 0){M(e,t,n,m);return}H(e,t,n,{overFormula:!0})&&(o.applyStyle([{r0:t,c0:n,r1:t,c1:n}],a.target==="fill"?{fill:m}:{color:m}),e.grid.invalidate(),L())},y=f("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:C("Colors")}),c=r.map((m,D)=>{const b=f("button",{class:`ct-swatch${m===i?" ct-on":""}`,type:"button",ariaLabel:m,title:m,tabIndex:D===s?0:-1,onclick:()=>x(m)});return b.style.background=m,y.append(b),b});y.addEventListener("keydown",m=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[m.key];if(D!==void 0){m.preventDefault();const b=s+D;b>=0&&b<r.length&&(c[s].tabIndex=-1,s=b,c[s].tabIndex=0,c[s].focus())}else(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),x(r[s]))});const h=f("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:C("Hex color")}),k=()=>{const m=h.value.trim(),D=/^#?[0-9a-f]{6}$/i.test(m)?`#${m.replace("#","").toUpperCase()}`:null;D?x(D):h.select()};return h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),k())}),l.append(y,f("div",{class:"ct-foot"},h,f("button",{class:"ct-btn",type:"button",text:C("Apply"),onclick:k}))),c[s]})}function Ot(e,t,n,a){const r=a.min??0,o=a.max??100,u=a.step??1,i=T(e,t,n);S(e,t,n,"Slider",l=>{const s=f("input",{type:"range",min:r,max:o,step:u,value:String(i??r),ariaLabel:C("Value")}),x=f("span",{class:"ct-value",text:s.value});s.addEventListener("input",()=>{x.textContent=s.value});const y=()=>M(e,t,n,s.value);return s.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),y())}),l.append(s,$(e,y,x)),s})}const et=e=>Number(e.toPrecision(15));function Pt(e=0){let t=String(e),n=null,a=null,r=!0,o=!1;const u=()=>{const i=Number(t);if(a===null||n===null)return;let l;a==="+"?l=n+i:a==="-"?l=n-i:a==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(et(l)):(o=!0,t="Error"),n=null,a=null};return{get display(){return t},get failed(){return o},press(i){if(i==="C"){t="0",n=null,a=null,r=!0,o=!1;return}o||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(et(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),o||(n=Number(t),a=i,r=!0)))}}}function Bt(e,t,n){const a=T(e,t,n),r=Pt(a??0);S(e,t,n,"Calculator",o=>{const u=f("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:C("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?C("Error"):r.display},l=()=>{i("="),r.failed||M(e,t,n,r.display)},s=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],x=f("div",{class:"ct-grid ct-keys"});let y=null;for(const[c,h]of s){const k=f("button",{class:`ct-key${h==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(h)});h==="7"&&(y=k),x.append(k)}return o.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),o.append(u,x,$(e,l)),y})}function Ut(e,t){const{book:n}=e,a=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),o=r.lastIndexOf("!"),u=o>=0?r.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=ft(o>=0?r.slice(o+1):r);if(!l&&o<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const s=[],x=Math.min(l.r1,i.maxRow,l.r0+j-1),y=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=x;c++){const h=[];let k=null;for(let m=l.c0;m<=y;m++){const D=i.kind(c,m)&V,b=n.styles.list[i.style(c,m)]??n.styles.list[0];h.push(e.grid.displayText(D,i.value(c,m),b)),m-l.c0===a&&(k=U(n,i,c,m))}h.some(m=>m!=="")&&s.push({cells:h,value:k})}return{head:t.columns??null,rows:s}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[a]??null}))}}function Ht(e,t,n,a){const{head:r,rows:o}=Ut(e,a),{book:u}=e,i=U(u,u.sheet,t,n);S(e,t,n,"List",l=>{if(o.length===0)return l.append(f("div",{text:C("No items"),class:"ct-item"})),l;let s=Math.max(0,o.findIndex(v=>i!==null&&String(v.value)===String(i)));const x=f("table",{class:"ct-table"});r&&x.append(f("thead",{},f("tr",{},...r.map((v,g)=>{const p=f("th",{text:v});return a.widths?.[g]>0&&(p.style.minWidth=`${a.widths[g]}px`),p}))));const y=f("tbody",{role:"listbox",ariaLabel:C("List"),tabIndex:0}),c=v=>M(e,t,n,vt(o[v].value)),h=o.map((v,g)=>{const p=f("tr",{role:"option",ariaSelected:String(g===s),onclick:()=>c(g)},...v.cells.map(d=>f("td",{text:d})));return y.append(p),p}),k=v=>{let g=Math.max(0,Math.min(o.length-1,v));const p=g<s?-1:1;for(;h[g].hidden&&g+p>=0&&g+p<o.length;)g+=p;h[g].hidden||(h[s].setAttribute("aria-selected","false"),s=g,h[s].setAttribute("aria-selected","true"),h[s].scrollIntoView({block:"nearest"}))};let m="",D=0;y.addEventListener("keydown",v=>{const p={ArrowUp:s-1,ArrowDown:s+1,PageUp:s-8,PageDown:s+8,Home:0,End:o.length-1}[v.key];if(p!==void 0)v.preventDefault(),k(p);else if(v.key==="Enter"||v.key===" ")v.preventDefault(),c(s);else if(v.key.length===1&&!v.metaKey&&!v.ctrlKey){const d=performance.now();m=d-D>800?v.key:m+v.key,D=d;const w=o.findIndex(A=>A.cells[0].toLowerCase().startsWith(m.toLowerCase()));w>=0&&k(w)}}),x.append(y);let b=null;return a.filter&&(b=f("input",{type:"text",placeholder:C("Filter"),ariaLabel:C("Filter the list")}),b.style.width="100%",b.style.boxSizing="border-box",b.style.marginBottom="4px",b.addEventListener("input",()=>{const v=b.value.trim().toLowerCase();o.forEach((p,d)=>{h[d].hidden=v!==""&&!p.cells.some(w=>String(w).toLowerCase().includes(v))});const g=h.findIndex(p=>!p.hidden);g>=0&&h[s].hidden&&k(g)}),b.addEventListener("keydown",v=>{v.key==="ArrowDown"?(v.preventDefault(),y.focus()):v.key==="Enter"&&(v.preventDefault(),h[s].hidden||c(s))}),l.append(b)),l.append(f("div",{class:"ct-list"},x)),requestAnimationFrame(()=>h[s]?.scrollIntoView({block:"nearest"})),b??y})}function re(e,t,n,{items:a,selected:r=[],multi:o=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:s=!1,float:x}){S(e,t,n,i,y=>{x!==void 0&&Et(x);const c=new Set(r);let h=Math.max(0,a.findIndex(p=>c.has(p.value)));const k=()=>{const p=a.filter(d=>c.has(d.value)).map(d=>d.value);u(p)!==!1&&L()},m=f("div",{class:"ct-list",role:"listbox",ariaLabel:C(i),ariaMultiselectable:String(o),tabIndex:0});l>0&&(m.style.maxHeight=`${l*24}px`);const D=[],b=a.map((p,d)=>{const w=f("span",{class:"ct-mark",text:c.has(p.value)?"✓":""});D.push(w);const A=f("div",{class:`ct-item${d===h?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(p.value)),onclick:()=>{v(d),g(),o||k()}},w,f("span",{text:p.text}));return m.append(A),A});function v(p){const d=Math.max(0,Math.min(a.length-1,p));b[h]?.classList.remove("ct-cursor"),h=d,b[h]?.classList.add("ct-cursor"),b[h]?.scrollIntoView({block:"nearest"})}function g(){const p=a[h];p&&(o||c.clear(),c.has(p.value)?c.delete(p.value):c.add(p.value),a.forEach((d,w)=>{D[w].textContent=c.has(d.value)?"✓":"",b[w].setAttribute("aria-selected",String(c.has(d.value)))}))}return m.addEventListener("keydown",p=>{const d={ArrowUp:h-1,ArrowDown:h+1,Home:0,End:a.length-1}[p.key];d!==void 0?(p.preventDefault(),v(d)):p.key===" "?(p.preventDefault(),g(),o||k()):p.key==="Enter"?(p.preventDefault(),o||(c.clear(),g()),k()):s&&!o&&(p.key==="ArrowLeft"||p.key==="ArrowRight")&&(p.preventDefault(),c.clear(),g(),k(),e.controller.moveTo(t,Math.max(0,n+(p.key==="ArrowLeft"?-1:1))))}),y.append(m),o&&y.append($(e,k)),a.length===0&&m.append(f("div",{class:"ct-item",text:C("No items")})),m})}const Wt={calendar:Mt,time:It,month:Rt,datetime:Tt,color:Nt,slider:Ot,calculator:Bt,list:Ht};function nt(e,t,n,a){K.get(a.type)?.open?.(e,t,n,a)!==!0&&Wt[a.type]?.(e,t,n,a)}function oe(e,t,n,a){return e.loading?!1:(H(e,t,n,{overFormula:!0})&&nt(e,t,n,a),!0)}function ae(e,t,n){const{sheet:a}=e.book,r=X(a,t,n);if(!r||e.loading)return!1;if(!H(e,t,n,{overFormula:!0}))return!0;const o=a.mergeAt(t,n);return nt(e,o?o.r0:t,o?o.c0:n,r),!0}export{W as DROPDOWN_TYPES,gt as MAX_APPLY_CELLS,_ as MONTHS,Jt as applyToRanges,Z as buildCalendar,H as canWriteCell,Zt as cellDropdownArrow,P as cellKey,T as cellSerial,wt as clipRange,L as closeDropdown,M as commit,X as dropdownAt,$ as footer,te as isDropdownOpen,Ut as listData,vt as literalInput,f as make,Pt as makeCalculator,Qt as makeDropdown,ae as openCellDropdown,oe as openDropdownConfig,re as openListPopup,S as openPopup,ne as popupViewChanged,U as readCellValue,Xt as registerDropdownKind,Et as setPopupFloat,ee as setPopupKeepOpen,G as swapMap,tt as timeInputs,O as todaySerial,kt as writeCell};
43
+ `;function Ot(){if(document.getElementById(rt))return;const e=document.createElement("style");e.id=rt,e.textContent=$t,document.head.append(e)}const p=(e,t={},...n)=>{const o=document.createElement(e);for(const[r,s]of Object.entries(t))r==="class"?o.className=s:r==="text"?o.textContent=s:r.startsWith("aria")||r==="role"?o.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,s):o[r]=s;return o.append(...n.filter(r=>r!=null)),o};let F=null;const ye=()=>F!==null;function ge(e,t){F!==null&&(F.keepOpen=e,F.onClose=t)}function ot(e){F!==null&&(F.mode=e?"float":"confine")}function xe(){F!==null&&F.mode!=="float"&&R(!1)}function R(e=!0){if(F===null)return;const{el:t,app:n,onDocPointer:o,onClose:r}=F;F=null,r?.(),document.removeEventListener("pointerdown",o,!0),t.remove(),e&&n.controller.focusGrid()}function T(e,t,n,o,r){R(!1),Ot(),e.grid.ensureVisible(t,n);const s=p("div",{class:"ct-popup",role:"dialog",ariaLabel:k(o),tabIndex:-1}),u=l=>{!s.contains(l.target)&&!F?.keepOpen?.(l)&&R(!1)};F={el:s,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),s.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),R();else if(l.key==="Tab"){const a=[...s.querySelectorAll('button, input, [tabindex="0"]')].filter(x=>!x.disabled&&x.tabIndex>=0&&x.offsetParent!==null);if(a.length===0)return;const y=a.indexOf(document.activeElement);l.preventDefault(),a[(y+(l.shiftKey?-1:1)+a.length)%a.length].focus()}}),ht().append(s);const i=r(s);return Pt(e,t,n,s),(i??s).focus({preventScroll:!0}),s}function Nt(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,s=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=s,l=Math.max(60,i?r:s);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const y=n.querySelector(".ct-list");y&&(y.style.maxHeight=`${Math.max(30,l-18)}px`)}const a=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-a}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function Pt(e,t,n,o){const r=e.grid.host.getBoundingClientRect(),s=e.grid.domRect(e.grid.cellRect(t,n));if(F?.mode==="confine"){Nt(r,s,o);return}const u=o.getBoundingClientRect(),i=2,l=r.top+s.y+s.h+i,a=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+s.y-u.height-i);o.style.top=`${a}px`,o.style.left=`${Math.max(8,Math.min(r.left+s.x,window.innerWidth-u.width-8))}px`}function $(e,t,n,o,r){const s=Rt(e,t,n,o,{...r,overFormula:!0});return s&&R(),s}const H=(e,t,n=null)=>p("div",{class:"ct-foot"},n,p("button",{class:"ct-btn",type:"button",text:k("Cancel"),onclick:()=>R()}),p("button",{class:"ct-btn ct-primary",type:"button",text:k("OK"),onclick:t})),X=["January","February","March","April","May","June","July","August","September","October","November","December"],Ut=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],W=61;function _(){const e=new Date;return N(e.getFullYear(),e.getMonth()+1,e.getDate())}const st=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function U(e,t,n){const{book:o}=e,r=Y(o,o.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Bt=(e,t)=>(t===12?N(e+1,1,1):N(e,t+1,1))-N(e,t,1);function at(e,t,n,{min:o=W,max:r=1/0,marked:s=null}={}){const u=p("div"),i=Math.max(W,o),l=g=>Math.min(r,Math.max(i,g));let a=l(e);const y=e,x=_(),c=g=>{const b=P(a),d=N(b.year,b.month,1),C=d-P(d).weekday,w=h=>{const D=b.year*12+b.month-1+h,L=Math.floor(D/12),M=D%12+1;a=l(N(L,M,Math.min(b.day,Bt(L,M)))),c(g),n?.(a)},f=p("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${k(X[b.month-1])} ${b.year}`});for(const h of Ut)f.append(p("div",{class:"ct-dow",text:k(h)}));let v=null;for(let h=0;h<42;h++){const D=C+h;if(D<W){f.append(p("div"));continue}const L=D<i||D>r,M=P(D),B=D===a,S=p("button",{class:`ct-cell${M.month!==b.month||L?" ct-out":""}${D===x?" ct-today":""}${(s?s(D):Math.floor(y)===D)?" ct-on":""}`,disabled:L,type:"button",text:String(M.day),tabIndex:B?0:-1,role:"gridcell",ariaLabel:`${M.year}-${String(M.month).padStart(2,"0")}-${String(M.day).padStart(2,"0")}`,onclick:()=>t(D)});B&&(v=S),f.append(S)}f.addEventListener("keydown",h=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[h.key];if(D!==void 0)h.preventDefault(),a=l(a+D),c(!0),n?.(a);else if(h.key==="PageUp"||h.key==="PageDown")h.preventDefault(),w((h.key==="PageUp"?-1:1)*(h.shiftKey?12:1));else if(h.key==="Home"||h.key==="End"){h.preventDefault();const L=P(a).weekday;a=l(a+(h.key==="Home"?-L:6-L)),c(!0),n?.(a)}else(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),t(a))});const m=p("div",{class:"ct-row"},p("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:k("Previous month"),tabIndex:-1,onclick:()=>w(-1)}),p("div",{class:"ct-head",text:`${k(X[b.month-1])} ${b.year}`}),p("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:k("Next month"),tabIndex:-1,onclick:()=>w(1)}));u.replaceChildren(m,f),u.focusCell=v,g&&v?.focus({preventScroll:!0})};return c(!1),u}function lt(e){const t=(i,l,a)=>p("input",{type:"number",min:0,max:l,value:String(a),ariaLabel:k(i),onfocus(){this.select()},onkeydown(y){if(y.key==="ArrowUp"||y.key==="ArrowDown"){y.preventDefault();const x=Number(this.value)+(y.key==="ArrowUp"?1:-1);this.value=String(x>l?0:x<0?l:x)}}}),n=t("Hours",23,e.h),o=t("Minutes",59,e.m),r=t("Seconds",59,e.s),s=p("div",{class:"ct-time"},n,p("span",{text:":"}),o,p("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:s,first:n,read:()=>(u(n,23)*3600+u(o,59)*60+u(r,59))/86400}}function Ht(e,t,n,o){const r=U(e,t,n)??_();T(e,t,n,"Date picker",s=>{const u=a=>$(e,t,n,String(a),{format:o.format??K.calendar}),i=at(Math.floor(r),u,void 0,{min:o.minDate,max:o.maxDate}),l=p("button",{class:"ct-btn",type:"button",text:k("Today"),onclick:()=>u(_())});return s.append(i,p("div",{class:"ct-foot"},l)),i.focusCell})}function Wt(e,t,n,o){const r=U(e,t,n),s=r===null?null:P(r).ms,u=new Date,i=s===null?{h:u.getHours(),m:u.getMinutes(),s:0}:st(s);T(e,t,n,"Time picker",l=>{const a=lt(i),y=()=>$(e,t,n,String(a.read()),{format:o.format??K.time});return a.wrap.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),y())}),l.append(a.wrap,H(e,y)),a.first})}function _t(e,t,n,o){const r=U(e,t,n),s=P(r!==null&&r>=W?r:_()),u=o.startYear??1901,i=o.stopYear??9999;let l=Math.max(u,Math.min(i,s.year)),a=s.month-1;T(e,t,n,"Month picker",y=>{const x=b=>$(e,t,n,String(N(l,b+1,1)),{format:o.format??K.month}),c=p("div"),g=b=>{const d=p("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let C=null;X.forEach((v,m)=>{const h=p("button",{class:`ct-cell${l===s.year&&m===s.month-1&&r!==null?" ct-on":""}`,type:"button",text:k(v).slice(0,3),ariaLabel:`${k(v)} ${l}`,tabIndex:m===a?0:-1,onclick:()=>x(m)});m===a&&(C=h),d.append(h)});const w=v=>{l=Math.max(u,Math.min(i,l+v)),g(!0)};d.addEventListener("keydown",v=>{const m={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[v.key];if(m!==void 0){v.preventDefault();const h=a+m;h<0?(a=h+12,w(-1)):h>11?(a=h-12,w(1)):(a=h,g(!0))}else v.key==="PageUp"||v.key==="PageDown"?(v.preventDefault(),w(v.key==="PageUp"?-1:1)):(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),x(a))});const f=p("div",{class:"ct-row"},p("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:k("Previous year"),tabIndex:-1,onclick:()=>w(-1)}),p("div",{class:"ct-head",text:String(l)}),p("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:k("Next year"),tabIndex:-1,onclick:()=>w(1)}));c.replaceChildren(f,d),c.focusCell=C,b&&C?.focus({preventScroll:!0})};return g(!1),y.append(c),c.focusCell})}function zt(e,t,n,o){const r=U(e,t,n),s=new Date,u=r!==null&&r>=W?Math.floor(r):_(),i=r!==null?st(P(r).ms):{h:s.getHours(),m:s.getMinutes(),s:0};T(e,t,n,"Date and time picker",l=>{let a=u;const y=lt(i),x=()=>$(e,t,n,String(a+y.read()),{format:o.format??K.datetime}),c=at(a,g=>{a=g,y.first.focus()},g=>{a=g},{min:o.minDate,max:o.maxDate});return y.wrap.addEventListener("keydown",g=>{g.key==="Enter"&&(g.preventDefault(),x())}),y.wrap.style.marginTop="8px",l.append(c,y.wrap,H(e,x)),c.focusCell})}const Kt=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Yt(e,t,n,o){const r=o.palette??Kt,{book:s}=e,u=Y(s,s.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;T(e,t,n,"Color picker",l=>{let a=Math.max(0,r.indexOf(i));const y=d=>{if(o.target===void 0){$(e,t,n,d);return}V(e,t,n,{overFormula:!0})&&(s.applyStyle([{r0:t,c0:n,r1:t,c1:n}],o.target==="fill"?{fill:d}:{color:d}),e.grid.invalidate(),R())},x=p("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:k("Colors")}),c=r.map((d,C)=>{const w=p("button",{class:`ct-swatch${d===i?" ct-on":""}`,type:"button",ariaLabel:d,title:d,tabIndex:C===a?0:-1,onclick:()=>y(d)});return w.style.background=d,x.append(w),w});x.addEventListener("keydown",d=>{const C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[d.key];if(C!==void 0){d.preventDefault();const w=a+C;w>=0&&w<r.length&&(c[a].tabIndex=-1,a=w,c[a].tabIndex=0,c[a].focus())}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),y(r[a]))});const g=p("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:k("Hex color")}),b=()=>{const d=g.value.trim(),C=/^#?[0-9a-f]{6}$/i.test(d)?`#${d.replace("#","").toUpperCase()}`:null;C?y(C):g.select()};return g.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),b())}),l.append(x,p("div",{class:"ct-foot"},g,p("button",{class:"ct-btn",type:"button",text:k("Apply"),onclick:b}))),c[a]})}function Vt(e,t,n,o){const r=o.min??0,s=o.max??100,u=o.step??1,i=U(e,t,n);T(e,t,n,"Slider",l=>{const a=p("input",{type:"range",min:r,max:s,step:u,value:String(i??r),ariaLabel:k("Value")}),y=p("span",{class:"ct-value",text:a.value});a.addEventListener("input",()=>{y.textContent=a.value});const x=()=>$(e,t,n,a.value);return a.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),x())}),l.append(a,H(e,x,y)),a})}const it=e=>Number(e.toPrecision(15));function qt(e=0){let t=String(e),n=null,o=null,r=!0,s=!1;const u=()=>{const i=Number(t);if(o===null||n===null)return;let l;o==="+"?l=n+i:o==="-"?l=n-i:o==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(it(l)):(s=!0,t="Error"),n=null,o=null};return{get display(){return t},get failed(){return s},press(i){if(i==="C"){t="0",n=null,o=null,r=!0,s=!1;return}s||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(it(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),s||(n=Number(t),o=i,r=!0)))}}}function Gt(e,t,n){const o=U(e,t,n),r=qt(o??0);T(e,t,n,"Calculator",s=>{const u=p("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:k("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?k("Error"):r.display},l=()=>{i("="),r.failed||$(e,t,n,r.display)},a=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],y=p("div",{class:"ct-grid ct-keys"});let x=null;for(const[c,g]of a){const b=p("button",{class:`ct-key${g==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(g)});g==="7"&&(x=b),y.append(b)}return s.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),s.append(u,y,H(e,l)),x})}function jt(e,t){const{book:n}=e,o=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),s=r.lastIndexOf("!"),u=s>=0?r.slice(0,s).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=Dt(s>=0?r.slice(s+1):r);if(!l&&s<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const a=[],y=Math.min(l.r1,i.maxRow,l.r0+tt-1),x=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=y;c++){const g=[];let b=null;for(let d=l.c0;d<=x;d++){const C=i.kind(c,d)&Z,w=n.styles.list[i.style(c,d)]??n.styles.list[0];g.push(e.grid.displayText(C,i.value(c,d),w)),d-l.c0===o&&(b=Y(n,i,c,d))}g.some(d=>d!=="")&&a.push({cells:g,value:b})}return{head:t.columns??null,rows:a}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[o]??null}))}}function Xt(e,t,n,o){const{head:r,rows:s}=jt(e,o),{book:u}=e,i=Y(u,u.sheet,t,n);T(e,t,n,"List",l=>{if(s.length===0)return l.append(p("div",{text:k("No items"),class:"ct-item"})),l;let a=Math.max(0,s.findIndex(f=>i!==null&&String(f.value)===String(i)));const y=p("table",{class:"ct-table"});r&&y.append(p("thead",{},p("tr",{},...r.map((f,v)=>{const m=p("th",{text:f});return o.widths?.[v]>0&&(m.style.minWidth=`${o.widths[v]}px`),m}))));const x=p("tbody",{role:"listbox",ariaLabel:k("List"),tabIndex:0}),c=f=>$(e,t,n,Mt(s[f].value)),g=s.map((f,v)=>{const m=p("tr",{role:"option",ariaSelected:String(v===a),onclick:()=>c(v)},...f.cells.map(h=>p("td",{text:h})));return x.append(m),m}),b=f=>{let v=Math.max(0,Math.min(s.length-1,f));const m=v<a?-1:1;for(;g[v].hidden&&v+m>=0&&v+m<s.length;)v+=m;g[v].hidden||(g[a].setAttribute("aria-selected","false"),a=v,g[a].setAttribute("aria-selected","true"),g[a].scrollIntoView({block:"nearest"}))};let d="",C=0;x.addEventListener("keydown",f=>{const m={ArrowUp:a-1,ArrowDown:a+1,PageUp:a-8,PageDown:a+8,Home:0,End:s.length-1}[f.key];if(m!==void 0)f.preventDefault(),b(m);else if(f.key==="Enter"||f.key===" ")f.preventDefault(),c(a);else if(f.key.length===1&&!f.metaKey&&!f.ctrlKey){const h=performance.now();d=h-C>800?f.key:d+f.key,C=h;const D=s.findIndex(L=>L.cells[0].toLowerCase().startsWith(d.toLowerCase()));D>=0&&b(D)}}),y.append(x);let w=null;return o.filter&&(w=p("input",{type:"text",placeholder:k("Filter"),ariaLabel:k("Filter the list")}),w.style.width="100%",w.style.boxSizing="border-box",w.style.marginBottom="4px",w.addEventListener("input",()=>{const f=w.value.trim().toLowerCase();s.forEach((m,h)=>{g[h].hidden=f!==""&&!m.cells.some(D=>String(D).toLowerCase().includes(f))});const v=g.findIndex(m=>!m.hidden);v>=0&&g[a].hidden&&b(v)}),w.addEventListener("keydown",f=>{f.key==="ArrowDown"?(f.preventDefault(),x.focus()):f.key==="Enter"&&(f.preventDefault(),g[a].hidden||c(a))}),l.append(w)),l.append(p("div",{class:"ct-list"},y)),requestAnimationFrame(()=>g[a]?.scrollIntoView({block:"nearest"})),w??x})}function ve(e,t,n,{items:o,selected:r=[],multi:s=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:a=!1,float:y}){if(!s&&o.length>Jt){Zt(e,t,n,{items:o,selected:r,onDone:u,label:i,maxItems:l,moveOnSide:a,float:y});return}T(e,t,n,i,x=>{y!==void 0&&ot(y);const c=new Set(r);let g=Math.max(0,o.findIndex(m=>c.has(m.value)));const b=()=>{const m=o.filter(h=>c.has(h.value)).map(h=>h.value);u(m)!==!1&&R()},d=p("div",{class:"ct-list",role:"listbox",ariaLabel:k(i),ariaMultiselectable:String(s),tabIndex:0});l>0&&(d.style.maxHeight=`${l*24}px`);const C=[],w=o.map((m,h)=>{const D=p("span",{class:"ct-mark",text:c.has(m.value)?"✓":""});C.push(D);const L=p("div",{class:`ct-item${h===g?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(m.value)),onclick:()=>{f(h),v(),s||b()}},D,p("span",{text:m.text}));return d.append(L),L});function f(m){const h=Math.max(0,Math.min(o.length-1,m));w[g]?.classList.remove("ct-cursor"),g=h,w[g]?.classList.add("ct-cursor"),w[g]?.scrollIntoView({block:"nearest"})}function v(){const m=o[g];m&&(s||c.clear(),c.has(m.value)?c.delete(m.value):c.add(m.value),o.forEach((h,D)=>{C[D].textContent=c.has(h.value)?"✓":"",w[D].setAttribute("aria-selected",String(c.has(h.value)))}))}return d.addEventListener("keydown",m=>{const h={ArrowUp:g-1,ArrowDown:g+1,Home:0,End:o.length-1}[m.key];h!==void 0?(m.preventDefault(),f(h)):m.key===" "?(m.preventDefault(),v(),s||b()):m.key==="Enter"?(m.preventDefault(),s||(c.clear(),v()),b()):a&&!s&&(m.key==="ArrowLeft"||m.key==="ArrowRight")&&(m.preventDefault(),c.clear(),v(),b(),e.controller.moveTo(t,Math.max(0,n+(m.key==="ArrowLeft"?-1:1))))}),x.append(d),s&&x.append(H(e,b)),o.length===0&&d.append(p("div",{class:"ct-item",text:k("No items")})),d})}const Jt=300,O=24,ct=new WeakMap;function Qt(e){let t=ct.get(e);return t===void 0&&(t=e.map(n=>String(n.text).toLowerCase()),ct.set(e,t)),t}function Zt(e,t,n,{items:o,selected:r,onDone:s,label:u,maxItems:i,moveOnSide:l,float:a}){T(e,t,n,u,y=>{a!==void 0&&ot(a);const x=Qt(o),c=r.length?String(r[0]).toLowerCase():null,g=Int32Array.from(o.keys());let b=g,d=Math.max(0,c===null?0:o.findIndex(S=>String(S.value).toLowerCase()===c));const C=p("input",{type:"search",placeholder:k("Search"),ariaLabel:k("Search the list")});C.style.width="100%",C.style.boxSizing="border-box",C.style.marginBottom="4px";const w=p("div",{class:"ct-count"}),f=p("div",{class:"ct-list",role:"listbox",ariaLabel:k(u),tabIndex:0}),v=i>0?i:10;f.style.height=`${v*O}px`,f.style.maxHeight="none",f.style.position="relative";const m=p("div");f.append(m);let h=[];const D=S=>{const A=o[b[S]];A&&s([A.value])!==!1&&R()},L=()=>{m.style.height=`${b.length*O}px`;for(const E of h)E.remove();h=[];const S=Math.max(0,Math.floor(f.scrollTop/O)-2),A=Math.min(b.length,S+v+4);for(let E=S;E<A;E++){const J=o[b[E]],Q=c!==null&&String(J.value).toLowerCase()===c,I=p("div",{class:`ct-item${E===d?" ct-cursor":""}`,role:"option",ariaSelected:String(Q),onclick:()=>D(E)},p("span",{class:"ct-mark",text:Q?"✓":""}),p("span",{text:J.text}));I.style.position="absolute",I.style.top=`${E*O}px`,I.style.left="0",I.style.right="0",I.style.height=`${O}px`,I.style.boxSizing="border-box",f.append(I),h.push(I)}w.textContent=b.length===o.length?k("{n} items",{n:o.length.toLocaleString()}):k("{n} of {total}",{n:b.length.toLocaleString(),total:o.length.toLocaleString()})},M=S=>{d=Math.max(0,Math.min(b.length-1,S));const A=d*O;A<f.scrollTop?f.scrollTop=A:A+O>f.scrollTop+f.clientHeight&&(f.scrollTop=A+O-f.clientHeight),L()};f.addEventListener("scroll",L),C.addEventListener("input",()=>{const S=C.value.trim().toLowerCase();if(S==="")b=g;else{const A=[];for(let E=0;E<x.length;E++)x[E].includes(S)&&A.push(E);b=Int32Array.from(A)}d=0,f.scrollTop=0,L()});const B=S=>{const A=v-1,E={ArrowUp:d-1,ArrowDown:d+1,PageUp:d-A,PageDown:d+A}[S.key];E!==void 0?(S.preventDefault(),M(E)):S.key==="Enter"?(S.preventDefault(),D(d)):l&&S.target===f&&(S.key==="ArrowLeft"||S.key==="ArrowRight")&&(S.preventDefault(),D(d),e.controller.moveTo(t,Math.max(0,n+(S.key==="ArrowLeft"?-1:1))))};return C.addEventListener("keydown",B),f.addEventListener("keydown",B),y.append(C,f,w),L(),requestAnimationFrame(()=>M(d)),C})}const te={calendar:Ht,time:Wt,month:_t,datetime:zt,color:Yt,slider:Vt,calculator:Gt,list:Xt};function ut(e,t,n,o){j.get(o.type)?.open?.(e,t,n,o)!==!0&&te[o.type]?.(e,t,n,o)}function be(e,t,n,o){return e.loading?!1:(V(e,t,n,{overFormula:!0})&&ut(e,t,n,o),!0)}function we(e,t,n){const{sheet:o}=e.book,r=nt(o,t,n);if(!r||e.loading)return!1;if(!V(e,t,n,{overFormula:!0}))return!0;const s=o.mergeAt(t,n);return ut(e,s?s.r0:t,s?s.c0:n,r),!0}export{G as DROPDOWN_TYPES,Ft as MAX_APPLY_CELLS,X as MONTHS,fe as applyToRanges,at as buildCalendar,V as canWriteCell,me as cellDropdownArrow,z as cellKey,U as cellSerial,It as clipRange,R as closeDropdown,$ as commit,nt as dropdownAt,H as footer,ye as isDropdownOpen,jt as listData,Mt as literalInput,p as make,qt as makeCalculator,he as makeDropdown,we as openCellDropdown,be as openDropdownConfig,ve as openListPopup,T as openPopup,xe as popupViewChanged,Y as readCellValue,pe as registerDropdownKind,ot as setPopupFloat,ge as setPopupKeepOpen,q as swapMap,lt as timeInputs,_ as todaySerial,Rt as writeCell};
@@ -1,2 +1,2 @@
1
- import{overlayRoot as Q}from"../api/overlay.js";import{base64ToBytes as ee}from"../core/base64.js";import{xmlAttr as te}from"../io/xml-escape.js";import{STR as ne}from"../core/sheet.js";import{setSparse as A}from"../core/sparse.js";import{parseInput as se}from"../core/input.js";import{CELLS_NS as oe,cellTypePart as ie}from"./persist.js";import{registerSection as le}from"../cells/sections.js";import{canWriteCell as B,closeDropdown as z,make as v,openListPopup as re,openPopup as ae,readCellValue as $}from"./dropdowns.js";import{cachedImage as P,CellType as fe,controlRect as ce,defineCellType as ue,drawImageFit as R,frame as de,inkOf as _,inRect as x,labelOf as pe,leftText as D,makeCellType as O,safeImage as me,safeInt as he,safeText as ge,setFont as W,textWidth as j}from"./base.js";import{drawGlyph as b}from"./glyphs.js";import{t as p}from"../i18n/index.js";const S=10*1024*1024,U=256*1024*1024,q=/^[a-z0-9]{1,40}$/,N=/^[\w.+-]+\/[\w.+-]+$/,we=/^[A-Za-z0-9+/]*={0,2}$/,T=/^image\/(png|jpeg|gif|webp|bmp|svg\+xml|x-icon|vnd\.microsoft\.icon)$/,ye=[["#C43E1C",["ppt","pptx","pps","ppsx","key","odp"]],["#107C41",["xls","xlsx","xlsm","xlsb","csv","tsv","ods","numbers"]],["#185ABD",["doc","docx","rtf","odt","pages"]],["#D13438",["pdf"]],["#7A5C00",["zip","rar","7z","tar","gz","bz2","xz"]],["#8764B8",["mp3","wav","flac","aac","ogg","m4a"]],["#B4009E",["mp4","mov","avi","mkv","webm","wmv"]],["#008272",["png","jpg","jpeg","gif","bmp","svg","ico","webp","tif","tiff","heic"]],["#3A3A3A",["js","mjs","ts","json","xml","html","css","py","java","c","cpp","sh","sql","md"]],["#606060",["txt","log"]]],ve=new Map(ye.flatMap(([t,e])=>e.map(s=>[s,t]))),k=new Map;function We(t,e){const s=String(t).replace(/^\./,"").toLowerCase(),n=me(e);n?k.set(s,n):k.delete(s)}const Fe=t=>{const e=t.lastIndexOf(".");return e>0?t.slice(e+1).toLowerCase():""};function xe(t,e,s,n,o,i){const l=Fe(e),r=k.get(l);if(r){const h=P(r);h&&R(t,h,s,n,o,o);return}const c=ve.get(l);if(c===void 0){b(t,"file",s,n,o,i);return}const f=o*.8,a=s+(o-f)/2,u=o*.26;t.save(),t.fillStyle="#ffffff",t.strokeStyle=c,t.lineWidth=Math.max(1,o/14),t.beginPath(),t.moveTo(a,n),t.lineTo(a+f-u,n),t.lineTo(a+f,n+u),t.lineTo(a+f,n+o),t.lineTo(a,n+o),t.closePath(),t.fill(),t.stroke(),t.fillStyle=c;const m=o*.5;if(t.fillRect(a,n+o-m,f,m),o>=13){const h=l.slice(0,4).toUpperCase();t.font=`600 ${Math.max(5,Math.min(m*.86,f*1.5/h.length))}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(h,a+f/2,n+o-m/2)}t.restore()}const y=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t<10240?1:0)} KB`:`${(t/1024/1024).toFixed(1)} MB`,Y=t=>String(t).split(/[/\\]/).pop().replace(/[\u0000-\u001f\u007f￾￿]/g,"").slice(0,200)||"file",I=t=>Math.floor(t.length*3/4)-(t.endsWith("==")?2:t.endsWith("=")?1:0);function V(t){return t.cellFiles||(t.cellFiles=new Map),t.cellFiles}function be(t){let e;do e=Math.random().toString(36).slice(2,14);while(t.has(e));return e}function Se(t,e,s,n){const o=V(t),i=be(o);return o.set(i,{id:i,name:Y(e),type:N.test(s)?s:"application/octet-stream",size:I(n),b64:n,url:null}),i}function M(t){return t.url===null&&(t.url=URL.createObjectURL(new Blob([ee(t.b64)],{type:t.type}))),t.url}function Te(t){const e=t.cellFiles,s=new Set;for(const n of t.sheets)if(n.cellTypes)for(const[o,i]of n.cellTypes){if(i.type!=="file"||i.options.file===void 0||s.has(i.options.file))continue;const l=Math.floor(o/16384);F(e,i.options,$(t,n,l,o-l*16384))&&s.add(i.options.file)}return s}function je(t){if(!t.cellFiles||t.cellFiles.size===0)return[];const e=[];let s=0;for(const n of Te(t)){const o=t.cellFiles.get(n),i=te(JSON.stringify({id:o.id,name:o.name,type:o.type}).slice(0,-1)),l=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
- <cells xmlns="${oe}" version="1"><section name="cellFile" data="${i},&quot;b64&quot;:&quot;${o.b64}&quot;}"/></cells>`;e.push(ie(s++,l,"cellFile8c"))}return e}le("cellFile",{book:{save:()=>{},load(t,e){const{id:s,name:n,type:o,b64:i}=e??{};typeof s!="string"||!q.test(s)||typeof i!="string"||!we.test(i)||I(i)>S||V(t).set(s,{id:s,name:Y(n),type:typeof o=="string"&&N.test(o)?o:"application/octet-stream",size:I(i),b64:i,url:null})}}});function F(t,e,s){if(!t||e.file===void 0)return null;const n=t.get(e.file);return n!==void 0&&pe(s)===n.name?n:null}function ke(t,e){if(!e)return!0;const s=t.name.toLowerCase(),n=(t.type||"").toLowerCase();return e.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean).some(o=>o.startsWith(".")?s.endsWith(o):o.endsWith("/*")?n.startsWith(o.slice(0,-1)):n===o)}const Ie=t=>new Promise((e,s)=>{const n=new FileReader;n.onload=()=>e(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>s(n.error),n.readAsDataURL(t)});async function X(t,e,s,n,o){const{book:i,shell:l}=t,{sheet:r}=i;if(!B(t,e,s))return!1;const c=n.options.maxSize??S;if(o.size>c)return l.setStatus(p("{name} is {size}. This cell takes files up to {limit}.",{name:o.name,size:y(o.size),limit:y(c)})),!1;if(!ke(o,n.options.accept))return l.setStatus(p("This cell doesn't take {name}. It accepts {accept}.",{name:o.name,accept:n.options.accept})),!1;let f=o.size;for(const w of i.cellFiles?.values()??[])f+=w.size;if(f>U)return l.setStatus(p("A workbook can hold {size} of files, and this one would go over.",{size:y(U)})),!1;let a;try{a=await Ie(o)}catch{return l.setStatus(p("Couldn't read {name}.",{name:o.name})),!1}if(i.sheet!==r)return l.setStatus("The sheet changed while the file was loading, so it was not added."),!1;const u=Se(i,o.name,o.type,a),m=i.cellFiles.get(u).name,h=se(m).kind===ne&&m[0]!=="="&&m[0]!=="'"?m:`'${m}`;return i.transact("entry",w=>(i.setInput(w,e,s,h),A(r,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],O("file",{...n.options,file:u})))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function G(t,e,s,n){if(!B(t,e,s))return!1;const{book:o}=t,{sheet:i}=o,{file:l,...r}=n.options;return o.transact("entry",c=>(o.setInput(c,e,s,""),A(i,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],O("file",r)))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function C(t){const e=document.createElement("a");e.href=M(t),e.download=t.name,Q().append(e),e.click(),e.remove()}function H(t,e,s,n){ae(t,e,s,p("Preview of {name}",{name:n.name}),o=>{const i=v("img",{alt:n.name,src:M(n)});i.style.cssText="display:block;max-width:min(480px,80vw);max-height:60vh";const l=v("button",{class:"ct-btn",type:"button",text:p("Close"),onclick:()=>z()});return o.append(i,v("div",{class:"ct-foot"},v("button",{class:"ct-btn",type:"button",text:p("Download"),onclick:()=>C(n)}),l)),l})}function J(t,e,s,n){const o=document.createElement("input");o.type="file",n.options.accept&&(o.accept=n.options.accept),o.addEventListener("change",()=>{o.files[0]&&X(t,e,s,n,o.files[0])}),o.click()}class Me extends fe{static typeName="file";static sanitize(e){return{accept:ge(e.accept,300),maxSize:he(e.maxSize,1,S),preview:e.preview===!1?!1:void 0,download:e.download===!1?!1:void 0,file:typeof e.file=="string"&&q.test(e.file)?e.file:void 0}}get blocksEditing(){return!0}_parts(e,s){const n=Math.min(16*s,e.h),o=e.y+(e.h-n)/2,i={x:e.x+e.w-n,y:o,w:n,h:n},l=this.options.download===!1?null:{x:i.x-n,y:o,w:n,h:n};return{clear:i,down:l,thumb:{x:e.x,y:e.y,w:Math.min(e.h,e.w/3),h:e.h}}}paint(e,s,n,o,i,l){const r=F(l?.book?.cellFiles,this.options,n),c=l?.printing===!0,f=Math.round(2*i);if(W(e,o,i),r===null){if(c)return;const d=Math.min(Math.round(14*i),s.h-2),g=s.y+(s.h-d)/2,K=s.w-d-f*3,Z=p("Choose or drop a file"),L="#6e6e6e";b(e,"upload",s.x+f,g,d,L),K>0&&D(e,Z,s.x+f*2+d,s.y,s.h,L);return}const a=this._parts(s,i);let u=s.x+f;if(this.options.preview!==!1&&T.test(r.type)&&typeof URL<"u"&&!c){const d=P(M(r));d&&R(e,d,s.x+1,s.y+1,a.thumb.w-2,s.h-2),u=s.x+a.thumb.w+f}else{const d=Math.min(Math.round(14*i),s.h-2);xe(e,r.name,u,s.y+(s.h-d)/2,d,_(o)),W(e,o,i),u+=d+f}const h=c?s.x+s.w:a.down?a.down.x:a.clear.x;e.save(),e.beginPath(),e.rect(u,s.y,Math.max(0,h-u),s.h),e.clip();const w=`${r.name} (${y(r.size)})`;if(D(e,w,u,s.y,s.h,_(o)),e.restore(),c)return;const E=(d,g)=>b(e,d,g.x+g.w*.1,g.y+g.h*.1,g.w*.8,"#3c3c3c");a.down&&E("download",a.down),E("clear",a.clear)}hitTest(e,s,n,o=1){if(!x(e,s,n))return null;if(this.options.file===void 0)return{part:"pick"};const i=this._parts(e,o);return x(i.clear,s,n)?{part:"clear"}:i.down&&x(i.down,s,n)?{part:"download"}:{part:"file"}}activate(e,s,n,o,i){const{book:l}=e,r=F(l.cellFiles,this.options,$(l,l.sheet,s,n));if(r===null)return J(e,s,n,this),!0;if(o==null){const f=[{text:p("Download"),value:"download"},{text:p("Replace…"),value:"pick"},{text:p("Clear"),value:"clear"}];return T.test(r.type)&&f.unshift({text:p("Preview"),value:"preview"}),re(e,s,n,{items:f,label:"File",onDone:([a])=>(z(),a==="download"?C(r):a==="pick"?J(e,s,n,this):a==="clear"?G(e,s,n,this):a==="preview"&&H(e,s,n,r),!1)}),!0}const c=this.hitTest(ce(e,s,n),o,i,e.grid.zoom);return c?.part==="clear"?G(e,s,n,this):c?.part==="download"?(C(r),!0):T.test(r.type)&&this.options.preview!==!1?(H(e,s,n,r),!0):!1}fitWidth(e,s){const n=F(de.book?.cellFiles,this.options,e);return n===null?j(s,p("Choose or drop a file"))+22:j(s,`${n.name} (${y(n.size)})`)+58}}ue(Me);function Ue(t){const{host:e}=t.grid,s=n=>{const{sheet:o}=t.book;if(!o.cellTypes||!n.dataTransfer?.types?.includes("Files"))return null;const{x:i,y:l}=t.controller._point(n),r=t.controller._hit(i,l);if(r.type!=="cell")return null;const c=o.mergeAt(r.row,r.col),f=c?c.r0:r.row,a=c?c.c0:r.col,u=o.cellTypes.get(f*16384+a);return u!==void 0&&u.type==="file"?{row:f,col:a,t:u}:null};e.addEventListener("dragover",n=>{s(n)!==null&&(n.preventDefault(),n.stopImmediatePropagation(),n.dataTransfer.dropEffect="copy")},!0),e.addEventListener("drop",n=>{const o=s(n);if(o===null)return;n.preventDefault(),n.stopImmediatePropagation();const i=n.dataTransfer.files[0];i&&X(t,o.row,o.col,o.t,i)},!0)}export{Me as FileCell,S as MAX_FILE_BYTES,Ue as attachFileDrop,je as cellFilesPackage,xe as drawFileIcon,y as formatSize,We as setFileIcon,X as takeFile};
1
+ import{hasCellTypes as ee,typeAtPosition as B,visitStored as te}from"../core/cell-type-rules.js";import{overlayRoot as ne}from"../api/overlay.js";import{base64ToBytes as se}from"../core/base64.js";import{xmlAttr as oe}from"../io/xml-escape.js";import{STR as ie}from"../core/sheet.js";import{setSparse as z}from"../core/sparse.js";import{parseInput as le}from"../core/input.js";import{CELLS_NS as re,cellTypePart as ae}from"./persist.js";import{registerSection as fe}from"../cells/sections.js";import{canWriteCell as $,closeDropdown as P,make as F,openListPopup as ce,openPopup as ue,readCellValue as x}from"./dropdowns.js";import{cachedImage as R,CellType as de,controlRect as pe,defineCellType as me,drawImageFit as _,frame as he,inkOf as D,inRect as b,labelOf as ge,leftText as O,makeCellType as W,safeImage as we,safeInt as ye,safeText as ve,setFont as j,textWidth as U}from"./base.js";import{drawGlyph as S}from"./glyphs.js";import{t as p}from"../i18n/index.js";const T=10*1024*1024,q=256*1024*1024,N=/^[a-z0-9]{1,40}$/,Y=/^[\w.+-]+\/[\w.+-]+$/,Fe=/^[A-Za-z0-9+/]*={0,2}$/,I=/^image\/(png|jpeg|gif|webp|bmp|svg\+xml|x-icon|vnd\.microsoft\.icon)$/,xe=[["#C43E1C",["ppt","pptx","pps","ppsx","key","odp"]],["#107C41",["xls","xlsx","xlsm","xlsb","csv","tsv","ods","numbers"]],["#185ABD",["doc","docx","rtf","odt","pages"]],["#D13438",["pdf"]],["#7A5C00",["zip","rar","7z","tar","gz","bz2","xz"]],["#8764B8",["mp3","wav","flac","aac","ogg","m4a"]],["#B4009E",["mp4","mov","avi","mkv","webm","wmv"]],["#008272",["png","jpg","jpeg","gif","bmp","svg","ico","webp","tif","tiff","heic"]],["#3A3A3A",["js","mjs","ts","json","xml","html","css","py","java","c","cpp","sh","sql","md"]],["#606060",["txt","log"]]],be=new Map(xe.flatMap(([t,e])=>e.map(s=>[s,t]))),M=new Map;function Ne(t,e){const s=String(t).replace(/^\./,"").toLowerCase(),n=we(e);n?M.set(s,n):M.delete(s)}const Se=t=>{const e=t.lastIndexOf(".");return e>0?t.slice(e+1).toLowerCase():""};function Te(t,e,s,n,o,i){const l=Se(e),r=M.get(l);if(r){const h=R(r);h&&_(t,h,s,n,o,o);return}const c=be.get(l);if(c===void 0){S(t,"file",s,n,o,i);return}const f=o*.8,a=s+(o-f)/2,u=o*.26;t.save(),t.fillStyle="#ffffff",t.strokeStyle=c,t.lineWidth=Math.max(1,o/14),t.beginPath(),t.moveTo(a,n),t.lineTo(a+f-u,n),t.lineTo(a+f,n+u),t.lineTo(a+f,n+o),t.lineTo(a,n+o),t.closePath(),t.fill(),t.stroke(),t.fillStyle=c;const m=o*.5;if(t.fillRect(a,n+o-m,f,m),o>=13){const h=l.slice(0,4).toUpperCase();t.font=`600 ${Math.max(5,Math.min(m*.86,f*1.5/h.length))}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(h,a+f/2,n+o-m/2)}t.restore()}const y=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t<10240?1:0)} KB`:`${(t/1024/1024).toFixed(1)} MB`,V=t=>String(t).split(/[/\\]/).pop().replace(/[\u0000-\u001f\u007f￾￿]/g,"").slice(0,200)||"file",k=t=>Math.floor(t.length*3/4)-(t.endsWith("==")?2:t.endsWith("=")?1:0);function X(t){return t.cellFiles||(t.cellFiles=new Map),t.cellFiles}function Ie(t){let e;do e=Math.random().toString(36).slice(2,14);while(t.has(e));return e}function Me(t,e,s,n){const o=X(t),i=Ie(o);return o.set(i,{id:i,name:V(e),type:Y.test(s)?s:"application/octet-stream",size:k(n),b64:n,url:null}),i}function C(t){return t.url===null&&(t.url=URL.createObjectURL(new Blob([se(t.b64)],{type:t.type}))),t.url}function ke(t){const e=t.cellFiles,s=new Set;for(const n of t.sheets){for(const{ranges:o,spec:i}of n.cellTypeRules??[]){const l=i.options.file;i.type!=="file"||!e.has(l)||s.has(l)||o.some(r=>te(n,r,(c,f)=>B(n,c,f)===i&&v(e,i.options,x(t,n,c,f))))&&s.add(l)}if(n.cellTypes)for(const[o,i]of n.cellTypes){if(i.type!=="file"||i.options.file===void 0||s.has(i.options.file))continue;const l=Math.floor(o/16384);v(e,i.options,x(t,n,l,o-l*16384))&&s.add(i.options.file)}}return s}function Ye(t){if(!t.cellFiles||t.cellFiles.size===0)return[];const e=[];let s=0;for(const n of ke(t)){const o=t.cellFiles.get(n),i=oe(JSON.stringify({id:o.id,name:o.name,type:o.type}).slice(0,-1)),l=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <cells xmlns="${re}" version="1"><section name="cellFile" data="${i},&quot;b64&quot;:&quot;${o.b64}&quot;}"/></cells>`;e.push(ae(s++,l,"cellFile8c"))}return e}fe("cellFile",{book:{save:()=>{},load(t,e){const{id:s,name:n,type:o,b64:i}=e??{};typeof s!="string"||!N.test(s)||typeof i!="string"||!Fe.test(i)||k(i)>T||X(t).set(s,{id:s,name:V(n),type:typeof o=="string"&&Y.test(o)?o:"application/octet-stream",size:k(i),b64:i,url:null})}}});function v(t,e,s){if(!t||e.file===void 0)return null;const n=t.get(e.file);return n!==void 0&&ge(s)===n.name?n:null}function Ce(t,e){if(!e)return!0;const s=t.name.toLowerCase(),n=(t.type||"").toLowerCase();return e.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean).some(o=>o.startsWith(".")?s.endsWith(o):o.endsWith("/*")?n.startsWith(o.slice(0,-1)):n===o)}const Ee=t=>new Promise((e,s)=>{const n=new FileReader;n.onload=()=>e(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>s(n.error),n.readAsDataURL(t)});async function G(t,e,s,n,o){const{book:i,shell:l}=t,{sheet:r}=i;if(!$(t,e,s))return!1;const c=n.options.maxSize??T;if(o.size>c)return l.setStatus(p("{name} is {size}. This cell takes files up to {limit}.",{name:o.name,size:y(o.size),limit:y(c)})),!1;if(!Ce(o,n.options.accept))return l.setStatus(p("This cell doesn't take {name}. It accepts {accept}.",{name:o.name,accept:n.options.accept})),!1;let f=o.size;for(const w of i.cellFiles?.values()??[])f+=w.size;if(f>q)return l.setStatus(p("A workbook can hold {size} of files, and this one would go over.",{size:y(q)})),!1;let a;try{a=await Ee(o)}catch{return l.setStatus(p("Couldn't read {name}.",{name:o.name})),!1}if(i.sheet!==r)return l.setStatus("The sheet changed while the file was loading, so it was not added."),!1;const u=Me(i,o.name,o.type,a),m=i.cellFiles.get(u).name,h=le(m).kind===ie&&m[0]!=="="&&m[0]!=="'"?m:`'${m}`;return i.transact("entry",w=>(i.setInput(w,e,s,h),z(r,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],W("file",{...n.options,file:u})))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function H(t,e,s,n){if(!$(t,e,s))return!1;const{book:o}=t,{sheet:i}=o,{file:l,...r}=n.options;return o.transact("entry",c=>(o.setInput(c,e,s,""),z(i,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],W("file",r)))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function E(t){const e=document.createElement("a");e.href=C(t),e.download=t.name,ne().append(e),e.click(),e.remove()}function J(t,e,s,n){ue(t,e,s,p("Preview of {name}",{name:n.name}),o=>{const i=F("img",{alt:n.name,src:C(n)});i.style.cssText="display:block;max-width:min(480px,80vw);max-height:60vh";const l=F("button",{class:"ct-btn",type:"button",text:p("Close"),onclick:()=>P()});return o.append(i,F("div",{class:"ct-foot"},F("button",{class:"ct-btn",type:"button",text:p("Download"),onclick:()=>E(n)}),l)),l})}function K(t,e,s,n){const o=document.createElement("input");o.type="file",n.options.accept&&(o.accept=n.options.accept),o.addEventListener("change",()=>{o.files[0]&&G(t,e,s,n,o.files[0])}),o.click()}class Ae extends de{static typeName="file";static sanitize(e){return{accept:ve(e.accept,300),maxSize:ye(e.maxSize,1,T),preview:e.preview===!1?!1:void 0,download:e.download===!1?!1:void 0,file:typeof e.file=="string"&&N.test(e.file)?e.file:void 0}}get blocksEditing(){return!0}_parts(e,s){const n=Math.min(16*s,e.h),o=e.y+(e.h-n)/2,i={x:e.x+e.w-n,y:o,w:n,h:n},l=this.options.download===!1?null:{x:i.x-n,y:o,w:n,h:n};return{clear:i,down:l,thumb:{x:e.x,y:e.y,w:Math.min(e.h,e.w/3),h:e.h}}}paint(e,s,n,o,i,l){const r=v(l?.book?.cellFiles,this.options,n),c=l?.printing===!0,f=Math.round(2*i);if(j(e,o,i),r===null){if(c)return;const d=Math.min(Math.round(14*i),s.h-2),g=s.y+(s.h-d)/2,Z=s.w-d-f*3,Q=p("Choose or drop a file"),L="#6e6e6e";S(e,"upload",s.x+f,g,d,L),Z>0&&O(e,Q,s.x+f*2+d,s.y,s.h,L);return}const a=this._parts(s,i);let u=s.x+f;if(this.options.preview!==!1&&I.test(r.type)&&typeof URL<"u"&&!c){const d=R(C(r));d&&_(e,d,s.x+1,s.y+1,a.thumb.w-2,s.h-2),u=s.x+a.thumb.w+f}else{const d=Math.min(Math.round(14*i),s.h-2);Te(e,r.name,u,s.y+(s.h-d)/2,d,D(o)),j(e,o,i),u+=d+f}const h=c?s.x+s.w:a.down?a.down.x:a.clear.x;e.save(),e.beginPath(),e.rect(u,s.y,Math.max(0,h-u),s.h),e.clip();const w=`${r.name} (${y(r.size)})`;if(O(e,w,u,s.y,s.h,D(o)),e.restore(),c)return;const A=(d,g)=>S(e,d,g.x+g.w*.1,g.y+g.h*.1,g.w*.8,"#3c3c3c");a.down&&A("download",a.down),A("clear",a.clear)}hitTest(e,s,n,o=1){if(!b(e,s,n))return null;if(this.options.file===void 0)return{part:"pick"};const i=this._parts(e,o);return b(i.clear,s,n)?{part:"clear"}:i.down&&b(i.down,s,n)?{part:"download"}:{part:"file"}}activate(e,s,n,o,i){const{book:l}=e,r=v(l.cellFiles,this.options,x(l,l.sheet,s,n));if(r===null)return K(e,s,n,this),!0;if(o==null){const f=[{text:p("Download"),value:"download"},{text:p("Replace…"),value:"pick"},{text:p("Clear"),value:"clear"}];return I.test(r.type)&&f.unshift({text:p("Preview"),value:"preview"}),ce(e,s,n,{items:f,label:"File",onDone:([a])=>(P(),a==="download"?E(r):a==="pick"?K(e,s,n,this):a==="clear"?H(e,s,n,this):a==="preview"&&J(e,s,n,r),!1)}),!0}const c=this.hitTest(pe(e,s,n),o,i,e.grid.zoom);return c?.part==="clear"?H(e,s,n,this):c?.part==="download"?(E(r),!0):I.test(r.type)&&this.options.preview!==!1?(J(e,s,n,r),!0):!1}fitWidth(e,s){const n=v(he.book?.cellFiles,this.options,e);return n===null?U(s,p("Choose or drop a file"))+22:U(s,`${n.name} (${y(n.size)})`)+58}}me(Ae);function Ve(t){const{host:e}=t.grid,s=n=>{const{sheet:o}=t.book;if(!ee(o)||!n.dataTransfer?.types?.includes("Files"))return null;const{x:i,y:l}=t.controller._point(n),r=t.controller._hit(i,l);if(r.type!=="cell")return null;const c=o.mergeAt(r.row,r.col),f=c?c.r0:r.row,a=c?c.c0:r.col,u=B(o,f,a);return u!==void 0&&u.type==="file"?{row:f,col:a,t:u}:null};e.addEventListener("dragover",n=>{s(n)!==null&&(n.preventDefault(),n.stopImmediatePropagation(),n.dataTransfer.dropEffect="copy")},!0),e.addEventListener("drop",n=>{const o=s(n);if(o===null)return;n.preventDefault(),n.stopImmediatePropagation();const i=n.dataTransfer.files[0];i&&G(t,o.row,o.col,o.t,i)},!0)}export{Ae as FileCell,T as MAX_FILE_BYTES,Ve as attachFileDrop,Ye as cellFilesPackage,Te as drawFileIcon,y as formatSize,Ne as setFileIcon,G as takeFile};
@@ -1,2 +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};
1
+ import{typeAtPosition as Z}from"../core/cell-type-rules.js";import{BOOL as U,DIRTY as Y,EMPTY as L,ERR as q,FORMULA as _,KIND_MASK as E,NUM as z,Sheet as G,STR as Q}from"../core/sheet.js";import{cellRef as v,MAX_COLS as ee,MAX_ROWS as ne,parseRangeRef as te,sheetReferencePattern as se}from"../core/address.js";import{sparklineIndex as oe}from"../core/sparklines.js";import{paintSparkline as le}from"../sparklines/excel-paint.js";import{toFileFormula as ie}from"../calc/parser.js";import{cssFont as re}from"../core/styles.js";import{readCellValue as W}from"./dropdowns.js";import{CellType as ce,defineCellType as fe,formatted as ue,frame as F,labelOf as ae,oneOf as de,paintPlain as pe,parseJsonCached as he,safeText as me}from"./base.js";import{pathValue as ge}from"./data-object.js";const j=60,ye=2e4,be=500,ke=/^R(?:\[(-?\d{1,7})\])?C(?:\[(-?\d{1,5})\])?$/,Ae=/\{([^{}]+)\}/g,Ce={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 Me(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=te(o>=0?e.slice(o+1):e);return t&&i?{sheet:t,range:i}:null}function H(n,e){const o=se(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:ne-1,e.maxRow),S=Math.min(Number.isFinite(a)?a:ee-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 Re(n,e,o,s){const{engine:t}=n;if(!t)return null;const i=new G(e.name),l={left:ye};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=ie(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 De(n,e,o,s,t){t==null||t===""?n.setCell(o,s,L,0):typeof t=="number"?n.setCell(o,s,z,t):typeof t=="boolean"?n.setCell(o,s,U,t?1:0):n.setCell(o,s,Q,e.strings.add(String(t)))}function Se(n,e){const{engine:o}=e,{sheet:s,formulas:t}=n.copy;for(const i of t)s.setCell(i.r,i.c,_|Y|z,0);for(const i of t)try{o.read(s,i.r,i.c)}catch{s.setCell(i.r,i.c,z,0)}}function Oe(n,e,o){const s=Me(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=[],T=t.sparklines&&t.sparklines.length>0?oe(t):null,O=[];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?.[v(u,d)],R=Z(t,u,d),k=T?.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!==q&&(t.kind(u,d)&_)===0&&w.includes("{")&&(D=w),D!==null&&!D.includes("{")&&(D=null);const K=D===null&&(t.kind(u,d)&_)!==0;k!==void 0&&O.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)||O.length>0?Re(n,t,h,O):null;return{W:S,H:C,cells:h,sheet:t,copy:$}}const P=new Map;function B(n,e){const o=e.source;let s=P.get(o);return(s===void 0||s.id!==F.id||s.book!==n)&&(P.size>=64&&P.clear(),s={id:F.id,book:n,tpl:Oe(n,o,e.bindings)},P.set(o,s)),s.tpl}function x(n,e,o,s,t,i){const l=ke.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:ge(e,n)}function Te(n){return n==null?"":typeof n=="object"?JSON.stringify(n):String(ae(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(Ae,(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=(Ce[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 we(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 Fe(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=re(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?we(n,e,l-a*2):[e],h=c*1.22,T=s.vAlign??"bottom",O=C.length*h;let N=T==="top"?i+c*1.05:T==="center"?i+(r-O)/2+c*.95:i+r-O+c*.95-2*y;for(const $ of C)n.fillText($,S,N),N+=h;n.textAlign="left"}const Ne=/^(?:(?:'(?:[^']|'')+'|[^'!]+)!)?\$?[A-Za-z]{1,3}\$?\d{1,7}(?::\$?[A-Za-z]{1,3}\$?\d{1,7})?$/;function $e(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++>=be)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 Ie extends ce{static typeName="range";static sanitize(e){return{source:typeof e.source=="string"&&e.source.length<=300&&Ne.test(e.source)?e.source:"",fit:de(e.fit,["stretch"]),bindings:$e(e.bindings),title:me(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){pe(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),T=typeof s=="string"?he(s):void 0,O=T!==null&&typeof T=="object"?T: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&&De(d.sheet,r,f.r,f.c,J(f,O,r,y,N,$));d.formulas.length>0&&Se(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,O,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&&le(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!==""&&Fe(e,String(ue(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}}fe(Ie);export{Ie as RangeTemplateCell,B as template};
package/core/autofill.js CHANGED
@@ -1 +1 @@
1
- import{EMPTY as k,FORMULA as M,KIND_MASK as w,NUM as y,STR as x}from"./sheet.js";import{partsToSerial as v,serialToParts as C}from"./numfmt.js";const z=[["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],["January","February","March","April","May","June","July","August","September","October","November","December"],["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],["Poniedziałek","Wtorek","Środa","Czwartek","Piątek","Sobota","Niedziela"],["Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień"]];function I(t,e){return t===t.toUpperCase()?e.toUpperCase():t===t.toLowerCase()?e.toLowerCase():e}const b=t=>/[ymd]/i.test(t.replace(/"[^"]*"|\[[^\]]*\]/g,""))&&!/^general$/i.test(t);function L(t,e){const n=t.toLowerCase();for(const f of z){const r=f.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:f,i:r}}if(e)for(const f of e){const r=f.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:f,i:r}}return null}const S=(t,e)=>(e===12?v(t+1,1,1):v(t,e+1,1))-v(t,e,1);function $(t,e){const n=t.year*12+t.month-1+e,f=Math.floor(n/12),r=n-f*12+1;return v(f,r,Math.min(t.day,S(f,r)))}const O=t=>{const e=t%100;return e>=11&&e<=13?"th":["th","st","nd","rd"][t%10]??"th"},A=/^(?:q|qtr|quarter)\.?\s*$/i;function U(t){const e=/^(.*?)(\d+)(st|nd|rd|th)(.*)$/i.exec(t);if(e&&!/\d/.test(e[4])){const[,s,a,l,c]=e,p=Number(a),g=s===""&&A.test(c.trim())&&p>=1&&p<=4;return{pre:s,num:p,width:a.length,ord:!0,upper:l===l.toUpperCase(),rest:c,wrap:g,key:`${s}\0ord\0${c}`}}const n=/^(\d+)( .*)$/s.exec(t);if(n)return{pre:"",num:Number(n[1]),width:n[1].length,ord:!1,rest:n[2],wrap:!1,key:`\0lead\0${n[2]}`};const f=/^(.*?)(\d+)$/s.exec(t);if(!f)return null;const[,r,i]=f,o=Number(i),u=A.test(r)&&o>=1&&o<=4;return{pre:r,num:o,width:i.length,ord:!1,rest:"",wrap:u,key:`${r}\0`}}function B(t,e){const n=t.wrap?((e-1)%4+4)%4+1:Math.abs(e),f=String(n).padStart(t.width,"0");if(!t.ord)return`${t.pre}${f}${t.rest}`;const r=O(n);return`${t.pre}${f}${t.upper?r.toUpperCase():r}${t.rest}`}function F(t,e={}){const n=t.length;if(n===0||t.some(r=>r.kind&M))return()=>null;const f=t.map(r=>r.kind&w);if(f.every(r=>r===y)){const r=b(t[0].format??"General");if(n===1){if(!r&&e.alone&&!e.force)return()=>null;const d=r&&_(t[0].format)?1/24:1;return h=>({kind:y,value:t[0].value+d*(h+1)})}const i=t[1].value-t[0].value;let o=!0;for(let d=2;d<n;d++)Math.abs(t[d].value-t[d-1].value-i)>1e-9&&(o=!1);if(r){const d=t.map(m=>C(m.value)),h=(d[1].year-d[0].year)*12+d[1].month-d[0].month,N=m=>m.day===d[0].day||m.day<d[0].day&&m.day===S(m.year,m.month);if(d.every(N)&&h!==0)return m=>({kind:y,value:$(d[0],h*(n+m))})}if(o)return d=>({kind:y,value:t[n-1].value+i*(d+1)});const u=t.map((d,h)=>h),s=u.reduce((d,h)=>d+h,0)/n,a=t.reduce((d,h)=>d+h.value,0)/n;let l=0,c=0;for(let d=0;d<n;d++)l+=(u[d]-s)*(t[d].value-a),c+=(u[d]-s)**2;const p=l/c,g=a-p*s;return d=>({kind:y,value:g+p*(n+d)})}if(f.every(r=>r===x)){const r=t.map(o=>L(o.text,e.lists));if(r.every(Boolean)&&r.every(o=>o.list===r[0].list)){const{list:o}=r[0],u=n>=2&&(r[1].i-r[0].i+o.length)%o.length||1;return s=>({text:I(t[0].text,o[(r[n-1].i+u*(s+1))%o.length])})}const i=t.map(o=>U(o.text));if(i.every(Boolean)&&i.every(o=>o.key===i[0].key)){const o=i.map(a=>a.num),u=n>=2?o[1]-o[0]:1;let s=!0;for(let a=2;a<n;a++)o[a]-o[a-1]!==u&&(s=!1);if(s&&u!==0)return a=>({text:B(i[0],o[n-1]+u*(a+1))})}}return()=>null}function _(t){const e=String(t??"").replace(/"[^"]*"|\[[^\]]*\]|\\./g,"");return!/[dy]/i.test(e)&&/[hs]/i.test(e)}function T(t,e){const n=t.kind&w;if(t.kind&M||n===k)return null;if(n===y)return b(t.format??"General")?"date":"number";if(n!==x)return null;const f=L(t.text,e);if(f)return f.list;const r=U(t.text);return r?`text:${r.key}`:null}function E(t,e={}){const n=[],f=new Int32Array(t.length).fill(-1),r=new Int32Array(t.length),i=u=>(u.kind&w)===k&&!(u.kind&M);let o=!1;for(let u=0;u<t.length;){const s=T(t[u],e.lists);if(s===null){u++;continue}const a=[u];for(let c=u+1;c<t.length;c++)if(!i(t[c])){if(T(t[c],e.lists)!==s)break;a.push(c)}const l=F(a.map(c=>t[c]),{...e,alone:t.length===1});l(0)!==null&&(o=!0),a.forEach((c,p)=>{f[c]=n.length,r[c]=p}),n.push({n:a.length,series:l}),u=a[a.length-1]+1}return{active:o,at(u,s){const a=f[u];if(a<0)return null;const l=n[a];return l.series(s*l.n+r[u])}}}function R(t,e){const n=t.length,f=t[n-1].value;if(e==="days"){const u=n>=2?t[1].value-t[0].value:1;return(s,a)=>({kind:y,value:f+u*(a*n+s+1)})}if(e==="weekdays")return n>1?(u,s)=>({kind:y,value:t[u].value+7*(s+1)}):(u,s)=>({kind:y,value:P(f,"weekday",1,s+1)});const r=e==="months"?1:12,i=C(t[0].value),o=v(i.year,i.month,1);return(u,s)=>{const a=t[u].value,l=Math.floor(a)-o+1,c=i.year*12+i.month-1+r*(s+1),p=Math.floor(c/12),g=c-p*12+1,d=v(p,g,1),h=l>=1&&l<=31?d+Math.min(l,S(p,g))-1:d+l-1;return{kind:y,value:h+(a-Math.floor(a))}}}function P(t,e,n,f){if(e==="day")return t+n*f;const r=C(t),i=t-Math.floor(t);if(e==="month")return $(r,n*f)+i;if(e==="year")return $(r,12*n*f)+i;let o=t;const u=n*f<0?-1:1;for(let s=Math.abs(n*f);s>0;){o+=u;const a=Math.floor(o)%7;a!==0&&a!==1&&s--}return o}function W(t){const e=[],n=t[0];n.source.forEach((i,o)=>{i.split(/[\s,;._-]+/).filter(Boolean).forEach((s,a)=>{for(const l of[c=>c,c=>c.toUpperCase(),c=>c.toLowerCase(),c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()])e.push(c=>l((c[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??""));e.push(l=>((l[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??"").charAt(0)),e.push(l=>((l[o]??"").split(/[\s,;._-]+/).filter(Boolean)[a]??"").charAt(0).toUpperCase())}),e.push(s=>(s[o]??"").toUpperCase()),e.push(s=>(s[o]??"").toLowerCase()),e.push(s=>(s[o]??"").replace(/\S+/g,a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase())),e.push(s=>(s[o]??"").replace(/\D/g,"")),e.push(s=>(s[o]??"").replace(/[^\p{L}]/gu,""));for(let s=1;s<=Math.min(i.length,12);s++)e.push(a=>(a[o]??"").slice(0,s)),e.push(a=>(a[o]??"").slice(-s))});const f=e.slice(),r=n.target;for(let i=1;i<r.length;i++){const o=r.slice(0,i);for(const u of f)if(u(n.source)===o)for(const s of[0,1,2,3]){const a=r.slice(i,i+s),l=r.slice(i+s);if(!/[\p{L}\d]/u.test(a))for(const c of f)c(n.source)===l&&e.push(p=>`${u(p)}${a}${c(p)}`)}}return e.find(i=>t.every(o=>i(o.source)===o.target))??null}export{z as BUILTIN_LISTS,k as EMPTY,P as dateStep,W as flashFillRule,b as isDateFormat,R as makeDatePlan,E as makeFillPlan,F as makeSeries};
1
+ import{EMPTY as S,FORMULA as M,KIND_MASK as w,NUM as y,STR as $}from"./sheet.js";import{culture as O}from"./culture.js";import{partsToSerial as v,serialToParts as L}from"./numfmt.js";const T=[["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],["January","February","March","April","May","June","July","August","September","October","November","December"],["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]],z=[["Poniedziałek","Wtorek","Środa","Czwartek","Piątek","Sobota","Niedziela"],["Pon","Wt","Śr","Czw","Pt","Sob","Niedz"],["Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień"],["Sty","Lut","Mar","Kwi","Maj","Cze","Lip","Sie","Wrz","Paź","Lis","Gru"]],_=[...T,...z],F=[...z,...T];function B(t,e){return t===t.toUpperCase()?e.toUpperCase():t===t.toLowerCase()?e.toLowerCase():e}const C=t=>/[ymd]/i.test(t.replace(/"[^"]*"|\[[^\]]*\]/g,""))&&!/^general$/i.test(t);function A(t,e){const n=t.toLowerCase(),f=O().language==="pl"?F:_;for(const l of f){const r=l.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:l,i:r}}if(e)for(const l of e){const r=l.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:l,i:r}}return null}const b=(t,e)=>(e===12?v(t+1,1,1):v(t,e+1,1))-v(t,e,1);function x(t,e){const n=t.year*12+t.month-1+e,f=Math.floor(n/12),l=n-f*12+1;return v(f,l,Math.min(t.day,b(f,l)))}const D=t=>{const e=t%100;return e>=11&&e<=13?"th":["th","st","nd","rd"][t%10]??"th"},I=/^(?:q|qtr|quarter)\.?\s*$/i;function N(t){const e=/^(.*?)(\d+)(st|nd|rd|th)(.*)$/i.exec(t);if(e&&!/\d/.test(e[4])){const[,o,s,u,c]=e,p=Number(s),g=o===""&&I.test(c.trim())&&p>=1&&p<=4;return{pre:o,num:p,width:s.length,ord:!0,upper:u===u.toUpperCase(),rest:c,wrap:g,key:`${o}\0ord\0${c}`}}const n=/^(\d+)( .*)$/s.exec(t);if(n)return{pre:"",num:Number(n[1]),width:n[1].length,ord:!1,rest:n[2],wrap:!1,key:`\0lead\0${n[2]}`};const f=/^(.*?)(\d+)$/s.exec(t);if(!f)return null;const[,l,r]=f,i=Number(r),a=I.test(l)&&i>=1&&i<=4;return{pre:l,num:i,width:r.length,ord:!1,rest:"",wrap:a,key:`${l}\0`}}function E(t,e){const n=t.wrap?((e-1)%4+4)%4+1:Math.abs(e),f=String(n).padStart(t.width,"0");if(!t.ord)return`${t.pre}${f}${t.rest}`;const l=D(n);return`${t.pre}${f}${t.upper?l.toUpperCase():l}${t.rest}`}function J(t,e={}){const n=t.length,f=e.direction??1;if(n===0||t.some(r=>r.kind&M))return()=>null;const l=t.map(r=>r.kind&w);if(l.every(r=>r===y)){const r=C(t[0].format??"General");if(n===1){if(!r&&e.alone&&!e.force)return()=>null;const d=r&&W(t[0].format)?1/24:1;return h=>({kind:y,value:t[0].value+f*d*(h+1)})}const i=t[1].value-t[0].value;let a=!0;for(let d=2;d<n;d++)Math.abs(t[d].value-t[d-1].value-i)>1e-9&&(a=!1);if(r){const d=t.map(m=>L(m.value)),h=(d[1].year-d[0].year)*12+d[1].month-d[0].month,P=m=>m.day===d[0].day||m.day<d[0].day&&m.day===b(m.year,m.month);if(d.every(P)&&h!==0)return m=>({kind:y,value:x(d[0],h*(n+m))})}if(a)return d=>({kind:y,value:t[n-1].value+i*(d+1)});const o=t.map((d,h)=>h),s=o.reduce((d,h)=>d+h,0)/n,u=t.reduce((d,h)=>d+h.value,0)/n;let c=0,p=0;for(let d=0;d<n;d++)c+=(o[d]-s)*(t[d].value-u),p+=(o[d]-s)**2;const g=c/p,k=u-g*s;return d=>({kind:y,value:k+g*(n+d)})}if(l.every(r=>r===$)){const r=t.map(a=>A(a.text,e.lists));if(r.every(Boolean)&&r.every(a=>a.list===r[0].list)){const{list:a}=r[0],o=n>=2&&(r[1].i-r[0].i+a.length)%a.length||f;return s=>{const u=(r[n-1].i+o*(s+1))%a.length;return{text:B(t[0].text,a[u<0?u+a.length:u])}}}const i=t.map(a=>N(a.text));if(i.every(Boolean)&&i.every(a=>a.key===i[0].key)){const a=i.map(u=>u.num),o=n>=2?a[1]-a[0]:f;let s=!0;for(let u=2;u<n;u++)a[u]-a[u-1]!==o&&(s=!1);if(s&&o!==0)return u=>({text:E(i[0],a[n-1]+o*(u+1))})}}return()=>null}function W(t){const e=String(t??"").replace(/"[^"]*"|\[[^\]]*\]|\\./g,"");return!/[dy]/i.test(e)&&/[hs]/i.test(e)}function U(t,e){const n=t.kind&w;if(t.kind&M||n===S)return null;if(n===y)return C(t.format??"General")?"date":"number";if(n!==$)return null;const f=A(t.text,e);if(f)return f.list;const l=N(t.text);return l?`text:${l.key}`:null}function q(t,e={}){const n=[],f=new Int32Array(t.length).fill(-1),l=new Int32Array(t.length),r=a=>(a.kind&w)===S&&!(a.kind&M);let i=!1;for(let a=0;a<t.length;){const o=U(t[a],e.lists);if(o===null){a++;continue}const s=[a];for(let c=a+1;c<t.length;c++)if(!r(t[c])){if(U(t[c],e.lists)!==o)break;s.push(c)}const u=J(s.map(c=>t[c]),{...e,alone:t.length===1});u(0)!==null&&(i=!0),s.forEach((c,p)=>{f[c]=n.length,l[c]=p}),n.push({n:s.length,series:u}),a=s[s.length-1]+1}return{active:i,at(a,o){const s=f[a];if(s<0)return null;const u=n[s];return u.series(o*u.n+l[a])}}}function H(t,e,n=1){const f=t.length,l=t[f-1].value;if(e==="days"){const o=f>=2?t[1].value-t[0].value:n;return(s,u)=>({kind:y,value:l+o*(u*f+s+1)})}if(e==="weekdays")return f>1?(o,s)=>({kind:y,value:t[o].value+n*7*(s+1)}):(o,s)=>({kind:y,value:G(l,"weekday",n,s+1)});const r=n*(e==="months"?1:12),i=L(t[0].value),a=v(i.year,i.month,1);return(o,s)=>{const u=t[o].value,c=Math.floor(u)-a+1,p=i.year*12+i.month-1+r*(s+1),g=Math.floor(p/12),k=p-g*12+1,d=v(g,k,1),h=c>=1&&c<=31?d+Math.min(c,b(g,k))-1:d+c-1;return{kind:y,value:h+(u-Math.floor(u))}}}function G(t,e,n,f){if(e==="day")return t+n*f;const l=L(t),r=t-Math.floor(t);if(e==="month")return x(l,n*f)+r;if(e==="year")return x(l,12*n*f)+r;let i=t;const a=n*f<0?-1:1;for(let o=Math.abs(n*f);o>0;){i+=a;const s=Math.floor(i)%7;s!==0&&s!==1&&o--}return i}function Y(t){const e=[],n=t[0];n.source.forEach((r,i)=>{r.split(/[\s,;._-]+/).filter(Boolean).forEach((o,s)=>{for(const u of[c=>c,c=>c.toUpperCase(),c=>c.toLowerCase(),c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()])e.push(c=>u((c[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??""));e.push(u=>((u[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??"").charAt(0)),e.push(u=>((u[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??"").charAt(0).toUpperCase())}),e.push(o=>(o[i]??"").toUpperCase()),e.push(o=>(o[i]??"").toLowerCase()),e.push(o=>(o[i]??"").replace(/\S+/g,s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase())),e.push(o=>(o[i]??"").replace(/\D/g,"")),e.push(o=>(o[i]??"").replace(/[^\p{L}]/gu,""));for(let o=1;o<=Math.min(r.length,12);o++)e.push(s=>(s[i]??"").slice(0,o)),e.push(s=>(s[i]??"").slice(-o))});const f=e.slice(),l=n.target;for(let r=1;r<l.length;r++){const i=l.slice(0,r);for(const a of f)if(a(n.source)===i)for(const o of[0,1,2,3]){const s=l.slice(r,r+o),u=l.slice(r+o);if(!/[\p{L}\d]/u.test(s))for(const c of f)c(n.source)===u&&e.push(p=>`${a(p)}${s}${c(p)}`)}}return e.find(r=>t.every(i=>r(i.source)===i.target))??null}export{_ as BUILTIN_LISTS,S as EMPTY,G as dateStep,Y as flashFillRule,C as isDateFormat,H as makeDatePlan,q as makeFillPlan,J as makeSeries};
@@ -0,0 +1 @@
1
+ import{MAX_COLS as y}from"./address.js";class u extends Map{constructor(o,t){super(),this.groups=new Map;for(let s=0;s<y;s++){const l=o?.get(s),r=t?t(l??0):l;r!==void 0&&super.set(s,r),this.group(r??0).add(s)}}group(o){return this.groups.has(o)||this.groups.set(o,new Set),this.groups.get(o)}move(o,t){const s=this.get(o)??0;if(t===s)return;const l=this.groups.get(s);l.delete(o),l.size||this.groups.delete(s),this.group(t).add(o)}set(o,t){return this.move(o,t),super.set(o,t)}delete(o){return this.move(o,0),super.delete(o)}clear(){for(const o of this.keys())this.delete(o)}commonStyle(){let o=0,t=0;for(const[s,l]of this.groups)l.size<=t||(o=s,t=l.size);return o}*exceptions(o){for(const[t,s]of this.groups)t!==o&&(yield*s)}}function C(e,o,t){const s=e.colStyles;t.push(["columns",0,s]),e.colStyles=new u(s,o),e.colsChanged=!0}function M(e,o,t,s,l,r,h=!1){const f=o==="col",g=f?e.colStyles??=new Map:e.rowStyles??=new Map,p=g.get(t);let n=e.colStyles;const m=!f&&p===void 0&&!h;m&&n?.size>y/2&&!(n instanceof u)&&(l.push(["columns",0,n]),e.colStyles=n=new u(n));const S=m&&n instanceof u?n.commonStyle():0,a=s(p??S);if(f){e.colsChanged=!0;for(const[c,i]of e.rowStyles??[]){const d=s(i);d!==i&&!e.cellStyle(c,t)&&r(c,t,d)}}else if(m&&n)for(const c of n instanceof u?n.exceptions(S):n.keys()){const i=s(n.get(c)??0);i!==a&&!e.cellStyle(t,c)&&r(t,c,i)}l.push([o,t,p]),g.set(t,a)}export{M as formatAxis,C as formatSheetColumns};
package/core/axis.js CHANGED
@@ -1 +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};
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 h=this.sizes[s];h!==65535&&(i+=h-t,this.tree[s+1]+=h-t)}for(let s=1;s<=this.count;s++){const h=s+(s&-s);h<=this.count&&(this.tree[h]+=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);const h=i===null;i=h?this.defaultSize: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]=h?65535:i;const e=i-n;if(e!==0){this.version++,this.delta+=e;for(let l=t+1;l<=this.count;l+=l&-l)this.tree[l]+=e;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 n=Math.floor(t/this.defaultSize);return n>=this.count?this.count-1:n}let i=0,s=t;const h=this.defaultSize;for(let n=this.topBit;n>0;n>>=1){const e=i+n;if(e<=this.count){const l=n*h+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 h=Math.min(t,this.count);for(let n=0;n<h;n++)this.sizes[n]!==65535&&s.setSize(n,this.sizes[n],this.isAuto(n))}if(this.hiddenSizes!==null)for(const[h,n]of this.hiddenSizes)h<t&&(s.hiddenSizes??=new Map,s.hiddenSizes.set(h,n));return s}shifted(t,i){const s=new u(this.count,this.defaultSize);if(this.sizes===null)return s;const h=new Uint16Array(this.count).fill(65535);i>0?(h.set(this.sizes.subarray(0,t)),h.set(this.sizes.subarray(t,this.count-i),t+i)):(h.set(this.sizes.subarray(0,t)),h.set(this.sizes.subarray(t-i),t)),s.sizes=h,s.tree=new Int32Array(this.count+1);let n=0;for(let e=0;e<this.count;e++){const l=h[e];if(l===65535)continue;const r=l-this.defaultSize;n+=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=n,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};
@@ -0,0 +1 @@
1
+ import{MAX_COLS as a,MAX_ROWS as x}from"./address.js";import{CHUNK_BITS as v,CHUNK_MASK as X}from"./sheet.js";import{adjustRange as j}from"../calc/adjust.js";import{subtractRect as w}from"./validation-ranges.js";const D=c=>!!(c.cellTypes||c.cellTypeRules),I=(c,e,r)=>e>=c.r0&&e<=c.r1&&r>=c.c0&&r<=c.c1,K=new WeakMap;function B(c,e,r,s){let t=r+c,n=r+e;for(;t<=n;)t%2&&s(t++),n%2===0&&s(n--),t>>=1,n>>=1}function E(c){const e=new Map;return c.forEach((r,s)=>{for(const t of r.ranges)B(t.c0,t.c1,a,n=>{let l=e.get(n);l||(l=new Map,e.set(n,l)),B(t.r0,t.r1,x,o=>{l.has(o)||l.set(o,s)})})}),e}function F(c,e,r){const s=c.cellTypes?.get(e*a+r),t=c.cellTypeRules;if(s!==void 0||!t)return s;if(t.length<32&&t.every(o=>o.ranges.length<32)){for(const o of t)for(const f of o.ranges)if(I(f,e,r))return o.spec;return}let n=K.get(t);n||(n=E(t),K.set(t,n));let l=t.length;for(let o=a+r;o>0;o>>=1){const f=n.get(o);if(f)for(let p=x+e;p>0;p>>=1){const i=f.get(p);i<l&&(l=i)}}return t[l]?.spec}function C(c,e){const r=Math.max(c.r0,e.r0),s=Math.max(c.c0,e.c0),t=Math.min(c.r1,e.r1),n=Math.min(c.c1,e.c1);return r<=t&&s<=n?{r0:r,c0:s,r1:t,c1:n}:null}function G(c,e,r){for(let s=e.c0;s<=Math.min(e.c1,c.maxCol);s++){const t=c.columns[s];if(t)for(let n=e.r0>>>v;n<=Math.min(e.r1>>>v,t.length-1);n++){const l=t[n];if(!l)continue;const o=n<<v;for(let f=Math.max(e.r0-o,0);f<=Math.min(e.r1-o,X);f++)if((l.kinds[f]||l.styles?.[f])&&r(o+f,s))return!0}}return!1}function M(c,e){if(!c)return null;const r=[];for(const s of c){const t=s.ranges.flatMap(e);if(t.length){const n=t.length===s.ranges.length&&t.every((l,o)=>l===s.ranges[o]);r.push(n?s:{ranges:t,spec:s.spec})}}return r.length===c.length&&r.every((s,t)=>s===c[t])?c:r.length?r:null}function S(c,e){return M(c,r=>{let s=[r];for(const t of e)s=s.flatMap(n=>w(n,t));return s})}const T=c=>c.r0===c.r1&&c.c0===c.c1;function J(c,e,r){const s=r===null?e:e.filter(n=>!T(n));if(s.length){const n=S(c.cellTypeRules,s);c.cellTypeRules=r===null?n:[...n??[],{ranges:s,spec:r}]}let t=c.cellTypes;if(r===null&&t){const n=t,l=o=>{n.has(o)&&(t===n&&(t=new Map(n)),t.delete(o))};if(e.every(T))for(const o of e)l(o.r0*a+o.c0);else for(const o of n.keys())e.some(f=>I(f,Math.floor(o/a),o%a))&&l(o)}else if(r!==null&&e.some(T)){t=new Map(t);for(const n of e)T(n)&&t.set(n.r0*a+n.c0,r)}c.cellTypes=t?.size?t:null,c.cellTypesChanged=!0}function Q(c,e){const r=e.axis==="row",s=e.span&&{r0:r?0:e.span[0],r1:r?x-1:e.span[1],c0:r?e.span[0]:0,c1:r?e.span[1]:a-1};return M(c,t=>{const n=s?C(t,s):t;if(!n)return[t];const l=j(n,e),o=s?w(t,s):[];return l&&o.push(l),o})}function V(c,e,r,s){const[t,n]=s==="row"?["r0","r1"]:["c0","c1"];return M(c,l=>{const o=C(l,e);if(!o||o[t]===e[t]&&o[n]===e[n])return[l];const f=w(l,e),p=r.slice(o[t]-e[t],o[n]-e[t]+1).sort((h,u)=>h-u);let i;for(const h of p){const u=h+e[t];i&&u===i[n]+1?i[n]=u:(i={...o,[t]:u,[n]:u},f.push(i))}return f})}function L(c,e,r,s,t,n){if(e-c+1===r)return[[t,n]];const l=[],o=Math.ceil((t-s-e)/r);for(let f=s+o*r;f+c<=n;f+=r)l.push([Math.max(t,f+c),Math.min(n,f+e)]);return l}function Y(c,e,r,s,{cut:t=!1,transpose:n=!1,fill:l=!1}={}){if(!c.cellTypeRules&&!e.cellTypeRules)return;const o=c.cellTypeRules;t&&(c.cellTypeRules=S(o,[r]));const f=S(e.cellTypeRules,[s]),[p,i,h,u]=n?["c0","c1","r0","r1"]:["r0","r1","c0","c1"],k=M(o,H=>{const g=C(H,r);if(!g)return[];const A=(y,m,R,d,W)=>L(g[y]-r[y],g[m]-r[y],r[m]-r[y]+1,R,d,W),O=A(p,i,l?r.r0:s.r0,s.r0,s.r1),U=A(h,u,l?r.c0:s.c0,s.c0,s.c1),_=[];for(const[y,m]of O)for(const[R,d]of U)_.push({r0:y,c0:R,r1:m,c1:d});return _});e.cellTypeRules=k?[...f??[],...k]:f}export{Y as copyTypeRules,D as hasCellTypes,C as intersection,Q as shiftedTypeRules,V as sortedTypeRules,F as typeAtPosition,G as visitStored,J as writeCellTypes};
package/core/changes.js CHANGED
@@ -1 +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};
1
+ import{FORMULA as x,KIND_MASK as y,STR as M}from"./sheet.js";const i=16384;class g{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 R(s,t,n){const{cells:e}=t.changes;for(let c=0;c<n.count;c++){const a=n.rows[c],l=n.cols[c],r=a*i+l;let o=e.get(r);o===void 0&&(o={kind:n.kinds[c],value:n.values[c],formula:n.kinds[c]&x?n.formulas?.get(c):void 0},e.set(r,o));const u=t.kind(a,l)&-97;u===o.kind&&t.value(a,l)===o.value&&(!(u&x)||v(t.formula(a,l),o.formula))&&e.delete(r)}}function T(s){return s.changes===null&&(s.changes=new g),s.changes}function A(s){s.changes=null}function D(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 l=Math.max(0,t.at-e.at)+Math.max(0,c-a);l>0&&n.push({at:Math.min(e.at,t.at),count:l})}}}return n}function I(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 K(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 w={cells:n.cells,rows:n.rows,cols:n.cols};return Object.assign(n,u),c(w)},a=t.axis==="row"?"rows":"cols",l=n[a],r=D(l.inserted,t);n[a]=t.n>0?{inserted:[...r,{at:t.at,count:t.n}],deleted:l.deleted}:{inserted:r,deleted:[...l.deleted,{at:t.at,count:-t.n}]};const o=new Map;for(const[u,w]of n.cells){let d=Math.floor(u/i),h=u-d*i;const f=t.axis==="row"?d:h;let k=f;if(t.n>0)f>=t.at&&(k=f+t.n);else if(f>=t.at-t.n)k=f+t.n;else if(f>=t.at)continue;t.axis==="row"?d=k:h=k,o.set(d*i+h,w)}return n.cells=o,c(e)}const m=(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=(l,r)=>{const o=l&y;return o===0?null:o===M?s.strings.get(r):o===3?r!==0:r},a=[];for(const[l,r]of e.cells){const o=Math.floor(l/i),u=l-o*i;m(n,o,u)&&a.push({row:o,col:u,oldValue:c(r.kind,r.value),newValue:c(t.kind(o,u),t.value(o,u))})}return a.sort((l,r)=>l.row-r.row||l.col-r.col)}function E(s,t){const n=s.changes;if(!(n===null||t.size===0))for(const e of[...n.cells.keys()])t.has(Math.floor(e/i))&&n.cells.delete(e)}const F=(s,t,n)=>s.changes!==null&&s.changes.cells.has(t*i+n);function O(s,t=null){const n=s.changes;if(n!==null){if(t===null){s.changes=new g;return}for(const e of[...n.cells.keys()]){const c=Math.floor(e/i);m(t,c,e-c*i)&&n.cells.delete(e)}}}export{g as ChangeTracker,O as clearDirty,E as clearDirtyRows,S as getDirtyCells,F as isDirtyCell,I as isInsertedAxis,R as noteChanges,K as noteStructure,T as startTracking,A as stopTracking};
@@ -1 +1 @@
1
- import{parseRangeRef as T}from"./address.js";import{BOOL as R,ERR as S,ERRORS as A,KIND_MASK as L,NUM as E,STR as h}from"./sheet.js";import{numberToText as O}from"../calc/values.js";import{formatGeneral as q,getFormatter as F}from"./numfmt.js";function N(u){return u.split(/\s+/).map(T).filter(Boolean)}import{CondFormats as j,cfEffectAt as w,evaluatorOf as z,iconAt as H}from"../cells/cf-engine.js";function b(u,n,e){const s=u.validations;if(!s)return null;for(const r of s)if(r._ranges===void 0&&(r._ranges=N(r.sqref)),r._ranges.some(t=>n>=t.r0&&n<=t.r1&&e>=t.c0&&e<=t.c1))return r;return null}function C(u,n,e,s,r){const t=e.formula1.trim();if(t.startsWith('"'))return t.slice(1,-1).split(",").map(o=>o.trim());const f=u.engine;let i=f.template(t,s,r).fn(s,r,n);return i&&i.sheet&&(i=f.toArr(i)),i&&i.data?i.data.filter(o=>o!==null):[]}function G(u,n,e,s,r){return B(u,n,e,s,r).map(t=>t.text)}function B(u,n,e,s,r){const t=e.formula1.trim(),f=()=>C(u,n,e,s,r).map(p=>({text:String(p),value:p}));if(t.startsWith('"'))return f();const l=u.engine.template(t,s,r).fn(s,r,n);if(!l||!l.sheet)return f();const i=[],o=l.sheet;for(let p=l.r0;p<=Math.min(l.r1,o.maxRow);p++)for(let a=l.c0;a<=Math.min(l.c1,o.maxCol);a++){const m=o.kind(p,a)&L;if(m===0)continue;const g=o.value(p,a),c=u.styles.get(o.style(p,a)).numFmt;m===E?i.push({text:c==="General"?q(g):F(c).number(g).replace(/\u0001.?\u0001/g," ").trim(),value:g}):m===h?i.push({text:u.strings.get(g),value:u.strings.get(g)}):m===R?i.push({text:g?"TRUE":"FALSE",value:g!==0}):i.push({text:A[g]??"#N/A",value:null})}return i}function K(u,n,e,s,r,t){if(e?.type!=="list"||typeof t!="string"||/^[='"]/.test(t))return null;const f=t.trim().toLowerCase(),l=C(u,n,e,s,r).find(i=>typeof i=="string"&&i.trim().toLowerCase()===f);return l!==void 0&&l.trim()!==t.trim()?l.trim():null}function W(u,n,e,s,r,t,f,l){if(e.type==="none"||e.type===void 0)return!0;if(t===0)return e.allowBlank;const i=u.engine,o=c=>{if(!c)return null;const x=i.template(c,s,r),y=i.legacy;i.legacy=!0;try{const d=x.fn(s,r,n);return d&&d.sheet?i.refAuto(d,s,r):d}finally{i.legacy=y}},p=t===E?O(f):t===R?f?"TRUE":"FALSE":String(l);if(e.type==="list"){if(t===S)return!1;const c=C(u,n,e,s,r);if(t===E&&c.some(y=>(typeof y=="number"?y:Number(y))===f))return!0;const x=p.trim().toLowerCase();return c.some(y=>String(y).trim().toLowerCase()===x)}if(e.type==="custom"){const c=[n.kind(s,r),n.value(s,r),n.maxRow,n.maxCol],x=t===h?u.strings.add(String(l)):t===R?f?1:0:f;n.setCell(s,r,t,x);try{const y=o(e.formula1);return y===!0||typeof y=="number"&&y!==0}finally{n.setCell(s,r,c[0],c[1]),n.maxRow=c[2],n.maxCol=c[3]}}let a;if(e.type==="textLength"){if(t===S)return!1;a=p.length}else if(t===R)a=1/0;else if(t!==E||(a=f,e.type==="whole"&&!Number.isInteger(a)))return!1;const m=o(e.formula1),g=o(e.formula2);switch(e.operator){case"notBetween":return a<m||a>g;case"equal":return a===m;case"notEqual":return a!==m;case"greaterThan":return a>m;case"lessThan":return a<m;case"greaterThanOrEqual":return a>=m;case"lessThanOrEqual":return a<=m;default:return a>=m&&a<=g}}export{R as BOOL,j as CondFormats,h as STR,w as cfEffectAt,z as evaluatorOf,H as iconAt,B as listEntries,G as listItems,K as listSpelling,C as listValues,N as rangesOf,W as validateEntry,b as validationAt};
1
+ import{parseRangeRef as L}from"./address.js";import{BOOL as x,ERR as T,ERRORS as O,KIND_MASK as q,NUM as E,STR as h}from"./sheet.js";import{numberToText as _}from"../calc/values.js";import{formatGeneral as F,getFormatter as N}from"./numfmt.js";function A(n){return n.split(/\s+/).map(L).filter(Boolean)}import{CondFormats as w,cfEffectAt as z,evaluatorOf as H,iconAt as J}from"../cells/cf-engine.js";function G(n,i,t){const r=n.validations;if(!r)return null;for(const s of r)if(s._ranges===void 0&&(s._ranges=A(s.sqref)),s._ranges.some(e=>i>=e.r0&&i<=e.r1&&t>=e.c0&&t<=e.c1))return s;return null}function C(n,i,t){n._ranges===void 0&&(n._ranges=n.sqref?A(n.sqref):[]);const r=n._ranges[0];return r?[r.r0,r.c0]:[i,t]}function S(n,i,t,r,s){const e=t.formula1.trim();if(e.startsWith('"'))return e.slice(1,-1).split(",").map(o=>o.trim());const l=n.engine;let a=l.template(e,...C(t,r,s)).fn(r,s,i);return a&&a.sheet&&(a=l.toArr(a)),a&&a.data?a.data.filter(o=>o!==null):[]}function K(n,i,t,r,s){return B(n,i,t,r,s).map(e=>e.text)}function B(n,i,t,r,s){const e=t.formula1.trim(),l=()=>S(n,i,t,r,s).map(p=>({text:String(p),value:p}));if(e.startsWith('"'))return l();const f=n.engine.template(e,...C(t,r,s)).fn(r,s,i);if(!f||!f.sheet)return l();const a=[],o=f.sheet;for(let p=f.r0;p<=Math.min(f.r1,o.maxRow);p++)for(let u=f.c0;u<=Math.min(f.c1,o.maxCol);u++){const m=o.kind(p,u)&q;if(m===0)continue;const g=o.value(p,u),c=n.styles.get(o.style(p,u)).numFmt;m===E?a.push({text:c==="General"?F(g):N(c).number(g).replace(/\u0001.?\u0001/g," ").trim(),value:g}):m===h?a.push({text:n.strings.get(g),value:n.strings.get(g)}):m===x?a.push({text:g?"TRUE":"FALSE",value:g!==0}):a.push({text:O[g]??"#N/A",value:null})}return a}function W(n,i,t,r,s,e){if(t?.type!=="list"||typeof e!="string"||/^[='"]/.test(e))return null;const l=e.trim().toLowerCase(),f=S(n,i,t,r,s).find(a=>typeof a=="string"&&a.trim().toLowerCase()===l);return f!==void 0&&f.trim()!==e.trim()?f.trim():null}function D(n,i,t,r,s,e,l,f){if(t.type==="none"||t.type===void 0)return!0;if(e===0)return t.allowBlank;const a=n.engine,o=c=>{if(!c)return null;const d=a.template(c,...C(t,r,s)),y=a.legacy;a.legacy=!0;try{const R=d.fn(r,s,i);return R&&R.sheet?a.refAuto(R,r,s):R}finally{a.legacy=y}},p=e===E?_(l):e===x?l?"TRUE":"FALSE":String(f);if(t.type==="list"){if(e===T)return!1;const c=S(n,i,t,r,s);if(e===E&&c.some(y=>(typeof y=="number"?y:Number(y))===l))return!0;const d=p.trim().toLowerCase();return c.some(y=>String(y).trim().toLowerCase()===d)}if(t.type==="custom"){const c=[i.kind(r,s),i.value(r,s),i.maxRow,i.maxCol],d=e===h?n.strings.add(String(f)):e===x?l?1:0:l;i.setCell(r,s,e,d);try{const y=o(t.formula1);return y===!0||typeof y=="number"&&y!==0}finally{i.setCell(r,s,c[0],c[1]),i.maxRow=c[2],i.maxCol=c[3]}}let u;if(t.type==="textLength"){if(e===T)return!1;u=p.length}else if(e===x)u=1/0;else if(e!==E||(u=l,t.type==="whole"&&!Number.isInteger(u)))return!1;const m=o(t.formula1),g=o(t.formula2);switch(t.operator){case"notBetween":return u<m||u>g;case"equal":return u===m;case"notEqual":return u!==m;case"greaterThan":return u>m;case"lessThan":return u<m;case"greaterThanOrEqual":return u>=m;case"lessThanOrEqual":return u<=m;default:return u>=m&&u<=g}}export{x as BOOL,w as CondFormats,h as STR,z as cfEffectAt,H as evaluatorOf,J as iconAt,B as listEntries,K as listItems,W as listSpelling,S as listValues,A as rangesOf,D as validateEntry,G as validationAt};
@@ -0,0 +1 @@
1
+ import{setNumberLocale as F}from"./numfmt.js";import{setEntryCurrency as L}from"./input.js";import{regionInput as Z}from"./region-input.js";import{arraySeparatorsOf as b}from"../calcx/culture/separators.js";import{customCulture as v}from"../calcx/culture/custom.js";import{localeData as K,preparedEras as G}from"../calcx/culture/format-locale.js";import{formulaFromUser as k,formulaToUser as M}from"../calcx/lang/convert.js";import{setDbcsLanguage as O}from"../calc/functions/dbcs.js";const W={US:"USD",GB:"GBP",PL:"PLN",DE:"EUR",FR:"EUR",ES:"EUR",IT:"EUR",NL:"EUR",AT:"EUR",BE:"EUR",IE:"EUR",PT:"EUR",FI:"EUR",GR:"EUR",CZ:"CZK",SK:"EUR",HU:"HUF",RO:"RON",SE:"SEK",NO:"NOK",DK:"DKK",CH:"CHF",UA:"UAH",TR:"TRY",JP:"JPY",CN:"CNY",KR:"KRW",IN:"INR",BR:"BRL",MX:"MXN",CA:"CAD",AU:"AUD",NZ:"NZD",ZA:"ZAR",IL:"ILS",SA:"SAR",AE:"AED",EG:"EGP"},q=[["en-US","English (United States)"],["en-GB","English (United Kingdom)"],["pl-PL","Polish (Poland)"],["de-DE","German (Germany)"],["fr-FR","French (France)"],["es-ES","Spanish (Spain)"],["it-IT","Italian (Italy)"],["nl-NL","Dutch (Netherlands)"],["pt-BR","Portuguese (Brazil)"],["cs-CZ","Czech (Czechia)"],["sv-SE","Swedish (Sweden)"],["uk-UA","Ukrainian (Ukraine)"],["tr-TR","Turkish (Türkiye)"],["ja-JP","Japanese (Japan)"],["zh-CN","Chinese (China)"],["ko-KR","Korean (Korea)"],["ar-SA","Arabic (Saudi Arabia)"],["he-IL","Hebrew (Israel)"]];function u(t){const o=v(t);if(o){const e=u(o.parent);return{...e,monthsWithDay:o.fields.months??e.monthsWithDay,...o.fields,tag:t}}const s=new Intl.NumberFormat(t,{useGrouping:!0,numberingSystem:"latn"}).formatToParts(12345675e-1),m=s.find(e=>e.type==="decimal")?.value??".",C=s.find(e=>e.type==="group")?.value??"",y=[],d=[];for(let e=0;e<12;e++){const n=new Date(Date.UTC(2024,e,15));y.push(new Intl.DateTimeFormat(t,{month:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),d.push(new Intl.DateTimeFormat(t,{month:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const p=[],h=[];for(let e=0;e<7;e++){const n=new Date(Date.UTC(2024,0,7+e));p.push(new Intl.DateTimeFormat(t,{weekday:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),h.push(new Intl.DateTimeFormat(t,{weekday:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const i=new Intl.DateTimeFormat(t,{dateStyle:"short",timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))),S=i.filter(e=>e.type==="day"||e.type==="month"||e.type==="year").map(e=>e.type),D=i.find(e=>e.type==="literal")?.value.trim()||"/",R=i.find(e=>e.type==="month")?.value.length>1,f={day:e=>e.length>1||R?"dd":"d",month:e=>e.length>1?"mm":"m",year:()=>"yyyy"},E=i.filter(e=>f[e.type]).map(e=>f[e.type](e.value)).join(D),I=new Intl.Locale(t).maximize().region,P=W[I]??"USD",l=new Intl.NumberFormat(t,{style:"currency",currency:P,numberingSystem:"latn"}).formatToParts(1),w=l.find(e=>e.type==="currency")?.value??"$",N=l.findIndex(e=>e.type==="currency")<l.findIndex(e=>e.type==="integer"),g={weekday:()=>"dddd",month:e=>/\d/.test(e)?"m":"mmmm",day:e=>e.length>1?"dd":"d",year:()=>"yyyy"},U=e=>new Intl.DateTimeFormat(t,{dateStyle:e,timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))).map(n=>g[n.type]?g[n.type](n.value):n.type==="literal"?`"${n.value}"`:"").join(""),A=new Intl.DateTimeFormat(t,{hour:"numeric",hour12:!0,timeZone:"UTC",calendar:"gregory"}),T=e=>A.formatToParts(new Date(Date.UTC(2024,0,5,e))).find(n=>n.type==="dayPeriod")?.value??(e<12?"AM":"PM");return{tag:t,language:new Intl.Locale(t).language,collator:new Intl.Collator(t,{sensitivity:"accent"}),decimal:m,group:C,listSep:m===","?";":",",...b(t,m),longDate:U("full"),longDateWithoutWeekday:U("long"),longTime:"h:mm:ss AM/PM",amDesignator:T(9),pmDesignator:T(15),months:y,shortMonths:d,monthsWithDay:K(t).monthsWithDay,days:p,shortDays:h,order:S,dateSep:D,shortDate:E,currency:{symbol:w,symbolFirst:N}}}let r=null,c=null;const a=()=>(r??=u("en-US"),r);function B(t=a().currency.symbol){return/^\p{Sc}$/u.test(t)?t:`"${t.replace(/"/g,"")}"`}function Q(t,o=B(),s=!a().currency.symbolFirst){return o?s?`${t} ${o}`:o+t:t}function V(t){return r=u(t),c=null,O(r.tag),L(r.currency),F({decimal:r.decimal,group:r.group,months:r.months,monthsWithDay:r.monthsWithDay,shortMonths:r.shortMonths,days:r.days,shortDays:r.shortDays,shortDate:r.shortDate,longDate:r.longDate,longTime:r.longTime,amDesignator:r.amDesignator,pmDesignator:r.pmDesignator,tag:r.tag,eras:r.eras?G(r.eras):null,numerals:r.numerals??null}),r}function ee(t){return M(t,a())}function x(t){return k(t,a())}const te=(t=a())=>({decimal:t.decimal,group:t.group,listSep:t.listSep,order:t.order,dateSep:t.dateSep,currency:t.currency});function re(t){return t===""||t[0]==="'"?t:t[0]==="="?t.length>1?x(t):t:(c??=Z(a()),c(t))}export{q as REGIONS,a as culture,u as cultureOf,Q as currencyAmountCode,B as currencySymbolCode,x as formulaToInvariant,ee as formulaToLocal,te as inputRegion,re as inputToInvariant,V as setCulture};
@@ -1 +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};
1
+ import{colIndex as v,colName as o,MAX_COLS as l,MAX_ROWS as y,parseRangeRef as E,rangeRef as F}from"./address.js";const g=/"(?:[^"]|"")*"|'(?:[^']|'')*'|(\$?)([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(r,t,n){if(t)return null;const e=v(r)+n;return e<0||e>=l?-1:e}function R(r,t,n){if(t)return null;const e=r-1+n;return e<0||e>=y?-1:e}function M(r,t,n){return t===0&&n===0?r:r.replace(g,(e,a,$,Z,i,_,m,d,N,x,A,C,b,c,p)=>{if($!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_]/.test(f)||f==="."&&p[c-2]!==":"||v($)>=l||Number(i)>y||Number(i)===0)return e;const u=z($,a==="$",n),s=R(Number(i),Z==="$",t);return u===-1||s===-1?"#REF!":`${a}${u===null?$.toUpperCase():o(u)}${Z}${s===null?i:s+1}`}if(m!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_.]/.test(f))return e;const u=R(Number(m),_==="$",t),s=R(Number(N),d==="$",t);return u===-1||s===-1?"#REF!":`${_}${u===null?m:u+1}:${d}${s===null?N:s+1}`}if(A!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_.]/.test(f))return e;const u=z(A,x==="$",n),s=z(b,C==="$",n);return u===-1||s===-1?"#REF!":`${x}${u===null?A.toUpperCase():o(u)}:${C}${s===null?b.toUpperCase():o(s)}`}return e})}function U(r,t,n){if(!r)return null;if(r.f!==void 0)return r.f;if(r.sf!==void 0){const e=Math.floor(r.base/l);return M(r.sf,t-e,n-(r.base-e*l))}return null}function I(r,t,n=0,e=0){const a={f:t};if(r.typed&&(a.typed=!0),r.ca&&(a.ca=r.ca),r.cm&&(a.cm=r.cm),r.t==="array"){a.t="array";const $=r.ref&&(n||e)?E(r.ref):null;a.ref=$?F({r0:$.r0+n,c0:$.c0+e,r1:$.r1+n,c1:$.c1+e}):r.ref}return a}export{U as formulaText,I as movedInfo,M as translateFormula};
package/core/input.js CHANGED
@@ -1 +1 @@
1
- import{BOOL as g,EMPTY as P,ERR as C,ERRORS as D,FORMULA as I,NUM as o,STR as v}from"./sheet.js";import{partsToSerial as l}from"./numfmt.js";const M=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A"],L=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],F=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/,S=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,A=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)[eE][+-]?\d+$/,Y=/^[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)?(?:\.\d*)?%$/,y="(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d*)?|\\.\\d+",j=/^([+-]?)[€£¥]\s?([+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d*)?)$/;let $={symbol:"$",symbolFirst:!0};function H(r){$={symbol:r.symbol,symbolFirst:r.symbolFirst}}const Z=r=>`"${r.replace(/"/g,"")}"`;function _(r){const e=r?"#,##0.00":"#,##0",n=Z($.symbol);return $.symbolFirst?`${n}${e}_);[Red]\\(${n}${e}\\)`:`${e} ${n}`}function q(r,e){return e===2?r%4===0&&(r%100!==0||r%400===0||r===1900)?29:28:[4,6,9,11].includes(e)?30:31}const d=r=>r.length<=2?(Number(r)<30?2e3:1900)+Number(r):Number(r),m=(r,e,n)=>r>=1900&&r<=9999&&e>=1&&e<=12&&n>=1&&n<=q(r,e),O=r=>{const e=r.toLowerCase().replace(/\.$/,"");if(e.length<3)return 0;const n=L.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},b=()=>new Date().getFullYear(),p=(r,e,n)=>r===1900&&e===2&&n===29?60:l(r,e,n);function T(r){let e;if(e=/^(\d{1,2})([/-])(\d{1,2})\2(\d{1,4})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[3]),d(e[4])];return m(t,n,u)?{value:p(t,n,u),format:"m/d/yyyy"}:null}if(e=/^(\d{4})([/-])(\d{1,2})\2(\d{1,2})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[3]),Number(e[4])];return m(n,u,t)?{value:p(n,u,t),format:"m/d/yyyy"}:null}if(e=/^(\d{1,2})[/-](\d{1,2})$/.exec(r)){const[n,u,t]=[Number(e[1]),Number(e[2]),b()];if(m(t,n,u))return{value:p(t,n,u),format:"d-mmm"};const s=d(e[2]);return e[2].length!==1&&m(s,n,1)?{value:l(s,n,1),format:"mmm-yy"}:null}if(e=/^(\d{1,2})[-\s]+([A-Za-z]+\.?)(?:[-\s,]+(\d{2}|\d{4}))?$/.exec(r)){const n=O(e[2]),u=Number(e[1]),t=e[3]?d(e[3]):b();return n&&m(t,n,u)?{value:p(t,n,u),format:e[3]?"d-mmm-yy":"d-mmm"}:null}if(e=/^([A-Za-z]+\.?)[-\s]+(\d{1,4})(?:,?\s*(\d{2}|\d{4}))?$/.exec(r)){const n=O(e[1]);if(!n)return null;const u=Number(e[2]);if(e[3]){const s=d(e[3]);return m(s,n,u)&&e[2].length<=2?{value:l(s,n,u),format:"d-mmm-yy"}:null}if(e[2].length<=2&&m(b(),n,u))return{value:l(b(),n,u),format:"d-mmm"};const t=d(e[2]);return m(t,n,1)&&e[2].length!==3?{value:l(t,n,1),format:"mmm-yy"}:null}return null}function U(r){let e=/^(\d{1,4}):(\d{1,2})(?::(\d{1,2}))?(?:\s+([AaPp][Mm]?))?$/.exec(r),n,u=0,t=0,s;if(e)[n,u,t]=[Number(e[1]),Number(e[2]),Number(e[3]??0)],s=e[4];else if(e=/^(\d{1,2})\s+([AaPp][Mm]?)$/.exec(r))n=Number(e[1]),s=e[2];else return null;if(u>59||t>59)return null;if(s){if(n<1||n>12)return null;const f=s[0].toLowerCase()==="p";n=n%12+(f?12:0)}const i=(n*3600+u*60+t)/86400;return s?{value:i,format:e[3]!==void 0?"h:mm:ss AM/PM":"h:mm AM/PM"}:n>=24?{value:i,format:"[h]:mm:ss"}:{value:i,format:e[3]!==void 0?"h:mm:ss":"h:mm"}}function z(r){const e=/^(.+?)\s+(\d{1,2}(?::\d{1,2}(?::\d{1,2})?)?\s*(?:[AaPp][Mm]?)?)$/.exec(r);if(!e||!/:|[AaPp]/.test(e[2]))return null;const n=T(e[1]),u=U(e[2]);return!n||!u||u.value>=1?null:{value:n.value+u.value,format:"m/d/yyyy h:mm"}}function B(r){const e=/^([+-]?)(\d+) (\d+)\/(\d+)$/.exec(r);if(!e)return null;const n=Number(e[4]);if(n===0)return null;const u=(Number(e[2])+Number(e[3])/n)*(e[1]==="-"?-1:1),t="?".repeat(Math.min(3,e[4].length));return{value:u,format:`# ${t}/${t}`}}function N(r){let e=0,n="";for(const u of r.replace(/,/g,""))u>="0"&&u<="9"?((e>0||u!=="0")&&e++,n+=e>15?"0":u):((u==="e"||u==="E")&&(e=-1/0),n+=u);return Number(n)}const c=N;function W(r){if(r==="")return{kind:P};if(r[0]==="="&&r.length>1)return{kind:I,formula:r.slice(1)};if(r[0]==="'")return{kind:v,text:r.slice(1)};const e=r.trim(),n=r.toUpperCase();if(n==="TRUE")return{kind:g,value:1};if(n==="FALSE")return{kind:g,value:0};const u=M.indexOf(n);if(u>=0)return{kind:C,value:D.indexOf(M[u]),text:r};let t;if((F.test(e)||A.test(e))&&!Number.isFinite(N(e)))return{kind:v,text:r};if(F.test(e))return{kind:o,value:N(e)};if(S.test(e))return{kind:o,value:c(e),format:e.includes(".")?"#,##0.00":"#,##0"};if(A.test(e))return{kind:o,value:N(e),format:"0.00E+00"};if(Y.test(e)&&/\d/.test(e)){const a=e.slice(0,-1);return{kind:o,value:c(a)/100,format:/\.\d/.test(a)?"0.00%":"0%"}}if(t=/^\((\d{1,3}(?:,\d{3})+(?:\.\d*)?|\d+(?:\.\d*)?|\.\d+)\)$/.exec(e))return{kind:o,value:-c(t[1]),...t[1].includes(",")?{format:t[1].includes(".")?"#,##0.00":"#,##0"}:{}};const s=$.symbol.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=(a,k,w)=>{const x=c(k)*(a==="-"||w?-1:1);return{kind:o,value:x,format:_(/\.\d/.test(k))}};if(t=new RegExp(`^([+-]?)${s}\\s?([+-]?)(${y})$`).exec(e))return i(t[1]||t[2],t[3]);if(t=new RegExp(`^([+-]?)(${y})\\s?${s}$`).exec(e))return i(t[1],t[2]);if((t=new RegExp(`^\\(${s}\\s?(${y})\\)$`).exec(e))||(t=new RegExp(`^\\((${y})\\s?${s}\\)$`).exec(e)))return i("",t[1],!0);if(t=j.exec(e))return{kind:o,value:c(t[2])*(t[1]==="-"?-1:1)};const f=B(e);if(f)return{kind:o,...f};const E=T(e);if(E)return{kind:o,...E};const R=U(e);if(R)return{kind:o,...R};const h=z(e);return h?{kind:o,...h}:{kind:v,text:r}}export{W as parseInput,H as setEntryCurrency};
1
+ import{BOOL as F,EMPTY as I,ERR as C,ERRORS as L,FORMULA as S,NUM as i,STR as $}from"./sheet.js";import{getFormatter as Y,partsToSerial as a}from"./numfmt.js";const M=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A"],j=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],A=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/,Z=/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,T=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)[eE][+-]?\d+$/,_=/^[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)?(?:\.\d*)?%$/,y="(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d*)?|\\.\\d+",q=/^([+-]?)[€£¥]\s?([+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d*)?)$/;let x={symbol:"$",symbolFirst:!0};function K(t){x={symbol:t.symbol,symbolFirst:t.symbolFirst}}const z=t=>`"${t.replace(/"/g,"")}"`;function B(t,e){const r=t?"#,##0.00":"#,##0",n=z(e.symbol);return e.symbolFirst?`${n}${r}_);[Red]\\(${n}${r}\\)`:`${r} ${n}`}function G(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 c=t=>t.length<=2?(Number(t)<30?2e3:1900)+Number(t):Number(t),m=(t,e,r)=>t>=1900&&t<=9999&&e>=1&&e<=12&&r>=1&&r<=G(t,e),U=t=>{const e=t.toLowerCase().replace(/\.$/,"");if(e.length<3)return 0;const r=j.indexOf(e.slice(0,3));return r<0?0:new Intl.DateTimeFormat("en-US",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,r,15))).toLowerCase().startsWith(e)?r+1:0},p=()=>new Date().getFullYear(),b=(t,e,r)=>t===1900&&e===2&&r===29?60:a(t,e,r);function O(t){let e;if(e=/^(\d{1,2})([/-])(\d{1,2})\2(\d{1,4})$/.exec(t)){const[r,n,u]=[Number(e[1]),Number(e[3]),c(e[4])];return m(u,r,n)?{value:b(u,r,n),format:"m/d/yyyy"}:null}if(e=/^(\d{4})([/-])(\d{1,2})\2(\d{1,2})$/.exec(t)){const[r,n,u]=[Number(e[1]),Number(e[3]),Number(e[4])];return m(r,n,u)?{value:b(r,n,u),format:"m/d/yyyy"}:null}if(e=/^(\d{1,2})[/-](\d{1,4})$/.exec(t)){const[r,n,u]=[Number(e[1]),Number(e[2]),p()];if(e[2].length<=2&&m(u,r,n))return{value:b(u,r,n),format:"d-mmm"};const s=c(e[2]);return e[2].length!==3&&m(s,r,1)?{value:a(s,r,1),format:"mmm-yy"}:null}if(e=/^(\d{1,2})[-\s]+([A-Za-z]+\.?)(?:[-\s,]+(\d{2}|\d{4}))?$/.exec(t)){const r=U(e[2]),n=Number(e[1]),u=e[3]?c(e[3]):p();return r&&m(u,r,n)?{value:b(u,r,n),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 r=U(e[1]);if(!r)return null;const n=Number(e[2]);if(e[3]){const s=c(e[3]);return m(s,r,n)&&e[2].length<=2?{value:a(s,r,n),format:"d-mmm-yy"}:null}if(e[2].length<=2&&m(p(),r,n))return{value:a(p(),r,n),format:"d-mmm"};const u=c(e[2]);return m(u,r,1)&&e[2].length!==3?{value:a(u,r,1),format:"mmm-yy"}:null}return null}function w(t){let e=/^(\d{1,4}):(\d{1,2})(?::(\d{1,2}))?(?:\s+([AaPp][Mm]?))?$/.exec(t),r,n=0,u=0,s;if(e)[r,n,u]=[Number(e[1]),Number(e[2]),Number(e[3]??0)],s=e[4];else if(e=/^(\d{1,2})\s+([AaPp][Mm]?)$/.exec(t))r=Number(e[1]),s=e[2];else return null;if(n>59||u>59)return null;if(s){if(r<1||r>12)return null;const d=s[0].toLowerCase()==="p";r=r%12+(d?12:0)}const o=(r*3600+n*60+u)/86400;return s?{value:o,format:e[3]!==void 0?"h:mm:ss AM/PM":"h:mm AM/PM"}:r>=24?{value:o,format:"[h]:mm:ss"}:{value:o,format:e[3]!==void 0?"h:mm:ss":"h:mm"}}function V(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 r=O(e[1]),n=w(e[2]);return!r||!n||n.value>=1?null:{value:r.value+n.value,format:"m/d/yyyy h:mm"}}function H(t){const e=/^([+-]?)(\d+) (\d+)\/(\d+)$/.exec(t);if(!e)return null;const r=Number(e[4]);if(r===0)return null;const n=(Number(e[2])+Number(e[3])/r)*(e[1]==="-"?-1:1),u="?".repeat(Math.min(3,e[4].length));return{value:n,format:`# ${u}/${u}`}}function N(t){let e=0,r="";for(const n of t.replace(/,/g,""))n>="0"&&n<="9"?((e>0||n!=="0")&&e++,r+=e>15?"0":n):((n==="e"||n==="E")&&(e=-1/0),r+=n);return Number(r)}const f=N;function Q(t){if(t.length<=32767)return t;const e=t.charCodeAt(32766);return t.slice(0,e>=55296&&e<=56319?32766:32767)}function W(t,e=x,r=0){if(t==="")return{kind:I};if(t[0]==="="&&t.length>1)return{kind:S,formula:t.slice(1)};if(t[0]==="'")return{kind:$,text:t.slice(1)};const n=t.trim(),u=t.toUpperCase();if(u==="TRUE")return{kind:F,value:1};if(u==="FALSE")return{kind:F,value:0};const s=M.indexOf(u);if(s>=0)return{kind:C,value:L.indexOf(M[s]),text:t};let o;if((o=/^([+-])\s+(\S.*)$/.exec(n))&&!/^[-+(]/.test(o[2])){const l=W(o[2],e,r);return l.kind===i&&!(l.format&&Y(l.format).isDate)?o[1]==="-"?{...l,value:-l.value}:l:{kind:$,text:t}}if((A.test(n)||T.test(n))&&!Number.isFinite(N(n)))return{kind:$,text:t};if(A.test(n))return{kind:i,value:N(n)};if(Z.test(n))return{kind:i,value:f(n),format:n.includes(".")?"#,##0.00":"#,##0"};if(T.test(n))return{kind:i,value:N(n),format:"0.00E+00"};if(_.test(n)&&/\d/.test(n)){const l=n.slice(0,-1);return{kind:i,value:f(l)/100,format:/\.\d/.test(l)?"0.00%":"0%"}}if(o=/^\((\d{1,3}(?:,\d{3})+(?:\.\d*)?|\d+(?:\.\d*)?|\.\d+)\)$/.exec(n))return{kind:i,value:-f(o[1]),...o[1].includes(",")?{format:o[1].includes(".")?"#,##0.00":"#,##0"}:{}};const d=e.symbol.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),v=(l,g,D)=>{const P=f(g)*(l==="-"||D?-1:1);return{kind:i,value:P,format:B(/\.\d/.test(g),e)}};if(o=new RegExp(`^([+-]?)${d}\\s?([+-]?)(${y})$`).exec(n))return v(o[1]||o[2],o[3]);if(o=new RegExp(`^([+-]?)(${y})\\s?${d}$`).exec(n))return v(o[1],o[2]);if((o=new RegExp(`^\\(${d}\\s?(${y})\\)$`).exec(n))||(o=new RegExp(`^\\((${y})\\s?${d}\\)$`).exec(n)))return v("",o[1],!0);if(o=q.exec(n))return{kind:i,value:f(o[2])*(o[1]==="-"?-1:1)};const R=H(n);if(R)return{kind:i,...R};const E=O(n);if(E)return{kind:i,...E,value:E.value-r};const k=w(n);if(k)return{kind:i,...k};const h=V(n);return h?{kind:i,...h,value:h.value-r}:{kind:$,text:t}}export{Q as cellEntryText,c as fullYear,W as parseInput,K as setEntryCurrency};
package/core/merge.js ADDED
@@ -0,0 +1 @@
1
+ import{EMPTY as g,CONTENT_MASK as v}from"./sheet.js";import{MAX_COLS as C}from"./address.js";import{formulaText as A,movedInfo as O}from"./formula-refs.js";import{tablesOf as S}from"./tables.js";const E=65536;function K(o,r){return(r.r1-r.r0+1)*(r.c1-r.c0+1)<=E?{r1:r.r1,c1:r.c1}:{r1:Math.max(r.r0,Math.min(r.r1,o.maxRow)),c1:Math.max(r.c0,Math.min(r.c1,o.maxCol))}}function h(o,r,e){const n=[],f=Math.min(r.r1,o.maxRow),c=Math.min(r.c1,o.maxCol);for(let u=r.r0;u<=f;u++)for(let t=r.c0;t<=c;t++)if((o.kind(u,t)&v)!==g&&(n.push({row:u,col:t}),n.length===e))return n;return n}function D(o,r=!1){if(!r)return[{r0:o.r0,c0:o.c0,r1:o.r1,c1:o.c1}];const e=[];for(let n=o.r0;n<=o.r1;n++)e.push({r0:n,c0:o.c0,r1:n,c1:o.c1});return e}function P(o,r,e){return S(o,r).some(n=>e.some(f=>f.r0<=n.r1&&n.r0<=f.r1&&f.c0<=n.c1&&n.c0<=f.c1))}function V(o,r){return r.some(e=>h(o,e,2).length>1)}function X(o,r,e,{center:n=!1}={}){const{sheet:f}=r;if(P(o,f,e))return null;const c=f.merges.slice(),u=[];for(const t of e)f.removeMergesIn(t);for(const t of e)b(o,r,t,n,u);return m(c,u)}function Y(o,r){return _(o,[r])}function _(o,r){const e=o.merges.slice();for(const n of r)o.removeMergesIn(n);return m(e)}function m(o,r=[],e=!0){return n=>{const f=n.merges;if(n.merges=o,n.mergeIndex=null,r.length>0){const c=new Map(n.valueMeta??[]);for(const{from:u,to:t,vm:M}of r)c.delete(e?t:u),c.set(e?u:t,M);n.valueMeta=c}return m(f,r,!e)}}function b(o,r,e,n,f){const{sheet:c}=r,{styles:u}=o,[t]=h(c,e,1),M=t??{row:e.r0,col:e.c0};let w=c.style(M.row,M.col);if(n&&(w=u.derive(w,{hAlign:"center"})),t!==void 0&&(t.row!==e.r0||t.col!==e.c0)){r.saveCell(e.r0,e.c0),c.setCell(e.r0,e.c0,c.kind(t.row,t.col)&v,c.value(t.row,t.col));const l=c.formula(t.row,t.col),s=A(l,t.row,t.col);c.setFormula(e.r0,e.c0,s===null?l:O(l,s,e.r0-t.row,e.c0-t.col)),l&&(o.formulasEdited=!0);const p=t.row*C+t.col,a=c.valueMeta?.get(p);if(a!==void 0){const d=e.r0*C+e.c0,i=new Map(c.valueMeta);i.delete(p),i.set(d,a),c.valueMeta=i,f.push({from:p,to:d,vm:a})}}const x=new Map,T=l=>{let s=x.get(l);return s===void 0&&(s=u.derive(w,{borders:u.get(l).borders??null}),x.set(l,s)),s},{r1:y,c1:I}=K(c,e);for(let l=e.r0;l<=y;l++)for(let s=e.c0;s<=I;s++){const a=(l!==e.r0||s!==e.c0)&&(c.kind(l,s)&v)!==g,d=c.style(l,s),i=T(d);!a&&i===d||(r.saveCell(l,s),a&&(c.setCell(l,s,g,0),c.setFormula(l,s,null)),i!==d&&c.setStyle(l,s,i))}c.addMerge({r0:e.r0,c0:e.c0,r1:e.r1,c1:e.c1})}export{X as mergeCells,V as mergeDropsValues,D as mergePieces,P as mergeTouchesTable,_ as unmergeAreas,Y as unmergeCells};