@flyfish-dev/cad-viewer 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/README.zh-CN.md +12 -1
- package/dist/cad-viewer.es.js +2211 -1824
- package/dist/cad-viewer.es.js.map +1 -1
- package/dist/cad-viewer.umd.cjs +7 -7
- package/dist/cad-viewer.umd.cjs.map +1 -1
- package/dist/types/core/entity.d.ts +3 -1
- package/dist/types/core/entity.d.ts.map +1 -1
- package/dist/types/core/linetype.d.ts +32 -0
- package/dist/types/core/linetype.d.ts.map +1 -0
- package/dist/types/core/scene.d.ts +8 -0
- package/dist/types/core/scene.d.ts.map +1 -0
- package/dist/types/core/transform.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +47 -0
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loaders/dwg/DwgParser.d.ts.map +1 -1
- package/dist/types/viewer/CadCanvasRenderer.d.ts +2 -0
- package/dist/types/viewer/CadCanvasRenderer.d.ts.map +1 -1
- package/dist/types/viewer/CadViewer.d.ts +1 -0
- package/dist/types/viewer/CadViewer.d.ts.map +1 -1
- package/dist/types/viewer/CadWebGLRenderer.d.ts +2 -0
- package/dist/types/viewer/CadWebGLRenderer.d.ts.map +1 -1
- package/dist/wasm/dwg-worker.js +8 -8
- package/dist/wasm/dwg-worker.js.map +1 -1
- package/package.json +4 -2
package/dist/cad-viewer.umd.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
(function(g,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("dwf-viewer")):typeof define=="function"&&define.amd?define(["exports","dwf-viewer"],C):(g=typeof globalThis<"u"?globalThis:g||self,C(g.LightweightCadViewer={},g.DwfViewerPackage))})(this,function(g,C){"use strict";var Nr=Object.defineProperty;var Mr=(g,C,M)=>C in g?Nr(g,C,{enumerable:!0,configurable:!0,writable:!0,value:M}):g[C]=M;var d=(g,C,M)=>Mr(g,typeof C!="symbol"?C+"":C,M);async function M(e){if(e.buffer instanceof Uint8Array)return e.buffer;if(e.buffer instanceof ArrayBuffer)return new Uint8Array(e.buffer);if(e.file)return new Uint8Array(await e.file.arrayBuffer());throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.")}function ue(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function W(e){var i;const t=e.fileName??((i=e.file)==null?void 0:i.name)??"",r=t.lastIndexOf(".");return r>=0?t.slice(r+1).toLowerCase():""}function L(e,t){const r=W(e);if(r==="dwg")return"dwg";if(r==="dxf")return"dxf";if(r==="dwfx")return"dwfx";if(r==="xps")return"xps";if(r==="dwf")return"dwf";if(t&&t.byteLength>=6){const i=Nt(t.slice(0,6));if(/^AC10/.test(i))return"dwg";if(t[0]===80&&t[1]===75)return"dwfx";const n=Nt(t.slice(0,Math.min(t.byteLength,2048))).toUpperCase();if(n.includes("SECTION")&&n.includes("ENTITIES"))return"dxf";if(n.includes("DWF"))return"dwf"}return"unknown"}function Nt(e){return Array.from(e,t=>t>=32&&t<=126?String.fromCharCode(t):" ").join("")}class Mt{constructor(t=[]){d(this,"loaders",[]);for(const r of t)this.register(r)}register(t){const r=this.loaders.findIndex(i=>i.id===t.id);return r>=0?this.loaders.splice(r,1,t):this.loaders.push(t),this}unregister(t){const r=this.loaders.findIndex(i=>i.id===t);return r>=0&&this.loaders.splice(r,1),this}list(){return[...this.loaders]}async detect(t){const r=await M(t),i=L(t,r),n=this.loaders.find(o=>o.formats.includes(i)&&o.accepts(t,r));if(n)return{loader:n,bytes:r,format:i};const s=this.loaders.find(o=>o.accepts(t,r));if(s)return{loader:s,bytes:r,format:i};throw new Error(`No CAD loader registered for ${i==="unknown"?"this file":i.toUpperCase()}.`)}async load(t,r={}){const{loader:i,bytes:n}=await this.detect(t);return i.load({...t,buffer:n},r)}}const me="wasm/dwg-worker.js";class Et{constructor(){d(this,"worker");d(this,"sequence",0);d(this,"pending",new Map)}load(t,r,i={}){var l,h;if(!Z())throw new Error("Web Worker is not available in this runtime.");const n=this.ensureWorker(i),s=++this.sequence,o=Math.max(0,Number(i.workerTimeoutMs??0)),a=i.fileName??r.fileName??((l=r.file)==null?void 0:l.name),c=ge(t,r,i);return(h=i.onProgress)==null||h.call(i,{phase:"worker-start",format:"dwg",message:"Dispatching DWG parse to worker…",total:t.byteLength}),new Promise((f,u)=>{var b;if((b=i.signal)!=null&&b.aborted){u(K());return}const p={resolve:f,reject:u,onProgress:i.onProgress,signal:i.signal};o>0&&(p.timer=setTimeout(()=>{this.pending.delete(s),this.resetWorker(),u(new Error(`DWG worker timed out after ${o} ms.`))},o)),i.signal&&(p.abortHandler=()=>{this.pending.delete(s),this.resetWorker(),u(K())},i.signal.addEventListener("abort",p.abortHandler,{once:!0})),this.pending.set(s,p);try{n.postMessage({type:"load",requestId:s,bytes:c,fileName:a,options:It(i)},[c])}catch(E){this.pending.delete(s),q(p),u(E instanceof Error?E:new Error(String(E)))}})}preload(t={}){var s;if(!Z())return Promise.reject(new Error("Web Worker is not available in this runtime."));const r=this.ensureWorker(t),i=++this.sequence,n=Math.max(0,Number(t.workerTimeoutMs??0));return(s=t.onProgress)==null||s.call(t,{phase:"worker-start",format:"dwg",message:"Starting DWG worker warmup…"}),new Promise((o,a)=>{var l;if((l=t.signal)!=null&&l.aborted){a(K());return}const c={resolve:()=>o(),reject:a,onProgress:t.onProgress,signal:t.signal};n>0&&(c.timer=setTimeout(()=>{this.pending.delete(i),this.resetWorker(),a(new Error(`DWG worker warmup timed out after ${n} ms.`))},n)),t.signal&&(c.abortHandler=()=>{this.pending.delete(i),this.resetWorker(),a(K())},t.signal.addEventListener("abort",c.abortHandler,{once:!0})),this.pending.set(i,c);try{r.postMessage({type:"warmup",requestId:i,options:It(t)})}catch(h){this.pending.delete(i),q(c),a(h instanceof Error?h:new Error(String(h)))}})}terminate(){this.resetWorker()}ensureWorker(t){return this.worker||(this.worker=pe(t),this.worker.onmessage=r=>this.handleMessage(r.data),this.worker.onerror=r=>{const i=r.message||"DWG worker failed.";this.rejectAll(new Error(i)),this.resetWorker(!1)},this.worker.onmessageerror=()=>{this.rejectAll(new Error("DWG worker returned a message that could not be cloned.")),this.resetWorker(!1)}),this.worker}handleMessage(t){var n,s;if(t.type==="ready")return;const r=this.pending.get(t.requestId);if(!r)return;if(t.type==="progress"){(n=r.onProgress)==null||n.call(r,t.progress);return}if(this.pending.delete(t.requestId),q(r),t.type==="result"){r.resolve(t.result);return}if(t.type==="warmup-result"){(s=r.onProgress)==null||s.call(r,{phase:"worker-ready",format:"dwg",message:"DWG worker warmup complete.",percent:100,elapsedMs:t.elapsedMs}),r.resolve(void 0);return}const i=new Error(t.error.message);i.name=t.error.name||"DwgWorkerError",t.error.stack&&(i.stack=t.error.stack),r.reject(i)}rejectAll(t){for(const[,r]of this.pending)q(r),r.reject(t);this.pending.clear()}resetWorker(t=!0){var r;t&&this.rejectAll(new Error("DWG worker was terminated.")),(r=this.worker)==null||r.terminate(),this.worker=void 0}}function Z(){return typeof Worker<"u"&&typeof URL<"u"}function pe(e){return e.workerFactory?e.workerFactory():new Worker(ve(e.workerUrl),{type:"module",name:"lightweight-cad-dwg-loader"})}function It(e){return{wasmPath:be(e.wasmPath),includePaperSpace:e.includePaperSpace,maxInsertDepth:e.maxInsertDepth,keepRaw:!!e.keepRaw}}function ge(e,t,r){return!!t.file||r.transferInputBuffer===!0?ue(e):e.slice().buffer}function q(e){e.timer&&clearTimeout(e.timer),e.signal&&e.abortHandler&&e.signal.removeEventListener("abort",e.abortHandler)}function K(){if(typeof DOMException<"u")return new DOMException("DWG loading was aborted.","AbortError");const e=new Error("DWG loading was aborted.");return e.name="AbortError",e}function be(e){const t=((e==null?void 0:e.trim())||"/wasm").replace(/\/+$/,"");return t===""?Tt():Lt(t)?t:t.startsWith("/")?`${Tt()}${t}`:new URL(t,st()).href.replace(/\/+$/,"")}function ve(e){if(e instanceof URL)return e;const t=(e==null?void 0:e.trim())||me;return Lt(t)?t:new URL(t,st()).href}function st(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"http://localhost/"}function Tt(){return typeof location<"u"&&location.origin?location.origin:new URL(st()).origin}function Lt(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)}class At{constructor(t={}){d(this,"id","dwg");d(this,"label","DWG / LibreDWG WebAssembly");d(this,"formats",["dwg"]);d(this,"defaults");d(this,"workerClient",new Et);this.defaults={useWorker:!0,...t}}accepts(t,r){return W(t)==="dwg"?!0:L(t,r)==="dwg"}async load(t,r={}){var o,a;const i={...this.defaults,...r};(o=i.onProgress)==null||o.call(i,{phase:"read",format:"dwg",message:"Reading DWG bytes…"});const n=await M(t),s=t.fileName??((a=t.file)==null?void 0:a.name);if(i.useWorker===!1)throw new Error("DWG main-thread parsing is intentionally not bundled by the default viewer. Keep useWorker enabled, or register a custom DWG loader for non-browser runtimes.");if(!Z())throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");try{return await this.workerClient.load(n,t,{...i,fileName:s})}catch(c){throw ye(c)?c:we(c)}}terminateWorker(){this.workerClient.terminate()}preload(t={}){const r={...this.defaults,...t};return r.useWorker===!1?Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")):this.workerClient.preload(r)}}function ye(e){return e instanceof Error&&e.name==="AbortError"}function we(e){const t=e instanceof Error?e.message:String(e);return new Error(`${t} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`)}function ot(e){return{format:e.format,sourceName:e.sourceName,units:e.units,header:e.header??{},layers:e.layers??{},blocks:e.blocks??{},entities:e.entities??[],pages:e.pages,metadata:e.metadata??{},warnings:e.warnings??[],raw:e.raw}}function A(e){switch(String(e??"").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":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";default:return"unsupported"}}function Bt(e,t,r={}){const i=t??String(e.type??e.entityType??e.objectName??"UNKNOWN").toUpperCase(),n=r.includeUnknownProperties===!1?{type:i,kind:A(i)}:{...e,type:i,kind:A(i)};r.keepRaw&&(n.raw=e),n.handle=S(e.handle??e.id),n.layer=S(e.layer??e.layerName),n.lineType=S(e.lineType??e.linetype);const s=r.numericColorMode??"auto",o=w(e.color),a=w(e.colorIndex??e.colorNumber??e.aci??e.aciColor??e.color_index);n.colorIndex=a??(s!=="rgb"&&o!==void 0&&Math.abs(o)<=257?o:void 0);const c=e.trueColor??e.true_color??e.truecolor??e.colorRGB??e.colorRgb??e.rgbColor??e.rgb,l=o!==void 0&&o>=0&&o<=16777215&&(s==="rgb"||s==="auto"&&Math.abs(o)>257);n.trueColor=c??(l?o:void 0),(typeof e.color=="string"||typeof e.color=="number")&&(n.color=e.color),n.colorNumber=w(e.colorNumber)??n.colorNumber,n.colorName=S(e.colorName??e.color_name)??n.colorName,n.fillColor=e.fillColor??e.fill_color,n.fillColorIndex=w(e.fillColorIndex??e.fill_color_index??e.fillColorNumber)??n.fillColorIndex,n.opacity=w(e.opacity??e.alpha)??n.opacity,n.lineweight=w(e.lineweight??e.lineWeight),n.isVisible=!(e.isVisible===!1||e.visible===!1),n.startPoint=k(e.startPoint??e.start??e.p0??e.from)??n.startPoint,n.endPoint=k(e.endPoint??e.end??e.p1??e.to)??n.endPoint,n.center=k(e.center??e.centerPoint)??n.center,n.insertionPoint=k(e.insertionPoint??e.position??e.location??e.point??e.basePoint)??n.insertionPoint,n.radius=w(e.radius)??n.radius,n.startAngle=w(e.startAngle??e.start_angle)??n.startAngle,n.endAngle=w(e.endAngle??e.end_angle)??n.endAngle,n.majorAxisEndPoint=k(e.majorAxisEndPoint??e.majorAxis??e.major)??n.majorAxisEndPoint,n.axisRatio=w(e.axisRatio??e.ratio)??n.axisRatio,n.height=w(e.height??e.textHeight)??n.height,n.textHeight=w(e.textHeight??e.height)??n.textHeight,n.rotation=w(e.rotation??e.angle)??n.rotation,n.text=S(e.text??e.value??e.string??e.contents)??n.text,n.name=S(e.name??e.blockName)??n.name,n.blockName=S(e.blockName??e.name)??n.blockName;const h=at(e.vertices??e.points);h.length>0&&(n.vertices=h);const f=at(e.controlPoints??e.control_points);f.length>0&&(n.controlPoints=f);const u=at(e.fitPoints??e.fit_points);return u.length>0&&(n.fitPoints=u),n}function k(e){if(!e||typeof e!="object")return;const t=e,r=Number(t.x??t.X??t[0]),i=Number(t.y??t.Y??t[1]),n=t.z??t.Z??t[2],s=n===void 0?void 0:Number(n);if(!(!Number.isFinite(r)||!Number.isFinite(i)))return Number.isFinite(s)?{x:r,y:i,z:s}:{x:r,y:i}}function at(e){if(!Array.isArray(e))return[];const t=[];for(const r of e){const i=k(r);if(!i)continue;const n=r,s=i,o=w(n.bulge);o!==void 0&&(s.bulge=o);const a=w(n.startWidth??n.start_width);a!==void 0&&(s.startWidth=a);const c=w(n.endWidth??n.end_width);c!==void 0&&(s.endWidth=c),t.push(s)}return t}function X(e){var r;const t={};for(const i of e.entities){const n=String(i.type??"UNKNOWN").toUpperCase();t[n]=(t[n]??0)+1}return{format:e.format,sourceName:e.sourceName,entityCount:e.entities.length,layerCount:Object.keys(e.layers).length,blockCount:Object.keys(e.blocks).length,pageCount:((r=e.pages)==null?void 0:r.length)??0,byType:t,warnings:[...e.warnings]}}function Ft(e,t){t.name&&(e[t.name]=t,e[t.name.toLowerCase()]=t)}function xe(e,t){t.name&&(e[t.name]=t,e[t.name.toLowerCase()]=t)}function Ce(e){return e!=null&&e.length?e.flatMap(t=>t.entities.map(r=>({...r,pageIndex:t.index}))):[]}function w(e){const t=Number(e);return Number.isFinite(t)?t:void 0}function S(e){if(typeof e!="string"&&typeof e!="number")return;const t=String(e);return t.length>0?t:void 0}function I(){return{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function R(e){return Number.isFinite(e.minX)&&Number.isFinite(e.minY)&&Number.isFinite(e.maxX)&&Number.isFinite(e.maxY)&&e.maxX>=e.minX&&e.maxY>=e.minY}function y(e,t){m(t)&&(e.minX=Math.min(e.minX,t.x),e.minY=Math.min(e.minY,t.y),e.maxX=Math.max(e.maxX,t.x),e.maxY=Math.max(e.maxY,t.y))}function Dt(e,t,r){if(!m(t)||!Number.isFinite(r))return;const i=Math.abs(r);y(e,{x:t.x-i,y:t.y-i}),y(e,{x:t.x+i,y:t.y+i})}function Wt(e,t=.02,r=1e-6){if(!R(e))return{minX:-10,minY:-10,maxX:10,maxY:10};const i=Math.max((e.maxX-e.minX)*t,r),n=Math.max((e.maxY-e.minY)*t,r);return{minX:e.minX-i,minY:e.minY-n,maxX:e.maxX+i,maxY:e.maxY+n}}function m(e){return!!e&&typeof e=="object"&&Number.isFinite(e.x)&&Number.isFinite(e.y)}function x(e){return{x:e.x,y:e.y}}function B(e){return e*Math.PI/180}function J(e,t,r,i,n=!0,s=64){if(!m(e)||!Number.isFinite(t))return[];let o=r,a=i;if(!Number.isFinite(o)||!Number.isFinite(a))return[];(Math.abs(o)>Math.PI*2+1e-6||Math.abs(a)>Math.PI*2+1e-6)&&(o=B(o),a=B(a)),n&&a<o&&(a+=Math.PI*2),!n&&o<a&&(o+=Math.PI*2);const c=a-o,l=Math.max(8,Math.min(256,Math.ceil(Math.abs(c)/(Math.PI*2)*s))),h=[];for(let f=0;f<=l;f++){const u=o+c*(f/l);h.push({x:e.x+Math.cos(u)*t,y:e.y+Math.sin(u)*t})}return h}function Q(e,t,r=1,i=0,n=Math.PI*2,s=96){if(!m(e)||!m(t))return[];const o=Math.hypot(t.x,t.y);if(!Number.isFinite(o)||o<=0)return[];const a=o*(Number.isFinite(r)&&r>0?r:1),c=Math.atan2(t.y,t.x);let l=Number.isFinite(i)?i:0,h=Number.isFinite(n)?n:Math.PI*2;(Math.abs(l)>Math.PI*2+1e-6||Math.abs(h)>Math.PI*2+1e-6)&&(l=B(l),h=B(h)),h<l&&(h+=Math.PI*2);const f=Math.max(12,Math.min(256,Math.ceil(Math.abs(h-l)/(Math.PI*2)*s))),u=[],p=Math.cos(c),b=Math.sin(c);for(let E=0;E<=f;E++){const $=l+(h-l)*(E/f),j=Math.cos($)*o,G=Math.sin($)*a;u.push({x:e.x+j*p-G*b,y:e.y+j*b+G*p})}return u}function Rt(e,t,r=0,i=16){if(!Number.isFinite(r)||Math.abs(r)<1e-12)return[x(e),x(t)];const n=Math.hypot(t.x-e.x,t.y-e.y);if(n<=1e-12)return[x(e),x(t)];const s=4*Math.atan(r),o=Math.abs(n/(2*Math.sin(s/2))),a={x:(e.x+t.x)/2,y:(e.y+t.y)/2},c=(t.x-e.x)/n,l=(t.y-e.y)/n,h=r>=0?1:-1,f=Math.sqrt(Math.max(o*o-(n/2)**2,0)),u={x:a.x-h*l*f,y:a.y+h*c*f},p=Math.atan2(e.y-u.y,e.x-u.x),b=Math.atan2(t.y-u.y,t.x-u.x);return J(u,o,p,b,r>=0,i)}function Ot(e){return e.replace(/\\P/g,`
|
|
2
|
-
`).replace(/\\~|\\ /g," ").replace(/\\[A-Za-z][^;]*;/g,"").replace(/[{}]/g,"").replace(/\\[A-Za-z]/g,"").trim()}function
|
|
1
|
+
(function(v,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("dwf-viewer")):typeof define=="function"&&define.amd?define(["exports","dwf-viewer"],M):(v=typeof globalThis<"u"?globalThis:v||self,M(v.LightweightCadViewer={},v.DwfViewerPackage))})(this,function(v,M){"use strict";var ur=Object.defineProperty;var mr=(v,M,T)=>M in v?ur(v,M,{enumerable:!0,configurable:!0,writable:!0,value:T}):v[M]=T;var u=(v,M,T)=>mr(v,typeof M!="symbol"?M+"":M,T);async function T(t){if(t.buffer instanceof Uint8Array)return t.buffer;if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer);if(t.file)return new Uint8Array(await t.file.arrayBuffer());throw new Error("CadLoadInput requires a File, ArrayBuffer, or Uint8Array.")}function Rt(t){return t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:t.slice().buffer}function X(t){var r;const e=t.fileName??((r=t.file)==null?void 0:r.name)??"",n=e.lastIndexOf(".");return n>=0?e.slice(n+1).toLowerCase():""}function R(t,e){const n=X(t);if(n==="dwg")return"dwg";if(n==="dxf")return"dxf";if(n==="dwfx")return"dwfx";if(n==="xps")return"xps";if(n==="dwf")return"dwf";if(e&&e.byteLength>=6){const r=Xe(e.slice(0,6));if(/^AC10/.test(r))return"dwg";if(e[0]===80&&e[1]===75)return"dwfx";const i=Xe(e.slice(0,Math.min(e.byteLength,2048))).toUpperCase();if(i.includes("SECTION")&&i.includes("ENTITIES"))return"dxf";if(i.includes("DWF"))return"dwf"}return"unknown"}function Xe(t){return Array.from(t,e=>e>=32&&e<=126?String.fromCharCode(e):" ").join("")}class je{constructor(e=[]){u(this,"loaders",[]);for(const n of e)this.register(n)}register(e){const n=this.loaders.findIndex(r=>r.id===e.id);return n>=0?this.loaders.splice(n,1,e):this.loaders.push(e),this}unregister(e){const n=this.loaders.findIndex(r=>r.id===e);return n>=0&&this.loaders.splice(n,1),this}list(){return[...this.loaders]}async detect(e){const n=await T(e),r=R(e,n),i=this.loaders.find(s=>s.formats.includes(r)&&s.accepts(e,n));if(i)return{loader:i,bytes:n,format:r};const o=this.loaders.find(s=>s.accepts(e,n));if(o)return{loader:o,bytes:n,format:r};throw new Error(`No CAD loader registered for ${r==="unknown"?"this file":r.toUpperCase()}.`)}async load(e,n={}){const{loader:r,bytes:i}=await this.detect(e);return r.load({...e,buffer:i},n)}}const Ot="wasm/dwg-worker.js";class $e{constructor(){u(this,"worker");u(this,"sequence",0);u(this,"pending",new Map)}load(e,n,r={}){var l,f;if(!ie())throw new Error("Web Worker is not available in this runtime.");const i=this.ensureWorker(r),o=++this.sequence,s=Math.max(0,Number(r.workerTimeoutMs??0)),a=r.fileName??n.fileName??((l=n.file)==null?void 0:l.name),c=zt(e,n,r);return(f=r.onProgress)==null||f.call(r,{phase:"worker-start",format:"dwg",message:"Dispatching DWG parse to worker…",total:e.byteLength}),new Promise((h,d)=>{var g;if((g=r.signal)!=null&&g.aborted){d(oe());return}const m={resolve:h,reject:d,onProgress:r.onProgress,signal:r.signal};s>0&&(m.timer=setTimeout(()=>{this.pending.delete(o),this.resetWorker(),d(new Error(`DWG worker timed out after ${s} ms.`))},s)),r.signal&&(m.abortHandler=()=>{this.pending.delete(o),this.resetWorker(),d(oe())},r.signal.addEventListener("abort",m.abortHandler,{once:!0})),this.pending.set(o,m);try{i.postMessage({type:"load",requestId:o,bytes:c,fileName:a,options:Ge(r)},[c])}catch(S){this.pending.delete(o),se(m),d(S instanceof Error?S:new Error(String(S)))}})}preload(e={}){var o;if(!ie())return Promise.reject(new Error("Web Worker is not available in this runtime."));const n=this.ensureWorker(e),r=++this.sequence,i=Math.max(0,Number(e.workerTimeoutMs??0));return(o=e.onProgress)==null||o.call(e,{phase:"worker-start",format:"dwg",message:"Starting DWG worker warmup…"}),new Promise((s,a)=>{var l;if((l=e.signal)!=null&&l.aborted){a(oe());return}const c={resolve:()=>s(),reject:a,onProgress:e.onProgress,signal:e.signal};i>0&&(c.timer=setTimeout(()=>{this.pending.delete(r),this.resetWorker(),a(new Error(`DWG worker warmup timed out after ${i} ms.`))},i)),e.signal&&(c.abortHandler=()=>{this.pending.delete(r),this.resetWorker(),a(oe())},e.signal.addEventListener("abort",c.abortHandler,{once:!0})),this.pending.set(r,c);try{n.postMessage({type:"warmup",requestId:r,options:Ge(e)})}catch(f){this.pending.delete(r),se(c),a(f instanceof Error?f:new Error(String(f)))}})}terminate(){this.resetWorker()}ensureWorker(e){return this.worker||(this.worker=Wt(e),this.worker.onmessage=n=>this.handleMessage(n.data),this.worker.onerror=n=>{const r=n.message||"DWG worker failed.";this.rejectAll(new Error(r)),this.resetWorker(!1)},this.worker.onmessageerror=()=>{this.rejectAll(new Error("DWG worker returned a message that could not be cloned.")),this.resetWorker(!1)}),this.worker}handleMessage(e){var i,o;if(e.type==="ready")return;const n=this.pending.get(e.requestId);if(!n)return;if(e.type==="progress"){(i=n.onProgress)==null||i.call(n,e.progress);return}if(this.pending.delete(e.requestId),se(n),e.type==="result"){n.resolve(e.result);return}if(e.type==="warmup-result"){(o=n.onProgress)==null||o.call(n,{phase:"worker-ready",format:"dwg",message:"DWG worker warmup complete.",percent:100,elapsedMs:e.elapsedMs}),n.resolve(void 0);return}const r=new Error(e.error.message);r.name=e.error.name||"DwgWorkerError",e.error.stack&&(r.stack=e.error.stack),n.reject(r)}rejectAll(e){for(const[,n]of this.pending)se(n),n.reject(e);this.pending.clear()}resetWorker(e=!0){var n;e&&this.rejectAll(new Error("DWG worker was terminated.")),(n=this.worker)==null||n.terminate(),this.worker=void 0}}function ie(){return typeof Worker<"u"&&typeof URL<"u"}function Wt(t){return t.workerFactory?t.workerFactory():new Worker(Yt(t.workerUrl),{type:"module",name:"lightweight-cad-dwg-loader"})}function Ge(t){return{wasmPath:_t(t.wasmPath),includePaperSpace:t.includePaperSpace,maxInsertDepth:t.maxInsertDepth,keepRaw:!!t.keepRaw}}function zt(t,e,n){return!!e.file||n.transferInputBuffer===!0?Rt(t):t.slice().buffer}function se(t){t.timer&&clearTimeout(t.timer),t.signal&&t.abortHandler&&t.signal.removeEventListener("abort",t.abortHandler)}function oe(){if(typeof DOMException<"u")return new DOMException("DWG loading was aborted.","AbortError");const t=new Error("DWG loading was aborted.");return t.name="AbortError",t}function _t(t){const e=((t==null?void 0:t.trim())||"/wasm").replace(/\/+$/,"");return e===""?Ze():qe(e)?e:e.startsWith("/")?`${Ze()}${e}`:new URL(e,we()).href.replace(/\/+$/,"")}function Yt(t){if(t instanceof URL)return t;const e=(t==null?void 0:t.trim())||Ot;return qe(e)?e:new URL(e,we()).href}function we(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"http://localhost/"}function Ze(){return typeof location<"u"&&location.origin?location.origin:new URL(we()).origin}function qe(t){return/^[a-z][a-z0-9+.-]*:/i.test(t)}class Ke{constructor(e={}){u(this,"id","dwg");u(this,"label","DWG / LibreDWG WebAssembly");u(this,"formats",["dwg"]);u(this,"defaults");u(this,"workerClient",new $e);this.defaults={useWorker:!0,...e}}accepts(e,n){return X(e)==="dwg"?!0:R(e,n)==="dwg"}async load(e,n={}){var s,a;const r={...this.defaults,...n};(s=r.onProgress)==null||s.call(r,{phase:"read",format:"dwg",message:"Reading DWG bytes…"});const i=await T(e),o=e.fileName??((a=e.file)==null?void 0:a.name);if(r.useWorker===!1)throw new Error("DWG main-thread parsing is intentionally not bundled by the default viewer. Keep useWorker enabled, or register a custom DWG loader for non-browser runtimes.");if(!ie())throw new Error("DWG loading requires Web Worker support in this build. Provide a custom loader for this runtime.");try{return await this.workerClient.load(i,e,{...r,fileName:o})}catch(c){throw Vt(c)?c:Ht(c)}}terminateWorker(){this.workerClient.terminate()}preload(e={}){const n={...this.defaults,...e};return n.useWorker===!1?Promise.reject(new Error("DWG preload requires worker mode in the default viewer.")):this.workerClient.preload(n)}}function Vt(t){return t instanceof Error&&t.name==="AbortError"}function Ht(t){const e=t instanceof Error?t.message:String(t);return new Error(`${e} If the worker asset cannot be resolved by your bundler/CDN, pass workerUrl or workerFactory to CadViewer.`)}function ae(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,metadata:t.metadata??{},warnings:t.warnings??[],raw:t.raw}}function O(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":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";default:return"unsupported"}}function ce(t,e,n={}){const r=e??String(t.type??t.entityType??t.objectName??"UNKNOWN").toUpperCase(),i=n.includeUnknownProperties===!1?{type:r,kind:O(r)}:{...t,type:r,kind:O(r)};n.keepRaw&&(i.raw=t),i.handle=P(t.handle??t.id),i.layer=P(t.layer??t.layerName),i.lineType=P(t.lineType??t.linetype),i.lineTypeScale=b(t.lineTypeScale??t.linetypeScale??t.ltscale)??i.lineTypeScale,i.flag=b(t.flag??t.flags)??i.flag;const o=t.isClosed===!0||t.closed===!0||t.shape===!0,s=/^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D|SPLINE)$/.test(r),a=r==="LWPOLYLINE";(o||s&&(Number(i.flag??0)&1)===1||a&&(Number(i.flag??0)&512)===512)&&(i.isClosed=!0);const c=n.numericColorMode??"auto",l=b(t.color),f=b(t.colorIndex??t.colorNumber??t.aci??t.aciColor??t.color_index);i.colorIndex=f??(c!=="rgb"&&l!==void 0&&Math.abs(l)<=257?l:void 0);const h=t.trueColor??t.true_color??t.truecolor??t.colorRGB??t.colorRgb??t.rgbColor??t.rgb,d=l!==void 0&&l>=0&&l<=16777215&&(c==="rgb"||c==="auto"&&Math.abs(l)>257);i.trueColor=h??(d?l:void 0),(typeof t.color=="string"||typeof t.color=="number")&&(i.color=t.color),i.colorNumber=b(t.colorNumber)??i.colorNumber,i.colorName=P(t.colorName??t.color_name)??i.colorName,i.fillColor=t.fillColor??t.fill_color,i.fillColorIndex=b(t.fillColorIndex??t.fill_color_index??t.fillColorNumber)??i.fillColorIndex,i.opacity=b(t.opacity??t.alpha)??i.opacity,i.lineweight=b(t.lineweight??t.lineWeight),i.isVisible=!(t.isVisible===!1||t.visible===!1),i.startPoint=N(t.startPoint??t.start??t.p0??t.from)??i.startPoint,i.endPoint=N(t.endPoint??t.end??t.p1??t.to)??i.endPoint,i.center=N(t.center??t.centerPoint)??i.center,i.insertionPoint=N(t.insertionPoint??t.position??t.location??t.point??t.basePoint)??i.insertionPoint,i.radius=b(t.radius)??i.radius,i.startAngle=b(t.startAngle??t.start_angle)??i.startAngle,i.endAngle=b(t.endAngle??t.end_angle)??i.endAngle,i.majorAxisEndPoint=N(t.majorAxisEndPoint??t.majorAxis??t.major)??i.majorAxisEndPoint,i.axisRatio=b(t.axisRatio??t.ratio)??i.axisRatio,i.height=b(t.height??t.textHeight)??i.height,i.textHeight=b(t.textHeight??t.height)??i.textHeight,i.rotation=b(t.rotation??t.angle)??i.rotation,i.text=P(t.text??t.value??t.string??t.contents)??i.text,i.name=P(t.name??t.blockName)??i.name,i.blockName=P(t.blockName??t.name)??i.blockName;const m=xe(t.vertices??t.points);m.length>0&&(i.vertices=m);const g=xe(t.controlPoints??t.control_points);g.length>0&&(i.controlPoints=g);const S=xe(t.fitPoints??t.fit_points);S.length>0&&(i.fitPoints=S);const y=t.attribs??t.attributes;return Array.isArray(y)&&(i.attribs=y.filter(x=>!!x&&typeof x=="object").map(x=>ce(x,void 0,n))),i}function N(t){if(!t||typeof t!="object")return;const e=t,n=Number(e.x??e.X??e[0]),r=Number(e.y??e.Y??e[1]),i=e.z??e.Z??e[2],o=i===void 0?void 0:Number(i);if(!(!Number.isFinite(n)||!Number.isFinite(r)))return Number.isFinite(o)?{x:n,y:r,z:o}:{x:n,y:r}}function xe(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const r=N(n);if(!r)continue;const i=n,o=r,s=b(i.bulge);s!==void 0&&(o.bulge=s);const a=b(i.startWidth??i.start_width);a!==void 0&&(o.startWidth=a);const c=b(i.endWidth??i.end_width);c!==void 0&&(o.endWidth=c),e.push(o)}return e}function J(t){var n;const e={};for(const r of t.entities){const i=String(r.type??"UNKNOWN").toUpperCase();e[i]=(e[i]??0)+1}return{format:t.format,sourceName:t.sourceName,entityCount:t.entities.length,layerCount:Object.keys(t.layers).length,blockCount:Object.keys(t.blocks).length,pageCount:((n=t.pages)==null?void 0:n.length)??0,byType:e,warnings:[...t.warnings]}}function Ce(t){if(t.isClosed===!0)return!0;const e=String(t.type??"").toUpperCase(),n=Number(t.flag??0);return e==="LWPOLYLINE"?(n&512)===512:/^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D)$/.test(e)?(n&1)===1:!1}function Pe(t,e){e.name&&(t[e.name]=e,t[e.name.toLowerCase()]=e)}function Je(t,e){e.name&&(t[e.name]=e,t[e.name.toLowerCase()]=e)}function Ut(t,e){e.name&&(t[e.name]=e,t[e.name.toLowerCase()]=e,e.handle&&(t[e.handle]=e,t[e.handle.toLowerCase()]=e))}function Xt(t){return t!=null&&t.length?t.flatMap(e=>e.entities.map(n=>({...n,pageIndex:e.index}))):[]}function b(t){const e=Number(t);return Number.isFinite(e)?e:void 0}function P(t){if(typeof t!="string"&&typeof t!="number")return;const e=String(t);return e.length>0?e:void 0}function B(){return{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function j(t){return Number.isFinite(t.minX)&&Number.isFinite(t.minY)&&Number.isFinite(t.maxX)&&Number.isFinite(t.maxY)&&t.maxX>=t.minX&&t.maxY>=t.minY}function C(t,e){p(e)&&(t.minX=Math.min(t.minX,e.x),t.minY=Math.min(t.minY,e.y),t.maxX=Math.max(t.maxX,e.x),t.maxY=Math.max(t.maxY,e.y))}function Qe(t,e,n){if(!p(e)||!Number.isFinite(n))return;const r=Math.abs(n);C(t,{x:e.x-r,y:e.y-r}),C(t,{x:e.x+r,y:e.y+r})}function et(t,e=.02,n=1e-6){if(!j(t))return{minX:-10,minY:-10,maxX:10,maxY:10};const r=Math.max((t.maxX-t.minX)*e,n),i=Math.max((t.maxY-t.minY)*e,n);return{minX:t.minX-r,minY:t.minY-i,maxX:t.maxX+r,maxY:t.maxY+i}}function p(t){return!!t&&typeof t=="object"&&Number.isFinite(t.x)&&Number.isFinite(t.y)}function k(t){return{x:t.x,y:t.y}}function W(t){return t*Math.PI/180}function Q(t,e,n,r,i=!0,o=64){if(!p(t)||!Number.isFinite(e))return[];let s=n,a=r;if(!Number.isFinite(s)||!Number.isFinite(a))return[];(Math.abs(s)>Math.PI*2+1e-6||Math.abs(a)>Math.PI*2+1e-6)&&(s=W(s),a=W(a)),i&&a<s&&(a+=Math.PI*2),!i&&s<a&&(s+=Math.PI*2);const c=a-s,l=Math.max(8,Math.min(256,Math.ceil(Math.abs(c)/(Math.PI*2)*o))),f=[];for(let h=0;h<=l;h++){const d=s+c*(h/l);f.push({x:t.x+Math.cos(d)*e,y:t.y+Math.sin(d)*e})}return f}function le(t,e,n=1,r=0,i=Math.PI*2,o=96){if(!p(t)||!p(e))return[];const s=Math.hypot(e.x,e.y);if(!Number.isFinite(s)||s<=0)return[];const a=s*(Number.isFinite(n)&&n>0?n:1),c=Math.atan2(e.y,e.x);let l=Number.isFinite(r)?r:0,f=Number.isFinite(i)?i:Math.PI*2;(Math.abs(l)>Math.PI*2+1e-6||Math.abs(f)>Math.PI*2+1e-6)&&(l=W(l),f=W(f)),f<l&&(f+=Math.PI*2);const h=Math.max(12,Math.min(256,Math.ceil(Math.abs(f-l)/(Math.PI*2)*o))),d=[],m=Math.cos(c),g=Math.sin(c);for(let S=0;S<=h;S++){const y=l+(f-l)*(S/h),x=Math.cos(y)*s,L=Math.sin(y)*a;d.push({x:t.x+x*m-L*g,y:t.y+x*g+L*m})}return d}function tt(t,e,n=0,r=16){if(!Number.isFinite(n)||Math.abs(n)<1e-12)return[k(t),k(e)];const i=Math.hypot(e.x-t.x,e.y-t.y);if(i<=1e-12)return[k(t),k(e)];const o=4*Math.atan(n),s=Math.abs(i/(2*Math.sin(o/2))),a={x:(t.x+e.x)/2,y:(t.y+e.y)/2},c=(e.x-t.x)/i,l=(e.y-t.y)/i,f=n>=0?1:-1,h=Math.sqrt(Math.max(s*s-(i/2)**2,0)),d={x:a.x-f*l*h,y:a.y+f*c*h},m=Math.atan2(t.y-d.y,t.x-d.x),g=Math.atan2(e.y-d.y,e.x-d.x);return Q(d,s,m,g,n>=0,r)}function nt(t){return t.replace(/\\P/g,`
|
|
2
|
+
`).replace(/\\~|\\ /g," ").replace(/\\[A-Za-z][^;]*;/g,"").replace(/[{}]/g,"").replace(/\\[A-Za-z]/g,"").trim()}function $(t,e,n){return Math.min(n,Math.max(e,t))}class rt{constructor(e={}){u(this,"id","dxf");u(this,"label","DXF / JavaScript parser");u(this,"formats",["dxf"]);u(this,"defaults");this.defaults=e}accepts(e,n){return X(e)==="dxf"||R(e,n)==="dxf"}async load(e,n={}){var h;const r={...this.defaults,...n},i=performance.now(),o=await T(e),s=Qt(o,r.dxfEncoding),a=[];let c;try{c=await jt(s)}catch(d){a.push(`dxf-parser failed, using built-in fallback parser: ${d instanceof Error?d.message:String(d)}`),c=on(s)}const l=$t(c,e.fileName??((h=e.file)==null?void 0:h.name),a),f=performance.now()-i;return{document:l,raw:c,bytes:o.byteLength,elapsedMs:f,format:"dxf",warnings:l.warnings}}}async function jt(t){const e=await import("dxf-parser"),n=e.default??e.DxfParser;if(!n)throw new Error("dxf-parser did not expose a parser constructor.");return new n().parseSync(t)}function $t(t,e,n=[]){const r=t&&typeof t=="object"?t:{},i=Gt(r),o=Zt(r),a=(Array.isArray(r.entities)?r.entities:[]).filter(l=>!!l&&typeof l=="object").map(l=>ke(l)),c=ae({format:"dxf",sourceName:e,header:r.header&&typeof r.header=="object"?r.header:{},layers:i,blocks:o,entities:a,metadata:{parser:"dxf-parser + cad-viewer normalizer"},warnings:n,raw:t});return a.length===0&&c.warnings.push("DXF file did not expose any ENTITIES."),c}function ke(t){const e=String(t.type??t.entityType??"UNKNOWN").toUpperCase(),n=ce(t,e),r=b(t.colorIndex??t.colorNumber??t.aci),i=b(t.color);if(n.colorIndex=r??(i!==void 0&&Math.abs(i)<=257?i:void 0),n.trueColor=t.trueColor??t.true_color??t.colorRGB??t.trueColorValue??(i!==void 0&&Math.abs(i)>257?i:void 0),n.layer=P(t.layer??t.layerName)??"0",n.isClosed=!!(t.shape??t.closed??t.isClosed)||(Number(t.flag??t.flags??0)&1)===1,e==="LINE"&&(n.startPoint=N(t.startPoint??{x:t.x1??t.x,y:t.y1??t.y,z:t.z1??t.z})??n.startPoint,n.endPoint=N(t.endPoint??{x:t.x2,y:t.y2,z:t.z2})??n.endPoint),(e==="TEXT"||e==="MTEXT"||e==="ATTRIB"||e==="ATTDEF")&&(n.insertionPoint=N(t.startPoint??t.position??t.insertionPoint)??n.insertionPoint,n.text=sn(t.text??t.string??t.value)??n.text,n.textHeight=b(t.textHeight??t.height)??n.textHeight,n.rotation=st(t.rotation??t.angle)),(e==="ARC"||e==="ELLIPSE")&&(n.startAngle=ot(t.startAngle??t.start_angle),n.endAngle=ot(t.endAngle??t.end_angle)),e==="INSERT"){n.blockName=P(t.name??t.blockName)??n.blockName,n.insertionPoint=N(t.position??t.insertionPoint??t.point)??n.insertionPoint;const o=b(t.xScale??t.scaleX??t.xscale),s=b(t.yScale??t.scaleY??t.yscale),a=b(t.zScale??t.scaleZ??t.zscale);(o!==void 0||s!==void 0||a!==void 0)&&(n.scale={x:o??1,y:s??o??1,z:a??1}),n.rotation=st(t.rotation??t.angle)}if(e==="SPLINE"){const o=fe(t.controlPoints??t.control_points??t.points);o.length&&(n.controlPoints=o);const s=fe(t.fitPoints??t.fit_points);s.length&&(n.fitPoints=s)}return e==="HATCH"&&(n.loops=Jt(t),n.fillColorIndex=n.colorIndex),(e==="SOLID"||e==="TRACE"||e==="3DFACE")&&(n.vertices=Kt(t),n.fillColorIndex=n.colorIndex),n}function Gt(t){const e={},n=t.tables,r=t.layers??(n==null?void 0:n.layer)??(n==null?void 0:n.LAYER)??(n==null?void 0:n.layers),i=qt(r);for(const o of i){const s=o,a=P(s.name??s.layerName);a&&Pe(e,{name:a,color:s.color??s.colorNumber??s.colorIndex,colorIndex:b(s.colorNumber??s.colorIndex??s.color),lineType:P(s.lineType??s.linetype),isVisible:Number(s.colorNumber??s.colorIndex??s.color??1)>=0,isFrozen:!!s.frozen,isLocked:!!s.locked,raw:s})}return e[0]||Pe(e,{name:"0",colorIndex:7,isVisible:!0}),e}function Zt(t){const e={},n=t.blocks;if(!n||typeof n!="object")return e;if(Array.isArray(n))for(const r of n)it(e,r);else for(const[r,i]of Object.entries(n))it(e,i,r);return e}function it(t,e,n){if(!e||typeof e!="object")return;const r=e,i=P(r.name??r.blockName??n);if(!i)return;const s=(Array.isArray(r.entities)?r.entities:[]).filter(a=>!!a&&typeof a=="object").map(a=>ke(a));Je(t,{name:i,basePoint:N(r.basePoint??r.position)??{x:0,y:0},entities:s,raw:r})}function qt(t){if(!t)return[];if(Array.isArray(t))return t;if(typeof t!="object")return[];const e=t;return Array.isArray(e.entries)?e.entries:Array.isArray(e.records)?e.records:Array.isArray(e.layers)?e.layers:Object.values(e).filter(n=>n&&typeof n=="object")}function fe(t){return Array.isArray(t)?t.map(N).filter(e=>!!e):[]}function Kt(t){const e=fe(t.vertices??t.points);if(e.length)return e;const n=[];for(let r=0;r<4;r++){const i=N({x:t[`x${r}`]??t[`x${r+1}`],y:t[`y${r}`]??t[`y${r+1}`],z:t[`z${r}`]??t[`z${r+1}`]});i&&n.push(i)}return n}function Jt(t){const e=t.boundaryLoops??t.loops??t.paths;if(Array.isArray(e))return e.map(n=>{const r=n;return{vertices:fe(r.vertices??r.points),isClosed:!0}}).filter(n=>n.vertices&&n.vertices.length>0)}function st(t){const e=b(t);if(e!==void 0)return Math.abs(e)>Math.PI*2+1e-6?W(e):e}function ot(t){const e=b(t);if(e!==void 0)return Math.abs(e)>Math.PI*2+1e-6?W(e):e}function Qt(t,e){const n=Se(e);if(n)return z(t,n);const r=en(t);if(r)return z(t,r);const i=Se(tn(t));if(i)return z(t,i);const o=z(t,"utf-8");return o.includes("�")?nn(t):o}const at={ANSI_874:"windows-874",ANSI_932:"shift_jis",ANSI_936:"gb18030",ANSI_949:"euc-kr",ANSI_950:"big5",ANSI_1250:"windows-1250",ANSI_1251:"windows-1251",ANSI_1252:"windows-1252",ANSI_1253:"windows-1253",ANSI_1254:"windows-1254",ANSI_1255:"windows-1255",ANSI_1256:"windows-1256",ANSI_1257:"windows-1257",ANSI_1258:"windows-1258",BIG5:"big5",CP874:"windows-874",CP932:"shift_jis",CP936:"gb18030",CP949:"euc-kr",CP950:"big5",CP1250:"windows-1250",CP1251:"windows-1251",CP1252:"windows-1252",CP1253:"windows-1253",CP1254:"windows-1254",CP1255:"windows-1255",CP1256:"windows-1256",CP1257:"windows-1257",CP1258:"windows-1258",GB18030:"gb18030",GB2312:"gb18030",GBK:"gb18030",SHIFT_JIS:"shift_jis",SHIFTJIS:"shift_jis",SJIS:"shift_jis",UTF8:"utf-8",UTF_8:"utf-8",UTF16:"utf-16le",UTF_16:"utf-16le",UTF16LE:"utf-16le",UTF_16LE:"utf-16le",UTF16BE:"utf-16be",UTF_16BE:"utf-16be"};function en(t){if(t.length>=3&&t[0]===239&&t[1]===187&&t[2]===191)return"utf-8";if(t.length>=2&&t[0]===255&&t[1]===254)return"utf-16le";if(t.length>=2&&t[0]===254&&t[1]===255)return"utf-16be"}function tn(t){var r,i,o,s;const n=z(t.subarray(0,Math.min(t.byteLength,131072)),"iso-8859-1").replace(/\r\n/g,`
|
|
3
3
|
`).replace(/\r/g,`
|
|
4
4
|
`).split(`
|
|
5
|
-
`);for(let a=0;a<
|
|
6
|
-
`)}function
|
|
5
|
+
`);for(let a=0;a<n.length-3;a++)if(!(((r=n[a])==null?void 0:r.trim())!=="9"||((i=n[a+1])==null?void 0:i.trim().toUpperCase())!=="$DWGCODEPAGE"))for(let c=a+2;c<Math.min(a+10,n.length-1);c+=2){const l=(o=n[c])==null?void 0:o.trim(),f=(s=n[c+1])==null?void 0:s.trim();if(l==="3"&&f)return f}}function Se(t){const e=t==null?void 0:t.trim();if(!e)return;const n=e.replace(/[-\s]+/g,"_").toUpperCase();if(at[n])return at[n];const r=/^ANSI_(\d{3,4})$/.exec(n);if(r)return Se(`cp${r[1]}`);const i=/^CP(\d{3,4})$/.exec(n);return i?i[1]==="936"?"gb18030":i[1]==="950"?"big5":i[1]==="932"?"shift_jis":i[1]==="949"?"euc-kr":`windows-${i[1]}`:e}function z(t,e){try{return new TextDecoder(e,{fatal:!1}).decode(t)}catch{return new TextDecoder("utf-8",{fatal:!1}).decode(t)}}function nn(t){const e=["windows-1252","gb18030","big5","shift_jis","euc-kr","iso-8859-1"];let n="",r=Number.POSITIVE_INFINITY;for(const i of e){const o=z(t,i),s=rn(o,i);s<r&&(r=s,n=o)}return n||z(t,"utf-8")}function rn(t,e){const n=Ne(t,/\uFFFD/g),r=Ne(t,/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g),i=Ne(t,/[\u3400-\u9FFF\uF900-\uFAFF]/g),o=t.includes("SECTION")&&(t.includes("ENTITIES")||t.includes("HEADER"));let s=n*1e4+r*1e3;return o&&(s-=500),e==="windows-1252"&&(s-=2),e==="gb18030"&&i>=2&&(s-=50+Math.min(i,200)*2),s}function Ne(t,e){var n;return((n=t.match(e))==null?void 0:n.length)??0}function sn(t){const e=P(t);if(e!==void 0)return e.replace(/\\U\+([0-9a-fA-F]{4,6})/g,(n,r)=>{const i=Number.parseInt(r,16);return Number.isFinite(i)&&i>=0&&i<=1114111?String.fromCodePoint(i):n}).replace(/%%[cC]/g,"∅").replace(/%%[dD]/g,"°").replace(/%%[pP]/g,"±").replace(/\\P/g,`
|
|
6
|
+
`)}function on(t){var l,f;const e=t.replace(/\r\n/g,`
|
|
7
7
|
`).replace(/\r/g,`
|
|
8
8
|
`).split(`
|
|
9
|
-
`),r=[];for(let f=0;f<t.length-1;f+=2){const u=Number((l=t[f])==null?void 0:l.trim()),p=t[f+1]??"";Number.isFinite(u)&&r.push({code:u,value:p.trimEnd()})}const i=[],n={};let s="",o=[],a;for(let f=0;f<r.length;f++){const u=r[f];if(u.code===0&&u.value==="SECTION"){s=((h=r[f+1])==null?void 0:h.code)===2?r[f+1].value.toUpperCase():"",f++;continue}if(u.code===0&&u.value==="ENDSEC"){c(),s="";continue}s==="ENTITIES"&&(u.code===0?(c(),o=[u]):o.push(u))}return c(),{header:{},tables:{},entities:i,blocks:n};function c(){var p;if(!o.length)return;const f=(p=o[0])==null?void 0:p.value.toUpperCase();if(f==="VERTEX"&&a){const b=P(o,10,20,30);b&&(a.vertices??(a.vertices=[])).push({...b,bulge:v(o,42)}),o=[];return}if(f==="SEQEND"){a&&i.push(a),a=void 0,o=[];return}if(a&&(i.push(a),a=void 0),!f||f==="EOF"){o=[];return}const u=Re(f,o);f==="POLYLINE"?a=u:i.push(u),o=[]}}function Re(e,t){const r={type:e,handle:U(t,5),layer:U(t,8)??"0",colorIndex:v(t,62),trueColor:v(t,420),lineType:U(t,6),lineweight:v(t,370)};switch(e){case"LINE":Object.assign(r,{startPoint:P(t,10,20,30),endPoint:P(t,11,21,31)});break;case"CIRCLE":Object.assign(r,{center:P(t,10,20,30),radius:v(t,40)});break;case"ARC":Object.assign(r,{center:P(t,10,20,30),radius:v(t,40),startAngle:et(v(t,50)),endAngle:et(v(t,51))});break;case"POINT":Object.assign(r,{point:P(t,10,20,30)});break;case"TEXT":case"MTEXT":Object.assign(r,{insertionPoint:P(t,10,20,30),text:_e(t),textHeight:v(t,40),rotation:et(v(t,50))});break;case"LWPOLYLINE":Object.assign(r,{vertices:ze(t),flag:v(t,70),isClosed:(Number(v(t,70)??0)&1)===1});break;case"POLYLINE":Object.assign(r,{vertices:[],flag:v(t,70),isClosed:(Number(v(t,70)??0)&1)===1});break;case"ELLIPSE":Object.assign(r,{center:P(t,10,20,30),majorAxisEndPoint:P(t,11,21,31),axisRatio:v(t,40),startAngle:v(t,41),endAngle:v(t,42)});break;case"SPLINE":Object.assign(r,{controlPoints:Oe(t,10,20,30),degree:v(t,71),isClosed:(Number(v(t,70)??0)&1)===1});break;case"INSERT":Object.assign(r,{name:U(t,2),blockName:U(t,2),insertionPoint:P(t,10,20,30),rotation:et(v(t,50)),scale:{x:v(t,41)??1,y:v(t,42)??v(t,41)??1,z:v(t,43)??1}});break;case"SOLID":case"TRACE":case"3DFACE":Object.assign(r,{vertices:[P(t,10,20,30),P(t,11,21,31),P(t,12,22,32),P(t,13,23,33)].filter(Boolean)});break}return ct(r)}function v(e,t){var n;const r=(n=e.find(s=>s.code===t))==null?void 0:n.value,i=Number(r);return Number.isFinite(i)?i:void 0}function U(e,t){var i;const r=(i=e.find(n=>n.code===t))==null?void 0:i.value;return r&&r.length>0?r:void 0}function P(e,t,r,i){const n=v(e,t),s=v(e,r),o=v(e,i);if(!(n===void 0||s===void 0))return o===void 0?{x:n,y:s}:{x:n,y:s,z:o}}function Oe(e,t,r,i){const n=[];for(let s=0;s<e.length;s++){if(e[s].code!==t)continue;const o=Number(e[s].value),a=e.slice(s+1).find(f=>f.code===r),c=e.slice(s+1).find(f=>f.code===i),l=Number(a==null?void 0:a.value),h=Number(c==null?void 0:c.value);Number.isFinite(o)&&Number.isFinite(l)&&n.push(Number.isFinite(h)?{x:o,y:l,z:h}:{x:o,y:l})}return n}function ze(e){const t=[];for(let r=0;r<e.length;r++){if(e[r].code!==10)continue;const i=Number(e[r].value);let n,s;for(let o=r+1;o<e.length&&e[o].code!==10;o++)e[o].code===20&&(n=Number(e[o].value)),e[o].code===42&&(s=Number(e[o].value));Number.isFinite(i)&&Number.isFinite(n)&&t.push({x:i,y:n,bulge:Number.isFinite(s)?s:void 0})}return t}function _e(e){const t=e.filter(r=>r.code===1||r.code===3).map(r=>r.value);return t.length?t.join(""):void 0}function et(e){return typeof e=="number"&&Number.isFinite(e)?B(e):void 0}class Ut{constructor(t={}){d(this,"id","dwf");d(this,"label","DWF/DWFx native viewer powered by dwf-viewer");d(this,"formats",["dwf","dwfx","xps"]);d(this,"nativeRenderer",!0);d(this,"defaults");d(this,"native");d(this,"host");d(this,"lastStats");this.defaults=t}accepts(t,r){const i=W(t);if(i==="dwf"||i==="dwfx"||i==="xps")return!0;const n=L(t,r);return n==="dwf"||n==="dwfx"||n==="xps"}async load(t,r={}){var f,u,p,b;const i={...this.defaults,...r},n=performance.now(),s=t.fileName??((f=t.file)==null?void 0:f.name),o=await M(t),a=jt(L(t,o),W(t));(u=i.onProgress)==null||u.call(i,{phase:"parse",format:a,message:"Opening DWF/DWFx with dwf-viewer…",percent:48});const c=await C.openDwfDocument(o,{fileName:s});(p=i.onProgress)==null||p.call(i,{phase:"normalize",format:a,message:"Reading DWF pages, sheets and model metadata…",percent:76});const l=Vt(c,s,a,i.keepRaw===!0),h=performance.now()-n;return(b=i.onProgress)==null||b.call(i,{phase:"done",format:l.format,message:"DWF/DWFx document ready.",percent:100,elapsedMs:h}),{document:l,raw:i.keepRaw?c:void 0,bytes:o.byteLength,elapsedMs:h,format:l.format,warnings:l.warnings}}async mount(t,r,i={}){var $,j,G,fe,de;const n={...this.defaults,...i},s=performance.now(),o=t.fileName??(($=t.file)==null?void 0:$.name),a=await M(t),c=jt(L(t,a),W(t)),l=Ve(n),h=Gt(n),f=$e(n,l,h),u=Zt(n,l,h);(j=n.onProgress)==null||j.call(n,{phase:"native-render",format:c,message:"Mounting native DWF renderer…",percent:28}),this.unmount(),this.host=r,r.replaceChildren(),this.native=new C.DwfViewer(r,f),(G=n.onProgress)==null||G.call(n,{phase:"parse",format:c,message:"Parsing DWF package and page streams…",percent:58}),await this.native.load(a,{fileName:o,...u}),(fe=n.onProgress)==null||fe.call(n,{phase:"render",format:c,message:"Rendering DWF/DWFx with dwf-viewer…",percent:88}),this.lastStats=await this.native.render();const p=this.native.getDocument(),b=Vt(p,o,c,n.keepRaw===!0);b.metadata.loaderMode="Native DWF",b.metadata.nativeRenderer="dwf-viewer",b.metadata.nativeRenderStats=this.lastStats?{...this.lastStats,warnings:this.lastStats.warnings.length}:void 0;const E=performance.now()-s;return(de=n.onProgress)==null||de.call(n,{phase:"done",format:b.format,message:"DWF/DWFx rendered.",percent:100,elapsedMs:E}),{document:b,raw:n.keepRaw?p:void 0,bytes:a.byteLength,elapsedMs:E,format:b.format,warnings:b.warnings}}unmount(){var t;(t=this.native)==null||t.dispose(),this.native=void 0,this.lastStats=void 0,this.host&&this.host.replaceChildren()}fit(){var t;(t=this.native)==null||t.fit()}zoomIn(){var r;const t=(r=this.native)==null?void 0:r.zoomInButton;t==null||t.click()}zoomOut(){var r;const t=(r=this.native)==null?void 0:r.zoomOutButton;t==null||t.click()}resize(){var t;(t=this.native)==null||t.render()}setNativeOptions(t){var i,n,s,o;const r=this.native;if(r){if(typeof t.dwfBackground=="string")r.background=t.dwfBackground;else{const a=Gt(t);a&&(r.background=a)}typeof t.dwfPreferWebgl=="boolean"&&((i=r.setPreferWebgl)==null||i.call(r,t.dwfPreferWebgl)),typeof t.dwfPreferWasm=="boolean"&&((n=r.setPreferWasm)==null||n.call(r,t.dwfPreferWasm)),t.dwfLineWeightMode&&((s=r.setLineWeightMode)==null||s.call(r,t.dwfLineWeightMode)),rt(r,"minStrokeCssPx",t.dwfMinStrokeCssPx),rt(r,"maxOverviewStrokeCssPx",t.dwfMaxOverviewStrokeCssPx),rt(r,"minTextCssPx",t.dwfMinTextCssPx),rt(r,"minFilledAreaCssPx",t.dwfMinFilledAreaCssPx),(o=r.render)==null||o.call(r)}}getLastNativeStats(){return this.lastStats}}function Vt(e,t,r,i){var a,c;const n=$t((e==null?void 0:e.diagnostics)??[]),s=((e==null?void 0:e.pageData)??[]).map((l,h)=>He(l,h));for(const l of(e==null?void 0:e.pageData)??[])n.push(...$t(l.diagnostics));const o={parser:"dwf-viewer",nativeRenderer:"dwf-viewer",dwfKind:e==null?void 0:e.kind,packageEntries:((a=e==null?void 0:e.packageEntries)==null?void 0:a.length)??0,resources:((c=e==null?void 0:e.resources)==null?void 0:c.length)??0,pageKinds:Ze(((e==null?void 0:e.pageData)??[]).map(l=>l.kind)),pageNames:((e==null?void 0:e.pages)??[]).map(l=>l.name)};return ot({format:r,sourceName:t,layers:{},blocks:{},pages:s,entities:Ce(s),metadata:o,warnings:qe(n),raw:i?e:void 0})}function He(e,t){const r=Ye(e,t);return{index:t,name:e.name||e.sourcePath||`${t+1}`,width:e.width||1e3,height:e.height||1e3,entities:r}}function Ye(e,t){return e.kind==="w2d-text"?e.primitives.flatMap((r,i)=>Xe(r,t,i)):e.kind==="image"?[{type:"DWF_IMAGE_PAGE",kind:"image",pageIndex:t,width:e.width,height:e.height,imageSource:e.sourcePath}]:e.kind==="w3d-model"?e.model.meshes.map((r,i)=>({id:r.id,type:"W3D_MESH",kind:"solid",pageIndex:t,color:r.color?Ge(r.color):void 0,name:r.name||`mesh-${i+1}`,raw:{vertexCount:r.vertexCount,triangleCount:r.triangleCount,materialId:r.materialId}})):e.kind==="xps-fixed-page"?[{type:"XPS_FIXED_PAGE",kind:"viewport",pageIndex:t,width:e.width,height:e.height,raw:{sourcePath:e.sourcePath}}]:[{type:"DWF_PAGE",kind:"viewport",pageIndex:t,width:e.width,height:e.height,raw:{sourcePath:e.sourcePath}}]}function Xe(e,t,r){const i={id:`dwf-${t}-${r}`,pageIndex:t,color:e.stroke,fillColor:e.fill,lineweight:e.lineWidth,raw:{matrix:e.matrix}};if(e.type==="polyline"||e.type==="polygon")return[{...i,type:e.type==="polygon"?"DWF_POLYGON":"DWF_POLYLINE",kind:"polyline",vertices:Ue(e.points),isClosed:e.type==="polygon"}];if(e.type==="path")return[{...i,type:"DWF_PATH",kind:"path",commands:e.commands}];if(e.type==="text")return[{...i,type:"DWF_TEXT",kind:"text",insertionPoint:{x:e.x,y:e.y,z:0},text:e.text,textHeight:e.size}];if(e.type==="rect"){const n=e.x,s=e.y,o=e.width,a=e.height;return[{...i,type:"DWF_RECT",kind:"polyline",isClosed:!0,vertices:[{x:n,y:s,z:0},{x:n+o,y:s,z:0},{x:n+o,y:s+a,z:0},{x:n,y:s+a,z:0}]}]}return[]}function Ue(e){const t=[];for(let r=0;r+1<e.length;r+=2)t.push({x:e[r],y:e[r+1],z:0});return t}function $t(e){return e.filter(t=>t.level!=="info").map(t=>`${t.code}: ${t.message}${t.source?` (${t.source})`:""}`)}function jt(e,t){return t==="dwf"||t==="dwfx"||t==="xps"?t:e==="dwf"||e==="dwfx"||e==="xps"?e:"dwf"}function Ve(e){if(e.dwfWasmUrl)return e.dwfWasmUrl;if(typeof document>"u")return;const t=e.wasmPath?new URL(je(e.wasmPath),document.baseURI).href:new URL("wasm/",document.baseURI).href;return new URL("dwfv-render.wasm",t).href}function Gt(e){if(e.dwfBackground)return e.dwfBackground;const t=e.canvasOptions;return(t==null?void 0:t.background)??"#05070d"}function $e(e,t,r){return{...Zt(e,t,r),maxDevicePixelRatio:e.dwfMaxDevicePixelRatio??2,maxCanvasPixels:e.dwfMaxCanvasPixels??16777216}}function Zt(e,t,r){return{wasmUrl:t,preferWebgl:e.dwfPreferWebgl??!0,preferWasm:e.dwfPreferWasm??!0,background:r,maxGpuCacheBytes:e.dwfMaxGpuCacheBytes??160*1024*1024,maxCachedScenes:e.dwfMaxCachedScenes??2,lineWeightMode:e.dwfLineWeightMode??"adaptive",minStrokeCssPx:e.dwfMinStrokeCssPx,maxOverviewStrokeCssPx:e.dwfMaxOverviewStrokeCssPx,minTextCssPx:e.dwfMinTextCssPx,minFilledAreaCssPx:e.dwfMinFilledAreaCssPx}}function rt(e,t,r){typeof r=="number"&&Number.isFinite(r)&&(e[t]=r)}function je(e){return e.endsWith("/")?e:`${e}/`}function Ge(e){const[t,r,i]=e.map(n=>Math.max(0,Math.min(255,Math.round(n*255))));return`#${ft(t)}${ft(r)}${ft(i)}`}function ft(e){return e.toString(16).padStart(2,"0")}function Ze(e){const t={};for(const r of e)t[r]=(t[r]??0)+1;return t}function qe(e){return Array.from(new Set(e))}function qt(e={}){return new Mt([new At(e),new zt(e),new Ut(e)])}function Kt(e){const t=e;return t.nativeRenderer===!0&&typeof t.mount=="function"}const Ke={1:"#ff0000",2:"#ffff00",3:"#00ff00",4:"#00ffff",5:"#0000ff",6:"#ff00ff",8:"#808080",9:"#c0c0c0",10:"#ff0000",11:"#ff7f7f",12:"#a50000",13:"#a55252",14:"#7f0000",15:"#7f3f3f",16:"#4c0000",17:"#4c2626",18:"#260000",19:"#261313",20:"#ff3f00",21:"#ff9f7f",22:"#a52900",23:"#a56752",24:"#7f1f00",25:"#7f4f3f",26:"#4c1300",27:"#4c2f26",28:"#260900",29:"#261713",30:"#ff7f00",31:"#ffbf7f",32:"#a55200",33:"#a57c52",34:"#7f3f00",35:"#7f5f3f",36:"#4c2600",37:"#4c3926",38:"#261300",39:"#261c13",40:"#ffbf00",41:"#ffdf7f",42:"#a57c00",43:"#a59152",44:"#7f5f00",45:"#7f6f3f",46:"#4c3900",47:"#4c4226",48:"#261c00",49:"#262113",50:"#ffff00",51:"#ffff7f",52:"#a5a500",53:"#a5a552",54:"#7f7f00",55:"#7f7f3f",56:"#4c4c00",57:"#4c4c26",58:"#262600",59:"#262613",60:"#bfff00",61:"#dfff7f",62:"#7ca500",63:"#91a552",64:"#5f7f00",65:"#6f7f3f",66:"#394c00",67:"#424c26",68:"#1c2600",69:"#212613",70:"#7fff00",71:"#bfff7f",72:"#52a500",73:"#7ca552",74:"#3f7f00",75:"#5f7f3f",76:"#264c00",77:"#394c26",78:"#132600",79:"#1c2613",80:"#3fff00",81:"#9fff7f",82:"#29a500",83:"#67a552",84:"#1f7f00",85:"#4f7f3f",86:"#134c00",87:"#2f4c26",88:"#092600",89:"#172613",90:"#00ff00",91:"#7fff7f",92:"#00a500",93:"#52a552",94:"#007f00",95:"#3f7f3f",96:"#004c00",97:"#264c26",98:"#002600",99:"#132613",100:"#00ff3f",101:"#7fff9f",102:"#00a529",103:"#52a567",104:"#007f1f",105:"#3f7f4f",106:"#004c13",107:"#264c2f",108:"#002609",109:"#132617",110:"#00ff7f",111:"#7fffbf",112:"#00a552",113:"#52a57c",114:"#007f3f",115:"#3f7f5f",116:"#004c26",117:"#264c39",118:"#002613",119:"#13261c",120:"#00ffbf",121:"#7fffdf",122:"#00a57c",123:"#52a591",124:"#007f5f",125:"#3f7f6f",126:"#004c39",127:"#264c42",128:"#00261c",129:"#132621",130:"#00ffff",131:"#7fffff",132:"#00a5a5",133:"#52a5a5",134:"#007f7f",135:"#3f7f7f",136:"#004c4c",137:"#264c4c",138:"#002626",139:"#132626",140:"#00bfff",141:"#7fdfff",142:"#007ca5",143:"#5291a5",144:"#005f7f",145:"#3f6f7f",146:"#00394c",147:"#26424c",148:"#001c26",149:"#132126",150:"#007fff",151:"#7fbfff",152:"#0052a5",153:"#527ca5",154:"#003f7f",155:"#3f5f7f",156:"#00264c",157:"#26394c",158:"#001326",159:"#131c26",160:"#003fff",161:"#7f9fff",162:"#0029a5",163:"#5267a5",164:"#001f7f",165:"#3f4f7f",166:"#00134c",167:"#262f4c",168:"#000926",169:"#131726",170:"#0000ff",171:"#7f7fff",172:"#0000a5",173:"#5252a5",174:"#00007f",175:"#3f3f7f",176:"#00004c",177:"#26264c",178:"#000026",179:"#131326",180:"#3f00ff",181:"#9f7fff",182:"#2900a5",183:"#6752a5",184:"#1f007f",185:"#4f3f7f",186:"#13004c",187:"#2f264c",188:"#090026",189:"#171326",190:"#7f00ff",191:"#bf7fff",192:"#5200a5",193:"#7c52a5",194:"#3f007f",195:"#5f3f7f",196:"#26004c",197:"#39264c",198:"#130026",199:"#1c1326",200:"#bf00ff",201:"#df7fff",202:"#7c00a5",203:"#9152a5",204:"#5f007f",205:"#6f3f7f",206:"#39004c",207:"#42264c",208:"#1c0026",209:"#211326",210:"#ff00ff",211:"#ff7fff",212:"#a500a5",213:"#a552a5",214:"#7f007f",215:"#7f3f7f",216:"#4c004c",217:"#4c264c",218:"#260026",219:"#261326",220:"#ff00bf",221:"#ff7fdf",222:"#a5007c",223:"#a55291",224:"#7f005f",225:"#7f3f6f",226:"#4c0039",227:"#4c2642",228:"#26001c",229:"#261321",230:"#ff007f",231:"#ff7fbf",232:"#a50052",233:"#a5527c",234:"#7f003f",235:"#7f3f5f",236:"#4c0026",237:"#4c2639",238:"#260013",239:"#26131c",240:"#ff003f",241:"#ff7f9f",242:"#a50029",243:"#a55267",244:"#7f001f",245:"#7f3f4f",246:"#4c0013",247:"#4c262f",248:"#260009",249:"#261317",250:"#333333",251:"#505050",252:"#696969",253:"#828282",254:"#bebebe",255:"#ffffff"};function T(e,t="#ffffff",r=t){if(typeof e!="number"||Number.isNaN(e))return t;const i=Math.abs(Math.trunc(e));return i===0||i===256||i===257?t:i===7?r:Ke[i]??t}function z(e,t="rgb"){const r=Math.max(0,Math.trunc(e))&16777215,i=r>>16&255,n=r>>8&255,s=r&255;return`rgb(${t==="rgb"?i:s}, ${n}, ${t==="rgb"?s:i})`}function _(e){if(typeof e=="string"){const t=e.trim();return t?/^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(t)?Je(t)??t:{red:"#ff0000",yellow:"#ffff00",green:"#00ff00",cyan:"#00ffff",blue:"#0000ff",magenta:"#ff00ff",white:"#ffffff",black:"#000000",grey:"#808080",gray:"#808080"}[t.toLowerCase()]:void 0}if(e&&typeof e=="object"){const t=e,r=Number(t.r??t.red),i=Number(t.g??t.green),n=Number(t.b??t.blue),s=Number(t.a??t.alpha??1);if([r,i,n].every(Number.isFinite))return Number.isFinite(s)&&s>=0&&s<1?`rgba(${r}, ${i}, ${n}, ${s})`:`rgb(${r}, ${i}, ${n})`}}function Je(e){if(!e)return;const t=e.trim();if(/^#[0-9a-f]{8}$/i.test(t)){const r=parseInt(t.slice(1,3),16)/255,i=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16),s=parseInt(t.slice(7,9),16);return r>=.999?`rgb(${i}, ${n}, ${s})`:`rgba(${i}, ${n}, ${s}, ${gt(r)})`}if(/^#[0-9a-f]{6}$/i.test(t)||/^#[0-9a-f]{3}$/i.test(t))return t;if(/^sc#/i.test(t)){const r=t.slice(3).split(",").map(a=>Number(a.trim())),[i,n,s,o]=r.length===4?r:[1,...r];if([i,n,s,o].every(Number.isFinite))return`rgba(${Math.round(n*255)}, ${Math.round(s*255)}, ${Math.round(o*255)}, ${gt(i)})`}}function D(e,t,r={}){const i=r.foreground??"#ffffff",n=i;let s;const o=_(e.trueColor)??_(e.color)??_(e.colorName);if(o&&(s=o),!s){const a=nr(e,["trueColor","true_color","truecolor","colorRGB","colorRgb","rgbColor","rgb"]);typeof a=="number"&&a>=0&&a<=16777215&&(s=z(a,r.trueColorByteOrder??"rgb"))}if(!s){const a=ee(e.colorIndex,e.colorNumber,e.aci);typeof a=="number"&&Math.abs(a)<=257&&a!==256&&a!==0&&a!==257&&(s=T(a,n,i))}if(!s&&typeof e.color=="number"){const a=Number(e.color);Math.abs(a)<=257?a!==0&&a!==256&&a!==257&&(s=T(a,n,i)):s=z(a,r.trueColorByteOrder??"rgb")}if(!s){const a=ir(t,e.layer);s=tr(a,r)}return Jt(s??n,r)}function dt(e,t,r={}){let i;const n=_(e.fillColor);if(n&&(i=n),!i&&typeof e.fillColor=="number"){const s=e.fillColor;i=Math.abs(s)<=257?T(s,r.foreground??"#ffffff",r.foreground??"#ffffff"):z(s,r.trueColorByteOrder??"rgb")}return!i&&typeof e.fillColorIndex=="number"&&(i=T(e.fillColorIndex,r.foreground??"#ffffff",r.foreground??"#ffffff")),i?Jt(i,r):void 0}function Jt(e,t={}){if(t.contrastMode!=="adaptive")return e;const r=t.background??"#0b1020",i=t.foreground??"#ffffff";return Qe(e,r,i,t.minColorContrast??2.4)}function Qe(e,t,r,i=2.4){const n=ut(r)??{r:255,g:255,b:255,a:1},s=ut(t)??{r:11,g:16,b:32,a:1},o=ut(e);if(!o)return e;const a=re(o,s);if(pt(a,s)>=i)return e;const c=mt(s),l=c<.5?{r:255,g:255,b:255,a:o.a}:{r:0,g:0,b:0,a:o.a};for(const h of[.25,.4,.55,.7,.85,1]){const f=sr(o,l,h);if(pt(re(f,s),s)>=i)return ie(f)}return pt(n,s)>=i?ie(n):c<.5?"#ffffff":"#000000"}function Qt(e){return e?e.isVisible!==!1&&e.isFrozen!==!0:!0}function tr(e,t){if(!e)return;const r=t.foreground??"#ffffff",i=_(e.trueColor);if(i)return i;if(typeof e.trueColor=="number"&&e.trueColor>=0&&e.trueColor<=16777215)return z(e.trueColor,t.trueColorByteOrder??"rgb");const n=_(e.color);if(n)return n;if(rr(e.colorIndex))return T(e.colorIndex,r,r);if(typeof e.color=="number"){const s=Number(e.color);return Math.abs(s)<=257?T(s,r,r):z(s,t.trueColorByteOrder??"rgb")}if(typeof e.colorIndex=="number")return T(e.colorIndex,r,r)}function er(e){return ee(e.colorIndex,e.colorNumber,e.aci)===0?!0:e.trueColor===void 0&&e.color===0}function te(e,t,r,i={}){if(!er(e))return e;const n=D(t,r,i);return{...e,color:n,trueColor:void 0,colorIndex:void 0,colorNumber:void 0}}function rr(e){return typeof e=="number"&&Number.isFinite(e)&&Math.abs(Math.trunc(e))>=1&&Math.abs(Math.trunc(e))<=255}function ir(e,t){if(!(!e||!t))return e.layers[t]??e.layers[t.toLowerCase()]??Object.values(e.layers).find(r=>r.name.toLowerCase()===t.toLowerCase())}function ee(...e){for(const t of e)if(typeof t=="number"&&Number.isFinite(t))return t}function nr(e,t){const r=e;for(const i of t){const n=r[i];if(typeof n=="number"&&Number.isFinite(n))return n}}function ut(e){const t=e.trim().toLowerCase();if(/^#[0-9a-f]{3}$/i.test(t))return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1};if(/^#[0-9a-f]{6}$/i.test(t))return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1};const r=t.match(/^rgba?\(([^)]+)\)$/i);if(r){const i=r[1].split(/[,\s/]+/).filter(Boolean).map(n=>Number(n.replace("%","")));if(i.length>=3&&i.slice(0,3).every(Number.isFinite)){const n=/%/.test(r[1]);return{r:H(n?i[0]*2.55:i[0]),g:H(n?i[1]*2.55:i[1]),b:H(n?i[2]*2.55:i[2]),a:Number.isFinite(i[3])?Math.max(0,Math.min(1,i[3])):1}}}}function re(e,t){const r=e.a+t.a*(1-e.a);return r<=0?{r:0,g:0,b:0,a:0}:{r:(e.r*e.a+t.r*t.a*(1-e.a))/r,g:(e.g*e.a+t.g*t.a*(1-e.a))/r,b:(e.b*e.a+t.b*t.a*(1-e.a))/r,a:r}}function sr(e,t,r){const i=Math.max(0,Math.min(1,r));return{r:e.r+(t.r-e.r)*i,g:e.g+(t.g-e.g)*i,b:e.b+(t.b-e.b)*i,a:e.a}}function mt(e){const t=[e.r,e.g,e.b].map(r=>{const i=r/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*t[0]+.7152*t[1]+.0722*t[2]}function pt(e,t){const r=mt(e),i=mt(t),n=Math.max(r,i),s=Math.min(r,i);return(n+.05)/(s+.05)}function ie(e){const t=H(e.r),r=H(e.g),i=H(e.b);return e.a<.999?`rgba(${t}, ${r}, ${i}, ${gt(e.a)})`:`rgb(${t}, ${r}, ${i})`}function H(e){return Math.max(0,Math.min(255,Math.round(e)))}function gt(e){return Math.round(e*1e3)/1e3}function bt(e,t){return{a:e.a*t.a+e.c*t.b,b:e.b*t.a+e.d*t.b,c:e.a*t.c+e.c*t.d,d:e.b*t.c+e.d*t.d,e:e.a*t.e+e.c*t.f+e.e,f:e.b*t.e+e.d*t.f+e.f}}function ne(e,t){return{a:1,b:0,c:0,d:1,e,f:t}}function or(e){const t=Math.cos(e),r=Math.sin(e);return{a:t,b:r,c:-r,d:t,e:0,f:0}}function ar(e,t=e){return{a:e,b:0,c:0,d:t,e:0,f:0}}function N(e,t){return{x:e.x*t.a+e.y*t.c+t.e,y:e.x*t.b+e.y*t.d+t.f,z:"z"in e?e.z:void 0}}function se(e,t){if(e)return e.map(r=>({cmd:r.cmd,points:r.points.map(i=>N(i,t))}))}function it(e,t={x:0,y:0}){const r=e.insertionPoint??{x:0,y:0},i=e.scale,n=Number(typeof i=="object"&&i?i.x??1:e.scaleX??1),s=Number(typeof i=="object"&&i?i.y??n:e.scaleY??n),o=Number(e.rotation??0);let a=ne(r.x,r.y);return a=bt(a,or(Number.isFinite(o)?o:0)),a=bt(a,ar(Number.isFinite(n)?n:1,Number.isFinite(s)?s:1)),a=bt(a,ne(-t.x,-t.y)),a}function nt(e,t){const r={...e,raw:e.raw??e};if(e.startPoint&&(r.startPoint=N(e.startPoint,t)),e.endPoint&&(r.endPoint=N(e.endPoint,t)),e.center&&(r.center=N(e.center,t)),e.insertionPoint&&(r.insertionPoint=N(e.insertionPoint,t)),e.majorAxisEndPoint){const n=N({x:0,y:0},t),s=N(e.majorAxisEndPoint,t);r.majorAxisEndPoint={x:s.x-n.x,y:s.y-n.y,z:s.z}}e.vertices&&(r.vertices=e.vertices.map(n=>({...N(n,t),bulge:n.bulge,startWidth:n.startWidth,endWidth:n.endWidth}))),e.points&&(r.points=e.points.map(n=>N(n,t))),e.controlPoints&&(r.controlPoints=e.controlPoints.map(n=>N(n,t))),e.fitPoints&&(r.fitPoints=e.fitPoints.map(n=>N(n,t))),e.commands&&(r.commands=se(e.commands,t)),e.loops&&(r.loops=e.loops.map(n=>{var s;return{...n,vertices:(s=n.vertices)==null?void 0:s.map(o=>N(o,t)),commands:se(n.commands,t)}}));const i=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c));return typeof e.radius=="number"&&Number.isFinite(i)&&(r.radius=e.radius*i),r}const cr={background:"#0b1020",foreground:"#ffffff",showUnsupportedMarkers:!1,showImagePlaceholders:!0,showPageBounds:!0,minScale:1e-9,maxScale:1e9,wheelZoomFactor:1.14,trueColorByteOrder:"rgb",maxInsertDepth:16,contrastMode:"adaptive",minColorContrast:2.4,maxCurveSegments:96,spatialIndexCellCount:72,maxVerticesPerBatch:65536,textMinPixelHeight:4,maxVisibleTextLabels:2500,powerPreference:"high-performance",antialias:!0,preserveDrawingBuffer:!1,enableSpatialIndex:!0};class vt{constructor(t,r={}){d(this,"canvas");d(this,"ctx");d(this,"opts");d(this,"document");d(this,"bounds",I());d(this,"view",{centerX:0,centerY:0,scale:1});d(this,"fitScale",1);d(this,"dpr",1);d(this,"isDragging",!1);d(this,"lastPointer");d(this,"resizeObserver");d(this,"imageCache",new Map);d(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"canvas2d"});d(this,"onStats");d(this,"onViewChange");const i=t.getContext("2d");if(!i)throw new Error("Canvas 2D context is not available.");this.canvas=t,this.ctx=i,this.opts={...cr,...r},this.canvas.classList.add("cad-viewer-canvas"),this.bindEvents(),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(t)),this.resize()}destroy(){var t;(t=this.resizeObserver)==null||t.disconnect()}clear(){this.document=void 0,this.bounds=I(),this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange()}setDocument(t){this.document=t,this.bounds=this.computeBounds(t),this.fitToView()}getDocument(){return this.document}setOptions(t){Object.assign(this.opts,t),this.render(),this.emitViewChange()}getOptions(){return{...this.opts}}fitToView(t=.92){if(!R(this.bounds)){this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange();return}const r=Math.max(1,this.cssWidth),i=Math.max(1,this.cssHeight),n=Math.max(this.bounds.maxX-this.bounds.minX,1e-9),s=Math.max(this.bounds.maxY-this.bounds.minY,1e-9),o=this.clampScale(Math.min(r/n,i/s)*t);this.fitScale=o,this.view={centerX:(this.bounds.minX+this.bounds.maxX)/2,centerY:(this.bounds.minY+this.bounds.maxY)/2,scale:o},this.render(),this.emitViewChange()}resize(){this.dpr=Math.max(1,window.devicePixelRatio||1);const t=Math.max(1,Math.floor(this.cssWidth*this.dpr)),r=Math.max(1,Math.floor(this.cssHeight*this.dpr));(this.canvas.width!==t||this.canvas.height!==r)&&(this.canvas.width=t,this.canvas.height=r),this.render(),this.emitViewChange()}zoom(t,r){if(!Number.isFinite(t)||t<=0)return;const i=r??{x:this.cssWidth/2,y:this.cssHeight/2},n=this.screenToWorld(i);this.view.scale=this.clampScale(this.view.scale*t);const s=this.screenToWorld(i);this.view.centerX+=n.x-s.x,this.view.centerY+=n.y-s.y,this.render(),this.emitViewChange()}zoomIn(){this.zoom(this.opts.wheelZoomFactor)}zoomOut(){this.zoom(1/this.opts.wheelZoomFactor)}panByScreenDelta(t,r){!Number.isFinite(t)||!Number.isFinite(r)||(this.view.centerX-=t/this.view.scale,this.view.centerY+=r/this.view.scale,this.render(),this.emitViewChange())}setViewState(t){if(![t.centerX,t.centerY,t.scale].every(Number.isFinite))throw new Error("Invalid view state.");this.view={...t,scale:this.clampScale(t.scale)},this.render(),this.emitViewChange()}getViewState(){return{...this.view}}getBounds(){return{...this.bounds}}getStats(){return lr(this.stats)}getZoomRatio(){return Math.abs(this.fitScale)<1e-12?1:this.view.scale/this.fitScale}getZoomPercent(){return this.getZoomRatio()*100}worldToScreen(t){return{x:this.cssWidth/2+(t.x-this.view.centerX)*this.view.scale,y:this.cssHeight/2-(t.y-this.view.centerY)*this.view.scale}}screenToWorld(t){return{x:this.view.centerX+(t.x-this.cssWidth/2)/this.view.scale,y:this.view.centerY-(t.y-this.cssHeight/2)/this.view.scale}}render(){var r,i;const t=performance.now();if(this.stats={total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"canvas2d"},this.clearCanvas(),this.document){this.opts.showPageBounds&&((r=this.document.pages)!=null&&r.length)&&this.drawPageBounds(this.document);for(const n of this.document.entities)this.drawEntityTracked(n,0)}return this.stats.renderElapsedMs=performance.now()-t,(i=this.onStats)==null||i.call(this,this.getStats()),this.getStats()}get cssWidth(){return this.canvas.clientWidth||1}get cssHeight(){return this.canvas.clientHeight||1}bindEvents(){this.canvas.addEventListener("wheel",r=>{r.preventDefault();const i=r.deltaY<0?this.opts.wheelZoomFactor:1/this.opts.wheelZoomFactor;this.zoom(i,{x:r.offsetX,y:r.offsetY})},{passive:!1}),this.canvas.addEventListener("pointerdown",r=>{this.canvas.setPointerCapture(r.pointerId),this.isDragging=!0,this.lastPointer={x:r.clientX,y:r.clientY},this.canvas.classList.add("is-dragging")}),this.canvas.addEventListener("pointermove",r=>{!this.isDragging||!this.lastPointer||(this.panByScreenDelta(r.clientX-this.lastPointer.x,r.clientY-this.lastPointer.y),this.lastPointer={x:r.clientX,y:r.clientY})});const t=r=>{r&&this.canvas.hasPointerCapture(r.pointerId)&&this.canvas.releasePointerCapture(r.pointerId),this.isDragging=!1,this.lastPointer=void 0,this.canvas.classList.remove("is-dragging")};this.canvas.addEventListener("pointerup",t),this.canvas.addEventListener("pointercancel",()=>t())}clearCanvas(){const t=this.ctx;t.save(),t.setTransform(this.dpr,0,0,this.dpr,0,0),t.clearRect(0,0,this.cssWidth,this.cssHeight),t.fillStyle=this.opts.background,t.fillRect(0,0,this.cssWidth,this.cssHeight),t.restore()}drawPageBounds(t){const r=this.ctx;r.save(),r.setTransform(this.dpr,0,0,this.dpr,0,0),r.strokeStyle="rgba(148, 163, 184, 0.35)",r.lineWidth=1,r.setLineDash([8,6]);for(const i of t.pages??[]){const n=this.worldToScreen({x:0,y:0}),s=this.worldToScreen({x:i.width,y:i.height});r.strokeRect(Math.min(n.x,s.x),Math.min(n.y,s.y),Math.abs(s.x-n.x),Math.abs(s.y-n.y))}r.restore()}drawEntityTracked(t,r){this.stats.total++;const i=String(t.type??"UNKNOWN").toUpperCase();this.stats.byType[i]=(this.stats.byType[i]??0)+1;const n=this.lookupLayer(t.layer);if(t.isVisible===!1||!Qt(n)){this.stats.skipped++;return}this.drawEntity(t,i,r)}drawEntity(t,r,i){switch(t.kind??A(r)){case"line":return this.drawLine(t);case"circle":return this.drawCircle(t);case"arc":return this.drawArc(t);case"polyline":return this.drawPolyline(t);case"ellipse":return this.drawEllipse(t);case"text":return this.drawText(t);case"point":return this.drawPoint(t);case"insert":return this.drawInsert(t,i);case"solid":return this.drawSolid(t);case"hatch":return this.drawHatch(t);case"spline":return this.drawSpline(t);case"path":return this.drawPath(t);case"image":return this.drawImage(t);case"viewport":return this.markSkipped(r);default:this.stats.unsupported[r]=(this.stats.unsupported[r]??0)+1,this.stats.skipped++,this.opts.showUnsupportedMarkers&&this.drawUnsupportedMarker(t)}}beginStyledPath(t,r=!1){const i=this.ctx;i.save(),i.setTransform(this.dpr,0,0,this.dpr,0,0);const n=D(t,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}),s=dt(t,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast})??n;i.strokeStyle=n,i.fillStyle=r?s:n,i.globalAlpha=O(Number(t.opacity??1),0,1),i.lineCap="round",i.lineJoin="round";const o=typeof t.lineweight=="number"&&t.lineweight>0?t.lineweight:0;i.lineWidth=Math.max(1,Math.min(12,o>0?o/30:1)),i.beginPath()}finishStroke(){this.ctx.stroke(),this.ctx.restore(),this.stats.drawn++}finishFillStroke(t=!1){t&&this.ctx.fill(),this.ctx.stroke(),this.ctx.restore(),this.stats.drawn++}drawLine(t){const r=t.startPoint,i=t.endPoint;if(!m(r)||!m(i))return this.markSkipped("LINE");const n=this.worldToScreen(r),s=this.worldToScreen(i);this.beginStyledPath(t),this.ctx.moveTo(n.x,n.y),this.ctx.lineTo(s.x,s.y),this.finishStroke()}drawCircle(t){const r=t.center,i=Number(t.radius);if(!m(r)||!Number.isFinite(i))return this.markSkipped("CIRCLE");const n=this.worldToScreen(r);this.beginStyledPath(t),this.ctx.arc(n.x,n.y,Math.abs(i)*this.view.scale,0,Math.PI*2),this.finishStroke()}drawArc(t){const r=t.center,i=Number(t.radius),n=Number(t.startAngle),s=Number(t.endAngle);if(!m(r)||!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(s))return this.markSkipped("ARC");this.strokeWorldPolyline(t,J(x(r),i,n,s,!0),!1)}drawPolyline(t){const r=t.vertices??t.points;if(!Array.isArray(r)||r.length<2)return this.markSkipped(String(t.type));const i=!!t.isClosed||(Number(t.flag)&1)===1,n=[],s=i?r.length:r.length-1;for(let o=0;o<s;o++){const a=r[o],c=r[(o+1)%r.length];if(!m(a)||!m(c))continue;const l=Rt(a,c,Number(a.bulge??0));n.length>0&&l.shift(),n.push(...l)}this.strokeWorldPolyline(t,n,i)}drawEllipse(t){const r=t.center,i=t.majorAxisEndPoint,n=Number(t.axisRatio??1);if(!m(r)||!m(i))return this.markSkipped("ELLIPSE");const s=Q(r,i,n,Number(t.startAngle??0),Number(t.endAngle??Math.PI*2)),o=Math.abs(Number(t.endAngle??Math.PI*2)-Number(t.startAngle??0))>=Math.PI*2-1e-6;this.strokeWorldPolyline(t,s,o)}drawPoint(t){const r=t.point??t.location??t.center??t.insertionPoint;if(!m(r))return this.markSkipped("POINT");const i=this.worldToScreen(r);this.beginStyledPath(t),this.ctx.moveTo(i.x-3,i.y),this.ctx.lineTo(i.x+3,i.y),this.ctx.moveTo(i.x,i.y-3),this.ctx.lineTo(i.x,i.y+3),this.finishStroke()}drawText(t){const r=t.insertionPoint??t.startPoint??t.center,i=Ot(String(t.text??t.value??"")),n=Number(t.textHeight??t.height??1);if(!m(r)||!i)return this.markSkipped(String(t.type));this.drawTextAt(t,r,i,n,Number(t.rotation??0))}drawInsert(t,r){const i=this.lookupBlock(t.blockName??t.name);if(i&&r<this.opts.maxInsertDepth){const a=it(t,i.basePoint??{x:0,y:0});for(const c of i.entities){const l=te(c,t,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast});this.drawEntityTracked(nt(l,a),r+1)}return}const n=t.insertionPoint;if(!m(n))return this.markSkipped("INSERT");const s=this.worldToScreen(n);this.beginStyledPath(t);const o=5;if(this.ctx.rect(s.x-o,s.y-o,o*2,o*2),this.finishStroke(),Array.isArray(t.attribs))for(const a of t.attribs)this.drawText(a)}drawSolid(t){const r=t.vertices??t.points;if(!Array.isArray(r)||r.length<3)return this.markSkipped(String(t.type));this.beginStyledPath(t,!0);const i=this.worldToScreen(r[0]);this.ctx.moveTo(i.x,i.y);for(const n of r.slice(1)){if(!m(n))continue;const s=this.worldToScreen(n);this.ctx.lineTo(s.x,s.y)}this.ctx.closePath(),this.finishFillStroke(!0)}drawHatch(t){var i,n;const r=t.loops;if(!Array.isArray(r)||r.length===0)return this.markSkipped("HATCH");this.beginStyledPath(t,!0);for(const s of r)if((i=s.commands)!=null&&i.length)this.addPathCommands(s.commands);else if((n=s.vertices)!=null&&n.length){const o=this.worldToScreen(s.vertices[0]);this.ctx.moveTo(o.x,o.y);for(const a of s.vertices.slice(1)){const c=this.worldToScreen(a);this.ctx.lineTo(c.x,c.y)}this.ctx.closePath()}this.finishFillStroke(!!dt(t,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}))}drawSpline(t){var i;const r=(i=t.fitPoints)!=null&&i.length?t.fitPoints:t.controlPoints;if(!r||r.length<2)return this.markSkipped("SPLINE");this.strokeWorldPolyline(t,r,!!t.isClosed)}drawPath(t){var r;if(!((r=t.commands)!=null&&r.length))return this.markSkipped(String(t.type));this.beginStyledPath(t,!!t.fillColor),this.addPathCommands(t.commands),this.finishFillStroke(!!t.fillColor)}addPathCommands(t){for(const r of t)if(r.cmd==="M"){const i=this.worldToScreen(r.points[0]);this.ctx.moveTo(i.x,i.y)}else if(r.cmd==="L"){const i=this.worldToScreen(r.points[0]);this.ctx.lineTo(i.x,i.y)}else if(r.cmd==="C"){const[i,n,s]=r.points.map(o=>this.worldToScreen(o));this.ctx.bezierCurveTo(i.x,i.y,n.x,n.y,s.x,s.y)}else if(r.cmd==="Q"){const[i,n]=r.points.map(s=>this.worldToScreen(s));this.ctx.quadraticCurveTo(i.x,i.y,n.x,n.y)}else r.cmd==="Z"&&this.ctx.closePath()}drawImage(t){const r=t.insertionPoint;if(!m(r))return this.markSkipped(String(t.type));const i=Number(t.width??32),n=Number(t.height??32),s=this.worldToScreen(r),o=this.worldToScreen({x:r.x+i,y:r.y-n}),a=Math.min(s.x,o.x),c=Math.min(s.y,o.y),l=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y),f=t.imageDataUrl;if(f){const u=this.getImage(f);if(u.complete&&u.naturalWidth>0){this.ctx.save(),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0),this.ctx.drawImage(u,a,c,l,h),this.ctx.restore(),this.stats.drawn++;return}u.onload=()=>this.render()}if(!this.opts.showImagePlaceholders)return this.markSkipped(String(t.type));this.beginStyledPath(t),this.ctx.rect(a,c,l,h),this.ctx.moveTo(a,c),this.ctx.lineTo(a+l,c+h),this.ctx.moveTo(a+l,c),this.ctx.lineTo(a,c+h),this.finishStroke()}getImage(t){let r=this.imageCache.get(t);return r||(r=new Image,r.src=t,this.imageCache.set(t,r)),r}drawUnsupportedMarker(t){const r=this.entityAnchor(t);if(!r)return;const i=this.worldToScreen(r);this.beginStyledPath(t),this.ctx.moveTo(i.x-4,i.y-4),this.ctx.lineTo(i.x+4,i.y+4),this.ctx.moveTo(i.x+4,i.y-4),this.ctx.lineTo(i.x-4,i.y+4),this.finishStroke()}drawTextAt(t,r,i,n,s){const o=this.ctx,a=this.worldToScreen(r);o.save(),o.setTransform(this.dpr,0,0,this.dpr,0,0),o.translate(a.x,a.y),o.rotate(-s);const c=Math.max(4,Math.min(256,Math.abs(n)*this.view.scale));o.font=`${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,o.fillStyle=D(t,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}),o.globalAlpha=O(Number(t.opacity??1),0,1),o.textBaseline="alphabetic";for(const[l,h]of i.split(/\r?\n/g).entries())o.fillText(h,0,l*c*1.22);o.restore(),this.stats.drawn++}strokeWorldPolyline(t,r,i){const n=r.filter(m);if(n.length<2)return this.markSkipped(String(t.type));this.beginStyledPath(t);const s=this.worldToScreen(n[0]);this.ctx.moveTo(s.x,s.y);for(const o of n.slice(1)){const a=this.worldToScreen(o);this.ctx.lineTo(a.x,a.y)}i&&this.ctx.closePath(),this.finishStroke()}markSkipped(t){this.stats.skipped++,this.stats.unsupported[t]=this.stats.unsupported[t]??0}entityAnchor(t){for(const r of["startPoint","insertionPoint","center","point","location"]){const i=t[r];if(m(i))return x(i)}if(Array.isArray(t.vertices)&&m(t.vertices[0]))return x(t.vertices[0]);if(Array.isArray(t.commands)&&t.commands.length){const r=t.commands.find(i=>i.points.length>0);if(r)return x(r.points[0])}}computeBounds(t){var i;const r=I();if((i=t.pages)!=null&&i.length)for(const n of t.pages)y(r,{x:0,y:0}),y(r,{x:n.width,y:n.height});for(const n of t.entities)this.includeEntityBounds(r,n,0);return Wt(r)}includeEntityBounds(t,r,i){const n=String(r.type??"").toUpperCase(),s=r.kind??A(n);if(s==="insert"){const o=this.lookupBlock(r.blockName??r.name);if(o&&i<this.opts.maxInsertDepth){const a=it(r,o.basePoint??{x:0,y:0});for(const c of o.entities)this.includeEntityBounds(t,nt(c,a),i+1);return}}if(s==="line")m(r.startPoint)&&y(t,r.startPoint),m(r.endPoint)&&y(t,r.endPoint);else if(s==="circle"||s==="arc")m(r.center)&&Number.isFinite(r.radius)&&Dt(t,r.center,Number(r.radius));else if(s==="polyline"||s==="solid"||s==="spline")for(const o of[...r.vertices??[],...r.points??[],...r.controlPoints??[],...r.fitPoints??[]])m(o)&&y(t,o);else if(s==="ellipse")m(r.center)&&m(r.majorAxisEndPoint)&&Q(r.center,r.majorAxisEndPoint,Number(r.axisRatio??1),Number(r.startAngle??0),Number(r.endAngle??Math.PI*2)).forEach(o=>y(t,o));else if(s==="path")for(const o of r.commands??[])for(const a of o.points)y(t,a);else if(s==="hatch")for(const o of r.loops??[]){for(const a of o.vertices??[])y(t,a);for(const a of o.commands??[])for(const c of a.points)y(t,c)}else{const o=this.entityAnchor(r);o&&y(t,o)}}lookupLayer(t){if(!(!this.document||!t))return this.document.layers[t]??this.document.layers[t.toLowerCase()]??Object.values(this.document.layers).find(r=>r.name.toLowerCase()===t.toLowerCase())}lookupBlock(t){if(!(!this.document||!t))return this.document.blocks[t]??this.document.blocks[t.toLowerCase()]??Object.values(this.document.blocks).find(r=>r.name.toLowerCase()===t.toLowerCase())}clampScale(t){return Math.min(this.opts.maxScale,Math.max(this.opts.minScale,t))}emitViewChange(){var t;(t=this.onViewChange)==null||t.call(this,{view:this.getViewState(),fitScale:this.fitScale,zoomRatio:this.getZoomRatio(),zoomPercent:this.getZoomPercent(),bounds:this.getBounds()})}}function lr(e){return{total:e.total,drawn:e.drawn,skipped:e.skipped,byType:{...e.byType},unsupported:{...e.unsupported},renderElapsedMs:e.renderElapsedMs,backend:e.backend,primitiveCount:e.primitiveCount,visiblePrimitiveCount:e.visiblePrimitiveCount,culledPrimitiveCount:e.culledPrimitiveCount,gpuMemoryBytes:e.gpuMemoryBytes,buildElapsedMs:e.buildElapsedMs}}const hr={background:"#0b1020",foreground:"#ffffff",showUnsupportedMarkers:!1,showImagePlaceholders:!0,showPageBounds:!0,minScale:1e-9,maxScale:1e9,wheelZoomFactor:1.14,trueColorByteOrder:"rgb",maxInsertDepth:16,contrastMode:"adaptive",minColorContrast:2.4,maxCurveSegments:96,spatialIndexCellCount:72,maxVerticesPerBatch:65536,textMinPixelHeight:4,maxVisibleTextLabels:2500,powerPreference:"high-performance",antialias:!0,preserveDrawingBuffer:!1,enableSpatialIndex:!0};class yt{constructor(t,r={}){d(this,"canvas");d(this,"backend","webgl");d(this,"gl");d(this,"program");d(this,"eventController",new AbortController);d(this,"imageCache",new Map);d(this,"opts");d(this,"document");d(this,"bounds",I());d(this,"view",{centerX:0,centerY:0,scale:1});d(this,"fitScale",1);d(this,"dpr",1);d(this,"isDragging",!1);d(this,"lastPointer");d(this,"resizeObserver");d(this,"overlayCanvas");d(this,"overlayCtx");d(this,"scene");d(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0});d(this,"rafHandle",0);d(this,"onStats");d(this,"onViewChange");const i=fr(t,r);if(!i)throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');this.canvas=t,this.gl=i,this.program=dr(i),this.opts={...hr,...r},this.canvas.classList.add("cad-viewer-canvas","cad-viewer-webgl-canvas"),this.createOverlayCanvas(),this.bindEvents(),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(t)),this.resize()}static isSupported(){return wt()}destroy(){var t,r;this.eventController.abort(),(t=this.resizeObserver)==null||t.disconnect(),this.cancelScheduledRender(),this.disposeScene(),(r=this.overlayCanvas)==null||r.remove()}clear(){this.document=void 0,this.bounds=I(),this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.disposeScene(),this.render(),this.emitViewChange()}setDocument(t){this.document=t,this.bounds=vr(t,this.opts),this.disposeScene();const r=mr(t,this.opts,this.bounds);this.scene=ur(this.gl,r),this.stats=xr(this.scene,0),this.fitToView()}getDocument(){return this.document}setOptions(t){const r=wr(this.opts,t);if(this.opts={...this.opts,...t},r&&this.document){this.setDocument(this.document);return}this.render(),this.emitViewChange()}getOptions(){return{...this.opts}}fitToView(t=.92){if(!R(this.bounds)){this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange();return}const r=Math.max(1,this.cssWidth),i=Math.max(1,this.cssHeight),n=Math.max(this.bounds.maxX-this.bounds.minX,1e-9),s=Math.max(this.bounds.maxY-this.bounds.minY,1e-9),o=this.clampScale(Math.min(r/n,i/s)*t);this.fitScale=o,this.view={centerX:(this.bounds.minX+this.bounds.maxX)/2,centerY:(this.bounds.minY+this.bounds.maxY)/2,scale:o},this.render(),this.emitViewChange()}resize(){this.dpr=Math.max(1,window.devicePixelRatio||1);const t=Math.max(1,Math.floor(this.cssWidth*this.dpr)),r=Math.max(1,Math.floor(this.cssHeight*this.dpr));(this.canvas.width!==t||this.canvas.height!==r)&&(this.canvas.width=t,this.canvas.height=r),this.resizeOverlay(t,r),this.render(),this.emitViewChange()}zoom(t,r){if(!Number.isFinite(t)||t<=0)return;const i=r??{x:this.cssWidth/2,y:this.cssHeight/2},n=this.screenToWorld(i);this.view.scale=this.clampScale(this.view.scale*t);const s=this.screenToWorld(i);this.view.centerX+=n.x-s.x,this.view.centerY+=n.y-s.y,this.scheduleRender(),this.emitViewChange()}zoomIn(){this.zoom(this.opts.wheelZoomFactor)}zoomOut(){this.zoom(1/this.opts.wheelZoomFactor)}panByScreenDelta(t,r){!Number.isFinite(t)||!Number.isFinite(r)||(this.view.centerX-=t/this.view.scale,this.view.centerY+=r/this.view.scale,this.scheduleRender(),this.emitViewChange())}setViewState(t){if(![t.centerX,t.centerY,t.scale].every(Number.isFinite))throw new Error("Invalid view state.");this.view={...t,scale:this.clampScale(t.scale)},this.render(),this.emitViewChange()}getViewState(){return{...this.view}}getBounds(){return{...this.bounds}}getStats(){return Cr(this.stats)}getZoomRatio(){return Math.abs(this.fitScale)<1e-12?1:this.view.scale/this.fitScale}getZoomPercent(){return this.getZoomRatio()*100}worldToScreen(t){return{x:this.cssWidth/2+(t.x-this.view.centerX)*this.view.scale,y:this.cssHeight/2-(t.y-this.view.centerY)*this.view.scale}}screenToWorld(t){return{x:this.view.centerX+(t.x-this.cssWidth/2)/this.view.scale,y:this.view.centerY-(t.y-this.cssHeight/2)/this.view.scale}}render(){return this.cancelScheduledRender(),this.renderNow()}renderNow(){var l;const t=performance.now(),r=this.gl;r.viewport(0,0,this.canvas.width,this.canvas.height);const i=kt(this.opts.background,[11,16,32,255]);r.clearColor(i[0]/255,i[1]/255,i[2]/255,i[3]/255),r.clear(r.COLOR_BUFFER_BIT),r.disable(r.DEPTH_TEST),r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);let n=0,s=0;const o=this.scene,a=this.visibleWorldBounds();if(o){r.useProgram(this.program.program),r.uniform2f(this.program.uViewCenter,this.view.centerX-o.origin.x,this.view.centerY-o.origin.y),r.uniform1f(this.program.uScale,this.view.scale*this.dpr),r.uniform2f(this.program.uViewport,this.canvas.width,this.canvas.height),r.uniform1f(this.program.uPointSize,Math.max(2,Math.min(12,4*this.dpr)));const h=this.drawBatches(o.lineBatches,r.LINES,a);n+=h.visible,s+=h.culled;const f=this.drawBatches(o.triangleBatches,r.TRIANGLES,a);n+=f.visible,s+=f.culled;const u=this.drawBatches(o.pointBatches,r.POINTS,a);n+=u.visible,s+=u.culled}this.renderOverlay(a);const c=performance.now()-t;return this.stats=o?{...o.stats,renderElapsedMs:c,backend:"webgl",primitiveCount:o.primitiveCount,visiblePrimitiveCount:n,culledPrimitiveCount:s,gpuMemoryBytes:o.gpuMemoryBytes,buildElapsedMs:o.buildElapsedMs}:{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:c,backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0},(l=this.onStats)==null||l.call(this,this.getStats()),this.getStats()}drawBatches(t,r,i){const n=this.gl;let s=0,o=0;for(const a of t){if(!Pt(a.bounds,i)){o+=a.primitiveCount;continue}n.bindBuffer(n.ARRAY_BUFFER,a.positionBuffer),n.enableVertexAttribArray(this.program.aPosition),n.vertexAttribPointer(this.program.aPosition,2,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,a.colorBuffer),n.enableVertexAttribArray(this.program.aColor),n.vertexAttribPointer(this.program.aColor,4,n.UNSIGNED_BYTE,!0,0,0),n.drawArrays(r,0,a.vertexCount),s+=a.primitiveCount}return{visible:s,culled:o}}scheduleRender(){this.rafHandle||(this.rafHandle=window.requestAnimationFrame(()=>{this.rafHandle=0,this.renderNow()}))}cancelScheduledRender(){this.rafHandle&&(window.cancelAnimationFrame(this.rafHandle),this.rafHandle=0)}renderOverlay(t){var n,s;const r=this.overlayCtx,i=this.overlayCanvas;!r||!i||(r.save(),r.setTransform(this.dpr,0,0,this.dpr,0,0),r.clearRect(0,0,this.cssWidth,this.cssHeight),this.opts.showPageBounds&&((s=(n=this.document)==null?void 0:n.pages)!=null&&s.length)&&this.drawPageBoundsOverlay(r),this.scene&&(this.drawImagesOverlay(r,this.scene.imageItems,t),this.drawTextOverlay(r,this.scene.textItems,t)),r.restore())}drawPageBoundsOverlay(t){var r,i;if((i=(r=this.document)==null?void 0:r.pages)!=null&&i.length){t.save(),t.strokeStyle="rgba(148, 163, 184, 0.34)",t.lineWidth=1,t.setLineDash([8,6]);for(const n of this.document.pages){const s=this.worldToScreen({x:0,y:0}),o=this.worldToScreen({x:n.width,y:n.height});t.strokeRect(Math.min(s.x,o.x),Math.min(s.y,o.y),Math.abs(o.x-s.x),Math.abs(o.y-s.y))}t.restore()}}drawTextOverlay(t,r,i){const n=this.opts.maxVisibleTextLabels;let s=0;for(const o of r){if(s>=n)break;if(!Pt(o.bounds,i))continue;const a=Math.abs(o.height)*this.view.scale;if(a<this.opts.textMinPixelHeight)continue;const c=this.worldToScreen(o.point);if(c.x<-512||c.y<-512||c.x>this.cssWidth+512||c.y>this.cssHeight+512)continue;t.save(),t.translate(c.x,c.y),t.rotate(-o.rotation);const l=Math.max(4,Math.min(256,a));t.font=`${l}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,t.fillStyle=o.color,t.globalAlpha=o.opacity,t.textBaseline="alphabetic";for(const[h,f]of o.text.split(/\r?\n/g).entries())t.fillText(f,0,h*l*1.22);t.restore(),s++}}drawImagesOverlay(t,r,i){for(const n of r){if(!Pt(n.bounds,i))continue;const s=this.worldToScreen(n.point),o=this.worldToScreen({x:n.point.x+n.width,y:n.point.y-n.height}),a=Math.min(s.x,o.x),c=Math.min(s.y,o.y),l=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y);if(!(l<1||h<1)){if(n.source){const f=this.getImage(n.source);if(f.complete&&f.naturalWidth>0){t.save(),t.globalAlpha=n.opacity,t.drawImage(f,a,c,l,h),t.restore();continue}f.onload=()=>this.scheduleRender()}this.opts.showImagePlaceholders&&(t.save(),t.strokeStyle=n.color,t.globalAlpha=n.opacity,t.lineWidth=1,t.strokeRect(a,c,l,h),t.beginPath(),t.moveTo(a,c),t.lineTo(a+l,c+h),t.moveTo(a+l,c),t.lineTo(a,c+h),t.stroke(),t.restore())}}}getImage(t){let r=this.imageCache.get(t);return r||(r=new Image,r.src=t,this.imageCache.set(t,r)),r}createOverlayCanvas(){const t=this.canvas.parentElement;if(!t||typeof document>"u")return;window.getComputedStyle(t).position==="static"&&(t.style.position="relative");const i=document.createElement("canvas");i.className="cad-viewer-text-overlay",i.setAttribute("aria-hidden","true"),i.style.position="absolute",i.style.inset="0",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",i.style.zIndex="1";const n=i.getContext("2d");n&&(t.appendChild(i),this.overlayCanvas=i,this.overlayCtx=n)}resizeOverlay(t,r){this.overlayCanvas&&(this.overlayCanvas.width!==t||this.overlayCanvas.height!==r)&&(this.overlayCanvas.width=t,this.overlayCanvas.height=r)}bindEvents(){const t=this.eventController.signal;this.canvas.addEventListener("wheel",i=>{i.preventDefault();const n=i.deltaY<0?this.opts.wheelZoomFactor:1/this.opts.wheelZoomFactor;this.zoom(n,{x:i.offsetX,y:i.offsetY})},{passive:!1,signal:t}),this.canvas.addEventListener("pointerdown",i=>{this.canvas.setPointerCapture(i.pointerId),this.isDragging=!0,this.lastPointer={x:i.clientX,y:i.clientY},this.canvas.classList.add("is-dragging")},{signal:t}),this.canvas.addEventListener("pointermove",i=>{!this.isDragging||!this.lastPointer||(this.panByScreenDelta(i.clientX-this.lastPointer.x,i.clientY-this.lastPointer.y),this.lastPointer={x:i.clientX,y:i.clientY})},{signal:t});const r=i=>{i&&this.canvas.hasPointerCapture(i.pointerId)&&this.canvas.releasePointerCapture(i.pointerId),this.isDragging=!1,this.lastPointer=void 0,this.canvas.classList.remove("is-dragging")};this.canvas.addEventListener("pointerup",r,{signal:t}),this.canvas.addEventListener("pointercancel",()=>r(),{signal:t}),this.canvas.addEventListener("webglcontextlost",i=>{i.preventDefault(),this.cancelScheduledRender()},{signal:t})}visibleWorldBounds(){const t=this.cssWidth/Math.max(this.view.scale,1e-12)/2,r=this.cssHeight/Math.max(this.view.scale,1e-12)/2;return{minX:this.view.centerX-t,maxX:this.view.centerX+t,minY:this.view.centerY-r,maxY:this.view.centerY+r}}get cssWidth(){return this.canvas.clientWidth||1}get cssHeight(){return this.canvas.clientHeight||1}clampScale(t){return Math.min(this.opts.maxScale,Math.max(this.opts.minScale,t))}disposeScene(){if(!this.scene)return;const t=this.gl;for(const r of[...this.scene.lineBatches,...this.scene.triangleBatches,...this.scene.pointBatches])t.deleteBuffer(r.positionBuffer),t.deleteBuffer(r.colorBuffer);this.scene=void 0}emitViewChange(){var t;(t=this.onViewChange)==null||t.call(this,{view:this.getViewState(),fitScale:this.fitScale,zoomRatio:this.getZoomRatio(),zoomPercent:this.getZoomPercent(),bounds:this.getBounds()})}}function wt(){if(typeof document>"u")return!1;const e=document.createElement("canvas");return!!(e.getContext("webgl2")??e.getContext("webgl")??e.getContext("experimental-webgl"))}function fr(e,t){const r={alpha:!1,antialias:t.antialias??!0,depth:!1,stencil:!1,preserveDrawingBuffer:t.preserveDrawingBuffer??!1,powerPreference:t.powerPreference??"high-performance"};return e.getContext("webgl2",r)??e.getContext("webgl",r)??e.getContext("experimental-webgl",r)??void 0}function dr(e){const t=`
|
|
9
|
+
`),n=[];for(let h=0;h<e.length-1;h+=2){const d=Number((l=e[h])==null?void 0:l.trim()),m=e[h+1]??"";Number.isFinite(d)&&n.push({code:d,value:m.trimEnd()})}const r=[],i={};let o="",s=[],a;for(let h=0;h<n.length;h++){const d=n[h];if(d.code===0&&d.value==="SECTION"){o=((f=n[h+1])==null?void 0:f.code)===2?n[h+1].value.toUpperCase():"",h++;continue}if(d.code===0&&d.value==="ENDSEC"){c(),o="";continue}o==="ENTITIES"&&(d.code===0?(c(),s=[d]):s.push(d))}return c(),{header:{},tables:{},entities:r,blocks:i};function c(){var m;if(!s.length)return;const h=(m=s[0])==null?void 0:m.value.toUpperCase();if(h==="VERTEX"&&a){const g=E(s,10,20,30);g&&(a.vertices??(a.vertices=[])).push({...g,bulge:w(s,42)}),s=[];return}if(h==="SEQEND"){a&&r.push(a),a=void 0,s=[];return}if(a&&(r.push(a),a=void 0),!h||h==="EOF"){s=[];return}const d=an(h,s);h==="POLYLINE"?a=d:r.push(d),s=[]}}function an(t,e){const n={type:t,handle:ee(e,5),layer:ee(e,8)??"0",colorIndex:w(e,62),trueColor:w(e,420),lineType:ee(e,6),lineweight:w(e,370)};switch(t){case"LINE":Object.assign(n,{startPoint:E(e,10,20,30),endPoint:E(e,11,21,31)});break;case"CIRCLE":Object.assign(n,{center:E(e,10,20,30),radius:w(e,40)});break;case"ARC":Object.assign(n,{center:E(e,10,20,30),radius:w(e,40),startAngle:he(w(e,50)),endAngle:he(w(e,51))});break;case"POINT":Object.assign(n,{point:E(e,10,20,30)});break;case"TEXT":case"MTEXT":Object.assign(n,{insertionPoint:E(e,10,20,30),text:fn(e),textHeight:w(e,40),rotation:he(w(e,50))});break;case"LWPOLYLINE":Object.assign(n,{vertices:ln(e),flag:w(e,70),isClosed:(Number(w(e,70)??0)&1)===1});break;case"POLYLINE":Object.assign(n,{vertices:[],flag:w(e,70),isClosed:(Number(w(e,70)??0)&1)===1});break;case"ELLIPSE":Object.assign(n,{center:E(e,10,20,30),majorAxisEndPoint:E(e,11,21,31),axisRatio:w(e,40),startAngle:w(e,41),endAngle:w(e,42)});break;case"SPLINE":Object.assign(n,{controlPoints:cn(e,10,20,30),degree:w(e,71),isClosed:(Number(w(e,70)??0)&1)===1});break;case"INSERT":Object.assign(n,{name:ee(e,2),blockName:ee(e,2),insertionPoint:E(e,10,20,30),rotation:he(w(e,50)),scale:{x:w(e,41)??1,y:w(e,42)??w(e,41)??1,z:w(e,43)??1}});break;case"SOLID":case"TRACE":case"3DFACE":Object.assign(n,{vertices:[E(e,10,20,30),E(e,11,21,31),E(e,12,22,32),E(e,13,23,33)].filter(Boolean)});break}return ke(n)}function w(t,e){var i;const n=(i=t.find(o=>o.code===e))==null?void 0:i.value,r=Number(n);return Number.isFinite(r)?r:void 0}function ee(t,e){var r;const n=(r=t.find(i=>i.code===e))==null?void 0:r.value;return n&&n.length>0?n:void 0}function E(t,e,n,r){const i=w(t,e),o=w(t,n),s=w(t,r);if(!(i===void 0||o===void 0))return s===void 0?{x:i,y:o}:{x:i,y:o,z:s}}function cn(t,e,n,r){const i=[];for(let o=0;o<t.length;o++){if(t[o].code!==e)continue;const s=Number(t[o].value),a=t.slice(o+1).find(h=>h.code===n),c=t.slice(o+1).find(h=>h.code===r),l=Number(a==null?void 0:a.value),f=Number(c==null?void 0:c.value);Number.isFinite(s)&&Number.isFinite(l)&&i.push(Number.isFinite(f)?{x:s,y:l,z:f}:{x:s,y:l})}return i}function ln(t){const e=[];for(let n=0;n<t.length;n++){if(t[n].code!==10)continue;const r=Number(t[n].value);let i,o;for(let s=n+1;s<t.length&&t[s].code!==10;s++)t[s].code===20&&(i=Number(t[s].value)),t[s].code===42&&(o=Number(t[s].value));Number.isFinite(r)&&Number.isFinite(i)&&e.push({x:r,y:i,bulge:Number.isFinite(o)?o:void 0})}return e}function fn(t){const e=t.filter(n=>n.code===1||n.code===3).map(n=>n.value);return e.length?e.join(""):void 0}function he(t){return typeof t=="number"&&Number.isFinite(t)?W(t):void 0}class ct{constructor(e={}){u(this,"id","dwf");u(this,"label","DWF/DWFx native viewer powered by dwf-viewer");u(this,"formats",["dwf","dwfx","xps"]);u(this,"nativeRenderer",!0);u(this,"defaults");u(this,"native");u(this,"host");u(this,"lastStats");this.defaults=e}accepts(e,n){const r=X(e);if(r==="dwf"||r==="dwfx"||r==="xps")return!0;const i=R(e,n);return i==="dwf"||i==="dwfx"||i==="xps"}async load(e,n={}){var h,d,m,g;const r={...this.defaults,...n},i=performance.now(),o=e.fileName??((h=e.file)==null?void 0:h.name),s=await T(e),a=ht(R(e,s),X(e));(d=r.onProgress)==null||d.call(r,{phase:"parse",format:a,message:"Opening DWF/DWFx with dwf-viewer…",percent:48});const c=await M.openDwfDocument(s,{fileName:o});(m=r.onProgress)==null||m.call(r,{phase:"normalize",format:a,message:"Reading DWF pages, sheets and model metadata…",percent:76});const l=lt(c,o,a,r.keepRaw===!0),f=performance.now()-i;return(g=r.onProgress)==null||g.call(r,{phase:"done",format:l.format,message:"DWF/DWFx document ready.",percent:100,elapsedMs:f}),{document:l,raw:r.keepRaw?c:void 0,bytes:s.byteLength,elapsedMs:f,format:l.format,warnings:l.warnings}}async mount(e,n,r={}){var y,x,L,D,A;const i={...this.defaults,...r},o=performance.now(),s=e.fileName??((y=e.file)==null?void 0:y.name),a=await T(e),c=ht(R(e,a),X(e)),l=pn(i),f=dt(i),h=gn(i,l,f),d=ut(i,l,f);(x=i.onProgress)==null||x.call(i,{phase:"native-render",format:c,message:"Mounting native DWF renderer…",percent:28}),this.unmount(),this.host=n,n.replaceChildren(),this.native=new M.DwfViewer(n,h),(L=i.onProgress)==null||L.call(i,{phase:"parse",format:c,message:"Parsing DWF package and page streams…",percent:58}),await this.native.load(a,{fileName:s,...d}),(D=i.onProgress)==null||D.call(i,{phase:"render",format:c,message:"Rendering DWF/DWFx with dwf-viewer…",percent:88}),this.lastStats=await this.native.render();const m=this.native.getDocument(),g=lt(m,s,c,i.keepRaw===!0);g.metadata.loaderMode="Native DWF",g.metadata.nativeRenderer="dwf-viewer",g.metadata.nativeRenderStats=this.lastStats?{...this.lastStats,warnings:this.lastStats.warnings.length}:void 0;const S=performance.now()-o;return(A=i.onProgress)==null||A.call(i,{phase:"done",format:g.format,message:"DWF/DWFx rendered.",percent:100,elapsedMs:S}),{document:g,raw:i.keepRaw?m:void 0,bytes:a.byteLength,elapsedMs:S,format:g.format,warnings:g.warnings}}unmount(){var e;(e=this.native)==null||e.dispose(),this.native=void 0,this.lastStats=void 0,this.host&&this.host.replaceChildren()}fit(){var e;(e=this.native)==null||e.fit()}zoomIn(){var n;const e=(n=this.native)==null?void 0:n.zoomInButton;e==null||e.click()}zoomOut(){var n;const e=(n=this.native)==null?void 0:n.zoomOutButton;e==null||e.click()}resize(){var e;(e=this.native)==null||e.render()}setNativeOptions(e){var r,i,o,s;const n=this.native;if(n){if(typeof e.dwfBackground=="string")n.background=e.dwfBackground;else{const a=dt(e);a&&(n.background=a)}typeof e.dwfPreferWebgl=="boolean"&&((r=n.setPreferWebgl)==null||r.call(n,e.dwfPreferWebgl)),typeof e.dwfPreferWasm=="boolean"&&((i=n.setPreferWasm)==null||i.call(n,e.dwfPreferWasm)),e.dwfLineWeightMode&&((o=n.setLineWeightMode)==null||o.call(n,e.dwfLineWeightMode)),de(n,"minStrokeCssPx",e.dwfMinStrokeCssPx),de(n,"maxOverviewStrokeCssPx",e.dwfMaxOverviewStrokeCssPx),de(n,"minTextCssPx",e.dwfMinTextCssPx),de(n,"minFilledAreaCssPx",e.dwfMinFilledAreaCssPx),(s=n.render)==null||s.call(n)}}getLastNativeStats(){return this.lastStats}}function lt(t,e,n,r){var a,c;const i=ft((t==null?void 0:t.diagnostics)??[]),o=((t==null?void 0:t.pageData)??[]).map((l,f)=>hn(l,f));for(const l of(t==null?void 0:t.pageData)??[])i.push(...ft(l.diagnostics));const s={parser:"dwf-viewer",nativeRenderer:"dwf-viewer",dwfKind:t==null?void 0:t.kind,packageEntries:((a=t==null?void 0:t.packageEntries)==null?void 0:a.length)??0,resources:((c=t==null?void 0:t.resources)==null?void 0:c.length)??0,pageKinds:vn(((t==null?void 0:t.pageData)??[]).map(l=>l.kind)),pageNames:((t==null?void 0:t.pages)??[]).map(l=>l.name)};return ae({format:n,sourceName:e,layers:{},blocks:{},pages:o,entities:Xt(o),metadata:s,warnings:wn(i),raw:r?t:void 0})}function hn(t,e){const n=dn(t,e);return{index:e,name:t.name||t.sourcePath||`${e+1}`,width:t.width||1e3,height:t.height||1e3,entities:n}}function dn(t,e){return t.kind==="w2d-text"?t.primitives.flatMap((n,r)=>un(n,e,r)):t.kind==="image"?[{type:"DWF_IMAGE_PAGE",kind:"image",pageIndex:e,width:t.width,height:t.height,imageSource:t.sourcePath}]:t.kind==="w3d-model"?t.model.meshes.map((n,r)=>({id:n.id,type:"W3D_MESH",kind:"solid",pageIndex:e,color:n.color?yn(n.color):void 0,name:n.name||`mesh-${r+1}`,raw:{vertexCount:n.vertexCount,triangleCount:n.triangleCount,materialId:n.materialId}})):t.kind==="xps-fixed-page"?[{type:"XPS_FIXED_PAGE",kind:"viewport",pageIndex:e,width:t.width,height:t.height,raw:{sourcePath:t.sourcePath}}]:[{type:"DWF_PAGE",kind:"viewport",pageIndex:e,width:t.width,height:t.height,raw:{sourcePath:t.sourcePath}}]}function un(t,e,n){const r={id:`dwf-${e}-${n}`,pageIndex:e,color:t.stroke,fillColor:t.fill,lineweight:t.lineWidth,raw:{matrix:t.matrix}};if(t.type==="polyline"||t.type==="polygon")return[{...r,type:t.type==="polygon"?"DWF_POLYGON":"DWF_POLYLINE",kind:"polyline",vertices:mn(t.points),isClosed:t.type==="polygon"}];if(t.type==="path")return[{...r,type:"DWF_PATH",kind:"path",commands:t.commands}];if(t.type==="text")return[{...r,type:"DWF_TEXT",kind:"text",insertionPoint:{x:t.x,y:t.y,z:0},text:t.text,textHeight:t.size}];if(t.type==="rect"){const i=t.x,o=t.y,s=t.width,a=t.height;return[{...r,type:"DWF_RECT",kind:"polyline",isClosed:!0,vertices:[{x:i,y:o,z:0},{x:i+s,y:o,z:0},{x:i+s,y:o+a,z:0},{x:i,y:o+a,z:0}]}]}return[]}function mn(t){const e=[];for(let n=0;n+1<t.length;n+=2)e.push({x:t[n],y:t[n+1],z:0});return e}function ft(t){return t.filter(e=>e.level!=="info").map(e=>`${e.code}: ${e.message}${e.source?` (${e.source})`:""}`)}function ht(t,e){return e==="dwf"||e==="dwfx"||e==="xps"?e:t==="dwf"||t==="dwfx"||t==="xps"?t:"dwf"}function pn(t){if(t.dwfWasmUrl)return t.dwfWasmUrl;if(typeof document>"u")return;const e=t.wasmPath?new URL(bn(t.wasmPath),document.baseURI).href:new URL("wasm/",document.baseURI).href;return new URL("dwfv-render.wasm",e).href}function dt(t){if(t.dwfBackground)return t.dwfBackground;const e=t.canvasOptions;return(e==null?void 0:e.background)??"#05070d"}function gn(t,e,n){return{...ut(t,e,n),maxDevicePixelRatio:t.dwfMaxDevicePixelRatio??2,maxCanvasPixels:t.dwfMaxCanvasPixels??16777216}}function ut(t,e,n){return{wasmUrl:e,preferWebgl:t.dwfPreferWebgl??!0,preferWasm:t.dwfPreferWasm??!0,background:n,maxGpuCacheBytes:t.dwfMaxGpuCacheBytes??160*1024*1024,maxCachedScenes:t.dwfMaxCachedScenes??2,lineWeightMode:t.dwfLineWeightMode??"adaptive",minStrokeCssPx:t.dwfMinStrokeCssPx,maxOverviewStrokeCssPx:t.dwfMaxOverviewStrokeCssPx,minTextCssPx:t.dwfMinTextCssPx,minFilledAreaCssPx:t.dwfMinFilledAreaCssPx}}function de(t,e,n){typeof n=="number"&&Number.isFinite(n)&&(t[e]=n)}function bn(t){return t.endsWith("/")?t:`${t}/`}function yn(t){const[e,n,r]=t.map(i=>Math.max(0,Math.min(255,Math.round(i*255))));return`#${Me(e)}${Me(n)}${Me(r)}`}function Me(t){return t.toString(16).padStart(2,"0")}function vn(t){const e={};for(const n of t)e[n]=(e[n]??0)+1;return e}function wn(t){return Array.from(new Set(t))}function mt(t={}){return new je([new Ke(t),new rt(t),new ct(t)])}function pt(t){const e=t;return e.nativeRenderer===!0&&typeof e.mount=="function"}const xn={1:"#ff0000",2:"#ffff00",3:"#00ff00",4:"#00ffff",5:"#0000ff",6:"#ff00ff",8:"#808080",9:"#c0c0c0",10:"#ff0000",11:"#ff7f7f",12:"#a50000",13:"#a55252",14:"#7f0000",15:"#7f3f3f",16:"#4c0000",17:"#4c2626",18:"#260000",19:"#261313",20:"#ff3f00",21:"#ff9f7f",22:"#a52900",23:"#a56752",24:"#7f1f00",25:"#7f4f3f",26:"#4c1300",27:"#4c2f26",28:"#260900",29:"#261713",30:"#ff7f00",31:"#ffbf7f",32:"#a55200",33:"#a57c52",34:"#7f3f00",35:"#7f5f3f",36:"#4c2600",37:"#4c3926",38:"#261300",39:"#261c13",40:"#ffbf00",41:"#ffdf7f",42:"#a57c00",43:"#a59152",44:"#7f5f00",45:"#7f6f3f",46:"#4c3900",47:"#4c4226",48:"#261c00",49:"#262113",50:"#ffff00",51:"#ffff7f",52:"#a5a500",53:"#a5a552",54:"#7f7f00",55:"#7f7f3f",56:"#4c4c00",57:"#4c4c26",58:"#262600",59:"#262613",60:"#bfff00",61:"#dfff7f",62:"#7ca500",63:"#91a552",64:"#5f7f00",65:"#6f7f3f",66:"#394c00",67:"#424c26",68:"#1c2600",69:"#212613",70:"#7fff00",71:"#bfff7f",72:"#52a500",73:"#7ca552",74:"#3f7f00",75:"#5f7f3f",76:"#264c00",77:"#394c26",78:"#132600",79:"#1c2613",80:"#3fff00",81:"#9fff7f",82:"#29a500",83:"#67a552",84:"#1f7f00",85:"#4f7f3f",86:"#134c00",87:"#2f4c26",88:"#092600",89:"#172613",90:"#00ff00",91:"#7fff7f",92:"#00a500",93:"#52a552",94:"#007f00",95:"#3f7f3f",96:"#004c00",97:"#264c26",98:"#002600",99:"#132613",100:"#00ff3f",101:"#7fff9f",102:"#00a529",103:"#52a567",104:"#007f1f",105:"#3f7f4f",106:"#004c13",107:"#264c2f",108:"#002609",109:"#132617",110:"#00ff7f",111:"#7fffbf",112:"#00a552",113:"#52a57c",114:"#007f3f",115:"#3f7f5f",116:"#004c26",117:"#264c39",118:"#002613",119:"#13261c",120:"#00ffbf",121:"#7fffdf",122:"#00a57c",123:"#52a591",124:"#007f5f",125:"#3f7f6f",126:"#004c39",127:"#264c42",128:"#00261c",129:"#132621",130:"#00ffff",131:"#7fffff",132:"#00a5a5",133:"#52a5a5",134:"#007f7f",135:"#3f7f7f",136:"#004c4c",137:"#264c4c",138:"#002626",139:"#132626",140:"#00bfff",141:"#7fdfff",142:"#007ca5",143:"#5291a5",144:"#005f7f",145:"#3f6f7f",146:"#00394c",147:"#26424c",148:"#001c26",149:"#132126",150:"#007fff",151:"#7fbfff",152:"#0052a5",153:"#527ca5",154:"#003f7f",155:"#3f5f7f",156:"#00264c",157:"#26394c",158:"#001326",159:"#131c26",160:"#003fff",161:"#7f9fff",162:"#0029a5",163:"#5267a5",164:"#001f7f",165:"#3f4f7f",166:"#00134c",167:"#262f4c",168:"#000926",169:"#131726",170:"#0000ff",171:"#7f7fff",172:"#0000a5",173:"#5252a5",174:"#00007f",175:"#3f3f7f",176:"#00004c",177:"#26264c",178:"#000026",179:"#131326",180:"#3f00ff",181:"#9f7fff",182:"#2900a5",183:"#6752a5",184:"#1f007f",185:"#4f3f7f",186:"#13004c",187:"#2f264c",188:"#090026",189:"#171326",190:"#7f00ff",191:"#bf7fff",192:"#5200a5",193:"#7c52a5",194:"#3f007f",195:"#5f3f7f",196:"#26004c",197:"#39264c",198:"#130026",199:"#1c1326",200:"#bf00ff",201:"#df7fff",202:"#7c00a5",203:"#9152a5",204:"#5f007f",205:"#6f3f7f",206:"#39004c",207:"#42264c",208:"#1c0026",209:"#211326",210:"#ff00ff",211:"#ff7fff",212:"#a500a5",213:"#a552a5",214:"#7f007f",215:"#7f3f7f",216:"#4c004c",217:"#4c264c",218:"#260026",219:"#261326",220:"#ff00bf",221:"#ff7fdf",222:"#a5007c",223:"#a55291",224:"#7f005f",225:"#7f3f6f",226:"#4c0039",227:"#4c2642",228:"#26001c",229:"#261321",230:"#ff007f",231:"#ff7fbf",232:"#a50052",233:"#a5527c",234:"#7f003f",235:"#7f3f5f",236:"#4c0026",237:"#4c2639",238:"#260013",239:"#26131c",240:"#ff003f",241:"#ff7f9f",242:"#a50029",243:"#a55267",244:"#7f001f",245:"#7f3f4f",246:"#4c0013",247:"#4c262f",248:"#260009",249:"#261317",250:"#333333",251:"#505050",252:"#696969",253:"#828282",254:"#bebebe",255:"#ffffff"};function F(t,e="#ffffff",n=e){if(typeof t!="number"||Number.isNaN(t))return e;const r=Math.abs(Math.trunc(t));return r===0||r===256||r===257?e:r===7?n:xn[r]??e}function G(t,e="rgb"){const n=Math.max(0,Math.trunc(t))&16777215,r=n>>16&255,i=n>>8&255,o=n&255;return`rgb(${e==="rgb"?r:o}, ${i}, ${e==="rgb"?o:r})`}function Z(t){if(typeof t=="string"){const e=t.trim();return e?/^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(e)?Cn(e)??e:{red:"#ff0000",yellow:"#ffff00",green:"#00ff00",cyan:"#00ffff",blue:"#0000ff",magenta:"#ff00ff",white:"#ffffff",black:"#000000",grey:"#808080",gray:"#808080"}[e.toLowerCase()]:void 0}if(t&&typeof t=="object"){const e=t,n=Number(e.r??e.red),r=Number(e.g??e.green),i=Number(e.b??e.blue),o=Number(e.a??e.alpha??1);if([n,r,i].every(Number.isFinite))return Number.isFinite(o)&&o>=0&&o<1?`rgba(${n}, ${r}, ${i}, ${o})`:`rgb(${n}, ${r}, ${i})`}}function Cn(t){if(!t)return;const e=t.trim();if(/^#[0-9a-f]{8}$/i.test(e)){const n=parseInt(e.slice(1,3),16)/255,r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16),o=parseInt(e.slice(7,9),16);return n>=.999?`rgb(${r}, ${i}, ${o})`:`rgba(${r}, ${i}, ${o}, ${Ae(n)})`}if(/^#[0-9a-f]{6}$/i.test(e)||/^#[0-9a-f]{3}$/i.test(e))return e;if(/^sc#/i.test(e)){const n=e.slice(3).split(",").map(a=>Number(a.trim())),[r,i,o,s]=n.length===4?n:[1,...n];if([r,i,o,s].every(Number.isFinite))return`rgba(${Math.round(i*255)}, ${Math.round(o*255)}, ${Math.round(s*255)}, ${Ae(r)})`}}function _(t,e,n={}){const r=n.foreground??"#ffffff",i=r;let o;const s=Z(t.trueColor)??Z(t.color)??Z(t.colorName);if(s&&(o=s),!o){const a=En(t,["trueColor","true_color","truecolor","colorRGB","colorRgb","rgbColor","rgb"]);typeof a=="number"&&a>=0&&a<=16777215&&(o=G(a,n.trueColorByteOrder??"rgb"))}if(!o){const a=vt(t.colorIndex,t.colorNumber,t.aci);typeof a=="number"&&Math.abs(a)<=257&&a!==256&&a!==0&&a!==257&&(o=F(a,i,r))}if(!o&&typeof t.color=="number"){const a=Number(t.color);Math.abs(a)<=257?a!==0&&a!==256&&a!==257&&(o=F(a,i,r)):o=G(a,n.trueColorByteOrder??"rgb")}if(!o){const a=Mn(e,t.layer);o=kn(a,n)}return gt(o??i,n)}function Ee(t,e,n={}){let r;const i=Z(t.fillColor);if(i&&(r=i),!r&&typeof t.fillColor=="number"){const o=t.fillColor;r=Math.abs(o)<=257?F(o,n.foreground??"#ffffff",n.foreground??"#ffffff"):G(o,n.trueColorByteOrder??"rgb")}return!r&&typeof t.fillColorIndex=="number"&&(r=F(t.fillColorIndex,n.foreground??"#ffffff",n.foreground??"#ffffff")),r?gt(r,n):void 0}function gt(t,e={}){if(e.contrastMode!=="adaptive")return t;const n=e.background??"#0b1020",r=e.foreground??"#ffffff";return Pn(t,n,r,e.minColorContrast??2.4)}function Pn(t,e,n,r=2.4){const i=Le(n)??{r:255,g:255,b:255,a:1},o=Le(e)??{r:11,g:16,b:32,a:1},s=Le(t);if(!s)return t;const a=wt(s,o);if(Te(a,o)>=r)return t;const c=Ie(o),l=c<.5?{r:255,g:255,b:255,a:s.a}:{r:0,g:0,b:0,a:s.a};for(const f of[.25,.4,.55,.7,.85,1]){const h=Ln(s,l,f);if(Te(wt(h,o),o)>=r)return xt(h)}return Te(i,o)>=r?xt(i):c<.5?"#ffffff":"#000000"}function bt(t){return t?t.isVisible!==!1&&t.isFrozen!==!0:!0}function kn(t,e){if(!t)return;const n=e.foreground??"#ffffff",r=Z(t.trueColor);if(r)return r;if(typeof t.trueColor=="number"&&t.trueColor>=0&&t.trueColor<=16777215)return G(t.trueColor,e.trueColorByteOrder??"rgb");const i=Z(t.color);if(i)return i;if(Nn(t.colorIndex))return F(t.colorIndex,n,n);if(typeof t.color=="number"){const o=Number(t.color);return Math.abs(o)<=257?F(o,n,n):G(o,e.trueColorByteOrder??"rgb")}if(typeof t.colorIndex=="number")return F(t.colorIndex,n,n)}function Sn(t){return vt(t.colorIndex,t.colorNumber,t.aci)===0?!0:t.trueColor===void 0&&t.color===0}function yt(t,e,n,r={}){if(!Sn(t))return t;const i=_(e,n,r);return{...t,color:i,trueColor:void 0,colorIndex:void 0,colorNumber:void 0}}function Nn(t){return typeof t=="number"&&Number.isFinite(t)&&Math.abs(Math.trunc(t))>=1&&Math.abs(Math.trunc(t))<=255}function Mn(t,e){if(!(!t||!e))return t.layers[e]??t.layers[e.toLowerCase()]??Object.values(t.layers).find(n=>n.name.toLowerCase()===e.toLowerCase())}function vt(...t){for(const e of t)if(typeof e=="number"&&Number.isFinite(e))return e}function En(t,e){const n=t;for(const r of e){const i=n[r];if(typeof i=="number"&&Number.isFinite(i))return i}}function Le(t){const e=t.trim().toLowerCase();if(/^#[0-9a-f]{3}$/i.test(e))return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:1};if(/^#[0-9a-f]{6}$/i.test(e))return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:1};const n=e.match(/^rgba?\(([^)]+)\)$/i);if(n){const r=n[1].split(/[,\s/]+/).filter(Boolean).map(i=>Number(i.replace("%","")));if(r.length>=3&&r.slice(0,3).every(Number.isFinite)){const i=/%/.test(n[1]);return{r:q(i?r[0]*2.55:r[0]),g:q(i?r[1]*2.55:r[1]),b:q(i?r[2]*2.55:r[2]),a:Number.isFinite(r[3])?Math.max(0,Math.min(1,r[3])):1}}}}function wt(t,e){const n=t.a+e.a*(1-t.a);return n<=0?{r:0,g:0,b:0,a:0}:{r:(t.r*t.a+e.r*e.a*(1-t.a))/n,g:(t.g*t.a+e.g*e.a*(1-t.a))/n,b:(t.b*t.a+e.b*e.a*(1-t.a))/n,a:n}}function Ln(t,e,n){const r=Math.max(0,Math.min(1,n));return{r:t.r+(e.r-t.r)*r,g:t.g+(e.g-t.g)*r,b:t.b+(e.b-t.b)*r,a:t.a}}function Ie(t){const e=[t.r,t.g,t.b].map(n=>{const r=n/255;return r<=.03928?r/12.92:((r+.055)/1.055)**2.4});return .2126*e[0]+.7152*e[1]+.0722*e[2]}function Te(t,e){const n=Ie(t),r=Ie(e),i=Math.max(n,r),o=Math.min(n,r);return(i+.05)/(o+.05)}function xt(t){const e=q(t.r),n=q(t.g),r=q(t.b);return t.a<.999?`rgba(${e}, ${n}, ${r}, ${Ae(t.a)})`:`rgb(${e}, ${n}, ${r})`}function q(t){return Math.max(0,Math.min(255,Math.round(t)))}function Ae(t){return Math.round(t*1e3)/1e3}const Ct=1e5,Pt=new Set(["","bylayer","15"]),Be=new Set(["byblock","14"]),In=new Set(["continuous","16"]),K=t=>String(t??"").trim().toLowerCase();function Tn(t){return Be.has(K(t))}function Fe(t,e,n){if(!Tn(t.lineType))return t;const r=De(e,n);return{...t,lineType:r||"Continuous",lineTypeScale:te(t.lineTypeScale,1)*te(e.lineTypeScale,1)}}function De(t,e){var i;let n=String(t.lineType??"").trim();const r=K(n);return Pt.has(r)?n=((i=Rn(e,t.layer))==null?void 0:i.lineType)??"Continuous":Be.has(r)&&(n="Continuous"),n||"Continuous"}function ue(t,e){var h,d;if(!e)return;const n=De(t,e),r=K(n);if(In.has(r)||Pt.has(r)||Be.has(r))return;const i=Dn(e,n);if(!(i!=null&&i.pattern.length))return;const o=te(t.lineTypeScale,te((h=e.header)==null?void 0:h.CELTSCALE,1)),s=te((d=e.header)==null?void 0:d.LTSCALE,1)*o,a=Bn(i,s),c=a.reduce((m,g)=>m+g.length,0);if(!Number.isFinite(c)||c<=1e-9)return;const l=a.some(m=>!m.draw&&m.length>1e-12),f=a.some(m=>m.marker);if(!(!l&&!f))return{name:i.name,segments:Fn(a,l),runs:a,period:c}}function An(t,e,n){return me(t,e,n).segments}function me(t,e,n,r=Ct){const i=t.filter(y=>Number.isFinite(y.x)&&Number.isFinite(y.y));if(i.length<2||n.runs.length===0)return{segments:[],dots:[]};const o=[];for(let y=0;y<i.length-1;y++)o.push([i[y],i[y+1]]);e&&o.push([i[i.length-1],i[0]]);const s=Number.isFinite(r)?Math.max(1,Math.floor(r)):Ct,a=o.reduce((y,[x,L])=>y+Math.hypot(L.x-x.x,L.y-x.y),0),l=(n.period>1e-12?a/n.period:Number.POSITIVE_INFINITY)*Math.max(1,n.runs.length);if(!Number.isFinite(l)||l>s)return{segments:o,dots:[]};const f={segments:[],dots:[]};let h=0,d=n.runs[0].length,m=!0;const g=y=>{const x=f.dots[f.dots.length-1];x&&Math.hypot(x.x-y.x,x.y-y.y)<=1e-10||f.dots.push(y)},S=()=>{h=(h+1)%n.runs.length,d=n.runs[h].length,m=!0};for(const[y,x]of o){const L=x.x-y.x,D=x.y-y.y,A=Math.hypot(L,D);if(A<=1e-14)continue;let H=0;for(;H<A-1e-12;){let Ft=0;for(;d<=1e-12&&Ft<n.runs.length;){const U=n.runs[h];if(m&&U.marker){const re=H/A;g({x:y.x+L*re,y:y.y+D*re})}S(),Ft++}if(d<=1e-12)break;const Dt=n.runs[h];if(m){if(Dt.marker){const U=H/A;g({x:y.x+L*U,y:y.y+D*U})}m=!1}const ve=Math.min(d,A-H);if(Dt.draw&&ve>1e-12){const U=H/A,re=(H+ve)/A;f.segments.push([{x:y.x+L*U,y:y.y+D*U},{x:y.x+L*re,y:y.y+D*re}])}H+=ve,d-=ve,d<=1e-12&&S()}}return f}function Bn(t,e){const n=[];for(const r of t.pattern){const i=Number(r.length),o=Number(r.elementTypeFlag??0)!==0;Number.isFinite(i)&&n.push({draw:i>=0,length:Math.abs(i)*e,marker:i>=0&&(i===0||o)})}return n}function Fn(t,e){if(!e)return[];const n=[];for(const i of t){if(i.length<=1e-12)continue;const o=n[n.length-1];(o==null?void 0:o.draw)===i.draw?o.length+=i.length:n.push({draw:i.draw,length:i.length})}const r=[];for(const i of n){const o=r.length%2===0;i.draw!==o&&r.push(1e-9),r.push(i.length)}return r.length%2===1&&r.push(1e-9),r}function Dn(t,e){const n=K(e),r=t.lineTypes??{};return r[e]??r[n]??Object.values(r).find(i=>K(i.name)===n||K(i.handle)===n)}function Rn(t,e){if(!(!t||!e))return t.layers[e]??t.layers[e.toLowerCase()]??Object.values(t.layers).find(n=>n.name.toLowerCase()===e.toLowerCase())}function te(t,e){const n=Number(t);return Number.isFinite(n)&&n>0?n:e}const On={a:1,b:0,c:0,d:1,e:0,f:0};function pe(t,e){return{a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,e:t.a*e.e+t.c*e.f+t.e,f:t.b*e.e+t.d*e.f+t.f}}function kt(t,e){return{a:1,b:0,c:0,d:1,e:t,f:e}}function St(t){const e=Math.cos(t),n=Math.sin(t);return{a:e,b:n,c:-n,d:e,e:0,f:0}}function Wn(t,e=t){return{a:t,b:0,c:0,d:e,e:0,f:0}}function I(t,e){return{x:t.x*e.a+t.y*e.c+e.e,y:t.x*e.b+t.y*e.d+e.f,z:"z"in t?t.z:void 0}}function Nt(t,e){if(t)return t.map(n=>({cmd:n.cmd,points:n.points.map(r=>I(r,e))}))}function ge(t,e={x:0,y:0}){const n=t.insertionPoint??{x:0,y:0},r=t.scale,i=Number(typeof r=="object"&&r?r.x??1:t.scaleX??1),o=Number(typeof r=="object"&&r?r.y??i:t.scaleY??i),s=Number(t.rotation??0);let a=kt(n.x,n.y);return a=pe(a,St(Number.isFinite(s)?s:0)),a=pe(a,Wn(Number.isFinite(i)?i:1,Number.isFinite(o)?o:1)),a=pe(a,kt(-e.x,-e.y)),a}function Y(t,e){const n={...t};if(t.startPoint&&(n.startPoint=I(t.startPoint,e)),t.endPoint&&(n.endPoint=I(t.endPoint,e)),t.center&&(n.center=I(t.center,e)),t.insertionPoint&&(n.insertionPoint=I(t.insertionPoint,e)),t.majorAxisEndPoint){const s=I({x:0,y:0},e),a=I(t.majorAxisEndPoint,e);n.majorAxisEndPoint={x:a.x-s.x,y:a.y-s.y,z:a.z}}t.vertices&&(n.vertices=t.vertices.map(s=>({...I(s,e),bulge:s.bulge,startWidth:s.startWidth,endWidth:s.endWidth}))),t.points&&(n.points=t.points.map(s=>I(s,e))),t.controlPoints&&(n.controlPoints=t.controlPoints.map(s=>I(s,e))),t.fitPoints&&(n.fitPoints=t.fitPoints.map(s=>I(s,e))),t.attribs&&(n.attribs=t.attribs.map(s=>Y(s,e))),t.commands&&(n.commands=Nt(t.commands,e)),t.loops&&(n.loops=t.loops.map(s=>{var a;return{...s,vertices:(a=s.vertices)==null?void 0:a.map(c=>I(c,e)),commands:Nt(s.commands,e)}}));const r=Math.sqrt(Math.abs(e.a*e.d-e.b*e.c));typeof t.radius=="number"&&Number.isFinite(r)&&(n.radius=t.radius*r);const i=Math.atan2(e.b,e.a),o=t.kind==="ellipse"||String(t.type??"").toUpperCase()==="ELLIPSE";return Number.isFinite(i)&&Math.abs(i)>1e-14&&((typeof t.rotation=="number"||t.kind==="text"||t.kind==="insert")&&(n.rotation=Number(t.rotation??0)+i),!o&&typeof t.startAngle=="number"&&(n.startAngle=t.startAngle+i),!o&&typeof t.endAngle=="number"&&(n.endAngle=t.endAngle+i)),e.a*e.d-e.b*e.c<0&&n.vertices&&(n.vertices=n.vertices.map(s=>({...s,bulge:typeof s.bulge=="number"?-s.bulge:void 0}))),n}const zn=t=>Math.abs(t.a-1)<1e-12&&Math.abs(t.b)<1e-12&&Math.abs(t.c)<1e-12&&Math.abs(t.d-1)<1e-12&&Math.abs(t.e)<1e-9&&Math.abs(t.f)<1e-9;function Re(t){var n,r,i;if(t.metadata.sceneTransformApplied===!0||((n=t.savedView)==null?void 0:n.sceneTransformApplied)===!1)return t;const e=((r=t.savedView)==null?void 0:r.sceneTransform)??On;return zn(e)?t:{...t,entities:t.entities.map(o=>Y(o,e)),pages:(i=t.pages)==null?void 0:i.map(o=>({...o,entities:o.entities.map(s=>Y(s,e))})),metadata:{...t.metadata,sceneTransformApplied:!0}}}const _n={background:"#0b1020",foreground:"#ffffff",showUnsupportedMarkers:!1,showImagePlaceholders:!0,showPageBounds:!0,minScale:1e-9,maxScale:1e9,wheelZoomFactor:1.14,trueColorByteOrder:"rgb",maxInsertDepth:16,contrastMode:"adaptive",minColorContrast:2.4,maxCurveSegments:96,spatialIndexCellCount:72,maxVerticesPerBatch:65536,textMinPixelHeight:4,maxVisibleTextLabels:2500,powerPreference:"high-performance",antialias:!0,preserveDrawingBuffer:!1,enableSpatialIndex:!0};class Oe{constructor(e,n={}){u(this,"canvas");u(this,"ctx");u(this,"opts");u(this,"sourceDocument");u(this,"document");u(this,"bounds",B());u(this,"view",{centerX:0,centerY:0,scale:1});u(this,"fitScale",1);u(this,"dpr",1);u(this,"isDragging",!1);u(this,"lastPointer");u(this,"resizeObserver");u(this,"imageCache",new Map);u(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"canvas2d"});u(this,"onStats");u(this,"onViewChange");const r=e.getContext("2d");if(!r)throw new Error("Canvas 2D context is not available.");this.canvas=e,this.ctx=r,this.opts={..._n,...n},this.canvas.classList.add("cad-viewer-canvas"),this.bindEvents(),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e)),this.resize()}destroy(){var e;(e=this.resizeObserver)==null||e.disconnect()}clear(){this.sourceDocument=void 0,this.document=void 0,this.bounds=B(),this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange()}setDocument(e){this.sourceDocument=e,this.document=Re(e),this.bounds=this.computeBounds(this.document),this.fitToView()}getDocument(){return this.document}getSourceDocument(){return this.sourceDocument}setOptions(e){Object.assign(this.opts,e),this.render(),this.emitViewChange()}getOptions(){return{...this.opts}}fitToView(e=.92){if(!j(this.bounds)){this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange();return}const n=Math.max(1,this.cssWidth),r=Math.max(1,this.cssHeight),i=Math.max(this.bounds.maxX-this.bounds.minX,1e-9),o=Math.max(this.bounds.maxY-this.bounds.minY,1e-9),s=this.clampScale(Math.min(n/i,r/o)*e);this.fitScale=s,this.view={centerX:(this.bounds.minX+this.bounds.maxX)/2,centerY:(this.bounds.minY+this.bounds.maxY)/2,scale:s},this.render(),this.emitViewChange()}resize(){this.dpr=Math.max(1,window.devicePixelRatio||1);const e=Math.max(1,Math.floor(this.cssWidth*this.dpr)),n=Math.max(1,Math.floor(this.cssHeight*this.dpr));(this.canvas.width!==e||this.canvas.height!==n)&&(this.canvas.width=e,this.canvas.height=n),this.render(),this.emitViewChange()}zoom(e,n){if(!Number.isFinite(e)||e<=0)return;const r=n??{x:this.cssWidth/2,y:this.cssHeight/2},i=this.screenToWorld(r);this.view.scale=this.clampScale(this.view.scale*e);const o=this.screenToWorld(r);this.view.centerX+=i.x-o.x,this.view.centerY+=i.y-o.y,this.render(),this.emitViewChange()}zoomIn(){this.zoom(this.opts.wheelZoomFactor)}zoomOut(){this.zoom(1/this.opts.wheelZoomFactor)}panByScreenDelta(e,n){!Number.isFinite(e)||!Number.isFinite(n)||(this.view.centerX-=e/this.view.scale,this.view.centerY+=n/this.view.scale,this.render(),this.emitViewChange())}setViewState(e){if(![e.centerX,e.centerY,e.scale].every(Number.isFinite))throw new Error("Invalid view state.");this.view={...e,scale:this.clampScale(e.scale)},this.render(),this.emitViewChange()}getViewState(){return{...this.view}}getBounds(){return{...this.bounds}}getStats(){return Yn(this.stats)}getZoomRatio(){return Math.abs(this.fitScale)<1e-12?1:this.view.scale/this.fitScale}getZoomPercent(){return this.getZoomRatio()*100}worldToScreen(e){return{x:this.cssWidth/2+(e.x-this.view.centerX)*this.view.scale,y:this.cssHeight/2-(e.y-this.view.centerY)*this.view.scale}}screenToWorld(e){return{x:this.view.centerX+(e.x-this.cssWidth/2)/this.view.scale,y:this.view.centerY-(e.y-this.cssHeight/2)/this.view.scale}}render(){var n,r;const e=performance.now();if(this.stats={total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"canvas2d"},this.clearCanvas(),this.document){this.opts.showPageBounds&&((n=this.document.pages)!=null&&n.length)&&this.drawPageBounds(this.document);for(const i of this.document.entities)this.drawEntityTracked(i,0)}return this.stats.renderElapsedMs=performance.now()-e,(r=this.onStats)==null||r.call(this,this.getStats()),this.getStats()}get cssWidth(){return this.canvas.clientWidth||1}get cssHeight(){return this.canvas.clientHeight||1}bindEvents(){this.canvas.addEventListener("wheel",n=>{n.preventDefault();const r=n.deltaY<0?this.opts.wheelZoomFactor:1/this.opts.wheelZoomFactor;this.zoom(r,{x:n.offsetX,y:n.offsetY})},{passive:!1}),this.canvas.addEventListener("pointerdown",n=>{this.canvas.setPointerCapture(n.pointerId),this.isDragging=!0,this.lastPointer={x:n.clientX,y:n.clientY},this.canvas.classList.add("is-dragging")}),this.canvas.addEventListener("pointermove",n=>{!this.isDragging||!this.lastPointer||(this.panByScreenDelta(n.clientX-this.lastPointer.x,n.clientY-this.lastPointer.y),this.lastPointer={x:n.clientX,y:n.clientY})});const e=n=>{n&&this.canvas.hasPointerCapture(n.pointerId)&&this.canvas.releasePointerCapture(n.pointerId),this.isDragging=!1,this.lastPointer=void 0,this.canvas.classList.remove("is-dragging")};this.canvas.addEventListener("pointerup",e),this.canvas.addEventListener("pointercancel",()=>e())}clearCanvas(){const e=this.ctx;e.save(),e.setTransform(this.dpr,0,0,this.dpr,0,0),e.clearRect(0,0,this.cssWidth,this.cssHeight),e.fillStyle=this.opts.background,e.fillRect(0,0,this.cssWidth,this.cssHeight),e.restore()}drawPageBounds(e){const n=this.ctx;n.save(),n.setTransform(this.dpr,0,0,this.dpr,0,0),n.strokeStyle="rgba(148, 163, 184, 0.35)",n.lineWidth=1,n.setLineDash([8,6]);for(const r of e.pages??[]){const i=this.worldToScreen({x:0,y:0}),o=this.worldToScreen({x:r.width,y:r.height});n.strokeRect(Math.min(i.x,o.x),Math.min(i.y,o.y),Math.abs(o.x-i.x),Math.abs(o.y-i.y))}n.restore()}drawEntityTracked(e,n){this.stats.total++;const r=String(e.type??"UNKNOWN").toUpperCase();this.stats.byType[r]=(this.stats.byType[r]??0)+1;const i=this.lookupLayer(e.layer);if(e.isVisible===!1||!bt(i)){this.stats.skipped++;return}this.drawEntity(e,r,n)}drawEntity(e,n,r){switch(e.kind??O(n)){case"line":return this.drawLine(e);case"circle":return this.drawCircle(e);case"arc":return this.drawArc(e);case"polyline":return this.drawPolyline(e);case"ellipse":return this.drawEllipse(e);case"text":return this.drawText(e);case"point":return this.drawPoint(e);case"insert":return this.drawInsert(e,r);case"solid":return this.drawSolid(e);case"hatch":return this.drawHatch(e);case"spline":return this.drawSpline(e);case"path":return this.drawPath(e);case"image":return this.drawImage(e);case"viewport":return this.markSkipped(n);default:this.stats.unsupported[n]=(this.stats.unsupported[n]??0)+1,this.stats.skipped++,this.opts.showUnsupportedMarkers&&this.drawUnsupportedMarker(e)}}beginStyledPath(e,n=!1,r=!0){const i=this.ctx;i.save(),i.setTransform(this.dpr,0,0,this.dpr,0,0);const o=_(e,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}),s=Ee(e,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast})??o;i.strokeStyle=o,i.fillStyle=n?s:o,i.globalAlpha=$(Number(e.opacity??1),0,1),i.lineCap="round",i.lineJoin="round";const a=typeof e.lineweight=="number"&&e.lineweight>0?e.lineweight:0;i.lineWidth=Math.max(1,Math.min(12,a>0?a/30:1));const c=r?ue(e,this.document):void 0;i.setLineDash(c?c.segments.map(l=>Math.max(.05,l*this.view.scale)):[]),i.beginPath()}finishStroke(){this.ctx.stroke(),this.ctx.restore(),this.stats.drawn++}finishFillStroke(e=!1){e&&this.ctx.fill(),this.ctx.stroke(),this.ctx.restore(),this.stats.drawn++}drawLine(e){const n=e.startPoint,r=e.endPoint;if(!p(n)||!p(r))return this.markSkipped("LINE");this.strokeWorldPolyline(e,[n,r],!1)}drawCircle(e){const n=e.center,r=Number(e.radius);if(!p(n)||!Number.isFinite(r))return this.markSkipped("CIRCLE");this.strokeWorldPolyline(e,Q(k(n),r,0,Math.PI*2,!0),!0)}drawArc(e){const n=e.center,r=Number(e.radius),i=Number(e.startAngle),o=Number(e.endAngle);if(!p(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(o))return this.markSkipped("ARC");this.strokeWorldPolyline(e,Q(k(n),r,i,o,!0),!1)}drawPolyline(e){const n=e.vertices??e.points;if(!Array.isArray(n)||n.length<2)return this.markSkipped(String(e.type));const r=Ce(e),i=[],o=r?n.length:n.length-1;for(let s=0;s<o;s++){const a=n[s],c=n[(s+1)%n.length];if(!p(a)||!p(c))continue;const l=tt(a,c,Number(a.bulge??0));i.length>0&&l.shift(),i.push(...l)}this.strokeWorldPolyline(e,i,r)}drawEllipse(e){const n=e.center,r=e.majorAxisEndPoint,i=Number(e.axisRatio??1);if(!p(n)||!p(r))return this.markSkipped("ELLIPSE");const o=le(n,r,i,Number(e.startAngle??0),Number(e.endAngle??Math.PI*2)),s=Math.abs(Number(e.endAngle??Math.PI*2)-Number(e.startAngle??0))>=Math.PI*2-1e-6;this.strokeWorldPolyline(e,o,s)}drawPoint(e){const n=e.point??e.location??e.center??e.insertionPoint;if(!p(n))return this.markSkipped("POINT");const r=this.worldToScreen(n);this.beginStyledPath(e),this.ctx.moveTo(r.x-3,r.y),this.ctx.lineTo(r.x+3,r.y),this.ctx.moveTo(r.x,r.y-3),this.ctx.lineTo(r.x,r.y+3),this.finishStroke()}drawText(e){const n=e.insertionPoint??e.startPoint??e.center,r=nt(String(e.text??e.value??"")),i=Number(e.textHeight??e.height??1);if(!p(n)||!r)return this.markSkipped(String(e.type));this.drawTextAt(e,n,r,i,Number(e.rotation??0))}drawInsert(e,n){const r=this.lookupBlock(e.blockName??e.name);if(r&&n<this.opts.maxInsertDepth){const a=ge(e,r.basePoint??{x:0,y:0});for(const c of r.entities){const l=yt(c,e,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}),f=Fe(l,e,this.document);this.drawEntityTracked(Y(f,a),n+1)}return}const i=e.insertionPoint;if(!p(i))return this.markSkipped("INSERT");const o=this.worldToScreen(i);this.beginStyledPath(e);const s=5;if(this.ctx.rect(o.x-s,o.y-s,s*2,s*2),this.finishStroke(),Array.isArray(e.attribs))for(const a of e.attribs)this.drawText(a)}drawSolid(e){const n=e.vertices??e.points;if(!Array.isArray(n)||n.length<3)return this.markSkipped(String(e.type));this.beginStyledPath(e,!0);const r=this.worldToScreen(n[0]);this.ctx.moveTo(r.x,r.y);for(const i of n.slice(1)){if(!p(i))continue;const o=this.worldToScreen(i);this.ctx.lineTo(o.x,o.y)}this.ctx.closePath(),this.finishFillStroke(!0)}drawHatch(e){var r,i;const n=e.loops;if(!Array.isArray(n)||n.length===0)return this.markSkipped("HATCH");this.beginStyledPath(e,!0);for(const o of n)if((r=o.commands)!=null&&r.length)this.addPathCommands(o.commands);else if((i=o.vertices)!=null&&i.length){const s=this.worldToScreen(o.vertices[0]);this.ctx.moveTo(s.x,s.y);for(const a of o.vertices.slice(1)){const c=this.worldToScreen(a);this.ctx.lineTo(c.x,c.y)}this.ctx.closePath()}this.finishFillStroke(!!Ee(e,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}))}drawSpline(e){var r;const n=(r=e.fitPoints)!=null&&r.length?e.fitPoints:e.controlPoints;if(!n||n.length<2)return this.markSkipped("SPLINE");this.strokeWorldPolyline(e,n,!!e.isClosed)}drawPath(e){var n;if(!((n=e.commands)!=null&&n.length))return this.markSkipped(String(e.type));this.beginStyledPath(e,!!e.fillColor),this.addPathCommands(e.commands),this.finishFillStroke(!!e.fillColor)}addPathCommands(e){for(const n of e)if(n.cmd==="M"){const r=this.worldToScreen(n.points[0]);this.ctx.moveTo(r.x,r.y)}else if(n.cmd==="L"){const r=this.worldToScreen(n.points[0]);this.ctx.lineTo(r.x,r.y)}else if(n.cmd==="C"){const[r,i,o]=n.points.map(s=>this.worldToScreen(s));this.ctx.bezierCurveTo(r.x,r.y,i.x,i.y,o.x,o.y)}else if(n.cmd==="Q"){const[r,i]=n.points.map(o=>this.worldToScreen(o));this.ctx.quadraticCurveTo(r.x,r.y,i.x,i.y)}else n.cmd==="Z"&&this.ctx.closePath()}drawImage(e){const n=e.insertionPoint;if(!p(n))return this.markSkipped(String(e.type));const r=Number(e.width??32),i=Number(e.height??32),o=this.worldToScreen(n),s=this.worldToScreen({x:n.x+r,y:n.y-i}),a=Math.min(o.x,s.x),c=Math.min(o.y,s.y),l=Math.abs(s.x-o.x),f=Math.abs(s.y-o.y),h=e.imageDataUrl;if(h){const d=this.getImage(h);if(d.complete&&d.naturalWidth>0){this.ctx.save(),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0),this.ctx.drawImage(d,a,c,l,f),this.ctx.restore(),this.stats.drawn++;return}d.onload=()=>this.render()}if(!this.opts.showImagePlaceholders)return this.markSkipped(String(e.type));this.beginStyledPath(e),this.ctx.rect(a,c,l,f),this.ctx.moveTo(a,c),this.ctx.lineTo(a+l,c+f),this.ctx.moveTo(a+l,c),this.ctx.lineTo(a,c+f),this.finishStroke()}getImage(e){let n=this.imageCache.get(e);return n||(n=new Image,n.src=e,this.imageCache.set(e,n)),n}drawUnsupportedMarker(e){const n=this.entityAnchor(e);if(!n)return;const r=this.worldToScreen(n);this.beginStyledPath(e),this.ctx.moveTo(r.x-4,r.y-4),this.ctx.lineTo(r.x+4,r.y+4),this.ctx.moveTo(r.x+4,r.y-4),this.ctx.lineTo(r.x-4,r.y+4),this.finishStroke()}drawTextAt(e,n,r,i,o){const s=this.ctx,a=this.worldToScreen(n);s.save(),s.setTransform(this.dpr,0,0,this.dpr,0,0),s.translate(a.x,a.y),s.rotate(-o);const c=Math.max(4,Math.min(256,Math.abs(i)*this.view.scale));s.font=`${c}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,s.fillStyle=_(e,this.document,{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}),s.globalAlpha=$(Number(e.opacity??1),0,1),s.textBaseline="alphabetic";for(const[l,f]of r.split(/\r?\n/g).entries())s.fillText(f,0,l*c*1.22);s.restore(),this.stats.drawn++}strokeWorldPolyline(e,n,r){const i=n.filter(p);if(i.length<2)return this.markSkipped(String(e.type));const o=ue(e,this.document);if(o){const a=me(i,r,o);this.beginStyledPath(e,!1,!1);for(const[c,l]of a.segments){const f=this.worldToScreen(c),h=this.worldToScreen(l);this.ctx.moveTo(f.x,f.y),this.ctx.lineTo(h.x,h.y)}if(this.ctx.stroke(),a.dots.length>0){this.ctx.setLineDash([]),this.ctx.beginPath();const c=Math.max(.5,this.ctx.lineWidth/2);for(const l of a.dots){const f=this.worldToScreen(l);this.ctx.moveTo(f.x+c,f.y),this.ctx.arc(f.x,f.y,c,0,Math.PI*2)}this.ctx.fillStyle=this.ctx.strokeStyle,this.ctx.fill()}this.ctx.restore(),this.stats.drawn++;return}this.beginStyledPath(e);const s=this.worldToScreen(i[0]);this.ctx.moveTo(s.x,s.y);for(const a of i.slice(1)){const c=this.worldToScreen(a);this.ctx.lineTo(c.x,c.y)}r&&this.ctx.closePath(),this.finishStroke()}markSkipped(e){this.stats.skipped++,this.stats.unsupported[e]=this.stats.unsupported[e]??0}entityAnchor(e){for(const n of["startPoint","insertionPoint","center","point","location"]){const r=e[n];if(p(r))return k(r)}if(Array.isArray(e.vertices)&&p(e.vertices[0]))return k(e.vertices[0]);if(Array.isArray(e.commands)&&e.commands.length){const n=e.commands.find(r=>r.points.length>0);if(n)return k(n.points[0])}}computeBounds(e){var r;const n=B();if((r=e.pages)!=null&&r.length)for(const i of e.pages)C(n,{x:0,y:0}),C(n,{x:i.width,y:i.height});for(const i of e.entities)this.includeEntityBounds(n,i,0);return et(n)}includeEntityBounds(e,n,r){const i=String(n.type??"").toUpperCase(),o=n.kind??O(i);if(o==="insert"){const s=this.lookupBlock(n.blockName??n.name);if(s&&r<this.opts.maxInsertDepth){const a=ge(n,s.basePoint??{x:0,y:0});for(const c of s.entities)this.includeEntityBounds(e,Y(c,a),r+1);return}}if(o==="line")p(n.startPoint)&&C(e,n.startPoint),p(n.endPoint)&&C(e,n.endPoint);else if(o==="circle"||o==="arc")p(n.center)&&Number.isFinite(n.radius)&&Qe(e,n.center,Number(n.radius));else if(o==="polyline"||o==="solid"||o==="spline")for(const s of[...n.vertices??[],...n.points??[],...n.controlPoints??[],...n.fitPoints??[]])p(s)&&C(e,s);else if(o==="ellipse")p(n.center)&&p(n.majorAxisEndPoint)&&le(n.center,n.majorAxisEndPoint,Number(n.axisRatio??1),Number(n.startAngle??0),Number(n.endAngle??Math.PI*2)).forEach(s=>C(e,s));else if(o==="path")for(const s of n.commands??[])for(const a of s.points)C(e,a);else if(o==="hatch")for(const s of n.loops??[]){for(const a of s.vertices??[])C(e,a);for(const a of s.commands??[])for(const c of a.points)C(e,c)}else{const s=this.entityAnchor(n);s&&C(e,s)}}lookupLayer(e){if(!(!this.document||!e))return this.document.layers[e]??this.document.layers[e.toLowerCase()]??Object.values(this.document.layers).find(n=>n.name.toLowerCase()===e.toLowerCase())}lookupBlock(e){if(!(!this.document||!e))return this.document.blocks[e]??this.document.blocks[e.toLowerCase()]??Object.values(this.document.blocks).find(n=>n.name.toLowerCase()===e.toLowerCase())}clampScale(e){return Math.min(this.opts.maxScale,Math.max(this.opts.minScale,e))}emitViewChange(){var e;(e=this.onViewChange)==null||e.call(this,{view:this.getViewState(),fitScale:this.fitScale,zoomRatio:this.getZoomRatio(),zoomPercent:this.getZoomPercent(),bounds:this.getBounds()})}}function Yn(t){return{total:t.total,drawn:t.drawn,skipped:t.skipped,byType:{...t.byType},unsupported:{...t.unsupported},renderElapsedMs:t.renderElapsedMs,backend:t.backend,primitiveCount:t.primitiveCount,visiblePrimitiveCount:t.visiblePrimitiveCount,culledPrimitiveCount:t.culledPrimitiveCount,gpuMemoryBytes:t.gpuMemoryBytes,buildElapsedMs:t.buildElapsedMs}}const Vn={background:"#0b1020",foreground:"#ffffff",showUnsupportedMarkers:!1,showImagePlaceholders:!0,showPageBounds:!0,minScale:1e-9,maxScale:1e9,wheelZoomFactor:1.14,trueColorByteOrder:"rgb",maxInsertDepth:16,contrastMode:"adaptive",minColorContrast:2.4,maxCurveSegments:96,spatialIndexCellCount:72,maxVerticesPerBatch:65536,textMinPixelHeight:4,maxVisibleTextLabels:2500,powerPreference:"high-performance",antialias:!0,preserveDrawingBuffer:!1,enableSpatialIndex:!0};class We{constructor(e,n={}){u(this,"canvas");u(this,"backend","webgl");u(this,"gl");u(this,"program");u(this,"eventController",new AbortController);u(this,"imageCache",new Map);u(this,"opts");u(this,"sourceDocument");u(this,"document");u(this,"bounds",B());u(this,"view",{centerX:0,centerY:0,scale:1});u(this,"fitScale",1);u(this,"dpr",1);u(this,"isDragging",!1);u(this,"lastPointer");u(this,"resizeObserver");u(this,"overlayCanvas");u(this,"overlayCtx");u(this,"scene");u(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:0,backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0});u(this,"rafHandle",0);u(this,"onStats");u(this,"onViewChange");const r=Hn(e,n);if(!r)throw new Error('WebGL is not available. Use renderer: "canvas2d" to force the Canvas2D fallback.');this.canvas=e,this.gl=r,this.program=Un(r),this.opts={...Vn,...n},this.canvas.classList.add("cad-viewer-canvas","cad-viewer-webgl-canvas"),this.createOverlayCanvas(),this.bindEvents(),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e)),this.resize()}static isSupported(){return ze()}destroy(){var e,n;this.eventController.abort(),(e=this.resizeObserver)==null||e.disconnect(),this.cancelScheduledRender(),this.disposeScene(),(n=this.overlayCanvas)==null||n.remove()}clear(){this.sourceDocument=void 0,this.document=void 0,this.bounds=B(),this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.disposeScene(),this.render(),this.emitViewChange()}setDocument(e){this.sourceDocument=e,this.document=Re(e),this.bounds=qn(this.document,this.opts),this.disposeScene();const n=jn(this.document,this.opts,this.bounds);this.scene=Xn(this.gl,n),this.stats=Jn(this.scene,0),this.fitToView()}getDocument(){return this.document}getSourceDocument(){return this.sourceDocument}setOptions(e){const n=Kn(this.opts,e);if(this.opts={...this.opts,...e},n&&(this.sourceDocument??this.document)){this.setDocument(this.sourceDocument??this.document);return}this.render(),this.emitViewChange()}getOptions(){return{...this.opts}}fitToView(e=.92){if(!j(this.bounds)){this.view={centerX:0,centerY:0,scale:1},this.fitScale=1,this.render(),this.emitViewChange();return}const n=Math.max(1,this.cssWidth),r=Math.max(1,this.cssHeight),i=Math.max(this.bounds.maxX-this.bounds.minX,1e-9),o=Math.max(this.bounds.maxY-this.bounds.minY,1e-9),s=this.clampScale(Math.min(n/i,r/o)*e);this.fitScale=s,this.view={centerX:(this.bounds.minX+this.bounds.maxX)/2,centerY:(this.bounds.minY+this.bounds.maxY)/2,scale:s},this.render(),this.emitViewChange()}resize(){this.dpr=Math.max(1,window.devicePixelRatio||1);const e=Math.max(1,Math.floor(this.cssWidth*this.dpr)),n=Math.max(1,Math.floor(this.cssHeight*this.dpr));(this.canvas.width!==e||this.canvas.height!==n)&&(this.canvas.width=e,this.canvas.height=n),this.resizeOverlay(e,n),this.render(),this.emitViewChange()}zoom(e,n){if(!Number.isFinite(e)||e<=0)return;const r=n??{x:this.cssWidth/2,y:this.cssHeight/2},i=this.screenToWorld(r);this.view.scale=this.clampScale(this.view.scale*e);const o=this.screenToWorld(r);this.view.centerX+=i.x-o.x,this.view.centerY+=i.y-o.y,this.scheduleRender(),this.emitViewChange()}zoomIn(){this.zoom(this.opts.wheelZoomFactor)}zoomOut(){this.zoom(1/this.opts.wheelZoomFactor)}panByScreenDelta(e,n){!Number.isFinite(e)||!Number.isFinite(n)||(this.view.centerX-=e/this.view.scale,this.view.centerY+=n/this.view.scale,this.scheduleRender(),this.emitViewChange())}setViewState(e){if(![e.centerX,e.centerY,e.scale].every(Number.isFinite))throw new Error("Invalid view state.");this.view={...e,scale:this.clampScale(e.scale)},this.render(),this.emitViewChange()}getViewState(){return{...this.view}}getBounds(){return{...this.bounds}}getStats(){return Qn(this.stats)}getZoomRatio(){return Math.abs(this.fitScale)<1e-12?1:this.view.scale/this.fitScale}getZoomPercent(){return this.getZoomRatio()*100}worldToScreen(e){return{x:this.cssWidth/2+(e.x-this.view.centerX)*this.view.scale,y:this.cssHeight/2-(e.y-this.view.centerY)*this.view.scale}}screenToWorld(e){return{x:this.view.centerX+(e.x-this.cssWidth/2)/this.view.scale,y:this.view.centerY-(e.y-this.cssHeight/2)/this.view.scale}}render(){return this.cancelScheduledRender(),this.renderNow()}renderNow(){var l;const e=performance.now(),n=this.gl;n.viewport(0,0,this.canvas.width,this.canvas.height);const r=Ve(this.opts.background,[11,16,32,255]);n.clearColor(r[0]/255,r[1]/255,r[2]/255,r[3]/255),n.clear(n.COLOR_BUFFER_BIT),n.disable(n.DEPTH_TEST),n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA);let i=0,o=0;const s=this.scene,a=this.visibleWorldBounds();if(s){n.useProgram(this.program.program),n.uniform2f(this.program.uViewCenter,this.view.centerX-s.origin.x,this.view.centerY-s.origin.y),n.uniform1f(this.program.uScale,this.view.scale*this.dpr),n.uniform2f(this.program.uViewport,this.canvas.width,this.canvas.height),n.uniform1f(this.program.uPointSize,Math.max(1,this.dpr));const f=this.drawBatches(s.lineBatches,n.LINES,a);i+=f.visible,o+=f.culled;const h=this.drawBatches(s.triangleBatches,n.TRIANGLES,a);i+=h.visible,o+=h.culled;const d=this.drawBatches(s.lineTypePointBatches,n.POINTS,a);i+=d.visible,o+=d.culled,n.uniform1f(this.program.uPointSize,Math.max(2,Math.min(12,4*this.dpr)));const m=this.drawBatches(s.pointBatches,n.POINTS,a);i+=m.visible,o+=m.culled}this.renderOverlay(a);const c=performance.now()-e;return this.stats=s?{...s.stats,renderElapsedMs:c,backend:"webgl",primitiveCount:s.primitiveCount,visiblePrimitiveCount:i,culledPrimitiveCount:o,gpuMemoryBytes:s.gpuMemoryBytes,buildElapsedMs:s.buildElapsedMs}:{total:0,drawn:0,skipped:0,byType:{},unsupported:{},renderElapsedMs:c,backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0},(l=this.onStats)==null||l.call(this,this.getStats()),this.getStats()}drawBatches(e,n,r){const i=this.gl;let o=0,s=0;for(const a of e){if(!Ye(a.bounds,r)){s+=a.primitiveCount;continue}i.bindBuffer(i.ARRAY_BUFFER,a.positionBuffer),i.enableVertexAttribArray(this.program.aPosition),i.vertexAttribPointer(this.program.aPosition,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,a.colorBuffer),i.enableVertexAttribArray(this.program.aColor),i.vertexAttribPointer(this.program.aColor,4,i.UNSIGNED_BYTE,!0,0,0),i.drawArrays(n,0,a.vertexCount),o+=a.primitiveCount}return{visible:o,culled:s}}scheduleRender(){this.rafHandle||(this.rafHandle=window.requestAnimationFrame(()=>{this.rafHandle=0,this.renderNow()}))}cancelScheduledRender(){this.rafHandle&&(window.cancelAnimationFrame(this.rafHandle),this.rafHandle=0)}renderOverlay(e){var i,o;const n=this.overlayCtx,r=this.overlayCanvas;!n||!r||(n.save(),n.setTransform(this.dpr,0,0,this.dpr,0,0),n.clearRect(0,0,this.cssWidth,this.cssHeight),this.opts.showPageBounds&&((o=(i=this.document)==null?void 0:i.pages)!=null&&o.length)&&this.drawPageBoundsOverlay(n),this.scene&&(this.drawImagesOverlay(n,this.scene.imageItems,e),this.drawTextOverlay(n,this.scene.textItems,e)),n.restore())}drawPageBoundsOverlay(e){var n,r;if((r=(n=this.document)==null?void 0:n.pages)!=null&&r.length){e.save(),e.strokeStyle="rgba(148, 163, 184, 0.34)",e.lineWidth=1,e.setLineDash([8,6]);for(const i of this.document.pages){const o=this.worldToScreen({x:0,y:0}),s=this.worldToScreen({x:i.width,y:i.height});e.strokeRect(Math.min(o.x,s.x),Math.min(o.y,s.y),Math.abs(s.x-o.x),Math.abs(s.y-o.y))}e.restore()}}drawTextOverlay(e,n,r){const i=this.opts.maxVisibleTextLabels;let o=0;for(const s of n){if(o>=i)break;if(!Ye(s.bounds,r))continue;const a=Math.abs(s.height)*this.view.scale;if(a<this.opts.textMinPixelHeight)continue;const c=this.worldToScreen(s.point);if(c.x<-512||c.y<-512||c.x>this.cssWidth+512||c.y>this.cssHeight+512)continue;e.save(),e.translate(c.x,c.y),e.rotate(-s.rotation);const l=Math.max(4,Math.min(256,a));e.font=`${l}px ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,e.fillStyle=s.color,e.globalAlpha=s.opacity,e.textBaseline="alphabetic";for(const[f,h]of s.text.split(/\r?\n/g).entries())e.fillText(h,0,f*l*1.22);e.restore(),o++}}drawImagesOverlay(e,n,r){for(const i of n){if(!Ye(i.bounds,r))continue;const o=this.worldToScreen(i.point),s=this.worldToScreen({x:i.point.x+i.width,y:i.point.y-i.height}),a=Math.min(o.x,s.x),c=Math.min(o.y,s.y),l=Math.abs(s.x-o.x),f=Math.abs(s.y-o.y);if(!(l<1||f<1)){if(i.source){const h=this.getImage(i.source);if(h.complete&&h.naturalWidth>0){e.save(),e.globalAlpha=i.opacity,e.drawImage(h,a,c,l,f),e.restore();continue}h.onload=()=>this.scheduleRender()}this.opts.showImagePlaceholders&&(e.save(),e.strokeStyle=i.color,e.globalAlpha=i.opacity,e.lineWidth=1,e.strokeRect(a,c,l,f),e.beginPath(),e.moveTo(a,c),e.lineTo(a+l,c+f),e.moveTo(a+l,c),e.lineTo(a,c+f),e.stroke(),e.restore())}}}getImage(e){let n=this.imageCache.get(e);return n||(n=new Image,n.src=e,this.imageCache.set(e,n)),n}createOverlayCanvas(){const e=this.canvas.parentElement;if(!e||typeof document>"u")return;window.getComputedStyle(e).position==="static"&&(e.style.position="relative");const r=document.createElement("canvas");r.className="cad-viewer-text-overlay",r.setAttribute("aria-hidden","true"),r.style.position="absolute",r.style.inset="0",r.style.width="100%",r.style.height="100%",r.style.pointerEvents="none",r.style.zIndex="1";const i=r.getContext("2d");i&&(e.appendChild(r),this.overlayCanvas=r,this.overlayCtx=i)}resizeOverlay(e,n){this.overlayCanvas&&(this.overlayCanvas.width!==e||this.overlayCanvas.height!==n)&&(this.overlayCanvas.width=e,this.overlayCanvas.height=n)}bindEvents(){const e=this.eventController.signal;this.canvas.addEventListener("wheel",r=>{r.preventDefault();const i=r.deltaY<0?this.opts.wheelZoomFactor:1/this.opts.wheelZoomFactor;this.zoom(i,{x:r.offsetX,y:r.offsetY})},{passive:!1,signal:e}),this.canvas.addEventListener("pointerdown",r=>{this.canvas.setPointerCapture(r.pointerId),this.isDragging=!0,this.lastPointer={x:r.clientX,y:r.clientY},this.canvas.classList.add("is-dragging")},{signal:e}),this.canvas.addEventListener("pointermove",r=>{!this.isDragging||!this.lastPointer||(this.panByScreenDelta(r.clientX-this.lastPointer.x,r.clientY-this.lastPointer.y),this.lastPointer={x:r.clientX,y:r.clientY})},{signal:e});const n=r=>{r&&this.canvas.hasPointerCapture(r.pointerId)&&this.canvas.releasePointerCapture(r.pointerId),this.isDragging=!1,this.lastPointer=void 0,this.canvas.classList.remove("is-dragging")};this.canvas.addEventListener("pointerup",n,{signal:e}),this.canvas.addEventListener("pointercancel",()=>n(),{signal:e}),this.canvas.addEventListener("webglcontextlost",r=>{r.preventDefault(),this.cancelScheduledRender()},{signal:e})}visibleWorldBounds(){const e=this.cssWidth/Math.max(this.view.scale,1e-12)/2,n=this.cssHeight/Math.max(this.view.scale,1e-12)/2;return{minX:this.view.centerX-e,maxX:this.view.centerX+e,minY:this.view.centerY-n,maxY:this.view.centerY+n}}get cssWidth(){return this.canvas.clientWidth||1}get cssHeight(){return this.canvas.clientHeight||1}clampScale(e){return Math.min(this.opts.maxScale,Math.max(this.opts.minScale,e))}disposeScene(){if(!this.scene)return;const e=this.gl;for(const n of[...this.scene.lineBatches,...this.scene.triangleBatches,...this.scene.lineTypePointBatches,...this.scene.pointBatches])e.deleteBuffer(n.positionBuffer),e.deleteBuffer(n.colorBuffer);this.scene=void 0}emitViewChange(){var e;(e=this.onViewChange)==null||e.call(this,{view:this.getViewState(),fitScale:this.fitScale,zoomRatio:this.getZoomRatio(),zoomPercent:this.getZoomPercent(),bounds:this.getBounds()})}}function ze(){if(typeof document>"u")return!1;const t=document.createElement("canvas");return!!(t.getContext("webgl2")??t.getContext("webgl")??t.getContext("experimental-webgl"))}function Hn(t,e){const n={alpha:!1,antialias:e.antialias??!0,depth:!1,stencil:!1,preserveDrawingBuffer:e.preserveDrawingBuffer??!1,powerPreference:e.powerPreference??"high-performance"};return t.getContext("webgl2",n)??t.getContext("webgl",n)??t.getContext("experimental-webgl",n)??void 0}function Un(t){const e=`
|
|
10
10
|
attribute vec2 a_position;
|
|
11
11
|
attribute vec4 a_color;
|
|
12
12
|
uniform vec2 u_viewCenter;
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
gl_PointSize = u_pointSize;
|
|
25
25
|
v_color = a_color;
|
|
26
26
|
}
|
|
27
|
-
`,
|
|
27
|
+
`,n=`
|
|
28
28
|
precision mediump float;
|
|
29
29
|
varying vec4 v_color;
|
|
30
30
|
void main() {
|
|
31
31
|
gl_FragColor = v_color;
|
|
32
32
|
}
|
|
33
|
-
`,i=oe(e,e.VERTEX_SHADER,t),n=oe(e,e.FRAGMENT_SHADER,r),s=e.createProgram();if(!s)throw new Error("Failed to create WebGL program.");if(e.attachShader(s,i),e.attachShader(s,n),e.linkProgram(s),!e.getProgramParameter(s,e.LINK_STATUS)){const h=e.getProgramInfoLog(s)??"Unknown WebGL program link error.";throw e.deleteProgram(s),new Error(h)}e.deleteShader(i),e.deleteShader(n);const o=e.getUniformLocation(s,"u_viewCenter"),a=e.getUniformLocation(s,"u_scale"),c=e.getUniformLocation(s,"u_viewport"),l=e.getUniformLocation(s,"u_pointSize");if(!o||!a||!c||!l)throw new Error("Failed to resolve WebGL shader uniforms.");return{program:s,aPosition:e.getAttribLocation(s,"a_position"),aColor:e.getAttribLocation(s,"a_color"),uViewCenter:o,uScale:a,uViewport:c,uPointSize:l}}function oe(e,t,r){const i=e.createShader(t);if(!i)throw new Error("Failed to create WebGL shader.");if(e.shaderSource(i,r),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const n=e.getShaderInfoLog(i)??"Unknown WebGL shader compile error.";throw e.deleteShader(i),new Error(n)}return i}function ur(e,t){let r=0;const i=a=>a.map(c=>{const l=ae(e,c.positions),h=ae(e,c.colors),f=c.positions.byteLength+c.colors.byteLength;return r+=f,{positionBuffer:l,colorBuffer:h,vertexCount:c.positions.length/2,primitiveCount:c.primitiveCount,bounds:c.bounds,gpuBytes:f}}),n=i(t.lineBatches),s=i(t.triangleBatches),o=i(t.pointBatches);return{origin:t.origin,lineBatches:n,triangleBatches:s,pointBatches:o,textItems:t.textItems,imageItems:t.imageItems,stats:t.stats,primitiveCount:t.primitiveCount,gpuMemoryBytes:r,buildElapsedMs:t.buildElapsedMs}}function ae(e,t){const r=e.createBuffer();if(!r)throw new Error("Failed to create WebGL buffer.");return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),r}function mr(e,t,r){const i=performance.now(),n=R(r)?{x:(r.minX+r.maxX)/2,y:(r.minY+r.maxY)/2}:{x:0,y:0},s=new pr(e,t,r,n);for(const a of e.entities)s.addEntityTracked(a,0);const o=s.finalize();return o.buildElapsedMs=performance.now()-i,o}class pr{constructor(t,r,i,n){d(this,"lineBuckets",new Map);d(this,"triangleBuckets",new Map);d(this,"pointBuckets",new Map);d(this,"textItems",[]);d(this,"imageItems",[]);d(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0});d(this,"tileSize");d(this,"maxVerticesPerBatch");d(this,"primitiveCount",0);this.document=t,this.opts=r,this.bounds=i,this.origin=n;const s=R(i)?Math.max(i.maxX-i.minX,i.maxY-i.minY,1e-9):1;this.tileSize=r.enableSpatialIndex?s/Math.max(8,r.spatialIndexCellCount):Number.POSITIVE_INFINITY,this.maxVerticesPerBatch=Math.max(4096,Math.floor(r.maxVerticesPerBatch))}addEntityTracked(t,r){this.stats.total++;const i=String(t.type??"UNKNOWN").toUpperCase();this.stats.byType[i]=(this.stats.byType[i]??0)+1;const n=this.lookupLayer(t.layer);if(t.isVisible===!1||!Qt(n)){this.stats.skipped++;return}this.addEntity(t,i,r)}finalize(){const t=xt(this.lineBuckets,this.maxVerticesPerBatch),r=xt(this.triangleBuckets,this.maxVerticesPerBatch),i=xt(this.pointBuckets,this.maxVerticesPerBatch);return this.stats.primitiveCount=this.primitiveCount,{origin:this.origin,lineBatches:t,triangleBatches:r,pointBatches:i,textItems:this.textItems,imageItems:this.imageItems,stats:this.stats,primitiveCount:this.primitiveCount,buildElapsedMs:0}}addEntity(t,r,i){switch(t.kind??A(r)){case"line":return this.addLineEntity(t);case"circle":return this.addCircleEntity(t);case"arc":return this.addArcEntity(t);case"polyline":return this.addPolylineEntity(t);case"ellipse":return this.addEllipseEntity(t);case"text":return this.addTextEntity(t);case"point":return this.addPointEntity(t);case"insert":return this.addInsertEntity(t,i);case"solid":return this.addSolidEntity(t);case"hatch":return this.addHatchEntity(t);case"spline":return this.addSplineEntity(t);case"path":return this.addPathEntity(t);case"image":return this.addImageEntity(t);case"viewport":return this.markSkipped(r);default:this.stats.unsupported[r]=(this.stats.unsupported[r]??0)+1,this.stats.skipped++,this.opts.showUnsupportedMarkers&&this.addUnsupportedMarker(t)}}addLineEntity(t){if(!m(t.startPoint)||!m(t.endPoint))return this.markSkipped("LINE");this.addSegment(t.startPoint,t.endPoint,this.strokeBytes(t)),this.stats.drawn++}addCircleEntity(t){const r=t.center,i=Number(t.radius);if(!m(r)||!Number.isFinite(i))return this.markSkipped("CIRCLE");const n=Math.max(16,Math.min(this.opts.maxCurveSegments,Math.ceil(Math.sqrt(Math.abs(i))*12))),s=J(r,i,0,Math.PI*2,!0,n);this.addPolyline(s,!0,this.strokeBytes(t)),this.stats.drawn++}addArcEntity(t){const r=t.center,i=Number(t.radius),n=Number(t.startAngle),s=Number(t.endAngle);if(!m(r)||!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(s))return this.markSkipped("ARC");this.addPolyline(J(r,i,n,s,!0,this.opts.maxCurveSegments),!1,this.strokeBytes(t)),this.stats.drawn++}addPolylineEntity(t){const r=t.vertices??t.points;if(!Array.isArray(r)||r.length<2)return this.markSkipped(String(t.type));const i=!!t.isClosed||(Number(t.flag)&1)===1,n=[],s=i?r.length:r.length-1;for(let o=0;o<s;o++){const a=r[o],c=r[(o+1)%r.length];if(!m(a)||!m(c))continue;const l=Rt(a,c,Number(a.bulge??0),Math.max(4,Math.min(24,this.opts.maxCurveSegments/4)));n.length>0&&l.shift(),n.push(...l)}if(n.length<2)return this.markSkipped(String(t.type));this.addPolyline(n,i,this.strokeBytes(t)),this.stats.drawn++}addEllipseEntity(t){if(!m(t.center)||!m(t.majorAxisEndPoint))return this.markSkipped("ELLIPSE");const r=Q(t.center,t.majorAxisEndPoint,Number(t.axisRatio??1),Number(t.startAngle??0),Number(t.endAngle??Math.PI*2),this.opts.maxCurveSegments),i=Math.abs(Number(t.endAngle??Math.PI*2)-Number(t.startAngle??0))>=Math.PI*2-1e-6;this.addPolyline(r,i,this.strokeBytes(t)),this.stats.drawn++}addTextEntity(t){const r=t.insertionPoint??t.startPoint??t.center,i=Ot(String(t.text??t.value??"")),n=Number(t.textHeight??t.height??1);if(!m(r)||!i||!Number.isFinite(n))return this.markSkipped(String(t.type));const s=x(r),o=Math.max(1,i.split(/\r?\n/g).reduce((c,l)=>Math.max(c,l.length),0))*Math.abs(n)*.62,a=Math.max(1,i.split(/\r?\n/g).length)*Math.abs(n)*1.22;this.textItems.push({point:s,text:i,height:n,rotation:Number(t.rotation??0),color:D(t,this.document,this.colorOptions()),opacity:O(Number(t.opacity??1),0,1),bounds:{minX:s.x-o*.1,minY:s.y-a,maxX:s.x+o,maxY:s.y+a}}),this.stats.drawn++}addPointEntity(t){const r=t.point??t.location??t.center??t.insertionPoint;if(!m(r))return this.markSkipped("POINT");this.addPoint(r,this.strokeBytes(t)),this.stats.drawn++}addInsertEntity(t,r){const i=this.lookupBlock(t.blockName??t.name);if(i&&r<this.opts.maxInsertDepth){const s=it(t,i.basePoint??{x:0,y:0});for(const o of i.entities){const a=te(o,t,this.document,this.colorOptions());this.addEntityTracked(nt(a,s),r+1)}return}const n=t.insertionPoint;if(!m(n))return this.markSkipped("INSERT");if(this.addPoint(n,this.strokeBytes(t)),Array.isArray(t.attribs))for(const s of t.attribs)this.addTextEntity(s);this.stats.drawn++}addSolidEntity(t){const r=t.vertices??t.points;if(!Array.isArray(r)||r.length<3)return this.markSkipped(String(t.type));const i=r.filter(m).map(x);if(i.length<3)return this.markSkipped(String(t.type));const n=this.fillBytes(t)??this.strokeBytes(t);this.addTriangleFan(i,n),this.addPolyline(i,!0,this.strokeBytes(t)),this.stats.drawn++}addHatchEntity(t){var o;const r=t.loops;if(!Array.isArray(r)||r.length===0)return this.markSkipped("HATCH");const i=this.strokeBytes(t),n=this.fillBytes(t);let s=!1;for(const a of r){const c=(o=a.commands)!=null&&o.length?ce(a.commands,this.opts.maxCurveSegments):(a.vertices??[]).filter(m).map(x);c.length<2||(this.addPolyline(c,!0,i),n&&c.length>=3&&this.addTriangleFan(c,n),s=!0)}if(!s)return this.markSkipped("HATCH");this.stats.drawn++}addSplineEntity(t){var i;const r=(i=t.fitPoints)!=null&&i.length?t.fitPoints:t.controlPoints;if(!r||r.length<2)return this.markSkipped("SPLINE");this.addPolyline(r.filter(m).map(x),!!t.isClosed,this.strokeBytes(t)),this.stats.drawn++}addPathEntity(t){var n;if(!((n=t.commands)!=null&&n.length))return this.markSkipped(String(t.type));const r=ce(t.commands,this.opts.maxCurveSegments);if(r.length<2)return this.markSkipped(String(t.type));this.addPolyline(r,!1,this.strokeBytes(t));const i=this.fillBytes(t);i&&r.length>=3&&this.addTriangleFan(r,i),this.stats.drawn++}addImageEntity(t){const r=t.insertionPoint;if(!m(r))return this.markSkipped(String(t.type));const i=Number(t.width??32),n=Number(t.height??32);if(!Number.isFinite(i)||!Number.isFinite(n))return this.markSkipped(String(t.type));const s=x(r),o=Ct([s,{x:s.x+i,y:s.y-n}]);this.imageItems.push({point:s,width:i,height:n,source:t.imageDataUrl??t.imageSource,color:D(t,this.document,this.colorOptions()),opacity:O(Number(t.opacity??1),0,1),bounds:o}),this.stats.drawn++}addUnsupportedMarker(t){const r=le(t);r&&this.addPoint(r,this.strokeBytes(t))}addPolyline(t,r,i){const n=t.filter(m).map(x);if(!(n.length<2)){for(let s=0;s<n.length-1;s++)this.addSegment(n[s],n[s+1],i);r&&this.addSegment(n[n.length-1],n[0],i)}}addSegment(t,r,i){if(!m(t)||!m(r)||Math.hypot(t.x-r.x,t.y-r.y)<=1e-14)return;const n=this.batchFor(this.lineBuckets,Ct([t,r]));Y(n,t,i,this.origin),Y(n,r,i,this.origin),n.primitiveCount++,this.primitiveCount++}addPoint(t,r){const i=this.batchFor(this.pointBuckets,yr(t));Y(i,t,r,this.origin),i.primitiveCount++,this.primitiveCount++}addTriangleFan(t,r){const i=t.filter(m).map(x);if(i.length<3)return;const n=Ct(i),s=this.batchFor(this.triangleBuckets,n);for(let o=1;o<i.length-1;o++)Y(s,i[0],r,this.origin),Y(s,i[o],r,this.origin),Y(s,i[o+1],r,this.origin),s.primitiveCount++,this.primitiveCount++}batchFor(t,r){const i=this.bucketKey(r);let n=t.get(i);return n||(n=gr(),t.set(i,n)),y(n.bounds,{x:r.minX,y:r.minY}),y(n.bounds,{x:r.maxX,y:r.maxY}),n}bucketKey(t){if(!Number.isFinite(this.tileSize))return"all";const r=(t.minX+t.maxX)/2,i=(t.minY+t.maxY)/2,n=Math.floor((r-this.bounds.minX)/this.tileSize),s=Math.floor((i-this.bounds.minY)/this.tileSize);return`${n}:${s}`}strokeBytes(t){return kt(D(t,this.document,this.colorOptions()),[255,255,255,255],O(Number(t.opacity??1),0,1))}fillBytes(t){const r=dt(t,this.document,this.colorOptions());return r?kt(r,[255,255,255,255],O(Number(t.opacity??1),0,1)):void 0}colorOptions(){return{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}}markSkipped(t){this.stats.skipped++,this.stats.unsupported[t]=this.stats.unsupported[t]??0}lookupLayer(t){if(t)return this.document.layers[t]??this.document.layers[t.toLowerCase()]??Object.values(this.document.layers).find(r=>r.name.toLowerCase()===t.toLowerCase())}lookupBlock(t){if(t)return this.document.blocks[t]??this.document.blocks[t.toLowerCase()]??Object.values(this.document.blocks).find(r=>r.name.toLowerCase()===t.toLowerCase())}}function gr(){return{positions:[],colors:[],bounds:I(),primitiveCount:0}}function Y(e,t,r,i){e.positions.push(t.x-i.x,t.y-i.y),e.colors.push(r[0],r[1],r[2],r[3])}function xt(e,t){const r=[];for(const i of e.values()){const n=i.positions.length/2;if(n<=0||!R(i.bounds))continue;if(n<=t){r.push({positions:new Float32Array(i.positions),colors:new Uint8Array(i.colors),bounds:{...i.bounds},primitiveCount:i.primitiveCount});continue}const s=br(i),o=Math.max(s,Math.floor(t/s)*s);for(let a=0;a<n;a+=o){const c=Math.min(n,a+o),l=i.positions.slice(a*2,c*2),h=i.colors.slice(a*4,c*4),f=I();for(let u=0;u<l.length;u+=2)y(f,{x:l[u],y:l[u+1]});r.push({positions:new Float32Array(l),colors:new Uint8Array(h),bounds:{...i.bounds},primitiveCount:Math.floor((c-a)/s)})}}return r}function br(e){const t=e.positions.length/2;return t===e.primitiveCount?1:t===e.primitiveCount*3?3:2}function vr(e,t){var s;const r=I();if((s=e.pages)!=null&&s.length)for(const o of e.pages)y(r,{x:0,y:0}),y(r,{x:o.width,y:o.height});const i=o=>{if(o)return e.blocks[o]??e.blocks[o.toLowerCase()]??Object.values(e.blocks).find(a=>a.name.toLowerCase()===o.toLowerCase())},n=(o,a)=>{const c=String(o.type??"").toUpperCase(),l=o.kind??A(c);if(l==="insert"){const h=i(o.blockName??o.name);if(h&&a<t.maxInsertDepth){const f=it(o,h.basePoint??{x:0,y:0});for(const u of h.entities)n(nt(u,f),a+1);return}}if(l==="line")m(o.startPoint)&&y(r,o.startPoint),m(o.endPoint)&&y(r,o.endPoint);else if(l==="circle"||l==="arc")m(o.center)&&Number.isFinite(o.radius)&&Dt(r,o.center,Number(o.radius));else if(l==="polyline"||l==="solid"||l==="spline")for(const h of[...o.vertices??[],...o.points??[],...o.controlPoints??[],...o.fitPoints??[]])m(h)&&y(r,h);else if(l==="ellipse")m(o.center)&&m(o.majorAxisEndPoint)&&Q(o.center,o.majorAxisEndPoint,Number(o.axisRatio??1),Number(o.startAngle??0),Number(o.endAngle??Math.PI*2),t.maxCurveSegments).forEach(h=>y(r,h));else if(l==="path")for(const h of o.commands??[])for(const f of h.points)y(r,f);else if(l==="hatch")for(const h of o.loops??[]){for(const f of h.vertices??[])y(r,f);for(const f of h.commands??[])for(const u of f.points)y(r,u)}else{const h=le(o);h&&y(r,h)}};for(const o of e.entities)n(o,0);return Wt(r)}function ce(e,t){const r=[];let i,n;const s=o=>{(!r.length||Math.hypot(r[r.length-1].x-o.x,r[r.length-1].y-o.y)>1e-12)&&r.push(x(o)),i=x(o)};for(const o of e)if(o.cmd==="M")i=x(o.points[0]),n=i,s(i);else if(o.cmd==="L")s(o.points[0]);else if(o.cmd==="Q"&&i&&o.points.length>=2){const a=i,[c,l]=o.points,h=Math.max(4,Math.min(t,24));for(let f=1;f<=h;f++){const u=f/h,p=1-u;s({x:p*p*a.x+2*p*u*c.x+u*u*l.x,y:p*p*a.y+2*p*u*c.y+u*u*l.y})}}else if(o.cmd==="C"&&i&&o.points.length>=3){const a=i,[c,l,h]=o.points,f=Math.max(6,Math.min(t,32));for(let u=1;u<=f;u++){const p=u/f,b=1-p;s({x:b**3*a.x+3*b*b*p*c.x+3*b*p*p*l.x+p**3*h.x,y:b**3*a.y+3*b*b*p*c.y+3*b*p*p*l.y+p**3*h.y})}}else o.cmd==="Z"&&n&&s(n);return r}function le(e){for(const t of["startPoint","insertionPoint","center","point","location"]){const r=e[t];if(m(r))return x(r)}if(Array.isArray(e.vertices)&&m(e.vertices[0]))return x(e.vertices[0]);if(Array.isArray(e.commands)&&e.commands.length){const t=e.commands.find(r=>r.points.length>0);if(t)return x(t.points[0])}}function Ct(e){const t=I();for(const r of e)y(t,r);return t}function yr(e){return{minX:e.x,minY:e.y,maxX:e.x,maxY:e.y}}function Pt(e,t){return e.minX<=t.maxX&&e.maxX>=t.minX&&e.minY<=t.maxY&&e.maxY>=t.minY}function wr(e,t){return t.trueColorByteOrder!==void 0&&t.trueColorByteOrder!==e.trueColorByteOrder||t.contrastMode!==void 0&&t.contrastMode!==e.contrastMode||t.minColorContrast!==void 0&&t.minColorContrast!==e.minColorContrast||t.foreground!==void 0&&t.foreground!==e.foreground||t.background!==void 0&&t.background!==e.background||t.maxInsertDepth!==void 0&&t.maxInsertDepth!==e.maxInsertDepth||t.maxCurveSegments!==void 0&&t.maxCurveSegments!==e.maxCurveSegments||t.spatialIndexCellCount!==void 0&&t.spatialIndexCellCount!==e.spatialIndexCellCount||t.maxVerticesPerBatch!==void 0&&t.maxVerticesPerBatch!==e.maxVerticesPerBatch||t.enableSpatialIndex!==void 0&&t.enableSpatialIndex!==e.enableSpatialIndex}function xr(e,t){return{...e.stats,renderElapsedMs:t,backend:"webgl",primitiveCount:e.primitiveCount,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:e.gpuMemoryBytes,buildElapsedMs:e.buildElapsedMs}}function Cr(e){return{total:e.total,drawn:e.drawn,skipped:e.skipped,byType:{...e.byType},unsupported:{...e.unsupported},renderElapsedMs:e.renderElapsedMs,backend:e.backend,primitiveCount:e.primitiveCount,visiblePrimitiveCount:e.visiblePrimitiveCount,culledPrimitiveCount:e.culledPrimitiveCount,gpuMemoryBytes:e.gpuMemoryBytes,buildElapsedMs:e.buildElapsedMs}}function kt(e,t,r=1){const i=e.trim().toLowerCase();let n;if(/^#[0-9a-f]{3}$/i.test(i))n=[parseInt(i[1]+i[1],16),parseInt(i[2]+i[2],16),parseInt(i[3]+i[3],16),255];else if(/^#[0-9a-f]{6}$/i.test(i))n=[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16),255];else{const o=i.match(/^rgba?\(([^)]+)\)$/i);if(o){const a=o[1].split(/[\s,\/]+/).filter(Boolean),c=a.slice(0,3).some(h=>h.includes("%")),l=a.map(h=>Number(h.replace("%","")));l.length>=3&&l.slice(0,3).every(Number.isFinite)&&(n=[V(c?l[0]*2.55:l[0]),V(c?l[1]*2.55:l[1]),V(c?l[2]*2.55:l[2]),V((Number.isFinite(l[3])?l[3]:1)*255)])}}const s=n??t;return[s[0],s[1],s[2],V(s[3]*r)]}function V(e){return Math.max(0,Math.min(255,Math.round(e)))}class he{constructor(t={}){d(this,"canvas");d(this,"renderer");d(this,"registry");d(this,"nativeHost");d(this,"options");d(this,"lastResult");d(this,"activeNativeLoader");var r;if(this.options={autoFit:!0,...t},this.registry=t.registry??qt(t),t.loaders)for(const i of t.loaders)this.registry.register(i);if(this.canvas=t.canvas??document.createElement("canvas"),this.canvas.classList.add("cad-viewer-canvas"),t.container)t.container.classList.add("cad-viewer-container"),t.canvas||(this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.display="block",t.container.appendChild(this.canvas)),this.nativeHost=t.nativeHost??document.createElement("div"),this.nativeHost.classList.add("cad-viewer-native-host"),t.nativeHost||t.container.appendChild(this.nativeHost);else if(t.nativeHost)this.nativeHost=t.nativeHost,this.nativeHost.classList.add("cad-viewer-native-host");else if((r=t.canvas)!=null&&r.parentElement){t.canvas.parentElement.classList.add("cad-viewer-container");const i=document.createElement("div");i.classList.add("cad-viewer-native-host"),t.canvas.parentElement.appendChild(i),this.nativeHost=i}this.renderer=Sr(t.renderer??"auto",this.canvas,t.canvasOptions),this.renderer.onStats=i=>{var n,s;return(s=(n=this.options).onRenderStats)==null?void 0:s.call(n,i)},this.renderer.onViewChange=i=>{var n,s;return(s=(n=this.options).onViewChange)==null?void 0:s.call(n,i)}}registerLoader(t){return this.registry.register(t),this}async loadFile(t,r={}){var i,n;return(n=(i=this.options).onLoadStart)==null||n.call(i,t),this.loadThroughRegistry({file:t,fileName:t.name},r,t.name)}async loadBuffer(t,r,i={}){var n,s;return(s=(n=this.options).onLoadStart)==null||s.call(n,t),this.loadThroughRegistry({buffer:t,fileName:r},i,r)}async load(t,r={}){var i,n,s;return(n=(i=this.options).onLoadStart)==null||n.call(i,t),this.loadThroughRegistry(t,r,t.fileName??((s=t.file)==null?void 0:s.name))}setDocument(t,r){var n,s;this.deactivateNativeRenderer();const i={document:t,raw:t.raw,bytes:0,elapsedMs:0,format:t.format,warnings:t.warnings,summary:X(t),fileName:r};return this.renderer.setDocument(t),this.options.autoFit||this.renderer.render(),this.lastResult=i,(s=(n=this.options).onLoad)==null||s.call(n,i),i}fit(){var t,r;this.activeNativeLoader?(r=(t=this.activeNativeLoader).fit)==null||r.call(t):this.renderer.fitToView()}zoomIn(){var t,r;this.activeNativeLoader?(r=(t=this.activeNativeLoader).zoomIn)==null||r.call(t):this.renderer.zoomIn()}zoomOut(){var t,r;this.activeNativeLoader?(r=(t=this.activeNativeLoader).zoomOut)==null||r.call(t):this.renderer.zoomOut()}resize(){var t,r;this.activeNativeLoader?(r=(t=this.activeNativeLoader).resize)==null||r.call(t):this.renderer.resize()}setCanvasOptions(t){var r,i;this.options.canvasOptions={...this.options.canvasOptions??{},...t},this.renderer.setOptions(t),this.activeNativeLoader&&((i=(r=this.activeNativeLoader).setNativeOptions)==null||i.call(r,{...this.mergeLoadOptions({}),dwfBackground:t.background??this.options.dwfBackground}))}async preloadDwg(t={}){const r=this.registry.list().find(i=>i.id==="dwg");if(!(r!=null&&r.preload))throw new Error("The registered DWG loader does not support preload().");return r.preload(this.mergeLoadOptions(t))}clear(){this.lastResult=void 0,this.deactivateNativeRenderer(),this.renderer.clear()}destroy(){var t,r,i;this.deactivateNativeRenderer();for(const n of this.registry.list()){const s=n;(t=s.terminateWorker)==null||t.call(s),(r=s.unmount)==null||r.call(s),(i=s.destroy)==null||i.call(s)}this.renderer.destroy()}getLoadResult(){return this.lastResult}getDocument(){var t;return this.activeNativeLoader?(t=this.lastResult)==null?void 0:t.document:this.renderer.getDocument()}getZoomPercent(){return this.activeNativeLoader?100:this.renderer.getZoomPercent()}isNativeRendererActive(){return!!this.activeNativeLoader}async loadThroughRegistry(t,r,i){var n,s;try{const o=this.mergeLoadOptions(r);St(o.signal);const a=await this.registry.detect(t),c={...t,buffer:a.bytes};if(Kt(a.loader))return await this.applyNativeLoadResult(a.loader,c,o,i);const l=await a.loader.load(c,o);return this.applyLoadResult(l,i)}catch(o){const a=kr(o);throw(s=(n=this.options).onError)==null||s.call(n,a),a}}applyLoadResult(t,r){var n,s,o,a;this.deactivateNativeRenderer(),(s=(n=this.options).onLoadProgress)==null||s.call(n,{phase:"render",format:t.format,message:"Rendering normalized CAD scene…",percent:96}),this.renderer.setDocument(t.document),this.options.autoFit||this.renderer.render();const i={...t,fileName:r,summary:X(t.document)};return this.lastResult=i,(a=(o=this.options).onLoad)==null||a.call(o,i),i}async applyNativeLoadResult(t,r,i,n){var s,o,a;if(!this.nativeHost)throw new Error("Native DWF rendering requires CadViewerOptions.container, nativeHost, or a canvas parent element.");St(i.signal),this.renderer.clear(),(s=this.activeNativeLoader)==null||s.unmount(),this.activeNativeLoader=t,this.canvas.style.display="none",this.nativeHost.classList.add("is-active");try{const c=await t.mount(r,this.nativeHost,i);St(i.signal);const l={...c,fileName:n,summary:X(c.document)};return this.lastResult=l,this.emitNativeRenderStats(c),(a=(o=this.options).onLoad)==null||a.call(o,l),l}catch(c){throw this.deactivateNativeRenderer(),c}}deactivateNativeRenderer(){var t,r;if(!this.activeNativeLoader&&!((t=this.nativeHost)!=null&&t.classList.contains("is-active"))){this.canvas.style.display="";return}(r=this.activeNativeLoader)==null||r.unmount(),this.activeNativeLoader=void 0,this.nativeHost&&(this.nativeHost.classList.remove("is-active"),this.nativeHost.replaceChildren()),this.canvas.style.display=""}emitNativeRenderStats(t){var o,a,c,l;const r=t.document.metadata,i=Number(((o=r.nativeRenderStats)==null?void 0:o.commands)??t.document.entities.length??0),s=String(((a=r.nativeRenderStats)==null?void 0:a.backend)??"webgl").includes("webgl")?"webgl":"canvas2d";(l=(c=this.options).onRenderStats)==null||l.call(c,{total:i,drawn:i,skipped:0,byType:X(t.document).byType,unsupported:{},renderElapsedMs:t.elapsedMs,backend:s,primitiveCount:i,visiblePrimitiveCount:i,culledPrimitiveCount:0,gpuMemoryBytes:void 0,buildElapsedMs:t.elapsedMs})}mergeLoadOptions(t){const r=this.options.onProgress,i=t.onProgress;return{...this.options,...t,onProgress:n=>{var s,o;(o=(s=this.options).onLoadProgress)==null||o.call(s,n),r==null||r(n),i&&i!==r&&i(n)}}}}function Pr(e={}){return new he(e)}function kr(e){return e instanceof Error?e:new Error(String(e))}function St(e){if(e!=null&&e.aborted)throw new DOMException("Loading cancelled.","AbortError")}function Sr(e,t,r={}){if(e==="canvas2d")return new vt(t,r);if(e==="webgl")return new yt(t,r);if(wt())try{return new yt(t,r)}catch{}return new vt(t,r)}g.CadCanvasRenderer=vt,g.CadLoaderRegistry=Mt,g.CadViewer=he,g.CadWebGLRenderer=yt,g.DwfLoader=Ut,g.DwgLoader=At,g.DwgWorkerClient=Et,g.DxfLoader=zt,g.colorFromAci=T,g.colorFromTrueColor=z,g.createCadDocument=ot,g.createCadViewer=Pr,g.createDefaultLoaderRegistry=qt,g.detectCadFormat=L,g.inferEntityKind=A,g.isCadNativeRenderableLoader=Kt,g.isWebGLAvailable=wt,g.normalizeCadEntity=Bt,g.readInputBytes=M,g.resolveCadColor=D,g.summarizeCadDocument=X,g.supportsDwgWorker=Z,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
33
|
+
`,r=Mt(t,t.VERTEX_SHADER,e),i=Mt(t,t.FRAGMENT_SHADER,n),o=t.createProgram();if(!o)throw new Error("Failed to create WebGL program.");if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS)){const f=t.getProgramInfoLog(o)??"Unknown WebGL program link error.";throw t.deleteProgram(o),new Error(f)}t.deleteShader(r),t.deleteShader(i);const s=t.getUniformLocation(o,"u_viewCenter"),a=t.getUniformLocation(o,"u_scale"),c=t.getUniformLocation(o,"u_viewport"),l=t.getUniformLocation(o,"u_pointSize");if(!s||!a||!c||!l)throw new Error("Failed to resolve WebGL shader uniforms.");return{program:o,aPosition:t.getAttribLocation(o,"a_position"),aColor:t.getAttribLocation(o,"a_color"),uViewCenter:s,uScale:a,uViewport:c,uPointSize:l}}function Mt(t,e,n){const r=t.createShader(e);if(!r)throw new Error("Failed to create WebGL shader.");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const i=t.getShaderInfoLog(r)??"Unknown WebGL shader compile error.";throw t.deleteShader(r),new Error(i)}return r}function Xn(t,e){let n=0;const r=c=>c.map(l=>{const f=Et(t,l.positions),h=Et(t,l.colors),d=l.positions.byteLength+l.colors.byteLength;return n+=d,{positionBuffer:f,colorBuffer:h,vertexCount:l.positions.length/2,primitiveCount:l.primitiveCount,bounds:l.bounds,gpuBytes:d}}),i=r(e.lineBatches),o=r(e.triangleBatches),s=r(e.lineTypePointBatches),a=r(e.pointBatches);return{origin:e.origin,lineBatches:i,triangleBatches:o,lineTypePointBatches:s,pointBatches:a,textItems:e.textItems,imageItems:e.imageItems,stats:e.stats,primitiveCount:e.primitiveCount,gpuMemoryBytes:n,buildElapsedMs:e.buildElapsedMs}}function Et(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create WebGL buffer.");return t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW),n}function jn(t,e,n){const r=performance.now(),i=j(n)?{x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2}:{x:0,y:0},o=new $n(t,e,n,i);for(const a of t.entities)o.addEntityTracked(a,0);const s=o.finalize();return s.buildElapsedMs=performance.now()-r,s}class $n{constructor(e,n,r,i){u(this,"lineBuckets",new Map);u(this,"triangleBuckets",new Map);u(this,"lineTypePointBuckets",new Map);u(this,"pointBuckets",new Map);u(this,"textItems",[]);u(this,"imageItems",[]);u(this,"stats",{total:0,drawn:0,skipped:0,byType:{},unsupported:{},backend:"webgl",primitiveCount:0,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:0,buildElapsedMs:0});u(this,"tileSize");u(this,"maxVerticesPerBatch");u(this,"primitiveCount",0);this.document=e,this.opts=n,this.bounds=r,this.origin=i;const o=j(r)?Math.max(r.maxX-r.minX,r.maxY-r.minY,1e-9):1;this.tileSize=n.enableSpatialIndex?o/Math.max(8,n.spatialIndexCellCount):Number.POSITIVE_INFINITY,this.maxVerticesPerBatch=Math.max(4096,Math.floor(n.maxVerticesPerBatch))}addEntityTracked(e,n){this.stats.total++;const r=String(e.type??"UNKNOWN").toUpperCase();this.stats.byType[r]=(this.stats.byType[r]??0)+1;const i=this.lookupLayer(e.layer);if(e.isVisible===!1||!bt(i)){this.stats.skipped++;return}this.addEntity(e,r,n)}finalize(){const e=be(this.lineBuckets,this.maxVerticesPerBatch),n=be(this.triangleBuckets,this.maxVerticesPerBatch),r=be(this.lineTypePointBuckets,this.maxVerticesPerBatch),i=be(this.pointBuckets,this.maxVerticesPerBatch);return this.stats.primitiveCount=this.primitiveCount,{origin:this.origin,lineBatches:e,triangleBatches:n,lineTypePointBatches:r,pointBatches:i,textItems:this.textItems,imageItems:this.imageItems,stats:this.stats,primitiveCount:this.primitiveCount,buildElapsedMs:0}}addEntity(e,n,r){switch(e.kind??O(n)){case"line":return this.addLineEntity(e);case"circle":return this.addCircleEntity(e);case"arc":return this.addArcEntity(e);case"polyline":return this.addPolylineEntity(e);case"ellipse":return this.addEllipseEntity(e);case"text":return this.addTextEntity(e);case"point":return this.addPointEntity(e);case"insert":return this.addInsertEntity(e,r);case"solid":return this.addSolidEntity(e);case"hatch":return this.addHatchEntity(e);case"spline":return this.addSplineEntity(e);case"path":return this.addPathEntity(e);case"image":return this.addImageEntity(e);case"viewport":return this.markSkipped(n);default:this.stats.unsupported[n]=(this.stats.unsupported[n]??0)+1,this.stats.skipped++,this.opts.showUnsupportedMarkers&&this.addUnsupportedMarker(e)}}addLineEntity(e){if(!p(e.startPoint)||!p(e.endPoint))return this.markSkipped("LINE");this.addPolyline([e.startPoint,e.endPoint],!1,this.strokeBytes(e),e),this.stats.drawn++}addCircleEntity(e){const n=e.center,r=Number(e.radius);if(!p(n)||!Number.isFinite(r))return this.markSkipped("CIRCLE");const i=Math.max(16,Math.min(this.opts.maxCurveSegments,Math.ceil(Math.sqrt(Math.abs(r))*12))),o=Q(n,r,0,Math.PI*2,!0,i);this.addPolyline(o,!0,this.strokeBytes(e),e),this.stats.drawn++}addArcEntity(e){const n=e.center,r=Number(e.radius),i=Number(e.startAngle),o=Number(e.endAngle);if(!p(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(o))return this.markSkipped("ARC");this.addPolyline(Q(n,r,i,o,!0,this.opts.maxCurveSegments),!1,this.strokeBytes(e),e),this.stats.drawn++}addPolylineEntity(e){const n=e.vertices??e.points;if(!Array.isArray(n)||n.length<2)return this.markSkipped(String(e.type));const r=Ce(e),i=[],o=r?n.length:n.length-1;for(let s=0;s<o;s++){const a=n[s],c=n[(s+1)%n.length];if(!p(a)||!p(c))continue;const l=tt(a,c,Number(a.bulge??0),Math.max(4,Math.min(24,this.opts.maxCurveSegments/4)));i.length>0&&l.shift(),i.push(...l)}if(i.length<2)return this.markSkipped(String(e.type));this.addPolyline(i,r,this.strokeBytes(e),e),this.stats.drawn++}addEllipseEntity(e){if(!p(e.center)||!p(e.majorAxisEndPoint))return this.markSkipped("ELLIPSE");const n=le(e.center,e.majorAxisEndPoint,Number(e.axisRatio??1),Number(e.startAngle??0),Number(e.endAngle??Math.PI*2),this.opts.maxCurveSegments),r=Math.abs(Number(e.endAngle??Math.PI*2)-Number(e.startAngle??0))>=Math.PI*2-1e-6;this.addPolyline(n,r,this.strokeBytes(e),e),this.stats.drawn++}addTextEntity(e){const n=e.insertionPoint??e.startPoint??e.center,r=nt(String(e.text??e.value??"")),i=Number(e.textHeight??e.height??1);if(!p(n)||!r||!Number.isFinite(i))return this.markSkipped(String(e.type));const o=k(n),s=Math.max(1,r.split(/\r?\n/g).reduce((c,l)=>Math.max(c,l.length),0))*Math.abs(i)*.62,a=Math.max(1,r.split(/\r?\n/g).length)*Math.abs(i)*1.22;this.textItems.push({point:o,text:r,height:i,rotation:Number(e.rotation??0),color:_(e,this.document,this.colorOptions()),opacity:$(Number(e.opacity??1),0,1),bounds:{minX:o.x-s*.1,minY:o.y-a,maxX:o.x+s,maxY:o.y+a}}),this.stats.drawn++}addPointEntity(e){const n=e.point??e.location??e.center??e.insertionPoint;if(!p(n))return this.markSkipped("POINT");this.addPoint(n,this.strokeBytes(e)),this.stats.drawn++}addInsertEntity(e,n){const r=this.lookupBlock(e.blockName??e.name);if(r&&n<this.opts.maxInsertDepth){const o=ge(e,r.basePoint??{x:0,y:0});for(const s of r.entities){const a=yt(s,e,this.document,this.colorOptions()),c=Fe(a,e,this.document);this.addEntityTracked(Y(c,o),n+1)}return}const i=e.insertionPoint;if(!p(i))return this.markSkipped("INSERT");if(this.addPoint(i,this.strokeBytes(e)),Array.isArray(e.attribs))for(const o of e.attribs)this.addTextEntity(o);this.stats.drawn++}addSolidEntity(e){const n=e.vertices??e.points;if(!Array.isArray(n)||n.length<3)return this.markSkipped(String(e.type));const r=n.filter(p).map(k);if(r.length<3)return this.markSkipped(String(e.type));const i=this.fillBytes(e)??this.strokeBytes(e);this.addTriangleFan(r,i),this.addPolyline(r,!0,this.strokeBytes(e),e),this.stats.drawn++}addHatchEntity(e){var s;const n=e.loops;if(!Array.isArray(n)||n.length===0)return this.markSkipped("HATCH");const r=this.strokeBytes(e),i=this.fillBytes(e);let o=!1;for(const a of n){const c=(s=a.commands)!=null&&s.length?Lt(a.commands,this.opts.maxCurveSegments):(a.vertices??[]).filter(p).map(k);c.length<2||(this.addPolyline(c,!0,r,e),i&&c.length>=3&&this.addTriangleFan(c,i),o=!0)}if(!o)return this.markSkipped("HATCH");this.stats.drawn++}addSplineEntity(e){var r;const n=(r=e.fitPoints)!=null&&r.length?e.fitPoints:e.controlPoints;if(!n||n.length<2)return this.markSkipped("SPLINE");this.addPolyline(n.filter(p).map(k),!!e.isClosed,this.strokeBytes(e),e),this.stats.drawn++}addPathEntity(e){var i;if(!((i=e.commands)!=null&&i.length))return this.markSkipped(String(e.type));const n=Lt(e.commands,this.opts.maxCurveSegments);if(n.length<2)return this.markSkipped(String(e.type));this.addPolyline(n,!1,this.strokeBytes(e),e);const r=this.fillBytes(e);r&&n.length>=3&&this.addTriangleFan(n,r),this.stats.drawn++}addImageEntity(e){const n=e.insertionPoint;if(!p(n))return this.markSkipped(String(e.type));const r=Number(e.width??32),i=Number(e.height??32);if(!Number.isFinite(r)||!Number.isFinite(i))return this.markSkipped(String(e.type));const o=k(n),s=_e([o,{x:o.x+r,y:o.y-i}]);this.imageItems.push({point:o,width:r,height:i,source:e.imageDataUrl??e.imageSource,color:_(e,this.document,this.colorOptions()),opacity:$(Number(e.opacity??1),0,1),bounds:s}),this.stats.drawn++}addUnsupportedMarker(e){const n=It(e);n&&this.addPoint(n,this.strokeBytes(e))}addPolyline(e,n,r,i){const o=e.filter(p).map(k);if(o.length<2)return;const s=i?ue(i,this.document):void 0;if(s){const a=me(o,n,s);for(const[c,l]of a.segments)this.addSegment(c,l,r);for(const c of a.dots)this.addLineTypePoint(c,r);return}for(let a=0;a<o.length-1;a++)this.addSegment(o[a],o[a+1],r);n&&this.addSegment(o[o.length-1],o[0],r)}addSegment(e,n,r){if(!p(e)||!p(n)||Math.hypot(e.x-n.x,e.y-n.y)<=1e-14)return;const i=this.batchFor(this.lineBuckets,_e([e,n]));V(i,e,r,this.origin),V(i,n,r,this.origin),i.primitiveCount++,this.primitiveCount++}addPoint(e,n){const r=this.batchFor(this.pointBuckets,Tt(e));V(r,e,n,this.origin),r.primitiveCount++,this.primitiveCount++}addLineTypePoint(e,n){const r=this.batchFor(this.lineTypePointBuckets,Tt(e));V(r,e,n,this.origin),r.primitiveCount++,this.primitiveCount++}addTriangleFan(e,n){const r=e.filter(p).map(k);if(r.length<3)return;const i=_e(r),o=this.batchFor(this.triangleBuckets,i);for(let s=1;s<r.length-1;s++)V(o,r[0],n,this.origin),V(o,r[s],n,this.origin),V(o,r[s+1],n,this.origin),o.primitiveCount++,this.primitiveCount++}batchFor(e,n){const r=this.bucketKey(n);let i=e.get(r);return i||(i=Gn(),e.set(r,i)),C(i.bounds,{x:n.minX,y:n.minY}),C(i.bounds,{x:n.maxX,y:n.maxY}),i}bucketKey(e){if(!Number.isFinite(this.tileSize))return"all";const n=(e.minX+e.maxX)/2,r=(e.minY+e.maxY)/2,i=Math.floor((n-this.bounds.minX)/this.tileSize),o=Math.floor((r-this.bounds.minY)/this.tileSize);return`${i}:${o}`}strokeBytes(e){return Ve(_(e,this.document,this.colorOptions()),[255,255,255,255],$(Number(e.opacity??1),0,1))}fillBytes(e){const n=Ee(e,this.document,this.colorOptions());return n?Ve(n,[255,255,255,255],$(Number(e.opacity??1),0,1)):void 0}colorOptions(){return{foreground:this.opts.foreground,background:this.opts.background,trueColorByteOrder:this.opts.trueColorByteOrder,contrastMode:this.opts.contrastMode,minColorContrast:this.opts.minColorContrast}}markSkipped(e){this.stats.skipped++,this.stats.unsupported[e]=this.stats.unsupported[e]??0}lookupLayer(e){if(e)return this.document.layers[e]??this.document.layers[e.toLowerCase()]??Object.values(this.document.layers).find(n=>n.name.toLowerCase()===e.toLowerCase())}lookupBlock(e){if(e)return this.document.blocks[e]??this.document.blocks[e.toLowerCase()]??Object.values(this.document.blocks).find(n=>n.name.toLowerCase()===e.toLowerCase())}}function Gn(){return{positions:[],colors:[],bounds:B(),primitiveCount:0}}function V(t,e,n,r){t.positions.push(e.x-r.x,e.y-r.y),t.colors.push(n[0],n[1],n[2],n[3])}function be(t,e){const n=[];for(const r of t.values()){const i=r.positions.length/2;if(i<=0||!j(r.bounds))continue;if(i<=e){n.push({positions:new Float32Array(r.positions),colors:new Uint8Array(r.colors),bounds:{...r.bounds},primitiveCount:r.primitiveCount});continue}const o=Zn(r),s=Math.max(o,Math.floor(e/o)*o);for(let a=0;a<i;a+=s){const c=Math.min(i,a+s),l=r.positions.slice(a*2,c*2),f=r.colors.slice(a*4,c*4),h=B();for(let d=0;d<l.length;d+=2)C(h,{x:l[d],y:l[d+1]});n.push({positions:new Float32Array(l),colors:new Uint8Array(f),bounds:{...r.bounds},primitiveCount:Math.floor((c-a)/o)})}}return n}function Zn(t){const e=t.positions.length/2;return e===t.primitiveCount?1:e===t.primitiveCount*3?3:2}function qn(t,e){var o;const n=B();if((o=t.pages)!=null&&o.length)for(const s of t.pages)C(n,{x:0,y:0}),C(n,{x:s.width,y:s.height});const r=s=>{if(s)return t.blocks[s]??t.blocks[s.toLowerCase()]??Object.values(t.blocks).find(a=>a.name.toLowerCase()===s.toLowerCase())},i=(s,a)=>{const c=String(s.type??"").toUpperCase(),l=s.kind??O(c);if(l==="insert"){const f=r(s.blockName??s.name);if(f&&a<e.maxInsertDepth){const h=ge(s,f.basePoint??{x:0,y:0});for(const d of f.entities)i(Y(d,h),a+1);return}}if(l==="line")p(s.startPoint)&&C(n,s.startPoint),p(s.endPoint)&&C(n,s.endPoint);else if(l==="circle"||l==="arc")p(s.center)&&Number.isFinite(s.radius)&&Qe(n,s.center,Number(s.radius));else if(l==="polyline"||l==="solid"||l==="spline")for(const f of[...s.vertices??[],...s.points??[],...s.controlPoints??[],...s.fitPoints??[]])p(f)&&C(n,f);else if(l==="ellipse")p(s.center)&&p(s.majorAxisEndPoint)&&le(s.center,s.majorAxisEndPoint,Number(s.axisRatio??1),Number(s.startAngle??0),Number(s.endAngle??Math.PI*2),e.maxCurveSegments).forEach(f=>C(n,f));else if(l==="path")for(const f of s.commands??[])for(const h of f.points)C(n,h);else if(l==="hatch")for(const f of s.loops??[]){for(const h of f.vertices??[])C(n,h);for(const h of f.commands??[])for(const d of h.points)C(n,d)}else{const f=It(s);f&&C(n,f)}};for(const s of t.entities)i(s,0);return et(n)}function Lt(t,e){const n=[];let r,i;const o=s=>{(!n.length||Math.hypot(n[n.length-1].x-s.x,n[n.length-1].y-s.y)>1e-12)&&n.push(k(s)),r=k(s)};for(const s of t)if(s.cmd==="M")r=k(s.points[0]),i=r,o(r);else if(s.cmd==="L")o(s.points[0]);else if(s.cmd==="Q"&&r&&s.points.length>=2){const a=r,[c,l]=s.points,f=Math.max(4,Math.min(e,24));for(let h=1;h<=f;h++){const d=h/f,m=1-d;o({x:m*m*a.x+2*m*d*c.x+d*d*l.x,y:m*m*a.y+2*m*d*c.y+d*d*l.y})}}else if(s.cmd==="C"&&r&&s.points.length>=3){const a=r,[c,l,f]=s.points,h=Math.max(6,Math.min(e,32));for(let d=1;d<=h;d++){const m=d/h,g=1-m;o({x:g**3*a.x+3*g*g*m*c.x+3*g*m*m*l.x+m**3*f.x,y:g**3*a.y+3*g*g*m*c.y+3*g*m*m*l.y+m**3*f.y})}}else s.cmd==="Z"&&i&&o(i);return n}function It(t){for(const e of["startPoint","insertionPoint","center","point","location"]){const n=t[e];if(p(n))return k(n)}if(Array.isArray(t.vertices)&&p(t.vertices[0]))return k(t.vertices[0]);if(Array.isArray(t.commands)&&t.commands.length){const e=t.commands.find(n=>n.points.length>0);if(e)return k(e.points[0])}}function _e(t){const e=B();for(const n of t)C(e,n);return e}function Tt(t){return{minX:t.x,minY:t.y,maxX:t.x,maxY:t.y}}function Ye(t,e){return t.minX<=e.maxX&&t.maxX>=e.minX&&t.minY<=e.maxY&&t.maxY>=e.minY}function Kn(t,e){return e.trueColorByteOrder!==void 0&&e.trueColorByteOrder!==t.trueColorByteOrder||e.contrastMode!==void 0&&e.contrastMode!==t.contrastMode||e.minColorContrast!==void 0&&e.minColorContrast!==t.minColorContrast||e.foreground!==void 0&&e.foreground!==t.foreground||e.background!==void 0&&e.background!==t.background||e.maxInsertDepth!==void 0&&e.maxInsertDepth!==t.maxInsertDepth||e.maxCurveSegments!==void 0&&e.maxCurveSegments!==t.maxCurveSegments||e.spatialIndexCellCount!==void 0&&e.spatialIndexCellCount!==t.spatialIndexCellCount||e.maxVerticesPerBatch!==void 0&&e.maxVerticesPerBatch!==t.maxVerticesPerBatch||e.enableSpatialIndex!==void 0&&e.enableSpatialIndex!==t.enableSpatialIndex}function Jn(t,e){return{...t.stats,renderElapsedMs:e,backend:"webgl",primitiveCount:t.primitiveCount,visiblePrimitiveCount:0,culledPrimitiveCount:0,gpuMemoryBytes:t.gpuMemoryBytes,buildElapsedMs:t.buildElapsedMs}}function Qn(t){return{total:t.total,drawn:t.drawn,skipped:t.skipped,byType:{...t.byType},unsupported:{...t.unsupported},renderElapsedMs:t.renderElapsedMs,backend:t.backend,primitiveCount:t.primitiveCount,visiblePrimitiveCount:t.visiblePrimitiveCount,culledPrimitiveCount:t.culledPrimitiveCount,gpuMemoryBytes:t.gpuMemoryBytes,buildElapsedMs:t.buildElapsedMs}}function Ve(t,e,n=1){const r=t.trim().toLowerCase();let i;if(/^#[0-9a-f]{3}$/i.test(r))i=[parseInt(r[1]+r[1],16),parseInt(r[2]+r[2],16),parseInt(r[3]+r[3],16),255];else if(/^#[0-9a-f]{6}$/i.test(r))i=[parseInt(r.slice(1,3),16),parseInt(r.slice(3,5),16),parseInt(r.slice(5,7),16),255];else{const s=r.match(/^rgba?\(([^)]+)\)$/i);if(s){const a=s[1].split(/[\s,\/]+/).filter(Boolean),c=a.slice(0,3).some(f=>f.includes("%")),l=a.map(f=>Number(f.replace("%","")));l.length>=3&&l.slice(0,3).every(Number.isFinite)&&(i=[ne(c?l[0]*2.55:l[0]),ne(c?l[1]*2.55:l[1]),ne(c?l[2]*2.55:l[2]),ne((Number.isFinite(l[3])?l[3]:1)*255)])}}const o=i??e;return[o[0],o[1],o[2],ne(o[3]*n)]}function ne(t){return Math.max(0,Math.min(255,Math.round(t)))}class At{constructor(e={}){u(this,"canvas");u(this,"renderer");u(this,"registry");u(this,"nativeHost");u(this,"options");u(this,"lastResult");u(this,"activeNativeLoader");var n;if(this.options={autoFit:!0,...e},this.registry=e.registry??mt(e),e.loaders)for(const r of e.loaders)this.registry.register(r);if(this.canvas=e.canvas??document.createElement("canvas"),this.canvas.classList.add("cad-viewer-canvas"),e.container)e.container.classList.add("cad-viewer-container"),e.canvas||(this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.display="block",e.container.appendChild(this.canvas)),this.nativeHost=e.nativeHost??document.createElement("div"),this.nativeHost.classList.add("cad-viewer-native-host"),e.nativeHost||e.container.appendChild(this.nativeHost);else if(e.nativeHost)this.nativeHost=e.nativeHost,this.nativeHost.classList.add("cad-viewer-native-host");else if((n=e.canvas)!=null&&n.parentElement){e.canvas.parentElement.classList.add("cad-viewer-container");const r=document.createElement("div");r.classList.add("cad-viewer-native-host"),e.canvas.parentElement.appendChild(r),this.nativeHost=r}this.renderer=nr(e.renderer??"auto",this.canvas,e.canvasOptions),this.renderer.onStats=r=>{var i,o;return(o=(i=this.options).onRenderStats)==null?void 0:o.call(i,r)},this.renderer.onViewChange=r=>{var i,o;return(o=(i=this.options).onViewChange)==null?void 0:o.call(i,r)}}registerLoader(e){return this.registry.register(e),this}async loadFile(e,n={}){var r,i;return(i=(r=this.options).onLoadStart)==null||i.call(r,e),this.loadThroughRegistry({file:e,fileName:e.name},n,e.name)}async loadBuffer(e,n,r={}){var i,o;return(o=(i=this.options).onLoadStart)==null||o.call(i,e),this.loadThroughRegistry({buffer:e,fileName:n},r,n)}async load(e,n={}){var r,i,o;return(i=(r=this.options).onLoadStart)==null||i.call(r,e),this.loadThroughRegistry(e,n,e.fileName??((o=e.file)==null?void 0:o.name))}setDocument(e,n){var i,o;this.deactivateNativeRenderer();const r={document:e,raw:e.raw,bytes:0,elapsedMs:0,format:e.format,warnings:e.warnings,summary:J(e),fileName:n};return this.renderer.setDocument(e),this.options.autoFit||this.renderer.render(),this.lastResult=r,(o=(i=this.options).onLoad)==null||o.call(i,r),r}fit(){var e,n;this.activeNativeLoader?(n=(e=this.activeNativeLoader).fit)==null||n.call(e):this.renderer.fitToView()}zoomIn(){var e,n;this.activeNativeLoader?(n=(e=this.activeNativeLoader).zoomIn)==null||n.call(e):this.renderer.zoomIn()}zoomOut(){var e,n;this.activeNativeLoader?(n=(e=this.activeNativeLoader).zoomOut)==null||n.call(e):this.renderer.zoomOut()}resize(){var e,n;this.activeNativeLoader?(n=(e=this.activeNativeLoader).resize)==null||n.call(e):this.renderer.resize()}setCanvasOptions(e){var n,r;this.options.canvasOptions={...this.options.canvasOptions??{},...e},this.renderer.setOptions(e),this.activeNativeLoader&&((r=(n=this.activeNativeLoader).setNativeOptions)==null||r.call(n,{...this.mergeLoadOptions({}),dwfBackground:e.background??this.options.dwfBackground}))}async preloadDwg(e={}){const n=this.registry.list().find(r=>r.id==="dwg");if(!(n!=null&&n.preload))throw new Error("The registered DWG loader does not support preload().");return n.preload(this.mergeLoadOptions(e))}clear(){this.lastResult=void 0,this.deactivateNativeRenderer(),this.renderer.clear()}destroy(){var e,n,r;this.deactivateNativeRenderer();for(const i of this.registry.list()){const o=i;(e=o.terminateWorker)==null||e.call(o),(n=o.unmount)==null||n.call(o),(r=o.destroy)==null||r.call(o)}this.renderer.destroy()}getLoadResult(){return this.lastResult}getDocument(){var e;return this.activeNativeLoader?(e=this.lastResult)==null?void 0:e.document:this.renderer.getDocument()}getSourceDocument(){var e;return this.activeNativeLoader?(e=this.lastResult)==null?void 0:e.document:this.renderer.getSourceDocument()}getZoomPercent(){return this.activeNativeLoader?100:this.renderer.getZoomPercent()}isNativeRendererActive(){return!!this.activeNativeLoader}async loadThroughRegistry(e,n,r){var i,o;try{const s=this.mergeLoadOptions(n);He(s.signal);const a=await this.registry.detect(e),c={...e,buffer:a.bytes};if(pt(a.loader))return await this.applyNativeLoadResult(a.loader,c,s,r);const l=await a.loader.load(c,s);return this.applyLoadResult(l,r)}catch(s){const a=tr(s);throw(o=(i=this.options).onError)==null||o.call(i,a),a}}applyLoadResult(e,n){var i,o,s,a;this.deactivateNativeRenderer(),(o=(i=this.options).onLoadProgress)==null||o.call(i,{phase:"render",format:e.format,message:"Rendering normalized CAD scene…",percent:96}),this.renderer.setDocument(e.document),this.options.autoFit||this.renderer.render();const r={...e,fileName:n,summary:J(e.document)};return this.lastResult=r,(a=(s=this.options).onLoad)==null||a.call(s,r),r}async applyNativeLoadResult(e,n,r,i){var o,s,a;if(!this.nativeHost)throw new Error("Native DWF rendering requires CadViewerOptions.container, nativeHost, or a canvas parent element.");He(r.signal),this.renderer.clear(),(o=this.activeNativeLoader)==null||o.unmount(),this.activeNativeLoader=e,this.canvas.style.display="none",this.nativeHost.classList.add("is-active");try{const c=await e.mount(n,this.nativeHost,r);He(r.signal);const l={...c,fileName:i,summary:J(c.document)};return this.lastResult=l,this.emitNativeRenderStats(c),(a=(s=this.options).onLoad)==null||a.call(s,l),l}catch(c){throw this.deactivateNativeRenderer(),c}}deactivateNativeRenderer(){var e,n;if(!this.activeNativeLoader&&!((e=this.nativeHost)!=null&&e.classList.contains("is-active"))){this.canvas.style.display="";return}(n=this.activeNativeLoader)==null||n.unmount(),this.activeNativeLoader=void 0,this.nativeHost&&(this.nativeHost.classList.remove("is-active"),this.nativeHost.replaceChildren()),this.canvas.style.display=""}emitNativeRenderStats(e){var s,a,c,l;const n=e.document.metadata,r=Number(((s=n.nativeRenderStats)==null?void 0:s.commands)??e.document.entities.length??0),o=String(((a=n.nativeRenderStats)==null?void 0:a.backend)??"webgl").includes("webgl")?"webgl":"canvas2d";(l=(c=this.options).onRenderStats)==null||l.call(c,{total:r,drawn:r,skipped:0,byType:J(e.document).byType,unsupported:{},renderElapsedMs:e.elapsedMs,backend:o,primitiveCount:r,visiblePrimitiveCount:r,culledPrimitiveCount:0,gpuMemoryBytes:void 0,buildElapsedMs:e.elapsedMs})}mergeLoadOptions(e){const n=this.options.onProgress,r=e.onProgress;return{...this.options,...e,onProgress:i=>{var o,s;(s=(o=this.options).onLoadProgress)==null||s.call(o,i),n==null||n(i),r&&r!==n&&r(i)}}}}function er(t={}){return new At(t)}function tr(t){return t instanceof Error?t:new Error(String(t))}function He(t){if(t!=null&&t.aborted)throw new DOMException("Loading cancelled.","AbortError")}function nr(t,e,n={}){if(t==="canvas2d")return new Oe(e,n);if(t==="webgl")return new We(e,n);if(ze())try{return new We(e,n)}catch{}return new Oe(e,n)}function rr(t,e,n,r={}){const i=t&&typeof t=="object"?t:{},o=or(i,r),s=ar(i,r),a=dr(i,r),c=sr(i.header,n),l=cr(i,c),f=l.view,h=Array.isArray(i.entities)?i.entities:[],d={keepRaw:!!r.keepRaw,includeUnknownProperties:!!r.keepRaw},m=h.filter(y=>!!y&&typeof y=="object").map(y=>Bt(y,d)),g=ae({format:"dwg",sourceName:e,header:c,layers:o,lineTypes:s,blocks:a,entities:m,savedView:f,metadata:{parser:"@mlightcad/libredwg-web",parserMode:"wasm",version:n,savedView:f},warnings:l.warning?[l.warning]:[],raw:r.keepRaw?t:void 0});return m.length===0&&g.warnings.push("DWG parsed successfully but no model-space entities were exposed by the converter. Check layout/paper-space content or unsupported proxy objects."),[...new Set(Object.values(s))].some(y=>y.pattern.some(x=>Number(x.elementTypeFlag??0)!==0))&&g.warnings.push("Complex SHX linetype glyphs are preserved in the normalized LTYPE definition and rendered as a dash/dot approximation; embedded shape glyph fidelity is not available yet."),g}function Bt(t,e){const n=ce(t,void 0,{...e,numericColorMode:"rgb"}),r=b(t.color);r!==void 0&&r>=0&&r<=16777215&&(n.color=r,n.trueColor=r),n.colorIndex=b(t.colorIndex??t.colorNumber??t.aci)??n.colorIndex,n.colorName=P(t.colorName??t.color_name)??n.colorName;const i=b(t.flag??t.flags);i!==void 0&&(n.flag=i);const o=String(t.type??t.entityType??"").toUpperCase(),s=/^(POLYLINE|POLYLINE_2D|POLYLINE2D|POLYLINE_3D|POLYLINE3D)$/.test(o);return(t.isClosed===!0||t.closed===!0||s&&(Number(i??0)&1)===1||o==="LWPOLYLINE"&&(Number(i??0)&512)===512)&&(n.isClosed=!0),n}function ir(t){return typeof t=="number"&&Number.isFinite(t)&&Math.abs(Math.trunc(t))>=1&&Math.abs(Math.trunc(t))<=255}function sr(t,e){const n=t&&typeof t=="object"?{...t}:{};return e&&(n.dwgVersion=e),n}function or(t,e){const n={},r=[],i=t.tables;for(const o of["LAYER","layer","layers"]){const s=t[o]??(i==null?void 0:i[o]);s&&r.push(s)}for(const o of r)for(const s of ye(o)){const a=s,c=P(a.name??a.layerName??a.entryName);if(!c)continue;const l=b(a.colorIndex??a.colorNumber),f=b(a.trueColor??a.true_color??a.truecolor??a.colorRGB??a.colorRgb??a.rgbColor??a.rgb),h=b(a.color),d=ir(l),m=f??(!d&&h!==void 0&&h>=0&&h<=16777215?h:void 0),g={name:c,color:d?void 0:a.color??a.colorName,colorIndex:l??(h!==void 0&&Math.abs(h)<=257?h:void 0),trueColor:m,lineType:P(a.lineType??a.linetype),lineweight:b(a.lineweight??a.lineWeight),isVisible:!(a.isVisible===!1||a.off===!0||Number(l??a.color??1)<0),isFrozen:!!(a.isFrozen??a.frozen),isLocked:!!(a.isLocked??a.locked),raw:e.keepRaw?a:void 0};Pe(n,g)}return n}function ar(t,e){const n={},r=t.tables,i=[t.LTYPE,t.ltype,t.lineTypes,r==null?void 0:r.LTYPE,r==null?void 0:r.ltype,r==null?void 0:r.lineTypes];for(const o of i)for(const s of ye(o)){const a=s,c=P(a.name??a.lineTypeName??a.entryName);if(!c)continue;const f=(Array.isArray(a.pattern)?a.pattern:Array.isArray(a.dashes)?a.dashes:[]).flatMap(h=>{if(typeof h=="number")return[{length:h}];if(!h||typeof h!="object")return[];const d=h,m=b(d.elementLength??d.length??d.dashLength);if(m===void 0)return[];const g=b(d.elementTypeFlag),S=b(d.shapeNumber),y=g!==void 0&&S!==void 0;return[{length:m,elementTypeFlag:y?S:b(d.typeFlag??d.elementTypeFlag),shapeNumber:y?g:b(d.shapeCode??d.shapeNumber),scale:b(d.scale),rotation:b(d.rotation),offsetX:b(d.offsetX),offsetY:b(d.offsetY),text:P(d.text)}]});Ut(n,{name:c,handle:P(a.handle??a.id),description:P(a.description),totalPatternLength:b(a.totalPatternLength??a.patternLength),pattern:f,raw:e.keepRaw?a:void 0})}return n}function cr(t,e){const n=t.tables,i=ye(t.VPORT??t.vports??(n==null?void 0:n.VPORT)??(n==null?void 0:n.vports)).filter(x=>!!x&&typeof x=="object").find(x=>String(x.name??"").trim().toLowerCase()==="*active"),o=i?"vport":"header-ucs",s=i??e,a=N(s.ucsOrigin??s.UCSORG??e.UCSORG),c=N(s.ucsXAxis??s.UCSXDIR??e.UCSXDIR),l=N(s.ucsYAxis??s.UCSYDIR??e.UCSYDIR),f=b(s.viewTwistAngle??s.twistAngle??s.VIEWTWIST)??0,h=N(s.viewDirectionFromTarget??s.viewDirection??s.direction??s.VIEWDIR),d=!hr(a,c,l);if(!(!!i||!!h||d||Math.abs(f)>1e-12))return{};const g=fr(h),S=g?lr(a,c,l,f):{a:1,b:0,c:0,d:1,e:0,f:0},y={source:o,name:P(s.name),handle:P(s.handle),center:N(s.center??s.VIEWCTR),target:N(s.viewTarget??s.target??s.TARGET),direction:h,viewHeight:b(s.viewHeight??s.height??s.VIEWSIZE),aspectRatio:b(s.aspectRatio),twistAngle:f,ucsOrigin:a,ucsXAxis:c,ucsYAxis:l,sceneTransformApplied:g,sceneTransform:S};return g?{view:y}:{view:y,warning:"The saved CAD view has a missing, non-finite, or tilted VIEWDIR. File Viewer kept world coordinates instead of applying an unsafe 2D UCS/PLAN rotation."}}function lr(t,e,n,r){const i=Ue(e)??{x:1,y:0},o=Ue(n)??{x:-i.y,y:i.x},s=i.x*o.x+i.y*o.y,a=Ue({x:o.x-i.x*s,y:o.y-i.y*s})??{x:-i.y,y:i.x},c={a:i.x,b:a.x,c:i.y,d:a.y,e:t?-(t.x*i.x+t.y*i.y):0,f:t?-(t.x*a.x+t.y*a.y):0};return pe(St(Number.isFinite(r)?r:0),c)}function Ue(t){if(!t||Math.abs(Number(t.z??0))>1e-6)return;const e=Math.hypot(t.x,t.y);if(!(!Number.isFinite(e)||e<1e-12))return{x:t.x/e,y:t.y/e}}function fr(t){if(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.z))return!1;const e=Math.hypot(t.x,t.y,Number(t.z));return!Number.isFinite(e)||e<1e-12?!1:Math.hypot(t.x,t.y)/e<=1e-4&&Math.abs(Number(t.z))/e>=1-1e-8}function hr(t,e,n){const r=(a,c)=>Number.isFinite(a)&&Math.abs(Number(a)-c)<=1e-10,i=!t||r(t.x,0)&&r(t.y,0)&&r(t.z??0,0),o=!e||r(e.x,1)&&r(e.y,0)&&r(e.z??0,0),s=!n||r(n.x,0)&&r(n.y,1)&&r(n.z??0,0);return i&&o&&s}function dr(t,e){const n={},r=[t.blocks,t.blockHeaders,t.block_records,t.blockRecords],i=t.tables;r.push(i==null?void 0:i.BLOCK,i==null?void 0:i.BLOCK_RECORD,i==null?void 0:i.blocks);const o={keepRaw:!!e.keepRaw,includeUnknownProperties:!!e.keepRaw};for(const s of r)for(const a of ye(s)){const c=a,l=P(c.name??c.blockName??c.name2);if(!l)continue;const h=(Array.isArray(c.entities)?c.entities:Array.isArray(c.ownedObjects)?c.ownedObjects:[]).filter(d=>!!d&&typeof d=="object").map(d=>Bt(d,o));Je(n,{name:l,basePoint:N(c.basePoint??c.origin)??{x:0,y:0},entities:h,raw:e.keepRaw?c:void 0})}return n}function ye(t){if(!t)return[];if(Array.isArray(t))return t;if(typeof t!="object")return[];const e=t,n=Object.values(e).filter(i=>i&&typeof i=="object"),r=["entries","records","items","values","layers","blocks"].flatMap(i=>Array.isArray(e[i])?e[i]:[]);return r.length>0?r:n}v.CadCanvasRenderer=Oe,v.CadLoaderRegistry=je,v.CadViewer=At,v.CadWebGLRenderer=We,v.DwfLoader=ct,v.DwgLoader=Ke,v.DwgWorkerClient=$e,v.DxfLoader=rt,v.applyByBlockLineTypeInheritance=Fe,v.colorFromAci=F,v.colorFromTrueColor=G,v.createCadDocument=ae,v.createCadSceneDocument=Re,v.createCadViewer=er,v.createDashedCadPrimitives=me,v.createDashedCadSegments=An,v.createDefaultLoaderRegistry=mt,v.detectCadFormat=R,v.inferEntityKind=O,v.isCadNativeRenderableLoader=pt,v.isCadPolylineClosed=Ce,v.isWebGLAvailable=ze,v.normalizeCadEntity=ce,v.normalizeDwgDatabase=rr,v.readInputBytes=T,v.resolveCadColor=_,v.resolveCadLinePattern=ue,v.resolveCadLineTypeReference=De,v.summarizeCadDocument=J,v.supportsDwgWorker=ie,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
34
34
|
//# sourceMappingURL=cad-viewer.umd.cjs.map
|