js-spread-grid 0.2.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/src/core/cursor.js +20 -0
- package/src/core/error.js +30 -0
- package/src/core/input.js +42 -0
- package/src/core/render.js +25 -159
- package/src/core/scroll.js +219 -0
- package/src/core/state.js +176 -71
- package/src/core/style.js +26 -0
- package/src/core/tooltip.js +33 -0
- package/src/core-utils/rect.js +14 -12
- package/src/core-utils/rect.test.js +7 -7
- package/src/core-utils/stringifyId.js +4 -2
- package/src/index.d.ts +6 -0
- package/src/index.js +200 -158
- package/src/state-utils/getActive.js +7 -6
- package/src/state-utils/getBoundingClientSize.js +14 -0
- package/src/state-utils/getCellEditType.js +5 -3
- package/src/state-utils/getCellPlacement.js +8 -6
- package/src/state-utils/getCellSection.js +9 -7
- package/src/state-utils/getClientSize.js +12 -0
- package/src/state-utils/getClipboardData.js +6 -4
- package/src/state-utils/getColumnIndex.js +3 -1
- package/src/state-utils/getCombinedCells.js +3 -1
- package/src/state-utils/getContextFormatting.js +4 -2
- package/src/state-utils/getCursorState.js +11 -0
- package/src/state-utils/getDataFormatting.js +11 -9
- package/src/state-utils/getDynamicRowHeight.js +10 -0
- package/src/state-utils/getEditableCells.js +7 -5
- package/src/state-utils/getEditedCellsAndFilters.js +5 -3
- package/src/state-utils/getEdition.js +3 -1
- package/src/state-utils/getFilterFormatting.js +4 -2
- package/src/state-utils/getFiltered.js +39 -19
- package/src/state-utils/getFilteringRules.js +3 -1
- package/src/state-utils/getFixedSize.js +91 -6
- package/src/state-utils/getFormatResolver.js +6 -4
- package/src/state-utils/getFormattingRules.js +3 -1
- package/src/state-utils/getGenerated.js +8 -6
- package/src/state-utils/getHighlightedCells.js +9 -7
- package/src/state-utils/getHoveredCell.js +13 -14
- package/src/state-utils/getInputFormatting.js +4 -2
- package/src/state-utils/getInputPlacement.js +8 -6
- package/src/state-utils/getInputState.js +10 -0
- package/src/state-utils/getInternalPosition.js +12 -16
- package/src/state-utils/getIsTextValid.js +3 -1
- package/src/state-utils/getKeys.js +12 -3
- package/src/state-utils/getLookup.js +4 -2
- package/src/state-utils/getMeasureFormatting.js +4 -2
- package/src/state-utils/getMeasured.js +36 -20
- package/src/state-utils/getMousePosition.js +3 -1
- package/src/state-utils/getNewSortBy.js +14 -9
- package/src/state-utils/getOrder.js +4 -2
- package/src/state-utils/getOrdered.js +62 -25
- package/src/state-utils/getPinned.js +17 -3
- package/src/state-utils/getPinning.js +43 -0
- package/src/state-utils/getPlaced.js +17 -14
- package/src/state-utils/getReducedCells.js +4 -2
- package/src/state-utils/getReducedFormatting.js +11 -9
- package/src/state-utils/getRenderFormatting.js +26 -16
- package/src/state-utils/getRenderState.js +14 -0
- package/src/state-utils/getReordered.js +13 -11
- package/src/state-utils/getResizable.js +24 -26
- package/src/state-utils/getResolved.js +115 -52
- package/src/state-utils/getResolvedFilters.js +4 -2
- package/src/state-utils/getResolvedScrollSpeed.js +37 -0
- package/src/state-utils/getResolvedSortBy.js +4 -2
- package/src/state-utils/getRowIndex.js +3 -1
- package/src/state-utils/getScrollOffset.js +12 -0
- package/src/state-utils/getScrollRect.js +12 -18
- package/src/state-utils/getScrollState.js +19 -0
- package/src/state-utils/getScrollTarget.js +136 -0
- package/src/state-utils/getSections.js +6 -4
- package/src/state-utils/getSelection.js +3 -1
- package/src/state-utils/getSortOrderFormatting.js +11 -0
- package/src/state-utils/getSorted.js +44 -30
- package/src/state-utils/getSortingFormatting.js +4 -2
- package/src/state-utils/getSortingRules.js +3 -1
- package/src/state-utils/getStatic.js +251 -0
- package/src/state-utils/getStatic.test.js +455 -0
- package/src/state-utils/getStyleState.js +11 -0
- package/src/state-utils/getToggledValue.js +6 -4
- package/src/state-utils/getTooltip.js +6 -4
- package/src/state-utils/getTooltipPlacement.js +4 -2
- package/src/state-utils/getTooltipState.js +10 -0
- package/src/state-utils/getTotalSize.js +47 -6
- package/src/state-utils/getUnfolded.js +23 -21
- package/src/state-utils/getWithAssumedId.js +5 -3
- package/src/types/Edition.js +14 -12
- package/src/types/FilteringRules.js +11 -9
- package/src/types/FormatResolver.js +8 -6
- package/src/types/FormattingRules.js +28 -19
- package/src/types/FormattingRules.test.js +6 -5
- package/src/types/RulesLookup.js +12 -10
- package/src/types/Selection.js +8 -6
- package/src/types/SortingRules.js +37 -21
- package/src/types/TextResolver.js +4 -2
- package/src/typings.js +351 -35
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SpreadGrid=t():e.SpreadGrid=t()}(self,(()=>(()=>{"use strict";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:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function o(e){return null===e?"null":Array.isArray(e)?`[${e.map(o).join(",")}]`:"object"==typeof e?(t=e,`{${Object.keys(t).sort().map((e=>`${e}:${o(t[e])}`)).join(",")}}`):JSON.stringify(e);var t}function n(e,t){const o="FILTER"===e.type,n="FILTER"===t.type;return o&&!n||!o&&n?"FILTER":"DATA"}function r(e,t,r,i){return e.map((e=>{const s=o(e.columnId),l=o(e.rowId);if(!r.has(s))return null;if(!i.has(l))return null;const u=r.get(s),d=i.get(l);return{edit:t.resolve(d,u).edit,cell:e,type:n(u,d)}})).filter((e=>e?.edit))}function i(e,t){return Math.round(e*t)/t}function s(e,t,o){const n=e.state,r=e.canvases[`${t}-${o}`],s=n.sections[t],l=n.sections[o],u=l.columns,d=s.rows,c=n.devicePixelRatio;if(0===d.length||0===u.length)return void(r.parentElement&&r.parentElement.removeChild(r));r.parentElement||e.element.appendChild(r);const a=r.getContext("2d",{alpha:!1}),h=n.scrollRect,f=n.textResolver,p=n.renderFormatResolver,m=n.borderWidth,g=s.showTopBorder,y=s.showBottomBorder,w=l.showLeftBorder,x=l.showRightBorder,b=m/2,R=d.length-1+(g?1:0)+(y?1:0),C=u.length-1+(w?1:0)+(x?1:0),v=d.map((e=>e.height)),A=u.map((e=>e.width)),k=A.reduce(((e,t)=>e+t),0)+C*m,E=v.reduce(((e,t)=>e+t),0)+R*m,I="center"===o?h.left:0,T="middle"===t?h.top:0,B="center"===o?h.width:l.width,D="middle"===t?h.height:s.height,L=A.reduce(((e,t,o)=>{const n=e[o]+t+m;return e.push(n),e}),[w?m:0]),M=v.reduce(((e,t,o)=>{const n=e[o]+t+m;return e.push(n),e}),[g?m:0]),F=L.slice(0,-1),z=M.slice(0,-1),S=Math.max(F.findLastIndex((e=>e<=I)),0),N=F.findLastIndex((e=>e<=I+B)),O=Math.max(z.findLastIndex((e=>e<=T)),0),H=z.findLastIndex((e=>e<=T+D)),K=Math.max(S,w?0:1),P=N+(x?1:0),W=Math.max(O,g?0:1),$=H+(y?1:0),q=Array.from({length:H-O+1},((e,t)=>{const o=d[t+O];return Array.from({length:N-S+1},((e,t)=>{const n=u[t+S];return p.resolve(o,n)}))})),V=(e,t)=>q[e-O][t-S];r.width=Math.round(B*c),r.height=Math.round(D*c),r.style.width=`${B}px`,r.style.height=`${D}px`,r.style.marginLeft=`${I}px`,r.style.marginTop=`${T}px`,r.style.marginRight=k-B-I+"px",r.style.marginBottom=E-D-T+"px",a.fillStyle="#E9E9E9",a.fillRect(0,0,r.width,r.height);const Y=(e,t)=>{a.setTransform(c,0,0,c,(e-I)*c,(t-T)*c)},G=(e,t,o,n)=>{a.beginPath(),a.rect(e,t,o,n),a.clip()};for(let e=S;e<=N;e++)for(let t=O;t<=H;t++){const o=V(t,e),n=o.style,r=M[t],s=L[e],l=A[e],u=v[t],d=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(Y(s,r),a.fillStyle=n.background||"white",a.fillRect(0,0,l,u),"draw"in o&&o.draw(a),n.highlight&&(a.fillStyle=n.highlight,a.fillRect(0,0,l,u)),n.corner&&(a.fillStyle=n.corner,a.beginPath(),a.moveTo(l-7,u),a.lineTo(l,u),a.lineTo(l,u-7),a.fill()),d&&"transparent"!==g){a.fillStyle=g,a.font=o.font;const e=f.getFontMetrics(o.font),t="center"==n.textAlign&&f.measureWidth(d,o.font)>l-p.left-p.right?"left":n.textAlign||"left";a.textAlign=t;const r=i("left"===t?p.left:"center"===t?l/2:"right"===t?l-p.right:0,c),s=i("top"===h?e.middle+e.topOffset+p.top:"middle"===h?u/2+e.middle:"bottom"===h?u+e.middle-e.bottomOffset-p.bottom:0,c);a.save(),G(0,2*m,l,u-4*m),a.fillText(d,r,s),a.restore()}}Y(0,0);const j=(e,t,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/c,s=t===n,l=e-(s?i/2:0),u=t-(s?0:i/2),d=o+(s?i/2:0),h=n+(s?0:i/2);a.strokeStyle=r.color||"black",a.lineWidth=i,r.dash?(a.setLineDash(r.dash.map((e=>e/c))),a.lineDashOffset=s?l:u):a.setLineDash([]),a.beginPath(),a.moveTo(l,u),a.lineTo(d,h),a.stroke()},U=(e,t)=>e?t?e.index>t.index?e:t:e:t;for(let e=W;e<=$;e++){const t=e-1,o=e;for(let e=S;e<=N;e++){const n=U(t>=O?V(t,e).style.borderBottom:null,o<=H?V(o,e).style.borderTop:null);j(L[e]-b,M[o]-b,L[e+1]-b,M[o]-b,n)}}for(let e=K;e<=P;e++){const t=e-1,o=e;for(let e=O;e<=H;e++){const n=U(t>=S?V(e,t).style.borderRight:null,o<=N?V(e,o).style.borderLeft:null);j(L[o]-b,M[e]-b,L[o]-b,M[e+1]-b,n)}}}function l(e){if(!e.error)try{!function(e){s(e,"top","left"),s(e,"top","center"),s(e,"top","right"),s(e,"middle","left"),s(e,"middle","center"),s(e,"middle","right"),s(e,"bottom","left"),s(e,"bottom","center"),s(e,"bottom","right"),function(e){const t=e.element,o=e.input,n=e.state,r=n.inputPlacement;if(!r){if(o.parentElement){const e=document.activeElement===o;o.parentElement.removeChild(o),e&&t.focus({preventScroll:!0})}return}const i=e.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 e=document.activeElement===t;t.appendChild(o),e&&o.focus({preventScroll:!0})}}(e),function(e){const t=e.element,o=e.state;e.isReordering?t.style.cursor="move":o.resizableColumn&&o.resizableRow?t.style.cursor="nwse-resize":o.resizableColumn?t.style.cursor="col-resize":o.resizableRow?t.style.cursor="row-resize":t.style.cursor="default"}(e),function(e){const t=e.element,o=e.tooltip,n=e.state.tooltip,r=e.state.tooltipPlacement;r?(o.innerHTML!==n&&(o.innerHTML=n),o.style.left=`calc(anchor(left) + ${r.left}px)`,o.style.top=`calc(anchor(top) + ${r.top}px)`,o.parentElement||(t.appendChild(o),o.showPopover({source:t}))):o.parentElement&&o.parentElement.removeChild(o)}(e)}(e)}catch(t){e.error=t}e.error&&function(e){if(e.errorRendered)return;e.errorRendered=!0;const t=e.element,o=e.error;t.style.backgroundColor="#9f0000",t.style.color="white",t.style.padding="20px",t.style.display="flex",t.style.flexDirection="column",t.style.userSelect="text",t.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 ${o.message}\n </div>\n <div style="font-size: 16px; white-space: pre-wrap;">${o.stack}</div>\n `}(e)}e.d(t,{default:()=>tt});const u={value:({newValue:e})=>e||"",text:({newValue:e})=>e||"Search...",edit:{validate:()=>!0,parse:({string:e})=>e,autoCommit:!0}};function d(e,t,o){return[{column:{type:"DATA"},row:{type:"HEADER"},value:({column:e})=>void 0===e.header?e.id:e.header},{column:{type:"HEADER"},row:{type:"DATA"},value:({row:e})=>void 0===e.header?e.id:e.header},{column:{type:"HEADER"},row:{type:"SPECIAL"},value:""},{column:{type:"SPECIAL"},row:{type:"HEADER"},value:""},{column:{type:"DATA"},row:{type:"FILTER"},...u},{column:{type:"FILTER"},row:{type:"DATA"},...u},{column:{type:"DATA"},row:{type:"DATA"},value:t},...e,...o.map((({columnId:e,rowId:t,direction:n},r)=>({column:{id:e},row:{id:t},text:({value:e,text:t})=>`${o.length>1?r+1:""}${"ASC"===n?"⇣":"⇡"} ${t||e}`})))]}const c=["column","row","condition"];function a(e){return Object.keys(e).length>Object.keys(e).filter((e=>c.includes(e))).length}function h(e,t){const o=[...c,...t];return e.map((e=>function(e,t){const o={};for(const n of t)n in e&&(o[n]=e[n]);return o}(e,o))).filter(a)}function f(e){return h(e,["value","text","edit"])}function p(e,t){return t?e+"99":e+"33"}function m(e,t,n,r,i,s,l,u,d,c,a,f,m){e=h(e,["value","style","text","font","padding","edit","draw"]);const g=n?o(n.columnId):null,y=n?o(n.rowId):null,w=null!==d,x=null!==u||w,b=c+2,R=c+4,C=(e,t,o,n)=>{if(o<0||o>=e.length)return!1;if(n<0||n>=t.length)return!1;const i=e[o].key,s=t[n].key;return r.isKeySelected(i,s)},v=(e,t)=>e?[t]:[];return[{column:{type:"DATA"},row:{type:"FILTER"},style:({newValue:e})=>({background:"#FBFBFB",foreground:e?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"FILTER"},row:{type:"DATA"},style:({newValue:e})=>({background:"#FBFBFB",foreground:e?"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"}},...e,...v(t&&!w,{column:{type:"ANY"},row:{id:t?.rowId},style:{highlight:"#81948133"}}),...v(t&&!x,{column:{id:t?.columnId},row:{id:t?.rowId},style:{highlight:"#81948188"}}),{column:{type:"ANY"},row:{type:"ANY"},condition:({rows:e,columns:t,row:o,column:n})=>C(e,t,o.index,n.index),style:({rows:e,columns:t,row:o,column:n,edit:r})=>({...C(e,t,o.index-1,n.index)?{}:{borderTop:{width:b,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...C(e,t,o.index+1,n.index)?{}:{borderBottom:{width:b,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...C(e,t,o.index,n.index-1)?{}:{borderLeft:{width:b,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...C(e,t,o.index,n.index+1)?{}:{borderRight:{width:b,color:"#596959",index:Number.MAX_SAFE_INTEGER}},highlight:p(r?"#798d9c":"#819481",g!==n.key||y!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:e,column:t})=>i.isKeySelected(e.key,t.key),style:({row:e,column:t})=>({highlight:p("#93a8b8",g!==t.key||y!==e.key)})},...v(!!n,{column:{id:n?.columnId},row:{id:n?.rowId},style:{highlight:"#ffffffaa"}}),...l.map((({columnId:e,rowId:t,direction:o},n)=>({column:{id:e},row:{id:t},style:{highlight:"#0377fc44"}}))),{column:{type:"ANY"},row:{type:"ANY"},condition:({edit:e})=>!!e,style:{corner:"#77777720"}},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:e,column:t})=>s.hasValueByKey(e.key,t.key),style:{corner:"darkgreen"}},...v(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:R,color:"cornflowerblue"}}}),...v(d,{column:{type:"HEADER"},row:{id:d},style:{borderBottom:{width:R,color:"cornflowerblue"}}}),...v(a&&f,{column:{id:f},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...v(a&&m,{column:{type:"ANY"},row:{id:m},style:{highlight:"#3a74e055"}})]}function g(e,t){const o=t.filter((e=>"BEGIN"===e.pinned)).length,n=t.filter((e=>"END"===e.pinned)).length,r=t.length-o-n,i=e.filter((e=>"BEGIN"===e.pinned)).length,s=e.filter((e=>"END"===e.pinned)).length,l=e.length-i-s,u=t.slice(0,o),d=t.slice(t.length-n,t.length),c=t.slice(o,t.length-n),a=e.slice(0,i),h=e.slice(e.length-s,e.length),f=e.slice(i,e.length-s),p=o>0,m=i>0,g=!0,y=!0,w=r>0||!p,x=!0,b=!p,R=!(n>0),C=!0,v=!0,A=l>0||!m,k=!0,E=!m,I=!(s>0),T=(e,t,o)=>{if(0===e.length)return 0;const n=t?e.at(0).topWithBorder:e.at(0).top;return(o?e.at(-1).bottomWithBorder:e.at(-1).bottom)-n},B=(e,t,o)=>{if(0===e.length)return 0;const n=t?e.at(0).leftWithBorder:e.at(0).left;return(o?e.at(-1).rightWithBorder:e.at(-1).right)-n};return{top:{rows:u,showTopBorder:g,showBottomBorder:y,height:T(u,g,y)},bottom:{rows:d,showTopBorder:w,showBottomBorder:x,height:T(d,w,x)},middle:{rows:c,showTopBorder:b,showBottomBorder:R,height:T(c,b,R)},left:{columns:a,showLeftBorder:C,showRightBorder:v,width:B(a,C,v)},right:{columns:h,showLeftBorder:A,showRightBorder:k,width:B(h,A,k)},center:{columns:f,showLeftBorder:E,showRightBorder:I,width:B(f,E,I)}}}function y(e,t){return[...e,...t.map((e=>({columnId:e.columnId,rowId:e.rowId,value:e.expression})))]}class w{constructor(e){this.lookup=new Map,e.forEach((e=>{const t=o(e.rowId),n=o(e.columnId);this.lookup.has(t)||this.lookup.set(t,new Map),this.lookup.get(t).set(n,e.value)}))}hasValueByKey(e,t){return this.lookup.has(e)&&this.lookup.get(e).has(t)}getValueByKey(e,t){if(this.hasValueByKey(e,t))return this.lookup.get(e).get(t)}hasValueById(e,t){return this.hasValueByKey(o(e),o(t))}getValueById(e,t){return this.getValueByKey(o(e),o(t))}}function x(e){return new w(e)}class b{constructor(e){this.lookup=new Map,e.forEach((e=>{const t=o(e.rowId),n=o(e.columnId);this.lookup.has(t)||this.lookup.set(t,new Set),this.lookup.get(t).add(n)}))}isKeySelected(e,t){return this.lookup.has(e)&&this.lookup.get(e).has(t)}isIdSelected(e,t){return this.isKeySelected(o(e),o(t))}}function R(e){return new b(e)}function C(e,t){return"function"==typeof e?e(t):e}function v(e,t){return"function"==typeof e?e(t):e}function A(e,t,o,n){return e<o?"BEGIN":e>=t-n?"END":void 0}function k(e,t,n){return e.map(((r,i)=>{const s="id"in r?r.id:r.type,l="selector"in r?r.selector:s;return{...r,id:s,selector:l,type:r.type||"DATA",key:o(s),pinned:A(i,e.length,t,n),header:"header"in r?r.header:s,labels:r.labels||[],index:i}}))}function E(e,t,n,r){const i=new Map(r.map((({columnId:e,width:t})=>[o(e),t])));return k(e,t,n).map((e=>({...e,width:i.has(e.key)?i.get(e.key):"width"in e?e.width:"fit"})))}function I(e,t,n,r){const i=new Map(r.map((({rowId:e,height:t})=>[o(e),t])));return k(e,t,n).map((e=>({...e,height:i.has(e.key)?i.get(e.key):"height"in e?e.height:"fit"})))}function T(e,t,o){let n=o;return e.map(((e,r)=>{const s=i("width"in e?e.width:100,t),l={...e,index:r,width:s,leftWithBorder:n-o,left:n,right:n+s,rightWithBorder:n+s+o};return n+=l.width+o,l}))}function B(e,t,o){let n=o;return e.map(((e,r)=>{const s=i("height"in e?e.height:20,t),l={...e,index:r,height:s,topWithBorder:n-o,top:n,bottom:n+s,bottomWithBorder:n+s+o};return n+=l.height+o,l}))}const D="12px Calibri",L={top:2,right:5,bottom:2,left:5};function M(e){return"function"==typeof e?e:()=>e}const F={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class z{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class S{lookup=new z;hasRules=!1;addRule(e,t,n){if(this.hasRules=!0,Array.isArray(e)){for(const o of e)this.addRule(o,t,n);return}if(Array.isArray(t)){for(const o of t)this.addRule(e,o,n);return}const r=e?"id"in e?{key:o(e.id)}:e:{type:"DATA"},i=t?"id"in t?{key:o(t.id)}:t:{type:"DATA"};function s(e,t){e.has(t)||e.set(t,[]),e.get(t).push(n)}function l(e,t){if(e.has(t)||e.set(t,new z),"key"in i)s(e.get(t).byKey,i.key);else if("index"in i)s(e.get(t).byIndex,i.index);else if("label"in i)s(e.get(t).byLabel,i.label);else for(const o of F[i.type||"NONE"])s(e.get(t).byType,o)}if("key"in r)l(this.lookup.byKey,r.key);else if("index"in r)l(this.lookup.byIndex,r.index);else if("label"in r)l(this.lookup.byLabel,r.label);else for(const e of F[r.type||"NONE"])l(this.lookup.byType,e)}getRules(e,t){const o=[];if(!this.hasRules)return o;function n(e){for(const t of e)o.push(t)}function r(e){e.byKey.has(t.key)&&n(e.byKey.get(t.key)),e.byIndex.has(t.index)&&n(e.byIndex.get(t.index)),e.byType.has(t.type)&&n(e.byType.get(t.type));for(const o of t.labels)e.byLabel.has(o)&&n(e.byLabel.get(o))}this.lookup.byKey.has(e.key)&&r(this.lookup.byKey.get(e.key)),this.lookup.byIndex.has(e.index)&&r(this.lookup.byIndex.get(e.index)),this.lookup.byType.has(e.type)&&r(this.lookup.byType.get(e.type));for(const t of e.labels)this.lookup.byLabel.has(t)&&r(this.lookup.byLabel.get(t));return o}}const N=["borderTop","borderRight","borderBottom","borderLeft"],O={validate:()=>!0,parse:({string:e})=>e};function H(e,t){const o={...e};if("border"in o){for(const e of N)o[e]=o.border;delete o.border}for(const e of N)e in o&&(o[e]={...o[e],index:t});return o}function K(e,t){if(!1!==e.edit)return!0===e.edit?"edit"in t?t.edit:O:"edit"in t?{...t.edit,...e.edit}:{...O,...e.edit}}class P{constructor(e){this.rulesLookup=new S;for(const[t,o]of e.entries()){const e={index:t};"condition"in o&&(e.condition=o.condition),"style"in o&&(e.style=M(o.style)),"value"in o&&(e.value=M(o.value)),"text"in o&&(e.text=M(o.text)),"font"in o&&(e.font=M(o.font)),"padding"in o&&(e.padding=M(o.padding)),"edit"in o&&(e.edit=o.edit),"tooltip"in o&&(e.tooltip=M(o.tooltip)),"draw"in o&&(e.draw=o.draw),this.rulesLookup.addRule(o.column,o.row,e)}}resolve(e,t,o,n,r,i){const s=this.rulesLookup.getRules(r,n).sort(((e,t)=>e.index-t.index)).filter(((e,t,o)=>e.index!==o[t-1]?.index));let l,u,d={data:e,rows:t,columns:o,row:n,column:r},c={},a=L,h=D;i.hasValueByKey(n.key,r.key)&&(d={...d,newValue:i.getValueByKey(n.key,r.key)});for(const e of s)if((!("condition"in e)||e.condition(d))&&("value"in e&&(d={...d,value:e.value(d)}),"style"in e&&(c={...c,...H(e.style(d),e.index)}),"text"in e&&(d={...d,text:e.text(d)}),"font"in e&&(h=e.font(d)),"padding"in e&&(a={...a,...e.padding(d)}),"edit"in e&&(d={...d,edit:K(e,d)}),"tooltip"in e&&(u=e.tooltip(d)),"draw"in e)){const t=d;l=o=>e.draw({...t,ctx:o})}const f=function(e){return"text"in e?`${e.text}`:"newValue"in e?`${e.newValue}`:void 0!==e.value?`${e.value}`:""}(d),p={style:c,text:f,padding:a,font:h};return"value"in d&&(p.value=d.value),"edit"in d&&void 0!==d.edit&&(p.edit=d.edit),void 0!==u&&(p.tooltip=u),void 0!==l&&(p.draw=l),p}}function W(e){return new P(e)}class ${constructor(e,t,o,n,r){this.formattingRules=e,this.data=t,this.rows=o,this.columns=n,this.edition=r}resolve(e,t){return this.formattingRules.resolve(this.data,this.rows,this.columns,e,t,this.edition)}}function q(e,t,o,n,r){return new $(e,t,o,n,r)}function V(e,t,n){const r=new Map;for(const i of e){const e=o(i[t]),s=o(i[n]);r.has(e)||r.set(e,new Map),r.get(e).set(s,i.expression)}return r}function Y(e,t,o,n,r,i,s){if(0===e.length)return r;const l=V(e,"columnId","rowId"),u=i.filter((e=>"FILTER"!==e.type&&l.has(e.key)));return 0===u.length?r:r.filter((e=>{for(const d of u){const u=o.resolve(n,r,i,e,d,s),c=l.get(d.key);if(!t.resolve(n,r,i,e,d,u.value,u.text,c))return!1}return!0}))}function G(e,t,o,n,r,i,s){if(0===e.length)return i;const l=V(e,"rowId","columnId"),u=r.filter((e=>"FILTER"!==e.type&&l.has(e.key)));return 0===u.length?i:i.filter((e=>{for(const d of u){const u=o.resolve(n,r,i,d,e,s),c=l.get(d.key);if(!t.resolve(n,r,i,d,e,u.value,u.text,c))return!1}return!0}))}function j(e,t,o,n){return{top:e,bottom:t,left:o,right:n}}function U(e,t){return{width:e.length?e.at(-1).rightWithBorder:0,height:t.length?t.at(-1).bottomWithBorder:0}}class _{constructor(){this.fontMetrics=new Map,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d")}measureWidth(e,t){if(!e)return 0;const o=this.context;return o.font=t||D,o.measureText(e).width}measureHeight(e,t){let o=1;for(const t of e)"\n"===t&&o++;return o*this.getFontMetrics(t).height}getFontMetrics(e){const t=e;if(this.fontMetrics.has(t))return this.fontMetrics.get(t);const o=this.context;o.font=e||D;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(t,i),i}}function X(){return new _}function J(e,t){return t.top>=e.top&&t.left>=e.left&&t.top+t.height<=e.top+e.height&&t.left+t.width<=e.left+e.width}function Q(e,t){const o={top:Math.max(e.top,t.top),left:Math.max(e.left,t.left),width:Math.min(e.left+e.width,t.left+t.width)-Math.max(e.left,t.left),height:Math.min(e.top+e.height,t.top+t.height)-Math.max(e.top,t.top)};return o.width>=0&&o.height>=0?o:{top:e.top,left:e.left,width:0,height:0}}function Z(e,t){return{top:e.top-t,left:e.left-t,width:e.width+2*t,height:e.height+2*t}}function ee(e){return e.width*e.height}function te(e,t){return{top:e.top,left:e.left,width:Math.max(0,e.width-t.left-t.right),height:Math.max(0,e.height-t.top-t.bottom)}}const oe=200,ne=400,re={left:0,top:0,width:0,height:0};function ie(e,t,o,n){const r=t.x,i=t.y,s=e.scrollLeft,l=e.scrollTop,u=e.clientWidth,d=e.clientHeight;return{x:r<=o.left?r:r>=u?r+s:r>=u-o.right?n.width-u+r:r+s,y:i<=o.top?i:i>=d?i+l:i>=d-o.bottom?n.height-d+i:i+l}}function se(e){return e.reduce(((e,t)=>e.set(t.key,t)),new Map)}function le(e,t,n,r,i,s,l,u){if(!e)return[];if(!t)return[];if(!r)return[];if(!n)return[];const d=o(n.columnId),c=o(n.rowId),a=o(r.columnId),h=o(r.rowId);if(!l.has(d))return[];if(!u.has(c))return[];if(!l.has(a))return[];if(!u.has(h))return[];const f=Math.min(l.get(d).index,l.get(a).index),p=Math.max(l.get(d).index,l.get(a).index),m=Math.min(u.get(c).index,u.get(h).index),g=Math.max(u.get(c).index,u.get(h).index);return i.slice(f,p+1).flatMap((e=>s.slice(m,g+1).map((t=>({rowId:t.id,columnId:e.id})))))}function ue(e,t){const o=function(e){return"BEGIN"===e.pinned?"top":"END"===e.pinned?"bottom":"middle"}(t),n=function(e){return"BEGIN"===e.pinned?"left":"END"===e.pinned?"right":"center"}(e);return`${o}-${n}`}function de(e,t,n,r,i){return 0===e.length?null:function(e,t,n,r){if(!e)return null;const i=o(e.columnId),s=o(e.rowId);if(!t.has(i))return null;if(!n.has(s))return null;const l=t.get(i),u=n.get(s),d={width:l.width,height:u.height,section:ue(l,u)};switch(u.pinned){case"BEGIN":d.top=u.top;break;case"END":d.bottom=r.top.height+r.middle.height+r.bottom.height-u.top-u.height;break;default:d.marginTop=u.top-r.top.height}switch(l.pinned){case"BEGIN":d.left=l.left;break;case"END":d.right=r.left.width+r.center.width+r.right.width-l.left-l.width;break;default:d.marginLeft=l.left-r.left.width}return d}(t,n,r,i)}function ce(e,t){return t.every((t=>t.edit.validate({string:e})))}function ae(e){return Array.isArray(e)?e.map(((e,t)=>t)):Object.keys(e)}function he(e){return ae(e)}function fe(e){const t=new Set;if(Array.isArray(e))for(const o of e)for(const e of ae(o))t.add(e);else for(const o in e)for(const n of ae(e[o]))t.add(n);return Array.from(t)}function pe(e,t){if(!e.some((e=>"DATA-BLOCK"===e.type)))return e;const o=[];for(const n of e)if("DATA-BLOCK"===n.type){const e="selector"in n?n.selector(t):fe(t),r="id"in n?n.id:({selector:e})=>e;for(const i of e)o.push({...n,id:r({data:t,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}function me(e,t){if(!e.some((e=>"DATA-BLOCK"===e.type)))return e;const o=[];for(const n of e)if("DATA-BLOCK"===n.type){const e="selector"in n?n.selector(t):he(t),r="id"in n?n.id:({selector:e})=>e;for(const i of e)o.push({...n,id:r({data:t,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}const ge=({text:e,expression:t})=>e.includes(t);class ye{constructor(e){this.rulesLookup=new S;for(const t of e){const e={by:o("by"in t?t.by:"FILTER"),condition:t.condition||ge};this.rulesLookup.addRule(t.column,t.row,e)}}resolve(e,t,o,n,r,i,s,l){const u=this.rulesLookup.getRules(r,n);if(0===u.length)return"DATA"!==n.type||"DATA"!==r.type||!l.has('"FILTER"')||ge({text:s,expression:l.get('"FILTER"')});let d={data:e,rows:t,columns:o,row:n,column:r,value:i,text:s};for(const e of u){if(!l.has(e.by))continue;const t={...d,expression:l.get(e.by)};if(!e.condition(t))return!1}return!0}}function we(e){return new ye(e)}function xe(e){return h(e,["value","text"])}function be(e){return h(e,["value","text","font","padding"])}function Re(e,t,o,n,r,i){if(e.every((e=>"number"==typeof e.width)))return e;const s=e=>{const i=e.width;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.width;if("fit-data-once"===i&&t.dataOnly)return t.width}let s=0;for(const r of t){if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const t=n.resolve(r,e),l=t.text,u=t.font,d=t.padding.left+t.padding.right,c=o.measureWidth(l,u)+d;s=Math.max(s,c)}return r.set(e.key,{width:s,dataOnly:"fit-data-once"===i}),s};for(const e of r.keys())i.has(e)||r.delete(e);return e.map((e=>({...e,width:s(e)})))}function Ce(e,t,o,n,r,i){if(t.every((e=>"number"==typeof e.height)))return t;const s=t=>{const i=t.height;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.height;if("fit-data-once"===i&&e.dataOnly)return e.height}let s=0;for(const r of e){if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const e=n.resolve(t,r),l=e.text,u=e.font,d=e.padding.top+e.padding.bottom,c=o.measureHeight(l,u)+d;s=Math.max(s,c)}return r.set(t.key,{height:s,dataOnly:"fit-data-once"===i}),s};for(const e of r.keys())i.has(e)||r.delete(e);return t.map((e=>({...e,height:s(e)})))}function ve(e){return new Set(e.map((e=>e.key)))}function Ae(e){return h(e,["value","text"])}function ke(e,t){return e===t?0:null==e.value?-1:null==t.value?1:e.value<t.value?-1:e.value>t.value?1:0}function Ee(e,t){return-ke(e,t)}class Ie{constructor(e){this.rulesLookup=new S;for(const t of e){const e=t.comparator?(e,o)=>t.comparator(e,o):(e,t)=>ke(e,t),n=t.comparator?(e,o)=>{return-("number"==typeof(n=t.comparator(e,o))?n:n?-1:1);var n}:(e,t)=>Ee(e,t),r={by:o("by"in t?t.by:"HEADER"),comparatorAsc:e,comparatorDesc:n};this.rulesLookup.addRule(t.column,t.row,r)}}resolve(e,t,o){const n=this.rulesLookup.getRules(e,t);if(0===n.length)return"DATA"!==t.type||"DATA"!==e.type?null:o.has('"HEADER"')?"ASC"===o.get('"HEADER"')?ke:Ee: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 Te(e){return"manual"===e?null:new Ie(e)}function Be(e,t,n){const r=new Map;for(const i of e){const e=o(i[t]),s=o(i[n]);r.has(e)||r.set(e,new Map),r.get(e).set(s,i.direction)}return r}function De(e,t){e.sort(((e,t)=>{const o=e.comparator(e.cell,t.cell);return"number"==typeof o?o:o?-1:1})),t.push(...e.map((e=>e.entity))),e.length=0}function Le(e,t,n,r,i,s,l){if(0===e.length)return i;if(null===t)return i;const u=Be(e,"columnId","rowId"),d=new Map(s.map((e=>[e.key,e]))),c=e.map((e=>o(e.columnId))).filter((e=>d.has(e))).map((e=>d.get(e))).reverse();if(0===c.length)return i;for(const e of c){const o=[],d=[];for(const c of i){const a=t.resolve(e,c,u.get(e.key));if(!a){De(d,o),o.push(c);continue}const h={entity:c,comparator:a,cell:n.resolve(r,i,s,c,e,l)};0!==d.length&&d[0].comparator!==a?(De(d,o),d.push(h)):d.push(h)}De(d,o),i=o}return i}function Me(e,t,n,r,i,s,l){if(0===e.length)return s;if(null===t)return s;const u=Be(e,"rowId","columnId"),d=new Map(i.map((e=>[e.key,e]))),c=e.map((e=>o(e.rowId))).filter((e=>d.has(e))).map((e=>d.get(e))).reverse();if(0===c.length)return s;for(const e of c){const o=[],d=[];for(const c of s){const a=t.resolve(c,e,u.get(e.key));if(!a){De(d,o),o.push(c);continue}const h={entity:c,comparator:a,cell:n.resolve(r,i,s,e,c,l)};0!==d.length&&d[0].comparator!==a?(De(d,o),d.push(h)):d.push(h)}De(d,o),s=o}return s}const Fe=5;function ze(e,t,n,r,i,s,l,u,d){if(!r)return null;if(l)return null;const c=t.get(o(r.columnId));if("HEADER"!==n.get(o(r.rowId)).type)return null;const a=ie(i,s,u,d);if(!a)return null;const h=a.x;return h>=c.right-Fe&&h<=c.right+Fe?c.id:0===c.index||h<c.left-Fe||h>c.left+Fe?null:e[c.index-1].id}function Se(e,t,n,r,i,s,l,u,d){if(!r)return null;if(l)return null;const c=t.get(o(r.columnId)),a=n.get(o(r.rowId));if("HEADER"!==c.type)return null;const h=ie(i,s,u,d);if(!h)return null;const f=h.y;return f>=a.bottom-Fe&&f<=a.bottom+Fe?a.id:0===a.index||f<a.top-Fe||f>a.top+Fe?null:e[a.index-1].id}function Ne(e){return e.map((e=>({columnId:"columnId"in e?e.columnId:"HEADER",rowId:"rowId"in e?e.rowId:"HEADER",direction:e.direction})))}function Oe(e){return e.map((e=>({columnId:"columnId"in e?e.columnId:"FILTER",rowId:"rowId"in e?e.rowId:"FILTER",expression:e.expression})))}function He(e){return e.filter((e=>"DATA"===e.type)).map((e=>e.id))}function Ke(e){return He(e)}function Pe(e){return He(e)}function We(e){return h(e,["value","text","tooltip"])}function $e(e,t,n,r){if(!e)return null;const i=o(e.columnId),s=o(e.rowId);if(!n.has(i))return null;if(!r.has(s))return null;const l=r.get(s),u=n.get(i);return t.resolve(l,u).tooltip}function qe(e,t){return e?{left:t.x+8,top:t.y+20}:null}function Ve(e){return e.map((e=>o(e)))}function Ye(e,t){if(!t)return e;const o=new Map;for(const t of e)o.set(t.key,t);const n=[];for(const e of t)o.has(e)&&(n.push(o.get(e)),o.delete(e));for(const t of e)o.has(t.key)&&n.push(o.get(t.key));return[...n.filter((e=>"BEGIN"===e.pinned)),...n.filter((e=>!e.pinned)),...n.filter((e=>"END"===e.pinned))]}function Ge(e){const t={...e.localOptions,...e.externalOptions},o=e.memory,n=e.state,i=e.element,s=[];function l(e,t,n){const r=o[e]&&o[e].dependencies;return r&&!n.some(((e,t)=>e!==r[t]))||(o[e]={value:t(...n),dependencies:n},s.push(e)),o[e].value}function u(e,t){const n=o[e]&&o[e].value;return JSON.stringify(n)!==JSON.stringify(t)&&(o[e]={value:t},s.push(e)),o[e].value}function c(e,t,n){(o[e]&&o[e].value)!==t&&(o[e]={value:t},n(t))}const a=window.devicePixelRatio,h=t.borderWidth/a,p=t.data,w=e.input.value,b=l("sortBy",Ne,[t.sortBy]),A=l("filters",Oe,[t.filters]),k=l("textResolver",X,[]),D=l("dataFormatting",d,[t.formatting,t.dataSelector,b]),L=l("editedCellsAndFilters",y,[t.editedCells,A]),M=l("edition",x,[L]),F=l("invokedColumns",C,[t.columns,p]),z=l("invokedRows",v,[t.rows,p]),S=l("unfoldedColumns",pe,[F,p]),N=l("unfoldedRows",me,[z,p]),O=l("unfilteredColumns",E,[S,t.pinnedLeft,t.pinnedRight,t.columnWidths]),H=l("unfilteredRows",I,[N,t.pinnedTop,t.pinnedBottom,t.rowHeights]),K=l("unfilteredColumnKeys",ve,[O]),P=l("unfilteredRowKeys",ve,[H]),$=l("columnsOrder",Ve,[t.columnsOrder]),V=l("rowsOrder",Ve,[t.rowsOrder]),_=l("orderedColumns",Ye,[O,$]),ue=l("orderedRows",Ye,[H,V]),ae=l("filterFormatting",xe,[D]),he=l("filterFormattingRules",W,[ae]),fe=l("filteringRules",we,[t.filtering]),ge=l("filteredColumns",G,[A,fe,he,p,ue,_,M]),ye=l("filteredRows",Y,[A,fe,he,p,ue,_,M]),ke=l("sortingFormatting",Ae,[D]),Ee=l("sortingFormattingRules",W,[ke]),Ie=l("sortingRules",Te,[t.sorting]),Be=l("sortedColumns",Me,[b,Ie,Ee,p,ye,ge,M]),De=l("sortedRows",Le,[b,Ie,Ee,p,ye,ge,M]),Fe=l("measureFormatting",be,[D]),He=l("measureFormattingRules",W,[Fe]),Ge=l("measureFormatResolver",q,[He,p,De,Be,M]),je=e.columnWidthCache,Ue=e.rowHeightCache,_e=l("measuredColumns",Re,[Be,De,k,Ge,je,K]),Xe=l("measuredRows",Ce,[Be,De,k,Ge,Ue,P]),Je=l("columns",T,[_e,a,h]),Qe=l("rows",B,[Xe,a,h]),Ze=l("columnLookup",se,[Je]),et=l("rowLookup",se,[Qe]),tt=t.focusedCell,ot=l("sections",g,[Je,Qe]),nt=t.selectedCells,rt=l("fixedSize",j,[ot.top.height,ot.bottom.height,ot.left.width,ot.right.width]),it=l("totalSize",U,[Je,Qe]),st=u("hoveredCell",function(e,t,o,n,r,i){if(!t)return null;if(t.x<0||t.y<0||t.x>i.width||t.y>i.height)return null;const s=ie(e,t,r,i),l=function(e,t){if(0===e.length)return-1;if(t<e[0].topWithBorder)return-1;if(t>e[e.length-1].bottomWithBorder)return-1;let o=0,n=e.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(t<e[r].topWithBorder)n=r-1;else{if(!(t>e[r].bottomWithBorder))return r;o=r+1}}return-1}(o,s.y),u=function(e,t){if(0===e.length)return-1;if(t<e[0].leftWithBorder)return-1;if(t>e[e.length-1].rightWithBorder)return-1;let o=0,n=e.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(t<e[r].leftWithBorder)n=r-1;else{if(!(t>e[r].rightWithBorder))return r;o=r+1}}return-1}(n,s.x);return-1===l||-1===u?null:{rowId:o[l].id,columnId:n[u].id}}(i,e.mousePosition,Qe,Je,rt,it)),lt=e.isReordering,ut=e.resizingColumn||l("resizableColumn",ze,[Je,Ze,et,st,i,e.mousePosition,lt,rt,it]),dt=e.resizingRow||l("resizableRow",Se,[Qe,Ze,et,st,i,e.mousePosition,lt,rt,it]),ct=l("highlightedCells",le,[e.isMouseDown,!ut&&!dt&&!e.didReorder,tt,st,Je,Qe,Ze,et]),at=l("selection",R,[nt]),ht=l("highlight",R,[ct]),ft=l("renderFormatting",m,[D,st,tt,at,ht,M,b,ut,dt,t.borderWidth,lt,e.reorderedColumn,e.reorderedRow]),pt=l("renderFormattingRules",W,[ft]),mt=l("renderFormatResolver",q,[pt,p,Qe,Je,M]),gt=l("inputFormatting",f,[D]),yt=l("inputFormattingRules",W,[gt]),wt=l("inputFormatResolver",q,[yt,p,Qe,Je,M]),xt=l("editableCells",r,[nt,wt,Ze,et]),bt=l("inputPlacement",de,[xt,tt,Ze,et,ot]),Rt=l("isTextValid",ce,[w,xt]),Ct=l("contextFormatting",We,[D]),vt=l("contextFormattingRules",W,[Ct]),At=l("contextFormatResolver",q,[vt,p,Qe,Je,M]),kt=l("tooltip",$e,[st,At,Ze,et]),Et=l("tooltipPlacement",qe,[kt,e.mousePosition]),It=u("scrollRect",function(e,t,o,n){const r={width:n.getBoundingClientRect().width,height:n.getBoundingClientRect().height},i={left:n.scrollLeft,top:n.scrollTop},s=e||re,l=te({left:0,top:0,...t},o),u=te({...i,...r},o),d=Q(l,Z(u,oe)),c=Q(l,Z(u,ne));return J(l,s)&&J(s,d)?ee(s)>2*ee(c)?c:s:c}(n?.scrollRect,it,rt,i)),Tt=l("activeColumns",Ke,[Je]),Bt=l("activeRows",Pe,[Qe]);c("activeColumnsCallback",Tt,t.onActiveColumnsChange),c("activeRowsCallback",Bt,t.onActiveRowsChange),c("hoveredCellCallback",st,t.onHoveredCellChange),t.onStateChange(s),e.state={options:t,devicePixelRatio:a,borderWidth:h,edition:M,columns:Je,rows:Qe,sections:ot,hoveredCell:st,focusedCell:tt,renderFormatResolver:mt,inputFormatResolver:wt,fixedSize:rt,totalSize:it,textResolver:k,scrollRect:It,highlightedCells:ct,inputPlacement:bt,columnLookup:Ze,rowLookup:et,text:w,isTextValid:Rt,resizableColumn:ut,resizableRow:dt,tooltip:kt,tooltipPlacement:Et}}function je(e){if(!e.error)try{Ge(e)}catch(t){e.error=t}}function Ue(e,t){const o=new b(t);return[...t,...e.filter((e=>!o.isIdSelected(e.rowId,e.columnId)))]}function _e(e,t){const o=new b(t);return e.filter((e=>!o.isIdSelected(e.rowId,e.columnId)))}function Xe(e){const t=e.currentTarget;if(!(t instanceof HTMLElement))throw new Error("Element is not an HTMLElement");const o=t.getBoundingClientRect();return{x:e.clientX-o.left,y:e.clientY-o.top}}function Je(e,t){return e.map((e=>({...e,columnId:"columnId"in e?e.columnId:t,rowId:"rowId"in e?e.rowId:t})))}function Qe(e,t,n){const r=o(t),i=o(n);if(r===i)return null;const s=e.findIndex((e=>e.key===r)),l=e.findIndex((e=>e.key===i));return-1===s||-1===l||s===l?null:[s,l]}class Ze{constructor(e,t,o,n){this.element=e,this.canvases=t,this.input=o,this.tooltip=n,this.localOptions={data:[],columns:[{type:"DATA-BLOCK"}],rows:[{type:"HEADER"},{type:"DATA-BLOCK"}],formatting:[],filtering:[],sorting:[],dataSelector:({data:e,row:t,column:o})=>e?.[t.selector]?.[o.selector],pinnedTop:0,pinnedBottom:0,pinnedLeft:0,pinnedRight:0,borderWidth:1,focusedCell:null,onFocusedCellChange:e=>{this.localOptions.focusedCell=e,this.requestNewRender()},selectedCells:[],onSelectedCellsChange:e=>{this.localOptions.selectedCells=e,this.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:e=>{this.localOptions.editedCells=e,this.requestNewRender()},filters:[],onFiltersChange:e=>{this.localOptions.filters=e,this.requestNewRender()},sortBy:[],onSortByChange:e=>{this.localOptions.sortBy=e,this.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:e=>{this.localOptions.columnWidths=e,this.requestNewRender()},rowHeights:[],onRowHeightsChange:e=>{this.localOptions.rowHeights=e,this.requestNewRender()},columnsOrder:[],onColumnsOrderChange:e=>{this.localOptions.columnsOrder=e,this.requestNewRender()},rowsOrder:[],onRowsOrderChange:e=>{this.localOptions.rowsOrder=e,this.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{}}}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(){this.renderRequested||(this.renderRequested=!0,requestAnimationFrame((()=>{this.renderRequested=!1,je(this),l(this)})))}}function et(e){if("spread-grid-context"in e)return;const t={"top-left":document.createElement("canvas"),"top-center":document.createElement("canvas"),"top-right":document.createElement("canvas"),"middle-left":document.createElement("canvas"),"middle-center":document.createElement("canvas"),"middle-right":document.createElement("canvas"),"bottom-left":document.createElement("canvas"),"bottom-center":document.createElement("canvas"),"bottom-right":document.createElement("canvas")},i=document.createElement("input"),s=document.createElement("div");e.setAttribute("tabindex","0"),e.setAttribute("style","max-width: 100vw; max-height: 100vh; overflow: auto; display: grid; position: relative; grid-template-columns: fit-content(0) fit-content(0) fit-content(0); grid-template-rows: fit-content(0) fit-content(0) fit-content(0); outline: none; user-select: none; touch-action: manipulation;"),e.classList.add("spread-grid"),t["top-left"].setAttribute("style","position: sticky; left: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 1;"),t["top-center"].setAttribute("style","position: sticky; top: 0; z-index: 1; grid-row: 1; grid-column: 2;"),t["top-right"].setAttribute("style","position: sticky; right: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 3;"),t["middle-left"].setAttribute("style","position: sticky; left: 0; z-index: 1; grid-row: 2; grid-column: 1;"),t["middle-center"].setAttribute("style","grid-row: 2; grid-column: 2; z-index: 0;"),t["middle-right"].setAttribute("style","position: sticky; right: 0; z-index: 1; grid-row: 2; grid-column: 3;"),t["bottom-left"].setAttribute("style","position: sticky; left: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 1;"),t["bottom-center"].setAttribute("style","position: sticky; bottom: 0; z-index: 1; grid-row: 3; grid-column: 2;"),t["bottom-right"].setAttribute("style","position: sticky; right: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 3;"),i.setAttribute("style","position: sticky; z-index: 3; outline: none; border: none; box-shadow: none; padding: 0 5px; font-size: 12px; font-family: Calibri; background-color: white; box-sizing: border-box; opacity: 0; pointer-events: none;"),s.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; "),s.setAttribute("popover","manual"),s.classList.add("spread-grid-tooltip");const l=new Ze(e,t,i,s);function u(e,t,o){e.addEventListener(t,(e=>{try{o(e)}catch(e){e.message=`[${t} event]: ${e.message}`,l.error=e,l.requestNewRender()}}))}e["spread-grid-context"]=l;const d=e=>{i.value=e,i.dispatchEvent(new Event("input"))},c=e=>{const t=l.state.options.selectedCells,o=l.state.inputFormatResolver,n=l.state.columnLookup,i=l.state.rowLookup,s=l.state.text,u=l.state.isTextValid,c=l.state.options.onEditedCellsChange,a=l.state.options.onFiltersChange,h=r(t,o,n,i);if(""===s)return;if(!u)return;if(e&&!h.every((e=>e.edit.autoCommit)))return;const f=h.filter((e=>"DATA"===e.type)),p=h.filter((e=>"FILTER"===e.type));var m;m=f.map((e=>({...e.cell,value:e.edit.parse({string:s})}))),c(Ue(l.state.options.editedCells,m)),(e=>{a(Ue(Je(l.state.options.filters,"FILTER"),e))})(p.map((e=>({...e.cell,expression:e.edit.parse({string:s})})))),e||d("")},a=e=>{const t=l.state.options.selectedCells,o=l.state.options.onEditedCellsChange,n=l.state.options.onFiltersChange,i=r(t,l.state.inputFormatResolver,l.state.columnLookup,l.state.rowLookup);var s;e&&!i.every((e=>e.edit.autoCommit))||(s=t,o(_e(l.state.options.editedCells,s)),(e=>{n(_e(Je(l.state.options.filters,"FILTER"),e))})(t))};u(e,"scroll",(e=>{l.requestNewRender()})),u(e,"pointerenter",(e=>{l.mousePosition=Xe(e),l.requestNewRender()})),u(e,"pointermove",(t=>{if(l.mousePosition=Xe(t),l.resizingColumn){const t=l.state.columnLookup.get(o(l.resizingColumn)),n=t.width,r=t.right,i=ie(e,l.mousePosition,l.state.fixedSize,l.state.totalSize),s=Math.max(10,i.x-r+n),u=l.state.options.columnWidths.filter((e=>o(e.columnId)!==t.key)).concat([{columnId:t.id,width:s}]);l.state.options.onColumnWidthsChange(u)}if(l.resizingRow){const t=l.state.rowLookup.get(o(l.resizingRow)),n=t.height,r=t.bottom,i=ie(e,l.mousePosition,l.state.fixedSize,l.state.totalSize),s=Math.max(10,i.y-r+n),u=l.state.options.rowHeights.filter((e=>o(e.rowId)!==t.key)).concat([{rowId:t.id,height:s}]);l.state.options.onRowHeightsChange(u)}if(l.reorderedColumn){const t=l.state.columns,o=l.state.hoveredCell,n=ie(e,l.mousePosition,l.state.fixedSize,l.state.totalSize),r=function(e,t,o,n){if(!o)return null;const r=Qe(e,t,o.columnId);if(!r)return null;const[i,s]=r,l=s<=i?n.x<e[s].leftWithBorder+e[i].width?s:s+1:n.x>e[s].rightWithBorder-e[i].width?s:s-1;if(l===i)return null;const u=e.map((e=>e.id));return u.splice(i,1),u.splice(l,0,t),u}(t,l.reorderedColumn,o,n);r&&(l.didReorder=!0,l.isReordering=!0,l.state.options.onColumnsOrderChange(r))}if(l.reorderedRow){const t=l.state.rows,o=l.state.hoveredCell,n=ie(e,l.mousePosition,l.state.fixedSize,l.state.totalSize),r=function(e,t,o,n){if(!o)return null;const r=Qe(e,t,o.rowId);if(!r)return null;const[i,s]=r,l=s<=i?n.y<e[s].topWithBorder+e[i].height?s:s+1:n.y>e[s].bottomWithBorder-e[i].height?s:s-1;if(l===i)return null;const u=e.map((e=>e.id));return u.splice(i,1),u.splice(l,0,t),u}(t,l.reorderedRow,o,n);r&&(l.didReorder=!0,l.isReordering=!0,l.state.options.onRowsOrderChange(r))}l.requestNewRender()})),u(e,"touchmove",(e=>{(l.resizingColumn||l.resizingRow||l.reorderedColumn||l.reorderedRow)&&(e.preventDefault(),e.stopPropagation())})),u(e,"pointerleave",(()=>{l.mousePosition=null,l.requestNewRender()})),u(e,"pointerdown",(e=>{l.mousePosition=Xe(e),je(l),d("");const t=l.state.hoveredCell;if(l.isMouseDown=!0,l.didReorder=!1,l.mouseDownPosition=l.mousePosition,l.mouseDownCell=t,l.state.resizableColumn&&(l.resizingColumn=l.state.resizableColumn),l.state.resizableRow&&(l.resizingRow=l.state.resizableRow),!l.resizingColumn&&t){const e=l.state.rowLookup.get(o(t.rowId));l.reorderedColumn="HEADER"===e.type?t.columnId:null}if(!l.resizingRow&&t){const e=l.state.columnLookup.get(o(t.columnId));l.reorderedRow="HEADER"===e.type?t.rowId:null}l.resizingColumn||l.resizingRow||l.state.options.onFocusedCellChange(t),e.ctrlKey||l.state.options.onSelectedCellsChange([]),l.requestNewRender()})),u(e,"pointerup",(e=>{l.mousePosition=Xe(e),je(l),l.isMouseDown=!1,l.isReordering=!1,l.resizingColumn=null,l.resizingRow=null,l.reorderedColumn=null,l.reorderedRow=null,l.state.options.onSelectedCellsChange(Ue(l.state.options.selectedCells,l.state.highlightedCells)),l.requestNewRender()})),u(e,"pointerdown",(e=>{l.element.setPointerCapture(e.pointerId)})),u(e,"pointerup",(e=>{l.element.releasePointerCapture(e.pointerId)})),u(e,"click",(e=>{l.mousePosition=Xe(e),je(l);const t=l.state.hoveredCell,r=l.mouseDownCell;if(l.state.resizableColumn||l.state.resizableRow)return;if(l.didReorder)return;if(null===t)return;if(null===r)return;if(o(t.columnId)!==o(r.columnId))return;if(o(t.rowId)!==o(r.rowId))return;const i=l.state.columnLookup.get(o(t.columnId)),s=l.state.rowLookup.get(o(t.rowId)),u=l.state.options.sortBy,d=l.state.inputFormatResolver.resolve(s,i),c={ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,button:e.button,buttons:e.buttons,detail:e.detail};if(d.edit?.toggle){const e=function(e,t,o,n){const r=n.hasValueByKey(o.key,t.key)?n.getValueByKey(o.key,t.key):e.value,i=e.edit.toggle;return"function"==typeof i?i({value:r}):i[(i.indexOf(r)+1)%i.length]}(d,i,s,l.state.edition),o=n(i,s);"DATA"===o&&l.state.options.onEditedCellsChange(Ue(l.state.options.editedCells,[{...t,value:e}])),"FILTER"===o&&l.state.options.onFiltersChange(Ue(Je(l.state.options.filters,"FILTER"),[{...t,expression:e}]))}else if("DATA"===i.type&&"DATA"===s.type)l.state.options.onCellClick({...l.state.hoveredCell,...c});else if("CUSTOM"===i.type||"CUSTOM"===s.type)l.state.options.onCustomCellClick({...l.state.hoveredCell,...c});else if("HEADER"===i.type||"HEADER"===s.type){const t=function(e,t,n,r){function i(e){const r="columnId"in e?e.columnId:"HEADER",i="rowId"in e?e.rowId:"HEADER";return t.key===o(r)&&n.key===o(i)}const s=["ASC","DESC",void 0],l=e.find(i),u=s.indexOf(l?.direction),d=s[(u+1)%s.length],c=e.indexOf(l)===e.length-1;return[...!r||!c&&l?e.filter((e=>!function(e){const r="columnId"in e?e.columnId:"HEADER",i="rowId"in e?e.rowId:"HEADER";return"HEADER"===t.type&&t.key===o(r)||"HEADER"===n.type&&n.key===o(i)}(e))):e.filter((e=>!i(e))),...d?[{columnId:t.id,rowId:n.id,direction:d}]:[]]}(u,i,s,e.ctrlKey);l.state.options.onSortByChange(t),l.state.options.onSelectedCellsChange([])}})),u(e,"dblclick",(e=>{if(l.mousePosition=Xe(e),je(l),l.state.resizableColumn){const e=o(l.state.resizableColumn),t=l.state.options.columnWidths.filter((t=>o(t.columnId)!==e));l.state.options.onColumnWidthsChange(t),l.columnWidthCache.delete(e)}if(l.state.resizableRow){const e=o(l.state.resizableRow),t=l.state.options.rowHeights.filter((t=>o(t.rowId)!==e));l.state.options.onRowHeightsChange(t),l.rowHeightCache.delete(e)}const t=l.state.focusedCell;if(null===t)return;const n=o(t.columnId),r=o(t.rowId),s=l.state.columnLookup,u=l.state.rowLookup,c=l.state.inputFormatResolver;if(!s.has(n))return;if(!u.has(r))return;const a=s.get(n),h=u.get(r),f=c.resolve(h,a),p=f.text;f.edit&&(f.edit.toggle||(d(p),i?.select()))})),u(e,"focus",(()=>{i.parentElement&&i.focus({preventScroll:!0})})),u(e,"keydown",(e=>{je(l);const t=l.state.focusedCell,n=l.state.columnLookup,r=l.state.rowLookup,i=l.state.options.selectedCells,s=l.state.options.onSelectedCellsChange,u=l.state.options.onFocusedCellChange,h=l.state.options.editedCells,f=l.state.options.onEditedCellsChange,p=l.state.columns,m=l.state.rows,g=l.state.text,y=l.state.inputFormatResolver,w=(e,t)=>{u(e),t.shiftKey?s(Ue(i,[e])):s([e])},x=(e,r)=>{if(!t)return;const i=o(t.columnId);if(!n.has(i))return;const s=n.get(i).index,l=Math.max(0,Math.min(p.length-1,s+e));if(l===s)return;const u={rowId:t.rowId,columnId:p[l].id};w(u,r)},R=(e,n)=>{if(!t)return;const i=o(t.rowId);if(!r.has(i))return;const s=r.get(i).index,l=Math.max(0,Math.min(m.length-1,s+e));if(l===s)return;const u={rowId:m[l].id,columnId:t.columnId};w(u,n)},C=()=>{e.preventDefault(),e.stopPropagation()};switch(e.key){case"Escape":""!==g?d(""):i.length>1?s([t]):h.length>0?f([]):(u(null),s([]));break;case"Enter":c(!1);break;case"ArrowUp":C(),R(e.ctrlKey?-m.length:-1,e);break;case"ArrowDown":C(),R(e.ctrlKey?m.length:1,e);break;case"ArrowLeft":C(),x(e.ctrlKey?-p.length:-1,e);break;case"ArrowRight":C(),x(e.ctrlKey?p.length:1,e);break;case"Delete":case"Backspace":a(!1);break;case"c":(e=>{if(!e.ctrlKey)return;const t=function(e,t,n,r){const i=new Map(t.map((e=>[e.key,e]))),s=new Map(n.map((e=>[e.key,e]))),l=e.map((e=>({columnKey:o(e.columnId),rowKey:o(e.rowId)}))).filter((e=>i.has(e.columnKey)&&s.has(e.rowKey))),u=new Set(l.map((e=>e.columnKey))),d=new Set(l.map((e=>e.rowKey)));if(0===l.length)return"";const c=new b(e),a=Math.min(...l.map((e=>i.get(e.columnKey).index))),h=Math.max(...l.map((e=>i.get(e.columnKey).index))),f=Math.min(...l.map((e=>s.get(e.rowKey).index))),p=Math.max(...l.map((e=>s.get(e.rowKey).index))),m=[];for(let e=f;e<=p;e++){const o=n[e],i=o.key;if(d.has(i)){for(let e=a;e<=h;e++){const n=t[e],s=n.key;if(u.has(s)){if(c.isKeySelected(i,s)){const e=r.resolve(o,n).text;m.push(e)}e<h&&m.push("\t")}}e<p&&m.push("\n")}}return m.join("")}(i,p,m,y);if(navigator.clipboard)navigator.clipboard.writeText(t);else{const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}})(e)}})),new ResizeObserver((()=>{l.requestNewRender()})).observe(e),u(i,"input",(e=>{je(l),i.value?(c(!0),i.style.opacity="1",i.style.pointerEvents="auto"):(e.isTrusted&&a(!0),i.style.opacity="0",i.style.pointerEvents="none")})),u(i,"click",(e=>{e.stopPropagation()})),u(i,"dblclick",(e=>{e.stopPropagation()})),u(i,"pointerdown",(e=>{e.stopPropagation()})),u(i,"keydown",(e=>{switch(e.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==i.value&&(e.stopPropagation(),l.requestNewRender());break;default:e.stopPropagation(),l.requestNewRender()}}))}function tt(e,t){et(e);const o=e["spread-grid-context"];o.externalOptions=t,null===o.state?(je(o),l(o)):o.requestNewRender()}return t.default})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SpreadGrid=e():t.SpreadGrid=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function o(t){return null===t?"null":Array.isArray(t)?`[${t.map(o).join(",")}]`:"object"==typeof t?(e=t,`{${Object.keys(e).sort().map((t=>`${t}:${o(e[t])}`)).join(",")}}`):JSON.stringify(t);var e}function n(t,e){const o="FILTER"===t.type,n="FILTER"===e.type;return o&&!n||!o&&n?"FILTER":"DATA"}function r(t,e,r,i){return t.map((t=>{const l=o(t.columnId),s=o(t.rowId);if(!r.has(l))return null;if(!i.has(s))return null;const u=r.get(l),c=i.get(s);return{edit:e.resolve(c,u).edit,cell:t,type:n(u,c)}})).filter((t=>t?.edit))}function i(t,e){return Math.round(t*e)/e}function l(t,e,o){const n=t.state.renderState,r=t.canvases[`${e}-${o}`],l=n.sections[e],s=n.sections[o],u=s.columns,c=l.rows,a=n.devicePixelRatio;if(0===c.length||0===u.length)return void(r.parentElement&&r.parentElement.removeChild(r));r.parentElement||t.element.appendChild(r);const d=r.getContext("2d",{alpha:!1}),h=n.scrollRect,f=n.textResolver,p=n.renderFormatResolver,m=n.borderWidth,g=l.showTopBorder,y=l.showBottomBorder,w=s.showLeftBorder,b=s.showRightBorder,C=m/2,x=c.length-1+(g?1:0)+(y?1:0),v=u.length-1+(w?1:0)+(b?1:0),A=c.map((t=>t.height)),R=u.map((t=>t.width)),I=R.reduce(((t,e)=>t+e),0)+v*m,k=A.reduce(((t,e)=>t+e),0)+x*m,E="center"===o?h.left:0,S="middle"===e?h.top:0,D="center"===o?h.width:s.width,M="middle"===e?h.height:l.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=c[e+K];return Array.from({length:N-z+1},((t,e)=>{const n=u[e+z];return p.resolve(o,n)}))})),V=(t,e)=>$[t-K][e-z];r.width=Math.round(D*a),r.height=Math.round(M*a),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(a,0,0,a,(t-E)*a,(e-S)*a)},G=(t,e,o,n)=>{d.beginPath(),d.rect(t,e,o,n),d.clip()};for(let t=z;t<=N;t++)for(let e=K;e<=F;e++){const o=V(e,t);if(!o.render)continue;const n=o.style,r=B[e],l=T[t],s=R[t],u=A[e],c=o.text,h=n.textBaseline||"middle",p=o.padding,g=n.foreground||"black";if(q(l,r),d.fillStyle=n.background||"white",d.fillRect(0,0,s,u),"draw"in o&&o.draw(d),n.highlight&&(d.fillStyle=n.highlight,d.fillRect(0,0,s,u)),n.corner&&(d.fillStyle=n.corner,d.beginPath(),d.moveTo(s-7,u),d.lineTo(s,u),d.lineTo(s,u-7),d.fill()),c&&"transparent"!==g){d.fillStyle=g,d.font=o.font;const t=f.getFontMetrics(o.font),e="center"==n.textAlign&&f.measureWidth(c,o.font)>s-p.left-p.right?"left":n.textAlign||"left";d.textAlign=e;const r=i("left"===e?p.left:"center"===e?s/2:"right"===e?s-p.right:0,a),l=i("top"===h?t.middle+t.topOffset+p.top:"middle"===h?u/2+t.middle:"bottom"===h?u+t.middle-t.bottomOffset-p.bottom:0,a);d.save(),G(0,2*m,s,u-4*m),d.fillText(c,r,l),d.restore()}}q(0,0);const _=(t,e,o,n,r)=>{if(!r)return;if(0===r.width)return;const i=r.width/a,l=e===n,s=t-(l?i/2:0),u=e-(l?0:i/2),c=o+(l?i/2:0),h=n+(l?0:i/2);d.strokeStyle=r.color||"black",d.lineWidth=i,r.dash?(d.setLineDash(r.dash.map((t=>t/a))),d.lineDashOffset=l?s:u):d.setLineDash([]),d.beginPath(),d.moveTo(s,u),d.lineTo(c,h),d.stroke()},j=(t,e)=>t?e?t.index>e.index?t:e:t:e;for(let t=P;t<=Y;t++){const e=t-1,o=t;for(let t=z;t<=N;t++){const n=j(e>=K?V(e,t).style.borderBottom:null,o<=F?V(o,t).style.borderTop:null);_(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);_(T[o]-C,B[t]-C,T[o]-C,B[t+1]-C,n)}}}t.d(e,{default:()=>We});const s={value:({newValue:t})=>t||"",text:({newValue:t})=>t||"Search...",edit:{validate:()=>!0,parse:({string:t})=>t,autoCommit:!0}};function u(t,e,o){return[{column:{type:"DATA"},row:{type:"HEADER"},value:({column:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"DATA"},value:({row:t})=>void 0===t.header?t.id:t.header},{column:{type:"HEADER"},row:{type:"SPECIAL"},value:""},{column:{type:"SPECIAL"},row:{type:"HEADER"},value:""},{column:{type:"DATA"},row:{type:"FILTER"},...s},{column:{type:"FILTER"},row:{type:"DATA"},...s},{column:{type:"DATA"},row:{type:"DATA"},value:e},...t,...o.map((({columnId:t,rowId:e,direction:n},r)=>({column:{id:t},row:{id:e},text:({value:t,text:e})=>`${o.length>1?r+1:""}${"ASC"===n?"⇣":"⇡"} ${e||t}`})))]}const c=["column","row","condition"];function a(t){return Object.keys(t).length>Object.keys(t).filter((t=>c.includes(t))).length}function d(t,e){const o=[...c,...e];return t.map((t=>function(t,e){const o={};for(const n of e)n in t&&(o[n]=t[n]);return o}(t,o))).filter(a)}function h(t){return d(t,["value","text","edit"])}function f(t,e){return e?t+"99":t+"33"}function p(t,e,n,r,i,l,s,u,c,a,h,p,m){t=d(t,["value","style","text","font","padding","edit","draw"]);const g=n?o(n.columnId):null,y=n?o(n.rowId):null,w=null!==c,b=null!==u||w,C=a+2,x=a+4,v=(t,e,o,n)=>{if(o<0||o>=t.length)return!1;if(n<0||n>=e.length)return!1;const i=t[o],l=e[n];if("DYNAMIC-BLOCK"===i.type)return!1;if("DYNAMIC-BLOCK"===l.type)return!1;const s=i.key,u=l.key;return r.isKeySelected(s,u)},A=(t,e)=>t?[e]:[];return[{column:{type:"DATA"},row:{type:"FILTER"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"FILTER"},row:{type:"DATA"},style:({newValue:t})=>({background:"#FBFBFB",foreground:t?"black":"#cccccc",border:{width:1,color:"gray"}})},{column:{type:"ANY"},row:{type:"HEADER"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"ANY"},style:{background:"#F5F5F5",border:{width:a,color:"gray"}}},{column:{type:"HEADER"},row:{type:"HEADER"},style:{background:"#E0E0E0"}},...t,...A(e&&!w,{column:{type:"ANY"},row:{id:e?.rowId},style:{highlight:"#81948133"}}),...A(e&&!b,{column:{id:e?.columnId},row:{id:e?.rowId},style:{highlight:"#81948188"}}),{column:{type:"ANY"},row:{type:"ANY"},condition:({rows:t,columns:e,row:o,column:n})=>v(t,e,o.index,n.index),style:({rows:t,columns:e,row:o,column:n,edit:r})=>({...v(t,e,o.index-1,n.index)?{}:{borderTop:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index+1,n.index)?{}:{borderBottom:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index-1)?{}:{borderLeft:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},...v(t,e,o.index,n.index+1)?{}:{borderRight:{width:C,color:"#596959",index:Number.MAX_SAFE_INTEGER}},highlight:f(r?"#798d9c":"#819481",g!==n.key||y!==o.key)})},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>i.isKeySelected(t.key,e.key),style:({row:t,column:e})=>({highlight:f("#93a8b8",g!==e.key||y!==t.key)})},...A(!!n,{column:{id:n?.columnId},row:{id:n?.rowId},style:{highlight:"#ffffffaa"}}),...s.map((({columnId:t,rowId:e,direction:o},n)=>({column:{id:t},row:{id:e},style:{highlight:"#0377fc44"}}))),{column:{type:"ANY"},row:{type:"ANY"},condition:({edit:t})=>!!t,style:{corner:"#77777720"}},{column:{type:"ANY"},row:{type:"ANY"},condition:({row:t,column:e})=>l.hasValueByKey(t.key,e.key),style:{corner:"darkgreen"}},...A(u,{column:{id:u},row:{type:"HEADER"},style:{borderRight:{width:x,color:"cornflowerblue"}}}),...A(c,{column:{type:"HEADER"},row:{id:c},style:{borderBottom:{width:x,color:"cornflowerblue"}}}),...A(h&&p,{column:{id:p},row:{type:"ANY"},style:{highlight:"#3a74e055"}}),...A(h&&m,{column:{type:"ANY"},row:{id:m},style:{highlight:"#3a74e055"}})]}function m(t,e){const o=e.filter((t=>"BEGIN"===t.pinned)).length,n=e.filter((t=>"END"===t.pinned)).length,r=e.length-o-n,i=t.filter((t=>"BEGIN"===t.pinned)).length,l=t.filter((t=>"END"===t.pinned)).length,s=t.length-i-l,u=e.slice(0,o),c=e.slice(e.length-n,e.length),a=e.slice(o,e.length-n),d=t.slice(0,i),h=t.slice(t.length-l,t.length),f=t.slice(i,t.length-l),p=o>0,m=i>0,g=!0,y=!0,w=r>0||!p,b=!0,C=!p,x=!(n>0),v=!0,A=!0,R=s>0||!m,I=!0,k=!m,E=!(l>0),S=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).topWithBorder:t.at(0).top;return(o?t.at(-1).bottomWithBorder:t.at(-1).bottom)-n},D=(t,e,o)=>{if(0===t.length)return 0;const n=e?t.at(0).leftWithBorder:t.at(0).left;return(o?t.at(-1).rightWithBorder:t.at(-1).right)-n};return{top:{rows:u,showTopBorder:g,showBottomBorder:y,height:S(u,g,y)},bottom:{rows:c,showTopBorder:w,showBottomBorder:b,height:S(c,w,b)},middle:{rows:a,showTopBorder:C,showBottomBorder:x,height:S(a,C,x)},left:{columns:d,showLeftBorder:v,showRightBorder:A,width:D(d,v,A)},right:{columns:h,showLeftBorder:R,showRightBorder:I,width:D(h,R,I)},center:{columns:f,showLeftBorder:k,showRightBorder:E,width:D(f,k,E)}}}function g(t,e){return[...t,...e.map((t=>({columnId:t.columnId,rowId:t.rowId,value:t.expression})))]}class y{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Map),this.lookup.get(e).set(n,t.value)}))}hasValueByKey(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}getValueByKey(t,e){if(this.hasValueByKey(t,e))return this.lookup.get(t).get(e)}hasValueById(t,e){return this.hasValueByKey(o(t),o(e))}getValueById(t,e){return this.getValueByKey(o(t),o(e))}}function w(t){return new y(t)}class b{constructor(t){this.lookup=new Map,t.forEach((t=>{const e=o(t.rowId),n=o(t.columnId);this.lookup.has(e)||this.lookup.set(e,new Set),this.lookup.get(e).add(n)}))}isKeySelected(t,e){return this.lookup.has(t)&&this.lookup.get(t).has(e)}isIdSelected(t,e){return this.isKeySelected(o(t),o(e))}}function C(t){return new b(t)}function x(t,e){return"function"==typeof t?t(e):t}function v(t,e){return"function"==typeof t?t(e):t}function A(t,e){const n=t.type||"DATA",r="selector"in t?t.selector:"id"in t?t.id:void 0,i="id"in t?t.id:"selector"in t?t.selector:n;return{...t,id:i,selector:r,type:n,key:o(i),header:"header"in t?t.header:i,resizable:!("resizable"in t)||t.resizable,labels:t.labels||[],index:e}}function R(t,e){const o="selector"in t?t.selector:({index:t})=>t,n="id"in t?t.id:({selector:t})=>t,r="header"in t?t.header:()=>`#${e}`;return{...t,id:n,selector:o,type:"DYNAMIC-BLOCK",header:r,labels:t.labels||[],index:e,resizable:!1}}function I(t,e){return"number"==typeof t?i(t,e):t}function k(t,e,n,r,l){const s=new Map(e.map((({columnId:t,width:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),l=t.width*t.count+n*(t.count-1);return{...o,count:t.count,width:i(l,r),columnWidth:i(t.width,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"width"in t?t.width:"fit";return{...o,width:I(n,r)}}}))}function E(t,e,n,r,l){const s=new Map(e.map((({rowId:t,height:e})=>[o(t),e])));return t.map(((t,e)=>{if("DYNAMIC-BLOCK"===t.type){const o=R(t,e),s="height"in t?t.height:l,u=s*t.count+n*(t.count-1);return{...o,count:t.count,height:i(u,r),rowHeight:i(s,r)}}{const o=A(t,e),n=s.has(o.key)?s.get(o.key):"height"in t?t.height:"fit";return{...o,height:I(n,r)}}}))}function S(t,e,o,n,r){if(t<o){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"BEGIN"}if(t>=e-n){if("DYNAMIC-BLOCK"===r)throw new Error("DYNAMIC-BLOCK should have been unfolded before pinning");return"END"}}function D(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.width,s={...r,index:i,width:l,leftWithBorder:n-o,left:n,right:n+l,rightWithBorder:n+l+o,pinned:S(i,t.length,e.left,e.right,r.type)};return n+=s.width+o,s}))}function M(t,e,o){let n=o;return t.map(((r,i)=>{const l=r.height,s={...r,index:i,height:l,topWithBorder:n-o,top:n,bottom:n+l,bottomWithBorder:n+l+o,pinned:S(i,t.length,e.top,e.bottom,r.type)};return n+=s.height+o,s}))}const T="12px Calibri",B={top:2,right:5,bottom:2,left:5};function L(t){return"function"==typeof t?t:()=>t}const O={HEADER:["HEADER"],FILTER:["FILTER"],DATA:["DATA"],CUSTOM:["CUSTOM"],ANY:["HEADER","DATA","FILTER","CUSTOM"],SPECIAL:["HEADER","FILTER","CUSTOM"],NONE:[]};class z{byKey=new Map;byIndex=new Map;byLabel=new Map;byType=new Map}class N{lookup=new z;hasRules=!1;addRule(t,e,n){if(this.hasRules=!0,Array.isArray(t)){for(const o of t)this.addRule(o,e,n);return}if(Array.isArray(e)){for(const o of e)this.addRule(t,o,n);return}const r=t?"id"in t?{key:o(t.id)}:t:{type:"DATA"},i=e?"id"in e?{key:o(e.id)}:e:{type:"DATA"};function l(t,e){t.has(e)||t.set(e,[]),t.get(e).push(n)}function s(t,e){if(t.has(e)||t.set(e,new z),"key"in i)l(t.get(e).byKey,i.key);else if("index"in i)l(t.get(e).byIndex,i.index);else if("label"in i)l(t.get(e).byLabel,i.label);else for(const o of O[i.type||"NONE"])l(t.get(e).byType,o)}if("key"in r)s(this.lookup.byKey,r.key);else if("index"in r)s(this.lookup.byIndex,r.index);else if("label"in r)s(this.lookup.byLabel,r.label);else for(const t of O[r.type||"NONE"])s(this.lookup.byType,t)}getRules(t,e){const o=[];if(!this.hasRules)return o;function n(t){for(const e of t)o.push(e)}function r(t){t.byKey.has(e.key)&&n(t.byKey.get(e.key)),t.byIndex.has(e.index)&&n(t.byIndex.get(e.index)),t.byType.has(e.type)&&n(t.byType.get(e.type));for(const o of e.labels)t.byLabel.has(o)&&n(t.byLabel.get(o))}this.lookup.byKey.has(t.key)&&r(this.lookup.byKey.get(t.key)),this.lookup.byIndex.has(t.index)&&r(this.lookup.byIndex.get(t.index)),this.lookup.byType.has(t.type)&&r(this.lookup.byType.get(t.type));for(const e of t.labels)this.lookup.byLabel.has(e)&&r(this.lookup.byLabel.get(e));return o}}const K=["borderTop","borderRight","borderBottom","borderLeft"],F={validate:()=>!0,parse:({string:t})=>t};function H(t,e){const o={...t};if("border"in o){for(const t of K)o[t]=o.border;delete o.border}for(const t of K)t in o&&(o[t]={...o[t],index:e});return o}function W(t,e){if(!1!==t.edit)return!0===t.edit?"edit"in e?e.edit:F:"edit"in e?{...e.edit,...t.edit}:{...F,...t.edit}}class P{constructor(t){this.rulesLookup=new N;for(const[e,o]of t.entries()){const t={index:e};"condition"in o&&(t.condition=o.condition),"style"in o&&(t.style=L(o.style)),"value"in o&&(t.value=L(o.value)),"text"in o&&(t.text=L(o.text)),"font"in o&&(t.font=L(o.font)),"padding"in o&&(t.padding=L(o.padding)),"edit"in o&&(t.edit=o.edit),"tooltip"in o&&(t.tooltip=L(o.tooltip)),"draw"in o&&(t.draw=o.draw),"sortOrder"in o&&(t.sortOrder=L(o.sortOrder)),this.rulesLookup.addRule(o.column,o.row,t)}}resolve(t,e,o,n,r,i){const l=this.rulesLookup.getRules(r,n).sort(((t,e)=>t.index-e.index)).filter(((t,e,o)=>t.index!==o[e-1]?.index));let s,u,c={data:t,rows:e,columns:o,row:n,column:r},a={},d=B,h=T;i.hasValueByKey(n.key,r.key)&&(c={...c,newValue:i.getValueByKey(n.key,r.key)});for(const t of l)if((!("condition"in t)||t.condition(c))&&("value"in t&&(c={...c,value:t.value(c)}),"style"in t&&(a={...a,...H(t.style(c),t.index)}),"text"in t&&(c={...c,text:t.text(c)}),"font"in t&&(h=t.font(c)),"padding"in t&&(d={...d,...t.padding(c)}),"edit"in t&&(c={...c,edit:W(t,c)}),"tooltip"in t&&(u=t.tooltip(c)),"sortOrder"in t&&(c={...c,sortOrder:t.sortOrder(c)}),"draw"in t)){const e=c;s=o=>t.draw({...e,ctx:o})}const f=function(t){return"text"in t?`${t.text}`:"newValue"in t?`${t.newValue}`:void 0!==t.value?`${t.value}`:""}(c),p={render:!0,style:a,text:f,padding:d,font:h};return"value"in c&&(p.value=c.value),"edit"in c&&void 0!==c.edit&&(p.edit=c.edit),void 0!==u&&(p.tooltip=u),"sortOrder"in c&&(p.sortOrder=c.sortOrder),void 0!==s&&(p.draw=s),p}}function Y(t){return new P(t)}class ${constructor(t,e,o,n,r){this.formattingRules=t,this.data=e,this.rows=o,this.columns=n,this.edition=r}resolve(t,e){return this.formattingRules.resolve(this.data,this.rows,this.columns,t,e,this.edition)}}function V(t,e,o,n,r){return new $(t,e,o,n,r)}function q(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.expression)}return r}function G(t,e,o,n,r,i,l){if(0===t.length)return r;const s=q(t,"columnId","rowId"),u=i.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?r:r.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,t,c,l),a=s.get(c.key);if(!e.resolve(n,r,i,t,c,u.value,u.text,a))return!1}return!0}))}function _(t,e,o,n,r,i,l){if(0===t.length)return i;const s=q(t,"rowId","columnId"),u=r.filter((t=>"FILTER"!==t.type&&"DYNAMIC-BLOCK"!==t.type&&s.has(t.key)));return 0===u.length?i:i.filter((t=>{if("DYNAMIC-BLOCK"===t.type)return!0;for(const c of u){if("DYNAMIC-BLOCK"===c.type)continue;const u=o.resolve(n,r,i,c,t,l),a=s.get(c.key);if(!e.resolve(n,r,i,c,t,u.value,u.text,a))return!1}return!0}))}function j(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.height+o,1];const n=Math.min(e,t.count);return[(t.rowHeight+o)*n,n]}function U(t,e,o){if("DYNAMIC-BLOCK"!==t.type)return[t.width+o,1];const n=Math.min(e,t.count);return[(t.columnWidth+o)*n,n]}function X(t,e,o,n){let r=0,i=0,l=0,s=0;if(o.top>0){r=n;for(let t=0,i=0;i<o.top;t++){const l=e[t],[s,u]=j(l,o.top-i,n);r+=s,i+=u}}if(o.left>0){l=n;for(let e=0,r=0;r<o.left;e++){const i=t[e],[s,u]=U(i,o.left-r,n);l+=s,r+=u}}if(o.bottom>0){i=n;for(let t=e.length-1,r=0;r<o.bottom;t--){const l=e[t],[s,u]=j(l,o.bottom-r,n);i+=s,r+=u}}if(o.right>0){s=n;for(let e=t.length-1,r=0;r<o.right;e--){const i=t[e],[l,u]=U(i,o.right-r,n);s+=l,r+=u}}return{top:r,bottom:i,left:l,right:s}}function J(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.height,o+=e;return o}function Q(t,e){if(0===t.length)return 0;let o=e;for(const n of t)o+=n.width,o+=e;return o}function Z(t,e,o){return{width:Q(t,o),height:J(e,o)}}class tt{constructor(){this.fontMetrics=new Map,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d")}measureWidth(t,e){if(!t)return 0;const o=this.context;return o.font=e||T,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||T;const n=o.measureText("X"),r=(n.actualBoundingBoxDescent-n.actualBoundingBoxAscent)/2,i={topOffset:r+n.fontBoundingBoxAscent,middle:-r,bottomOffset:n.fontBoundingBoxDescent-r,height:n.fontBoundingBoxAscent+n.fontBoundingBoxDescent};return this.fontMetrics.set(e,i),i}}function et(){return new tt}function ot(t,e){return e.top>=t.top&&e.left>=t.left&&e.top+e.height<=t.top+t.height&&e.left+e.width<=t.left+t.width}function nt(t,e){const o={top:Math.max(t.top,e.top),left:Math.max(t.left,e.left),width:Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left),height:Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top)};return o.width>=0&&o.height>=0?o:{top:t.top,left:t.left,width:0,height:0}}function rt(t,e){return{top:t.top-e,left:t.left-e,width:t.width+2*e,height:t.height+2*e}}function it(t){return t.width*t.height}function lt(t,e){return{top:t.top,left:t.left,width:Math.max(0,t.width-e.left-e.right),height:Math.max(0,t.height-e.top-e.bottom)}}const st=200,ut=400,ct={left:0,top:0,width:0,height:0};function at(t,e,o,n,r){const i=t||ct,l=lt({left:0,top:0,...o},n),s=lt({...e,...r},n),u=nt(l,rt(s,st)),c=nt(l,rt(s,ut));return ot(l,i)&&ot(i,u)?it(i)>2*it(c)?c:i:c}function dt(t,e,o,n,r){if(!t)return null;if(t.x<0||t.y<0||t.x>r.width||t.y>r.height)return null;const i=function(t,e){if(0===t.length)return-1;if(e<t[0].topWithBorder)return-1;if(e>t[t.length-1].bottomWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].topWithBorder)n=r-1;else{if(!(e>t[r].bottomWithBorder))return r;o=r+1}}return-1}(e,t.y),l=function(t,e){if(0===t.length)return-1;if(e<t[0].leftWithBorder)return-1;if(e>t[t.length-1].rightWithBorder)return-1;let o=0,n=t.length-1;for(;o<=n;){const r=Math.floor((o+n)/2);if(e<t[r].leftWithBorder)n=r-1;else{if(!(e>t[r].rightWithBorder))return r;o=r+1}}return-1}(o,t.x);return-1===i||-1===l?null:{rowId:e[i].id,columnId:o[l].id}}function ht(t){return t.reduce(((t,e)=>t.set(e.key,e)),new Map)}function ft(t,e,n,r,i,l,s,u){if(!t)return[];if(!e)return[];if(!r)return[];if(!n)return[];const c=o(n.columnId),a=o(n.rowId),d=o(r.columnId),h=o(r.rowId);if(!s.has(c))return[];if(!u.has(a))return[];if(!s.has(d))return[];if(!u.has(h))return[];const f=Math.min(s.get(c).index,s.get(d).index),p=Math.max(s.get(c).index,s.get(d).index),m=Math.min(u.get(a).index,u.get(h).index),g=Math.max(u.get(a).index,u.get(h).index);return i.slice(f,p+1).flatMap((t=>l.slice(m,g+1).map((e=>({rowId:e.id,columnId:t.id})))))}function pt(t,e){const o=function(t){return"BEGIN"===t.pinned?"top":"END"===t.pinned?"bottom":"middle"}(e),n=function(t){return"BEGIN"===t.pinned?"left":"END"===t.pinned?"right":"center"}(t);return`${o}-${n}`}function mt(t,e,n,r,i){return 0===t.length?null:function(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!e.has(i))return null;if(!n.has(l))return null;const s=e.get(i),u=n.get(l),c={width:s.width,height:u.height,section:pt(s,u)};switch(u.pinned){case"BEGIN":c.top=u.top;break;case"END":c.bottom=r.top.height+r.middle.height+r.bottom.height-u.top-u.height;break;default:c.marginTop=u.top-r.top.height}switch(s.pinned){case"BEGIN":c.left=s.left;break;case"END":c.right=r.left.width+r.center.width+r.right.width-s.left-s.width;break;default:c.marginLeft=s.left-r.left.width}return c}(e,n,r,i)}function gt(t,e){return e.every((e=>e.edit.validate({string:t})))}function yt(t){return Array.isArray(t)?t.map(((t,e)=>e)):Object.keys(t)}function wt(t){return yt(t)}function bt(t){const e=new Set;if(Array.isArray(t))for(const o of t)for(const t of yt(o))e.add(t);else for(const o in t)for(const n of yt(t[o]))e.add(n);return Array.from(e)}function Ct(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):bt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}function xt(t,e){if(!t.some((t=>"DATA-BLOCK"===t.type)))return t;const o=[];for(const n of t)if("DATA-BLOCK"===n.type){const t="selector"in n?n.selector({data:e}):wt(e),r="id"in n?n.id:({selector:t})=>t;for(const i of t)o.push({...n,id:r({data:e,selector:i}),selector:i,type:"DATA"})}else o.push(n);return o}const vt=({text:t,expression:e})=>t.includes(e);class At{constructor(t){this.rulesLookup=new N;for(const e of t){const t={by:o("by"in e?e.by:"FILTER"),condition:e.condition||vt};this.rulesLookup.addRule(e.column,e.row,t)}}resolve(t,e,o,n,r,i,l,s){const u=this.rulesLookup.getRules(r,n);if(0===u.length)return"DATA"!==n.type||"DATA"!==r.type||!s.has('"FILTER"')||vt({text:l,expression:s.get('"FILTER"')});let c={data:t,rows:e,columns:o,row:n,column:r,value:i,text:l};for(const t of u){if(!s.has(t.by))continue;const e={...c,expression:s.get(t.by)};if(!t.condition(e))return!1}return!0}}function Rt(t){return new At(t)}function It(t){return d(t,["value","text"])}function kt(t){return d(t,["value","text","font","padding"])}function Et(t,e,o,n,r,l,s){if(t.every((t=>"number"==typeof t.width)))return t;const u=t=>{if("DYNAMIC-BLOCK"===t.type)return t.width;const i=t.width;if("number"==typeof i)return i;if(r.has(t.key)){const e=r.get(t.key);if("fit-once"===i&&!e.dataOnly)return e.width;if("fit-data-once"===i&&e.dataOnly)return e.width}let l=0;for(const r of e){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const e=n.resolve(r,t),s=e.text,u=e.font,c=e.padding.left+e.padding.right,a=o.measureWidth(s,u)+c;l=Math.max(l,a)}return r.set(t.key,{width:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return t.map((t=>({...t,width:i(u(t),s)})))}function St(t,e,o,n,r,l,s){if(e.every((t=>"number"==typeof t.height)))return e;const u=e=>{if("DYNAMIC-BLOCK"===e.type)return e.height;const i=e.height;if("number"==typeof i)return i;if(r.has(e.key)){const t=r.get(e.key);if("fit-once"===i&&!t.dataOnly)return t.height;if("fit-data-once"===i&&t.dataOnly)return t.height}let l=0;for(const r of t){if("DYNAMIC-BLOCK"===r.type)continue;if("DATA"!==r.type&&"fit-data-once"===i)continue;if("DATA"!==r.type&&"fit-data"===i)continue;const t=n.resolve(e,r),s=t.text,u=t.font,c=t.padding.top+t.padding.bottom,a=o.measureHeight(s,u)+c;l=Math.max(l,a)}return r.set(e.key,{height:l,dataOnly:"fit-data-once"===i}),l};for(const t of r.keys())l.has(t)||r.delete(t);return e.map((t=>({...t,height:i(u(t),s)})))}function Dt(t){const e=new Set;for(const o of t)"DYNAMIC-BLOCK"!=o.type&&e.add(o.key);return e}function Mt(t){return d(t,["value","text"])}function Tt(t){return d(t,["value","sortOrder"])}function Bt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value<e.value?-1:t.value>e.value?1:0}function Lt(t,e){return t===e?0:void 0===t.value?1:void 0===e.value||t.value>e.value?-1:t.value<e.value?1:0}class Ot{constructor(t){this.rulesLookup=new N;for(const e of t){const t=e.comparatorAsc||e.comparator,n=e.comparatorDesc||(e.comparator?(t,o)=>{return-("number"==typeof(n=e.comparator(t,o))?n:n?-1:1);var n}:null),r=t?(e,o)=>t(e,o):(t,e)=>Bt(t,e),i=n?(t,e)=>n(t,e):(t,e)=>Lt(t,e),l={by:o("by"in e?e.by:"HEADER"),comparatorAsc:r,comparatorDesc:i};this.rulesLookup.addRule(e.column,e.row,l)}}resolve(t,e,o){const n=this.rulesLookup.getRules(t,e);if(0===n.length)return"DATA"!==e.type||"DATA"!==t.type?null:o.has('"HEADER"')?"ASC"===o.get('"HEADER"')?Bt:Lt:null;if(n.length>1)throw new Error("Multiple sorting rules for the same cell");const r=n[0];return o.has(r.by)?"ASC"===o.get(r.by)?r.comparatorAsc:r.comparatorDesc:null}}function zt(t){return"manual"===t?null:new Ot(t)}function Nt(t,e,n){const r=new Map;for(const i of t){const t=o(i[e]),l=o(i[n]);r.has(t)||r.set(t,new Map),r.get(t).set(l,i.direction)}return r}function Kt(t,e){t.sort(((t,e)=>{const o=t.comparator(t.cell,e.cell);return"number"==typeof o?o:o?-1:1})),e.push(...t.map((t=>t.entity))),t.length=0}function Ft(t,e,n,r,i,l,s){if(0===t.length)return i;if(null===e)return i;const u=Nt(t,"columnId","rowId"),c=new Map(l.filter((t=>"DYNAMIC-BLOCK"!==t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.columnId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return i;for(const t of a){const o=[],c=[];for(const a of i){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(t,a,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,a,t,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),i=o}return i}function Ht(t,e,n,r,i,l,s){if(0===t.length)return l;if(null===e)return l;const u=Nt(t,"rowId","columnId"),c=new Map(i.filter((t=>"DYNAMIC-BLOCK"!=t.type)).map((t=>[t.key,t]))),a=t.map((t=>o(t.rowId))).filter((t=>c.has(t))).map((t=>c.get(t))).reverse();if(0===a.length)return l;for(const t of a){const o=[],c=[];for(const a of l){if("DYNAMIC-BLOCK"===a.type){Kt(c,o),o.push(a);continue}const d=e.resolve(a,t,u.get(t.key));if(!d){Kt(c,o),o.push(a);continue}const h={entity:a,comparator:d,cell:n.resolve(r,i,l,t,a,s)};0!==c.length&&c[0].comparator!==d?(Kt(c,o),c.push(h)):c.push(h)}Kt(c,o),l=o}return l}const Wt=5;function Pt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId));if("HEADER"!==n.get(o(r.rowId)).type)return null;if(!s.resizable)return null;if(!i)return null;const u=i.x;return u>=s.right-Wt&&u<=s.right+Wt?s.id:0===s.index||u<s.left-Wt||u>s.left+Wt?null:t[s.index-1].id}function Yt(t,e,n,r,i,l){if(!r)return null;if(l)return null;const s=e.get(o(r.columnId)),u=n.get(o(r.rowId));if("HEADER"!==s.type)return null;if(!u.resizable)return null;if(!i)return null;const c=i.y;return c>=u.bottom-Wt&&c<=u.bottom+Wt?u.id:0===u.index||c<u.top-Wt||c>u.top+Wt?null:t[u.index-1].id}function $t(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"HEADER",rowId:"rowId"in t?t.rowId:"HEADER",direction:t.direction})))}function Vt(t){return t.map((t=>({columnId:"columnId"in t?t.columnId:"FILTER",rowId:"rowId"in t?t.rowId:"FILTER",expression:t.expression})))}function qt(t){return t.filter((t=>"DATA"===t.type)).map((t=>t.id))}function Gt(t){return qt(t)}function _t(t){return qt(t)}function jt(t){return d(t,["value","text","tooltip"])}function Ut(t,e,n,r){if(!t)return null;const i=o(t.columnId),l=o(t.rowId);if(!n.has(i))return null;if(!r.has(l))return null;const s=r.get(l),u=n.get(i);return e.resolve(s,u).tooltip}function Xt(t,e){return t?{left:e.x+8,top:e.y+20}:null}function Jt(t){return t.map((t=>o(t)))}function Qt(t,e){if(!e.length)return t;const o=new Map;for(const[t,n]of e.entries())o.set(n,t);const n=[],r=e.length;let i=0;for(const[e,l]of t.entries())if("DYNAMIC-BLOCK"===l.type)i++,n.push({entry:l,score:[i,0,0]}),i++;else{const t=l.key,s=o.has(t)?o.get(t):r;n.push({entry:l,score:[i,s,e]})}return n.sort(((t,e)=>function(t,e){if(t.length!=e.length)throw new Error("lengths should be the same");for(let o=0;o<t.length;o++){const n=t[o]-e[o];if(0!=n)return n}return 0}(t.score,e.score))).map((t=>t.entry))}function Zt(t,e){return Qt(t,e)}function te(t,e){return Qt(t,e)}function ee(t){return t.some((t=>"DYNAMIC-BLOCK"===t.type))}function oe(t){const e=[];for(const[o,n]of t){if(o>n)continue;if(0===e.length){e.push([o,n]);continue}const[t,r]=e[e.length-1];r<o-1?e.push([o,n]):(e.pop(),e.push([t,n]))}return e}function ne(t){return t.reduce(((t,e)=>"DYNAMIC-BLOCK"===e.type?t+e.count:t+1),0)}function re(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.left+i.left,h=d+r.width,f=[],p=(t,e)=>{f.push(e),s+=e.width+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),width:e.columnWidth})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",width:e*t.columnWidth+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,columnWidth:o}=t,r=o+l,i=n.left-u,c=a-n.right-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function ie(t,e,n,r,i,l){if(!ee(e))return e;let s=l,u=0,c=0;const a=ne(e),d=r.top+i.top,h=d+r.height,f=[],p=(t,e)=>{f.push(e),s+=e.height+l,u+=t},m=t=>{p(1,t)},g=(e,n,r)=>{for(let i=n;i<=r;i++){const n=e.selector({data:t,index:i}),r=e.id({data:t,selector:n});p(1,{...e,type:"DATA",id:r,key:o(r),selector:n,header:e.header({data:t,selector:n}),height:e.rowHeight})}},y=(t,e)=>{if(e>0){const n="__separator_"+c++;p(e,{...t,type:"SEPARATOR",id:n,key:o(n),header:"",height:e*t.rowHeight+(e-1)*l})}};for(const t of e){if("DYNAMIC-BLOCK"!==t.type){m(t);continue}const{count:e,rowHeight:o}=t,r=o+l,i=n.top-u,c=a-n.bottom-u,f=Math.floor((d-s)/r),p=Math.floor((h-s)/r),w=oe([[0,i-1],[Math.max(0,i,f),Math.min(e-1,c-1,p)],[c,e-1]]);let b=0;for(const[e,o]of w)y(t,e-b),g(t,e,o),b=o+1;y(t,e-b)}return f}function le(t,e,o,n,r,i){const l=t.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),s=e.reduce(((t,e)=>t+function(t){return"DYNAMIC-BLOCK"===t.type?t.count:1}(e)),0),u=Math.min(r,l),c=Math.min(o,s);return{left:u,top:c,right:Math.min(i,l-u),bottom:Math.min(n,s-c)}}function se(t){return{width:t.clientWidth,height:t.clientHeight}}function ue(t){return{left:t.scrollLeft,top:t.scrollTop}}function ce(t,e,o,n,r){if(!t)return null;const i=t.x,l=t.y;return{x:i<=n.left?i:i>=e.width?i+o.left:i>=e.width-n.right?r.width-e.width+i:i+o.left,y:l<=n.top?l:l>=e.height?l+o.top:l>=e.height-n.bottom?r.height-e.height+l:l+o.top}}function ae(t,e,o,n,r,i){return!!t&&(void 0===o||o<n||o>i-r||!e)}function de(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 he(t,e,o,n,r,i,l,s,u){if(!ae(t,e,r?.y,i.top,i.bottom,l.height))return null;let c=Math.floor(t.index)+n.top,a=-i.top,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.rowHeight+u)*e,c-=e,e<t.count){d=t.rowHeight;break}}else{if(0===c){d=t.height;break}a+=t.height+u,c-=1}return de(t,a,d,s.height-i.top-i.bottom)}function fe(t,e,o,n,r,i,l,s,u){if(!ae(t,e,r?.x,i.left,i.right,l.width))return null;let c=Math.floor(t.index)+n.left,a=-i.left,d=0;for(const t of o)if("DYNAMIC-BLOCK"===t.type){const e=Math.min(c,t.count);if(a+=(t.columnWidth+u)*e,c-=e,e<t.count){d=t.columnWidth;break}}else{if(0===c){d=t.width;break}a+=t.width+u,c-=1}return de(t,a,d,s.width-i.left-i.right)}function pe(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 me(t,e,o,n,r){return{verticalTarget:t,horizontalTarget:e,verticalSpeed:o,horizontalSpeed:n,clientSizeVersion:r}}function ge(t){return{scrollbarWidth:t.scrollbarWidth||"auto"}}function ye(t,e,o,n,r,i){return{sections:t,devicePixelRatio:e,scrollRect:o,renderFormatResolver:n,borderWidth:r,textResolver:i}}function we(t,e){return{inputPlacement:t,isTextValid:e}}function be(t,e,o){return{resizableColumn:t,resizableRow:e,isReordering:o}}function Ce(t,e){return{tooltip:t,tooltipPlacement:e}}function xe(t){return t.measureHeight("X",T)+B.top+B.bottom}function ve(t,e){return!t&&!e||!(!t||!e)&&t.x===e.x&&t.y===e.y}function Ae(t,e){return!t&&!e||!(!t||!e)&&t.width===e.width&&t.height===e.height}function Re(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top}function Ie(t,e){return!t&&!e||!(!t||!e)&&t.left===e.left&&t.top===e.top&&t.width===e.width&&t.height===e.height}function ke(t,e){return!t&&!e||!(!t||!e)&&o(t.rowId)===o(e.rowId)&&o(t.columnId)===o(e.columnId)}function Ee(t,e){return!t&&!e||!(!t||!e)&&t.scrollbarWidth===e.scrollbarWidth}function Se(t){const e={...t.localOptions,...t.externalOptions},o=t.memory,n=t.state,i=t.element,l=[];function s(t,e,n,r=((t,e)=>t===e)){const i=o[t]&&o[t].dependencies;if(!i||n.some(((t,e)=>t!==i[e]))){const i=o[t]&&o[t].value,s=o[t]&&o[t].version||0,u=e(...n);r(i,u)?o[t]={value:i,dependencies:n,version:s}:(o[t]={value:u,dependencies:n,version:s+1},l.push(t))}return o[t].value}function c(t,e,n){(o[t]&&o[t].value)!==e&&(o[t]={value:e},n(e))}const a=s("devicePixelRatio",(t=>t),[window.devicePixelRatio]),d=s("borderWidth",(t=>t),[e.borderWidth/a]),f=e.data,y=t.input.value,b=s("sortBy",$t,[e.sortBy]),A=s("filters",Vt,[e.filters]),R=s("textResolver",et,[]),I=s("dataFormatting",u,[e.formatting,e.dataSelector,b]),S=s("editedCellsAndFilters",g,[e.editedCells,A]),T=s("edition",w,[S]),B=s("invokedColumns",x,[e.columns,f]),L=s("invokedRows",v,[e.rows,f]),O=s("mousePosition",(t=>t),[t.mousePosition],ve),z=s("unfoldedColumns",Ct,[B,f]),N=s("unfoldedRows",xt,[L,f]),K=s("dynamicRowHeight",xe,[R]),F=s("unfilteredColumns",k,[z,e.columnWidths,d,a,150]),H=s("unfilteredRows",E,[N,e.rowHeights,d,a,K]),W=s("unfilteredColumnKeys",Dt,[F]),P=s("unfilteredRowKeys",Dt,[H]),$=s("columnsOrder",Jt,[e.columnsOrder]),q=s("rowsOrder",Jt,[e.rowsOrder]),j=s("orderedColumns",Zt,[F,$]),U=s("orderedRows",te,[H,q]),J=s("filterFormatting",It,[I]),Q=s("filterFormattingRules",Y,[J]),tt=s("filteringRules",Rt,[e.filtering]),ot=s("filteredColumns",_,[A,tt,Q,f,U,j,T]),nt=s("filteredRows",G,[A,tt,Q,f,U,j,T]),rt=s("sortingFormatting",Mt,[I]),it=s("sortingFormattingRules",Y,[rt]),lt=s("sortingRules",zt,[e.sorting]),st=s("sortedColumns",Ht,[b,lt,it,f,nt,ot,T]),ut=s("sortedRows",Ft,[b,lt,it,f,nt,ot,T]),ct=s("pinning",le,[st,ut,e.pinnedTop,e.pinnedBottom,e.pinnedLeft,e.pinnedRight]),pt=s("measureFormatting",kt,[I]),yt=s("measureFormattingRules",Y,[pt]),wt=s("measureFormatResolver",V,[yt,f,ut,st,T]),bt=t.columnWidthCache,vt=t.rowHeightCache,At=s("measuredColumns",Et,[st,ut,R,wt,bt,W,a]),Bt=s("measuredRows",St,[st,ut,R,wt,vt,P,a]),Lt=s("fixedSize",X,[At,Bt,ct,d]),Ot=s("totalSize",Z,[At,Bt,d]),Nt=s("clientSize",(t=>t),[se(i)],Ae),Kt=s("boundingClientSize",(t=>t),[se(i)],Ae),Wt=s("scrollOffset",(t=>t),[ue(i)],Re),qt=s("internalMousePosition",ce,[O,Nt,Wt,Lt,Ot],ve),Qt=s("scrollRect",at,[n?.renderState?.scrollRect,Wt,Ot,Lt,Kt],Ie),ee=s("horizontalScrollTarget",fe,[e.horizontalScrollTarget,e.disableScrollOnHover,At,ct,qt,Lt,Ot,Nt,d]),oe=s("verticalScrollTarget",he,[e.verticalScrollTarget,e.disableScrollOnHover,Bt,ct,qt,Lt,Ot,Nt,d]),ne=s("horizontalScrollSpeed",pe,[e.horizontalScrollSpeed]),ae=s("verticalScrollSpeed",pe,[e.verticalScrollSpeed]),de=s("staticColumns",re,[f,At,ct,Qt,Lt,d]),Se=s("staticRows",ie,[f,Bt,ct,Qt,Lt,d]),De=s("columns",D,[de,ct,d]),Me=s("rows",M,[Se,ct,d]),Te=s("columnLookup",ht,[De]),Be=s("rowLookup",ht,[Me]),Le=e.focusedCell,Oe=s("sections",m,[De,Me]),ze=e.selectedCells,Ne=s("hoveredCell",dt,[qt,Me,De,Lt,Ot],ke),Ke=t.isReordering,Fe=t.resizingColumn||s("resizableColumn",Pt,[De,Te,Be,Ne,qt,Ke]),He=t.resizingRow||s("resizableRow",Yt,[Me,Te,Be,Ne,qt,Ke]),We=s("highlightedCells",ft,[t.isMouseDown,!Fe&&!He&&!t.didReorder,Le,Ne,De,Me,Te,Be]),Pe=s("selection",C,[ze]),Ye=s("highlight",C,[We]),$e=s("renderFormatting",p,[I,Ne,Le,Pe,Ye,T,b,Fe,He,e.borderWidth,Ke,t.reorderedColumn,t.reorderedRow]),Ve=s("renderFormattingRules",Y,[$e]),qe=s("renderFormatResolver",V,[Ve,f,Me,De,T]),Ge=s("sortOrderFormatting",Tt,[I]),_e=s("sortOrderFormattingRules",Y,[Ge]),je=s("sortOrderFormatResolver",V,[_e,f,Me,De,T]),Ue=s("inputFormatting",h,[I]),Xe=s("inputFormattingRules",Y,[Ue]),Je=s("inputFormatResolver",V,[Xe,f,Me,De,T]),Qe=s("editableCells",r,[ze,Je,Te,Be]),Ze=s("inputPlacement",mt,[Qe,Le,Te,Be,Oe]),to=s("isTextValid",gt,[y,Qe]),eo=s("contextFormatting",jt,[I]),oo=s("contextFormattingRules",Y,[eo]),no=s("contextFormatResolver",V,[oo,f,Me,De,T]),ro=s("tooltip",Ut,[Ne,no,Te,Be]),io=s("tooltipPlacement",Xt,[ro,O]),lo=s("renderState",ye,[Oe,a,Qt,qe,d,R]),so=s("inputState",we,[Ze,to]),uo=s("cursorState",be,[Fe,He,t.isReordering]),co=s("tooltipState",Ce,[ro,io]),ao=s("scrollState",me,[oe,ee,ae,ne,o.clientSize.version]),ho=s("styleState",ge,[e.style],Ee),fo=s("activeColumns",Gt,[De]),po=s("activeRows",_t,[Me]);c("activeColumnsCallback",fo,e.onActiveColumnsChange),c("activeRowsCallback",po,e.onActiveRowsChange),c("hoveredCellCallback",Ne,e.onHoveredCellChange),e.onStateChange(l),t.state={options:e,edition:T,columns:De,rows:Me,hoveredCell:Ne,focusedCell:Le,inputFormatResolver:Je,fixedSize:Lt,totalSize:Ot,clientSize:Nt,scrollOffset:Wt,highlightedCells:We,columnLookup:Te,rowLookup:Be,text:y,scrollState:ao,styleState:ho,sortOrderFormatResolver:je,renderState:lo,inputState:so,cursorState:uo,tooltipState:co}}function De(t,e){const o=new b(e);return[...e,...t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))]}function Me(t,e){const o=new b(e);return t.filter((t=>!o.isIdSelected(t.rowId,t.columnId)))}function Te(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 Be(t,e){return t.map((t=>({...t,columnId:"columnId"in t?t.columnId:e,rowId:"rowId"in t?t.rowId:e})))}function Le(t,e,n){const r=o(e),i=o(n);if(r===i)return null;const l=t.findIndex((t=>t.key===r)),s=t.findIndex((t=>t.key===i));return-1===l||-1===s||l===s?null:[l,s]}function Oe(t){const e=t.element;t.scrollAnimationId&&(cancelAnimationFrame(t.scrollAnimationId),t.scrollAnimationId=null,e.scrollTop=e.scrollTop,e.scrollLeft=e.scrollLeft)}function ze(t,e,o,n){return t>0?Math.min(t,e*o+n):Math.max(t,-e*o+n)}function Ne(t,e,o,n,r,i,l,s,u,c,a){if(null===n)return null;const d=n-o;if(Math.abs(d)<1)return null;if(d<0&&0===o)return null;if(d>0&&o>=i-r-1)return null;const h=function(t,e){const o=Math.abs(e);for(const e of t)if(o<=e.maxDistance)return e.scrollSpeed;return"auto"}(u,d);return a||"auto"===h?{[t]:n,behavior:"auto"}:"number"==typeof h?{[t]:o+ze(d,h,e,c),behavior:"auto"}:l!==n||s===o?{[t]:n}:null}function Ke(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 Fe(t){if(!t.errorRendered)try{Se(t),t.state.styleState!==t.lastStyleState&&(t.lastStyleState=t.state.styleState,function(t){const e=t.state.styleState,o=t.element,n=`\n max-width: 100vw;\n max-height: 100vh;\n overflow: auto;\n display: grid;\n position: relative;\n grid-template-columns: fit-content(0) fit-content(0) fit-content(0);\n grid-template-rows: fit-content(0) fit-content(0) fit-content(0);\n outline: none;\n user-select: none;\n touch-action: manipulation;\n scrollbar-width: ${e.scrollbarWidth};\n `;o.setAttribute("style",n)}(t)),t.state.renderState!==t.lastRenderState&&(t.lastRenderState=t.state.renderState,function(t){l(t,"top","left"),l(t,"top","center"),l(t,"top","right"),l(t,"middle","left"),l(t,"middle","center"),l(t,"middle","right"),l(t,"bottom","left"),l(t,"bottom","center"),l(t,"bottom","right")}(t)),t.state.inputState!==t.lastInputState&&(t.lastInputState=t.state.inputState,function(t){const e=t.element,o=t.input,n=t.state.inputState,r=n.inputPlacement;if(!r){if(o.parentElement){const t=document.activeElement===o;o.parentElement.removeChild(o),t&&e.focus({preventScroll:!0})}return}const i=t.canvases[r.section];if(o.style.left="left"in r?`${r.left}px`:"0",o.style.top="top"in r?`${r.top}px`:"0",o.style.right="right"in r?`${r.right}px`:"0",o.style.bottom="bottom"in r?`${r.bottom}px`:"0",o.style.marginLeft="marginLeft"in r?`${r.marginLeft}px`:"0",o.style.marginTop="marginTop"in r?`${r.marginTop}px`:"0",o.style.width=`${r.width}px`,o.style.height=`${r.height}px`,o.style.gridArea=i.style.gridArea,o.style.zIndex=i.style.zIndex,o.style.backgroundColor=n.isTextValid?"white":"#eb3434",!o.parentElement){const t=document.activeElement===e;e.appendChild(o),t&&o.focus({preventScroll:!0})}}(t)),t.state.cursorState!==t.lastCursorState&&(t.lastCursorState=t.state.cursorState,function(t){const e=t.element,o=t.state.cursorState;o.isReordering?e.style.cursor="move":o.resizableColumn&&o.resizableRow?e.style.cursor="nwse-resize":o.resizableColumn?e.style.cursor="col-resize":o.resizableRow?e.style.cursor="row-resize":e.style.cursor="default"}(t)),t.state.tooltipState!==t.lastTooltipState&&(t.lastTooltipState=t.state.tooltipState,function(t){const e=t.element,o=t.tooltip,n=t.state.tooltipState,r=n.tooltip,i=n.tooltipPlacement;i?(o.innerHTML!==r&&(o.innerHTML=r),o.style.left=`calc(anchor(left) + ${i.left}px)`,o.style.top=`calc(anchor(top) + ${i.top}px)`,o.parentElement||(e.appendChild(o),o.showPopover({source:e}))):o.parentElement&&o.parentElement.removeChild(o)}(t)),t.state.scrollState!==t.lastScrollState&&(t.lastScrollState=t.state.scrollState,function(t){const e=t.element,o=t.state.scrollState,n=o.verticalTarget,r=o.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Oe(t);if(t.scrollAnimationId)return;let i=performance.now(),l=null,s=null,u={top:e.scrollTop,left:e.scrollLeft},c=0,a=0;const d=o=>{const n=t.state.scrollState.verticalTarget,r=t.state.scrollState.horizontalTarget;if(null===n&&null===r||!e.isConnected)return void Oe(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 Ne("top",e,l.scrollTop,u,l.clientHeight,l.scrollHeight,o?.top,n.top,s.verticalSpeed,r,i)}(t,h,s,u,c,f),m=function(t,e,o,n,r,i){const l=t.element,s=t.state.scrollState,u=s.horizontalTarget;return Ne("left",e,l.scrollLeft,u,l.clientWidth,l.scrollWidth,o?.left,n.left,s.horizontalSpeed,r,i)}(t,h,l,u,a,f),g={...s,...l,behavior:"smooth",...p,...m};(p||m)&&e.scrollTo(g),c=p&&"auto"===g.behavior?g.top-e.scrollTop:0,a=m&&"auto"===g.behavior?g.left-e.scrollLeft:0,s=p||s,l=m||l,u={top:e.scrollTop,left:e.scrollLeft},t.scrollAnimationId=requestAnimationFrame(d)};d(i)}(t))}catch(e){Ke(t,e)}}function He(t){if("spread-grid-context"in t)return;const e={"top-left":document.createElement("canvas"),"top-center":document.createElement("canvas"),"top-right":document.createElement("canvas"),"middle-left":document.createElement("canvas"),"middle-center":document.createElement("canvas"),"middle-right":document.createElement("canvas"),"bottom-left":document.createElement("canvas"),"bottom-center":document.createElement("canvas"),"bottom-right":document.createElement("canvas")},i=document.createElement("input"),l=document.createElement("div");t.setAttribute("tabindex","0"),t.classList.add("spread-grid"),e["top-left"].setAttribute("style","position: sticky; left: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 1;"),e["top-center"].setAttribute("style","position: sticky; top: 0; z-index: 1; grid-row: 1; grid-column: 2;"),e["top-right"].setAttribute("style","position: sticky; right: 0; top: 0; z-index: 2; grid-row: 1; grid-column: 3;"),e["middle-left"].setAttribute("style","position: sticky; left: 0; z-index: 1; grid-row: 2; grid-column: 1;"),e["middle-center"].setAttribute("style","grid-row: 2; grid-column: 2; z-index: 0;"),e["middle-right"].setAttribute("style","position: sticky; right: 0; z-index: 1; grid-row: 2; grid-column: 3;"),e["bottom-left"].setAttribute("style","position: sticky; left: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 1;"),e["bottom-center"].setAttribute("style","position: sticky; bottom: 0; z-index: 1; grid-row: 3; grid-column: 2;"),e["bottom-right"].setAttribute("style","position: sticky; right: 0; bottom: 0; z-index: 2; grid-row: 3; grid-column: 3;"),i.setAttribute("style","position: sticky; z-index: 3; outline: none; border: none; box-shadow: none; padding: 0 5px; font-size: 12px; font-family: Calibri; background-color: white; box-sizing: border-box; opacity: 0; pointer-events: none;"),l.setAttribute("style","pointer-events: none; background-color: white; color: black; border: 1px solid black; padding: 3px 7px; inset: unset; position: absolute; font-size: 12px; font-family: Calibri; "),l.setAttribute("popover","manual"),l.classList.add("spread-grid-tooltip");const s={element:t,canvases:e,input:i,tooltip:l,localOptions:null,externalOptions:{},state:null,memory:{},renderRequested:!1,mousePosition:null,isMouseDown:!1,columnWidthCache:new Map,rowHeightCache:new Map,isReordering:!1,errorRendered:!1,error:null,resizingColumn:null,resizingRow:null,reorderedColumn:null,reorderedRow:null,didReorder:!1,mouseDownPosition:null,mouseDownCell:null,requestNewRender:null,fractionalScrollProgressVertical:0,fractionalScrollProgressHorizontal:0};function u(t,e,o){t.addEventListener(e,(t=>{try{o(t)}catch(t){t.message=`[${e} event]: ${t.message}`,Ke(s,t)}}))}s.requestNewRender=()=>{s.renderRequested||s.errorRendered||(s.renderRequested=!0,requestAnimationFrame((()=>{s.renderRequested=!1,Fe(s)})))},s.localOptions={data:[],columns:[{type:"DATA-BLOCK"}],rows:[{type:"HEADER"},{type:"DATA-BLOCK"}],formatting:[],filtering:[],sorting:[],dataSelector:({data:t,row:e,column:o})=>t?.[e.selector]?.[o.selector],pinnedTop:0,pinnedBottom:0,pinnedLeft:0,pinnedRight:0,borderWidth:1,focusedCell:null,onFocusedCellChange:t=>{s.localOptions.focusedCell=t,s.requestNewRender()},selectedCells:[],onSelectedCellsChange:t=>{s.localOptions.selectedCells=t,s.requestNewRender()},highlightedCells:[],editedCells:[],onEditedCellsChange:t=>{s.localOptions.editedCells=t,s.requestNewRender()},filters:[],onFiltersChange:t=>{s.localOptions.filters=t,s.requestNewRender()},sortBy:[],onSortByChange:t=>{s.localOptions.sortBy=t,s.requestNewRender()},onCellClick:()=>{},onCustomCellClick:()=>{},columnWidths:[],onColumnWidthsChange:t=>{s.localOptions.columnWidths=t,s.requestNewRender()},rowHeights:[],onRowHeightsChange:t=>{s.localOptions.rowHeights=t,s.requestNewRender()},columnsOrder:[],onColumnsOrderChange:t=>{s.localOptions.columnsOrder=t,s.requestNewRender()},rowsOrder:[],onRowsOrderChange:t=>{s.localOptions.rowsOrder=t,s.requestNewRender()},onActiveColumnsChange:()=>{},onActiveRowsChange:()=>{},onHoveredCellChange:()=>{},onStateChange:()=>{},verticalScrollTarget:null,horizontalScrollTarget:null,verticalScrollSpeed:"smooth",horizontalScrollSpeed:"smooth",disableScrollOnHover:!0,style:{}},t["spread-grid-context"]=s;const c=t=>{i.value=t,i.dispatchEvent(new Event("input"))},a=t=>{const e=s.state.options.selectedCells,o=s.state.inputFormatResolver,n=s.state.columnLookup,i=s.state.rowLookup,l=s.state.text,u=s.state.inputState.isTextValid,a=s.state.options.onEditedCellsChange,d=s.state.options.onFiltersChange,h=r(e,o,n,i);if(""===l)return;if(!u)return;if(t&&!h.every((t=>t.edit.autoCommit)))return;const f=h.filter((t=>"DATA"===t.type)),p=h.filter((t=>"FILTER"===t.type));var m;m=f.map((t=>({...t.cell,value:t.edit.parse({string:l})}))),a(De(s.state.options.editedCells,m)),(t=>{d(De(Be(s.state.options.filters,"FILTER"),t))})(p.map((t=>({...t.cell,expression:t.edit.parse({string:l})})))),t||c("")},d=t=>{const e=s.state.options.selectedCells,o=s.state.options.onEditedCellsChange,n=s.state.options.onFiltersChange,i=r(e,s.state.inputFormatResolver,s.state.columnLookup,s.state.rowLookup);var l;t&&!i.every((t=>t.edit.autoCommit))||(l=e,o(Me(s.state.options.editedCells,l)),(t=>{n(Me(Be(s.state.options.filters,"FILTER"),t))})(e))};u(t,"scroll",(t=>{s.requestNewRender()})),u(t,"pointerenter",(t=>{s.mousePosition=Te(t),s.requestNewRender()})),u(t,"pointermove",(t=>{if(s.mousePosition=Te(t),s.resizingColumn){const t=s.state.columnLookup.get(o(s.resizingColumn)),e=t.width,n=t.right,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.x-n+e),l=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t.key)).concat([{columnId:t.id,width:i}]);s.state.options.onColumnWidthsChange(l)}if(s.resizingRow){const t=s.state.rowLookup.get(o(s.resizingRow)),e=t.height,n=t.bottom,r=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),i=Math.max(10,r.y-n+e),l=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t.key)).concat([{rowId:t.id,height:i}]);s.state.options.onRowHeightsChange(l)}if(s.reorderedColumn){const t=s.state.columns,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=Le(t,e,o.columnId);if(!r)return null;const[i,l]=r,s=l<=i?n.x<t[l].leftWithBorder+t[i].width?l:l+1:n.x>t[l].rightWithBorder-t[i].width?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedColumn,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onColumnsOrderChange(n))}if(s.reorderedRow){const t=s.state.rows,e=s.state.hoveredCell,o=ce(s.mousePosition,s.state.clientSize,s.state.scrollOffset,s.state.fixedSize,s.state.totalSize),n=function(t,e,o,n){if(!o)return null;const r=Le(t,e,o.rowId);if(!r)return null;const[i,l]=r,s=l<=i?n.y<t[l].topWithBorder+t[i].height?l:l+1:n.y>t[l].bottomWithBorder-t[i].height?l:l-1;if(s===i)return null;const u=t.map((t=>t.id));return u.splice(i,1),u.splice(s,0,e),u}(t,s.reorderedRow,e,o);n&&(s.didReorder=!0,s.isReordering=!0,s.state.options.onRowsOrderChange(n))}s.requestNewRender()})),u(t,"touchmove",(t=>{(s.resizingColumn||s.resizingRow||s.reorderedColumn||s.reorderedRow)&&(t.preventDefault(),t.stopPropagation())})),u(t,"pointerleave",(()=>{s.mousePosition=null,s.requestNewRender()})),u(t,"pointerdown",(t=>{s.mousePosition=Te(t),Se(s),c("");const e=s.state.hoveredCell;if(s.isMouseDown=!0,s.didReorder=!1,s.mouseDownPosition=s.mousePosition,s.mouseDownCell=e,s.state.cursorState.resizableColumn&&(s.resizingColumn=s.state.cursorState.resizableColumn),s.state.cursorState.resizableRow&&(s.resizingRow=s.state.cursorState.resizableRow),!s.resizingColumn&&e){const t=s.state.rowLookup.get(o(e.rowId));s.reorderedColumn="HEADER"===t.type?e.columnId:null}if(!s.resizingRow&&e){const t=s.state.columnLookup.get(o(e.columnId));s.reorderedRow="HEADER"===t.type?e.rowId:null}s.resizingColumn||s.resizingRow||s.state.options.onFocusedCellChange(e),t.ctrlKey||s.state.options.onSelectedCellsChange([]),s.requestNewRender()})),u(t,"pointerup",(t=>{s.mousePosition=Te(t),Se(s),s.isMouseDown=!1,s.isReordering=!1,s.resizingColumn=null,s.resizingRow=null,s.reorderedColumn=null,s.reorderedRow=null,s.state.options.onSelectedCellsChange(De(s.state.options.selectedCells,s.state.highlightedCells)),s.requestNewRender()})),u(t,"pointerdown",(t=>{s.element.setPointerCapture(t.pointerId)})),u(t,"pointerup",(t=>{s.element.releasePointerCapture(t.pointerId)})),u(t,"click",(t=>{s.mousePosition=Te(t),Se(s);const e=s.state.hoveredCell,r=s.mouseDownCell;if(s.state.cursorState.resizableColumn||s.state.cursorState.resizableRow)return;if(s.didReorder)return;if(null===e)return;if(null===r)return;if(o(e.columnId)!==o(r.columnId))return;if(o(e.rowId)!==o(r.rowId))return;const i=s.state.columnLookup.get(o(e.columnId)),l=s.state.rowLookup.get(o(e.rowId)),u=s.state.options.sortBy,c=s.state.inputFormatResolver.resolve(l,i),a={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,button:t.button,buttons:t.buttons,detail:t.detail};if(c.edit?.toggle){const t=function(t,e,o,n){const r=n.hasValueByKey(o.key,e.key)?n.getValueByKey(o.key,e.key):t.value,i=t.edit.toggle;return"function"==typeof i?i({value:r}):i[(i.indexOf(r)+1)%i.length]}(c,i,l,s.state.edition),o=n(i,l);"DATA"===o&&s.state.options.onEditedCellsChange(De(s.state.options.editedCells,[{...e,value:t}])),"FILTER"===o&&s.state.options.onFiltersChange(De(Be(s.state.options.filters,"FILTER"),[{...e,expression:t}]))}else if("DATA"===i.type&&"DATA"===l.type)s.state.options.onCellClick({...s.state.hoveredCell,...a});else if("CUSTOM"===i.type||"CUSTOM"===l.type)s.state.options.onCustomCellClick({...s.state.hoveredCell,...a});else if("HEADER"===i.type||"HEADER"===l.type){const e=s.state.sortOrderFormatResolver.resolve(l,i),n=function(t,e,n,r,i){function l(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return e.key===o(r)&&n.key===o(i)}const s=i?i.map((t=>null===t?void 0:t)):["ASC","DESC",void 0],u=t.find(l),c=s.indexOf(u?.direction),a=s[(c+1)%s.length],d=t.indexOf(u)===t.length-1;return[...!r||!d&&u?t.filter((t=>!function(t){const r="columnId"in t?t.columnId:"HEADER",i="rowId"in t?t.rowId:"HEADER";return"HEADER"===e.type&&e.key===o(r)||"HEADER"===n.type&&n.key===o(i)}(t))):t.filter((t=>!l(t))),...a?[{columnId:e.id,rowId:n.id,direction:a}]:[]]}(u,i,l,t.ctrlKey,e.sortOrder);s.state.options.onSortByChange(n),s.state.options.onSelectedCellsChange([])}})),u(t,"dblclick",(t=>{if(s.mousePosition=Te(t),Se(s),s.state.cursorState.resizableColumn){const t=o(s.state.cursorState.resizableColumn),e=s.state.options.columnWidths.filter((e=>o(e.columnId)!==t));s.state.options.onColumnWidthsChange(e),s.columnWidthCache.delete(t)}if(s.state.cursorState.resizableRow){const t=o(s.state.cursorState.resizableRow),e=s.state.options.rowHeights.filter((e=>o(e.rowId)!==t));s.state.options.onRowHeightsChange(e),s.rowHeightCache.delete(t)}const e=s.state.focusedCell;if(null===e)return;const n=o(e.columnId),r=o(e.rowId),l=s.state.columnLookup,u=s.state.rowLookup,a=s.state.inputFormatResolver;if(!l.has(n))return;if(!u.has(r))return;const d=l.get(n),h=u.get(r),f=a.resolve(h,d),p=f.text;f.edit&&(f.edit.toggle||(c(p),i?.select()))})),u(t,"focus",(()=>{i.parentElement&&i.focus({preventScroll:!0})})),u(t,"keydown",(t=>{Se(s);const e=s.state.focusedCell,n=s.state.columnLookup,r=s.state.rowLookup,i=s.state.options.selectedCells,l=s.state.options.onSelectedCellsChange,u=s.state.options.onFocusedCellChange,h=s.state.options.editedCells,f=s.state.options.onEditedCellsChange,p=s.state.columns,m=s.state.rows,g=s.state.text,y=s.state.inputFormatResolver,w=(t,e)=>{u(t),e.shiftKey?l(De(i,[t])):l([t])},C=(t,r)=>{if(!e)return;const i=o(e.columnId);if(!n.has(i))return;const l=n.get(i).index,s=Math.max(0,Math.min(p.length-1,l+t));if(s===l)return;const u={rowId:e.rowId,columnId:p[s].id};w(u,r)},x=(t,n)=>{if(!e)return;const i=o(e.rowId);if(!r.has(i))return;const l=r.get(i).index,s=Math.max(0,Math.min(m.length-1,l+t));if(s===l)return;const u={rowId:m[s].id,columnId:e.columnId};w(u,n)},v=()=>{t.preventDefault(),t.stopPropagation()};switch(t.key){case"Escape":""!==g?c(""):i.length>1?l([e]):h.length>0?f([]):(u(null),l([]));break;case"Enter":a(!1);break;case"ArrowUp":v(),x(t.ctrlKey?-m.length:-1,t);break;case"ArrowDown":v(),x(t.ctrlKey?m.length:1,t);break;case"ArrowLeft":v(),C(t.ctrlKey?-p.length:-1,t);break;case"ArrowRight":v(),C(t.ctrlKey?p.length:1,t);break;case"Delete":case"Backspace":d(!1);break;case"c":(t=>{if(!t.ctrlKey)return;const e=function(t,e,n,r){const i=new Map(e.map((t=>[t.key,t]))),l=new Map(n.map((t=>[t.key,t]))),s=t.map((t=>({columnKey:o(t.columnId),rowKey:o(t.rowId)}))).filter((t=>i.has(t.columnKey)&&l.has(t.rowKey))),u=new Set(s.map((t=>t.columnKey))),c=new Set(s.map((t=>t.rowKey)));if(0===s.length)return"";const a=new b(t),d=Math.min(...s.map((t=>i.get(t.columnKey).index))),h=Math.max(...s.map((t=>i.get(t.columnKey).index))),f=Math.min(...s.map((t=>l.get(t.rowKey).index))),p=Math.max(...s.map((t=>l.get(t.rowKey).index))),m=[];for(let t=f;t<=p;t++){const o=n[t],i=o.key;if(c.has(i)){for(let t=d;t<=h;t++){const n=e[t],l=n.key;if(u.has(l)){if(a.isKeySelected(i,l)){const t=r.resolve(o,n).text;m.push(t)}t<h&&m.push("\t")}}t<p&&m.push("\n")}}return m.join("")}(i,p,m,y);if(navigator.clipboard)navigator.clipboard.writeText(e);else{const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}})(t)}})),new ResizeObserver((()=>{s.requestNewRender()})).observe(t),u(i,"input",(t=>{Se(s),i.value?(a(!0),i.style.opacity="1",i.style.pointerEvents="auto"):(t.isTrusted&&d(!0),i.style.opacity="0",i.style.pointerEvents="none")})),u(i,"click",(t=>{t.stopPropagation()})),u(i,"dblclick",(t=>{t.stopPropagation()})),u(i,"pointerdown",(t=>{t.stopPropagation()})),u(i,"keydown",(t=>{switch(t.key){case"Enter":case"Escape":break;case"Delete":case"Backspace":case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":""!==i.value&&(t.stopPropagation(),s.requestNewRender());break;default:t.stopPropagation(),s.requestNewRender()}})),u(t,"wheel",(e=>{null===s.state.scrollState.verticalTarget&&null===s.state.scrollState.horizontalTarget||(t.scrollBy({top:e.deltaY,left:e.deltaX,behavior:"auto"}),e.preventDefault(),e.stopPropagation())}))}function We(t,e){He(t);const o=t["spread-grid-context"];o.externalOptions=e,null===o.state?Fe(o):o.requestNewRender()}return e.default})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-spread-grid",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Fast grid for js applications",
|
|
5
5
|
"author": "Tomasz Rewak <tomasz.rewak@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://spread-grid.tomasz-rewak.com",
|
|
15
15
|
"main": "dist/index.js",
|
|
16
|
+
"types": "src/index.d.ts",
|
|
16
17
|
"type": "module",
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "webpack --mode=production --output-library-type=umd --output-library-export=default --output-library-name=SpreadGrid --entry ./src/index.js --output-filename ./index.js",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @import * as Types from "../typings.js"; */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Types.Context} context
|
|
5
|
+
*/
|
|
6
|
+
export default function updateCursor(context) {
|
|
7
|
+
const element = context.element;
|
|
8
|
+
const cursorState = context.state.cursorState;
|
|
9
|
+
|
|
10
|
+
if (cursorState.isReordering)
|
|
11
|
+
element.style.cursor = 'move';
|
|
12
|
+
else if (cursorState.resizableColumn && cursorState.resizableRow)
|
|
13
|
+
element.style.cursor = 'nwse-resize';
|
|
14
|
+
else if (cursorState.resizableColumn)
|
|
15
|
+
element.style.cursor = 'col-resize';
|
|
16
|
+
else if (cursorState.resizableRow)
|
|
17
|
+
element.style.cursor = 'row-resize';
|
|
18
|
+
else
|
|
19
|
+
element.style.cursor = 'default';
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @import * as Types from "../typings.js" **/
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Types.Context} context
|
|
5
|
+
* @param {Error} error
|
|
6
|
+
*/
|
|
7
|
+
export default function showError(context, error) {
|
|
8
|
+
if (context.errorRendered)
|
|
9
|
+
return;
|
|
10
|
+
|
|
11
|
+
context.errorRendered = true;
|
|
12
|
+
|
|
13
|
+
const element = context.element;
|
|
14
|
+
|
|
15
|
+
element.style.backgroundColor = '#9f0000';
|
|
16
|
+
element.style.color = 'white';
|
|
17
|
+
element.style.padding = '20px';
|
|
18
|
+
element.style.display = 'flex';
|
|
19
|
+
element.style.flexDirection = 'column';
|
|
20
|
+
element.style.userSelect = 'text';
|
|
21
|
+
element.innerHTML = `
|
|
22
|
+
<div style="font-size: 16px;">
|
|
23
|
+
An error occurred while rendering the grid, please contact the support.
|
|
24
|
+
</div>
|
|
25
|
+
<div style="font-size: 20px; font-weight: bold; padding: 20px 0;">
|
|
26
|
+
${error.message}
|
|
27
|
+
</div>
|
|
28
|
+
<div style="font-size: 16px; white-space: pre-wrap;">${error.stack}</div>
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** @import * as Types from "../typings.js"; */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Types.Context} context
|
|
5
|
+
*/
|
|
6
|
+
export default function showInput(context) {
|
|
7
|
+
const element = context.element;
|
|
8
|
+
const input = context.input;
|
|
9
|
+
const inputState = context.state.inputState;
|
|
10
|
+
const inputPlacement = inputState.inputPlacement;
|
|
11
|
+
|
|
12
|
+
if (!inputPlacement) {
|
|
13
|
+
if (input.parentElement) {
|
|
14
|
+
const hasFocus = document.activeElement === input;
|
|
15
|
+
input.parentElement.removeChild(input);
|
|
16
|
+
if (hasFocus)
|
|
17
|
+
element.focus({ preventScroll: true });
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const canvas = context.canvases[inputPlacement.section];
|
|
23
|
+
|
|
24
|
+
input.style.left = 'left' in inputPlacement ? `${inputPlacement.left}px` : '0';
|
|
25
|
+
input.style.top = 'top' in inputPlacement ? `${inputPlacement.top}px` : '0';
|
|
26
|
+
input.style.right = 'right' in inputPlacement ? `${inputPlacement.right}px` : '0';
|
|
27
|
+
input.style.bottom = 'bottom' in inputPlacement ? `${inputPlacement.bottom}px` : '0';
|
|
28
|
+
input.style.marginLeft = 'marginLeft' in inputPlacement ? `${inputPlacement.marginLeft}px` : '0';
|
|
29
|
+
input.style.marginTop = 'marginTop' in inputPlacement ? `${inputPlacement.marginTop}px` : '0';
|
|
30
|
+
input.style.width = `${inputPlacement.width}px`;
|
|
31
|
+
input.style.height = `${inputPlacement.height}px`;
|
|
32
|
+
input.style.gridArea = canvas.style.gridArea;
|
|
33
|
+
input.style.zIndex = canvas.style.zIndex;
|
|
34
|
+
input.style.backgroundColor = inputState.isTextValid ? 'white' : '#eb3434';
|
|
35
|
+
|
|
36
|
+
if (!input.parentElement) {
|
|
37
|
+
const hasFocus = document.activeElement === element;
|
|
38
|
+
element.appendChild(input);
|
|
39
|
+
if (hasFocus)
|
|
40
|
+
input.focus({ preventScroll: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/core/render.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
/** @import * as Types from "../typings.js"; */
|
|
2
|
+
|
|
1
3
|
import roundToPixels from "../core-utils/roundToPixels.js";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
* @param {Context} context
|
|
5
|
-
* @param {VerticalSectionName} vertical
|
|
6
|
-
* @param {HorizontalSectionName} horizontal
|
|
6
|
+
* @param {Types.Context} context
|
|
7
|
+
* @param {Types.VerticalSectionName} vertical
|
|
8
|
+
* @param {Types.HorizontalSectionName} horizontal
|
|
7
9
|
*/
|
|
8
10
|
function renderSection(context, vertical, horizontal) {
|
|
9
|
-
const
|
|
11
|
+
const renderState = context.state.renderState;
|
|
10
12
|
const canvas = context.canvases[`${vertical}-${horizontal}`];
|
|
11
|
-
const verticalSection =
|
|
12
|
-
const horizontalSection =
|
|
13
|
+
const verticalSection = renderState.sections[vertical];
|
|
14
|
+
const horizontalSection = renderState.sections[horizontal];
|
|
13
15
|
const columns = horizontalSection.columns;
|
|
14
16
|
const rows = verticalSection.rows;
|
|
15
|
-
const devicePixelRatio =
|
|
17
|
+
const devicePixelRatio = renderState.devicePixelRatio;
|
|
16
18
|
|
|
17
19
|
if (rows.length === 0 || columns.length === 0) {
|
|
18
20
|
if (canvas.parentElement)
|
|
@@ -24,17 +26,16 @@ function renderSection(context, vertical, horizontal) {
|
|
|
24
26
|
context.element.appendChild(canvas);
|
|
25
27
|
|
|
26
28
|
// Checking how often this is called
|
|
27
|
-
//
|
|
29
|
+
//console.log('draw');
|
|
28
30
|
|
|
29
31
|
// TODO: Borders are still blurry after scrolling at high zoom-out levels
|
|
30
32
|
|
|
31
33
|
const ctx = canvas.getContext("2d", { alpha: false });
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const textResolver = state.textResolver;
|
|
34
|
+
const scrollRect = renderState.scrollRect;
|
|
35
|
+
const textResolver = renderState.textResolver;
|
|
35
36
|
// TODO: Make sure those formatters are split based on the rule areas
|
|
36
|
-
const formatResolver =
|
|
37
|
-
const borderWidth =
|
|
37
|
+
const formatResolver = renderState.renderFormatResolver;
|
|
38
|
+
const borderWidth = renderState.borderWidth;
|
|
38
39
|
const sectionBorders = {
|
|
39
40
|
top: verticalSection.showTopBorder,
|
|
40
41
|
bottom: verticalSection.showBottomBorder,
|
|
@@ -102,7 +103,7 @@ function renderSection(context, vertical, horizontal) {
|
|
|
102
103
|
/**
|
|
103
104
|
* @param {number} rowIndex
|
|
104
105
|
* @param {number} columnIndex
|
|
105
|
-
* @returns {Cell}
|
|
106
|
+
* @returns {Types.Cell}
|
|
106
107
|
*/
|
|
107
108
|
const getCell = (rowIndex, columnIndex) => cells[rowIndex - minVisibleRowIndex][columnIndex - minVisibleColumnIndex];
|
|
108
109
|
|
|
@@ -142,6 +143,10 @@ function renderSection(context, vertical, horizontal) {
|
|
|
142
143
|
for (let columnIndex = minVisibleColumnIndex; columnIndex <= maxVisibleColumnIndex; columnIndex++) {
|
|
143
144
|
for (let rowIndex = minVisibleRowIndex; rowIndex <= maxVisibleRowIndex; rowIndex++) {
|
|
144
145
|
const cell = getCell(rowIndex, columnIndex);
|
|
146
|
+
|
|
147
|
+
if (!cell.render)
|
|
148
|
+
continue;
|
|
149
|
+
|
|
145
150
|
const style = cell.style;
|
|
146
151
|
const cellTop = verticalOffsets[rowIndex];
|
|
147
152
|
const cellLeft = horizontalOffsets[columnIndex];
|
|
@@ -221,7 +226,7 @@ function renderSection(context, vertical, horizontal) {
|
|
|
221
226
|
* @param {number} y1
|
|
222
227
|
* @param {number} x2
|
|
223
228
|
* @param {number} y2
|
|
224
|
-
* @param {Border} style
|
|
229
|
+
* @param {Types.Border} style
|
|
225
230
|
*/
|
|
226
231
|
const drawBorder = (x1, y1, x2, y2, style) => {
|
|
227
232
|
if (!style)
|
|
@@ -257,9 +262,9 @@ function renderSection(context, vertical, horizontal) {
|
|
|
257
262
|
}
|
|
258
263
|
|
|
259
264
|
/**
|
|
260
|
-
* @param {Border} borderStyleA
|
|
261
|
-
* @param {Border} borderStyleB
|
|
262
|
-
* @returns {Border}
|
|
265
|
+
* @param {Types.Border} borderStyleA
|
|
266
|
+
* @param {Types.Border} borderStyleB
|
|
267
|
+
* @returns {Types.Border}
|
|
263
268
|
*/
|
|
264
269
|
const selectBorder = (borderStyleA, borderStyleB) => {
|
|
265
270
|
if (!borderStyleA)
|
|
@@ -315,98 +320,9 @@ function renderSection(context, vertical, horizontal) {
|
|
|
315
320
|
}
|
|
316
321
|
|
|
317
322
|
/**
|
|
318
|
-
* @param {Context} context
|
|
319
|
-
*/
|
|
320
|
-
function renderInput(context) {
|
|
321
|
-
const element = context.element;
|
|
322
|
-
const input = context.input;
|
|
323
|
-
const state = context.state;
|
|
324
|
-
const inputPlacement = state.inputPlacement;
|
|
325
|
-
|
|
326
|
-
if (!inputPlacement) {
|
|
327
|
-
if (input.parentElement) {
|
|
328
|
-
const hasFocus = document.activeElement === input;
|
|
329
|
-
input.parentElement.removeChild(input);
|
|
330
|
-
if (hasFocus)
|
|
331
|
-
element.focus({ preventScroll: true });
|
|
332
|
-
}
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const canvas = context.canvases[inputPlacement.section];
|
|
337
|
-
|
|
338
|
-
input.style.left = 'left' in inputPlacement ? `${inputPlacement.left}px` : '0';
|
|
339
|
-
input.style.top = 'top' in inputPlacement ? `${inputPlacement.top}px` : '0';
|
|
340
|
-
input.style.right = 'right' in inputPlacement ? `${inputPlacement.right}px` : '0';
|
|
341
|
-
input.style.bottom = 'bottom' in inputPlacement ? `${inputPlacement.bottom}px` : '0';
|
|
342
|
-
input.style.marginLeft = 'marginLeft' in inputPlacement ? `${inputPlacement.marginLeft}px` : '0';
|
|
343
|
-
input.style.marginTop = 'marginTop' in inputPlacement ? `${inputPlacement.marginTop}px` : '0';
|
|
344
|
-
input.style.width = `${inputPlacement.width}px`;
|
|
345
|
-
input.style.height = `${inputPlacement.height}px`;
|
|
346
|
-
input.style.gridArea = canvas.style.gridArea;
|
|
347
|
-
input.style.zIndex = canvas.style.zIndex;
|
|
348
|
-
input.style.backgroundColor = state.isTextValid ? 'white' : '#eb3434';
|
|
349
|
-
|
|
350
|
-
if (!input.parentElement) {
|
|
351
|
-
const hasFocus = document.activeElement === element;
|
|
352
|
-
element.appendChild(input);
|
|
353
|
-
if (hasFocus)
|
|
354
|
-
input.focus({ preventScroll: true });
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* @param {Context} context
|
|
360
|
-
*/
|
|
361
|
-
function renderCursor(context) {
|
|
362
|
-
const element = context.element;
|
|
363
|
-
const state = context.state;
|
|
364
|
-
|
|
365
|
-
if (context.isReordering)
|
|
366
|
-
element.style.cursor = 'move';
|
|
367
|
-
else if (state.resizableColumn && state.resizableRow)
|
|
368
|
-
element.style.cursor = 'nwse-resize';
|
|
369
|
-
else if (state.resizableColumn)
|
|
370
|
-
element.style.cursor = 'col-resize';
|
|
371
|
-
else if (state.resizableRow)
|
|
372
|
-
element.style.cursor = 'row-resize';
|
|
373
|
-
else
|
|
374
|
-
element.style.cursor = 'default';
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/** @param {Context} context */
|
|
378
|
-
function renderTooltip(context) {
|
|
379
|
-
const element = context.element;
|
|
380
|
-
const tooltip = context.tooltip;
|
|
381
|
-
const content = context.state.tooltip;
|
|
382
|
-
const placement = context.state.tooltipPlacement;
|
|
383
|
-
|
|
384
|
-
if (!placement) {
|
|
385
|
-
if (tooltip.parentElement)
|
|
386
|
-
tooltip.parentElement.removeChild(tooltip);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (tooltip.innerHTML !== content) {
|
|
391
|
-
tooltip.innerHTML = content;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
tooltip.style.left = `calc(anchor(left) + ${placement.left}px)`;
|
|
395
|
-
tooltip.style.top = `calc(anchor(top) + ${placement.top}px)`;
|
|
396
|
-
|
|
397
|
-
if (!tooltip.parentElement) {
|
|
398
|
-
element.appendChild(tooltip);
|
|
399
|
-
// @ts-ignore
|
|
400
|
-
tooltip.showPopover({
|
|
401
|
-
source: element,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* @param {Context} context
|
|
323
|
+
* @param {Types.Context} context
|
|
408
324
|
*/
|
|
409
|
-
function
|
|
325
|
+
export default function render(context) {
|
|
410
326
|
renderSection(context, 'top', 'left');
|
|
411
327
|
renderSection(context, 'top', 'center');
|
|
412
328
|
renderSection(context, 'top', 'right');
|
|
@@ -416,54 +332,4 @@ function renderInternal(context) {
|
|
|
416
332
|
renderSection(context, 'bottom', 'left');
|
|
417
333
|
renderSection(context, 'bottom', 'center');
|
|
418
334
|
renderSection(context, 'bottom', 'right');
|
|
419
|
-
|
|
420
|
-
renderInput(context);
|
|
421
|
-
renderCursor(context);
|
|
422
|
-
renderTooltip(context);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* @param {Context} context
|
|
427
|
-
*/
|
|
428
|
-
function renderError(context) {
|
|
429
|
-
if (context.errorRendered)
|
|
430
|
-
return;
|
|
431
|
-
|
|
432
|
-
context.errorRendered = true;
|
|
433
|
-
|
|
434
|
-
const element = context.element;
|
|
435
|
-
const error = context.error;
|
|
436
|
-
|
|
437
|
-
element.style.backgroundColor = '#9f0000';
|
|
438
|
-
element.style.color = 'white';
|
|
439
|
-
element.style.padding = '20px';
|
|
440
|
-
element.style.display = 'flex';
|
|
441
|
-
element.style.flexDirection = 'column';
|
|
442
|
-
element.style.userSelect = 'text';
|
|
443
|
-
element.innerHTML = `
|
|
444
|
-
<div style="font-size: 16px;">
|
|
445
|
-
An error occurred while rendering the grid, please contact the support.
|
|
446
|
-
</div>
|
|
447
|
-
<div style="font-size: 20px; font-weight: bold; padding: 20px 0;">
|
|
448
|
-
${error.message}
|
|
449
|
-
</div>
|
|
450
|
-
<div style="font-size: 16px; white-space: pre-wrap;">${error.stack}</div>
|
|
451
|
-
`;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* @param {Context} context
|
|
456
|
-
*/
|
|
457
|
-
export default function render(context) {
|
|
458
|
-
if (!context.error) {
|
|
459
|
-
try {
|
|
460
|
-
renderInternal(context);
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
context.error = error;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (context.error)
|
|
468
|
-
renderError(context);
|
|
469
335
|
}
|