Files
PhoneViewer/public/wasm/dwg-worker.js
T

25 lines
161 KiB
JavaScript
Raw Normal View History

2026-10-26 18:07:00 +08:00
var Ze=Object.defineProperty;var qe=(t,n,o)=>n in t?Ze(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o;var M=(t,n,o)=>qe(t,typeof n!="symbol"?n+"":n,o);const Qe="modulepreload",je=function(t){return"/"+t},le={},Ee=function(n,o,e){let a=Promise.resolve();if(o&&o.length>0){let d=function(c){return Promise.all(c.map(E=>Promise.resolve(E).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};var r=d;document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),_=s?.nonce||s?.getAttribute("nonce");a=d(o.map(c=>{if(c=je(c),c in le)return;le[c]=!0;const E=c.endsWith(".css"),u=E?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${u}`))return;const l=document.createElement("link");if(l.rel=E?"stylesheet":Qe,E||(l.as="script"),l.crossOrigin="",l.href=c,_&&l.setAttribute("nonce",_),document.head.appendChild(l),E)return new Promise((I,f)=>{l.addEventListener("load",I),l.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${c}`)))})}))}function i(s){const _=new Event("vite:preloadError",{cancelable:!0});if(_.payload=s,window.dispatchEvent(_),!_.defaultPrevented)throw s}return a.then(s=>{for(const _ of s||[])_.status==="rejected"&&i(_.reason);return n().catch(i)})};function to(t){return{format:t.format,sourceName:t.sourceName,units:t.units,header:t.header??{},layers:t.layers??{},lineTypes:t.lineTypes??{},blocks:t.blocks??{},entities:t.entities??[],pages:t.pages,savedView:t.savedView,dataLinks:t.dataLinks,dataTables:t.dataTables,xrecords:t.xrecords,dictionaries:t.dictionaries,metadata:t.metadata??{},warnings:t.warnings??[],raw:t.raw}}function ue(t){switch(String(t??"").toUpperCase()){case"LINE":return"line";case"CIRCLE":return"circle";case"ARC":return"arc";case"LWPOLYLINE":case"POLYLINE":case"POLYLINE_2D":case"POLYLINE2D":case"POLYLINE_3D":case"POLYLINE3D":case"LEADER":case"MULTILEADER":return"polyline";case"ELLIPSE":return"ellipse";case"TEXT":case"MTEXT":case"ATTRIB":case"ATTDEF":case"DIMENSION":return"text";case"POINT":return"point";case"INSERT":case"MINSERT":return"insert";case"SOLID":case"TRACE":case"3DFACE":return"solid";case"HATCH":return"hatch";case"SPLINE":return"spline";case"PATH":case"XPS_PATH":case"DWF_PATH":return"path";case"IMAGE":case"RASTER_IMAGE":case"DWF_IMAGE":return"image";case"VIEWPORT":return"viewport";case"TABLE":case"ACAD_TABLE":case"ACDBTABLE":return"table";default:return"unsupported"}}function Re(t,n,o={}){const e=n??String(t.type??t.entityType??t.objectName??"UNKNOWN").toUpperCase(),a=o.includeUnknownProperties===!1?{type:e,kind:ue(e)}:{...t,type:e,kind:ue(e)};o.keepRaw&&(a.raw=t),a.handle=y(t.handle??t.id),a.layer=y(t.layer??t.layerName),a.lineType=y(t.lineType??t.linetype),a.lineTypeScale=P(t.lineTypeScale??t.linetypeScale??t.ltscale)??a.lineTypeScale,a.flag=P(t.flag??t.flags)??a.flag,a.constantWidth=P(t.constantWidth??t.constWidth??t.const_width)??a.constantWidth,a.thickness=P(t.thickness)??a.thickness;const i=t.isClosed===!0||t.closed===!0||t.shape===!0,r=/^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D|SPLINE)$/.test(e),s=e==="LWPOLYLINE";(i||r&&(Number(a.flag??0)&1)===1||s&&(Number(a.flag??0)&512)===512)&&(a.isClosed=!0);const _=o.numericColorMode??"auto",d=P(t.color),c=P(t.colorIndex??t.colorNumber??t.aci??t.aciColor??t.color_index);a.colorIndex=c??(_!=="rgb"&&d!==void 0&&Math.abs(d)<=257?d:void 0);const E=t.trueColor??t.true_color??t.truecolor??t.colorRGB??t.colorRgb??t.rgbColor??t.rgb,u=d!==void 0&&d>=0&&d<=16777215&&(_==="rgb"||_==="auto"&&Math.abs(d)>257);a.trueColor=E??(u?d:void 0),(typeof t.color=="string"||typeof t.color=="number")&&(a.color=t.color),a.colorNumber=P(t.colorNumber)??a.colorNumber,a.colorName=y(t.colorName??t.color_name)??a.colorName,a.fillColor=t.fillColor??t.fill_color,a.fillColorIndex=P(t.fillColorIndex??t.fill_color_index??t.fillColorNumber)??a.fillColorIndex,a.opacity=P(t.opacity??t.alpha)??a.opacity,a.lineweight=P(t.lineweight??t.lineWeight),a.isVisible=!(t.isVisible===!1||t.visible===!1);const l=O(t.text);a.startPoint=b(t.startPoint??l?.startPoint??t.start??t
`).replace(/\\[LOlo]/g,"").replace(/\\[Ff][^;\\]*?(?:\|[^;\\]*)*;/g,"").replace(/\\[KkCcHhWwTtAa][^;\\]*;?/g,"").replace(/\\[a-zA-Z]+;?/g,"").replace(/%%(d|p|c|%)/gi,"").replace(/\\\\/g,"\\").replace(/\\~/g," ").replace(/[{}]/g,"").split(`
`).map(o=>o.trim()).filter(o=>o.length>0)}lines(n,o,e,a,i="start"){const r=new k().expandByPoint({x:e.x,y:e.y}).expandByPoint({x:e.x+a,y:e.y-n.length*o*1.5}),s=n.map((_,d)=>{const c=e.x,E=e.y-d*o*1.5,u=`translate(${c},${E}) scale(1,-1) translate(${-c},${-E})`;return`<text x="${c}" y="${E}" font-size="${o}" text-anchor="${i}" transform="${u}">${_}</text>`});return{bbox:r,element:s.join(`
`)}}mtext(n){const o=n.textHeight,e=n.insertionPoint,a=this.extractMTextLines(n.text),i=n.attachmentPoint;let r="start";return i==J.BottomCenter||i==J.MiddleCenter||i==J.TopCenter?r="middle":(i==J.BottomRight||i==J.MiddleRight||i==J.TopRight)&&(r="end"),this.lines(a,o,e,n.extentsWidth,r)}table(n){const{rowCount:o,columnCount:e,rowHeightArr:a,columnWidthArr:i,startPoint:r,cells:s}=n,_=r.x,d=r.y,c=[];for(let A=0,h=d;A<o;A++){const g=a[A];let p=_;for(let C=0;C<e;C++){const L=A*e+C,R=s[L],D=i[C];c.push({x:p,y:h,width:D,height:g,cell:R,row:A,col:C}),p+=D}h+=g}const E=c.map(({x:A,y:h,width:g,height:p,cell:C})=>{const L=[];C.topBorderVisibility&&L.push(`<line x1="${A}" y1="${h}" x2="${A+g}" y2="${h}" stroke="black" />`),C.bottomBorderVisibility&&L.push(`<line x1="${A}" y1="${h+p}" x2="${A+g}" y2="${h+p}" stroke="black" />`),C.leftBorderVisibility&&L.push(`<line x1="${A}" y1="${h}" x2="${A}" y2="${h+p}" stroke="black" />`),C.rightBorderVisibility&&L.push(`<line x1="${A+g}" y1="${h}" x2="${A+g}" y2="${h+p}" stroke="black" />`);const R=A+g/2,D=h+p/2+C.textHeight/3,Y=`<text x="${R}" y="${D}" font-size="${C.textHeight}" text-anchor="middle" dominant-baseline="middle">${C.text}</text>`;return[...L,Y].join(`
`)}).join(`
`),u=i.reduce((A,h)=>A+h,0),l=a.reduce((A,h)=>A+h,0),I=new k().expandByPoint({x:_,y:d}).expandByPoint({x:_+u,y:d+l}),f=`
<svg xmlns="http://www.w3.org/2000/svg" width="${u}" height="${l}" viewBox="${_} ${d} ${u} ${l}">
${E}
</svg>
`.trim();return{bbox:I,element:f}}text(n){const o=n.textHeight,e=n.startPoint,a=[n.text];let i=n.endPoint.x-n.endPoint.x;n.halign==0&&(i=n.text.length*o+n.startPoint.x);let r="start";return n.halign==Dt.CENTER?r="middle":n.halign==Dt.RIGHT&&(r="end"),this.lines(a,o,e,i,r)}vertices(n,o=!1){const e=n.reduce((i,r)=>i.expandByPoint(r),new k);let a=n.reduce((i,r,s)=>(i+=s===0?"M":"L",i+=r.x+","+r.y,i),"");return o&&(a+="Z"),{bbox:e,element:`<path d="${a}" />`}}circle(n){const o=new k().expandByPoint({x:n.center.x+n.radius,y:n.center.y+n.radius}).expandByPoint({x:n.center.x-n.radius,y:n.center.y-n.radius}),e=`<circle cx="${n.center.x}" cy="${n.center.y}" r="${n.radius}" />`;return{bbox:o,element:e}}ellipseOrArc(n,o,e,a,i,r,s){const _=Math.sqrt(e*e+a*a),d=i*_,c=-Math.atan2(-a,e),E=this.bboxEllipseOrArc(n,o,e,a,i,r,s);if(Math.abs(r-s)<1e-9||Math.abs(r-s+Math.PI*2)<1e-9){const u=`<g transform="rotate(${c/Math.PI*180} ${n}, ${o})"><ellipse cx="${n}" cy="${o}" rx="${_}" ry="${d}" /></g>`;return{bbox:E,element:u}}else{const u=this.rotate({x:Math.cos(r)*_,y:Math.sin(r)*d},c),l={x:n+u.x,y:o+u.y},I=this.rotate({x:Math.cos(s)*_,y:Math.sin(s)*d},c),f={x:n+I.x,y:o+I.y},h=(s<r?s+Math.PI*2:s)-r<Math.PI?0:1,p=`<path d="${`M ${l.x} ${l.y} A ${_} ${d} ${c/Math.PI*180} ${h} 1 ${f.x} ${f.y}`}" />`;return{bbox:E,element:p}}}bboxEllipseOrArc(n,o,e,a,i,r,s){for(;r<0;)r+=Math.PI*2;for(;s<=r;)s+=Math.PI*2;const _=[];if(Math.abs(e)<1e-12||Math.abs(a)<1e-12)for(let l=0;l<4;l++)_.push(l/2*Math.PI);else _[0]=Math.atan(-a*i/e)-Math.PI,_[1]=Math.atan(e*i/a)-Math.PI,_[2]=_[0]-Math.PI,_[3]=_[1]-Math.PI;for(let l=4;l>=0;l--){for(;_[l]<r;)_[l]+=Math.PI*2;_[l]>s&&_.splice(l,1)}_.push(r),_.push(s);const d=_.map(l=>({x:Math.cos(l),y:Math.sin(l)})),c=[[e,-a*i],[a,e*i]];return d.map(l=>({x:l.x*c[0][0]+l.y*c[0][1]+n,y:l.x*c[1][0]+l.y*c[1][1]+o})).reduce((l,I)=>(l.expandByPoint(I),l),new k)}ellipse(n){const{bbox:o,element:e}=this.ellipseOrArc(n.center.x,n.center.y,n.majorAxisEndPoint.x,n.majorAxisEndPoint.y,n.axisRatio,n.startAngle,n.endAngle);return{bbox:o,element:e}}arc(n){const{bbox:o,element:e}=this.ellipseOrArc(n.center.x,n.center.y,n.radius,0,1,n.startAngle,n.endAngle);return{bbox:o,element:e}}dimension(n){const o=this.blockMap.get(n.name);return o?{bbox:o.bbox,element:`<use href="#${n.name}" />`}:null}insert(n){const o=this.blockMap.get(n.name);if(o){const e=n.insertionPoint,a=n.rotation*(180/Math.PI),i=`translate(${e.x},${e.y}) rotate(${a}) scale(${n.xScale},${n.yScale})`;return{bbox:o.bbox.clone().transform({x:n.xScale,y:n.yScale},{x:e.x,y:e.y}).rotate(n.rotation,e),element:`<use href="#${n.name}" transform="${i}" />`}}return null}block(n,o){const e=n.entities,{bbox:a,elements:i}=e.reduce((r,s)=>{const _=this.entityToBoundsAndElement(s);if(_){const{bbox:d,element:c}=_;d.valid&&(r.bbox.expandByPoint(d.min),r.bbox.expandByPoint(d.max));const E=this.getEntityColor(o.tables.LAYER.entries,s),u=s.type=="TEXT"||s.type=="MTEXT"?E.cssColor:"none";E.isByBlock?r.elements.push(`<g id="${s.handle}">${c}</g>`):r.elements.push(`<g id="${s.handle}" stroke="${E.cssColor}" fill="${u}">${c}</g>`)}return r},{bbox:new k,elements:[]});return a.valid?{bbox:a,element:`<g id="${n.name}">${i.join(`
`)}</g>`}:null}entityToBoundsAndElement(n){let o=null;switch(n.type){case"ARC":o=this.arc(n);break;case"CIRCLE":o=this.circle(n);break;case"DIMENSION":o=this.dimension(n);break;case"ELLIPSE":o=this.ellipse(n);break;case"INSERT":o=this.insert(n);break;case"LINE":o=this.line(n);break;case"LWPOLYLINE":{const e=n,a=!!(e.flag&512),i=aa(e,a);o=this.vertices(i,a);break}case"MTEXT":o=this.mtext(n);break;case"SPLINE":{const e=n;o=this.vertices(this.interpolateBSpline(e.controlPoints,e.degree,e.knots,25,e.weights));break}case"POLYLINE":break;case"RAY":o=this.ray(n);break;case"TABLE":case"ACAD_TABLE":o=this.table(n);break;case"TEXT":o=this.text(n);break;case"XLINE":o=this.xline(n);break;default:o=null;break}return o?this.addFlipXIfApplicable(n,o):null}getEntityColor(n,o){const e=new te;if(o.colorIndex!=null?e.colorIndex=o.colorIndex:o.colorName?e.colorName=o.colorName:o.color!=null&&(e.color=o.color),e.colorIndex==7&&(e.colorIndex=256),e.isByLayer){const a=n.find(i=>i.name===o.layer);a!=null&&(e.colorIndex=a.colorIndex)}return e.color==null&&(e.color=16777215),e}convert(n){let o=null;this.blockMap.clear();let e="";n.tables.BLOCK_RECORD.entries.forEach(r=>{if(Oe(r.name))o=r;else{const s=this.block(r,n);s&&(e+=s.element,this.blockMap.set(r.name,s))}});const a=this.block(o,n),i=a&&a.bbox.valid?{x:a.bbox.min.x,y:-a.bbox.max.y,width:a.bbox.max.x-a.bbox.min.x,height:a.bbox.max.y-a.bbox.min.y}:{x:0,y:0,width:0,height:0};return`<?xml version="1.0"?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
preserveAspectRatio="xMinYMin meet"
viewBox="${i.x} ${i.y} ${i.width} ${i.height}"
width="100%" height="100%"
>
<defs>${e}</defs>
<g stroke="#000000" stroke-width="0.1%" fill="none" transform="matrix(1,0,0,-1,0,0)">
${a?a.element:""}
</g>
</svg>`}}var ne;(function(t){t[t.BMP=2]="BMP",t[t.WMF=3]="WMF",t[t.PNG=6]="PNG"})(ne||(ne={}));const _n=class _n{constructor(n){M(this,"wasmInstance");M(this,"decoder");return this.wasmInstance=n,new Proxy(this,{get:(o,e,a)=>e in o?Reflect.get(o,e,a):Reflect.get(o.wasmInstance,e,a)})}dwg_read_data(n,o){if(o==rn.DWG){const e="tmp.dwg";try{this.wasmInstance.FS.writeFile(e,new Uint8Array(n));const a=this.wasmInstance.dwg_read_file(e);if(a.error&an.OUTOFMEM)throw this.wasmInstance.dwg_abandon(a.data),new Error("Failed to decode DWG: out of WASM memory. Rebuild with pnpm build:wasm (INITIAL_MEMORY=1GB) or use a smaller file.");return a.error!=0&&console.warn("Open dwg file with error code:",a.error),a.data}finally{this.wasmInstance.FS.analyzePath(e,!1).exists&&this.wasmInstance.FS.unlink(e)}}}dwg_write_dxf(n){const o="tmp.dwg",e="tmp.dxf";try{this.wasmInstance.FS.writeFile(o,new Uint8Array(n));const a=this.wasmInstance.dwg_write_dxf(o,e);return a!=0?(console.log("Convert dwg to dxf with error code: ",a),null):this.wasmInstance.FS.readFile(e)}finally{this.wasmInstance.FS.analyzePath(o,!1).exists&&this.wasmInstance.FS.unlink(o),this.wasmInstance.FS.analyzePath(e,!1).exists&&this.wasmInstance.FS.unlink(e)}}dwg_get_version_type(n){const o=this.wasmInstance.dwg_get_version_type(n);return be[o]}dwg_get_codepage(n){return this.wasmInstance.dwg_get_codepage(n)}dwg_bmp(n){return this.wasmInstance.dwg_bmp(n)}dwg_get_num_classes(n){return this.wasmInstance.dwg_get_num_classes(n)}dwg_get_class(n,o){return this.wasmInstance.dwg_get_class(n,o)}convert(n){const o=this.dwg_get_codepage(n),e=bn(o);return this.decoder=new TextDecoder(e),new ye(this).convert(n)}convertEx(n){const o=this.dwg_get_codepage(n),e=bn(o);this.decoder=new TextDecoder(e);const a=new ye(this);return{database:a.convert(n),stats:a.getConversionStats()}}dwg_to_svg(n){return new ia().convert(n)}dwg_free(n){if(n)try{this.wasmInstance.dwg_free(n)}catch{try{this.wasmInstance.dwg_abandon(n)}catch{}}}dwg_free_object(n){this.wasmInstance.dwg_free_object(n)}dwg_ref_object(n,o){return this.wasmInstance.dwg_ref_object(n,o)}dwg_ref_object_silent(n,o){return this.wasmInstance.dwg_ref_object_silent(n,o)}dwg_ref_object_relative(n,o,e){return this.wasmInstance.dwg_ref_object_relative(n,o,e)}dwg_resolve_handle(n,o){return this.wasmInstance.dwg_resolve_handle(n,o)}dwg_resolve_handle_silent(n,o){return this.wasmInstance.dwg_resolve_handle_silent(n,o)}dwg_resolve_handleref(n,o){return this.wasmInstance.dwg_resolve_handleref(n,o)}dwg_ref_get_absref(n){if(!n)return null;const o=this.wasmInstance.dwg_ref_get_absref(n);return o===0?null:o}dwg_ref_get_handle_value(n){if(!n)return null;const o=this.wasmInstance.dwg_ref_get_handle_value(n);return o===0n?null:o}dwg_ref_get_handle_absolute_ref(n){if(!n)return null;const o=this.wasmInstance.dwg_ref_get_handle_absolute_ref(n);return o===0n?null:o}dwg_obj_get_handle_value(n){if(!n)return null;const o=this.wasmInstance.dwg_obj_get_handle_value(n);return o===0n?null:o}dwg_ref_get_id(n){const o=this.dwg_ref_get_absref(n);return o?.toString(16).toUpperCase()}dwg_ref_get_object_name(n){const o=this.wasmInstance,e=o.dwg_ref_get_object(n),a=o.dwg_object_to_object_tio(e);return this.dwg_dynapi_entity_data(a,"name")}dwg_obj_obj_to_object(n){return this.wasmInstance.dwg_obj_obj_to_object(n)}dwg_obj_generic_to_object(n){return this.wasmInstance.dwg_obj_generic_to_object(n)}dwg_object_to_object(n){return this.wasmInstance.dwg_object_to_object(n)}dwg_object_to_object_tio(n){return this.wasmInstance.dwg_object_to_object_tio(n)}dwg_object_to_entity(n){return this.wasmInstance.dwg_object_to_entity(n)}dwg_object_to_entity_tio(n){return this.wasmInstance.dwg_object_to_entity_tio(n)}dwg_getall_entities_in_model_space(n){const o=this.wasmInstance,e=o.dwg_model_space_object(n),a=[];let i=o.get_first_owned_entity(e);for(;i;)a.push(i),i=o.get_next_owned_entity(e,i);return a}dwg_getall_object_by_type(n,o){const e=this.wasmInstance,a=e.dwg_get_num_objects(n),i=[];for(let r=0;r<a;r++){const s=e.dwg_get_object(n,r),_=e.dwg_object_to_object_tio(s);_&&e.dwg_object_get_fixedtype(s)=
//# sourceMappingURL=dwg-worker.js.map