@8sheets/data-grid 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/api/theme-core.js +2 -0
  3. package/calc/compile.js +1 -1
  4. package/calc/engine.js +1 -1
  5. package/calc/functions/info.js +1 -1
  6. package/calc/functions/math.js +1 -1
  7. package/calc/parser.js +3 -3
  8. package/calc/values.js +1 -1
  9. package/calcx/culture/custom.js +1 -0
  10. package/calcx/culture/format-locale.js +1 -1
  11. package/calcx/culture/separators.js +1 -0
  12. package/calcx/lang/convert.js +1 -0
  13. package/cells/axis-ops.js +1 -1
  14. package/cells/block.js +1 -0
  15. package/cells/book-css.js +2 -2
  16. package/cells/cell-defaults.js +1 -1
  17. package/cells/consolidate-links.js +1 -1
  18. package/cells/find-engine.js +2 -2
  19. package/cells/format-panes.js +3 -3
  20. package/cells/format-tabs.js +2 -2
  21. package/cells/outline-column.js +1 -1
  22. package/cells/panes.js +1 -1
  23. package/cells/selection-modes.js +1 -1
  24. package/cells/shift-check.js +1 -0
  25. package/cells/table-rows.js +1 -0
  26. package/cells/text-layout.js +9 -8
  27. package/cells/ui-kit.js +15 -0
  28. package/cells/view-options.js +1 -1
  29. package/celltypes/diagonal.js +1 -1
  30. package/celltypes/dropdowns.js +2 -2
  31. package/core/autofill.js +1 -1
  32. package/core/axis-styles.js +1 -0
  33. package/core/axis.js +1 -1
  34. package/core/culture.js +1 -0
  35. package/core/formula-refs.js +1 -1
  36. package/core/input.js +1 -1
  37. package/core/merge.js +1 -0
  38. package/core/numfmt.js +1 -1
  39. package/core/region-input.js +1 -0
  40. package/core/row-fit.js +1 -0
  41. package/core/sheet.js +1 -1
  42. package/core/structure.js +1 -0
  43. package/core/styles.js +1 -1
  44. package/core/tables.js +2 -2
  45. package/core/whatif.js +1 -1
  46. package/core/workbook.js +1 -1
  47. package/datasheets/data-core.js +1 -1
  48. package/datasheets/gantt-paint.js +1 -1
  49. package/datasheets/path-binding.js +2 -2
  50. package/datasheets/rules.js +1 -1
  51. package/datasheets/view.js +2 -2
  52. package/i18n/dom.js +1 -1
  53. package/i18n/en/cells.js +1 -1
  54. package/i18n/en/format.js +1 -1
  55. package/i18n/en/shell.js +2 -2
  56. package/i18n/pl/cells.js +1 -1
  57. package/i18n/pl/format.js +1 -1
  58. package/i18n/pl/shell.js +2 -2
  59. package/io/csv.js +8 -8
  60. package/io/plan.js +1 -1
  61. package/io/text-split.js +3 -3
  62. package/io/xlsx-write.js +1 -1
  63. package/objects/chart-model.js +1 -1
  64. package/package.json +1 -1
  65. package/pivot/engine.js +1 -1
  66. package/print/paginate.js +1 -1
  67. package/print/render-page.js +3 -3
  68. package/table-view/api.js +1 -1
  69. package/table-view/cell-editor.js +2 -1
  70. package/table-view/chart.js +1 -0
  71. package/table-view/column-drag.js +1 -1
  72. package/table-view/context-menu.js +1 -0
  73. package/table-view/editors.js +1 -0
  74. package/table-view/events.js +1 -1
  75. package/table-view/files.js +1 -1
  76. package/table-view/fill-handle.js +1 -0
  77. package/table-view/filter-builder.js +1 -0
  78. package/table-view/find.js +1 -0
  79. package/table-view/grid-keys.js +2 -2
  80. package/table-view/labels-de.js +1 -0
  81. package/table-view/labels-es.js +1 -0
  82. package/table-view/labels-fr.js +1 -0
  83. package/table-view/labels-ja.js +1 -0
  84. package/table-view/labels.js +1 -1
  85. package/table-view/model.js +1 -1
  86. package/table-view/mount.js +1 -1
  87. package/table-view/panel.js +1 -1
  88. package/table-view/pivot-spec.js +1 -0
  89. package/table-view/pivot.js +1 -1
  90. package/table-view/public.d.ts +277 -28
  91. package/table-view/reader.worker.js +1 -1
  92. package/table-view/remote.js +1 -1
  93. package/table-view/row-drag.js +1 -0
  94. package/table-view/sparkline.js +1 -0
  95. package/table-view/state-check.js +1 -0
  96. package/table-view/table-css.js +380 -0
  97. package/table-view/version.js +1 -1
  98. package/ui/dialogs.js +3 -3
  99. package/ui/menu-base.js +1 -1
