@novnox/grid 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +133 -0
- package/README.md +453 -2
- package/dist/nox-grid.iife.js +75 -0
- package/dist/nox-grid.min.js +74 -0
- package/dist/types/book.d.ts +74 -0
- package/dist/types/conditional.d.ts +79 -0
- package/dist/types/events.d.ts +129 -0
- package/dist/types/find.d.ts +37 -0
- package/dist/types/footer.d.ts +6 -0
- package/dist/types/format.d.ts +21 -0
- package/dist/types/formula/engine.d.ts +25 -0
- package/dist/types/formula/formula.d.ts +56 -0
- package/dist/types/formula/functions.d.ts +18 -0
- package/dist/types/formula/nodes.d.ts +71 -0
- package/dist/types/formula/parser.d.ts +6 -0
- package/dist/types/formula/values.d.ts +95 -0
- package/dist/types/formula/writer.d.ts +8 -0
- package/dist/types/grid.d.ts +573 -0
- package/dist/types/headerGroups.d.ts +23 -0
- package/dist/types/i18n.d.ts +66 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/license.d.ts +37 -0
- package/dist/types/model.d.ts +278 -0
- package/dist/types/outline.d.ts +41 -0
- package/dist/types/pageFind.d.ts +11 -0
- package/dist/types/print.d.ts +24 -0
- package/dist/types/refs.d.ts +95 -0
- package/dist/types/renderer.d.ts +48 -0
- package/dist/types/scheme.d.ts +28 -0
- package/dist/types/sheetData.d.ts +97 -0
- package/dist/types/styles.d.ts +2 -0
- package/dist/types/types.d.ts +254 -0
- package/dist/types/undo.d.ts +28 -0
- package/package.json +38 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*! NoxGrid web 1.0.0 | Copyright (c) 2026 Nox. All rights reserved. */
|
|
2
|
+
var zo={editCell:"\uADF8\uB9AC\uB4DC \uCE78 \uD3B8\uC9D1",sortAsc:"\u2191 \uC624\uB984\uCC28\uC21C",sortDesc:"\u2193 \uB0B4\uB9BC\uCC28\uC21C",search:"\uAC80\uC0C9",selectAll:"(\uBAA8\uB450 \uC120\uD0DD)",blank:"(\uBE48 \uCE78)",clearFilter:"\uD544\uD130 \uC9C0\uC6B0\uAE30",ok:"\uD655\uC778",badFormat:"\uD615\uC2DD\uC774 \uB9DE\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",badFormula:"\uC218\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",formulaError:r=>`\uC218\uC2DD \uC624\uB958: ${r}`,required:r=>`${r}: \uAC12\uC744 \uC785\uB825\uD558\uC138\uC694.`,min:r=>`${r} \uC774\uC0C1\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4.`,max:r=>`${r} \uC774\uD558\uC5EC\uC57C \uD569\uB2C8\uB2E4.`,maxLength:r=>`${r}\uC790\uAE4C\uC9C0 \uC785\uB825\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`,notInList:"\uBAA9\uB85D\uC5D0 \uC788\uB294 \uAC12\uB9CC \uC785\uB825\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",findWhat:"\uCC3E\uC744 \uB0B4\uC6A9",findNext:"\uB2E4\uC74C",close:"\uB2EB\uAE30",replaceWith:"\uBC14\uAFC0 \uB0B4\uC6A9",replace:"\uBC14\uAFB8\uAE30",replaceAll:"\uBAA8\uB450",matchCase:"\uB300/\uC18C\uBB38\uC790",wholeCell:"\uCE78 \uC804\uCCB4",inColumn:"\uD604\uC7AC \uC5F4",replaced:"\uBC14\uAFE8\uC2B5\uB2C8\uB2E4.",notReplaceable:"\uBC14\uAFC0 \uCE78\uC774 \uC544\uB2D9\uB2C8\uB2E4.",replacedCount:r=>`${r}\uCE78\uC744 \uBC14\uAFE8\uC2B5\uB2C8\uB2E4.`,notFound:"\uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",addSheet:"\uC2DC\uD2B8 \uCD94\uAC00",licenseNotice:"NoxGrid \xB7 \uBB34\uB8CC \uC0AC\uC6A9\uAD8C \uD0A4 \uB4F1\uB85D: novnox.dev/license",am:"\uC624\uC804",pm:"\uC624\uD6C4",subtotal:{sum:"\uD569\uACC4",count:"\uAC1C\uC218",average:"\uD3C9\uADE0",max:"\uCD5C\uB300",min:"\uCD5C\uC18C"},subtotalLabel:(r,e)=>`${r} ${e}`,grandTotal:r=>`\uCD1D${r}`,parse:{incomplete:"\uC2DD\uC774 \uB05D\uB098\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4",badRef:"\uCC38\uC870 \uD615\uC2DD\uC774 \uC798\uBABB\uB418\uC5C8\uC2B5\uB2C8\uB2E4",cannotRead:r=>`'${r}' \uC744(\uB97C) \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4`,noRefAfterSheet:"\uC2DC\uD2B8 \uC774\uB984 \uB4A4\uC5D0 \uCC38\uC870\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4",unclosedString:'\uAE00\uC790 \uB530\uC634\uD45C(")\uAC00 \uB2EB\uD788\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4',unknownError:"\uC54C \uC218 \uC5C6\uB294 \uC624\uB958 \uAC12\uC785\uB2C8\uB2E4",badNumber:"\uC22B\uC790 \uD615\uC2DD\uC774 \uC798\uBABB\uB418\uC5C8\uC2B5\uB2C8\uB2E4",unclosedSheet:"\uC2DC\uD2B8 \uC774\uB984 \uB530\uC634\uD45C(')\uAC00 \uB2EB\uD788\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4",noBang:"\uC2DC\uD2B8 \uC774\uB984 \uB4A4\uC5D0 ! \uAC00 \uC5C6\uC2B5\uB2C8\uB2E4",expected:r=>`'${r}' \uC774(\uAC00) \uD544\uC694\uD569\uB2C8\uB2E4`,at:(r,e)=>`${r} (\uC704\uCE58 ${e})`,empty:"\uC218\uC2DD\uC774 \uBE44\uC5B4 \uC788\uC2B5\uB2C8\uB2E4."}},Io={editCell:"Edit grid cell",sortAsc:"\u2191 Sort A\u2192Z",sortDesc:"\u2193 Sort Z\u2192A",search:"Search",selectAll:"(Select all)",blank:"(Blanks)",clearFilter:"Clear filter",ok:"OK",badFormat:"The value is not in the correct format.",badFormula:"The formula is not valid.",formulaError:r=>`Formula error: ${r}`,required:r=>`${r}: a value is required.`,min:r=>`Must be ${r} or greater.`,max:r=>`Must be ${r} or less.`,maxLength:r=>`Up to ${r} characters.`,notInList:"Only values from the list are allowed.",findWhat:"Find what",findNext:"Next",close:"Close",replaceWith:"Replace with",replace:"Replace",replaceAll:"All",matchCase:"Match case",wholeCell:"Whole cell",inColumn:"This column",replaced:"Replaced.",notReplaceable:"This cell cannot be replaced.",replacedCount:r=>`Replaced ${r} cell${r===1?"":"s"}.`,notFound:"Not found.",addSheet:"Add sheet",licenseNotice:"NoxGrid \xB7 Get a free license key: novnox.dev/license",am:"AM",pm:"PM",subtotal:{sum:"Total",count:"Count",average:"Average",max:"Max",min:"Min"},subtotalLabel:(r,e)=>`${r} ${e}`,grandTotal:r=>`Grand ${r}`,parse:{incomplete:"Unexpected end of formula",badRef:"Invalid reference",cannotRead:r=>`Unexpected '${r}'`,noRefAfterSheet:"A reference must follow the sheet name",unclosedString:'Missing closing quote (")',unknownError:"Unknown error value",badNumber:"Invalid number",unclosedSheet:"Missing closing quote (') in sheet name",noBang:"'!' must follow the sheet name",expected:r=>`'${r}' expected`,at:(r,e)=>`${r} (position ${e})`,empty:"The formula is empty."}},Fn={ko:zo,en:Io},en="en";function Ct(r){en=Fn[r]?r:"en"}function $o(){return en}function N(){return Fn[en]}var on="https://novnox.dev/license/",tn="NOX1.",Po={kty:"EC",crv:"P-256",x:"WM_HWO2_cFa2dGrN2_DGI92ZnsnFhY4NQB-b4yUyzNo",y:"aX1ft4suJXsJv3oV_j66Nf85KtM4QBK6AqNrj8NAYfc"},tt=null,St=null,Tn=!1,nn=new Set;function Nn(r){let e=r.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((r.length+3)%4),t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}var Ge=r=>({valid:!1,type:"none",domains:[],message:r});function Go(r,e){if(!e.length)return!0;let t=r.toLowerCase();return e.some(n=>{let o=n.toLowerCase();if(o.startsWith("*.")){let i=o.slice(2);return t===i||t.endsWith("."+i)}return t===o})}function Vn(r){let e=r.toLowerCase();return e===""||e==="localhost"||e==="::1"||e==="[::1]"||/^127\./.test(e)||/\.(local|localhost|test)$/.test(e)}async function Hn(r,e){var u;let t=(r!=null?r:"").trim();if(!t.startsWith(tn))return Ge("NoxGrid \uC0AC\uC6A9\uAD8C \uD0A4 \uD615\uC2DD\uC774 \uC544\uB2D9\uB2C8\uB2E4.");let n=t.lastIndexOf(".");if(n<=tn.length)return Ge("NoxGrid \uC0AC\uC6A9\uAD8C \uD0A4 \uD615\uC2DD\uC774 \uC544\uB2D9\uB2C8\uB2E4.");let o=typeof crypto!="undefined"?crypto.subtle:void 0;if(!o)return Ge("\uBCF4\uC548 \uC5F0\uACB0(https)\uC5D0\uC11C\uB9CC \uC0AC\uC6A9\uAD8C \uD0A4\uB97C \uD655\uC778\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.");let i;try{let c=await o.importKey("jwk",Po,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),h=t.slice(0,n);if(!await o.verify({name:"ECDSA",hash:"SHA-256"},c,Nn(t.slice(n+1)),new TextEncoder().encode(h)))return Ge("\uC0AC\uC6A9\uAD8C \uD0A4\uAC00 \uB9DE\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4 (\uC11C\uBA85 \uD655\uC778 \uC2E4\uD328).");i=JSON.parse(new TextDecoder().decode(Nn(h.slice(tn.length))))}catch{return Ge("NoxGrid \uC0AC\uC6A9\uAD8C \uD0A4 \uD615\uC2DD\uC774 \uC544\uB2D9\uB2C8\uB2E4.")}if(i.p!=="NoxGrid")return Ge("NoxGrid \uC0AC\uC6A9\uAD8C \uD0A4\uAC00 \uC544\uB2D9\uB2C8\uB2E4.");let s={valid:!1,type:i.t==="commercial"?"commercial":i.t==="community"?"community":"free1",licensee:i.n,email:i.e,organization:i.o,maxMajor:typeof i.maj=="number"?i.maj:1,issued:i.iss,expires:i.exp,domains:Array.isArray(i.d)?i.d:[],id:i.id,message:""},l=new Date,a=`${l.getFullYear()}-${String(l.getMonth()+1).padStart(2,"0")}-${String(l.getDate()).padStart(2,"0")}`;return((u=s.maxMajor)!=null?u:1)<1?s.message=`\uC774 \uD0A4\uB294 NoxGrid ${s.maxMajor}.x \uC6A9\uC785\uB2C8\uB2E4. \uC0C8 \uD0A4\uB97C \uBC1B\uC73C\uC138\uC694: ${on}`:s.expires&&s.expires<a?s.message=`\uC0AC\uC6A9\uAD8C \uD0A4 \uAE30\uAC04\uC774 \uB05D\uB0AC\uC2B5\uB2C8\uB2E4 (${s.expires}).`:e!==void 0&&!Vn(e)&&!Go(e,s.domains)?s.message=`\uC774 \uD0A4\uB294 ${s.domains.join(", ")} \uC5D0\uC11C\uB9CC \uC4F8 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`:(s.valid=!0,s.message=`\uC0AC\uC6A9\uAD8C \uD655\uC778: ${s.licensee}`),s}function Dn(){return typeof location!="undefined"?location.hostname:""}function Wo(r){return St=Hn(r,Dn()).then(e=>{tt=e,St=null,!e.valid&&typeof console!="undefined"&&console.warn(`[NoxGrid] ${e.message}`);for(let t of nn)t();return e}),St}function Bo(){return tt}function On(){return Vn(Dn())||St||tt!=null&&tt.valid?!1:(!Tn&&typeof console!="undefined"&&(Tn=!0,console.info(`[NoxGrid] \uC0AC\uC6A9\uAD8C \uD0A4\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uBB34\uB8CC \uD0A4: ${on}`)),!0)}function Ln(r){return nn.add(r),()=>nn.delete(r)}var kt=new Set,Mt=!1;function Uo(r){if(!r.isConnected)return!1;let e=r.getBoundingClientRect();return e.width<=0||e.height<=0?!1:e.bottom>0&&e.right>0&&e.top<window.innerHeight&&e.left<window.innerWidth}function zn(r){if(!(r.ctrlKey||r.metaKey)||r.altKey||r.shiftKey||r.key.toLowerCase()!=="f"||r.defaultPrevented)return;let e=[...kt].filter(o=>o.findAllowed&&Uo(o.root));if(!e.length)return;let t=document.activeElement,n=e.length===1?e[0]:e.find(o=>!!t&&o.root.contains(t));!n||t&&n.root.contains(t)||(r.preventDefault(),n.openFind())}function In(r){return kt.add(r),!Mt&&typeof document!="undefined"&&(document.addEventListener("keydown",zn,!0),Mt=!0),()=>{kt.delete(r),!kt.size&&Mt&&(document.removeEventListener("keydown",zn,!0),Mt=!1)}}var $n=new Map;function ye(r){return r instanceof Date&&!isNaN(r.getTime())}function ke(r,e){return r==null?"":typeof r=="number"?isFinite(r)?e?Rt(r,e):Ko(r):String(r):ye(r)?Et(r,e||(_o(r)?"yyyy-MM-dd HH:mm":"yyyy-MM-dd")):typeof r=="boolean"?r?"TRUE":"FALSE":String(r)}function _o(r){return r.getHours()!==0||r.getMinutes()!==0||r.getSeconds()!==0}function Ko(r){return Number.isInteger(r)?String(r):String(parseFloat(r.toPrecision(15)))}var He=(r,e=2)=>String(r).padStart(e,"0");function Et(r,e){return e.replace(/yyyy|yy|MM|M|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,t=>{switch(t){case"yyyy":return String(r.getFullYear());case"yy":return He(r.getFullYear()%100);case"MM":return He(r.getMonth()+1);case"M":return String(r.getMonth()+1);case"dd":return He(r.getDate());case"d":return String(r.getDate());case"HH":return He(r.getHours());case"H":return String(r.getHours());case"hh":return He(r.getHours()%12||12);case"h":return String(r.getHours()%12||12);case"mm":return He(r.getMinutes());case"ss":return He(r.getSeconds());case"tt":return r.getHours()<12?N().am:N().pm;default:return t.slice(1,-1)}})}function Rt(r,e){let t=$n.get(e);return t||(t=jo(e),$n.set(e,t)),t(r)}function jo(r){let e=/^([NFPCD])(\d{0,2})$/i.exec(r);if(e){let s=e[1].toUpperCase(),l=e[2]===""?s==="D"?0:2:parseInt(e[2],10);switch(s){case"N":return a=>At(a,l,!0);case"F":return a=>At(a,l,!1);case"P":return a=>At(a*100,l,!0)+"%";case"C":return a=>(a<0?"-\u20A9":"\u20A9")+At(Math.abs(a),e[2]===""?0:l,!0);default:return a=>String(Math.round(a)).padStart(l,"0")}}let t=Xo(r),n=rn(t[0]),o=t.length>1?rn(t[1]):null,i=t.length>2?rn(t[2]):null;return s=>s===0&&i?i(0):s<0&&o?o(-s):n(s)}function Xo(r){let e=[],t="",n=!1;for(let o of r)o==='"'&&(n=!n),o===";"&&!n?(e.push(t),t=""):t+=o;return e.push(t),e}function rn(r){let e="",t="",n="",o=!1,i=!1,s=!1;for(let b=0;b<r.length;b++){let g=r[b];if(g==='"'){let w=r.indexOf('"',b+1),S=r.slice(b+1,w<0?r.length:w);o?(i=!0,t+=S):e+=S,b=w<0?r.length:w;continue}if(g==="\\"&&b+1<r.length){o?t+=r[++b]:e+=r[++b],o&&(i=!0);continue}g==="%"&&(s=!0),!i&&"#0,.?".includes(g)?(o=!0,n+=g):o?(i=!0,t+=g):e+=g}if(!n){let b=e+t;return g=>g<0?"-"+b:b}let l=n.indexOf("."),a=l<0?n:n.slice(0,l),u=l<0?"":n.slice(l+1),c=1,h=a;for(;h.endsWith(",");)c*=1e3,h=h.slice(0,-1);let d=h.includes(","),f=(h.match(/0/g)||[]).length,m=(u.match(/0/g)||[]).length,p=u.replace(/,/g,"").length;return b=>{let g=b/c;s&&(g*=100);let w=g<0;g=Math.abs(g);let S=Gn(g,p).toFixed(p);if(p>m){let D=S.length;for(;D>S.length-(p-m)&&S[D-1]==="0";)D--;S=S.slice(0,D),S.endsWith(".")&&(S=S.slice(0,-1))}let[v,k]=S.split(".");v==="0"&&f===0&&(v=""),v.length<f&&(v=v.padStart(f,"0")),d&&(v=Wn(v));let R=k!==void 0?`${v}.${k}`:v;return(w?"-":"")+e+R+t}}function Gn(r,e){let t=Math.pow(10,e);return Math.round((r+Number.EPSILON)*t)/t}function Wn(r){return r.replace(/\B(?=(\d{3})+(?!\d))/g,",")}function At(r,e,t){let n=r<0,o=Gn(Math.abs(r),e).toFixed(e),[i,s]=o.split("."),l=t?Wn(i):i;return(n?"-":"")+(s!==void 0?`${l}.${s}`:l)}function sn(r){let e=r.trim().replace(/,/g,"").replace(/^₩/,"");if(e==="")return null;let t=!1;if(e.endsWith("%")&&(t=!0,e=e.slice(0,-1)),!/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(e))return null;let n=parseFloat(e);return t?n/100:n}function xe(r){let e=r.trim(),t=/^(\d{4})[-/.]?(\d{1,2})[-/.]?(\d{1,2})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(e);if(!t)return null;let n=new Date(+t[1],+t[2]-1,+t[3],t[4]?+t[4]:0,t[5]?+t[5]:0,t[6]?+t[6]:0);return n.getMonth()!==+t[2]-1||n.getDate()!==+t[3]?null:n}function We(r,e){let t=r==null||r==="",n=e==null||e==="";if(t||n)return t===n?0:t?1:-1;let o=Pn(r),i=Pn(e);return typeof o=="number"&&typeof i=="number"?o-i:typeof o=="number"?-1:typeof i=="number"?1:Yo.compare(o,i)}var Yo=new Intl.Collator("ko",{numeric:!0,sensitivity:"base"});function Pn(r){return typeof r=="number"?r:typeof r=="boolean"?r?1:0:ye(r)?r.getTime():String(r)}function Re(r,e){if(ye(r)&&ye(e))return r.getTime()===e.getTime();let t=r==null||r==="",n=e==null||e==="";return t||n?t&&n:r===e}var Ft=class{constructor(e){this.options=e}},nt=class{constructor(e,t){this.model=e;this.changed=t;this.list=[];this.scaleCache=new Map;this.version=-1}get count(){return this.list.length}get(e){return this.list[e]}[Symbol.iterator](){return this.list[Symbol.iterator]()}add(e){let t=new Ft(e);return this.list.push(t),this.changed(),t}addExpression(e,t,n,o=!1){return this.add({operator:"expression",columns:e,test:t,entireRow:o,...n})}addColorScale(e,t,n,o){return this.add({operator:"colorScale",columns:e,minColor:t,maxColor:n,midColor:o})}remove(e){let t=this.list.indexOf(e);t>=0&&(this.list.splice(t,1),this.changed())}clear(){this.list=[],this.changed()}invalidate(){this.version=-1}evaluate(e,t){var o,i,s,l,a,u;if(this.list.length===0)return null;this.version===-1&&(this.scaleCache.clear(),this.version=0);let n=null;for(let c=0;c<this.list.length;c++){let h=this.list[c].options,d=this.columnsOf(h);if(h.range&&(e<h.range.row||e>h.range.row2))continue;let f=t;if(h.entireRow){if(!d||d.length===0)continue;f=d[0]}else if(d&&!d.includes(t)||h.range&&(t<h.range.col||t>h.range.col2))continue;let m=this.model.getValue(e,f);if(h.operator==="colorScale"){if(typeof m!="number")continue;let p=this.scaleColor(c,h,f,m);n!=null||(n={}),(o=n.backColor)!=null||(n.backColor=p);continue}if(this.matches(h,e,f,m)&&(n!=null||(n={}),h.backColor!==void 0&&((i=n.backColor)!=null||(n.backColor=h.backColor)),h.foreColor!==void 0&&((s=n.foreColor)!=null||(n.foreColor=h.foreColor)),h.bold!==void 0&&((l=n.bold)!=null||(n.bold=h.bold)),h.italic!==void 0&&((a=n.italic)!=null||(n.italic=h.italic)),h.strikeout!==void 0&&((u=n.strikeout)!=null||(n.strikeout=h.strikeout)),h.stopIfTrue))break}return n}columnsOf(e){if(!e.columns)return null;let t=[];for(let n of e.columns){let o=this.model.columnIndex(n);o>=0&&t.push(o)}return t}matches(e,t,n,o){let i=o==null||o==="",s=u=>We(o,qo(u,o)),l=()=>(o==null?"":String(o)).toLowerCase(),a=()=>{var u;return String((u=e.value1)!=null?u:"").toLowerCase()};switch(e.operator){case"blank":return i;case"notBlank":return!i;case"equal":return!i&&s(e.value1)===0;case"notEqual":return i||s(e.value1)!==0;case"greater":return!i&&s(e.value1)>0;case"greaterOrEqual":return!i&&s(e.value1)>=0;case"less":return!i&&s(e.value1)<0;case"lessOrEqual":return!i&&s(e.value1)<=0;case"between":return!i&&s(e.value1)>=0&&s(e.value2)<=0;case"notBetween":return!i&&(s(e.value1)<0||s(e.value2)>0);case"contains":return l().includes(a());case"beginsWith":return l().startsWith(a());case"endsWith":return l().endsWith(a());case"expression":{if(!e.test)return!1;let u=this.model;try{return!!e.test({row:t,col:n,value:o,get:c=>u.getValue(t,u.columnIndex(c))})}catch{return!1}}default:return!1}}scaleColor(e,t,n,o){var c,h;let i=`${e}:${n}`,s=this.scaleCache.get(i);if(!s){let d=1/0,f=-1/0,m=t.range?t.range.row:0,p=t.range?Math.min(t.range.row2,this.model.rowCount-1):this.model.rowCount-1;for(let b=m;b<=p;b++){let g=this.model.getValue(b,n);typeof g=="number"&&(g<d&&(d=g),g>f&&(f=g))}s={min:d,max:f},this.scaleCache.set(i,s)}let l=s.max>s.min?(o-s.min)/(s.max-s.min):.5,a=(c=t.minColor)!=null?c:"#f8696b",u=(h=t.maxColor)!=null?h:"#63be7b";return t.midColor?l<.5?W(a,t.midColor,l*2):W(t.midColor,u,(l-.5)*2):W(a,u,l)}};function qo(r,e){if(typeof e=="number"&&typeof r=="string"&&r.trim()!==""&&!isNaN(+r))return+r;if(ye(e)&&typeof r=="string"){let t=new Date(r);return isNaN(t.getTime())?r:t}return r}function W(r,e,t){let n=Bn(r),o=Bn(e);t=Math.max(0,Math.min(1,t));let i=s=>Math.round(n[s]+(o[s]-n[s])*t);return`rgb(${i(0)},${i(1)},${i(2)})`}function Bn(r){if(r=r.trim(),r[0]==="#"){let t=r.length===4?r.slice(1).split("").map(n=>n+n).join(""):r.slice(1,7);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let e=/(\d+)\D+(\d+)\D+(\d+)/.exec(r);return e?[+e[1],+e[2],+e[3]]:[0,0,0]}var Tt=class{constructor(){this.handlers=new Map}on(e,t){let n=this.handlers.get(e);return n||this.handlers.set(e,n=new Set),n.add(t),()=>this.off(e,t)}off(e,t){var n;(n=this.handlers.get(e))==null||n.delete(t)}has(e){var t,n;return((n=(t=this.handlers.get(e))==null?void 0:t.size)!=null?n:0)>0}emit(e,t){let n=this.handlers.get(e);if(n)for(let o of[...n])o(t)}};var Nt=class{constructor(e=100){this.limit=e;this.done=[];this.undone=[];this.batch=null;this.depth=0;this.replaying=!1;this.enabled=!0}get canUndo(){return this.done.length>0}get canRedo(){return this.undone.length>0}get recording(){return this.enabled&&!this.replaying}push(e){if(this.recording){if(this.batch){this.batch.push(e);return}this.done.push(e),this.done.length>this.limit&&this.done.shift(),this.undone.length=0}}transaction(e){this.depth++===0&&(this.batch=[]);try{return e()}finally{if(--this.depth===0){let t=this.batch;this.batch=null,t.length===1?this.push(t[0]):t.length>1&&this.push({undo:()=>{for(let n=t.length-1;n>=0;n--)t[n].undo()},redo:()=>{for(let n of t)n.redo()}})}}}undo(){let e=this.done.pop();return e?(this.replay(()=>e.undo()),this.undone.push(e),!0):!1}redo(){let e=this.undone.pop();return e?(this.replay(()=>e.redo()),this.done.push(e),!0):!1}clear(){this.done.length=0,this.undone.length=0}replay(e){this.replaying=!0;try{e()}finally{this.replaying=!1}}};function Qo(r){switch(r.t){case"unary":case"pct":return[r.operand];case"bin":return[r.left,r.right];case"func":return r.args;case"paren":return[r.inner];default:return[]}}function*Te(r){let e=[r];for(;e.length;){let t=e.pop();yield t;for(let n of Qo(t))e.push(n)}}function Fe(r){switch(r.t){case"unary":return{...r,operand:Fe(r.operand)};case"pct":return{...r,operand:Fe(r.operand)};case"bin":return{...r,left:Fe(r.left),right:Fe(r.right)};case"func":return{...r,args:r.args.map(Fe)};case"paren":return{...r,inner:Fe(r.inner)};default:return{...r}}}function De(r){r.r1>r.r2&&([r.r1,r.r2]=[r.r2,r.r1],[r.r1Abs,r.r2Abs]=[r.r2Abs,r.r1Abs]),r.c1>r.c2&&([r.c1,r.c2]=[r.c2,r.c1],[r.c1Abs,r.c2Abs]=[r.c2Abs,r.c1Abs])}var $=class ${constructor(e){this.code=e}toString(){return this.code}static fromCode(e){var n;let t=e.toUpperCase();return(n=$.all.find(o=>o.code===t))!=null?n:null}};$.DivideByZero=new $("#DIV/0!"),$.Value=new $("#VALUE!"),$.Reference=new $("#REF!"),$.Name=new $("#NAME?"),$.NotAvailable=new $("#N/A"),$.Number=new $("#NUM!"),$.NullIntersection=new $("#NULL!"),$.Circular=new $("#CIRC!"),$.all=[$.DivideByZero,$.Value,$.Reference,$.Name,$.NotAvailable,$.Number,$.NullIntersection,$.Circular];var C=$,ve=class extends Error{constructor(t,n){super(t);this.position=n;this.name="FormulaSyntaxError"}},Un=2147483647,X=class{constructor(e,t,n,o,i){this.sheet=e;this.r1=t;this.c1=n;this.r2=o;this.c2=i}get rows(){return Math.min(Un,this.r2-this.r1+1)}get columns(){return Math.min(Un,this.c2-this.c1+1)}get isSingleCell(){return this.r1===this.r2&&this.c1===this.c2}get lastRow(){return Math.min(this.r2,this.sheet.rowCount-1)}get lastColumn(){return Math.min(this.c2,this.sheet.columnCount-1)}get(e,t){let n=this.r1+e,o=this.c1+t;return n>this.lastRow||o>this.lastColumn?null:ot(this.sheet.getValue(n,o))}*values(){let e=this.lastRow,t=this.lastColumn;for(let n=this.r1;n<=e;n++)for(let o=this.c1;o<=t;o++)yield ot(this.sheet.getValue(n,o))}get cellCount(){return this.rows*this.columns}},Yn=Date.UTC(1899,11,30),qn=864e5;function ee(r){return(Date.UTC(r.getFullYear(),r.getMonth(),r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds(),r.getMilliseconds())-Yn)/qn}function Ht(r){let e=new Date(Yn+Math.round(r*qn)),t=new Date(2e3,0,1,e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds());return t.setFullYear(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),t}function ot(r){if(r==null)return null;if(typeof r=="number")return isNaN(r)?C.Number:r;if(typeof r=="boolean"||r instanceof C)return r;if(r instanceof Date)return isNaN(r.getTime())?null:r;if(typeof r=="string"){if(r.length===0)return null;if(Zo(r)){let e=Be(r);if(e!==null)return e}return r}return String(r)}function _n(r){return r!==void 0&&r>="0"&&r<="9"}function Zo(r){let e=r.trim();if(!e)return!1;let t=e[0]==="-"||e[0]==="+"?1:0;return t>=e.length||!_n(e[t])&&e[t]!=="."?!1:!(e[t]==="0"&&t+1<e.length&&_n(e[t+1]))}function Be(r){let e=r.trim();if(!/^[-+]?(\d{1,3}(,\d{3})+|\d+)?(\.\d*)?([eE][-+]?\d+)?$/.test(e)||!/\d/.test(e))return null;let t=parseFloat(e.replace(/,/g,""));return isNaN(t)?null:t}function Qn(r){return r===null?0:r instanceof X?C.Value:r}function q(r){return isNaN(r)||!isFinite(r)?C.Number:r}function an(r){return r>=-657435&&r<2958466?Ht(r):q(r)}function oe(r){if(r==null)return 0;if(typeof r=="number")return r;if(typeof r=="boolean")return r?1:0;if(r instanceof Date)return ee(r);if(typeof r=="string"){let e=Be(r);if(e!==null)return e;let t=xe(r);return t?ee(t):null}return null}function Dt(r){if(r==null)return!1;if(typeof r=="boolean")return r;if(typeof r=="number")return r!==0;if(r instanceof Date)return ee(r)!==0;if(typeof r=="string"){let e=r.toUpperCase();if(e==="TRUE")return!0;if(e==="FALSE")return!1}return null}function se(r){return r==null?"":typeof r=="string"?r:typeof r=="number"?Kn(r):typeof r=="boolean"?r?"TRUE":"FALSE":r instanceof Date?Kn(ee(r)):r instanceof C?r.code:String(r)}function Kn(r){return Math.abs(r)<1e15&&r===Math.floor(r)?r.toFixed(0)==="-0"?"0":r.toFixed(0):String(Number(r.toPrecision(15))).replace("e+","E+").replace("e-","E-")}var Jo=new Intl.Collator("ko",{sensitivity:"accent"});function Vt(r,e){let t=Jo.compare(r,e);return t<0?-1:t>0?1:0}function ge(r,e){if(r===null&&e===null)return 0;r===null&&(r=jn(e)),e===null&&(e=jn(r));let t=ln(r),n=ln(e);if(t!==n)return t<n?-1:1;switch(t){case 0:{let o=oe(r),i=oe(e);return Ue(o,i)?0:o<i?-1:1}case 1:return Vt(se(r),se(e));case 2:return r===e?0:r?1:-1;default:{let o=se(r).toUpperCase(),i=se(e).toUpperCase();return o<i?-1:o>i?1:0}}}function jn(r){switch(ln(r)){case 0:return 0;case 2:return!1;default:return""}}function ln(r){return typeof r=="number"||r instanceof Date?0:typeof r=="string"?1:typeof r=="boolean"?2:3}function Ue(r,e){if(r===e)return!0;let t=Math.max(Math.abs(r),Math.abs(e));return Math.abs(r-e)<=t*1e-15}function be(r){return typeof r=="number"||r instanceof Date}function _e(r){return typeof r=="number"?r:ee(r)}function Ot(r,e=!0){let t="";for(let n=0;n<r.length;n++){let o=r[n];o==="~"&&n+1<r.length&&"*?~".includes(r[n+1])?t+=Xn(r[++n]):o==="*"?t+="[\\s\\S]*":o==="?"?t+="[\\s\\S]":t+=Xn(o)}return new RegExp(e?`^${t}$`:t,"i")}function Xn(r){return r.replace(/[.*+?^${}()|[\]\\/-]/g,"\\$&")}var rt=class r{constructor(e,t){this.op=e;this.value=t;this.isNumber=!1;this.number=0;this.pattern=null;typeof t=="number"?(this.isNumber=!0,this.number=t):t instanceof Date?(this.isNumber=!0,this.number=ee(t)):typeof t=="string"&&(e==="="||e==="<>")&&(t.includes("*")||t.includes("?"))&&(this.pattern=Ot(t))}static parse(e){if(e==null)return new r("=","");if(typeof e=="number"||typeof e=="boolean"||e instanceof Date)return new r("=",e);let t=se(e),n="=";for(let s of["<>","<=",">=","<",">","="])if(t.startsWith(s)){n=s,t=t.slice(s.length);break}let o=t,i=t.length>0?Be(t):null;return i!==null?o=i:t.toUpperCase()==="TRUE"?o=!0:t.toUpperCase()==="FALSE"&&(o=!1),new r(n,o)}matches(e){if(e instanceof C)return!1;if(typeof this.value=="string"&&this.value.length===0){let n=e===null||e==="";return this.op==="<>"?!n:this.op==="="&&n}if(this.isNumber){if(!be(e))return this.op==="<>";let n=_e(e);return this.test(Ue(n,this.number)?0:n<this.number?-1:1)}if(typeof this.value=="boolean")return typeof e!="boolean"?this.op==="<>":this.test(e===this.value?0:e?1:-1);let t=this.value;if(this.op==="="||this.op==="<>"){let n;return typeof e!="string"?n=!1:this.pattern?n=this.pattern.test(e):n=Vt(e,t)===0,this.op==="="?n:!n}return typeof e!="string"?!1:this.test(Vt(e,t))}test(e){switch(this.op){case"=":return e===0;case"<>":return e!==0;case"<":return e<0;case">":return e>0;case"<=":return e<=0;case">=":return e>=0;default:return!1}}};var le=()=>N().parse;function cn(r){return r>="A"&&r<="Z"||r>="a"&&r<="z"}var er=/\p{L}/u,tr=/[\p{L}\p{Nd}]/u;function Lt(r){return er.test(r)||r==="_"||r==="\\"}function zt(r){return tr.test(r)||r==="_"||r==="."||r==="\\"}function Ke(r){return r!==void 0&&r>="0"&&r<="9"}var un=class{constructor(e){this.s=e;this.pos=0}expression(){return this.comparison()}comparison(){let e=this.concat();for(;;){this.ws();let t=null;for(let n of["<>","<=",">=","<",">","="])if(this.match(n)){t=n;break}if(!t)return e;e={t:"bin",op:t,left:e,right:this.concat()}}}concat(){let e=this.additive();for(;;){if(this.ws(),!this.match("&"))return e;e={t:"bin",op:"&",left:e,right:this.additive()}}}additive(){let e=this.multiplicative();for(;;)if(this.ws(),this.match("+"))e={t:"bin",op:"+",left:e,right:this.multiplicative()};else if(this.match("-"))e={t:"bin",op:"-",left:e,right:this.multiplicative()};else return e}multiplicative(){let e=this.power();for(;;)if(this.ws(),this.match("*"))e={t:"bin",op:"*",left:e,right:this.power()};else if(this.match("/"))e={t:"bin",op:"/",left:e,right:this.power()};else return e}power(){let e=this.unary();for(;;){if(this.ws(),!this.match("^"))return e;e={t:"bin",op:"^",left:e,right:this.unary()}}}unary(){return this.ws(),this.match("-")?{t:"unary",op:"-",operand:this.unary()}:this.match("+")?{t:"unary",op:"+",operand:this.unary()}:this.percent()}percent(){let e=this.primary();for(;;){if(this.ws(),!this.match("%"))return e;e={t:"pct",operand:e}}}primary(){this.ws();let e=this.s;if(this.pos>=e.length)throw this.error(le().incomplete);let t=e[this.pos];if(t==="("){this.pos++;let n=this.expression();return this.ws(),this.expect(")"),{t:"paren",inner:n}}if(t==='"')return{t:"lit",value:this.readString()};if(t==="#")return{t:"lit",value:this.readError()};if(t==="'")return this.reference(this.readQuotedSheet());if(Ke(t)||t==="."||t==="$"||Lt(t)){let n=this.tryReference(null);if(n)return n;if(Ke(t)||t===".")return{t:"lit",value:this.readNumber()};if(t==="$")throw this.error(le().badRef);let o=this.readName();if(this.ws(),this.peek("!"))return this.pos++,this.reference(o);if(this.peek("("))return this.pos++,{t:"func",name:nr(o),args:this.readArgs()};let i=o.toUpperCase();return i==="TRUE"?{t:"lit",value:!0}:i==="FALSE"?{t:"lit",value:!1}:{t:"name",name:o}}throw this.error(le().cannotRead(t))}readArgs(){let e=[];if(this.ws(),this.match(")"))return e;for(;;)if(this.ws(),this.peek(",")||this.peek(")")?e.push({t:"empty"}):e.push(this.expression()),this.ws(),!this.match(","))return this.expect(")"),e}reference(e){if(this.ws(),this.peek("#"))return{t:"lit",value:this.readError()};let t=this.tryReference(e);if(!t)throw this.error(le().noRefAfterSheet);return t}tryReference(e){let t=this.pos,n=this.tryCell();if(n){let s=this.pos;if(this.match(":")){e!==null&&this.skipSameSheetPrefix(e);let l=this.tryCell();if(l){let a={t:"area",sheet:e,kind:"cells",r1:n.row,c1:n.col,r2:l.row,c2:l.col,r1Abs:n.rowAbs,c1Abs:n.colAbs,r2Abs:l.rowAbs,c2Abs:l.colAbs,invalid:!1};return De(a),a}this.pos=s}return{t:"ref",sheet:e,row:n.row,col:n.col,rowAbs:n.rowAbs,colAbs:n.colAbs,invalid:!1}}this.pos=t;let o=this.tryColumn();if(o&&this.match(":")){let s=this.tryColumn();if(s&&!this.nextIsNameChar()){let l={t:"area",sheet:e,kind:"columns",r1:0,r2:2147483647,c1:o.col,c2:s.col,r1Abs:!1,r2Abs:!1,c1Abs:o.abs,c2Abs:s.abs,invalid:!1};return De(l),l}}this.pos=t;let i=this.tryRow();if(i&&this.match(":")){let s=this.tryRow();if(s&&!this.nextIsNameChar()){let l={t:"area",sheet:e,kind:"rows",r1:i.row,r2:s.row,c1:0,c2:2147483647,r1Abs:i.abs,r2Abs:s.abs,c1Abs:!1,c2Abs:!1,invalid:!1};return De(l),l}}return this.pos=t,null}skipSameSheetPrefix(e){let t=this.pos,n=null;if(this.peek("'"))try{n=this.readQuotedSheet()}catch{this.pos=t;return}else if(this.pos<this.s.length&&Lt(this.s[this.pos])){let o=this.readName();this.peek("!")&&(this.pos++,n=o)}(n===null||n.toUpperCase()!==e.toUpperCase())&&(this.pos=t)}tryCell(){let e=this.pos,t=this.tryColumn();if(t){let n=this.tryRow();if(n&&!this.nextIsNameChar()&&!this.peek("("))return{row:n.row,col:t.col,rowAbs:n.abs,colAbs:t.abs}}return this.pos=e,null}tryColumn(){let e=this.pos,t=this.match("$"),n=0,o=0;for(;this.pos<this.s.length&&o<4&&cn(this.s[this.pos]);)n=n*26+(this.s[this.pos].toUpperCase().charCodeAt(0)-64),this.pos++,o++;return o===0||o>3?(this.pos=e,null):{col:n-1,abs:t}}tryRow(){let e=this.pos,t=this.match("$"),n=0,o=0;for(;this.pos<this.s.length&&Ke(this.s[this.pos]);)if(n=n*10+(this.s.charCodeAt(this.pos)-48),this.pos++,++o>9)return this.pos=e,null;return o===0||n<1?(this.pos=e,null):{row:n-1,abs:t}}nextIsNameChar(){return this.pos<this.s.length&&(zt(this.s[this.pos])||this.s[this.pos]==="!")}readString(){let e="";for(this.pos++;;){if(this.pos>=this.s.length)throw this.error(le().unclosedString);let t=this.s[this.pos++];if(t==='"'){if(this.peek('"')){e+='"',this.pos++;continue}return e}e+=t}}readError(){for(let e of C.all)if(this.s.substr(this.pos,e.code.length).toUpperCase()===e.code)return this.pos+=e.code.length,e;throw this.error(le().unknownError)}readNumber(){let e=this.s,t=this.pos;for(;Ke(e[this.pos]);)this.pos++;if(this.peek("."))for(this.pos++;Ke(e[this.pos]);)this.pos++;if(e[this.pos]==="E"||e[this.pos]==="e"){let i=this.pos;this.pos++,(this.peek("+")||this.peek("-"))&&this.pos++;let s=0;for(;Ke(e[this.pos]);)this.pos++,s++;s===0&&(this.pos=i)}let n=e.slice(t,this.pos),o=Number(n);if(n==="."||n===""||isNaN(o))throw this.pos=t,this.error(le().badNumber);return o}readName(){let e=this.pos;for(;this.pos<this.s.length&&zt(this.s[this.pos]);)this.pos++;return this.s.slice(e,this.pos)}readQuotedSheet(){let e="";for(this.pos++;;){if(this.pos>=this.s.length)throw this.error(le().unclosedSheet);let t=this.s[this.pos++];if(t==="'"){if(this.peek("'")){e+="'",this.pos++;continue}break}e+=t}if(!this.match("!"))throw this.error(le().noBang);return e}ws(){for(;this.pos<this.s.length&&` \r
|
|
3
|
+
`.includes(this.s[this.pos]);)this.pos++}peek(e){return this.s[this.pos]===e}match(e){return this.s.startsWith(e,this.pos)?(this.pos+=e.length,!0):!1}expect(e){if(!this.peek(e))throw this.error(le().expected(e));this.pos++}error(e){return new ve(le().at(e,this.pos+1),this.pos)}};function nr(r){let e=r.toUpperCase();for(let t of["_XLFN._XLWS.","_XLFN.","_XLWS."])if(e.startsWith(t))return e.slice(t.length);return e}function Jn(r){let e=r.trim();if(e.startsWith("=")&&(e=e.slice(1)),e.trim().length===0)throw new ve(le().empty,0);let t=new un(e),n=t.expression();if(t.ws(),t.pos<e.length)throw t.error(le().cannotRead(e[t.pos]));return n}var Xe=new Map,lt=new Map,U=255,M=C;function y(r,e,t,n){Xe.set(r,{min:e,max:t,fn:n})}function to(){return[...Xe.keys(),...lt.keys()].sort()}function no(r){return Xe.has(r.toUpperCase())}function oo(r){let e=r.toUpperCase();return Xe.has(e)||lt.has(e)}function ro(r,e){if(!r||!r.trim())throw new Error("\uD568\uC218 \uC774\uB984\uC774 \uBE44\uC5C8\uC2B5\uB2C8\uB2E4.");if(typeof e!="function")throw new TypeError("\uD568\uC218\uAC00 \uC544\uB2D9\uB2C8\uB2E4.");let t=r.trim().toUpperCase();for(let n of t)if(!zt(n))throw new Error("\uD568\uC218 \uC774\uB984\uC5D0 \uC4F8 \uC218 \uC5C6\uB294 \uAE00\uC790\uC785\uB2C8\uB2E4: "+n);if(Xe.has(t))throw new Error("\uAE30\uBCF8 \uD568\uC218 \uC774\uB984\uC740 \uC4F8 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: "+t);lt.set(t,e),Z()}function io(r){let e=!!r&<.delete(r.trim().toUpperCase());return e&&Z(),e}function so(r,e,t){let n=Xe.get(e);if(n)return t.length<n.min||t.length>n.max?M.Value:n.fn(r,t);let o=lt.get(e);if(!o)return M.Name;let i=t.map(s=>{let l=r.eval(s);if(l instanceof X){if(l.isSingleCell)return l.get(0,0);let a=Math.min(l.rows,1e5),u=Math.min(l.columns,1e3),c=[];for(let h=0;h<a;h++){let d=[];for(let f=0;f<u;f++)d.push(l.get(h,f));c.push(d)}return c}return l});try{return ot(o(i))}catch{return M.Value}}var Se=(r,e)=>e<r.length&&r[e].t!=="empty",Q=(r,e,t)=>t<e.length?r.scalar(e[t]):null;function T(r,e,t,n=0){if(!Se(e,t))return n;let o=r.scalar(e[t]);if(o instanceof C)return o;let i=oe(o);return i===null?M.Value:i}function B(r,e,t,n=""){if(!Se(e,t))return n;let o=r.scalar(e[t]);return o instanceof C?o:se(o)}function at(r,e,t,n=!1){if(!Se(e,t))return n;let o=r.scalar(e[t]);if(o instanceof C)return o;let i=Dt(o);return i===null?M.Value:i}function hn(r){if(r instanceof C||r instanceof Date)return r;if(typeof r=="string"){let t=xe(r);if(t)return t}let e=oe(r);return e===null?M.Value:e<-657435||e>=2958466?M.Number:Ht(e)}var Ce=(r,e,t)=>hn(Q(r,e,t));function re(r,e,t){if(t>=e.length)return null;let n=r.eval(e[t]);return n instanceof X?n:null}function G(...r){for(let e of r)if(e instanceof C)return e;return null}function lo(r,e,t){let n=[];for(let o=t;o<e.length;o++){if(e[o].t==="empty"){n.push(0);continue}let i=r.eval(e[o]);if(i instanceof X)for(let s of i.values()){if(s instanceof C)return s;typeof s=="number"?n.push(s):s instanceof Date&&n.push(ee(s))}else{if(i instanceof C)return i;let s=oe(i);if(s===null)return M.Value;n.push(s)}}return n}function Oe(r,e,t,n){let o=lo(r,e,t);return o instanceof C?o:n(o)}function*dn(r,e,t){for(let n=t;n<e.length;n++){let o=r.eval(e[n]);o instanceof X?yield*o.values():yield o}}var fn=r=>r.reduce((e,t)=>e+t,0),mn=r=>fn(r)/r.length;function Ae(r,e,t){let n=T(r,e,0);return n instanceof C?n:q(t(n))}function or(r,e,t){e=Math.max(-15,Math.min(15,e));let n=Math.pow(10,Math.abs(e)),o=r<0?-1:1,i=e>=0?Math.abs(r)*n:Math.abs(r)/n;i=Number(i.toPrecision(15));let s;t===1?s=Math.ceil(i):t===-1?s=Math.floor(i):s=Math.floor(i+.5);let l=e>=0?s/n:s*n;return o*Number(l.toPrecision(15))+0}function It(r,e,t){let n=T(r,e,0),o=T(r,e,1),i=G(n,o);return i||q(or(n,Math.trunc(o),t))}function $t(r,e,t,n){let o=T(r,e,0);if(o instanceof C)return o;let i=T(r,e,1,n?1:o<0?-1:1);if(i instanceof C)return i;if(i===0||o===0)return 0;if(n)i=Math.abs(i);else if(o>0&&i<0)return M.Number;let s=Math.round(o/i*1e10)/1e10;return q((t?Math.ceil(s):Math.floor(s))*i)}function rr(r,e){let t=[];for(let a of e){let u=r.eval(a);if(u instanceof C)return u;if(u instanceof X)t.push(u);else return M.Value}let n=t[0].rows,o=t[0].columns;if(t.some(a=>a.rows!==n||a.columns!==o))return M.Value;let i=Math.max(...t.map(a=>a.lastRow-a.r1)),s=Math.max(...t.map(a=>a.lastColumn-a.c1)),l=0;for(let a=0;a<=Math.min(n-1,i);a++)for(let u=0;u<=Math.min(o-1,s);u++){let c=1;for(let h of t){let d=h.get(a,u);if(d instanceof C)return d;c*=be(d)?_e(d):0}l+=c}return q(l)}y("SUM",1,U,(r,e)=>Oe(r,e,0,t=>q(fn(t))));y("PRODUCT",1,U,(r,e)=>Oe(r,e,0,t=>t.length===0?0:q(t.reduce((n,o)=>n*o,1))));y("SUMPRODUCT",1,U,rr);y("ABS",1,1,(r,e)=>Ae(r,e,Math.abs));y("INT",1,1,(r,e)=>Ae(r,e,Math.floor));y("SIGN",1,1,(r,e)=>Ae(r,e,t=>Math.sign(t)));y("SQRT",1,1,(r,e)=>Ae(r,e,t=>t<0?NaN:Math.sqrt(t)));y("EXP",1,1,(r,e)=>Ae(r,e,Math.exp));y("LN",1,1,(r,e)=>Ae(r,e,t=>t<=0?NaN:Math.log(t)));y("LOG10",1,1,(r,e)=>Ae(r,e,t=>t<=0?NaN:Math.log10(t)));y("LOG",1,2,(r,e)=>{let t=T(r,e,0),n=T(r,e,1,10),o=G(t,n);return o||(t<=0||n<=0||n===1?M.Number:q(Math.log(t)/Math.log(n)))});y("PI",0,0,()=>Math.PI);y("POWER",2,2,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=G(t,n);return o||(t===0&&n<0?M.DivideByZero:q(Math.pow(t,n)))});y("MOD",2,2,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=G(t,n);return o||(n===0?M.DivideByZero:q(t-n*Math.floor(t/n)))});y("QUOTIENT",2,2,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=G(t,n);return o||(n===0?M.DivideByZero:Math.trunc(t/n))});y("ROUND",2,2,(r,e)=>It(r,e,0));y("ROUNDUP",2,2,(r,e)=>It(r,e,1));y("ROUNDDOWN",2,2,(r,e)=>It(r,e,-1));y("TRUNC",1,2,(r,e)=>It(r,e,-1));y("CEILING",1,2,(r,e)=>$t(r,e,!0,!1));y("FLOOR",1,2,(r,e)=>$t(r,e,!1,!1));y("CEILING.MATH",1,3,(r,e)=>$t(r,e,!0,!0));y("FLOOR.MATH",1,3,(r,e)=>$t(r,e,!1,!0));y("EVEN",1,1,(r,e)=>Ae(r,e,t=>{let n=Math.ceil(Math.abs(t)/2)*2;return t<0?-n:n}));y("ODD",1,1,(r,e)=>Ae(r,e,t=>{let n=Math.ceil((Math.abs(t)-1)/2)*2+1;return t<0?-n:n}));y("RAND",0,0,()=>Math.random());y("RANDBETWEEN",2,2,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=G(t,n);return o||(t=Math.ceil(t),n=Math.floor(n),t>n?M.Number:Math.floor(t+Math.random()*(n-t+1)))});function ir(r){if(r.length===0)return M.Number;r.sort((t,n)=>t-n);let e=r.length>>1;return r.length%2===1?r[e]:(r[e-1]+r[e])/2}function it(r,e,t){let n=r.length;if(n===0||e&&n<2)return M.DivideByZero;let o=mn(r),s=r.reduce((l,a)=>l+(a-o)*(a-o),0)/(e?n-1:n);return q(t?Math.sqrt(s):s)}function sr(r,e){let t=0;for(let n of e){let o=r.eval(n);if(o instanceof X)for(let i of o.values())be(i)&&t++;else!(o instanceof C)&&o!==null&&oe(o)!==null&&t++}return t}function lr(r,e){let t=0;for(let n of e){if(n.t==="empty")continue;let o=r.eval(n);if(o instanceof X)for(let i of o.values())i!==null&&t++;else t++}return t}function ao(r,e,t){let n=lo(r,[e[0]],0);if(n instanceof C)return n;let o=T(r,e,1);if(o instanceof C)return o;let i=Math.ceil(o);return i<1||i>n.length?M.Number:(n.sort((s,l)=>s-l),t?n[n.length-i]:n[i-1])}function uo(r,e){let t=T(r,e,0),n=T(r,e,2),o=G(t,n);if(o)return o;let i=re(r,e,1);if(!i)return M.Value;let s=[];for(let u of i.values())be(u)&&s.push(_e(u));let l=t;return s.some(u=>Ue(u,l))?(n===0?s.filter(u=>u>l&&!Ue(u,l)).length:s.filter(u=>u<l&&!Ue(u,l)).length)+1:M.NotAvailable}function Ne(r,e,t,n){let o,i=[];if(t){let f=n==="COUNT"?0:1;if((e.length-f)%2!==0||e.length-f<2||(o=n==="COUNT"?null:re(r,e,0),n!=="COUNT"&&!o))return M.Value;for(let m=f;m<e.length;m+=2){let p=re(r,e,m);if(!p)return M.Value;let b=Q(r,e,m+1);if(b instanceof C)return b;i.push({range:p,criteria:rt.parse(b)})}}else{let f=re(r,e,0);if(!f)return M.Value;let m=Q(r,e,1);if(m instanceof C)return m;if(i.push({range:f,criteria:rt.parse(m)}),o=n==="COUNT"?null:Se(e,2)?re(r,e,2):f,n!=="COUNT"&&!o)return M.Value}let s=i[0].range.rows,l=i[0].range.columns;if(t&&i.some(f=>f.range.rows!==s||f.range.columns!==l)||t&&o&&(o.rows!==s||o.columns!==l))return M.Value;let a=s;s*l>2e6&&(a=Math.max(...i.map(f=>f.range.lastRow-f.range.r1))+1);let u=0,c=0,h=Number.MAX_VALUE,d=-Number.MAX_VALUE;for(let f=0;f<a;f++)for(let m=0;m<l;m++){if(!i.every(g=>g.criteria.matches(g.range.get(f,m))))continue;if(n==="COUNT"){c++;continue}let p=o.get(f,m);if(p instanceof C)return p;if(!be(p))continue;let b=_e(p);u+=b,c++,h=Math.min(h,b),d=Math.max(d,b)}switch(n){case"COUNT":return c;case"AVERAGE":return c===0?M.DivideByZero:u/c;case"MAX":return c===0?0:d;case"MIN":return c===0?0:h;default:return q(u)}}function ar(r,e){let t=T(r,e,0);if(t instanceof C)return t;let n=Math.trunc(t),o=n%100,i=n>100;if(o<1||o>11)return M.Value;let s=[],l=0;for(let a=1;a<e.length;a++){let u=r.eval(e[a]);if(u instanceof X){let c=u.lastRow,h=u.lastColumn;for(let d=u.r1;d<=c;d++)if(!(i&&u.sheet.isRowHidden(d)))for(let f=u.c1;f<=h;f++){if(u.sheet.isSubtotalCell(d,f))continue;let m=ot(u.sheet.getValue(d,f));if(m instanceof C)return m;m!==null&&l++,be(m)&&s.push(_e(m))}}else{if(u instanceof C)return u;u!==null&&l++;let c=oe(u);c!==null&&s.push(c)}}switch(o){case 1:return s.length===0?M.DivideByZero:mn(s);case 2:return s.length;case 3:return l;case 4:return s.length===0?0:Math.max(...s);case 5:return s.length===0?0:Math.min(...s);case 6:return s.length===0?0:q(s.reduce((a,u)=>a*u,1));case 7:return it(s,!0,!0);case 8:return it(s,!1,!0);case 9:return q(fn(s));case 10:return it(s,!0,!1);default:return it(s,!1,!1)}}y("AVERAGE",1,U,(r,e)=>Oe(r,e,0,t=>t.length===0?M.DivideByZero:mn(t)));y("MIN",1,U,(r,e)=>Oe(r,e,0,t=>t.length===0?0:t.reduce((n,o)=>Math.min(n,o),1/0)));y("MAX",1,U,(r,e)=>Oe(r,e,0,t=>t.length===0?0:t.reduce((n,o)=>Math.max(n,o),-1/0)));y("MEDIAN",1,U,(r,e)=>Oe(r,e,0,ir));y("COUNT",1,U,sr);y("COUNTA",1,U,lr);y("COUNTBLANK",1,1,(r,e)=>{let t=re(r,e,0);if(!t)return M.Value;let n=0;for(let o of t.values())o!==null&&o!==""&&n++;return t.cellCount-n});for(let[r,e,t]of[["STDEV",!0,!0],["STDEV.S",!0,!0],["STDEVP",!1,!0],["STDEV.P",!1,!0],["VAR",!0,!1],["VAR.S",!0,!1],["VARP",!1,!1],["VAR.P",!1,!1]])y(r,1,U,(n,o)=>Oe(n,o,0,i=>it(i,e,t)));y("LARGE",2,2,(r,e)=>ao(r,e,!0));y("SMALL",2,2,(r,e)=>ao(r,e,!1));y("RANK",2,3,uo);y("RANK.EQ",2,3,uo);y("SUMIF",2,3,(r,e)=>Ne(r,e,!1,"SUM"));y("AVERAGEIF",2,3,(r,e)=>Ne(r,e,!1,"AVERAGE"));y("COUNTIF",2,2,(r,e)=>Ne(r,e,!1,"COUNT"));y("SUMIFS",3,U,(r,e)=>Ne(r,e,!0,"SUM"));y("AVERAGEIFS",3,U,(r,e)=>Ne(r,e,!0,"AVERAGE"));y("COUNTIFS",2,U,(r,e)=>Ne(r,e,!0,"COUNT"));y("MAXIFS",3,U,(r,e)=>Ne(r,e,!0,"MAX"));y("MINIFS",3,U,(r,e)=>Ne(r,e,!0,"MIN"));y("SUBTOTAL",2,U,ar);function pn(r,e,t,n){let o=n,i=!1;for(let s of e){let l=r.eval(s);if(l instanceof X)for(let a of l.values()){if(a instanceof C)return a;(typeof a=="boolean"||be(a))&&(o=t(o,Dt(a)),i=!0)}else{if(l instanceof C)return l;let a=Dt(l);if(a===null)return M.Value;o=t(o,a),i=!0}}return i?o:M.Value}y("IF",1,3,(r,e)=>{let t=at(r,e,0);return t instanceof C?t:t?e.length>1?r.eval(e[1]):!0:e.length>2?r.eval(e[2]):!1});y("IFS",2,U,(r,e)=>{if(e.length%2!==0)return M.Value;for(let t=0;t<e.length;t+=2){let n=at(r,e,t);if(n instanceof C)return n;if(n)return r.eval(e[t+1])}return M.NotAvailable});y("IFERROR",2,2,(r,e)=>{let t=r.scalar(e[0]);return t instanceof C?r.eval(e[1]):t});y("IFNA",2,2,(r,e)=>{let t=r.scalar(e[0]);return t===M.NotAvailable?r.eval(e[1]):t});y("SWITCH",3,U,(r,e)=>{let t=Q(r,e,0);if(t instanceof C)return t;let n=1;for(;n+1<e.length;n+=2){let o=Q(r,e,n);if(o instanceof C)return o;if(ge(t,o)===0)return r.eval(e[n+1])}return n<e.length?r.eval(e[n]):M.NotAvailable});y("AND",1,U,(r,e)=>pn(r,e,(t,n)=>t&&n,!0));y("OR",1,U,(r,e)=>pn(r,e,(t,n)=>t||n,!1));y("XOR",1,U,(r,e)=>pn(r,e,(t,n)=>t!==n,!1));y("NOT",1,1,(r,e)=>{let t=at(r,e,0);return t instanceof C?t:!t});y("TRUE",0,0,()=>!0);y("FALSE",0,0,()=>!1);y("NA",0,0,()=>M.NotAvailable);y("ISBLANK",1,1,(r,e)=>Q(r,e,0)===null);y("ISNUMBER",1,1,(r,e)=>be(Q(r,e,0)));y("ISTEXT",1,1,(r,e)=>typeof Q(r,e,0)=="string");y("ISNONTEXT",1,1,(r,e)=>typeof Q(r,e,0)!="string");y("ISLOGICAL",1,1,(r,e)=>typeof Q(r,e,0)=="boolean");y("ISERROR",1,1,(r,e)=>Q(r,e,0)instanceof C);y("ISERR",1,1,(r,e)=>{let t=Q(r,e,0);return t instanceof C&&t!==M.NotAvailable});y("ISNA",1,1,(r,e)=>Q(r,e,0)===M.NotAvailable);y("ISEVEN",1,1,(r,e)=>{let t=T(r,e,0);return t instanceof C?t:Math.abs(Math.trunc(t))%2===0});y("ISODD",1,1,(r,e)=>{let t=T(r,e,0);return t instanceof C?t:Math.abs(Math.trunc(t))%2===1});y("N",1,1,(r,e)=>{let t=Q(r,e,0);return typeof t=="number"||t instanceof C?t:t instanceof Date?ee(t):typeof t=="boolean"&&t?1:0});function co(r,e,t){let n=B(r,e,0),o=B(r,e,1),i=T(r,e,2,1),s=G(n,o,i);if(s)return s;let l=n,a=o,u=i;if(u<1||u>a.length+1)return M.Value;let c=Math.trunc(u)-1,h;if(t&&(l.includes("*")||l.includes("?"))){let d=new RegExp(Ot(l,!1).source,"ig");d.lastIndex=c;let f=d.exec(a);h=f?f.index:-1}else t?h=a.toLocaleLowerCase("ko").indexOf(l.toLocaleLowerCase("ko"),c):h=a.indexOf(l,c);return h<0?M.Value:h+1}y("CONCATENATE",1,U,(r,e)=>{let t="";for(let n=0;n<e.length;n++){let o=B(r,e,n);if(o instanceof C)return o;t+=o}return t});y("CONCAT",1,U,(r,e)=>{let t="";for(let n of dn(r,e,0)){if(n instanceof C)return n;t+=se(n)}return t});y("TEXTJOIN",3,U,(r,e)=>{let t=B(r,e,0),n=at(r,e,1),o=G(t,n);if(o)return o;let i=[];for(let s of dn(r,e,2)){if(s instanceof C)return s;let l=se(s);(!n||l.length>0)&&i.push(l)}return i.join(t)});y("LEFT",1,2,(r,e)=>{let t=B(r,e,0),n=T(r,e,1,1),o=G(t,n);return o||(n<0?M.Value:t.slice(0,Math.trunc(Math.min(t.length,n))))});y("RIGHT",1,2,(r,e)=>{let t=B(r,e,0),n=T(r,e,1,1),o=G(t,n);if(o)return o;if(n<0)return M.Value;let i=Math.trunc(Math.min(t.length,n));return t.slice(t.length-i)});y("MID",3,3,(r,e)=>{let t=B(r,e,0),n=T(r,e,1),o=T(r,e,2),i=G(t,n,o);if(i)return i;let s=t;if(n<1||o<0)return M.Value;let l=Math.trunc(Math.min(s.length,n-1));return s.substr(l,Math.trunc(Math.min(s.length-l,o)))});y("LEN",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.length});y("UPPER",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.toLocaleUpperCase("ko")});y("LOWER",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.toLocaleLowerCase("ko")});y("PROPER",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.toLocaleLowerCase("ko").replace(/(^|[^\p{L}'])(\p{L})/gu,(n,o,i)=>o+i.toLocaleUpperCase("ko"))});y("TRIM",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.split(" ").filter(n=>n.length>0).join(" ")});y("SUBSTITUTE",3,4,(r,e)=>{let t=B(r,e,0),n=B(r,e,1),o=B(r,e,2),i=T(r,e,3,0),s=G(t,n,o,i);if(s)return s;let l=t,a=n;if(a.length===0)return l;if(i<=0)return Se(e,3)?M.Value:l.split(a).join(o);let u=-1;for(let c=0;c<Math.trunc(i);c++)if(u=l.indexOf(a,u+1),u<0)return l;return l.slice(0,u)+o+l.slice(u+a.length)});y("REPLACE",4,4,(r,e)=>{let t=B(r,e,0),n=T(r,e,1),o=T(r,e,2),i=B(r,e,3),s=G(t,n,o,i);if(s)return s;let l=t;if(n<1||o<0)return M.Value;let a=Math.trunc(Math.min(l.length,n-1)),u=Math.trunc(Math.min(l.length-a,o));return l.slice(0,a)+i+l.slice(a+u)});y("FIND",2,3,(r,e)=>co(r,e,!1));y("SEARCH",2,3,(r,e)=>co(r,e,!0));y("REPT",2,2,(r,e)=>{let t=B(r,e,0),n=T(r,e,1),o=G(t,n);return o||(n<0||t.length*n>32767?M.Value:t.repeat(Math.trunc(n)))});y("EXACT",2,2,(r,e)=>{var o;let t=B(r,e,0),n=B(r,e,1);return(o=G(t,n))!=null?o:t===n});y("VALUE",1,1,(r,e)=>{let t=Q(r,e,0);if(t instanceof C)return t;if(typeof t=="string"&&t.trim().endsWith("%")){let o=Be(t.trim().replace(/%+$/,""));if(o!==null)return o/100}let n=oe(t);return n===null?M.Value:n});y("TEXT",2,2,(r,e)=>{let t=Q(r,e,0),n=B(r,e,1);return t instanceof C?t:n instanceof C?n:ur(t,n)});y("CHAR",1,1,(r,e)=>{let t=T(r,e,0);return t instanceof C?t:t<1||t>65535?M.Value:String.fromCharCode(Math.trunc(t))});y("UNICHAR",1,1,(r,e)=>{let t=T(r,e,0);return t instanceof C?t:t<1||t>1114111?M.Value:String.fromCodePoint(Math.trunc(t))});y("CODE",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.length===0?M.Value:t.charCodeAt(0)});y("UNICODE",1,1,(r,e)=>{let t=B(r,e,0);return t instanceof C?t:t.length===0?M.Value:t.codePointAt(0)});y("T",1,1,(r,e)=>{let t=Q(r,e,0);return typeof t=="string"||t instanceof C?t:""});function ur(r,e){if(typeof r=="string"&&Be(r)===null)return r;let t=cr(e);if(!t)return se(r);if(t.isDate){let o=hn(r);return o instanceof C?o:Et(o,t.format)}let n=oe(r);return n===null?M.Value:Rt(n,t.format)}function cr(r){var s;if(!r||r.toUpperCase()==="GENERAL"||r==="@")return null;let e=r.replace(/"[^"]*"/g,"").replace(/\\./g,"").replace(/\[[^\]]*\]/g,"");if(!(/[ydhs]/i.test(e)||/m/i.test(e)&&!/[#0?]/.test(e)))return{format:r,isDate:!1};let n=/AM\/PM|A\/P/i.test(e),o=(s=r.match(/"[^"]*"|\\.|\[[^\]]*\]|AM\/PM|A\/P|y+|m+|d+|h+|s+|[^"\\[ymdhsAa]+|./gi))!=null?s:[],i=[];for(let l=0;l<o.length;l++){let a=o[l],u=a.toLowerCase();if(a[0]==='"')i.push(a);else if(a[0]==="\\")i.push(`"${a.slice(1)}"`);else{if(a[0]==="[")continue;if(/^(am\/pm|a\/p)$/i.test(a))i.push("tt");else if(u[0]==="y")i.push(a.length<=2?"yy":"yyyy");else if(u[0]==="d")i.push(a.length===1?"d":"dd");else if(u[0]==="h")i.push(n?a.length===1?"h":"hh":a.length===1?"H":"HH");else if(u[0]==="s")i.push(a.length===1?"s":"ss");else if(u[0]==="m"){let c=hr(o,l),h=dr(o,l),d=c&&/^h/i.test(c)||h&&/^s/i.test(h);i.push(d?"mm":a.length===1?"M":"MM")}else i.push(/[a-zA-Z]/.test(a)?`"${a}"`:a)}}return{format:i.join(""),isDate:!0}}function hr(r,e){for(let t=e-1;t>=0;t--)if(/^[ymdhs]/i.test(r[t]))return r[t];return null}function dr(r,e){for(let t=e+1;t<r.length;t++)if(/^[ymdhs]/i.test(r[t]))return r[t];return null}function je(r,e){let t=r.getFullYear(),n=r.getMonth()+e,o=new Date(2e3,0,1,r.getHours(),r.getMinutes(),r.getSeconds(),r.getMilliseconds());o.setFullYear(t,n,1);let i=new Date(o.getFullYear(),o.getMonth()+1,0).getDate();return o.setDate(Math.min(r.getDate(),i)),o}function st(r){let e=new Date(2e3,0,1);return e.setFullYear(r.getFullYear(),r.getMonth(),r.getDate()),e}var gn=r=>r.getFullYear()>=1&&r.getFullYear()<=9999;function Ye(r,e,t){let n=Ce(r,e,0);return n instanceof C?n:t(n)}y("TODAY",0,0,()=>st(new Date));y("NOW",0,0,()=>new Date);y("DATE",3,3,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=T(r,e,2),i=G(t,n,o);if(i)return i;let s=Math.trunc(t);if(s<1900&&s>=0&&(s+=1900),s<1||s>9999)return M.Number;let l=new Date(2e3,0,1);l.setFullYear(s,0,1);let a=je(l,Math.trunc(n)-1);return a.setDate(a.getDate()+Math.trunc(o)-1),gn(a)?a:M.Number});y("TIME",3,3,(r,e)=>{let t=T(r,e,0),n=T(r,e,1),o=T(r,e,2),i=G(t,n,o);if(i)return i;let s=Math.trunc(t)*3600+Math.trunc(n)*60+Math.trunc(o);return s<0?M.Number:s%86400/86400});y("YEAR",1,1,(r,e)=>Ye(r,e,t=>t.getFullYear()));y("MONTH",1,1,(r,e)=>Ye(r,e,t=>t.getMonth()+1));y("DAY",1,1,(r,e)=>Ye(r,e,t=>t.getDate()));y("HOUR",1,1,(r,e)=>Ye(r,e,t=>t.getHours()));y("MINUTE",1,1,(r,e)=>Ye(r,e,t=>t.getMinutes()));y("SECOND",1,1,(r,e)=>Ye(r,e,t=>t.getSeconds()));y("WEEKDAY",1,2,(r,e)=>{let t=Ce(r,e,0),n=T(r,e,1,1),o=G(t,n);if(o)return o;let i=t.getDay();switch(Math.trunc(n)){case 1:return i+1;case 2:return(i+6)%7+1;case 3:return(i+6)%7;default:return M.Number}});y("EDATE",2,2,(r,e)=>{let t=Ce(r,e,0),n=T(r,e,1),o=G(t,n);if(o)return o;let i=je(st(t),Math.trunc(n));return gn(i)?i:M.Number});y("EOMONTH",2,2,(r,e)=>{let t=Ce(r,e,0),n=T(r,e,1),o=G(t,n);if(o)return o;let i=new Date(2e3,0,1);i.setFullYear(t.getFullYear(),t.getMonth(),1);let s=je(i,Math.trunc(n)+1);return s.setDate(s.getDate()-1),gn(s)?s:M.Number});y("DAYS",2,2,(r,e)=>{var o;let t=Ce(r,e,0),n=Ce(r,e,1);return(o=G(t,n))!=null?o:Math.trunc(ee(t))-Math.trunc(ee(n))});y("DATEDIF",3,3,(r,e)=>{let t=Ce(r,e,0),n=Ce(r,e,1),o=B(r,e,2),i=G(t,n,o);if(i)return i;let s=st(t),l=st(n);if(s>l)return M.Number;let a=(l.getFullYear()-s.getFullYear())*12+l.getMonth()-s.getMonth()-(l.getDate()<s.getDate()?1:0),u=(c,h)=>Math.round(ee(c)-ee(h));switch(o.toUpperCase()){case"Y":return Math.trunc(a/12);case"M":return a;case"D":return u(l,s);case"YM":return a%12;case"MD":return u(l,je(s,a));case"YD":{let c=je(s,(l.getFullYear()-s.getFullYear())*12);return c>l&&(c=je(c,-12)),u(l,c)}default:return M.Number}});y("DATEVALUE",1,1,(r,e)=>{let t=B(r,e,0);if(t instanceof C)return t;let n=xe(t);return n?st(n):M.Value});y("NETWORKDAYS",2,3,(r,e)=>{let t=Ce(r,e,0),n=Ce(r,e,1),o=G(t,n);if(o)return o;let i=new Set;if(Se(e,2))for(let c of[...dn(r,e,2)]){if(c===null)continue;let h=hn(c);h instanceof C||i.add(Math.floor(ee(h)))}let s=Math.floor(ee(t)),l=Math.floor(ee(n)),a=1;s>l&&([s,l]=[l,s],a=-1);let u=0;for(let c=s;c<=l;c++){let h=((c+6)%7+7)%7;!(h===0||h===6)&&!i.has(c)&&u++}return a*u});function eo(r,e){let t=be(r),n=be(e);return t||n?t&&n:typeof r==typeof e&&r instanceof C==e instanceof C}function bn(r,e,t,n){if(n===0){let i=typeof t=="string"&&(t.includes("*")||t.includes("?"))?Ot(t):null;for(let s=0;s<r;s++){let l=e(s);if(i){if(typeof l=="string"&&i.test(l))return s}else if(l!==null&&eo(l,t)&&ge(l,t)===0)return s}return-1}let o=-1;for(let i=0;i<r;i++){let s=e(i);if(s===null||!eo(s,t))continue;let l=ge(s,t);if(n>0)if(l<=0)o=i;else break;else if(l>=0)o=i;else break}return o}function ho(r,e,t){let n=Q(r,e,0);if(n instanceof C)return n;let o=re(r,e,1),i=T(r,e,2),s=at(r,e,3,!0),l=G(i,s);if(l)return l;if(!o)return M.NotAvailable;let a=Math.trunc(i);if(a<1)return M.Value;if(a>(t?o.columns:o.rows))return M.Reference;let u=t?Math.min(o.rows,o.lastRow-o.r1+1):Math.min(o.columns,o.lastColumn-o.c1+1),c=bn(u,h=>t?o.get(h,0):o.get(0,h),n,s?1:0);return c<0?M.NotAvailable:t?o.get(c,a-1):o.get(a-1,c)}y("VLOOKUP",3,4,(r,e)=>ho(r,e,!0));y("HLOOKUP",3,4,(r,e)=>ho(r,e,!1));y("MATCH",2,3,(r,e)=>{let t=Q(r,e,0);if(t instanceof C)return t;let n=re(r,e,1),o=T(r,e,2,1);if(o instanceof C)return o;if(!n||n.rows>1&&n.columns>1)return M.NotAvailable;let i=n.columns===1,s=i?Math.min(n.rows,n.lastRow-n.r1+1):Math.min(n.columns,n.lastColumn-n.c1+1),l=bn(s,a=>i?n.get(a,0):n.get(0,a),t,Math.sign(o));return l<0?M.NotAvailable:l+1});y("XLOOKUP",3,4,(r,e)=>{let t=Q(r,e,0);if(t instanceof C)return t;let n=re(r,e,1),o=re(r,e,2);if(!n||!o||n.rows>1&&n.columns>1)return M.Value;let i=n.columns===1,s=i?Math.min(n.rows,n.lastRow-n.r1+1):Math.min(n.columns,n.lastColumn-n.c1+1),l=bn(s,a=>i?n.get(a,0):n.get(0,a),t,0);return l<0?Se(e,3)?r.scalar(e[3]):M.NotAvailable:i?o.get(l,0):o.get(0,l)});y("INDEX",2,3,(r,e)=>{let t=re(r,e,0),n=T(r,e,1),o=T(r,e,2,0),i=G(n,o);if(i)return i;if(!t)return M.Value;let s=Math.trunc(n),l=Math.trunc(o);return!Se(e,2)&&t.rows===1&&(l=s,s=1),s<0||l<0||s>t.rows||l>t.columns?M.Reference:s===0&&l===0?t:s===0?new X(t.sheet,t.r1,t.c1+l-1,t.r2,t.c1+l-1):l===0?t.columns===1?t.get(s-1,0):new X(t.sheet,t.r1+s-1,t.c1,t.r1+s-1,t.c2):t.get(s-1,l-1)});y("CHOOSE",2,U,(r,e)=>{let t=T(r,e,0);if(t instanceof C)return t;let n=Math.trunc(t);return n<1||n>=e.length?M.Value:r.eval(e[n])});y("ROW",0,1,(r,e)=>{if(!Se(e,0))return r.row+1;let t=re(r,e,0);return t?t.r1+1:M.Value});y("COLUMN",0,1,(r,e)=>{if(!Se(e,0))return r.col+1;let t=re(r,e,0);return t?t.c1+1:M.Value});y("ROWS",1,1,(r,e)=>{var t,n;return(n=(t=re(r,e,0))==null?void 0:t.rows)!=null?n:1});y("COLUMNS",1,1,(r,e)=>{var t,n;return(n=(t=re(r,e,0))==null?void 0:t.columns)!=null?n:1});var ut=1;function Z(){ut++}var fr=150,Pt=0,ct=class{constructor(e){this.item=e}};function yn(r,e,t,n){if(r.cacheVersion===ut)return r.cached;if(r.evaluating)return C.Circular;if(Pt>0){if(Pt>=fr)throw new ct({f:r,sheet:e,row:t,col:n});return fo(r,e,t,n)}let o=[{f:r,sheet:e,row:t,col:n}];for(;o.length;){let i=o[o.length-1];if(i.f.cacheVersion===ut){o.pop();continue}try{fo(i.f,i.sheet,i.row,i.col),o.pop()}catch(s){if(!(s instanceof ct))throw s;o.some(l=>l.f===s.item.f)?(s.item.f.cached=C.Circular,s.item.f.cacheVersion=ut):o.push(s.item)}}return r.cached}function fo(r,e,t,n){r.evaluating=!0,Pt++;let o;try{let i=new wn(e,t,n);o=Qn(i.deref(i.eval(r.root)))}catch(i){if(i instanceof ct||i instanceof RangeError&&/call stack/i.test(i.message))throw i;o=C.Value}finally{r.evaluating=!1,Pt--}return r.cached=o,r.cacheVersion=ut,o}var wn=class{constructor(e,t,n){this.sheet=e;this.row=t;this.col=n}eval(e){switch(e.t){case"lit":return e.value;case"empty":return null;case"paren":return this.eval(e.inner);case"ref":{if(e.invalid)return C.Reference;let t=this.sheet.findSheet(e.sheet);return t?new X(t,e.row,e.col,e.row,e.col):C.Reference}case"area":{if(e.invalid)return C.Reference;let t=this.sheet.findSheet(e.sheet);return t?e.kind==="columns"?new X(t,0,e.c1,Math.max(0,t.rowCount-1),e.c2):e.kind==="rows"?new X(t,e.r1,0,e.r2,Math.max(0,t.columnCount-1)):new X(t,e.r1,e.c1,e.r2,e.c2):C.Reference}case"unary":{let t=this.scalar(e.operand);if(e.op==="+"||t instanceof C)return t;let n=oe(t);return n===null?C.Value:-n}case"pct":{let t=this.scalar(e.operand);if(t instanceof C)return t;let n=oe(t);return n===null?C.Value:n/100}case"bin":return mr(e.op,this.scalar(e.left),this.scalar(e.right));case"func":return so(this,e.name,e.args);case"name":return C.Name}}scalar(e){return this.deref(this.eval(e))}deref(e){return e instanceof X?e.isSingleCell?e.get(0,0):e.c1===e.c2&&e.sheet===this.sheet&&this.row>=e.r1&&this.row<=e.r2?e.get(this.row-e.r1,0):e.r1===e.r2&&e.sheet===this.sheet&&this.col>=e.c1&&this.col<=e.c2?e.get(0,this.col-e.c1):C.Value:e}};function mr(r,e,t){if(e instanceof C)return e;if(t instanceof C)return t;switch(r){case"&":return se(e)+se(t);case"=":return ge(e,t)===0;case"<>":return ge(e,t)!==0;case"<":return ge(e,t)<0;case">":return ge(e,t)>0;case"<=":return ge(e,t)<=0;case">=":return ge(e,t)>=0}let n=oe(e),o=oe(t);if(n===null||o===null)return C.Value;let i=e instanceof Date,s=t instanceof Date;switch(r){case"+":return i!==s?an(n+o):q(n+o);case"-":return i&&!s?an(n-o):q(n-o);case"*":return q(n*o);case"/":return o===0?C.DivideByZero:q(n/o);case"^":return n===0&&o===0?C.Number:n===0&&o<0?C.DivideByZero:q(Math.pow(n,o));default:return C.Value}}function Me(r){let e="";for(r++;r>0;){let t=(r-1)%26;e=String.fromCharCode(65+t)+e,r=Math.floor((r-1)/26)}return e}function ze(r,e){return Me(e)+(r+1)}function mo(r){let e=[];return Le(e,r),e.join("")}function Le(r,e){switch(e.t){case"lit":r.push(pr(e.value));return;case"empty":return;case"paren":r.push("("),Le(r,e.inner),r.push(")");return;case"unary":r.push(e.op),Le(r,e.operand);return;case"pct":Le(r,e.operand),r.push("%");return;case"bin":Le(r,e.left),r.push(e.op),Le(r,e.right);return;case"func":r.push(e.name,"("),e.args.forEach((t,n)=>{n>0&&r.push(","),Le(r,t)}),r.push(")");return;case"name":r.push(e.name);return;case"ref":gr(r,e);return;case"area":br(r,e)}}function pr(r){return typeof r=="number"?String(r).replace("e+","E+").replace("e-","E-"):typeof r=="boolean"?r?"TRUE":"FALSE":typeof r=="string"?`"${r.replace(/"/g,'""')}"`:r.code}function gr(r,e){if(po(r,e.sheet),e.invalid){r.push("#REF!");return}r.push((e.colAbs?"$":"")+Me(e.col)+(e.rowAbs?"$":"")+(e.row+1))}function br(r,e){if(po(r,e.sheet),e.invalid){r.push("#REF!");return}let t=(o,i)=>(i?"$":"")+Me(o),n=(o,i)=>(i?"$":"")+(o+1);e.kind==="columns"?r.push(t(e.c1,e.c1Abs),":",t(e.c2,e.c2Abs)):e.kind==="rows"?r.push(n(e.r1,e.r1Abs),":",n(e.r2,e.r2Abs)):r.push(t(e.c1,e.c1Abs),n(e.r1,e.r1Abs),":",t(e.c2,e.c2Abs),n(e.r2,e.r2Abs))}function po(r,e){e&&(wr(e)?r.push(`'${e.replace(/'/g,"''")}'!`):r.push(e,"!"))}function wr(r){if(!Lt(r[0])||r[0]==="\\")return!0;for(let n of r)if(!/[\p{L}\p{Nd}_.]/u.test(n))return!0;let e=0;for(;e<r.length&&cn(r[e]);)e++;if(e>0&&e<=3&&e<r.length&&/^\d+$/.test(r.slice(e)))return!0;let t=r.toUpperCase();return t==="TRUE"||t==="FALSE"}var he=class r{constructor(e){this.root=e;this.cached=null;this.cacheVersion=-1;this.evaluating=!1;this._text=null}static parse(e){return new r(Jn(e))}static tryParse(e){if(!e||!e.trim())return null;try{return r.parse(e)}catch(t){if(t instanceof ve)return null;throw t}}get text(){var e;return(e=this._text)!=null?e:this._text=mo(this.root)}toString(){return"="+this.text}clone(){return new r(Fe(this.root))}evaluate(e,t,n){return yn(this,e,t,n)}evaluateOnce(e,t,n){return this.cacheVersion=-1,yn(this,e,t,n)}static get functionNames(){return to()}static registerFunction(e,t){ro(e,t)}static unregisterFunction(e){return io(e)}static isFunctionDefined(e){return oo(e)}static invalidate(){Z()}changed(){this._text=null,this.cacheVersion=-1}done(e){return e&&this.changed(),e}insertRows(e,t,n){let o=!1;for(let i of Te(this.root))i.t==="ref"&&!i.invalid&&e(i.sheet)?i.row>=t&&(i.row+=n,o=!0):i.t==="area"&&!i.invalid&&i.kind!=="columns"&&e(i.sheet)&&(i.r1>=t&&(i.r1+=n,o=!0),i.r2>=t&&(i.r2+=n,o=!0));return this.done(o)}removeRows(e,t,n){let o=t+n,i=!1;for(let s of Te(this.root))if(s.t==="ref"&&!s.invalid&&e(s.sheet))s.row>=t&&s.row<o?(s.invalid=!0,i=!0):s.row>=o&&(s.row-=n,i=!0);else if(s.t==="area"&&!s.invalid&&s.kind!=="columns"&&e(s.sheet)){let l=s.r1<t?s.r1:s.r1>=o?s.r1-n:t,a=s.r2<t?s.r2:s.r2>=o?s.r2-n:t-1;a<l?(s.invalid=!0,i=!0):(l!==s.r1||a!==s.r2)&&(s.r1=l,s.r2=a,i=!0)}return this.done(i)}remapColumns(e,t){let n=!1;for(let o of Te(this.root))if(o.t==="ref"&&!o.invalid&&e(o.sheet)){let i=t(o.col);i<0?(o.invalid=!0,n=!0):i!==o.col&&(o.col=i,n=!0)}else if(o.t==="area"&&!o.invalid&&o.kind!=="rows"&&e(o.sheet)){let i=-1;for(let l=o.c1;l<=o.c2&&i<0;l++)i=t(l);let s=-1;for(let l=o.c2;l>=o.c1&&s<0;l--)s=t(l);i<0||s<0?(o.invalid=!0,n=!0):(i!==o.c1||s!==o.c2)&&(o.c1=i,o.c2=s,De(o),n=!0)}return this.done(n)}offset(e,t){if(e===0&&t===0)return!1;let n=!1;for(let o of Te(this.root))if(o.t==="ref"&&!o.invalid){let i=o.rowAbs?o.row:o.row+e,s=o.colAbs?o.col:o.col+t;i<0||s<0?o.invalid=!0:(o.row=i,o.col=s),n=!0}else o.t==="area"&&!o.invalid&&(o.kind!=="columns"&&(o.r1=o.r1Abs?o.r1:o.r1+e,o.r2=o.r2Abs?o.r2:o.r2+e),o.kind!=="rows"&&(o.c1=o.c1Abs?o.c1:o.c1+t,o.c2=o.c2Abs?o.c2:o.c2+t),o.r1<0||o.r2<0||o.c1<0||o.c2<0?o.invalid=!0:De(o),n=!0);return this.done(n)}mapSheets(e){let t=!1;for(let n of Te(this.root))if((n.t==="ref"||n.t==="area")&&n.sheet!==null){let o=e(n.sheet);o!==n.sheet&&(n.sheet=o,t=!0)}return this.done(t)}get isSubtotal(){for(let e of Te(this.root))if(e.t==="func"&&e.name==="SUBTOTAL")return!0;return!1}get isFullySupported(){for(let e of Te(this.root))if((e.t==="ref"||e.t==="area")&&e.invalid||e.t==="name"||e.t==="func"&&!no(e.name)||e.t==="lit"&&e.value===C.Circular)return!1;return!0}};var Gt=7,yr={sum:9,count:3,average:1,max:4,min:5},xr=(r,e)=>{var t,n;return(n=(t=r.rows[e])==null?void 0:t.outline)!=null?n:0};function bo(r){var s,l;let e=r.rows.length,t=[],n=0,o=new Array(Gt+2).fill(-1);for(let a=0;a<=e;a++){let u=a<e?xr(r,a):0;u>n&&(n=u);for(let c=Gt;c>=1;c--)if(o[c]>=0&&u<c){let h=o[c],d=a-1,f=d+1<e?d+1:h-1;t.push({level:c,start:h,end:d,summary:f,collapsed:!!(((l=(s=r.rows[h])==null?void 0:s.collapsed)!=null?l:0)&1<<c)}),o[c]=-1}for(let c=1;c<=u;c++)o[c]<0&&(o[c]=a)}let i=new Uint8Array(e);for(let a of t)if(a.collapsed)for(let u=a.start;u<=a.end;u++)i[u]=1;for(let a=0;a<e;a++){let u=r.rows[a];i[a]?u?u.outlineHidden=!0:r.row(a,!0).outlineHidden=!0:u!=null&&u.outlineHidden&&(u.outlineHidden=!1)}t.sort((a,u)=>a.start-u.start||a.level-u.level),r.outlineGroups=t,r.outlineLevels=n}function qe(r,e,t,n){var u;let o=Math.max(0,Math.min(e,t)),i=Math.min(r.rows.length-1,Math.max(e,t)),s=[];for(let c=o;c<=i;c++){let h=r.row(c,!0);s.push([h,h.outline,h.collapsed]);let d=Math.max(0,Math.min(Gt,((u=h.outline)!=null?u:0)+n));h.outline=d||void 0}let l=s.map(([c])=>[c,c.outline,c.collapsed]);r.hasOutline=!0;let a=c=>{for(let[h,d,f]of c)h.outline=d,h.collapsed=f;r.layoutChanged()};r.undo.push({undo:()=>a(s),redo:()=>a(l)}),r.layoutChanged()}function xn(r,e,t){let n=null;for(let o of r.outlineGroups)t!==void 0&&o.level!==t||(e>=o.start&&e<=o.end||o.summary===e)&&(!n||o.level>n.level)&&(n=o);return n}function Wt(r,e,t){var i,s;let n=r.row(e.start,!0),o=1<<e.level;n.collapsed=t?((i=n.collapsed)!=null?i:0)|o:((s=n.collapsed)!=null?s:0)&~o,r.layoutChanged()}function wo(r,e){var t,n;for(let o of r.outlineGroups){let i=r.row(o.start,!0),s=1<<o.level;i.collapsed=o.level>=e?((t=i.collapsed)!=null?t:0)|s:((n=i.collapsed)!=null?n:0)&~s}r.layoutChanged()}function yo(r,e){var s;let t=(s=e.function)!=null?s:"sum",n=yr[t],o=N().subtotal[t],i=0;return r.undo.transaction(()=>{var h,d,f,m;let l=[],a=0;for(;a<r.rowCount;){if((h=r.rows[a])!=null&&h.subtotal){a++;continue}let p=r.getValue(a,e.groupBy),b=a;for(;b+1<r.rowCount&&!((d=r.rows[b+1])!=null&&d.subtotal)&&vr(r.getValue(b+1,e.groupBy),p);)b++;l.push({start:a,end:b,value:p}),a=b+1}let u=l.length?l[0].start:0,c=l.length?l[l.length-1].end:-1;for(let p=l.length-1;p>=0;p--){let b=l[p],g=b.end+1;r.insertRows(g,1,!0),c++,go(r,g,b.start,b.end,e,n,N().subtotalLabel(String((f=b.value)!=null?f:""),o)),qe(r,b.start,b.end,1),i++}if(((m=e.grandTotal)==null||m)&&l.length){let p=c+1;r.insertRows(p,1,!0),go(r,p,u,c,e,n,N().grandTotal(o)),qe(r,u,c,1),i++}r.hasOutline=!0}),r.layoutChanged(),i}function go(r,e,t,n,o,i,s){var c,h;let l=r.row(e,!0);l.subtotal=!0,r.setValue(e,o.groupBy,s);for(let d of o.columns){let f=Me(d);r.setFormula(e,d,he.parse(`=SUBTOTAL(${i},${f}${t+1}:${f}${n+1})`))}let a={bold:(c=o.bold)!=null?c:!0,backColor:(h=o.backColor)!=null?h:void 0};for(let d=0;d<r.columns.length;d++)r.setCellStyle(e,d,a);let u=l.subtotal;r.undo.push({undo:()=>l.subtotal=void 0,redo:()=>l.subtotal=u})}function vr(r,e){if(r instanceof Date&&e instanceof Date)return r.getTime()===e.getTime();let t=r==null||r==="",n=e==null||e==="";return t&&n?!0:r===e}function xo(r){let e=0;return r.undo.transaction(()=>{var t,n,o;for(let i=r.rowCount-1;i>=0;i--)(t=r.rows[i])!=null&&t.subtotal&&(r.removeRows(i,1),e++);for(let i=0;i<Gt;i++){let s=!1;for(let l=0;l<r.rowCount;l++)((o=(n=r.rows[l])==null?void 0:n.outline)!=null?o:0)>0&&(s=!0);if(!s)break;qe(r,0,r.rowCount-1,-1)}for(let i=0;i<r.rowCount;i++){let s=r.rows[i];s!=null&&s.collapsed&&(s.collapsed=void 0)}}),r.layoutChanged(),e}var Cr=1;function Sr(r){return r?(Array.isArray(r)?r:r.split("|")).map(t=>String(t).trim()).filter(t=>t.length>0):[]}var we=class r{constructor(e={}){this.id=Cr++;var t,n,o,i,s,l,a,u,c,h,d,f,m,p,b,g,w,S,v,k,R,D,z,_;this.name=(n=(t=e.name)!=null?t:e.field)!=null?n:"",this.header=(s=(i=(o=e.header)!=null?o:e.name)!=null?i:e.field)!=null?s:"",this.field=e.field,this.kind=(l=e.kind)!=null?l:"text",this.width=(a=e.width)!=null?a:this.kind==="check"?60:100,this.minWidth=(u=e.minWidth)!=null?u:16,this.visible=(c=e.visible)!=null?c:!0,this.readOnly=(h=e.readOnly)!=null?h:this.kind==="label",this.sortable=(d=e.sortable)!=null?d:!["check","combo","button","image","progress"].includes(this.kind),this.sortCompare=e.sortCompare,this.sortValue=e.sortValue,this.fillWeight=Math.max(0,(f=e.fillWeight)!=null?f:0),this.emptyText=e.emptyText,this.clickable=typeof e.clickable=="function"?e.clickable:!!e.clickable,this.headerToolTip=e.headerToolTip,this.headerCheckBox=!!e.headerCheckBox&&e.kind==="check",this.toolTip=e.toolTip,this.resizable=(m=e.resizable)!=null?m:!0,this.filterable=(p=e.filterable)!=null?p:!0,this.format=e.format,this.align=(b=e.align)!=null?b:"general",this.verticalAlignment=(g=e.verticalAlignment)!=null?g:"middle",this.wrapText=(w=e.wrapText)!=null?w:!1,this.backColor=e.backColor,this.foreColor=e.foreColor,this.bold=(S=e.bold)!=null?S:!1,this.mergeMode=(v=e.mergeMode)!=null?v:"none",this.items=((k=e.items)!=null?k:[]).map(P=>typeof P=="string"?{value:P,text:P}:P),this.buttonText=e.buttonText,this.images=e.images,this.maximum=(R=e.maximum)!=null?R:e.kind==="progress"?100:void 0,this.required=(D=e.required)!=null?D:!1,this.minimum=e.minimum,this.maxLength=e.maxLength,this.pattern=e.pattern,this.valueList=e.valueList,this.validationMessage=e.validationMessage,this.group=Sr(e.group),this.footer=(z=e.footer)!=null?z:"none",this.footerText=(_=e.footerText)!=null?_:"",this.footerFormat=e.footerFormat,this.tag=e.tag}update(e){let t=new r(e),n=this,o=this.width;for(let i of Object.keys(t))i!=="id"&&(n[i]=t[i]);e.width===void 0&&(this.width=o)}effectiveAlign(e,t){let n=t!=null&&t.align&&t.align!=="general"?t.align:this.align;return n!=="general"?n:this.kind==="check"||this.kind==="button"||this.kind==="image"?"center":typeof e=="number"||ye(e)?"right":"left"}parse(e){var n;let t=e;switch(this.kind){case"number":case"progress":{if(t.trim()==="")return null;let o=sn(t);return o===null?void 0:o}case"date":{if(t.trim()==="")return null;let o=xe(t);return o===null?void 0:o}case"check":{let o=t.trim().toLowerCase();return!(o===""||o==="false"||o==="0"||o==="n")}case"combo":{let o=(n=this.items.find(i=>i.text===t))!=null?n:this.items.find(i=>String(i.value)===t);return o?o.value:t}default:return t}}text(e,t){var n,o,i;if(this.kind==="check")return e?"TRUE":"FALSE";if(this.kind==="date"&&typeof e=="string"&&e!==""){let s=xe(e);if(s)return ke(s,(o=(n=t==null?void 0:t.format)!=null?n:this.format)!=null?o:/[ T]\d/.test(e)?"yyyy-MM-dd HH:mm":"yyyy-MM-dd")}if(this.kind==="combo"){let s=this.items.find(l=>Re(l.value,e));if(s)return s.text}return ke(e,(i=t==null?void 0:t.format)!=null?i:this.format)}},ht=class{},Ut=class{constructor(e,t,n){this.count=e;this.size=t;this.visible=n;this.order=new Int32Array(0);this.offsets=new Float64Array(1);this.dirty=!0}invalidate(){this.dirty=!0}ensure(){if(!this.dirty)return;this.dirty=!1;let e=this.count(),t=new Int32Array(e),n=0;for(let i=0;i<e;i++)this.visible(i)&&(t[n++]=i);this.order=t.subarray(0,n);let o=new Float64Array(n+1);for(let i=0;i<n;i++)o[i+1]=o[i]+this.size(this.order[i]);this.offsets=o}get visibleCount(){return this.ensure(),this.order.length}physical(e){return this.ensure(),this.order[e]}visual(e){this.ensure();let t=0,n=this.order.length-1;for(;t<=n;){let o=t+n>>1,i=this.order[o];if(i===e)return o;i<e?t=o+1:n=o-1}return-(t+1)}offset(e){return this.ensure(),this.offsets[Math.max(0,Math.min(e,this.order.length))]}sizeAt(e){return this.offset(e+1)-this.offset(e)}get total(){return this.ensure(),this.offsets[this.order.length]}indexAt(e){this.ensure();let t=this.order.length;if(t===0)return-1;if(e<=0)return 0;if(e>=this.offsets[t])return t-1;let n=0,o=t-1;for(;n<o;){let i=n+o+1>>1;this.offsets[i]<=e?n=i:o=i-1}return n}step(e,t){let n=this.visibleCount;if(n===0)return e;let o=this.visual(e);return o<0&&(o=Math.min(-o-1,n-1)),this.physical(Math.max(0,Math.min(n-1,o+t)))}},dt=class{constructor(){this.columns=[];this.rows=[];this.merges=[];this.filters=new Map;this.sortSpecs=[];this.defaultRowHeight=26;this.data=null;this.source=null;this.undo=new Nt;this.onChange=()=>{};this.onValueChanged=()=>{};this.isNestedChange=()=>!1;this.fillExtra=new Map;this.valueSource="code";this.sheetName=null;this.resolveSheet=()=>null;this.hasFormulas=!1;this.hasOutline=!1;this.outlineGroups=[];this.outlineLevels=0;this.quickFilter=null;let e=this;this.formulaSheet={get rowCount(){return e.rows.length},get columnCount(){return e.columns.length},getValue:(t,n)=>t<0||n<0?C.Reference:t>=e.rows.length||n>=e.columns.length?null:e.getValue(t,n),findSheet:t=>!t||e.sheetName&&t.toUpperCase()===e.sheetName.toUpperCase()?e.formulaSheet:e.resolveSheet(t),isSubtotalCell:(t,n)=>{var o;return!!((o=e.formulaAt(t,n))!=null&&o.isSubtotal)},isRowHidden:t=>t>=0&&t<e.rows.length&&!e.isRowVisible(t)},this.rowAxis=new Ut(()=>this.rows.length,t=>{var n,o;return(o=(n=this.rows[t])==null?void 0:n.height)!=null?o:this.defaultRowHeight},t=>{let n=this.rows[t];return!n||!n.hidden&&!n.filtered&&!n.outlineHidden}),this.colAxis=new Ut(()=>this.columns.length,t=>{var n;return this.columns[t].width+((n=this.fillExtra.get(this.columns[t].id))!=null?n:0)},t=>this.columns[t].visible)}get rowCount(){return this.rows.length}set rowCount(e){e=Math.max(0,Math.floor(e));let t=this.rows.length;e!==t&&(e>t?this.insertRows(t,e-t):this.removeRows(e,t-e))}layoutChanged(){Z(),this.hasOutline&&bo(this),this.rowAxis.invalidate(),this.colAxis.invalidate(),this.onChange("layout")}row(e,t=!1){let n=this.rows[e];return!n&&t&&e>=0&&e<this.rows.length&&(n=new ht,this.data&&(n.data=this.data[e]),this.rows[e]=n),n}isClickable(e,t){var o,i,s,l,a;let n=(o=this.columns[t])==null?void 0:o.clickable;return typeof n!="function"?!!n:(i=this.rows[e])!=null&&i.subtotal?!1:!!n((a=(s=this.rows[e])==null?void 0:s.data)!=null?a:(l=this.data)==null?void 0:l[e],e)}rowKeyOf(e){var n,o;let t=this.rows[e];if(!(t!=null&&t.subtotal)){if(this.rowKeyField){let i=(o=t==null?void 0:t.data)!=null?o:(n=this.data)==null?void 0:n[e];if(i)return i[this.rowKeyField]}return t==null?void 0:t.key}}insertRows(e,t,n=!1){if(t<=0)return;e=Math.max(0,Math.min(e,this.rows.length));let o=new Array(t);if(t<=1e4)for(let s=0;s<t;s++)o[s]=new ht;let i=[];if(this.data){i=Array.from({length:t},()=>!n&&this.newRowData?{...this.newRowData()}:{});for(let s=0;s<t;s++){let l=new ht;l.data=i[s],o[s]=l}}this.spliceRows(e,0,o,i,n)}removeRows(e,t){t=Math.min(t,this.rows.length-e),!(t<=0||e<0)&&this.spliceRows(e,t,[],[])}spliceRows(e,t,n,o,i=!1){let s=n.length,l=this.snapshotFormulas(),a=()=>{var S;let f=this.rows.length,m=s>0&&e<f,p=t>0&&e+t<f,b=this.data&&e<this.data.length&&(S=this.data[e+t])!=null?S:null,g=Bt(this.rows,e,t,n),w=this.data?Bt(this.data,e,t,o):[];if(this.data&&(c=this.sourceRemove(w),i||this.sourceInsert(o,b)),this.shiftMerges(e,s-t),this.hasFormulas){let v=this.selfTarget();for(let{cell:k}of this.formulaCells())m&&k.f.insertRows(v,e,s),p&&k.f.removeRows(v,e,t)}return this.layoutChanged(),{removed:g,removedData:w}},u=this.merges.map(f=>({...f})),c=[],{removed:h,removedData:d}=a();this.undo.push({undo:()=>{Bt(this.rows,e,s,h),this.data&&(Bt(this.data,e,s,d),this.sourceRemove(o),this.sourceRestore(c)),this.merges=u.map(f=>({...f})),this.restoreFormulas(l),this.layoutChanged()},redo:()=>{a()}})}shiftMerges(e,t){if(t===0)return;let n=[];for(let o of this.merges){let i=o.row+o.rowSpan;if(t>0)o.row>=e?n.push({...o,row:o.row+t}):i>e?n.push({...o,rowSpan:o.rowSpan+t}):n.push(o);else{let s=e-t;if(i<=e)n.push(o);else if(o.row>=s)n.push({...o,row:o.row+t});else{let l=Math.min(o.row,e),a=o.rowSpan-(Math.min(i,s)-Math.max(o.row,e));a>0&&n.push({...o,row:l,rowSpan:a})}}}this.merges=n.filter(o=>o.rowSpan>0&&o.colSpan>0&&o.rowSpan*o.colSpan>1)}setRowHeight(e,t){let n=this.row(e,!0),o=n.height;o!==t&&(n.height=t,this.undo.push({undo:()=>this.setRowHeight(e,o),redo:()=>this.setRowHeight(e,t)}),this.layoutChanged())}setRowHidden(e,t){let n=this.row(e,!0),o=!!n.hidden;o!==t&&(n.hidden=t,this.undo.push({undo:()=>this.setRowHidden(e,o),redo:()=>this.setRowHidden(e,t)}),this.layoutChanged())}isRowVisible(e){let t=this.rows[e];return!t||!t.hidden&&!t.filtered&&!t.outlineHidden}visibleRows(){let e=[];for(let t=0;t<this.rowCount;t++){let n=this.rows[t];n&&(n.hidden||n.filtered||n.subtotal)||e.push(t)}return e}columnIndex(e){return typeof e=="number"?e>=0&&e<this.columns.length?e:-1:e instanceof we?this.columns.indexOf(e):this.columns.findIndex(t=>t.name===e)}insertColumn(e,t){e=Math.max(0,Math.min(e,this.columns.length));let n=this.snapshotFormulas();this.columns.splice(e,0,t),this.shiftMergeCols(e,1),this.remapFormulaColumns(o=>o>=e?o+1:o),this.undo.push({undo:()=>{let o=this.columns.indexOf(t);o>=0&&this.columns.splice(o,1),this.shiftMergeCols(o,-1),this.restoreFormulas(n),this.layoutChanged()},redo:()=>this.insertColumn(e,t)}),this.layoutChanged()}remapFormulaColumns(e){if(!this.hasFormulas)return;let t=this.selfTarget();for(let{cell:n}of this.formulaCells())n.f.remapColumns(t,e)}removeColumn(e){if(e<0||e>=this.columns.length)return;let t=this.snapshotFormulas(),[n]=this.columns.splice(e,1),o=this.merges.map(i=>({...i}));return this.shiftMergeCols(e,-1),this.remapFormulaColumns(i=>i===e?-1:i>e?i-1:i),this.filters.delete(n.id),this.sortSpecs=this.sortSpecs.filter(i=>i.col!==n),this.undo.push({undo:()=>{this.columns.splice(e,0,n),this.merges=o,this.restoreFormulas(t),this.layoutChanged()},redo:()=>this.removeColumn(e)}),this.layoutChanged(),n}moveColumn(e,t){if(e===t||e<0||e>=this.columns.length)return;t=Math.max(0,Math.min(t,this.columns.length-1));let n=this.columns.slice(),[o]=this.columns.splice(e,1);this.columns.splice(t,0,o),this.remapFormulaColumns(i=>i<n.length?this.columns.indexOf(n[i]):i),this.undo.push({undo:()=>this.moveColumn(t,e),redo:()=>this.moveColumn(e,t)}),this.layoutChanged()}shiftMergeCols(e,t){let n=[];for(let o of this.merges){let i=o.col+o.colSpan;t>0?o.col>=e?n.push({...o,col:o.col+1}):i>e?n.push({...o,colSpan:o.colSpan+1}):n.push(o):i<=e?n.push(o):o.col>e?n.push({...o,col:o.col-1}):o.colSpan>1&&n.push({...o,colSpan:o.colSpan-1})}this.merges=n.filter(o=>o.rowSpan*o.colSpan>1)}setColumnWidth(e,t){let n=this.columns[e];if(!n)return;t=Math.max(n.minWidth,Math.round(t));let o=n.width;o!==t&&(n.width=t,this.undo.push({undo:()=>this.setColumnWidth(this.columns.indexOf(n),o),redo:()=>this.setColumnWidth(this.columns.indexOf(n),t)}),this.layoutChanged())}getValue(e,t){var s;let n=this.columns[t];if(!n)return;let o=this.rows[e];if(!o)return this.data&&n.field&&e>=0&&e<this.data.length?Co(this.data[e][n.field]):void 0;let i=(s=o.cells)==null?void 0:s.get(n.id);return i!=null&&i.f?i.f.evaluate(this.formulaSheet,e,t):n.field&&o.data?Co(o.data[n.field]):i==null?void 0:i.v}formulaAt(e,t){var o,i,s;let n=this.columns[t];return n?(s=(i=(o=this.rows[e])==null?void 0:o.cells)==null?void 0:i.get(n.id))==null?void 0:s.f:void 0}setFormula(e,t,n){var f;let o=this.columns[t];if(!o||e<0||e>=this.rows.length)return!1;let i=this.row(e,!0);(f=i.cells)!=null||(i.cells=new Map);let s=i.cells.get(o.id);s||(s={},i.cells.set(o.id,s));let l=s,a=l.f,u=l.v;if(!n&&!a)return!1;let c=a?a.cacheVersion>=0?a.cached:void 0:o.field&&i.data?i.data[o.field]:u,h=(m,p)=>{l.f=m,l.v=p,m&&(this.hasFormulas=!0),Z(),this.onChange("value")},d=n?void 0:c;return h(n!=null?n:void 0,d),this.undo.push({undo:()=>{let m=this.getValue(e,t);h(a,u),this.onValueChanged(e,t,m,()=>this.getValue(e,t),this.valueSource)},redo:()=>{let m=this.getValue(e,t);h(n!=null?n:void 0,d),this.onValueChanged(e,t,m,()=>this.getValue(e,t),this.valueSource)}}),this.onValueChanged(e,t,c,()=>this.getValue(e,t),this.valueSource),!0}selfTarget(){var t;let e=(t=this.sheetName)==null?void 0:t.toUpperCase();return n=>n===null||!!e&&n.toUpperCase()===e}*formulaCells(){var e;if(this.hasFormulas)for(let t=0;t<this.rows.length;t++){let n=(e=this.rows[t])==null?void 0:e.cells;if(n)for(let[o,i]of n)i.f&&(yield{row:t,cell:i,colId:o})}}snapshotFormulas(){let e=[];for(let{cell:t}of this.formulaCells())e.push({cell:t,f:t.f.clone()});return e}restoreFormulas(e){for(let t of e)t.cell.f=t.f.clone();Z()}setValue(e,t,n){let o=this.columns[t];if(!o||e<0||e>=this.rows.length)return!1;let i=this.getValue(e,t),s=this.formulaAt(e,t);if(!s&&Re(i,n)&&typeof i==typeof n)return!1;this.writeValue(e,o,n);let l=this.isNestedChange();return this.undo.push({undo:()=>{let a=this.getValue(e,t);if(this.writeValue(e,o,i),s)this.row(e,!0).cells.get(o.id).f=s,Z();else if(Re(a,i)&&typeof a==typeof i)return;this.onValueChanged(e,t,a,s?()=>this.getValue(e,t):i,this.valueSource,l)},redo:()=>{let a=this.getValue(e,t),u=this.formulaAt(e,t);this.writeValue(e,o,n),!(!u&&Re(a,n)&&typeof a==typeof n)&&this.onValueChanged(e,t,a,n,this.valueSource,l)}}),this.onValueChanged(e,t,i,n,this.valueSource),this.onChange("value"),!0}writeValue(e,t,n){var s,l,a;let o=this.row(e,!0);Z();let i=(s=o.cells)==null?void 0:s.get(t.id);if(i!=null&&i.f&&(i.f=void 0),t.field&&(o.data||this.data))(l=o.data)!=null||(o.data={}),o.data[t.field]=n;else{(a=o.cells)!=null||(o.cells=new Map);let u=o.cells.get(t.id);u?u.v=n:o.cells.set(t.id,{v:n})}this.undo.replaying&&this.onChange("value")}getCellStyle(e,t){var o,i,s;let n=this.columns[t];return n?(s=(i=(o=this.rows[e])==null?void 0:o.cells)==null?void 0:i.get(n.id))==null?void 0:s.s:void 0}getRowStyle(e){var t;return(t=this.rows[e])==null?void 0:t.style}setCellStyle(e,t,n){var u;let o=this.columns[t];if(!o||e<0||e>=this.rows.length)return;let i=this.row(e,!0);(u=i.cells)!=null||(i.cells=new Map);let s=i.cells.get(o.id),l=s!=null&&s.s?{...s.s}:void 0,a;if(n===null)a=void 0;else{a={...l!=null?l:{}};for(let c of Object.keys(n)){let h=n[c];h===void 0?delete a[c]:a[c]=h}Object.keys(a).length===0&&(a=void 0)}s||(s={},i.cells.set(o.id,s)),s.s=a,this.undo.push({undo:()=>this.replaceStyle(e,o,l),redo:()=>this.replaceStyle(e,o,a)}),this.onChange("style")}replaceStyle(e,t,n){var s,l;let o=this.row(e,!0);(s=o.cells)!=null||(o.cells=new Map);let i=(l=o.cells.get(t.id))!=null?l:{};i.s=n?{...n}:void 0,o.cells.set(t.id,i),this.onChange("style")}mergeAt(e,t){for(let n of this.merges)if(e>=n.row&&e<n.row+n.rowSpan&&t>=n.col&&t<n.col+n.colSpan)return n}addMerge(e){if(e.rowSpan*e.colSpan<=1)return;let t=this.merges.map(o=>({...o}));this.merges=this.merges.filter(o=>!vo(o,e)),this.merges.push({...e});let n=this.merges.map(o=>({...o}));this.undo.push({undo:()=>this.setMerges(t),redo:()=>this.setMerges(n)}),this.onChange("layout")}removeMerges(e){let t=this.merges.map(o=>({...o}));if(this.merges=this.merges.filter(o=>!vo(o,e)),this.merges.length===t.length)return;let n=this.merges.map(o=>({...o}));this.undo.push({undo:()=>this.setMerges(t),redo:()=>this.setMerges(n)}),this.onChange("layout")}setMerges(e){this.merges=e.map(t=>({...t})),this.onChange("layout")}valueMergeSpan(e,t,n=500){let o=this.columns[t];if(!o||o.mergeMode==="none")return[e,e];let i=this.getValue(e,t);if(i==null||i==="")return[e,e];let s=this.rowAxis,l=s.visual(e);if(l<0)return[e,e];let a=l,u=l,c=s.visibleCount,h=null;if(o.mergeMode==="restricted")for(let m=t-1;m>=0;m--){let p=this.columns[m];if(p.visible&&p.mergeMode!=="none"){h=this.valueMergeSpan(e,m,n);break}}let d=h?s.visual(h[0]):0,f=h?s.visual(h[1]):c-1;for(;a>d&&l-a<n&&Re(this.getValue(s.physical(a-1),t),i);)a--;for(;u<f&&u-l<n&&Re(this.getValue(s.physical(u+1),t),i);)u++;return[s.physical(a),s.physical(u)]}sort(e){let t=e.map(i=>{var s;return{col:this.columns[i.col],c:i.col,order:(s=i.order)!=null?s:"asc"}}).filter(i=>i.col),n=this.rows.length,o=Array.from({length:n},(i,s)=>s);if(t.length){let i=t.map(s=>{var u,c,h,d;let l=new Array(n),a=s.col.sortValue;if(a)for(let f=0;f<n;f++)l[f]=a((h=(u=this.rows[f])==null?void 0:u.data)!=null?h:(c=this.data)==null?void 0:c[f],f);else for(let f=0;f<n;f++)l[f]=this.getValue(f,s.c);if(!a&&s.col.kind==="date")for(let f=0;f<n;f++){let m=l[f];typeof m=="string"&&m!==""&&(l[f]=(d=xe(m))!=null?d:m)}return l});o.sort((s,l)=>{for(let a=0;a<t.length;a++){let u=i[a][s],c=i[a][l],h=t[a].col.sortCompare;if(h){let p=Math.sign(h(u,c,s,l)||0);if(p!==0)return t[a].order==="desc"?-p:p;continue}let d=We(u,c),f=u==null||u==="",m=c==null||c==="";if(d!==0&&!f&&!m&&t[a].order==="desc"&&(d=-d),d!==0)return d}return s-l})}this.reorder(o,t.map(i=>({col:i.col,order:i.order})))}clearSort(e=!0){let t=this.rows.length;if(!e||!this.data||!this.source||this.data.length!==t){if(!this.sortSpecs.length)return;let i=this.sortSpecs;this.sortSpecs=[],this.undo.push({undo:()=>this.sortSpecs=i,redo:()=>this.sortSpecs=[]}),this.layoutChanged();return}let n=new Map;for(let i=0;i<t;i++)n.set(this.data[i],i);let o=[];for(let i of this.source){let s=n.get(i);s!==void 0&&(o.push(s),n.delete(i))}for(let i of n.values())o.push(i);this.reorder(o,[])}reorder(e,t){let n=e.length,o=this.sortSpecs,i=this.snapshotFormulas(),s=()=>{var a,u;if(this.hasFormulas)for(let c=0;c<n;c++){if(e[c]===c)continue;let h=(a=this.rows[c])==null?void 0:a.cells;if(h)for(let d of h.values())(u=d.f)==null||u.offset(c-e[c],0)}};this.applyPermutation(e),s(),this.sortSpecs=t;let l=new Array(n);for(let a=0;a<n;a++)l[e[a]]=a;this.undo.push({undo:()=>{this.applyPermutation(l),this.restoreFormulas(i),this.sortSpecs=o},redo:()=>{this.applyPermutation(e),s(),this.sortSpecs=t}})}sourceRemove(e){let t=this.source;if(!t||!e.length)return[];let n=new Set(e),o=[];for(let i=0;i<t.length;i++)n.has(t[i])&&o.push({obj:t[i],index:i});if(o.length){let i=0;for(let s=0;s<t.length;s++)n.has(t[s])||(t[i++]=t[s]);t.length=i}return o}sourceRestore(e){let t=this.source;if(t)for(let n of e)t.splice(Math.min(n.index,t.length),0,n.obj)}sourceInsert(e,t){let n=this.source;if(!n||!e.length)return;let o=t?n.indexOf(t):-1;o<0?n.push(...e):n.splice(o,0,...e)}sourceIndex(e){var n;let t=(n=this.data)==null?void 0:n[e];return t&&this.source?this.source.indexOf(t):-1}applyPermutation(e){let t=this.rows.slice();for(let n=0;n<e.length;n++)this.rows[n]=t[e[n]];if(this.data){let n=this.data.slice();for(let o=0;o<e.length;o++)this.data[o]=n[e[o]]}this.layoutChanged()}setFilter(e,t){let n=this.columns[e];n&&(t?this.filters.set(n.id,t):this.filters.delete(n.id),this.applyFilters())}getFilter(e){let t=this.columns[e];return t?this.filters.get(t.id):void 0}clearFilters(){this.filters.clear(),this.applyFilters()}get hasFilters(){return this.filters.size>0||!!this.quickFilter}applyFilters(){var o,i;let e=[...this.filters.entries()].map(([s,l])=>({c:this.columns.findIndex(a=>a.id===s),f:l})).filter(s=>s.c>=0),t=this.quickFilter,n=t?(o=t.cols)!=null?o:this.columns.map((s,l)=>s.visible?l:-1).filter(s=>s>=0):[];for(let s=0;s<this.rows.length;s++){let l=!0;for(let{c:u,f:c}of e){let h=this.getValue(s,u);if((c.predicate&&!c.predicate(h,s)||c.values&&!c.values.has(this.columns[u].text(h,this.getCellStyle(s,u))))&&(l=!1),!l)break}l&&t&&!((i=this.rows[s])!=null&&i.subtotal)&&(l=n.some(u=>this.columns[u].text(this.getValue(s,u),this.getCellStyle(s,u)).toLowerCase().includes(t.text)));let a=this.rows[s];l?a&&(a.filtered=!1):this.row(s,!0).filtered=!0}this.layoutChanged()}distinctTexts(e,t=1e4){let n=this.columns[e],o=new Set,i=[];for(let s=0;s<this.rows.length&&o.size<t;s++){let l=this.getValue(s,e),a=n.text(l,this.getCellStyle(s,e));o.has(a)||(o.add(a),i.push({t:a,v:l}))}return i.sort((s,l)=>We(s.v,l.v)),i.map(s=>s.t)}setData(e,t=!1){let n=t&&this.sortSpecs.length?this.sortSpecs.map(o=>({col:this.columns.indexOf(o.col),order:o.order})).filter(o=>o.col>=0):[];if(this.setDataCore(e),n.length){let o=this.undo.enabled;this.undo.enabled=!1,this.sort(n),this.undo.enabled=o}}setDataCore(e){this.source=e,this.data=e?e.slice():null;let t=e?e.length:0;this.rows=new Array(t),this.merges=[],this.sortSpecs=[],this.undo.clear(),this.hasFilters&&this.applyFilters(),this.layoutChanged()}validate(e,t){let n=this.columns[e];if(!n)return null;let o=t==null||t==="",i=l=>n.validationMessage||l;if(o)return n.required?i(N().required(n.header||n.name)):null;if(typeof t=="number"){if(n.minimum!==void 0&&t<n.minimum)return i(N().min(n.minimum));if(n.kind!=="progress"&&n.maximum!==void 0&&t>n.maximum)return i(N().max(n.maximum))}let s=typeof t=="string"?t:n.text(t);return n.maxLength!==void 0&&typeof t=="string"&&t.length>n.maxLength?i(N().maxLength(n.maxLength)):n.pattern&&typeof t=="string"&&!new RegExp(n.pattern).test(t)?i(N().badFormat):n.valueList&&n.valueList.length&&!n.valueList.some(l=>Re(l,t)||String(l)===s)?i(N().notInList):null}};function Bt(r,e,t,n){if(n.length<5e3)return r.splice(e,t,...n);let o=r.slice(e,e+t),i=r.slice(e+t);r.length=e;for(let s=0;s<n.length;s++)r.push(n[s]);for(let s=0;s<i.length;s++)r.push(i[s]);return o}function vo(r,e){return r.row<e.row+e.rowSpan&&e.row<r.row+r.rowSpan&&r.col<e.col+e.colSpan&&e.col<r.col+r.colSpan}function Co(r){return r==null||typeof r=="string"||typeof r=="number"||typeof r=="boolean"||r instanceof Date?r:String(r)}var ft=class{constructor(e){this.grid=e}get count(){return this.grid.model.columns.length}get(e){let t=this.grid.model.columnIndex(e);return t>=0?this.grid.model.columns[t]:void 0}indexOf(e){return this.grid.model.columnIndex(e)}add(e={}){return this.grid.addColumnInternal(this.count,e)}insert(e,t={}){return this.grid.addColumnInternal(e,t)}remove(e){this.grid.model.removeColumn(this.grid.model.columnIndex(e))}move(e,t){this.grid.model.moveColumn(this.grid.model.columnIndex(e),t)}clear(){let e=this.grid.model,t=e.undo.enabled;for(e.undo.enabled=!1;e.columns.length;)e.removeColumn(e.columns.length-1);e.undo.enabled=t,e.undo.clear()}refresh(){this.grid.model.layoutChanged()}setWidth(e,t){this.grid.model.setColumnWidth(this.grid.model.columnIndex(e),t)}setVisible(e,t){let n=this.get(e);n&&(n.visible=t,this.grid.model.layoutChanged())}[Symbol.iterator](){return this.grid.model.columns[Symbol.iterator]()}toArray(){return this.grid.model.columns.slice()}},Qe=class{constructor(e,t,n,o,i){this.grid=e;this.row=t;this.col=n;this.row2=o;this.col2=i}each(e){let t=this.grid.model,n=Math.max(0,Math.min(this.row,this.row2)),o=Math.min(t.rowCount-1,Math.max(this.row,this.row2)),i=Math.max(0,Math.min(this.col,this.col2)),s=Math.min(t.columns.length-1,Math.max(this.col,this.col2));t.undo.transaction(()=>{for(let l=n;l<=o;l++)for(let a=i;a<=s;a++)e(l,a)})}setStyle(e){return this.each((t,n)=>this.grid.model.setCellStyle(t,n,e)),this}clearStyle(){return this.each((e,t)=>this.grid.model.setCellStyle(e,t,null)),this}set value(e){this.each((t,n)=>this.grid.model.setValue(t,n,e))}set backColor(e){this.setStyle({backColor:e})}set foreColor(e){this.setStyle({foreColor:e})}set bold(e){this.setStyle({bold:e})}set italic(e){this.setStyle({italic:e})}set underline(e){this.setStyle({underline:e})}set strikeout(e){this.setStyle({strikeout:e})}set fontSize(e){this.setStyle({fontSize:e})}set align(e){this.setStyle({align:e})}set verticalAlignment(e){this.setStyle({verticalAlignment:e})}set wrapText(e){this.setStyle({wrapText:e})}set format(e){this.setStyle({format:e})}set readOnly(e){this.setStyle({readOnly:e})}set borders(e){this.setStyle({borders:e})}setOutline(e={color:"#000",width:1}){let t=Math.min(this.row,this.row2),n=Math.max(this.row,this.row2),o=Math.min(this.col,this.col2),i=Math.max(this.col,this.col2);return this.each((s,l)=>{var c,h;let u={...(h=(c=this.grid.model.getCellStyle(s,l))==null?void 0:c.borders)!=null?h:{}};s===t&&(u.top=e),s===n&&(u.bottom=e),l===o&&(u.left=e),l===i&&(u.right=e),(s===t||s===n||l===o||l===i)&&this.grid.model.setCellStyle(s,l,{borders:u})}),this}merge(){return this.grid.mergeCells(Math.min(this.row,this.row2),Math.min(this.col,this.col2),Math.abs(this.row2-this.row)+1,Math.abs(this.col2-this.col)+1),this}unmerge(){return this.grid.unmergeCells(Math.min(this.row,this.row2),Math.min(this.col,this.col2),Math.abs(this.row2-this.row)+1,Math.abs(this.col2-this.col)+1),this}},mt=class extends Qe{constructor(e,t,n){super(e,t,n,t,n)}get style(){var e;return(e=this.grid.model.getCellStyle(this.row,this.col))!=null?e:{}}get value(){return this.grid.model.getValue(this.row,this.col)}set value(e){this.grid.model.setValue(this.row,this.col,e)}get text(){return this.grid.getText(this.row,this.col)}get backColor(){return this.style.backColor}set backColor(e){this.setStyle({backColor:e})}get foreColor(){return this.style.foreColor}set foreColor(e){this.setStyle({foreColor:e})}get bold(){return this.style.bold}set bold(e){this.setStyle({bold:e})}get italic(){return this.style.italic}set italic(e){this.setStyle({italic:e})}get underline(){return this.style.underline}set underline(e){this.setStyle({underline:e})}get strikeout(){return this.style.strikeout}set strikeout(e){this.setStyle({strikeout:e})}get fontSize(){return this.style.fontSize}set fontSize(e){this.setStyle({fontSize:e})}get align(){return this.style.align}set align(e){this.setStyle({align:e})}get verticalAlignment(){return this.style.verticalAlignment}set verticalAlignment(e){this.setStyle({verticalAlignment:e})}get wrapText(){return this.style.wrapText}set wrapText(e){this.setStyle({wrapText:e})}get format(){return this.style.format}set format(e){this.setStyle({format:e})}get readOnly(){return this.grid.isCellReadOnly(this.row,this.col)}set readOnly(e){this.setStyle({readOnly:e})}get borders(){return this.style.borders}set borders(e){this.setStyle({borders:e})}get validationError(){return this.grid.getValidationError(this.row,this.col)}};var ie=6,_t=class{constructor(e){this.g=e;this.dpr=1;this.measureCache=new Map;this.images=new Map;this.underlineNext=!1;let t=e.canvas.getContext("2d");if(!t)throw new Error("Canvas 2D \uB97C \uC4F8 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");this.ctx=t}paint(){let e=this.g,t=this.ctx,n=e.layout();t.setTransform(this.dpr,0,0,this.dpr,0,0),t.fillStyle=e.colors.back,t.fillRect(0,0,n.width,n.height);let o=e.model.rowAxis,i=e.model.colAxis,s=o.visibleCount,l=i.visibleCount,a=n.frozenRows,u=n.frozenCols,c=n.headerH+n.frozenH,h=n.rowHeaderW+n.frozenW,d=s>a?Math.max(a,o.indexAt(o.offset(a)+n.scrollTop)):a,f=s>a?o.indexAt(o.offset(a)+n.scrollTop+Math.max(0,n.bodyBottom-c)):a-1,m=l>u?Math.max(u,i.indexAt(i.offset(u)+n.scrollLeft)):u,p=l>u?i.indexAt(i.offset(u)+n.scrollLeft+Math.max(0,n.width-h)):u-1,b=[],g=[{v0:0,v1:a-1,y:n.headerH,h:n.frozenH},{v0:d,v1:f,y:c,h:n.bodyBottom-c}],w=[{u0:0,u1:u-1,x:n.rowHeaderW,w:n.frozenW},{u0:m,u1:p,x:h,w:n.width-h}];for(let S of g)for(let v of w)S.v1<S.v0||v.u1<v.u0||S.h<=0||v.w<=0||b.push({v0:S.v0,v1:S.v1,u0:v.u0,u1:v.u1,clip:{x:v.x,y:S.y,w:v.w,h:S.h}});for(let S of b)this.drawCells(S,n);for(let S of b)this.drawSelection(S,n);this.drawColumnHeaders(n,w),this.drawRowHeaders(n,g),this.drawCorner(n),this.drawFooter(n,w),t.strokeStyle=W(e.colors.gridLine,e.colors.headerFore,.35),t.lineWidth=1,a>0&&this.hline(n.rowHeaderW,n.width,c-.5),u>0&&this.vline(h-.5,n.headerH,n.bodyBottom),e.emptyMessage&&o.visibleCount===0&&this.drawEmptyMessage(n,e.emptyMessage),On()&&this.drawLicenseNotice(n)}drawEmptyMessage(e,t){let n=this.ctx,o=this.g,i=e.headerH,s=e.bodyBottom-i;s<o.fontSize+4||(n.save(),n.beginPath(),n.rect(e.rowHeaderW,i,e.width-e.rowHeaderW,s),n.clip(),n.font=`${o.fontSize}px ${o.fontFamily}`,n.fillStyle=W(o.colors.fore,o.colors.cellBack,.45),n.textAlign="center",n.textBaseline="middle",n.fillText(t,e.rowHeaderW+(e.width-e.rowHeaderW)/2,i+Math.min(s,160)/2),n.restore())}drawCells(e,t){var c,h;let n=this.g,o=n.model,i=this.ctx,s=o.rowAxis,l=o.colAxis;i.save(),i.beginPath(),i.rect(e.clip.x,e.clip.y,e.clip.w,e.clip.h),i.clip();let a=new Set,u=o.columns.some(d=>d.visible&&d.mergeMode!=="none");for(let d=e.v0;d<=e.v1;d++){let f=s.physical(d),m=n.rowY(d,t),p=s.sizeAt(d);for(let b=e.u0;b<=e.u1;b++){let g=l.physical(b),w=n.colX(b,t),S=l.sizeAt(b),v={x:w,y:m,w:S,h:p},k=null,R=o.merges.length?o.mergeAt(f,g):void 0;if(R){if(k=`m${R.row},${R.col}`,a.has(k))continue;v=(c=n.cellRect(R.row,R.col,t))!=null?c:v,this.paintCell(R.row,R.col,v,d,e.clip),a.add(k);continue}if(u&&o.columns[g].mergeMode!=="none"){let[D,z]=o.valueMergeSpan(f,g);if(z>D){if(k=`v${g},${D}`,a.has(k))continue;a.add(k),v=(h=n.cellRect(D,g,t))!=null?h:v,this.paintCell(D,g,v,s.visual(D),e.clip,!0);continue}}this.paintCell(f,g,v,d,e.clip)}}i.restore()}paintCell(e,t,n,o,i,s=!1){var E,A,F,V;let l=this.g,a=l.model,u=this.ctx,c=a.columns[t],h=l.colors,d=a.getValue(e,t),f=a.getCellStyle(e,t),m=a.getRowStyle(e),p=l.conditionalFormats.count?l.conditionalFormats.evaluate(e,t):null,b=l.sel,g=l.selectionShown&&e>=b.row&&e<=b.row2&&t>=b.col&&t<=b.col2,w=l.selectionMode!=="fullRow"&&e===l.cur.row&&t===l.cur.col,S=c.readOnly||c.kind==="label"||!!(f!=null&&f.readOnly),v=h.cellBack;l.alternatingRows&&o%2===1&&!s&&(v=h.altBack),S&&(v=h.readOnlyBack),c.backColor&&(v=c.backColor),m!=null&&m.backColor&&(v=m.backColor),f!=null&&f.backColor&&(v=f.backColor),p!=null&&p.backColor&&(v=p.backColor);let k=S?h.readOnlyFore:h.fore,R=!1,D=!!(c.backColor||m!=null&&m.backColor||f!=null&&f.backColor||p!=null&&p.backColor);c.foreColor&&(k=c.foreColor),m!=null&&m.foreColor&&(k=m.foreColor),f!=null&&f.foreColor&&(k=f.foreColor),p!=null&&p.foreColor&&(k=p.foreColor),R=!!(c.foreColor||m!=null&&m.foreColor||f!=null&&f.foreColor||p!=null&&p.foreColor),l.hoverRow&&!g&&e===l.hoverRowIndex&&(v=(E=h.hoverBack)!=null?E:W(h.cellBack,h.accent,.07)),g&&!w&&!(l.selectionKeepsBackColors&&D)&&(v=h.selBack,(!R||l.selectionOverridesCellColors)&&(k=h.selFore)),u.fillStyle=v,u.fillRect(n.x,n.y,n.w,n.h);let z={x:n.x,y:n.y,w:n.w-1,h:n.h-1},_=z;if(s){let L=Math.max(z.y,i.y),te=Math.min(z.y+z.h,i.y+i.h);te>L&&(_={x:z.x,y:L,w:z.w,h:te-L})}if(!(l.editing&&w))switch(c.kind){case"check":(A=a.rows[e])!=null&&A.subtotal||this.drawCheck(_,!!d,k,l.isCellReadOnly(e,t),v);break;case"button":this.drawButton(_,(F=c.buttonText)!=null?F:c.text(d,f),f);break;case"image":this.drawImage(_,c,d);break;case"progress":this.drawProgress(_,c,d,k,f);break;default:{let L=c.text(d,f);if(L===""&&c.emptyText&&(d==null||d==="")&&(L=c.emptyText),L!==""){let te=l.hoverCell;this.underlineNext=!!c.clickable&&!!te&&te.row===e&&te.col===t&&a.isClickable(e,t),this.drawText(_,L,c,d,f,p,m,k),this.underlineNext=!1}}}u.lineWidth=1,u.strokeStyle=h.gridLine,l.horizontalGridLines&&this.hline(n.x,n.x+n.w,n.y+n.h-.5),l.verticalGridLines&&this.vline(n.x+n.w-.5,n.y,n.y+n.h),f!=null&&f.borders&&this.drawBorders(n,f),l.showValidationErrors&&c.kind!=="check"&&Mr(c)&&!a.formulaAt(e,t)&&!((V=a.rows[e])!=null&&V.subtotal)&&a.validate(t,d)&&(u.fillStyle="#e11d48",u.beginPath(),u.moveTo(n.x+n.w-8,n.y+1),u.lineTo(n.x+n.w-1,n.y+1),u.lineTo(n.x+n.w-1,n.y+8),u.closePath(),u.fill())}font(e,t,n,o){var u,c,h,d,f,m,p,b,g,w;let i=this.g,s=(d=(h=(c=(u=n==null?void 0:n.bold)!=null?u:e==null?void 0:e.bold)!=null?c:o==null?void 0:o.bold)!=null?h:t==null?void 0:t.bold)!=null?d:!1,l=(p=(m=(f=n==null?void 0:n.italic)!=null?f:e==null?void 0:e.italic)!=null?m:o==null?void 0:o.italic)!=null?p:!1,a=(g=(b=e==null?void 0:e.fontSize)!=null?b:o==null?void 0:o.fontSize)!=null?g:i.fontSize;return`${l?"italic ":""}${s?"bold ":""}${a}px ${(w=e==null?void 0:e.fontFamily)!=null?w:i.fontFamily}`}drawText(e,t,n,o,i,s,l,a){var z,_,P,E,A,F,V,L;let u=this.ctx,c=this.font(i,n,s,l);u.font=c,u.fillStyle=a,u.textBaseline="middle";let h=n.effectiveAlign(o,i),d=(z=i==null?void 0:i.verticalAlignment)!=null?z:n.verticalAlignment,f=(P=(_=i==null?void 0:i.wrapText)!=null?_:l==null?void 0:l.wrapText)!=null?P:n.wrapText,m=(A=(E=i==null?void 0:i.fontSize)!=null?E:l==null?void 0:l.fontSize)!=null?A:this.g.fontSize,p=Math.round(m*1.35),b=e.w-ie*2,g=t.includes(`
|
|
4
|
+
`)||f?this.wrapLines(t,b,f,c):[t],w=Math.max(1,Math.floor((e.h-2)/p));g.length>w&&!f&&(g=g.slice(0,w));let S=g.length*p,v;d==="top"?v=e.y+3+p/2:d==="bottom"?v=e.y+e.h-3-S+p/2:v=e.y+(e.h-S)/2+p/2;let k=g.some(te=>this.measure(c,te)>b)||S>e.h;k&&(u.save(),u.beginPath(),u.rect(e.x+1,e.y,e.w-2,e.h),u.clip());let R=this.underlineNext||((F=i==null?void 0:i.underline)!=null?F:l==null?void 0:l.underline),D=(L=(V=s==null?void 0:s.strikeout)!=null?V:i==null?void 0:i.strikeout)!=null?L:l==null?void 0:l.strikeout;for(let te=0;te<g.length;te++){let Je=g[te],Ee=this.measure(c,Je),ue;h==="right"?ue=e.x+e.w-ie-Ee:h==="center"?ue=e.x+(e.w-Ee)/2:ue=e.x+ie,h!=="left"&&Ee>b&&(ue=e.x+ie);let H=Math.round(v+te*p);u.textAlign="left",u.fillText(Je,ue,H),(R||D)&&(u.strokeStyle=a,u.lineWidth=Math.max(1,m/14),R&&this.hline(ue,ue+Ee,Math.round(H+m*.45)+.5),D&&this.hline(ue,ue+Ee,Math.round(H)+.5))}k&&u.restore()}wrapLines(e,t,n,o){var s;let i=[];for(let l of e.split(`
|
|
5
|
+
`)){if(!n||this.measure(o,l)<=t){i.push(l);continue}let a="",u=(s=l.match(/\S+\s*|\s+/g))!=null?s:[l];for(let c of u){if(this.measure(o,a+c)<=t){a+=c;continue}if(a&&i.push(a.trimEnd()),this.measure(o,c)<=t)a=c;else{a="";for(let h of c)this.measure(o,a+h)>t&&a&&(i.push(a),a=""),a+=h}}i.push(a.trimEnd())}return i}measure(e,t){let n=e+""+t,o=this.measureCache.get(n);return o===void 0&&(this.measureCache.size>2e4&&this.measureCache.clear(),this.ctx.font=e,o=this.ctx.measureText(t).width,this.measureCache.set(n,o)),o}checkRect(e){return{x:Math.round(e.x+(e.w-14)/2),y:Math.round(e.y+(e.h-14)/2),w:14,h:14}}hitCheckBox(e,t,n,o){let i=this.g.cellRect(e,t);return i?n>=i.x&&n<=i.x+i.w&&o>=i.y&&o<=i.y+i.h:!1}drawCheck(e,t,n,o,i){let s=this.ctx,l=this.checkRect(e),a=this.g.colors.accent;if(Ze(s,l.x+.5,l.y+.5,l.w-1,l.h-1,3),t)s.fillStyle=o?W(a,"#ffffff",.45):a,s.fill(),s.strokeStyle="#ffffff",s.lineWidth=2,s.beginPath(),s.moveTo(l.x+3.5,l.y+7.5),s.lineTo(l.x+6,l.y+10),s.lineTo(l.x+10.5,l.y+4.5),s.stroke();else{let u=i!=null?i:this.g.colors.cellBack;s.fillStyle=u,s.fill(),s.strokeStyle=W(n,u,.45),s.lineWidth=1,s.stroke()}}drawButton(e,t,n){let o=this.ctx,i=this.g,s=e.x+3,l=e.y+3,a=e.w-6,u=e.h-6;if(a<=4||u<=4)return;Ze(o,s+.5,l+.5,a-1,u-1,4),o.fillStyle=W(i.colors.headerBack,"#ffffff",.3),o.fill(),o.strokeStyle=W(i.colors.gridLine,i.colors.headerFore,.3),o.lineWidth=1,o.stroke();let c=this.font(n,null,null);o.font=c,o.fillStyle=i.colors.headerFore,o.textBaseline="middle",o.textAlign="center",o.save(),o.beginPath(),o.rect(s,l,a,u),o.clip(),o.fillText(t,s+a/2,Math.round(l+u/2)),o.restore(),o.textAlign="left"}drawImage(e,t,n){var h;if(n==null||n==="")return;let o=(h=t.images)==null?void 0:h[String(n)];if(!o&&typeof n=="string"&&/^(https?:|data:|blob:|\.{0,2}\/)/.test(n)&&(o=n),!o)return;let i;if(typeof o=="string"?(i=this.images.get(o),i||(i=new Image,i.onload=()=>this.g.invalidate(),i.src=o,this.images.set(o,i))):i=o,!i.complete||!i.naturalWidth){i.onload||(i.onload=()=>this.g.invalidate());return}let s=e.h-4,l=e.w-4,a=Math.min(1,s/i.naturalHeight,l/i.naturalWidth),u=i.naturalWidth*a,c=i.naturalHeight*a;this.ctx.drawImage(i,Math.round(e.x+(e.w-u)/2),Math.round(e.y+(e.h-c)/2),u,c)}drawProgress(e,t,n,o,i){var S,v;let s=typeof n=="number"?n:NaN;if(isNaN(s))return;let l=this.ctx,a=this.g,u=(S=t.maximum)!=null?S:100,c=Math.max(0,Math.min(1,u?s/u:0)),h=t.format?t.text(n,i):`${Math.round(c*100)}%`,d=`${Math.max(10,a.fontSize-1)}px ${a.fontFamily}`,f=Math.max(34,this.measure(d,h)+8),m=e.w-f>30,p=e.x+6,b=e.w-12-(m?f:0),g=Math.min(8,e.h-8),w=Math.round(e.y+(e.h-g)/2);Ze(l,p,w,b,g,g/2),l.fillStyle=W(a.colors.gridLine,a.colors.cellBack,.3),l.fill(),c>0&&(Ze(l,p,w,Math.max(g,b*c),g,g/2),l.fillStyle=(v=i==null?void 0:i.foreColor)!=null?v:a.colors.accent,l.fill()),m&&(l.font=d,l.fillStyle=o,l.textBaseline="middle",l.textAlign="right",l.fillText(h,e.x+e.w-6,Math.round(e.y+e.h/2)),l.textAlign="left")}drawBorders(e,t){let n=t.borders,o=(i,s)=>{var a,u;if(!i)return;let l=(a=i.width)!=null?a:1;this.ctx.strokeStyle=(u=i.color)!=null?u:"#000",this.ctx.lineWidth=l,s(l%2?.5:0)};o(n.top,i=>this.hline(e.x,e.x+e.w,e.y+i)),o(n.bottom,i=>this.hline(e.x,e.x+e.w,e.y+e.h-1+i)),o(n.left,i=>this.vline(e.x+i,e.y,e.y+e.h)),o(n.right,i=>this.vline(e.x+e.w-1+i,e.y,e.y+e.h))}drawSelection(e,t){var h,d;let n=this.g;if(!n.selectionShown)return;let o=this.ctx,i=n.sel,s=typeof document!="undefined"&&(document.activeElement===n.input||n.root.contains(document.activeElement));o.save(),o.beginPath(),o.rect(e.clip.x,e.clip.y,e.clip.w,e.clip.h),o.clip();let l=n.cellRect(i.row,i.col,t,!1),a=n.cellRect(i.row2,i.col2,t,!1),u=(h=n.colors.selBorder)!=null?h:n.colors.accent,c=s?u:W(u,"#9ca3af",.6);if(l&&a){let f=l.x,m=l.y,p=i.row===i.row2&&i.col===i.col2?(d=n.cellRect(i.row,i.col,t))!=null?d:l:{x:f,y:m,w:a.x+a.w-f,h:a.y+a.h-m};o.strokeStyle=c,o.lineWidth=2,o.strokeRect(p.x+.5,p.y+.5,p.w-2,p.h-2),o.fillStyle=c,o.fillRect(p.x+p.w-5,p.y+p.h-5,5,5)}o.restore()}drawColumnHeaders(e,t){if(e.headerH<=0)return;let n=this.g,o=n.model,i=this.ctx,s=o.colAxis,l=n.colors;i.fillStyle=l.headerBack,i.fillRect(e.rowHeaderW,0,e.width-e.rowHeaderW,e.headerH);let a=`${n.headerBold?"600 ":""}${n.fontSize}px ${n.fontFamily}`,u=n.hoverInfo;for(let c of t){if(c.u1<c.u0||c.w<=0)continue;i.save(),i.beginPath(),i.rect(c.x,0,c.w,e.headerH),i.clip();for(let d=c.u0;d<=c.u1;d++){let f=s.physical(d),m=o.columns[f],p=n.colX(d,e),b=s.sizeAt(d),g=n.leafTop(d,e),w=e.headerH-g,S=n.selectionShown&&n.selectionMode!=="fullRow"&&f>=n.sel.col&&f<=n.sel.col2;S&&(i.fillStyle=W(l.headerBack,l.accent,.12),i.fillRect(p,g,b,w)),u&&u.area==="colHeader"&&u.col===f&&u.resizeCol===void 0&&(i.fillStyle=W(l.headerBack,l.headerFore,.06),i.fillRect(p,g,b,w));let v=0;if(m.headerCheckBox){let A=n.headerCheckState(f),F=14,V=Math.round(m.header?p+ie:p+(b-F)/2),L=Math.round(g+w/2-F/2);Ze(i,V+.5,L+.5,F-1,F-1,3),A==="off"?(i.fillStyle=l.cellBack,i.fill(),i.strokeStyle=W(l.headerFore,l.headerBack,.45),i.lineWidth=1,i.stroke()):(i.fillStyle=l.accent,i.fill(),i.strokeStyle="#ffffff",i.lineWidth=2,i.beginPath(),A==="on"?(i.moveTo(V+3.5,L+7.5),i.lineTo(V+6,L+10),i.lineTo(V+10.5,L+4.5)):(i.moveTo(V+3.5,L+7),i.lineTo(V+10.5,L+7)),i.stroke()),v=m.header?F+4:b}let k=o.sortSpecs.findIndex(A=>A.col===m),R=n.allowFilter&&m.filterable,D=(R?18:0)+(k>=0?14:0);i.font=a,i.fillStyle=l.headerFore,i.textBaseline="middle";let z=m.header,_=this.measure(a,z),P=b-ie*2-D-v,E=v?p+ie+v:p+(b-D-_)/2;if(_>P&&(E=p+ie+v),i.save(),i.beginPath(),i.rect(p+2,g,Math.max(0,b-D-4),w),i.clip(),i.textAlign="left",i.fillText(z,E,Math.round(g+w/2)),i.restore(),k>=0){let A=o.sortSpecs[k].order==="asc",F=p+b-(R?18:0)-12,V=g+w/2;i.fillStyle=l.accent,i.beginPath(),A?(i.moveTo(F,V+3),i.lineTo(F+8,V+3),i.lineTo(F+4,V-3)):(i.moveTo(F,V-3),i.lineTo(F+8,V-3),i.lineTo(F+4,V+3)),i.fill(),o.sortSpecs.length>1&&(i.font=`9px ${n.fontFamily}`,i.fillText(String(k+1),F+9,V-5))}if(R){let A=!!o.filters.get(m.id),F=p+b-20,V=Math.round(g+w/2-8);A&&(Ze(i,F,V,16,16,3),i.fillStyle=W(l.headerBack,l.accent,.2),i.fill()),i.fillStyle=A?l.accent:W(l.headerFore,l.headerBack,.35),i.beginPath(),i.moveTo(F+4,V+5),i.lineTo(F+12,V+5),i.lineTo(F+9,V+9),i.lineTo(F+9,V+13),i.lineTo(F+7,V+12),i.lineTo(F+7,V+9),i.closePath(),i.fill()}i.strokeStyle=l.gridLine,i.lineWidth=1,this.vline(p+b-.5,g+(n.headerBold?7:0),n.headerBold?e.headerH-7:e.headerH),S&&(i.strokeStyle=l.accent,i.lineWidth=2,this.hline(p,p+b,e.headerH-1))}let h=c.u0<e.frozenCols;for(let d of e.groups.cells){if(d.u1<c.u0||d.u0>c.u1||d.u0<e.frozenCols!==h)continue;let f=n.colX(d.u0,e),m=n.colX(d.u1,e)+s.sizeAt(d.u1)-f,p=d.level*e.headerRowH;i.font=a,i.fillStyle=l.headerFore,i.textBaseline="middle";let b=this.measure(a,d.text),g=Math.max(f,c.x),w=Math.min(f+m,c.x+c.w),S=g+(w-g-b)/2;b>w-g-ie*2&&(S=g+ie),i.save(),i.beginPath(),i.rect(f+2,p,Math.max(0,m-4),e.headerRowH),i.clip(),i.textAlign="left",i.fillText(d.text,S,Math.round(p+e.headerRowH/2)),i.restore(),i.strokeStyle=l.gridLine,i.lineWidth=1,this.vline(f+m-.5,p,p+e.headerRowH),this.hline(f,f+m,p+e.headerRowH-.5)}i.restore()}i.strokeStyle=n.headerBold?W(l.gridLine,l.headerFore,.25):l.gridLine,i.lineWidth=1,this.hline(e.rowHeaderW,e.width,e.headerH-.5)}drawFooter(e,t){if(e.footerH<=0)return;let n=this.g,o=n.model,i=this.ctx,s=o.colAxis,l=n.colors,a=e.bodyBottom,u=e.footerH;i.fillStyle=l.headerBack,i.fillRect(0,a,e.width,u);let c=`600 ${n.fontSize}px ${n.fontFamily}`;i.font=c,i.textBaseline="middle",i.fillStyle=l.headerFore,e.rowHeaderW>e.outlineW&&(i.textAlign="center",i.fillText("\u03A3",(e.outlineW+e.rowHeaderW)/2,Math.round(a+1+u/2)));for(let h of t)if(!(h.u1<h.u0||h.w<=0)){i.save(),i.beginPath(),i.rect(h.x,a,h.w,u),i.clip();for(let d=h.u0;d<=h.u1;d++){let f=s.physical(d),m=o.columns[f],p=n.colX(d,e),b=s.sizeAt(d);if(i.strokeStyle=l.gridLine,i.lineWidth=1,this.vline(p+b-.5,a,a+u),m.footer==="none")continue;let g=n.footerTextOf(f);if(!g)continue;let S=typeof n.getFooterValue(f)=="number"||m.footer==="count";i.fillStyle=l.headerFore,i.font=c,i.save(),i.beginPath(),i.rect(p+2,a,Math.max(0,b-4),u),i.clip(),i.textAlign=S?"right":m.align==="center"?"center":"left";let v=S?p+b-ie:m.align==="center"?p+b/2:p+ie;i.fillText(g,v,Math.round(a+1+u/2)),i.restore()}i.restore()}i.textAlign="left",i.strokeStyle=W(l.gridLine,l.headerFore,.35),i.lineWidth=1,this.hline(0,e.width,a+.5),this.hline(0,e.width,a+2.5),e.rowHeaderW>0&&(i.strokeStyle=l.gridLine,this.vline(e.rowHeaderW-.5,a,a+u))}drawRowHeaders(e,t){if(e.rowHeaderW<=0)return;let n=this.g,o=n.model,i=this.ctx,s=o.rowAxis,l=n.colors;i.fillStyle=l.headerBack,i.fillRect(0,e.headerH,e.rowHeaderW,e.bodyBottom-e.headerH);let a=`${Math.max(10,n.fontSize-1)}px ${n.fontFamily}`;for(let u of t)if(!(u.v1<u.v0||u.h<=0)){i.save(),i.beginPath(),i.rect(0,u.y,e.rowHeaderW,u.h),i.clip();for(let c=u.v0;c<=u.v1;c++){let h=s.physical(c),d=n.rowY(c,e),f=s.sizeAt(c),m=n.selectionShown&&h>=n.sel.row&&h<=n.sel.row2;m&&(i.fillStyle=W(l.headerBack,l.accent,.12),i.fillRect(e.outlineW,d,e.rowHeaderW-e.outlineW,f)),i.font=a,i.fillStyle=m?l.accent:l.headerFore,i.textAlign="center",i.textBaseline="middle",e.rowHeaderW-e.outlineW>4&&i.fillText(String(h+1),e.outlineW+(e.rowHeaderW-e.outlineW)/2,Math.round(d+f/2)),i.strokeStyle=l.gridLine,i.lineWidth=1,this.hline(e.outlineW,e.rowHeaderW,d+f-.5),m&&(i.strokeStyle=l.accent,i.lineWidth=2,this.vline(e.rowHeaderW-1,d,d+f))}e.outlineW>0&&this.drawOutline(e,u),i.restore()}i.textAlign="left",i.strokeStyle=l.gridLine,i.lineWidth=1,this.vline(e.rowHeaderW-.5,e.headerH,e.bodyBottom),e.outlineW>0&&this.vline(e.outlineW-.5,e.headerH,e.bodyBottom)}drawOutline(e,t){let n=this.g,o=n.model,i=this.ctx,s=o.rowAxis,l=n.colors,a=W(l.headerFore,l.headerBack,.45),u=t.y,c=t.y+t.h,h=d=>s.visual(d);for(let d of o.outlineGroups){let f=So(d.level);if(i.strokeStyle=a,i.lineWidth=1,!d.collapsed){let S=h(d.start),v=h(d.end);if(S>=0&&v>=0&&!(v<t.v0||S>t.v1)){let k=n.rowY(S,e)+3,R=n.rowY(v,e)+s.sizeAt(v)-1;R>=u&&k<=c&&(this.vline(f+.5,k,R),this.hline(f,f+5,Math.round(R)-.5))}}if(d.summary<0)continue;let m=h(d.summary);if(m<t.v0||m>t.v1||m<0)continue;let p=n.rowY(m,e),b=s.sizeAt(m),g=f-5,w=Math.round(p+b/2-5);i.fillStyle=l.cellBack,i.fillRect(g+.5,w+.5,10,10),i.strokeStyle=a,i.strokeRect(g+.5,w+.5,10,10),i.strokeStyle=l.headerFore,this.hline(g+3,g+8,w+5.5),d.collapsed&&this.vline(g+5.5,w+3,w+8)}}drawCorner(e){if(e.rowHeaderW<=0||e.headerH<=0)return;let t=this.ctx,n=this.g.colors;if(t.fillStyle=n.headerBack,t.fillRect(0,0,e.rowHeaderW,e.headerH),e.outlineW>0){let o=this.g.model.outlineLevels+1;t.font=`${Math.max(9,this.g.fontSize-3)}px ${this.g.fontFamily}`,t.textAlign="center",t.textBaseline="middle";for(let i=1;i<=o;i++){let s=So(i)-6,l=Math.round(e.headerH/2-6);t.fillStyle=W(n.headerBack,"#ffffff",.5),t.fillRect(s+.5,l+.5,12,12),t.strokeStyle=W(n.headerFore,n.headerBack,.45),t.lineWidth=1,t.strokeRect(s+.5,l+.5,12,12),t.fillStyle=n.headerFore,t.fillText(String(i),s+6.5,l+7)}t.textAlign="left"}t.fillStyle=W(n.headerBack,n.headerFore,.25),t.beginPath(),t.moveTo(e.rowHeaderW-4,e.headerH-12),t.lineTo(e.rowHeaderW-4,e.headerH-4),t.lineTo(e.rowHeaderW-12,e.headerH-4),t.closePath(),t.fill(),t.strokeStyle=n.gridLine,t.lineWidth=1,this.hline(0,e.rowHeaderW,e.headerH-.5),this.vline(e.rowHeaderW-.5,0,e.headerH)}drawLicenseNotice(e){if(e.width<220||e.height<80)return;let t=this.ctx,n=N().licenseNotice,o=`11px ${this.g.fontFamily}`,i=this.measure(o,n)+14,s=e.width-i-8,l=e.bodyBottom-26;t.save(),t.globalAlpha=.88,t.fillStyle="#fffbeb",t.fillRect(s,l,i,20),t.strokeStyle="#f59e0b",t.lineWidth=1,t.strokeRect(s+.5,l+.5,i-1,19),t.globalAlpha=1,t.fillStyle="#92400e",t.font=o,t.textBaseline="middle",t.textAlign="left",t.fillText(n,s+7,l+10.5),t.restore()}measureColumn(e){let t=this.g,n=t.model,o=n.columns[e],i=`${t.headerBold?"600 ":""}${t.fontSize}px ${t.fontFamily}`,s=this.measure(i,o.header)+ie*2+8+(t.allowFilter?18:0)+14,l=n.rowAxis,a=Math.min(l.visibleCount,2e3);for(let u=0;u<a;u++){let c=l.physical(u),h=n.getValue(c,e),d=n.getCellStyle(c,e),f=o.kind==="check"?"":o.text(h,d);if(!f)continue;let m=this.font(d,o,null,n.getRowStyle(c));for(let p of f.split(`
|
|
6
|
+
`))s=Math.max(s,this.measure(m,p)+ie*2+2)}return Math.ceil(s)}hline(e,t,n){let o=this.ctx;o.beginPath(),o.moveTo(e,n),o.lineTo(t,n),o.stroke()}vline(e,t,n){let o=this.ctx;o.beginPath(),o.moveTo(e,t),o.lineTo(e,n),o.stroke()}};function So(r){return 4+(r-1)*14+7}function Mo(r){let e=Math.floor((r-4)/14)+1;return e>=1?e:0}function Mr(r){return r.required||r.minimum!==void 0||r.maximum!==void 0&&r.kind!=="progress"||r.maxLength!==void 0||!!r.pattern||!!r.valueList}function Ze(r,e,t,n,o,i){i=Math.min(i,n/2,o/2),r.beginPath(),r.moveTo(e+i,t),r.lineTo(e+n-i,t),r.arcTo(e+n,t,e+n,t+i,i),r.lineTo(e+n,t+o-i),r.arcTo(e+n,t+o,e+n-i,t+o,i),r.lineTo(e+i,t+o),r.arcTo(e,t+o,e,t+o-i,i),r.lineTo(e,t+i),r.arcTo(e,t,e+i,t,i),r.closePath()}function ko(r,e){let t=e.matchCase?r:r.toLocaleLowerCase("ko");return n=>{let o=e.matchCase?n:n.toLocaleLowerCase("ko");return e.wholeCell?o===t:o.includes(t)}}function pt(r,e,t={}){if(!e)return null;let n=r.model,o=n.rowAxis,i=n.colAxis,s=o.visibleCount,l=i.visibleCount;if(!s||!l)return null;let a=t.inColumn!==void 0?n.columnIndex(t.inColumn):-1,u=[];for(let b=0;b<l;b++){let g=i.physical(b);(a<0||g===a)&&u.push(g)}if(!u.length)return null;let c=ko(e,t),h=r.currentCell,d=o.visual(h.row);d<0&&(d=0);let f=Math.max(0,u.indexOf(h.col)),m=s*u.length,p=t.backwards?-1:1;for(let b=0;b<m;b++){f+=p,f>=u.length?(f=0,d=(d+1)%s):f<0&&(f=u.length-1,d=(d-1+s)%s);let g=o.physical(d),w=u[f];if(c(r.getText(g,w)))return r.select(g,w),{row:g,col:w}}return null}function Ao(r,e,t,n,o){return ko(n,o)(r.getText(e,t))}function kr(r,e,t,n){if(n.wholeCell)return t;let o=n.matchCase?"g":"gi";return r.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o),()=>t)}function Eo(r,e,t){return!r.isCellReadOnly(e,t)&&!r.model.formulaAt(e,t)&&r.model.columns[t].kind!=="check"}function Ro(r,e,t,n,o,i){let s=r.model.columns[t],l=kr(r.getText(e,t),n,o,i),a=s.parse(l);return a===void 0||r.model.validate(t,a)?!1:r.withSource("replace",()=>r.model.setValue(e,t,a))}function vn(r,e,t,n={}){let{row:o,col:i}=r.currentCell,s=!1;return Ao(r,o,i,e,n)&&Eo(r,o,i)&&(s=Ro(r,o,i,e,t,n)),pt(r,e,n),s}function Cn(r,e,t,n={}){if(!e)return 0;let o=r.model,i=n.inColumn!==void 0?o.columnIndex(n.inColumn):-1,s=0;return o.undo.transaction(()=>{for(let l=0;l<o.rowCount;l++)if(o.isRowVisible(l))for(let a=0;a<o.columns.length;a++)!o.columns[a].visible||i>=0&&a!==i||Ao(r,l,a,e,n)&&Eo(r,l,a)&&Ro(r,l,a,e,t,n)&&s++}),s&&o.hasFilters&&o.applyFilters(),r.invalidate(),s}var Kt=class{constructor(e){this.g=e;this.lastText="";let t=this.el=document.createElement("div");t.className="nox-grid-find";let n=N();t.innerHTML=`
|
|
7
|
+
<div class="row"><input class="what" type="search" placeholder="${n.findWhat}" aria-label="${n.findWhat}"><button class="next" type="button">${n.findNext}</button><button class="close" type="button" aria-label="${n.close}">\u2715</button></div>
|
|
8
|
+
<div class="row replace"><input class="with" type="text" placeholder="${n.replaceWith}" aria-label="${n.replaceWith}"><button class="one" type="button">${n.replace}</button><button class="all" type="button">${n.replaceAll}</button></div>
|
|
9
|
+
<div class="opts"><label><input type="checkbox" class="case"> ${n.matchCase}</label><label><input type="checkbox" class="whole"> ${n.wholeCell}</label><label><input type="checkbox" class="col"> ${n.inColumn}</label></div>
|
|
10
|
+
<div class="status"></div>`;let o=i=>t.querySelector(i);this.what=o(".what"),this.withText=o(".with"),this.replaceRow=o(".replace"),this.status=o(".status"),this.matchCase=o(".case"),this.wholeCell=o(".whole"),this.inColumn=o(".col"),o(".next").onclick=()=>this.next(!1),o(".close").onclick=()=>this.close(),o(".one").onclick=()=>{let i=vn(this.g,this.what.value,this.withText.value,this.options());this.status.textContent=i?N().replaced:N().notReplaceable},o(".all").onclick=()=>{let i=Cn(this.g,this.what.value,this.withText.value,this.options());this.status.textContent=N().replacedCount(i)},t.addEventListener("keydown",i=>{i.key==="Escape"?(i.preventDefault(),this.close()):(i.key==="Enter"||i.key==="F3")&&(i.preventDefault(),this.next(i.shiftKey)),i.stopPropagation()}),t.addEventListener("pointerdown",i=>i.stopPropagation())}options(){return{matchCase:this.matchCase.checked,wholeCell:this.wholeCell.checked,inColumn:this.inColumn.checked?this.g.currentCell.col:void 0}}open(e){this.replaceRow.style.display=e?"":"none",this.el.isConnected||this.g.root.appendChild(this.el);let t=this.g.getText(this.g.currentCell.row,this.g.currentCell.col);!this.what.value&&t&&(this.what.value=t),this.status.textContent="",this.what.focus(),this.what.select()}get isOpen(){return this.el.isConnected}next(e){let t=this.what.value||this.lastText;this.lastText=t;let n=pt(this.g,t,{...this.options(),backwards:e});this.status.textContent=n?"":N().notFound}close(){this.el.remove(),this.g.focus()}};function Ie(r,e){let t=0;for(let i of r)t=Math.max(t,i.length);if(t===0)return{levels:0,depth:r.map(()=>0),cells:[]};let n=[],o=r.length;for(let i=0;i<t;i++){let s=0;for(;s<o;){if(r[s].length<=i){s++;continue}let l=s;for(;l+1<o&&l+1<e==s<e&&Ar(r[s],r[l+1],i);)l++;n.push({level:i,u0:s,u1:l,text:r[s][i]}),s=l+1}}return{levels:t,depth:r.map(i=>i.length),cells:n}}function Ar(r,e,t){if(r.length<=t||e.length<=t)return!1;for(let n=0;n<=t;n++)if(r[n]!==e[n])return!1;return!0}function Fo(r){return[...r.group,r.header].filter(e=>e.length>0).join(" ")}var Ve=r=>r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Er(r){let e=r==null?void 0:r.borders;if(!e)return"";let t=(n,o)=>{var i,s;return o?`border-${n}:${(i=o.width)!=null?i:1}px solid ${(s=o.color)!=null?s:"#000"};`:""};return t("left",e.left)+t("top",e.top)+t("right",e.right)+t("bottom",e.bottom)}function gt(r,e={}){var h,d,f,m,p,b,g,w,S,v,k,R,D,z,_,P,E,A,F,V,L,te,Je,Ee,ue;let t=r.model,n=r.selection,o=[],i=[];for(let H=0;H<t.rowAxis.visibleCount;H++){let I=t.rowAxis.physical(H);(!e.selectionOnly||I>=n.row&&I<=n.row2)&&o.push(I)}for(let H=0;H<t.colAxis.visibleCount;H++){let I=t.colAxis.physical(H);t.columns[I].kind!=="button"&&(!e.selectionOnly||I>=n.col&&I<=n.col2)&&i.push(I)}let s=r.fontSize,l=[];if(l.push(`<table class="nox-print" style="font-size:${s}px">`),l.push("<colgroup>"+i.map(H=>`<col style="width:${t.columns[H].width}px">`).join("")+"</colgroup>"),(h=e.headers)==null||h){let H=Ie(i.map(j=>t.columns[j].group),-1),I=Array.from({length:H.levels+1},()=>[]);for(let j=0;j<i.length;j++){for(let K of H.cells)K.u0===j&&I[K.level].push(`<th${K.u1>K.u0?` colspan="${K.u1-K.u0+1}"`:""}>${Ve(K.text)}</th>`);let O=(d=H.depth[j])!=null?d:0,Y=H.levels+1-O;I[O].push(`<th${Y>1?` rowspan="${Y}"`:""}>${Ve(t.columns[i[j]].header)}</th>`)}l.push("<thead>"+I.map(j=>`<tr>${j.join("")}</tr>`).join("")+"</thead>")}l.push("<tbody>");let a=new Map(o.map((H,I)=>[H,I])),u=new Map(i.map((H,I)=>[H,I])),c=new Set;for(let H of o){l.push(`<tr style="height:${(m=(f=t.rows[H])==null?void 0:f.height)!=null?m:r.rowHeight}px">`);for(let I of i){if(c.has(`${H},${I}`))continue;let j=t.columns[I],O=t.getCellStyle(H,I),Y=t.getRowStyle(H),K=r.conditionalFormats.count?r.conditionalFormats.evaluate(H,I):null,fe=t.getValue(H,I),Zt="",ne=t.mergeAt(H,I);if(ne&&ne.row===H&&ne.col===I){let pe=0,Pe=0;for(let ce=ne.row;ce<ne.row+ne.rowSpan;ce++)a.has(ce)&&pe++;for(let ce=ne.col;ce<ne.col+ne.colSpan;ce++)u.has(ce)&&Pe++;for(let ce=ne.row;ce<ne.row+ne.rowSpan;ce++)for(let vt=ne.col;vt<ne.col+ne.colSpan;vt++)(ce!==H||vt!==I)&&c.add(`${ce},${vt}`);pe>1&&(Zt+=` rowspan="${pe}"`),Pe>1&&(Zt+=` colspan="${Pe}"`)}let me="",An=(g=(b=(p=K==null?void 0:K.backColor)!=null?p:O==null?void 0:O.backColor)!=null?b:Y==null?void 0:Y.backColor)!=null?g:j.backColor,En=(v=(S=(w=K==null?void 0:K.foreColor)!=null?w:O==null?void 0:O.foreColor)!=null?S:Y==null?void 0:Y.foreColor)!=null?v:j.foreColor;An&&(me+=`background:${An};`),En&&(me+=`color:${En};`),((D=(R=(k=K==null?void 0:K.bold)!=null?k:O==null?void 0:O.bold)!=null?R:Y==null?void 0:Y.bold)!=null?D:j.bold)&&(me+="font-weight:bold;"),((_=(z=K==null?void 0:K.italic)!=null?z:O==null?void 0:O.italic)!=null?_:Y!=null&&Y.italic)&&(me+="font-style:italic;");let Rn=[((P=O==null?void 0:O.underline)!=null?P:Y!=null&&Y.underline)?"underline":"",((A=(E=K==null?void 0:K.strikeout)!=null?E:O==null?void 0:O.strikeout)!=null?A:Y!=null&&Y.strikeout)?"line-through":""].filter(Boolean).join(" ");Rn&&(me+=`text-decoration:${Rn};`),O!=null&&O.fontSize&&(me+=`font-size:${O.fontSize}px;`),me+=`text-align:${j.effectiveAlign(fe,O)};`;let Jt=(F=O==null?void 0:O.verticalAlignment)!=null?F:j.verticalAlignment;Jt&&Jt!=="middle"&&(me+=`vertical-align:${Jt};`),((V=O==null?void 0:O.wrapText)!=null?V:j.wrapText)&&(me+="white-space:pre-wrap;"),me+=Er(O);let et;switch(j.kind){case"check":et=(L=t.rows[H])!=null&&L.subtotal?"":fe?"\u2611":"\u2610";break;case"progress":{let pe=(te=j.maximum)!=null?te:100;et=typeof fe=="number"?`${Math.round((pe?fe/pe:0)*100)}%`:"";break}case"image":{let pe=fe==null||(Je=j.images)==null?void 0:Je[String(fe)],Pe=typeof pe=="string"?pe:pe instanceof HTMLImageElement?pe.src:typeof fe=="string"&&/^(https?:|data:)/.test(fe)?fe:"";et=Pe?`<img src="${Ve(Pe)}" style="max-height:${((ue=(Ee=t.rows[H])==null?void 0:Ee.height)!=null?ue:r.rowHeight)-4}px">`:"";break}default:et=Ve(j.text(fe,O)).replace(/\n/g,"<br>")}l.push(`<td${Zt} style="${me}">${et}</td>`)}l.push("</tr>")}return l.push("</tbody>"),r.footerVisible&&i.some(H=>t.columns[H].footer!=="none")&&l.push('<tfoot class="nox-footer"><tr>'+i.map(H=>{let I=t.columns[H];return`<td style="text-align:${typeof r.getFooterValue(H)=="number"||I.footer==="count"?"right":I.align==="center"?"center":"left"}">${Ve(r.footerTextOf(H))}</td>`}).join("")+"</tr></tfoot>"),l.push("</table>"),l.join("")}function bt(r,e={}){var s,l,a,u;let t=new Date,n=(s=e.footer)!=null?s:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,o=`
|
|
11
|
+
@page { size: ${e.landscape?"A4 landscape":"A4"}; margin: ${(l=e.margin)!=null?l:"12mm"}; }
|
|
12
|
+
* { box-sizing: border-box; }
|
|
13
|
+
body { margin: 0; font-family: "Malgun Gothic","Apple SD Gothic Neo","Segoe UI",sans-serif; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
|
14
|
+
h1 { font-size: 15px; margin: 0 0 6px; }
|
|
15
|
+
section + section { break-before: page; }
|
|
16
|
+
table.nox-print { border-collapse: collapse; table-layout: fixed; width: auto; }
|
|
17
|
+
.nox-print th, .nox-print td { border: 1px solid #bfbfbf; padding: 2px 5px; overflow: hidden; white-space: nowrap; text-overflow: clip; }
|
|
18
|
+
.nox-print th { background: #f2f2f2; font-weight: 600; text-align: center; }
|
|
19
|
+
.nox-print thead { display: table-header-group; }
|
|
20
|
+
.nox-print tfoot { display: table-row-group; }
|
|
21
|
+
.nox-print tfoot td { background: #f2f2f2; font-weight: 600; border-top: 3px double #808080; }
|
|
22
|
+
.nox-print tr { break-inside: avoid; }
|
|
23
|
+
footer { margin-top: 6px; font-size: 10px; color: #666; }`,i=r.map(c=>`<section>${c.title?`<h1>${Ve(c.title)}</h1>`:""}${c.table}<footer>${Ve(n)}</footer></section>`).join("");return`<!doctype html><html lang="ko"><head><meta charset="utf-8"><title>${Ve((u=(a=r[0])==null?void 0:a.title)!=null?u:"NoxGrid")}</title><style>${o}</style></head><body>${i}</body></html>`}function wt(r){return new Promise(e=>{let t=document.createElement("iframe");t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden",document.body.appendChild(t);let n=t.contentDocument;n.open(),n.write(r),n.close();let o=()=>{let s=t.contentWindow,l=()=>{setTimeout(()=>t.remove(),500),e()};s.addEventListener("afterprint",l,{once:!0}),s.focus(),s.print(),setTimeout(l,6e4)},i=Array.from(n.images);i.every(s=>s.complete)?setTimeout(o,50):Promise.all(i.map(s=>new Promise(l=>{s.onload=s.onerror=l}))).then(()=>o())})}var x=(r,e,t)=>`rgb(${r},${e},${t})`,J="#ffffff";function ae(r,e,t,n,o,i,s,l,a,u,c,h,d=!1){return{headerBack:r,headerFore:e,cellBack:t,altBack:n,gridLine:o,selBack:i,selFore:s,accent:l,readOnlyBack:a||t,readOnlyFore:u||x(90,90,90),back:c||x(250,250,251),fore:h||x(17,24,39),modern:d}}var $e={default:ae(x(242,244,247),x(55,65,81),J,x(249,250,251),x(226,229,234),x(214,230,253),x(17,24,39),x(37,99,235),x(246,247,249)),blue:ae(x(221,235,247),x(31,56,100),J,x(242,247,252),x(189,215,238),x(155,194,230),x(16,24,40),x(46,117,182),x(234,240,247)),green:ae(x(226,239,218),x(56,87,35),J,x(244,249,241),x(198,224,180),x(169,208,142),x(20,30,15),x(84,130,53),x(237,242,233)),gray:ae(x(217,217,217),x(38,38,38),J,x(242,242,242),x(191,191,191),x(180,198,231),x(0,0,0),x(89,89,89),x(235,235,235)),orange:ae(x(252,228,214),x(130,60,20),J,x(254,246,240),x(248,203,173),x(244,176,132),x(40,20,10),x(237,125,49),x(248,238,230)),classic:ae(x(240,240,240),x(0,0,0),J,J,x(212,212,212),x(204,232,255),x(0,0,0),x(16,124,65),x(242,242,242)),dark:ae(x(45,45,48),x(230,230,230),x(30,30,30),x(37,37,38),x(63,63,70),x(38,79,120),J,x(86,156,214),x(42,42,46),x(170,170,170),x(25,25,26),x(220,220,220)),modern:ae(J,x(71,85,105),J,x(248,250,252),x(226,232,240),x(219,234,254),x(15,23,42),x(37,99,235),x(241,245,249),x(71,85,105),J,x(30,41,59),!0),teal:ae(x(240,253,250),x(17,94,89),J,x(248,252,251),x(204,231,226),x(204,251,241),x(4,47,46),x(13,148,136),x(240,247,246),x(55,95,91),J,x(30,41,59),!0),purple:ae(x(245,243,255),x(76,29,149),J,x(250,249,255),x(226,222,245),x(237,233,254),x(46,16,101),x(124,58,237),x(245,243,250),x(88,70,130),J,x(30,41,59),!0),rose:ae(x(255,241,242),x(159,18,57),J,x(255,250,250),x(244,220,225),x(255,228,230),x(76,5,25),x(225,29,72),x(250,244,245),x(120,60,75),J,x(30,41,59),!0),midnight:ae(x(30,41,59),x(203,213,225),x(15,23,42),x(20,30,50),x(45,58,80),x(30,64,120),J,x(96,165,250),x(24,34,54),x(148,163,184),x(11,17,32),x(226,232,240),!0),nox:ae(x(17,26,54),x(199,210,234),x(10,16,34),x(13,21,48),x(34,48,90),x(14,58,92),J,x(34,211,238),x(15,23,48),x(138,151,182),x(6,10,24),x(232,237,247),!0)},Rr=Object.keys($e);var Fr=`
|
|
24
|
+
.nox-grid{position:relative;overflow:hidden;width:100%;height:100%;box-sizing:border-box;user-select:none;-webkit-user-select:none;font-family:"Malgun Gothic","Apple SD Gothic Neo","Segoe UI",system-ui,sans-serif;font-size:13px}
|
|
25
|
+
.nox-grid-scroller{position:absolute;inset:0;overflow:auto;outline:none}
|
|
26
|
+
.nox-grid-spacer{position:relative;pointer-events:auto}
|
|
27
|
+
.nox-grid-canvas{position:absolute;left:0;top:0;pointer-events:none}
|
|
28
|
+
.nox-grid-input{position:absolute;left:0;top:0;margin:0;padding:3px 6px;box-sizing:border-box;border:2px solid transparent;resize:none;overflow:hidden;opacity:0;pointer-events:none;outline:none;white-space:pre-wrap;line-height:1.35;z-index:2;background:transparent}
|
|
29
|
+
.nox-grid-input.editing{opacity:1;pointer-events:auto;box-shadow:0 2px 8px rgba(15,23,42,.18)}
|
|
30
|
+
.nox-grid-popup-editor{position:absolute;left:0;top:0;margin:0;box-sizing:border-box;border:2px solid;z-index:3;padding:0 4px;outline:none}
|
|
31
|
+
.nox-grid-celltip{position:absolute;left:0;top:0;z-index:5;max-width:420px;padding:4px 8px;border-radius:4px;border:1px solid;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,.15);pointer-events:none;white-space:pre-wrap;word-break:break-all}
|
|
32
|
+
.nox-grid-tip{position:absolute;left:0;top:0;z-index:5;max-width:280px;padding:5px 9px;border-radius:4px;background:#fff1f2;color:#9f1239;border:1px solid #fda4af;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,.12);pointer-events:none;white-space:pre-wrap}
|
|
33
|
+
.nox-grid-filter{position:absolute;left:0;top:0;z-index:6;width:230px;padding:8px;box-sizing:border-box;background:#fff;color:#111827;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 8px 24px rgba(15,23,42,.18);font-size:12.5px;user-select:none}
|
|
34
|
+
.nox-grid-filter-title{font-weight:600;margin:0 2px 6px}
|
|
35
|
+
.nox-grid-filter-sort{display:flex;gap:4px;margin-bottom:6px}
|
|
36
|
+
.nox-grid-filter-sort button{flex:1}
|
|
37
|
+
.nox-grid-filter input[type=search]{width:100%;box-sizing:border-box;padding:4px 6px;border:1px solid #d1d5db;border-radius:4px;margin-bottom:6px;font:inherit}
|
|
38
|
+
.nox-grid-filter-list{max-height:220px;overflow:auto;border:1px solid #e5e7eb;border-radius:4px;padding:4px}
|
|
39
|
+
.nox-grid-filter-list label{display:block;padding:2px 2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
|
|
40
|
+
.nox-grid-filter-actions{display:flex;justify-content:flex-end;gap:6px;margin-top:8px}
|
|
41
|
+
.nox-grid-filter button{font:inherit;padding:4px 10px;border:1px solid #d1d5db;border-radius:4px;background:#f9fafb;color:inherit;cursor:pointer}
|
|
42
|
+
.nox-grid-filter button.primary{background:#2563eb;border-color:#2563eb;color:#fff}
|
|
43
|
+
.nox-grid-find{position:absolute;right:16px;top:6px;z-index:7;width:300px;padding:8px;box-sizing:border-box;background:#fff;color:#111827;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 8px 24px rgba(15,23,42,.18);font-size:12.5px;user-select:none}
|
|
44
|
+
.nox-grid-find .row{display:flex;gap:4px;margin-bottom:6px}
|
|
45
|
+
.nox-grid-find input[type=search],.nox-grid-find input[type=text]{flex:1;min-width:0;padding:4px 6px;border:1px solid #d1d5db;border-radius:4px;font:inherit}
|
|
46
|
+
.nox-grid-find button{font:inherit;padding:3px 8px;border:1px solid #d1d5db;border-radius:4px;background:#f9fafb;color:inherit;cursor:pointer}
|
|
47
|
+
.nox-grid-find .opts{display:flex;gap:10px;flex-wrap:wrap}
|
|
48
|
+
.nox-grid-find .opts label{display:flex;gap:3px;align-items:center;cursor:pointer}
|
|
49
|
+
.nox-grid-find input{user-select:text}
|
|
50
|
+
.nox-grid-find .status{color:#6b7280;margin-top:4px;min-height:1em}
|
|
51
|
+
`,To=!1;function jt(){if(To||typeof document=="undefined")return;To=!0;let r=document.createElement("style");r.setAttribute("data-nox-grid",""),r.textContent=Fr,document.head.appendChild(r)}function Sn(r){var e,t;return r.error!=null?(e=C.fromCode(r.error))!=null?e:r.error:r.number!=null?r.number:r.bool!=null?r.bool:r.date!=null?Tr(r.date):(t=r.text)!=null?t:null}function Tr(r){let e=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?)?$/.exec(r);return e?new Date(+e[1],+e[2]-1,+e[3],e[4]?+e[4]:0,e[5]?+e[5]:0,e[6]?+e[6]:0):new Date(r)}function Nr(r){let e=(t,n=2)=>String(t).padStart(n,"0");return`${e(r.getFullYear(),4)}-${e(r.getMonth()+1)}-${e(r.getDate())}T${e(r.getHours())}:${e(r.getMinutes())}:${e(r.getSeconds())}`}function Xt(r,e){e==null||e===""||(typeof e=="number"?r.number=e:typeof e=="boolean"?r.bool=e:e instanceof Date?r.date=Nr(e):e instanceof C?r.error=e.code:r.text=String(e))}function No(r){if(!r)return;let e={};for(let[t,n]of Object.entries(r))n!=null&&(e[t]=n);return Object.keys(e).length?e:void 0}function Yt(r,e,t={}){var d,f,m,p,b,g,w,S,v,k,R,D,z,_;let n=(d=t.headerRow)!=null?d:!0,o=(f=t.detectKinds)!=null?f:!0,i=n?1:0,s=(m=e.cells)!=null?m:[],l=Math.max((p=e.columnCount)!=null?p:0,...s.map(P=>P.col+1),0),a=Math.max((b=e.rowCount)!=null?b:0,...s.map(P=>P.row+1),i),u=new Map(((g=e.columns)!=null?g:[]).map(P=>[P.index,P])),c=[];for(let P=0;P<l;P++){if(!o){c.push("text");continue}let E=0,A=0,F=0,V=0;for(let L of s)L.col!==P||L.row<i||(L.number!=null?E++:L.date!=null?A++:L.bool!=null?F++:L.text!=null&&L.text!==""&&V++);c.push(V>0?"text":A>0&&E===0&&F===0?"date":F>0&&E===0&&A===0?"check":E>0&&A===0&&F===0?"number":"text")}let h=r.undo.enabled;r.undo.enabled=!1;try{r.columns=[],r.merges=[],r.filters.clear(),r.sortSpecs=[],r.setData(null),r.sheetName=(w=e.name)!=null?w:null;let P=E=>{if(!n)return Me(E);let A=s.find(V=>V.row===0&&V.col===E),F=A?Sn(A):null;return F==null?Me(E):String(F)};for(let E=0;E<l;E++){let A=u.get(E);r.columns.push(new we({name:Me(E),header:(S=A==null?void 0:A.header)!=null?S:P(E),kind:c[E],width:(v=A==null?void 0:A.width)!=null?v:c[E]==="check"?60:100,visible:!(A!=null&&A.hidden),format:(k=A==null?void 0:A.format)!=null?k:void 0}))}r.rowCount=a-i;for(let E of s){let A=E.row-i;if(A<0||E.col>=l)continue;let F=Sn(E);F!=null&&r.setValue(A,E.col,c[E.col]==="check"&&F===null?!1:F);let V=No(E.style);if(V&&r.setCellStyle(A,E.col,V),E.formula){let L=he.tryParse(E.formula);L&&(i>0&&L.removeRows(()=>!0,0,i),r.setFormula(A,E.col,L))}}for(let E of(R=e.rows)!=null?R:[]){let A=E.index-i;A<0||A>=r.rowCount||(E.height&&r.setRowHeight(A,E.height),E.hidden&&r.setRowHidden(A,!0))}for(let E of(D=e.merges)!=null?D:[]){let A=E.row-i,F=E.rowSpan;A<0&&(F+=A,A=0),F*E.colSpan>1&&F>0&&r.addMerge({row:A,col:E.col,rowSpan:F,colSpan:E.colSpan})}}finally{r.undo.enabled=h,r.undo.clear()}return r.layoutChanged(),{frozenRows:Math.max(0,((z=e.frozenRows)!=null?z:0)-i),frozenColumns:(_=e.frozenColumns)!=null?_:0,autoFilter:!!e.autoFilter}}function qt(r,e={}){var h,d,f,m,p,b,g;let t=(h=e.headerRow)!=null?h:!0,n=r.columns,o=t?Ie(n.map(w=>w.group),-1):{levels:0,depth:[],cells:[]},i=t?o.levels+1:0,s=[],l=[];if(t){n.forEach((w,S)=>{var R;let v=(R=o.depth[S])!=null?R:0,k={row:v,col:S,style:{bold:!0}};Xt(k,w.header),s.push(k),v<o.levels&&l.push({row:v,col:S,rowSpan:o.levels-v+1,colSpan:1})});for(let w of o.cells){let S={row:w.level,col:w.u0,style:{bold:!0,align:"center"}};Xt(S,w.text),s.push(S),w.u1>w.u0&&l.push({row:w.level,col:w.u0,rowSpan:1,colSpan:w.u1-w.u0+1})}}for(let w=0;w<r.rowCount;w++)for(let S=0;S<n.length;S++){let v=r.formulaAt(w,S),k=r.getValue(w,S),R=No(r.getCellStyle(w,S)),D=k==null||k===""||n[S].kind==="check"&&k===!1&&!v;if(D&&!v&&!R)continue;let z={row:w+i,col:S};if(D||Xt(z,k),v){let _=v.clone();i>0&&_.insertRows(()=>!0,0,i),z.formula=_.toString()}R&&(z.style=R),s.push(z)}let a=[];for(let w=0;w<r.rowCount;w++){let S=r.rows[w];S&&(S.height!==void 0||S.hidden)&&a.push({index:w+i,height:(d=S.height)!=null?d:null,hidden:!!S.hidden})}let u=(f=e.footer)!=null&&f.some(w=>w)?e.footer:void 0;if(u){let w=r.rowCount+i;u.forEach((S,v)=>{if(!S)return;let k={row:w,col:v,style:{bold:!0}};S.value!==null&&S.value!==void 0&&Xt(k,S.value),S.formula&&(k.formula=S.formula),s.push(k)})}let c=(m=e.autoFilter)!=null?m:!1;return{name:(p=r.sheetName)!=null?p:"Sheet1",rowCount:r.rowCount+i+(u?1:0),columnCount:n.length,columns:n.map((w,S)=>{var v;return{index:S,header:w.header,width:w.width,hidden:!w.visible,format:(v=w.format)!=null?v:null}}),rows:a,cells:s,merges:[...l,...r.merges.map(w=>({...w,row:w.row+i}))],frozenRows:((b=e.frozenRows)!=null?b:0)+i,frozenColumns:(g=e.frozenColumns)!=null?g:0,autoFilter:c,autoFilterRange:c&&n.length&&(i>1||u)?`${ze(Math.max(0,i-1),0)}:${ze(Math.max(i-1,r.rowCount+i-1),n.length-1)}`:null}}function yt(r){return r<10?"0"+r:String(r)}function Vr(r){if(r==null)return"";if(typeof r=="boolean")return r?"true":"false";if(r instanceof Date){let e=`${r.getFullYear()}-${yt(r.getMonth()+1)}-${yt(r.getDate())}`;return r.getHours()||r.getMinutes()||r.getSeconds()?`${e} ${yt(r.getHours())}:${yt(r.getMinutes())}:${yt(r.getSeconds())}`:e}return String(r)}function Mn(r,e={}){var a,u;let t=typeof e=="string"?{delimiter:e}:e,n=(a=t.delimiter)!=null?a:",",o=t.columns?t.columns.map(c=>r.columnIndex(c)).filter(c=>c>=0).map(c=>({c:r.columns[c],i:c})):r.columns.map((c,h)=>({c,i:h})).filter(c=>c.c.visible),i=c=>c.includes(n)||c.includes('"')||c.includes(`
|
|
52
|
+
`)||c.includes("\r")?`"${c.replace(/"/g,'""')}"`:c,s=[];t.headers!==!1&&s.push(o.map(c=>i(Fo(c.c))).join(n));let l=t.visibleRowsOnly!==!1;for(let c=0;c<r.rowCount;c++)l&&!r.isRowVisible(c)||t.subtotals===!1&&((u=r.rows[c])!=null&&u.subtotal)||s.push(o.map(h=>{let d=r.getValue(c,h.i);return t.raw?i(Vr(d)):i(h.c.kind==="check"?d?"TRUE":"FALSE":h.c.text(d,r.getCellStyle(c,h.i)))}).join(n));return s.join(`\r
|
|
53
|
+
`)+`\r
|
|
54
|
+
`}function Qt(r,e){let t=r.columns[e];if(!t||t.footer==="none")return null;if(t.footer==="text")return typeof t.footerText!="function"?t.footerText:t.footerText({visibleRowCount:r.visibleRows().length,rowCount:r.rowCount});let n=0,o=0,i=0,s=null,l=null,a=null,u=null;for(let c=0;c<r.rowCount;c++){let h=r.rows[c];if(h&&(h.hidden||h.filtered||h.subtotal))continue;let d=r.getValue(c,e);if(!(d==null||d==="")){if(n++,ye(d)){(!a||d<a)&&(a=d),(!u||d>u)&&(u=d);continue}typeof d!="number"||!Number.isFinite(d)||(o++,i+=d,(s===null||d<s)&&(s=d),(l===null||d>l)&&(l=d))}}switch(t.footer){case"count":return n;case"sum":return o?Hr(i):null;case"avg":return o?i/o:null;case"min":return o?s:a;case"max":return o?l:u;default:return null}}function Hr(r){return Math.round(r*1e10)/1e10}function Vo(r,e,t){var i;let n=r.columns[e];if(t==null)return"";if(typeof t=="string")return t;let o=(i=n.footerFormat)!=null?i:n.footer==="count"?"#,##0":n.format;return ke(t,o)}var Dr='"Malgun Gothic", "Apple SD Gothic Neo", "Segoe UI", system-ui, sans-serif',xt=class{constructor(e,t={}){this.model=new dt;this.emitter=new Tt;this.frame=0;this.destroyed=!1;this._rowHeight=26;this._headerHeight=30;this._footerVisible=!1;this.footerCache=null;this.footerBusy=!1;this._rowHeaderWidth=46;this._rowHeadersVisible=!0;this._columnHeadersVisible=!0;this._frozenRows=0;this._frozenColumns=0;this._readOnly=!1;this._scheme="default";this.colors={...$e.default};this.alternatingRows=!0;this._verticalGridLines=!0;this.ownVerticalGridLines=!1;this.horizontalGridLines=!0;this.fontFamily=Dr;this.fontSize=13;this.headerBold=!1;this.allowSort=!0;this.allowFilter=!1;this.allowColumnResize=!0;this.allowEdit=!0;this.allowFind=!0;this.findPanel=null;this.allowUserFormulas=!1;this.showValidationErrors=!0;this.formulaClip=null;this.cur={row:0,col:0};this.anchor={row:0,col:0};this._sel={row:0,col:0,row2:0,col2:0};this._selectionMode="cell";this.selectionShown=!0;this._hoverRow=!1;this._captureFind="grid";this.offPageFind=null;this.showCellToolTips=!1;this.pasteAddsRows=!1;this._emptyMessage="";this._selectionKeepsBackColors=!1;this.selectionOverridesCellColors=!1;this.cellTipEl=null;this.cellTipTimer=0;this.cellTipAt=null;this.measureCtx=null;this.editing=!1;this.enterMode=!1;this.composing=!1;this.editRow=-1;this.editCol=-1;this.popupEditor=null;this.drag=null;this.autoScroll=0;this.lastPointer={x:0,y:0};this.hover=null;this.tipEl=null;this.tipCell=null;this.tipTimer=0;this.filterPopup=null;this.dprQuery=null;this.offLicense=()=>{};this.updateCount=0;this._sortCycle="ascDesc";this.valueChangedDepth=0;this._autoHeight=!1;this._maxHeight=0;this.onDprChange=()=>{this.resize(),this.watchDpr()};this.touchStart=null;this.onDocPointerDown=e=>{this.filterPopup&&!this.filterPopup.contains(e.target)&&this.closeFilterPopup()};jt(),t.locale&&Ct(t.locale),this.host=e,this.conditionalFormats=new nt(this.model,()=>this.invalidate()),this.columns=new ft(this);let n=this.root=document.createElement("div");n.className="nox-grid";let o=this.scroller=document.createElement("div");o.className="nox-grid-scroller";let i=this.spacer=document.createElement("div");i.className="nox-grid-spacer",o.appendChild(i);let s=this.canvas=document.createElement("canvas");s.className="nox-grid-canvas";let l=this.input=document.createElement("textarea");l.className="nox-grid-input",l.setAttribute("autocomplete","off"),l.setAttribute("autocorrect","off"),l.setAttribute("autocapitalize","off"),l.setAttribute("spellcheck","false"),l.setAttribute("aria-label",N().editCell),l.tabIndex=0,n.append(o,s,l),e.appendChild(n),this.renderer=new _t(this),this.model.onChange=a=>{this.footerCache=null,a!=="value"&&this.hideTip(),a!=="layout"&&this.conditionalFormats.invalidate(),a==="layout"&&this.updateCount===0&&this.updateScrollSize(),this.invalidate()},this.model.isNestedChange=()=>this.valueChangedDepth>0,this.model.onValueChanged=(a,u,c,h,d,f)=>{if(this.tipCell&&this.tipCell.row===a&&this.tipCell.col===u&&this.hideTip(),!this.emitter.has("cellValueChanged"))return;let m=f!=null?f:this.valueChangedDepth>0;this.valueChangedDepth++;try{if(typeof h=="function"){let p=h,b={row:a,col:u,oldValue:c,source:d,nested:m};Object.defineProperty(b,"newValue",{get:p,enumerable:!0}),this.emitter.emit("cellValueChanged",b)}else this.emitter.emit("cellValueChanged",{row:a,col:u,oldValue:c,newValue:h,source:d,nested:m})}finally{this.valueChangedDepth--}},this.applyOptions(t),this.offLicense=Ln(()=>this.invalidate()),this.attachEvents(),this.updateScrollSize(),this.resize()}get verticalGridLines(){return this._verticalGridLines}set verticalGridLines(e){this._verticalGridLines=e,this.ownVerticalGridLines=!0,this.invalidate()}get sel(){let e=this._sel;return this._selectionMode==="fullRow"?{row:e.row,col:0,row2:e.row2,col2:Math.max(0,this.model.columns.length-1)}:e}set sel(e){this._sel=e}get selectionMode(){return this._selectionMode}set selectionMode(e){this._selectionMode=e==="fullRow"?"fullRow":"cell",this.invalidate()}get captureFind(){return this._captureFind}set captureFind(e){var t;if(this._captureFind=e==="page"?"page":"grid",(t=this.offPageFind)==null||t.call(this),this.offPageFind=null,this._captureFind==="page"&&!this.destroyed){let n=this;this.offPageFind=In({root:this.root,get findAllowed(){return n.allowFind},openFind:()=>n.showFindDialog(!1)})}}get emptyMessage(){return this._emptyMessage}set emptyMessage(e){this._emptyMessage=e!=null?e:"",this._autoHeight&&this.updateScrollSize(),this.invalidate()}get selectionKeepsBackColors(){return this._selectionKeepsBackColors}set selectionKeepsBackColors(e){this._selectionKeepsBackColors=!!e,this.invalidate()}headerCheckState(e){var i;let t=this.model.columnIndex(e),n=0,o=0;for(let s=0;s<this.model.rowCount;s++)if(!((i=this.model.rows[s])!=null&&i.subtotal||!this.model.isRowVisible(s))&&(this.model.getValue(s,t)?n++:o++,n&&o))return"mixed";return n&&!o?"on":"off"}toggleHeaderCheck(e){if(this._readOnly)return;let t=this.headerCheckState(e)!=="on",n={col:e,checked:t,cancel:!1};this.emitter.emit("headerCheckChanging",n),!n.cancel&&(this.withSource("toggle",()=>this.setAllChecked(e,t)),this.emitter.emit("headerCheckChanged",{col:e,checked:t}),this.invalidate())}hideSelection(){this.selectionShown=!1,this.invalidate()}get rowKey(){return this.model.rowKeyField}set rowKey(e){this.model.rowKeyField=e||void 0}getRowKey(e){return this.model.rowKeyOf(e)}setRowKey(e,t){e<0||e>=this.model.rowCount||(this.model.row(e,!0).key=t)}indexOfKey(e){let t=this.model.rowCount;for(let n=0;n<t;n++)if(this.model.rowKeyOf(n)===e)return n;return-1}setAllChecked(e,t,n={}){let o=this.model.columnIndex(e);if(o<0||this.model.columns[o].kind!=="check")return 0;let i=n.visibleOnly!==!1,s=0;return this.endEdit(!0),this.batch(()=>{var l;for(let a=0;a<this.model.rowCount;a++)(l=this.model.rows[a])!=null&&l.subtotal||i&&!this.model.isRowVisible(a)||this.isCellReadOnly(a,o)&&!this._readOnly||!!this.model.getValue(a,o)!==t&&this.model.setValue(a,o,t)&&s++}),s}get newRowData(){return this.model.newRowData}set newRowData(e){this.model.newRowData=e}getColors(){return{...this.colors}}getCellRect(e,t){let n=this.model.columnIndex(t);if(n<0||e<0||e>=this.model.rowCount||!this.model.columns[n].visible||!this.model.isRowVisible(e))return null;let o=this.layout(),i=this.cellRect(e,n,o);if(!i)return null;let s=Math.max(i.x,o.rowHeaderW),l=Math.max(i.y,o.headerH),a=Math.min(i.x+i.w,o.width),u=Math.min(i.y+i.h,o.bodyBottom);return a<=s||u<=l?null:{x:i.x,y:i.y,width:i.w,height:i.h}}getHeaderRect(e){let t=this.model.columnIndex(e);if(t<0||!this.model.columns[t].visible||!this._columnHeadersVisible)return null;let n=this.layout(),o=this.model.colAxis.visual(t),i=this.colX(o,n),s=this.model.colAxis.sizeAt(o);if(i+s<=n.rowHeaderW||i>=n.width)return null;let l=this.leafTop(o,n);return{x:i,y:l,width:s,height:n.headerH-l}}setQuickFilter(e,t={}){let n=(e!=null?e:"").trim().toLowerCase(),o=t.columns?t.columns.map(i=>this.model.columnIndex(i)).filter(i=>i>=0):null;this.model.quickFilter=n?{text:n,cols:o}:null,this.model.applyFilters(),this.clampSelection(),this.emitter.emit("filtered",{col:-1})}get quickFilter(){var e,t;return(t=(e=this.model.quickFilter)==null?void 0:e.text)!=null?t:""}get visibleRowCount(){return this.model.visibleRows().length}visibleRows(){return this.model.visibleRows()}cellTipText(e,t){var h,d,f,m,p,b,g,w;let n=this.model.columns[t];if(!n)return"";if(n.toolTip)return(m=n.toolTip((f=(h=this.model.data)==null?void 0:h[e])!=null?f:(d=this.model.rows[e])==null?void 0:d.data,e))!=null?m:"";if(!this.showCellToolTips||n.kind==="check"||n.kind==="image"||n.kind==="button")return"";let o=n.text(this.model.getValue(e,t),this.model.getCellStyle(e,t));if(!o)return"";let i=this.cellRect(e,t);if(!i)return"";(p=this.measureCtx)!=null||(this.measureCtx=document.createElement("canvas").getContext("2d"));let s=this.measureCtx;if(!s)return"";let l=this.model.getCellStyle(e,t);s.font=`${l!=null&&l.bold||n.bold?"bold ":""}${(b=l==null?void 0:l.fontSize)!=null?b:this.fontSize}px ${(g=l==null?void 0:l.fontFamily)!=null?g:this.fontFamily}`;let a=i.w-12,u=o.split(`
|
|
55
|
+
`),c=Math.max(...u.map(S=>s.measureText(S).width));if(n.wrapText||u.length>1){let S=((w=l==null?void 0:l.fontSize)!=null?w:this.fontSize)*1.35,v=Math.max(1,Math.floor((i.h-4)/S));return u.reduce((R,D)=>R+Math.max(1,Math.ceil(s.measureText(D).width/Math.max(1,a))),0)>v?o:""}return c>a?o:""}headerTipText(e){var s,l;let t=this.model.columns[e];if(!t)return"";if(t.headerToolTip)return(s=typeof t.headerToolTip=="function"?t.headerToolTip(e):t.headerToolTip)!=null?s:"";if(!this.showCellToolTips||!t.header)return"";let n=this.getHeaderRect(e);if(!n)return"";(l=this.measureCtx)!=null||(this.measureCtx=document.createElement("canvas").getContext("2d"));let o=this.measureCtx;if(!o)return"";o.font=`${this.headerBold?"bold ":""}${this.fontSize}px ${this.fontFamily}`;let i=n.width-12-(this.allowFilter&&t.filterable?18:0);return o.measureText(t.header).width>i?t.header:""}scheduleCellTip(e){let t=e.area==="colHeader"&&e.col>=0&&e.resizeCol===void 0&&!e.filterButton,n=t?-1:e.row;if(this.cellTipAt&&(e.area==="cell"||t)&&this.cellTipAt.row===n&&this.cellTipAt.col===e.col||(this.hideCellTip(),e.area!=="cell"&&!t))return;let i=this.model.columns[e.col];if(t?!(i!=null&&i.headerToolTip)&&!this.showCellToolTips:!(i!=null&&i.toolTip)&&!this.showCellToolTips)return;this.cellTipAt={row:n,col:e.col};let s=this.lastPointer.x,l=this.lastPointer.y;this.cellTipTimer=window.setTimeout(()=>{let a=this.cellTipAt;if(!a||this.drag||this.editing)return;let u=a.row<0?this.headerTipText(a.col):this.cellTipText(a.row,a.col);if(!u)return;let c=this.cellTipEl=document.createElement("div");c.className="nox-grid-celltip",c.textContent=u;let h=this.colors;c.style.background=h.cellBack,c.style.color=h.fore,c.style.borderColor=h.gridLine,c.style.fontFamily=this.fontFamily,this.root.appendChild(c);let d=this.root.clientWidth,f=Math.max(0,Math.min(s+12,d-c.offsetWidth-4));c.style.transform=`translate(${f}px, ${l+18}px)`},450)}hideCellTip(){var e;clearTimeout(this.cellTipTimer),(e=this.cellTipEl)==null||e.remove(),this.cellTipEl=null,this.cellTipAt=null}get hoverRow(){return this._hoverRow}set hoverRow(e){this._hoverRow=e,this.invalidate()}get hoverRowIndex(){let e=this.hover;return e&&(e.area==="cell"||e.area==="rowHeader")?e.row:-1}get hoverCell(){let e=this.hover;return e&&e.area==="cell"?{row:e.row,col:e.col}:null}applyOptions(e){var t;e.rowHeight&&(this._rowHeight=this.model.defaultRowHeight=e.rowHeight),e.headerHeight&&(this._headerHeight=e.headerHeight),e.footerVisible!==void 0&&(this._footerVisible=e.footerVisible),e.rowHeaderWidth&&(this._rowHeaderWidth=e.rowHeaderWidth),e.rowHeadersVisible!==void 0&&(this._rowHeadersVisible=e.rowHeadersVisible),e.columnHeadersVisible!==void 0&&(this._columnHeadersVisible=e.columnHeadersVisible),e.fontFamily&&(this.fontFamily=e.fontFamily),e.fontSize&&(this.fontSize=e.fontSize),e.readOnly!==void 0&&(this._readOnly=e.readOnly),e.alternatingRows!==void 0&&(this.alternatingRows=e.alternatingRows),e.allowSort!==void 0&&(this.allowSort=e.allowSort),e.allowFilter!==void 0&&(this.allowFilter=e.allowFilter),e.allowColumnResize!==void 0&&(this.allowColumnResize=e.allowColumnResize),e.allowEdit!==void 0&&(this.allowEdit=e.allowEdit),e.showValidationErrors!==void 0&&(this.showValidationErrors=e.showValidationErrors),e.allowUserFormulas!==void 0&&(this.allowUserFormulas=e.allowUserFormulas),e.allowFind!==void 0&&(this.allowFind=e.allowFind),e.locale&&Ct(e.locale),e.sheetName&&(this.model.sheetName=e.sheetName),e.undoLimit&&(this.model.undo.limit=e.undoLimit),this.model.undo.enabled=!1;for(let n of(t=e.columns)!=null?t:[])this.model.columns.push(new we(n));e.data?this.model.setData(e.data):e.rowCount&&(this.model.rowCount=e.rowCount),this.model.undo.enabled=e.allowUndo!==!1,this.model.undo.clear(),e.colorScheme&&(this.colorScheme=e.colorScheme),e.verticalGridLines!==void 0&&(this.verticalGridLines=e.verticalGridLines),e.horizontalGridLines!==void 0&&(this.horizontalGridLines=e.horizontalGridLines),e.frozenRows&&(this._frozenRows=e.frozenRows),e.frozenColumns&&(this._frozenColumns=e.frozenColumns),e.maxHeight&&(this._maxHeight=e.maxHeight),e.sortCycle&&(this.sortCycle=e.sortCycle),e.selectionMode&&(this._selectionMode=e.selectionMode==="fullRow"?"fullRow":"cell"),e.initialSelection==="none"&&(this.selectionShown=!1),e.hoverRow&&(this._hoverRow=!0),e.captureFind&&(this.captureFind=e.captureFind),e.showCellToolTips&&(this.showCellToolTips=!0),e.pasteAddsRows&&(this.pasteAddsRows=!0),e.emptyMessage&&(this.emptyMessage=e.emptyMessage),e.selectionKeepsBackColors&&(this.selectionKeepsBackColors=!0),e.rowKey&&(this.model.rowKeyField=e.rowKey),e.newRowData&&(this.model.newRowData=e.newRowData),e.selectionOverridesCellColors&&(this.selectionOverridesCellColors=!0),e.autoHeight&&(this._autoHeight=!0),this.model.layoutChanged()}get rowCount(){return this.model.rowCount}set rowCount(e){let t=this.model.undo.enabled;this.model.undo.enabled=!1,this.model.rowCount=e,this.model.undo.enabled=t,this.clampSelection()}get columnCount(){return this.model.columns.length}get rowHeight(){return this._rowHeight}set rowHeight(e){this._rowHeight=this.model.defaultRowHeight=Math.max(8,e),this.model.layoutChanged()}get headerHeight(){return this._headerHeight}set headerHeight(e){this._headerHeight=Math.max(8,e),this.updateScrollSize(),this.invalidate()}get footerVisible(){return this._footerVisible}set footerVisible(e){this._footerVisible!==e&&(this._footerVisible=e,this.footerCache=null,this.updateScrollSize(),this.invalidate())}getFooterValue(e){var o;let t=this.model.columnIndex(e);if(t<0)return null;this.ensureFooter();let n=this.footerCache;return n&&n.has(t)?(o=n.get(t))!=null?o:null:Qt(this.model,t)}footerTextOf(e){let t=this.model.columns[e];return!t||t.footer==="none"?"":Vo(this.model,e,this.getFooterValue(e))}refreshFooter(){this.footerCache=null,this.invalidate()}ensureFooter(){var t;if(this.footerCache||this.footerBusy)return;this.footerBusy=!0;let e=new Map;try{let n=this.model.columns;for(let o=0;o<n.length;o++){if(n[o].footer==="none")continue;let i={col:o,value:Qt(this.model,o)};this.emitter.has("footerValue")&&this.emitter.emit("footerValue",i),e.set(o,(t=i.value)!=null?t:null)}this.footerCache=e}finally{this.footerBusy=!1}}headerGroups(){let e=this.model.colAxis,t=[];for(let n=0;n<e.visibleCount;n++)t.push(this.model.columns[e.physical(n)].group);return Ie(t,Math.min(this._frozenColumns,e.visibleCount))}leafTop(e,t){var n;return t.groups.levels===0?0:((n=t.groups.depth[e])!=null?n:0)*t.headerRowH}get rowHeadersVisible(){return this._rowHeadersVisible}set rowHeadersVisible(e){this._rowHeadersVisible=e,this.updateScrollSize(),this.invalidate()}get columnHeadersVisible(){return this._columnHeadersVisible}set columnHeadersVisible(e){this._columnHeadersVisible=e,this.updateScrollSize(),this.invalidate()}get frozenRows(){return this._frozenRows}set frozenRows(e){this._frozenRows=Math.max(0,e),this.invalidate()}get frozenColumns(){return this._frozenColumns}set frozenColumns(e){this._frozenColumns=Math.max(0,e),this.invalidate()}get readOnly(){return this._readOnly}set readOnly(e){this._readOnly=e,e&&this.endEdit(!1)}get colorScheme(){return this._scheme}set colorScheme(e){var n;let t=(n=$e[e])!=null?n:$e.default;this._scheme=$e[e]?e:"default",this.colors={...t},this.headerBold=t.modern,this.ownVerticalGridLines||(this._verticalGridLines=!t.modern),this.root.style.background=t.back,this.invalidate()}setColors(e){Object.assign(this.colors,e),this.root.style.background=this.colors.back,this.invalidate()}get alternatingRowColors(){return this.alternatingRows}set alternatingRowColors(e){this.alternatingRows=e,this.invalidate()}getValue(e,t){return this.model.getValue(e,this.model.columnIndex(t))}setValue(e,t,n){let o=this.model.columnIndex(t);this.model.setValue(e,o,n)}getText(e,t){let n=this.model.columnIndex(t),o=this.model.columns[n];return o?o.text(this.model.getValue(e,n),this.model.getCellStyle(e,n)):""}cells(e,t){return new mt(this,e,this.model.columnIndex(t))}range(e,t,n,o){return new Qe(this,e,this.model.columnIndex(t),n,this.model.columnIndex(o))}setValues(e,t,n){this.beginUpdate();try{this.model.undo.transaction(()=>{let o=this.model.rowCount,i=this.model.columns.length;for(let s=0;s<n.length&&e+s<o;s++)for(let l=0;l<n[s].length&&t+l<i;l++)this.model.setValue(e+s,t+l,n[s][l])})}finally{this.endUpdate()}}getValues(e,t,n,o){let i=[];for(let s=0;s<n;s++){let l=[];for(let a=0;a<o;a++)l.push(this.model.getValue(e+s,t+a));i.push(l)}return i}clearRange(e,t,n,o){this.setValues(e,t,Array.from({length:n},()=>new Array(o).fill(null)))}setText(e,t,n){let o=this.model.columnIndex(t),i=this.model.columns[o];if(!i)throw new RangeError(`\uC5F4\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${String(t)}`);let s=i.parse(n);if(s===void 0)throw new TypeError(`${i.header||i.name}: "${n}" \uB97C \uBC14\uAFC0 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.`);this.model.setValue(e,o,s)}setFormula(e,t,n){let o=this.model.columnIndex(t);if(o<0)throw new RangeError(`\uC5F4\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${String(t)}`);let i=n&&n.trim()?he.parse(n):null;this.model.setFormula(e,o,i)}getFormula(e,t){let n=this.model.formulaAt(e,this.model.columnIndex(t));return n?n.toString():null}hasFormula(e,t){return!!this.model.formulaAt(e,this.model.columnIndex(t))}evaluate(e){return he.parse(e).evaluateOnce(this.model.formulaSheet,this.cur.row,this.cur.col)}recalculate(){Z(),this.conditionalFormats.invalidate(),this.invalidate()}get sheetName(){return this.model.sheetName}set sheetName(e){this.model.sheetName=e,Z(),this.invalidate()}toPrintHtml(e={}){return bt([{title:e.title,table:gt(this,e)}],e)}print(e={}){return this.endEdit(!0),wt(this.toPrintHtml(e))}findNext(e,t={}){return this.endEdit(!0),pt(this,e,t)}replace(e,t,n={}){return this.endEdit(!0),vn(this,e,t,n)}replaceAll(e,t,n={}){return this.endEdit(!0),Cn(this,e,t,n)}showFindDialog(e=!1){var t;this.endEdit(!0),(t=this.findPanel)!=null||(this.findPanel=new Kt(this)),this.findPanel.open(e)}groupRows(e,t){this.endEdit(!0),qe(this.model,e,t,1),this.afterOutline()}ungroupRows(e,t){this.endEdit(!0),qe(this.model,e,t,-1),this.afterOutline()}collapseGroup(e,t){let n=xn(this.model,e,t);return n?(Wt(this.model,n,!0),this.afterOutline(),!0):!1}expandGroup(e,t){let n=xn(this.model,e,t);return n?(Wt(this.model,n,!1),this.afterOutline(),!0):!1}showOutlineLevel(e){wo(this.model,e),this.afterOutline()}get outlineLevels(){return this.model.outlineLevels}addSubtotals(e){this.endEdit(!0);let t=this.model.columnIndex(e.groupBy),n=e.columns.map(s=>this.model.columnIndex(s)).filter(s=>s>=0);if(t<0||!n.length)return 0;let o={groupBy:t,columns:n,function:e.function,grandTotal:e.grandTotal,backColor:e.backColor},i=this.model.undo.transaction(()=>(e.sortFirst&&this.model.sort([{col:t,order:"asc"}]),yo(this.model,o)));return this.afterOutline(),i}removeSubtotals(){this.endEdit(!0);let e=xo(this.model);return this.afterOutline(),e}isSubtotalRow(e){var t;return!!((t=this.model.rows[e])!=null&&t.subtotal)}afterOutline(){this.updateScrollSize(),this.clampSelection(),this.invalidate()}loadSheetData(e,t={}){this.endEdit(!1),this.closeFilterPopup();let n=Yt(this.model,e,t);this._frozenRows=n.frozenRows,this._frozenColumns=n.frozenColumns,n.autoFilter&&(this.allowFilter=!0),this.cur={row:0,col:0},this.scroller.scrollTop=0,this.scroller.scrollLeft=0,this.clampSelection(),this.updateScrollSize(),this.invalidate()}loadWorkbookData(e,t,n={}){var s,l;let o=(s=e.sheets)!=null?s:[],i=typeof t=="string"?o.find(a=>{var u;return((u=a.name)!=null?u:"").toUpperCase()===t.toUpperCase()}):o[(l=t!=null?t:e.activeSheet)!=null?l:0];if(!i)throw new RangeError(`\uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4: ${String(t)}`);this.loadSheetData(i,n)}toSheetData(e={}){var t;return qt(this.model,{headerRow:e.headerRow,frozenRows:this._frozenRows,frozenColumns:this._frozenColumns,autoFilter:this.allowFilter,footer:this.exportFooter((t=e.headerRow)!=null?t:!0)})}exportFooter(e){let t=this.model.columns;if(!this._footerVisible||!t.some(s=>s.footer!=="none"))return;let n=e?Ie(t.map(s=>s.group),-1).levels+1:0,o=this.model.rowCount,i={sum:109,avg:101,count:103,max:104,min:105};return t.map((s,l)=>{if(s.footer==="none")return null;let a=this.getFooterValue(l),u=Qt(this.model,l),c=a===u||a instanceof Date&&u instanceof Date&&a.getTime()===u.getTime(),h=i[s.footer];return c&&h&&o>0?{formula:`=SUBTOTAL(${h},${ze(n,l)}:${ze(n+o-1,l)})`,value:a}:{value:a}})}toWorkbookData(e={}){return{sheets:[this.toSheetData(e)],activeSheet:0}}toCsv(e={}){return Mn(this.model,e)}downloadCsv(e="grid.csv",t={}){let n=new Blob(["\uFEFF"+Mn(this.model,t)],{type:"text/csv;charset=utf-8"}),o=URL.createObjectURL(n),i=document.createElement("a");i.href=o,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3)}setColumns(e){this.endEdit(!0);let t=this.model,n=t.undo.enabled;t.undo.enabled=!1;try{let o=i=>i.name||i.field||"";for(e.forEach((i,s)=>{let l=o(i),a=-1;if(l){for(let u=s;u<t.columns.length;u++)if(o(t.columns[u])===l){a=u;break}}a>=0?(t.columns[a].update(i),a!==s&&t.moveColumn(a,s)):t.insertColumn(s,new we(i))});t.columns.length>e.length;)t.removeColumn(t.columns.length-1)}finally{t.undo.enabled=n}t.undo.clear(),t.layoutChanged(),this.clampSelection()}beginUpdate(){this.updateCount++}endUpdate(){this.updateCount!==0&&--this.updateCount===0&&(this.updateScrollSize(),this.invalidate())}get allowUndo(){return this.model.undo.enabled}set allowUndo(e){this.model.undo.enabled=e,e||this.model.undo.clear()}clearUndo(){this.model.undo.clear()}setData(e,t={}){this.endEdit(!1),this.model.setData(e,!!t.keepSort),this.clampSelection(),this.updateFill()}updateFill(){let e=this.model,t=e.columns.filter(o=>o.visible&&o.fillWeight>0),n=e.fillExtra.size;if(e.fillExtra.clear(),t.length){let o=this.rowHeaderTotal();for(let s of e.columns)s.visible&&(o+=s.width);let i=Math.floor(this.scroller.clientWidth-o);if(i>0){let s=t.reduce((a,u)=>a+u.fillWeight,0),l=i;t.forEach((a,u)=>{let c=u===t.length-1?l:Math.floor(i*a.fillWeight/s);l-=c,e.fillExtra.set(a.id,c)})}}(t.length||n)&&e.colAxis.invalidate()}get data(){return this.model.source}rowData(e){var t;return(t=this.model.data)==null?void 0:t[e]}dataIndex(e){return this.model.sourceIndex(e)}insertRows(e,t=1){this.endEdit(!0),this.model.insertRows(e,t),this.clampSelection()}removeRows(e,t=1){this.endEdit(!1),this.model.removeRows(e,t),this.clampSelection()}setRowHeight(e,t){this.model.setRowHeight(e,t!=null?t:void 0)}getRowHeight(e){var t,n;return(n=(t=this.model.rows[e])==null?void 0:t.height)!=null?n:this._rowHeight}setRowVisible(e,t){this.model.setRowHidden(e,!t),this.clampSelection()}isRowVisible(e){return this.model.isRowVisible(e)}mergeCells(e,t,n,o){this.model.addMerge({row:e,col:t,rowSpan:n,colSpan:o})}unmergeCells(e,t,n=1,o=1){this.model.removeMerges({row:e,col:t,rowSpan:n,colSpan:o})}get merges(){return this.model.merges}sort(e){this.endEdit(!0);let t=e.map(o=>{var i;return{col:this.model.columnIndex(o.col),order:(i=o.order)!=null?i:"asc"}}).filter(o=>o.col>=0),n=this.model.rows[this.cur.row];if(this.model.sort(t),n){let o=this.model.rows.indexOf(n);o>=0&&this.setCurrent(o,this.cur.col,!1)}this.emitter.emit("sorted",{specs:t}),this.invalidate()}clearSort(e=!0){this.endEdit(!0),this.model.clearSort(e),this.emitter.emit("sorted",{specs:[]}),this.invalidate()}get sortCycle(){return this._sortCycle}set sortCycle(e){this._sortCycle=e==="ascDescNone"?e:"ascDesc"}get sortColumns(){return this.model.sortSpecs.map(e=>({col:this.model.columns.indexOf(e.col),order:e.order}))}sortByHeader(e,t){let n=this.model.columns[e];if(!n||!n.sortable)return;let o=this.model.sortSpecs.map(l=>({col:this.model.columns.indexOf(l.col),order:l.order})),i=o.findIndex(l=>l.col===e),s;if(t)s=o.slice(),i>=0?s[i]={col:e,order:s[i].order==="asc"?"desc":"asc"}:s.push({col:e,order:"asc"});else{if(this._sortCycle==="ascDescNone"&&i>=0&&o.length===1&&o[i].order==="desc"){this.clearSort();return}s=[{col:e,order:i>=0&&o[i].order==="asc"&&o.length===1?"desc":"asc"}]}this.sort(s.map(l=>({col:l.col,order:l.order})))}setFilter(e,t){let n=this.model.columnIndex(e);n<0||(this.endEdit(!0),t===null?this.model.setFilter(n,null):typeof t=="function"?this.model.setFilter(n,{predicate:t}):this.model.setFilter(n,{values:new Set(t)}),this.clampSelection(),this.emitter.emit("filtered",{col:n}))}clearFilters(){this.model.clearFilters(),this.clampSelection()}isFiltered(e){return!!this.model.getFilter(this.model.columnIndex(e))}getValidationError(e,t){let n=this.model.columnIndex(t);return this.model.formulaAt(e,n)||this.isSubtotalRow(e)?null:this.model.validate(n,this.model.getValue(e,n))}validate(){let e=[],n=this.model.columns.map((o,i)=>({c:o,i})).filter(({c:o})=>o.required||o.minimum!==void 0||o.maximum!==void 0||o.maxLength!==void 0||o.pattern||o.valueList);if(n.length){for(let o=0;o<this.model.rowCount;o++)if(!this.isSubtotalRow(o))for(let{i}of n){if(this.model.formulaAt(o,i))continue;let s=this.model.validate(i,this.model.getValue(o,i));s&&e.push({row:o,col:i,message:s})}}return e.length&&(this.select(e[0].row,e[0].col),this.showTip(e[0].row,e[0].col,e[0].message)),e}get currentCell(){return{...this.cur}}get selection(){return{...this.sel}}select(e,t,n,o){this.selectionShown=!0;let i=this.model.columnIndex(t),s=o===void 0?i:this.model.columnIndex(o);this.endEdit(!0),this.anchor={row:e,col:i},this.cur={row:e,col:i},this.sel=de(e,i,n!=null?n:e,s),this.scrollToCell(e,i),this.selectionChanged()}selectAll(){!this.model.rowCount||!this.model.columns.length||(this.sel={row:0,col:0,row2:this.model.rowCount-1,col2:this.model.columns.length-1},this.invalidate())}scrollToCell(e,t){let n=this.model.columnIndex(t),o=this.layout(),i=this.model.rowAxis,s=this.model.colAxis,l=i.visual(e);if(l>=o.frozenRows){let u=i.offset(l)-i.offset(o.frozenRows),c=u+i.sizeAt(l),h=o.bodyBottom-o.headerH-o.frozenH;u<this.scroller.scrollTop?this.scroller.scrollTop=u:c>this.scroller.scrollTop+h&&(this.scroller.scrollTop=c-h)}let a=s.visual(n);if(a>=o.frozenCols){let u=s.offset(a)-s.offset(o.frozenCols),c=u+s.sizeAt(a),h=o.width-o.rowHeaderW-o.frozenW;u<this.scroller.scrollLeft?this.scroller.scrollLeft=u:c>this.scroller.scrollLeft+h&&(this.scroller.scrollLeft=Math.min(u,c-h))}this.invalidate()}withSource(e,t){let n=this.model.valueSource;this.model.valueSource=e;try{return e==="code"||e==="undo"||e==="redo"?t():this.model.undo.transaction(t)}finally{this.model.valueSource=n}}undo(){this.endEdit(!0);let e=this.withSource("undo",()=>this.model.undo.undo());return e&&(this.afterReplay(),this.emitter.emit("undo",{})),e}redo(){this.endEdit(!0);let e=this.withSource("redo",()=>this.model.undo.redo());return e&&(this.afterReplay(),this.emitter.emit("redo",{})),e}get canUndo(){return this.model.undo.canUndo}get canRedo(){return this.model.undo.canRedo}batch(e){return this.model.undo.transaction(e)}afterReplay(){this.conditionalFormats.invalidate(),this.updateScrollSize(),this.clampSelection(),this.invalidate()}copySelectionText(){var u;let{row:e,col:t,row2:n,col2:o}=this.sel,i=[],s=new Map,l=0;for(let c=e;c<=n;c++){if(!this.model.isRowVisible(c))continue;let h=[],d=0;for(let f=t;f<=o;f++){if(!((u=this.model.columns[f])!=null&&u.visible))continue;let m=this.model.formulaAt(c,f);m&&s.set(`${l},${d}`,m.clone()),d++;let p=this.model.getValue(c,f),b=this.model.columns[f],g=b.kind==="check"?p?"TRUE":"FALSE":b.text(p,this.model.getCellStyle(c,f));h.push(/[\t\n"]/.test(g)?`"${g.replace(/"/g,'""')}"`:g)}i.push(h.join(" ")),l++}let a=i.join(`\r
|
|
56
|
+
`);return this.formulaClip=s.size?{text:a,row:e,col:t,cells:s}:null,a}pasteText(e){return this._readOnly||!this.allowEdit?0:this.withSource("paste",()=>this.pasteTextCore(e))}pasteTextCore(e){let t=Oo(e);if(!t.length)return 0;let n=0,o={addedRows:0,droppedRows:0,droppedColumns:0},i=null,s=this.formulaClip&&this.formulaClip.text.replace(/\r\n/g,`
|
|
57
|
+
`)===e.replace(/\r\n/g,`
|
|
58
|
+
`).replace(/\n$/,"")?this.formulaClip:null,l=0,a=0,u=(h,d,f)=>{let m=this.model.columns[d];if(!m||h>=this.model.rowCount||this.isCellReadOnly(h,d))return;let p=s==null?void 0:s.cells.get(`${l},${a}`);if(p){let w=p.clone();w.offset(h-(s.row+l),d-(s.col+a)),this.model.setFormula(h,d,w)&&n++;return}if(this.allowUserFormulas&&f.length>1&&f[0]==="="){let w=he.tryParse(f);if(!w){i!=null||(i={r:h,c:d,m:N().badFormula});return}this.model.setFormula(h,d,w)&&n++;return}let b=m.parse(f);if(this.emitter.has("cellPasting")){let w={row:h,col:d,text:f,value:b,cancel:!1};if(this.emitter.emit("cellPasting",w),w.cancel)return;w.value!==b&&(b=w.value)}if(b===void 0){i!=null||(i={r:h,c:d,m:N().badFormat});return}let g=this.model.validate(d,b);if(g){i!=null||(i={r:h,c:d,m:g});return}this.model.setValue(h,d,b)&&n++};if(this.model.undo.transaction(()=>{if(t.length===1&&t[0].length===1&&(this.sel.row!==this.sel.row2||this.sel.col!==this.sel.col2)){for(let h=this.sel.row;h<=this.sel.row2;h++)if(this.model.isRowVisible(h))for(let d=this.sel.col;d<=this.sel.col2;d++)u(h,d,t[0][0])}else{let h=0;for(let g=this.cur.row;g<this.model.rowCount&&h<t.length;g++)this.model.isRowVisible(g)&&h++;let d=t.length-h;d>0&&this.pasteAddsRows?(this.model.insertRows(this.model.rowCount,d),o.addedRows=d):d>0&&(o.droppedRows=d);let f=0;for(let g=this.cur.col;g<this.model.columns.length;g++)this.model.columns[g].visible&&f++;o.droppedColumns=Math.max(0,Math.max(...t.map(g=>g.length))-f);let m=this.cur.row;l=0;for(let g of t){for(;m<this.model.rowCount&&!this.model.isRowVisible(m);)m++;let w=this.cur.col;a=0;for(let S of g){for(;w<this.model.columns.length&&!this.model.columns[w].visible;)w++;u(m,w,S),w++,a++}m++,l++}let p=Math.min(this.model.rowCount-1,m-1),b=Math.min(this.model.columns.length-1,this.cur.col+Math.max(...t.map(g=>g.length))-1);this.sel=de(this.cur.row,this.cur.col,p,b)}}),i){let h=i;this.showTip(h.r,h.c,h.m)}this.model.hasFilters&&this.model.applyFilters(),this.invalidate();let c=this.sel;return this.emitter.emit("pasted",{row:c.row,col:c.col,rowCount:c.row2-c.row+1,colCount:c.col2-c.col+1,changed:n,...o}),n}clearSelection(){if(this._readOnly||!this.allowEdit)return;let e=null;if(this.model.undo.transaction(()=>{var t;for(let n=this.sel.row;n<=this.sel.row2;n++)if(this.model.isRowVisible(n))for(let o=this.sel.col;o<=this.sel.col2;o++){if(this.isCellReadOnly(n,o))continue;let i=this.model.columns[o],s=i.kind==="check"?!1:null;if(i.required&&i.kind!=="check"){e!=null||(e={r:n,c:o,m:(t=this.model.validate(o,null))!=null?t:""});continue}this.model.setValue(n,o,s)}}),e){let t=e;this.showTip(t.r,t.c,t.m)}}isCellReadOnly(e,t){var o,i;let n=this.model.columns[t];return!n||this._readOnly||n.readOnly||n.kind==="label"||n.kind==="button"||n.kind==="image"||(o=this.model.getCellStyle(e,t))!=null&&o.readOnly?!0:!!((i=this.model.getRowStyle(e))!=null&&i.readOnly)}autoFitColumn(e){let t=this.model.columnIndex(e),n=this.model.columns[t];if(!n)return;let o=this.renderer.measureColumn(t);this.model.setColumnWidth(t,Math.max(n.minWidth,Math.min(600,o))),this.emitter.emit("columnResized",{col:t,width:n.width})}on(e,t){let n=this.emitter.on(e,t);return e==="footerValue"&&this.refreshFooter(),n}off(e,t){e==="footerValue"&&(this.footerCache=null),this.emitter.off(e,t)}invalidate(){this.frame||this.destroyed||this.updateCount>0||(this.frame=requestAnimationFrame(()=>{this.frame=0,this.paintNow()}))}paintNow(){this.destroyed||(this.renderer.paint(),this.positionInput(),this.positionTip())}resize(){let e=window.devicePixelRatio||1,t=this.scroller.clientWidth,n=this.scroller.clientHeight;this.canvas.style.width=`${t}px`,this.canvas.style.height=`${n}px`;let o=Math.max(1,Math.round(t*e)),i=Math.max(1,Math.round(n*e));(this.canvas.width!==o||this.canvas.height!==i)&&(this.canvas.width=o,this.canvas.height=i),this.renderer.dpr=e,(this.model.columns.some(s=>s.fillWeight>0)||this.model.fillExtra.size)&&this.updateScrollSize(),this.paintNow()}focus(){this.input.focus({preventScroll:!0})}destroy(){var e,t,n,o,i;this.destroyed=!0,this.offLicense(),(e=this.offPageFind)==null||e.call(this),this.offPageFind=null,this.hideCellTip(),cancelAnimationFrame(this.frame),(t=this.resizeObserver)==null||t.disconnect(),(o=(n=this.dprQuery)==null?void 0:n.removeEventListener)==null||o.call(n,"change",this.onDprChange),this.dprQuery=null,this.closeFilterPopup(),this.hideTip(),(i=this.findPanel)==null||i.el.remove(),this.root.remove()}layout(){let e=this.model.rowAxis,t=this.model.colAxis,n=Math.min(this._frozenRows,e.visibleCount),o=Math.min(this._frozenColumns,t.visibleCount),i=this._columnHeadersVisible?this.headerGroups():{levels:0,depth:[],cells:[]},s=this.scroller.clientHeight,l=this._columnHeadersVisible?this._headerHeight*(i.levels+1):0,a=this._footerVisible?this._rowHeight:0;return{width:this.scroller.clientWidth,height:s,headerH:l,footerH:a,bodyBottom:Math.max(l,s-a),headerRowH:this._headerHeight,groups:i,rowHeaderW:this.rowHeaderTotal(),outlineW:this.outlineWidth(),frozenRows:n,frozenCols:o,frozenH:e.offset(n),frozenW:t.offset(o),scrollTop:this.scroller.scrollTop,scrollLeft:this.scroller.scrollLeft}}rowY(e,t){let n=this.model.rowAxis;return e<t.frozenRows?t.headerH+n.offset(e):t.headerH+t.frozenH+n.offset(e)-n.offset(t.frozenRows)-t.scrollTop}colX(e,t){let n=this.model.colAxis;return e<t.frozenCols?t.rowHeaderW+n.offset(e):t.rowHeaderW+t.frozenW+n.offset(e)-n.offset(t.frozenCols)-t.scrollLeft}cellRect(e,t,n=this.layout(),o=!0){var g;let i=this.model.rowAxis,s=this.model.colAxis,l=e,a=e,u=t,c=t;if(o){let w=this.model.mergeAt(e,t);w?(l=w.row,a=w.row+w.rowSpan-1,u=w.col,c=w.col+w.colSpan-1):((g=this.model.columns[t])==null?void 0:g.mergeMode)!=="none"&&([l,a]=this.model.valueMergeSpan(e,t))}let h=Ho(i.visual(l)),d=Do(i.visual(a)),f=Ho(s.visual(u)),m=Do(s.visual(c));if(d<h||m<f||h>=i.visibleCount||f>=s.visibleCount)return null;let p=this.rowY(h,n),b=this.colX(f,n);return{x:b,y:p,w:this.colX(m,n)+s.sizeAt(m)-b,h:this.rowY(d,n)+i.sizeAt(d)-p}}hitTest(e,t){let n=this.layout(),o=this.model.rowAxis,i=this.model.colAxis,s={area:"none",row:-1,col:-1};if(e<0||t<0||e>n.width||t>n.height)return s;let l=-1,a=-1;if(e>=n.rowHeaderW&&i.visibleCount){let u;e<n.rowHeaderW+n.frozenW?u=i.indexAt(e-n.rowHeaderW):u=i.indexAt(e-n.rowHeaderW-n.frozenW+n.scrollLeft+i.offset(n.frozenCols));let c=this.colX(u,n);e<=c+i.sizeAt(u)&&(l=i.physical(u))}if(n.footerH>0&&t>=n.bodyBottom){if(e>=n.rowHeaderW&&i.visibleCount){let u;if(e<n.rowHeaderW+n.frozenW?u=i.indexAt(e-n.rowHeaderW):u=i.indexAt(e-n.rowHeaderW-n.frozenW+n.scrollLeft+i.offset(n.frozenCols)),e<=this.colX(u,n)+i.sizeAt(u))return{area:"footer",row:-1,col:i.physical(u)}}return{area:"footer",row:-1,col:-1}}if(t>=n.headerH&&o.visibleCount){let u;t<n.headerH+n.frozenH?u=o.indexAt(t-n.headerH):u=o.indexAt(t-n.headerH-n.frozenH+n.scrollTop+o.offset(n.frozenRows));let c=this.rowY(u,n);t<=c+o.sizeAt(u)&&(a=o.physical(u))}if(n.outlineW>0&&e<n.outlineW){let u=Mo(e);return t<n.headerH?u>=1&&u<=this.model.outlineLevels+1?{area:"outlineLevel",row:-1,col:-1,level:u}:s:a>=0?{area:"outline",row:a,col:-1,level:u}:s}if(t<n.headerH){if(e<n.rowHeaderW)return{area:"corner",row:-1,col:-1};let u=l>=0&&t<this.leafTop(i.visual(l),n),c={area:u?"colGroup":"colHeader",row:-1,col:l};for(let h=0;h<i.visibleCount;h++){let d=this.colX(h,n)+i.sizeAt(h);if(!(d<n.rowHeaderW)&&!(h>=n.frozenCols&&d<n.rowHeaderW+n.frozenW)){if(Math.abs(e-d)<=4&&this.isHeaderBorder(h,t,n)){let f=i.physical(h);this.allowColumnResize&&this.model.columns[f].resizable&&(c.resizeCol=f);break}if(d>e+5)break}}if(!u&&l>=0&&this.allowFilter&&this.model.columns[l].filterable){let h=this.colX(i.visual(l),n)+this.model.columns[l].width;e>=h-20&&e<=h-4&&c.resizeCol===void 0&&(c.filterButton=!0)}return c}return e<n.rowHeaderW?a>=0?{area:"rowHeader",row:a,col:-1}:s:a>=0&&l>=0?{area:"cell",row:a,col:l}:s}isHeaderBorder(e,t,n){let o=n.groups;if(o.levels===0||this.leafTop(e,n)<=t)return!0;let i=l=>l<n.frozenCols;if(e+1<o.depth.length&&this.leafTop(e+1,n)<=t&&i(e+1)===i(e))return!0;let s=Math.floor(t/n.headerRowH);return o.cells.some(l=>l.level===s&&l.u1===e)}updateScrollSize(){this.updateFill();let e=this.rowHeaderTotal()+this.model.colAxis.total,t=this._columnHeadersVisible?this.headerGroups().levels:0,n=(this._columnHeadersVisible?this._headerHeight*(t+1):0)+this.model.rowAxis.total+(this._footerVisible?this._rowHeight:0);if(this.spacer.style.width=`${Math.ceil(e)}px`,this.spacer.style.height=`${Math.ceil(n)}px`,this._autoHeight){let o=this.scroller.offsetHeight-this.scroller.clientHeight,i=Math.ceil(n)+Math.max(0,o);this._emptyMessage&&this.model.rowAxis.visibleCount===0&&(i+=this._rowHeight*2),this._maxHeight>0&&(i=Math.min(i,this._maxHeight));let s=`${i}px`;this.root.style.height!==s&&(this.root.style.height=s)}}get autoHeight(){return this._autoHeight}set autoHeight(e){this._autoHeight=e,e||(this.root.style.height=""),this.updateScrollSize()}get maxHeight(){return this._maxHeight}set maxHeight(e){this._maxHeight=Math.max(0,e||0),this.updateScrollSize()}outlineWidth(){return this.model.outlineLevels>0?8+(this.model.outlineLevels+1)*14:0}rowHeaderTotal(){return this.outlineWidth()+(this._rowHeadersVisible?this._rowHeaderWidth:0)}clampSelection(){let e=this.model.rowCount,t=this.model.columns.length,n=(o,i)=>Math.max(0,Math.min(o,Math.max(0,i-1)));this.cur={row:n(this.cur.row,e),col:n(this.cur.col,t)},e&&!this.model.isRowVisible(this.cur.row)&&(this.cur.row=this.model.rowAxis.step(this.cur.row,0)),this.anchor={...this.cur},this.sel=de(this.cur.row,this.cur.col,this.cur.row,this.cur.col),this.invalidate()}setCurrent(e,t,n){let o=this.model.rowCount,i=this.model.columns.length;if(!(!o||!i)){if(e=Math.max(0,Math.min(o-1,e)),t=Math.max(0,Math.min(i-1,t)),n)this.cur={row:e,col:t},this.sel=de(this.anchor.row,this.anchor.col,e,t);else{let s=this.model.mergeAt(e,t);s&&(e=s.row,t=s.col),this.cur={row:e,col:t},this.anchor={row:e,col:t},this.sel=s?{row:s.row,col:s.col,row2:s.row+s.rowSpan-1,col2:s.col+s.colSpan-1}:de(e,t,e,t)}this.scrollToCell(e,t),this.selectionChanged()}}selectionChanged(){this.invalidate(),this.emitter.emit("selectionChanged",{row:this.cur.row,col:this.cur.col})}moveBy(e,t,n){let o=this.model.rowAxis,i=this.model.colAxis,{row:s,col:l}=n?this.cur:this.cur;if(!n){let a=this.model.mergeAt(s,l);a&&(e>0&&(s=a.row+a.rowSpan-1),t>0&&(l=a.col+a.colSpan-1))}e&&(s=o.step(s,e)),t&&(l=i.step(l,t)),this.setCurrent(s,l,n)}pageRows(){let e=this.layout();return Math.max(1,Math.floor((e.bodyBottom-e.headerH-e.frozenH)/this._rowHeight)-1)}attachEvents(){let e=this.scroller;e.addEventListener("scroll",()=>{this.closeFilterPopup(),this.hideCellTip(),this.editing&&!this.popupEditor&&this.positionInput(),this.invalidate()}),e.addEventListener("pointerdown",n=>{if(n.pointerType==="touch"){this.touchStart={id:n.pointerId,x:n.clientX,y:n.clientY,left:e.scrollLeft,top:e.scrollTop,down:n};return}this.onPointerDown(n)}),e.addEventListener("pointermove",n=>this.onPointerMove(n)),e.addEventListener("pointerup",n=>{let o=this.touchStart;if(n.pointerType==="touch"&&o&&o.id===n.pointerId){this.touchStart=null,Math.abs(n.clientX-o.x)<10&&Math.abs(n.clientY-o.y)<10&&e.scrollLeft===o.left&&e.scrollTop===o.top&&(this.onPointerDown(o.down),this.onPointerUp(n));return}this.onPointerUp(n)}),e.addEventListener("pointercancel",n=>{var o;((o=this.touchStart)==null?void 0:o.id)===n.pointerId&&(this.touchStart=null)}),e.addEventListener("pointerleave",()=>{this.hover=null,this.hideCellTip(),this.drag||(e.style.cursor=""),this.invalidate()}),e.addEventListener("dblclick",n=>this.onDoubleClick(n)),e.addEventListener("contextmenu",n=>{let o=this.hitAt(n);o.area==="cell"&&!Or(this.sel,o.row,o.col)&&this.setCurrent(o.row,o.col,!1)});let t=this.input;t.addEventListener("keydown",n=>this.onKeyDown(n)),t.addEventListener("input",()=>{!this.editing&&!this.composing&&t.value!==""&&this.beginEdit(!0,t.value)}),t.addEventListener("compositionstart",()=>{this.composing=!0,this.editing||this.beginEdit(!0,null)}),t.addEventListener("compositionend",()=>{this.composing=!1}),t.addEventListener("blur",()=>{this.editing&&!this.popupEditor&&this.endEdit(!0),this.invalidate()}),t.addEventListener("focus",()=>this.invalidate()),t.addEventListener("copy",n=>{var o;this.editing||(n.preventDefault(),(o=n.clipboardData)==null||o.setData("text/plain",this.copySelectionText()))}),t.addEventListener("cut",n=>{var o;this.editing||(n.preventDefault(),(o=n.clipboardData)==null||o.setData("text/plain",this.copySelectionText()),this.clearSelection())}),t.addEventListener("paste",n=>{var i;if(this.editing)return;n.preventDefault();let o=(i=n.clipboardData)==null?void 0:i.getData("text/plain");o&&this.pasteText(o)}),typeof ResizeObserver!="undefined"&&(this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.scroller)),this.watchDpr()}watchDpr(){var e,t,n,o;window.matchMedia&&((t=(e=this.dprQuery)==null?void 0:e.removeEventListener)==null||t.call(e,"change",this.onDprChange),this.dprQuery=window.matchMedia(`(resolution: ${window.devicePixelRatio||1}dppx)`),(o=(n=this.dprQuery).addEventListener)==null||o.call(n,"change",this.onDprChange))}hitAt(e){let t=this.root.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;return this.lastPointer={x:n,y:o},this.hitTest(n,o)}onPointerDown(e){let t=this.hitAt(e),n=t.area==="colHeader"&&t.col>=0&&t.resizeCol===void 0&&!t.filterButton&&!this.model.columns[t.col].headerCheckBox&&!(this.allowSort&&this.model.columns[t.col].sortable);if((t.area==="cell"||t.area==="rowHeader"||t.area==="corner"||n)&&(this.selectionShown=!0),this.hideCellTip(),e.button!==0){this.focus();return}let o=this.root.getBoundingClientRect();if(e.clientX-o.left>this.scroller.clientWidth||e.clientY-o.top>this.scroller.clientHeight||(e.preventDefault(),this.closeFilterPopup(),this.editing&&this.endEdit(!0),this.editing))return;this.focus();let i=this.hitAt(e),s=this.model.colAxis;if((i.area==="colHeader"||i.area==="colGroup")&&i.resizeCol!==void 0)this.drag={kind:"resize",col:i.resizeCol,startX:this.lastPointer.x,startW:this.model.columns[i.resizeCol].width};else if(i.area==="colHeader"&&i.col>=0){if(i.filterButton){this.openFilterPopup(i.col);return}if(this.model.columns[i.col].headerCheckBox){this.toggleHeaderCheck(i.col);return}if(this.allowSort&&this.model.columns[i.col].sortable){this.sortByHeader(i.col,e.shiftKey);return}if(e.shiftKey)this.sel=de(0,this.anchor.col,this.model.rowCount-1,i.col);else{let l=this.model.rowAxis.visibleCount?this.model.rowAxis.physical(0):0;this.cur={row:l,col:i.col},this.anchor={...this.cur},this.sel=de(0,i.col,this.model.rowCount-1,i.col)}this.drag={kind:"cols"},this.selectionChanged()}else if(i.area==="rowHeader"){let l=this.model.columns.length-1;if(e.shiftKey)this.sel=de(this.anchor.row,0,i.row,l);else{let a=s.visibleCount?s.physical(0):0;this.cur={row:i.row,col:a},this.anchor={...this.cur},this.sel=de(i.row,0,i.row,l)}this.drag={kind:"rows"},this.selectionChanged()}else if(i.area==="outlineLevel")this.showOutlineLevel(i.level);else if(i.area==="outline"){let l=this.model.outlineGroups.find(a=>a.summary===i.row&&a.level===i.level);l&&(Wt(this.model,l,!l.collapsed),this.afterOutline())}else if(i.area==="corner")this.selectAll();else if(i.area==="cell"){let l=this.model.columns[i.col];e.shiftKey?this.setCurrent(i.row,i.col,!0):this.setCurrent(i.row,i.col,!1),this.emitter.emit("cellClick",{row:i.row,col:i.col,event:e}),!e.shiftKey&&l.kind==="check"&&this.renderer.hitCheckBox(i.row,i.col,this.lastPointer.x,this.lastPointer.y)?this.toggleChecks([{row:i.row,col:i.col}]):!e.shiftKey&&l.kind==="button"?this.emitter.emit("buttonClick",{row:i.row,col:i.col}):this.drag={kind:"cells"}}if(this.drag)try{this.scroller.setPointerCapture(e.pointerId)}catch{}}onPointerMove(e){var o;let t=this.hitAt(e),n=this.drag;if(!n){let i=this.hover;this.hover=t,this.scheduleCellTip(t);let s=t.area==="cell"&&this.model.isClickable(t.row,t.col);this.scroller.style.cursor=(t.area==="colHeader"||t.area==="colGroup")&&t.resizeCol!==void 0?"col-resize":s?"pointer":"";let l=this._hoverRow&&((o=i==null?void 0:i.row)!=null?o:-1)!==t.row,a=((i==null?void 0:i.row)!==t.row||(i==null?void 0:i.col)!==t.col)&&(s||(i==null?void 0:i.area)==="cell"&&this.model.isClickable(i.row,i.col));(l||a)&&this.invalidate();return}if(n.kind==="resize"){let i=n.startW+(this.lastPointer.x-n.startX),s=this.model.columns[n.col];s.width=Math.max(s.minWidth,Math.round(i)),this.model.colAxis.invalidate(),this.updateScrollSize(),this.invalidate();return}this.dragSelect(),this.startAutoScroll()}dragSelect(){let e=this.drag;if(!e)return;let t=this.layout(),n=Math.max(t.rowHeaderW+1,Math.min(t.width-1,this.lastPointer.x)),o=Math.max(t.headerH+1,Math.min(t.bodyBottom-1,this.lastPointer.y)),i=this.hitTest(n,o);e.kind==="cells"&&i.row>=0&&i.col>=0?(this.cur={row:i.row,col:i.col},this.sel=this.expandForMerges(de(this.anchor.row,this.anchor.col,i.row,i.col))):e.kind==="rows"&&i.row>=0?this.sel=de(this.anchor.row,0,i.row,this.model.columns.length-1):e.kind==="cols"&&i.col>=0&&(this.sel=de(0,this.anchor.col,this.model.rowCount-1,i.col)),this.invalidate()}expandForMerges(e){let t=!0,n={...e};for(;t;){t=!1;for(let o of this.model.merges){if(!(o.row<=n.row2&&o.row+o.rowSpan-1>=n.row&&o.col<=n.col2&&o.col+o.colSpan-1>=n.col))continue;let s={row:Math.min(n.row,o.row),col:Math.min(n.col,o.col),row2:Math.max(n.row2,o.row+o.rowSpan-1),col2:Math.max(n.col2,o.col+o.colSpan-1)};(s.row!==n.row||s.col!==n.col||s.row2!==n.row2||s.col2!==n.col2)&&(Object.assign(n,s),t=!0)}}return n}startAutoScroll(){if(this.autoScroll)return;let e=()=>{if(this.autoScroll=0,!this.drag||this.drag.kind==="resize")return;let t=this.layout(),{x:n,y:o}=this.lastPointer,i=0,s=0;o<t.headerH+t.frozenH&&this.drag.kind!=="cols"?s=-Math.min(40,t.headerH+t.frozenH-o+4):o>t.bodyBottom&&(s=Math.min(40,o-t.bodyBottom+4)),n<t.rowHeaderW+t.frozenW&&this.drag.kind!=="rows"?i=-Math.min(40,t.rowHeaderW+t.frozenW-n+4):n>t.width&&(i=Math.min(40,n-t.width+4)),(i||s)&&(this.scroller.scrollTop+=s,this.scroller.scrollLeft+=i,this.dragSelect(),this.autoScroll=requestAnimationFrame(e))};this.autoScroll=requestAnimationFrame(e)}onPointerUp(e){var n,o;let t=this.drag;if(this.drag=null,(o=(n=this.scroller).hasPointerCapture)!=null&&o.call(n,e.pointerId)&&this.scroller.releasePointerCapture(e.pointerId),(t==null?void 0:t.kind)==="resize"){let i=this.model.columns[t.col],s=i.width;i.width=t.startW,this.model.setColumnWidth(t.col,s),this.updateScrollSize(),this.emitter.emit("columnResized",{col:t.col,width:s})}else t&&this.selectionChanged()}onDoubleClick(e){let t=this.hitAt(e);if((t.area==="colHeader"||t.area==="colGroup")&&t.resizeCol!==void 0){this.autoFitColumn(t.resizeCol);return}if(t.area!=="cell")return;this.emitter.emit("cellDoubleClick",{row:t.row,col:t.col,event:e});let n=this.model.columns[t.col].kind;n==="check"||n==="button"||this.beginEdit(!1,null)}onKeyDown(e){var n,o;this.selectionShown||(this.selectionShown=!0,this.invalidate());let t=e.ctrlKey||e.metaKey;if(this.editing){if(this.composing||e.isComposing)return;switch(e.key){case"Enter":if(e.altKey){e.preventDefault(),zr(this.input,`
|
|
59
|
+
`);return}e.preventDefault(),this.endEdit(!0)&&this.moveBy(e.shiftKey?-1:1,0,!1);return;case"Tab":e.preventDefault(),this.endEdit(!0)&&this.moveBy(0,e.shiftKey?-1:1,!1);return;case"Escape":e.preventDefault(),this.endEdit(!1);return;case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":this.enterMode&&(e.preventDefault(),this.endEdit(!0)&&this.onArrow(e.key,!1,!1));return;default:return}}if(t&&!e.altKey){let i=e.key.toLowerCase();if(i==="z"){e.preventDefault(),e.shiftKey?this.redo():this.undo();return}if(i==="y"){e.preventDefault(),this.redo();return}if(i==="a"){e.preventDefault(),this.selectAll();return}if((i==="f"||i==="h")&&this.allowFind){e.preventDefault(),this.showFindDialog(i==="h"&&!this._readOnly&&this.allowEdit);return}if(i==="c"||i==="x"){!this.editing&&!this.input.value&&(this.input.value=" ",this.input.select(),setTimeout(()=>{!this.editing&&this.input.value===" "&&(this.input.value="")},0));return}if(i==="v")return}switch(e.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":e.preventDefault(),this.onArrow(e.key,e.shiftKey,t);return;case"Enter":e.preventDefault(),this.moveBy(e.shiftKey?-1:1,0,!1);return;case"Tab":e.preventDefault(),this.moveBy(0,e.shiftKey?-1:1,!1);return;case"Home":{e.preventDefault();let i=this.model.colAxis,s=this.model.rowAxis,l=t&&s.visibleCount?s.physical(0):this.cur.row;i.visibleCount&&this.setCurrent(l,i.physical(0),e.shiftKey);return}case"End":{e.preventDefault();let i=this.model.colAxis,s=this.model.rowAxis,l=t&&s.visibleCount?s.physical(s.visibleCount-1):this.cur.row;i.visibleCount&&this.setCurrent(l,i.physical(i.visibleCount-1),e.shiftKey);return}case"PageDown":e.preventDefault(),this.moveBy(this.pageRows(),0,e.shiftKey);return;case"PageUp":e.preventDefault(),this.moveBy(-this.pageRows(),0,e.shiftKey);return;case"F2":e.preventDefault(),this.beginEdit(!1,null);return;case"F3":if(this.allowFind){e.preventDefault();let i=this.findPanel;i&&i.lastText?pt(this,i.lastText,{...i.options(),backwards:e.shiftKey}):this.showFindDialog(!1)}return;case"Delete":e.preventDefault(),this.withSource("delete",()=>this.clearSelection());return;case"Backspace":e.preventDefault(),this.beginEdit(!0,"");return;case" ":if(((n=this.model.columns[this.cur.col])==null?void 0:n.kind)==="check"){e.preventDefault();let i=[];for(let s=this.sel.row;s<=this.sel.row2;s++)for(let l=this.sel.col;l<=this.sel.col2;l++)this.model.columns[l].kind==="check"&&this.model.isRowVisible(s)&&i.push({row:s,col:l});this.toggleChecks(i)}else((o=this.model.columns[this.cur.col])==null?void 0:o.kind)==="button"&&(e.preventDefault(),this.emitter.emit("buttonClick",{row:this.cur.row,col:this.cur.col}));return;default:e.altKey&&e.key==="ArrowDown"&&(e.preventDefault(),this.beginEdit(!1,null))}}onArrow(e,t,n){let o=e==="ArrowUp"?-1:e==="ArrowDown"?1:0,i=e==="ArrowLeft"?-1:e==="ArrowRight"?1:0;n?this.moveBy(o*1e9,i*1e9,t):this.moveBy(o,i,t)}toggleChecks(e){let t=e.filter(o=>{var i;return!this.isCellReadOnly(o.row,o.col)&&!((i=this.model.rows[o.row])!=null&&i.subtotal)});if(!t.length)return;let n=t.every(o=>!!this.model.getValue(o.row,o.col));this.withSource("toggle",()=>this.model.undo.transaction(()=>{for(let o of t)this.model.setValue(o.row,o.col,!n)}))}beginEdit(e,t){if(this.editing)return!0;let{row:n,col:o}=this.cur;if(!this.allowEdit||this.isCellReadOnly(n,o))return this.input.value="",!1;let i={row:n,col:o,cancel:!1};if(this.emitter.emit("beginEdit",i),i.cancel)return this.input.value="",!1;let s=this.model.columns[o];this.scrollToCell(n,o),this.editing=!0,this.enterMode=e,this.editRow=n,this.editCol=o;let l=this.model.getValue(n,o);if(!e&&(s.kind==="combo"||s.kind==="date")&&!this.model.formulaAt(n,o))return this.openPopupEditor(s,l),!0;let a=this.input,u=this.model.formulaAt(n,o);if(t!==null?a.value=t:e||(a.value=u?u.toString():Lr(s,l)),a.classList.add("editing"),this.applyEditorStyle(a),this.positionInput(),!e||t!==null){let c=a.value.length;a.setSelectionRange(c,c)}return this.invalidate(),!0}endEdit(e){if(!this.editing)return!0;let t=this.editRow,n=this.editCol,o=this.model.columns[n],i,s;if(this.popupEditor){let u=this.popupEditor;i=u.value,u instanceof HTMLSelectElement?s=u.selectedIndex>=0&&o.items[u.selectedIndex]?o.items[u.selectedIndex].value:null:s=i?o.parse(i):null}else i=this.input.value,s=o?o.parse(i):i;let l=!this.popupEditor&&(this.allowUserFormulas||this.model.formulaAt(t,n))&&i.length>1&&i[0]==="="?i:null,a=null;if(e&&o&&l)try{a=he.parse(l)}catch(u){let c=u instanceof ve?N().formulaError(u.message):N().badFormula;return this.emitter.emit("dataError",{row:t,col:n,text:i,message:c}),this.showTip(t,n,c),!1}else if(e&&o){if(s===void 0)return this.emitter.emit("dataError",{row:t,col:n,text:i,message:N().badFormat}),this.showTip(t,n,N().badFormat),!1;let u=this.model.validate(n,s);if(u)return this.emitter.emit("dataError",{row:t,col:n,text:i,message:u}),this.showTip(t,n,u),!1}return this.editing=!1,this.enterMode=!1,this.closePopupEditor(),this.input.classList.remove("editing"),this.input.value="",e&&o&&(this.withSource("edit",()=>{a?this.model.setFormula(t,n,a):this.model.formulaAt(t,n)&&i===this.model.formulaAt(t,n).toString()||this.model.setValue(t,n,s)}),this.model.hasFilters&&this.model.applyFilters()),this.emitter.emit("endEdit",{row:t,col:n,cancelled:!e}),this.hideTip(),this.invalidate(),document.activeElement!==this.input&&this.root.contains(document.activeElement)&&this.focus(),!0}applyEditorStyle(e){var s,l;let t=this.model.getCellStyle(this.editRow,this.editCol),n=this.model.columns[this.editCol],o=(s=t==null?void 0:t.fontSize)!=null?s:this.fontSize;e.style.font=`${t!=null&&t.italic?"italic ":""}${t!=null&&t.bold||n.bold?"bold ":""}${o}px ${(l=t==null?void 0:t.fontFamily)!=null?l:this.fontFamily}`;let i=n.effectiveAlign(this.model.getValue(this.editRow,this.editCol),t);e.style.textAlign=i==="right"?"right":i==="center"?"center":"left",e.style.color=this.colors.fore,e.style.background=this.colors.cellBack,e.style.borderColor=this.colors.accent}positionInput(){var c;let e=this.editing?this.editRow:this.cur.row,t=this.editing?this.editCol:this.cur.col,n=this.layout(),o=this.model.rowCount&&this.model.columns.length?this.cellRect(e,t,n):null,i=(c=this.popupEditor)!=null?c:this.input;if(!o){i.style.transform="translate(-9999px, 0)";return}let s=Math.max(o.x,n.rowHeaderW),l=Math.max(o.y,n.headerH),a=Math.max(20,Math.min(o.x+o.w,n.width)-s),u=Math.max(this._rowHeight,Math.min(o.y+o.h,n.bodyBottom)-l);i.style.transform=`translate(${s}px, ${l}px)`,i.style.width=`${a+(this.editing?1:0)}px`,i.style.height=`${u+(this.editing?1:0)}px`}openPopupEditor(e,t){let n;if(e.kind==="combo"){let o=document.createElement("select");for(let s of e.items){let l=document.createElement("option");l.textContent=s.text,o.appendChild(l)}let i=e.items.findIndex(s=>s.value===t||String(s.value)===String(t!=null?t:""));o.selectedIndex=i,n=o}else{let o=document.createElement("input");o.type="date",o.value=t instanceof Date?ke(t,"yyyy-MM-dd"):"",n=o}if(n.className="nox-grid-popup-editor",this.applyEditorStyle(n),this.popupEditor=n,this.root.appendChild(n),this.positionInput(),n.addEventListener("keydown",o=>{let i=o.key;i==="Enter"||i==="Tab"?(o.preventDefault(),this.endEdit(!0)&&this.moveBy(i==="Enter"?o.shiftKey?-1:1:0,i==="Tab"?o.shiftKey?-1:1:0,!1)):i==="Escape"&&(o.preventDefault(),this.endEdit(!1))}),n.addEventListener("change",()=>{n instanceof HTMLSelectElement&&this.endEdit(!0)}),n.addEventListener("blur",()=>setTimeout(()=>{this.popupEditor===n&&this.endEdit(!0)},0)),n.focus(),n instanceof HTMLSelectElement&&"showPicker"in n)try{n.showPicker()}catch{}}closePopupEditor(){let e=this.popupEditor;e&&(this.popupEditor=null,e.remove())}showTip(e,t,n){this.hideTip();let o=this.cellRect(e,t);if(!o)return;let i=this.tipEl=document.createElement("div");i.className="nox-grid-tip",i.textContent=n,i.style.transform=`translate(${Math.max(0,o.x)}px, ${o.y+o.h+2}px)`,this.root.appendChild(i),this.tipCell={row:e,col:t},this.tipTimer=window.setTimeout(()=>this.hideTip(),3500)}positionTip(){if(!this.tipEl||!this.tipCell)return;let e=this.cellRect(this.tipCell.row,this.tipCell.col);if(!e){this.hideTip();return}this.tipEl.style.transform=`translate(${Math.max(0,e.x)}px, ${e.y+e.h+2}px)`}hideTip(){var e;clearTimeout(this.tipTimer),(e=this.tipEl)==null||e.remove(),this.tipEl=null,this.tipCell=null}openFilterPopup(e){var S;this.closeFilterPopup();let t=this.model.columns[e],n=this.layout(),o=this.colX(this.model.colAxis.visual(e),n),i=this.model.distinctTexts(e),s=(S=this.model.getFilter(e))==null?void 0:S.values,l=this.filterPopup=document.createElement("div");l.className="nox-grid-filter",l.style.transform=`translate(${Math.max(0,Math.min(o,n.width-230))}px, ${n.headerH}px)`;let a=(v,k,R="")=>{let D=document.createElement("button");return D.type="button",D.textContent=v,R&&(D.className=R),D.addEventListener("click",k),D},u=document.createElement("div");u.className="nox-grid-filter-sort",u.append(a(N().sortAsc,()=>{this.closeFilterPopup(),this.sort([{col:e,order:"asc"}])}),a(N().sortDesc,()=>{this.closeFilterPopup(),this.sort([{col:e,order:"desc"}])}));let c=document.createElement("input");c.type="search",c.placeholder=N().search;let h=document.createElement("div");h.className="nox-grid-filter-list";let d=[],f=document.createElement("label"),m=document.createElement("input");m.type="checkbox",f.append(m,document.createTextNode(" "+N().selectAll)),h.appendChild(f);let p=N();for(let v of i.slice(0,2e3)){let k=document.createElement("label"),R=document.createElement("input");R.type="checkbox",R.checked=!s||s.has(v),k.append(R,document.createTextNode(" "+(v===""?p.blank:v))),h.appendChild(k),d.push({t:v,cb:R,row:k})}let b=()=>{let v=d.filter(k=>k.row.style.display!=="none");m.checked=v.every(k=>k.cb.checked),m.indeterminate=!m.checked&&v.some(k=>k.cb.checked)};b(),m.addEventListener("change",()=>{for(let v of d)v.row.style.display!=="none"&&(v.cb.checked=m.checked)}),h.addEventListener("change",v=>{v.target!==m&&b()}),c.addEventListener("input",()=>{let v=c.value.toLowerCase();for(let k of d)k.row.style.display=k.t.toLowerCase().includes(v)?"":"none";b()});let g=document.createElement("div");g.className="nox-grid-filter-actions",g.append(a(N().clearFilter,()=>{this.closeFilterPopup(),this.setFilter(e,null)}),a(N().ok,()=>{let v=d.filter(k=>k.cb.checked&&k.row.style.display!=="none").map(k=>k.t);this.closeFilterPopup(),this.setFilter(e,v.length===d.length?null:v)},"primary"));let w=document.createElement("div");w.className="nox-grid-filter-title",w.textContent=t.header||t.name,l.append(w,u,c,h,g),l.addEventListener("pointerdown",v=>v.stopPropagation()),l.addEventListener("keydown",v=>{v.key==="Escape"&&(this.closeFilterPopup(),this.focus())}),this.root.appendChild(l),c.focus(),setTimeout(()=>document.addEventListener("pointerdown",this.onDocPointerDown,!0),0)}closeFilterPopup(){var e;document.removeEventListener("pointerdown",this.onDocPointerDown,!0),(e=this.filterPopup)==null||e.remove(),this.filterPopup=null}get hoverInfo(){return this.hover}addColumnInternal(e,t){let n=t instanceof we?t:new we(t);return this.model.insertColumn(e,n),this.updateScrollSize(),n}};function de(r,e,t,n){return{row:Math.min(r,t),col:Math.min(e,n),row2:Math.max(r,t),col2:Math.max(e,n)}}function Or(r,e,t){return e>=r.row&&e<=r.row2&&t>=r.col&&t<=r.col2}function Ho(r){return r>=0?r:-r-1}function Do(r){return r>=0?r:-r-2}function Lr(r,e){return e==null?"":r.kind==="number"||r.kind==="progress"?String(e):r.kind==="date"&&e instanceof Date?ke(e,e.getHours()||e.getMinutes()?"yyyy-MM-dd HH:mm":"yyyy-MM-dd"):r.text(e)}function zr(r,e){let t=r.selectionStart,n=r.selectionEnd;r.value=r.value.slice(0,t)+e+r.value.slice(n),r.setSelectionRange(t+e.length,t+e.length)}function Oo(r){let e=[],t=[],n="",o=0,i=!1,s=r.replace(/\r\n?/g,`
|
|
60
|
+
`);for(;o<s.length;){let l=s[o];if(i){if(l==='"'){if(s[o+1]==='"'){n+='"',o+=2;continue}i=!1,o++;continue}n+=l,o++;continue}if(l==='"'&&n===""){i=!0,o++;continue}l===" "?(t.push(n),n=""):l===`
|
|
61
|
+
`?(t.push(n),e.push(t),t=[],n=""):n+=l,o++}return(n!==""||t.length)&&(t.push(n),e.push(t)),e}var Ir=`
|
|
62
|
+
.nox-book{display:flex;flex-direction:column;width:100%;height:100%;box-sizing:border-box;font-family:"Malgun Gothic","Apple SD Gothic Neo","Segoe UI",system-ui,sans-serif}
|
|
63
|
+
.nox-book-sheets{position:relative;flex:1;min-height:0}
|
|
64
|
+
.nox-book-sheet{position:absolute;inset:0}
|
|
65
|
+
.nox-book-tabs{display:flex;align-items:stretch;gap:2px;height:30px;padding:0 6px;border-top:1px solid #d1d5db;background:#f3f4f6;overflow-x:auto;overflow-y:hidden;user-select:none;flex:none}
|
|
66
|
+
.nox-book-tab{position:relative;display:flex;align-items:center;padding:0 14px;margin-top:-1px;border:1px solid transparent;border-top:none;border-radius:0 0 6px 6px;font-size:12.5px;color:#4b5563;cursor:pointer;white-space:nowrap;background:transparent}
|
|
67
|
+
.nox-book-tab:hover{background:#e5e7eb}
|
|
68
|
+
.nox-book-tab.active{background:#fff;color:#111827;border-color:#d1d5db;font-weight:600;box-shadow:inset 0 2px 0 var(--nox-accent,#2563eb)}
|
|
69
|
+
.nox-book-tab.drop-before::before{content:"";position:absolute;left:-3px;top:4px;bottom:4px;width:3px;border-radius:2px;background:var(--nox-accent,#2563eb)}
|
|
70
|
+
.nox-book-tab.drop-after::after{content:"";position:absolute;right:-3px;top:4px;bottom:4px;width:3px;border-radius:2px;background:var(--nox-accent,#2563eb)}
|
|
71
|
+
.nox-book-tab input{font:inherit;width:110px;padding:1px 4px;border:1px solid #2563eb;border-radius:3px}
|
|
72
|
+
.nox-book-add{border:none;background:transparent;font-size:16px;color:#6b7280;cursor:pointer;padding:0 10px}
|
|
73
|
+
.nox-book-add:hover{color:#111827;background:#e5e7eb}
|
|
74
|
+
`,Lo=!1,kn=class{constructor(e,t={}){this.host=e;this.entries=[];this.active=-1;this.listeners=new Set;var o,i,s,l,a;if(jt(),!Lo&&typeof document!="undefined"){Lo=!0;let u=document.createElement("style");u.setAttribute("data-nox-grid-book",""),u.textContent=Ir,document.head.appendChild(u)}this.allowAddSheets=(o=t.allowAddSheets)!=null?o:!0,this.allowMoveSheets=(i=t.allowMoveSheets)!=null?i:!0,this.allowRenameSheets=(s=t.allowRenameSheets)!=null?s:!0,this.defaults=(l=t.defaults)!=null?l:{};let n=this.root=document.createElement("div");n.className="nox-book",this.area=document.createElement("div"),this.area.className="nox-book-sheets",this.tabs=document.createElement("div"),this.tabs.className="nox-book-tabs",this.tabs.setAttribute("role","tablist"),n.append(this.area,this.tabs),e.appendChild(n),n.addEventListener("keydown",u=>{var c;if((u.ctrlKey||u.metaKey)&&(u.key==="PageDown"||u.key==="PageUp")){u.preventDefault(),u.stopPropagation();let h=this.entries.length;h&&(this.activeSheet=(this.active+(u.key==="PageDown"?1:-1)+h)%h),(c=this.activeGrid)==null||c.focus()}},!0);for(let u of(a=t.sheets)!=null?a:[])this.addSheet(u.name,u);this.entries.length||this.addSheet(),this.activeSheet=0}get sheetCount(){return this.entries.length}get sheetNames(){return this.entries.map(e=>e.name)}sheet(e){var t;return(t=this.entries[this.indexOf(e)])==null?void 0:t.grid}indexOf(e){if(typeof e=="number")return e>=0&&e<this.entries.length?e:-1;let t=e.toUpperCase();return this.entries.findIndex(n=>n.name.toUpperCase()===t)}get activeSheet(){return this.active}set activeSheet(e){if(e<0||e>=this.entries.length)return;let t=e!==this.active;this.active=e,this.entries.forEach((o,i)=>o.el.style.display=i===e?"":"none");let n=this.entries[e].grid;if(n.resize(),Z(),n.recalculate(),this.renderTabs(),t)for(let o of this.listeners)o(e)}get activeGrid(){var e;return(e=this.entries[this.active])==null?void 0:e.grid}onActiveSheetChanged(e){return this.listeners.add(e),()=>this.listeners.delete(e)}addSheet(e,t={},n=this.entries.length){var u;let o=this.uniqueName((e==null?void 0:e.trim())||this.nextName()),i=document.createElement("div");i.className="nox-book-sheet",i.style.display="none",this.area.appendChild(i);let s={...this.defaults,...t,sheetName:o};!s.columns&&!s.data&&(s.columns=Array.from({length:10},(c,h)=>({name:String.fromCharCode(65+h),header:String.fromCharCode(65+h)})),(u=s.rowCount)!=null||(s.rowCount=50));let l=new xt(i,s);l.model.resolveSheet=c=>{let h=this.entries[this.indexOf(c)];return h?h.grid.model.formulaSheet:null};let a=Math.max(0,Math.min(n,this.entries.length));return this.entries.splice(a,0,{name:o,grid:l,el:i}),this.active>=a&&this.entries.length>1&&this.active++,Z(),this.renderTabs(),l}removeSheet(e){let t=this.indexOf(e);if(t<0||this.entries.length<=1)return!1;let[n]=this.entries.splice(t,1);return n.grid.destroy(),n.el.remove(),Z(),(this.active>=this.entries.length||t<this.active)&&(this.active=Math.max(0,this.active-(t<=this.active?1:0))),this.activeSheet=Math.min(this.active,this.entries.length-1),!0}renameSheet(e,t){var a;let n=this.indexOf(e),o=t.trim();if(n<0||!o||/[\\/?*[\]:]/.test(o))return!1;let i=this.indexOf(o);if(i>=0&&i!==n)return!1;let s=this.entries[n].name;if(s===o)return!0;let l=s.toUpperCase();for(let u of this.entries)for(let{cell:c}of u.grid.model.formulaCells())c.f.mapSheets(h=>h.toUpperCase()===l?o:h);return this.entries[n].name=o,this.entries[n].grid.model.sheetName=o,Z(),(a=this.activeGrid)==null||a.recalculate(),this.renderTabs(),!0}moveSheet(e,t){if(e<0||e>=this.entries.length||(t=Math.max(0,Math.min(t,this.entries.length-1)),e===t))return;let n=this.entries[this.active],[o]=this.entries.splice(e,1);this.entries.splice(t,0,o),this.active=this.entries.indexOf(n),this.renderTabs()}loadWorkbookData(e,t={}){var n,o,i;for(let s of this.entries)s.grid.destroy(),s.el.remove();this.entries.length=0,this.active=-1;for(let s of(n=e.sheets)!=null?n:[]){let l=this.addSheet((o=s.name)!=null?o:void 0,{rowCount:0,columns:[]}),a=Yt(l.model,s,t);l.frozenRows=a.frozenRows,l.frozenColumns=a.frozenColumns,a.autoFilter&&(l.allowFilter=!0),l.recalculate()}this.entries.length||this.addSheet(),this.activeSheet=Math.max(0,Math.min((i=e.activeSheet)!=null?i:0,this.entries.length-1))}toWorkbookData(e={}){return{sheets:this.entries.map(t=>{var n;return qt(t.grid.model,{headerRow:e.headerRow,frozenRows:t.grid.frozenRows,frozenColumns:t.grid.frozenColumns,autoFilter:t.grid.allowFilter,footer:t.grid.exportFooter((n=e.headerRow)!=null?n:!0)})}),activeSheet:this.active}}printAll(e={}){return wt(this.toPrintHtml(e))}toPrintHtml(e={}){return bt(this.entries.map(t=>({title:e.title?`${e.title} - ${t.name}`:t.name,table:gt(t.grid,e)})),e)}destroy(){for(let e of this.entries)e.grid.destroy();this.root.remove()}nextName(){let e=this.entries.length+1;for(;this.indexOf(`Sheet${e}`)>=0;)e++;return`Sheet${e}`}uniqueName(e){if(this.indexOf(e)<0)return e;let t=2;for(;this.indexOf(`${e} (${t})`)>=0;)t++;return`${e} (${t})`}renderTabs(){var n;let e=this.tabs;e.textContent="";let t=(n=this.activeGrid)==null?void 0:n.colors.accent;if(t&&this.root.style.setProperty("--nox-accent",t),this.entries.forEach((o,i)=>{let s=document.createElement("div");s.className="nox-book-tab"+(i===this.active?" active":""),s.setAttribute("role","tab"),s.setAttribute("aria-selected",String(i===this.active)),s.textContent=o.name,s.dataset.index=String(i),s.addEventListener("pointerdown",l=>this.onTabDown(l,i)),s.addEventListener("dblclick",()=>this.beginRename(i,s)),e.appendChild(s)}),this.allowAddSheets){let o=document.createElement("button");o.type="button",o.className="nox-book-add",o.textContent="+",o.title=N().addSheet,o.addEventListener("click",()=>{var i;this.addSheet(),this.activeSheet=this.entries.length-1,(i=this.activeGrid)==null||i.focus()}),e.appendChild(o)}}onTabDown(e,t){if(e.button!==0||e.target.tagName==="INPUT"||(t!==this.active&&(this.activeSheet=t),!this.allowMoveSheets||this.entries.length<2))return;let n=e.clientX,o=!1,i=-1,s=()=>Array.from(this.tabs.querySelectorAll(".nox-book-tab")),l=u=>{if(!o&&Math.abs(u.clientX-n)<6)return;o=!0;let c=s();c.forEach(h=>h.classList.remove("drop-before","drop-after")),i=c.length;for(let h=0;h<c.length;h++){let d=c[h].getBoundingClientRect();if(u.clientX<d.left+d.width/2){i=h;break}}i<c.length?c[i].classList.add("drop-before"):c[c.length-1].classList.add("drop-after")},a=()=>{var u;if(document.removeEventListener("pointermove",l),document.removeEventListener("pointerup",a),s().forEach(c=>c.classList.remove("drop-before","drop-after")),o&&i>=0){let c=this.active,h=i>c?i-1:i;this.moveSheet(c,h)}(u=this.activeGrid)==null||u.focus()};document.addEventListener("pointermove",l),document.addEventListener("pointerup",a)}beginRename(e,t){if(!this.allowRenameSheets)return;let n=document.createElement("input");n.value=this.entries[e].name,t.textContent="",t.appendChild(n),n.focus(),n.select();let o=!1,i=s=>{var l;o||(o=!0,(!s||!this.renameSheet(e,n.value))&&this.renderTabs(),(l=this.activeGrid)==null||l.focus())};n.addEventListener("keydown",s=>{s.stopPropagation(),s.key==="Enter"?i(!0):s.key==="Escape"&&i(!1)}),n.addEventListener("blur",()=>i(!0))}};var Ms="1.0.0";export{mt as CellRef,we as Column,ft as ColumnCollection,Ft as ConditionalFormat,nt as ConditionalFormatCollection,C as FormulaError,ve as FormulaSyntaxError,dt as GridModel,on as LICENSE_URL,he as NoxFormula,xt as NoxGrid,kn as NoxGridBook,Qe as RangeRef,X as RangeValue,ze as cellName,Sn as cellValueOf,Rr as colorSchemeNames,$e as colorSchemes,Me as columnName,We as compareValues,Et as formatDate,Rt as formatNumber,ke as formatValue,Ht as fromOADate,Bo as getLicenseInfo,$o as getLocale,gt as gridTableHtml,xe as parseDate,sn as parseNumber,Oo as parseTsv,bt as printDocumentHtml,wt as printHtml,Wo as setLicenseKey,Ct as setLocale,ee as toOADate,Hn as validateLicenseKey,Ms as version};
|