let x=[];function I(){const e=new Date,t=String(e.getFullYear()).padStart(4,"0"),u=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0"),g=Math.random().toString(36).toUpperCase().substring(2,6);return`BOM_${t}${u}${a}_${g}`}function k(){x=[{name:"BOM编号",value:I()},{name:"图纸文件名",value:t=>t.图纸文件名??t["物料名称/图纸名称"]}]}let S=null,w=null;async function $(){return await import("./exceljs.min-8XQPYeYl.js").then(function(t){return t.e})}async function j(){const e=await import("./xlsx-B9BSDMFH.js"),t=await import("./cpexcel.full-D_t_3Qa-.js");return e.set_cptable(t),e}function D(e){switch(e){case"png":return"image/png";case"jpg":case"jpeg":case"gif":case"bmp":return"image/jpeg";case"svg":return"image/svg+xml";case"webp":return"image/webp";default:return"image/jpeg"}}async function L(e,t,u={}){const{onError:a=null,headIndex:g=1}=u;try{S||(S=await j()),w||(w=await $());const o=new w.Workbook;await o.xlsx.load(e);const p=new Map;o.eachSheet((l,M)=>{l.getImages().forEach(c=>{const m=o.model.media.find(r=>r.index===c.imageId);if(m){const r=`${c.range.tl.nativeRow},${c.range.tl.nativeCol}`;p.set(r,m)}})}),k();const d=S.read(e,{type:"buffer",raw:!0,codepage:65001}),f=Math.max(+g-1,0),h=d.SheetNames.map(l=>{var m;const M=d.Sheets[l],c=S.utils.sheet_to_json(M,{header:1,raw:!1,range:f});if(c.length<=1)return null;try{const r=(m=c[0])==null?void 0:m.map(s=>({name:String(s).trim()}));r.push(...x.map(s=>({name:s.name})));const X=c.slice(1).map((s,y)=>{const i={};for(let n=0;n<s.length;n++){const v=s[n],E=`${y+1+f},${n}`;if(v!=null)i[r[n].name]=String(v);else{const b=p.get(E);b&&(i[r[n].name]=new Blob([b.buffer],{type:D(b.extension)}))}}if(Object.keys(i).length>1)for(const n of x)i[n.name]=String(typeof n.value=="function"?n.value(i):n.value).trim();return i}).filter(s=>Object.values(s).some(y=>y!==null));return X.length?{name:l,tableData:{fields:r,records:X}}:null}catch{return a&&a({message:"message.sheetError",payload:{sheetName:l}}),null}}).filter(l=>l!==null);return h.length===0?(a&&a({message:"message.noSheet"}),null):{sheets:h,name:t}}catch(o){return a&&a({message:"message.fileError",error:o}),null}}onmessage=async function(e){const{data:t}=e,{type:u,payload:a}=t;if(u==="readXLSX"){const{data:g,name:o,headIndex:p}=a,d=await L(g,o,{onError:({message:f,payload:h})=>postMessage({type:"error",payload:{message:f,payload:h}}),headIndex:p});postMessage({type:"readXLSX",payload:d})}};
