
/* eslint-disable */
// sd-skip-auto-import
import{markMergedCell}from"./table-util";function getClosestElement(e,t){if(Element.prototype.closest)return e.closest(t);do{if(e.msMatchesSelector(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null}const selection={getCellElementFromNode(e){if(!e)return null;const t=getClosestElement(e.parentElement||e.parentNode,"td,th");if(!t)return null;return t},getTableElementsFromCellElement(e){if(!e||!e.parentElement||!e.parentElement.parentElement)return null;const t=e.parentElement.parentElement;const l=["TBODY","THEAD"].includes(t.tagName)?t.parentElement:t;if(!l)return null;return l},getRangeByStartAndEndElement(e,t,l){l=markMergedCell(l);const n={start:{row:parseInt(e.attributes["data-row"].value),cell:parseInt(e.attributes["data-ceil"].value)},end:{row:parseInt(t.attributes["data-row"].value),cell:parseInt(t.attributes["data-ceil"].value)}};let r=Math.min(n.start.row,n.end.row);let a=Math.max(n.start.row,n.end.row);let s=Math.min(n.start.cell,n.end.cell);let o=Math.max(n.start.cell,n.end.cell);let i=false;while(false===i){const e=[];for(let t=r;t<=a;t++)for(let n=s;n<=o;n++){const r=l[t][n].merged;if(r){e.push(r.firstCell);e.push([r.firstCell[0],r.firstCell[1]+(r.colspan||0)]);e.push([r.firstCell[0]+(r.rowspan||0),r.firstCell[1]]);e.push([r.firstCell[0]+(r.rowspan||0),r.firstCell[1]+(r.colspan||0)])}}e.push([r,s]);e.push([r,o]);e.push([a,s]);e.push([a,o]);const t=Math.min(...e.map((e=>e[0])));const n=Math.max(...e.map((e=>e[0])));const u=Math.min(...e.map((e=>e[1])));const m=Math.max(...e.map((e=>e[1])));if(JSON.stringify([r,a,s,o])===JSON.stringify([t,n,u,m]))i=true;else[r,a,s,o]=[t,n,u,m]}return{start:{row:r,cell:s},end:{row:a,cell:o}}}};export default selection;