react-spread-grid 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"react";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},o={};e.d(o,{A:()=>Ve});const n=(r={default:()=>t.default,useState:()=>t.useState},i={},e.d(i,r),i);var r,i;function l(t){return null===t?"null":Array.isArray(t)?`[${t.map(l).join(",")}]`:"object"==typeof t?(e=t,`{${Object.keys(e).sort().map((t=>`${t}:${l(e[t])}`)).join(",")}}`):JSON.stringify(t);var e}function s(t,e){const o="FILTER"===t.type,n="FILTER"===e.type;return o&&!n||!o&&n?"FILTER":"DATA"}function u(t,e,o,n){return t.map((t=>{const r=l(t.columnId),i=l(t.rowId);if(!o.has(r))return null;if(!n.has(i))return null;const u=o.get(r),a=n.get(i);return{edit:e.resolve(a,u).edit,cell:t,type:s(u,a)}})).filter((t=>t?.edit))}function a(t,e){return Math.round(t*e)/e}function c(t,e,o){const n=t.state.renderState,r=t.canvases[`${e}-${o}`],i=n.sections[e],l=n.sections[o],s=l.columns,u=i.rows,c=n.devicePixelRatio;if(0===u.length||0===s.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=i.showTopBorder,y=i.showBottomBorder,w=l.showLeftBorder,b=l.showRightBorder,C=m/2,x=u.length-1+(g?1:0)+(y?1:0),v=s.length-1+(w?1:0)+(b?1:0),A=u.map((t=>t.height)),R=s.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:l.width,M="middle"===e?h.height:i.height,T=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=T.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+M)),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=u[e+K];return Array.from({length:N-z+1},((t,e)=>{const n=s[e+z];return p.resolve(o,n)}))})),V=(t,e)=>$[t-K][e-z];r.width=Math.round(D*c),r.height=Math.round(M*c),r.style.width=`${D}px`,r.style.height=`${M}px`,r.style.marginLeft=`${E}px`,r.style.marginTop=`${S}px`,r.style.marginRight=I-D-E+"px",r.style.marginBottom=k-M-S+"px",d.fillStyle="#E9E9E9",d.fillRect(0,0,r.width,r.height);const q=(t,e)=>{d.setTransform(c,0,0,c,(t-E)*c,(e-S)*c)},_=(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],i=T[t],l=R[t],s=A[e],u=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(q(i,r),d.fillStyle=n.background||"white",d.fillRect(0,0,l,s),"draw"in o&&o.draw(d),n.highlight&&(d.fillStyle=n.highlight,d.fillRect(0,0,l,s)),n.corner&&(d.fillStyle=n.corner,d.beginPath(),d.moveTo(l-7,s),d.lineTo(l,s),d.lineTo(l,s-7),d.fill()),u&&"transparent"!==g){d.fillStyle=g,d.font=o.font;const t=f.getFontMetrics(o.font),e="center"==n.textAlign&&f.measureWidth(u,o.font)>l-p.left-p.right?"left":n.textAlign||"left";d.textAlign=e;const r=a("left"===e?p.left:"center"===e?l/2:"right"===e?l-p.right:0,c),i=a("top"===h?t.middle+t.topOffset+p.top:"middle"===h?s/2+t.middle:"bottom"===h?s+t.middle-t.bottomOffset-p.bottom:0,c);d.save(),_(0,2*m,l,s-4*m),d.fillText(u,r,i),d.restore()}}q(0,0);const G=(t,e,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/c,l=e===n,s=t-(l?i/2:0),u=e-(l?0:i/2),a=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/c))),d.lineDashOffset=l?s:u):d.setLineDash([]),d.beginPath(),d.moveTo(s,u),d.lineTo(a,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);G(T[t]-C,B[o]-C,T[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);G(T[o]-C,B[t]-C,T[o]-C,B[t+1]-C,n)}}}const d={value:({newValue:t})=>t||"",text:({newValue:t})=>t||"Search...",edit:{validate:()=>!0,parse:({string:t})=>t,autoCommit:!0}};function h(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"},...d},{column:{type:"FILTER"},row:{type:"DATA"},...d},{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 f=["column","row","condition"];function p(t){return Object.keys(t).length>Object.keys(t).filter((t=>f.includes(t))).length}function m(t,e){const o=[...f,...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(p)}function g(t){return m(t,["value","text","edit"])}function y(t,e){return e?t+"99":t+"33"}function w(t,e,o,n,r,i,s,u,a,c,d,h,f){t=m(t,["value","style","text","font","padding","edit","draw"]);const p=o?l(o.columnId):null,g=o?l(o.rowId):null,w=null!==a,b=null!==u||w,C=c+2,x=c+4,v=(t,e,o,r)=>{if(o<0||o>=t.length)return!1;if(r<0||r>=e.length)return!1;const i=t[o],l=e[r];if("DYNAMIC-BLOCK"===i.type)return!1;if("DYNAMIC-BLOCK"===l.type)return!1;const s=i.key,u=l.key;return n.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:c,color:"gray"}}},{column:{type:"HEADER"},row:{type:"ANY"},style:{background:"#F5F5F5",border:{width:c,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:y(r?"#798d9c":"#819481",p!==n.key||g!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>r.isKeySelected(t.key,e.key),style:({row:t,column:e})=>({highlight:y("#93a8b8",p!==e.key||g!==t.key)})},...A(!!o,{column:{id:o?.columnId},row:{id:o?.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})=>i.hasValueByKey(t.key,e.key),style:{corner:"darkgreen"}},...A(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:x,color:"cornflowerblue"}}}),...A(a,{column:{type:"HEADER"},row:{id:a},style:{borderBottom:{width:x,color:"cornflowerblue"}}}),...A(d&&h,{column:{id:h},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...A(d&&f,{column:{type:"ANY"},row:{id:f},style:{highlight:"#3a74e055"}})]}function b(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),a=e.slice(e.length-n,e.length),c=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:a,showTopBorder:w,showBottomBorder:b,height:S(a,w,b)},middle:{rows:c,showTopBorder:C,showBottomBorder:x,height:S(c,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 C(t,e){return[...t,...e.map((t=>({columnId:t.columnId,rowId:t.rowId,value:t.expression})))]}class x{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=l(t.rowId),o=l(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Map),this.lookup.get(e).set(o,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(l(t),l(e))}getValueById(t,e){return this.getValueByKey(l(t),l(e))}}function v(t){return new x(t)}class A{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=l(t.rowId),o=l(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Set),this.lookup.get(e).add(o)}))}isKeySelected(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}isIdSelected(t,e){return this.isKeySelected(l(t),l(e))}}function R(t){return new A(t)}function I(t,e){return"function"==typeof t?t(e):t}function k(t,e){return"function"==typeof t?t(e):t}function E(t,e){const o=t.type||"DATA",n="selector"in t?t.selector:"id"in t?t.id:void 0,r="id"in t?t.id:"selector"in t?t.selector:o;return{...t,id:r,selector:n,type:o,key:l(r),header:"header"in t?t.header:r,resizable:!("resizable"in t)||t.resizable,labels:t.labels||[],index:e}}function S(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 D(t,e){return"number"==typeof t?a(t,e):t}function M(t,e,o,n,r){const i=new Map(e.map((({columnId:t,width:e})=>[l(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const r=S(t,e),i=t.width*t.count+o*(t.count-1);return{...r,count:t.count,width:a(i,n),columnWidth:a(t.width,n)}}{const o=E(t,e),r=i.has(o.key)?i.get(o.key):"width"in t?t.width:"fit";return{...o,width:D(r,n)}}}))}function T(t,e,o,n,r){const i=new Map(e.map((({rowId:t,height:e})=>[l(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const i=S(t,e),l="height"in t?t.height:r,s=l*t.count+o*(t.count-1);return{...i,count:t.count,height:a(s,n),rowHeight:a(l,n)}}{const o=E(t,e),r=i.has(o.key)?i.get(o.key):"height"in t?t.height:"fit";return{...o,height:D(r,n)}}}))}function B(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 L(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:B(i,t.length,e.left,e.right,r.type)};return n+=s.width+o,s}))}function O(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:B(i,t.length,e.top,e.bottom,r.type)};return n+=s.height+o,s}))}const z="12px Calibri",N={top:2,right:5,bottom:2,left:5};function K(t){return"function"==typeof t?t:()=>t}const F={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class H{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class W{lookup=new H;hasRules=!1;addRule(t,e,o){if(this.hasRules=!0,Array.isArray(t)){for(const n of t)this.addRule(n,e,o);return}if(Array.isArray(e)){for(const n of e)this.addRule(t,n,o);return}const n=t?"id"in t?{key:l(t.id)}:t:{type:"DATA"},r=e?"id"in e?{key:l(e.id)}:e:{type:"DATA"};function i(t,e){t.has(e)||t.set(e,[]),t.get(e).push(o)}function s(t,e){if(t.has(e)||t.set(e,new H),"key"in r)i(t.get(e).byKey,r.key);else if("index"in r)i(t.get(e).byIndex,r.index);else if("label"in r)i(t.get(e).byLabel,r.label);else for(const o of F[r.type||"NONE"])i(t.get(e).byType,o)}if("key"in n)s(this.lookup.byKey,n.key);else if("index"in n)s(this.lookup.byIndex,n.index);else if("label"in n)s(this.lookup.byLabel,n.label);else for(const t of F[n.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 P=["borderTop","borderRight","borderBottom","borderLeft"],Y={validate:()=>!0,parse:({string:t})=>t};function $(t,e){const o={...t};if("border"in o){for(const t of P)o[t]=o.border;delete o.border}for(const t of P)t in o&&(o[t]={...o[t],index:e});return o}function V(t,e){if(!1!==t.edit)return!0===t.edit?"edit"in e?e.edit:Y:"edit"in e?{...e.edit,...t.edit}:{...Y,...t.edit}}class q{constructor(t){this.rulesLookup=new W;for(const[e,o]of t.entries()){const t={index:e};"condition"in o&&(t.condition=o.condition),"style"in o&&(t.style=K(o.style)),"value"in o&&(t.value=K(o.value)),"text"in o&&(t.text=K(o.text)),"font"in o&&(t.font=K(o.font)),"padding"in o&&(t.padding=K(o.padding)),"edit"in o&&(t.edit=o.edit),"tooltip"in o&&(t.tooltip=K(o.tooltip)),"draw"in o&&(t.draw=o.draw),"sortOrder"in o&&(t.sortOrder=K(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,a={data:t,rows:e,columns:o,row:n,column:r},c={},d=N,h=z;i.hasValueByKey(n.key,r.key)&&(a={...a,newValue:i.getValueByKey(n.key,r.key)});for(const t of l)if((!("condition"in t)||t.condition(a))&&("value"in t&&(a={...a,value:t.value(a)}),"style"in t&&(c={...c,...$(t.style(a),t.index)}),"text"in t&&(a={...a,text:t.text(a)}),"font"in t&&(h=t.font(a)),"padding"in t&&(d={...d,...t.padding(a)}),"edit"in t&&(a={...a,edit:V(t,a)}),"tooltip"in t&&(u=t.tooltip(a)),"sortOrder"in t&&(a={...a,sortOrder:t.sortOrder(a)}),"draw"in t)){const e=a;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}`:""}(a),p={render:!0,style:c,text:f,padding:d,font:h};return"value"in a&&(p.value=a.value),"edit"in a&&void 0!==a.edit&&(p.edit=a.edit),void 0!==u&&(p.tooltip=u),"sortOrder"in a&&(p.sortOrder=a.sortOrder),void 0!==s&&(p.draw=s),p}}function _(t){return new q(t)}class G{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 j(t,e,o,n,r){return new G(t,e,o,n,r)}function U(t,e,o){const n=new Map;for(const r of t){const t=l(r[e]),i=l(r[o]);n.has(t)||n.set(t,new Map),n.get(t).set(i,r.expression)}return n}function X(t,e,o,n,r,i,l){if(0===t.length)return r;const s=U(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 a of u){if("DYNAMIC-BLOCK"===a.type)continue;const u=o.resolve(n,r,i,t,a,l),c=s.get(a.key);if(!e.resolve(n,r,i,t,a,u.value,u.text,c))return!1}return!0}))}function J(t,e,o,n,r,i,l){if(0===t.length)return i;const s=U(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 a of u){if("DYNAMIC-BLOCK"===a.type)continue;const u=o.resolve(n,r,i,a,t,l),c=s.get(a.key);if(!e.resolve(n,r,i,a,t,u.value,u.text,c))return!1}return!0}))}function Q(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 Z(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 tt(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]=Q(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]=Z(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]=Q(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]=Z(i,o.right-r,n);s+=l,r+=u}}return{top:r,bottom:i,left:l,right:s}}function et(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.height,o+=e;return o}function ot(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.width,o+=e;return o}function nt(t,e,o){return{width:ot(t,o),height:et(e,o)}}class rt{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||z,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||z;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 it(){return new rt}function lt(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 st(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 ut(t,e){return{top:t.top-e,left:t.left-e,width:t.width+2*e,height:t.height+2*e}}function at(t){return t.width*t.height}function ct(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 dt=200,ht=400,ft={left:0,top:0,width:0,height:0};function pt(t,e,o,n,r){const i=t||ft,l=ct({left:0,top:0,...o},n),s=ct({...e,...r},n),u=st(l,ut(s,dt)),a=st(l,ut(s,ht));return lt(l,i)&<(i,u)?at(i)>2*at(a)?a:i:a}function mt(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 gt(t){return t.reduce(((t,e)=>t.set(e.key,e)),new Map)}function yt(t,e,o,n,r,i,s,u){if(!t)return[];if(!e)return[];if(!n)return[];if(!o)return[];const a=l(o.columnId),c=l(o.rowId),d=l(n.columnId),h=l(n.rowId);if(!s.has(a))return[];if(!u.has(c))return[];if(!s.has(d))return[];if(!u.has(h))return[];const f=Math.min(s.get(a).index,s.get(d).index),p=Math.max(s.get(a).index,s.get(d).index),m=Math.min(u.get(c).index,u.get(h).index),g=Math.max(u.get(c).index,u.get(h).index);return r.slice(f,p+1).flatMap((t=>i.slice(m,g+1).map((e=>({rowId:e.id,columnId:t.id})))))}function wt(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 bt(t,e,o,n,r){return 0===t.length?null:function(t,e,o,n){if(!t)return null;const r=l(t.columnId),i=l(t.rowId);if(!e.has(r))return null;if(!o.has(i))return null;const s=e.get(r),u=o.get(i),a={width:s.width,height:u.height,section:wt(s,u)};switch(u.pinned){case"BEGIN":a.top=u.top;break;case"END":a.bottom=n.top.height+n.middle.height+n.bottom.height-u.top-u.height;break;default:a.marginTop=u.top-n.top.height}switch(s.pinned){case"BEGIN":a.left=s.left;break;case"END":a.right=n.left.width+n.center.width+n.right.width-s.left-s.width;break;default:a.marginLeft=s.left-n.left.width}return a}(e,o,n,r)}function Ct(t,e){return e.every((e=>e.edit.validate({string:t})))}function xt(t){return Array.isArray(t)?t.map(((t,e)=>e)):Object.keys(t)}function vt(t){return xt(t)}function At(t){const e=new Set;if(Array.isArray(t))for(const o of t)for(const t of xt(o))e.add(t);else for(const o in t)for(const n of xt(t[o]))e.add(n);return Array.from(e)}function Rt(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}):At(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 It(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}):vt(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 kt=({text:t,expression:e})=>t.includes(e);class Et{constructor(t){this.rulesLookup=new W;for(const e of t){const t={by:l("by"in e?e.by:"FILTER"),condition:e.condition||kt};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"')||kt({text:l,expression:s.get('"FILTER"')});let a={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={...a,expression:s.get(t.by)};if(!t.condition(e))return!1}return!0}}function St(t){return new Et(t)}function Dt(t){return m(t,["value","text"])}function Mt(t){return m(t,["value","text","font","padding"])}function Tt(t,e,o,n,r,i,l){if(t.every((t=>"number"==typeof t.width)))return t;const s=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,a=e.padding.left+e.padding.right,c=o.measureWidth(s,u)+a;l=Math.max(l,c)}return r.set(t.key,{width:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())i.has(t)||r.delete(t);return t.map((t=>({...t,width:a(s(t),l)})))}function Bt(t,e,o,n,r,i,l){if(e.every((t=>"number"==typeof t.height)))return e;const s=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,a=t.padding.top+t.padding.bottom,c=o.measureHeight(s,u)+a;l=Math.max(l,c)}return r.set(e.key,{height:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())i.has(t)||r.delete(t);return e.map((t=>({...t,height:a(s(t),l)})))}function Lt(t){const e=new Set;for(const o of t)"DYNAMIC-BLOCK"!=o.type&&e.add(o.key);return e}function Ot(t){return m(t,["value","text"])}function zt(t){return m(t,["value","sortOrder"])}function Nt(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 Kt(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 Ft{constructor(t){this.rulesLookup=new W;for(const e of t){const t=e.comparatorAsc||e.comparator,o=e.comparatorDesc||(e.comparator?(t,o)=>{return-("number"==typeof(n=e.comparator(t,o))?n:n?-1:1);var n}:null),n=t?(e,o)=>t(e,o):(t,e)=>Nt(t,e),r=o?(t,e)=>o(t,e):(t,e)=>Kt(t,e),i={by:l("by"in e?e.by:"HEADER"),comparatorAsc:n,comparatorDesc:r};this.rulesLookup.addRule(e.column,e.row,i)}}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"')?Nt:Kt: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 Ht(t){return"manual"===t?null:new Ft(t)}function Wt(t,e,o){const n=new Map;for(const r of t){const t=l(r[e]),i=l(r[o]);n.has(t)||n.set(t,new Map),n.get(t).set(i,r.direction)}return n}function Pt(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 Yt(t,e,o,n,r,i,s){if(0===t.length)return r;if(null===e)return r;const u=Wt(t,"columnId","rowId"),a=new Map(i.filter((t=>"DYNAMIC-BLOCK"!==t.type)).map((t=>[t.key,t]))),c=t.map((t=>l(t.columnId))).filter((t=>a.has(t))).map((t=>a.get(t))).reverse();if(0===c.length)return r;for(const t of c){const l=[],a=[];for(const c of r){if("DYNAMIC-BLOCK"===c.type){Pt(a,l),l.push(c);continue}const d=e.resolve(t,c,u.get(t.key));if(!d){Pt(a,l),l.push(c);continue}const h={entity:c,comparator:d,cell:o.resolve(n,r,i,c,t,s)};0!==a.length&&a[0].comparator!==d?(Pt(a,l),a.push(h)):a.push(h)}Pt(a,l),r=l}return r}function $t(t,e,o,n,r,i,s){if(0===t.length)return i;if(null===e)return i;const u=Wt(t,"rowId","columnId"),a=new Map(r.filter((t=>"DYNAMIC-BLOCK"!=t.type)).map((t=>[t.key,t]))),c=t.map((t=>l(t.rowId))).filter((t=>a.has(t))).map((t=>a.get(t))).reverse();if(0===c.length)return i;for(const t of c){const l=[],a=[];for(const c of i){if("DYNAMIC-BLOCK"===c.type){Pt(a,l),l.push(c);continue}const d=e.resolve(c,t,u.get(t.key));if(!d){Pt(a,l),l.push(c);continue}const h={entity:c,comparator:d,cell:o.resolve(n,r,i,t,c,s)};0!==a.length&&a[0].comparator!==d?(Pt(a,l),a.push(h)):a.push(h)}Pt(a,l),i=l}return i}const Vt=5;function qt(t,e,o,n,r,i){if(!n)return null;if(i)return null;const s=e.get(l(n.columnId));if("HEADER"!==o.get(l(n.rowId)).type)return null;if(!s.resizable)return null;if(!r)return null;const u=r.x;return u>=s.right-Vt&&u<=s.right+Vt?s.id:0===s.index||u<s.left-Vt||u>s.left+Vt?null:t[s.index-1].id}function _t(t,e,o,n,r,i){if(!n)return null;if(i)return null;const s=e.get(l(n.columnId)),u=o.get(l(n.rowId));if("HEADER"!==s.type)return null;if(!u.resizable)return null;if(!r)return null;const a=r.y;return a>=u.bottom-Vt&&a<=u.bottom+Vt?u.id:0===u.index||a<u.top-Vt||a>u.top+Vt?null:t[u.index-1].id}function Gt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"HEADER",rowId:"rowId"in t?t.rowId:"HEADER",direction:t.direction})))}function jt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"FILTER",rowId:"rowId"in t?t.rowId:"FILTER",expression:t.expression})))}function Ut(t){return t.filter((t=>"DATA"===t.type)).map((t=>t.id))}function Xt(t){return Ut(t)}function Jt(t){return Ut(t)}function Qt(t){return m(t,["value","text","tooltip"])}function Zt(t,e,o,n){if(!t)return null;const r=l(t.columnId),i=l(t.rowId);if(!o.has(r))return null;if(!n.has(i))return null;const s=n.get(i),u=o.get(r);return e.resolve(s,u).tooltip}function te(t,e){return t?{left:e.x+8,top:e.y+20}:null}function ee(t){return t.map((t=>l(t)))}function oe(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 ne(t,e){return oe(t,e)}function re(t,e){return oe(t,e)}function ie(t){return t.some((t=>"DYNAMIC-BLOCK"===t.type))}function le(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 se(t){return t.reduce(((t,e)=>"DYNAMIC-BLOCK"===e.type?t+e.count:t+1),0)}function ue(t,e,o,n,r,i){if(!ie(e))return e;let s=i,u=0,a=0;const c=se(e),d=n.left+r.left,h=d+n.width,f=[],p=(t,e)=>{f.push(e),s+=e.width+i,u+=t},m=t=>{p(1,t)},g=(e,o,n)=>{for(let r=o;r<=n;r++){const o=e.selector({data:t,index:r}),n=e.id({data:t,selector:o});p(1,{...e,type:"DATA",id:n,key:l(n),selector:o,header:e.header({data:t,selector:o}),width:e.columnWidth})}},y=(t,e)=>{if(e>0){const o="__separator_"+a++;p(e,{...t,type:"SEPARATOR",id:o,key:l(o),header:"",width:e*t.columnWidth+(e-1)*i})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,columnWidth:n}=t,r=n+i,l=o.left-u,a=c-o.right-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=le([[0,l-1],[Math.max(0,l,f),Math.min(e-1,a-1,p)],[a,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 ae(t,e,o,n,r,i){if(!ie(e))return e;let s=i,u=0,a=0;const c=se(e),d=n.top+r.top,h=d+n.height,f=[],p=(t,e)=>{f.push(e),s+=e.height+i,u+=t},m=t=>{p(1,t)},g=(e,o,n)=>{for(let r=o;r<=n;r++){const o=e.selector({data:t,index:r}),n=e.id({data:t,selector:o});p(1,{...e,type:"DATA",id:n,key:l(n),selector:o,header:e.header({data:t,selector:o}),height:e.rowHeight})}},y=(t,e)=>{if(e>0){const o="__separator_"+a++;p(e,{...t,type:"SEPARATOR",id:o,key:l(o),header:"",height:e*t.rowHeight+(e-1)*i})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,rowHeight:n}=t,r=n+i,l=o.top-u,a=c-o.bottom-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=le([[0,l-1],[Math.max(0,l,f),Math.min(e-1,a-1,p)],[a,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 ce(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),a=Math.min(o,s);return{left:u,top:a,right:Math.min(i,l-u),bottom:Math.min(n,s-a)}}function de(t){return{width:t.clientWidth,height:t.clientHeight}}function he(t){return{left:t.scrollLeft,top:t.scrollTop}}function fe(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 pe(t,e,o,n,r,i){return!!t&&(void 0===o||o<n||o>i-r||!e)}function me(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 ge(t,e,o,n,r,i,l,s,u){if(!pe(t,e,r?.y,i.top,i.bottom,l.height))return null;let a=Math.floor(t.index)+n.top,c=-i.top,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(a,t.count);if(c+=(t.rowHeight+u)*e,a-=e,e<t.count){d=t.rowHeight;break}}else{if(0===a){d=t.height;break}c+=t.height+u,a-=1}return me(t,c,d,s.height-i.top-i.bottom)}function ye(t,e,o,n,r,i,l,s,u){if(!pe(t,e,r?.x,i.left,i.right,l.width))return null;let a=Math.floor(t.index)+n.left,c=-i.left,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(a,t.count);if(c+=(t.columnWidth+u)*e,a-=e,e<t.count){d=t.columnWidth;break}}else{if(0===a){d=t.width;break}c+=t.width+u,a-=1}return me(t,c,d,s.width-i.left-i.right)}function we(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 be(t,e,o,n,r){return{verticalTarget:t,horizontalTarget:e,verticalSpeed:o,horizontalSpeed:n,clientSizeVersion:r}}function Ce(t){return{scrollbarWidth:t.scrollbarWidth||"auto"}}function xe(t,e,o,n,r,i){return{sections:t,devicePixelRatio:e,scrollRect:o,renderFormatResolver:n,borderWidth:r,textResolver:i}}function ve(t,e){return{inputPlacement:t,isTextValid:e}}function Ae(t,e,o){return{resizableColumn:t,resizableRow:e,isReordering:o}}function Re(t,e){return{tooltip:t,tooltipPlacement:e}}function Ie(t){return t.measureHeight("X",z)+N.top+N.bottom}function ke(t,e){return!t&&!e||!(!t||!e)&&t.x===e.x&&t.y===e.y}function Ee(t,e){return!t&&!e||!(!t||!e)&&t.width===e.width&&t.height===e.height}function Se(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top}function De(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height}function Me(t,e){return!t&&!e||!(!t||!e)&&l(t.rowId)===l(e.rowId)&&l(t.columnId)===l(e.columnId)}function Te(t,e){return!t&&!e||!(!t||!e)&&t.scrollbarWidth===e.scrollbarWidth}function Be(t){const e={...t.localOptions,...t.externalOptions},o=t.memory,n=t.state,r=t.element,i=[];function l(t,e,n,r=((t,e)=>t===e)){const l=o[t]&&o[t].dependencies;if(!l||n.some(((t,e)=>t!==l[e]))){const l=o[t]&&o[t].value,s=o[t]&&o[t].version||0,u=e(...n);r(l,u)?o[t]={value:l,dependencies:n,version:s}:(o[t]={value:u,dependencies:n,version:s+1},i.push(t))}return o[t].value}function s(t,e,n){(o[t]&&o[t].value)!==e&&(o[t]={value:e},n(e))}const a=l("devicePixelRatio",(t=>t),[window.devicePixelRatio]),c=l("borderWidth",(t=>t),[e.borderWidth/a]),d=e.data,f=t.input.value,p=l("sortBy",Gt,[e.sortBy]),m=l("filters",jt,[e.filters]),y=l("textResolver",it,[]),x=l("dataFormatting",h,[e.formatting,e.dataSelector,p]),A=l("editedCellsAndFilters",C,[e.editedCells,m]),E=l("edition",v,[A]),S=l("invokedColumns",I,[e.columns,d]),D=l("invokedRows",k,[e.rows,d]),B=l("mousePosition",(t=>t),[t.mousePosition],ke),z=l("unfoldedColumns",Rt,[S,d]),N=l("unfoldedRows",It,[D,d]),K=l("dynamicRowHeight",Ie,[y]),F=l("unfilteredColumns",M,[z,e.columnWidths,c,a,150]),H=l("unfilteredRows",T,[N,e.rowHeights,c,a,K]),W=l("unfilteredColumnKeys",Lt,[F]),P=l("unfilteredRowKeys",Lt,[H]),Y=l("columnsOrder",ee,[e.columnsOrder]),$=l("rowsOrder",ee,[e.rowsOrder]),V=l("orderedColumns",ne,[F,Y]),q=l("orderedRows",re,[H,$]),G=l("filterFormatting",Dt,[x]),U=l("filterFormattingRules",_,[G]),Q=l("filteringRules",St,[e.filtering]),Z=l("filteredColumns",J,[m,Q,U,d,q,V,E]),et=l("filteredRows",X,[m,Q,U,d,q,V,E]),ot=l("sortingFormatting",Ot,[x]),rt=l("sortingFormattingRules",_,[ot]),lt=l("sortingRules",Ht,[e.sorting]),st=l("sortedColumns",$t,[p,lt,rt,d,et,Z,E]),ut=l("sortedRows",Yt,[p,lt,rt,d,et,Z,E]),at=l("pinning",ce,[st,ut,e.pinnedTop,e.pinnedBottom,e.pinnedLeft,e.pinnedRight]),ct=l("measureFormatting",Mt,[x]),dt=l("measureFormattingRules",_,[ct]),ht=l("measureFormatResolver",j,[dt,d,ut,st,E]),ft=t.columnWidthCache,wt=t.rowHeightCache,xt=l("measuredColumns",Tt,[st,ut,y,ht,ft,W,a]),vt=l("measuredRows",Bt,[st,ut,y,ht,wt,P,a]),At=l("fixedSize",tt,[xt,vt,at,c]),kt=l("totalSize",nt,[xt,vt,c]),Et=l("clientSize",(t=>t),[de(r)],Ee),Nt=l("boundingClientSize",(t=>t),[de(r)],Ee),Kt=l("scrollOffset",(t=>t),[he(r)],Se),Ft=l("internalMousePosition",fe,[B,Et,Kt,At,kt],ke),Wt=l("scrollRect",pt,[n?.renderState?.scrollRect,Kt,kt,At,Nt],De),Pt=l("horizontalScrollTarget",ye,[e.horizontalScrollTarget,e.disableScrollOnHover,xt,at,Ft,At,kt,Et,c]),Vt=l("verticalScrollTarget",ge,[e.verticalScrollTarget,e.disableScrollOnHover,vt,at,Ft,At,kt,Et,c]),Ut=l("horizontalScrollSpeed",we,[e.horizontalScrollSpeed]),oe=l("verticalScrollSpeed",we,[e.verticalScrollSpeed]),ie=l("staticColumns",ue,[d,xt,at,Wt,At,c]),le=l("staticRows",ae,[d,vt,at,Wt,At,c]),se=l("columns",L,[ie,at,c]),pe=l("rows",O,[le,at,c]),me=l("columnLookup",gt,[se]),Be=l("rowLookup",gt,[pe]),Le=e.focusedCell,Oe=l("sections",b,[se,pe]),ze=e.selectedCells,Ne=l("hoveredCell",mt,[Ft,pe,se,At,kt],Me),Ke=t.isReordering,Fe=t.resizingColumn||l("resizableColumn",qt,[se,me,Be,Ne,Ft,Ke]),He=t.resizingRow||l("resizableRow",_t,[pe,me,Be,Ne,Ft,Ke]),We=l("highlightedCells",yt,[t.isMouseDown,!Fe&&!He&&!t.didReorder,Le,Ne,se,pe,me,Be]),Pe=l("selection",R,[ze]),Ye=l("highlight",R,[We]),$e=l("renderFormatting",w,[x,Ne,Le,Pe,Ye,E,p,Fe,He,e.borderWidth,Ke,t.reorderedColumn,t.reorderedRow]),Ve=l("renderFormattingRules",_,[$e]),qe=l("renderFormatResolver",j,[Ve,d,pe,se,E]),_e=l("sortOrderFormatting",zt,[x]),Ge=l("sortOrderFormattingRules",_,[_e]),je=l("sortOrderFormatResolver",j,[Ge,d,pe,se,E]),Ue=l("inputFormatting",g,[x]),Xe=l("inputFormattingRules",_,[Ue]),Je=l("inputFormatResolver",j,[Xe,d,pe,se,E]),Qe=l("editableCells",u,[ze,Je,me,Be]),Ze=l("inputPlacement",bt,[Qe,Le,me,Be,Oe]),to=l("isTextValid",Ct,[f,Qe]),eo=l("contextFormatting",Qt,[x]),oo=l("contextFormattingRules",_,[eo]),no=l("contextFormatResolver",j,[oo,d,pe,se,E]),ro=l("tooltip",Zt,[Ne,no,me,Be]),io=l("tooltipPlacement",te,[ro,B]),lo=l("renderState",xe,[Oe,a,Wt,qe,c,y]),so=l("inputState",ve,[Ze,to]),uo=l("cursorState",Ae,[Fe,He,t.isReordering]),ao=l("tooltipState",Re,[ro,io]),co=l("scrollState",be,[Vt,Pt,oe,Ut,o.clientSize.version]),ho=l("styleState",Ce,[e.style],Te),fo=l("activeColumns",Xt,[se]),po=l("activeRows",Jt,[pe]);s("activeColumnsCallback",fo,e.onActiveColumnsChange),s("activeRowsCallback",po,e.onActiveRowsChange),s("hoveredCellCallback",Ne,e.onHoveredCellChange),e.onStateChange(i),t.state={options:e,edition:E,columns:se,rows:pe,hoveredCell:Ne,focusedCell:Le,inputFormatResolver:Je,fixedSize:At,totalSize:kt,clientSize:Et,scrollOffset:Kt,highlightedCells:We,columnLookup:me,rowLookup:Be,text:f,scrollState:co,styleState:ho,sortOrderFormatResolver:je,renderState:lo,inputState:so,cursorState:uo,tooltipState:ao}}function Le(t,e){const o=new A(e);return[...e,...t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))]}function Oe(t,e){const o=new A(e);return t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))}function ze(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 Ne(t,e){return t.map((t=>({...t,columnId:"columnId"in t?t.columnId:e,rowId:"rowId"in t?t.rowId:e})))}function Ke(t,e,o){const n=l(e),r=l(o);if(n===r)return null;const i=t.findIndex((t=>t.key===n)),s=t.findIndex((t=>t.key===r));return-1===i||-1===s||i===s?null:[i,s]}function Fe(t){const e=t.element;t.scrollAnimationId&&(cancelAnimationFrame(t.scrollAnimationId),t.scrollAnimationId=null,e.scrollTop=e.scrollTop,e.scrollLeft=e.scrollLeft)}function He(t,e,o,n){return t>0?Math.min(t,e*o+n):Math.max(t,-e*o+n)}function We(t,e,o,n,r,i,l,s,u,a,c){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 c||"auto"===h?{[t]:n,behavior:"auto"}:"number"==typeof h?{[t]:o+He(d,h,e,a),behavior:"auto"}:l!==n||s===o?{[t]:n}:null}function Pe(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 Ye(t){if(!t.errorRendered)try{Be(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){c(t,"top","left"),c(t,"top","center"),c(t,"top","right"),c(t,"middle","left"),c(t,"middle","center"),c(t,"middle","right"),c(t,"bottom","left"),c(t,"bottom","center"),c(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 Fe(t);if(t.scrollAnimationId)return;let i=performance.now(),l=null,s=null,u={top:e.scrollTop,left:e.scrollLeft},a=0,c=0;const d=o=>{const n=t.state.scrollState.verticalTarget,r=t.state.scrollState.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Fe(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 We("top",e,l.scrollTop,u,l.clientHeight,l.scrollHeight,o?.top,n.top,s.verticalSpeed,r,i)}(t,h,s,u,a,f),m=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.horizontalTarget;return We("left",e,l.scrollLeft,u,l.clientWidth,l.scrollWidth,o?.left,n.left,s.horizontalSpeed,r,i)}(t,h,l,u,c,f),g={...s,...l,behavior:"smooth",...p,...m};(p||m)&&e.scrollTo(g),a=p&&"auto"===g.behavior?g.top-e.scrollTop:0,c=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){Pe(t,e)}}function $e(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")},o=document.createElement("input"),n=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;"),o.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;"),n.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; "),n.setAttribute("popover","manual"),n.classList.add("spread-grid-tooltip");const r={element:t,canvases:e,input:o,tooltip:n,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 i(t,e,o){t.addEventListener(e,(t=>{try{o(t)}catch(t){t.message=`[${e} event]: ${t.message}`,Pe(r,t)}}))}r.requestNewRender=()=>{r.renderRequested||r.errorRendered||(r.renderRequested=!0,requestAnimationFrame((()=>{r.renderRequested=!1,Ye(r)})))},r.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=>{r.localOptions.focusedCell=t,r.requestNewRender()},selectedCells:[],onSelectedCellsChange:t=>{r.localOptions.selectedCells=t,r.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:t=>{r.localOptions.editedCells=t,r.requestNewRender()},filters:[],onFiltersChange:t=>{r.localOptions.filters=t,r.requestNewRender()},sortBy:[],onSortByChange:t=>{r.localOptions.sortBy=t,r.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:t=>{r.localOptions.columnWidths=t,r.requestNewRender()},rowHeights:[],onRowHeightsChange:t=>{r.localOptions.rowHeights=t,r.requestNewRender()},columnsOrder:[],onColumnsOrderChange:t=>{r.localOptions.columnsOrder=t,r.requestNewRender()},rowsOrder:[],onRowsOrderChange:t=>{r.localOptions.rowsOrder=t,r.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{},verticalScrollTarget:null,horizontalScrollTarget:null,verticalScrollSpeed:"smooth",horizontalScrollSpeed:"smooth",disableScrollOnHover:!0,style:{}},t["spread-grid-context"]=r;const a=t=>{o.value=t,o.dispatchEvent(new Event("input"))},c=t=>{const e=r.state.options.selectedCells,o=r.state.inputFormatResolver,n=r.state.columnLookup,i=r.state.rowLookup,l=r.state.text,s=r.state.inputState.isTextValid,c=r.state.options.onEditedCellsChange,d=r.state.options.onFiltersChange,h=u(e,o,n,i);if(""===l)return;if(!s)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})}))),c(Le(r.state.options.editedCells,m)),(t=>{d(Le(Ne(r.state.options.filters,"FILTER"),t))})(p.map((t=>({...t.cell,expression:t.edit.parse({string:l})})))),t||a("")},d=t=>{const e=r.state.options.selectedCells,o=r.state.options.onEditedCellsChange,n=r.state.options.onFiltersChange,i=u(e,r.state.inputFormatResolver,r.state.columnLookup,r.state.rowLookup);var l;t&&!i.every((t=>t.edit.autoCommit))||(l=e,o(Oe(r.state.options.editedCells,l)),(t=>{n(Oe(Ne(r.state.options.filters,"FILTER"),t))})(e))};i(t,"scroll",(t=>{r.requestNewRender()})),i(t,"pointerenter",(t=>{r.mousePosition=ze(t),r.requestNewRender()})),i(t,"pointermove",(t=>{if(r.mousePosition=ze(t),r.resizingColumn){const t=r.state.columnLookup.get(l(r.resizingColumn)),e=t.width,o=t.right,n=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),i=Math.max(10,n.x-o+e),s=r.state.options.columnWidths.filter((e=>l(e.columnId)!==t.key)).concat([{columnId:t.id,width:i}]);r.state.options.onColumnWidthsChange(s)}if(r.resizingRow){const t=r.state.rowLookup.get(l(r.resizingRow)),e=t.height,o=t.bottom,n=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),i=Math.max(10,n.y-o+e),s=r.state.options.rowHeights.filter((e=>l(e.rowId)!==t.key)).concat([{rowId:t.id,height:i}]);r.state.options.onRowHeightsChange(s)}if(r.reorderedColumn){const t=r.state.columns,e=r.state.hoveredCell,o=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=Ke(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,r.reorderedColumn,e,o);n&&(r.didReorder=!0,r.isReordering=!0,r.state.options.onColumnsOrderChange(n))}if(r.reorderedRow){const t=r.state.rows,e=r.state.hoveredCell,o=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=Ke(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,r.reorderedRow,e,o);n&&(r.didReorder=!0,r.isReordering=!0,r.state.options.onRowsOrderChange(n))}r.requestNewRender()})),i(t,"touchmove",(t=>{(r.resizingColumn||r.resizingRow||r.reorderedColumn||r.reorderedRow)&&(t.preventDefault(),t.stopPropagation())})),i(t,"pointerleave",(()=>{r.mousePosition=null,r.requestNewRender()})),i(t,"pointerdown",(t=>{r.mousePosition=ze(t),Be(r),a("");const e=r.state.hoveredCell;if(r.isMouseDown=!0,r.didReorder=!1,r.mouseDownPosition=r.mousePosition,r.mouseDownCell=e,r.state.cursorState.resizableColumn&&(r.resizingColumn=r.state.cursorState.resizableColumn),r.state.cursorState.resizableRow&&(r.resizingRow=r.state.cursorState.resizableRow),!r.resizingColumn&&e){const t=r.state.rowLookup.get(l(e.rowId));r.reorderedColumn="HEADER"===t.type?e.columnId:null}if(!r.resizingRow&&e){const t=r.state.columnLookup.get(l(e.columnId));r.reorderedRow="HEADER"===t.type?e.rowId:null}r.resizingColumn||r.resizingRow||r.state.options.onFocusedCellChange(e),t.ctrlKey||r.state.options.onSelectedCellsChange([]),r.requestNewRender()})),i(t,"pointerup",(t=>{r.mousePosition=ze(t),Be(r),r.isMouseDown=!1,r.isReordering=!1,r.resizingColumn=null,r.resizingRow=null,r.reorderedColumn=null,r.reorderedRow=null,r.state.options.onSelectedCellsChange(Le(r.state.options.selectedCells,r.state.highlightedCells)),r.requestNewRender()})),i(t,"pointerdown",(t=>{r.element.setPointerCapture(t.pointerId)})),i(t,"pointerup",(t=>{r.element.releasePointerCapture(t.pointerId)})),i(t,"click",(t=>{r.mousePosition=ze(t),Be(r);const e=r.state.hoveredCell,o=r.mouseDownCell;if(r.state.cursorState.resizableColumn||r.state.cursorState.resizableRow)return;if(r.didReorder)return;if(null===e)return;if(null===o)return;if(l(e.columnId)!==l(o.columnId))return;if(l(e.rowId)!==l(o.rowId))return;const n=r.state.columnLookup.get(l(e.columnId)),i=r.state.rowLookup.get(l(e.rowId)),u=r.state.options.sortBy,a=r.state.inputFormatResolver.resolve(i,n),c={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,detail:t.detail};if(a.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]}(a,n,i,r.state.edition),o=s(n,i);"DATA"===o&&r.state.options.onEditedCellsChange(Le(r.state.options.editedCells,[{...e,value:t}])),"FILTER"===o&&r.state.options.onFiltersChange(Le(Ne(r.state.options.filters,"FILTER"),[{...e,expression:t}]))}else if("DATA"===n.type&&"DATA"===i.type)r.state.options.onCellClick({...r.state.hoveredCell,...c});else if("CUSTOM"===n.type||"CUSTOM"===i.type)r.state.options.onCustomCellClick({...r.state.hoveredCell,...c});else if("HEADER"===n.type||"HEADER"===i.type){const e=r.state.sortOrderFormatResolver.resolve(i,n),o=function(t,e,o,n,r){function i(t){const n="columnId"in t?t.columnId:"HEADER",r="rowId"in t?t.rowId:"HEADER";return e.key===l(n)&&o.key===l(r)}const s=r?r.map((t=>null===t?void 0:t)):["ASC","DESC",void 0],u=t.find(i),a=s.indexOf(u?.direction),c=s[(a+1)%s.length],d=t.indexOf(u)===t.length-1;return[...!n||!d&&u?t.filter((t=>!function(t){const n="columnId"in t?t.columnId:"HEADER",r="rowId"in t?t.rowId:"HEADER";return"HEADER"===e.type&&e.key===l(n)||"HEADER"===o.type&&o.key===l(r)}(t))):t.filter((t=>!i(t))),...c?[{columnId:e.id,rowId:o.id,direction:c}]:[]]}(u,n,i,t.ctrlKey,e.sortOrder);r.state.options.onSortByChange(o),r.state.options.onSelectedCellsChange([])}})),i(t,"dblclick",(t=>{if(r.mousePosition=ze(t),Be(r),r.state.cursorState.resizableColumn){const t=l(r.state.cursorState.resizableColumn),e=r.state.options.columnWidths.filter((e=>l(e.columnId)!==t));r.state.options.onColumnWidthsChange(e),r.columnWidthCache.delete(t)}if(r.state.cursorState.resizableRow){const t=l(r.state.cursorState.resizableRow),e=r.state.options.rowHeights.filter((e=>l(e.rowId)!==t));r.state.options.onRowHeightsChange(e),r.rowHeightCache.delete(t)}const e=r.state.focusedCell;if(null===e)return;const n=l(e.columnId),i=l(e.rowId),s=r.state.columnLookup,u=r.state.rowLookup,c=r.state.inputFormatResolver;if(!s.has(n))return;if(!u.has(i))return;const d=s.get(n),h=u.get(i),f=c.resolve(h,d),p=f.text;f.edit&&(f.edit.toggle||(a(p),o?.select()))})),i(t,"focus",(()=>{o.parentElement&&o.focus({preventScroll:!0})})),i(t,"keydown",(t=>{Be(r);const e=r.state.focusedCell,o=r.state.columnLookup,n=r.state.rowLookup,i=r.state.options.selectedCells,s=r.state.options.onSelectedCellsChange,u=r.state.options.onFocusedCellChange,h=r.state.options.editedCells,f=r.state.options.onEditedCellsChange,p=r.state.columns,m=r.state.rows,g=r.state.text,y=r.state.inputFormatResolver,w=(t,e)=>{u(t),e.shiftKey?s(Le(i,[t])):s([t])},b=(t,n)=>{if(!e)return;const r=l(e.columnId);if(!o.has(r))return;const i=o.get(r).index,s=Math.max(0,Math.min(p.length-1,i+t));if(s===i)return;const u={rowId:e.rowId,columnId:p[s].id};w(u,n)},C=(t,o)=>{if(!e)return;const r=l(e.rowId);if(!n.has(r))return;const i=n.get(r).index,s=Math.max(0,Math.min(m.length-1,i+t));if(s===i)return;const u={rowId:m[s].id,columnId:e.columnId};w(u,o)},x=()=>{t.preventDefault(),t.stopPropagation()};switch(t.key){case"Escape":""!==g?a(""):i.length>1?s([e]):h.length>0?f([]):(u(null),s([]));break;case"Enter":c(!1);break;case"ArrowUp":x(),C(t.ctrlKey?-m.length:-1,t);break;case"ArrowDown":x(),C(t.ctrlKey?m.length:1,t);break;case"ArrowLeft":x(),b(t.ctrlKey?-p.length:-1,t);break;case"ArrowRight":x(),b(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,o,n){const r=new Map(e.map((t=>[t.key,t]))),i=new Map(o.map((t=>[t.key,t]))),s=t.map((t=>({columnKey:l(t.columnId),rowKey:l(t.rowId)}))).filter((t=>r.has(t.columnKey)&&i.has(t.rowKey))),u=new Set(s.map((t=>t.columnKey))),a=new Set(s.map((t=>t.rowKey)));if(0===s.length)return"";const c=new A(t),d=Math.min(...s.map((t=>r.get(t.columnKey).index))),h=Math.max(...s.map((t=>r.get(t.columnKey).index))),f=Math.min(...s.map((t=>i.get(t.rowKey).index))),p=Math.max(...s.map((t=>i.get(t.rowKey).index))),m=[];for(let t=f;t<=p;t++){const r=o[t],i=r.key;if(a.has(i)){for(let t=d;t<=h;t++){const o=e[t],l=o.key;if(u.has(l)){if(c.isKeySelected(i,l)){const t=n.resolve(r,o).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((()=>{r.requestNewRender()})).observe(t),i(o,"input",(t=>{Be(r),o.value?(c(!0),o.style.opacity="1",o.style.pointerEvents="auto"):(t.isTrusted&&d(!0),o.style.opacity="0",o.style.pointerEvents="none")})),i(o,"click",(t=>{t.stopPropagation()})),i(o,"dblclick",(t=>{t.stopPropagation()})),i(o,"pointerdown",(t=>{t.stopPropagation()})),i(o,"keydown",(t=>{switch(t.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==o.value&&(t.stopPropagation(),r.requestNewRender());break;default:t.stopPropagation(),r.requestNewRender()}})),i(t,"wheel",(e=>{null===r.state.scrollState.verticalTarget&&null===r.state.scrollState.horizontalTarget||(t.scrollBy({top:e.deltaY,left:e.deltaX,behavior:"auto"}),e.preventDefault(),e.stopPropagation())}))}function Ve(t){const[e,o]=(0,n.useState)(null);return e&&function(t,e){$e(t);const o=t["spread-grid-context"];o.externalOptions=e,null===o.state?Ye(o):o.requestNewRender()}(e,t),n.default.createElement("div",{ref:o})}var qe=o.A;export{qe as default};
|
|
1
|
+
import*as t from"react";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},o={};e.d(o,{A:()=>_e});const n=(r={default:()=>t.default,useState:()=>t.useState},i={},e.d(i,r),i);var r,i;function l(t){return null===t?"null":Array.isArray(t)?`[${t.map(l).join(",")}]`:"object"==typeof t?(e=t,`{${Object.keys(e).sort().map((t=>`${t}:${l(e[t])}`)).join(",")}}`):JSON.stringify(t);var e}function s(t,e){const o="FILTER"===t.type,n="FILTER"===e.type;return o&&!n||!o&&n?"FILTER":"DATA"}function u(t,e,o,n){return t.map((t=>{const r=l(t.columnId),i=l(t.rowId);if(!o.has(r))return null;if(!n.has(i))return null;const u=o.get(r),a=n.get(i);return{edit:e.resolve(a,u).edit,cell:t,type:s(u,a)}})).filter((t=>t?.edit))}function a(t,e){return Math.round(t*e)/e}function c(t,e,o){const n=t.state.renderState,r=t.canvases[`${e}-${o}`],i=n.sections[e],l=n.sections[o],s=l.columns,u=i.rows,c=n.devicePixelRatio;if(0===u.length||0===s.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=i.showTopBorder,y=i.showBottomBorder,w=l.showLeftBorder,b=l.showRightBorder,C=m/2,x=u.length-1+(g?1:0)+(y?1:0),v=s.length-1+(w?1:0)+(b?1:0),A=u.map((t=>t.height)),R=s.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:l.width,T="middle"===e?h.height:i.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=u[e+K];return Array.from({length:N-z+1},((t,e)=>{const n=s[e+z];return p.resolve(o,n)}))})),V=(t,e)=>$[t-K][e-z];r.width=Math.round(D*c),r.height=Math.round(T*c),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(c,0,0,c,(t-E)*c,(e-S)*c)},_=(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],i=M[t],l=R[t],s=A[e],u=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(q(i,r),d.fillStyle=n.background||"white",d.fillRect(0,0,l,s),"draw"in o&&o.draw(d),n.highlight&&(d.fillStyle=n.highlight,d.fillRect(0,0,l,s)),n.corner&&(d.fillStyle=n.corner,d.beginPath(),d.moveTo(l-7,s),d.lineTo(l,s),d.lineTo(l,s-7),d.fill()),u&&"transparent"!==g){d.fillStyle=g,d.font=o.font;const t=f.getFontMetrics(o.font),e="center"==n.textAlign&&f.measureWidth(u,o.font)>l-p.left-p.right?"left":n.textAlign||"left";d.textAlign=e;const r=a("left"===e?p.left:"center"===e?l/2:"right"===e?l-p.right:0,c),i=a("top"===h?t.middle+t.topOffset+p.top:"middle"===h?s/2+t.middle:"bottom"===h?s+t.middle-t.bottomOffset-p.bottom:0,c);d.save(),_(0,2*m,l,s-4*m),d.fillText(u,r,i),d.restore()}}q(0,0);const G=(t,e,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/c,l=e===n,s=t-(l?i/2:0),u=e-(l?0:i/2),a=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/c))),d.lineDashOffset=l?s:u):d.setLineDash([]),d.beginPath(),d.moveTo(s,u),d.lineTo(a,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);G(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);G(M[o]-C,B[t]-C,M[o]-C,B[t+1]-C,n)}}}const d={value:({newValue:t})=>t||"",text:({newValue:t})=>t||"Search...",edit:{validate:()=>!0,parse:({string:t})=>t,autoCommit:!0}};function h(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"},...d},{column:{type:"FILTER"},row:{type:"DATA"},...d},{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 f=["column","row","condition"];function p(t){return Object.keys(t).length>Object.keys(t).filter((t=>f.includes(t))).length}function m(t,e){const o=[...f,...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(p)}function g(t){return m(t,["value","text","edit"])}function y(t,e){return e?t+"99":t+"33"}function w(t,e,o,n,r,i,s,u,a,c,d,h,f){t=m(t,["value","style","text","font","padding","edit","draw"]);const p=o?l(o.columnId):null,g=o?l(o.rowId):null,w=null!==a,b=null!==u||w,C=c+2,x=c+4,v=(t,e,o,r)=>{if(o<0||o>=t.length)return!1;if(r<0||r>=e.length)return!1;const i=t[o],l=e[r];if("DYNAMIC-BLOCK"===i.type)return!1;if("DYNAMIC-BLOCK"===l.type)return!1;const s=i.key,u=l.key;return n.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:c,color:"gray"}}},{column:{type:"HEADER"},row:{type:"ANY"},style:{background:"#F5F5F5",border:{width:c,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:y(r?"#798d9c":"#819481",p!==n.key||g!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>r.isKeySelected(t.key,e.key),style:({row:t,column:e})=>({highlight:y("#93a8b8",p!==e.key||g!==t.key)})},...A(!!o,{column:{id:o?.columnId},row:{id:o?.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})=>i.hasValueByKey(t.key,e.key),style:{corner:"darkgreen"}},...A(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:x,color:"cornflowerblue"}}}),...A(a,{column:{type:"HEADER"},row:{id:a},style:{borderBottom:{width:x,color:"cornflowerblue"}}}),...A(d&&h,{column:{id:h},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...A(d&&f,{column:{type:"ANY"},row:{id:f},style:{highlight:"#3a74e055"}})]}function b(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),a=e.slice(e.length-n,e.length),c=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:a,showTopBorder:w,showBottomBorder:b,height:S(a,w,b)},middle:{rows:c,showTopBorder:C,showBottomBorder:x,height:S(c,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 C(t,e){return[...t,...e.map((t=>({columnId:t.columnId,rowId:t.rowId,value:t.expression})))]}class x{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=l(t.rowId),o=l(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Map),this.lookup.get(e).set(o,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(l(t),l(e))}getValueById(t,e){return this.getValueByKey(l(t),l(e))}}function v(t){return new x(t)}class A{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=l(t.rowId),o=l(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Set),this.lookup.get(e).add(o)}))}isKeySelected(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}isIdSelected(t,e){return this.isKeySelected(l(t),l(e))}}function R(t){return new A(t)}function I(t,e){return"function"==typeof t?t(e):t}function k(t,e){return"function"==typeof t?t(e):t}function E(t,e){const o=t.type||"DATA",n="selector"in t?t.selector:"id"in t?t.id:void 0,r="id"in t?t.id:"selector"in t?t.selector:o;return{...t,id:r,selector:n,type:o,key:l(r),header:"header"in t?t.header:r,resizable:!("resizable"in t)||t.resizable,labels:t.labels||[],index:e}}function S(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 D(t,e){return"number"==typeof t?a(t,e):t}function T(t,e,o,n,r){const i=new Map(e.map((({columnId:t,width:e})=>[l(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const r=S(t,e),i=t.width*t.count+o*(t.count-1);return{...r,count:t.count,width:a(i,n),columnWidth:a(t.width,n)}}{const o=E(t,e),r=i.has(o.key)?i.get(o.key):"width"in t?t.width:"fit";return{...o,width:D(r,n)}}}))}function M(t,e,o,n,r){const i=new Map(e.map((({rowId:t,height:e})=>[l(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const i=S(t,e),l="height"in t?t.height:r,s=l*t.count+o*(t.count-1);return{...i,count:t.count,height:a(s,n),rowHeight:a(l,n)}}{const o=E(t,e),r=i.has(o.key)?i.get(o.key):"height"in t?t.height:"fit";return{...o,height:D(r,n)}}}))}function B(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 L(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:B(i,t.length,e.left,e.right,r.type)};return n+=s.width+o,s}))}function O(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:B(i,t.length,e.top,e.bottom,r.type)};return n+=s.height+o,s}))}const z="12px Calibri",N={top:2,right:5,bottom:2,left:5};function K(t){return"function"==typeof t?t:()=>t}const F={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class H{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class W{lookup=new H;hasRules=!1;addRule(t,e,o){if(this.hasRules=!0,Array.isArray(t)){for(const n of t)this.addRule(n,e,o);return}if(Array.isArray(e)){for(const n of e)this.addRule(t,n,o);return}const n=t?"id"in t?{key:l(t.id)}:t:{type:"DATA"},r=e?"id"in e?{key:l(e.id)}:e:{type:"DATA"};function i(t,e){t.has(e)||t.set(e,[]),t.get(e).push(o)}function s(t,e){if(t.has(e)||t.set(e,new H),"key"in r)i(t.get(e).byKey,r.key);else if("index"in r)i(t.get(e).byIndex,r.index);else if("label"in r)i(t.get(e).byLabel,r.label);else for(const o of F[r.type||"NONE"])i(t.get(e).byType,o)}if("key"in n)s(this.lookup.byKey,n.key);else if("index"in n)s(this.lookup.byIndex,n.index);else if("label"in n)s(this.lookup.byLabel,n.label);else for(const t of F[n.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 P=["borderTop","borderRight","borderBottom","borderLeft"],Y={validate:()=>!0,parse:({string:t})=>t};function $(t,e){const o={...t};if("border"in o){for(const t of P)o[t]=o.border;delete o.border}for(const t of P)t in o&&(o[t]={...o[t],index:e});return o}function V(t,e){if(!1!==t.edit)return!0===t.edit?"edit"in e?e.edit:Y:"edit"in e?{...e.edit,...t.edit}:{...Y,...t.edit}}class q{constructor(t){this.rulesLookup=new W;for(const[e,o]of t.entries()){const t={index:e};"condition"in o&&(t.condition=o.condition),"style"in o&&(t.style=K(o.style)),"value"in o&&(t.value=K(o.value)),"text"in o&&(t.text=K(o.text)),"font"in o&&(t.font=K(o.font)),"padding"in o&&(t.padding=K(o.padding)),"edit"in o&&(t.edit=o.edit),"tooltip"in o&&(t.tooltip=K(o.tooltip)),"draw"in o&&(t.draw=o.draw),"sortOrder"in o&&(t.sortOrder=K(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,a={data:t,rows:e,columns:o,row:n,column:r},c={},d=N,h=z;i.hasValueByKey(n.key,r.key)&&(a={...a,newValue:i.getValueByKey(n.key,r.key)});for(const t of l)if((!("condition"in t)||t.condition(a))&&("value"in t&&(a={...a,value:t.value(a)}),"style"in t&&(c={...c,...$(t.style(a),t.index)}),"text"in t&&(a={...a,text:t.text(a)}),"font"in t&&(h=t.font(a)),"padding"in t&&(d={...d,...t.padding(a)}),"edit"in t&&(a={...a,edit:V(t,a)}),"tooltip"in t&&(u=t.tooltip(a)),"sortOrder"in t&&(a={...a,sortOrder:t.sortOrder(a)}),"draw"in t)){const e=a;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}`:""}(a),p={render:!0,style:c,text:f,padding:d,font:h};return"value"in a&&(p.value=a.value),"edit"in a&&void 0!==a.edit&&(p.edit=a.edit),void 0!==u&&(p.tooltip=u),"sortOrder"in a&&(p.sortOrder=a.sortOrder),void 0!==s&&(p.draw=s),p}}function _(t){return new q(t)}class G{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 j(t,e,o,n,r){return new G(t,e,o,n,r)}function U(t,e,o){const n=new Map;for(const r of t){const t=l(r[e]),i=l(r[o]);n.has(t)||n.set(t,new Map),n.get(t).set(i,r.expression)}return n}function X(t,e,o,n,r,i,l){if(0===t.length)return r;const s=U(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 a of u){if("DYNAMIC-BLOCK"===a.type)continue;const u=o.resolve(n,r,i,t,a,l),c=s.get(a.key);if(!e.resolve(n,r,i,t,a,u.value,u.text,c))return!1}return!0}))}function J(t,e,o,n,r,i,l){if(0===t.length)return i;const s=U(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 a of u){if("DYNAMIC-BLOCK"===a.type)continue;const u=o.resolve(n,r,i,a,t,l),c=s.get(a.key);if(!e.resolve(n,r,i,a,t,u.value,u.text,c))return!1}return!0}))}function Q(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 Z(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 tt(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]=Q(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]=Z(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]=Q(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]=Z(i,o.right-r,n);s+=l,r+=u}}return{top:r,bottom:i,left:l,right:s}}function et(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.height,o+=e;return o}function ot(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.width,o+=e;return o}function nt(t,e,o){return{width:ot(t,o),height:et(e,o)}}class rt{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||z,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||z;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 it(){return new rt}function lt(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 st(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 ut(t,e){return{top:t.top-e,left:t.left-e,width:t.width+2*e,height:t.height+2*e}}function at(t){return t.width*t.height}function ct(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 dt=200,ht=400,ft={left:0,top:0,width:0,height:0};function pt(t,e,o,n,r){const i=t||ft,l=ct({left:0,top:0,...o},n),s=ct({...e,...r},n),u=st(l,ut(s,dt)),a=st(l,ut(s,ht));return lt(l,i)&<(i,u)?at(i)>2*at(a)?a:i:a}function mt(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 gt(t){return t.reduce(((t,e)=>t.set(e.key,e)),new Map)}function yt(t,e,o,n,r,i,s,u){if(!t)return[];if(!e)return[];if(!n)return[];if(!o)return[];const a=l(o.columnId),c=l(o.rowId),d=l(n.columnId),h=l(n.rowId);if(!s.has(a))return[];if(!u.has(c))return[];if(!s.has(d))return[];if(!u.has(h))return[];const f=Math.min(s.get(a).index,s.get(d).index),p=Math.max(s.get(a).index,s.get(d).index),m=Math.min(u.get(c).index,u.get(h).index),g=Math.max(u.get(c).index,u.get(h).index);return r.slice(f,p+1).flatMap((t=>i.slice(m,g+1).map((e=>({rowId:e.id,columnId:t.id})))))}function wt(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 bt(t,e,o,n,r){return 0===t.length?null:function(t,e,o,n){if(!t)return null;const r=l(t.columnId),i=l(t.rowId);if(!e.has(r))return null;if(!o.has(i))return null;const s=e.get(r),u=o.get(i),a={width:s.width,height:u.height,section:wt(s,u)};switch(u.pinned){case"BEGIN":a.top=u.top;break;case"END":a.bottom=n.top.height+n.middle.height+n.bottom.height-u.top-u.height;break;default:a.marginTop=u.top-n.top.height}switch(s.pinned){case"BEGIN":a.left=s.left;break;case"END":a.right=n.left.width+n.center.width+n.right.width-s.left-s.width;break;default:a.marginLeft=s.left-n.left.width}return a}(e,o,n,r)}function Ct(t,e){return e.every((e=>e.edit.validate({string:t})))}function xt(t){return Array.isArray(t)?t.map(((t,e)=>e)):Object.keys(t)}function vt(t){return xt(t)}function At(t){const e=new Set;if(Array.isArray(t))for(const o of t)for(const t of xt(o))e.add(t);else for(const o in t)for(const n of xt(t[o]))e.add(n);return Array.from(e)}function Rt(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}):At(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 It(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}):vt(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 kt=({text:t,expression:e})=>t.includes(e);class Et{constructor(t){this.rulesLookup=new W;for(const e of t){const t={by:l("by"in e?e.by:"FILTER"),condition:e.condition||kt};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"')||kt({text:l,expression:s.get('"FILTER"')});let a={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={...a,expression:s.get(t.by)};if(!t.condition(e))return!1}return!0}}function St(t){return new Et(t)}function Dt(t){return m(t,["value","text"])}function Tt(t){return m(t,["value","text","font","padding"])}function Mt(t,e,o,n,r,i,l){if(t.every((t=>"number"==typeof t.width)))return t;const s=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,a=e.padding.left+e.padding.right,c=o.measureWidth(s,u)+a;l=Math.max(l,c)}return r.set(t.key,{width:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())i.has(t)||r.delete(t);return t.map((t=>({...t,width:a(s(t),l)})))}function Bt(t,e,o,n,r,i,l){if(e.every((t=>"number"==typeof t.height)))return e;const s=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,a=t.padding.top+t.padding.bottom,c=o.measureHeight(s,u)+a;l=Math.max(l,c)}return r.set(e.key,{height:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())i.has(t)||r.delete(t);return e.map((t=>({...t,height:a(s(t),l)})))}function Lt(t){const e=new Set;for(const o of t)"DYNAMIC-BLOCK"!=o.type&&e.add(o.key);return e}function Ot(t){return m(t,["value","text"])}function zt(t){return m(t,["value","sortOrder"])}function Nt(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 Kt(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 Ft{constructor(t){this.rulesLookup=new W;for(const e of t){const t=e.comparatorAsc||e.comparator,o=e.comparatorDesc||(e.comparator?(t,o)=>{return-("number"==typeof(n=e.comparator(t,o))?n:n?-1:1);var n}:null),n=t?(e,o)=>t(e,o):(t,e)=>Nt(t,e),r=o?(t,e)=>o(t,e):(t,e)=>Kt(t,e),i={by:l("by"in e?e.by:"HEADER"),comparatorAsc:n,comparatorDesc:r};this.rulesLookup.addRule(e.column,e.row,i)}}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"')?Nt:Kt: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 Ht(t){return"manual"===t?null:new Ft(t)}function Wt(t,e,o){const n=new Map;for(const r of t){const t=l(r[e]),i=l(r[o]);n.has(t)||n.set(t,new Map),n.get(t).set(i,r.direction)}return n}function Pt(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 Yt(t,e,o,n,r,i,s){if(0===t.length)return r;if(null===e)return r;const u=Wt(t,"columnId","rowId"),a=new Map(i.filter((t=>"DYNAMIC-BLOCK"!==t.type)).map((t=>[t.key,t]))),c=t.map((t=>l(t.columnId))).filter((t=>a.has(t))).map((t=>a.get(t))).reverse();if(0===c.length)return r;for(const t of c){const l=[],a=[];for(const c of r){if("DYNAMIC-BLOCK"===c.type){Pt(a,l),l.push(c);continue}const d=e.resolve(t,c,u.get(t.key));if(!d){Pt(a,l),l.push(c);continue}const h={entity:c,comparator:d,cell:o.resolve(n,r,i,c,t,s)};0!==a.length&&a[0].comparator!==d?(Pt(a,l),a.push(h)):a.push(h)}Pt(a,l),r=l}return r}function $t(t,e,o,n,r,i,s){if(0===t.length)return i;if(null===e)return i;const u=Wt(t,"rowId","columnId"),a=new Map(r.filter((t=>"DYNAMIC-BLOCK"!=t.type)).map((t=>[t.key,t]))),c=t.map((t=>l(t.rowId))).filter((t=>a.has(t))).map((t=>a.get(t))).reverse();if(0===c.length)return i;for(const t of c){const l=[],a=[];for(const c of i){if("DYNAMIC-BLOCK"===c.type){Pt(a,l),l.push(c);continue}const d=e.resolve(c,t,u.get(t.key));if(!d){Pt(a,l),l.push(c);continue}const h={entity:c,comparator:d,cell:o.resolve(n,r,i,t,c,s)};0!==a.length&&a[0].comparator!==d?(Pt(a,l),a.push(h)):a.push(h)}Pt(a,l),i=l}return i}const Vt=5;function qt(t,e,o,n,r,i){if(!n)return null;if(i)return null;const s=e.get(l(n.columnId));if("HEADER"!==o.get(l(n.rowId)).type)return null;if(!s.resizable)return null;if(!r)return null;const u=r.x;return u>=s.right-Vt&&u<=s.right+Vt?s.id:0===s.index||u<s.left-Vt||u>s.left+Vt?null:t[s.index-1].id}function _t(t,e,o,n,r,i){if(!n)return null;if(i)return null;const s=e.get(l(n.columnId)),u=o.get(l(n.rowId));if("HEADER"!==s.type)return null;if(!u.resizable)return null;if(!r)return null;const a=r.y;return a>=u.bottom-Vt&&a<=u.bottom+Vt?u.id:0===u.index||a<u.top-Vt||a>u.top+Vt?null:t[u.index-1].id}function Gt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"HEADER",rowId:"rowId"in t?t.rowId:"HEADER",direction:t.direction})))}function jt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"FILTER",rowId:"rowId"in t?t.rowId:"FILTER",expression:t.expression})))}function Ut(t){return t.filter((t=>"DATA"===t.type)).map((t=>t.id))}function Xt(t){return Ut(t)}function Jt(t){return Ut(t)}function Qt(t){return m(t,["value","text","tooltip"])}function Zt(t,e,o,n){if(!t)return null;const r=l(t.columnId),i=l(t.rowId);if(!o.has(r))return null;if(!n.has(i))return null;const s=n.get(i),u=o.get(r);return e.resolve(s,u).tooltip}function te(t,e){return t?{left:e.x+8,top:e.y+20}:null}function ee(t){return t.map((t=>l(t)))}function oe(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 ne(t,e){return oe(t,e)}function re(t,e){return oe(t,e)}function ie(t){return t.some((t=>"DYNAMIC-BLOCK"===t.type))}function le(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 se(t){return t.reduce(((t,e)=>"DYNAMIC-BLOCK"===e.type?t+e.count:t+1),0)}function ue(t,e,o,n,r,i){if(!ie(e))return e;let s=i,u=0,a=0;const c=se(e),d=n.left+r.left,h=d+n.width,f=[],p=(t,e)=>{f.push(e),s+=e.width+i,u+=t},m=t=>{p(1,t)},g=(e,o,n)=>{for(let r=o;r<=n;r++){const o=e.selector({data:t,index:r}),n=e.id({data:t,selector:o});p(1,{...e,type:"DATA",id:n,key:l(n),selector:o,header:e.header({data:t,selector:o}),width:e.columnWidth})}},y=(t,e)=>{if(e>0){const o="__separator_"+a++;p(e,{...t,type:"SEPARATOR",id:o,key:l(o),header:"",width:e*t.columnWidth+(e-1)*i})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,columnWidth:n}=t,r=n+i,l=o.left-u,a=c-o.right-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=le([[0,l-1],[Math.max(0,l,f),Math.min(e-1,a-1,p)],[a,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 ae(t,e,o,n,r,i){if(!ie(e))return e;let s=i,u=0,a=0;const c=se(e),d=n.top+r.top,h=d+n.height,f=[],p=(t,e)=>{f.push(e),s+=e.height+i,u+=t},m=t=>{p(1,t)},g=(e,o,n)=>{for(let r=o;r<=n;r++){const o=e.selector({data:t,index:r}),n=e.id({data:t,selector:o});p(1,{...e,type:"DATA",id:n,key:l(n),selector:o,header:e.header({data:t,selector:o}),height:e.rowHeight})}},y=(t,e)=>{if(e>0){const o="__separator_"+a++;p(e,{...t,type:"SEPARATOR",id:o,key:l(o),header:"",height:e*t.rowHeight+(e-1)*i})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,rowHeight:n}=t,r=n+i,l=o.top-u,a=c-o.bottom-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=le([[0,l-1],[Math.max(0,l,f),Math.min(e-1,a-1,p)],[a,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 ce(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),a=Math.min(o,s);return{left:u,top:a,right:Math.min(i,l-u),bottom:Math.min(n,s-a)}}function de(t){return{width:t.clientWidth,height:t.clientHeight}}function he(t){return{left:t.scrollLeft,top:t.scrollTop}}function fe(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 pe(t,e,o,n){if(!e)return t;if(!o)return t;if(!n)return t;const r=l(o.columnId),i=n.find((t=>"key"in t&&t.key===r));return"DATA"!==i?.type?t:n}function me(t,e,o,n){if(!e)return t;if(!o)return t;if(!n)return t;const r=l(o.rowId),i=n.find((t=>"key"in t&&t.key===r));return"DATA"!==i?.type?t:n}function ge(t,e,o,n,r,i){return!!t&&(void 0===o||o<n||o>i-r||!e)}function ye(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 we(t,e,o,n,r,i,l,s,u){if(!ge(t,e,r?.y,i.top,i.bottom,l.height))return null;let a=Math.floor(t.index)+n.top,c=-i.top,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(a,t.count);if(c+=(t.rowHeight+u)*e,a-=e,e<t.count){d=t.rowHeight;break}}else{if(0===a){d=t.height;break}c+=t.height+u,a-=1}return ye(t,c,d,s.height-i.top-i.bottom)}function be(t,e,o,n,r,i,l,s,u){if(!ge(t,e,r?.x,i.left,i.right,l.width))return null;let a=Math.floor(t.index)+n.left,c=-i.left,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(a,t.count);if(c+=(t.columnWidth+u)*e,a-=e,e<t.count){d=t.columnWidth;break}}else{if(0===a){d=t.width;break}c+=t.width+u,a-=1}return ye(t,c,d,s.width-i.left-i.right)}function Ce(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 xe(t,e,o,n,r){return{verticalTarget:t,horizontalTarget:e,verticalSpeed:o,horizontalSpeed:n,clientSizeVersion:r}}function ve(t){return{scrollbarWidth:t.scrollbarWidth||"auto"}}function Ae(t,e,o,n,r,i){return{sections:t,devicePixelRatio:e,scrollRect:o,renderFormatResolver:n,borderWidth:r,textResolver:i}}function Re(t,e){return{inputPlacement:t,isTextValid:e}}function Ie(t,e,o){return{resizableColumn:t,resizableRow:e,isReordering:o}}function ke(t,e){return{tooltip:t,tooltipPlacement:e}}function Ee(t){return t.measureHeight("X",z)+N.top+N.bottom}function Se(t,e){return!t&&!e||!(!t||!e)&&t.x===e.x&&t.y===e.y}function De(t,e){return!t&&!e||!(!t||!e)&&t.width===e.width&&t.height===e.height}function Te(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top}function Me(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height}function Be(t,e){return!t&&!e||!(!t||!e)&&l(t.rowId)===l(e.rowId)&&l(t.columnId)===l(e.columnId)}function Le(t,e){return!t&&!e||!(!t||!e)&&t.scrollbarWidth===e.scrollbarWidth}function Oe(t){const e={...t.localOptions,...t.externalOptions},o=t.memory,n=t.state,r=t.element,i=[];function l(t,e,n,r=((t,e)=>t===e)){const l=o[t]&&o[t].dependencies;if(!l||n.some(((t,e)=>t!==l[e]))){const l=o[t]&&o[t].value,s=o[t]&&o[t].version||0,u=e(...n);r(l,u)?o[t]={value:l,dependencies:n,version:s}:(o[t]={value:u,dependencies:n,version:s+1},i.push(t))}return o[t].value}function s(t,e,n){(o[t]&&o[t].value)!==e&&(o[t]={value:e},n(e))}const a=l("devicePixelRatio",(t=>t),[window.devicePixelRatio]),c=l("borderWidth",(t=>t),[e.borderWidth/a]),d=e.data,f=t.input.value,p=l("sortBy",Gt,[e.sortBy]),m=l("filters",jt,[e.filters]),y=l("textResolver",it,[]),x=l("dataFormatting",h,[e.formatting,e.dataSelector,p]),A=l("editedCellsAndFilters",C,[e.editedCells,m]),E=l("edition",v,[A]),S=l("invokedColumns",I,[e.columns,d]),D=l("invokedRows",k,[e.rows,d]),B=l("mousePosition",(t=>t),[t.mousePosition],Se),z=l("unfoldedColumns",Rt,[S,d]),N=l("unfoldedRows",It,[D,d]),K=l("dynamicRowHeight",Ee,[y]),F=l("unfilteredColumns",T,[z,e.columnWidths,c,a,150]),H=l("unfilteredRows",M,[N,e.rowHeights,c,a,K]),W=l("unfilteredColumnKeys",Lt,[F]),P=l("unfilteredRowKeys",Lt,[H]),Y=l("columnsOrder",ee,[e.columnsOrder]),$=l("rowsOrder",ee,[e.rowsOrder]),V=l("orderedColumns",ne,[F,Y]),q=l("orderedRows",re,[H,$]),G=l("filterFormatting",Dt,[x]),U=l("filterFormattingRules",_,[G]),Q=l("filteringRules",St,[e.filtering]),Z=l("filteredColumns",J,[m,Q,U,d,q,V,E]),et=l("filteredRows",X,[m,Q,U,d,q,V,E]),ot=l("sortingFormatting",Ot,[x]),rt=l("sortingFormattingRules",_,[ot]),lt=l("sortingRules",Ht,[e.sorting]),st=l("sortedColumns",$t,[p,lt,rt,d,et,Z,E]),ut=l("sortedRows",Yt,[p,lt,rt,d,et,Z,E]),at=e.freezeOnHover&&!i.includes("sortBy")&&!i.includes("filters"),ct=l("shapedColumns",pe,[st,at,n?.hoveredCell,n?.shapedColumns]),dt=l("shapedRows",me,[ut,at,n?.hoveredCell,n?.shapedRows]),ht=l("pinning",ce,[ct,dt,e.pinnedTop,e.pinnedBottom,e.pinnedLeft,e.pinnedRight]),ft=l("measureFormatting",Tt,[x]),wt=l("measureFormattingRules",_,[ft]),xt=l("measureFormatResolver",j,[wt,d,dt,ct,E]),vt=t.columnWidthCache,At=t.rowHeightCache,kt=l("measuredColumns",Mt,[ct,dt,y,xt,vt,W,a]),Et=l("measuredRows",Bt,[ct,dt,y,xt,At,P,a]),Nt=l("fixedSize",tt,[kt,Et,ht,c]),Kt=l("totalSize",nt,[kt,Et,c]),Ft=l("clientSize",(t=>t),[de(r)],De),Wt=l("boundingClientSize",(t=>t),[de(r)],De),Pt=l("scrollOffset",(t=>t),[he(r)],Te),Vt=l("internalMousePosition",fe,[B,Ft,Pt,Nt,Kt],Se),Ut=l("scrollRect",pt,[n?.renderState?.scrollRect,Pt,Kt,Nt,Wt],Me),oe=l("horizontalScrollTarget",be,[e.horizontalScrollTarget,e.disableScrollOnHover,kt,ht,Vt,Nt,Kt,Ft,c]),ie=l("verticalScrollTarget",we,[e.verticalScrollTarget,e.disableScrollOnHover,Et,ht,Vt,Nt,Kt,Ft,c]),le=l("horizontalScrollSpeed",Ce,[e.horizontalScrollSpeed]),se=l("verticalScrollSpeed",Ce,[e.verticalScrollSpeed]),ge=l("staticColumns",ue,[d,kt,ht,Ut,Nt,c]),ye=l("staticRows",ae,[d,Et,ht,Ut,Nt,c]),Oe=l("columns",L,[ge,ht,c]),ze=l("rows",O,[ye,ht,c]),Ne=l("columnLookup",gt,[Oe]),Ke=l("rowLookup",gt,[ze]),Fe=e.focusedCell,He=l("sections",b,[Oe,ze]),We=e.selectedCells,Pe=l("hoveredCell",mt,[Vt,ze,Oe,Nt,Kt],Be),Ye=t.isReordering,$e=t.resizingColumn||l("resizableColumn",qt,[Oe,Ne,Ke,Pe,Vt,Ye]),Ve=t.resizingRow||l("resizableRow",_t,[ze,Ne,Ke,Pe,Vt,Ye]),qe=l("highlightedCells",yt,[t.isMouseDown,!$e&&!Ve&&!t.didReorder,Fe,Pe,Oe,ze,Ne,Ke]),_e=l("selection",R,[We]),Ge=l("highlight",R,[qe]),je=l("renderFormatting",w,[x,Pe,Fe,_e,Ge,E,p,$e,Ve,e.borderWidth,Ye,t.reorderedColumn,t.reorderedRow]),Ue=l("renderFormattingRules",_,[je]),Xe=l("renderFormatResolver",j,[Ue,d,ze,Oe,E]),Je=l("sortOrderFormatting",zt,[x]),Qe=l("sortOrderFormattingRules",_,[Je]),Ze=l("sortOrderFormatResolver",j,[Qe,d,ze,Oe,E]),to=l("inputFormatting",g,[x]),eo=l("inputFormattingRules",_,[to]),oo=l("inputFormatResolver",j,[eo,d,ze,Oe,E]),no=l("editableCells",u,[We,oo,Ne,Ke]),ro=l("inputPlacement",bt,[no,Fe,Ne,Ke,He]),io=l("isTextValid",Ct,[f,no]),lo=l("contextFormatting",Qt,[x]),so=l("contextFormattingRules",_,[lo]),uo=l("contextFormatResolver",j,[so,d,ze,Oe,E]),ao=l("tooltip",Zt,[Pe,uo,Ne,Ke]),co=l("tooltipPlacement",te,[ao,B]),ho=l("renderState",Ae,[He,a,Ut,Xe,c,y]),fo=l("inputState",Re,[ro,io]),po=l("cursorState",Ie,[$e,Ve,t.isReordering]),mo=l("tooltipState",ke,[ao,co]),go=l("scrollState",xe,[ie,oe,se,le,o.clientSize.version]),yo=l("styleState",ve,[e.style],Le),wo=l("activeColumns",Xt,[Oe]),bo=l("activeRows",Jt,[ze]);s("activeColumnsCallback",wo,e.onActiveColumnsChange),s("activeRowsCallback",bo,e.onActiveRowsChange),s("hoveredCellCallback",Pe,e.onHoveredCellChange),e.onStateChange(i),t.state={options:e,edition:E,columns:Oe,rows:ze,hoveredCell:Pe,focusedCell:Fe,inputFormatResolver:oo,fixedSize:Nt,totalSize:Kt,clientSize:Ft,scrollOffset:Pt,highlightedCells:qe,columnLookup:Ne,rowLookup:Ke,text:f,scrollState:go,styleState:yo,sortOrderFormatResolver:Ze,renderState:ho,inputState:fo,cursorState:po,tooltipState:mo,shapedColumns:ct,shapedRows:dt}}function ze(t,e){const o=new A(e);return[...e,...t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))]}function Ne(t,e){const o=new A(e);return t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))}function Ke(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 Fe(t,e){return t.map((t=>({...t,columnId:"columnId"in t?t.columnId:e,rowId:"rowId"in t?t.rowId:e})))}function He(t,e,o){const n=l(e),r=l(o);if(n===r)return null;const i=t.findIndex((t=>t.key===n)),s=t.findIndex((t=>t.key===r));return-1===i||-1===s||i===s?null:[i,s]}function We(t){const e=t.element;t.scrollAnimationId&&(cancelAnimationFrame(t.scrollAnimationId),t.scrollAnimationId=null,e.scrollTop=e.scrollTop,e.scrollLeft=e.scrollLeft)}function Pe(t,e,o,n){return t>0?Math.min(t,e*o+n):Math.max(t,-e*o+n)}function Ye(t,e,o,n,r,i,l,s,u,a,c){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 c||"auto"===h?{[t]:n,behavior:"auto"}:"number"==typeof h?{[t]:o+Pe(d,h,e,a),behavior:"auto"}:l!==n||s===o?{[t]:n}:null}function $e(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 Ve(t){if(!t.errorRendered)try{Oe(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){c(t,"top","left"),c(t,"top","center"),c(t,"top","right"),c(t,"middle","left"),c(t,"middle","center"),c(t,"middle","right"),c(t,"bottom","left"),c(t,"bottom","center"),c(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 We(t);if(t.scrollAnimationId)return;let i=performance.now(),l=null,s=null,u={top:e.scrollTop,left:e.scrollLeft},a=0,c=0;const d=o=>{const n=t.state.scrollState.verticalTarget,r=t.state.scrollState.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void We(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 Ye("top",e,l.scrollTop,u,l.clientHeight,l.scrollHeight,o?.top,n.top,s.verticalSpeed,r,i)}(t,h,s,u,a,f),m=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.horizontalTarget;return Ye("left",e,l.scrollLeft,u,l.clientWidth,l.scrollWidth,o?.left,n.left,s.horizontalSpeed,r,i)}(t,h,l,u,c,f),g={...s,...l,behavior:"smooth",...p,...m};(p||m)&&e.scrollTo(g),a=p&&"auto"===g.behavior?g.top-e.scrollTop:0,c=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){$e(t,e)}}function qe(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")},o=document.createElement("input"),n=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;"),o.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;"),n.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; "),n.setAttribute("popover","manual"),n.classList.add("spread-grid-tooltip");const r={element:t,canvases:e,input:o,tooltip:n,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 i(t,e,o){t.addEventListener(e,(t=>{try{o(t)}catch(t){t.message=`[${e} event]: ${t.message}`,$e(r,t)}}))}r.requestNewRender=()=>{r.renderRequested||r.errorRendered||(r.renderRequested=!0,requestAnimationFrame((()=>{r.renderRequested=!1,Ve(r)})))},r.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=>{r.localOptions.focusedCell=t,r.requestNewRender()},selectedCells:[],onSelectedCellsChange:t=>{r.localOptions.selectedCells=t,r.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:t=>{r.localOptions.editedCells=t,r.requestNewRender()},filters:[],onFiltersChange:t=>{r.localOptions.filters=t,r.requestNewRender()},sortBy:[],onSortByChange:t=>{r.localOptions.sortBy=t,r.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:t=>{r.localOptions.columnWidths=t,r.requestNewRender()},rowHeights:[],onRowHeightsChange:t=>{r.localOptions.rowHeights=t,r.requestNewRender()},columnsOrder:[],onColumnsOrderChange:t=>{r.localOptions.columnsOrder=t,r.requestNewRender()},rowsOrder:[],onRowsOrderChange:t=>{r.localOptions.rowsOrder=t,r.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{},verticalScrollTarget:null,horizontalScrollTarget:null,verticalScrollSpeed:"smooth",horizontalScrollSpeed:"smooth",disableScrollOnHover:!0,freezeOnHover:!1,style:{}},t["spread-grid-context"]=r;const a=t=>{o.value=t,o.dispatchEvent(new Event("input"))},c=t=>{const e=r.state.options.selectedCells,o=r.state.inputFormatResolver,n=r.state.columnLookup,i=r.state.rowLookup,l=r.state.text,s=r.state.inputState.isTextValid,c=r.state.options.onEditedCellsChange,d=r.state.options.onFiltersChange,h=u(e,o,n,i);if(""===l)return;if(!s)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})}))),c(ze(r.state.options.editedCells,m)),(t=>{d(ze(Fe(r.state.options.filters,"FILTER"),t))})(p.map((t=>({...t.cell,expression:t.edit.parse({string:l})})))),t||a("")},d=t=>{const e=r.state.options.selectedCells,o=r.state.options.onEditedCellsChange,n=r.state.options.onFiltersChange,i=u(e,r.state.inputFormatResolver,r.state.columnLookup,r.state.rowLookup);var l;t&&!i.every((t=>t.edit.autoCommit))||(l=e,o(Ne(r.state.options.editedCells,l)),(t=>{n(Ne(Fe(r.state.options.filters,"FILTER"),t))})(e))};i(t,"scroll",(t=>{r.requestNewRender()})),i(t,"pointerenter",(t=>{r.mousePosition=Ke(t),r.requestNewRender()})),i(t,"pointermove",(t=>{if(r.mousePosition=Ke(t),r.resizingColumn){const t=r.state.columnLookup.get(l(r.resizingColumn)),e=t.width,o=t.right,n=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),i=Math.max(10,n.x-o+e),s=r.state.options.columnWidths.filter((e=>l(e.columnId)!==t.key)).concat([{columnId:t.id,width:i}]);r.state.options.onColumnWidthsChange(s)}if(r.resizingRow){const t=r.state.rowLookup.get(l(r.resizingRow)),e=t.height,o=t.bottom,n=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),i=Math.max(10,n.y-o+e),s=r.state.options.rowHeights.filter((e=>l(e.rowId)!==t.key)).concat([{rowId:t.id,height:i}]);r.state.options.onRowHeightsChange(s)}if(r.reorderedColumn){const t=r.state.columns,e=r.state.hoveredCell,o=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=He(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,r.reorderedColumn,e,o);n&&(r.didReorder=!0,r.isReordering=!0,r.state.options.onColumnsOrderChange(n))}if(r.reorderedRow){const t=r.state.rows,e=r.state.hoveredCell,o=fe(r.mousePosition,r.state.clientSize,r.state.scrollOffset,r.state.fixedSize,r.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=He(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,r.reorderedRow,e,o);n&&(r.didReorder=!0,r.isReordering=!0,r.state.options.onRowsOrderChange(n))}r.requestNewRender()})),i(t,"touchmove",(t=>{(r.resizingColumn||r.resizingRow||r.reorderedColumn||r.reorderedRow)&&(t.preventDefault(),t.stopPropagation())})),i(t,"pointerleave",(()=>{r.mousePosition=null,r.requestNewRender()})),i(t,"pointerdown",(t=>{r.mousePosition=Ke(t),Oe(r),a("");const e=r.state.hoveredCell;if(r.isMouseDown=!0,r.didReorder=!1,r.mouseDownPosition=r.mousePosition,r.mouseDownCell=e,r.state.cursorState.resizableColumn&&(r.resizingColumn=r.state.cursorState.resizableColumn),r.state.cursorState.resizableRow&&(r.resizingRow=r.state.cursorState.resizableRow),!r.resizingColumn&&e){const t=r.state.rowLookup.get(l(e.rowId));r.reorderedColumn="HEADER"===t.type?e.columnId:null}if(!r.resizingRow&&e){const t=r.state.columnLookup.get(l(e.columnId));r.reorderedRow="HEADER"===t.type?e.rowId:null}r.resizingColumn||r.resizingRow||r.state.options.onFocusedCellChange(e),t.ctrlKey||r.state.options.onSelectedCellsChange([]),r.requestNewRender()})),i(t,"pointerup",(t=>{r.mousePosition=Ke(t),Oe(r),r.isMouseDown=!1,r.isReordering=!1,r.resizingColumn=null,r.resizingRow=null,r.reorderedColumn=null,r.reorderedRow=null,r.state.options.onSelectedCellsChange(ze(r.state.options.selectedCells,r.state.highlightedCells)),r.requestNewRender()})),i(t,"pointerdown",(t=>{r.element.setPointerCapture(t.pointerId)})),i(t,"pointerup",(t=>{r.element.releasePointerCapture(t.pointerId)})),i(t,"click",(t=>{r.mousePosition=Ke(t),Oe(r);const e=r.state.hoveredCell,o=r.mouseDownCell;if(r.state.cursorState.resizableColumn||r.state.cursorState.resizableRow)return;if(r.didReorder)return;if(null===e)return;if(null===o)return;if(l(e.columnId)!==l(o.columnId))return;if(l(e.rowId)!==l(o.rowId))return;const n=r.state.columnLookup.get(l(e.columnId)),i=r.state.rowLookup.get(l(e.rowId)),u=r.state.options.sortBy,a=r.state.inputFormatResolver.resolve(i,n),c={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,detail:t.detail};if(a.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]}(a,n,i,r.state.edition),o=s(n,i);"DATA"===o&&r.state.options.onEditedCellsChange(ze(r.state.options.editedCells,[{...e,value:t}])),"FILTER"===o&&r.state.options.onFiltersChange(ze(Fe(r.state.options.filters,"FILTER"),[{...e,expression:t}]))}else if("DATA"===n.type&&"DATA"===i.type)r.state.options.onCellClick({...r.state.hoveredCell,...c});else if("CUSTOM"===n.type||"CUSTOM"===i.type)r.state.options.onCustomCellClick({...r.state.hoveredCell,...c});else if("HEADER"===n.type||"HEADER"===i.type){const e=r.state.sortOrderFormatResolver.resolve(i,n),o=function(t,e,o,n,r){function i(t){const n="columnId"in t?t.columnId:"HEADER",r="rowId"in t?t.rowId:"HEADER";return e.key===l(n)&&o.key===l(r)}const s=r?r.map((t=>null===t?void 0:t)):["ASC","DESC",void 0],u=t.find(i),a=s.indexOf(u?.direction),c=s[(a+1)%s.length],d=t.indexOf(u)===t.length-1;return[...!n||!d&&u?t.filter((t=>!function(t){const n="columnId"in t?t.columnId:"HEADER",r="rowId"in t?t.rowId:"HEADER";return"HEADER"===e.type&&e.key===l(n)||"HEADER"===o.type&&o.key===l(r)}(t))):t.filter((t=>!i(t))),...c?[{columnId:e.id,rowId:o.id,direction:c}]:[]]}(u,n,i,t.ctrlKey,e.sortOrder);r.state.options.onSortByChange(o),r.state.options.onSelectedCellsChange([])}})),i(t,"dblclick",(t=>{if(r.mousePosition=Ke(t),Oe(r),r.state.cursorState.resizableColumn){const t=l(r.state.cursorState.resizableColumn),e=r.state.options.columnWidths.filter((e=>l(e.columnId)!==t));r.state.options.onColumnWidthsChange(e),r.columnWidthCache.delete(t)}if(r.state.cursorState.resizableRow){const t=l(r.state.cursorState.resizableRow),e=r.state.options.rowHeights.filter((e=>l(e.rowId)!==t));r.state.options.onRowHeightsChange(e),r.rowHeightCache.delete(t)}const e=r.state.focusedCell;if(null===e)return;const n=l(e.columnId),i=l(e.rowId),s=r.state.columnLookup,u=r.state.rowLookup,c=r.state.inputFormatResolver;if(!s.has(n))return;if(!u.has(i))return;const d=s.get(n),h=u.get(i),f=c.resolve(h,d),p=f.text;f.edit&&(f.edit.toggle||(a(p),o?.select()))})),i(t,"focus",(()=>{o.parentElement&&o.focus({preventScroll:!0})})),i(t,"keydown",(t=>{Oe(r);const e=r.state.focusedCell,o=r.state.columnLookup,n=r.state.rowLookup,i=r.state.options.selectedCells,s=r.state.options.onSelectedCellsChange,u=r.state.options.onFocusedCellChange,h=r.state.options.editedCells,f=r.state.options.onEditedCellsChange,p=r.state.columns,m=r.state.rows,g=r.state.text,y=r.state.inputFormatResolver,w=(t,e)=>{u(t),e.shiftKey?s(ze(i,[t])):s([t])},b=(t,n)=>{if(!e)return;const r=l(e.columnId);if(!o.has(r))return;const i=o.get(r).index,s=Math.max(0,Math.min(p.length-1,i+t));if(s===i)return;const u={rowId:e.rowId,columnId:p[s].id};w(u,n)},C=(t,o)=>{if(!e)return;const r=l(e.rowId);if(!n.has(r))return;const i=n.get(r).index,s=Math.max(0,Math.min(m.length-1,i+t));if(s===i)return;const u={rowId:m[s].id,columnId:e.columnId};w(u,o)},x=()=>{t.preventDefault(),t.stopPropagation()};switch(t.key){case"Escape":""!==g?a(""):i.length>1?s([e]):h.length>0?f([]):(u(null),s([]));break;case"Enter":c(!1);break;case"ArrowUp":x(),C(t.ctrlKey?-m.length:-1,t);break;case"ArrowDown":x(),C(t.ctrlKey?m.length:1,t);break;case"ArrowLeft":x(),b(t.ctrlKey?-p.length:-1,t);break;case"ArrowRight":x(),b(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,o,n){const r=new Map(e.map((t=>[t.key,t]))),i=new Map(o.map((t=>[t.key,t]))),s=t.map((t=>({columnKey:l(t.columnId),rowKey:l(t.rowId)}))).filter((t=>r.has(t.columnKey)&&i.has(t.rowKey))),u=new Set(s.map((t=>t.columnKey))),a=new Set(s.map((t=>t.rowKey)));if(0===s.length)return"";const c=new A(t),d=Math.min(...s.map((t=>r.get(t.columnKey).index))),h=Math.max(...s.map((t=>r.get(t.columnKey).index))),f=Math.min(...s.map((t=>i.get(t.rowKey).index))),p=Math.max(...s.map((t=>i.get(t.rowKey).index))),m=[];for(let t=f;t<=p;t++){const r=o[t],i=r.key;if(a.has(i)){for(let t=d;t<=h;t++){const o=e[t],l=o.key;if(u.has(l)){if(c.isKeySelected(i,l)){const t=n.resolve(r,o).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((()=>{r.requestNewRender()})).observe(t),i(o,"input",(t=>{Oe(r),o.value?(c(!0),o.style.opacity="1",o.style.pointerEvents="auto"):(t.isTrusted&&d(!0),o.style.opacity="0",o.style.pointerEvents="none")})),i(o,"click",(t=>{t.stopPropagation()})),i(o,"dblclick",(t=>{t.stopPropagation()})),i(o,"pointerdown",(t=>{t.stopPropagation()})),i(o,"keydown",(t=>{switch(t.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==o.value&&(t.stopPropagation(),r.requestNewRender());break;default:t.stopPropagation(),r.requestNewRender()}})),i(t,"wheel",(e=>{null===r.state.scrollState.verticalTarget&&null===r.state.scrollState.horizontalTarget||(t.scrollBy({top:e.deltaY,left:e.deltaX,behavior:"auto"}),e.preventDefault(),e.stopPropagation())}))}function _e(t){const[e,o]=(0,n.useState)(null);return e&&function(t,e){qe(t);const o=t["spread-grid-context"];o.externalOptions=e,null===o.state?Ve(o):o.requestNewRender()}(e,t),n.default.createElement("div",{ref:o})}var Ge=o.A;export{Ge as default};
|