import{Q as e,X as t,Z as n}from"./runtime.worker-DciBQjX_.js";const r=`CSV import`,i=/\\|\/|\?|\*|\[|\]|:/g;function a(e){return((e??r).trim().replace(i,``).trim()||r).slice(0,31)}function o(r,i){let o=s(i?.separator),l=e(i?.anchor??`A1`),u=l.sheetName?.trim(),d=i?.sheetName?.trim();if(u&&d&&u!==d)throw Error(`CSV import specifies conflicting sheet names: "${d}" (options.sheetName) vs "${u}" (anchor).`);let f=a(u??d),p=n(l.ref);if(!p)throw Error(`CSV import anchor must be an A1 cell reference; received "${i?.anchor??`A1`}".`);let{bounds:m}=p;if(m.startRow!==m.endRow||m.startCol!==m.endCol)throw Error(`CSV import anchor must be a single cell reference; received "${i?.anchor??`A1`}".`);let h=c(r,o),g=h.length,_=g>0?h[0]?.length??0:0;if(g===0||_===0)return{sheetName:f,values:[]};let v={startRow:m.startRow,startCol:m.startCol,endRow:m.startRow+g-1,endCol:m.startCol+_-1};return{sheetName:f,values:h,rangeRef:t(v),rect:{r1:v.startRow,c1:v.startCol,r2:v.endRow,c2:v.endCol}}}function s(e){let t=e??`,`;if(t.length!==1)throw Error(`CSV import separator must be a single character; received "${t}".`);return t}function c(e,t){if(!e.trim())return[];let n=l(e,t);if(n.length===0)return[];let r=n.reduce((e,t)=>Math.max(e,t.length),0);return r===0?[]:n.map(e=>{if(e.length===r)return e;let t=e.slice();for(;t.length<r;)t.push(``);return t})}function l(e,t){let n=[],r=[],i=``,a=!1,o=()=>{r.push(i),i=``},s=()=>{n.push(r),r=[]};for(let n=0;n<e.length;n+=1){let r=e[n]??``;if(a){if(r===`"`){if(e[n+1]===`"`){i+=`"`,n+=1;continue}a=!1;continue}i+=r;continue}if(r===`"`){a=!0;continue}if(r===t){o();continue}if(r===`
`){o(),s();continue}if(r===`\r`){e[n+1]===`
`&&(n+=1),o(),s();continue}i+=r}for(o(),s();n.length>0;){let e=n[n.length-1]??[];if(!(e.length>0&&e.every(e=>e===``)))break;n.pop()}return n}export{o as planCsvImport,a as sanitizeSheetName};
//# sourceMappingURL=workbook-from-csv-UVGLnNAc.js.map