@8sheets/data-grid 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/api/serialize.js +1 -1
- package/api/theme-core.js +2 -0
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.js +1 -1
- package/calcx/async.js +1 -1
- package/calcx/culture/custom.js +1 -0
- package/calcx/culture/format-locale.js +1 -1
- package/calcx/culture/separators.js +1 -0
- package/calcx/functions/dynamic.js +1 -1
- package/calcx/functions/ets.js +1 -1
- package/calcx/functions/misc.js +1 -1
- package/calcx/lang/convert.js +1 -0
- package/cells/axis-ops.js +1 -1
- package/cells/block.js +1 -0
- package/cells/book-css.js +2 -2
- package/cells/cell-defaults.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/consolidate-links.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/format-panes.js +3 -3
- package/cells/format-tabs.js +2 -2
- package/cells/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/rich-runs.js +2 -2
- package/cells/rich-values.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/cells/shift-check.js +1 -0
- package/cells/table-rows.js +1 -0
- package/cells/text-layout.js +9 -8
- package/cells/ui-kit.js +15 -0
- package/cells/view-options.js +1 -1
- package/celltypes/cell-types.js +2 -2
- package/celltypes/diagonal.js +1 -1
- package/celltypes/dropdowns.js +3 -2
- package/celltypes/file-cell.js +2 -2
- package/celltypes/range-template.js +2 -2
- package/core/autofill.js +1 -1
- package/core/axis-styles.js +1 -0
- package/core/axis.js +1 -1
- package/core/cell-type-rules.js +1 -0
- package/core/changes.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -0
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/merge.js +1 -0
- package/core/numfmt.js +1 -1
- package/core/region-input.js +1 -0
- package/core/row-fit.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparse.js +1 -1
- package/core/structure.js +1 -0
- package/core/styles.js +1 -1
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -0
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/data-core.js +1 -1
- package/datasheets/gantt-paint.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/path-binding.js +2 -2
- package/datasheets/rules.js +1 -1
- package/datasheets/view.js +2 -2
- package/i18n/dom.js +1 -1
- package/i18n/en/cells.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/shell.js +2 -2
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/shell.js +2 -2
- package/io/client.js +1 -1
- package/io/csv.js +8 -8
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-write.js +1 -1
- package/io/xml-scan.js +2 -1
- package/io/zip-reader.js +1 -1
- package/objects/chart-model.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/paginate.js +1 -1
- package/print/render-page.js +3 -3
- package/slicers/format.js +2 -2
- package/slicers/structured.js +1 -1
- package/table-view/api.js +1 -1
- package/table-view/cell-editor.js +2 -1
- package/table-view/chart.js +1 -0
- package/table-view/column-drag.js +1 -1
- package/table-view/context-menu.js +1 -0
- package/table-view/editors.js +1 -0
- package/table-view/events.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/fill-handle.js +1 -0
- package/table-view/filter-builder.js +1 -0
- package/table-view/find.js +1 -0
- package/table-view/grid-keys.js +2 -2
- package/table-view/labels-de.js +1 -0
- package/table-view/labels-es.js +1 -0
- package/table-view/labels-fr.js +1 -0
- package/table-view/labels-ja.js +1 -0
- package/table-view/labels.js +1 -1
- package/table-view/model.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/panel.js +1 -1
- package/table-view/pivot-spec.js +1 -0
- package/table-view/pivot.js +1 -1
- package/table-view/public.d.ts +277 -28
- package/table-view/reader.worker.js +1 -1
- package/table-view/remote.js +1 -1
- package/table-view/row-drag.js +1 -0
- package/table-view/sparkline.js +1 -0
- package/table-view/state-check.js +1 -0
- package/table-view/table-css.js +380 -0
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/core/numfmt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{calendarParts as X,dbnumDigits as Z,dbnumPlaces as H,eraAt as R,erasOf as P,hijriLocale as K,localeData as Q,mapDigits as V,numeralDigits as v,parseLocaleBracket as ee}from"../calcx/culture/format-locale.js";const y={decimal:".",group:",",months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortMonths:null,shortDays:null,shortDate:"m/d/yyyy",longDate:"dddd, mmmm d, yyyy",longTime:"h:mm:ss AM/PM",amDesignator:"AM",pmDesignator:"PM",tag:null,eras:null,numerals:null};function ge(t){Object.assign(y,t),G.clear()}const D="",be={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yyyy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yyyy h:mm",37:"#,##0_);(#,##0)",38:"#,##0_);[Red](#,##0)",39:"#,##0.00_);(#,##0.00)",40:"#,##0.00_);[Red](#,##0.00)",41:'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',42:'_($* #,##0_);_($* \\(#,##0\\);_($* "-"_);_(@_)',43:'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',44:'_($* #,##0.00_);_($* \\(#,##0.00\\);_($* "-"??_);_(@_)',45:"mm:ss",46:"[h]:mm:ss",47:"mm:ss.0",48:"##0.0E+0",49:"@"},B={black:"#000000",blue:"#0000FF",cyan:"#00FFFF",green:"#00FF00",magenta:"#FF00FF",red:"#FF0000",white:"#FFFFFF",yellow:"#FFFF00"},te=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"];function U(t){const s=[[]];let n=s[0];const o=e=>{const i=n[n.length-1];i&&i.k==="lit"?i.s+=e:n.push({k:"lit",s:e})};for(let e=0;e<t.length;e++){const i=t[e];if((i==="G"||i==="g")&&t.slice(e,e+7).toLowerCase()==="general"){o("General"),e+=6;continue}switch(i){case";":n=[],s.push(n);break;case'"':{const a=t.indexOf('"',e+1);o(a<0?t.slice(e+1):t.slice(e+1,a)),e=a<0?t.length:a;break}case"\\":e+1<t.length&&o(t[++e]);break;case"_":e++,o(" ");break;case"*":n.push({k:"fill",c:t[++e]??" "});break;case"[":{const a=t.indexOf("]",e);if(a<0){o(i);break}const l=t.slice(e+1,a);e=a;const f=l.toLowerCase();if(/^dbnum[1-4]$/.test(f)){n.push({k:"dbnum",n:Number(f[5])});break}if(/^h+$/.test(f)||/^m+$/.test(f)||/^s+$/.test(f))n.push({k:"elapsed",c:f[0],n:f.length});else if(B[f])n.push({k:"color",v:B[f]});else if(/^color\s*\d+$/.test(f)){const d=te[Number(f.replace(/\D/g,""))-1];d&&n.push({k:"color",v:`#${d}`})}else if(/^(<=|>=|<>|<|>|=)\s*-?[\d.]+/.test(l)){const d=/^(<=|>=|<>|<|>|=)\s*(-?[\d.]+(?:[eE][+-]?\d+)?)/.exec(l);n.push({k:"cond",op:d[1],v:Number(d[2])})}else if(l[0]==="$"){const d=ee(l);d?.currency&&o(d.currency),d&&(d.tag||d.calendar||d.numerals||d.system||d.gannen)&&n.push({k:"loc",info:d})}break}case"@":n.push({k:"text"});break;case"#":case"0":case"?":n.push({k:"d",c:i});break;case".":n.push({k:"point"});break;case",":n.push({k:"comma"});break;case"%":n.push({k:"pct"});break;case"/":n.push({k:"slash"});break;case"E":case"e":{const a=t[e+1];if((a==="+"||a==="-")&&/[0#?]/.test(t[e+2]??""))n.push({k:"exp",plus:a==="+",upper:i==="E"}),e++;else if(i==="e"){let l=1;for(;t[e+l]==="e";)l++;n.push({k:"date",c:"e",n:l}),e+=l-1}else o(i);break}case"y":case"Y":case"m":case"M":case"d":case"D":case"h":case"H":case"s":case"S":{const a=i.toLowerCase();let l=1;for(;t[e+l]?.toLowerCase()===a;)l++;n.push({k:"date",c:a,n:l}),e+=l-1;break}case"g":case"G":case"b":case"B":{const a=i.toLowerCase();if(a==="b"&&t[e+1]==="2"){n.push({k:"hijri"}),e++;break}let l=1;for(;t[e+l]?.toLowerCase()===a;)l++;n.push({k:"date",c:a,n:l}),e+=l-1;break}case"A":case"a":{const a=t.slice(e,e+5).toUpperCase();if(/^AAA/.test(a)){let l=3;for(;t[e+l]?.toLowerCase()==="a";)l++;n.push({k:"date",c:"a",n:l}),e+=l-1}else a==="AM/PM"?(n.push({k:"ampm",long:!0}),e+=4):a.startsWith("A/P")?(n.push({k:"ampm",long:!1,lower:i==="a"}),e+=2):o(i);break}default:o(i)}}return s}function se(t){const s={tokens:t,color:null,cond:null,isDate:!1,isText:!1,isNum:!1,isGeneral:!1},n=[];for(const e of t)e.k==="color"?s.color=e.v:e.k==="cond"?s.cond=e:e.k==="loc"?s.loc=e.info:e.k==="dbnum"?s.dbnum=e.n:e.k==="hijri"?s.hijri=!0:n.push(e);if(s.loc?.system){n.length=0;for(const e of U(s.loc.system==="date"?y.longDate:y.longTime)[0])n.push(e)}s.tokens=n;const o=n.filter(e=>e.k==="lit").map(e=>e.s).join("");if(s.isDate=n.some(e=>e.k==="date"||e.k==="elapsed"||e.k==="ampm"),s.isText=n.some(e=>e.k==="text"),s.isNum=!s.isDate&&n.some(e=>e.k==="d"),/general/i.test(o)){s.isGeneral=!0;for(const e of n)e.k==="lit"&&(e.s=e.s.replace(/general/i,""))}return s.isDate?oe(s):s.isNum&&le(s),s.digits=ie(s),s}const ne=t=>t.op==="<"&&t.v<=0||t.op==="<="&&t.v<0||t.op==="="&&t.v<0;function q(t,s){const n=I(s);return t.dbnum?H(n,t.dbnum,t.loc?.tag??y.tag)??n:n}function ie(t){if(t.dbnum){const s=Z(t.dbnum,t.loc?.tag??y.tag);if(s)return s}return t.loc?.numerals>1?v(t.loc.numerals):y.numerals??null}function oe(t){if(t.tokens.some(e=>e.k==="date"&&e.c==="g")&&P(t.loc,y)){let e=!1;for(const i of t.tokens)i.k==="date"&&i.c==="g"?e=!0:e&&i.k==="date"&&i.c==="y"&&(i.c="e",i.n=2)}const s=t.tokens;let n=null;for(let e=0;e<s.length;e++){const i=s[e];if(i.k==="date"&&i.c==="m"&&i.n<=2){let a=null;for(let l=e+1;l<s.length;l++)if(s[l].k!=="lit"){a=s[l];break}(n==="h"||a&&a.k==="date"&&a.c==="s"||a&&a.k==="elapsed"&&a.c==="s")&&(i.c="n"),n=null}else i.k==="date"&&i.c==="h"||i.k==="elapsed"&&i.c==="h"?n="h":(i.k==="date"||i.k==="elapsed")&&(n=null)}t.hour12=s.some(e=>e.k==="ampm"),t.subDigits=0;const o=[];for(let e=0;e<s.length;e++){const i=s[e];if(i.k==="point"&&s[e+1]?.k==="d"){let a=0;for(;s[e+1+a]?.k==="d";)a++;o.push({k:"sub",n:a}),t.subDigits=Math.max(t.subDigits,a),e+=a}else i.k==="point"?o.push({k:"lit",s:"."}):i.k==="slash"?o.push({k:"lit",s:"/"}):i.k==="comma"?o.push({k:"lit",s:","}):i.k==="d"?o.push({k:"lit",s:i.c}):i.k==="pct"?o.push({k:"lit",s:"%"}):o.push(i)}t.tokens=o}function le(t){const s=t.tokens;let n=-1,o=-1,e=-1,i=-1,a=-1;s.forEach((c,k)=>{c.k==="d"?(o<0&&(o=k),n=k):c.k==="point"&&e<0?e=k:c.k==="exp"&&i<0?i=k:c.k==="slash"&&a<0&&o>=0&&(a=k)});let l=0,f=0,d=!1;const b=[];for(let c=0;c<s.length;c++){const k=s[c];if(k.k==="pct")l++,b.push({k:"lit",s:"%"});else if(k.k==="comma"){let m=!1;for(let h=c+1;h<s.length;h++){if(s[h].k==="d"){m=!0;break}if(s[h].k!=="comma")break}m&&c>o&&(e<0||c<e)?d=!0:c>o&&c<=n+8&&!m?f++:b.push({k:"lit",s:","})}else k.k==="slash"&&c!==a?b.push({k:"lit",s:"/"}):k.k==="point"&&c!==e?b.push({k:"lit",s:"."}):b.push(k)}t.tokens=b,t.pct=l,t.scale=f,t.grouping=d,t.fraction=a>=0,t.scientific=i>=0;let u="int";const p={int:0,dec:0,exp:0,num:0,den:0};let g="";for(const c of b)c.k==="point"?u="dec":c.k==="exp"?u="exp":c.k==="slash"?u="den":c.k==="d"?(c.part=u,p[u]++,u==="den"&&(g+=c.c)):c.k==="lit"&&u==="den"&&/^\d+$/.test(c.s)&&(g+=c.s);if(t.fraction){let k=b.findIndex(h=>h.k==="slash")-1,m=!1;for(;k>=0;){const h=b[k];if(h.k==="d")h.part="num",p.num++,p.int--,m=!0;else if(m)break;k--}t.fixedDen=/^\d+$/.test(g)?Number(g):0,t.denDigits=p.den}t.counts=p}function j(t,s){if(Number.isInteger(t)&&t<1e15)return{int:t===0?"":String(t),dec:"0".repeat(s)};const n=t.toExponential(14),o=n.indexOf("e"),e=n[0]+n.slice(2,o),a=Number(n.slice(o+1))+1+s;let l,f=!1;if(a<0?l="":a>=e.length?l=e+"0".repeat(a-e.length):(f=e.charCodeAt(a)>=53,l=e.slice(0,a)),f){let g=l.length-1;const c=l.split("");for(;g>=0;)if(c[g]==="9")c[g]="0",g--;else{c[g]=String.fromCharCode(c[g].charCodeAt(0)+1);break}l=c.join(""),g<0&&(l="1"+l)}const b=l.length-s;let u,p;return b<=0?(u="",p="0".repeat(-b)+l):(u=l.slice(0,b),p=l.slice(b)),u=u.replace(/^0+/,""),{int:u,dec:p}}function ae(t){if(t.length<=3)return t;let s="",n=t.length%3;for(n>0&&(s=t.slice(0,n));n<t.length;n+=3)s+=(s?y.group:"")+t.slice(n,n+3);return s}function re(t,s){if(s.fixedDen>0)return[Math.round(t*s.fixedDen),s.fixedDen];const n=10**s.denDigits-1;let[o,e,i,a]=[0,1,1,0],l=t;for(let f=0;f<32;f++){const d=Math.floor(l),b=d*i+o,u=d*a+e;if(u>n)break;[o,e,i,a]=[i,a,b,u];const p=l-d;if(p<1e-10)break;l=1/p}return[i,a||1]}function ce(t,s){let n=s;t.pct&&(n*=100**t.pct),t.scale&&(n/=1e3**t.scale);const{counts:o}=t;let e="",i="",a="",l=!1,f="",d="";if(t.fraction){const r=o.int>0?Math.floor(n):0,[F,M]=re(n-r,t);let S=r,w=F;w===M&&o.int>0&&(S+=1,w=0),e=S===0?w===0&&o.int>0?"0":"":String(S),f=w===0&&o.int>0?"":String(w),d=w===0&&o.int>0?"":String(M)}else if(t.scientific){let r=n===0?0:Math.floor(Math.log10(n));const F=Math.max(o.int,1);F>1&&(r=Math.floor(r/F)*F);let M=j(n/10**r,o.dec);M.int.length>F&&(r+=F>1?F:1,M=j(n/10**r,o.dec)),e=n===0&&F>1?"0".repeat(F):M.int,i=M.dec,l=r<0,a=String(Math.abs(r))}else{const r=j(n,o.dec);e=r.int,i=r.dec}let b=i.length,u="";const p=t.tokens,g=[];for(const r of p)r.k==="d"&&r.part==="int"&&g.push(r);const c=new Map;let k=e.length-1;for(let r=g.length-1;r>=0;r--){const F=g[r];if(k>=0){let M=e[k--];r===0&&k>=0&&(M=e.slice(0,k+1)+M,k=-1),c.set(F,M)}else c.set(F,F.c==="0"?"0":F.c==="?"?" ":"")}if(t.grouping&&g.length){let r="";for(const S of g)r+=c.get(S);const F=/^ */.exec(r)[0],M=ae(r.slice(F.length));c.forEach((S,w)=>c.set(w,"")),c.set(g[0],F+M)}const m=[];for(const r of p)r.k==="d"&&r.part==="dec"&&m.push(r);for(let r=m.length-1;r>=0&&!(m[r].c==="0"||i[r]!=="0");r--)b=r;let h=0,C=0;const x=p.filter(r=>r.k==="d"&&r.part==="exp").length,$=a.padStart(x,"0");let L=0;const O=p.filter(r=>r.k==="d"&&r.part==="num").length,T=f.padStart(O," ");let A=0;const N=p.filter(r=>r.k==="d"&&r.part==="den").length,E=d.padEnd(N," "),W=t.fraction&&f==="";for(const r of p)switch(r.k){case"lit":u+=r.s===""?"":r.s;break;case"fill":u+=D+r.c+D;break;case"point":g.length===0&&!t.fraction&&!t.scientific&&e!=="0"&&!u.includes(y.decimal)&&(u+=e),u+=y.decimal;break;case"exp":u+=(r.upper?"E":"e")+(l?"-":r.plus?"+":"");break;case"slash":u+=W?" ":"/";break;case"d":switch(r.part){case"int":u+=c.get(r);break;case"dec":{const F=h++;F<b?u+=i[F]:r.c==="?"?u+=" ":r.c==="0"&&(u+="0");break}case"exp":C===0&&(u+=$),C++;break;case"num":{L===0?u+=T.slice(0,T.length-O+1):u+=T[T.length-O+L],L++;break}case"den":{A<N&&(u+=E[A]),A++,A===N&&E.length>N&&(u+=E.slice(N));break}default:}break;default:}return u}function fe(t){let s=Math.floor(t),n=t-s,o=Math.round(n*864e5);o>=864e5&&(s+=1,o-=864e5);let e,i,a;if(s===0)e=1900,i=1,a=0;else if(s===60)e=1900,i=2,a=29;else{const f=(s<60?s+1:s)-25569+719468,d=Math.floor(f/146097),b=f-d*146097,u=Math.floor((b-Math.floor(b/1460)+Math.floor(b/36524)-Math.floor(b/146096))/365),p=b-(365*u+Math.floor(u/4)-Math.floor(u/100)),g=Math.floor((5*p+2)/153);a=p-Math.floor((153*g+2)/5)+1,i=g<10?g+3:g-9,e=u+d*400+(i<=2?1:0)}const l=s===0?6:(s-1)%7;return{year:e,month:i,day:a,weekday:l,ms:o,serial:t}}function Fe(t,s){const n=t.trim().split(/[^0-9]+/).filter(Boolean).map(Number);if(n.length!==3)return null;const o=f=>n[s.indexOf(f)];let e=o("Y");const i=o("M"),a=o("D");if(e<100&&(e+=e<30?2e3:1900),!(i>=1&&i<=12&&a>=1&&a<=new Date(Date.UTC(e,i,0)).getUTCDate()))return null;const l=ue(e,i,a);return Number.isFinite(l)?l:null}function ue(t,s,n){const o=s<=2?t-1:t,e=s<=2?s+9:s-3,i=Math.floor(o/400),a=o-i*400,l=Math.floor((153*e+2)/5)+n-1,f=a*365+Math.floor(a/4)-Math.floor(a/100)+l,d=i*146097+f-719468+25569;return d<61?d-1:d}const _=t=>t<10?"0"+t:String(t);function J(t,s){const n=86400*10**(t.subDigits??0);s=Math.round(s*n)/n;const o=fe(s),e=o.ms;let i=Math.floor(e/1e3);const a=e-i*1e3;let l="";t.subDigits>0?(l=(a/1e3).toFixed(t.subDigits).slice(2),l.length===0&&(l="")):a>=500&&(i+=1);let f=Math.floor(i/3600);const d=Math.floor(i%3600/60),b=i%60;f>=24&&(f=23);const u=t.hour12?f%12===0?12:f%12:f,{loc:p}=t,g=t.hijri&&!p?.tag,c=p?.tag?Q(p.tag):g?K():y,k=p?.calendar||g?X(g?"hijri":p.calendar,s,o,p?.tag??null)??o:o;let m="";for(const h of t.tokens)switch(h.k){case"lit":m+=h.s;break;case"fill":m+=D+h.c+D;break;case"date":switch(h.c){case"y":m+=h.n<=2?_(k.year%100):String(k.year);break;case"e":{const C=P(p,y);if(C===null){m+=String(k.year);break}const x=o.year-R(C,s).firstYear+1;x===1&&p?.gannen?m+="元":m+=h.n===1?x:_(x);break}case"g":{const C=P(p,y);if(C===null)break;const x=R(C,s);m+=h.n===1?x.symbol:h.n===2?x.abbreviation:x.name;break}case"b":{const C=p?.tag?o.year:o.year+543;m+=h.n<=2?_(C%100):String(C);break}case"a":m+=h.n===3?c.shortDays?.[o.weekday]??c.days[o.weekday].slice(0,3):c.days[o.weekday];break;case"m":h.n===1?m+=k.month:h.n===2?m+=_(k.month):k.monthName?m+=h.n===5?k.monthName[0]:k.monthName:h.n===3?m+=c.shortMonths?.[k.month-1]??c.months[k.month-1].slice(0,3):h.n===5?m+=c.months[k.month-1][0]:m+=c.months[k.month-1];break;case"d":h.n===1?m+=k.day:h.n===2?m+=_(k.day):h.n===3?m+=c.shortDays?.[o.weekday]??c.days[o.weekday].slice(0,3):m+=c.days[o.weekday];break;case"h":m+=h.n===1?u:_(u);break;case"n":m+=h.n===1?d:_(d);break;case"s":m+=h.n===1?b:_(b);break;default:}break;case"elapsed":{const x=Math.floor(s)*86400+i,$=h.c==="h"?Math.floor(x/3600):h.c==="m"?Math.floor(x/60):x;m+=String($).padStart(h.n,"0");break}case"ampm":h.long?m+=f<12?p?.tag?c.am:y.amDesignator:p?.tag?c.pm:y.pmDesignator:m+=h.lower?f<12?"a":"p":f<12?"A":"P";break;case"sub":m+=y.decimal+l.slice(0,h.n);break;default:}return m}function I(t,s=11){if(t===0)return"0";const n=Math.abs(t);let o;if(Number.isInteger(t)&&n<1e11)o=String(t);else if(n>=1e11||n<1e-9){const e=t.toExponential(Math.max(s-6,0)),i=e.indexOf("e");let a=e.slice(0,i);a.includes(".")&&(a=a.replace(/\.?0+$/,""));const l=Number(e.slice(i+1)),f=Math.abs(l);o=`${a}E${l<0?"-":"+"}${f<10?"0":""}${f}`}else{const e=n>=1?Math.floor(Math.log10(n))+1:1,i=Math.max(s-e-(n<1?1:0),0),a=n<1?-Math.floor(Math.log10(n))-1:0;o=Number(t.toPrecision(15)).toFixed(Math.min(Math.max(i,0),20)),a>=i&&i>=0&&Number(o)===0&&(o=t.toExponential(s-6)),o.includes(".")&&(o=o.replace(/\.?0+$/,""))}return y.decimal==="."?o:o.replace(".",y.decimal)}class he{constructor(s){this.code=s;const n=U(s);this.sections=n.slice(0,4).map(se);const o=this.sections[0];if(this.general=this.sections.length===1&&o.isGeneral&&!o.dbnum&&o.tokens.every(e=>e.k==="lit"&&e.s===""),this.isDate=this.sections.some(e=>e.isDate),this.isText=this.sections.length===1&&o.isText,this.sections.some(e=>e.digits)){const e=this.number;this.number=i=>{const a=this.sections[this._pick(i)],l=e.call(this,i);return a.digits?V(l,a.digits):l}}}_pick(s){const n=this.sections;if(n[0].cond!==null||n[1]&&n[1].cond!==null){for(let i=0;i<Math.min(n.length,3);i++){const a=n[i].cond;if(a===null){if(i===n.length-1||i===2||n[i].isText&&i===3)return i;continue}if(ke(a,s))return i}return Math.min(n.length-1,2)}const e=n.length>1&&n.length<4&&n[n.length-1].isText?n.length-1:n.length;return e===1?0:e===2?s<0?1:0:s>0?0:s<0?1:2}number(s){if(this.general)return I(s);const n=this._pick(s),o=this.sections[n],e=this.sections[0].cond!==null||this.sections[1]&&this.sections[1].cond!==null,i=s<0&&(o.cond!==null?!ne(o.cond):n===0||e);if(o.isDate){const l=s<0&&n>0?-s:s;return Y(o,l)?"#".repeat(8):l<0?`-${J(o,-l)}`:J(o,l)}if(o.isNum){const l=ce(o,Math.abs(s));return i&&de(l)?"-"+l:l}if(o.isGeneral){let l="";for(const f of o.tokens)f.k==="lit"?l+=f.s===""?q(o,Math.abs(s)):f.s.replace("",q(o,Math.abs(s))):f.k==="fill"&&(l+=D+f.c+D);return s<0&&n===0?"-"+l:l}let a=i?"-":"";for(const l of o.tokens)l.k==="lit"?a+=l.s:l.k==="fill"?a+=D+l.c+D:l.k==="pct"?a+="%":l.k==="text"&&(a+=I(Math.abs(s)));return a}dateOverflow(s){if(this.general)return!1;const n=this._pick(s),o=this.sections[n];return!!o.isDate&&Y(o,s<0&&n>0?-s:s)}text(s){const n=this.sections,o=n.length===4?n[3]:n.length===1&&n[0].isText?n[0]:null;if(o===null)return s;let e="";for(const i of o.tokens)i.k==="lit"?e+=i.s:i.k==="text"?e+=s:i.k==="fill"&&(e+=D+i.c+D);return e}color(s){return this.sections[this._pick(s)].color}}const me=2958466;function Y(t,s){return t.tokens.some(o=>o.k==="date"||o.k==="ampm")?s<0||s>=me:!1}function de(t){for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);if(n>=49&&n<=57)return!0}return!1}function ke(t,s){switch(t.op){case"<":return s<t.v;case"<=":return s<=t.v;case">":return s>t.v;case">=":return s>=t.v;case"=":return s===t.v;default:return s!==t.v}}const G=new Map;function z(t){let s=G.get(t);return s===void 0&&(s=new he(t==="m/d/yyyy"?y.shortDate:t==="m/d/yyyy h:mm"?`${y.shortDate} h:mm`:t),G.set(t,s)),s}function ye(t,s){return z(t).number(s)}function xe(t){return z("#,##0").number(t)}export{be as BUILTIN_FORMATS,D as FILL_MARK,Fe as dateSerial,xe as formatCount,I as formatGeneral,ye as formatNumber,z as getFormatter,ue as partsToSerial,fe as serialToParts,ge as setNumberLocale};
|
|
1
|
+
import{calendarParts as K,dbnumDigits as Z,dbnumPlaces as Q,eraAt as R,erasOf as O,hijriLocale as V,localeData as v,mapDigits as ee,numeralDigits as te,parseLocaleBracket as ne}from"../calcx/culture/format-locale.js";const C={decimal:".",group:",",months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthsWithDay:null,shortMonths:null,shortDays:null,shortDate:"m/d/yyyy",longDate:"dddd, mmmm d, yyyy",longTime:"h:mm:ss AM/PM",amDesignator:"AM",pmDesignator:"PM",tag:null,eras:null,numerals:null};function ye(e){Object.assign(C,e),W.clear()}const N="",Me="[$-F800]dddd, mmmm d, yyyy",De={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yyyy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yyyy h:mm",37:"#,##0_);(#,##0)",38:"#,##0_);[Red](#,##0)",39:"#,##0.00_);(#,##0.00)",40:"#,##0.00_);[Red](#,##0.00)",41:'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',42:'_($* #,##0_);_($* \\(#,##0\\);_($* "-"_);_(@_)',43:'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',44:'_($* #,##0.00_);_($* \\(#,##0.00\\);_($* "-"??_);_(@_)',45:"mm:ss",46:"[h]:mm:ss",47:"mm:ss.0",48:"##0.0E+0",49:"@"},q={black:"#000000",blue:"#0000FF",cyan:"#00FFFF",green:"#00FF00",magenta:"#FF00FF",red:"#FF0000",white:"#FFFFFF",yellow:"#FFFF00"},se=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"];function B(e){const n=[[]];let s=n[0];const l=t=>{const o=s[s.length-1];o&&o.k==="lit"?o.s+=t:s.push({k:"lit",s:t})};for(let t=0;t<e.length;t++){const o=e[t];if((o==="G"||o==="g")&&e.slice(t,t+7).toLowerCase()==="general"){l("General"),t+=6;continue}switch(o){case";":s=[],n.push(s);break;case'"':{const a=e.indexOf('"',t+1);l(a<0?e.slice(t+1):e.slice(t+1,a)),t=a<0?e.length:a;break}case"\\":t+1<e.length&&l(e[++t]);break;case"_":t++,l(" ");break;case"*":s.push({k:"fill",c:e[++t]??" "});break;case"[":{const a=e.indexOf("]",t);if(a<0){l(o);break}const i=e.slice(t+1,a);t=a;const r=i.toLowerCase();if(/^dbnum[1-4]$/.test(r)){s.push({k:"dbnum",n:Number(r[5])});break}if(/^h+$/.test(r)||/^m+$/.test(r)||/^s+$/.test(r))s.push({k:"elapsed",c:r[0],n:r.length});else if(q[r])s.push({k:"color",v:q[r]});else if(/^color\s*\d+$/.test(r)){const u=se[Number(r.replace(/\D/g,""))-1];u&&s.push({k:"color",v:`#${u}`})}else if(/^(<=|>=|<>|<|>|=)\s*-?[\d.]+/.test(i)){const u=/^(<=|>=|<>|<|>|=)\s*(-?[\d.]+(?:[eE][+-]?\d+)?)/.exec(i);s.push({k:"cond",op:u[1],v:Number(u[2])})}else if(i[0]==="$"){const u=ne(i);u?.currency&&l(u.currency),u&&(u.tag||u.calendar||u.numerals||u.system||u.gannen)&&s.push({k:"loc",info:u})}break}case"@":s.push({k:"text"});break;case"#":case"0":case"?":s.push({k:"d",c:o});break;case".":s.push({k:"point"});break;case",":s.push({k:"comma"});break;case"%":s.push({k:"pct"});break;case"/":s.push({k:"slash"});break;case"E":case"e":{const a=e[t+1];if(a==="+"||a==="-")s.push({k:"expCandidate",plus:a==="+",upper:o==="E"}),t++;else if(o==="e"){let i=1;for(;e[t+i]==="e";)i++;s.push({k:"date",c:"e",n:i}),t+=i-1}else l(o);break}case"y":case"Y":case"m":case"M":case"d":case"D":case"h":case"H":case"s":case"S":{const a=o.toLowerCase();let i=1;for(;e[t+i]?.toLowerCase()===a;)i++;s.push({k:"date",c:a,n:i}),t+=i-1;break}case"n":case"N":s.push({k:"lit",s:o,invalidTextFormat:!0});break;case"g":case"G":case"b":case"B":{const a=o.toLowerCase();if(a==="b"&&e[t+1]==="2"){s.push({k:"hijri"}),t++;break}let i=1;for(;e[t+i]?.toLowerCase()===a;)i++;s.push({k:"date",c:a,n:i}),t+=i-1;break}case"A":case"a":case"Å":case"å":{const a=e.slice(t,t+5).toUpperCase();if(/^(?:AAA|ÅÅÅ)/.test(a)){const i=o.toLowerCase();let r=3;for(;e[t+r]?.toLowerCase()===i;)r++;s.push({k:"date",c:"a",n:r}),t+=r-1}else a==="AM/PM"?(s.push({k:"ampm",long:!0}),t+=4):a.startsWith("A/P")?(s.push({k:"ampm",long:!1,lower:o==="a"}),t+=2):l(o);break}default:l(o)}}return n}function ie(e){const n={tokens:e,color:null,cond:null,isDate:!1,isText:!1,isNum:!1,isGeneral:!1},s=[];for(const t of e)t.invalidTextFormat&&(n.invalidTextFormat=!0),t.k==="color"?n.color=t.v:t.k==="cond"?n.cond=t:t.k==="loc"?n.loc=t.info:t.k==="dbnum"?n.dbnum=t.n:t.k==="hijri"?n.hijri=!0:s.push(t);if(n.loc?.system){s.length=0;for(const t of B(n.loc.system==="date"?C.longDate:C.longTime)[0])s.push(t)}n.tokens=s;for(let t=0;t<s.length;t++){const o=s[t];if(o.k==="expCandidate")if(s.slice(0,t).some(a=>a.k==="d")&&s.slice(t+1).some(a=>a.k==="d"))o.k="exp",o.upper||(n.invalidTextFormat=!0);else{const a=o.plus?"+":"-",i=o.upper?[{k:"lit",s:"E"+a}]:[{k:"date",c:"e",n:1},{k:"lit",s:a}];s.splice(t,1,...i)}}const l=s.filter(t=>t.k==="lit").map(t=>t.s).join("");if(n.isDate=s.some(t=>t.k==="date"||t.k==="elapsed"||t.k==="ampm"),n.isText=s.some(t=>t.k==="text"),n.isNum=!n.isDate&&s.some(t=>t.k==="d"),/general/i.test(l)){n.isGeneral=!0;for(const t of s)t.k==="lit"&&(t.s=t.s.replace(/general/i,""))}return n.isDate?le(n):n.isNum&&re(n),n.digits=ae(n),n}const oe=e=>e.op==="<"&&e.v<=0||e.op==="<="&&e.v<0||e.op==="="&&e.v<0;function U(e,n){const s=P(n);return e.dbnum?Q(s,e.dbnum,e.loc?.tag??C.tag)??s:s}function ae(e){if(e.dbnum){const n=Z(e.dbnum,e.loc?.tag??C.tag);if(n)return n}return e.loc?.numerals>1?te(e.loc.numerals):C.numerals??null}function le(e){if(e.tokens.some(a=>a.k==="date"&&a.c==="g")&&O(e.loc,C)){let a=!1;for(const i of e.tokens)i.k==="date"&&i.c==="g"?a=!0:a&&i.k==="date"&&i.c==="y"&&(i.c="e",i.n=2)}const n=e.tokens;let s=null;const l=new Set;let t=!1;for(let a=0;a<n.length;a++){const i=n[a];if(i.k==="date"&&i.c==="m"&&i.n<=2){let r=null;for(let u=a+1;u<n.length;u++)if(n[u].k!=="lit"){r=n[u];break}(s==="h"||s==="s"||(r?.k==="date"||r?.k==="elapsed")&&r.c==="s")&&(i.c="n"),s=null}else(i.k==="date"||i.k==="elapsed")&&(s=i.c==="h"||i.c==="s"?i.c:null);if(i.k==="elapsed")t&&(i.c==="h"||i.c==="m")&&(i.afterSeconds=!0),l.add(i.c);else if(i.k==="date"){i.c==="s"&&(t=!0);const r=i.c==="n"?"m":i.c;l.has(r)&&(i.k="elapsed",i.c=r)}}e.hasDay=n.some(a=>a.k==="date"&&a.c==="d"&&a.n<=2),e.hasCalendar=n.some(a=>a.k==="date"&&"ymdageb".includes(a.c)),e.hour12=n.some(a=>a.k==="ampm"),e.subDigits=0;const o=[];for(let a=0;a<n.length;a++){const i=n[a];if(i.k==="point"&&n[a+1]?.k==="d"){let r=0;for(;n[a+1+r]?.k==="d";)r++;o.push({k:"sub",n:r}),e.subDigits=Math.max(e.subDigits,r),a+=r}else i.k==="point"?o.push({k:"lit",s:"."}):i.k==="slash"?o.push({k:"lit",s:"/"}):i.k==="comma"?o.push({k:"lit",s:","}):i.k==="d"?o.push({k:"lit",s:i.c}):i.k==="pct"?o.push({k:"lit",s:"%"}):o.push(i)}e.tokens=o}function re(e){const n=e.tokens;let s=-1,l=-1,t=-1,o=-1,a=-1;n.forEach((c,b)=>{c.k==="d"?(l<0&&(l=b),s=b):c.k==="point"&&t<0?t=b:c.k==="exp"&&o<0?o=b:c.k==="slash"&&a<0&&l>=0&&(a=b)});let i=0,r=0,u=!1;const m=[];for(let c=0;c<n.length;c++){const b=n[c];if(b.k==="pct")i++,m.push({k:"lit",s:"%"});else if(b.k==="comma"){let M=!1;for(let y=c+1;y<n.length;y++){if(n[y].k==="d"){M=!0;break}if(n[y].k!=="comma")break}if(M&&c>l&&(t<0||c<t))u=!0;else{if(M&&t>=0&&c>t&&(o<0||c<o))continue;c>l&&c<=s+8&&!M?r++:m.push({k:"lit",s:","})}}else b.k==="slash"&&c!==a?m.push({k:"lit",s:"/"}):b.k==="point"&&c!==t?m.push({k:"lit",s:"."}):m.push(b)}e.tokens=m,e.pct=i,e.scale=r,e.grouping=u,e.fraction=a>=0,e.scientific=o>=0,e.exponentPlus=o>=0&&n[o].plus;let h="int";const x={int:0,dec:0,exp:0,num:0,den:0};let F="";for(const c of m)c.k==="point"?h="dec":c.k==="exp"?h="exp":c.k==="slash"?h="den":c.k==="d"?(c.part=h,x[h]++,h==="den"&&(F+=c.c)):c.k==="lit"&&h==="den"&&/^\d+$/.test(c.s)&&(F+=c.s);if(e.fraction){const c=m.findIndex(d=>d.k==="slash");let b=c-1,M=!1;for(;b>=0;){const d=m[b];if(d.k==="d")d.part="num",x.num++,x.int--,M=!0;else if(M)break;b--}e.fixedDen=/^\d+$/.test(F)?Number(F):0,e.denDigits=x.den;const y=m.findLastIndex(d=>d.k==="d"&&d.part==="int"),p=m.findIndex(d=>d.k==="d"&&d.part==="num"),k=m.findLastIndex((d,$)=>$>c&&(d.k==="d"&&d.part==="den"||e.fixedDen&&d.k==="lit"&&/^\d+$/.test(d.s))),_=y<0?p:y+1,w=Math.max(k,c),T=m.slice(_,w+1);e.fractionParts={start:_,end:w,numStart:p,always:T.some(d=>d.part==="num"&&d.c==="0"),pad:m.some(d=>d.k==="d"&&d.c==="?"),width:T.reduce((d,$)=>d+($.k==="lit"?$.s.length:1),0),padWhole:y>=0&&m.slice(0,y+1).some(d=>d.k==="d"&&d.c==="?"),requiredWhole:y>=0&&m.slice(0,y+1).some(d=>d.k==="d"&&d.c==="0"),padNumerator:T.some(d=>d.part==="num"&&d.c==="?"),padDen:T.some(d=>d.part==="den"&&d.c==="0")}}e.counts=x}function G(e,n){if(Number.isInteger(e)&&e<1e15)return{int:e===0?"":String(e),dec:"0".repeat(n)};const s=e.toExponential(14),l=s.indexOf("e"),t=s[0]+s.slice(2,l),a=Number(s.slice(l+1))+1+n;let i,r=!1;if(a<0?i="":a>=t.length?i=t+"0".repeat(a-t.length):(r=t.charCodeAt(a)>=53,i=t.slice(0,a)),r){let F=i.length-1;const c=i.split("");for(;F>=0;)if(c[F]==="9")c[F]="0",F--;else{c[F]=String.fromCharCode(c[F].charCodeAt(0)+1);break}i=c.join(""),F<0&&(i="1"+i)}const m=i.length-n;let h,x;return m<=0?(h="",x="0".repeat(-m)+i):(h=i.slice(0,m),x=i.slice(m)),h=h.replace(/^0+/,""),{int:h,dec:x}}function ce(e){if(e.length<=3)return e;let n="",s=e.length%3;for(s>0&&(n=e.slice(0,s));s<e.length;s+=3)n+=(n?C.group:"")+e.slice(s,s+3);return n}function fe(e,n){if(n.fixedDen>0)return[Math.round(e*n.fixedDen),n.fixedDen];const s=10**n.denDigits-1;let[l,t,o,a]=[0,1,1,0],i=e;for(let r=0;r<32;r++){const u=Math.floor(i),m=u*o+l,h=u*a+t;if(h>s)break;[l,t,o,a]=[o,a,m,h];const x=i-u;if(x<1e-10)break;i=1/x}return[o,a||1]}function ue(e,n){let s=n;e.pct&&(s*=100**e.pct),e.scale&&(s/=1e3**e.scale);const{counts:l}=e;let t="",o="",a="",i=!1,r="",u="";if(e.fraction){const f=l.int>0?Math.floor(s):0,[g,D]=fe(s-f,e);let S=f,A=g;A===D&&l.int>0&&(S+=1,A=0);const L=e.fractionParts,j=A===0&&l.int>0&&!L.always;t=S===0?j||A===0&&(L.padWhole||L.requiredWhole)?"0":"":String(S),r=j?"":String(A),u=j?"":String(D)}else if(e.scientific){let f=s===0?0:Math.floor(Math.log10(s));const g=Math.max(l.int,1);g>1&&(f=Math.floor(f/g)*g);let D=G(s/10**f,l.dec);D.int.length>g&&(f+=g>1?g:1,D=G(s/10**f,l.dec)),t=s===0?"0".repeat(g):D.int,o=D.dec,i=f<0,a=String(Math.abs(f))}else{const f=G(s,l.dec);t=f.int,o=f.dec}let m=o.length,h="";const x=e.tokens,F=[];for(const f of x)f.k==="d"&&f.part==="int"&&F.push(f);const c=new Map;let b=t.length-1;for(let f=F.length-1;f>=0;f--){const g=F[f];if(b>=0){let D=t[b--];f===0&&b>=0&&(D=t.slice(0,b+1)+D,b=-1),c.set(g,D)}else c.set(g,g.c==="0"?"0":g.c==="?"?" ":"")}if(e.grouping&&F.length){let f="";for(const A of F)f+=c.get(A);const g=/^ */.exec(f)[0],D=ce(f.slice(g.length));c.forEach((A,L)=>c.set(L,""));const S=Math.max(0,Math.floor((f.length-1)/3)-Math.floor((f.length-g.length-1)/3));c.set(F[0],g+" ".repeat(S)+D)}const M=[];for(const f of x)f.k==="d"&&f.part==="dec"&&M.push(f);for(let f=M.length-1;f>=0&&o[f]==="0";f--)m=f;let y=0,p=0;const k=x.filter(f=>f.k==="d"&&f.part==="exp").length,_=a.padStart(k,"0");let w=0,T=0;const d=e.fractionParts?.padDen?u.padStart(l.den,"0"):u,$=e.fraction&&r==="",H=t!==""||F.some(f=>f.c==="0");for(let f=0;f<x.length;f++){const g=x[f],D=e.fractionParts;if(D&&f===D.start&&$){D.pad&&(h+=" ".repeat(D.width)),f=D.end;continue}if(D&&f>=D.start&&f<D.numStart&&!H){(D.padWhole||D.padNumerator&&r!=="0")&&g.k==="lit"&&(h+=" ".repeat(g.s.length));continue}switch(g.k){case"lit":h+=g.s===""?"":g.s;break;case"fill":h+=N+g.c+N;break;case"point":F.length===0&&!e.fraction&&!e.scientific&&t!=="0"&&!h.includes(C.decimal)&&(h+=t),h+=C.decimal;break;case"exp":h+=g.upper?"E":"e";break;case"slash":h+="/";break;case"d":switch(g.part){case"int":h+=c.get(g);break;case"dec":{const S=y++;S<m?h+=o[S]:g.c==="?"?h+=" ":g.c==="0"&&(h+="0");break}case"exp":p===0&&(h+=(i?"-":e.exponentPlus?"+":"")+_),p++;break;case"num":{const S=r.length-l.num+w++;S<0?h+=g.c==="#"?"":g.c==="?"?" ":"0":h+=w===1?r.slice(0,S+1):r[S];break}case"den":{h+=d[T++]??(g.c==="?"?" ":""),T===l.den&&d.length>l.den&&(h+=d.slice(l.den));break}default:}break;default:}}return h}const Ce=1462;function he(e,n=0){const s=Math.floor(e);let l=s+n;const t=e-s;let o=Math.round(t*864e5);o>=864e5&&(l+=1,o-=864e5);let a,i,r;if(l===0)a=1900,i=1,r=0;else if(l===60)a=1900,i=2,r=29;else{const m=(l<60?l+1:l)-25569+719468,h=Math.floor(m/146097),x=m-h*146097,F=Math.floor((x-Math.floor(x/1460)+Math.floor(x/36524)-Math.floor(x/146096))/365),c=x-(365*F+Math.floor(F/4)-Math.floor(F/100)),b=Math.floor((5*c+2)/153);r=c-Math.floor((153*b+2)/5)+1,i=b<10?b+3:b-9,a=F+h*400+(i<=2?1:0)}const u=l===0?6:(l-1)%7;return{year:a,month:i,day:r,weekday:u,ms:o,serial:e}}function we(e,n){const s=e.trim().split(/[^0-9]+/).filter(Boolean).map(Number);if(s.length!==3)return null;const l=r=>s[n.indexOf(r)];let t=l("Y");const o=l("M"),a=l("D");if(t<100&&(t+=t<30?2e3:1900),!(o>=1&&o<=12&&a>=1&&a<=new Date(Date.UTC(t,o,0)).getUTCDate()))return null;const i=de(t,o,a);return Number.isFinite(i)?i:null}function de(e,n,s){const l=n<=2?e-1:e,t=n<=2?n+9:n-3,o=Math.floor(l/400),a=l-o*400,i=Math.floor((153*t+2)/5)+s-1,r=a*365+Math.floor(a/4)-Math.floor(a/100)+i,u=o*146097+r-719468+25569;return u<61?u-1:u}const E=e=>e<10?"0"+e:String(e);function Y(e,n,s){const l=86400*10**(e.subDigits??0),t=n*86400;n=Math.round(n*l)/l;const o=he(n,s),a=o.ms;let i=Math.floor(a/1e3);const r=a-i*1e3;let u="";e.subDigits>0?(u=(r/1e3).toFixed(e.subDigits).slice(2),u.length===0&&(u="")):r>=500&&(i+=1);let m=Math.floor(i/3600);const h=Math.floor(i%3600/60),x=i%60;m>=24&&(m=23);const F=e.hour12?m%12===0?12:m%12:m,{loc:c}=e,b=e.hijri&&!c?.tag,M=c?.tag?v(c.tag):b?V():C,y=c?.calendar||b?K(b?"hijri":c.calendar,n+s,o,c?.tag??null)??o:o;let p="";for(const k of e.tokens)switch(k.k){case"lit":p+=k.s;break;case"fill":p+=N+k.c+N;break;case"date":switch(k.c){case"y":p+=k.n<=2?E(y.year%100):String(y.year);break;case"e":{const _=O(c,C);if(_===null){p+=String(y.year);break}const w=o.year-R(_,n+s).firstYear+1;w===1&&c?.gannen?p+="元":p+=k.n===1?w:E(w);break}case"g":{const _=O(c,C);if(_===null)break;const w=R(_,n+s);p+=k.n===1?w.symbol:k.n===2?w.abbreviation:w.name;break}case"b":{const _=c?.tag?o.year:o.year+543;p+=k.n<=2?E(_%100):String(_);break}case"a":p+=k.n===3?M.shortDays?.[o.weekday]??M.days[o.weekday].slice(0,3):M.days[o.weekday];break;case"m":k.n===1?p+=y.month:k.n===2?p+=E(y.month):y.monthName?p+=k.n===5?y.monthName[0]:y.monthName:k.n===3?p+=M.shortMonths?.[y.month-1]??M.months[y.month-1].slice(0,3):k.n===5?p+=M.months[y.month-1][0]:p+=(e.hasDay?M.monthsWithDay??M.months:M.months)[y.month-1];break;case"d":k.n===1?p+=y.day:k.n===2?p+=E(y.day):k.n===3?p+=M.shortDays?.[o.weekday]??M.days[o.weekday].slice(0,3):p+=M.days[o.weekday];break;case"h":p+=k.n===1?F:E(F);break;case"n":p+=k.n===1?h:E(h);break;case"s":p+=k.n===1?x:E(x);break;default:}break;case"elapsed":{const w=Math.floor(n)*86400+i;let T=k.c==="h"?Math.floor(w/3600):k.c==="m"?Math.floor(w/60):w;if(k.afterSeconds){const d=Math.abs(t-Math.round(t))<1e-7?0:t%1;T=Math.floor((x+.5+d)*(k.c==="h"?24:1440))}p+=String(T).padStart(k.n,"0");break}case"ampm":k.long?p+=m<12?c?.tag?M.am:C.amDesignator:c?.tag?M.pm:C.pmDesignator:p+=k.lower?m<12?"a":"p":m<12?"A":"P";break;case"sub":p+=C.decimal+u.slice(0,k.n);break;default:}return p}function me(e){return e.replace(/e([+-])(\d+)$/i,(n,s,l)=>`E${s}${l.padStart(2,"0")}`)}function I(e,n){const[s,l]=e.toExponential(n).split("e");return me(Number(s)+"e"+l).replace(".",C.decimal)}function J(e,n){const s=Number(e.toPrecision(15)).toFixed(n);return s.includes(".")?s.replace(/\.?0+$/,"").replace(".",C.decimal):s}function P(e,n=11){const s=Math.abs(e);if(Number.isInteger(e)&&s<1e11||!Number.isFinite(e))return String(e);const l=Math.max(n-6,0);if(s>=1e11||s<1e-9)return I(e,l);const t=Math.floor(Math.log10(s)),o=Math.max(0,n-(s<1?2:t+1));return t<0&&o+t<l&&Number(e.toFixed(o))!==e?I(e,l):J(e,o)}function pe(e,n){const s=P(e);if(n(s))return s;const l=Math.abs(e);if(l===0)return s;const t=Math.floor(Math.log10(l)),o=!s.includes("E");for(let a=11;a>=1;a--){if(o&&a>t){const i=Math.min(20,a-1-t),r=J(e,i);if(n(r))return r}if(!o||t<0||a<=t){const i=I(e,a-1);if(n(i))return i}}return I(e,0)}class ke{constructor(n){this.code=n;const s=B(n);this.sections=s.slice(0,4).map(ie);const l=this.sections[0];if(this.general=this.sections.length===1&&l.isGeneral&&!l.dbnum&&l.tokens.every(t=>t.k==="lit"&&t.s===""),this.isDate=this.sections.some(t=>t.isDate),this.isText=this.sections.length===1&&l.isText,this.sections.some(t=>t.digits)){const t=this.number;this.number=(o,a)=>{const i=this.sections[this._pick(o)],r=t.call(this,o,a);return i?.digits?ee(r,i.digits):r}}}_pick(n){const s=this.sections;if(s[0].cond!==null||s[1]&&s[1].cond!==null){for(let o=0;o<Math.min(s.length,3);o++){const a=s[o].cond;if(a===null){if(o===s.length-1||o===2||s[o].isText&&o===3)return o;continue}if(Fe(a,n))return o}return s.length===1?-1:Math.min(s.length-1,2)}const t=s.length>1&&s.length<4&&s[s.length-1].isText?s.length-1:s.length;return t===1?0:t===2?n<0?1:0:n>0?0:n<0?1:2}number(n,s=0){if(this.general)return P(n);const l=this._pick(n);if(l===-1)return P(n);const t=this.sections[l],o=this.sections[0].cond!==null||this.sections[1]&&this.sections[1].cond!==null,a=n<0&&(t.cond!==null?!oe(t.cond):l===0||o);if(t.isDate){const r=n<0&&l>0?-n:n;return z(t,r,s)?"#".repeat(8):r<0?`-${Y(t,-r,s)}`:Y(t,r,s)}if(t.isNum){const r=ue(t,Math.abs(n));return a&&be(r)?"-"+r:r}if(t.isGeneral){let r="";for(const u of t.tokens)u.k==="lit"?r+=u.s===""?U(t,Math.abs(n)):u.s.replace("",U(t,Math.abs(n))):u.k==="fill"&&(r+=N+u.c+N);return n<0&&l===0?"-"+r:r}let i=a?"-":"";for(const r of t.tokens)r.k==="lit"?i+=r.s:r.k==="fill"?i+=N+r.c+N:r.k==="pct"?i+="%":r.k==="text"&&(i+=P(Math.abs(n)));return i}dateOverflow(n,s=0){if(this.general)return!1;const l=this._pick(n),t=this.sections[l];return!!t?.isDate&&z(t,n<0&&l>0?-n:n,s)}hasCalendarDate(n){return this.sections[this._pick(n)]?.hasCalendar===!0}numberForText(n,s){const l=this.sections[this._pick(n)];return this.sections.some(t=>t.invalidTextFormat)||this.dateOverflow(n,s)?null:this.general||l===void 0?pe(n,t=>t.length<=(n<0?12:11)):this.number(n,s)}text(n){const s=this.sections,l=s.length===4?s[3]:s.length===1&&s[0].isText?s[0]:null;if(l===null)return n;let t="";for(const o of l.tokens)o.k==="lit"?t+=o.s:o.k==="text"?t+=n:o.k==="fill"&&(t+=N+o.c+N);return t}color(n){return this.sections[this._pick(n)]?.color??null}}const ge=2958466;function z(e,n,s){return e.tokens.some(t=>t.k==="date"||t.k==="ampm")?s===0&&n<0||Math.abs(n)>=ge-s:!1}function be(e){for(let n=0;n<e.length;n++){const s=e.charCodeAt(n);if(s>=49&&s<=57)return!0}return!1}function Fe(e,n){switch(e.op){case"<":return n<e.v;case"<=":return n<=e.v;case">":return n>e.v;case">=":return n>=e.v;case"=":return n===e.v;default:return n!==e.v}}const W=new Map;function X(e){let n=W.get(e);return n===void 0&&(n=new ke(e==="m/d/yyyy"?C.shortDate:e==="m/d/yyyy h:mm"?`${C.shortDate} h:mm`:e),W.set(e,n)),n}function _e(e,n,s=0){return X(e).number(n,s)}function Se(e){return X("#,##0").number(e)}export{De as BUILTIN_FORMATS,Ce as DATE_1904_OFFSET,N as FILL_MARK,Me as SYSTEM_LONG_DATE,we as dateSerial,me as excelExponent,pe as fitGeneral,Se as formatCount,P as formatGeneral,_e as formatNumber,X as getFormatter,de as partsToSerial,he as serialToParts,ye as setNumberLocale};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fullYear as U,parseInput as y}from"./input.js";import{NUM as k}from"./sheet.js";const l=r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),q=new Set([" "," "," "]),z=r=>r.replace(/\B(?=(\d{3})+(?!\d))/g,",");function K(r){const{decimal:$,order:E}=r,a=r.group===$?"":r.group,c=q.has(a)?"[\\s\\u00a0\\u202f]":a?l(a):null,p=l($),m=`(?:\\d+(?:${p}\\d*)?|${p}\\d+)`,i=c?`(?:\\d{1,3}(?:${c}\\d{3})+(?:${p}\\d*)?|${m})`:m,A=c?new RegExp(c):null,w=c?new RegExp(c,"g"):null,C=new RegExp(`^([+-]?)\\s*(${i})(%?)$`),D=new RegExp(`^([+-]?${m})[eE]([+-]?\\d+)$`),R=r.currency?.symbol??"$",x=l(R),G=new RegExp(`^(${i})\\s?${x}$`),Y=new RegExp(`^${x}\\s?(${i})$`),N=r.dateSep??"/",f=`(?:/|-|${l(N)})`,h=N==="."?"\\.?":"",j=new RegExp(`^(\\d{4})(${f})(\\d{1,2})\\2(\\d{1,2})${h}$`),v=new RegExp(`^(\\d{1,2})(${f})(\\d{1,2})(?:\\2(\\d{1,4}))?${h}$`),F=new RegExp(`^(\\d{1,2})${f}(\\d{4})$`),S=n=>Object.fromEntries(n.map((t,s)=>[t,[1,3,4][s]])),M=S(E),O=S(E.filter(n=>n!=="year")),B=n=>(w?n.replace(w,""):n).replace($,"."),P=$==="."?null:/\d[.,]|[.,]\d/,u=n=>P?.test(n)&&y(n).kind===k?`'${n}`:n;return n=>{if(n===""||n[0]==="'"||n[0]==="=")return n;const t=n.trim(),s=o=>y(o).kind===k?o:null;let e=C.exec(t);if(e){const o=B(e[2]);if(A?.test(e[2])){const[g,d]=o.split(".");return`${e[1]}${z(g)}${d===void 0?"":`.${d}`}${e[3]}`}return`${e[1]}${o}${e[3]}`}if(e=D.exec(t),e)return`${e[1].replace($,".")}e${e[2]}`;if(e=G.exec(t)??Y.exec(t),e)return`${B(e[1])} ${R}`;if(e=j.exec(t),e)return s(`${e[1]}-${e[3]}-${e[4]}`)??u(n);if(e=v.exec(t),e){const{month:o,day:g,year:d}=e[4]===void 0?O:M,b=`${Number(e[o])}/${Number(e[g])}`,I=d?s(`${b}/${e[d]}`):y(b).format==="d-mmm"?b:null;return I!==null?I:e[4]===void 0&&e[3].length===2?s(`${Number(e[1])}/${U(e[3])}`)??u(n):u(n)}return e=F.exec(t),e?s(`${Number(e[1])}/${e[2]}`)??u(n):u(n)}}export{K as regionInput};
|
package/core/row-fit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY as c,KIND_MASK as a,STR as d}from"./sheet.js";const l=t=>Math.ceil(t*1.33);function x(t,o,i,f){for(let n=0;n<t.columns.length;n++){if(t.columns[n]===void 0)continue;const e=t.kind(i,n)&a;e!==c&&(t.merges.length&&t.mergeAt(i,n)||f(n,e,o.styles.list[t.style(i,n)]??o.styles.list[0]))}}function g(t,o,i,f,n,e){let r=l(e.fontSize)+(e.ext?.pad?e.ext.pad[0]+e.ext.pad[2]:0);const u=n===d&&o.strings.rich!==null?o.strings.rich.get(t.value(i,f)):void 0;if(u)for(const s of u)s.sz&&(r=Math.max(r,l(s.sz)));return r}function m(t,o,i){let f=0;return x(t,o,i,(n,e,r)=>{f=Math.max(f,g(t,o,i,n,e,r))}),f}function p(t,o,i,f=m){const n=t.rows;return n.isHidden(i)||t.filteredRows?.has(i)||n.isCustom(i)&&!n.isAuto(i)?n.sizeOf(i):Math.max(n.defaultSize,f(t,o,i))}function h(t,o,i,f,n=2e3){if(!(f-i>n))for(let e=i;e<=f;e++){const r=p(t,o,e);r!==t.rows.sizeOf(e)&&t.rows.setSize(e,r,!0)}}export{p as autoRowHeight,g as cellLineHeight,x as eachFittedCell,m as fontRowHeight,h as growRowsToFonts,l as lineHeight};
|
package/core/sheet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Axis as
|
|
1
|
+
import{Axis as w}from"./axis.js";import{MAX_COLS as I,MAX_ROWS as A}from"./address.js";import{FormulaStore as S}from"./formula-store.js";const u=10,M=1<<u,g=M-1,H=0,O=1,V=2,Y=3,j=4,W=8,X=16,Z=32,b=64,K=7,N=15,q=["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA","#SPILL!","#CALC!","#BUSY!","#CONNECT!","#BLOCKED!","#FIELD!","#UNKNOWN!"];class z{constructor(){this.kinds=new Uint8Array(M),this.values=new Float64Array(M),this.styles=null}}function E(m,t,e,s,n,l){const i=(f,d)=>{if(!s||f<0||f>=e||s.sizeOf(f)>0)return f;const x=s.offsetOf(f)-(d<0?1:0);return x<0?-1:x>=s.total?e:s.indexAt(x)},r=i(t>0?e-1:0,-t);if((r-m)*t<=0)return m;let o=i(m+t,t);if(n(m)&&n(o)){for(;o!==r;){const f=i(o+t,t);if(!n(f))break;o=f}return o}for(;(r-o)*t>=0;){if(n(o))return o;o=i(l(o),t)}return r}let D=1;class J{constructor(t){this.uid=D++,this.name=t,this.rowExtras=null,this.colExtras=null,this.valueMeta=null,this.columns=[],this.maxRow=-1,this.maxCol=-1,this.rows=new w(A,16),this.cols=new w(I,65),this._formulas=new S,this.spills=null,this.rowStyles=null,this.colStyles=null,this.merges=[],this.cellTypeRules=null,this.cellTypes=null,this.sparkRules=null,this.cellDropdowns=null,this.cellTags=null,this.cellPicOpts=null,this.cellButtons=null,this.cellStates=null,this.changes=null,this.autoMerges=null,this.background=null,this.outlineColumn=null,this.split=null,this.frozenTrailingRows=0,this.frozenTrailingCols=0,this.axisSizing=null,this.hideZeros=!1,this.mergeIndex=null,this.frozenRows=0,this.frozenCols=0,this.showGridlines=!0,this.zoom=1,this.sourceId=null,this.revision=0}_chunk(t,e){const s=this.columns[e];return s===void 0?void 0:s[t>>>u]}_ensure(t,e){let s=this.columns[e];s===void 0&&(s=[],this.columns[e]=s);const n=t>>>u;let l=s[n];return l===void 0&&(l=new z,s[n]=l),l}kind(t,e){const s=this._chunk(t,e);return s===void 0?0:s.kinds[t&g]}value(t,e){const s=this._chunk(t,e);return s===void 0?0:s.values[t&g]}style(t,e){const s=this._chunk(t,e);if(s!==void 0&&s.styles!==null){const n=s.styles[t&g];if(n!==0)return n}if(this.rowStyles!==null){const n=this.rowStyles.get(t);if(n!==void 0)return n}if(this.colStyles!==null){const n=this.colStyles.get(e);if(n!==void 0)return n}return 0}cellStyle(t,e){const s=this._chunk(t,e);return s===void 0||s.styles===null?0:s.styles[t&g]}get formulas(){return this._formulas}set formulas(t){this._formulas=t instanceof S?t:S.from(t)}formula(t,e){return this._formulas.at(t,e)}setCell(t,e,s,n){const l=this._ensure(t,e),i=t&g;if(this.valueListeners&&(l.kinds[i]!==s||l.values[i]!==n))for(const r of this.valueListeners)r(t,e,t,e);l.kinds[i]=s,l.values[i]=n,t>this.maxRow&&(this.maxRow=t),e>this.maxCol&&(this.maxCol=e)}setStyle(t,e,s){const n=this._ensure(t,e);if(n.styles===null){if(s===0)return;n.styles=new Uint16Array(M)}n.styles[t&g]=s,t>this.maxRow&&(this.maxRow=t),e>this.maxCol&&(this.maxCol=e)}setFormula(t,e,s){s?this._formulas.put(t,e,s):this._formulas.remove(t,e)}applyBatch(t){const{rows:e,cols:s,kinds:n,values:l,styles:i,count:r}=t;let o=-1,f=-1,d=null,x=this.maxRow,p=this.maxCol;for(let h=0;h<r;h++){const c=e[h],a=s[h],k=c>>>u;(a!==o||k!==f)&&(d=this._ensure(c,a),o=a,f=k);const y=c&g;d.kinds[y]=n[h],d.values[y]=l[h];const _=i[h];_!==0&&(d.styles===null&&(d.styles=new Uint16Array(M)),d.styles[y]=_),a>p&&(p=a)}if(this.valueListeners)for(const h of this.valueListeners)for(let c=0;c<r;c++)h(e[c],s[c],e[c],s[c]);if(r>0&&e[r-1]>x&&(x=e[r-1]),this.maxRow=x,this.maxCol=p,t.formulas){const h=this._formulas;for(const[c,a]of t.formulas)h.set(c,a)}if(t.valueMeta){this.valueMeta===null&&(this.valueMeta=new Map);for(const[h,c]of t.valueMeta)this.valueMeta.set(h,c)}this.revision++}addMerge(t){this.merges.push(t),this.mergeIndex=null}removeMergesIn(t){const e=this.merges.length;this.merges=this.merges.filter(s=>!B(s,t)),this.merges.length!==e&&(this.mergeIndex=null)}_buildMergeIndex(){const t=new Map;for(const e of this.merges)for(let s=e.r0>>>u;s<=e.r1>>>u;s++){const n=t.get(s);n?n.push(e):t.set(s,[e])}this.mergeIndex=t}mergeAt(t,e){if(this.merges.length===0)return null;this.mergeIndex===null&&this._buildMergeIndex();const s=this.mergeIndex.get(t>>>u);if(s===void 0)return null;for(let n=0;n<s.length;n++){const l=s[n];if(t>=l.r0&&t<=l.r1&&e>=l.c0&&e<=l.c1)return l}return null}mergesInRows(t,e){if(this.merges.length===0)return[];this.mergeIndex===null&&this._buildMergeIndex();const s=new Set;for(let n=t>>>u;n<=e>>>u;n++){const l=this.mergeIndex.get(n);if(l)for(const i of l)i.r1>=t&&i.r0<=e&&s.add(i)}return[...s]}jumpRow(t,e,s,n=!1){const l=this.columns[e],i=o=>{const f=l?.[o>>>u];return f!==void 0&&(f.kinds[o&g]&N)!==0},r=o=>l?.[o>>>u]!==void 0?o+s:s>0?(o>>>u)+1<<u:(o>>>u<<u)-1;return E(t,s,n?this.rows.count:A,n&&this.rows,i,r)}jumpCol(t,e,s,n=!1){const l=r=>(this.kind(t,r)&N)!==0,i=r=>s>0&&r>=this.maxCol?I:r+s;return E(e,s,n?this.cols.count:I,n&&this.cols,l,i)}aggregate(t){let e=0,s=0,n=0,l=1/0,i=-1/0;for(const{r0:r,c0:o,r1:f,c1:d}of t){const x=Math.min(d,this.maxCol),p=Math.min(f,this.maxRow);for(let h=o;h<=x;h++){const c=this.columns[h];if(c!==void 0)for(let a=r>>>u;a<=p>>>u;a++){const k=c[a];if(k===void 0)continue;const y=a<<u,_=Math.max(r-y,0),L=Math.min(p-y,g),{kinds:T,values:U}=k;for(let R=_;R<=L;R++){const v=T[R]&K;if(v!==0&&(n++,v===O)){const C=U[R];e+=C,s++,C<l&&(l=C),C>i&&(i=C)}}}}}return{sum:e,numeric:s,filled:n,min:l,max:i}}}function B(m,t){return m.r0<=t.r1&&m.r1>=t.r0&&m.c0<=t.c1&&m.c1>=t.c0}export{Y as BOOL,u as CHUNK_BITS,g as CHUNK_MASK,M as CHUNK_SIZE,N as CONTENT_MASK,Z as DIRTY,H as EMPTY,j as ERR,q as ERRORS,b as EVALUATING,W as FORMULA,K as KIND_MASK,O as NUM,X as SPILL,V as STR,J as Sheet,B as rangesTouch};
|
package/core/sparse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
import{copyTypeRules as h,shiftedTypeRules as O,sortedTypeRules as U}from"./cell-type-rules.js";const t=16384,v=["cellTypes","cellDropdowns","cellTags","cellButtons"],D=new Set,L=(n,o)=>n*t+o,N=[];function V(n,{moved:o=!0}={}){v.includes(n)||v.push(n),o||D.add(n)}const z=n=>{for(const o of v)if(n[o])return!0;return!!n.cellTypeRules};function S(n){const o={cellTypeRules:n.cellTypeRules??null};for(const c of v)o[c]=n[c]??null;return o}const E=n=>o=>{const c=E(S(o));return Object.assign(o,n),o.cellTypesChanged=!0,c},B=()=>B,W=n=>E(S(n)),X=n=>S(n);function q(n,o,c,e,i=2e6){const u=E(S(n)),f=new Map(n[o]??[]);let d=0;for(const{r0:p,c0:l,r1:s,c1:T}of c){const M=Math.min(s,Math.max(n.maxRow,p)),a=Math.min(T,Math.max(n.maxCol,l));for(let y=p;y<=M&&d<i;y++)for(let R=l;R<=a&&d<i;R++,d++)e===void 0?f.delete(y*t+R):f.set(y*t+R,e)}return n[o]=f.size>0?f:null,n.cellTypesChanged=!0,u}function Y(n,o,c){return c>0?n>=o?n+c:n:n>=o-c?n+c:n>=o?-1:n}function F(n,o){if(!z(n))return B;const c=E(S(n));n.cellTypeRules=O(n.cellTypeRules,o);const e=o.axis==="row";for(const i of v){if(D.has(i))continue;const u=n[i];if(!u)continue;const f=new Map;for(const[d,p]of u){const l=Math.floor(d/t),s=d-l*t,T=e?s:l;if(o.span&&(T<o.span[0]||T>o.span[1])){f.set(d,p);continue}const M=Y(e?l:s,o.at,o.n);M<0||f.set(e?M*t+s:l*t+M,p)}n[i]=f.size>0?f:null}return n.cellTypesChanged=!0,c}function G(n,o,c,e,i,u,f="row"){if(!z(n))return B;const d=E(S(n));n.cellTypeRules=U(n.cellTypeRules,{r0:o,r1:c,c0:e,c1:i},u,f);for(const p of v){if(D.has(p))continue;const l=n[p];if(!l)continue;const s=new Map;for(const[T,M]of l){const a=Math.floor(T/t),y=T-a*t;a>=o&&a<=c&&y>=e&&y<=i?s.set(f==="row"?(o+u[a-o])*t+y:a*t+e+u[y-e],M):s.set(T,M)}n[p]=s}return n.cellTypesChanged=!0,d}function I(n,o,c,e,{cut:i=!1,transpose:u=!1}={}){if(!z(n)&&!z(o))return B;const f=E(S(o)),d=n===o?null:E(S(n)),p=c.r1-c.r0+1,l=c.c1-c.c0+1;h(n,o,c,e,{cut:i,transpose:u});const s=e.r1-e.r0+1,T=e.c1-e.c0+1;for(const a of v){const y=n[a],R=o[a];if(!y&&!R)continue;const m=[];if(y)for(const[r,x]of y){const w=Math.floor(r/t),k=r-w*t;w>=c.r0&&w<=c.r1&&k>=c.c0&&k<=c.c1&&m.push([w-c.r0,k-c.c0,x])}const C=new Map(R??[]);if(i&&n===o)for(const[r,x]of m)C.delete((c.r0+r)*t+c.c0+x);if(C.size<s*T)for(const r of C.keys()){const x=Math.floor(r/t),w=r%t;x>=e.r0&&x<=e.r1&&w>=e.c0&&w<=e.c1&&C.delete(r)}else for(let r=e.r0;r<=e.r1;r++)for(let x=e.c0;x<=e.c1;x++)C.delete(r*t+x);if(m.length>0){const r=u?l:p,x=u?p:l;for(let w=0;w+r<=s||w===0;w+=r)for(let k=0;k+x<=T||k===0;k+=x)for(const[_,b,A]of m){const H=e.r0+w+(u?b:_),K=e.c0+k+(u?_:b);C.set(H*t+K,A)}}if(o[a]=C.size>0?C:null,i&&n!==o&&y){const r=new Map(y);for(const[x,w]of m)r.delete((c.r0+x)*t+c.c0+w);n[a]=r.size>0?r:null}}if(o.cellTypesChanged=!0,n.cellTypesChanged=!0,d===null)return f;const M=(a,y)=>R=>M(a(o),y(n))??R;return M(f,d)}function J(n,o,c){if(!z(n))return B;const e=E(S(n));h(n,n,o,c,{fill:!0});const i=o.r1-o.r0+1,u=o.c1-o.c0+1;for(const f of v){const d=n[f];if(!d)continue;const p=new Map(d);for(let l=c.r0;l<=c.r1;l++)for(let s=c.c0;s<=c.c1;s++){if(l>=o.r0&&l<=o.r1&&s>=o.c0&&s<=o.c1)continue;const T=o.r0+((l-o.r0)%i+i)%i,M=o.c0+((s-o.c0)%u+u)%u,a=d.get(T*t+M);a===void 0?p.delete(l*t+s):p.set(l*t+s,a)}n[f]=p.size>0?p:null}return n.cellTypesChanged=!0,e}export{I as copySparseBlock,J as fillSparse,B as noUndo,G as permuteSparse,V as registerSparseMap,q as setSparse,N as sheetRenameHooks,F as shiftSparse,L as sparseKey,X as sparseState,W as sparseUndo};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CHUNK_BITS as v,CHUNK_MASK as A,CHUNK_SIZE as q,FORMULA as ln,STR as sn}from"./sheet.js";import{FormulaStore as X}from"./formula-store.js";import{cellRef as B,MAX_COLS as w,MAX_ROWS as k,parseCellRef as L,parseRangeRef as b,rangeRef as H}from"./address.js";import{translateFormula as on}from"./formula-refs.js";import{adjustFormula as T,adjustRange as O}from"../calc/adjust.js";import{clonePageSetup as en,shiftPageSetup as an}from"../print/page-setup.js";import{shiftSparse as cn}from"./sparse.js";import{shiftRuleFormulas as un}from"../cells/cf-file.js";import{noteStructure as fn}from"./changes.js";import{shiftHeaderColors as mn}from"../cells/header-colors.js";function V(t){return{kinds:new Uint8Array(q),values:new Float64Array(q),styles:t.styles===null?null:new Uint16Array(q)}}function W(t,n,r){if(!t||n===0)return;const s=/outlineLevel="\d+"/.exec(t.get(n-1)??"");if(s)for(let o=n;o<n+r;o++)t.set(o,s[0])}function Z(t,n,r,s,o,c){let l=s,e=r,u=c;for(;l>0;){const a=u>>>v,i=u&A,m=Math.min(l,q-i);let y=o[a];y===void 0&&(y=V(t),o[a]=y);const d=e-n;y.kinds.set(t.kinds.subarray(d,d+m),i),y.values.set(t.values.subarray(d,d+m),i),t.styles!==null&&(y.styles===null&&(y.styles=new Uint16Array(q)),y.styles.set(t.styles.subarray(d,d+m),i)),l-=m,e+=m,u+=m}}function G(t,n,r){const s=n>>>v,o=t.slice(0,s),c=t[s];c!==void 0&&(n&A)>0&&Z(c,s<<v,s<<v,n&A,o,s<<v);const l=r<0?n-r:n;for(let e=s;e<t.length;e++){const u=t[e];if(u===void 0)continue;const a=e<<v,i=Math.max(a,l),m=a+q;if(i>=m)continue;const y=i+r;if(y>=k)continue;const d=Math.min(m-i,k-y);Z(u,a,i,d,o,y)}return o}function dn(t,n,r){const s=[];for(let o=0;o<t.length;o++){const c=t[o];c!==void 0&&(o<n?s[o]=c:r>0?o+r<w&&(s[o+r]=c):o>=n-r&&(s[o+r]=c))}return s}function gn(t,n,r,s){const o=r-1,c=Math.min(s,(n?k:w)-r);if(c<=0)return;if(n){const u=c*t.columns.filter(Boolean).length<=4194304;for(let i=0;u&&i<t.columns.length;i++){if(t.columns[i]===void 0)continue;const m=t.cellStyle(o,i);if(m!==0)for(let y=0;y<c;y++)t.setStyle(r+y,i,m)}const a=t.rowStyles?.get(o);if(a!==void 0)for(let i=0;i<c;i++)t.rowStyles.set(r+i,a);return}const l=t.columns[o];if(l!==void 0&&l.some(u=>u?.styles)){for(let u=0;u<c;u++){const a=[];l.forEach((i,m)=>{if(i===void 0||i.styles===null)return;const y=V(i);y.styles.set(i.styles),a[m]=y}),t.columns[r+u]=a}r+c-1>t.maxCol&&(t.maxCol=r+c-1)}const e=t.colStyles?.get(o);if(e!==void 0)for(let u=0;u<c;u++)t.colStyles.set(r+u,e)}function N(t,n,r){if(t===null)return null;const s=new Map;for(const[o,c]of t)o<n?s.set(o,c):(r>0||o>=n-r)&&s.set(o+r,c);return s}const U=(t,n,r)=>r.axis==="row"?t<r.at?[t,n]:r.n>0?t+r.n<k?[t+r.n,n]:null:t>=r.at-r.n?[t+r.n,n]:null:n<r.at?[t,n]:r.n>0?n+r.n<w?[t,n+r.n]:null:n>=r.at-r.n?[t,n+r.n]:null;function J(t,n,r){if(t.f!==void 0)return t.f;if(t.sf!==void 0){const s=Math.floor(t.base/w);return on(t.sf,n-s,r-(t.base-s*w))}return null}const P=(t,n)=>(t.f??t.sf)?.toUpperCase().includes(n)===!0;function Q(t,n){for(const r of t.descriptors())if(P(r,n))return!0;return!1}function _(t,n){const r=b(t),s=r&&O(r,n);return s?H(s):t}function Y(t,n,r,s,o){if(t.t==="dataTable"){if(!s)return t;const l={...t,ref:_(t.ref,r),tpl:void 0};return t.r1&&(l.r1=_(t.r1,r)),t.r2&&(l.r2=_(t.r2,r)),l}const c={f:T(n,r,s,o)};return t.typed&&(c.typed=!0),t.ca&&(c.ca=t.ca),t.cm&&(c.cm=t.cm),t.t==="array"&&(c.t="array",c.ref=s&&t.ref?_(t.ref,r):t.ref),c}function Un(t,n,r){t.collab?.structure(n,r);const{at:s,n:o}=r,c=r.axis==="row",l=$(t,n),e=fn(n,r);if(c){const d=[];n.columns.forEach((p,R)=>{d[R]=G(p,s,o)}),n.columns=d,n.rows=n.rows.shifted(s,o),n.rowStyles=N(n.rowStyles,s,o),n.rowExtras=N(n.rowExtras,s,o),o>0&&W(n.rowExtras,s,o),n.maxRow=n.maxRow>=s?Math.max(s-1,n.maxRow+o):n.maxRow,n.maxRow>=k&&(n.maxRow=k-1),n.frozenRows>s&&(n.frozenRows=Math.max(s,n.frozenRows+o))}else n.columns=dn(n.columns,s,o),n.cols=n.cols.shifted(s,o),n.colStyles=N(n.colStyles,s,o),n.colExtras=N(n.colExtras,s,o),o>0&&W(n.colExtras,s,o),n.colsChanged=!0,n.maxCol=n.maxCol>=s?Math.max(s-1,n.maxCol+o):n.maxCol,n.maxCol>=w&&(n.maxCol=w-1),n.frozenCols>s&&(n.frozenCols=Math.max(s,n.frozenCols+o));if(o>0&&s>0&&!r.noFormat&&gn(n,c,s,o),n.merges=n.merges.map(d=>O(d,r)).filter(d=>d!==null&&(d.r0!==d.r1||d.c0!==d.c1)),n.mergeIndex=null,n.spills){const d=new Map;for(const[p,R]of n.spills){const f=Math.floor(p/w),x=U(f,p-f*w,r),g=O(R,r);x&&g&&d.set(x[0]*w+x[1],{...R,...g})}n.spills=d}if(n.valueMeta){const d=new Map;for(const[p,R]of n.valueMeta){const f=Math.floor(p/w),x=U(f,p-f*w,r);x&&d.set(x[0]*w+x[1],R)}n.valueMeta=d}const u=n.name.toUpperCase();for(const d of t.sheets){const p=d===n;if(!p&&!Q(d.formulas,u))continue;const R=new X;d.formulas.forEachCell((f,x,g)=>{const C=p?U(f,x,r):[f,x];if(C===null)return;if(!p&&!P(g,u)){R.put(C[0],C[1],g);return}const S=J(g,f,x);if(S===null||!p&&!S.toUpperCase().includes(u)){R.put(C[0],C[1],g);return}const M=Y(g,S,r,p,n.name);if(M.t==="array"&&M.ref&&p){const z=d.spills?.get(C[0]*w+C[1]);z&&(M.ref=H(z))}R.put(C[0],C[1],M)}),d.formulas=R}const a=tn(t,n,r),i=t.engine;if(i){for(const d of i.names.values())d.text=T(d.text,r,!1,n.name);i.names.size>0&&(t.namesChanged=!0),i.nameTemplates.clear(),i.rebuild()}n.structureOps=[...n.structureOps??[],r],n.pageSetup&&(an(n.pageSetup,r),n.pageSetupChanged=!0),n.viewChanged=!0,n.revision++,t.collab?.structureDone(n);const m=(d,p)=>()=>m(d(),p()),y=m(a,D(t,n,l));return e===null?y:m(y,e)}const E=(t,n)=>{if(n.span){const[r,s]=n.span;if(!(n.axis==="row"?t.c0>=r&&t.c1<=s:t.r0>=r&&t.r1<=s))return t}return O(t,n)};function j(t,n){return t.split(/\s+/).map(b).filter(Boolean).map(r=>E(r,n)).filter(Boolean).map(H).join(" ")}function F(t,n,r){if(r.span){const[s,o]=r.span,c=r.axis==="row"?n:t;if(c<s||c>o)return[t,n]}return U(t,n,r)}function h(t,n){if(!t)return t;const r=E(t,n);if(r===null)return null;let{columns:s}=t;if(n.axis==="col"&&s?.size>0){s=new Map;for(const[c,l]of t.columns){const e=F(t.r0,c,n);e&&s.set(e[1],l)}}let{buttons:o}=t;if(n.axis==="col"&&o?.size>0){o=new Map;for(const[c,l]of t.buttons){const e=F(t.r0,c,n);e&&o.set(e[1],l)}}return{...t,...r,columns:s,buttons:o,sortState:nn(t.sortState,n)}}function nn(t,n){if(!t)return t??null;const r=E(t,n);if(r===null)return null;const s=[];for(const o of t.conditions){const c=E(o,n);c!==null&&s.push({...o,...c})}return s.length>0?{...t,...r,conditions:s}:null}const I=t=>({sheets:t.sheets.map(n=>[n,{cf:n.cf,cellStates:n.cellStates,headerColors:n.headerColors,validations:n.validations,hyperlinks:n.hyperlinks,ignoredErrors:n.ignoredErrors,comments:n.comments,sparklines:n.sparklines,sparkRules:n.sparkRules,autoFilter:n.autoFilter,advancedFilter:n.advancedFilter,outlineColumn:n.outlineColumn,outlineVersion:(n.outlineVersion??0)+1,sortState:n.sortState,filteredRows:n.filteredRows,scenarios:n.scenarios,threads:n.threads}]),tables:t.engine?[...t.engine.tables.values()].map(n=>[n,{r0:n.r0,c0:n.c0,r1:n.r1,c1:n.c1,columns:n.columns,filter:n.filter,totals:n.totals,dirty:n.dirty,columnsChanged:n.columnsChanged}]):[]}),rn=t=>{for(const[n,r]of t.sheets)Object.assign(n,r),n.cfEval?.invalidate();for(const[n,r]of t.tables)Object.assign(n,r)};function tn(t,n,r){const s=I(t),o=n.name;for(const l of t.sheets){const e=l===n,u=a=>typeof a=="string"&&a!==""?T(a,r,e,o):a;if(l.cf?.length>0&&(l.cf=l.cf.map(({_ranges:a,...i})=>({...i,sqref:e?j(i.sqref,r):i.sqref,rules:i.rules.map(m=>un(m,u))})).filter(a=>a.sqref!==""),l.cfChanged=!0,l.cfEval?.invalidate()),e&&l.headerColors&&!r.span&&(l.headerColors=mn(l.headerColors,r)),e&&l.cellStates?.length>0){const a=l.cellStates.map(i=>({...i,ranges:i.ranges.map(m=>E(m,r)).filter(Boolean)})).filter(i=>i.ranges.length>0);l.cellStates=a.length>0?a:null}l.validations?.length>0&&(l.validations=l.validations.map(({_ranges:a,...i})=>({...i,sqref:e?j(i.sqref,r):i.sqref,formula1:u(i.formula1),formula2:u(i.formula2)})).filter(a=>a.sqref!==""),l.validationsChanged=!0),e&&l.ignoredErrors?.length>0&&(l.ignoredErrors=l.ignoredErrors.map(a=>({...a,sqref:j(a.sqref,r)})).filter(a=>a.sqref!==""),l.ignoredErrorsChanged=!0),l.hyperlinks?.length>0&&(l.hyperlinks=l.hyperlinks.map(({_ranges:a,...i})=>{const m=e?j(i.ref,r):i.ref;return{...i,ref:m,...i.location?{location:u(i.location)}:{}}}).filter(a=>a.ref!==""),l.hyperlinksChanged=!0),l.sparkRules?.length>0&&(l.sparkRules=l.sparkRules.map(a=>({...a,sqref:e?j(a.sqref,r):a.sqref,formula:u(a.formula)})).filter(a=>a.sqref!=="")),l.sparklines?.length>0&&(l.sparklines=l.sparklines.map(a=>({...a,items:a.items.map(i=>{const m=L(i.cell),y=e&&m?F(m.row,m.col,r):m?[m.row,m.col]:null;return y?{...i,cell:B(y[0],y[1]),source:u(i.source)}:null}).filter(Boolean)})).filter(a=>a.items.length>0),l.sparklinesChanged=!0)}if(n.comments?.size>0){const l=new Map;for(const[e,u]of n.comments){const a=Math.floor(e/w),i=F(a,e-a*w,r);i&&l.set(i[0]*w+i[1],{...u,ref:B(i[0],i[1])})}n.comments=l,n.commentsChanged=!0}if(n.scenarios?.items.length>0&&(n.scenarios={...n.scenarios,items:n.scenarios.items.map(l=>({...l,cells:l.cells.map(e=>{const u=L(e.r),a=u&&F(u.row,u.col,r);return a?{...e,r:B(a[0],a[1])}:null}).filter(Boolean)}))},n.scenariosChanged=!0),n.threads?.length>0&&(n.threads=n.threads.map(l=>{const e=L(l.ref),u=e&&F(e.row,e.col,r);return u?{...l,ref:B(u[0],u[1])}:null}).filter(Boolean),n.threadsChanged=!0),n.outlineColumn){const l=n.outlineColumn;if(r.axis==="col"&&!r.span){const e=U(0,l.col,r);n.outlineColumn=e?{...l,col:e[1]}:null}else if(r.axis==="row"&&!r.span&&l.checks){const e={};for(const u of Object.keys(l.checks)){const a=U(Number(u),0,r);a&&(e[a[0]]=l.checks[u])}n.outlineColumn={...l,checks:e}}}if(n.outlineVersion=(n.outlineVersion??0)+1,n.sortState&&(n.sortState=nn(n.sortState,r),n.filterChanged=!0),n.autoFilter&&(n.autoFilter=h(n.autoFilter,r),n.filterChanged=!0),n.advancedFilter){const l=n.advancedFilter,e=l.listSheet===n?E(l,r):l;n.advancedFilter=e===null?null:{...l,r0:e.r0,c0:e.c0,r1:e.r1,c1:e.c1,criteria:l.criteria&&l.criteriaSheet===n?E(l.criteria,r):l.criteria,extract:l.extract?E(l.extract,r):null},n.filterChanged=!0}if(n.filteredRows&&r.axis==="row"&&!r.span){const l=new Set;for(const e of n.filteredRows){const u=U(e,0,r);u&&l.add(u[0])}n.filteredRows=l}if(t.engine)for(const l of[...t.engine.tables.values()]){if(l.sheet!==n)continue;const e=E(l,r);if(e===null)continue;const u=!r.span||r.span[0]<=l.r0&&r.span[1]>=l.r1;r.axis==="col"&&u&&e.c1-e.c0!==l.c1-l.c0&&Cn(t,l,r),Object.assign(l,{r0:e.r0,c0:e.c0,r1:e.r1,c1:e.c1}),l.filter=h(l.filter,r),l.dirty=!0}const c=l=>()=>{const e=I(t);return rn(l),c(e)};return c(s)}function On(t){const n=r=>()=>{const s=I(t);return rn(r),n(s)};return n(I(t))}function xn(t,n){return D(t,n,$(t,n))}function yn(t,n,r,s){if(t===void 0&&n===void 0)return;const o=t===void 0?[]:t.slice();for(let c=r>>>v;c<=s>>>v;c++){const l=t?.[c],e=n?.[c];if(l===void 0&&e===void 0)continue;const u=c<<v,a=Math.max(r,u)-u,i=Math.min(s,u+A)-u+1,m=l===void 0?V({styles:null}):{kinds:l.kinds.slice(),values:l.values.slice(),styles:l.styles?l.styles.slice():null};e===void 0?(m.kinds.fill(0,a,i),m.values.fill(0,a,i),m.styles!==null&&m.styles.fill(0,a,i)):(m.kinds.set(e.kinds.subarray(a,i),a),m.values.set(e.values.subarray(a,i),a),e.styles!==null?(m.styles===null&&(m.styles=new Uint16Array(q)),m.styles.set(e.styles.subarray(a,i),a)):m.styles!==null&&m.styles.fill(0,a,i)),o[c]=m}return o}function wn(t){if(t===void 0)return-1;for(let n=t.length-1;n>=0;n--){const r=t[n];if(r!==void 0){for(let s=A;s>=0;s--)if(r.kinds[s]!==0||r.styles!==null&&r.styles[s]!==0)return(n<<v)+s}}return-1}function An(t,n,r){t.collab?.structure(n,r);const{at:s,n:o}=r,[c,l]=r.span,e=r.axis==="row",u=xn(t,n),a=n.columns.slice();if(e)for(let f=c;f<=Math.min(l,n.columns.length-1);f++)n.columns[f]!==void 0&&(a[f]=G(n.columns[f],s,o),o>0&&(n.maxRow=Math.min(k-1,Math.max(n.maxRow,wn(a[f])))));else{const f=n.columns.length-1,x=o>0?Math.min(f+o,w-1):f;for(let g=s;g<=x;g++){const C=g-o,S=o>0&&g<s+o?void 0:n.columns[C],M=yn(n.columns[g],S,c,l);M!==void 0&&(a[g]=M)}o>0&&(n.maxCol=Math.min(w-1,Math.max(n.maxCol,Math.min(n.maxCol+o,x))))}if(n.columns=a,o>0&&s>0&&!r.noFormat){const f=Math.min(o,(e?k:w)-s),x=Math.min(l,e?n.maxCol:n.maxRow);if(f>0&&f*(x-c+1)<=1<<22)for(let g=c;g<=x;g++){const C=e?n.cellStyle(s-1,g):n.cellStyle(g,s-1);if(C!==0)for(let S=0;S<f;S++)e?n.setStyle(s+S,g,C):n.setStyle(g,s+S,C)}}const i=f=>e?f.c0>=c&&f.c1<=l:f.r0>=c&&f.r1<=l;if(n.merges=n.merges.map(f=>i(f)?O(f,r):f).filter(f=>f!==null&&(f.r0!==f.r1||f.c0!==f.c1)),n.mergeIndex=null,n.spills){const f=new Map;for(const[x,g]of n.spills){const C=Math.floor(x/w),S=F(C,x-C*w,r),M=i(g)?O(g,r):g;S&&M&&f.set(S[0]*w+S[1],{...g,...M})}n.spills=f}if(n.valueMeta){const f=new Map;for(const[x,g]of n.valueMeta){const C=Math.floor(x/w),S=F(C,x-C*w,r);S&&f.set(S[0]*w+S[1],g)}n.valueMeta=f}const m=n.name.toUpperCase();for(const f of t.sheets){const x=f===n;if(!x&&!Q(f.formulas,m))continue;const g=new X;f.formulas.forEachCell((C,S,M)=>{const z=x?F(C,S,r):[C,S];if(z===null)return;const K=x||P(M,m)?J(M,C,S):null;K===null||!x&&!K.toUpperCase().includes(m)?g.put(z[0],z[1],M):g.put(z[0],z[1],Y(M,K,r,x,n.name))}),f.formulas=g}const y=tn(t,n,r),d=cn(n,r),p=t.engine;if(p){for(const f of p.names.values())f.text=T(f.text,r,!1,n.name);p.names.size>0&&(t.namesChanged=!0),p.nameTemplates.clear(),p.rebuild()}n.viewChanged=!0,n.revision++,t.collab?.structureDone(n);const R=(f,x,g)=>()=>R(f(n),x(n),g(n));return R(d,y,u)}function Cn(t,n,r){const s=r.at-n.c0,o=n.columns.slice(),c=n.totals?.slice()??null;if(r.n>0){const l=new Set(o.map(u=>u.toLowerCase())),e=[];for(let u=0,a=1;u<r.n;u++){for(;l.has(`column${a}`);)a++;l.add(`column${a}`),e.push(`Column${a}`)}o.splice(s,0,...e),c?.splice(s,0,...e.map(()=>null)),n.headerRows>0&&e.forEach((u,a)=>n.sheet.setCell(n.r0,r.at+a,sn,t.strings.add(u)))}else{const l=Math.max(s,0),e=Math.min(-r.n-Math.max(0,n.c0-r.at),o.length-l);o.splice(l,e),c?.splice(l,e)}n.columns=o,n.totals=c,n.columnsChanged=!0}function $(t,n){const r=t.engine;return{columns:n.columns,rows:n.rows,cols:n.cols,rowStyles:n.rowStyles,colStyles:n.colStyles,rowExtras:n.rowExtras,colExtras:n.colExtras,valueMeta:n.valueMeta,merges:n.merges,spills:n.spills,maxRow:n.maxRow,maxCol:n.maxCol,frozenRows:n.frozenRows,frozenCols:n.frozenCols,colsChanged:n.colsChanged,structureOps:n.structureOps,pageSetup:n.pageSetup?en(n.pageSetup):null,formulas:t.sheets.map(s=>[s,s.formulas]),names:r?[...r.names].map(([s,o])=>[s,{...o}]):null}}function D(t,n,r){return()=>{const s=$(t,n);n.columns=r.columns,n.rows=r.rows,n.cols=r.cols,n.rowStyles=r.rowStyles,n.colStyles=r.colStyles,n.rowExtras=r.rowExtras,n.colExtras=r.colExtras,n.valueMeta=r.valueMeta,n.merges=r.merges,n.mergeIndex=null,n.spills=r.spills,n.maxRow=r.maxRow,n.maxCol=r.maxCol,n.frozenRows=r.frozenRows,n.frozenCols=r.frozenCols,n.colsChanged=r.colsChanged,n.structureOps=r.structureOps,r.pageSetup&&(n.pageSetup=r.pageSetup);for(const[c,l]of r.formulas)c.formulas=l;const o=t.engine;return o&&((o.names.size||r.names.length)&&(t.namesChanged=!0),o.names=new Map(r.names),o.nameTemplates.clear(),o.rebuild()),n.revision++,D(t,n,s)}}export{ln as FORMULA,I as captureFeatures,On as featuresUndo,rn as restoreFeatures,An as shiftBand,tn as shiftFeatures,Un as shiftStructure,xn as structureUndo};
|
package/core/styles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d='"Aptos Narrow","Calibri","Carlito","Arial Narrow","Helvetica Neue",Arial,sans-serif',u="Aptos Narrow",m=12;function c(){return{fontName:u,fontSize:12,bold:!1,italic:!1,underline:0,strike:!1,color:null,fill:null,borders:null,numFmt:"General",hAlign:null,vAlign:null,wrap:!1,indent:0,rotation:0,shrink:!1}}const g=["pattern","gradient","quotePrefix","vertAlign","namedStyle","unlocked","hiddenFormula","readingOrder","justifyLastLine"];function x(f){return JSON.stringify(f,(t,i)=>t[0]==="_"?void 0:i)}class b{constructor(){this.list=[c()],this.index=null,this.sourceCount=0,this.deriveCache=new Map,this.hasButtons=!1,this.hasExt=!1}get(t){return this.list[t]??this.list[0]}explicitDefault(){if(this.list[this.defaultCellId]!==this.list[0]){if(this.list.length>=65535)throw new Error("Too many cell formats");this.defaultCellId=this.list.length,this.list.push(this.list[0])}return this.defaultCellId}load(t){this.list=t.length?t:[c()],this.sourceCount=t.length,this.index=null,this.hasExt=!1,this.hasButtons=!1,this.deriveCache.clear()}intern(t){if(this.index===null){this.index=new Map;for(let n=this.list.length-1;n>=0;n--)this.index.set(x(this.list[n]),n)}const i=x(t);let l=this.index.get(i);if(l===void 0){if(l=this.list.length,l>=65535)throw new Error("Too many cell formats");this.list.push(t),this.index.set(i,l)}return l}derive(t,i,l=JSON.stringify(i)){let n=this.deriveCache.get(l);n===void 0&&(n=new Map,this.deriveCache.set(l,n));let h=n.get(t);if(h===void 0){const a=this.get(t),s={...a,...i};for(const e of Object.keys(s))e[0]==="_"&&delete s[e];if(i.ext!==void 0){const e={...a.ext??{},...i.ext??{}};for(const r of Object.keys(e))e[r]===null&&delete e[r];Object.keys(e).length>0?(s.ext=e,e.buttons!==void 0&&(this.hasButtons=!0),this.hasExt=!0):delete s.ext}if(a.themeRefs||i.themeRefs){const e={...a.themeRefs};for(const[r,o]of Object.entries(i.themeRefs??{}))o!==void 0&&(e[r]=o);for(const[r,o]of[["fill","fill"],["color","color"],["fontName","font"],["pattern","patternFg"]])r in i&&!i.themeRefs?.[o]&&delete e[o];Object.keys(e).length?s.themeRefs=e:delete s.themeRefs}for(const e of g)(s[e]===null||s[e]===void 0||s[e]===!1)&&delete s[e];h=this.intern(s),n.set(t,h)}return h}}function k(f,t){const i=f.fontName===u?d:`"${f.fontName}",${d}`;return`${f.italic?"italic ":""}${f.bold?"bold ":""}${t}px ${i}`}export{u as DEFAULT_FONT,m as DEFAULT_SIZE,d as FONT_FALLBACK,b as StyleTable,k as cssFont,c as defaultStyle};
|
package/core/tables.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{patchTableColumns as
|
|
2
|
-
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="${e}" name="${
|
|
1
|
+
import{formulaEntryLimit as H}from"../calc/parser.js";import{patchTableColumns as q,totalsChildXml as B}from"../slicers/table-file.js";import{allUndo as J,cowTx as Q,rectsTouch as A}from"../cells/block.js";import{checkBandShift as V,MSG_OFF as k}from"../cells/shift-check.js";import{unmergeCells as ee}from"./merge.js";import{shiftBand as te}from"./structure.js";import{colName as re,MAX_COLS as ne,MAX_ROWS as se,rangeRef as L,sheetPrefix as le}from"./address.js";import{columnStem as M,freeColumnName as oe,newColumnName as ae,nextName as ce,tableStem as ie,totalLabel as ue}from"./default-names.js";import{FORMULA as D,KIND_MASK as _,STR as v}from"./sheet.js";import{translateFormula as fe}from"./formula-refs.js";import{autoFilterXml as me,sortStateXml as de}from"../cells/filter-file.js";import{PRESET_DXFS as pe,PRESET_STYLES as K}from"./table-presets.js";import{resolveColor as he}from"../io/xlsx-styles.js";import{elementTableColors as we}from"../slicers/custom-styles.js";import{undoGroup as be}from"../cells/undo-group.js";import{escapeMarkup as F,xmlAttr as I}from"../io/xml-escape.js";const Ce=["FFFFFF","000000","E8E8E8","0E2841","156082","E97132","196B24","0F9ED5","A02B93","4EA72E"],P=new Set;function qe(t){P.add(t)}function ge(t,e){const r=K[t];if(!r)return null;const s=e&&e.length>=10?e:Ce,n=c=>typeof c=="string"?`#${c}`:he({a:{theme:String(c[0]),tint:c[1]?String(c[1]):void 0}},s),a={},o={};for(const[c,l,i]of r){const u=pe[l],f={};u.bold&&(f.bold=!0),u.italic&&(f.italic=!0),u.c&&(f.color=n(u.c)),u.f&&(f.fill=n(u.f));for(const m of["l","r","t","b","v","h"])u[m]&&(f.borders??={},f.borders[m]={style:u[m][0],color:n(u[m][1])});a[c]=f,i&&(o[c]=i)}return{el:a,sizes:o}}const Z=new WeakMap,$e={};function Re(t,e){if(t&&K[t]&&t.startsWith("TableStyle")){const r=e&&e.length>=10?e:$e;let s=Z.get(r);s||Z.set(r,s=new Map);let n=s.get(t);if(!n){const{el:a,sizes:o}=ge(t,e),c=l=>o[l]??1;n=we(a,[c("firstRowStripe"),c("secondRowStripe")],[c("firstColumnStripe"),c("secondColumnStripe")]),s.set(t,n)}return n}for(const r of P){const s=r(t,e);if(s)return s}return null}function Je(t,e){const r=t.r0+t.headerRows,s=t.sheet?.rows;if(!s||s.hiddenSizes===null||s.hiddenSizes.size===0)return e-r;let n=t._bandRows;if(!n||n.version!==s.version||n.top!==r||n.r1!==t.r1||n.rows!==s){const c=[];for(const l of s.hiddenSizes.keys())l>=r&&l<=t.r1&&c.push(l);c.sort((l,i)=>l-i),n={version:s.version,top:r,r1:t.r1,rows:s,list:c},t._bandRows=n}let a=0,o=n.list.length;for(;a<o;){const c=a+o>>1;n.list[c]<e?a=c+1:o=c}return e-r-a}function Se(t){const e=t.engine;return ce(ie(),r=>e.tables.has(r.toUpperCase()))}function Qe(t,e,r,s,n="TableStyleMedium2",a=[]){const o=t.engine,c=[];let l={...r};const i={...l,r0:l.r0-1,r1:l.r0-1},u=S(t,e),f=!s&&l.r0>0&&!O(e,i.r0,l.c0,l.c1)&&!u.some(d=>A(d,i))&&!e.merges.some(d=>A(d,i))&&!a.some(d=>d.anchor?.sheet===e&&d.renderedRange&&A(d.renderedRange,i)),m=!s&&!f;let h=null;return t.transact("table",d=>{if(e.protection)return;if(m){const p=l.r1+1>=se?k:V(t,e,{...l,r1:l.r0},"down",1,a);if(p)throw new Te(p)}const w=[];if(e.merges.some(p=>A(p,l))&&w.push(ee(e,l)),m?(w.push(te(t,e,{axis:"row",at:l.r0,n:1,span:[l.c0,l.c1]})),d=Q(e),l.r1++):f&&l.r0--,!s)for(let p=l.c0;p<=l.c1;p++)t.setInput(d,l.r0,p,`${M()}${p-l.c0+1}`);const b=new Set;for(let p=l.c0;p<=l.c1;p++){let $=t.editText(e,l.r0,p).trim()||`${M()}${p-l.c0+1}`,g=$;for(let R=2;b.has(g.toLowerCase());R++)g=`${$}${R}`;b.add(g.toLowerCase()),c.push(g),(g!==$||(e.kind(l.r0,p)&_)!==v)&&($=g,d.saveCell(l.r0,p),e.setCell(l.r0,p,v,t.strings.add(g)))}h={name:Se(t),sheet:e,...l,headerRows:1,totalsRows:0,columns:c,styleName:n,showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1,filter:{r0:l.r0,c0:l.c0,r1:l.r1,c1:l.c1,columns:new Map},isNew:!0,dirty:!0},o.tables.set(h.name.toUpperCase(),h);const C=p=>()=>(p?o.tables.set(h.name.toUpperCase(),h):o.tables.delete(h.name.toUpperCase()),o.rebuild(),C(!p));return J([...w,C(!1)])}),h}class Te extends Error{}function O(t,e,r,s){for(let n=r;n<=s;n++)if(t.kind(e,n)!==0)return!0;return!1}function S(t,e){const r=[];if(t.engine)for(const s of t.engine.tables.values())s.sheet===e&&r.push(s);return r}function Ve(t,e,r,s){for(const n of S(t,e)){const a=r===n.r1+1-0&&n.totalsRows===0&&s>=n.c0&&s<=n.c1,o=s===n.c1+1&&r>=n.r0&&r<=n.r1;if(a)return n.r1=r,n.filter&&(n.filter.r1=r),n.dirty=!0,r-1>=n.r0+n.headerRows&&t.transact("table-row",c=>{for(let l=n.c0;l<=n.c1;l++)l===s||(e.kind(r-1,l)&D)===0||e.kind(r,l)!==0||t.setInput(c,r,l,`=${fe(t.editText(e,r-1,l).slice(1),1,0)}`,{overLimitAsText:!0})}),t.engine.rebuild(),n;if(o){n.c1=s;const c=t.editText(e,n.r0,s).trim()||ae(new Set(n.columns.map(l=>l.toLowerCase())),n.columns);return n.columns.push(c),n.filter&&(n.filter.c1=s),e.kind(n.r0,s)===0&&e.setCell(n.r0,s,v,t.strings.add(c)),n.dirty=!0,n.columnsChanged=!0,t.engine.rebuild(),n}}return null}function ke(t,e,r){for(const s of S(t,e)){if(r.r0!==s.r1+1||s.totalsRows!==0||r.c0<s.c0||r.c0>s.c1)continue;const n=r.r1;if(S(t,e).some(o=>o!==s&&o.r0<=n&&o.r1>=r.r0&&o.c0<=s.c1&&o.c1>=s.c0))return null;const a={r1:s.r1,filter:s.filter?{...s.filter}:null};return t.transact("table-expand",()=>{const o=i=>{s.r1=i.r1,s.filter=i.filter?{...i.filter}:null,s.dirty=!0,t.engine.rebuild()},c={r1:n,filter:s.filter?{...s.filter,r1:n}:null};o(c);const l=(i,u)=>()=>(o(i),l(u,i));return l(a,c)}),s}return null}function et(t,e,r,s,n,a){if(!n.startsWith("="))return!1;for(const o of S(t,e)){if(s<o.c0||s>o.c1||r<=o.r0||r>o.r1-o.totalsRows)continue;const c=o.r0+o.headerRows,l=o.r1-o.totalsRows;for(let i=c;i<=l;i++)if(i!==r&&e.kind(i,s)!==0)return!1;return l===c?!1:(t.transact("calculated-column",i=>{for(let u=c;u<=l;u++)u!==r&&t.setInput(i,u,s,`=${a(n.slice(1),u-r,0)}`,{overLimitAsText:!0})}),!0)}return!1}const j=(t,e)=>{const r=t.totals?.[e];return r?r.label!==void 0?` totalsRowLabel="${I(r.label)}"`:` totalsRowFunction="${r.fn}"`:""},W=t=>`<tableStyleInfo name="${I(t.styleName??"TableStyleMedium2")}" showFirstColumn="${t.showFirstColumn?1:0}" showLastColumn="${t.showLastColumn?1:0}" showRowStripes="${t.showRowStripes===!1?0:1}" showColumnStripes="${t.showColumnStripes?1:0}"/>`,xe=t=>L({r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1}),Y=t=>t.filter&&t.headerRows>0?me({...t.filter,r0:t.r0,c0:t.c0,r1:t.r1-t.totalsRows,c1:t.c1},!1)+de(t.filter.sortState):"",G=t=>`${t.headerRows===0?' headerRowCount="0"':""}${t.totalsRows?` totalsRowCount="${t.totalsRows}"`:' totalsRowShown="0"'}`;function tt(t,e){const r=t.columns.map((n,a)=>{const o=B(t,a),c=`<tableColumn id="${t.columnIds?.[a]??a+1}" name="${I(n)}"${j(t,a)}`;return o?`${c}>${o}</tableColumn>`:`${c}/>`}).join(""),s=Y(t);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="${e}" name="${F(t.name)}" displayName="${F(t.name)}" ref="${L(t)}"${G(t)}>${s}<tableColumns count="${t.columns.length}">${r}</tableColumns>${W(t)}</table>`}function rt(t){return{name:t.name,ref:L(t),filterRef:t.filter&&t.headerRows>0?xe(t):null,filterXml:Y(t),counts:G(t),styleInfo:W(t),totals:t.totals?t.columns.map((e,r)=>j(t,r)):null,totalsChild:t.totals?t.columns.map((e,r)=>B(t,r)):null}}function nt(t,e){let r=t.replace(/<table\b[^>]*>/,s=>s.replace(/\bname="[^"]*"/,`name="${F(e.name)}"`).replace(/\bdisplayName="[^"]*"/,`displayName="${F(e.name)}"`).replace(/\bref="[^"]*"/,`ref="${e.ref}"`).replace(/\s(?:headerRowCount|totalsRowCount|totalsRowShown)="[^"]*"/g,"").replace(/\s*(\/?)>$/,`${e.counts}$1>`));return r=r.replace(/<autoFilter\b[^>]*\/>|<autoFilter\b[\s\S]*?<\/autoFilter>/,"").replace(/<sortState\b[^>]*\/>|<sortState\b[\s\S]*?<\/sortState>/,""),e.filterXml&&(r=r.replace("<tableColumns",`${e.filterXml}<tableColumns`)),/<tableStyleInfo\b/.test(r)?r=r.replace(/<tableStyleInfo\b[^>]*\/>/,e.styleInfo):r=r.replace("</tableColumns>",`</tableColumns>${e.styleInfo}`),e.totals&&(r=q(r,e)),r}const ye=/[[\]#']/g,U=t=>t.replace(ye,"'$&"),ve=/^[A-Za-z_\\][A-Za-z0-9_.\\]*$/;function z(t,e){const r=[];for(const s of t.sheets){const n=new Map;for(const[a,o]of s.formulas){const c=o.f??o.sf;if(typeof c!="string")continue;const l=o.f===void 0&&o.base!==void 0;let i=l?n.get(o):void 0;if(i===void 0){const u=e(c,s,Math.floor((l?o.base:a)/ne));i=u===c?null:o.f!==void 0?{...o,f:u,tpl:void 0}:{...o,sf:u,tpl:void 0},l&&n.set(o,i)}i!==null&&r.push([s.formulas,a,o,i])}}for(const[s,n]of t.engine.names){const a=e(n.text,null,0,s);a!==n.text&&r.push([t.engine.names,s,n,{...n,text:a}])}for(const s of t.engine.tables.values())s.totals?.forEach((n,a)=>{if(n?.fn!=="custom"||!n.formula)return;const o=e(n.formula,s.sheet,s.r1);o!==n.formula&&r.push([{set:(c,l)=>{s.totals[c]=l,s.dirty=!0}},a,n,{...n,formula:o}])});return t.formulasEdited=!0,r.some(s=>s[0]===t.engine.names)&&(t.namesChanged=!0),E(r,3),r}const E=(t,e)=>{for(const r of t)r[0].set(r[1],r[e])};function T(t,e,r,s,{rebuild:n=!1}={}){const a=t.engine;t.transact(r,o=>{const c={...e},l=s(o),i={...e};e.dirty=!0,n&&a.rebuild();const u=(f,m,h)=>()=>(Object.assign(e,f),e.dirty=!0,h?.(),n&&a.rebuild(),u(m,f,h));return u(c,i,l)})}function st(t,e,r,s){T(t,e,"table-option",()=>{e[r]=s})}function lt(t,e,r){r&&e.headerRows===0||T(t,e,"table-filter",()=>{e.filter=r?{r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}:null})}function ot(t,e,r){const s=t.engine;if(!ve.test(r)||/^[A-Za-z]{1,3}[0-9]+$/.test(r)||/^[Rr][Cc]?$|^[Cc]$/.test(r))return"That isn't a valid table name.";const n=r.toUpperCase();if(n===e.name.toUpperCase()&&r===e.name)return null;if(s.tables.has(n)&&s.tables.get(n)!==e)return"Another table already uses that name.";if(s.names.has(n))return"A defined name already uses that name.";const a=e.name;return t.transact("table-name",()=>{const o=new RegExp(`(^|[^A-Za-z0-9_.\\\\])${a.replace(/[.\\]/g,"\\$&")}(?=\\[)`,"gi"),c=z(t,f=>f.replace(o,`$1${r}`)),l=(f,m,h)=>{s.tables.delete(f.toUpperCase()),e.name=m,s.tables.set(m.toUpperCase(),e),e.dirty=!0,E(c,h),s.rebuild()};l(a,r,3);const i=()=>(l(a,r,3),u),u=()=>(l(r,a,2),i);return u}),null}const Ee={average:101,countNums:102,count:103,max:104,min:105,stdDev:107,sum:109,var:110};function Ae(t,e,r){if(!r)return null;if(r.label!==void 0)return r.label;if(r.fn==="custom")return r.formula?`=${r.formula}`:null;const s=Ee[r.fn];return s?`=SUBTOTAL(${s},${t.name}[${U(t.columns[e])}])`:null}function at(t,e,r){const{sheet:s}=e;if(r===e.totalsRows>0)return null;if(r){const a=e.r1+1;if(O(s,a,e.c0,e.c1))return"Clear the row under the table to add a total row.";const o=e.columns.map((l,i)=>e.totals?.[i]??null);if(!o.some(Boolean)&&(o[0]={label:ue()},o.length>1)){let l=!1;for(let i=e.r0+e.headerRows;i<=e.r1&&!l;i++)l=(s.kind(i,e.c1)&_)===1;o[o.length-1]={fn:l?"sum":"count"}}const c=o.map((l,i)=>Ae(e,i,l));for(let l=0;l<c.length;l++){if(o[l]?.label!==void 0||!c[l])continue;const i=H(c[l].slice(1));if(i)return i}return T(t,e,"table-totals",l=>{e.totals=o,c.forEach((i,u)=>{o[u]?.label!==void 0?t.setRichInput(l,a,e.c0+u,i,null):i&&t.setInput(l,a,e.c0+u,i)}),e.totalsRows=1,e.r1=a,e.columnsChanged=e.source!==!0},{rebuild:!0}),null}const n=e.r1;return T(t,e,"table-totals",a=>{for(let o=e.c0;o<=e.c1;o++)t.setInput(a,n,o,"");e.totalsRows=0,e.r1=n-1},{rebuild:!0}),null}function ct(t,e,r){if(r===e.headerRows>0)return null;const{sheet:s}=e;return r?e.r0===0||O(s,e.r0-1,e.c0,e.c1)?"Clear the row above the table to show its headers.":(T(t,e,"table-header",n=>{e.r0-=1,e.headerRows=1,e.columns.forEach((a,o)=>t.setRichInput(n,e.r0,e.c0+o,a,null)),e.filter={r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}},{rebuild:!0}),null):(T(t,e,"table-header",n=>{for(let a=e.c0;a<=e.c1;a++)t.setInput(n,e.r0,a,"");e.r0+=1,e.headerRows=0,e.filter=null},{rebuild:!0}),null)}function it(t,e,r){const{sheet:s}=e;if(r.r0!==e.r0)return"The header row must stay in the same row.";if(r.c0!==e.c0)return"The table must keep its first column.";if(r.r1<r.r0+e.headerRows+e.totalsRows)return"The table needs at least one data row.";for(const n of S(t,s))if(n!==e&&n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0)return"A table can't overlap another table.";return T(t,e,"table-resize",()=>{const n=r.c1-r.c0+1,a=e.columns.slice(0,n);for(let o=a.length;o<n;o++){const c=e.c0+o;let l=e.headerRows?t.editText(s,e.r0,c).trim():"";l||(l=`${M()}${o+1}`),a.push(l)}e.columns=a,e.r1=r.r1,e.c1=r.c1,e.filter&&(e.filter={r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1,columns:new Map}),e.columnsChanged=!0},{rebuild:!0}),null}function Fe(t,e,r){const{sheet:s}=e,n=e.r1-e.r0+1,a=e.c1-e.c0+1,o=new Map,c=(i,u,f,m)=>{const h=(i-e.r0)*a+(u-e.c0);let d=o.get(h);d||o.set(h,d={}),d[f]=m};for(const i of r.areas(e,e.r0,e.r1,e.c0,e.c1)){const u=i.borders;for(let f=Math.max(i.r0,e.r0);f<=Math.min(i.r1,e.r1);f++)for(let m=Math.max(i.c0,e.c0);m<=Math.min(i.c1,e.c1);m++)u.t&&f===i.r0&&c(f,m,"t",u.t),u.b&&f===i.r1&&c(f,m,"b",u.b),u.l&&m===i.c0&&c(f,m,"l",u.l),u.r&&m===i.c1&&c(f,m,"r",u.r),u.h&&f<i.r1&&c(f,m,"b",u.h),u.v&&m<i.c1&&c(f,m,"r",u.v)}const l=new Map;t.transact("format",i=>{for(let u=0;u<n;u++){const f=e.r0+u;for(let m=0;m<a;m++){const h=e.c0+m,d=r.format(e,f,h),w=o.get(u*a+m),b=s.style(f,h),C=t.styles.get(b),p={};if(d.fill&&!C.fill&&(p.fill=d.fill),d.color&&!C.color&&(p.color=d.color),d.bold&&!C.bold&&(p.bold=!0),d.italic&&!C.italic&&(p.italic=!0),w){const x=C.borders??{},X={l:x.l??null,r:x.r??null,t:x.t??null,b:x.b??null};let N=!1;for(const y of["l","r","t","b"])w[y]&&!x[y]&&(X[y]={style:w[y].style,color:w[y].color},N=!0);N&&(p.borders=X)}const $=JSON.stringify(p);if($==="{}")continue;const g=`${b}|${$}`;let R=l.get(g);R===void 0&&l.set(g,R=t.styles.derive(b,p,$)),R!==b&&(i.saveCell(f,h),s.setStyle(f,h,R))}}})}function ut(t,e){be(t,"Convert to Range",()=>Le(t,e))}function Le(t,e){const r=t.engine,{sheet:s}=e,n=Re(e.styleName,t.theme),a=t.activeSheet;t.activeSheet=t.sheets.indexOf(s),n?.format&&Fe(t,e,n),t.activeSheet=a;const o=e.name.toUpperCase(),c=new RegExp(`(^|[^A-Za-z0-9_.\\\\])${e.name.replace(/[.\\]/g,"\\$&")}(\\[(?:[^\\[\\]']|'.|\\[(?:[^\\[\\]']|'.)*\\])*\\])`,"gi");t.transact("table-convert",()=>{const l=z(t,(m,h,d)=>m.replace(c,(w,b,C)=>{const p=r.tableSpecToA1(e,C,d);return p===null?w:`${b}${h===s?"":le(s.name)}${p}`})),i=e.source===!0&&e.part?{part:e.part,sheetIndex:t.sheets.indexOf(s)}:null,u=()=>{r.tables.delete(o),i&&(t.removedTables??=[]).push(i),E(l,3),r.rebuild()},f=()=>(r.tables.set(o,e),i&&(t.removedTables=t.removedTables.filter(m=>m!==i)),E(l,2),r.rebuild(),()=>(u(),f));return u(),f})}function Me(t,e,r,s){const n=t.toLowerCase(),a=`${e.toLowerCase()}[`;let o="",c=0;for(let l=n.indexOf(a);l>=0;l=n.indexOf(a,l+1)){const i=l+a.length-1;let u=0,f=i;for(;f<t.length;f++){const d=t[f];if(d==="'")f++;else if(d==="[")u++;else if(d==="]"&&--u===0)break}const m=t.slice(i,f+1),h=m.split(`[${r}]`).join(`[${s}]`);h!==m&&(o+=t.slice(c,i)+h,c=f+1)}return c===0?t:o+t.slice(c)}function _e(t,e,r,s){const n=e.columns[r],a=U(n),o=U(s),c=z(t,f=>f.includes("[")?Me(f,e.name,a,o):f),l=(f,m)=>{e.columns=e.columns.map((h,d)=>d===r?f:h),e.columnsChanged=!0,e.dirty=!0,E(c,m),t.engine?.rebuild()};l(s,3);const i=()=>(l(s,3),u),u=()=>(l(n,2),i);return u}function ft(t,e,r){let s=null;const{sheet:n}=e;for(const a of S(t,n))if(!(a.headerRows===0||a.dataSheet))for(let o=0;o<r.count;o++){if(r.rows[o]!==a.r0||r.cols[o]<a.c0||r.cols[o]>a.c1)continue;const c=r.cols[o],l=c-a.c0,i=n.kind(a.r0,c);let u=i===0?"":String(t.engine.read(n,a.r0,c)??"").trim();const f=new Set(a.columns.filter((w,b)=>b!==l).map(w=>w.toLowerCase()));if(u==="")u=oe(f);else if(f.has(u.toLowerCase())){const w=u;let b=2;for(;f.has(`${w}${b}`.toLowerCase());)b++;u=`${w}${b}`}if(((i&_)!==v||(i&D)!==0||t.strings.get(n.value(a.r0,c))!==u)&&(e.saveCell(a.r0,c),n.setFormula(a.r0,c,null),n.setCell(a.r0,c,v,t.strings.add(u))),a.columns[l]===u)continue;const m=_e(t,a,l,u),h=s,d=(w,b)=>b?()=>d(w(),b()):w;s=d(m,h)}return s}const mt=[...Array.from({length:21},(t,e)=>`TableStyleLight${e+1}`),...Array.from({length:28},(t,e)=>`TableStyleMedium${e+1}`),...Array.from({length:11},(t,e)=>`TableStyleDark${e+1}`)];export{Ee as SUBTOTAL_CODE,mt as TABLE_STYLE_NAMES,Te as TableCreationError,Je as bandRow,re as colName,ut as convertTableToRange,Qe as createTable,et as fillCalculatedColumn,ke as growTableOver,Ve as maybeExpandTable,Se as nextTableName,nt as patchTableXml,ge as presetElements,ot as renameTable,_e as renameTableColumn,it as resizeTable,z as rewriteFormulas,qe as setCustomTableResolver,lt as setTableFilterButton,ct as setTableHeaderRow,st as setTableOption,at as setTableTotals,U as structuredColumn,ft as syncTableHeaders,Re as tableColors,rt as tablePatch,tt as tableXml,S as tablesOf,Ae as totalInput};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseRangeRef as h,rangeRef as p}from"./address.js";const m=(n,r)=>n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0;function u(n,r){if(!m(n,r))return[n];const s=[],o=Math.max(n.c0,r.c0),f=Math.min(n.c1,r.c1);return n.c0<r.c0&&s.push({...n,c1:r.c0-1}),n.c1>r.c1&&s.push({...n,c0:r.c1+1}),n.r0<r.r0&&s.push({r0:n.r0,c0:o,r1:r.r0-1,c1:f}),n.r1>r.r1&&s.push({r0:r.r1+1,c0:o,r1:n.r1,c1:f}),s}function d(n,r){let s=String(n).split(/\s+/).map(h).filter(Boolean);for(const o of r)s=s.flatMap(f=>u(f,o));return s.map(p).join(" ")}const a=({sqref:n,_ranges:r,...s})=>JSON.stringify(s,Object.keys(s).sort());function q(n,r,s){const o=[];for(const t of n??[]){const e=d(t.sqref,r);e!==""&&o.push(e===t.sqref?t:c(t,e))}if(s===null)return o;const f=r.map(p).join(" "),i=o.findIndex(t=>a(t)===a(s));return i>=0?o[i]=c(o[i],`${o[i].sqref} ${f}`):o.push(c(s,f)),o}function c(n,r){const{_ranges:s,...o}=n;return{...o,sqref:r}}export{d as subtractFromSqref,u as subtractRect,q as withRuleOn};
|
package/core/whatif.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FORMULA as H,KIND_MASK as K,NUM as b,STR as
|
|
1
|
+
import{FORMULA as H,KIND_MASK as K,NUM as b,STR as $}from"./sheet.js";import{cellRef as I,MAX_COLS as W,parseRangeRef as F,rangeRef as X}from"./address.js";async function Z(t,n,r,e,a,{maxIter:o=200,tolerance:l=.001}={}){const u=t.engine,g=async d=>{t.transact("goal-seek",S=>{S.saveCell(e.row,e.col),n.setCell(e.row,e.col,b,d)}),await u.whenIdle();const x=u.read(n,r.row,r.col);return typeof x=="number"?x-a:NaN},s=()=>t.undoStack.length,c=s(),f=n.value(e.row,e.col);let p=f,i=await g(p),v=f===0?1:f*1.01,M=await g(v),E={x:p,f:i},L=null,h=null;for(let d=0;d<o&&((Math.abs(M)<Math.abs(E.f)||Number.isNaN(E.f))&&(E={x:v,f:M}),!(Math.abs(M)<=l));d++){i*M<0&&(L=i<0?p:v,h=i<0?v:p);let x=M===i?v*1.5+1:v-M*(v-p)/(M-i);if(L!==null&&(!Number.isFinite(x)||x<Math.min(L,h)||x>Math.max(L,h))&&(x=(L+h)/2),!Number.isFinite(x))break;p=v,i=M,v=x,M=await g(v)}for(;s()>c;)t.undoStack.pop();t.transact("goal-seek",d=>{d.saveCell(e.row,e.col),n.setCell(e.row,e.col,b,f)});const m=t.undoStack.pop();return t.transact("goal-seek",d=>{d.saveCell(e.row,e.col),n.setCell(e.row,e.col,b,E.x)}),await u.whenIdle(),{value:E.x,found:Math.abs(E.f)<=l,result:u.read(n,r.row,r.col)}}const P=t=>{if(t===void 0)return 0;const n=t.indexOf('outlineLevel="');return n<0?0:t.charCodeAt(n+14)-48},U=(t,n)=>t.rowExtras===null?0:P(t.rowExtras.get(n));function j(t,n,r){t.rowExtras||(t.rowExtras=new Map);const e=(t.rowExtras.get(n)??"").replace(/\s*outlineLevel="\d+"/,"").trim(),a=r>0?`${e} outlineLevel="${r}"`.trim():e;a?t.rowExtras.set(n,a):t.rowExtras.delete(n)}const _=(t,n)=>t.colExtras===null?0:P(t.colExtras.get(n));function z(t,n,r){t.colExtras||(t.colExtras=new Map);const e=(t.colExtras.get(n)??"").replace(/\s*outlineLevel="\d+"/,"").trim(),a=r>0?`${e} outlineLevel="${r}"`.trim():e;a?t.colExtras.set(n,a):t.colExtras.delete(n)}function C(t,n,r,e,a){for(let o=r;o<=e;o++)n==="row"?j(t,o,Math.max(0,Math.min(7,U(t,o)+a))):z(t,o,Math.max(0,Math.min(7,_(t,o)+a)));t.outlineVersion=(t.outlineVersion??0)+1,n==="col"&&(t.colsChanged=!0),t.revision++}function tt(t,n){let r=0;const e=n==="row"?t.rowExtras:t.colExtras;if(e)for(const a of e.values()){const o=/outlineLevel="(\d+)"/.exec(a);o&&(r=Math.max(r,Number(o[1])))}return r}function nt(t,n,r){return n==="row"?U(t,r):_(t,r)}function rt(t,n,r){const e=n==="row"?t.rowExtras:t.colExtras,a=n==="row"?t.rows:t.cols;if(e){for(const[o,l]of e){const u=/outlineLevel="(\d+)"/.exec(l);u&&a.setHidden(o,Number(u[1])>=r)}n==="col"&&(t.colsChanged=!0),t.revision++}}function et(t,n,r,e,a,o){const l=[],u={1:"Average",2:"Count",3:"Count",4:"Max",5:"Min",6:"Product",7:"StdDev",8:"StdDevp",9:"Total",10:"Var",11:"Varp"}[a],g=c=>(n.kind(c,e)&K)===$?t.strings.get(n.value(c,e)):String(n.value(c,e));let s=r.r0+1;for(let c=r.r0+1;c<=r.r1+1;c++)(c>r.r1||g(c)!==g(s))&&(l.push({afterRow:c-1,from:s,to:c-1,title:`${g(s)} ${u}`}),s=c);return{groups:l,functionNum:a,sumCols:o,groupCol:e,grandTitle:`Grand ${u}`}}function ot(t,n,r,e,a){const o={r0:r.r0+1,c0:r.c0+1,r1:r.r1,c1:r.c1},l=e&&a,u={t:"dataTable",ref:X(o),dt2D:l?"1":"0",dtr:e?"1":"0",r1:I((e??a).row,(e??a).col)};l&&(u.r2=I(a.row,a.col));const g=t.engine,s={sheet:n,row:o.r0,col:o.c0,info:u};t.transact("data-table",c=>{for(let i=o.r0;i<=o.r1;i++)for(let v=o.c0;v<=o.c1;v++)c.saveCell(i,v),n.setFormula(i,v,null),n.setCell(i,v,b,0);n.setFormula(o.r0,o.c0,u),n.setCell(o.r0,o.c0,H|b,0),t.formulasEdited=!0,g.dataTables.push(s),g.tablesDirty=!0;const f=()=>(g.dataTables=g.dataTables.filter(i=>i!==s),p),p=()=>(g.dataTables.push(s),g.tablesDirty=!0,f);return f})}const q=(t,n,r,e)=>{const a=n.kind(r,e)&K;return a===0?"":a===$?t.strings.get(n.value(r,e)):String(n.value(r,e))};function at(t,n,r,e){const a=[],o=new Set;for(const l of r.split(/[\s,;]+/)){const u=F(l.replace(/\$/g,""));if(u)for(let g=u.r0;g<=u.r1&&a.length<32;g++)for(let s=u.c0;s<=u.c1&&a.length<32;s++){const c=I(g,s);if(o.has(c))continue;o.add(c);const f=e?.cells.find(p=>p.r===c);a.push({r:c,val:f?f.val:q(t,n,g,s)})}}return a}function ct(t,n,r){t.transact("scenario",e=>{for(const{r:a,val:o}of r.cells){const l=F(a);l&&t.setInput(e,l.r0,l.c0,o,{overLimitAsText:!0})}})}function st(t,n,r,e){const a=t.engine,o=[["Scenario Summary","Current Values",...r.map(s=>s.name)]],l=[];for(const s of r)for(const c of s.cells)l.includes(c.r)||l.push(c.r);const u=s=>{const c=F(s);return{row:c.r0,col:c.c0}};o.push(["Changing Cells:"]);for(const s of l){const{row:c,col:f}=u(s);o.push([s,q(t,n,c,f),...r.map(p=>p.cells.find(i=>i.r===s)?.val??"")])}if(e.length>0){o.push(["Result Cells:"]);const s=r.map(c=>a.evaluateWith(n,c.cells.map(f=>({...u(f.r),text:f.val})),()=>e.map(({row:f,col:p})=>a.read(n,f,p))));e.forEach(({row:c,col:f},p)=>{o.push([I(c,f),String(a.read(n,c,f)??""),...s.map(i=>String(i[p]??""))])})}const g=t.addSheet();return t.transact("scenario-summary",s=>{o.forEach((c,f)=>c.forEach((p,i)=>{p!==""&&t.setInput(s,f,i,String(p),{overLimitAsText:!0})}))}),g}const w=t=>t.filter(n=>typeof n=="number"),R=t=>t.reduce((n,r)=>n+r,0),B=t=>R(t)/t.length,O=(t,n)=>{const r=B(t);return R(t.map(e=>(e-r)**2))/n},J={Sum:t=>R(w(t)),Count:t=>t.filter(n=>n!==null&&n!=="").length,Average:t=>w(t).length?B(w(t)):null,Max:t=>w(t).length?Math.max(...w(t)):0,Min:t=>w(t).length?Math.min(...w(t)):0,Product:t=>w(t).length?w(t).reduce((n,r)=>n*r,1):0,"Count Numbers":t=>w(t).length,StdDev:t=>w(t).length>1?Math.sqrt(O(w(t),w(t).length-1)):null,StdDevp:t=>w(t).length?Math.sqrt(O(w(t),w(t).length)):null,Var:t=>w(t).length>1?O(w(t),w(t).length-1):null,Varp:t=>w(t).length?O(w(t),w(t).length):null};function lt(t,n,r,e,a,{topRow:o=!1,leftCol:l=!1}={}){const u=t.engine,g=J[a],s=[],c=[],f=new Map,p=new Map,i=new Map,v=(h,m,d)=>{const x=String(d).toLowerCase();let S=h.get(x);return S===void 0&&(S=m.length,h.set(x,S),m.push(d)),S};for(const{sheet:h,range:m,read:d}of e){const x=d??((y,T)=>u.read(h,y,T)),S=m.r0+(o?1:0),N=m.c0+(l?1:0);for(let y=S;y<=m.r1;y++){const T=l?x(y,m.c0):y-S;if(l&&(T===null||T===""))continue;const k=v(f,s,T);for(let D=N;D<=m.c1;D++){const A=o?x(m.r0,D):D-N;if(o&&(A===null||A===""))continue;const G=v(p,c,A),V=k*16384+G;i.has(V)||i.set(V,[]),i.get(V).push(x(y,D))}}}const M=r.row+(o?1:0),E=r.col+(l?1:0),L=(h,m,d,x)=>{h.saveCell(m,d),n.setFormula(m,d,null),typeof x=="number"?n.setCell(m,d,b,x):n.setCell(m,d,$,t.strings.add(String(x)))};return t.transact("consolidate",h=>{o&&c.forEach((m,d)=>L(h,r.row,E+d,m)),l&&s.forEach((m,d)=>L(h,M+d,r.col,m));for(const[m,d]of i){const x=Math.floor(m/16384),S=m-x*16384,N=g(d);N!==null&&L(h,M+x,E+S,N)}}),{rows:s.length,cols:c.length}}export{J as CONSOLIDATE_FUNCTIONS,W as MAX_COLS,C as changeOutline,lt as consolidate,ot as createDataTable,Z as goalSeek,tt as maxOutlineLevel,nt as outlineLevel,st as scenarioSummary,at as scenarioValues,rt as showOutlineLevel,ct as showScenario,et as subtotalPlan};
|
package/core/workbook.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{expandBareTables as j}from"../slicers/structured.js";import{syncTableHeaders as J}from"./tables.js";import{BOOL as I,CHUNK_BITS as A,CHUNK_MASK as W,EMPTY as _,ERR as F,ERRORS as Z,FORMULA as v,DIRTY as N,EVALUATING as z,KIND_MASK as Y,NUM as P,Sheet as T,SPILL as X,STR as R}from"./sheet.js";import{cellRef as Q,MAX_COLS as w,MAX_ROWS as B,quoteSheetName as ee,rangeRef as te,renameSheetInFormula as D,sheetReferencePattern as q}from"./address.js";import{translateFormula as se}from"./formula-refs.js";import{sheetStem as G}from"./default-names.js";import{StringTable as ne}from"./strings.js";import{StyleTable as ie}from"./styles.js";import{parseInput as H}from"./input.js";import{noteChanges as V}from"./changes.js";import{overrideRuns as le}from"../cells/rich-runs.js";import{sheetRenameHooks as re}from"./sparse.js";import{shiftRuleFormulas as oe}from"../cells/cf-file.js";import{expandStructured as ae,toDisplayFormula as K,toFileFormula as he}from"../calc/parser.js";const ce=200,ue=new Set(["entry","clear","format","borders","fill"]);class fe{constructor(){this.ids=new Int32Array(1024),this.list=[]}set(t,e){if(t>=this.ids.length){let l=this.ids.length*2;for(;l<=t;)l*=2;const i=new Int32Array(l);i.set(this.ids),this.ids=i}const n=this.list.length;(n===0||this.list[n-1]!==e)&&this.list.push(e),this.ids[t]=this.list.length}get(t){const e=t<this.ids.length?this.ids[t]:0;return e===0?void 0:this.list[e-1]}}class b{constructor(){this.capacity=1024,this.count=0,this.rows=new Uint32Array(this.capacity),this.cols=new Uint16Array(this.capacity),this.kinds=new Uint8Array(this.capacity),this.styles=new Uint16Array(this.capacity),this.values=new Float64Array(this.capacity),this.formulas=null,this.vms=null}_grow(){const t=this.capacity*2,e=(n,l)=>{const i=new n(t);return i.set(l),i};this.rows=e(Uint32Array,this.rows),this.cols=e(Uint16Array,this.cols),this.kinds=e(Uint8Array,this.kinds),this.styles=e(Uint16Array,this.styles),this.values=e(Float64Array,this.values),this.capacity=t}push(t,e,n){this.count===this.capacity&&this._grow();const l=this.count++,i=t.kind(e,n)&~(N|z);if(this.rows[l]=e,this.cols[l]=n,this.kinds[l]=i,this.styles[l]=t.cellStyle(e,n),this.values[l]=t.value(e,n),i&v&&(this.formulas===null&&(this.formulas=new fe),this.formulas.set(l,t.formula(e,n))),t.valueMeta!==null){const s=t.valueMeta.get(e*w+n);s!==void 0&&(this.vms??=new Map).set(l,s)}}}class be{constructor(){this.sheets=[new T(`${G()}1`)],this.activeSheet=0,this.strings=new ne,this.styles=new ie,this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.source=null,this.formulasEdited=!1,this.edits=0,this._dirty=!1,this.engine=null,this.selectedSheets=null}get sheet(){return this.sheets[this.activeSheet]}get dirty(){return this._dirty}set dirty(t){t&&this.edits++,this._dirty=!!t}onChange(t){this.listeners.add(t)}_emit(t){this.dirty=!0;for(const e of this.listeners)e(t)}addSheet(t){const e=G();let n=1,l=t??`${e}${n}`;const i=o=>this.sheets.some(r=>r.name.toLowerCase()===o.toLowerCase());for(;i(l);)l=`${e}${++n}`;const s=new T(l);return this.sheets.push(s),this.activeSheet=this.sheets.length-1,this.engine?.sheetsChanged(),this._emit("sheets"),s}deleteSheet(t){if(this.sheets.filter(n=>!n.hidden).length<=1)return!1;this._shrink3D(t),this._refErrorsFor(t);const[e]=this.sheets.splice(t,1);if(this.selectedSheets?.delete(e),this._forgetSheet(e,t),this.engine)for(const[n,l]of this.engine.tables)l.sheet===e&&this.engine.tables.delete(n);for(this._reindexNames(n=>n===t?-1:n>t?n-1:n),this.activeSheet>=this.sheets.length&&(this.activeSheet=this.sheets.length-1);this.sheets[this.activeSheet].hidden;)this.activeSheet=(this.activeSheet+1)%this.sheets.length;return this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),!0}_forgetSheet(t,e){const n=i=>i.sheet===t||i.sheet===void 0&&i.sheetIndex===e||(i.extra?.parts??[]).some(n),l=i=>{i.sheetIndex>e&&i.sheetIndex--;for(const s of i.extra?.parts??[])l(s)};for(const i of[this.undoStack,this.redoStack]){const s=i.filter(o=>!n(o));s.forEach(l),i.splice(0,i.length,...s)}}moveSheet(t,e){if(t===e)return;const n=this.sheet,[l]=this.sheets.splice(t,1);this.sheets.splice(e,0,l),this.activeSheet=this.sheets.indexOf(n);const i=o=>o===t?e:t<e?o>t&&o<=e?o-1:o:o>=e&&o<t?o+1:o,s=o=>{o.sheetIndex=i(o.sheetIndex);for(const r of o.extra?.parts??[])s(r)};for(const o of this.undoStack)s(o);for(const o of this.redoStack)s(o);this.structureEdited=!0,this._reindexNames(i),this.engine?.orderChanged(),this._emit("sheets")}_copyScopedNames(t,e,n){const{engine:l}=this;if(!l||l.names.size===0)return;const i=`${t}!`;let s=!1;for(const[o,r]of[...l.names])o.startsWith(i)&&(l.names.set(`${t+1}!${o.slice(i.length)}`,{...r,text:D(r.text,e.name,n.name)}),s=!0);s&&(this.namesChanged=!0)}_reindexNames(t){const{engine:e}=this;if(!e||e.names.size===0)return;const n=[];let l=!1;for(const[i,s]of e.names){const o=i.indexOf("!"),r=o<0?0:t(Number(i.slice(0,o)));o>=0&&r!==Number(i.slice(0,o))&&(l=!0),o<0?n.push([i,s]):r>=0&&n.push([`${r}!${i.slice(o+1)}`,s])}if(l){e.names.clear();for(const[i,s]of n)e.names.set(i,s);e.nameTemplates.clear(),this.namesChanged=!0,e.rebuild()}}duplicateSheet(t){const e=this.sheets[t];let l=`${e.name} (2)`,i=2;for(;this.sheets.some(a=>a.name.toLowerCase()===l.toLowerCase());)l=`${e.name} (${++i})`;const s=new T(l);e.columns.forEach((a,h)=>{const u=[];a.forEach((c,g)=>{u[g]={kinds:c.kinds.slice(),values:c.values.slice(),styles:c.styles?c.styles.slice():null}}),s.columns[h]=u}),s.maxRow=e.maxRow,s.maxCol=e.maxCol,s.rows=e.rows.shifted(0,0),s.cols=e.cols.shifted(0,0);const o=new Map;e.formulas.forEachCell((a,h,u)=>{let c=o.get(u);c===void 0&&(c={...u,tpl:void 0},o.set(u,c)),s.setFormula(a,h,c)}),s.merges=e.merges.map(a=>({...a})),s.rowStyles=e.rowStyles?new Map(e.rowStyles):null,s.colStyles=e.colStyles?new Map(e.colStyles):null,s.frozenRows=e.frozenRows,s.frozenCols=e.frozenCols,s.showGridlines=e.showGridlines,s.cellTypes=e.cellTypes?new Map(e.cellTypes):null,s.sparkRules=e.sparkRules,s.cellDropdowns=e.cellDropdowns?new Map(e.cellDropdowns):null,s.cellTags=e.cellTags?new Map(e.cellTags):null,s.cellButtons=e.cellButtons?new Map(e.cellButtons):null,s.cellStates=e.cellStates?e.cellStates.slice():null,s.autoMerges=e.autoMerges?e.autoMerges.map(a=>({...a})):null,s.background=e.background,s.outlineColumn=e.outlineColumn?{...e.outlineColumn}:null,s.frozenTrailingRows=e.frozenTrailingRows,s.frozenTrailingCols=e.frozenTrailingCols,s.hideZeros=e.hideZeros,s.hideHeadings=e.hideHeadings,s.isChartSheet=e.isChartSheet,s.hideOutline=e.hideOutline,s.gridColorId=e.gridColorId,s.areaOffset=e.areaOffset,s.selectionPolicy=e.selectionPolicy,s.selectionUnit=e.selectionUnit,s.gridlineAxes=e.gridlineAxes,s.gridColor=e.gridColor,s.tabStyles=e.tabStyles;const r=x;return s.cf=r(e.cf),s.validations=r(e.validations),s.comments=r(e.comments),s.threads=r(e.threads),s.hyperlinks=e.hyperlinks?e.hyperlinks.map(a=>({...r({...a,_ranges:void 0})})):e.hyperlinks,s.autoFilter=r(e.autoFilter),s.filteredRows=e.filteredRows?new Set(e.filteredRows):e.filteredRows,s.pageSetup=r(e.pageSetup),s.tabColor=e.tabColor,s.protection=r(e.protection),s.rtl=e.rtl,s.zoom=e.zoom,s.valueMeta=e.valueMeta?new Map(e.valueMeta):null,s.colsChanged=!0,s.viewChanged=!0,this.sheets.splice(t+1,0,s),this.activeSheet=t+1,this._reindexNames(a=>a>t?a+1:a),this._copyScopedNames(t,e,s),this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),s}sheetNameProblem(t,e){const n=e.trim().slice(0,31);return!n||/[\\/?*[\]:]/.test(n)||/^'|'$/.test(n)?"rules":n.toLowerCase()==="history"?"reserved":this.sheets.some((l,i)=>i!==t&&l.name.toLowerCase()===n.toLowerCase())?"taken":null}renameSheet(t,e){const n=e.trim().slice(0,31);if(this.sheetNameProblem(t,e)!==null)return!1;const l=this.sheets[t].name;this.sheets[t].name=n,this._renameInFormulas(l,n);for(const i of re)i(this,l,n);return this.engine?.sheetsChanged(),this._emit("sheets"),!0}_shrink3D(t){const e=this.sheets[t].name.toLowerCase(),n=r=>this.sheets.findIndex(a=>a.name.toLowerCase()===r.toLowerCase()),l=r=>r[0]==="'"?r.slice(1,-1).replace(/''/g,"'"):r,i=/((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*)):((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*))!/g,s=r=>r.replace(i,(a,h,u,c)=>{if(r[c-1]==="]")return a;const g=l(h),p=l(u);if(g.toLowerCase()!==e&&p.toLowerCase()!==e)return a;let f=n(g),S=n(p);if(f<0||S<0||(f>S&&([f,S]=[S,f]),f===t&&f++,S===t&&S--,f>S))return a;const d=y=>ee(this.sheets[y].name);return f===S?`${d(f)}!`:`${d(f)}:${d(S)}!`}),o=r=>r.includes(":")&&r.includes("!")?r.split(/("(?:[^"]|"")*")/).map((a,h)=>h%2?a:s(a)).join(""):r;for(const r of this.sheets){const a=new Map;r.formulas.forEachCell((h,u,c)=>{let g=a.get(c);if(g===void 0){const p=c.f??c.sf,f=typeof p=="string"?o(p):p;g=f===p?null:c.f!==void 0?{...c,f,tpl:void 0}:{...c,sf:f,tpl:void 0},a.set(c,g)}g!==null&&r.setFormula(h,u,g)})}for(const r of this.engine?.names.values()??[])typeof r.text=="string"&&(r.text=o(r.text));this.engine?.templates.clear()}_refErrorsFor(t){const e=q(this.sheets[t].name),n=s=>s.split(/("(?:[^"]|"")*")/).map((o,r)=>r%2?o:o.replace(e,"#REF!")).join(""),l=s=>typeof s=="string"&&s!==""?n(s):s,i=this.sheets[t];for(const s of this.sheets){if(s===i)continue;s.cf?.length>0&&(s.cf=s.cf.map(r=>({...r,rules:r.rules.map(a=>oe(a,l))})),s.cfChanged=!0,s.cfEval?.invalidate()),s.validations?.length>0&&(s.validations=s.validations.map(r=>({...r,formula1:l(r.formula1),formula2:l(r.formula2)})),s.validationsChanged=!0);const o=new Map;s.formulas.forEachCell((r,a,h)=>{let u=o.get(h);if(u===void 0){const c=h.f??h.sf,g=typeof c=="string"?n(c):c;u=g===c?null:h.f!==void 0?{...h,f:g,tpl:void 0}:{...h,sf:g,tpl:void 0},o.set(h,u)}u!==null&&(s.setFormula(r,a,u),this.formulasEdited=!0)})}for(const s of this.engine?.names.values()??[])typeof s.text=="string"&&(s.text=n(s.text));this.engine?.templates.clear()}_renameInFormulas(t,e){const n=q(t);let l=!1;for(const i of this.sheets){const s=new Map;i.formulas.forEachCell((o,r,a)=>{let h=s.get(a);if(h===void 0){const u=a.f??a.sf;if(u===void 0||!n.test(u))n.lastIndex=0,h=null;else{n.lastIndex=0;const c=D(u,t,e);h=a.f!==void 0?{...a,f:c,tpl:void 0}:{...a,sf:c,tpl:void 0}}s.set(a,h)}h!==null&&(i.setFormula(o,r,h),l=!0)})}l&&(this.formulasEdited=!0,this.engine?.templates.clear(),this.engine?.rebuild())}editText(t,e,n){const l=t.kind(e,n);if(this.engine?.dataTables.length){const o=this.engine.dataTableAt(t,e,n);if(o){const{info:r}=o,a=r.dt2D==="1",h=r.dtr==="1";return`{=TABLE(${a||h?r.r1:""},${a?r.r2:h?"":r.r1})}`}}if(l&X&&this.engine){const o=this.engine.spillMaster(t,e,n);if(o)return this.editText(t,o.row,o.col)}if(l&v){const o=t.formula(e,n);if(o&&o.f!==void 0){const r="="+K(o.f);return o.t==="array"&&!o.cm?`{${r}}`:r}if(o&&o.sf!==void 0){const r=Math.floor(o.base/w),a=o.base-r*w;return"="+K(se(o.sf,e-r,n-a))}}const i=l&Y;if(i===_)return"";const s=t.value(e,n);if(i===F&&t.valueMeta!==null&&!(l&v)){const o=this.richImages?.get(t.valueMeta.get(e*w+n));if(o!==void 0)return o.alt??"";const r=this.richValues?.indexOfVm(t.valueMeta.get(e*w+n))??-1,a=r>=0?this.richValues.view(r):null;if(a!==null)return a.text}return i===R?this.styles.get(t.style(e,n)).quotePrefix?`'${this.strings.get(s)}`:this.strings.get(s):i===I?s?"TRUE":"FALSE":i===F?Z[s]??"#N/A":String(s)}transact(t,e){if(this.guard&&!this.guard(t))return;const n=this.selectedSheets,l=n!==null&&n.size>1&&ue.has(t)?this._runGroup(t,e,n):this._runOn(this.sheet,t,e);l!==null&&this._pushUndo(l)}transactOn(t,e,n){const l=this._runOn(t,e,n);l!==null&&this._pushUndo(l)}_runOn(t,e,n){const l=new b,i={sheet:t,log:l,saveCell:(h,u)=>l.push(t,h,u)},s=n(i)??null;e!=="entry"&&this.engine?.presentationChanged(),t.changes!==null&&l.count>0&&V(this,t,l),l.vms!==null&&de(t,l);const o=l.count>0&&this.engine?.tables.size>0?J(this,i,l):null,r=(h,u)=>c=>r(h(c),u(c)),a=s&&o?r(s,o):s??o;return l.count===0&&a===null?null:(t.revision++,this.engine?.cellsChanged(t,l.rows,l.cols,l.count),{sheetIndex:t===this.sheet?this.activeSheet:this.sheets.indexOf(t),sheet:t,log:l,label:e,extra:a})}_runGroup(t,e,n){const l=[];for(const i of this.sheets){if(!n.has(i)||i.protection&&i!==this.sheet)continue;const s=this._runOn(i,t,e);s!==null&&l.push(s)}return l.length===0?null:{sheetIndex:this.activeSheet,sheet:this.sheet,log:new b,label:t,extra:O(this,l)}}runSlice(t,e,n){const l=this._runOn(t,e,n);return l!==null&&this._emit("cells"),l}pushFolded(t,e,n){t.length!==0&&this._pushUndo({sheetIndex:this.sheets.indexOf(n),sheet:n,log:new b,label:e,extra:O(this,t)})}rollbackSlices(t){for(let e=t.length-1;e>=0;e--)this._restore(t[e]);this._emit("cells")}_pushUndo(t){this.allowUndo===!1?this.undoStack.length=0:(this.undoStack.push(t),this.undoStack.length>(this.historyLimit??ce)&&this.undoStack.shift()),this.redoStack.length=0,this._emit("cells")}_restore(t){const e=t.sheet??this.sheets[t.sheetIndex],{log:n}=t,l=new b;for(let o=n.count-1;o>=0;o--){const r=n.rows[o],a=n.cols[o];l.push(e,r,a),e.setCell(r,a,n.kinds[o],n.values[o]),e.setStyle(r,a,n.styles[o]),e.setFormula(r,a,n.kinds[o]&v?n.formulas.get(o):null)}if(n.vms!==null){e.valueMeta=new Map(e.valueMeta??[]);for(const[o,r]of n.vms)e.valueMeta.set(n.rows[o]*w+n.cols[o],r)}let i=null;t.extra&&(i=t.extra(e)),this.engine?.presentationChanged(),e.changes!==null&&n.count>0&&V(this,e,l),e.revision++,this.engine?.cellsChanged(e,n.rows,n.cols,n.count);const s=this.sheets.indexOf(e);return s>=0&&(this.activeSheet=s),{sheetIndex:s>=0?s:t.sheetIndex,sheet:e,log:l,label:t.label,extra:i}}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(this._restore(t)),this._emit("cells"),!0):!1}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(this._restore(t)),this._emit("cells"),!0):!1}setInput(t,e,n,l){const{sheet:i}=t;this.recorder?.push(`sheet.setValue(${JSON.stringify(Q(e,n))}, ${JSON.stringify(l)});`),t.saveCell(e,n),i.setFormula(e,n,null);const s=i.cellStyle(e,n),r=l!==""&&this.styles.get(i.style(e,n)).numFmt==="@"?{kind:R,text:l[0]==="'"?l.slice(1):l}:H(l),a=l[0]==="'"&&l.length>1;switch((a||s!==0&&this.styles.get(s).quotePrefix)&&i.setStyle(e,n,this.styles.derive(s,{quotePrefix:a})),r.kind){case _:i.setCell(e,n,_,0);break;case P:i.setCell(e,n,P,r.value),r.format&&(i.cellStyle(e,n)===0||this.styles.get(i.cellStyle(e,n)).numFmt==="General")&&i.setStyle(e,n,this.styles.derive(i.cellStyle(e,n),{numFmt:r.format}));break;case I:i.setCell(e,n,I,r.value);break;case F:i.setCell(e,n,F,r.value);break;case v:i.setCell(e,n,v|_,0),i.setFormula(e,n,{f:he(this._expandTableRefs(j(r.formula,this.engine?.tables),i,e,n),this.engine?.names??null),typed:this.dynamicArrays!==!1}),this.formulasEdited=!0;break;default:i.setCell(e,n,R,this.strings.add(r.text))}}setRichInput(t,e,n,l,i){const{sheet:s}=t;t.saveCell(e,n),s.setFormula(e,n,null),s.setCell(e,n,R,this.strings.addRich(l,i))}_expandTableRefs(t,e,n,l){const i=this.engine;return!i||i.tables.size===0?t:ae(t,()=>{for(const s of i.tables.values())if(s.sheet===e&&n>=s.r0&&n<=s.r1&&l>=s.c0&&l<=s.c1)return s;return null})}clearRange(t,e="contents",{visibleOnly:n=!1}={}){this.sheet.dataRanges?.cleared(t)||this.transact("clear",l=>{const{sheet:i}=l,s=[];if(e!=="contents")for(const{r0:r,c0:a,r1:h,c1:u}of t){const c=r===0&&h===B-1,g=a===0&&u===w-1,p=(f,S,d,y)=>{for(const[C,k]of[...S])C<d||C>y||(s.push([f,C,k]),S.delete(C))};c&&i.colStyles!==null&&p("col",i.colStyles,a,u),g&&i.rowStyles!==null&&p("row",i.rowStyles,r,h)}const o=n&&i.filteredRows?.size>0?i.filteredRows:null;for(const{r0:r,c0:a,r1:h,c1:u}of t){const c=Math.min(u,i.maxCol),g=Math.min(h,i.maxRow);for(let p=a;p<=c;p++)if(i.columns[p]!==void 0)for(let f=r;f<=g;f++){if(i._chunk(f,p)===void 0){f|=1023;continue}if(o!==null&&o.has(f))continue;const d=i.kind(f,p)!==0,y=i.cellStyle(f,p)!==0;if(e==="formats"){if(!y)continue;l.saveCell(f,p),i.setStyle(f,p,0);continue}!d&&!(e==="all"&&y)||(l.saveCell(f,p),i.setCell(f,p,_,0),i.setFormula(f,p,null),e==="all"&&i.setStyle(f,p,0))}}return s.length>0?E([],s):void 0})}applyStyle(t,e){const n=JSON.stringify(e);if(this.recorder)for(const l of t)this.recorder.push(`sheet.setFormat(${JSON.stringify(te(l))}, ${n});`);this.transact("format",l=>{const{sheet:i}=l;this.strings.rich!==null&&le(this,l,t,e);const s=[],o=new Set,r=[];for(const{r0:a,c0:h,r1:u,c1:c}of t){const g=a===0&&u===B-1,p=h===0&&c===w-1;if(g){i.colStyles===null&&(i.colStyles=new Map);for(let d=h;d<=c;d++){const y=i.colStyles.get(d);r.push(["col",d,y]),i.colStyles.set(d,this.styles.derive(y??0,e,n))}if(p&&i.rowStyles!==null)for(const[d,y]of i.rowStyles)r.push(["row",d,y]),i.rowStyles.set(d,this.styles.derive(y,e,n))}else if(p){i.rowStyles===null&&(i.rowStyles=new Map);for(let d=a;d<=u;d++){const y=i.rowStyles.get(d);r.push(["row",d,y]),i.rowStyles.set(d,this.styles.derive(y??0,e,n))}}const f=g?i.maxRow:u,S=p?i.maxCol:c;for(let d=h;d<=S;d++)for(let y=a>>>A;y<=f>>>A;y++){const C=y<<A,k=Math.max(a,C),L=Math.min(f,C+W);if(k>L)continue;const $=i._ensure(k,d),U=d*2048+y;o.has(U)||(o.add(U),s.push(d,y,$.styles===null?null:$.styles.slice()));for(let M=k;M<=L;M++)i.setStyle(M,d,this.styles.derive(i.style(M,d),e,n))}}return E(s,r)})}}function O(m,t){const e=()=>{const n=[];for(let l=t.length-1;l>=0;l--)n.push(m._restore(t[l]));return O(m,n)};return e.parts=t,e}function de(m,t){let e=null;for(const n of t.vms.keys()){const l=t.rows[n],i=t.cols[n];(m.kind(l,i)&~(N|z))===t.kinds[n]&&m.value(l,i)===t.values[n]||(e??=new Map(m.valueMeta),e.delete(l*w+i))}e!==null&&(m.valueMeta=e.size>0?e:null)}function x(m){if(m===null||typeof m!="object")return m;if(Array.isArray(m))return m.map(x);if(m instanceof Map)return new Map([...m].map(([e,n])=>[e,x(n)]));if(m instanceof Set)return new Set([...m].map(x));if(ArrayBuffer.isView(m))return m.slice();const t={};for(const[e,n]of Object.entries(m))!e.startsWith("_")&&typeof n!="function"&&(t[e]=x(n));return t}function E(m,t){return e=>{const n=[];for(let i=0;i<m.length;i+=3){const s=m[i],o=m[i+1],r=e.columns[s]?.[o];r!==void 0&&(n.push(s,o,r.styles),r.styles=m[i+2])}const l=[];for(const[i,s,o]of t){const r=i==="col"?"colStyles":"rowStyles",a=e[r]??=new Map;l.push([i,s,a.get(s)]),o===void 0?a.delete(s):a.set(s,o)}return E(n,l)}}export{b as CellLog,ue as GROUP_LABELS,be as Workbook,O as foldEntries,H as parseInput,E as swapStyles};
|
|
1
|
+
import{expandBareTables as ue}from"../slicers/structured.js";import{syncTableHeaders as fe,tablesOf as de}from"./tables.js";import{BOOL as D,CHUNK_BITS as z,CHUNK_MASK as W,EMPTY as I,ERR as U,ERRORS as me,FORMULA as F,DIRTY as J,EVALUATING as Z,KIND_MASK as Y,NUM as P,Sheet as B,SPILL as pe,STR as T}from"./sheet.js";import{cellRef as ge,isValidName as ye,MAX_COLS as R,MAX_ROWS as X,quoteSheetName as Q,rangeRef as Se,renameSheetInFormula as V,sheetReferencePattern as ee}from"./address.js";import{translateFormula as we}from"./formula-refs.js";import{sheetStem as te}from"./default-names.js";import{StringTable as Ce}from"./strings.js";import{formatAxis as se,formatSheetColumns as ve}from"./axis-styles.js";import{autoRowHeight as ke}from"./row-fit.js";import{StyleTable as xe}from"./styles.js";import{cellEntryText as ne,parseInput as ie}from"./input.js";import{DATE_1904_OFFSET as _e}from"./numfmt.js";import{noteChanges as oe}from"./changes.js";import{overrideRuns as Re}from"../cells/rich-runs.js";import{sheetRenameHooks as be}from"./sparse.js";import{shiftRuleFormulas as re}from"../cells/cf-file.js";import{expandStructured as Me,formulaEntryLimit as Fe,FormulaSyntaxError as L,tokenize as Te,toDisplayFormula as le,toFileFormula as Ae}from"../calc/parser.js";const Ee=200,Ie=new Set(["entry","clear","format","borders","fill"]);class Oe{constructor(){this.ids=new Int32Array(1024),this.list=[]}set(t,e){if(t>=this.ids.length){let o=this.ids.length*2;for(;o<=t;)o*=2;const r=new Int32Array(o);r.set(this.ids),this.ids=r}const i=this.list.length;(i===0||this.list[i-1]!==e)&&this.list.push(e),this.ids[t]=this.list.length}get(t){const e=t<this.ids.length?this.ids[t]:0;return e===0?void 0:this.list[e-1]}}class ${constructor(){this.capacity=1024,this.count=0,this.rows=new Uint32Array(this.capacity),this.cols=new Uint16Array(this.capacity),this.kinds=new Uint8Array(this.capacity),this.styles=new Uint16Array(this.capacity),this.values=new Float64Array(this.capacity),this.formulas=null,this.vms=null}_grow(){const t=this.capacity*2,e=(i,o)=>{const r=new i(t);return r.set(o),r};this.rows=e(Uint32Array,this.rows),this.cols=e(Uint16Array,this.cols),this.kinds=e(Uint8Array,this.kinds),this.styles=e(Uint16Array,this.styles),this.values=e(Float64Array,this.values),this.capacity=t}push(t,e,i){this.count===this.capacity&&this._grow();const o=this.count++,r=t.kind(e,i)&~(J|Z);if(this.rows[o]=e,this.cols[o]=i,this.kinds[o]=r,this.styles[o]=t.cellStyle(e,i),this.values[o]=t.value(e,i),r&F&&(this.formulas===null&&(this.formulas=new Oe),this.formulas.set(o,t.formula(e,i))),t.valueMeta!==null){const s=t.valueMeta.get(e*R+i);s!==void 0&&(this.vms??=new Map).set(o,s)}}}class Qe{get namesChanged(){return this._namesChanged}set namesChanged(t){this._namesChanged=t,t&&(this.namesRevision=(this.namesRevision??0)+1)}constructor(){this.sheets=[new B(`${te()}1`)],this.activeSheet=0,this.date1904=!1,this.strings=new Ce,this.styles=new xe,this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.source=null,this.formulasEdited=!1,this.edits=0,this._dirty=!1,this.engine=null,this.selectedSheets=null}get sheet(){return this.sheets[this.activeSheet]}get dateOffset(){return this.date1904?_e:0}get dirty(){return this._dirty}set dirty(t){t&&this.edits++,this._dirty=!!t}onChange(t){this.listeners.add(t)}clearHistory(){if(this.historyCleared=(this.historyCleared??0)+1,!(this.undoStack.length===0&&this.redoStack.length===0)){this.undoStack.length=0,this.redoStack.length=0;for(const t of this.listeners)t("history")}}_emit(t){(t==="cells"||t==="bulk")&&(this.formatValueRevision=(this.formatValueRevision??0)+1),this.dirty=!0;for(const e of this.listeners)e(t)}addSheet(t){const e=te();let i=1,o=t??`${e}${i}`;const r=n=>this.sheets.some(l=>l.name.toLowerCase()===n.toLowerCase());for(;r(o);)o=`${e}${++i}`;const s=new B(o);return this.sheets.push(s),this.activeSheet=this.sheets.length-1,this.engine?.sheetsChanged(),this._emit("sheets"),s}deleteSheet(t){return this.sheets.filter(e=>!e.hidden).length<=1?!1:(this._shrink3D(t),this._refErrorsFor(t),this._removeSheet(t))}_removeSheet(t){if(this.sheets.length<=1)return!1;const[e]=this.sheets.splice(t,1);if(this.selectedSheets?.delete(e),this._forgetSheet(e,t),this.engine)for(const[o,r]of this.engine.tables)r.sheet===e&&this.engine.tables.delete(o);this._reindexNames(o=>o===t?-1:o>t?o-1:o),this.activeSheet>=this.sheets.length&&(this.activeSheet=this.sheets.length-1);const i=this.activeSheet;for(;this.sheets[this.activeSheet].hidden&&(this.activeSheet=(this.activeSheet+1)%this.sheets.length,this.activeSheet!==i););return this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),!0}_forgetSheet(t,e){const i=r=>r.sheet===t||r.sheet===void 0&&r.sheetIndex===e||(r.extra?.parts??[]).some(i),o=r=>{r.sheetIndex>e&&r.sheetIndex--;for(const s of r.extra?.parts??[])o(s)};for(const r of[this.undoStack,this.redoStack]){const s=r.filter(n=>!i(n));s.forEach(o),r.splice(0,r.length,...s)}}moveSheet(t,e){if(t===e)return;const i=this.sheet,[o]=this.sheets.splice(t,1);this.sheets.splice(e,0,o),this.activeSheet=this.sheets.indexOf(i);const r=n=>n===t?e:t<e?n>t&&n<=e?n-1:n:n>=e&&n<t?n+1:n,s=n=>{n.sheetIndex=r(n.sheetIndex);for(const l of n.extra?.parts??[])s(l)};for(const n of this.undoStack)s(n);for(const n of this.redoStack)s(n);this.structureEdited=!0,this._reindexNames(r),this.engine?.orderChanged(),this._emit("sheets")}_copyTables(t,e){const i=new Map,o=new Set;for(const r of de(this,t)){const{sheet:s,part:n,id:l,source:c,sheetIndex:a,...h}=r;let u=this.engine.tables.size+i.size+2,p,f;do{const d=String(u++),g=r.name.slice(0,255-d.length);p=g+d,ye(p)||(p=g.slice(0,254-d.length)+"_"+d),f=p.toUpperCase()}while(o.has(f)||this.engine.tables.has(f)||this.engine.names.has(f));o.add(f),i.set(r.name.toUpperCase(),{...A(h),name:p,sheet:e,isNew:!0,dirty:!0})}return i}_copyScopedNames(t,e,i,o){const{engine:r}=this;if(!r||r.names.size===0)return;const s=`${t}!`;let n=!1;for(const[l,c]of[...r.names])l.startsWith(s)&&(r.names.set(`${t+1}!${l.slice(s.length)}`,{...c,text:o(V(c.text,e.name,i.name))}),n=!0);n&&(this.namesChanged=!0)}_reindexNames(t){const{engine:e}=this;if(!e||e.names.size===0)return;const i=[];let o=!1;for(const[r,s]of e.names){const n=r.indexOf("!"),l=n<0?0:t(Number(r.slice(0,n)));n>=0&&l!==Number(r.slice(0,n))&&(o=!0),n<0?i.push([r,s]):l>=0&&i.push([`${l}!${r.slice(n+1)}`,s])}if(o){e.names.clear();for(const[r,s]of i)e.names.set(r,s);e.nameTemplates.clear(),this.namesChanged=!0,e.rebuild()}}duplicateSheet(t){const e=this.sheets[t];let o=`${e.name} (2)`,r=2;for(;this.sheets.some(h=>h.name.toLowerCase()===o.toLowerCase());)o=`${e.name} (${++r})`;const s=new B(o),n=this._copyTables(e,s),l=h=>Ue(h,n,e.name,s.name);for(const h of n.values())for(const u of h.totals??[])u?.formula&&(u.formula=l(u.formula));e.columns.forEach((h,u)=>{const p=[];h.forEach((f,d)=>{p[d]={kinds:f.kinds.slice(),values:f.values.slice(),styles:f.styles?f.styles.slice():null}}),s.columns[u]=p}),s.maxRow=e.maxRow,s.maxCol=e.maxCol,s.rows=e.rows.shifted(0,0),s.cols=e.cols.shifted(0,0);const c=new Map;e.formulas.forEachCell((h,u,p)=>{let f=c.get(p);f===void 0&&(f={...p,tpl:void 0},p.f!==void 0&&(f.f=l(p.f)),p.sf!==void 0&&(f.sf=l(p.sf)),c.set(p,f)),s.setFormula(h,u,f)}),s.merges=e.merges.map(h=>({...h})),s.rowStyles=e.rowStyles?new Map(e.rowStyles):null,s.colStyles=e.colStyles?new Map(e.colStyles):null,s.frozenRows=e.frozenRows,s.frozenCols=e.frozenCols,s.showGridlines=e.showGridlines,s.cellTypeRules=e.cellTypeRules,s.cellTypes=e.cellTypes?new Map(e.cellTypes):null,s.sparkRules=e.sparkRules,s.cellDropdowns=e.cellDropdowns?new Map(e.cellDropdowns):null,s.cellTags=e.cellTags?new Map(e.cellTags):null,s.cellButtons=e.cellButtons?new Map(e.cellButtons):null,s.cellStates=e.cellStates?e.cellStates.slice():null,s.autoMerges=e.autoMerges?e.autoMerges.map(h=>({...h})):null,s.background=e.background,s.outlineColumn=e.outlineColumn?{...e.outlineColumn}:null,s.frozenTrailingRows=e.frozenTrailingRows,s.frozenTrailingCols=e.frozenTrailingCols,s.hideZeros=e.hideZeros,s.hideHeadings=e.hideHeadings,s.isChartSheet=e.isChartSheet,s.hideOutline=e.hideOutline,s.gridColorId=e.gridColorId,s.areaOffset=e.areaOffset,s.selectionPolicy=e.selectionPolicy,s.selectionUnit=e.selectionUnit,s.gridlineAxes=e.gridlineAxes,s.gridColor=e.gridColor,s.tabStyles=e.tabStyles;const a=A;if(s.cf=a(e.cf),s.validations=a(e.validations),n.size){for(const h of s.cf??[])h.rules=h.rules.map(u=>re(u,l));for(const h of s.validations??[])h.formula1&&(h.formula1=l(h.formula1)),h.formula2&&(h.formula2=l(h.formula2))}s.comments=a(e.comments),s.threads=a(e.threads),s.hyperlinks=e.hyperlinks?e.hyperlinks.map(h=>({...a({...h,_ranges:void 0})})):e.hyperlinks,s.autoFilter=a(e.autoFilter),s.filteredRows=e.filteredRows?new Set(e.filteredRows):e.filteredRows,s.pageSetup=a(e.pageSetup),s.tabColor=e.tabColor,s.protection=a(e.protection),s.rtl=e.rtl,s.zoom=e.zoom,s.valueMeta=e.valueMeta?new Map(e.valueMeta):null,s.colsChanged=!0,s.viewChanged=!0,this.sheets.splice(t+1,0,s);for(const h of n.values())this.engine.tables.set(h.name.toUpperCase(),h);return this.activeSheet=t+1,this._reindexNames(h=>h>t?h+1:h),this._copyScopedNames(t,e,s,l),this.structureEdited=!0,this.engine?.sheetsChanged(),this.engine?.rebuild(),this._emit("sheets"),s}sheetNameProblem(t,e){const i=e.trim().slice(0,31);return!i||/[\\/?*[\]:]/.test(i)||/^'|'$/.test(i)?"rules":i.toLowerCase()==="history"?"reserved":this.sheets.some((o,r)=>r!==t&&o.name.toLowerCase()===i.toLowerCase())?"taken":null}renameSheet(t,e){const i=e.trim().slice(0,31);if(this.sheetNameProblem(t,e)!==null)return!1;const o=this.sheets[t].name;this.sheets[t].name=i,this.engine?.sheetsChanged(),this._renameInFormulas(o,i);for(const r of be)r(this,o,i);return this._emit("sheets"),!0}_shrink3D(t){const e=this.sheets[t].name.toLowerCase(),i=l=>this.sheets.findIndex(c=>c.name.toLowerCase()===l.toLowerCase()),o=l=>l[0]==="'"?l.slice(1,-1).replace(/''/g,"'"):l,r=/((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*)):((?:'(?:[^']|'')+'|[A-Za-z_\u00C0-\uFFFF][\w.\u00C0-\uFFFF]*))!/g,s=l=>l.replace(r,(c,a,h,u)=>{if(l[u-1]==="]")return c;const p=o(a),f=o(h);if(p.toLowerCase()!==e&&f.toLowerCase()!==e)return c;let d=i(p),g=i(f);if(d<0||g<0||(d>g&&([d,g]=[g,d]),d===t&&d++,g===t&&g--,d>g))return c;const y=w=>Q(this.sheets[w].name);return d===g?`${y(d)}!`:`${y(d)}:${y(g)}!`}),n=l=>l.includes(":")&&l.includes("!")?l.split(/("(?:[^"]|"")*")/).map((c,a)=>a%2?c:s(c)).join(""):l;for(const l of this.sheets){const c=new Map;l.formulas.forEachCell((a,h,u)=>{let p=c.get(u);if(p===void 0){const f=u.f??u.sf,d=typeof f=="string"?n(f):f;p=d===f?null:u.f!==void 0?{...u,f:d,tpl:void 0}:{...u,sf:d,tpl:void 0},c.set(u,p)}p!==null&&l.setFormula(a,h,p)})}for(const l of this.engine?.names.values()??[])typeof l.text=="string"&&(l.text=n(l.text));this.engine?.templates.clear()}_refErrorsFor(t){const e=ee(this.sheets[t].name),i=s=>s.split(/("(?:[^"]|"")*")/).map((n,l)=>l%2?n:n.replace(e,"#REF!")).join(""),o=s=>typeof s=="string"&&s!==""?i(s):s,r=this.sheets[t];for(const s of this.sheets){if(s===r)continue;s.cf?.length>0&&(s.cf=s.cf.map(l=>({...l,rules:l.rules.map(c=>re(c,o))})),s.cfChanged=!0,s.cfEval?.invalidate()),s.validations?.length>0&&(s.validations=s.validations.map(l=>({...l,formula1:o(l.formula1),formula2:o(l.formula2)})),s.validationsChanged=!0);const n=new Map;s.formulas.forEachCell((l,c,a)=>{let h=n.get(a);if(h===void 0){const u=a.f??a.sf,p=typeof u=="string"?i(u):u;h=p===u?null:a.f!==void 0?{...a,f:p,tpl:void 0}:{...a,sf:p,tpl:void 0},n.set(a,h)}h!==null&&(s.setFormula(l,c,h),this.formulasEdited=!0)})}for(const s of this.engine?.names.values()??[])typeof s.text=="string"&&(s.text=i(s.text));this.engine?.templates.clear()}_renameInFormulas(t,e){const i=ee(t);let o=!1;for(const s of this.sheets){const n=new Map;s.formulas.forEachCell((l,c,a)=>{let h=n.get(a);if(h===void 0){const u=a.f??a.sf;if(u===void 0||!i.test(u))i.lastIndex=0,h=null;else{i.lastIndex=0;const p=V(u,t,e);h=a.f!==void 0?{...a,f:p,tpl:void 0}:{...a,sf:p,tpl:void 0}}n.set(a,h)}h!==null&&(s.setFormula(l,c,h),o=!0)})}let r=!1;for(const s of this.engine?.names.values()??[]){if(typeof s.text!="string")continue;const n=V(s.text,t,e);n!==s.text&&(s.text=n,r=!0)}r&&(this.namesChanged=!0,this.engine.nameTemplates.clear()),(o||r)&&(o&&(this.formulasEdited=!0),this.engine?.templates.clear(),this.engine?.rebuild())}editText(t,e,i){const o=t.kind(e,i);if(this.engine?.dataTables.length){const n=this.engine.dataTableAt(t,e,i);if(n){const{info:l}=n,c=l.dt2D==="1",a=l.dtr==="1";return`{=TABLE(${c||a?l.r1:""},${c?l.r2:a?"":l.r1})}`}}if(o&pe&&this.engine){const n=this.engine.spillMaster(t,e,i);if(n)return this.editText(t,n.row,n.col)}if(o&F){const n=t.formula(e,i),l=n&&!n.typed&&n.t!=="array"&&n.tpl?.rangeResult?"=@":"=";if(n&&n.f!==void 0){const c=l+le(n.f);return n.t==="array"&&!n.cm?`{${c}}`:c}if(n&&n.sf!==void 0){const c=Math.floor(n.base/R),a=n.base-c*R;return l+le(we(n.sf,e-c,i-a))}}const r=o&Y;if(r===I)return"";const s=t.value(e,i);if(r===U&&t.valueMeta!==null&&!(o&F)){const n=this.richImages?.get(t.valueMeta.get(e*R+i));if(n!==void 0)return n.alt??"";const l=this.richValues?.indexOfVm(t.valueMeta.get(e*R+i))??-1,c=l>=0?this.richValues.view(l):null;if(c!==null)return c.text}return r===T?this.styles.get(t.style(e,i)).quotePrefix?`'${this.strings.get(s)}`:this.strings.get(s):r===D?s?"TRUE":"FALSE":r===U?me[s]??"#N/A":String(s)}transact(t,e,i=null){if(this.guard&&!this.guard(t))return;const o=this.selectedSheets;!i&&o?.size>1&&Ie.has(t)&&(i=this.sheets.filter(s=>o.has(s)&&(!s.protection||s===this.sheet)));const r=i?this._runGroup(t,e,i):this._runOn(this.sheet,t,e);r!==null&&this._pushUndo(r)}transactOn(t,e,i){const o=this._runOn(t,e,i);o!==null&&this._pushUndo(o)}_runOn(t,e,i){const o=new $,r={sheet:t,log:o,saveCell:(f,d)=>o.push(t,f,d)},{maxRow:s,maxCol:n}=t,l=this.recorder?.length,c=this.formulasEdited;let a;try{a=i(r)??null}catch(f){throw f instanceof L&&(ae(t,o),t.maxRow=s,t.maxCol=n,this.formulasEdited=c,l!==void 0&&(this.recorder.length=l),this.engine?.cellsChanged(t,o.rows,o.cols,o.count)),f}e!=="entry"&&this.engine?.presentationChanged(),t.changes!==null&&o.count>0&&oe(this,t,o),o.vms!==null&&ze(t,o);const h=o.count>0&&this.engine?.tables.size>0?fe(this,r,o):null,u=(f,d)=>g=>u(f(g),d(g)),p=a&&h?u(a,h):a??h;return o.count===0&&p===null?null:(t.revision++,this.engine?.cellsChanged(t,o.rows,o.cols,o.count),{sheetIndex:t===this.sheet?this.activeSheet:this.sheets.indexOf(t),sheet:t,log:o,label:e,extra:p})}_runGroup(t,e,i){const o=[],r=this.activeSheet,s=this.recorder?.length,n=this.formulasEdited,l=[];try{for(const c of i){const{maxRow:a,maxCol:h}=c,u=this._runOn(c,t,e);u!==null&&(o.push(u),l.push([c,a,h]))}}catch(c){if(c instanceof L){this.rollbackSlices(o);for(const[a,h,u]of l)a.maxRow=h,a.maxCol=u;this.activeSheet=r,this.formulasEdited=n,s!==void 0&&(this.recorder.length=s)}throw c}return o.length===0?null:{sheetIndex:this.activeSheet,sheet:this.sheet,log:new $,label:t,extra:H(this,o)}}runSlice(t,e,i){const o=this._runOn(t,e,i);return o!==null&&this._emit("cells"),o}pushFolded(t,e,i){t.length!==0&&this._pushUndo({sheetIndex:this.sheets.indexOf(i),sheet:i,log:new $,label:e,extra:H(this,t)})}rollbackSlices(t){for(let e=t.length-1;e>=0;e--)this._restore(t[e]);this._emit("cells")}_pushUndo(t){this.allowUndo===!1?this.undoStack.length=0:(this.undoStack.push(t),this.undoStack.length>(this.historyLimit??Ee)&&this.undoStack.shift()),this.redoStack.length=0,this._emit("cells")}_restore(t){const e=t.sheet??this.sheets[t.sheetIndex],{log:i}=t,o=new $;if(ae(e,i,o),i.vms!==null){e.valueMeta=new Map(e.valueMeta??[]);for(const[n,l]of i.vms)e.valueMeta.set(i.rows[n]*R+i.cols[n],l)}let r=null;t.extra&&(r=t.extra(e)),this.engine?.presentationChanged(),e.changes!==null&&i.count>0&&oe(this,e,o),e.revision++,this.engine?.cellsChanged(e,i.rows,i.cols,i.count);const s=this.sheets.indexOf(e);return s>=0&&(this.activeSheet=s),{sheetIndex:s>=0?s:t.sheetIndex,sheet:e,log:o,label:t.label,extra:r}}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(this._restore(t)),this._emit("cells"),!0):!1}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(this._restore(t)),this._emit("cells"),!0):!1}setInput(t,e,i,o,{overLimitAsText:r=!1,typedQuote:s=!0}={}){const{sheet:n}=t,l=n.style(e,i),c=o!==""&&this.styles.get(l).numFmt==="@";let a=c?{kind:T,text:o[0]==="'"?o.slice(1):o}:ie(o,void 0,this.dateOffset);if(a.kind===F){const u=Fe(a.formula);if(u){if(!r)throw new L(u);a={kind:T,text:o}}}if(this.recorder){const u=a.kind===T&&o.startsWith("=")&&!c?`'${o}`:o;this.recorder.push(`sheet.setValue(${JSON.stringify(ge(e,i))}, ${JSON.stringify(u)});`)}t.saveCell(e,i),n.setFormula(e,i,null);const h=s&&o[0]==="'"&&o.length>1;switch((h||this.styles.get(l).quotePrefix)&&n.setStyle(e,i,this.styles.derive(l,{quotePrefix:h})),a.kind){case I:n.setCell(e,i,I,0);break;case P:n.setCell(e,i,P,a.value),a.format&&this.styles.get(l).numFmt==="General"&&n.setStyle(e,i,this.styles.derive(n.style(e,i),{numFmt:a.format}));break;case D:n.setCell(e,i,D,a.value);break;case U:n.setCell(e,i,U,a.value);break;case F:n.setCell(e,i,F|I,0),n.setFormula(e,i,{f:Ae(this._expandTableRefs(ue(a.formula,this.engine?.tables),n,e,i),this.engine?.names??null),typed:this.dynamicArrays!==!1}),this.formulasEdited=!0;break;default:n.setCell(e,i,T,this.strings.add(ne(a.text)))}}setRichInput(t,e,i,o,r){const{sheet:s}=t;t.saveCell(e,i),s.setFormula(e,i,null);const n=ne(o);s.setCell(e,i,T,this.strings.addRich(n,n===o?r:r?.filter(l=>l.at<n.length)))}_expandTableRefs(t,e,i,o){const r=this.engine;return!r||r.tables.size===0?t:Me(t,()=>{for(const s of r.tables.values())if(s.sheet===e&&i>=s.r0&&i<=s.r1&&o>=s.c0&&o<=s.c1)return s;return null})}clearRange(t,e="contents",{visibleOnly:i=!1}={}){this.sheet.dataRanges?.cleared(t)||this.transact("clear",o=>{const{sheet:r}=o,s=[];if(e!=="contents")for(const{r0:l,c0:c,r1:a,c1:h}of t){const u=l===0&&a===X-1,p=c===0&&h===R-1,f=(d,g,y,w)=>{for(const[C,x]of[...g])C<y||C>w||(s.push([d,C,x]),g.delete(C))};u&&r.colStyles!==null&&f("col",r.colStyles,c,h),p&&r.rowStyles!==null&&f("row",r.rowStyles,l,a)}const n=i&&r.filteredRows?.size>0?r.filteredRows:null;for(const{r0:l,c0:c,r1:a,c1:h}of t){const u=Math.min(h,r.maxCol),p=Math.min(a,r.maxRow);for(let f=c;f<=u;f++)if(r.columns[f]!==void 0)for(let d=l;d<=p;d++){if(r._chunk(d,f)===void 0){d|=1023;continue}if(n!==null&&n.has(d))continue;const y=r.kind(d,f)!==0,w=r.cellStyle(d,f)!==0;if(e==="formats"){if(!w)continue;o.saveCell(d,f),r.setStyle(d,f,0);continue}!y&&!(e==="all"&&w)||(o.saveCell(d,f),r.setCell(d,f,I,0),r.setFormula(d,f,null),e==="all"&&r.setStyle(d,f,0))}}return s.length>0?j([],s):void 0})}applyStyle(t,e,{measureRow:i,numberFit:o}={}){const r=JSON.stringify(e);if(this.recorder)for(const s of t)this.recorder.push(`sheet.setFormat(${JSON.stringify(Se(s))}, ${r});`);this.transact("format",s=>{const{sheet:n}=s;this.strings.rich!==null&&Re(this,s,t,e);const l=[],c=new Set,a=[],h=[],u=(g,y,w)=>{const C=g*2048+y;c.has(C)||(c.add(C),l.push(g,y,w.styles===null?null:w.styles.slice()))},p=(g,y,w)=>{w===0&&(n.rowStyles?.has(g)||n.colStyles?.has(y))&&(w=this.styles.explicitDefault()),n.setStyle(g,y,w)};for(const{r0:g,c0:y,r1:w,c1:C}of t){const x=g===0&&w===X-1,v=y===0&&C===R-1,k=x||v,b=k?Math.min(w,n.maxRow):w,he=k?Math.min(C,n.maxCol):C;for(let S=y;S<=he&&g<=b;S++){const _=n.columns[S];if(!(k&&!_))for(let M=g>>>z;M<=b>>>z;M++){const G=M<<z,K=Math.max(g,G),ce=Math.min(b,G+W),N=k?_[M]:n._ensure(K,S);if(!(k&&!N?.styles)){u(S,M,N);for(let E=K;E<=ce;E++)(!k||N.styles[E&W])&&p(E,S,this.styles.derive(n.style(E,S),e,r))}}}const O=S=>this.styles.derive(S,e,r),q=(S,_,M)=>{u(_,S>>>z,n._ensure(S,_)),n.setStyle(S,_,M||this.styles.explicitDefault())};if(v&&x){ve(n,O,a);for(const[S,_]of n.rowStyles??[])a.push(["row",S,_]),n.rowStyles.set(S,O(_))}else if(x)for(let S=y;S<=C;S++)se(n,"col",S,O,a,q);else if(v)for(let S=g;S<=w;S++)se(n,"row",S,O,a,q)}const f=(g,y,w)=>{const C=n[g];w!==C.sizeOf(y)&&(h.push([g,y,C.isCustom(y)?C.sizeOf(y):null,C.isAuto(y)]),C.setSize(y,w,!0),g==="cols"&&(n.colsChanged=!0))},d=e.fontSize!==void 0||e.wrap!==void 0||e.rotation!==void 0||["justify","distributed"].includes(e.hAlign)||["justify","distributed"].includes(e.vAlign);for(const{r0:g,r1:y,c0:w,c1:C}of t){const x=Math.min(y,n.maxRow);if(d&&x-g<=2e3)for(let v=g;v<=x;v++)f("rows",v,ke(n,this,v,i));if(o)for(const v of o.cols){if(v<w||v>C||!n.columns[v]||n.cols.isCustom(v)&&!n.cols.isAuto(v))continue;let k=n.cols.sizeOf(v);for(const b of o.rows)b>=g&&b<=x&&(n.kind(b,v)&Y)===P&&(k=Math.max(k,o.measure(n,b,v)));f("cols",v,k)}}return j(l,a,h)})}}function ae(m,t,e){for(let i=t.count-1;i>=0;i--){const o=t.rows[i],r=t.cols[i];e?.push(m,o,r),m.setCell(o,r,t.kinds[i],t.values[i]),m.setStyle(o,r,t.styles[i]),m.setFormula(o,r,t.kinds[i]&F?t.formulas.get(i):null)}}function H(m,t){const e=()=>{const i=[];for(let o=t.length-1;o>=0;o--)i.push(m._restore(t[o]));return H(m,i)};return e.parts=t,e}function ze(m,t){let e=null;for(const i of t.vms.keys()){const o=t.rows[i],r=t.cols[i];(m.kind(o,r)&~(J|Z))===t.kinds[i]&&m.value(o,r)===t.values[i]||(e??=new Map(m.valueMeta),e.delete(o*R+r))}e!==null&&(m.valueMeta=e.size>0?e:null)}function Ue(m,t,e,i){if(!t.size||typeof m!="string")return m;let o;try{o=Te(m)}catch(n){if(n instanceof L)return m;throw n}let r="",s=0;for(let n=0;n<o.length;n++){const l=o[n],c=l.t==="name"?m.slice(l.s,l.e):l.t==="table"?l.v.name:null;if(!c)continue;const a=t.get(c.toUpperCase());if(!a)continue;let h=n-1;for(;o[h]?.t==="ws";)h--;const u=o[h];if(u?.t==="sheet"){const{book:p,sheet:f,sheet2:d}=u.v;if(p!==null||d!==null)continue;if(f.toUpperCase()===e.toUpperCase())r+=m.slice(s,u.s)+Q(i)+"!",s=u.e;else if(f.toUpperCase()!==i.toUpperCase())continue}r+=m.slice(s,l.s)+a.name,s=l.s+c.length}return s?r+m.slice(s):m}function A(m){if(m===null||typeof m!="object")return m;if(Array.isArray(m))return m.map(A);if(m instanceof Map)return new Map([...m].map(([e,i])=>[e,A(i)]));if(m instanceof Set)return new Set([...m].map(A));if(ArrayBuffer.isView(m))return m.slice();const t={};for(const[e,i]of Object.entries(m))!e.startsWith("_")&&typeof i!="function"&&(t[e]=A(i));return t}function j(m,t,e=[]){return i=>{const o=[];for(let n=0;n<m.length;n+=3){const l=m[n],c=m[n+1],a=i.columns[l]?.[c];a!==void 0&&(o.push(l,c,a.styles),a.styles=m[n+2])}const r=[];for(let n=t.length-1;n>=0;n--){const[l,c,a]=t[n];if(l==="columns"){r.push([l,c,i.colStyles]),i.colStyles=a,i.colsChanged=!0;continue}l==="col"&&(i.colsChanged=!0);const h=l==="col"?"colStyles":"rowStyles",u=i[h]??=new Map;r.push([l,c,u.get(c)]),a===void 0?u.delete(c):u.set(c,a)}const s=[];for(let n=e.length-1;n>=0;n--){const[l,c,a,h]=e[n],u=i[l];s.push([l,c,u.isCustom(c)?u.sizeOf(c):null,u.isAuto(c)]),u.setSize(c,a,h),l==="cols"&&(i.colsChanged=!0)}return j(o,r,s)}}export{$ as CellLog,Ie as GROUP_LABELS,Qe as Workbook,H as foldEntries,ie as parseInput,j as swapStyles};
|