(function(p,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(p=typeof globalThis<"u"?globalThis:p||self,e(p.VueSheetz={},p.Vue))})(this,function(p,e){"use strict";const ze="",X=(c,i)=>{const g=c.__vccOpts||c;for(const[B,S]of i)g[B]=S;return g},a=c=>(e.pushScopeId("data-v-7e4a8d91"),c=c(),e.popScopeId(),c),Y={class:"columns"},Z=["onClick"],G={key:0,class:"colum_sort"},Q=["onClick"],x=[a(()=>e.createElementVNode("path",{d:"M16 18L16 16M16 6L20 10.125M16 6L12 10.125M16 6L16 13"},null,-1)),a(()=>e.createElementVNode("path",{d:"M8 18L12 13.875M8 18L4 13.875M8 18L8 11M8 6V8"},null,-1))],I=["onClick"],ee=[a(()=>e.createElementVNode("path",{d:"M4 16L13 16"},null,-1)),a(()=>e.createElementVNode("path",{d:"M6 11H13"},null,-1)),a(()=>e.createElementVNode("path",{d:"M8 6L13 6"},null,-1)),a(()=>e.createElementVNode("path",{d:"M17 4L17 20L20 16"},null,-1))],te=[a(()=>e.createElementVNode("path",{d:"M4 8H13"},null,-1)),a(()=>e.createElementVNode("path",{d:"M6 13H13"},null,-1)),a(()=>e.createElementVNode("path",{d:"M8 18H13"},null,-1)),a(()=>e.createElementVNode("path",{d:"M17 20V4L20 8"},null,-1))],oe=["onPointerdown"],ne={class:"rows"},le=["onClick"],re=["onPointerdown"],se=["onKeyup"],ce=["checked"],ie={key:2,width:"90%",height:"12"},ae=a(()=>e.createElementVNode("rect",{width:"100%",height:"100%",x:"0",y:"0",rx:"6",ry:"6",fill:"#EDEDED"},null,-1)),de=["width","fill"],he=["fill","stroke"],me=["value","onKeyup","onKeydown","onInput"],ue=["value","onKeyup","onInput"],pe=a(()=>e.createElementVNode("div",{class:"column_line"},null,-1)),ye=a(()=>e.createElementVNode("div",{class:"row_line"},null,-1)),fe=X({__name:"VueSheetzComponent",props:{data:{type:Array,required:!0},height:{type:[String,Number],default:"100%"},width:{type:[String,Number],default:"100%"},manualColResize:{type:[String,Boolean],default:!0},manualRowResize:{type:[String,Boolean],default:!0},colSorting:[String,Boolean],colWidths:Array,colHeaders:Array,colsAlignment:Array,colsFormat:Array},setup(c){const i=c,g=e.computed(()=>{const t=["px","em","rem","%","vw","vh"],{height:o}=i;return t.some(n=>o.toString().includes(n))?o:`${o}px`}),B=e.computed(()=>{const t=["px","em","rem","%","vw","vh"],{width:o}=i;return t.some(n=>o.toString().includes(n))?o:`${o}px`}),S=e.computed(()=>{let t="";for(const[o,l]of Object.entries($.value))t+=`${o}: ${l}`;return t}),ke=e.computed(()=>{let t="";const o={left:"start",center:"center",right:"end"};return i.colHeaders&&(t+="--column-header-align: start;"),i.colsAlignment&&(t+=i.colsAlignment.reduce((l,n,s)=>n?l+=`--column${s}-x-align: ${o[n]};`:l,"")),t}),N=e.computed(()=>i.colHeaders?i.colHeaders:Ce),ge=e.computed(()=>{let t="";for(const[o,l]of Object.entries(A.value))t+=`${o}: ${l}`;return t}),E=L(i.data),k=Array(26).fill(null).map((t,o)=>o+65).map(t=>String.fromCharCode(t)),_e=i.data.reduce((t,{length:o})=>t=o>t?o:t,0),we=Math.min(Math.max(_e,26),702),Ce=Array(we).fill(null).reduce((t,o,l)=>{const n=Math.floor(l/k.length),s=k[l]??k[n-1]+k[l-n*k.length];return t=[...t,s]},[]),M=e.ref(Math.max(i.data.length,100)),$=e.ref({}),A=e.ref({}),_=e.ref(!1),m=e.ref(!1),w=e.ref(null),C=e.ref("asc"),d=e.ref(L(E));function L(t){return JSON.parse(JSON.stringify(t))}const Be=()=>{i.colWidths&&i.colWidths.forEach((t,o)=>$.value[`--column${o}-width`]=`${t}px;`)},Se=()=>w.value!==null?d.value=L(E).sort((t,o)=>{const l=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"}),n=w.value,s=C.value==="asc",r=l.compare(t[n],o[n]);return s?r:r*-1}):d.value=E,Ee=t=>{const l=Object.entries({33:"#f44336",66:"#1677ff",100:"#4caf50"}).find(([n])=>t<=n);return l?l[1]:""},$e=t=>[...Array(5).fill(!0),...Array(5).fill(!1)].slice(5-t,10-t),Le=()=>{const t=document.querySelectorAll(".spreadsheet_elem");if(_.value){_.value=!1,t.forEach(o=>o.classList.remove("selectedLine"));return}_.value=!0,t.forEach(o=>o.classList.add("selectedLine")),document.querySelector(".cells").removeAttribute("style")},z=t=>{const o=document.querySelector(".cells");F(),document.querySelectorAll(`.${t}`).forEach(l=>l.classList.toggle("selectedLine")),o.style.setProperty(`--${t}-border`,"2px")},F=()=>{_.value=!1,document.querySelectorAll(".selectedLine").forEach(t=>t.classList.toggle("selectedLine")),document.querySelector(".cells").removeAttribute("style")},b=t=>{t.target.setAttribute("contenteditable",!0),document.getSelection().collapse(t.target,t.target.childNodes.length),t.target.focus()},y=t=>t.target.setAttribute("contenteditable",!1),be=t=>{m.value=!0;let o;const l=document.querySelector(".spreadsheet_content"),n=document.querySelector(`.column${t}`),s=document.querySelector(".column_line"),r=n.getBoundingClientRect().left,f=l.getBoundingClientRect().left;window.onpointermove=u=>{m.value&&(o=u.clientX-r,s.style.opacity="1",s.style.left=`${u.clientX+l.scrollLeft-f}px`)},window.onpointerup=()=>{m.value&&(o&&($.value[`--column${t}-width`]=`${o}px;`),s.style.left="0",s.style.opacity="0",m.value=!1)}},Ve=t=>{m.value=!0;let o;const l=document.querySelector(".spreadsheet_content"),n=document.querySelector(`.row${t}`),s=document.querySelector(".row_line"),r=n.getBoundingClientRect().top,f=l.getBoundingClientRect().top;window.onpointermove=u=>{m.value&&(o=u.clientY-r,s.style.opacity="1",s.style.top=`${u.clientY+l.scrollTop-f}px`)},window.onpointerup=()=>{m.value&&(o&&(A.value[`--row${t}-height`]=`${o}px;`),s.style.top="0",s.style.opacity="0",m.value=!1)}},V=(t,o)=>{w.value=t,C.value=o,Se()},D=(t,o)=>{const l=`${t}`.split("");return o.replace(/#/g,()=>l.shift()).replace(/undefined/g,"")},K=(t,o=null)=>{const l=t.target.getAttribute("value");t.key==="Backspace"?t.target.setAttribute("value",l.slice(0,-1)):(o==null?void 0:o.replace(/[^#]/g,"").length)<=l.length?t.preventDefault():t.key.length===1&&t.key!==" "&&t.target.setAttribute("value",l+t.key)},Ne=({target:t},o)=>{const l=t.getAttribute("value"),n=D(l,o);l?t.textContent=n:t.innerHTML=" ",queueMicrotask(()=>document.getSelection().collapse(t,t.childNodes.length))},Me=({target:t},o)=>{const l=t.getAttribute("value"),n=o(l);l?t.textContent=n:t.innerHTML=" ",queueMicrotask(()=>document.getSelection().collapse(t,t.childNodes.length))};return e.watch(()=>i.colWidths,Be,{deep:!0,immediate:!0}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{class:"spreadsheet_content",style:e.normalizeStyle([`height: ${g.value}`,`width: ${B.value}`,S.value,ke.value,ge.value])},[e.createElementVNode("div",{class:"corner",onClick:Le}),e.createElementVNode("div",Y,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,(l,n)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["column spreadsheet_elem",`column${n}`]),style:e.normalizeStyle([`width: var(--column${n}-width, 65px)`,"justify-content: var(--column-header-align, center)"]),key:l,onClick:s=>z(`column${n}`)},[e.createTextVNode(e.toDisplayString(l)+" ",1),c.colSorting?(e.openBlock(),e.createElementBlock("div",G,[w.value!==n?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"sort_icon",width:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#666","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",onClick:s=>V(n,"asc")},x,8,Q)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[C.value==="asc"?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"sort_icon",width:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#1677ff","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",onClick:s=>V(n,"desc")},ee,8,I)):C.value==="desc"?(e.openBlock(),e.createElementBlock("svg",{key:1,class:"sort_icon",width:"17",viewBox:"0 0 24 24",fill:"none",stroke:"#1677ff","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",onClick:o[0]||(o[0]=s=>V(null,"asc"))},te)):e.createCommentVNode("",!0)],64))])):e.createCommentVNode("",!0),c.manualColResize?(e.openBlock(),e.createElementBlock("div",{key:1,class:"column_resizer",onPointerdown:s=>be(n)},null,40,oe)):e.createCommentVNode("",!0)],14,Z))),128))]),e.createElementVNode("div",ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value,(l,n)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["row spreadsheet_elem",`row${n}`]),style:e.normalizeStyle(`height: var(--row${n}-height, 25px)`),key:l,onClick:s=>z(`row${n}`)},[e.createTextVNode(e.toDisplayString(n+1)+" ",1),c.manualRowResize?(e.openBlock(),e.createElementBlock("div",{key:0,class:"row_resizer",onPointerdown:s=>Ve(n)},null,40,re)):e.createCommentVNode("",!0)],14,le))),128))]),e.createElementVNode("div",{class:"cells",onClick:F,onKeyup:o[5]||(o[5]=l=>l.key==="Delete"?console.log(l.target):"")},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value,(l,n)=>(e.openBlock(),e.createElementBlock("div",{class:"cell_row",key:l},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,(s,r)=>{var f,u,q,H,j,R,T,O,W,P,U,v,J;return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["cell spreadsheet_elem",[`row${n}`,`column${r}`]]),style:e.normalizeStyle([`width: var(--column${r}-width, 65px)`,`height: var(--row${n}-height, 25px)`]),key:s,tabindex:"-1"},[!((f=c.colsFormat)!=null&&f[r])||c.colsFormat[r]==="text"?(e.openBlock(),e.createElementBlock("div",{key:0,class:"cell_input",style:e.normalizeStyle([`justify-content: var(--column${r}-x-align, center)`,`align-items: var(--column${r}-y-align, center)`]),onDblclick:b,onBlur:y,onKeydown:o[1]||(o[1]=e.withKeys(e.withModifiers(()=>{},["prevent"]),["enter"])),onKeyup:e.withKeys(y,["enter"]),onInput:o[2]||(o[2]=({target:h})=>h.innerHTML?"":h.innerHTML=" ")},e.toDisplayString((u=d.value[n])==null?void 0:u[r]),45,se)):c.colsFormat[r]==="check"?(e.openBlock(),e.createElementBlock("input",{key:1,type:"checkbox",checked:(q=d.value[n])==null?void 0:q[r],class:"cell_checkbox"},null,8,ce)):c.colsFormat[r]==="progress"?(e.openBlock(),e.createElementBlock("svg",ie,[e.createElementVNode("title",null,e.toDisplayString((H=d.value[n])==null?void 0:H[r])+"%",1),ae,e.createElementVNode("rect",{width:`${(j=d.value[n])==null?void 0:j[r]}%`,height:"100%",x:"0",y:"0",rx:"6",ry:"6",fill:Ee((R=d.value[n])==null?void 0:R[r])},null,8,de)])):c.colsFormat[r]==="rating"?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:3},e.renderList($e((T=d.value[n])==null?void 0:T[r]),(h,Ae)=>(e.openBlock(),e.createElementBlock("svg",{key:h+Ae,width:"14",viewBox:"0 0 24 24"},[e.createElementVNode("path",{d:`M9.15316 5.40838C10.4198 3.13613 11.0531 2 12 2C12.9469 2 13.5802 3.13612\r 14.8468 5.40837L15.1745 5.99623C15.5345 6.64193 15.7144 6.96479 15.9951\r 7.17781C16.2757 7.39083 16.6251 7.4699 17.3241 7.62805L17.9605 7.77203C20.4201\r 8.32856 21.65 8.60682 21.9426 9.54773C22.2352 10.4886 21.3968 11.4691 19.7199\r 13.4299L19.2861 13.9372C18.8096 14.4944 18.5713 14.773 18.4641 15.1177C18.357\r 15.4624 18.393 15.8341 18.465 16.5776L18.5306 17.2544C18.7841 19.8706 18.9109\r 21.1787 18.1449 21.7602C17.3788 22.3417 16.2273 21.8115 13.9243 20.7512L13.3285\r 20.4768C12.6741 20.1755 12.3469 20.0248 12 20.0248C11.6531 20.0248 11.3259\r 20.1755 10.6715 20.4768L10.0757 20.7512C7.77268 21.8115 6.62118 22.3417 5.85515\r 21.7602C5.08912 21.1787 5.21588 19.8706 5.4694 17.2544L5.53498 16.5776C5.60703\r 15.8341 5.64305 15.4624 5.53586 15.1177C5.42868 14.773 5.19043 14.4944 4.71392\r 13.9372L4.2801 13.4299C2.60325 11.4691 1.76482 10.4886 2.05742 9.54773C2.35002\r 8.60682 3.57986 8.32856 6.03954 7.77203L6.67589 7.62805C7.37485 7.4699 7.72433\r 7.39083 8.00494 7.17781C8.28555 6.96479 8.46553 6.64194 8.82547 5.99623L9.15316\r 5.40838Z`,fill:h?"#ffeb3b":"none",stroke:h?"#ffeb3b":"#000","stroke-width":"2","stroke-linecap":"round"},null,8,he)]))),128)):(W=(O=c.colsFormat[r]).includes)!=null&&W.call(O,"#")?(e.openBlock(),e.createElementBlock("div",{key:4,class:"cell_input",style:e.normalizeStyle([`justify-content: var(--column${r}-x-align, center)`,`align-items: var(--column${r}-y-align, center)`]),value:(P=d.value[n])==null?void 0:P[r],onDblclick:b,onBlur:y,onKeydown:[o[3]||(o[3]=e.withKeys(e.withModifiers(()=>{},["prevent"]),["enter"])),h=>K(h,c.colsFormat[r])],onKeyup:e.withKeys(y,["enter"]),onInput:h=>Ne(h,c.colsFormat[r])},e.toDisplayString(D((U=d.value[n])==null?void 0:U[r],c.colsFormat[r])),45,me)):typeof c.colsFormat[r]=="function"?(e.openBlock(),e.createElementBlock("div",{key:5,class:"cell_input",style:e.normalizeStyle([`justify-content: var(--column${r}-x-align, center)`,`align-items: var(--column${r}-y-align, center)`]),value:(v=d.value[n])==null?void 0:v[r],onDblclick:b,onBlur:y,onKeydown:[o[4]||(o[4]=e.withKeys(e.withModifiers(()=>{},["prevent"]),["enter"])),K],onKeyup:e.withKeys(y,["enter"]),onInput:h=>Me(h,c.colsFormat[r])},e.toDisplayString(c.colsFormat[r]((J=d.value[n])==null?void 0:J[r])),45,ue)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"border_line",style:e.normalizeStyle(`border-width: var(--row${n}-border, 0) var(--column${r}-border, 0)`)},null,4)],6)}),128))]))),128)),pe,ye],32)],4))}},[["__scopeId","data-v-7e4a8d91"]]);p.VueSheetzComponent=fe,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});