js-spread-grid 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/core/state.js +5 -3
- package/src/typings.js +2 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SpreadGrid=e():t.SpreadGrid=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function o(t){return null===t?"null":Array.isArray(t)?`[${t.map(o).join(",")}]`:"object"==typeof t?(e=t,`{${Object.keys(e).sort().map((t=>`${t}:${o(e[t])}`)).join(",")}}`):JSON.stringify(t);var e}function n(t,e){const o="FILTER"===t.type,n="FILTER"===e.type;return o&&!n||!o&&n?"FILTER":"DATA"}function r(t,e,r,i){return t.map((t=>{const l=o(t.columnId),s=o(t.rowId);if(!r.has(l))return null;if(!i.has(s))return null;const u=r.get(l),c=i.get(s);return{edit:e.resolve(c,u).edit,cell:t,type:n(u,c)}})).filter((t=>t?.edit))}function i(t,e){return Math.round(t*e)/e}function l(t,e,o){const n=t.state.renderState,r=t.canvases[`${e}-${o}`],l=n.sections[e],s=n.sections[o],u=s.columns,c=l.rows,a=n.devicePixelRatio;if(0===c.length||0===u.length)return void(r.parentElement&&r.parentElement.removeChild(r));r.parentElement||t.element.appendChild(r);const d=r.getContext("2d",{alpha:!1}),h=n.scrollRect,f=n.textResolver,p=n.renderFormatResolver,m=n.borderWidth,g=l.showTopBorder,y=l.showBottomBorder,w=s.showLeftBorder,b=s.showRightBorder,C=m/2,x=c.length-1+(g?1:0)+(y?1:0),v=u.length-1+(w?1:0)+(b?1:0),A=c.map((t=>t.height)),R=u.map((t=>t.width)),I=R.reduce(((t,e)=>t+e),0)+v*m,k=A.reduce(((t,e)=>t+e),0)+x*m,E="center"===o?h.left:0,S="middle"===e?h.top:0,D="center"===o?h.width:s.width,T="middle"===e?h.height:l.height,M=R.reduce(((t,e,o)=>{const n=t[o]+e+m;return t.push(n),t}),[w?m:0]),B=A.reduce(((t,e,o)=>{const n=t[o]+e+m;return t.push(n),t}),[g?m:0]),L=M.slice(0,-1),O=B.slice(0,-1),z=Math.max(L.findLastIndex((t=>t<=E)),0),N=L.findLastIndex((t=>t<=E+D)),K=Math.max(O.findLastIndex((t=>t<=S)),0),F=O.findLastIndex((t=>t<=S+T)),H=Math.max(z,w?0:1),W=N+(b?1:0),P=Math.max(K,g?0:1),Y=F+(y?1:0),$=Array.from({length:F-K+1},((t,e)=>{const o=c[e+K];return Array.from({length:N-z+1},((t,e)=>{const n=u[e+z];return p.resolve(o,n)}))})),V=(t,e)=>$[t-K][e-z];r.width=Math.round(D*a),r.height=Math.round(T*a),r.style.width=`${D}px`,r.style.height=`${T}px`,r.style.marginLeft=`${E}px`,r.style.marginTop=`${S}px`,r.style.marginRight=I-D-E+"px",r.style.marginBottom=k-T-S+"px",d.fillStyle="#E9E9E9",d.fillRect(0,0,r.width,r.height);const q=(t,e)=>{d.setTransform(a,0,0,a,(t-E)*a,(e-S)*a)},G=(t,e,o,n)=>{d.beginPath(),d.rect(t,e,o,n),d.clip()};for(let t=z;t<=N;t++)for(let e=K;e<=F;e++){const o=V(e,t);if(!o.render)continue;const n=o.style,r=B[e],l=M[t],s=R[t],u=A[e],c=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(q(l,r),d.fillStyle=n.background||"white",d.fillRect(0,0,s,u),"draw"in o&&o.draw(d),n.highlight&&(d.fillStyle=n.highlight,d.fillRect(0,0,s,u)),n.corner&&(d.fillStyle=n.corner,d.beginPath(),d.moveTo(s-7,u),d.lineTo(s,u),d.lineTo(s,u-7),d.fill()),c&&"transparent"!==g){d.fillStyle=g,d.font=o.font;const t=f.getFontMetrics(o.font),e="center"==n.textAlign&&f.measureWidth(c,o.font)>s-p.left-p.right?"left":n.textAlign||"left";d.textAlign=e;const r=i("left"===e?p.left:"center"===e?s/2:"right"===e?s-p.right:0,a),l=i("top"===h?t.middle+t.topOffset+p.top:"middle"===h?u/2+t.middle:"bottom"===h?u+t.middle-t.bottomOffset-p.bottom:0,a);d.save(),G(0,2*m,s,u-4*m),d.fillText(c,r,l),d.restore()}}q(0,0);const _=(t,e,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/a,l=e===n,s=t-(l?i/2:0),u=e-(l?0:i/2),c=o+(l?i/2:0),h=n+(l?0:i/2);d.strokeStyle=r.color||"black",d.lineWidth=i,r.dash?(d.setLineDash(r.dash.map((t=>t/a))),d.lineDashOffset=l?s:u):d.setLineDash([]),d.beginPath(),d.moveTo(s,u),d.lineTo(c,h),d.stroke()},j=(t,e)=>t?e?t.index>e.index?t:e:t:e;for(let t=P;t<=Y;t++){const e=t-1,o=t;for(let t=z;t<=N;t++){const n=j(e>=K?V(e,t).style.borderBottom:null,o<=F?V(o,t).style.borderTop:null);_(M[t]-C,B[o]-C,M[t+1]-C,B[o]-C,n)}}for(let t=H;t<=W;t++){const e=t-1,o=t;for(let t=K;t<=F;t++){const n=j(e>=z?V(t,e).style.borderRight:null,o<=N?V(t,o).style.borderLeft:null);_(M[o]-C,B[t]-C,M[o]-C,B[t+1]-C,n)}}}t.d(e,{default:()=>Ye});const s={value:({newValue:t})=>t||"",text:({newValue:t})=>t||"Search...",edit:{validate:()=>!0,parse:({string:t})=>t,autoCommit:!0}};function u(t,e,o){return[{column:{type:"DATA"},row:{type:"HEADER"},value:({column:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"DATA"},value:({row:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"SPECIAL"},value:""},{column:{type:"SPECIAL"},row:{type:"HEADER"},value:""},{column:{type:"DATA"},row:{type:"FILTER"},...s},{column:{type:"FILTER"},row:{type:"DATA"},...s},{column:{type:"DATA"},row:{type:"DATA"},value:e},...t,...o.map((({columnId:t,rowId:e,direction:n},r)=>({column:{id:t},row:{id:e},text:({value:t,text:e})=>`${o.length>1?r+1:""}${"ASC"===n?"⇣":"⇡"} ${e||t}`})))]}const c=["column","row","condition"];function a(t){return Object.keys(t).length>Object.keys(t).filter((t=>c.includes(t))).length}function d(t,e){const o=[...c,...e];return t.map((t=>function(t,e){const o={};for(const n of e)n in t&&(o[n]=t[n]);return o}(t,o))).filter(a)}function h(t){return d(t,["value","text","edit"])}function f(t,e){return e?t+"99":t+"33"}function p(t,e,n,r,i,l,s,u,c,a,h,p,m){t=d(t,["value","style","text","font","padding","edit","draw"]);const g=n?o(n.columnId):null,y=n?o(n.rowId):null,w=null!==c,b=null!==u||w,C=a+2,x=a+4,v=(t,e,o,n)=>{if(o<0||o>=t.length)return!1;if(n<0||n>=e.length)return!1;const i=t[o],l=e[n];if("DYNAMIC-BLOCK"===i.type)return!1;if("DYNAMIC-BLOCK"===l.type)return!1;const s=i.key,u=l.key;return r.isKeySelected(s,u)},A=(t,e)=>t?[e]:[];return[{column:{type:"DATA"},row:{type:"FILTER"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"FILTER"},row:{type:"DATA"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"ANY"},row:{type:"HEADER"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"ANY"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"HEADER"},style:{background:"#E0E0E0"}},...t,...A(e&&!w,{column:{type:"ANY"},row:{id:e?.rowId},style:{highlight:"#81948133"}}),...A(e&&!b,{column:{id:e?.columnId},row:{id:e?.rowId},style:{highlight:"#81948188"}}),{column:{type:"ANY"},row:{type:"ANY"},condition:({rows:t,columns:e,row:o,column:n})=>v(t,e,o.index,n.index),style:({rows:t,columns:e,row:o,column:n,edit:r})=>({...v(t,e,o.index-1,n.index)?{}:{borderTop:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index+1,n.index)?{}:{borderBottom:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index-1)?{}:{borderLeft:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index+1)?{}:{borderRight:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},highlight:f(r?"#798d9c":"#819481",g!==n.key||y!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>i.isKeySelected(t.key,e.key),style:({row:t,column:e})=>({highlight:f("#93a8b8",g!==e.key||y!==t.key)})},...A(!!n,{column:{id:n?.columnId},row:{id:n?.rowId},style:{highlight:"#ffffffaa"}}),...s.map((({columnId:t,rowId:e,direction:o},n)=>({column:{id:t},row:{id:e},style:{highlight:"#0377fc44"}}))),{column:{type:"ANY"},row:{type:"ANY"},condition:({edit:t})=>!!t,style:{corner:"#77777720"}},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>l.hasValueByKey(t.key,e.key),style:{corner:"darkgreen"}},...A(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:x,color:"cornflowerblue"}}}),...A(c,{column:{type:"HEADER"},row:{id:c},style:{borderBottom:{width:x,color:"cornflowerblue"}}}),...A(h&&p,{column:{id:p},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...A(h&&m,{column:{type:"ANY"},row:{id:m},style:{highlight:"#3a74e055"}})]}function m(t,e){const o=e.filter((t=>"BEGIN"===t.pinned)).length,n=e.filter((t=>"END"===t.pinned)).length,r=e.length-o-n,i=t.filter((t=>"BEGIN"===t.pinned)).length,l=t.filter((t=>"END"===t.pinned)).length,s=t.length-i-l,u=e.slice(0,o),c=e.slice(e.length-n,e.length),a=e.slice(o,e.length-n),d=t.slice(0,i),h=t.slice(t.length-l,t.length),f=t.slice(i,t.length-l),p=o>0,m=i>0,g=!0,y=!0,w=r>0||!p,b=!0,C=!p,x=!(n>0),v=!0,A=!0,R=s>0||!m,I=!0,k=!m,E=!(l>0),S=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).topWithBorder:t.at(0).top;return(o?t.at(-1).bottomWithBorder:t.at(-1).bottom)-n},D=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).leftWithBorder:t.at(0).left;return(o?t.at(-1).rightWithBorder:t.at(-1).right)-n};return{top:{rows:u,showTopBorder:g,showBottomBorder:y,height:S(u,g,y)},bottom:{rows:c,showTopBorder:w,showBottomBorder:b,height:S(c,w,b)},middle:{rows:a,showTopBorder:C,showBottomBorder:x,height:S(a,C,x)},left:{columns:d,showLeftBorder:v,showRightBorder:A,width:D(d,v,A)},right:{columns:h,showLeftBorder:R,showRightBorder:I,width:D(h,R,I)},center:{columns:f,showLeftBorder:k,showRightBorder:E,width:D(f,k,E)}}}function g(t,e){return[...t,...e.map((t=>({columnId:t.columnId,rowId:t.rowId,value:t.expression})))]}class y{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Map),this.lookup.get(e).set(n,t.value)}))}hasValueByKey(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}getValueByKey(t,e){if(this.hasValueByKey(t,e))return this.lookup.get(t).get(e)}hasValueById(t,e){return this.hasValueByKey(o(t),o(e))}getValueById(t,e){return this.getValueByKey(o(t),o(e))}}function w(t){return new y(t)}class b{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Set),this.lookup.get(e).add(n)}))}isKeySelected(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}isIdSelected(t,e){return this.isKeySelected(o(t),o(e))}}function C(t){return new b(t)}function x(t,e){return"function"==typeof t?t(e):t}function v(t,e){return"function"==typeof t?t(e):t}function A(t,e){const n=t.type||"DATA",r="selector"in t?t.selector:"id"in t?t.id:void 0,i="id"in t?t.id:"selector"in t?t.selector:n;return{...t,id:i,selector:r,type:n,key:o(i),header:"header"in t?t.header:i,resizable:!("resizable"in t)||t.resizable,labels:t.labels||[],index:e}}function R(t,e){const o="selector"in t?t.selector:({index:t})=>t,n="id"in t?t.id:({selector:t})=>t,r="header"in t?t.header:()=>`#${e}`;return{...t,id:n,selector:o,type:"DYNAMIC-BLOCK",header:r,labels:t.labels||[],index:e,resizable:!1}}function I(t,e){return"number"==typeof t?i(t,e):t}function k(t,e,n,r,l){const s=new Map(e.map((({columnId:t,width:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),l=t.width*t.count+n*(t.count-1);return{...o,count:t.count,width:i(l,r),columnWidth:i(t.width,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"width"in t?t.width:"fit";return{...o,width:I(n,r)}}}))}function E(t,e,n,r,l){const s=new Map(e.map((({rowId:t,height:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),s="height"in t?t.height:l,u=s*t.count+n*(t.count-1);return{...o,count:t.count,height:i(u,r),rowHeight:i(s,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"height"in t?t.height:"fit";return{...o,height:I(n,r)}}}))}function S(t,e,o,n,r){if(t<o){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"BEGIN"}if(t>=e-n){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"END"}}function D(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.width,s={...r,index:i,width:l,leftWithBorder:n-o,left:n,right:n+l,rightWithBorder:n+l+o,pinned:S(i,t.length,e.left,e.right,r.type)};return n+=s.width+o,s}))}function T(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.height,s={...r,index:i,height:l,topWithBorder:n-o,top:n,bottom:n+l,bottomWithBorder:n+l+o,pinned:S(i,t.length,e.top,e.bottom,r.type)};return n+=s.height+o,s}))}const M="12px Calibri",B={top:2,right:5,bottom:2,left:5};function L(t){return"function"==typeof t?t:()=>t}const O={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class z{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class N{lookup=new z;hasRules=!1;addRule(t,e,n){if(this.hasRules=!0,Array.isArray(t)){for(const o of t)this.addRule(o,e,n);return}if(Array.isArray(e)){for(const o of e)this.addRule(t,o,n);return}const r=t?"id"in t?{key:o(t.id)}:t:{type:"DATA"},i=e?"id"in e?{key:o(e.id)}:e:{type:"DATA"};function l(t,e){t.has(e)||t.set(e,[]),t.get(e).push(n)}function s(t,e){if(t.has(e)||t.set(e,new z),"key"in i)l(t.get(e).byKey,i.key);else if("index"in i)l(t.get(e).byIndex,i.index);else if("label"in i)l(t.get(e).byLabel,i.label);else for(const o of O[i.type||"NONE"])l(t.get(e).byType,o)}if("key"in r)s(this.lookup.byKey,r.key);else if("index"in r)s(this.lookup.byIndex,r.index);else if("label"in r)s(this.lookup.byLabel,r.label);else for(const t of O[r.type||"NONE"])s(this.lookup.byType,t)}getRules(t,e){const o=[];if(!this.hasRules)return o;function n(t){for(const e of t)o.push(e)}function r(t){t.byKey.has(e.key)&&n(t.byKey.get(e.key)),t.byIndex.has(e.index)&&n(t.byIndex.get(e.index)),t.byType.has(e.type)&&n(t.byType.get(e.type));for(const o of e.labels)t.byLabel.has(o)&&n(t.byLabel.get(o))}this.lookup.byKey.has(t.key)&&r(this.lookup.byKey.get(t.key)),this.lookup.byIndex.has(t.index)&&r(this.lookup.byIndex.get(t.index)),this.lookup.byType.has(t.type)&&r(this.lookup.byType.get(t.type));for(const e of t.labels)this.lookup.byLabel.has(e)&&r(this.lookup.byLabel.get(e));return o}}const K=["borderTop","borderRight","borderBottom","borderLeft"],F={validate:()=>!0,parse:({string:t})=>t};function H(t,e){const o={...t};if("border"in o){for(const t of K)o[t]=o.border;delete o.border}for(const t of K)t in o&&(o[t]={...o[t],index:e});return o}function W(t,e){if(!1!==t.edit)return!0===t.edit?"edit"in e?e.edit:F:"edit"in e?{...e.edit,...t.edit}:{...F,...t.edit}}class P{constructor(t){this.rulesLookup=new N;for(const[e,o]of t.entries()){const t={index:e};"condition"in o&&(t.condition=o.condition),"style"in o&&(t.style=L(o.style)),"value"in o&&(t.value=L(o.value)),"text"in o&&(t.text=L(o.text)),"font"in o&&(t.font=L(o.font)),"padding"in o&&(t.padding=L(o.padding)),"edit"in o&&(t.edit=o.edit),"tooltip"in o&&(t.tooltip=L(o.tooltip)),"draw"in o&&(t.draw=o.draw),"sortOrder"in o&&(t.sortOrder=L(o.sortOrder)),this.rulesLookup.addRule(o.column,o.row,t)}}resolve(t,e,o,n,r,i){const l=this.rulesLookup.getRules(r,n).sort(((t,e)=>t.index-e.index)).filter(((t,e,o)=>t.index!==o[e-1]?.index));let s,u,c={data:t,rows:e,columns:o,row:n,column:r},a={},d=B,h=M;i.hasValueByKey(n.key,r.key)&&(c={...c,newValue:i.getValueByKey(n.key,r.key)});for(const t of l)if((!("condition"in t)||t.condition(c))&&("value"in t&&(c={...c,value:t.value(c)}),"style"in t&&(a={...a,...H(t.style(c),t.index)}),"text"in t&&(c={...c,text:t.text(c)}),"font"in t&&(h=t.font(c)),"padding"in t&&(d={...d,...t.padding(c)}),"edit"in t&&(c={...c,edit:W(t,c)}),"tooltip"in t&&(u=t.tooltip(c)),"sortOrder"in t&&(c={...c,sortOrder:t.sortOrder(c)}),"draw"in t)){const e=c;s=o=>t.draw({...e,ctx:o})}const f=function(t){return"text"in t?`${t.text}`:"newValue"in t?`${t.newValue}`:void 0!==t.value?`${t.value}`:""}(c),p={render:!0,style:a,text:f,padding:d,font:h};return"value"in c&&(p.value=c.value),"edit"in c&&void 0!==c.edit&&(p.edit=c.edit),void 0!==u&&(p.tooltip=u),"sortOrder"in c&&(p.sortOrder=c.sortOrder),void 0!==s&&(p.draw=s),p}}function Y(t){return new P(t)}class ${constructor(t,e,o,n,r){this.formattingRules=t,this.data=e,this.rows=o,this.columns=n,this.edition=r}resolve(t,e){return this.formattingRules.resolve(this.data,this.rows,this.columns,t,e,this.edition)}}function V(t,e,o,n,r){return new $(t,e,o,n,r)}function q(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.expression)}return r}function G(t,e,o,n,r,i,l){if(0===t.length)return r;const s=q(t,"columnId","rowId"),u=i.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?r:r.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,t,c,l),a=s.get(c.key);if(!e.resolve(n,r,i,t,c,u.value,u.text,a))return!1}return!0}))}function _(t,e,o,n,r,i,l){if(0===t.length)return i;const s=q(t,"rowId","columnId"),u=r.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?i:i.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,c,t,l),a=s.get(c.key);if(!e.resolve(n,r,i,c,t,u.value,u.text,a))return!1}return!0}))}function j(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.height+o,1];const n=Math.min(e,t.count);return[(t.rowHeight+o)*n,n]}function U(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.width+o,1];const n=Math.min(e,t.count);return[(t.columnWidth+o)*n,n]}function X(t,e,o,n){let r=0,i=0,l=0,s=0;if(o.top>0){r=n;for(let t=0,i=0;i<o.top;t++){const l=e[t],[s,u]=j(l,o.top-i,n);r+=s,i+=u}}if(o.left>0){l=n;for(let e=0,r=0;r<o.left;e++){const i=t[e],[s,u]=U(i,o.left-r,n);l+=s,r+=u}}if(o.bottom>0){i=n;for(let t=e.length-1,r=0;r<o.bottom;t--){const l=e[t],[s,u]=j(l,o.bottom-r,n);i+=s,r+=u}}if(o.right>0){s=n;for(let e=t.length-1,r=0;r<o.right;e--){const i=t[e],[l,u]=U(i,o.right-r,n);s+=l,r+=u}}return{top:r,bottom:i,left:l,right:s}}function J(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.height,o+=e;return o}function Q(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.width,o+=e;return o}function Z(t,e,o){return{width:Q(t,o),height:J(e,o)}}class tt{constructor(){this.fontMetrics=new Map,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d")}measureWidth(t,e){if(!t)return 0;const o=this.context;return o.font=e||M,o.measureText(t).width}measureHeight(t,e){let o=1;for(const e of t)"\n"===e&&o++;return o*this.getFontMetrics(e).height}getFontMetrics(t){const e=t;if(this.fontMetrics.has(e))return this.fontMetrics.get(e);const o=this.context;o.font=t||M;const n=o.measureText("X"),r=(n.actualBoundingBoxDescent-n.actualBoundingBoxAscent)/2,i={topOffset:r+n.fontBoundingBoxAscent,middle:-r,bottomOffset:n.fontBoundingBoxDescent-r,height:n.fontBoundingBoxAscent+n.fontBoundingBoxDescent};return this.fontMetrics.set(e,i),i}}function et(){return new tt}function ot(t,e){return e.top>=t.top&&e.left>=t.left&&e.top+e.height<=t.top+t.height&&e.left+e.width<=t.left+t.width}function nt(t,e){const o={top:Math.max(t.top,e.top),left:Math.max(t.left,e.left),width:Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left),height:Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top)};return o.width>=0&&o.height>=0?o:{top:t.top,left:t.left,width:0,height:0}}function rt(t,e){return{top:t.top-e,left:t.left-e,width:t.width+2*e,height:t.height+2*e}}function it(t){return t.width*t.height}function lt(t,e){return{top:t.top,left:t.left,width:Math.max(0,t.width-e.left-e.right),height:Math.max(0,t.height-e.top-e.bottom)}}const st=200,ut=400,ct={left:0,top:0,width:0,height:0};function at(t,e,o,n,r){const i=t||ct,l=lt({left:0,top:0,...o},n),s=lt({...e,...r},n),u=nt(l,rt(s,st)),c=nt(l,rt(s,ut));return ot(l,i)&&ot(i,u)?it(i)>2*it(c)?c:i:c}function dt(t,e,o,n,r){if(!t)return null;if(t.x<0||t.y<0||t.x>r.width||t.y>r.height)return null;const i=function(t,e){if(0===t.length)return-1;if(e<t[0].topWithBorder)return-1;if(e>t[t.length-1].bottomWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].topWithBorder)n=r-1;else{if(!(e>t[r].bottomWithBorder))return r;o=r+1}}return-1}(e,t.y),l=function(t,e){if(0===t.length)return-1;if(e<t[0].leftWithBorder)return-1;if(e>t[t.length-1].rightWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].leftWithBorder)n=r-1;else{if(!(e>t[r].rightWithBorder))return r;o=r+1}}return-1}(o,t.x);return-1===i||-1===l?null:{rowId:e[i].id,columnId:o[l].id}}function ht(t){return t.reduce(((t,e)=>t.set(e.key,e)),new Map)}function ft(t,e,n,r,i,l,s,u){if(!t)return[];if(!e)return[];if(!r)return[];if(!n)return[];const c=o(n.columnId),a=o(n.rowId),d=o(r.columnId),h=o(r.rowId);if(!s.has(c))return[];if(!u.has(a))return[];if(!s.has(d))return[];if(!u.has(h))return[];const f=Math.min(s.get(c).index,s.get(d).index),p=Math.max(s.get(c).index,s.get(d).index),m=Math.min(u.get(a).index,u.get(h).index),g=Math.max(u.get(a).index,u.get(h).index);return i.slice(f,p+1).flatMap((t=>l.slice(m,g+1).map((e=>({rowId:e.id,columnId:t.id})))))}function pt(t,e){const o=function(t){return"BEGIN"===t.pinned?"top":"END"===t.pinned?"bottom":"middle"}(e),n=function(t){return"BEGIN"===t.pinned?"left":"END"===t.pinned?"right":"center"}(t);return`${o}-${n}`}function mt(t,e,n,r,i){return 0===t.length?null:function(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!e.has(i))return null;if(!n.has(l))return null;const s=e.get(i),u=n.get(l),c={width:s.width,height:u.height,section:pt(s,u)};switch(u.pinned){case"BEGIN":c.top=u.top;break;case"END":c.bottom=r.top.height+r.middle.height+r.bottom.height-u.top-u.height;break;default:c.marginTop=u.top-r.top.height}switch(s.pinned){case"BEGIN":c.left=s.left;break;case"END":c.right=r.left.width+r.center.width+r.right.width-s.left-s.width;break;default:c.marginLeft=s.left-r.left.width}return c}(e,n,r,i)}function gt(t,e){return e.every((e=>e.edit.validate({string:t})))}function yt(t){return Array.isArray(t)?t.map(((t,e)=>e)):Object.keys(t)}function wt(t){return yt(t)}function bt(t){const e=new Set;if(Array.isArray(t))for(const o of t)for(const t of yt(o))e.add(t);else for(const o in t)for(const n of yt(t[o]))e.add(n);return Array.from(e)}function Ct(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):bt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}function xt(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):wt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}const vt=({text:t,expression:e})=>t.includes(e);class At{constructor(t){this.rulesLookup=new N;for(const e of t){const t={by:o("by"in e?e.by:"FILTER"),condition:e.condition||vt};this.rulesLookup.addRule(e.column,e.row,t)}}resolve(t,e,o,n,r,i,l,s){const u=this.rulesLookup.getRules(r,n);if(0===u.length)return"DATA"!==n.type||"DATA"!==r.type||!s.has('"FILTER"')||vt({text:l,expression:s.get('"FILTER"')});let c={data:t,rows:e,columns:o,row:n,column:r,value:i,text:l};for(const t of u){if(!s.has(t.by))continue;const e={...c,expression:s.get(t.by)};if(!t.condition(e))return!1}return!0}}function Rt(t){return new At(t)}function It(t){return d(t,["value","text"])}function kt(t){return d(t,["value","text","font","padding"])}function Et(t,e,o,n,r,l,s){if(t.every((t=>"number"==typeof t.width)))return t;const u=t=>{if("DYNAMIC-BLOCK"===t.type)return t.width;const i=t.width;if("number"==typeof i)return i;if(r.has(t.key)){const e=r.get(t.key);if("fit-once"===i&&!e.dataOnly)return e.width;if("fit-data-once"===i&&e.dataOnly)return e.width}let l=0;for(const r of e){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const e=n.resolve(r,t),s=e.text,u=e.font,c=e.padding.left+e.padding.right,a=o.measureWidth(s,u)+c;l=Math.max(l,a)}return r.set(t.key,{width:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return t.map((t=>({...t,width:i(u(t),s)})))}function St(t,e,o,n,r,l,s){if(e.every((t=>"number"==typeof t.height)))return e;const u=e=>{if("DYNAMIC-BLOCK"===e.type)return e.height;const i=e.height;if("number"==typeof i)return i;if(r.has(e.key)){const t=r.get(e.key);if("fit-once"===i&&!t.dataOnly)return t.height;if("fit-data-once"===i&&t.dataOnly)return t.height}let l=0;for(const r of t){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const t=n.resolve(e,r),s=t.text,u=t.font,c=t.padding.top+t.padding.bottom,a=o.measureHeight(s,u)+c;l=Math.max(l,a)}return r.set(e.key,{height:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return e.map((t=>({...t,height:i(u(t),s)})))}function Dt(t){const e=new Set;for(const o of t)"DYNAMIC-BLOCK"!=o.type&&e.add(o.key);return e}function Tt(t){return d(t,["value","text"])}function Mt(t){return d(t,["value","sortOrder"])}function Bt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value<e.value?-1:t.value>e.value?1:0}function Lt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value>e.value?-1:t.value<e.value?1:0}class Ot{constructor(t){this.rulesLookup=new N;for(const e of t){const t=e.comparatorAsc||e.comparator,n=e.comparatorDesc||(e.comparator?(t,o)=>{return-("number"==typeof(n=e.comparator(t,o))?n:n?-1:1);var n}:null),r=t?(e,o)=>t(e,o):(t,e)=>Bt(t,e),i=n?(t,e)=>n(t,e):(t,e)=>Lt(t,e),l={by:o("by"in e?e.by:"HEADER"),comparatorAsc:r,comparatorDesc:i};this.rulesLookup.addRule(e.column,e.row,l)}}resolve(t,e,o){const n=this.rulesLookup.getRules(t,e);if(0===n.length)return"DATA"!==e.type||"DATA"!==t.type?null:o.has('"HEADER"')?"ASC"===o.get('"HEADER"')?Bt:Lt:null;if(n.length>1)throw new Error("Multiple sorting rules for the same cell");const r=n[0];return o.has(r.by)?"ASC"===o.get(r.by)?r.comparatorAsc:r.comparatorDesc:null}}function zt(t){return"manual"===t?null:new Ot(t)}function Nt(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.direction)}return r}function Kt(t,e){t.sort(((t,e)=>{const o=t.comparator(t.cell,e.cell);return"number"==typeof o?o:o?-1:1})),e.push(...t.map((t=>t.entity))),t.length=0}function Ft(t,e,n,r,i,l,s){if(0===t.length)return i;if(null===e)return i;const u=Nt(t,"columnId","rowId"),c=new Map(l.filter((t=>"DYNAMIC-BLOCK"!==t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.columnId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return i;for(const t of a){const o=[],c=[];for(const a of i){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(t,a,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,a,t,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),i=o}return i}function Ht(t,e,n,r,i,l,s){if(0===t.length)return l;if(null===e)return l;const u=Nt(t,"rowId","columnId"),c=new Map(i.filter((t=>"DYNAMIC-BLOCK"!=t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.rowId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return l;for(const t of a){const o=[],c=[];for(const a of l){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(a,t,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,t,a,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),l=o}return l}const Wt=5;function Pt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId));if("HEADER"!==n.get(o(r.rowId)).type)return null;if(!s.resizable)return null;if(!i)return null;const u=i.x;return u>=s.right-Wt&&u<=s.right+Wt?s.id:0===s.index||u<s.left-Wt||u>s.left+Wt?null:t[s.index-1].id}function Yt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId)),u=n.get(o(r.rowId));if("HEADER"!==s.type)return null;if(!u.resizable)return null;if(!i)return null;const c=i.y;return c>=u.bottom-Wt&&c<=u.bottom+Wt?u.id:0===u.index||c<u.top-Wt||c>u.top+Wt?null:t[u.index-1].id}function $t(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"HEADER",rowId:"rowId"in t?t.rowId:"HEADER",direction:t.direction})))}function Vt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"FILTER",rowId:"rowId"in t?t.rowId:"FILTER",expression:t.expression})))}function qt(t){return t.filter((t=>"DATA"===t.type)).map((t=>t.id))}function Gt(t){return qt(t)}function _t(t){return qt(t)}function jt(t){return d(t,["value","text","tooltip"])}function Ut(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!n.has(i))return null;if(!r.has(l))return null;const s=r.get(l),u=n.get(i);return e.resolve(s,u).tooltip}function Xt(t,e){return t?{left:e.x+8,top:e.y+20}:null}function Jt(t){return t.map((t=>o(t)))}function Qt(t,e){if(!e.length)return t;const o=new Map;for(const[t,n]of e.entries())o.set(n,t);const n=[],r=e.length;let i=0;for(const[e,l]of t.entries())if("DYNAMIC-BLOCK"===l.type)i++,n.push({entry:l,score:[i,0,0]}),i++;else{const t=l.key,s=o.has(t)?o.get(t):r;n.push({entry:l,score:[i,s,e]})}return n.sort(((t,e)=>function(t,e){if(t.length!=e.length)throw new Error("lengths should be the same");for(let o=0;o<t.length;o++){const n=t[o]-e[o];if(0!=n)return n}return 0}(t.score,e.score))).map((t=>t.entry))}function Zt(t,e){return Qt(t,e)}function te(t,e){return Qt(t,e)}function ee(t){return t.some((t=>"DYNAMIC-BLOCK"===t.type))}function oe(t){const e=[];for(const[o,n]of t){if(o>n)continue;if(0===e.length){e.push([o,n]);continue}const[t,r]=e[e.length-1];r<o-1?e.push([o,n]):(e.pop(),e.push([t,n]))}return e}function ne(t){return t.reduce(((t,e)=>"DYNAMIC-BLOCK"===e.type?t+e.count:t+1),0)}function re(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.left+i.left,h=d+r.width,f=[],p=(t,e)=>{f.push(e),s+=e.width+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),width:e.columnWidth})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",width:e*t.columnWidth+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,columnWidth:o}=t,r=o+l,i=n.left-u,c=a-n.right-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function ie(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.top+i.top,h=d+r.height,f=[],p=(t,e)=>{f.push(e),s+=e.height+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),height:e.rowHeight})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",height:e*t.rowHeight+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,rowHeight:o}=t,r=o+l,i=n.top-u,c=a-n.bottom-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function le(t,e,o,n,r,i){const l=t.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),s=e.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),u=Math.min(r,l),c=Math.min(o,s);return{left:u,top:c,right:Math.min(i,l-u),bottom:Math.min(n,s-c)}}function se(t){return{width:t.clientWidth,height:t.clientHeight}}function ue(t){return{left:t.scrollLeft,top:t.scrollTop}}function ce(t,e,o,n,r){if(!t)return null;const i=t.x,l=t.y;return{x:i<=n.left?i:i>=e.width?i+o.left:i>=e.width-n.right?r.width-e.width+i:i+o.left,y:l<=n.top?l:l>=e.height?l+o.top:l>=e.height-n.bottom?r.height-e.height+l:l+o.top}}function ae(t,e,n,r){if(!e)return t;if(!n)return t;if(!r)return t;const i=o(n.columnId),l=r.find((t=>"key"in t&&t.key===i));return"DATA"!==l?.type?t:r}function de(t,e,n,r){if(!e)return t;if(!n)return t;if(!r)return t;const i=o(n.rowId),l=r.find((t=>"key"in t&&t.key===i));return"DATA"!==l?.type?t:r}function he(t,e,o,n,r,i){return!!t&&(void 0===o||o<n||o>i-r||!e)}function fe(t,e,o,n){const r=t.position||"BEGIN",i=t.index%1*o;if("BEGIN"===r)return e+i;if("MIDDLE"===r)return e-(n-o)/2+i;if("END"===r)return e-(n-o)+i;throw new Error(`Invalid scroll position: ${r}`)}function pe(t,e,o,n,r,i,l,s,u){if(!he(t,e,r?.y,i.top,i.bottom,l.height))return null;let c=Math.floor(t.index)+n.top,a=-i.top,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.rowHeight+u)*e,c-=e,e<t.count){d=t.rowHeight;break}}else{if(0===c){d=t.height;break}a+=t.height+u,c-=1}return fe(t,a,d,s.height-i.top-i.bottom)}function me(t,e,o,n,r,i,l,s,u){if(!he(t,e,r?.x,i.left,i.right,l.width))return null;let c=Math.floor(t.index)+n.left,a=-i.left,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.columnWidth+u)*e,c-=e,e<t.count){d=t.columnWidth;break}}else{if(0===c){d=t.width;break}a+=t.width+u,c-=1}return fe(t,a,d,s.width-i.left-i.right)}function ge(t){return t?"number"==typeof t||"string"==typeof t?[{maxDistance:1/0,scrollSpeed:t}]:0===t.length?[{maxDistance:1/0,scrollSpeed:"smooth"}]:t.sort(((t,e)=>t.maxDistance-e.maxDistance)):[{maxDistance:1/0,scrollSpeed:"smooth"}]}function ye(t,e,o,n,r){return{verticalTarget:t,horizontalTarget:e,verticalSpeed:o,horizontalSpeed:n,clientSizeVersion:r}}function we(t){return{scrollbarWidth:t.scrollbarWidth||"auto"}}function be(t,e,o,n,r,i){return{sections:t,devicePixelRatio:e,scrollRect:o,renderFormatResolver:n,borderWidth:r,textResolver:i}}function Ce(t,e){return{inputPlacement:t,isTextValid:e}}function xe(t,e,o){return{resizableColumn:t,resizableRow:e,isReordering:o}}function ve(t,e){return{tooltip:t,tooltipPlacement:e}}function Ae(t){return t.measureHeight("X",M)+B.top+B.bottom}function Re(t,e){return!t&&!e||!(!t||!e)&&t.x===e.x&&t.y===e.y}function Ie(t,e){return!t&&!e||!(!t||!e)&&t.width===e.width&&t.height===e.height}function ke(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top}function Ee(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height}function Se(t,e){return!t&&!e||!(!t||!e)&&o(t.rowId)===o(e.rowId)&&o(t.columnId)===o(e.columnId)}function De(t,e){return!t&&!e||!(!t||!e)&&t.scrollbarWidth===e.scrollbarWidth}function Te(t){const e={...t.localOptions,...t.externalOptions},o=t.memory,n=t.state,i=t.element,l=[];function s(t,e,n,r=((t,e)=>t===e)){const i=o[t]&&o[t].dependencies;if(!i||n.some(((t,e)=>t!==i[e]))){const i=o[t]&&o[t].value,s=o[t]&&o[t].version||0,u=e(...n);r(i,u)?o[t]={value:i,dependencies:n,version:s}:(o[t]={value:u,dependencies:n,version:s+1},l.push(t))}return o[t].value}function c(t,e,n){(o[t]&&o[t].value)!==e&&(o[t]={value:e},n(e))}const a=s("devicePixelRatio",(t=>t),[window.devicePixelRatio]),d=s("borderWidth",(t=>t),[e.borderWidth/a]),f=e.data,y=t.input.value,b=s("sortBy",$t,[e.sortBy]),A=s("filters",Vt,[e.filters]),R=s("textResolver",et,[]),I=s("dataFormatting",u,[e.formatting,e.dataSelector,b]),S=s("editedCellsAndFilters",g,[e.editedCells,A]),M=s("edition",w,[S]),B=s("invokedColumns",x,[e.columns,f]),L=s("invokedRows",v,[e.rows,f]),O=s("mousePosition",(t=>t),[t.mousePosition],Re),z=s("unfoldedColumns",Ct,[B,f]),N=s("unfoldedRows",xt,[L,f]),K=s("dynamicRowHeight",Ae,[R]),F=s("unfilteredColumns",k,[z,e.columnWidths,d,a,150]),H=s("unfilteredRows",E,[N,e.rowHeights,d,a,K]),W=s("unfilteredColumnKeys",Dt,[F]),P=s("unfilteredRowKeys",Dt,[H]),$=s("columnsOrder",Jt,[e.columnsOrder]),q=s("rowsOrder",Jt,[e.rowsOrder]),j=s("orderedColumns",Zt,[F,$]),U=s("orderedRows",te,[H,q]),J=s("filterFormatting",It,[I]),Q=s("filterFormattingRules",Y,[J]),tt=s("filteringRules",Rt,[e.filtering]),ot=s("filteredColumns",_,[A,tt,Q,f,U,j,M]),nt=s("filteredRows",G,[A,tt,Q,f,U,j,M]),rt=s("sortingFormatting",Tt,[I]),it=s("sortingFormattingRules",Y,[rt]),lt=s("sortingRules",zt,[e.sorting]),st=s("sortedColumns",Ht,[b,lt,it,f,nt,ot,M]),ut=s("sortedRows",Ft,[b,lt,it,f,nt,ot,M]),ct=e.freezeOnHover&&!l.includes("sortBy")&&!l.includes("filters"),pt=s("shapedColumns",ae,[st,ct,n?.hoveredCell,n?.shapedColumns]),yt=s("shapedRows",de,[ut,ct,n?.hoveredCell,n?.shapedRows]),wt=s("pinning",le,[pt,yt,e.pinnedTop,e.pinnedBottom,e.pinnedLeft,e.pinnedRight]),bt=s("measureFormatting",kt,[I]),vt=s("measureFormattingRules",Y,[bt]),At=s("measureFormatResolver",V,[vt,f,yt,pt,M]),Bt=t.columnWidthCache,Lt=t.rowHeightCache,Ot=s("measuredColumns",Et,[pt,yt,R,At,Bt,W,a]),Nt=s("measuredRows",St,[pt,yt,R,At,Lt,P,a]),Kt=s("fixedSize",X,[Ot,Nt,wt,d]),Wt=s("totalSize",Z,[Ot,Nt,d]),qt=s("clientSize",(t=>t),[se(i)],Ie),Qt=s("boundingClientSize",(t=>t),[se(i)],Ie),ee=s("scrollOffset",(t=>t),[ue(i)],ke),oe=s("internalMousePosition",ce,[O,qt,ee,Kt,Wt],Re),ne=s("scrollRect",at,[n?.renderState?.scrollRect,ee,Wt,Kt,Qt],Ee),he=s("horizontalScrollTarget",me,[e.horizontalScrollTarget,e.disableScrollOnHover,Ot,wt,oe,Kt,Wt,qt,d]),fe=s("verticalScrollTarget",pe,[e.verticalScrollTarget,e.disableScrollOnHover,Nt,wt,oe,Kt,Wt,qt,d]),Te=s("horizontalScrollSpeed",ge,[e.horizontalScrollSpeed]),Me=s("verticalScrollSpeed",ge,[e.verticalScrollSpeed]),Be=s("staticColumns",re,[f,Ot,wt,ne,Kt,d]),Le=s("staticRows",ie,[f,Nt,wt,ne,Kt,d]),Oe=s("columns",D,[Be,wt,d]),ze=s("rows",T,[Le,wt,d]),Ne=s("columnLookup",ht,[Oe]),Ke=s("rowLookup",ht,[ze]),Fe=e.focusedCell,He=s("sections",m,[Oe,ze]),We=e.selectedCells,Pe=s("hoveredCell",dt,[oe,ze,Oe,Kt,Wt],Se),Ye=t.isReordering,$e=t.resizingColumn||s("resizableColumn",Pt,[Oe,Ne,Ke,Pe,oe,Ye]),Ve=t.resizingRow||s("resizableRow",Yt,[ze,Ne,Ke,Pe,oe,Ye]),qe=s("highlightedCells",ft,[t.isMouseDown,!$e&&!Ve&&!t.didReorder,Fe,Pe,Oe,ze,Ne,Ke]),Ge=s("selection",C,[We]),_e=s("highlight",C,[qe]),je=s("renderFormatting",p,[I,Pe,Fe,Ge,_e,M,b,$e,Ve,e.borderWidth,Ye,t.reorderedColumn,t.reorderedRow]),Ue=s("renderFormattingRules",Y,[je]),Xe=s("renderFormatResolver",V,[Ue,f,ze,Oe,M]),Je=s("sortOrderFormatting",Mt,[I]),Qe=s("sortOrderFormattingRules",Y,[Je]),Ze=s("sortOrderFormatResolver",V,[Qe,f,ze,Oe,M]),to=s("inputFormatting",h,[I]),eo=s("inputFormattingRules",Y,[to]),oo=s("inputFormatResolver",V,[eo,f,ze,Oe,M]),no=s("editableCells",r,[We,oo,Ne,Ke]),ro=s("inputPlacement",mt,[no,Fe,Ne,Ke,He]),io=s("isTextValid",gt,[y,no]),lo=s("contextFormatting",jt,[I]),so=s("contextFormattingRules",Y,[lo]),uo=s("contextFormatResolver",V,[so,f,ze,Oe,M]),co=s("tooltip",Ut,[Pe,uo,Ne,Ke]),ao=s("tooltipPlacement",Xt,[co,O]),ho=s("renderState",be,[He,a,ne,Xe,d,R]),fo=s("inputState",Ce,[ro,io]),po=s("cursorState",xe,[$e,Ve,t.isReordering]),mo=s("tooltipState",ve,[co,ao]),go=s("scrollState",ye,[fe,he,Me,Te,o.clientSize.version]),yo=s("styleState",we,[e.style],De),wo=s("activeColumns",Gt,[Oe]),bo=s("activeRows",_t,[ze]);c("activeColumnsCallback",wo,e.onActiveColumnsChange),c("activeRowsCallback",bo,e.onActiveRowsChange),c("hoveredCellCallback",Pe,e.onHoveredCellChange),e.onStateChange(l),t.state={options:e,edition:M,columns:Oe,rows:ze,hoveredCell:Pe,focusedCell:Fe,inputFormatResolver:oo,fixedSize:Kt,totalSize:Wt,clientSize:qt,scrollOffset:ee,highlightedCells:qe,columnLookup:Ne,rowLookup:Ke,text:y,scrollState:go,styleState:yo,sortOrderFormatResolver:Ze,renderState:ho,inputState:fo,cursorState:po,tooltipState:mo,shapedColumns:pt,shapedRows:yt}}function Me(t,e){const o=new b(e);return[...e,...t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))]}function Be(t,e){const o=new b(e);return t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))}function Le(t){const e=t.currentTarget;if(!(e instanceof HTMLElement))throw new Error("Element is not an HTMLElement");const o=e.getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}}function Oe(t,e){return t.map((t=>({...t,columnId:"columnId"in t?t.columnId:e,rowId:"rowId"in t?t.rowId:e})))}function ze(t,e,n){const r=o(e),i=o(n);if(r===i)return null;const l=t.findIndex((t=>t.key===r)),s=t.findIndex((t=>t.key===i));return-1===l||-1===s||l===s?null:[l,s]}function Ne(t){const e=t.element;t.scrollAnimationId&&(cancelAnimationFrame(t.scrollAnimationId),t.scrollAnimationId=null,e.scrollTop=e.scrollTop,e.scrollLeft=e.scrollLeft)}function Ke(t,e,o,n){return t>0?Math.min(t,e*o+n):Math.max(t,-e*o+n)}function Fe(t,e,o,n,r,i,l,s,u,c,a){if(null===n)return null;const d=n-o;if(Math.abs(d)<1)return null;if(d<0&&0===o)return null;if(d>0&&o>=i-r-1)return null;const h=function(t,e){const o=Math.abs(e);for(const e of t)if(o<=e.maxDistance)return e.scrollSpeed;return"auto"}(u,d);return a||"auto"===h?{[t]:n,behavior:"auto"}:"number"==typeof h?{[t]:o+Ke(d,h,e,c),behavior:"auto"}:l!==n||s===o?{[t]:n}:null}function He(t,e){if(t.errorRendered)return;t.errorRendered=!0;const o=t.element;o.style.backgroundColor="#9f0000",o.style.color="white",o.style.padding="20px",o.style.display="flex",o.style.flexDirection="column",o.style.userSelect="text",o.innerHTML=`\n <div style="font-size: 16px;">\n An error occurred while rendering the grid, please contact the support.\n </div>\n <div style="font-size: 20px; font-weight: bold; padding: 20px 0;">\n ${e.message}\n </div>\n <div style="font-size: 16px; white-space: pre-wrap;">${e.stack}</div>\n `}function We(t){if(!t.errorRendered)try{Te(t),t.state.styleState!==t.lastStyleState&&(t.lastStyleState=t.state.styleState,function(t){const e=t.state.styleState,o=t.element,n=`\n max-width: 100vw;\n max-height: 100vh;\n overflow: auto;\n display: grid;\n position: relative;\n grid-template-columns: fit-content(0) fit-content(0) fit-content(0);\n grid-template-rows: fit-content(0) fit-content(0) fit-content(0);\n outline: none;\n user-select: none;\n touch-action: manipulation;\n scrollbar-width: ${e.scrollbarWidth};\n `;o.setAttribute("style",n)}(t)),t.state.renderState!==t.lastRenderState&&(t.lastRenderState=t.state.renderState,function(t){l(t,"top","left"),l(t,"top","center"),l(t,"top","right"),l(t,"middle","left"),l(t,"middle","center"),l(t,"middle","right"),l(t,"bottom","left"),l(t,"bottom","center"),l(t,"bottom","right")}(t)),t.state.inputState!==t.lastInputState&&(t.lastInputState=t.state.inputState,function(t){const e=t.element,o=t.input,n=t.state.inputState,r=n.inputPlacement;if(!r){if(o.parentElement){const t=document.activeElement===o;o.parentElement.removeChild(o),t&&e.focus({preventScroll:!0})}return}const i=t.canvases[r.section];if(o.style.left="left"in r?`${r.left}px`:"0",o.style.top="top"in r?`${r.top}px`:"0",o.style.right="right"in r?`${r.right}px`:"0",o.style.bottom="bottom"in r?`${r.bottom}px`:"0",o.style.marginLeft="marginLeft"in r?`${r.marginLeft}px`:"0",o.style.marginTop="marginTop"in r?`${r.marginTop}px`:"0",o.style.width=`${r.width}px`,o.style.height=`${r.height}px`,o.style.gridArea=i.style.gridArea,o.style.zIndex=i.style.zIndex,o.style.backgroundColor=n.isTextValid?"white":"#eb3434",!o.parentElement){const t=document.activeElement===e;e.appendChild(o),t&&o.focus({preventScroll:!0})}}(t)),t.state.cursorState!==t.lastCursorState&&(t.lastCursorState=t.state.cursorState,function(t){const e=t.element,o=t.state.cursorState;o.isReordering?e.style.cursor="move":o.resizableColumn&&o.resizableRow?e.style.cursor="nwse-resize":o.resizableColumn?e.style.cursor="col-resize":o.resizableRow?e.style.cursor="row-resize":e.style.cursor="default"}(t)),t.state.tooltipState!==t.lastTooltipState&&(t.lastTooltipState=t.state.tooltipState,function(t){const e=t.element,o=t.tooltip,n=t.state.tooltipState,r=n.tooltip,i=n.tooltipPlacement;i?(o.innerHTML!==r&&(o.innerHTML=r),o.style.left=`calc(anchor(left) + ${i.left}px)`,o.style.top=`calc(anchor(top) + ${i.top}px)`,o.parentElement||(e.appendChild(o),o.showPopover({source:e}))):o.parentElement&&o.parentElement.removeChild(o)}(t)),t.state.scrollState!==t.lastScrollState&&(t.lastScrollState=t.state.scrollState,function(t){const e=t.element,o=t.state.scrollState,n=o.verticalTarget,r=o.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Ne(t);if(t.scrollAnimationId)return;let i=performance.now(),l=null,s=null,u={top:e.scrollTop,left:e.scrollLeft},c=0,a=0;const d=o=>{const n=t.state.scrollState.verticalTarget,r=t.state.scrollState.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Ne(t);null===n&&(s=null),null===r&&(l=null);const h=(o-i)/1e3;i=o;const f=t.lastScrollClientSizeVersion!==t.state.scrollState.clientSizeVersion;t.lastScrollClientSizeVersion=t.state.scrollState.clientSizeVersion;const p=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.verticalTarget;return Fe("top",e,l.scrollTop,u,l.clientHeight,l.scrollHeight,o?.top,n.top,s.verticalSpeed,r,i)}(t,h,s,u,c,f),m=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.horizontalTarget;return Fe("left",e,l.scrollLeft,u,l.clientWidth,l.scrollWidth,o?.left,n.left,s.horizontalSpeed,r,i)}(t,h,l,u,a,f),g={...s,...l,behavior:"smooth",...p,...m};(p||m)&&e.scrollTo(g),c=p&&"auto"===g.behavior?g.top-e.scrollTop:0,a=m&&"auto"===g.behavior?g.left-e.scrollLeft:0,s=p||s,l=m||l,u={top:e.scrollTop,left:e.scrollLeft},t.scrollAnimationId=requestAnimationFrame(d)};d(i)}(t))}catch(e){He(t,e)}}function Pe(t){if("spread-grid-context"in t)return;const e={"top-left":document.createElement("canvas"),"top-center":document.createElement("canvas"),"top-right":document.createElement("canvas"),"middle-left":document.createElement("canvas"),"middle-center":document.createElement("canvas"),"middle-right":document.createElement("canvas"),"bottom-left":document.createElement("canvas"),"bottom-center":document.createElement("canvas"),"bottom-right":document.createElement("canvas")},i=document.createElement("input"),l=document.createElement("div");t.setAttribute("tabindex","0"),t.classList.add("spread-grid"),e["top-left"].setAttribute("style","position: sticky; left: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 1;"),e["top-center"].setAttribute("style","position: sticky; top: 0; z-index: 1; grid-row: 1; grid-column: 2;"),e["top-right"].setAttribute("style","position: sticky; right: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 3;"),e["middle-left"].setAttribute("style","position: sticky; left: 0; z-index: 1; grid-row: 2; grid-column: 1;"),e["middle-center"].setAttribute("style","grid-row: 2; grid-column: 2; z-index: 0;"),e["middle-right"].setAttribute("style","position: sticky; right: 0; z-index: 1; grid-row: 2; grid-column: 3;"),e["bottom-left"].setAttribute("style","position: sticky; left: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 1;"),e["bottom-center"].setAttribute("style","position: sticky; bottom: 0; z-index: 1; grid-row: 3; grid-column: 2;"),e["bottom-right"].setAttribute("style","position: sticky; right: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 3;"),i.setAttribute("style","position: sticky; z-index: 3; outline: none; border: none; box-shadow: none; padding: 0 5px; font-size: 12px; font-family: Calibri; background-color: white; box-sizing: border-box; opacity: 0; pointer-events: none;"),l.setAttribute("style","pointer-events: none; background-color: white; color: black; border: 1px solid black; padding: 3px 7px; inset: unset; position: absolute; font-size: 12px; font-family: Calibri; "),l.setAttribute("popover","manual"),l.classList.add("spread-grid-tooltip");const s={element:t,canvases:e,input:i,tooltip:l,localOptions:null,externalOptions:{},state:null,memory:{},renderRequested:!1,mousePosition:null,isMouseDown:!1,columnWidthCache:new Map,rowHeightCache:new Map,isReordering:!1,errorRendered:!1,error:null,resizingColumn:null,resizingRow:null,reorderedColumn:null,reorderedRow:null,didReorder:!1,mouseDownPosition:null,mouseDownCell:null,requestNewRender:null,fractionalScrollProgressVertical:0,fractionalScrollProgressHorizontal:0};function u(t,e,o){t.addEventListener(e,(t=>{try{o(t)}catch(t){t.message=`[${e} event]: ${t.message}`,He(s,t)}}))}s.requestNewRender=()=>{s.renderRequested||s.errorRendered||(s.renderRequested=!0,requestAnimationFrame((()=>{s.renderRequested=!1,We(s)})))},s.localOptions={data:[],columns:[{type:"DATA-BLOCK"}],rows:[{type:"HEADER"},{type:"DATA-BLOCK"}],formatting:[],filtering:[],sorting:[],dataSelector:({data:t,row:e,column:o})=>t?.[e.selector]?.[o.selector],pinnedTop:0,pinnedBottom:0,pinnedLeft:0,pinnedRight:0,borderWidth:1,focusedCell:null,onFocusedCellChange:t=>{s.localOptions.focusedCell=t,s.requestNewRender()},selectedCells:[],onSelectedCellsChange:t=>{s.localOptions.selectedCells=t,s.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:t=>{s.localOptions.editedCells=t,s.requestNewRender()},filters:[],onFiltersChange:t=>{s.localOptions.filters=t,s.requestNewRender()},sortBy:[],onSortByChange:t=>{s.localOptions.sortBy=t,s.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:t=>{s.localOptions.columnWidths=t,s.requestNewRender()},rowHeights:[],onRowHeightsChange:t=>{s.localOptions.rowHeights=t,s.requestNewRender()},columnsOrder:[],onColumnsOrderChange:t=>{s.localOptions.columnsOrder=t,s.requestNewRender()},rowsOrder:[],onRowsOrderChange:t=>{s.localOptions.rowsOrder=t,s.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{},verticalScrollTarget:null,horizontalScrollTarget:null,verticalScrollSpeed:"smooth",horizontalScrollSpeed:"smooth",disableScrollOnHover:!0,freezeOnHover:!1,style:{}},t["spread-grid-context"]=s;const c=t=>{i.value=t,i.dispatchEvent(new Event("input"))},a=t=>{const e=s.state.options.selectedCells,o=s.state.inputFormatResolver,n=s.state.columnLookup,i=s.state.rowLookup,l=s.state.text,u=s.state.inputState.isTextValid,a=s.state.options.onEditedCellsChange,d=s.state.options.onFiltersChange,h=r(e,o,n,i);if(""===l)return;if(!u)return;if(t&&!h.every((t=>t.edit.autoCommit)))return;const f=h.filter((t=>"DATA"===t.type)),p=h.filter((t=>"FILTER"===t.type));var m;m=f.map((t=>({...t.cell,value:t.edit.parse({string:l})}))),a(Me(s.state.options.editedCells,m)),(t=>{d(Me(Oe(s.state.options.filters,"FILTER"),t))})(p.map((t=>({...t.cell,expression:t.edit.parse({string:l})})))),t||c("")},d=t=>{const e=s.state.options.selectedCells,o=s.state.options.onEditedCellsChange,n=s.state.options.onFiltersChange,i=r(e,s.state.inputFormatResolver,s.state.columnLookup,s.state.rowLookup);var l;t&&!i.every((t=>t.edit.autoCommit))||(l=e,o(Be(s.state.options.editedCells,l)),(t=>{n(Be(Oe(s.state.options.filters,"FILTER"),t))})(e))};u(t,"scroll",(t=>{s.requestNewRender()})),u(t,"pointerenter",(t=>{s.mousePosition=Le(t),s.requestNewRender()})),u(t,"pointermove",(t=>{if(s.mousePosition=Le(t),s.resizingColumn){const t=s.state.columnLookup.get(o(s.resizingColumn)),e=t.width,n=t.right,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.x-n+e),l=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t.key)).concat([{columnId:t.id,width:i}]);s.state.options.onColumnWidthsChange(l)}if(s.resizingRow){const t=s.state.rowLookup.get(o(s.resizingRow)),e=t.height,n=t.bottom,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.y-n+e),l=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t.key)).concat([{rowId:t.id,height:i}]);s.state.options.onRowHeightsChange(l)}if(s.reorderedColumn){const t=s.state.columns,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=ze(t,e,o.columnId);if(!r)return null;const[i,l]=r,s=l<=i?n.x<t[l].leftWithBorder+t[i].width?l:l+1:n.x>t[l].rightWithBorder-t[i].width?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedColumn,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onColumnsOrderChange(n))}if(s.reorderedRow){const t=s.state.rows,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=ze(t,e,o.rowId);if(!r)return null;const[i,l]=r,s=l<=i?n.y<t[l].topWithBorder+t[i].height?l:l+1:n.y>t[l].bottomWithBorder-t[i].height?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedRow,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onRowsOrderChange(n))}s.requestNewRender()})),u(t,"touchmove",(t=>{(s.resizingColumn||s.resizingRow||s.reorderedColumn||s.reorderedRow)&&(t.preventDefault(),t.stopPropagation())})),u(t,"pointerleave",(()=>{s.mousePosition=null,s.requestNewRender()})),u(t,"pointerdown",(t=>{s.mousePosition=Le(t),Te(s),c("");const e=s.state.hoveredCell;if(s.isMouseDown=!0,s.didReorder=!1,s.mouseDownPosition=s.mousePosition,s.mouseDownCell=e,s.state.cursorState.resizableColumn&&(s.resizingColumn=s.state.cursorState.resizableColumn),s.state.cursorState.resizableRow&&(s.resizingRow=s.state.cursorState.resizableRow),!s.resizingColumn&&e){const t=s.state.rowLookup.get(o(e.rowId));s.reorderedColumn="HEADER"===t.type?e.columnId:null}if(!s.resizingRow&&e){const t=s.state.columnLookup.get(o(e.columnId));s.reorderedRow="HEADER"===t.type?e.rowId:null}s.resizingColumn||s.resizingRow||s.state.options.onFocusedCellChange(e),t.ctrlKey||s.state.options.onSelectedCellsChange([]),s.requestNewRender()})),u(t,"pointerup",(t=>{s.mousePosition=Le(t),Te(s),s.isMouseDown=!1,s.isReordering=!1,s.resizingColumn=null,s.resizingRow=null,s.reorderedColumn=null,s.reorderedRow=null,s.state.options.onSelectedCellsChange(Me(s.state.options.selectedCells,s.state.highlightedCells)),s.requestNewRender()})),u(t,"pointerdown",(t=>{s.element.setPointerCapture(t.pointerId)})),u(t,"pointerup",(t=>{s.element.releasePointerCapture(t.pointerId)})),u(t,"click",(t=>{s.mousePosition=Le(t),Te(s);const e=s.state.hoveredCell,r=s.mouseDownCell;if(s.state.cursorState.resizableColumn||s.state.cursorState.resizableRow)return;if(s.didReorder)return;if(null===e)return;if(null===r)return;if(o(e.columnId)!==o(r.columnId))return;if(o(e.rowId)!==o(r.rowId))return;const i=s.state.columnLookup.get(o(e.columnId)),l=s.state.rowLookup.get(o(e.rowId)),u=s.state.options.sortBy,c=s.state.inputFormatResolver.resolve(l,i),a={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,detail:t.detail};if(c.edit?.toggle){const t=function(t,e,o,n){const r=n.hasValueByKey(o.key,e.key)?n.getValueByKey(o.key,e.key):t.value,i=t.edit.toggle;return"function"==typeof i?i({value:r}):i[(i.indexOf(r)+1)%i.length]}(c,i,l,s.state.edition),o=n(i,l);"DATA"===o&&s.state.options.onEditedCellsChange(Me(s.state.options.editedCells,[{...e,value:t}])),"FILTER"===o&&s.state.options.onFiltersChange(Me(Oe(s.state.options.filters,"FILTER"),[{...e,expression:t}]))}else if("DATA"===i.type&&"DATA"===l.type)s.state.options.onCellClick({...s.state.hoveredCell,...a});else if("CUSTOM"===i.type||"CUSTOM"===l.type)s.state.options.onCustomCellClick({...s.state.hoveredCell,...a});else if("HEADER"===i.type||"HEADER"===l.type){const e=s.state.sortOrderFormatResolver.resolve(l,i),n=function(t,e,n,r,i){function l(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return e.key===o(r)&&n.key===o(i)}const s=i?i.map((t=>null===t?void 0:t)):["ASC","DESC",void 0],u=t.find(l),c=s.indexOf(u?.direction),a=s[(c+1)%s.length],d=t.indexOf(u)===t.length-1;return[...!r||!d&&u?t.filter((t=>!function(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return"HEADER"===e.type&&e.key===o(r)||"HEADER"===n.type&&n.key===o(i)}(t))):t.filter((t=>!l(t))),...a?[{columnId:e.id,rowId:n.id,direction:a}]:[]]}(u,i,l,t.ctrlKey,e.sortOrder);s.state.options.onSortByChange(n),s.state.options.onSelectedCellsChange([])}})),u(t,"dblclick",(t=>{if(s.mousePosition=Le(t),Te(s),s.state.cursorState.resizableColumn){const t=o(s.state.cursorState.resizableColumn),e=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t));s.state.options.onColumnWidthsChange(e),s.columnWidthCache.delete(t)}if(s.state.cursorState.resizableRow){const t=o(s.state.cursorState.resizableRow),e=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t));s.state.options.onRowHeightsChange(e),s.rowHeightCache.delete(t)}const e=s.state.focusedCell;if(null===e)return;const n=o(e.columnId),r=o(e.rowId),l=s.state.columnLookup,u=s.state.rowLookup,a=s.state.inputFormatResolver;if(!l.has(n))return;if(!u.has(r))return;const d=l.get(n),h=u.get(r),f=a.resolve(h,d),p=f.text;f.edit&&(f.edit.toggle||(c(p),i?.select()))})),u(t,"focus",(()=>{i.parentElement&&i.focus({preventScroll:!0})})),u(t,"keydown",(t=>{Te(s);const e=s.state.focusedCell,n=s.state.columnLookup,r=s.state.rowLookup,i=s.state.options.selectedCells,l=s.state.options.onSelectedCellsChange,u=s.state.options.onFocusedCellChange,h=s.state.options.editedCells,f=s.state.options.onEditedCellsChange,p=s.state.columns,m=s.state.rows,g=s.state.text,y=s.state.inputFormatResolver,w=(t,e)=>{u(t),e.shiftKey?l(Me(i,[t])):l([t])},C=(t,r)=>{if(!e)return;const i=o(e.columnId);if(!n.has(i))return;const l=n.get(i).index,s=Math.max(0,Math.min(p.length-1,l+t));if(s===l)return;const u={rowId:e.rowId,columnId:p[s].id};w(u,r)},x=(t,n)=>{if(!e)return;const i=o(e.rowId);if(!r.has(i))return;const l=r.get(i).index,s=Math.max(0,Math.min(m.length-1,l+t));if(s===l)return;const u={rowId:m[s].id,columnId:e.columnId};w(u,n)},v=()=>{t.preventDefault(),t.stopPropagation()};switch(t.key){case"Escape":""!==g?c(""):i.length>1?l([e]):h.length>0?f([]):(u(null),l([]));break;case"Enter":a(!1);break;case"ArrowUp":v(),x(t.ctrlKey?-m.length:-1,t);break;case"ArrowDown":v(),x(t.ctrlKey?m.length:1,t);break;case"ArrowLeft":v(),C(t.ctrlKey?-p.length:-1,t);break;case"ArrowRight":v(),C(t.ctrlKey?p.length:1,t);break;case"Delete":case"Backspace":d(!1);break;case"c":(t=>{if(!t.ctrlKey)return;const e=function(t,e,n,r){const i=new Map(e.map((t=>[t.key,t]))),l=new Map(n.map((t=>[t.key,t]))),s=t.map((t=>({columnKey:o(t.columnId),rowKey:o(t.rowId)}))).filter((t=>i.has(t.columnKey)&&l.has(t.rowKey))),u=new Set(s.map((t=>t.columnKey))),c=new Set(s.map((t=>t.rowKey)));if(0===s.length)return"";const a=new b(t),d=Math.min(...s.map((t=>i.get(t.columnKey).index))),h=Math.max(...s.map((t=>i.get(t.columnKey).index))),f=Math.min(...s.map((t=>l.get(t.rowKey).index))),p=Math.max(...s.map((t=>l.get(t.rowKey).index))),m=[];for(let t=f;t<=p;t++){const o=n[t],i=o.key;if(c.has(i)){for(let t=d;t<=h;t++){const n=e[t],l=n.key;if(u.has(l)){if(a.isKeySelected(i,l)){const t=r.resolve(o,n).text;m.push(t)}t<h&&m.push("\t")}}t<p&&m.push("\n")}}return m.join("")}(i,p,m,y);if(navigator.clipboard)navigator.clipboard.writeText(e);else{const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}})(t)}})),new ResizeObserver((()=>{s.requestNewRender()})).observe(t),u(i,"input",(t=>{Te(s),i.value?(a(!0),i.style.opacity="1",i.style.pointerEvents="auto"):(t.isTrusted&&d(!0),i.style.opacity="0",i.style.pointerEvents="none")})),u(i,"click",(t=>{t.stopPropagation()})),u(i,"dblclick",(t=>{t.stopPropagation()})),u(i,"pointerdown",(t=>{t.stopPropagation()})),u(i,"keydown",(t=>{switch(t.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==i.value&&(t.stopPropagation(),s.requestNewRender());break;default:t.stopPropagation(),s.requestNewRender()}})),u(t,"wheel",(e=>{null===s.state.scrollState.verticalTarget&&null===s.state.scrollState.horizontalTarget||(t.scrollBy({top:e.deltaY,left:e.deltaX,behavior:"auto"}),e.preventDefault(),e.stopPropagation())}))}function Ye(t,e){Pe(t);const o=t["spread-grid-context"];o.externalOptions=e,null===o.state?We(o):o.requestNewRender()}return e.default})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SpreadGrid=e():t.SpreadGrid=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function o(t){return null===t?"null":Array.isArray(t)?`[${t.map(o).join(",")}]`:"object"==typeof t?(e=t,`{${Object.keys(e).sort().map((t=>`${t}:${o(e[t])}`)).join(",")}}`):JSON.stringify(t);var e}function n(t,e){const o="FILTER"===t.type,n="FILTER"===e.type;return o&&!n||!o&&n?"FILTER":"DATA"}function r(t,e,r,i){return t.map((t=>{const l=o(t.columnId),s=o(t.rowId);if(!r.has(l))return null;if(!i.has(s))return null;const u=r.get(l),c=i.get(s);return{edit:e.resolve(c,u).edit,cell:t,type:n(u,c)}})).filter((t=>t?.edit))}function i(t,e){return Math.round(t*e)/e}function l(t,e,o){const n=t.state.renderState,r=t.canvases[`${e}-${o}`],l=n.sections[e],s=n.sections[o],u=s.columns,c=l.rows,a=n.devicePixelRatio;if(0===c.length||0===u.length)return void(r.parentElement&&r.parentElement.removeChild(r));r.parentElement||t.element.appendChild(r);const d=r.getContext("2d",{alpha:!1}),h=n.scrollRect,f=n.textResolver,p=n.renderFormatResolver,m=n.borderWidth,g=l.showTopBorder,y=l.showBottomBorder,w=s.showLeftBorder,b=s.showRightBorder,C=m/2,x=c.length-1+(g?1:0)+(y?1:0),v=u.length-1+(w?1:0)+(b?1:0),A=c.map((t=>t.height)),R=u.map((t=>t.width)),I=R.reduce(((t,e)=>t+e),0)+v*m,k=A.reduce(((t,e)=>t+e),0)+x*m,E="center"===o?h.left:0,S="middle"===e?h.top:0,D="center"===o?h.width:s.width,T="middle"===e?h.height:l.height,M=R.reduce(((t,e,o)=>{const n=t[o]+e+m;return t.push(n),t}),[w?m:0]),B=A.reduce(((t,e,o)=>{const n=t[o]+e+m;return t.push(n),t}),[g?m:0]),L=M.slice(0,-1),O=B.slice(0,-1),z=Math.max(L.findLastIndex((t=>t<=E)),0),N=L.findLastIndex((t=>t<=E+D)),K=Math.max(O.findLastIndex((t=>t<=S)),0),F=O.findLastIndex((t=>t<=S+T)),H=Math.max(z,w?0:1),W=N+(b?1:0),P=Math.max(K,g?0:1),Y=F+(y?1:0),$=Array.from({length:F-K+1},((t,e)=>{const o=c[e+K];return Array.from({length:N-z+1},((t,e)=>{const n=u[e+z];return p.resolve(o,n)}))})),V=(t,e)=>$[t-K][e-z];r.width=Math.round(D*a),r.height=Math.round(T*a),r.style.width=`${D}px`,r.style.height=`${T}px`,r.style.marginLeft=`${E}px`,r.style.marginTop=`${S}px`,r.style.marginRight=I-D-E+"px",r.style.marginBottom=k-T-S+"px",d.fillStyle="#E9E9E9",d.fillRect(0,0,r.width,r.height);const q=(t,e)=>{d.setTransform(a,0,0,a,(t-E)*a,(e-S)*a)},G=(t,e,o,n)=>{d.beginPath(),d.rect(t,e,o,n),d.clip()};for(let t=z;t<=N;t++)for(let e=K;e<=F;e++){const o=V(e,t);if(!o.render)continue;const n=o.style,r=B[e],l=M[t],s=R[t],u=A[e],c=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(q(l,r),d.fillStyle=n.background||"white",d.fillRect(0,0,s,u),"draw"in o&&o.draw(d),n.highlight&&(d.fillStyle=n.highlight,d.fillRect(0,0,s,u)),n.corner&&(d.fillStyle=n.corner,d.beginPath(),d.moveTo(s-7,u),d.lineTo(s,u),d.lineTo(s,u-7),d.fill()),c&&"transparent"!==g){d.fillStyle=g,d.font=o.font;const t=f.getFontMetrics(o.font),e="center"==n.textAlign&&f.measureWidth(c,o.font)>s-p.left-p.right?"left":n.textAlign||"left";d.textAlign=e;const r=i("left"===e?p.left:"center"===e?s/2:"right"===e?s-p.right:0,a),l=i("top"===h?t.middle+t.topOffset+p.top:"middle"===h?u/2+t.middle:"bottom"===h?u+t.middle-t.bottomOffset-p.bottom:0,a);d.save(),G(0,2*m,s,u-4*m),d.fillText(c,r,l),d.restore()}}q(0,0);const _=(t,e,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/a,l=e===n,s=t-(l?i/2:0),u=e-(l?0:i/2),c=o+(l?i/2:0),h=n+(l?0:i/2);d.strokeStyle=r.color||"black",d.lineWidth=i,r.dash?(d.setLineDash(r.dash.map((t=>t/a))),d.lineDashOffset=l?s:u):d.setLineDash([]),d.beginPath(),d.moveTo(s,u),d.lineTo(c,h),d.stroke()},j=(t,e)=>t?e?t.index>e.index?t:e:t:e;for(let t=P;t<=Y;t++){const e=t-1,o=t;for(let t=z;t<=N;t++){const n=j(e>=K?V(e,t).style.borderBottom:null,o<=F?V(o,t).style.borderTop:null);_(M[t]-C,B[o]-C,M[t+1]-C,B[o]-C,n)}}for(let t=H;t<=W;t++){const e=t-1,o=t;for(let t=K;t<=F;t++){const n=j(e>=z?V(t,e).style.borderRight:null,o<=N?V(t,o).style.borderLeft:null);_(M[o]-C,B[t]-C,M[o]-C,B[t+1]-C,n)}}}t.d(e,{default:()=>Ye});const s={value:({newValue:t})=>t||"",text:({newValue:t})=>t||"Search...",edit:{validate:()=>!0,parse:({string:t})=>t,autoCommit:!0}};function u(t,e,o){return[{column:{type:"DATA"},row:{type:"HEADER"},value:({column:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"DATA"},value:({row:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"SPECIAL"},value:""},{column:{type:"SPECIAL"},row:{type:"HEADER"},value:""},{column:{type:"DATA"},row:{type:"FILTER"},...s},{column:{type:"FILTER"},row:{type:"DATA"},...s},{column:{type:"DATA"},row:{type:"DATA"},value:e},...t,...o.map((({columnId:t,rowId:e,direction:n},r)=>({column:{id:t},row:{id:e},text:({value:t,text:e})=>`${o.length>1?r+1:""}${"ASC"===n?"⇣":"⇡"} ${e||t}`})))]}const c=["column","row","condition"];function a(t){return Object.keys(t).length>Object.keys(t).filter((t=>c.includes(t))).length}function d(t,e){const o=[...c,...e];return t.map((t=>function(t,e){const o={};for(const n of e)n in t&&(o[n]=t[n]);return o}(t,o))).filter(a)}function h(t){return d(t,["value","text","edit"])}function f(t,e){return e?t+"99":t+"33"}function p(t,e,n,r,i,l,s,u,c,a,h,p,m){t=d(t,["value","style","text","font","padding","edit","draw"]);const g=n?o(n.columnId):null,y=n?o(n.rowId):null,w=null!==c,b=null!==u||w,C=a+2,x=a+4,v=(t,e,o,n)=>{if(o<0||o>=t.length)return!1;if(n<0||n>=e.length)return!1;const i=t[o],l=e[n];if("DYNAMIC-BLOCK"===i.type)return!1;if("DYNAMIC-BLOCK"===l.type)return!1;const s=i.key,u=l.key;return r.isKeySelected(s,u)},A=(t,e)=>t?[e]:[];return[{column:{type:"DATA"},row:{type:"FILTER"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"FILTER"},row:{type:"DATA"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"ANY"},row:{type:"HEADER"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"ANY"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"HEADER"},style:{background:"#E0E0E0"}},...t,...A(e&&!w,{column:{type:"ANY"},row:{id:e?.rowId},style:{highlight:"#81948133"}}),...A(e&&!b,{column:{id:e?.columnId},row:{id:e?.rowId},style:{highlight:"#81948188"}}),{column:{type:"ANY"},row:{type:"ANY"},condition:({rows:t,columns:e,row:o,column:n})=>v(t,e,o.index,n.index),style:({rows:t,columns:e,row:o,column:n,edit:r})=>({...v(t,e,o.index-1,n.index)?{}:{borderTop:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index+1,n.index)?{}:{borderBottom:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index-1)?{}:{borderLeft:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index+1)?{}:{borderRight:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},highlight:f(r?"#798d9c":"#819481",g!==n.key||y!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>i.isKeySelected(t.key,e.key),style:({row:t,column:e})=>({highlight:f("#93a8b8",g!==e.key||y!==t.key)})},...A(!!n,{column:{id:n?.columnId},row:{id:n?.rowId},style:{highlight:"#ffffffaa"}}),...s.map((({columnId:t,rowId:e,direction:o},n)=>({column:{id:t},row:{id:e},style:{highlight:"#0377fc44"}}))),{column:{type:"ANY"},row:{type:"ANY"},condition:({edit:t})=>!!t,style:{corner:"#77777720"}},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>l.hasValueByKey(t.key,e.key),style:{corner:"darkgreen"}},...A(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:x,color:"cornflowerblue"}}}),...A(c,{column:{type:"HEADER"},row:{id:c},style:{borderBottom:{width:x,color:"cornflowerblue"}}}),...A(h&&p,{column:{id:p},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...A(h&&m,{column:{type:"ANY"},row:{id:m},style:{highlight:"#3a74e055"}})]}function m(t,e){const o=e.filter((t=>"BEGIN"===t.pinned)).length,n=e.filter((t=>"END"===t.pinned)).length,r=e.length-o-n,i=t.filter((t=>"BEGIN"===t.pinned)).length,l=t.filter((t=>"END"===t.pinned)).length,s=t.length-i-l,u=e.slice(0,o),c=e.slice(e.length-n,e.length),a=e.slice(o,e.length-n),d=t.slice(0,i),h=t.slice(t.length-l,t.length),f=t.slice(i,t.length-l),p=o>0,m=i>0,g=!0,y=!0,w=r>0||!p,b=!0,C=!p,x=!(n>0),v=!0,A=!0,R=s>0||!m,I=!0,k=!m,E=!(l>0),S=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).topWithBorder:t.at(0).top;return(o?t.at(-1).bottomWithBorder:t.at(-1).bottom)-n},D=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).leftWithBorder:t.at(0).left;return(o?t.at(-1).rightWithBorder:t.at(-1).right)-n};return{top:{rows:u,showTopBorder:g,showBottomBorder:y,height:S(u,g,y)},bottom:{rows:c,showTopBorder:w,showBottomBorder:b,height:S(c,w,b)},middle:{rows:a,showTopBorder:C,showBottomBorder:x,height:S(a,C,x)},left:{columns:d,showLeftBorder:v,showRightBorder:A,width:D(d,v,A)},right:{columns:h,showLeftBorder:R,showRightBorder:I,width:D(h,R,I)},center:{columns:f,showLeftBorder:k,showRightBorder:E,width:D(f,k,E)}}}function g(t,e){return[...t,...e.map((t=>({columnId:t.columnId,rowId:t.rowId,value:t.expression})))]}class y{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Map),this.lookup.get(e).set(n,t.value)}))}hasValueByKey(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}getValueByKey(t,e){if(this.hasValueByKey(t,e))return this.lookup.get(t).get(e)}hasValueById(t,e){return this.hasValueByKey(o(t),o(e))}getValueById(t,e){return this.getValueByKey(o(t),o(e))}}function w(t){return new y(t)}class b{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Set),this.lookup.get(e).add(n)}))}isKeySelected(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}isIdSelected(t,e){return this.isKeySelected(o(t),o(e))}}function C(t){return new b(t)}function x(t,e){return"function"==typeof t?t(e):t}function v(t,e){return"function"==typeof t?t(e):t}function A(t,e){const n=t.type||"DATA",r="selector"in t?t.selector:"id"in t?t.id:void 0,i="id"in t?t.id:"selector"in t?t.selector:n;return{...t,id:i,selector:r,type:n,key:o(i),header:"header"in t?t.header:i,resizable:!("resizable"in t)||t.resizable,labels:t.labels||[],index:e}}function R(t,e){const o="selector"in t?t.selector:({index:t})=>t,n="id"in t?t.id:({selector:t})=>t,r="header"in t?t.header:()=>`#${e}`;return{...t,id:n,selector:o,type:"DYNAMIC-BLOCK",header:r,labels:t.labels||[],index:e,resizable:!1}}function I(t,e){return"number"==typeof t?i(t,e):t}function k(t,e,n,r,l){const s=new Map(e.map((({columnId:t,width:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),l=t.width*t.count+n*(t.count-1);return{...o,count:t.count,width:i(l,r),columnWidth:i(t.width,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"width"in t?t.width:"fit";return{...o,width:I(n,r)}}}))}function E(t,e,n,r,l){const s=new Map(e.map((({rowId:t,height:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),s="height"in t?t.height:l,u=s*t.count+n*(t.count-1);return{...o,count:t.count,height:i(u,r),rowHeight:i(s,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"height"in t?t.height:"fit";return{...o,height:I(n,r)}}}))}function S(t,e,o,n,r){if(t<o){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"BEGIN"}if(t>=e-n){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"END"}}function D(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.width,s={...r,index:i,width:l,leftWithBorder:n-o,left:n,right:n+l,rightWithBorder:n+l+o,pinned:S(i,t.length,e.left,e.right,r.type)};return n+=s.width+o,s}))}function T(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.height,s={...r,index:i,height:l,topWithBorder:n-o,top:n,bottom:n+l,bottomWithBorder:n+l+o,pinned:S(i,t.length,e.top,e.bottom,r.type)};return n+=s.height+o,s}))}const M="12px Calibri",B={top:2,right:5,bottom:2,left:5};function L(t){return"function"==typeof t?t:()=>t}const O={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class z{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class N{lookup=new z;hasRules=!1;addRule(t,e,n){if(this.hasRules=!0,Array.isArray(t)){for(const o of t)this.addRule(o,e,n);return}if(Array.isArray(e)){for(const o of e)this.addRule(t,o,n);return}const r=t?"id"in t?{key:o(t.id)}:t:{type:"DATA"},i=e?"id"in e?{key:o(e.id)}:e:{type:"DATA"};function l(t,e){t.has(e)||t.set(e,[]),t.get(e).push(n)}function s(t,e){if(t.has(e)||t.set(e,new z),"key"in i)l(t.get(e).byKey,i.key);else if("index"in i)l(t.get(e).byIndex,i.index);else if("label"in i)l(t.get(e).byLabel,i.label);else for(const o of O[i.type||"NONE"])l(t.get(e).byType,o)}if("key"in r)s(this.lookup.byKey,r.key);else if("index"in r)s(this.lookup.byIndex,r.index);else if("label"in r)s(this.lookup.byLabel,r.label);else for(const t of O[r.type||"NONE"])s(this.lookup.byType,t)}getRules(t,e){const o=[];if(!this.hasRules)return o;function n(t){for(const e of t)o.push(e)}function r(t){t.byKey.has(e.key)&&n(t.byKey.get(e.key)),t.byIndex.has(e.index)&&n(t.byIndex.get(e.index)),t.byType.has(e.type)&&n(t.byType.get(e.type));for(const o of e.labels)t.byLabel.has(o)&&n(t.byLabel.get(o))}this.lookup.byKey.has(t.key)&&r(this.lookup.byKey.get(t.key)),this.lookup.byIndex.has(t.index)&&r(this.lookup.byIndex.get(t.index)),this.lookup.byType.has(t.type)&&r(this.lookup.byType.get(t.type));for(const e of t.labels)this.lookup.byLabel.has(e)&&r(this.lookup.byLabel.get(e));return o}}const K=["borderTop","borderRight","borderBottom","borderLeft"],F={validate:()=>!0,parse:({string:t})=>t};function H(t,e){const o={...t};if("border"in o){for(const t of K)o[t]=o.border;delete o.border}for(const t of K)t in o&&(o[t]={...o[t],index:e});return o}function W(t,e){if(!1!==t.edit)return!0===t.edit?"edit"in e?e.edit:F:"edit"in e?{...e.edit,...t.edit}:{...F,...t.edit}}class P{constructor(t){this.rulesLookup=new N;for(const[e,o]of t.entries()){const t={index:e};"condition"in o&&(t.condition=o.condition),"style"in o&&(t.style=L(o.style)),"value"in o&&(t.value=L(o.value)),"text"in o&&(t.text=L(o.text)),"font"in o&&(t.font=L(o.font)),"padding"in o&&(t.padding=L(o.padding)),"edit"in o&&(t.edit=o.edit),"tooltip"in o&&(t.tooltip=L(o.tooltip)),"draw"in o&&(t.draw=o.draw),"sortOrder"in o&&(t.sortOrder=L(o.sortOrder)),this.rulesLookup.addRule(o.column,o.row,t)}}resolve(t,e,o,n,r,i){const l=this.rulesLookup.getRules(r,n).sort(((t,e)=>t.index-e.index)).filter(((t,e,o)=>t.index!==o[e-1]?.index));let s,u,c={data:t,rows:e,columns:o,row:n,column:r},a={},d=B,h=M;i.hasValueByKey(n.key,r.key)&&(c={...c,newValue:i.getValueByKey(n.key,r.key)});for(const t of l)if((!("condition"in t)||t.condition(c))&&("value"in t&&(c={...c,value:t.value(c)}),"style"in t&&(a={...a,...H(t.style(c),t.index)}),"text"in t&&(c={...c,text:t.text(c)}),"font"in t&&(h=t.font(c)),"padding"in t&&(d={...d,...t.padding(c)}),"edit"in t&&(c={...c,edit:W(t,c)}),"tooltip"in t&&(u=t.tooltip(c)),"sortOrder"in t&&(c={...c,sortOrder:t.sortOrder(c)}),"draw"in t)){const e=c;s=o=>t.draw({...e,ctx:o})}const f=function(t){return"text"in t?`${t.text}`:"newValue"in t?`${t.newValue}`:void 0!==t.value?`${t.value}`:""}(c),p={render:!0,style:a,text:f,padding:d,font:h};return"value"in c&&(p.value=c.value),"edit"in c&&void 0!==c.edit&&(p.edit=c.edit),void 0!==u&&(p.tooltip=u),"sortOrder"in c&&(p.sortOrder=c.sortOrder),void 0!==s&&(p.draw=s),p}}function Y(t){return new P(t)}class ${constructor(t,e,o,n,r){this.formattingRules=t,this.data=e,this.rows=o,this.columns=n,this.edition=r}resolve(t,e){return this.formattingRules.resolve(this.data,this.rows,this.columns,t,e,this.edition)}}function V(t,e,o,n,r){return new $(t,e,o,n,r)}function q(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.expression)}return r}function G(t,e,o,n,r,i,l){if(0===t.length)return r;const s=q(t,"columnId","rowId"),u=i.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?r:r.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,t,c,l),a=s.get(c.key);if(!e.resolve(n,r,i,t,c,u.value,u.text,a))return!1}return!0}))}function _(t,e,o,n,r,i,l){if(0===t.length)return i;const s=q(t,"rowId","columnId"),u=r.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?i:i.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,c,t,l),a=s.get(c.key);if(!e.resolve(n,r,i,c,t,u.value,u.text,a))return!1}return!0}))}function j(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.height+o,1];const n=Math.min(e,t.count);return[(t.rowHeight+o)*n,n]}function U(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.width+o,1];const n=Math.min(e,t.count);return[(t.columnWidth+o)*n,n]}function X(t,e,o,n){let r=0,i=0,l=0,s=0;if(o.top>0){r=n;for(let t=0,i=0;i<o.top;t++){const l=e[t],[s,u]=j(l,o.top-i,n);r+=s,i+=u}}if(o.left>0){l=n;for(let e=0,r=0;r<o.left;e++){const i=t[e],[s,u]=U(i,o.left-r,n);l+=s,r+=u}}if(o.bottom>0){i=n;for(let t=e.length-1,r=0;r<o.bottom;t--){const l=e[t],[s,u]=j(l,o.bottom-r,n);i+=s,r+=u}}if(o.right>0){s=n;for(let e=t.length-1,r=0;r<o.right;e--){const i=t[e],[l,u]=U(i,o.right-r,n);s+=l,r+=u}}return{top:r,bottom:i,left:l,right:s}}function J(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.height,o+=e;return o}function Q(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.width,o+=e;return o}function Z(t,e,o){return{width:Q(t,o),height:J(e,o)}}class tt{constructor(){this.fontMetrics=new Map,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d")}measureWidth(t,e){if(!t)return 0;const o=this.context;return o.font=e||M,o.measureText(t).width}measureHeight(t,e){let o=1;for(const e of t)"\n"===e&&o++;return o*this.getFontMetrics(e).height}getFontMetrics(t){const e=t;if(this.fontMetrics.has(e))return this.fontMetrics.get(e);const o=this.context;o.font=t||M;const n=o.measureText("X"),r=(n.actualBoundingBoxDescent-n.actualBoundingBoxAscent)/2,i={topOffset:r+n.fontBoundingBoxAscent,middle:-r,bottomOffset:n.fontBoundingBoxDescent-r,height:n.fontBoundingBoxAscent+n.fontBoundingBoxDescent};return this.fontMetrics.set(e,i),i}}function et(){return new tt}function ot(t,e){return e.top>=t.top&&e.left>=t.left&&e.top+e.height<=t.top+t.height&&e.left+e.width<=t.left+t.width}function nt(t,e){const o={top:Math.max(t.top,e.top),left:Math.max(t.left,e.left),width:Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left),height:Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top)};return o.width>=0&&o.height>=0?o:{top:t.top,left:t.left,width:0,height:0}}function rt(t,e){return{top:t.top-e,left:t.left-e,width:t.width+2*e,height:t.height+2*e}}function it(t){return t.width*t.height}function lt(t,e){return{top:t.top,left:t.left,width:Math.max(0,t.width-e.left-e.right),height:Math.max(0,t.height-e.top-e.bottom)}}const st=200,ut=400,ct={left:0,top:0,width:0,height:0};function at(t,e,o,n,r){const i=t||ct,l=lt({left:0,top:0,...o},n),s=lt({...e,...r},n),u=nt(l,rt(s,st)),c=nt(l,rt(s,ut));return ot(l,i)&&ot(i,u)?it(i)>2*it(c)?c:i:c}function dt(t,e,o,n,r){if(!t)return null;if(t.x<0||t.y<0||t.x>r.width||t.y>r.height)return null;const i=function(t,e){if(0===t.length)return-1;if(e<t[0].topWithBorder)return-1;if(e>t[t.length-1].bottomWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].topWithBorder)n=r-1;else{if(!(e>t[r].bottomWithBorder))return r;o=r+1}}return-1}(e,t.y),l=function(t,e){if(0===t.length)return-1;if(e<t[0].leftWithBorder)return-1;if(e>t[t.length-1].rightWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].leftWithBorder)n=r-1;else{if(!(e>t[r].rightWithBorder))return r;o=r+1}}return-1}(o,t.x);return-1===i||-1===l?null:{rowId:e[i].id,columnId:o[l].id}}function ht(t){return t.reduce(((t,e)=>t.set(e.key,e)),new Map)}function ft(t,e,n,r,i,l,s,u){if(!t)return[];if(!e)return[];if(!r)return[];if(!n)return[];const c=o(n.columnId),a=o(n.rowId),d=o(r.columnId),h=o(r.rowId);if(!s.has(c))return[];if(!u.has(a))return[];if(!s.has(d))return[];if(!u.has(h))return[];const f=Math.min(s.get(c).index,s.get(d).index),p=Math.max(s.get(c).index,s.get(d).index),m=Math.min(u.get(a).index,u.get(h).index),g=Math.max(u.get(a).index,u.get(h).index);return i.slice(f,p+1).flatMap((t=>l.slice(m,g+1).map((e=>({rowId:e.id,columnId:t.id})))))}function pt(t,e){const o=function(t){return"BEGIN"===t.pinned?"top":"END"===t.pinned?"bottom":"middle"}(e),n=function(t){return"BEGIN"===t.pinned?"left":"END"===t.pinned?"right":"center"}(t);return`${o}-${n}`}function mt(t,e,n,r,i){return 0===t.length?null:function(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!e.has(i))return null;if(!n.has(l))return null;const s=e.get(i),u=n.get(l),c={width:s.width,height:u.height,section:pt(s,u)};switch(u.pinned){case"BEGIN":c.top=u.top;break;case"END":c.bottom=r.top.height+r.middle.height+r.bottom.height-u.top-u.height;break;default:c.marginTop=u.top-r.top.height}switch(s.pinned){case"BEGIN":c.left=s.left;break;case"END":c.right=r.left.width+r.center.width+r.right.width-s.left-s.width;break;default:c.marginLeft=s.left-r.left.width}return c}(e,n,r,i)}function gt(t,e){return e.every((e=>e.edit.validate({string:t})))}function yt(t){return Array.isArray(t)?t.map(((t,e)=>e)):Object.keys(t)}function wt(t){return yt(t)}function bt(t){const e=new Set;if(Array.isArray(t))for(const o of t)for(const t of yt(o))e.add(t);else for(const o in t)for(const n of yt(t[o]))e.add(n);return Array.from(e)}function Ct(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):bt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}function xt(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):wt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}const vt=({text:t,expression:e})=>t.includes(e);class At{constructor(t){this.rulesLookup=new N;for(const e of t){const t={by:o("by"in e?e.by:"FILTER"),condition:e.condition||vt};this.rulesLookup.addRule(e.column,e.row,t)}}resolve(t,e,o,n,r,i,l,s){const u=this.rulesLookup.getRules(r,n);if(0===u.length)return"DATA"!==n.type||"DATA"!==r.type||!s.has('"FILTER"')||vt({text:l,expression:s.get('"FILTER"')});let c={data:t,rows:e,columns:o,row:n,column:r,value:i,text:l};for(const t of u){if(!s.has(t.by))continue;const e={...c,expression:s.get(t.by)};if(!t.condition(e))return!1}return!0}}function Rt(t){return new At(t)}function It(t){return d(t,["value","text"])}function kt(t){return d(t,["value","text","font","padding"])}function Et(t,e,o,n,r,l,s){if(t.every((t=>"number"==typeof t.width)))return t;const u=t=>{if("DYNAMIC-BLOCK"===t.type)return t.width;const i=t.width;if("number"==typeof i)return i;if(r.has(t.key)){const e=r.get(t.key);if("fit-once"===i&&!e.dataOnly)return e.width;if("fit-data-once"===i&&e.dataOnly)return e.width}let l=0;for(const r of e){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const e=n.resolve(r,t),s=e.text,u=e.font,c=e.padding.left+e.padding.right,a=o.measureWidth(s,u)+c;l=Math.max(l,a)}return r.set(t.key,{width:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return t.map((t=>({...t,width:i(u(t),s)})))}function St(t,e,o,n,r,l,s){if(e.every((t=>"number"==typeof t.height)))return e;const u=e=>{if("DYNAMIC-BLOCK"===e.type)return e.height;const i=e.height;if("number"==typeof i)return i;if(r.has(e.key)){const t=r.get(e.key);if("fit-once"===i&&!t.dataOnly)return t.height;if("fit-data-once"===i&&t.dataOnly)return t.height}let l=0;for(const r of t){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const t=n.resolve(e,r),s=t.text,u=t.font,c=t.padding.top+t.padding.bottom,a=o.measureHeight(s,u)+c;l=Math.max(l,a)}return r.set(e.key,{height:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return e.map((t=>({...t,height:i(u(t),s)})))}function Dt(t){const e=new Set;for(const o of t)"DYNAMIC-BLOCK"!=o.type&&e.add(o.key);return e}function Tt(t){return d(t,["value","text"])}function Mt(t){return d(t,["value","sortOrder"])}function Bt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value<e.value?-1:t.value>e.value?1:0}function Lt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value>e.value?-1:t.value<e.value?1:0}class Ot{constructor(t){this.rulesLookup=new N;for(const e of t){const t=e.comparatorAsc||e.comparator,n=e.comparatorDesc||(e.comparator?(t,o)=>{return-("number"==typeof(n=e.comparator(t,o))?n:n?-1:1);var n}:null),r=t?(e,o)=>t(e,o):(t,e)=>Bt(t,e),i=n?(t,e)=>n(t,e):(t,e)=>Lt(t,e),l={by:o("by"in e?e.by:"HEADER"),comparatorAsc:r,comparatorDesc:i};this.rulesLookup.addRule(e.column,e.row,l)}}resolve(t,e,o){const n=this.rulesLookup.getRules(t,e);if(0===n.length)return"DATA"!==e.type||"DATA"!==t.type?null:o.has('"HEADER"')?"ASC"===o.get('"HEADER"')?Bt:Lt:null;if(n.length>1)throw new Error("Multiple sorting rules for the same cell");const r=n[0];return o.has(r.by)?"ASC"===o.get(r.by)?r.comparatorAsc:r.comparatorDesc:null}}function zt(t){return"manual"===t?null:new Ot(t)}function Nt(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.direction)}return r}function Kt(t,e){t.sort(((t,e)=>{const o=t.comparator(t.cell,e.cell);return"number"==typeof o?o:o?-1:1})),e.push(...t.map((t=>t.entity))),t.length=0}function Ft(t,e,n,r,i,l,s){if(0===t.length)return i;if(null===e)return i;const u=Nt(t,"columnId","rowId"),c=new Map(l.filter((t=>"DYNAMIC-BLOCK"!==t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.columnId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return i;for(const t of a){const o=[],c=[];for(const a of i){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(t,a,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,a,t,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),i=o}return i}function Ht(t,e,n,r,i,l,s){if(0===t.length)return l;if(null===e)return l;const u=Nt(t,"rowId","columnId"),c=new Map(i.filter((t=>"DYNAMIC-BLOCK"!=t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.rowId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return l;for(const t of a){const o=[],c=[];for(const a of l){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(a,t,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,t,a,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),l=o}return l}const Wt=5;function Pt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId));if("HEADER"!==n.get(o(r.rowId)).type)return null;if(!s.resizable)return null;if(!i)return null;const u=i.x;return u>=s.right-Wt&&u<=s.right+Wt?s.id:0===s.index||u<s.left-Wt||u>s.left+Wt?null:t[s.index-1].id}function Yt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId)),u=n.get(o(r.rowId));if("HEADER"!==s.type)return null;if(!u.resizable)return null;if(!i)return null;const c=i.y;return c>=u.bottom-Wt&&c<=u.bottom+Wt?u.id:0===u.index||c<u.top-Wt||c>u.top+Wt?null:t[u.index-1].id}function $t(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"HEADER",rowId:"rowId"in t?t.rowId:"HEADER",direction:t.direction})))}function Vt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"FILTER",rowId:"rowId"in t?t.rowId:"FILTER",expression:t.expression})))}function qt(t){return t.filter((t=>"DATA"===t.type)).map((t=>t.id))}function Gt(t){return qt(t)}function _t(t){return qt(t)}function jt(t){return d(t,["value","text","tooltip"])}function Ut(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!n.has(i))return null;if(!r.has(l))return null;const s=r.get(l),u=n.get(i);return e.resolve(s,u).tooltip}function Xt(t,e){return t?{left:e.x+8,top:e.y+20}:null}function Jt(t){return t.map((t=>o(t)))}function Qt(t,e){if(!e.length)return t;const o=new Map;for(const[t,n]of e.entries())o.set(n,t);const n=[],r=e.length;let i=0;for(const[e,l]of t.entries())if("DYNAMIC-BLOCK"===l.type)i++,n.push({entry:l,score:[i,0,0]}),i++;else{const t=l.key,s=o.has(t)?o.get(t):r;n.push({entry:l,score:[i,s,e]})}return n.sort(((t,e)=>function(t,e){if(t.length!=e.length)throw new Error("lengths should be the same");for(let o=0;o<t.length;o++){const n=t[o]-e[o];if(0!=n)return n}return 0}(t.score,e.score))).map((t=>t.entry))}function Zt(t,e){return Qt(t,e)}function te(t,e){return Qt(t,e)}function ee(t){return t.some((t=>"DYNAMIC-BLOCK"===t.type))}function oe(t){const e=[];for(const[o,n]of t){if(o>n)continue;if(0===e.length){e.push([o,n]);continue}const[t,r]=e[e.length-1];r<o-1?e.push([o,n]):(e.pop(),e.push([t,n]))}return e}function ne(t){return t.reduce(((t,e)=>"DYNAMIC-BLOCK"===e.type?t+e.count:t+1),0)}function re(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.left+i.left,h=d+r.width,f=[],p=(t,e)=>{f.push(e),s+=e.width+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),width:e.columnWidth})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",width:e*t.columnWidth+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,columnWidth:o}=t,r=o+l,i=n.left-u,c=a-n.right-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function ie(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.top+i.top,h=d+r.height,f=[],p=(t,e)=>{f.push(e),s+=e.height+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),height:e.rowHeight})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",height:e*t.rowHeight+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,rowHeight:o}=t,r=o+l,i=n.top-u,c=a-n.bottom-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function le(t,e,o,n,r,i){const l=t.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),s=e.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),u=Math.min(r,l),c=Math.min(o,s);return{left:u,top:c,right:Math.min(i,l-u),bottom:Math.min(n,s-c)}}function se(t){return{width:t.clientWidth,height:t.clientHeight}}function ue(t){return{left:t.scrollLeft,top:t.scrollTop}}function ce(t,e,o,n,r){if(!t)return null;const i=t.x,l=t.y;return{x:i<=n.left?i:i>=e.width?i+o.left:i>=e.width-n.right?r.width-e.width+i:i+o.left,y:l<=n.top?l:l>=e.height?l+o.top:l>=e.height-n.bottom?r.height-e.height+l:l+o.top}}function ae(t,e,n,r){if(!e)return t;if(!n)return t;if(!r)return t;const i=o(n.columnId),l=r.find((t=>"key"in t&&t.key===i));return"DATA"!==l?.type?t:r}function de(t,e,n,r){if(!e)return t;if(!n)return t;if(!r)return t;const i=o(n.rowId),l=r.find((t=>"key"in t&&t.key===i));return"DATA"!==l?.type?t:r}function he(t,e,o,n,r,i){return!!t&&(void 0===o||o<n||o>i-r||!e)}function fe(t,e,o,n){const r=t.position||"BEGIN",i=t.index%1*o;if("BEGIN"===r)return e+i;if("MIDDLE"===r)return e-(n-o)/2+i;if("END"===r)return e-(n-o)+i;throw new Error(`Invalid scroll position: ${r}`)}function pe(t,e,o,n,r,i,l,s,u){if(!he(t,e,r?.y,i.top,i.bottom,l.height))return null;let c=Math.floor(t.index)+n.top,a=-i.top,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.rowHeight+u)*e,c-=e,e<t.count){d=t.rowHeight;break}}else{if(0===c){d=t.height;break}a+=t.height+u,c-=1}return fe(t,a,d,s.height-i.top-i.bottom)}function me(t,e,o,n,r,i,l,s,u){if(!he(t,e,r?.x,i.left,i.right,l.width))return null;let c=Math.floor(t.index)+n.left,a=-i.left,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.columnWidth+u)*e,c-=e,e<t.count){d=t.columnWidth;break}}else{if(0===c){d=t.width;break}a+=t.width+u,c-=1}return fe(t,a,d,s.width-i.left-i.right)}function ge(t){return t?"number"==typeof t||"string"==typeof t?[{maxDistance:1/0,scrollSpeed:t}]:0===t.length?[{maxDistance:1/0,scrollSpeed:"smooth"}]:t.sort(((t,e)=>t.maxDistance-e.maxDistance)):[{maxDistance:1/0,scrollSpeed:"smooth"}]}function ye(t,e,o,n,r){return{verticalTarget:t,horizontalTarget:e,verticalSpeed:o,horizontalSpeed:n,clientSizeVersion:r}}function we(t){return{scrollbarWidth:t.scrollbarWidth||"auto"}}function be(t,e,o,n,r,i){return{sections:t,devicePixelRatio:e,scrollRect:o,renderFormatResolver:n,borderWidth:r,textResolver:i}}function Ce(t,e){return{inputPlacement:t,isTextValid:e}}function xe(t,e,o){return{resizableColumn:t,resizableRow:e,isReordering:o}}function ve(t,e){return{tooltip:t,tooltipPlacement:e}}function Ae(t){return t.measureHeight("X",M)+B.top+B.bottom}function Re(t,e){return!t&&!e||!(!t||!e)&&t.x===e.x&&t.y===e.y}function Ie(t,e){return!t&&!e||!(!t||!e)&&t.width===e.width&&t.height===e.height}function ke(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top}function Ee(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height}function Se(t,e){return!t&&!e||!(!t||!e)&&o(t.rowId)===o(e.rowId)&&o(t.columnId)===o(e.columnId)}function De(t,e){return!t&&!e||!(!t||!e)&&t.scrollbarWidth===e.scrollbarWidth}function Te(t){const e={...t.localOptions,...t.externalOptions},o=t.memory,n=t.state,i=t.element,l=[];function s(t,e,n,r=((t,e)=>t===e)){const i=o[t]&&o[t].dependencies;if(!i||n.some(((t,e)=>t!==i[e]))){const i=o[t]&&o[t].value,s=o[t]&&o[t].version||0,u=e(...n);r(i,u)?o[t]={value:i,dependencies:n,version:s}:(o[t]={value:u,dependencies:n,version:s+1},l.push(t))}return o[t].value}function c(t,e,n){(o[t]&&o[t].value)!==e&&(o[t]={value:e},n(e))}const a=s("devicePixelRatio",(t=>t),[window.devicePixelRatio]),d=s("borderWidth",(t=>t),[e.borderWidth/a]),f=e.data,y=t.input.value,b=s("sortBy",$t,[e.sortBy]),A=s("filters",Vt,[e.filters]),R=s("columnWidths",(t=>t),[e.columnWidths]),I=s("rowHeights",(t=>t),[e.rowHeights]),S=s("textResolver",et,[]),M=s("dataFormatting",u,[e.formatting,e.dataSelector,b]),B=s("editedCellsAndFilters",g,[e.editedCells,A]),L=s("edition",w,[B]),O=s("invokedColumns",x,[e.columns,f]),z=s("invokedRows",v,[e.rows,f]),N=s("mousePosition",(t=>t),[t.mousePosition],Re),K=s("unfoldedColumns",Ct,[O,f]),F=s("unfoldedRows",xt,[z,f]),H=s("dynamicRowHeight",Ae,[S]),W=s("unfilteredColumns",k,[K,R,d,a,150]),P=s("unfilteredRows",E,[F,I,d,a,H]),$=s("unfilteredColumnKeys",Dt,[W]),q=s("unfilteredRowKeys",Dt,[P]),j=s("columnsOrder",Jt,[e.columnsOrder]),U=s("rowsOrder",Jt,[e.rowsOrder]),J=s("orderedColumns",Zt,[W,j]),Q=s("orderedRows",te,[P,U]),tt=s("filterFormatting",It,[M]),ot=s("filterFormattingRules",Y,[tt]),nt=s("filteringRules",Rt,[e.filtering]),rt=s("filteredColumns",_,[A,nt,ot,f,Q,J,L]),it=s("filteredRows",G,[A,nt,ot,f,Q,J,L]),lt=s("sortingFormatting",Tt,[M]),st=s("sortingFormattingRules",Y,[lt]),ut=s("sortingRules",zt,[e.sorting]),ct=s("sortedColumns",Ht,[b,ut,st,f,it,rt,L]),pt=s("sortedRows",Ft,[b,ut,st,f,it,rt,L]),yt=e.freezeOnHover&&!l.includes("sortBy")&&!l.includes("filters")&&!l.includes("columnWidths")&&!l.includes("rowHeights"),wt=s("shapedColumns",ae,[ct,yt,n?.hoveredCell,n?.shapedColumns]),bt=s("shapedRows",de,[pt,yt,n?.hoveredCell,n?.shapedRows]),vt=s("pinning",le,[wt,bt,e.pinnedTop,e.pinnedBottom,e.pinnedLeft,e.pinnedRight]),At=s("measureFormatting",kt,[M]),Bt=s("measureFormattingRules",Y,[At]),Lt=s("measureFormatResolver",V,[Bt,f,bt,wt,L]),Ot=t.columnWidthCache,Nt=t.rowHeightCache,Kt=s("measuredColumns",Et,[wt,bt,S,Lt,Ot,$,a]),Wt=s("measuredRows",St,[wt,bt,S,Lt,Nt,q,a]),qt=s("fixedSize",X,[Kt,Wt,vt,d]),Qt=s("totalSize",Z,[Kt,Wt,d]),ee=s("clientSize",(t=>t),[se(i)],Ie),oe=s("boundingClientSize",(t=>t),[se(i)],Ie),ne=s("scrollOffset",(t=>t),[ue(i)],ke),he=s("internalMousePosition",ce,[N,ee,ne,qt,Qt],Re),fe=s("scrollRect",at,[n?.renderState?.scrollRect,ne,Qt,qt,oe],Ee),Te=s("horizontalScrollTarget",me,[e.horizontalScrollTarget,e.disableScrollOnHover,Kt,vt,he,qt,Qt,ee,d]),Me=s("verticalScrollTarget",pe,[e.verticalScrollTarget,e.disableScrollOnHover,Wt,vt,he,qt,Qt,ee,d]),Be=s("horizontalScrollSpeed",ge,[e.horizontalScrollSpeed]),Le=s("verticalScrollSpeed",ge,[e.verticalScrollSpeed]),Oe=s("staticColumns",re,[f,Kt,vt,fe,qt,d]),ze=s("staticRows",ie,[f,Wt,vt,fe,qt,d]),Ne=s("columns",D,[Oe,vt,d]),Ke=s("rows",T,[ze,vt,d]),Fe=s("columnLookup",ht,[Ne]),He=s("rowLookup",ht,[Ke]),We=e.focusedCell,Pe=s("sections",m,[Ne,Ke]),Ye=e.selectedCells,$e=s("hoveredCell",dt,[he,Ke,Ne,qt,Qt],Se),Ve=t.isReordering,qe=t.resizingColumn||s("resizableColumn",Pt,[Ne,Fe,He,$e,he,Ve]),Ge=t.resizingRow||s("resizableRow",Yt,[Ke,Fe,He,$e,he,Ve]),_e=s("highlightedCells",ft,[t.isMouseDown,!qe&&!Ge&&!t.didReorder,We,$e,Ne,Ke,Fe,He]),je=s("selection",C,[Ye]),Ue=s("highlight",C,[_e]),Xe=s("renderFormatting",p,[M,$e,We,je,Ue,L,b,qe,Ge,e.borderWidth,Ve,t.reorderedColumn,t.reorderedRow]),Je=s("renderFormattingRules",Y,[Xe]),Qe=s("renderFormatResolver",V,[Je,f,Ke,Ne,L]),Ze=s("sortOrderFormatting",Mt,[M]),to=s("sortOrderFormattingRules",Y,[Ze]),eo=s("sortOrderFormatResolver",V,[to,f,Ke,Ne,L]),oo=s("inputFormatting",h,[M]),no=s("inputFormattingRules",Y,[oo]),ro=s("inputFormatResolver",V,[no,f,Ke,Ne,L]),io=s("editableCells",r,[Ye,ro,Fe,He]),lo=s("inputPlacement",mt,[io,We,Fe,He,Pe]),so=s("isTextValid",gt,[y,io]),uo=s("contextFormatting",jt,[M]),co=s("contextFormattingRules",Y,[uo]),ao=s("contextFormatResolver",V,[co,f,Ke,Ne,L]),ho=s("tooltip",Ut,[$e,ao,Fe,He]),fo=s("tooltipPlacement",Xt,[ho,N]),po=s("renderState",be,[Pe,a,fe,Qe,d,S]),mo=s("inputState",Ce,[lo,so]),go=s("cursorState",xe,[qe,Ge,t.isReordering]),yo=s("tooltipState",ve,[ho,fo]),wo=s("scrollState",ye,[Me,Te,Le,Be,o.clientSize.version]),bo=s("styleState",we,[e.style],De),Co=s("activeColumns",Gt,[Ne]),xo=s("activeRows",_t,[Ke]);c("activeColumnsCallback",Co,e.onActiveColumnsChange),c("activeRowsCallback",xo,e.onActiveRowsChange),c("hoveredCellCallback",$e,e.onHoveredCellChange),e.onStateChange(l),t.state={options:e,edition:L,columns:Ne,rows:Ke,hoveredCell:$e,focusedCell:We,inputFormatResolver:ro,fixedSize:qt,totalSize:Qt,clientSize:ee,scrollOffset:ne,highlightedCells:_e,columnLookup:Fe,rowLookup:He,text:y,scrollState:wo,styleState:bo,sortOrderFormatResolver:eo,renderState:po,inputState:mo,cursorState:go,tooltipState:yo,shapedColumns:wt,shapedRows:bt}}function Me(t,e){const o=new b(e);return[...e,...t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))]}function Be(t,e){const o=new b(e);return t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))}function Le(t){const e=t.currentTarget;if(!(e instanceof HTMLElement))throw new Error("Element is not an HTMLElement");const o=e.getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}}function Oe(t,e){return t.map((t=>({...t,columnId:"columnId"in t?t.columnId:e,rowId:"rowId"in t?t.rowId:e})))}function ze(t,e,n){const r=o(e),i=o(n);if(r===i)return null;const l=t.findIndex((t=>t.key===r)),s=t.findIndex((t=>t.key===i));return-1===l||-1===s||l===s?null:[l,s]}function Ne(t){const e=t.element;t.scrollAnimationId&&(cancelAnimationFrame(t.scrollAnimationId),t.scrollAnimationId=null,e.scrollTop=e.scrollTop,e.scrollLeft=e.scrollLeft)}function Ke(t,e,o,n){return t>0?Math.min(t,e*o+n):Math.max(t,-e*o+n)}function Fe(t,e,o,n,r,i,l,s,u,c,a){if(null===n)return null;const d=n-o;if(Math.abs(d)<1)return null;if(d<0&&0===o)return null;if(d>0&&o>=i-r-1)return null;const h=function(t,e){const o=Math.abs(e);for(const e of t)if(o<=e.maxDistance)return e.scrollSpeed;return"auto"}(u,d);return a||"auto"===h?{[t]:n,behavior:"auto"}:"number"==typeof h?{[t]:o+Ke(d,h,e,c),behavior:"auto"}:l!==n||s===o?{[t]:n}:null}function He(t,e){if(t.errorRendered)return;t.errorRendered=!0;const o=t.element;o.style.backgroundColor="#9f0000",o.style.color="white",o.style.padding="20px",o.style.display="flex",o.style.flexDirection="column",o.style.userSelect="text",o.innerHTML=`\n <div style="font-size: 16px;">\n An error occurred while rendering the grid, please contact the support.\n </div>\n <div style="font-size: 20px; font-weight: bold; padding: 20px 0;">\n ${e.message}\n </div>\n <div style="font-size: 16px; white-space: pre-wrap;">${e.stack}</div>\n `}function We(t){if(!t.errorRendered)try{Te(t),t.state.styleState!==t.lastStyleState&&(t.lastStyleState=t.state.styleState,function(t){const e=t.state.styleState,o=t.element,n=`\n max-width: 100vw;\n max-height: 100vh;\n overflow: auto;\n display: grid;\n position: relative;\n grid-template-columns: fit-content(0) fit-content(0) fit-content(0);\n grid-template-rows: fit-content(0) fit-content(0) fit-content(0);\n outline: none;\n user-select: none;\n touch-action: manipulation;\n scrollbar-width: ${e.scrollbarWidth};\n `;o.setAttribute("style",n)}(t)),t.state.renderState!==t.lastRenderState&&(t.lastRenderState=t.state.renderState,function(t){l(t,"top","left"),l(t,"top","center"),l(t,"top","right"),l(t,"middle","left"),l(t,"middle","center"),l(t,"middle","right"),l(t,"bottom","left"),l(t,"bottom","center"),l(t,"bottom","right")}(t)),t.state.inputState!==t.lastInputState&&(t.lastInputState=t.state.inputState,function(t){const e=t.element,o=t.input,n=t.state.inputState,r=n.inputPlacement;if(!r){if(o.parentElement){const t=document.activeElement===o;o.parentElement.removeChild(o),t&&e.focus({preventScroll:!0})}return}const i=t.canvases[r.section];if(o.style.left="left"in r?`${r.left}px`:"0",o.style.top="top"in r?`${r.top}px`:"0",o.style.right="right"in r?`${r.right}px`:"0",o.style.bottom="bottom"in r?`${r.bottom}px`:"0",o.style.marginLeft="marginLeft"in r?`${r.marginLeft}px`:"0",o.style.marginTop="marginTop"in r?`${r.marginTop}px`:"0",o.style.width=`${r.width}px`,o.style.height=`${r.height}px`,o.style.gridArea=i.style.gridArea,o.style.zIndex=i.style.zIndex,o.style.backgroundColor=n.isTextValid?"white":"#eb3434",!o.parentElement){const t=document.activeElement===e;e.appendChild(o),t&&o.focus({preventScroll:!0})}}(t)),t.state.cursorState!==t.lastCursorState&&(t.lastCursorState=t.state.cursorState,function(t){const e=t.element,o=t.state.cursorState;o.isReordering?e.style.cursor="move":o.resizableColumn&&o.resizableRow?e.style.cursor="nwse-resize":o.resizableColumn?e.style.cursor="col-resize":o.resizableRow?e.style.cursor="row-resize":e.style.cursor="default"}(t)),t.state.tooltipState!==t.lastTooltipState&&(t.lastTooltipState=t.state.tooltipState,function(t){const e=t.element,o=t.tooltip,n=t.state.tooltipState,r=n.tooltip,i=n.tooltipPlacement;i?(o.innerHTML!==r&&(o.innerHTML=r),o.style.left=`calc(anchor(left) + ${i.left}px)`,o.style.top=`calc(anchor(top) + ${i.top}px)`,o.parentElement||(e.appendChild(o),o.showPopover({source:e}))):o.parentElement&&o.parentElement.removeChild(o)}(t)),t.state.scrollState!==t.lastScrollState&&(t.lastScrollState=t.state.scrollState,function(t){const e=t.element,o=t.state.scrollState,n=o.verticalTarget,r=o.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Ne(t);if(t.scrollAnimationId)return;let i=performance.now(),l=null,s=null,u={top:e.scrollTop,left:e.scrollLeft},c=0,a=0;const d=o=>{const n=t.state.scrollState.verticalTarget,r=t.state.scrollState.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Ne(t);null===n&&(s=null),null===r&&(l=null);const h=(o-i)/1e3;i=o;const f=t.lastScrollClientSizeVersion!==t.state.scrollState.clientSizeVersion;t.lastScrollClientSizeVersion=t.state.scrollState.clientSizeVersion;const p=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.verticalTarget;return Fe("top",e,l.scrollTop,u,l.clientHeight,l.scrollHeight,o?.top,n.top,s.verticalSpeed,r,i)}(t,h,s,u,c,f),m=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.horizontalTarget;return Fe("left",e,l.scrollLeft,u,l.clientWidth,l.scrollWidth,o?.left,n.left,s.horizontalSpeed,r,i)}(t,h,l,u,a,f),g={...s,...l,behavior:"smooth",...p,...m};(p||m)&&e.scrollTo(g),c=p&&"auto"===g.behavior?g.top-e.scrollTop:0,a=m&&"auto"===g.behavior?g.left-e.scrollLeft:0,s=p||s,l=m||l,u={top:e.scrollTop,left:e.scrollLeft},t.scrollAnimationId=requestAnimationFrame(d)};d(i)}(t))}catch(e){He(t,e)}}function Pe(t){if("spread-grid-context"in t)return;const e={"top-left":document.createElement("canvas"),"top-center":document.createElement("canvas"),"top-right":document.createElement("canvas"),"middle-left":document.createElement("canvas"),"middle-center":document.createElement("canvas"),"middle-right":document.createElement("canvas"),"bottom-left":document.createElement("canvas"),"bottom-center":document.createElement("canvas"),"bottom-right":document.createElement("canvas")},i=document.createElement("input"),l=document.createElement("div");t.setAttribute("tabindex","0"),t.classList.add("spread-grid"),e["top-left"].setAttribute("style","position: sticky; left: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 1;"),e["top-center"].setAttribute("style","position: sticky; top: 0; z-index: 1; grid-row: 1; grid-column: 2;"),e["top-right"].setAttribute("style","position: sticky; right: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 3;"),e["middle-left"].setAttribute("style","position: sticky; left: 0; z-index: 1; grid-row: 2; grid-column: 1;"),e["middle-center"].setAttribute("style","grid-row: 2; grid-column: 2; z-index: 0;"),e["middle-right"].setAttribute("style","position: sticky; right: 0; z-index: 1; grid-row: 2; grid-column: 3;"),e["bottom-left"].setAttribute("style","position: sticky; left: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 1;"),e["bottom-center"].setAttribute("style","position: sticky; bottom: 0; z-index: 1; grid-row: 3; grid-column: 2;"),e["bottom-right"].setAttribute("style","position: sticky; right: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 3;"),i.setAttribute("style","position: sticky; z-index: 3; outline: none; border: none; box-shadow: none; padding: 0 5px; font-size: 12px; font-family: Calibri; background-color: white; box-sizing: border-box; opacity: 0; pointer-events: none;"),l.setAttribute("style","pointer-events: none; background-color: white; color: black; border: 1px solid black; padding: 3px 7px; inset: unset; position: absolute; font-size: 12px; font-family: Calibri; "),l.setAttribute("popover","manual"),l.classList.add("spread-grid-tooltip");const s={element:t,canvases:e,input:i,tooltip:l,localOptions:null,externalOptions:{},state:null,memory:{},renderRequested:!1,mousePosition:null,isMouseDown:!1,columnWidthCache:new Map,rowHeightCache:new Map,isReordering:!1,errorRendered:!1,error:null,resizingColumn:null,resizingRow:null,reorderedColumn:null,reorderedRow:null,didReorder:!1,mouseDownPosition:null,mouseDownCell:null,requestNewRender:null,fractionalScrollProgressVertical:0,fractionalScrollProgressHorizontal:0};function u(t,e,o){t.addEventListener(e,(t=>{try{o(t)}catch(t){t.message=`[${e} event]: ${t.message}`,He(s,t)}}))}s.requestNewRender=()=>{s.renderRequested||s.errorRendered||(s.renderRequested=!0,requestAnimationFrame((()=>{s.renderRequested=!1,We(s)})))},s.localOptions={data:[],columns:[{type:"DATA-BLOCK"}],rows:[{type:"HEADER"},{type:"DATA-BLOCK"}],formatting:[],filtering:[],sorting:[],dataSelector:({data:t,row:e,column:o})=>t?.[e.selector]?.[o.selector],pinnedTop:0,pinnedBottom:0,pinnedLeft:0,pinnedRight:0,borderWidth:1,focusedCell:null,onFocusedCellChange:t=>{s.localOptions.focusedCell=t,s.requestNewRender()},selectedCells:[],onSelectedCellsChange:t=>{s.localOptions.selectedCells=t,s.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:t=>{s.localOptions.editedCells=t,s.requestNewRender()},filters:[],onFiltersChange:t=>{s.localOptions.filters=t,s.requestNewRender()},sortBy:[],onSortByChange:t=>{s.localOptions.sortBy=t,s.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:t=>{s.localOptions.columnWidths=t,s.requestNewRender()},rowHeights:[],onRowHeightsChange:t=>{s.localOptions.rowHeights=t,s.requestNewRender()},columnsOrder:[],onColumnsOrderChange:t=>{s.localOptions.columnsOrder=t,s.requestNewRender()},rowsOrder:[],onRowsOrderChange:t=>{s.localOptions.rowsOrder=t,s.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{},verticalScrollTarget:null,horizontalScrollTarget:null,verticalScrollSpeed:"smooth",horizontalScrollSpeed:"smooth",disableScrollOnHover:!0,freezeOnHover:!1,style:{}},t["spread-grid-context"]=s;const c=t=>{i.value=t,i.dispatchEvent(new Event("input"))},a=t=>{const e=s.state.options.selectedCells,o=s.state.inputFormatResolver,n=s.state.columnLookup,i=s.state.rowLookup,l=s.state.text,u=s.state.inputState.isTextValid,a=s.state.options.onEditedCellsChange,d=s.state.options.onFiltersChange,h=r(e,o,n,i);if(""===l)return;if(!u)return;if(t&&!h.every((t=>t.edit.autoCommit)))return;const f=h.filter((t=>"DATA"===t.type)),p=h.filter((t=>"FILTER"===t.type));var m;m=f.map((t=>({...t.cell,value:t.edit.parse({string:l})}))),a(Me(s.state.options.editedCells,m)),(t=>{d(Me(Oe(s.state.options.filters,"FILTER"),t))})(p.map((t=>({...t.cell,expression:t.edit.parse({string:l})})))),t||c("")},d=t=>{const e=s.state.options.selectedCells,o=s.state.options.onEditedCellsChange,n=s.state.options.onFiltersChange,i=r(e,s.state.inputFormatResolver,s.state.columnLookup,s.state.rowLookup);var l;t&&!i.every((t=>t.edit.autoCommit))||(l=e,o(Be(s.state.options.editedCells,l)),(t=>{n(Be(Oe(s.state.options.filters,"FILTER"),t))})(e))};u(t,"scroll",(t=>{s.requestNewRender()})),u(t,"pointerenter",(t=>{s.mousePosition=Le(t),s.requestNewRender()})),u(t,"pointermove",(t=>{if(s.mousePosition=Le(t),s.resizingColumn){const t=s.state.columnLookup.get(o(s.resizingColumn)),e=t.width,n=t.right,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.x-n+e),l=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t.key)).concat([{columnId:t.id,width:i}]);s.state.options.onColumnWidthsChange(l)}if(s.resizingRow){const t=s.state.rowLookup.get(o(s.resizingRow)),e=t.height,n=t.bottom,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.y-n+e),l=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t.key)).concat([{rowId:t.id,height:i}]);s.state.options.onRowHeightsChange(l)}if(s.reorderedColumn){const t=s.state.columns,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=ze(t,e,o.columnId);if(!r)return null;const[i,l]=r,s=l<=i?n.x<t[l].leftWithBorder+t[i].width?l:l+1:n.x>t[l].rightWithBorder-t[i].width?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedColumn,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onColumnsOrderChange(n))}if(s.reorderedRow){const t=s.state.rows,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=ze(t,e,o.rowId);if(!r)return null;const[i,l]=r,s=l<=i?n.y<t[l].topWithBorder+t[i].height?l:l+1:n.y>t[l].bottomWithBorder-t[i].height?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedRow,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onRowsOrderChange(n))}s.requestNewRender()})),u(t,"touchmove",(t=>{(s.resizingColumn||s.resizingRow||s.reorderedColumn||s.reorderedRow)&&(t.preventDefault(),t.stopPropagation())})),u(t,"pointerleave",(()=>{s.mousePosition=null,s.requestNewRender()})),u(t,"pointerdown",(t=>{s.mousePosition=Le(t),Te(s),c("");const e=s.state.hoveredCell;if(s.isMouseDown=!0,s.didReorder=!1,s.mouseDownPosition=s.mousePosition,s.mouseDownCell=e,s.state.cursorState.resizableColumn&&(s.resizingColumn=s.state.cursorState.resizableColumn),s.state.cursorState.resizableRow&&(s.resizingRow=s.state.cursorState.resizableRow),!s.resizingColumn&&e){const t=s.state.rowLookup.get(o(e.rowId));s.reorderedColumn="HEADER"===t.type?e.columnId:null}if(!s.resizingRow&&e){const t=s.state.columnLookup.get(o(e.columnId));s.reorderedRow="HEADER"===t.type?e.rowId:null}s.resizingColumn||s.resizingRow||s.state.options.onFocusedCellChange(e),t.ctrlKey||s.state.options.onSelectedCellsChange([]),s.requestNewRender()})),u(t,"pointerup",(t=>{s.mousePosition=Le(t),Te(s),s.isMouseDown=!1,s.isReordering=!1,s.resizingColumn=null,s.resizingRow=null,s.reorderedColumn=null,s.reorderedRow=null,s.state.options.onSelectedCellsChange(Me(s.state.options.selectedCells,s.state.highlightedCells)),s.requestNewRender()})),u(t,"pointerdown",(t=>{s.element.setPointerCapture(t.pointerId)})),u(t,"pointerup",(t=>{s.element.releasePointerCapture(t.pointerId)})),u(t,"click",(t=>{s.mousePosition=Le(t),Te(s);const e=s.state.hoveredCell,r=s.mouseDownCell;if(s.state.cursorState.resizableColumn||s.state.cursorState.resizableRow)return;if(s.didReorder)return;if(null===e)return;if(null===r)return;if(o(e.columnId)!==o(r.columnId))return;if(o(e.rowId)!==o(r.rowId))return;const i=s.state.columnLookup.get(o(e.columnId)),l=s.state.rowLookup.get(o(e.rowId)),u=s.state.options.sortBy,c=s.state.inputFormatResolver.resolve(l,i),a={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,detail:t.detail};if(c.edit?.toggle){const t=function(t,e,o,n){const r=n.hasValueByKey(o.key,e.key)?n.getValueByKey(o.key,e.key):t.value,i=t.edit.toggle;return"function"==typeof i?i({value:r}):i[(i.indexOf(r)+1)%i.length]}(c,i,l,s.state.edition),o=n(i,l);"DATA"===o&&s.state.options.onEditedCellsChange(Me(s.state.options.editedCells,[{...e,value:t}])),"FILTER"===o&&s.state.options.onFiltersChange(Me(Oe(s.state.options.filters,"FILTER"),[{...e,expression:t}]))}else if("DATA"===i.type&&"DATA"===l.type)s.state.options.onCellClick({...s.state.hoveredCell,...a});else if("CUSTOM"===i.type||"CUSTOM"===l.type)s.state.options.onCustomCellClick({...s.state.hoveredCell,...a});else if("HEADER"===i.type||"HEADER"===l.type){const e=s.state.sortOrderFormatResolver.resolve(l,i),n=function(t,e,n,r,i){function l(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return e.key===o(r)&&n.key===o(i)}const s=i?i.map((t=>null===t?void 0:t)):["ASC","DESC",void 0],u=t.find(l),c=s.indexOf(u?.direction),a=s[(c+1)%s.length],d=t.indexOf(u)===t.length-1;return[...!r||!d&&u?t.filter((t=>!function(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return"HEADER"===e.type&&e.key===o(r)||"HEADER"===n.type&&n.key===o(i)}(t))):t.filter((t=>!l(t))),...a?[{columnId:e.id,rowId:n.id,direction:a}]:[]]}(u,i,l,t.ctrlKey,e.sortOrder);s.state.options.onSortByChange(n),s.state.options.onSelectedCellsChange([])}})),u(t,"dblclick",(t=>{if(s.mousePosition=Le(t),Te(s),s.state.cursorState.resizableColumn){const t=o(s.state.cursorState.resizableColumn),e=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t));s.state.options.onColumnWidthsChange(e),s.columnWidthCache.delete(t)}if(s.state.cursorState.resizableRow){const t=o(s.state.cursorState.resizableRow),e=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t));s.state.options.onRowHeightsChange(e),s.rowHeightCache.delete(t)}const e=s.state.focusedCell;if(null===e)return;const n=o(e.columnId),r=o(e.rowId),l=s.state.columnLookup,u=s.state.rowLookup,a=s.state.inputFormatResolver;if(!l.has(n))return;if(!u.has(r))return;const d=l.get(n),h=u.get(r),f=a.resolve(h,d),p=f.text;f.edit&&(f.edit.toggle||(c(p),i?.select()))})),u(t,"focus",(()=>{i.parentElement&&i.focus({preventScroll:!0})})),u(t,"keydown",(t=>{Te(s);const e=s.state.focusedCell,n=s.state.columnLookup,r=s.state.rowLookup,i=s.state.options.selectedCells,l=s.state.options.onSelectedCellsChange,u=s.state.options.onFocusedCellChange,h=s.state.options.editedCells,f=s.state.options.onEditedCellsChange,p=s.state.columns,m=s.state.rows,g=s.state.text,y=s.state.inputFormatResolver,w=(t,e)=>{u(t),e.shiftKey?l(Me(i,[t])):l([t])},C=(t,r)=>{if(!e)return;const i=o(e.columnId);if(!n.has(i))return;const l=n.get(i).index,s=Math.max(0,Math.min(p.length-1,l+t));if(s===l)return;const u={rowId:e.rowId,columnId:p[s].id};w(u,r)},x=(t,n)=>{if(!e)return;const i=o(e.rowId);if(!r.has(i))return;const l=r.get(i).index,s=Math.max(0,Math.min(m.length-1,l+t));if(s===l)return;const u={rowId:m[s].id,columnId:e.columnId};w(u,n)},v=()=>{t.preventDefault(),t.stopPropagation()};switch(t.key){case"Escape":""!==g?c(""):i.length>1?l([e]):h.length>0?f([]):(u(null),l([]));break;case"Enter":a(!1);break;case"ArrowUp":v(),x(t.ctrlKey?-m.length:-1,t);break;case"ArrowDown":v(),x(t.ctrlKey?m.length:1,t);break;case"ArrowLeft":v(),C(t.ctrlKey?-p.length:-1,t);break;case"ArrowRight":v(),C(t.ctrlKey?p.length:1,t);break;case"Delete":case"Backspace":d(!1);break;case"c":(t=>{if(!t.ctrlKey)return;const e=function(t,e,n,r){const i=new Map(e.map((t=>[t.key,t]))),l=new Map(n.map((t=>[t.key,t]))),s=t.map((t=>({columnKey:o(t.columnId),rowKey:o(t.rowId)}))).filter((t=>i.has(t.columnKey)&&l.has(t.rowKey))),u=new Set(s.map((t=>t.columnKey))),c=new Set(s.map((t=>t.rowKey)));if(0===s.length)return"";const a=new b(t),d=Math.min(...s.map((t=>i.get(t.columnKey).index))),h=Math.max(...s.map((t=>i.get(t.columnKey).index))),f=Math.min(...s.map((t=>l.get(t.rowKey).index))),p=Math.max(...s.map((t=>l.get(t.rowKey).index))),m=[];for(let t=f;t<=p;t++){const o=n[t],i=o.key;if(c.has(i)){for(let t=d;t<=h;t++){const n=e[t],l=n.key;if(u.has(l)){if(a.isKeySelected(i,l)){const t=r.resolve(o,n).text;m.push(t)}t<h&&m.push("\t")}}t<p&&m.push("\n")}}return m.join("")}(i,p,m,y);if(navigator.clipboard)navigator.clipboard.writeText(e);else{const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}})(t)}})),new ResizeObserver((()=>{s.requestNewRender()})).observe(t),u(i,"input",(t=>{Te(s),i.value?(a(!0),i.style.opacity="1",i.style.pointerEvents="auto"):(t.isTrusted&&d(!0),i.style.opacity="0",i.style.pointerEvents="none")})),u(i,"click",(t=>{t.stopPropagation()})),u(i,"dblclick",(t=>{t.stopPropagation()})),u(i,"pointerdown",(t=>{t.stopPropagation()})),u(i,"keydown",(t=>{switch(t.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==i.value&&(t.stopPropagation(),s.requestNewRender());break;default:t.stopPropagation(),s.requestNewRender()}})),u(t,"wheel",(e=>{null===s.state.scrollState.verticalTarget&&null===s.state.scrollState.horizontalTarget||(t.scrollBy({top:e.deltaY,left:e.deltaX,behavior:"auto"}),e.preventDefault(),e.stopPropagation())}))}function Ye(t,e){Pe(t);const o=t["spread-grid-context"];o.externalOptions=e,null===o.state?We(o):o.requestNewRender()}return e.default})()));
|
package/package.json
CHANGED
package/src/core/state.js
CHANGED
|
@@ -199,6 +199,8 @@ export default function updateState(context) {
|
|
|
199
199
|
const text = context.input.value;
|
|
200
200
|
const sortBy = cache('sortBy', getResolvedSortBy, [options.sortBy]);
|
|
201
201
|
const filters = cache('filters', getResolvedFilters, [options.filters]);
|
|
202
|
+
const columnWidths = cache('columnWidths', v => v, [options.columnWidths]);
|
|
203
|
+
const rowHeights = cache('rowHeights', v => v, [options.rowHeights]);
|
|
202
204
|
const textResolver = cache('textResolver', getTextResolver, []);
|
|
203
205
|
const dataFormatting = cache('dataFormatting', getDataFormatting, [options.formatting, options.dataSelector, sortBy]);
|
|
204
206
|
const editedCellsAndFilters = cache('editedCellsAndFilters', getEditedCellsAndFilters, [options.editedCells, filters]);
|
|
@@ -214,8 +216,8 @@ export default function updateState(context) {
|
|
|
214
216
|
const unfoldedRows = cache('unfoldedRows', getUnfoldedRows, [invokedRows, data]);
|
|
215
217
|
const dynamicColumnWidth = 150;
|
|
216
218
|
const dynamicRowHeight = cache('dynamicRowHeight', getDynamicRowHeight, [textResolver]);
|
|
217
|
-
const unfilteredColumns = cache('unfilteredColumns', getResolvedColumns, [unfoldedColumns,
|
|
218
|
-
const unfilteredRows = cache('unfilteredRows', getResolvedRows, [unfoldedRows,
|
|
219
|
+
const unfilteredColumns = cache('unfilteredColumns', getResolvedColumns, [unfoldedColumns, columnWidths, borderWidth, devicePixelRatio, dynamicColumnWidth]);
|
|
220
|
+
const unfilteredRows = cache('unfilteredRows', getResolvedRows, [unfoldedRows, rowHeights, borderWidth, devicePixelRatio, dynamicRowHeight]);
|
|
219
221
|
const unfilteredColumnKeys = cache('unfilteredColumnKeys', getKeys, [unfilteredColumns]);
|
|
220
222
|
const unfilteredRowKeys = cache('unfilteredRowKeys', getKeys, [unfilteredRows]);
|
|
221
223
|
|
|
@@ -240,7 +242,7 @@ export default function updateState(context) {
|
|
|
240
242
|
const sortedRows = cache('sortedRows', getSortedRows, [sortBy, sortingRules, sortingFormattingRules, data, filteredRows, filteredColumns, edition]);
|
|
241
243
|
|
|
242
244
|
// Shaping finalization
|
|
243
|
-
const freezeOnHover = options.freezeOnHover && !stateChanges.includes('sortBy') && !stateChanges.includes('filters');
|
|
245
|
+
const freezeOnHover = options.freezeOnHover && !stateChanges.includes('sortBy') && !stateChanges.includes('filters') && !stateChanges.includes('columnWidths') && !stateChanges.includes('rowHeights');
|
|
244
246
|
const shapedColumns = cache('shapedColumns', getFrozenColumns, [sortedColumns, freezeOnHover, previousState?.hoveredCell, previousState?.shapedColumns]);
|
|
245
247
|
const shapedRows = cache('shapedRows', getFrozenRows, [sortedRows, freezeOnHover, previousState?.hoveredCell, previousState?.shapedRows]);
|
|
246
248
|
const pinning = cache('pinning', getPinning, [shapedColumns, shapedRows, options.pinnedTop, options.pinnedBottom, options.pinnedLeft, options.pinnedRight]);
|
package/src/typings.js
CHANGED
|
@@ -1142,6 +1142,8 @@ export { };
|
|
|
1142
1142
|
* @property {Cached<CachedNumber>} [borderWidth]
|
|
1143
1143
|
* @property {Cached<SortBy[]>} [sortBy]
|
|
1144
1144
|
* @property {Cached<ResolvedFilter[]>} [filters]
|
|
1145
|
+
* @property {Cached<ColumnWidth[]>} [columnWidths]
|
|
1146
|
+
* @property {Cached<RowHeight[]>} [rowHeights]
|
|
1145
1147
|
* @property {Cached<TextResolver>} [textResolver]
|
|
1146
1148
|
* @property {Cached<Rule[]>} [dataFormatting]
|
|
1147
1149
|
* @property {Cached<EditedCell[]>} [editedCellsAndFilters]
|