@@ -0,0 +1 @@
1
+ const e={fr:[".",";"],es:["\\",";"],pl:["\\",";"],pt:["\\",";"],nl:["\\",";"],sv:["\\",";"],cs:["\\",";"],da:["\\",";"],fi:["\\",";"],hu:["\\",";"],it:["\\","."],nb:["\\","."],no:["\\","."],nn:["\\","."],ru:[";",":"],tr:[";","\\"],de:[".",";"],en:[",",";"],ja:[",",";"],ko:[",",";"],zh:[",",";"]};function t(o,a){const n=o.split("-")[0].toLowerCase(),r=e[n];return r&&!(a===","&&r[0]===",")?{arrayColSep:r[0],arrayRowSep:r[1]}:a===","?{arrayColSep:"\\",arrayRowSep:";"}:{arrayColSep:",",arrayRowSep:";"}}export{t as arraySeparatorsOf};
@@ -0,0 +1 @@
1
+ const L=new Map;let p=null;function W(e,n){const r=e.toLowerCase(),s=n.parent?L.get(n.parent.toLowerCase()):null;L.set(r,y(r,n,s)),p?.code===r&&(p=L.get(r))}function y(e,n,r){const s={...r?.source.functions??{},...n.functions??{}},u={...r?.source.errors??{},...n.errors??{}},f={...r?.source.booleans??{},...n.booleans??{}},i={...r?.source.structured??{},...n.structured??{}},h=d=>new Map(Object.entries(d).map(([t,l])=>[l.toUpperCase(),t]));return{code:e,name:n.name??e,source:{functions:s,errors:u,booleans:f,structured:i},fnToLocal:new Map(Object.entries(s)),fnToEnglish:h(s),errToLocal:new Map(Object.entries(u).map(([d,t])=>[d.toUpperCase(),t])),errToEnglish:h(u),boolToLocal:new Map(Object.entries(f)),boolToEnglish:h(f),structToLocal:new Map(Object.entries(i).map(([d,t])=>[d.toUpperCase(),t])),structToEnglish:h(i)}}const v=()=>[...L.values()].map(e=>({code:e.code,name:e.name}));function B(e){if(!e||e.toLowerCase()==="en")return p=null,!0;const n=L.get(e.toLowerCase());return n===void 0?!1:(p=n,!0)}const X=()=>p?.code??"en",b="_XLL.",g=new Set,A=e=>{for(const n of g)if(n(e))return!0;return!1};function z(e){return g.add(e),()=>g.delete(e)}function S(e,n){let r=n;for(;r.startsWith(b);)r=r.slice(b.length);if(e.fnToLocal.has(r))return!1;const s=e.fnToEnglish.get(r);return s!==void 0&&s!==r}function E(e,n){const r=n.toUpperCase();return S(e,r)?`_xll.${n}`:e.fnToLocal.get(r)??n}function j(e,n){const r=n.toUpperCase();return r.startsWith(b)&&S(e,r)?n.slice(b.length):e.fnToEnglish.get(r)??n}const H=e=>p?E(p,e):e,P=e=>(p?j(p,e):e).toUpperCase(),Q=e=>p?.errToLocal.get(e.toUpperCase())??e,$=e=>{const n=e?"TRUE":"FALSE";return p?.boolToLocal.get(n)??n},O=Object.freeze({decimal:".",listSep:",",arrayColSep:",",arrayRowSep:";"}),m=e=>e>="0"&&e<="9",_=/[\p{L}_\\]/u,D=/[\p{L}\p{N}_.\\?]/u;function F(e,n,r){let s=n+1;for(;s<e.length;)if(e[s]===r)if(e[s+1]===r)s+=2;else return s+1;else s++;return s}function M(e,n,r,s){if(/^\[\d+\]/.test(e)&&!e.includes("#"))return e;let u="",f=0,i=0;for(;i<e.length;){const h=e[i];if(h==="'"&&e[i+1]!==void 0)u+=h+e[i+1],i+=2;else if(h==="["){if(f++,u+=h,i++,e[i]==="#"){const d=e.indexOf("]",i),t=e.slice(i,d<0?e.length:d),l=s?n?s.structToLocal.get(t.toUpperCase()):s.structToEnglish.get(t.toUpperCase()):void 0;u+=l??t,i+=t.length}}else h==="]"?(f--,u+=h,i++):f===1&&h===(n?",":r)?(u+=n?r:",",i++):(u+=h,i++)}return u}function R(e,n,r,s){const{decimal:u,listSep:f,arrayColSep:i,arrayRowSep:h}=r,d=e.length;let t="",l=0,T=0;for(;l<d;){const c=e[l];if(c==='"'||c==="'"){const a=F(e,l,c);t+=e.slice(l,a),l=a}else if(c==="["){let a=0,o=l;for(;o<d;o++)if(e[o]==="'")o++;else if(e[o]==="[")a++;else if(e[o]==="]"&&(a--,a===0))break;t+=M(e.slice(l,o+1),n,f,s),l=o+1}else if(c==="{")T++,t+=c,l++;else if(c==="}")T--,t+=c,l++;else if(c==="#"){const a=/^#[^\s,;:()+\-*^&=<>{}\\|]*[!?]?/u.exec(e.slice(l,l+40));let o=null;if(a&&s){const w=n?s.errToLocal:s.errToEnglish;for(let C=a[0].length;C>1;C--){const U=w.get(a[0].slice(0,C).toUpperCase());if(U!==void 0){o={len:C,swapped:U};break}}}o?(t+=o.swapped,l+=o.len):(t+=c,l++)}else if(m(c)||c===(n?".":u)&&m(e[l+1]??"")){const a=n?".":u;let o=l;for(;o<d&&m(e[o]);)o++;if(e[o]===a)for(o++;o<d&&m(e[o]);)o++;if((e[o]==="e"||e[o]==="E")&&(m(e[o+1]??"")||(e[o+1]==="+"||e[o+1]==="-")&&m(e[o+2]??"")))for(o+=2;o<d&&m(e[o]);)o++;const w=e.slice(l,o);t+=a===(n?u:".")?w:w.replace(a,n?u:"."),l=o}else if(_.test(c)&&!(c==="\\"&&T>0)){let a=l+1;for(;a<d&&D.test(e[a]);)a++;const o=e.slice(l,a),w=e[a];if(s&&w==="(")A(o.toUpperCase())?t+=o:t+=n?E(s,o):j(s,o);else if(s&&w!=="!"&&w!=="["){const C=o.toUpperCase(),U=n?s.boolToLocal.get(C):s.boolToEnglish.get(C);t+=U??o}else t+=o;l=a}else n?(c===","?t+=T>0?i:f:c===";"&&T>0?t+=h:t+=c,l++):(T>0&&c===i?t+=",":T>0&&c===h?t+=";":T===0&&c===f?t+=",":t+=c,l++)}return t}const N=e=>e.decimal==="."&&e.listSep===","&&e.arrayColSep===","&&e.arrayRowSep===";";function G(e,n=O){return p===null&&N(n)?e:R(e,!0,n,p)}function I(e,n=O){return p===null&&N(n)?e:R(e,!1,n,p)}function J(e,n,r=40){const s=e.toUpperCase(),u=[];for(const f of n){if(f.startsWith("_"))continue;const i=p?E(p,f):f;i.toUpperCase().startsWith(s)&&u.push({local:i,english:f})}return u.sort((f,i)=>f.local.localeCompare(i.local)),u.slice(0,r)}export{O as STANDARD_SEPARATORS,z as addDefinedNameCheck,v as availableLanguages,J as completeFunctionName,P as englishFunctionName,I as formulaFromUser,X as formulaLanguage,G as formulaToUser,$ as localBooleanText,Q as localErrorText,H as localFunctionName,W as registerLanguage,B as setFormulaLanguage};
package/cells/axis-ops.js CHANGED
@@ -1 +1 @@
1
- import{selectedSheets as C}from"../core/sheet-group.js";import{openFormatCells as O,promptNumber as F}from"../ui/dialogs.js";import{guardOption as R}from"../ui/protection-ui.js";import{MAX_COLS as S,MAX_ROWS as z}from"../core/address.js";import{CHUNK_BITS as T}from"../core/sheet.js";import{wrapsByAlign as _}from"./text-layout.js";import{canResize as b}from"./axis-limits.js";import{openTrackSize as y}from"./cell-options-ui.js";import{openHeaderColors as v}from"./header-colors.js";const h=o=>o==="col"?"cols":"rows";function I(o){const e=o.grid.selection.ranges[0];e.c0===0&&e.c1===S-1?v(o,"row",e.r0,e.r1):v(o,"col",e.c0,e.c1)}function m(o,e,r){return()=>{const s=o[e];return o[e]=r,e==="cols"&&(o.colsChanged=!0),o.revision++,m(o,e,s)}}function g(o,e){const{book:r,grid:s}=o;e==="col"&&(r.sheet.colsChanged=!0),r.dirty=!0,o.objects?.geometryChanged?.(),s.invalidate()}function U(o,e){const{sheet:r,styles:s}=o.book,n=new Set,i=new Map,l=t=>{let c=i.get(t);if(c===void 0){const f=s.get(t);c=!!(f.wrap||_(f)),i.set(t,c)}return c};o:for(const t of e.slice(0,256)){const c=r.columns[t];if(c===void 0)continue;const f=r.colStyles?.get(t)??0;for(let d=0;d<c.length;d++){const u=c[d];if(u!==void 0)for(let a=0;a<u.kinds.length;a++){if(u.kinds[a]===0)continue;const w=u.styles===null||u.styles[a]===0?f:u.styles[a];if(!(w===0||!l(w))&&(n.add((d<<T)+a),n.size>=B))break o}}}for(const t of n)o.commands._growRow(t);return n.size>0}const B=2e3;function H(o,e,r){const s=o.book.sheet,n=s.rows.reshaped();if(!U(o,e))return r;const i=(l,t)=>()=>{const c=l(),f=t();return i(f,c)};return i(m(s,"rows",n),r)}function A(o,e,r,s=null){const{book:n}=o,i=n.sheet,l=h(e);n.transact("axis",()=>{const t=i[l].reshaped();r(),i.revision++;const c=m(i,l,t);return s!==null&&e==="col"?H(o,s,c):c}),g(o,e),s!==null&&n.collab?.changed?.()}const M=(o,e)=>o==="col"?e.r0===0&&e.r1===z-1:e.c0===0&&e.c1===S-1,k=(o,e)=>o==="col"?[e.c0,e.c1]:[e.r0,e.r1];function x(o,e,r){const s=new Set,n=e==="col"?S-1:z-1;for(const i of r.ranges){const[l,t]=k(e,i),c=e==="col"?o.maxCol:o.maxRow,f=t>=n?Math.max(l,c):t;for(let d=l;d<=f;d++)s.add(d)}return[...s]}function j(o,e,r,s){const n=[];let i=!1;for(const l of s.ranges){if(!M(e,l))continue;const[t,c]=k(e,l);r>=t&&r<=c&&(i=!0);const f=Math.min(c,t+2e4);for(let d=t;d<=f;d++)n.push(d)}return i?n:[r]}function Y(o,e,r,s){const n=j(o,e,r,s),i=o[h(e)];return{list:n,saved:i.reshaped(),starts:n.map(l=>i.sizeOf(l))}}function Z(o,e,r,s){const n=o[h(e)];for(const i of r.group.list)n.isHidden(i)&&n.setHidden(i,!1),n.setSize(i,s)}function $(o,e){const{book:r}=o,s=r.sheet,n=e.type==="colResize"?"col":"row",i=h(n),l=s[i],{list:t,starts:c,saved:f}=e.group;t.forEach((d,u)=>{l.sizeOf(d)===0&&!l.isHidden(d)&&(c[u]>0&&l.setSize(d,c[u]),l.setHidden(d,!0))}),r.transact("axis",()=>n==="col"?H(o,t,m(s,i,f)):m(s,i,f)),g(o,n),n==="col"&&r.collab?.changed?.()}function p(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const s=o.book.sheet,n=s[h(e)],i=x(s,e,o.grid.selection).filter(t=>b(s,e,t)),l=C(o.book);if(l.length>1){const t=h(e);o.book.transact("axis",()=>{const c=l.map(d=>{const u=d[t].reshaped();for(const w of i)b(d,e,w)&&(r===0?d[t].setHidden(w,!0):(d[t].setHidden(w,!1),d[t].setSize(w,r)));d.revision++,t==="cols"&&(d.colsChanged=!0);const a=m(d,t,u);return e==="col"&&d===s?H(o,i,a):a}),f=d=>()=>f(d.map(u=>u()));return f(c)}),g(o,e),e==="col"&&o.book.collab?.changed?.();return}A(o,e,()=>{for(const t of i)r===0?n.setHidden(t,!0):(n.setHidden(t,!1),n.setSize(t,r))},e==="col"?i:null)}function oo(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const s=o.book.sheet,n=s[h(e)];A(o,e,()=>{for(const i of o.grid.selection.ranges){const[l,t]=k(e,i);if(r)for(let c=l;c<=t;c++)n.setHidden(c,!0);else if(n.hiddenSizes)for(const c of[...n.hiddenSizes.keys()])c<l||c>t||e==="row"&&s.filteredRows?.has(c)||n.setHidden(c,!1)}})}function W(o,e){const{book:r,commands:s,grid:n}=o,i=r.sheet,l=x(i,e,n.selection);if(e==="row"){s.fitAxis("row",l);return}const t=n.selection.ranges[n.selection.ranges.length-1];s.fitAxis("col",l,M("col",t)?null:t)}const D=o=>o<=5?0:Math.round((o-5)/6*100)/100,E=o=>o<=0?0:Math.round(o*6+5);function L(o){const{book:e,grid:r}=o,s=e.sheet;F(o,"Standard Width","Standard column width:",D(s.cols.defaultSize),0,255,n=>{const i=C(e);e.transact("axis",()=>{const l=i.map(c=>{const f=c.cols;return c.cols=f.reshaped(f.count,Math.max(1,E(n))),c.standardWidthChanged=!0,m(c,"cols",f)}),t=c=>()=>t(c.map(f=>f()));return t(l)}),g(o,"col"),r.invalidate()})}function eo(o){const e=o.commands;return{items:[["Row Height…",()=>y(o,"row")],["AutoFit Row Height",()=>W(o,"row")],null,["Column Width…",()=>y(o,"col")],["AutoFit Selection",()=>W(o,"col")],["Standard Width…",()=>L(o)],null,["Hide & Unhide",()=>{},{items:()=>({items:[["Hide Rows",()=>e.setHidden("row",!0)],["Hide Columns",()=>e.setHidden("col",!0)],null,["Unhide Rows",()=>e.setHidden("row",!1)],["Unhide Columns",()=>e.setHidden("col",!1)]]})}],null,["Header Color…",()=>I(o)],["Format Cells…",()=>O(o),{kbd:"⌘1"}]]}}function to(o,e){const r=o.book.sheet,s=e.type==="colResize"?"col":"row";m(r,h(s),e.group.saved)(),s==="col"&&(r.colsChanged=!0),o.objects?.geometryChanged?.(),o.grid.invalidate()}export{A as axisStep,b as canResize,to as cancelAxisDrag,E as charsToWidth,Y as dragGroup,Z as dragSize,$ as endAxisDrag,W as fitSelected,eo as formatMenu,oo as hideSelected,L as openStandardWidth,j as selectedAround,p as setSelectedSize,D as widthToChars};
1
+ import{selectedSheets as C}from"../core/sheet-group.js";import{openFormatCells as O,promptNumber as F}from"../ui/dialogs.js";import{guardOption as R}from"../ui/protection-ui.js";import{MAX_COLS as b,MAX_ROWS as z}from"../core/address.js";import{CHUNK_BITS as T}from"../core/sheet.js";import{wrapsByAlign as _}from"./text-layout.js";import{canResize as H}from"./axis-limits.js";import{openTrackSize as v}from"./cell-options-ui.js";import{openHeaderColors as y}from"./header-colors.js";const h=o=>o==="col"?"cols":"rows";function I(o){const e=o.grid.selection.ranges[0];e.c0===0&&e.c1===b-1?y(o,"row",e.r0,e.r1):y(o,"col",e.c0,e.c1)}function m(o,e,r){return()=>{const n=o[e];return o[e]=r,e==="cols"&&(o.colsChanged=!0),o.revision++,m(o,e,n)}}function w(o,e){const{book:r,grid:n}=o;e==="col"&&(r.sheet.colsChanged=!0),r.dirty=!0,o.objects?.geometryChanged?.(),n.invalidate()}function U(o,e){const{sheet:r,styles:n}=o.book,t=new Set,c=new Map,l=s=>{let i=c.get(s);if(i===void 0){const f=n.get(s);i=!!(f.wrap||_(f)),c.set(s,i)}return i};o:for(const s of e.slice(0,256)){const i=r.columns[s];if(i===void 0)continue;const f=r.colStyles?.get(s)??0;for(let d=0;d<i.length;d++){const u=i[d];if(u!==void 0)for(let a=0;a<u.kinds.length;a++){if(u.kinds[a]===0)continue;const g=u.styles===null||u.styles[a]===0?f:u.styles[a];if(!(g===0||!l(g))&&(t.add((d<<T)+a),t.size>=B))break o}}}for(const s of t)o.commands._growRow(s);return t.size>0}const B=2e3;function k(o,e,r){const n=o.book.sheet,t=n.rows.reshaped();if(!U(o,e))return r;const c=(l,s)=>()=>{const i=l(),f=s();return c(f,i)};return c(m(n,"rows",t),r)}function A(o,e,r,n=null){const{book:t}=o,c=t.sheet,l=h(e);t.transact("axis",()=>{const s=c[l].reshaped();r(),c.revision++;const i=m(c,l,s);return n!==null&&e==="col"?k(o,n,i):i}),w(o,e),n!==null&&t.collab?.changed?.()}const x=(o,e)=>o==="col"?e.r0===0&&e.r1===z-1:e.c0===0&&e.c1===b-1,S=(o,e)=>o==="col"?[e.c0,e.c1]:[e.r0,e.r1];function V(o,e){const r=e.map(t=>S(o,t)).sort((t,c)=>t[0]-c[0]),n=[];for(const[t,c]of r){const l=n[n.length-1];l&&t<=l[1]+1?l[1]=Math.max(l[1],c):n.push([t,c])}return n}function M(o,e,r){const n=new Set,t=e==="col"?b-1:z-1;for(const c of r.ranges){const[l,s]=S(e,c),i=e==="col"?o.maxCol:o.maxRow,f=s>=t?Math.max(l,i):s;for(let d=l;d<=f;d++)n.add(d)}return[...n]}function j(o,e,r,n){const t=[];let c=!1;for(const l of n.ranges){if(!x(e,l))continue;const[s,i]=S(e,l);r>=s&&r<=i&&(c=!0);const f=Math.min(i,s+2e4);for(let d=s;d<=f;d++)t.push(d)}return c?t:[r]}function Y(o,e,r,n){const t=j(o,e,r,n),c=o[h(e)];return{list:t,saved:c.reshaped(),starts:t.map(l=>c.sizeOf(l))}}function Z(o,e,r,n){const t=o[h(e)];for(const c of r.group.list)t.isHidden(c)&&t.setHidden(c,!1),t.setSize(c,n)}function $(o,e){const{book:r}=o,n=r.sheet,t=e.type==="colResize"?"col":"row",c=h(t),l=n[c],{list:s,starts:i,saved:f}=e.group;s.forEach((d,u)=>{l.sizeOf(d)===0&&!l.isHidden(d)&&(i[u]>0&&l.setSize(d,i[u]),l.setHidden(d,!0))}),r.transact("axis",()=>t==="col"?k(o,s,m(n,c,f)):m(n,c,f)),w(o,t),t==="col"&&r.collab?.changed?.()}function oo(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const n=o.book.sheet,t=n[h(e)],c=M(n,e,o.grid.selection).filter(s=>H(n,e,s)),l=C(o.book);if(l.length>1){const s=h(e);o.book.transact("axis",()=>{const i=l.map(d=>{const u=d[s].reshaped();for(const g of c)H(d,e,g)&&(r===0?d[s].setHidden(g,!0):(d[s].setHidden(g,!1),d[s].setSize(g,r)));d.revision++,s==="cols"&&(d.colsChanged=!0);const a=m(d,s,u);return e==="col"&&d===n?k(o,c,a):a}),f=d=>()=>f(d.map(u=>u()));return f(i)}),w(o,e),e==="col"&&o.book.collab?.changed?.();return}A(o,e,()=>{for(const s of c)r===0?t.setHidden(s,!0):(t.setHidden(s,!1),t.setSize(s,r))},e==="col"?c:null)}function eo(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const n=o.book.sheet,t=n[h(e)];A(o,e,()=>{for(const c of o.grid.selection.ranges){const[l,s]=S(e,c);if(r)for(let i=l;i<=s;i++)t.setHidden(i,!0);else if(t.hiddenSizes)for(const i of[...t.hiddenSizes.keys()])i<l||i>s||e==="row"&&n.filteredRows?.has(i)||t.setHidden(i,!1)}})}function W(o,e){const{book:r,commands:n,grid:t}=o,c=r.sheet,l=M(c,e,t.selection);if(e==="row"){n.fitAxis("row",l);return}const s=t.selection.ranges[t.selection.ranges.length-1];n.fitAxis("col",l,x("col",s)?null:s)}const p=o=>o<=5?0:Math.round((o-5)/6*100)/100,D=o=>o<=0?0:Math.round(o*6+5);function E(o){const{book:e,grid:r}=o,n=e.sheet;F(o,"Standard Width","Standard column width:",p(n.cols.defaultSize),0,255,t=>{const c=C(e);e.transact("axis",()=>{const l=c.map(i=>{const f=i.cols;return i.cols=f.reshaped(f.count,Math.max(1,D(t))),i.standardWidthChanged=!0,m(i,"cols",f)}),s=i=>()=>s(i.map(f=>f()));return s(l)}),w(o,"col"),r.invalidate()})}function to(o){const e=o.commands;return{items:[["Row Height…",()=>v(o,"row")],["AutoFit Row Height",()=>W(o,"row")],null,["Column Width…",()=>v(o,"col")],["AutoFit Selection",()=>W(o,"col")],["Standard Width…",()=>E(o)],null,["Hide & Unhide",()=>{},{items:()=>({items:[["Hide Rows",()=>e.setHidden("row",!0)],["Hide Columns",()=>e.setHidden("col",!0)],null,["Unhide Rows",()=>e.setHidden("row",!1)],["Unhide Columns",()=>e.setHidden("col",!1)]]})}],null,["Header Color…",()=>I(o)],["Format Cells…",()=>O(o),{kbd:"⌘1"}]]}}function no(o,e){const r=o.book.sheet,n=e.type==="colResize"?"col":"row";m(r,h(n),e.group.saved)(),n==="col"&&(r.colsChanged=!0),o.objects?.geometryChanged?.(),o.grid.invalidate()}export{A as axisStep,H as canResize,no as cancelAxisDrag,D as charsToWidth,Y as dragGroup,Z as dragSize,$ as endAxisDrag,W as fitSelected,to as formatMenu,eo as hideSelected,E as openStandardWidth,j as selectedAround,V as selectedSpans,oo as setSelectedSize,p as widthToChars};
package/cells/block.js ADDED
@@ -0,0 +1 @@
1
+ import{EMPTY as M,FORMULA as g,SPILL as R}from"../core/sheet.js";import{MAX_COLS as F,MAX_ROWS as I}from"../core/address.js";import{formulaText as A}from"../core/formula-refs.js";import{CellLog as C}from"../core/workbook.js";const L=t=>t.r0===0&&t.r1===I-1,O=t=>t.c0===0&&t.c1===F-1,P=(t,n)=>t.r0<=n.r1&&t.r1>=n.r0&&t.c0<=n.c1&&t.c1>=n.c0,U=(t,n)=>t.r0>=n.r0&&t.r1<=n.r1&&t.c0>=n.c0&&t.c1<=n.c1,_=(t,n)=>t.r0===n.r0&&t.r1===n.r1&&t.c0===n.c0&&t.c1===n.c1,z=(t,n,s)=>t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1;function E(t,n){const s=t.selectedSheets?.size>1?t.selectedSheets:[t.sheet];for(const e of s)if(!(!e.spills||e.protection&&e!==t.sheet)){for(const r of e.spills.values())if(r.fixed&&n.some(o=>P(o,r))&&!n.some(o=>U(r,o)))return!0}return!1}function H(t,n){return{r0:t.r0,c0:t.c0,r1:L(t)?Math.min(t.r1,Math.max(n.maxRow,t.r0)):t.r1,c1:O(t)?Math.min(t.c1,Math.max(n.maxCol,t.c0)):t.c1}}function Y(t,n){const s=new Int32Array(n-t+1);for(let e=0;e<s.length;e++)s[e]=t+e;return s}function j(t,n){for(const s of[...t.formulas.keys()])n.styles.get(t.styles[s]).hiddenFormula&&(t.kinds[s]&=~g,t.formulas.delete(s));return t}function q(t,n,s){const e=n.length,r=s.length,o=e*r,l=new Uint8Array(o),c=new Float64Array(o),i=new Uint16Array(o),u=new Uint16Array(o),S=new Map,k=t.rowStyles!==null||t.colStyles!==null;for(let p=0;p<r;p++){const x=s[p],a=t.columns[x];if(!(a===void 0&&!k))for(let d=0;d<e;d++){const h=n[d],f=d*r+p,m=a===void 0?void 0:a[h>>>10];if(m!==void 0){const y=h&1023;if(l[f]=m.kinds[y],c[f]=m.values[y],m.styles!==null&&(u[f]=m.styles[y]),l[f]&g){const w=t.formula(h,x);w&&S.set(f,{info:w,text:A(w,h,x)})}}i[f]=u[f]!==0||!k?u[f]:t.style(h,x)}}return{sheet:t,rows:n,cols:s,h:e,w:r,kinds:l,values:c,styles:i,own:u,formulas:S}}function D(t,n){const s=[],e=n.length,r=t.length;let o=null;for(let l=0;l<e;l++){const c=t[l%r],i=n[l];o!==null&&c===o.s+o.n&&i===o.t+o.n?o.n++:(o={s:c,t:i,n:1},s.push(o))}return s}function G(t,n,s){const e=[];for(const r of t)for(const o of n){const l=s?{r0:o.s,r1:o.s+o.n-1,c0:r.s,c1:r.s+r.n-1}:{r0:r.s,r1:r.s+r.n-1,c0:o.s,c1:o.s+o.n-1};e.push({source:l,target:{r0:r.t,r1:r.t+r.n-1,c0:o.t,c1:o.t+o.n-1},transpose:s})}return e}function J(t,n){const{source:s,target:e}=n;return n.transpose?{r0:e.r0+t.c0-s.c0,r1:e.r0+t.c1-s.c0,c0:e.c0+t.r0-s.r0,c1:e.c0+t.r1-s.r0}:{r0:e.r0+t.r0-s.r0,r1:e.r0+t.r1-s.r0,c0:e.c0+t.c0-s.c0,c1:e.c0+t.c1-s.c0}}function K(t){let n=1/0,s=1/0,e=-1,r=-1;for(const o of t)o.r0<n&&(n=o.r0),o.c0<s&&(s=o.c0),o.r1>e&&(e=o.r1),o.c1>r&&(r=o.c1);return{r0:n,c0:s,r1:e,c1:r}}function W(t){const n=t.filter(Boolean);return s=>{const e=[];for(let r=n.length-1;r>=0;r--)e.push(n[r](s));return W(e)}}class N{constructor(n,s){this.book=n,this.sheet=s,this.log=new C}save(n,s){this.log.push(this.sheet,n,s)}undo(){const{book:n,sheet:s,log:e}=this;if(e.count===0)return null;const r=o=>()=>{const l=new C;for(let c=o.count-1;c>=0;c--){const i=o.rows[c],u=o.cols[c];l.push(s,i,u),s.setCell(i,u,o.kinds[c],o.values[c]),s.setStyle(i,u,o.styles[c]),s.setFormula(i,u,o.kinds[c]&g?o.formulas.get(c):null)}return s.revision++,n.engine?.cellsChanged(s,o.rows,o.cols,o.count),r(l)};return this.notify(),r(e)}notify(){const{log:n,sheet:s,book:e}=this;s.revision++,e.engine?.cellsChanged(s,n.rows,n.cols,n.count)}}function Q(t){const n=new WeakSet,s=new WeakSet;return t.columns=t.columns.slice(),{sheet:t,saveCell(e,r){let o=t.columns[r];if(o===void 0)return;n.has(o)||(o=o.slice(),t.columns[r]=o,n.add(o));const l=e>>>10,c=o[l];if(c===void 0||s.has(c))return;const i={kinds:c.kinds.slice(),values:c.values.slice(),styles:c.styles?c.styles.slice():null};o[l]=i,s.add(i)}}}export{M as EMPTY,N as ForeignLog,R as SPILL,W as allUndo,K as boundsOf,z as cellInRect,E as changesPartOfArray,Q as cowTx,A as formulaText,Y as indexRange,L as isWholeCols,O as isWholeRows,J as mapRect,q as readBlock,U as rectInside,G as rectPairs,P as rectsTouch,_ as sameRect,D as segmentsOf,H as usedPart,j as withoutHiddenFormulas};
package/cells/book-css.js CHANGED
@@ -167,8 +167,8 @@ const r=`
167
167
  #app.bk-fx-expanded #formula-input { height: 72px; }
168
168
 
169
169
  .bk-note { position: absolute; z-index: 6; border: 1px solid #808080; background: #ffffe1; color: #000; box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.3); padding: 2px 3px; white-space: pre-wrap; overflow: hidden; cursor: move; font-size: 10px; line-height: 1.25; }
170
- .bk-note-edit { padding: 4px 5px; border-style: dashed !important; }
171
- .bk-note-text { display: block; width: 100%; height: 100%; resize: none; outline: 0; padding: 0; background: transparent; color: inherit; cursor: text; user-select: text; }
170
+ .bk-note-edit { display: flex; flex-direction: column; padding: 4px 5px; border-style: dashed !important; }
171
+ .bk-note-text { flex: 1; min-height: 0; display: block; width: 100%; height: 100%; resize: none; outline: 0; padding: 0; background: transparent; color: inherit; cursor: text; user-select: text; }
172
172
  .bk-note-body { height: 100%; overflow: hidden; pointer-events: none; }
173
173
  .bk-note-grip { position: absolute; right: 0; bottom: 0; width: 8px; height: 8px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, #808080 50%); }
174
174
  .bk-mentions { position: fixed; z-index: 50; min-width: 150px; max-height: 40vh; overflow-y: auto; padding: 5px; border-radius: 8px; background: var(--menu); color: var(--ink); box-shadow: var(--shadow); }
@@ -1 +1 @@
1
- import{BOOL as y,EMPTY as v,ERR as z,ERRORS as T,NUM as g,STR as k}from"../core/sheet.js";import{registerSparseMap as E,sparseKey as O}from"../core/sparse.js";import{registerSection as Y}from"./sections.js";E("cellDefaults");const m=16384;function R(t,l,f,i,o){if(o.f===void 0)return typeof o.v=="number"?{kind:g,value:o.v}:typeof o.v=="boolean"?{kind:y,value:o.v?1:0}:{kind:k,value:t.strings.add(String(o.v))};const{engine:n}=t;if(!n)return{kind:v,value:0};try{const r=n.template(o.f,f,i).fn(f,i,l),e=r?.sheet?n.refAuto(r,f,i):r;return typeof e=="number"?{kind:g,value:e}:typeof e=="boolean"?{kind:y,value:e?1:0}:typeof e=="string"?{kind:k,value:t.strings.add(e)}:e&&e.code!==void 0?{kind:z,value:Math.max(0,T.indexOf(e.code))}:{kind:v,value:0}}catch{return{kind:v,value:0}}}function B(t,l,f,i,o,n,r,e,s,a,u){const{book:p,dpr:M}=t;for(const[x,S]of f.cellDefaults){const c=Math.floor(x/m),d=x-c*m;if(c<o||c>n||d<r||d>e||f.kind(c,d)!==0)continue;const{kind:D,value:C}=R(p,f,c,d,S);if(D===v)continue;const b=Math.round(i.x*M+(f.cols.offsetOf(d)-i.originX)*s),A=Math.round(i.y*M+(f.rows.offsetOf(c)-i.originY)*s),h=Math.round(f.cols.sizeOf(d)*s),w=Math.round(f.rows.sizeOf(c)*s);h>0&&w>0&&t._paintText(l,c,d,D,C,b,A,h,w,s,r,e,a,u)}}function H(t,l,f){const{book:i,grid:o}=t,n=i.sheet;i.guardHint={ranges:l},i.transact("entry",()=>{const r=n.cellDefaults??null,e=new Map(r??[]);for(const a of l)for(let u=a.r0;u<=Math.min(a.r1,a.r0+1e5);u++)for(let p=a.c0;p<=Math.min(a.c1,a.c0+1e3);p++)f===void 0?e.delete(O(u,p)):e.set(O(u,p),f);n.cellDefaults=e.size>0?e:null,n.cellTypesChanged=!0;const s=a=>()=>{const u=n.cellDefaults;return n.cellDefaults=a,n.cellTypesChanged=!0,s(u)};return s(r)}),o.invalidate()}function I(t){for(const l of t.sheets){if(!l.cellDefaults)continue;const f=new Map;for(const[i,o]of l.cellDefaults){const n=Math.floor(i/m),r=i-n*m;if(l.kind(n,r)!==0)continue;const e=R(t,l,n,r,o);e.kind!==v&&(l._ensure(n,r),n>l.maxRow&&(l.maxRow=n),r>l.maxCol&&(l.maxCol=r),f.set(i,e))}l.defaultsForSave=f.size>0?f:null}}const F=t=>typeof t=="number"||typeof t=="boolean"||typeof t=="string";Y("cellDefaults",{sheet:{save(t){return t.cellDefaults?.size>0?[...t.cellDefaults]:void 0},load(t,l,f){if(!Array.isArray(l))return;const i=l.filter(o=>Array.isArray(o)&&Number.isInteger(o[0])&&o[1]&&(typeof o[1].f=="string"||F(o[1].v)));t.cellDefaults=i.length>0?new Map(i):null;for(const[o,n]of i){const r=Math.floor(o/m),e=o-r*m,s=t.kind(r,e)&7;if(s===v)continue;(n.f!==void 0||(s===g?t.value(r,e)===n.v:s===k?f.strings.get(t.value(r,e))===String(n.v):s===y))&&!(t.kind(r,e)&8)&&t.setCell(r,e,0,0)}}}});export{R as defaultValueAt,B as paintCellDefaults,I as prepareDefaultsForSave,H as setCellDefaults};
1
+ import{BOOL as m,EMPTY as v,ERR as z,ERRORS as T,NUM as k,STR as g}from"../core/sheet.js";import{registerSparseMap as E,sparseKey as C}from"../core/sparse.js";import{registerSection as Y}from"./sections.js";E("cellDefaults");const y=16384;function O(e,r,s,f,o){if(o.f===void 0)return typeof o.v=="number"?{kind:k,value:o.v}:typeof o.v=="boolean"?{kind:m,value:o.v?1:0}:{kind:g,value:e.strings.add(String(o.v))};const{engine:n}=e;if(!n)return{kind:v,value:0};try{const l=n.template(o.f,s,f).fn(s,f,r),t=l?.sheet?n.refAuto(l,s,f):l;return typeof t=="number"?{kind:k,value:t}:typeof t=="boolean"?{kind:m,value:t?1:0}:typeof t=="string"?{kind:g,value:e.strings.add(t)}:t&&t.code!==void 0?{kind:z,value:Math.max(0,T.indexOf(t.code))}:{kind:v,value:0}}catch{return{kind:v,value:0}}}function B(e,r,s,f,o,n,l,t,i,a,u){const{book:p,dpr:M}=e;for(const[x,R]of s.cellDefaults){const c=Math.floor(x/y),d=x-c*y;if(c<o||c>n||d<l||d>t||s.kind(c,d)!==0)continue;const{kind:D,value:S}=O(p,s,c,d,R);if(D===v)continue;const b=Math.round(f.x*M+(e.displayCols.offsetOf(d)-f.originX)*i),A=Math.round(f.y*M+(s.rows.offsetOf(c)-f.originY)*i),h=Math.round(e.displayCols.sizeOf(d)*i),w=Math.round(s.rows.sizeOf(c)*i);h>0&&w>0&&e._paintText(r,c,d,D,S,b,A,h,w,i,l,t,a,u)}}function H(e,r,s){const{book:f,grid:o}=e,n=f.sheet;f.guardHint={ranges:r},f.transact("entry",()=>{const l=n.cellDefaults??null,t=new Map(l??[]);for(const a of r)for(let u=a.r0;u<=Math.min(a.r1,a.r0+1e5);u++)for(let p=a.c0;p<=Math.min(a.c1,a.c0+1e3);p++)s===void 0?t.delete(C(u,p)):t.set(C(u,p),s);n.cellDefaults=t.size>0?t:null,n.cellTypesChanged=!0;const i=a=>()=>{const u=n.cellDefaults;return n.cellDefaults=a,n.cellTypesChanged=!0,i(u)};return i(l)}),o.invalidate()}function I(e){for(const r of e.sheets){if(!r.cellDefaults)continue;const s=new Map;for(const[f,o]of r.cellDefaults){const n=Math.floor(f/y),l=f-n*y;if(r.kind(n,l)!==0)continue;const t=O(e,r,n,l,o);t.kind!==v&&(r._ensure(n,l),n>r.maxRow&&(r.maxRow=n),l>r.maxCol&&(r.maxCol=l),s.set(f,t))}r.defaultsForSave=s.size>0?s:null}}const F=e=>typeof e=="number"||typeof e=="boolean"||typeof e=="string";Y("cellDefaults",{sheet:{save(e){return e.cellDefaults?.size>0?[...e.cellDefaults]:void 0},load(e,r,s){if(!Array.isArray(r))return;const f=r.filter(o=>Array.isArray(o)&&Number.isInteger(o[0])&&o[1]&&(typeof o[1].f=="string"||F(o[1].v)));e.cellDefaults=f.length>0?new Map(f):null;for(const[o,n]of f){const l=Math.floor(o/y),t=o-l*y,i=e.kind(l,t)&7;if(i===v)continue;(n.f!==void 0||(i===k?e.value(l,t)===n.v:i===g?s.strings.get(e.value(l,t))===String(n.v):i===m))&&!(e.kind(l,t)&8)&&e.setCell(l,t,0,0)}}}});export{O as defaultValueAt,B as paintCellDefaults,I as prepareDefaultsForSave,H as setCellDefaults};
@@ -1 +1 @@
1
- import{colName as E,rangeRef as K,sheetPrefix as O}from"../core/address.js";import{KIND_MASK as P,NUM as z}from"../core/sheet.js";import{changeOutline as H}from"../core/whatif.js";import{outlineChanged as I,setFlag as R}from"./outline-column.js";import{xmlAttr as j}from"../io/xml-escape.js";const M={Sum:["SUM",null],Count:["COUNTA","count"],Average:["AVERAGE","average"],Max:["MAX","max"],Min:["MIN","min"],Product:["PRODUCT","product"],"Count Numbers":["COUNT","countNums"],StdDev:["STDEV","stdDev"],StdDevp:["STDEVP","stdDevp"],Var:["VAR","var"],Varp:["VARP","varp"]},A=n=>typeof n=="string"&&/^[=+\-@']/.test(n)?`'${n}`:String(n??"");function F(n){return String(n??"Book1").replace(/\.[^.]+$/,"").toLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu,(m,i,c)=>i+c.toUpperCase())}function J(n){if(!n)return"";const t=M[n.fn]?.[1],m=`${t?` function="${t}"`:""}${n.leftLabels?' leftLabels="1"':""}${n.topLabels?' topLabels="1"':""}${n.link?' link="1"':""}`,i=n.refs.map(c=>`<dataRef ref="${K(c.range)}" sheet="${j(c.sheet.name)}"/>`).join("");return`<dataConsolidate${m}><dataRefs count="${n.refs.length}">${i}</dataRefs></dataConsolidate>`}function Q(n,t,m,i,{topRow:c=!1,leftCol:w=!1}={}){const{book:d}=n,u=d.sheet;if(m.some(r=>r.sheet===u))return{error:"Links can't be created to source areas on the destination sheet."};const x=d.engine,v=M[i]?.[0]??"SUM",S=[],y=new Map,C=[],D=new Map,L=(r,l,a)=>{const p=String(a).toLowerCase();let s=r.get(p);return s===void 0&&(s=l.length,r.set(p,s),l.push(a)),s},T=m.map(({sheet:r,range:l})=>{const a=l.r0+(c?1:0),p=l.c0+(w?1:0),s=[];for(let e=p;e<=l.c1;e++){const o=c?x.read(r,l.r0,e):e-p;c&&(o===null||o==="")||s.push([e,L(D,C,o)])}const h=[];for(let e=a;e<=l.r1;e++){const o=w?x.read(r,e,l.c0):e-a;w&&(o===null||o==="")||h.push([e,L(y,S,o)])}return{from:r,cols:s,rows:h}}),$=t.col+(w?2:0),V=F(d.fileName??n.fileName);let f=t.row+(c?1:0);return d.guardHint={ranges:[{r0:t.row,c0:t.col,r1:t.row+1,c1:$+C.length}]},d.transact("consolidate",r=>{const l=U(u);return c&&C.forEach((a,p)=>d.setInput(r,t.row,$+p,A(a))),S.forEach((a,p)=>{const s=f,h=new Set;for(const o of T)for(const[g,b]of o.rows)if(b===p){w&&d.setInput(r,f,t.col+1,V);for(const[k,N]of o.cols)(o.from.kind(g,k)&P)===z&&(d.setInput(r,f,$+N,`=${O(o.from.name)}$${E(k)}$${g+1}`),h.add(N));f++}if(f===s)return;const e=f-1;H(u,"row",s,e,1);for(let o=s;o<=e;o++)u.rows.setHidden(o,!0);w&&d.setInput(r,f,t.col,A(a));for(const o of[...h].sort((g,b)=>g-b)){const g=E($+o);d.setInput(r,f,$+o,`=${v}(${g}${s+1}${e>s?`:${g}${e+1}`:""})`)}R(u,"row",f,!0),f++}),u.dataConsolidate={fn:i,leftLabels:w,topLabels:c,link:!0,refs:m.map(a=>({sheet:a.sheet,range:a.range}))},u.dataConsolidateChanged=!0,I(u),u.colsChanged=!0,l}),d.dirty=!0,n.objects?.geometryChanged?.(),n.grid.invalidate(),{rows:S.length,cols:C.length}}function U(n){const t={rowExtras:n.rowExtras?new Map(n.rowExtras):null,hidden:new Set(n.rows.hiddenSizes?n.rows.hiddenSizes.keys():[]),consolidate:n.dataConsolidate??null};return()=>{const m=U(n);if(n.rows.hiddenSizes)for(const i of[...n.rows.hiddenSizes.keys()])t.hidden.has(i)||n.rows.setHidden(i,!1);for(const i of t.hidden)n.rows.setHidden(i,!0);return n.rowExtras=t.rowExtras,n.dataConsolidate=t.consolidate,n.dataConsolidateChanged=!0,I(n),n.revision++,m}}export{M as LINK_FUNCTIONS,F as bookLabel,Q as consolidateLinked,J as dataConsolidateXml};
1
+ import{colName as I,rangeRef as K,sheetPrefix as O}from"../core/address.js";import{KIND_MASK as P,NUM as z}from"../core/sheet.js";import{changeOutline as H}from"../core/whatif.js";import{outlineChanged as M,setFlag as R}from"./outline-column.js";import{xmlAttr as j}from"../io/xml-escape.js";const A={Sum:["SUM",null],Count:["COUNTA","count"],Average:["AVERAGE","average"],Max:["MAX","max"],Min:["MIN","min"],Product:["PRODUCT","product"],"Count Numbers":["COUNT","countNums"],StdDev:["STDEV","stdDev"],StdDevp:["STDEVP","stdDevp"],Var:["VAR","var"],Varp:["VARP","varp"]},x=n=>typeof n=="string"&&/^[=+\-@']/.test(n)?`'${n}`:String(n??"");function F(n){return String(n??"Book1").replace(/\.[^.]+$/,"").toLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu,(m,i,c)=>i+c.toUpperCase())}function J(n){if(!n)return"";const t=A[n.fn]?.[1],m=`${t?` function="${t}"`:""}${n.leftLabels?' leftLabels="1"':""}${n.topLabels?' topLabels="1"':""}${n.link?' link="1"':""}`,i=n.refs.map(c=>`<dataRef ref="${K(c.range)}" sheet="${j(c.sheet.name)}"/>`).join("");return`<dataConsolidate${m}><dataRefs count="${n.refs.length}">${i}</dataRefs></dataConsolidate>`}function Q(n,t,m,i,{topRow:c=!1,leftCol:w=!1}={}){const{book:d}=n,u=d.sheet;if(m.some(r=>r.sheet===u))return{error:"Links can't be created to source areas on the destination sheet."};const L=d.engine,v=A[i]?.[0]??"SUM",S=[],y=new Map,C=[],D=new Map,k=(r,l,a)=>{const p=String(a).toLowerCase();let s=r.get(p);return s===void 0&&(s=l.length,r.set(p,s),l.push(a)),s},T=m.map(({sheet:r,range:l})=>{const a=l.r0+(c?1:0),p=l.c0+(w?1:0),s=[];for(let e=p;e<=l.c1;e++){const o=c?L.read(r,l.r0,e):e-p;c&&(o===null||o==="")||s.push([e,k(D,C,o)])}const h=[];for(let e=a;e<=l.r1;e++){const o=w?L.read(r,e,l.c0):e-a;w&&(o===null||o==="")||h.push([e,k(y,S,o)])}return{from:r,cols:s,rows:h}}),$=t.col+(w?2:0),V=F(d.fileName??n.fileName);let f=t.row+(c?1:0);return d.guardHint={ranges:[{r0:t.row,c0:t.col,r1:t.row+1,c1:$+C.length}]},d.transact("consolidate",r=>{const l=U(u);return c&&C.forEach((a,p)=>d.setInput(r,t.row,$+p,x(a))),S.forEach((a,p)=>{const s=f,h=new Set;for(const o of T)for(const[g,b]of o.rows)if(b===p){w&&d.setInput(r,f,t.col+1,x(V));for(const[N,E]of o.cols)(o.from.kind(g,N)&P)===z&&(d.setInput(r,f,$+E,`=${O(o.from.name)}$${I(N)}$${g+1}`),h.add(E));f++}if(f===s)return;const e=f-1;H(u,"row",s,e,1);for(let o=s;o<=e;o++)u.rows.setHidden(o,!0);w&&d.setInput(r,f,t.col,x(a));for(const o of[...h].sort((g,b)=>g-b)){const g=I($+o);d.setInput(r,f,$+o,`=${v}(${g}${s+1}${e>s?`:${g}${e+1}`:""})`)}R(u,"row",f,!0),f++}),u.dataConsolidate={fn:i,leftLabels:w,topLabels:c,link:!0,refs:m.map(a=>({sheet:a.sheet,range:a.range}))},u.dataConsolidateChanged=!0,M(u),u.colsChanged=!0,l}),d.dirty=!0,n.objects?.geometryChanged?.(),n.grid.invalidate(),{rows:S.length,cols:C.length}}function U(n){const t={rowExtras:n.rowExtras?new Map(n.rowExtras):null,hidden:new Set(n.rows.hiddenSizes?n.rows.hiddenSizes.keys():[]),consolidate:n.dataConsolidate??null};return()=>{const m=U(n);if(n.rows.hiddenSizes)for(const i of[...n.rows.hiddenSizes.keys()])t.hidden.has(i)||n.rows.setHidden(i,!1);for(const i of t.hidden)n.rows.setHidden(i,!0);return n.rowExtras=t.rowExtras,n.dataConsolidate=t.consolidate,n.dataConsolidateChanged=!0,M(n),n.revision++,m}}export{A as LINK_FUNCTIONS,F as bookLabel,Q as consolidateLinked,J as dataConsolidateXml};
@@ -1,2 +1,2 @@
1
- import{CHUNK_BITS as T,CHUNK_MASK as R,EMPTY as B,FORMULA as U,KIND_MASK as J,SPILL as W,STR as D}from"../core/sheet.js";const N=/[.+^${}()|[\]\\]/g;function H(e){if(!/[*?~]/.test(e))return null;let t="";for(let n=0;n<e.length;n++){const s=e[n];s==="~"&&n+1<e.length&&"*?~".includes(e[n+1])?t+=e[++n].replace(/[*?]/,"\\$&"):s==="*"?t+="[\\s\\S]*":s==="?"?t+="[\\s\\S]":t+=s.replace(N,"\\$&")}return t}function v(e,{matchCase:t=!1,whole:n=!1}={}){const s=H(e);if(s===null&&!n){if(t)return r=>r.includes(e);const i=e.toLowerCase();return r=>r.toLowerCase().includes(i)}if(s===null){if(t)return r=>r===e;const i=e.toLowerCase();return r=>r.toLowerCase()===i}const o=new RegExp(n?`^(?:${s})$`:s,t?"":"i");return i=>o.test(i)}function G(e,t,{matchCase:n=!1,whole:s=!1}={}){const o=H(e)??e.replace(N,"\\$&").replace(/[*?]/g,"\\$&"),i=new RegExp(s?`^(?:${o})$`:o,n?"g":"gi");return r=>r.replace(i,()=>t)}const X=(e,t)=>e===t||e&&t&&typeof e=="object"&&JSON.stringify(e)===JSON.stringify(t);function Y(e,t,n){const{styles:s,strings:o}=e,{what:i,look:r,format:h}=t,u=i===""?null:v(i,t),d=new Uint8Array(o.size+1),c=new Map,m=l=>{let a=c.get(l);if(a===void 0){const w=s.get(l);a=Object.keys(h).every(x=>X(w[x]??null,h[x]??null)),c.set(l,a)}return a};return(l,a,w,x,f)=>{if(r==="values"&&(l.rows.isHidden(a)||l.cols.isHidden(w)||l.filteredRows?.has(a))||h!==null&&!m(l.style(a,w)))return!1;if(u===null)return!0;const p=x&J,S=l.protection&&x&U&&s.get(l.style(a,w)).hiddenFormula;if(r==="formulas"&&x&U&&!S)return u(e.editText(l,a,w));if(p===B)return!1;if(p===D){if(f>=d.length)return u(o.get(f));let y=d[f];return y===0&&(y=u(o.get(f))?1:2,d[f]=y),y===1}const g=r==="formulas"&&!S?e.editText(l,a,w):n(p,f,s.get(l.style(a,w)));return u(g)}}const P=12,F=()=>new Promise(e=>setTimeout(e,0));class K{constructor(t){this.ctrl=t,this.start=performance.now()}async pause(){return performance.now()-this.start<P?!this.ctrl.cancelled:(this.ctrl.onProgress?.(),await F(),this.start=performance.now(),!this.ctrl.cancelled)}}const A=(e,t,n)=>e?n*1048576+t:t*16384+n;function q(e){const t=[];for(let n=0;n<=e.maxCol;n++)e.columns[n]!==void 0&&t.push(n);return t}async function _(e,{byCols:t,dir:n,from:s,to:o,withEmpty:i},r,h){const u=q(e);n<0&&u.reverse();const d=s===null?-n*(1/0):s,c=o===null?n*(1/0):o,m=n>0?f=>f>=d&&f<=c:f=>f<=d&&f>=c,l=i===!0;if(t){for(const f of u){const p=e.columns[f],S=n>0?0:p.length-1,g=n>0?p.length:-1;for(let y=S;y!==g;y+=n){const L=p[y];if(L===void 0)continue;const k=y<<T,{kinds:I,values:M,styles:O}=L;for(let C=n>0?0:R;C>=0&&C<=R;C+=n){const $=I[C];if($===0&&!(l&&O!==null&&O[C]!==0))continue;const E=k+C;if(m(A(!0,E,f))&&r(E,f,$,M[C]))return!0}if(!await h.pause())return!1}}return!1}const a=e.maxRow>>>T,w=n>0?0:a,x=n>0?a+1:-1;for(let f=w;f!==x;f+=n){const p=[];for(const g of u){const y=e.columns[g][f];y!==void 0&&p.push(g,y)}if(p.length===0)continue;const S=f<<T;for(let g=n>0?0:R;g>=0&&g<=R;g+=n){const y=S+g;for(let L=0;L<p.length;L+=2){const k=p[L+1],I=k.kinds[g];if(I===0&&!(l&&k.styles!==null&&k.styles[g]!==0))continue;const M=p[L];if(m(A(!1,y,M))&&r(y,M,I,k.values[g]))return!0}}if(!await h.pause())return!1}return!1}function Q(e,t){if(!t.author?.startsWith("tc="))return t;const n=t.author.slice(3),s=(e.threads??[]).filter(o=>o.id===n||o.parentId===n).map(o=>o.text).join(`
2
- `);return{...t,text:s}}function z(e,t,n){if(!e.comments)return[];const s=[];for(const[o,i]of e.comments){const r=Math.floor(o/16384);s.push({row:r,col:o-r*16384,note:Q(e,i)})}return s.sort((o,i)=>n*(A(t,o.row,o.col)-A(t,i.row,i.col))),s}function V(e,t,n){const s=e.sheets.filter(r=>!r.hidden);if(t.within!=="workbook")return[e.sheet];const o=s.indexOf(e.sheet),i=[];for(let r=0;r<s.length;r++)i.push(s[(o+n*r+s.length*2)%s.length]);return i}const Z=(e,t,n)=>e.some(s=>t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1);function j(e,t,n){const s=Y(e,t,n);if(!t.ranges)return s;const o=t.sheet??e.sheet;return(i,r,h,u,d)=>(i!==o||Z(t.ranges,r,h))&&s(i,r,h,u,d)}async function it(e,t,n,s,o,i={}){const r=t.byColumns===!0,h=new K(i),u=V(e,t,s),d=A(r,n.row,n.col);if(t.look==="notes")return b(e,t,u,d,r,s);const c=j(e,t,o),m=t.what===""&&t.format!==null;let l=null;const a=async(w,x,f,p)=>(await _(w,{byCols:r,dir:s,from:x,to:f,withEmpty:m},(S,g,y,L)=>p&&A(r,S,g)===d||!c(w,S,g,y,L)?!1:(l={sheet:w,row:S,col:g},!0),h),l!==null||i.cancelled===!0);if(await a(u[0],d,null,!0))return l;for(let w=1;w<u.length;w++)if(await a(u[w],null,null,!1))return l;return await a(u[0],null,d,!1),l}function b(e,t,n,s,o,i){const r=v(t.what,t),h=c=>r(c.note.text??""),u=z(n[0],o,i),d=i>0?c=>c>s:c=>c<s;for(const c of u)if(d(A(o,c.row,c.col))&&h(c))return{sheet:n[0],row:c.row,col:c.col};for(let c=1;c<n.length;c++)for(const m of z(n[c],o,i))if(h(m))return{sheet:n[c],row:m.row,col:m.col};for(const c of u)if(!d(A(o,c.row,c.col))&&h(c))return{sheet:n[0],row:c.row,col:c.col};return null}class tt{constructor(t){this.cap=t,this.count=0,this.overflow=!1,this.size=Math.min(t,1024),this.rows=new Uint32Array(this.size),this.cols=new Uint16Array(this.size),this.sheets=new Uint16Array(this.size),this.sheetList=[]}push(t,n,s){if(this.count===this.cap)return this.overflow=!0,!1;if(this.count===this.size){this.size=Math.min(this.cap,this.size*2);const r=(h,u)=>{const d=new h(this.size);return d.set(u),d};this.rows=r(Uint32Array,this.rows),this.cols=r(Uint16Array,this.cols),this.sheets=r(Uint16Array,this.sheets)}let o=this.sheetList.indexOf(t);o<0&&(o=this.sheetList.length,this.sheetList.push(t));const i=this.count++;return this.rows[i]=n,this.cols[i]=s,this.sheets[i]=o,!0}}async function et(e,t,n,s={},o=1e5){const i=new tt(o),r=t.byColumns===!0,h=new K(s),u=t.sheet?[t.sheet]:t.within==="workbook"?e.sheets.filter(m=>!m.hidden):[e.sheet];if(t.look==="notes"){const m=v(t.what,t);for(const l of u)for(const a of z(l,r,1))m(a.note.text??"")&&i.push(l,a.row,a.col);return i}const d=j(e,t,n),c=t.what===""&&t.format!==null;for(const m of u)if(await _(m,{byCols:r,dir:1,from:null,to:null,withEmpty:c},(a,w,x,f)=>d(m,a,w,x,f)?!i.push(m,a,w):!1,h)||s.cancelled)break;return i}function nt(e,t,n,s,o,i,r=null){const{sheet:h}=t;let u=!1;if(o!==null){const d=h.formula(n,s);if(d&&d.t==="array")return!1;const c=h.kind(n,s);if(c&W&&!(c&U))return!1;const m=e.editText(h,n,s),l=o(m);if(l!==m&&l.startsWith("=")&&l.length>1&&!st(e,l.slice(1)))return r!==null&&r.invalid++,!1;l!==m&&(e.setInput(t,n,s,l),u=!0)}return i&&(u||t.saveCell(n,s),h.setStyle(n,s,e.styles.derive(h.style(n,s),i)),u=!0),u}async function ot(e,t,n,s,o,i={}){const r=await et(e,{...t,look:"formulas"},o,i,4294967295);if(i.cancelled)return{count:0,sheets:0,cancelled:!0};const h=t.what===""?null:G(t.what,n??"",t);let u=0,d=0;const c={locked:0,invalid:0},m=[];for(let l=0;l<r.sheetList.length;l++){const a=r.sheetList[l],w=[];let x=0,f=0;for(;f<r.count;){const p=performance.now(),S=e.runSlice(a,"replace",g=>{for(let y=0;f<r.count&&!(y%1024===1023&&performance.now()-p>P);f++,y++){if(r.sheets[f]!==l)continue;const L=r.rows[f],k=r.cols[f];if(a.protection&&e.styles.get(a.style(L,k)).unlocked!==!0){c.locked++;continue}nt(e,g,L,k,h,s,c)&&x++}});if(S!==null&&w.push(S),i.onProgress?.(),f<r.count&&await F(),i.cancelled)return e.rollbackSlices([...m,...w]),{count:0,sheets:0,cancelled:!0}}m.push(...w),x>0&&(u+=x,d++)}return e.pushFolded(m,"replace",e.sheet),{count:u,sheets:d,...c}}function st(e,t){if(!e.engine)return!0;try{return e.engine.validate(t),!0}catch{return!1}}export{tt as FoundList,et as findAll,it as findNext,v as makeMatcher,G as makeReplacer,Y as makeTest,ot as replaceAll,nt as replaceInCell};
1
+ import{formulaEntryLimit as B}from"../calc/parser.js";import{CHUNK_BITS as T,CHUNK_MASK as R,EMPTY as J,FORMULA as U,KIND_MASK as W,SPILL as D,STR as G}from"../core/sheet.js";const N=/[.+^${}()|[\]\\]/g;function H(e){if(!/[*?~]/.test(e))return null;let t="";for(let n=0;n<e.length;n++){const s=e[n];s==="~"&&n+1<e.length&&"*?~".includes(e[n+1])?t+=e[++n].replace(/[*?]/,"\\$&"):s==="*"?t+="[\\s\\S]*":s==="?"?t+="[\\s\\S]":t+=s.replace(N,"\\$&")}return t}function v(e,{matchCase:t=!1,whole:n=!1}={}){const s=H(e);if(s===null&&!n){if(t)return r=>r.includes(e);const i=e.toLowerCase();return r=>r.toLowerCase().includes(i)}if(s===null){if(t)return r=>r===e;const i=e.toLowerCase();return r=>r.toLowerCase()===i}const o=new RegExp(n?`^(?:${s})$`:s,t?"":"i");return i=>o.test(i)}function X(e,t,{matchCase:n=!1,whole:s=!1}={}){const o=H(e)??e.replace(N,"\\$&").replace(/[*?]/g,"\\$&"),i=new RegExp(s?`^(?:${o})$`:o,n?"g":"gi");return r=>r.replace(i,()=>t)}const Y=(e,t)=>e===t||e&&t&&typeof e=="object"&&JSON.stringify(e)===JSON.stringify(t);function q(e,t,n){const{styles:s,strings:o}=e,{what:i,look:r,format:h}=t,u=i===""?null:v(i,t),d=new Uint8Array(o.size+1),c=new Map,m=l=>{let a=c.get(l);if(a===void 0){const w=s.get(l);a=Object.keys(h).every(x=>Y(w[x]??null,h[x]??null)),c.set(l,a)}return a};return(l,a,w,x,f)=>{if(r==="values"&&(l.rows.isHidden(a)||l.cols.isHidden(w)||l.filteredRows?.has(a))||h!==null&&!m(l.style(a,w)))return!1;if(u===null)return!0;const p=x&W,S=l.protection&&x&U&&s.get(l.style(a,w)).hiddenFormula;if(r==="formulas"&&x&U&&!S)return u(e.editText(l,a,w));if(p===J)return!1;if(p===G){if(f>=d.length)return u(o.get(f));let y=d[f];return y===0&&(y=u(o.get(f))?1:2,d[f]=y),y===1}const g=r==="formulas"&&!S?e.editText(l,a,w):n(p,f,s.get(l.style(a,w)));return u(g)}}const P=12,F=()=>new Promise(e=>setTimeout(e,0));class K{constructor(t){this.ctrl=t,this.start=performance.now()}async pause(){return performance.now()-this.start<P?!this.ctrl.cancelled:(this.ctrl.onProgress?.(),await F(),this.start=performance.now(),!this.ctrl.cancelled)}}const A=(e,t,n)=>e?n*1048576+t:t*16384+n;function Q(e){const t=[];for(let n=0;n<=e.maxCol;n++)e.columns[n]!==void 0&&t.push(n);return t}async function _(e,{byCols:t,dir:n,from:s,to:o,withEmpty:i},r,h){const u=Q(e);n<0&&u.reverse();const d=s===null?-n*(1/0):s,c=o===null?n*(1/0):o,m=n>0?f=>f>=d&&f<=c:f=>f<=d&&f>=c,l=i===!0;if(t){for(const f of u){const p=e.columns[f],S=n>0?0:p.length-1,g=n>0?p.length:-1;for(let y=S;y!==g;y+=n){const L=p[y];if(L===void 0)continue;const k=y<<T,{kinds:I,values:M,styles:E}=L;for(let C=n>0?0:R;C>=0&&C<=R;C+=n){const O=I[C];if(O===0&&!(l&&E!==null&&E[C]!==0))continue;const $=k+C;if(m(A(!0,$,f))&&r($,f,O,M[C]))return!0}if(!await h.pause())return!1}}return!1}const a=e.maxRow>>>T,w=n>0?0:a,x=n>0?a+1:-1;for(let f=w;f!==x;f+=n){const p=[];for(const g of u){const y=e.columns[g][f];y!==void 0&&p.push(g,y)}if(p.length===0)continue;const S=f<<T;for(let g=n>0?0:R;g>=0&&g<=R;g+=n){const y=S+g;for(let L=0;L<p.length;L+=2){const k=p[L+1],I=k.kinds[g];if(I===0&&!(l&&k.styles!==null&&k.styles[g]!==0))continue;const M=p[L];if(m(A(!1,y,M))&&r(y,M,I,k.values[g]))return!0}}if(!await h.pause())return!1}return!1}function V(e,t){if(!t.author?.startsWith("tc="))return t;const n=t.author.slice(3),s=(e.threads??[]).filter(o=>o.id===n||o.parentId===n).map(o=>o.text).join(`
2
+ `);return{...t,text:s}}function z(e,t,n){if(!e.comments)return[];const s=[];for(const[o,i]of e.comments){const r=Math.floor(o/16384);s.push({row:r,col:o-r*16384,note:V(e,i)})}return s.sort((o,i)=>n*(A(t,o.row,o.col)-A(t,i.row,i.col))),s}function Z(e,t,n){const s=e.sheets.filter(r=>!r.hidden);if(t.within!=="workbook")return[e.sheet];const o=s.indexOf(e.sheet),i=[];for(let r=0;r<s.length;r++)i.push(s[(o+n*r+s.length*2)%s.length]);return i}const b=(e,t,n)=>e.some(s=>t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1);function j(e,t,n){const s=q(e,t,n);if(!t.ranges)return s;const o=t.sheet??e.sheet;return(i,r,h,u,d)=>(i!==o||b(t.ranges,r,h))&&s(i,r,h,u,d)}async function ct(e,t,n,s,o,i={}){const r=t.byColumns===!0,h=new K(i),u=Z(e,t,s),d=A(r,n.row,n.col);if(t.look==="notes")return tt(e,t,u,d,r,s);const c=j(e,t,o),m=t.what===""&&t.format!==null;let l=null;const a=async(w,x,f,p)=>(await _(w,{byCols:r,dir:s,from:x,to:f,withEmpty:m},(S,g,y,L)=>p&&A(r,S,g)===d||!c(w,S,g,y,L)?!1:(l={sheet:w,row:S,col:g},!0),h),l!==null||i.cancelled===!0);if(await a(u[0],d,null,!0))return l;for(let w=1;w<u.length;w++)if(await a(u[w],null,null,!1))return l;return await a(u[0],null,d,!1),l}function tt(e,t,n,s,o,i){const r=v(t.what,t),h=c=>r(c.note.text??""),u=z(n[0],o,i),d=i>0?c=>c>s:c=>c<s;for(const c of u)if(d(A(o,c.row,c.col))&&h(c))return{sheet:n[0],row:c.row,col:c.col};for(let c=1;c<n.length;c++)for(const m of z(n[c],o,i))if(h(m))return{sheet:n[c],row:m.row,col:m.col};for(const c of u)if(!d(A(o,c.row,c.col))&&h(c))return{sheet:n[0],row:c.row,col:c.col};return null}class et{constructor(t){this.cap=t,this.count=0,this.overflow=!1,this.size=Math.min(t,1024),this.rows=new Uint32Array(this.size),this.cols=new Uint16Array(this.size),this.sheets=new Uint16Array(this.size),this.sheetList=[]}push(t,n,s){if(this.count===this.cap)return this.overflow=!0,!1;if(this.count===this.size){this.size=Math.min(this.cap,this.size*2);const r=(h,u)=>{const d=new h(this.size);return d.set(u),d};this.rows=r(Uint32Array,this.rows),this.cols=r(Uint16Array,this.cols),this.sheets=r(Uint16Array,this.sheets)}let o=this.sheetList.indexOf(t);o<0&&(o=this.sheetList.length,this.sheetList.push(t));const i=this.count++;return this.rows[i]=n,this.cols[i]=s,this.sheets[i]=o,!0}}async function nt(e,t,n,s={},o=1e5){const i=new et(o),r=t.byColumns===!0,h=new K(s),u=t.sheet?[t.sheet]:t.within==="workbook"?e.sheets.filter(m=>!m.hidden):[e.sheet];if(t.look==="notes"){const m=v(t.what,t);for(const l of u)for(const a of z(l,r,1))m(a.note.text??"")&&i.push(l,a.row,a.col);return i}const d=j(e,t,n),c=t.what===""&&t.format!==null;for(const m of u)if(await _(m,{byCols:r,dir:1,from:null,to:null,withEmpty:c},(a,w,x,f)=>d(m,a,w,x,f)?!i.push(m,a,w):!1,h)||s.cancelled)break;return i}function st(e,t,n,s,o,i,r=null){const{sheet:h}=t;let u=!1;if(o!==null){const d=h.formula(n,s);if(d&&d.t==="array")return!1;const c=h.kind(n,s);if(c&D&&!(c&U))return!1;const m=e.editText(h,n,s),l=o(m);if(l!==m&&l.startsWith("=")&&l.length>1&&!rt(e,l.slice(1)))return r!==null&&r.invalid++,!1;l!==m&&(e.setInput(t,n,s,l),u=!0)}return i&&(u||t.saveCell(n,s),h.setStyle(n,s,e.styles.derive(h.style(n,s),i)),u=!0),u}async function lt(e,t,n,s,o,i={}){const r=await nt(e,{...t,look:"formulas"},o,i,4294967295);if(i.cancelled)return{count:0,sheets:0,cancelled:!0};const h=t.what===""?null:X(t.what,n??"",t);let u=0,d=0;const c={locked:0,invalid:0},m=[];for(let l=0;l<r.sheetList.length;l++){const a=r.sheetList[l],w=[];let x=0,f=0;for(;f<r.count;){const p=performance.now(),S=e.runSlice(a,"replace",g=>{for(let y=0;f<r.count&&!(y%1024===1023&&performance.now()-p>P);f++,y++){if(r.sheets[f]!==l)continue;const L=r.rows[f],k=r.cols[f];if(a.protection&&e.styles.get(a.style(L,k)).unlocked!==!0){c.locked++;continue}st(e,g,L,k,h,s,c)&&x++}});if(S!==null&&w.push(S),i.onProgress?.(),f<r.count&&await F(),i.cancelled)return e.rollbackSlices([...m,...w]),{count:0,sheets:0,cancelled:!0}}m.push(...w),x>0&&(u+=x,d++)}return e.pushFolded(m,"replace",e.sheet),{count:u,sheets:d,...c}}function rt(e,t){if(!e.engine)return!B(t);try{return e.engine.validate(t),!0}catch{return!1}}export{et as FoundList,nt as findAll,ct as findNext,v as makeMatcher,X as makeReplacer,q as makeTest,lt as replaceAll,st as replaceInCell};
@@ -1,3 +1,3 @@
1
- import{el as n}from"../ui/dialogs.js";import{PATTERN_LABELS as tt,patternFill as W}from"../render/patterns.js";import{gradientCss as et}from"./paint.js";import{ensureStyles as D,numberField as _,paletteButton as V,popButton as nt,popOver as lt,svgNode as it}from"./format-tabs.js";import{t as s,tc as w}from"../i18n/index.js";const P=(e,t,l,r,a="dlg-input")=>{const c=n("select",{class:a,"aria-label":s(r)});for(const[u,x]of e)c.append(n("option",{value:x,textContent:u}));return c.value=t??"",c.addEventListener("change",()=>l(c.value)),c},E=(e,t,l)=>{const r=n("input",{type:"checkbox",checked:t,on:{change:()=>l(r.checked)}}),a=n("label",{class:"dlg-row dlg-check"},r,s(e));return a.input=r,a},ot=[["General",""],["Left (Indent)","left"],["Center","center"],["Right (Indent)","right"],["Fill","fill"],["Justify","justify"],["Center Across Selection","centerContinuous"],["Distributed (Indent)","distributed"]],st=[["Top","top"],["Center","center"],["Bottom",""],["Justify","justify"],["Distributed","distributed"]],q=new Set(["left","right","distributed"]),Y=e=>e.map(([t,l])=>[w("align",t),l]),Z=e=>e.replace(/[&<>"]/g,t=>`&#${t.charCodeAt(0)};`),S={cx:7.5,cy:75,radius:69},at=(e,t=S.radius)=>[S.cx+t*Math.cos(e*Math.PI/180),S.cy-t*Math.sin(e*Math.PI/180)],X=(e,t,l)=>`M${e} ${t-l}L${e+l} ${t}L${e} ${t+l}L${e-l} ${t}Z`;function rt(){let e="";for(let t=-90;t<=90;t+=15){const[l,r]=at(t);e+=t%45===0?`<path d="${X(l,r,3)}" fill="#222"/>`:`<circle cx="${l}" cy="${r}" r="0.9" fill="#555"/>`}return`<svg class="fc-dial" viewBox="0 0 91 150" role="slider" aria-label="${Z(s("Orientation"))}" aria-valuemin="-90" aria-valuemax="90" tabindex="0">${e}
2
- <g data-hand><text x="10" y="79.5" font-size="13" fill="#000">${Z(s("Text"))}</text><line x1="39" y1="75" x2="72" y2="75" stroke="#777" stroke-width="1"/></g>
3
- <path data-mark d="${X(S.cx+S.radius,S.cy,3.4)}" fill="#8c1d2f"/></svg>`}function mt(e,t,l,r){D();let a=e.hAlign??"",c=e.rotation===255,u=e.rotation>90&&e.rotation<=180?90-e.rotation:e.rotation===255?0:e.rotation;const x=n("div",{class:"dlg-label",textContent:s("Indent:")}),v=_({value:e.indent,min:0,max:250,label:w("fc","Indent"),onInput:o=>{t.indent=Math.max(0,o||0)}}),L=()=>{const o=q.has(a)||Number(v.input.value)>0;v.setDisabled(!o),x.classList.toggle("fc-off",!o)},f=E("Justify distributed",e.justifyLastLine===!0,o=>{t.justifyLastLine=o||void 0}),F=()=>{const o=a==="distributed";f.input.disabled=!o},N=P(Y(ot),e.hAlign,o=>{a=o,t.hAlign=o||null,!q.has(o)&&Number(v.input.value)>0&&(v.set(0),t.indent=0),o!=="distributed"&&f.input.checked&&(f.input.checked=!1,t.justifyLastLine=void 0),L(),F()},"Horizontal alignment"),h=_({value:u,min:-90,max:90,label:"Degrees",onInput:o=>T(Math.max(-90,Math.min(90,o||0)),!1)}),g=it(rt()),y=g.querySelector("[data-hand]"),d=g.querySelector("[data-mark]"),p=n("button",{type:"button",class:"fc-vert","aria-label":s("Vertical text"),title:s("Vertical text"),"aria-pressed":String(c)},...[...s("Text")].map(o=>n("span",{textContent:o}))),I=()=>{y.setAttribute("transform",`rotate(${-u} ${S.cx} ${S.cy})`),d.setAttribute("transform",`rotate(${-u} ${S.cx} ${S.cy})`),y.style.opacity=c?"0.3":"1",d.style.display=c?"none":"",g.setAttribute("aria-valuenow",String(u)),p.setAttribute("aria-pressed",String(c))},T=(o,k=!0)=>{u=o,c=!1,t.rotation=o<0?90-o:o,k&&h.set(o),I()};p.addEventListener("click",()=>{c=!c,u=0,h.set(0),t.rotation=c?255:0,I()});const m=o=>{const k=g.getBoundingClientRect(),M=(o.clientX-k.left)*(91/k.width)-S.cx,z=S.cy-(o.clientY-k.top)*(150/k.height);let A=M<=0?Math.sign(z)*90:Math.round(Math.atan2(z,M)*180/Math.PI);const B=Math.round(A/15)*15;Math.abs(B-A)<=2&&(A=B),T(A===0?0:A)};return g.addEventListener("pointerdown",o=>{o.preventDefault(),g.setPointerCapture(o.pointerId),g.focus(),m(o)}),g.addEventListener("pointermove",o=>{g.hasPointerCapture(o.pointerId)&&m(o)}),g.addEventListener("keydown",o=>{const k={ArrowUp:1,ArrowRight:1,ArrowDown:-1,ArrowLeft:-1}[o.key];k&&(o.preventDefault(),T(Math.max(-90,Math.min(90,u+k))))}),L(),F(),I(),n("div",{class:"fc-align fc-bleed"},n("div",{class:"fc-align-left"},n("div",{class:"fc-align-grid"},n("div",{},n("div",{class:"dlg-label",textContent:s("Horizontal alignment:")}),N),n("div",{},x,v.node),n("div",{},n("div",{class:"dlg-label",textContent:s("Vertical alignment:")}),P(Y(st),e.vAlign,o=>{t.vAlign=o||null},"Vertical alignment"))),f),n("div",{class:"fc-align-right"},n("div",{class:"dlg-label",textContent:s("Orientation:")}),n("div",{class:"fc-orient"},p,g),n("div",{class:"fc-degrees"},n("span",{textContent:s("Degrees:")}),h.node)),n("div",{class:"fc-align-low"},n("div",{class:"dlg-label",textContent:s("Text control:")}),E("Wrap text",e.wrap,o=>{t.wrap=o}),E("Shrink to fit",e.shrink,o=>{t.shrink=o}),E("Merge cells",l,r),n("div",{class:"fc-textdir"},n("span",{textContent:s("Text direction:")}),P([[s("Context"),"0"],[s("Left-to-Right"),"1"],[s("Right-to-Left"),"2"]],String(e.readingOrder??0),o=>{t.readingOrder=Number(o)||void 0},"Text direction"))))}const ct=["Aptos Narrow","Aptos","Arial","Calibri","Cambria","Consolas","Courier New","Georgia","Helvetica Neue","Menlo","Tahoma","Times New Roman","Trebuchet MS","Verdana"],K=["Regular","Italic","Bold","Bold Italic"],dt=[8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72];function H(e,t,l={}){const r=n("input",{class:"dlg-input",spellcheck:!1,"aria-label":s(t),...l}),a=n("select",{class:"dlg-list",size:6,"aria-label":s("{name} list",{name:s(t)})});return{node:n("div",{class:"fc-combo"},n("label",{class:"fc-combo-head"},n("span",{textContent:s(e)}),r),a),input:r,list:a}}const j=(e,t,l=r=>r)=>{for(const r of t)e.append(n("option",{value:r,textContent:l(r)}))},R=e=>{const t=e.options[e.selectedIndex];if(!t)return;const l=t.offsetTop-e.options[0].offsetTop+t.offsetHeight;e.scrollTop=l>e.clientHeight?l-e.clientHeight+t.offsetHeight:0},G=(e,t)=>e&&t?"Bold Italic":e?"Bold":t?"Italic":"Regular",O=e=>w("fontstyle",e);function xt(e,t,l,r){D();const a=i=>l[i]!==void 0?l[i]:e[i],c=t.fontName,u=[...ct];u.includes(e.fontName)||u.unshift(e.fontName);const x=i=>s("{name} (Body)",{name:i}),v=i=>s("{name} (Headings)",{name:i}),L=i=>i===c?x(i):i,f=[x(""),v("")].filter(Boolean),F=i=>{const b=i.trim(),C=f.find($=>b.endsWith($));return C?b.slice(0,b.length-C.length).trim():b},N=[];r&&N.push(v(r)),N.push(x(c),...u);const h=n("div",{class:"fc-preview","aria-label":s("Preview")});let g=null;const y=()=>{const i=a("vertAlign"),b=Number(a("underline")??0);h.style.font=`${a("italic")?"italic ":""}${a("bold")?"bold ":""}${Math.min(a("fontSize"),36)}px "${a("fontName")}", sans-serif`,h.style.color=a("color")??"#000000",h.style.textDecoration=[b?"underline":"",a("strike")?"line-through":""].filter(Boolean).join(" "),h.style.textDecorationStyle=b===2||b===4?"double":"solid",h.replaceChildren(i?n(i==="superscript"?"sup":"sub",{textContent:a("fontName")}):document.createTextNode(a("fontName"))),g.checked=["fontName","fontSize","bold","italic","strike","color"].every(C=>(a(C)??null)===(t[C]??null))&&b===Number(t.underline??0)&&!i},d=H("Font:","Font");j(d.list,N),d.input.value=L(e.fontName),d.list.value=L(e.fontName),d.list.addEventListener("change",()=>{d.input.value=d.list.value,l.fontName=F(d.list.value),y()}),d.input.addEventListener("input",()=>{const i=F(d.input.value);if(i==="")return;l.fontName=i;const b=d.input.value.trim().toLowerCase(),C=N.find($=>$.toLowerCase().startsWith(b));C?(d.list.value=C,R(d.list)):d.list.selectedIndex=-1,y()}),d.input.addEventListener("change",()=>{d.input.value=L(F(d.input.value)||a("fontName"))});const p=H("Font style:","Font style");j(p.list,K,O);const I=i=>{p.input.value=O(i),p.list.value=i};I(G(e.bold,e.italic));const T=i=>{l.bold=i.includes("Bold"),l.italic=i.includes("Italic"),y()};p.list.addEventListener("change",()=>{p.input.value=O(p.list.value),T(p.list.value)}),p.input.addEventListener("input",()=>{const i=p.input.value.trim().toLowerCase(),b=K.find(C=>O(C).toLowerCase()===i);b&&(p.list.value=b,T(b))}),p.input.addEventListener("change",()=>I(G(a("bold"),a("italic"))));const m=H("Size:","Size",{type:"number",min:1,max:409,step:"any"});j(m.list,dt.map(String));const o=i=>{m.input.value=String(i),m.list.value=String(i)};o(e.fontSize),m.list.addEventListener("change",()=>{m.input.value=m.list.value,l.fontSize=Number(m.list.value),y()}),m.input.addEventListener("input",()=>{const i=Number(m.input.value);i>0&&(l.fontSize=i,m.list.value=String(i),y())});const k=P([[s("None"),"0"],[w("underline","Single"),"1"],[w("underline","Double"),"2"],[w("underline","Single Accounting"),"3"],[w("underline","Double Accounting"),"4"]],String(e.underline),i=>{l.underline=Number(i),y()},"Underline"),M=(i,b,C)=>{const $=n("input",{type:"checkbox",checked:b,"aria-label":s(i),on:{change:()=>{C($.checked),y()}}});return{i:$,row:n("label",{class:"dlg-row dlg-check"},$,s(i))}},z=M("Strikethrough",e.strike,i=>{l.strike=i}),A=M("Superscript",e.vertAlign==="superscript",i=>{l.vertAlign=i?"superscript":null,i&&(B.i.checked=!1)}),B=M("Subscript",e.vertAlign==="subscript",i=>{l.vertAlign=i?"subscript":null,i&&(A.i.checked=!1)}),J=V(e.color,"#000000",i=>{l.color=i,y()},{label:"Font color"});g=n("input",{type:"checkbox","aria-label":s("Normal font"),on:{change:()=>{if(!g.checked){y();return}Object.assign(l,{fontName:t.fontName,fontSize:t.fontSize,bold:t.bold,italic:t.italic,strike:t.strike,underline:t.underline??0,color:t.color??null,vertAlign:null}),d.input.value=L(t.fontName),d.list.value=L(t.fontName),o(t.fontSize),I(G(t.bold,t.italic)),k.value=String(t.underline??0),z.i.checked=t.strike,A.i.checked=!1,B.i.checked=!1,J.setValue(t.color??null),R(d.list),R(m.list),y()}}});const U=n("div",{class:"fc-font fc-bleed"},n("div",{class:"fc-font-top"},d.node,p.node,m.node,n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Underline:")}),k),n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Color:")}),J),n("div",{class:"fc-font-cell fc-font-normal"},n("label",{class:"dlg-row dlg-check"},g,s("Normal font")))),n("div",{class:"fc-font-low"},n("div",{},n("div",{class:"dlg-label",textContent:s("Effects:")}),z.row,A.row,B.row),n("div",{},n("div",{class:"dlg-label",textContent:s("Preview")}),h)));return U.onShow=()=>[d.list,p.list,m.list].forEach(R),y(),U}function Q(e){const t=document.createElement("canvas");if(t.width=32,t.height=20,e){const l=t.getContext("2d");l.fillStyle=W(l,{type:e,fg:"#000000"},1)??"#FFFFFF",l.fillRect(0,0,32,20)}return t}function ut(e,t){const l=n("span",{class:"fc-pat-chip"}),r=nt("Pattern style",l),a=()=>l.replaceChildren(...e?[Q(e)]:[]);return a(),r.setValue=c=>{e=c,a()},lt(r,"Pattern style list",c=>{const u=n("div",{class:"fc-pat-grid"});for(const[x,v]of tt)u.append(n("button",{type:"button",title:w("pattern",x),"aria-label":w("pattern",x),"aria-pressed":String(v===e),on:{click:()=>{e=v,a(),c(),t(v)}}},Q(v)));return u}),r}function ht(e,t,l){D();let r=e.pattern?.type??"",a=e.pattern?.fg??"#000000";const c=n("div",{class:"fc-sample","aria-label":s("Sample")}),u=()=>{const f=t.fill!==void 0?t.fill:e.fill,F=t.gradient!==void 0?t.gradient:e.gradient,N=t.pattern!==void 0?t.pattern:e.pattern;if(c.style.backgroundColor=f??(F||N?"#FFFFFF":"transparent"),c.style.backgroundImage="none",F)c.style.backgroundImage=et(F);else if(N){const h=document.createElement("canvas");h.width=16,h.height=16;const g=h.getContext("2d");g.fillStyle=W(g,N,1)??"#FFFFFF",g.fillRect(0,0,16,16),c.style.backgroundImage=`url(${h.toDataURL()})`}},x=ut(r,f=>{r=f,t.pattern=f?{type:f,fg:a}:null,f&&(t.gradient=null),f&&!e.fill&&!t.fill&&(t.fill="#FFFFFF"),u()}),v=V(e.fill??null,"#FFFFFF",f=>{f===null?(t.fill=null,t.pattern=null,t.gradient=null,r="",x.setValue("")):(t.fill=f,t.gradient=null),u()},{none:"No Color",label:"Background color",named:!0}),L=n("button",{type:"button",class:"dlg-btn",textContent:s("Fill Effects…"),on:{click:()=>l(t.gradient??e.gradient,f=>{t.gradient=f,t.pattern=null,t.fill=f.stops[0].color,r="",x.setValue(""),v.setValue(null),u()})}});return u(),n("div",{class:"fc-fill fc-bleed"},n("div",{class:"fc-fill-left"},n("div",{class:"dlg-label",textContent:s("Background color:")}),v,L),n("div",{class:"fc-fill-right"},n("div",{class:"dlg-label",textContent:s("Pattern color:")}),V(e.pattern?.fg??null,"#000000",f=>{a=f??"#000000",r&&(t.pattern={type:r,fg:a}),u()},{label:"Pattern color",named:!0}),n("div",{class:"dlg-label",textContent:s("Pattern style:")}),x),n("div",{class:"fc-fill-low"},n("div",{class:"dlg-label",textContent:s("Sample")}),c))}function yt(e,t){return D(),n("div",{class:"fc-protect"},n("p",{class:"fc-hint",textContent:s("To lock cells or hide formulas, protect the worksheet. On the Review tab, click Protect Sheet.")}),E(w("protect","Locked"),e.unlocked!==!0,l=>{t.unlocked=l?void 0:!0}),E(w("protect","Hidden"),e.hiddenFormula===!0,l=>{t.hiddenFormula=l?!0:void 0}),E("Allow editing in the cell",e.ext?.noEdit!==!0,l=>{t.ext={noEdit:l?null:!0}}))}export{mt as alignmentTab,ht as fillTab,xt as fontTab,yt as protectionTab};
1
+ import{el as n}from"../ui/dialogs.js";import{PATTERN_LABELS as te,patternFill as _}from"../render/patterns.js";import{gradientCss as ne}from"./paint.js";import{ensureStyles as z,numberField as q,paletteButton as H,popButton as le,popOver as ie,svgNode as oe}from"./format-tabs.js";import{t as s,tc as F}from"../i18n/index.js";const D=(t,e,i,c,d="dlg-input")=>{const r=n("select",{class:d,"aria-label":s(c)});for(const[p,m]of t)r.append(n("option",{value:m,textContent:p}));return r.value=e??"",r.addEventListener("change",()=>i(r.value)),r},E=(t,e,i)=>{const c=n("input",{type:"checkbox",checked:e,on:{change:()=>i(c.checked)}}),d=n("label",{class:"dlg-row dlg-check"},c,s(t));return d.input=c,d},se=[["General",""],["Left (Indent)","left"],["Center","center"],["Right (Indent)","right"],["Fill","fill"],["Justify","justify"],["Center Across Selection","centerContinuous"],["Distributed (Indent)","distributed"]],re=[["Top","top"],["Center","center"],["Bottom",""],["Justify","justify"],["Distributed","distributed"]],Y=new Set(["left","right","distributed"]),Z=t=>t.map(([e,i])=>[F("align",e),i]),X=t=>t.replace(/[&<>"]/g,e=>`&#${e.charCodeAt(0)};`),C={cx:7.5,cy:75,radius:69},ae=(t,e=C.radius)=>[C.cx+e*Math.cos(t*Math.PI/180),C.cy-e*Math.sin(t*Math.PI/180)],K=(t,e,i)=>`M${t} ${e-i}L${t+i} ${e}L${t} ${e+i}L${t-i} ${e}Z`;function ce(){let t="";for(let e=-90;e<=90;e+=15){const[i,c]=ae(e);t+=e%45===0?`<path d="${K(i,c,3)}" fill="#222"/>`:`<circle cx="${i}" cy="${c}" r="0.9" fill="#555"/>`}return`<svg class="fc-dial" viewBox="0 0 91 150" role="slider" aria-label="${X(s("Orientation"))}" aria-valuemin="-90" aria-valuemax="90" tabindex="0">${t}
2
+ <g data-hand><text x="10" y="79.5" font-size="13" fill="#000">${X(s("Text"))}</text><line x1="39" y1="75" x2="72" y2="75" stroke="#777" stroke-width="1"/></g>
3
+ <path data-mark d="${K(C.cx+C.radius,C.cy,3.4)}" fill="#8c1d2f"/></svg>`}function he(t,e,i,c){z();let d=t.hAlign??"",r=t.rotation===255,p=t.rotation>90&&t.rotation<=180?90-t.rotation:t.rotation===255?0:t.rotation;const m=n("div",{class:"dlg-label",textContent:s("Indent:")}),g=q({value:t.indent,min:0,max:250,label:F("fc","Indent"),onInput:l=>{e.indent=Math.max(0,l||0)}}),w=()=>{const l=Y.has(d)||Number(g.input.value)>0;g.setDisabled(!l),m.classList.toggle("fc-off",!l)},x=E("Justify distributed",t.justifyLastLine===!0,l=>{e.justifyLastLine=l||void 0}),N=()=>{const l=d==="distributed";x.input.disabled=!l},A=D(Z(se),t.hAlign,l=>{d=l,e.hAlign=l||null,!Y.has(l)&&Number(g.input.value)>0&&(g.set(0),e.indent=0),l!=="distributed"&&x.input.checked&&(x.input.checked=!1,e.justifyLastLine=void 0),w(),N()},"Horizontal alignment"),f=q({value:p,min:-90,max:90,label:"Degrees",onInput:l=>I(Math.max(-90,Math.min(90,l||0)),!1)}),u=oe(ce()),S=u.querySelector("[data-hand]"),b=u.querySelector("[data-mark]"),a=n("button",{type:"button",class:"fc-vert","aria-label":s("Vertical text"),title:s("Vertical text"),"aria-pressed":String(r)},...[...s("Text")].map(l=>n("span",{textContent:l}))),h=()=>{S.setAttribute("transform",`rotate(${-p} ${C.cx} ${C.cy})`),b.setAttribute("transform",`rotate(${-p} ${C.cx} ${C.cy})`),S.style.opacity=r?"0.3":"1",b.style.display=r?"none":"",u.setAttribute("aria-valuenow",String(p)),a.setAttribute("aria-pressed",String(r))},I=(l,y=!0)=>{p=l,r=!1,e.rotation=l<0?90-l:l,y&&f.set(l),h()};a.addEventListener("click",()=>{r=!r,p=0,f.set(0),e.rotation=r?255:0,h()});const M=l=>{const y=u.getBoundingClientRect(),B=(l.clientX-y.left)*(91/y.width)-C.cx,T=C.cy-(l.clientY-y.top)*(150/y.height);let L=B<=0?Math.sign(T)*90:Math.round(Math.atan2(T,B)*180/Math.PI);const R=Math.round(L/15)*15;Math.abs(R-L)<=2&&(L=R),I(L===0?0:L)};return u.addEventListener("pointerdown",l=>{l.preventDefault(),u.setPointerCapture(l.pointerId),u.focus(),M(l)}),u.addEventListener("pointermove",l=>{u.hasPointerCapture(l.pointerId)&&M(l)}),u.addEventListener("keydown",l=>{const y={ArrowUp:1,ArrowRight:1,ArrowDown:-1,ArrowLeft:-1}[l.key];y&&(l.preventDefault(),I(Math.max(-90,Math.min(90,p+y))))}),w(),N(),h(),n("div",{class:"fc-align fc-bleed"},n("div",{class:"fc-align-left"},n("div",{class:"fc-align-grid"},n("div",{},n("div",{class:"dlg-label",textContent:s("Horizontal alignment:")}),A),n("div",{},m,g.node),n("div",{},n("div",{class:"dlg-label",textContent:s("Vertical alignment:")}),D(Z(re),t.vAlign,l=>{e.vAlign=l||null},"Vertical alignment"))),x),n("div",{class:"fc-align-right"},n("div",{class:"dlg-label",textContent:s("Orientation:")}),n("div",{class:"fc-orient"},a,u),n("div",{class:"fc-degrees"},n("span",{textContent:s("Degrees:")}),f.node)),n("div",{class:"fc-align-low"},n("div",{class:"dlg-label",textContent:s("Text control:")}),E("Wrap text",t.wrap,l=>{e.wrap=l}),E("Shrink to fit",t.shrink,l=>{e.shrink=l}),E("Merge cells",i,c),n("div",{class:"fc-textdir"},n("span",{textContent:s("Text direction:")}),D([[s("Context"),"0"],[s("Left-to-Right"),"1"],[s("Right-to-Left"),"2"]],String(t.readingOrder??0),l=>{e.readingOrder=Number(l)||void 0},"Text direction"))))}const de=["Aptos Narrow","Aptos","Arial","Calibri","Cambria","Consolas","Courier New","Georgia","Helvetica Neue","Menlo","Tahoma","Times New Roman","Trebuchet MS","Verdana"],Q=["Regular","Italic","Bold","Bold Italic"],ue=[8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72];function j(t,e,i={}){const c=n("input",{class:"dlg-input",spellcheck:!1,"aria-label":s(e),...i}),d=n("select",{class:"dlg-list",size:6,"aria-label":s("{name} list",{name:s(e)})});return{node:n("div",{class:"fc-combo"},n("label",{class:"fc-combo-head"},n("span",{textContent:s(t)}),c),d),input:c,list:d}}const G=(t,e,i=c=>c)=>{for(const c of e)t.append(n("option",{value:c,textContent:i(c)}))},P=t=>{const e=t.options[t.selectedIndex];if(!e)return;const i=e.offsetTop-t.options[0].offsetTop+e.offsetHeight;t.scrollTop=i>t.clientHeight?i-t.clientHeight+e.offsetHeight:0},J=(t,e)=>t&&e?"Bold Italic":t?"Bold":e?"Italic":"Regular",O=t=>F("fontstyle",t);function xe(t,e,i,c,d){z();const r=o=>i[o]!==void 0?i[o]:t[o],p=e.fontName,m=[...de];m.includes(t.fontName)||m.unshift(t.fontName);const g=o=>s("{name} (Body)",{name:o}),w=o=>s("{name} (Headings)",{name:o}),x=o=>o===p?g(o):o,N=[g(""),w("")].filter(Boolean),A=o=>{const v=o.trim(),k=N.find($=>v.endsWith($));return k?v.slice(0,v.length-k.length).trim():v},f=[];c&&f.push(w(c)),f.push(g(p),...m);const u=n("div",{class:"fc-preview","aria-label":s("Preview")});let S=null;const b=()=>{const o=r("vertAlign"),v=Number(r("underline")??0);u.style.font=`${r("italic")?"italic ":""}${r("bold")?"bold ":""}${Math.min(r("fontSize"),36)}px "${r("fontName")}", sans-serif`,u.style.color=r("color")??"#000000",u.style.textDecoration=[v?"underline":"",r("strike")?"line-through":""].filter(Boolean).join(" "),u.style.textDecorationStyle=v===2||v===4?"double":"solid",u.replaceChildren(o?n(o==="superscript"?"sup":"sub",{textContent:r("fontName")}):document.createTextNode(r("fontName"))),S.checked=["fontName","fontSize","bold","italic","strike","color"].every(k=>(r(k)??null)===(e[k]??null))&&v===Number(e.underline??0)&&!o},a=j("Font:","Font");G(a.list,f),a.input.value=x(t.fontName),a.list.value=x(t.fontName),a.list.addEventListener("change",()=>{a.input.value=a.list.value,i.fontName=A(a.list.value),b()}),a.input.addEventListener("input",()=>{const o=A(a.input.value);if(o==="")return;i.fontName=o;const v=a.input.value.trim().toLowerCase(),k=f.find($=>$.toLowerCase().startsWith(v));k?(a.list.value=k,P(a.list)):a.list.selectedIndex=-1,b()}),a.input.addEventListener("change",()=>{a.input.value=x(A(a.input.value)||r("fontName"))});const h=j("Font style:","Font style");G(h.list,Q,O);const I=o=>{h.input.value=O(o),h.list.value=o};I(J(t.bold,t.italic));const M=o=>{i.bold=o.includes("Bold"),i.italic=o.includes("Italic"),b()};h.list.addEventListener("change",()=>{h.input.value=O(h.list.value),M(h.list.value)}),h.input.addEventListener("input",()=>{const o=h.input.value.trim().toLowerCase(),v=Q.find(k=>O(k).toLowerCase()===o);v&&(h.list.value=v,M(v))}),h.input.addEventListener("change",()=>I(J(r("bold"),r("italic"))));const l=j("Size:","Size",{type:"number",min:1,max:409,step:"any"});G(l.list,ue.map(String));const y=o=>{l.input.value=String(o),l.list.value=String(o)};y(t.fontSize),l.list.addEventListener("change",()=>{l.input.value=l.list.value,i.fontSize=Number(l.list.value),b()}),l.input.addEventListener("input",()=>{const o=Number(l.input.value);o>0&&(i.fontSize=o,l.list.value=String(o),b())});const B=D([[s("None"),"0"],[F("underline","Single"),"1"],[F("underline","Double"),"2"],[F("underline","Single Accounting"),"3"],[F("underline","Double Accounting"),"4"]],String(t.underline),o=>{i.underline=Number(o),b()},"Underline"),T=(o,v,k)=>{const $=n("input",{type:"checkbox",checked:v,"aria-label":s(o),on:{change:()=>{k($.checked),b()}}});return{i:$,row:n("label",{class:"dlg-row dlg-check"},$,s(o))}},L=T("Strikethrough",t.strike,o=>{i.strike=o}),R=T("Superscript",t.vertAlign==="superscript",o=>{i.vertAlign=o?"superscript":null,o&&(V.i.checked=!1)}),V=T("Subscript",t.vertAlign==="subscript",o=>{i.vertAlign=o?"subscript":null,o&&(R.i.checked=!1)}),U=H(t.color,"#000000",(o,v)=>{i.color=o,(i.themeRefs??={}).color=v,b()},{label:"Font color",theme:d});S=n("input",{type:"checkbox","aria-label":s("Normal font"),on:{change:()=>{if(!S.checked){b();return}Object.assign(i,{fontName:e.fontName,fontSize:e.fontSize,bold:e.bold,italic:e.italic,strike:e.strike,underline:e.underline??0,color:e.color??null,vertAlign:null}),a.input.value=x(e.fontName),a.list.value=x(e.fontName),y(e.fontSize),I(J(e.bold,e.italic)),B.value=String(e.underline??0),L.i.checked=e.strike,R.i.checked=!1,V.i.checked=!1,i.themeRefs&&delete i.themeRefs.color,U.setValue(e.color??null),P(a.list),P(l.list),b()}}});const W=n("div",{class:"fc-font fc-bleed"},n("div",{class:"fc-font-top"},a.node,h.node,l.node,n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Underline:")}),B),n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Color:")}),U),n("div",{class:"fc-font-cell fc-font-normal"},n("label",{class:"dlg-row dlg-check"},S,s("Normal font")))),n("div",{class:"fc-font-low"},n("div",{},n("div",{class:"dlg-label",textContent:s("Effects:")}),L.row,R.row,V.row),n("div",{},n("div",{class:"dlg-label",textContent:s("Preview")}),u)));return W.onShow=()=>[a.list,h.list,l.list].forEach(P),b(),W}function ee(t){const e=document.createElement("canvas");if(e.width=32,e.height=20,t){const i=e.getContext("2d");i.fillStyle=_(i,{type:t,fg:"#000000"},1)??"#FFFFFF",i.fillRect(0,0,32,20)}return e}function fe(t,e){const i=n("span",{class:"fc-pat-chip"}),c=le("Pattern style",i),d=()=>i.replaceChildren(...t?[ee(t)]:[]);return d(),c.setValue=r=>{t=r,d()},ie(c,"Pattern style list",r=>{const p=n("div",{class:"fc-pat-grid"});for(const[m,g]of te)p.append(n("button",{type:"button",title:F("pattern",m),"aria-label":F("pattern",m),"aria-pressed":String(g===t),on:{click:()=>{t=g,d(),r(),e(g)}}},ee(g)));return p}),c}function ye(t,e,i,c){z();let d=t.pattern?.type??"",r=t.pattern?.fg??"#000000",p=t.themeRefs?.patternFg;const m=n("div",{class:"fc-sample","aria-label":s("Sample")}),g=()=>{const f=e.fill!==void 0?e.fill:t.fill,u=e.gradient!==void 0?e.gradient:t.gradient,S=e.pattern!==void 0?e.pattern:t.pattern;if(m.style.backgroundColor=f??(u||S?"#FFFFFF":"transparent"),m.style.backgroundImage="none",u)m.style.backgroundImage=ne(u);else if(S){const b=document.createElement("canvas");b.width=16,b.height=16;const a=b.getContext("2d");a.fillStyle=_(a,S,1)??"#FFFFFF",a.fillRect(0,0,16,16),m.style.backgroundImage=`url(${b.toDataURL()})`}},w=()=>{e.pattern=d?{type:d,fg:r}:null,d&&p?(e.themeRefs??={}).patternFg=p:e.themeRefs&&delete e.themeRefs.patternFg},x=fe(d,f=>{d=f,w(),f&&(e.gradient=null),f&&!t.fill&&!e.fill&&(e.fill="#FFFFFF"),g()}),N=H(t.fill??null,"#FFFFFF",(f,u)=>{(e.themeRefs??={}).fill=u,f===null?(e.fill=null,e.gradient=null,d="",w(),x.setValue("")):(e.fill=f,e.gradient=null),g()},{none:"No Color",label:"Background color",named:!0,theme:c}),A=n("button",{type:"button",class:"dlg-btn",textContent:s("Fill Effects…"),on:{click:()=>i(e.gradient??t.gradient,f=>{e.gradient=f,e.fill=f.stops[0].color,e.themeRefs&&delete e.themeRefs.fill,d="",w(),x.setValue(""),N.setValue(null),g()})}});return g(),n("div",{class:"fc-fill fc-bleed"},n("div",{class:"fc-fill-left"},n("div",{class:"dlg-label",textContent:s("Background color:")}),N,A),n("div",{class:"fc-fill-right"},n("div",{class:"dlg-label",textContent:s("Pattern color:")}),H(t.pattern?.fg??null,"#000000",(f,u)=>{p=u,r=f??"#000000",d&&w(),g()},{label:"Pattern color",named:!0,theme:c}),n("div",{class:"dlg-label",textContent:s("Pattern style:")}),x),n("div",{class:"fc-fill-low"},n("div",{class:"dlg-label",textContent:s("Sample")}),m))}function ke(t,e){return z(),n("div",{class:"fc-protect"},n("p",{class:"fc-hint",textContent:s("To lock cells or hide formulas, protect the worksheet. On the Review tab, click Protect Sheet.")}),E(F("protect","Locked"),t.unlocked!==!0,i=>{e.unlocked=i?void 0:!0}),E(F("protect","Hidden"),t.hiddenFormula===!0,i=>{e.hiddenFormula=i?!0:void 0}),E("Allow editing in the cell",t.ext?.noEdit!==!0,i=>{e.ext={noEdit:i?null:!0}}))}export{he as alignmentTab,ye as fillTab,xe as fontTab,ke as protectionTab};
@@ -1,4 +1,4 @@
1
- import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numfmt.js";import{paletteColors as Q}from"../ui/menu-base.js";import{t as l,tc as F}from"../i18n/index.js";import{formatCodeProblem as $e}from"./format-code.js";function ee(n,s){I();const{theme:f,standard:p}=Q(),r=[],t=h=>{for(const c of r)c.setAttribute("aria-pressed",String(c.dataset.color===h))},m=h=>{const c=o("div",{class:"palette"});for(const u of h){const C=o("button",{type:"button",title:u,"aria-label":u,"aria-pressed":"false",class:"fc-swatch",on:{click:()=>{t(u),s(u)}}});C.style.background=u,C.dataset.color=u,r.push(C),c.append(C)}return c},y=o("input",{type:"color",class:"dlg-color",value:(n??"#FFFFFF").toLowerCase(),"aria-label":l("More colors"),on:{input:()=>{const h=y.value.toUpperCase();t(h),s(h)}}}),v=o("div",{},o("div",{class:"palette-label",textContent:l("Theme Colors")}),m(f),o("div",{class:"palette-label",textContent:l("Standard Colors")}),m(p),o("label",{class:"dlg-row"},`${l("More Colors:")} `,y));return t(n?n.toUpperCase():null),v.mark=h=>t(h?h.toUpperCase():null),v}function O(n){const s=document.createElement("template");return s.innerHTML=n.trim(),s.content.firstChild}const z=()=>O('<svg class="fc-chev" width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 1l3.5 3.5L8 1"/></svg>');function te(n,s,f){let p=null;const r=()=>{p?.remove(),p=null,document.removeEventListener("pointerdown",t,!0)},t=m=>{p&&!p.contains(m.target)&&!n.contains(m.target)&&r()};n.addEventListener("click",()=>{if(p){r();return}p=o("div",{class:"fc-pop",role:"dialog","aria-label":l(s)},f(r)),n.closest("dialog").append(p);const m=n.getBoundingClientRect();p.style.left=`${Math.max(8,Math.min(m.left,window.innerWidth-p.offsetWidth-8))}px`,p.style.top=`${Math.max(8,Math.min(m.bottom+2,window.innerHeight-p.offsetHeight-8))}px`,document.addEventListener("pointerdown",t,!0)})}function ne(n,...s){return I(),o("button",{type:"button",class:"dlg-btn fc-popbtn","aria-label":l(n),title:l(n)},...s,z())}function oe(n,s,f,{none:p="Automatic",label:r="Color",named:t=!1}={}){const m=o("span",{class:"fc-chip"}),y=o("span",{class:"fc-chip-text",textContent:l(p??"")}),v=()=>{const u=t&&n==null;m.hidden=u,y.hidden=!u,m.style.background=n??s},h=ne(r,m,y),c=u=>{n=u,v(),f(u)};return h.setValue=u=>{n=u,v()},v(),te(h,l("{name} palette",{name:l(r)}),u=>o("div",{},p===null?null:o("button",{type:"button",class:"dlg-btn",textContent:l(p),on:{click:()=>{c(null),u()}}}),ee(n,C=>{c(C),u()}))),h}function le({value:n,min:s,max:f,label:p,onInput:r}){I();const t=o("input",{class:"dlg-input fc-num",type:"number",min:s,max:f,value:n,"aria-label":l(p),on:{input:()=>r(Number(t.value))}}),m=c=>{t.disabled||(t.value=String(Math.max(s,Math.min(f,(Number(t.value)||0)+c))),t.dispatchEvent(new Event("input",{bubbles:!0})))},y=o("button",{type:"button","aria-label":l("Increase {name}",{name:l(p)}),on:{click:()=>m(1)}},O('<svg width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5l3.5-3.5L8 5"/></svg>')),v=o("button",{type:"button","aria-label":l("Decrease {name}",{name:l(p)}),on:{click:()=>m(-1)}},z());return{node:o("span",{class:"fc-numfield"},t,o("span",{class:"fc-stepper"},y,v)),input:t,set:c=>{t.value=String(c)},setDisabled:c=>{t.disabled=c,y.disabled=c,v.disabled=c}}}const B=n=>n>0?`.${"0".repeat(n)}`:"",U=[["-1,234.10",n=>n],["1,234.10 (red)",n=>`${n};[Red]${n}`],["(1,234.10)",n=>`${n}_);(${n})`],["(1,234.10) (red)",n=>`${n}_);[Red](${n})`]],ie=[["None",""],["$","$"],["€","€"],["£","£"],["¥","¥"],["zł",'"zł"'],["CHF",'"CHF"'],["kr",'"kr"']],W=["m/d/yyyy","dddd, mmmm d, yyyy","m/d","m/d/yy","mm/dd/yy","d-mmm","d-mmm-yy","dd-mmm-yy","mmm-yy","mmmm-yy","mmmm d, yyyy","m/d/yy h:mm AM/PM","m/d/yy h:mm","mmmmm","mmmmm-yy","d-mmm-yyyy","yyyy-mm-dd","dd.mm.yyyy"],Y=["h:mm:ss AM/PM","h:mm AM/PM","h:mm:ss","h:mm","m/d/yy h:mm AM/PM","m/d/yy h:mm","mm:ss","mm:ss.0","[h]:mm:ss"],ae=[["English (United States)",""],["English (United Kingdom)","[$-809]"],["Polish","[$-415]"],["German","[$-407]"],["French","[$-40C]"],["Spanish","[$-C0A]"],["Italian","[$-410]"],["Japanese","[$-411]"],["Chinese (Simplified)","[$-804]"],["Korean","[$-412]"],["Arabic","[$-401]"],["Hebrew","[$-40D]"]],G=[["Up to one digit (1/4)","# ?/?"],["Up to two digits (21/25)","# ??/??"],["Up to three digits (312/943)","# ???/???"],["As halves (1/2)","# ?/2"],["As quarters (2/4)","# ?/4"],["As eighths (4/8)","# ?/8"],["As sixteenths (8/16)","# ??/16"],["As tenths (3/10)","# ?/10"],["As hundredths (30/100)","# ??/100"]],H=[["Zip Code","00000"],["Zip Code + 4","00000-0000"],["Phone Number","[<=9999999]###-####;(###) ###-####"],["Social Security Number","000-00-0000"]],se=["General","0","0.00","#,##0","#,##0.00","#,##0_);(#,##0)","#,##0_);[Red](#,##0)","#,##0.00_);(#,##0.00)","#,##0.00_);[Red](#,##0.00)","$#,##0_);($#,##0)","$#,##0_);[Red]($#,##0)","$#,##0.00_);($#,##0.00)","$#,##0.00_);[Red]($#,##0.00)","0%","0.00%","0.00E+00","##0.0E+0","# ?/?","# ??/??","m/d/yy","d-mmm-yy","d-mmm","mmm-yy","h:mm AM/PM","h:mm:ss AM/PM","h:mm","h:mm:ss","m/d/yy h:mm","mm:ss","mm:ss.0","@","[h]:mm:ss",'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)','_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)','_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)','_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'],re=["General","Number","Currency","Accounting","Date","Time","Percentage","Fraction","Scientific","Text","Special","Custom"],ce=(n,s)=>{const f=n?`${n}* `:"* ",p=`#,##0${B(s)}`;return`_(${f}${p}_);_(${f}(${p});_(${f}"-"${s>0?"?".repeat(s):""}_);_(@_)`};function de(n){const s=n.replace(/"[^"]*"|\\.|\[[^\]]*\]|_.|\*./g,"");if(n==="General")return{category:"General"};if(n==="@")return{category:"Text"};if(H.some(([,m])=>m===n))return{category:"Special"};if(G.some(([,m])=>m===n))return{category:"Fraction"};if(/^_\(/.test(n)&&n.split(";").length===4&&n.includes("*"))return{category:"Accounting"};if(/%/.test(s))return{category:"Percentage",decimals:/\.(0+)/.exec(s)?.[1].length??0};if(/E[+-]/i.test(s))return{category:"Scientific",decimals:/\.(0+)/.exec(s)?.[1].length??0};const f=n.replace(/^\[\$-[0-9A-Fa-f]+\]/,"");if(W.includes(f))return{category:"Date",type:f,locale:n.slice(0,n.length-f.length)};if(Y.includes(f))return{category:"Time",type:f,locale:n.slice(0,n.length-f.length)};if(j(n).isDate)return{category:"Custom"};const r=n.split(";")[0],t=/^(\$|€|£|¥|"[^"]+")?(#,##)?0(\.0+)?(_\))?$/.exec(r);if(t){const m=t[3]?t[3].length-1:0,y=n.includes(";")?n.includes("[Red](")?3:n.includes(";(")?2:n.includes(";[Red]")?1:-1:0;if(y>=0)return t[1]?{category:"Currency",symbol:t[1],decimals:m,negative:y}:{category:"Number",decimals:m,thousands:!!t[2],negative:y}}return{category:"Custom"}}function ve(n,s,f,p=[]){const r=de(n),t={category:r.category,decimals:r.decimals??2,thousands:r.thousands??!1,negative:r.negative??0,symbol:r.symbol??"$",type:r.type,locale:r.locale??"",code:n};I();const m=o("output",{class:"fmt-preview","aria-label":l("Sample")}),y=o("p",{class:"dlg-note"}),v=o("div",{}),h=o("select",{class:"dlg-list",size:12,"aria-label":l("Category")});for(const d of re)h.append(o("option",{value:d,textContent:F("numfmt",d)}));h.value=t.category;const c=d=>{t.code=d,m.textContent=s(d),f(d)},u=d=>{const g=le({value:t.decimals,min:0,max:30,label:"Decimal places",onInput:x=>{t.decimals=Math.max(0,Math.min(30,x||0)),d()}});return o("label",{class:"dlg-row"},`${l("Decimal places:")} `,g.node)},C=(d,g,x,P,i=7)=>{const e=o("select",{class:"dlg-list",size:i,"aria-label":l(x),on:{change:()=>P(e.value)}});for(const[a,b]of d)e.append(o("option",{value:b,textContent:a}));return e.value=g,e},M=(d,g,x,P)=>{const i=o("select",{class:"dlg-input","aria-label":l(x),on:{change:()=>P(i.value)}});for(const[e,a]of d)i.append(o("option",{value:a,textContent:e}));return i.value=g,i},_=d=>d.map(([g,x])=>[l(g),x]),E=d=>C(U.map(([g],x)=>[l(g),String(x)]),String(t.negative),"Negative numbers",g=>{t.negative=Number(g),c(d())},4),L=()=>{const d=t.category,g=[];let x="";const P=ie.map(([i,e])=>[i==="None"?l("None"):i,e]);if(d==="General")x=l("General format cells have no specific number format."),c("General");else if(d==="Number"){const i=()=>U[t.negative][1](`${t.thousands?"#,##0":"0"}${B(t.decimals)}`),e=o("input",{type:"checkbox",checked:t.thousands,on:{change:()=>{t.thousands=e.checked,c(i())}}});g.push(u(()=>c(i())),o("label",{class:"dlg-row"},e,` ${l("Use 1000 Separator (,)")}`),o("div",{class:"dlg-label",textContent:l("Negative numbers:")}),E(i)),x=l("Number is used for general display of numbers. Currency and Accounting offer specialized formatting for monetary value."),c(i())}else if(d==="Currency"){const i=()=>U[t.negative][1](`${t.symbol}#,##0${B(t.decimals)}`);g.push(u(()=>c(i())),o("label",{class:"dlg-row"},`${l("Symbol:")} `,M(P,t.symbol,"Symbol",e=>{t.symbol=e,c(i())})),o("div",{class:"dlg-label",textContent:l("Negative numbers:")}),E(i)),x=l("Currency formats are used for general monetary values. Use Accounting formats to align decimal points in a column."),c(i())}else if(d==="Accounting"){const i=()=>ce(t.symbol,t.decimals);g.push(u(()=>c(i())),o("label",{class:"dlg-row"},`${l("Symbol:")} `,M(P,t.symbol,"Symbol",e=>{t.symbol=e,c(i())}))),x=l("Accounting formats line up the currency symbols and decimal points in a column."),r.category!=="Accounting"||t.code!==n?c(i()):c(n)}else if(d==="Date"||d==="Time"){const i=d==="Date"?W:Y;i.includes(t.type)||([t.type]=i);const e=()=>`${t.locale}${t.type}`,a=d==="Date"?45000.75:.75;g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(i.map(b=>[j(b).number(a),b]),t.type,"Type",b=>{t.type=b,c(e())}),o("label",{class:"dlg-row"},`${l("Locale:")} `,M(_(ae),t.locale,"Locale",b=>{t.locale=b,c(e())}))),x=d==="Date"?l("Date formats display date and time serial numbers as date values."):l("Time formats display date and time serial numbers as time values."),c(e())}else if(d==="Percentage"||d==="Scientific"){const i=()=>d==="Percentage"?`0${B(t.decimals)}%`:`0${B(t.decimals)}E+00`;g.push(u(()=>c(i()))),x=d==="Percentage"?l("Percentage formats multiply the cell value by 100 and display the result with a percent symbol."):"",c(i())}else if(d==="Fraction"){const i=G.some(([,e])=>e===t.code)?t.code:G[0][1];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(_(G),i,"Type",c)),c(i)}else if(d==="Text")x=l("Text format cells are treated as text even when a number is in the cell. The cell is displayed exactly as entered."),c("@");else if(d==="Special"){const i=H.some(([,e])=>e===t.code)?t.code:H[0][1];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(_(H),i,"Type",c,4)),x=l("Special formats are useful for tracking list and database values."),c(i)}else{const i=o("input",{class:"dlg-input",value:t.code,spellcheck:!1,"aria-label":l("Format code"),on:{input:()=>c(i.value)}}),e=[...new Set([...se,...p])];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),i,C(e.map(a=>[a,a]),t.code,"Existing formats",a=>{i.value=a,c(a)},8)),x=l("Type the number format code, using one of the existing codes as a starting point."),c(t.code)}v.replaceChildren(...g),y.textContent=x};return h.addEventListener("change",()=>{t.category=h.value,t.category==="Custom"&&(t.code=t.code||"General"),L()}),L(),o("div",{class:"fc-number"},o("div",{},o("div",{class:"dlg-label",textContent:l("Category:")}),h),o("div",{class:"fc-number-side"},o("div",{class:"dlg-label",textContent:l("Sample")}),m,v,y))}const V="fc-styles";function I(){document.getElementById(V)||document.head.append(o("style",{id:V,textContent:`
1
+ import{el as l}from"../ui/dialogs.js";import{culture as W,cultureOf as le,currencyAmountCode as ie,currencySymbolCode as se}from"../core/culture.js";import{parseLocaleBracket as ae}from"../calcx/culture/format-locale.js";import{getFormatter as Y,SYSTEM_LONG_DATE as V}from"../core/numfmt.js";import{paletteColors as re}from"../ui/menu-base.js";import{t as s,tc as O}from"../i18n/index.js";import{formatCodeProblem as Pe}from"./format-code.js";function ce(t,i,m){F();const{theme:d,standard:r,refs:e}=re(m),p=[],h=c=>{for(const u of p)u.setAttribute("aria-pressed",String(u.dataset.color===c))},x=(c,u)=>{const D=l("div",{class:"palette"});for(const[T,_]of c.entries()){const L=l("button",{type:"button",title:_,"aria-label":_,"aria-pressed":"false",class:"fc-swatch",on:{click:()=>{h(_),i(_,u?.[T])}}});L.style.background=_,L.dataset.color=_,p.push(L),D.append(L)}return D},b=l("input",{type:"color",class:"dlg-color",value:(t??"#FFFFFF").toLowerCase(),"aria-label":s("More colors"),on:{input:()=>{const c=b.value.toUpperCase();h(c),i(c)}}}),y=l("div",{},l("div",{class:"palette-label",textContent:s("Theme Colors")}),x(d,e),l("div",{class:"palette-label",textContent:s("Standard Colors")}),x(r),l("label",{class:"dlg-row"},`${s("More Colors:")} `,b));return h(t?t.toUpperCase():null),y.mark=c=>h(c?c.toUpperCase():null),y}function G(t){const i=document.createElement("template");return i.innerHTML=t.trim(),i.content.firstChild}const K=()=>G('<svg class="fc-chev" width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 1l3.5 3.5L8 1"/></svg>');function de(t,i,m){let d=null;const r=()=>{d?.remove(),d=null,document.removeEventListener("pointerdown",e,!0)},e=p=>{d&&!d.contains(p.target)&&!t.contains(p.target)&&r()};t.addEventListener("click",()=>{if(d){r();return}d=l("div",{class:"fc-pop",role:"dialog","aria-label":s(i)},m(r)),t.closest("dialog").append(d);const p=t.getBoundingClientRect();d.style.left=`${Math.max(8,Math.min(p.left,window.innerWidth-d.offsetWidth-8))}px`,d.style.top=`${Math.max(8,Math.min(p.bottom+2,window.innerHeight-d.offsetHeight-8))}px`,document.addEventListener("pointerdown",e,!0)})}function pe(t,...i){return F(),l("button",{type:"button",class:"dlg-btn fc-popbtn","aria-label":s(t),title:s(t)},...i,K())}function me(t,i,m,{none:d="Automatic",label:r="Color",named:e=!1,theme:p}={}){const h=l("span",{class:"fc-chip"}),x=l("span",{class:"fc-chip-text",textContent:s(d??"")}),b=()=>{const u=e&&t==null;h.hidden=u,x.hidden=!u,h.style.background=t??i},y=pe(r,h,x),c=(u,D)=>{t=u,b(),m(u,D)};return y.setValue=u=>{t=u,b()},b(),de(y,s("{name} palette",{name:s(r)}),u=>l("div",{},d===null?null:l("button",{type:"button",class:"dlg-btn",textContent:s(d),on:{click:()=>{c(null),u()}}}),ce(t,(D,T)=>{c(D,T),u()},p))),y}function fe({value:t,min:i,max:m,label:d,onInput:r}){F();const e=l("input",{class:"dlg-input fc-num",type:"number",min:i,max:m,value:t,"aria-label":s(d),on:{input:()=>r(Number(e.value))}}),p=y=>{e.disabled||(e.value=String(Math.max(i,Math.min(m,(Number(e.value)||0)+y))),e.dispatchEvent(new Event("input",{bubbles:!0})))},h=l("button",{type:"button","aria-label":s("Increase {name}",{name:s(d)}),on:{click:()=>p(1)}},G('<svg width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5l3.5-3.5L8 5"/></svg>')),x=l("button",{type:"button","aria-label":s("Decrease {name}",{name:s(d)}),on:{click:()=>p(-1)}},K());return{node:l("span",{class:"fc-numfield"},e,l("span",{class:"fc-stepper"},h,x)),input:e,set:y=>{e.value=String(y)},setDisabled:y=>{e.disabled=y,h.disabled=y,x.disabled=y}}}const R=t=>t>0?`.${"0".repeat(t)}`:"",H=[t=>t,t=>`${t};[Red]${t}`,t=>`${t}_);(${t})`,t=>`${t}_);[Red](${t})`],X=[["None",""],["$","$"],["€","€"],["£","£"],["¥","¥"],["zł",'"zł"'],["CHF",'"CHF"'],["kr",'"kr"']],z=new Map;function Z(t){if(z.has(t))return z.get(t);const i=t&&ae(t.slice(1,-1))?.tag,m=i?le(i):W(),d=(x,b,y)=>{const c={day:x,month:b,year:y};return m.order.map(u=>c[u]).filter(Boolean).join(m.dateSep)},r=m.shortDate.includes("dd")?"dd":"d",e=m.shortDate.includes("mm")?"mm":"m",p=d(r,e,"yy"),h=[...new Set([i?m.shortDate:"m/d/yyyy",i?m.longDate:V,d(r,e),p,d("dd","mm","yy"),"d-mmm","d-mmm-yy","dd-mmm-yy","mmm-yy","mmmm-yy",m.longDateWithoutWeekday,`${p} h:mm AM/PM`,`${p} h:mm`,"mmmmm","mmmmm-yy","d-mmm-yyyy","yyyy-mm-dd","dd.mm.yyyy"])];return i&&z.set(t,h),h}const q=["h:mm:ss AM/PM","h:mm AM/PM","h:mm:ss","h:mm","m/d/yy h:mm AM/PM","m/d/yy h:mm","mm:ss","mm:ss.0","[h]:mm:ss"],ue=[["Default",""],["English (United States)","[$-409]"],["English (United Kingdom)","[$-809]"],["Polish","[$-415]"],["German","[$-407]"],["French","[$-40C]"],["Spanish","[$-C0A]"],["Italian","[$-410]"],["Japanese","[$-411]"],["Chinese (Simplified)","[$-804]"],["Korean","[$-412]"],["Arabic","[$-401]"],["Hebrew","[$-40D]"]],j=[["Up to one digit (1/4)","# ?/?"],["Up to two digits (21/25)","# ??/??"],["Up to three digits (312/943)","# ???/???"],["As halves (1/2)","# ?/2"],["As quarters (2/4)","# ?/4"],["As eighths (4/8)","# ?/8"],["As sixteenths (8/16)","# ??/16"],["As tenths (3/10)","# ?/10"],["As hundredths (30/100)","# ??/100"]],U=[["Zip Code","00000"],["Zip Code + 4","00000-0000"],["Phone Number","[<=9999999]###-####;(###) ###-####"],["Social Security Number","000-00-0000"]],ge=["General","0","0.00","#,##0","#,##0.00","#,##0_);(#,##0)","#,##0_);[Red](#,##0)","#,##0.00_);(#,##0.00)","#,##0.00_);[Red](#,##0.00)","$#,##0_);($#,##0)","$#,##0_);[Red]($#,##0)","$#,##0.00_);($#,##0.00)","$#,##0.00_);[Red]($#,##0.00)","0%","0.00%","0.00E+00","##0.0E+0","# ?/?","# ??/??","m/d/yy","d-mmm-yy","d-mmm","mmm-yy","h:mm AM/PM","h:mm:ss AM/PM","h:mm","h:mm:ss","m/d/yy h:mm","mm:ss","mm:ss.0","@","[h]:mm:ss",'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)','_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)','_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)','_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'],he=["General","Number","Currency","Accounting","Date","Time","Percentage","Fraction","Scientific","Text","Special","Custom"],xe=(t,i)=>{const m=t?`${t}* `:"* ",d=`#,##0${R(i)}`;return`_(${m}${d}_);_(${m}(${d});_(${m}"-"${i>0?"?".repeat(i):""}_);_(@_)`};function be(t){if(t==="General")return{category:"General"};if(t==="@")return{category:"Text"};if(U.some(([,p])=>p===t))return{category:"Special"};if(j.some(([,p])=>p===t))return{category:"Fraction"};if(/^_\(/.test(t)&&t.split(";").length===4&&t.includes("*"))return{category:"Accounting"};if(/^0(?:\.0+)?%$/.test(t))return{category:"Percentage",decimals:/\.(0+)/.exec(t)?.[1].length??0};if(/^[#0]+(?:\.0+)?E[+-]0+$/i.test(t))return{category:"Scientific",decimals:/\.(0+)/.exec(t)?.[1].length??0};if(t===V)return{category:"Date",type:t,locale:""};const i=t.replace(/^\[\$-[0-9A-Fa-f]+\]/,""),m=t.slice(0,t.length-i.length);if(/[dmy]/i.test(i)&&(Z(m).includes(i)||["dddd, mmmm d, yyyy","mmmm d, yyyy","m/d","m/d/yy","mm/dd/yy"].includes(i)))return{category:"Date",type:i,locale:m};if(q.includes(i))return{category:"Time",type:i,locale:t.slice(0,t.length-i.length)};const d=t.replace(/\\([()])/g,"$1"),r=d.split(";")[0].replace(/_\)$/,""),e=/^(\p{Sc}|"[^"]+")?(#,##)?0(\.0+)?(?: (\p{Sc}|"[^"]+"))?$/u.exec(r);if(e){const p=e[3]?e[3].length-1:0,h=H.findIndex(x=>x(r)===d);if(h>=0){const x=e[1]??e[4];if(!x)return{category:"Number",decimals:p,thousands:!!e[2],negative:h};const b=x.replace(/"/g,"");if(/^\p{Sc}$/u.test(b)||X.some(([y])=>y===b)||b===W().currency.symbol)return{category:"Currency",symbol:x,decimals:p,negative:h,suffix:!!e[4]}}}return{category:"Custom"}}function Ae(t,i,m,d=[]){const r=be(t),e={category:r.category,decimals:r.decimals??2,thousands:r.thousands??!1,negative:r.negative??0,symbol:r.symbol,type:r.type,locale:r.locale??"",code:t};F();const p=l("output",{class:"fmt-preview","aria-label":s("Sample")}),h=l("p",{class:"dlg-note"}),x=l("div",{}),b=l("select",{class:"dlg-list",size:12,"aria-label":s("Category")});for(const a of he)b.append(l("option",{value:a,textContent:O("numfmt",a)}));b.value=e.category;let y;const c=a=>{y?.(),e.code=a,p.textContent=i(a),m(a)},u=a=>{const w=fe({value:e.decimals,min:0,max:30,label:"Decimal places",onInput:k=>{e.decimals=Math.max(0,Math.min(30,k||0)),a()}});return l("label",{class:"dlg-row"},`${s("Decimal places:")} `,w.node)},D=(a,w,k,$,C=7)=>{const n=l("select",{class:"dlg-list",size:C,"aria-label":s(k),on:{change:()=>$(n.value)}});for(const[o,f]of a)n.append(l("option",{value:f,textContent:o}));return n.value=w,n},T=(a,w,k,$)=>{const C=l("select",{class:"dlg-input","aria-label":s(k),on:{change:()=>$(C.value)}});for(const[n,o]of a)C.append(l("option",{value:o,textContent:n}));return C.value=w,C},_=a=>a.map(([w,k])=>[s(w),k]),L=a=>{const w=()=>H.map(($,C)=>{const n=Y(a(C)),o=n.number(-1234.1).trim();return[n.color(-1234.1)?s("{sample} (red)",{sample:o}):o,String(C)]}),k=D(w(),String(e.negative),"Negative numbers",$=>{e.negative=Number($),c(a())},4);return y=()=>w().forEach(([$],C)=>{k.options[C].textContent=$}),k},B=()=>{y=null;const a=e.category,w=[];let k="";const $=a==="Accounting"?"$":se(),C=()=>e.symbol??$,n=X.map(([o,f])=>[o==="None"?s("None"):o,f]);if(C()&&!n.some(([,o])=>o===C())&&n.push([C().replace(/"/g,""),C()]),a==="General")k=s("General format cells have no specific number format."),c("General");else if(a==="Number"){const o=(v=e.negative)=>H[v](`${e.thousands?"#,##0":"0"}${R(e.decimals)}`),f=l("input",{type:"checkbox",checked:e.thousands,on:{change:()=>{e.thousands=f.checked,c(o())}}});w.push(u(()=>c(o())),l("label",{class:"dlg-row"},f,` ${s("Use 1000 Separator (,)")}`),l("div",{class:"dlg-label",textContent:s("Negative numbers:")}),L(o)),k=s("Number is used for general display of numbers. Currency and Accounting offer specialized formatting for monetary value."),c(o())}else if(a==="Currency"){const o=(f=e.negative)=>{const v=`#,##0${R(e.decimals)}`,g=e.symbol===r.symbol?r.suffix:void 0;return H[f](ie(v,C(),g))};w.push(u(()=>c(o())),l("label",{class:"dlg-row"},`${s("Symbol:")} `,T(n,C(),"Symbol",f=>{e.symbol=f,c(o())})),l("div",{class:"dlg-label",textContent:s("Negative numbers:")}),L(o)),k=s("Currency formats are used for general monetary values. Use Accounting formats to align decimal points in a column."),c(r.category===a&&e.code===t?t:o())}else if(a==="Accounting"){const o=()=>xe(C(),e.decimals);w.push(u(()=>c(o())),l("label",{class:"dlg-row"},`${s("Symbol:")} `,T(n,C(),"Symbol",f=>{e.symbol=f,c(o())}))),k=s("Accounting formats line up the currency symbols and decimal points in a column."),r.category!=="Accounting"||e.code!==t?c(o()):c(t)}else if(a==="Date"||a==="Time"){const o=a==="Date"?[...Z(e.locale)]:[...q];r.category===a&&r.locale===e.locale&&r.type&&!o.includes(r.type)&&o.push(r.type),o.includes(e.type)||([e.type]=o);const f=()=>`${e.locale}${e.type}`,v=a==="Date"?45000.75:.75;w.push(l("div",{class:"dlg-label",textContent:s("Type:")}),D(o.map(g=>[Y(e.locale+g).number(v),g]),e.type,"Type",g=>{e.type=g,c(f())}),l("label",{class:"dlg-row"},`${s("Locale:")} `,T(_(ue),e.locale,"Locale",g=>{e.locale=g,B()}))),k=a==="Date"?s("Date formats display date and time serial numbers as date values."):s("Time formats display date and time serial numbers as time values."),c(f())}else if(a==="Percentage"||a==="Scientific"){const o=()=>a==="Percentage"?`0${R(e.decimals)}%`:`0${R(e.decimals)}E+00`;w.push(u(()=>c(o()))),k=a==="Percentage"?s("Percentage formats multiply the cell value by 100 and display the result with a percent symbol."):"",c(o())}else if(a==="Fraction"){const o=j.some(([,f])=>f===e.code)?e.code:j[0][1];w.push(l("div",{class:"dlg-label",textContent:s("Type:")}),D(_(j),o,"Type",c)),c(o)}else if(a==="Text")k=s("Text format cells are treated as text even when a number is in the cell. The cell is displayed exactly as entered."),c("@");else if(a==="Special"){const o=U.some(([,f])=>f===e.code)?e.code:U[0][1];w.push(l("div",{class:"dlg-label",textContent:s("Type:")}),D(_(U),o,"Type",c,4)),k=s("Special formats are useful for tracking list and database values."),c(o)}else{const o=l("input",{class:"dlg-input",value:e.code,spellcheck:!1,"aria-label":s("Format code"),on:{input:()=>c(o.value)}}),f=[...new Set([...ge,...d])];w.push(l("div",{class:"dlg-label",textContent:s("Type:")}),o,D(f.map(v=>[v,v]),e.code,"Existing formats",v=>{o.value=v,c(v)},8)),k=s("Type the number format code, using one of the existing codes as a starting point."),c(e.code)}x.replaceChildren(...w),h.textContent=k};return b.addEventListener("change",()=>{e.category=b.value,e.category==="Custom"&&(e.code=e.code||"General"),B()}),B(),l("div",{class:"fc-number"},l("div",{},l("div",{class:"dlg-label",textContent:s("Category:")}),b),l("div",{class:"fc-number-side"},l("div",{class:"dlg-label",textContent:s("Sample")}),p,x,h))}const J="fc-styles";function F(){document.getElementById(J)||document.head.append(l("style",{id:J,textContent:`
2
2
  .fc-dlg[open] { display: flex; flex-direction: column; height: 603px; overflow: hidden; }
3
3
  .fc-dlg .dlg-body { flex: 1; min-height: 0; display: flex; }
4
4
  .fc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
@@ -99,4 +99,4 @@ import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numf
99
99
 
100
100
  .fc-protect .fc-hint { margin: 13px 0 13px; max-width: 520px; }
101
101
  .fc-protect .dlg-check { margin-left: 2px; }
102
- `}))}const pe=["none","hair","dotted","dashDotDot","dashDot","dashed","thin","mediumDashDotDot","slantDashDot","mediumDashDot","mediumDashed","medium","thick","double"],K={none:"None",hair:"Hairline",dotted:"Dotted",dashDotDot:"Dash Dot Dot",dashDot:"Dash Dot",dashed:"Dashed",thin:"Thin",mediumDashDotDot:"Medium Dash Dot Dot",slantDashDot:"Slanted Dash Dot",mediumDashDot:"Medium Dash Dot",mediumDashed:"Medium Dashed",medium:"Medium",thick:"Thick",double:"Double"},X=n=>K[n]?F("line",K[n]):n,Z={hair:[1,1],dotted:[2,2],dashed:[4,2],dashDot:[6,2,2,2],dashDotDot:[6,2,2,2,2,2],mediumDashed:[6,2],mediumDashDot:[6,2,2,2],mediumDashDotDot:[6,2,2,2,2,2],slantDashDot:[6,2,2,2]},q={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3};function me(n){const s=window.devicePixelRatio||1,f=100,p=22,r=document.createElement("canvas");r.width=f*s,r.height=p*s,r.style.width=`${f}px`,r.style.height=`${p}px`;const t=r.getContext("2d");if(t.scale(s,s),t.strokeStyle="#000",t.fillStyle="#000",n==="none")return t.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',t.textAlign="center",t.fillText(l("None"),f/2,15),r;if(n==="double")return t.fillRect(3,9,f-6,1),t.fillRect(3,12,f-6,1),r;t.lineWidth=q[n]??1,t.setLineDash(Z[n]??[]);const m=t.lineWidth%2?11.5:11;return t.beginPath(),t.moveTo(3,m),t.lineTo(f-3,m),t.stroke(),r}const N=128,w=8,D=N-w,S=N/2,fe={t:"M1 2.5h14",h:"M1 8h14",b:"M1 13.5h14",l:"M2.5 1v14",v:"M8 1v14",r:"M13.5 1v14",up:"M2 14 14 2",down:"M2 2l12 12"},ue=n=>O(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" aria-hidden="true"><path d="M2.5 2.5h11v11h-11z" stroke-dasharray="1 2" opacity="0.6"/><path d="${fe[n]}" stroke-width="1.4"/></svg>`),ge={None:'<svg width="30" height="24" viewBox="0 0 30 24" aria-hidden="true"></svg>',Outline:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M5.75 2.75h18.5v18.5H5.75z"/></svg>',Inside:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M15 2.5v19M5.5 12h19"/></svg>'};function we(n,s,f){I();const p={t:void 0,b:void 0,l:void 0,r:void 0,h:void 0,v:void 0,up:void 0,down:void 0},r={t:n?.t??null,b:n?.b??null,l:n?.l??null,r:n?.r??null,h:null,v:null,up:n?.up?n.d:null,down:n?.down?n.d:null};let t="thin",m="#000000";const y=window.devicePixelRatio||1,v=o("canvas",{class:"fc-border-box",width:N*y,height:N*y,"aria-label":l("Border preview")});v.style.width=`${N}px`,v.style.height=`${N}px`;const h=()=>t==="none"?null:{style:t,color:m},c=()=>{const e=v.getContext("2d");e.setTransform(y,0,0,y,0,0),e.clearRect(0,0,N,N),e.fillStyle="#fff",e.fillRect(0,0,N,N),e.strokeStyle="#a0a0a0",e.lineWidth=1,e.setLineDash([]);const a=(k,A,T,R)=>{e.beginPath(),e.moveTo(k+.5,A+.5),e.lineTo(T+.5,R+.5),e.stroke()};for(const[k,A]of[[w,-1],[D,1]])for(const[T,R]of[[w,-1],[D,1]])a(k,T,k+A*5,T),a(k,T,k,T+R*5);if(s)for(const[k,A,T,R]of[[S,w,0,-5],[S,D,0,5],[w,S,-5,0],[D,S,5,0]])a(k,A,k+T,A+R);e.fillStyle="#000",e.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',e.textAlign="center",e.textBaseline="middle";const b=l("Text");if(s)for(const k of[(w+S)/2,(S+D)/2])for(const A of[(w+S)/2,(S+D)/2])e.fillText(b,A,k);else e.fillText(b,S,S);const $=(k,A,T,R,J)=>{k&&(e.strokeStyle=k.color,e.lineWidth=k.style==="double"?3:q[k.style]??1,e.setLineDash(Z[k.style]??[]),e.beginPath(),e.moveTo(A,T),e.lineTo(R,J),e.stroke())};$(r.t,w,w,D,w),$(r.b,w,D,D,D),$(r.l,w,w,w,D),$(r.r,D,w,D,D),$(r.h,w,S,D,S),$(r.v,S,w,S,D),$(r.up,w,D,D,w),$(r.down,w,w,D,D),e.setLineDash([])},u=(e,a)=>{p[e]=a,r[e]=a},C={},M=()=>{c();for(const[e,a]of Object.entries(C))a.setAttribute("aria-pressed",String(!!r[e]));f(p)},_=e=>{const a=h(),b=r[e]&&a&&r[e].style===a.style&&r[e].color===a.color;u(e,b?null:a),M()},E=(e,a)=>{const b=[["t",Math.abs(a-w)],["b",Math.abs(a-D)],["l",Math.abs(e-w)],["r",Math.abs(e-D)]];return s&&b.push(["h",Math.abs(a-S)],["v",Math.abs(e-S)]),b.sort(($,k)=>$[1]-k[1]),b[0][1]<=9?b[0][0]:Math.abs(a-e)<Math.abs(e+a-N)?"down":"up"};v.addEventListener("click",e=>{const a=v.getBoundingClientRect();_(E(e.clientX-a.left,e.clientY-a.top))});const L=(e,a,b)=>{const $=F("border",e);return o("div",{class:"fc-preset"},o("button",{type:"button","aria-label":$,title:$,disabled:!!b,on:{click:()=>{a(),M()}}},O(ge[e])),o("span",{textContent:$}))},d=(e,a,b,$,k)=>{const A=F("border",e),T=o("button",{type:"button",class:"fc-edge",title:A,"aria-label":A,"aria-pressed":"false",disabled:!!k,on:{click:()=>_(a)}},ue(a));return T.style.left=`${b}px`,T.style.top=`${$}px`,C[a]=T,T},g=o("div",{class:"fc-lines",role:"listbox","aria-label":l("Line style")}),x=pe.map(e=>{const a=o("button",{type:"button",role:"option",class:"fc-line",title:X(e),"aria-label":X(e),on:{click:()=>{t=e,P()}}},me(e));return a.dataset.style=e,a}),P=()=>{for(const e of x)e.setAttribute("aria-selected",String(e.dataset.style===t))};g.append(...x),P();const i=o("div",{class:"fc-edges"},d("Top","t",0,0),d("Horizontal","h",0,52,!s),d("Bottom","b",0,104),v,d("Diagonal Up","up",0,145),d("Left","l",40,145),d("Vertical","v",89,145,!s),d("Right","r",141,145),d("Diagonal Down","down",183,145));c();for(const[e,a]of Object.entries(C))a.setAttribute("aria-pressed",String(!!r[e]));return o("div",{class:"fc-border"},o("div",{class:"fc-border-left"},o("div",{class:"dlg-label",textContent:l("Line Style:")}),g,o("div",{class:"dlg-label",textContent:l("Line Color:")}),oe(null,"#000000",e=>{m=e??"#000000"},{label:"Line color",named:!0})),o("div",{class:"fc-border-right"},o("div",{class:"dlg-label",textContent:l("Presets:")}),o("div",{class:"fc-presets"},L("None",()=>{for(const e of Object.keys(p))u(e,null)}),L("Outline",()=>{const e=h();for(const a of["t","b","l","r"])u(a,e)}),L("Inside",()=>{const e=h();u("h",e),u("v",e)},!s)),o("hr",{class:"fc-border-rule"}),o("div",{class:"dlg-label",textContent:l("Border:")}),i),o("p",{class:"fc-hint",textContent:l("Click a line style and color, and then click a preset border pattern or individual border buttons. You can also apply borders by clicking in the preview box.")}))}function De(n,s){const{book:f,grid:p}=n;Object.values(s).some(t=>t!==void 0)&&(f.transact("borders",t=>{const{sheet:m}=t;for(const{r0:y,c0:v,r1:h,c1:c}of p.selection.ranges){const u=Math.min(h,Math.max(m.maxRow,y+1024)),C=Math.min(c,Math.max(m.maxCol,v+256));for(let M=y;M<=u;M++)for(let _=v;_<=C;_++){const E={},L=(a,b)=>{b!==void 0&&(E[a]=b)};L("t",M===y?s.t:s.h),L("b",M===u?s.b:s.h),L("l",_===v?s.l:s.v),L("r",_===C?s.r:s.v);const d=s.up,g=s.down;if(d!==void 0||g!==void 0){const a=d??g??null;d!==void 0&&(E.up=d!==null),g!==void 0&&(E.down=g!==null),E.d=a}if(Object.keys(E).length===0)continue;t.saveCell(M,_);const x=m.cellStyle(M,_)||m.style(M,_),i={...f.styles.get(x).borders??{l:null,r:null,t:null,b:null},...E};i.d&&!i.up&&!i.down&&(i.d=null);const e=!i.l&&!i.r&&!i.t&&!i.b&&!i.d;m.setStyle(M,_,f.styles.derive(x,{borders:e?null:i}))}}}),p.invalidate())}export{De as applyBorderEdges,we as borderTab,I as ensureStyles,$e as formatCodeProblem,X as lineStyleName,le as numberField,ve as numberTab,oe as paletteButton,ee as paletteGrid,ne as popButton,te as popOver,de as readFormat,O as svgNode};
102
+ `}))}const ye=["none","hair","dotted","dashDotDot","dashDot","dashed","thin","mediumDashDotDot","slantDashDot","mediumDashDot","mediumDashed","medium","thick","double"],Q={none:"None",hair:"Hairline",dotted:"Dotted",dashDotDot:"Dash Dot Dot",dashDot:"Dash Dot",dashed:"Dashed",thin:"Thin",mediumDashDotDot:"Medium Dash Dot Dot",slantDashDot:"Slanted Dash Dot",mediumDashDot:"Medium Dash Dot",mediumDashed:"Medium Dashed",medium:"Medium",thick:"Thick",double:"Double"},ee=t=>Q[t]?O("line",Q[t]):t,te={hair:[1,1],dotted:[2,2],dashed:[4,2],dashDot:[6,2,2,2],dashDotDot:[6,2,2,2,2,2],mediumDashed:[6,2],mediumDashDot:[6,2,2,2],mediumDashDotDot:[6,2,2,2,2,2],slantDashDot:[6,2,2,2]},ne={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3};function ve(t){const i=window.devicePixelRatio||1,m=100,d=22,r=document.createElement("canvas");r.width=m*i,r.height=d*i,r.style.width=`${m}px`,r.style.height=`${d}px`;const e=r.getContext("2d");if(e.scale(i,i),e.strokeStyle="#000",e.fillStyle="#000",t==="none")return e.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',e.textAlign="center",e.fillText(s("None"),m/2,15),r;if(t==="double")return e.fillRect(3,9,m-6,1),e.fillRect(3,12,m-6,1),r;e.lineWidth=ne[t]??1,e.setLineDash(te[t]??[]);const p=e.lineWidth%2?11.5:11;return e.beginPath(),e.moveTo(3,p),e.lineTo(m-3,p),e.stroke(),r}const P=128,S=8,M=P-S,A=P/2,we={t:"M1 2.5h14",h:"M1 8h14",b:"M1 13.5h14",l:"M2.5 1v14",v:"M8 1v14",r:"M13.5 1v14",up:"M2 14 14 2",down:"M2 2l12 12"},De=t=>G(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" aria-hidden="true"><path d="M2.5 2.5h11v11h-11z" stroke-dasharray="1 2" opacity="0.6"/><path d="${we[t]}" stroke-width="1.4"/></svg>`),ke={None:'<svg width="30" height="24" viewBox="0 0 30 24" aria-hidden="true"></svg>',Outline:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M5.75 2.75h18.5v18.5H5.75z"/></svg>',Inside:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M15 2.5v19M5.5 12h19"/></svg>'};function Ee(t,i,m,d){F();const r={t:void 0,b:void 0,l:void 0,r:void 0,h:void 0,v:void 0,up:void 0,down:void 0},e={t:t?.t??null,b:t?.b??null,l:t?.l??null,r:t?.r??null,h:null,v:null,up:t?.up?t.d:null,down:t?.down?t.d:null};let p="thin",h="#000000";const x=window.devicePixelRatio||1,b=l("canvas",{class:"fc-border-box",width:P*x,height:P*x,"aria-label":s("Border preview")});b.style.width=`${P}px`,b.style.height=`${P}px`;const y=()=>p==="none"?null:{style:p,color:h},c=()=>{const n=b.getContext("2d");n.setTransform(x,0,0,x,0,0),n.clearRect(0,0,P,P),n.fillStyle="#fff",n.fillRect(0,0,P,P),n.strokeStyle="#a0a0a0",n.lineWidth=1,n.setLineDash([]);const o=(g,N,E,I)=>{n.beginPath(),n.moveTo(g+.5,N+.5),n.lineTo(E+.5,I+.5),n.stroke()};for(const[g,N]of[[S,-1],[M,1]])for(const[E,I]of[[S,-1],[M,1]])o(g,E,g+N*5,E),o(g,E,g,E+I*5);if(i)for(const[g,N,E,I]of[[A,S,0,-5],[A,M,0,5],[S,A,-5,0],[M,A,5,0]])o(g,N,g+E,N+I);n.fillStyle="#000",n.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',n.textAlign="center",n.textBaseline="middle";const f=s("Text");if(i)for(const g of[(S+A)/2,(A+M)/2])for(const N of[(S+A)/2,(A+M)/2])n.fillText(f,N,g);else n.fillText(f,A,A);const v=(g,N,E,I,oe)=>{g&&(n.strokeStyle=g.color,n.lineWidth=g.style==="double"?3:ne[g.style]??1,n.setLineDash(te[g.style]??[]),n.beginPath(),n.moveTo(N,E),n.lineTo(I,oe),n.stroke())};v(e.t,S,S,M,S),v(e.b,S,M,M,M),v(e.l,S,S,S,M),v(e.r,M,S,M,M),v(e.h,S,A,M,A),v(e.v,A,S,A,M),v(e.up,S,M,M,S),v(e.down,S,S,M,M),n.setLineDash([])},u=(n,o)=>{r[n]=o,e[n]=o},D={},T=()=>{c();for(const[n,o]of Object.entries(D))o.setAttribute("aria-pressed",String(!!e[n]));m(r)},_=n=>{const o=y(),f=e[n]&&o&&e[n].style===o.style&&e[n].color===o.color;u(n,f?null:o),T()},L=(n,o)=>{const f=[["t",Math.abs(o-S)],["b",Math.abs(o-M)],["l",Math.abs(n-S)],["r",Math.abs(n-M)]];return i&&f.push(["h",Math.abs(o-A)],["v",Math.abs(n-A)]),f.sort((v,g)=>v[1]-g[1]),f[0][1]<=9?f[0][0]:Math.abs(o-n)<Math.abs(n+o-P)?"down":"up"};b.addEventListener("click",n=>{const o=b.getBoundingClientRect();_(L(n.clientX-o.left,n.clientY-o.top))});const B=(n,o,f)=>{const v=O("border",n);return l("div",{class:"fc-preset"},l("button",{type:"button","aria-label":v,title:v,disabled:!!f,on:{click:()=>{o(),T()}}},G(ke[n])),l("span",{textContent:v}))},a=(n,o,f,v,g)=>{const N=O("border",n),E=l("button",{type:"button",class:"fc-edge",title:N,"aria-label":N,"aria-pressed":"false",disabled:!!g,on:{click:()=>_(o)}},De(o));return E.style.left=`${f}px`,E.style.top=`${v}px`,D[o]=E,E},w=l("div",{class:"fc-lines",role:"listbox","aria-label":s("Line style")}),k=ye.map(n=>{const o=l("button",{type:"button",role:"option",class:"fc-line",title:ee(n),"aria-label":ee(n),on:{click:()=>{p=n,$()}}},ve(n));return o.dataset.style=n,o}),$=()=>{for(const n of k)n.setAttribute("aria-selected",String(n.dataset.style===p))};w.append(...k),$();const C=l("div",{class:"fc-edges"},a("Top","t",0,0),a("Horizontal","h",0,52,!i),a("Bottom","b",0,104),b,a("Diagonal Up","up",0,145),a("Left","l",40,145),a("Vertical","v",89,145,!i),a("Right","r",141,145),a("Diagonal Down","down",183,145));c();for(const[n,o]of Object.entries(D))o.setAttribute("aria-pressed",String(!!e[n]));return l("div",{class:"fc-border"},l("div",{class:"fc-border-left"},l("div",{class:"dlg-label",textContent:s("Line Style:")}),w,l("div",{class:"dlg-label",textContent:s("Line Color:")}),me(null,"#000000",n=>{h=n??"#000000"},{label:"Line color",named:!0,theme:d})),l("div",{class:"fc-border-right"},l("div",{class:"dlg-label",textContent:s("Presets:")}),l("div",{class:"fc-presets"},B("None",()=>{for(const n of Object.keys(r))u(n,null)}),B("Outline",()=>{const n=y();for(const o of["t","b","l","r"])u(o,n)}),B("Inside",()=>{const n=y();u("h",n),u("v",n)},!i)),l("hr",{class:"fc-border-rule"}),l("div",{class:"dlg-label",textContent:s("Border:")}),C),l("p",{class:"fc-hint",textContent:s("Click a line style and color, and then click a preset border pattern or individual border buttons. You can also apply borders by clicking in the preview box.")}))}function Le(t,i){const{book:m,grid:d}=t;Object.values(i).some(e=>e!==void 0)&&(m.transact("borders",e=>{const{sheet:p}=e;for(const{r0:h,c0:x,r1:b,c1:y}of d.selection.ranges){const c=Math.min(b,Math.max(p.maxRow,h+1024)),u=Math.min(y,Math.max(p.maxCol,x+256));for(let D=h;D<=c;D++)for(let T=x;T<=u;T++){const _={},L=(n,o)=>{o!==void 0&&(_[n]=o)};L("t",D===h?i.t:i.h),L("b",D===c?i.b:i.h),L("l",T===x?i.l:i.v),L("r",T===u?i.r:i.v);const B=i.up,a=i.down;if(B!==void 0||a!==void 0){const n=B??a??null;B!==void 0&&(_.up=B!==null),a!==void 0&&(_.down=a!==null),_.d=n}if(Object.keys(_).length===0)continue;e.saveCell(D,T);const w=p.cellStyle(D,T)||p.style(D,T),$={...m.styles.get(w).borders??{l:null,r:null,t:null,b:null},..._};$.d&&!$.up&&!$.down&&($.d=null);const C=!$.l&&!$.r&&!$.t&&!$.b&&!$.d;p.setStyle(D,T,m.styles.derive(w,{borders:C?null:$}))}}}),d.invalidate())}export{Le as applyBorderEdges,Ee as borderTab,F as ensureStyles,Pe as formatCodeProblem,ee as lineStyleName,fe as numberField,Ae as numberTab,me as paletteButton,ce as paletteGrid,pe as popButton,de as popOver,be as readFormat,G as svgNode};
@@ -1 +1 @@
1
- import{maxOutlineLevel as ft,outlineLevel as M}from"../core/whatif.js";import{MAX_COLS as X,MAX_ROWS as $}from"../core/address.js";import{registerSection as Q}from"./sections.js";const z=14,j=new WeakMap;function x(t,e){const o=e==="row"?t.rowExtras:t.colExtras;if(o===null)return 0;let l=j.get(t);l===void 0&&(l={},j.set(t,l));let r=l[e];if((r===void 0||r.map!==o||r.version!==(t.outlineVersion??0)||r.size>o.size)&&(r={map:o,version:t.outlineVersion??0,size:0,it:o.values(),max:0},l[e]=r),r.size!==o.size)for(;;){const n=r.it.next();if(n.done)break;r.size++;const i=n.value.indexOf('outlineLevel="');i>=0&&(r.max=Math.max(r.max,Number(n.value.charCodeAt(i+14)-48)))}return r.max}function bt(t,e){const o=t.rows.count,l=t.cols.count;return o===$&&l===X||e.row<o&&e.col<l?e:{...e,row:Math.min(e.row,o-1),col:Math.min(e.col,l-1),ranges:e.ranges.map(r=>({...r,r0:Math.min(r.r0,o-1),c0:Math.min(r.c0,l-1),r1:r.r1===$-1?r.r1:Math.min(r.r1,o-1),c1:r.c1===X-1?r.c1:Math.min(r.c1,l-1)}))}}const tt=t=>{t.outlineVersion=(t.outlineVersion??0)+1};function Mt(t,e){const o=x(t,e);return o===0?0:(o+1)*z+4}const E=(t,e)=>e==="row"?t.summaryAbove===!0:t.summaryLeft===!0;function et(t,e,o,l){const r=e==="row"?t.rows:t.cols,n=[],i=[],c=(w,f)=>{for(;i.length>=w;){const a=i.pop();a.end=f,n.push(a)}};let m=o;const d=Math.max(0,o-2e4);for(;m>d&&M(t,e,m-1)>0;)m--;const u=Math.min(r.count-1,l+2e4);let p=m;for(;p<=u;p++){const w=M(t,e,p);for(w<i.length&&c(w+1,p-1);i.length<w;)i.push({level:i.length+1,start:p,end:-1});if(w===0&&p>l)break}return c(1,p-1),n.filter(w=>w.end>=o-1&&w.start<=l+1)}function yt(t,e){const{sheet:o,dpr:l,theme:r}=e,n=h=>Math.round(h*l),i=e.gutterW,c=e.gutterH,m=e.rowHeaderW,d=e.colHeaderH,u=e.book.outlineStyle,p=u?.ink??r.headerInk,w=u?.bg??r.headerBg,f=u?.button??w,a=u?.line??p;t.fillStyle=w,i>0&&t.fillRect(0,0,n(i),n(e.cssH)),c>0&&t.fillRect(0,0,n(e.cssW),n(c));const s=11,C=(h,v,y)=>{t.fillStyle=f,t.strokeStyle=a,t.lineWidth=Math.max(1,Math.round(l/2)),t.fillRect(n(h),n(v),n(s),n(s)),t.strokeRect(n(h)+.5,n(v)+.5,n(s)-1,n(s)-1),t.fillStyle=p;const g=u&&(y==="+"?u.plusImage:y==="-"?u.minusImage:null),R=g?Z(e,g):null;R?t.drawImage(R,n(h),n(v),n(s),n(s)):y==="+"||y==="-"?(t.fillRect(n(h+2.5),n(v+s/2)-.5,n(s-5),Math.max(1,Math.round(l))),y==="+"&&t.fillRect(n(h+s/2)-.5,n(v+2.5),Math.max(1,Math.round(l)),n(s-5))):(t.font=`${n(9)}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(y,n(h+s/2),n(v+s/2)+.5))},S=h=>{const v=h==="row",y=x(o,h)+1;for(let k=0;k<y;k++)v?C(2+k*z,Math.max(0,d-14),String(k+1)):C(Math.max(0,m-14),2+k*z,String(k+1));const g=v?o.rows:o.cols,R=v?e.cssH-d:e.cssW-m,q=v?e.scrollY:e.scrollX,_=v?o.frozenRows:o.frozenCols,J=_?g.offsetOf(_):0,F=Math.max(g.indexAt(q+J),_),V=g.indexAt(q+J+R/e.zoom);t.save(),t.beginPath(),v?t.rect(0,n(d),n(i),n(R)):t.rect(n(m),0,n(R),n(c)),t.clip();const P=k=>{const b=v?e.cellRect(k,0):e.cellRect(0,k);return v?{at:b.y,size:b.h}:{at:b.x,size:b.w}},L=Math.max(1,Math.round((u?.lineWidth??1)*l));if(V-F<2e3){t.fillStyle=u?.dot??p;const k=Math.max(1,Math.round(l*1.5));for(let b=F;b<=V;b++){const I=M(o,h,b);if(I===0||g.isHidden(b))continue;const H=P(b),W=I*z+2+s/2;v?t.fillRect(n(W)-.5,n(H.at+H.size/2)-.5,k,k):t.fillRect(n(H.at+H.size/2)-.5,n(W)-.5,k,k)}}for(const k of et(o,h,F,V)){const b=(k.level-1)*z+2,I=E(o,h)?k.start-1:k.end+1,H=P(k.start).at,W=P(k.end).at+P(k.end).size,B=g.isHidden(k.start)&&g.isHidden(k.end);if(t.fillStyle=a,!B){const A=E(o,h)?W:H;v?(t.fillRect(n(b+s/2)-.5,n(H),L,n(W-H)),t.fillRect(n(b+s/2)-.5,n(A)-(E(o,h)?L:0),n(s/2),L)):(t.fillRect(n(H),n(b+s/2)-.5,n(W-H),L),t.fillRect(n(A)-(E(o,h)?L:0),n(b+s/2)-.5,L,n(s/2)))}if(I>=0&&I<g.count){const A=P(I);v?C(b,A.at+(A.size-s)/2,B?"+":"-"):C(A.at+(A.size-s)/2,b,B?"+":"-")}}t.restore()};i>0&&S("row"),c>0&&S("col")}function Ct(t,e,o){const{sheet:l}=t,r=t.gutterW,n=t.gutterH,i=t.rowHeaderW,c=t.colHeaderH,m=(u,p)=>{const w=Math.floor((p-2)/z)+1;return w>=1&&w<=x(l,u)+1?{kind:"level",axis:u,level:w}:null};if(r>0&&e<r&&o>=c-16&&o<c)return m("row",e);if(n>0&&o<n&&e>=i-16&&e<i)return m("col",o);const d=(u,p,w)=>{const{row:f,col:a}=u==="row"?t.hitCell(i,p):t.hitCell(p,c),s=u==="row"?f:a;for(const C of et(l,u,s-1,s+1)){const S=E(l,u)?C.start-1:C.end+1,h=(C.level-1)*z+2;if(S===s&&w>=h&&w<h+z)return{kind:"toggle",axis:u,group:C}}return null};return r>0&&e<r&&o>=c?d("row",o,e):n>0&&o<n&&e>=i?d("col",e,o):null}function gt(t,e){const{sheet:o}=t.book;return U(t,"outline",()=>{e.kind==="level"?st(o,e.axis,e.level):mt(o,e.axis,e.group)})}const ot=t=>new Map(t.hiddenSizes??[]);function nt(t){const e={rowExtras:t.rowExtras?new Map(t.rowExtras):null,colExtras:t.colExtras?new Map(t.colExtras):null,rows:ot(t.rows),cols:ot(t.cols),summaryAbove:t.summaryAbove,summaryLeft:t.summaryLeft,autoStyles:t.outlineAutoStyles,outlineColumn:t.outlineColumn};return()=>{const o=nt(t);for(const[l,r]of[[t.rows,e.rows],[t.cols,e.cols]]){if(l.hiddenSizes)for(const n of[...l.hiddenSizes.keys()])r.has(n)||l.setHidden(n,!1);for(const n of r.keys())l.setHidden(n,!0)}return Object.assign(t,{rowExtras:e.rowExtras,colExtras:e.colExtras,summaryAbove:e.summaryAbove,summaryLeft:e.summaryLeft,outlineAutoStyles:e.autoStyles,outlineColumn:e.outlineColumn}),tt(t),t.colsChanged=!0,t.revision++,o}}function U(t,e,o){const{book:l,grid:r}=t,n=l.sheet;return n.protection&&!n.protectionExtras?.outline?(l.guard?.("outline"),!1):(l.transact(n.protection?"outline":e,()=>{const i=nt(n);return o(),tt(n),n.colsChanged=!0,n.revision++,i}),l.dirty=!0,t.objects?.geometryChanged?.(),r.invalidate(),!0)}const D=(t,e)=>e==="row"?t.rowExtras:t.colExtras,O=(t,e)=>e==="row"?t.rows:t.cols,lt=/\s*collapsed="[^"]*"/;function dt(t,e,o){const l=D(t,e)?.get(o);return l!==void 0&&/collapsed="(1|true)"/.test(l)}function K(t,e,o,l){if(o<0)return;e==="row"&&!t.rowExtras&&(t.rowExtras=new Map),e==="col"&&!t.colExtras&&(t.colExtras=new Map);const r=D(t,e),n=(r.get(o)??"").replace(lt,"").trim(),i=l?`${n} collapsed="1"`.trim():n;i?r.set(o,i):r.delete(o)}const Y=(t,e,o)=>E(t,e)?o.start-1:o.end+1,rt=(t,e,o)=>e==="row"&&t.filteredRows?.has(o)===!0;function it(t,e,o,l,r){const n=O(t,e);let i=o;for(;i<=l;){if(M(t,e,i)<=r){rt(t,e,i)||n.setHidden(i,!1),i++;continue}let c=i;for(;c<l&&M(t,e,c+1)>r;)c++;dt(t,e,Y(t,e,{start:i,end:c}))||it(t,e,i,c,r+1),i=c+1}}function ct(t,e,o,l){const r=O(t,e);if(K(t,e,Y(t,e,o),l),l)for(let n=o.start;n<=o.end;n++)r.setHidden(n,!0);else it(t,e,o.start,o.end,o.level);e==="col"&&(t.colsChanged=!0)}function mt(t,e,o){const l=O(t,e);ct(t,e,o,!(l.isHidden(o.start)&&l.isHidden(o.end)))}function st(t,e,o){const l=D(t,e);if(!l)return;const r=O(t,e),n=[...l.keys()].filter(d=>M(t,e,d)>0).sort((d,u)=>d-u);for(const d of n)M(t,e,d)>=o?r.setHidden(d,!0):rt(t,e,d)||r.setHidden(d,!1);for(const d of[...l.keys()])lt.test(l.get(d))&&K(t,e,d,!1);const i=[],c=(d,u)=>{for(;i.length>d;){const p=i.pop();i.length+1>=o&&K(t,e,Y(t,e,{start:p,end:u}),!0)}};let m=-2;for(const d of n){d!==m+1&&c(0,m);const u=M(t,e,d);for(c(u,d-1);i.length<u;)i.push(d);m=d}c(0,m),e==="col"&&(t.colsChanged=!0)}function Ht(t,e,o){const l=[],r=O(t,e);for(let n=M(t,e,o);n>=1;n--){let i=o;for(;i>0&&M(t,e,i-1)>=n;)i--;let c=o;for(;c<r.count-1&&M(t,e,c+1)>=n;)c++;l.push({level:n,start:i,end:c})}return l}function St(t,e,o){const r=E(t,e)?o+1:o-1;if(r<0)return null;const n=M(t,e,o)+1;if(M(t,e,r)<n)return null;let i=r,c=r;const m=O(t,e);for(;i>0&&M(t,e,i-1)>=n;)i--;for(;c<m.count-1&&M(t,e,c+1)>=n;)c++;return{level:n,start:i,end:c}}const N=14,T=(t,e,o,l)=>{const r=t.book.styles.get(e.style(o,l)).indent??0,n=e.outlineColumn?.maxLevel;return n===void 0?r:Math.min(r,n)};function ut(t,e,o,l){return(e.kind(o+1,l)&15)!==0&&T(t,e,o+1,l)>T(t,e,o,l)}const at=new Map,pt=/^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/,wt=7e5,G=t=>typeof t=="string"&&t.length<=wt&&pt.test(t);function Z(t,e){if(!e)return null;let o=at.get(e);return o===void 0&&(o=new Image,o.onload=()=>t.invalidate(),o.src=e,at.set(e,o)),o.complete&&o.naturalWidth>0?o:null}function zt(t,e,o,l,r,n,i,c){const{sheet:m,theme:d}=e,u=m.outlineColumn,p=T(e,m,o,l),w=Math.round(p*9*c);let f=r+w;const a=Math.round(10*c),s=n+i/2,C=d.cellInk??"#000000",S=u.indicator!==!1&&ut(e,m,o,l),h=S&&m.rows.isHidden(o+1),v=S?Z(e,h?u.indicatorImages?.collapsed:u.indicatorImages?.expanded):null;if(v?t.drawImage(v,f,s-a/2,a,a):S&&(t.fillStyle=C,t.beginPath(),h?(t.moveTo(f+a*.3,s-a*.35),t.lineTo(f+a*.8,s),t.lineTo(f+a*.3,s+a*.35)):(t.moveTo(f+a*.15,s-a*.2),t.lineTo(f+a*.85,s-a*.2),t.lineTo(f+a*.5,s+a*.3)),t.closePath(),t.fill()),f+=Math.round(N*c),u.checkbox){const y=u.checks?.[o]===!0;t.strokeStyle=C,t.lineWidth=Math.max(1,Math.round(c/2)),t.strokeRect(f+.5,s-a/2+.5,a-1,a-1),y&&(t.beginPath(),t.moveTo(f+a*.2,s),t.lineTo(f+a*.42,s+a*.25),t.lineTo(f+a*.82,s-a*.28),t.stroke()),f+=Math.round(N*c)}if(u.images?.length>0){const y=Z(e,u.images[Math.min(p,u.images.length-1)]);y&&t.drawImage(y,f,s-a/2,a,a),f+=Math.round(N*c)}return e._ink=null,f-r-w}function At(t,e,o,l){const{book:r,grid:n}=t,i=r.sheet,c=i.outlineColumn;if(c===null||c.col!==o)return!1;const m=n.cellRect(e,o),d=T(n,i,e,o),u=m.x+2+d*9*n.zoom,p=N*n.zoom,w=f=>f<=i.maxRow&&T(n,i,f,o)>d&&(i.kind(f,o)&15)!==0;return c.indicator!==!1&&l>=u-2&&l<u+p&&ut(n,i,e,o)?U(t,"outline",()=>{const f=!i.rows.isHidden(e+1);for(let a=e+1;w(a);a++)f?i.rows.setHidden(a,!0):T(n,i,a,o)===d+1&&i.rows.setHidden(a,!1)}):c.checkbox&&l>=u+p&&l<u+p*2?U(t,"outline",()=>{const f={...c.checks??{}},a=!f[e];a?f[e]=!0:delete f[e];for(let s=e+1;w(s);s++)a?f[s]=!0:delete f[s];i.outlineColumn={...c,checks:f}}):!1}Q("outlineColumn",{sheet:{save(t){return t.outlineColumn===null?void 0:t.outlineColumn},load(t,e){if(!e||!Number.isInteger(e.col)||e.col<0||e.col>=X)return;const o={};if(e.checks&&typeof e.checks=="object")for(const[r,n]of Object.entries(e.checks))Number(r)>=0&&Number(r)<$&&n===!0&&(o[r]=!0);if(t.outlineColumn={col:e.col,checkbox:e.checkbox===!0,indicator:e.indicator!==!1,checks:o},Number.isInteger(e.maxLevel)&&e.maxLevel>=0&&(t.outlineColumn.maxLevel=e.maxLevel),Array.isArray(e.images)){const r=e.images.filter(G).slice(0,16);r.length>0&&(t.outlineColumn.images=r)}const l=e.indicatorImages;if(l&&typeof l=="object"){const r={};G(l.expanded)&&(r.expanded=l.expanded),G(l.collapsed)&&(r.collapsed=l.collapsed),(r.expanded||r.collapsed)&&(t.outlineColumn.indicatorImages=r)}}}}),Q("outlineStyle",{book:{save(t){return t.outlineStyle??void 0},load(t,e){if(!e||typeof e!="object")return;const o={};for(const l of["bg","ink","button","line","dot"])typeof e[l]=="string"&&/^#[0-9a-fA-F]{6}$/.test(e[l])&&(o[l]=e[l]);Number.isFinite(e.lineWidth)&&e.lineWidth>=1&&e.lineWidth<=6&&(o.lineWidth=e.lineWidth);for(const l of["plusImage","minusImage"])G(e[l])&&(o[l]=e[l]);t.outlineStyle=Object.keys(o).length>0?o:null}}});export{bt as clampToSheet,St as groupOfMark,Ht as groupsAt,ft as maxOutlineLevel,tt as outlineChanged,At as outlineColumnClick,Mt as outlineGutterSize,Ct as outlineHit,U as outlineStep,zt as paintOutlineColumnMark,yt as paintOutlineGutter,gt as runOutlineHit,K as setFlag,ct as setGroupCollapsed,st as showLevel};
1
+ import{maxOutlineLevel as ft,outlineLevel as M}from"../core/whatif.js";import{MAX_COLS as X,MAX_ROWS as $}from"../core/address.js";import{registerSection as Q}from"./sections.js";const z=14,j=new WeakMap;function x(t,e){const o=e==="row"?t.rowExtras:t.colExtras;if(o===null)return 0;let l=j.get(t);l===void 0&&(l={},j.set(t,l));let r=l[e];if((r===void 0||r.map!==o||r.version!==(t.outlineVersion??0)||r.size>o.size)&&(r={map:o,version:t.outlineVersion??0,size:0,it:o.values(),max:0},l[e]=r),r.size!==o.size)for(;;){const n=r.it.next();if(n.done)break;r.size++;const i=n.value.indexOf('outlineLevel="');i>=0&&(r.max=Math.max(r.max,Number(n.value.charCodeAt(i+14)-48)))}return r.max}function bt(t,e){const o=t.rows.count,l=t.cols.count;return o===$&&l===X||e.row<o&&e.col<l?e:{...e,row:Math.min(e.row,o-1),col:Math.min(e.col,l-1),ranges:e.ranges.map(r=>({...r,r0:Math.min(r.r0,o-1),c0:Math.min(r.c0,l-1),r1:r.r1===$-1?r.r1:Math.min(r.r1,o-1),c1:r.c1===X-1?r.c1:Math.min(r.c1,l-1)}))}}const tt=t=>{t.outlineVersion=(t.outlineVersion??0)+1};function Mt(t,e){const o=x(t,e);return o===0?0:(o+1)*z+4}const E=(t,e)=>e==="row"?t.summaryAbove===!0:t.summaryLeft===!0;function et(t,e,o,l){const r=e==="row"?t.rows:t.cols,n=[],i=[],c=(w,f)=>{for(;i.length>=w;){const a=i.pop();a.end=f,n.push(a)}};let m=o;const d=Math.max(0,o-2e4);for(;m>d&&M(t,e,m-1)>0;)m--;const u=Math.min(r.count-1,l+2e4);let p=m;for(;p<=u;p++){const w=M(t,e,p);for(w<i.length&&c(w+1,p-1);i.length<w;)i.push({level:i.length+1,start:p,end:-1});if(w===0&&p>l)break}return c(1,p-1),n.filter(w=>w.end>=o-1&&w.start<=l+1)}function yt(t,e){const{sheet:o,dpr:l,theme:r}=e,n=h=>Math.round(h*l),i=e.gutterW,c=e.gutterH,m=e.rowHeaderW,d=e.colHeaderH,u=e.book.outlineStyle,p=u?.ink??r.headerInk,w=u?.bg??r.headerBg,f=u?.button??w,a=u?.line??p;t.fillStyle=w,i>0&&t.fillRect(0,0,n(i),n(e.cssH)),c>0&&t.fillRect(0,0,n(e.cssW),n(c));const s=11,C=(h,v,y)=>{t.fillStyle=f,t.strokeStyle=a,t.lineWidth=Math.max(1,Math.round(l/2)),t.fillRect(n(h),n(v),n(s),n(s)),t.strokeRect(n(h)+.5,n(v)+.5,n(s)-1,n(s)-1),t.fillStyle=p;const g=u&&(y==="+"?u.plusImage:y==="-"?u.minusImage:null),R=g?Z(e,g):null;R?t.drawImage(R,n(h),n(v),n(s),n(s)):y==="+"||y==="-"?(t.fillRect(n(h+2.5),n(v+s/2)-.5,n(s-5),Math.max(1,Math.round(l))),y==="+"&&t.fillRect(n(h+s/2)-.5,n(v+2.5),Math.max(1,Math.round(l)),n(s-5))):(t.font=`${n(9)}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(y,n(h+s/2),n(v+s/2)+.5))},S=h=>{const v=h==="row",y=x(o,h)+1;for(let k=0;k<y;k++)v?C(2+k*z,Math.max(0,d-14),String(k+1)):C(Math.max(0,m-14),2+k*z,String(k+1));const g=v?o.rows:e.displayCols,R=v?e.cssH-d:e.cssW-m,q=v?e.scrollY:e.scrollX,_=v?o.frozenRows:o.frozenCols,J=_?g.offsetOf(_):0,F=Math.max(g.indexAt(q+J),_),V=g.indexAt(q+J+R/e.zoom);t.save(),t.beginPath(),v?t.rect(0,n(d),n(i),n(R)):t.rect(n(m),0,n(R),n(c)),t.clip();const P=k=>{const b=v?e.cellRect(k,0):e.cellRect(0,k);return v?{at:b.y,size:b.h}:{at:b.x,size:b.w}},L=Math.max(1,Math.round((u?.lineWidth??1)*l));if(V-F<2e3){t.fillStyle=u?.dot??p;const k=Math.max(1,Math.round(l*1.5));for(let b=F;b<=V;b++){const I=M(o,h,b);if(I===0||g.isHidden(b))continue;const H=P(b),W=I*z+2+s/2;v?t.fillRect(n(W)-.5,n(H.at+H.size/2)-.5,k,k):t.fillRect(n(H.at+H.size/2)-.5,n(W)-.5,k,k)}}for(const k of et(o,h,F,V)){const b=(k.level-1)*z+2,I=E(o,h)?k.start-1:k.end+1,H=P(k.start).at,W=P(k.end).at+P(k.end).size,B=g.isHidden(k.start)&&g.isHidden(k.end);if(t.fillStyle=a,!B){const A=E(o,h)?W:H;v?(t.fillRect(n(b+s/2)-.5,n(H),L,n(W-H)),t.fillRect(n(b+s/2)-.5,n(A)-(E(o,h)?L:0),n(s/2),L)):(t.fillRect(n(H),n(b+s/2)-.5,n(W-H),L),t.fillRect(n(A)-(E(o,h)?L:0),n(b+s/2)-.5,L,n(s/2)))}if(I>=0&&I<g.count){const A=P(I);v?C(b,A.at+(A.size-s)/2,B?"+":"-"):C(A.at+(A.size-s)/2,b,B?"+":"-")}}t.restore()};i>0&&S("row"),c>0&&S("col")}function Ct(t,e,o){const{sheet:l}=t,r=t.gutterW,n=t.gutterH,i=t.rowHeaderW,c=t.colHeaderH,m=(u,p)=>{const w=Math.floor((p-2)/z)+1;return w>=1&&w<=x(l,u)+1?{kind:"level",axis:u,level:w}:null};if(r>0&&e<r&&o>=c-16&&o<c)return m("row",e);if(n>0&&o<n&&e>=i-16&&e<i)return m("col",o);const d=(u,p,w)=>{const{row:f,col:a}=u==="row"?t.hitCell(i,p):t.hitCell(p,c),s=u==="row"?f:a;for(const C of et(l,u,s-1,s+1)){const S=E(l,u)?C.start-1:C.end+1,h=(C.level-1)*z+2;if(S===s&&w>=h&&w<h+z)return{kind:"toggle",axis:u,group:C}}return null};return r>0&&e<r&&o>=c?d("row",o,e):n>0&&o<n&&e>=i?d("col",e,o):null}function gt(t,e){const{sheet:o}=t.book;return U(t,"outline",()=>{e.kind==="level"?st(o,e.axis,e.level):mt(o,e.axis,e.group)})}const ot=t=>new Map(t.hiddenSizes??[]);function nt(t){const e={rowExtras:t.rowExtras?new Map(t.rowExtras):null,colExtras:t.colExtras?new Map(t.colExtras):null,rows:ot(t.rows),cols:ot(t.cols),summaryAbove:t.summaryAbove,summaryLeft:t.summaryLeft,autoStyles:t.outlineAutoStyles,outlineColumn:t.outlineColumn};return()=>{const o=nt(t);for(const[l,r]of[[t.rows,e.rows],[t.cols,e.cols]]){if(l.hiddenSizes)for(const n of[...l.hiddenSizes.keys()])r.has(n)||l.setHidden(n,!1);for(const n of r.keys())l.setHidden(n,!0)}return Object.assign(t,{rowExtras:e.rowExtras,colExtras:e.colExtras,summaryAbove:e.summaryAbove,summaryLeft:e.summaryLeft,outlineAutoStyles:e.autoStyles,outlineColumn:e.outlineColumn}),tt(t),t.colsChanged=!0,t.revision++,o}}function U(t,e,o){const{book:l,grid:r}=t,n=l.sheet;return n.protection&&!n.protectionExtras?.outline?(l.guard?.("outline"),!1):(l.transact(n.protection?"outline":e,()=>{const i=nt(n);return o(),tt(n),n.colsChanged=!0,n.revision++,i}),l.dirty=!0,t.objects?.geometryChanged?.(),r.invalidate(),!0)}const D=(t,e)=>e==="row"?t.rowExtras:t.colExtras,O=(t,e)=>e==="row"?t.rows:t.cols,lt=/\s*collapsed="[^"]*"/;function dt(t,e,o){const l=D(t,e)?.get(o);return l!==void 0&&/collapsed="(1|true)"/.test(l)}function K(t,e,o,l){if(o<0)return;e==="row"&&!t.rowExtras&&(t.rowExtras=new Map),e==="col"&&!t.colExtras&&(t.colExtras=new Map);const r=D(t,e),n=(r.get(o)??"").replace(lt,"").trim(),i=l?`${n} collapsed="1"`.trim():n;i?r.set(o,i):r.delete(o)}const Y=(t,e,o)=>E(t,e)?o.start-1:o.end+1,rt=(t,e,o)=>e==="row"&&t.filteredRows?.has(o)===!0;function it(t,e,o,l,r){const n=O(t,e);let i=o;for(;i<=l;){if(M(t,e,i)<=r){rt(t,e,i)||n.setHidden(i,!1),i++;continue}let c=i;for(;c<l&&M(t,e,c+1)>r;)c++;dt(t,e,Y(t,e,{start:i,end:c}))||it(t,e,i,c,r+1),i=c+1}}function ct(t,e,o,l){const r=O(t,e);if(K(t,e,Y(t,e,o),l),l)for(let n=o.start;n<=o.end;n++)r.setHidden(n,!0);else it(t,e,o.start,o.end,o.level);e==="col"&&(t.colsChanged=!0)}function mt(t,e,o){const l=O(t,e);ct(t,e,o,!(l.isHidden(o.start)&&l.isHidden(o.end)))}function st(t,e,o){const l=D(t,e);if(!l)return;const r=O(t,e),n=[...l.keys()].filter(d=>M(t,e,d)>0).sort((d,u)=>d-u);for(const d of n)M(t,e,d)>=o?r.setHidden(d,!0):rt(t,e,d)||r.setHidden(d,!1);for(const d of[...l.keys()])lt.test(l.get(d))&&K(t,e,d,!1);const i=[],c=(d,u)=>{for(;i.length>d;){const p=i.pop();i.length+1>=o&&K(t,e,Y(t,e,{start:p,end:u}),!0)}};let m=-2;for(const d of n){d!==m+1&&c(0,m);const u=M(t,e,d);for(c(u,d-1);i.length<u;)i.push(d);m=d}c(0,m),e==="col"&&(t.colsChanged=!0)}function Ht(t,e,o){const l=[],r=O(t,e);for(let n=M(t,e,o);n>=1;n--){let i=o;for(;i>0&&M(t,e,i-1)>=n;)i--;let c=o;for(;c<r.count-1&&M(t,e,c+1)>=n;)c++;l.push({level:n,start:i,end:c})}return l}function St(t,e,o){const r=E(t,e)?o+1:o-1;if(r<0)return null;const n=M(t,e,o)+1;if(M(t,e,r)<n)return null;let i=r,c=r;const m=O(t,e);for(;i>0&&M(t,e,i-1)>=n;)i--;for(;c<m.count-1&&M(t,e,c+1)>=n;)c++;return{level:n,start:i,end:c}}const N=14,T=(t,e,o,l)=>{const r=t.book.styles.get(e.style(o,l)).indent??0,n=e.outlineColumn?.maxLevel;return n===void 0?r:Math.min(r,n)};function ut(t,e,o,l){return(e.kind(o+1,l)&15)!==0&&T(t,e,o+1,l)>T(t,e,o,l)}const at=new Map,pt=/^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/,wt=7e5,G=t=>typeof t=="string"&&t.length<=wt&&pt.test(t);function Z(t,e){if(!e)return null;let o=at.get(e);return o===void 0&&(o=new Image,o.onload=()=>t.invalidate(),o.src=e,at.set(e,o)),o.complete&&o.naturalWidth>0?o:null}function zt(t,e,o,l,r,n,i,c){const{sheet:m,theme:d}=e,u=m.outlineColumn,p=T(e,m,o,l),w=Math.round(p*9*c);let f=r+w;const a=Math.round(10*c),s=n+i/2,C=d.cellInk??"#000000",S=u.indicator!==!1&&ut(e,m,o,l),h=S&&m.rows.isHidden(o+1),v=S?Z(e,h?u.indicatorImages?.collapsed:u.indicatorImages?.expanded):null;if(v?t.drawImage(v,f,s-a/2,a,a):S&&(t.fillStyle=C,t.beginPath(),h?(t.moveTo(f+a*.3,s-a*.35),t.lineTo(f+a*.8,s),t.lineTo(f+a*.3,s+a*.35)):(t.moveTo(f+a*.15,s-a*.2),t.lineTo(f+a*.85,s-a*.2),t.lineTo(f+a*.5,s+a*.3)),t.closePath(),t.fill()),f+=Math.round(N*c),u.checkbox){const y=u.checks?.[o]===!0;t.strokeStyle=C,t.lineWidth=Math.max(1,Math.round(c/2)),t.strokeRect(f+.5,s-a/2+.5,a-1,a-1),y&&(t.beginPath(),t.moveTo(f+a*.2,s),t.lineTo(f+a*.42,s+a*.25),t.lineTo(f+a*.82,s-a*.28),t.stroke()),f+=Math.round(N*c)}if(u.images?.length>0){const y=Z(e,u.images[Math.min(p,u.images.length-1)]);y&&t.drawImage(y,f,s-a/2,a,a),f+=Math.round(N*c)}return e._ink=null,f-r-w}function At(t,e,o,l){const{book:r,grid:n}=t,i=r.sheet,c=i.outlineColumn;if(c===null||c.col!==o)return!1;const m=n.cellRect(e,o),d=T(n,i,e,o),u=m.x+2+d*9*n.zoom,p=N*n.zoom,w=f=>f<=i.maxRow&&T(n,i,f,o)>d&&(i.kind(f,o)&15)!==0;return c.indicator!==!1&&l>=u-2&&l<u+p&&ut(n,i,e,o)?U(t,"outline",()=>{const f=!i.rows.isHidden(e+1);for(let a=e+1;w(a);a++)f?i.rows.setHidden(a,!0):T(n,i,a,o)===d+1&&i.rows.setHidden(a,!1)}):c.checkbox&&l>=u+p&&l<u+p*2?U(t,"outline",()=>{const f={...c.checks??{}},a=!f[e];a?f[e]=!0:delete f[e];for(let s=e+1;w(s);s++)a?f[s]=!0:delete f[s];i.outlineColumn={...c,checks:f}}):!1}Q("outlineColumn",{sheet:{save(t){return t.outlineColumn===null?void 0:t.outlineColumn},load(t,e){if(!e||!Number.isInteger(e.col)||e.col<0||e.col>=X)return;const o={};if(e.checks&&typeof e.checks=="object")for(const[r,n]of Object.entries(e.checks))Number(r)>=0&&Number(r)<$&&n===!0&&(o[r]=!0);if(t.outlineColumn={col:e.col,checkbox:e.checkbox===!0,indicator:e.indicator!==!1,checks:o},Number.isInteger(e.maxLevel)&&e.maxLevel>=0&&(t.outlineColumn.maxLevel=e.maxLevel),Array.isArray(e.images)){const r=e.images.filter(G).slice(0,16);r.length>0&&(t.outlineColumn.images=r)}const l=e.indicatorImages;if(l&&typeof l=="object"){const r={};G(l.expanded)&&(r.expanded=l.expanded),G(l.collapsed)&&(r.collapsed=l.collapsed),(r.expanded||r.collapsed)&&(t.outlineColumn.indicatorImages=r)}}}}),Q("outlineStyle",{book:{save(t){return t.outlineStyle??void 0},load(t,e){if(!e||typeof e!="object")return;const o={};for(const l of["bg","ink","button","line","dot"])typeof e[l]=="string"&&/^#[0-9a-fA-F]{6}$/.test(e[l])&&(o[l]=e[l]);Number.isFinite(e.lineWidth)&&e.lineWidth>=1&&e.lineWidth<=6&&(o.lineWidth=e.lineWidth);for(const l of["plusImage","minusImage"])G(e[l])&&(o[l]=e[l]);t.outlineStyle=Object.keys(o).length>0?o:null}}});export{bt as clampToSheet,St as groupOfMark,Ht as groupsAt,ft as maxOutlineLevel,tt as outlineChanged,At as outlineColumnClick,Mt as outlineGutterSize,Ct as outlineHit,U as outlineStep,zt as paintOutlineColumnMark,yt as paintOutlineGutter,gt as runOutlineHit,K as setFlag,ct as setGroupCollapsed,st as showLevel};
package/cells/panes.js CHANGED
@@ -1 +1 @@
1
- import{registerSection as S}from"./sections.js";import{MAX_COLS as M,MAX_ROWS as b}from"../core/address.js";import{optionFor as w}from"./options.js";import{allows as H}from"../core/protection.js";function $(t){const{book:o,grid:e}=t,i=o.sheet;if(i.split){h(t);return}if(i.frozenRows||i.frozenCols||i.frozenTrailingRows||i.frozenTrailingCols){t.shell.setStatus("Panes can't be split while they're frozen. Unfreeze them first.");return}const{row:r,col:n}=e.selection,l=(e.cssW-e.rowHeaderW)/e.zoom,s=(e.cssH-e.colHeaderH)/e.zoom;let c=i.cols.offsetOf(n)-e.scrollX,a=i.rows.offsetOf(r)-e.scrollY;c<=0&&a<=0&&(c=l/2,a=s/2),c=c>0&&c<l?Math.round(c):0,a=a>0&&a<s?Math.round(a):0,i.split={x:c,y:a,scrollX:e.scrollX,scrollY:e.scrollY},i.viewChanged=!0,o.dirty=!0,e.invalidate()}function h(t){const{book:o,grid:e}=t,i=o.sheet;i.split&&(e.scrollX=i.split.scrollX,e.scrollY=i.split.scrollY,i.split=null,e.activeBand=null,i.viewChanged=!0,o.dirty=!0,e.invalidate())}function X(t,o,e){const{sheet:i,zoom:r}=t;if(!i.split)return null;const n=t.rowHeaderW,l=t.colHeaderH;return i.split.x>0&&Math.abs(o-n-i.split.x*r)<=4&&e>=l?{axis:"col"}:i.split.y>0&&Math.abs(e-l-i.split.y*r)<=4&&o>=n?{axis:"row"}:null}function k(t){const{sheet:o}=t,{split:e}=o,i=l=>{const s=/^([A-Z]+)(\d+)$/.exec(l??"");if(!s)return null;let c=0;for(const a of s[1])c=c*26+a.charCodeAt(0)-64;return{x:o.cols.offsetOf(c-1),y:o.rows.offsetOf(Number(s[2])-1)}},r=i(e.topLeft),n=i(e.firstTopLeft);e.topLeft=null,e.firstTopLeft=null,n&&(e.scrollX=n.x,e.scrollY=n.y),r&&(t.scrollX=Math.max(0,r.x-e.x),t.scrollY=Math.max(0,r.y-e.y),e.mainX=t.scrollX,e.mainY=t.scrollY)}function O(t,o,e,i){const{grid:r,book:n}=t,{sheet:l,zoom:s}=r,c=l.split;c&&(o==="col"?c.x=Math.max(0,Math.round((e-r.rowHeaderW)/s)):c.y=Math.max(0,Math.round((i-r.colHeaderH)/s)),c.x<=0&&c.y<=0&&(l.split=null),l.viewChanged=!0,n.dirty=!0,r.invalidate())}function v(t,o,e,i=!0){const{book:r,grid:n}=t,l=r.sheet;l.split&&h(t),l.frozenTrailingRows=Math.max(0,o),l.frozenTrailingCols=Math.max(0,e),l.trailingStick=i,r.dirty=!0,n.scrollTo(n.scrollX,n.scrollY),n.invalidate()}function Y(t){const o=String(t).trim().toLowerCase();return o==="auto"?"auto":/^\d*\.?\d*\*$/.test(o)?o==="*"?1:Number(o.slice(0,-1)):null}function y(t,o,e,i){t.axisSizing??={rows:new Map,cols:new Map};const r=o==="col"?t.axisSizing.cols:t.axisSizing.rows;i===null?r.delete(e):r.set(e,i),t.axisSizing.rows.size===0&&t.axisSizing.cols.size===0&&(t.axisSizing=null),t.sizingKey=null}function W(t,o,e){t.axisSizing!==null&&y(t,o,e,null)}function L(t){const{sheet:o,zoom:e}=t,i=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`;if(o.sizingKey===i)return;const r=(n,l)=>{const s=n==="col"?o.cols:o.rows,c=(n==="col"?t.cssW-t.rowHeaderW:t.cssH-t.colHeaderH)/e;let a=n==="col"?o.maxCol:o.maxRow,u=0,x=0;for(const[f,p]of l)f>a&&(a=f),p==="auto"?t.onAutoSize?.(n,f):s.isHidden(f)||(u+=p,x+=s.sizeOf(f));if(u===0)return;const g=c-(s.offsetOf(a+1)-x);if(g<1)return;let d=!1;for(const[f,p]of l){if(p==="auto"||s.isHidden(f))continue;const m=Math.floor(g*p/u);s.sizeOf(f)!==m&&(s.setSize(f,m),d=!0)}d&&n==="col"&&(o.colsChanged=!0)};r("col",o.axisSizing.cols),r("row",o.axisSizing.rows),o.sizingKey=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`}S("layout",{sheet:{save(t){const o={};return t.frozenTrailingRows&&(o.trailRows=t.frozenTrailingRows),t.frozenTrailingCols&&(o.trailCols=t.frozenTrailingCols),t.trailingStick===!1&&(o.stick=!1),t.axisSizing&&(o.cols=[...t.axisSizing.cols],o.rows=[...t.axisSizing.rows]),Object.keys(o).length?o:void 0},load(t,o){if(!o||typeof o!="object")return;const e=(r,n)=>Number.isInteger(r)&&r>0&&r<n?r:0;t.frozenTrailingRows=e(o.trailRows,1e3),t.frozenTrailingCols=e(o.trailCols,1e3),o.stick===!1&&(t.trailingStick=!1);const i=(r,n,l)=>{if(Array.isArray(n))for(const s of n.slice(0,1e4))!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||s[0]>=l||(s[1]==="auto"||typeof s[1]=="number"&&s[1]>0)&&y(t,r,s[0],s[1])};i("col",o.cols,M),i("row",o.rows,b)}}});function I(t,o,e){return e.ctrlKey===!0||e.altKey===!0||(o==="col"?t.columnResizeMode:t.rowResizeMode)==="split"}function K(t,o){for(let e=o+1;e<t.count;e++)if(t.sizeOf(e)>0)return e;return-1}function N(t,o,e,i,r,n){const l=i+r,s=Math.max(0,Math.min(l,i+n));t.setSize(o,s),t.setSize(e,l-s)}const z=7;function B(t,o,e){if(!w(t.book,"dragMerge"))return!1;const{grid:i,sel:r}=t;if(r.ranges.length!==1)return!1;const n=r.ranges[0],l=i.cellRect(n.r0,n.c0),s=i.cellRect(n.r1,n.c1),c=s.x+s.w,a=s.y+s.h,u=(l.x+c)/2,x=(l.y+a)/2;return Math.abs(e-a)<=z&&Math.abs(o-u)<=z||Math.abs(o-c)<=z&&Math.abs(e-x)<=z}function D(t,o,e){const i=o.selection;if(i.ranges.length!==1)return;const r=o._rangeRectInPane(i.ranges[0],e);if(r===null)return;const{dpr:n,theme:l}=o,s=Math.round(5*n);t.fillStyle=l.accent,t.fillRect((r.x0+r.x1)/2-s/2,r.y1-s/2,s,s),t.fillRect(r.x1-s/2,(r.y0+r.y1)/2-s/2,s,s)}function _(t,o,e,i){const r={...o,r1:Math.max(o.r1,e),c1:Math.max(o.c1,i)};for(const n of t.merges){const l=n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0,s=n.r0>=r.r0&&n.r1<=r.r1&&n.c0>=r.c0&&n.c1<=r.c1;if(l&&!s)return null}return r}const P=(t,o)=>{const e=w(o,"dragHeaders");return e==="both"||e===t};export{H as allows,L as applyAxisSizing,k as applySplitTopLeft,B as dragMergeHit,_ as dragMergeTarget,O as dragSplitBar,W as dropAxisSizing,P as headerDragAllowed,I as isSplitResize,K as nextVisible,D as paintDragMergeGrip,Y as parseSizeSpec,h as removeSplit,y as setAxisSizing,v as setTrailing,X as splitBarHit,N as splitResize,$ as toggleSplit};
1
+ import{registerSection as S}from"./sections.js";import{MAX_COLS as M,MAX_ROWS as b}from"../core/address.js";import{optionFor as w}from"./options.js";import{allows as H}from"../core/protection.js";function $(t){const{book:o,grid:e}=t,i=o.sheet;if(i.split){h(t);return}if(i.frozenRows||i.frozenCols||i.frozenTrailingRows||i.frozenTrailingCols){t.shell.setStatus("Panes can't be split while they're frozen. Unfreeze them first.");return}const{row:r,col:n}=e.selection,l=(e.cssW-e.rowHeaderW)/e.zoom,s=(e.cssH-e.colHeaderH)/e.zoom;let c=e.displayCols.offsetOf(n)-e.scrollX,a=i.rows.offsetOf(r)-e.scrollY;c<=0&&a<=0&&(c=l/2,a=s/2),c=c>0&&c<l?Math.round(c):0,a=a>0&&a<s?Math.round(a):0,i.split={x:c,y:a,scrollX:e.scrollX,scrollY:e.scrollY},i.viewChanged=!0,o.dirty=!0,e.invalidate()}function h(t){const{book:o,grid:e}=t,i=o.sheet;i.split&&(e.scrollX=i.split.scrollX,e.scrollY=i.split.scrollY,i.split=null,e.activeBand=null,i.viewChanged=!0,o.dirty=!0,e.invalidate())}function X(t,o,e){const{sheet:i,zoom:r}=t;if(!i.split)return null;const n=t.rowHeaderW,l=t.colHeaderH;return i.split.x>0&&Math.abs(o-n-i.split.x*r)<=4&&e>=l?{axis:"col"}:i.split.y>0&&Math.abs(e-l-i.split.y*r)<=4&&o>=n?{axis:"row"}:null}function k(t){const{sheet:o}=t,{split:e}=o,i=l=>{const s=/^([A-Z]+)(\d+)$/.exec(l??"");if(!s)return null;let c=0;for(const a of s[1])c=c*26+a.charCodeAt(0)-64;return{x:t.displayCols.offsetOf(c-1),y:o.rows.offsetOf(Number(s[2])-1)}},r=i(e.topLeft),n=i(e.firstTopLeft);e.topLeft=null,e.firstTopLeft=null,n&&(e.scrollX=n.x,e.scrollY=n.y),r&&(t.scrollX=Math.max(0,r.x-e.x),t.scrollY=Math.max(0,r.y-e.y),e.mainX=t.scrollX,e.mainY=t.scrollY)}function O(t,o,e,i){const{grid:r,book:n}=t,{sheet:l,zoom:s}=r,c=l.split;c&&(o==="col"?c.x=Math.max(0,Math.round((e-r.rowHeaderW)/s)):c.y=Math.max(0,Math.round((i-r.colHeaderH)/s)),c.x<=0&&c.y<=0&&(l.split=null),l.viewChanged=!0,n.dirty=!0,r.invalidate())}function v(t,o,e,i=!0){const{book:r,grid:n}=t,l=r.sheet;l.split&&h(t),l.frozenTrailingRows=Math.max(0,o),l.frozenTrailingCols=Math.max(0,e),l.trailingStick=i,r.dirty=!0,n.scrollTo(n.scrollX,n.scrollY),n.invalidate()}function Y(t){const o=String(t).trim().toLowerCase();return o==="auto"?"auto":/^\d*\.?\d*\*$/.test(o)?o==="*"?1:Number(o.slice(0,-1)):null}function y(t,o,e,i){t.axisSizing??={rows:new Map,cols:new Map};const r=o==="col"?t.axisSizing.cols:t.axisSizing.rows;i===null?r.delete(e):r.set(e,i),t.axisSizing.rows.size===0&&t.axisSizing.cols.size===0&&(t.axisSizing=null),t.sizingKey=null}function W(t,o,e){t.axisSizing!==null&&y(t,o,e,null)}function L(t){const{sheet:o,zoom:e}=t,i=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`;if(o.sizingKey===i)return;const r=(n,l)=>{const s=n==="col"?o.cols:o.rows,c=(n==="col"?t.cssW-t.rowHeaderW:t.cssH-t.colHeaderH)/e;let a=n==="col"?o.maxCol:o.maxRow,u=0,x=0;for(const[f,p]of l)f>a&&(a=f),p==="auto"?t.onAutoSize?.(n,f):s.isHidden(f)||(u+=p,x+=s.sizeOf(f));if(u===0)return;const g=c-(s.offsetOf(a+1)-x);if(g<1)return;let d=!1;for(const[f,p]of l){if(p==="auto"||s.isHidden(f))continue;const m=Math.floor(g*p/u);s.sizeOf(f)!==m&&(s.setSize(f,m),d=!0)}d&&n==="col"&&(o.colsChanged=!0)};r("col",o.axisSizing.cols),r("row",o.axisSizing.rows),o.sizingKey=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`}S("layout",{sheet:{save(t){const o={};return t.frozenTrailingRows&&(o.trailRows=t.frozenTrailingRows),t.frozenTrailingCols&&(o.trailCols=t.frozenTrailingCols),t.trailingStick===!1&&(o.stick=!1),t.axisSizing&&(o.cols=[...t.axisSizing.cols],o.rows=[...t.axisSizing.rows]),Object.keys(o).length?o:void 0},load(t,o){if(!o||typeof o!="object")return;const e=(r,n)=>Number.isInteger(r)&&r>0&&r<n?r:0;t.frozenTrailingRows=e(o.trailRows,1e3),t.frozenTrailingCols=e(o.trailCols,1e3),o.stick===!1&&(t.trailingStick=!1);const i=(r,n,l)=>{if(Array.isArray(n))for(const s of n.slice(0,1e4))!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||s[0]>=l||(s[1]==="auto"||typeof s[1]=="number"&&s[1]>0)&&y(t,r,s[0],s[1])};i("col",o.cols,M),i("row",o.rows,b)}}});function I(t,o,e){return e.ctrlKey===!0||e.altKey===!0||(o==="col"?t.columnResizeMode:t.rowResizeMode)==="split"}function K(t,o){for(let e=o+1;e<t.count;e++)if(t.sizeOf(e)>0)return e;return-1}function N(t,o,e,i,r,n){const l=i+r,s=Math.max(0,Math.min(l,i+n));t.setSize(o,s),t.setSize(e,l-s)}const z=7;function B(t,o,e){if(!w(t.book,"dragMerge"))return!1;const{grid:i,sel:r}=t;if(r.ranges.length!==1)return!1;const n=r.ranges[0],l=i.cellRect(n.r0,n.c0),s=i.cellRect(n.r1,n.c1),c=s.x+s.w,a=s.y+s.h,u=(l.x+c)/2,x=(l.y+a)/2;return Math.abs(e-a)<=z&&Math.abs(o-u)<=z||Math.abs(o-c)<=z&&Math.abs(e-x)<=z}function D(t,o,e){const i=o.selection;if(i.ranges.length!==1)return;const r=o._rangeRectInPane(i.ranges[0],e);if(r===null)return;const{dpr:n,theme:l}=o,s=Math.round(5*n);t.fillStyle=l.accent,t.fillRect((r.x0+r.x1)/2-s/2,r.y1-s/2,s,s),t.fillRect(r.x1-s/2,(r.y0+r.y1)/2-s/2,s,s)}function _(t,o,e,i){const r={...o,r1:Math.max(o.r1,e),c1:Math.max(o.c1,i)};for(const n of t.merges){const l=n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0,s=n.r0>=r.r0&&n.r1<=r.r1&&n.c0>=r.c0&&n.c1<=r.c1;if(l&&!s)return null}return r}const P=(t,o)=>{const e=w(o,"dragHeaders");return e==="both"||e===t};export{H as allows,L as applyAxisSizing,k as applySplitTopLeft,B as dragMergeHit,_ as dragMergeTarget,O as dragSplitBar,W as dropAxisSizing,P as headerDragAllowed,I as isSplitResize,K as nextVisible,D as paintDragMergeGrip,Y as parseSizeSpec,h as removeSplit,y as setAxisSizing,v as setTrailing,X as splitBarHit,N as splitResize,$ as toggleSplit};