106 lines
225 KiB
JavaScript
106 lines
225 KiB
JavaScript
|
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./dist-BzZSLV34.js","./package-Bop5TfAT.js","./runtime-core.esm-bundler-DO-WTVbd.js","./package-OvxnQO7z.css"])))=>i.map(i=>d[i]);
|
||
|
|
import{h as e,r as t}from"./package-Bop5TfAT.js";import{D as n,J as r,X as i,Y as a,_ as o,b as s,f as c,g as l,h as u,i as d,o as f,r as p,s as m,t as h,y as g}from"./runtime-core.esm-bundler-DO-WTVbd.js";function _(e,t,n,r){return r===void 0?{level:e,code:t,message:n}:{level:e,code:t,message:n,source:r}}function v(e){return(e??[]).filter(e=>e.level!==`info`)}function y(){return globalThis.DecompressionStream}var b=class{async inflateRaw(e){let t=y();if(!t)throw Error(`This browser does not expose DecompressionStream. Provide a custom InflateProvider, or pre-bundle a WASM/JS inflater.`);try{return await x(e,`deflate-raw`,t)}catch(n){try{return await x(e,`deflate`,t)}catch{throw n instanceof Error?n:Error(String(n))}}}};async function x(e,t,n){let r=new Blob([e]).stream().pipeThrough(new n(t)),i=await new Response(r).arrayBuffer();return new Uint8Array(i)}var S=new TextDecoder(`utf-8`);new TextDecoder(`ascii`);function C(e){return S.decode(e)}function w(e){let t=[],n=e.replace(/\\/g,`/`);for(let e of n.split(`/`))!e||e===`.`||(e===`..`?t.pop():t.push(e));return t.join(`/`)}function T(e){let t=w(e),n=t.lastIndexOf(`/`);return n<0?``:t.slice(0,n)}function E(e,t){if(!t)return w(e);if(t.startsWith(`/`))return w(t.slice(1));let n=T(e);return w((n?n+`/`:``)+t)}function ee(e){let t=e.indexOf(`:`);return t>=0?e.slice(t+1):e}function D(e){return ee(e.localName||e.nodeName)}function O(e,t){return e.getAttribute(t)??e.getAttributeNS(null,t)??void 0}function k(e){return Array.from(e.childNodes).filter(e=>e.nodeType===1)}function A(e,t=`document.xml`){if(typeof DOMParser<`u`){let n=new DOMParser().parseFromString(e,`application/xml`),r=n.getElementsByTagName(`parsererror`)[0];if(r)throw Error(`XML parse error in ${t}: ${r.textContent?.slice(0,180)??`unknown error`}`);return n}try{return ne(e)}catch(e){throw Error(`XML parse error in ${t}: ${String(e)}`)}}var j=class e{constructor(e,t){this.nodeType=1,this.childNodes=[],this.nodeName=e,this.localName=ee(e),this.attributes=t}get textContent(){return this.childNodes.map(e=>e.textContent??``).join(``)}get children(){return this.childNodes.filter(t=>t instanceof e)}getAttribute(e){return this.attributes.find(t=>t.name===e||t.nodeName===e)?.value??null}getAttributeNS(e,t){return this.attributes.find(e=>e.localName===t)?.value??null}getElementsByTagName(t){let n=[],r=i=>{(t===`*`||i.nodeName===t||i.localName===t)&&n.push(i);for(let t of i.childNodes)t instanceof e&&r(t)};for(let t of this.childNodes)t instanceof e&&r(t);return n}},M=class{constructor(e){this.textContent=e,this.nodeType=3}},te=class{constructor(){this.nodeType=9,this.childNodes=[]}get textContent(){return this.childNodes.map(e=>e.textContent??``).join(``)}get children(){return this.childNodes.filter(e=>e instanceof j)}get documentElement(){return this.children[0]}getElementsByTagName(e){let t=[],n=r=>{(e===`*`||r.nodeName===e||r.localName===e)&&t.push(r);for(let e of r.childNodes)e instanceof j&&n(e)};for(let e of this.childNodes)e instanceof j&&n(e);return t}};function ne(e){let t=new te,n=[t],r=0;for(;r<e.length;){let i=e.indexOf(`<`,r);if(i<0){re(n[n.length-1],e.slice(r));break}if(i>r&&re(n[n.length-1],e.slice(r,i)),e.startsWith(`<!--`,i)){let t=e.indexOf(`-->`,i+4);if(t<0)throw Error(`Unclosed XML comment.`);r=t+3;continue}if(e.startsWith(`<![CDATA[`,i)){let t=e.indexOf(`]]>`,i+9);if(t<0)throw Error(`Unclosed XML CDATA section.`);re(n[n.length-1],e.slice(i+9,t)),r=t+3;continue}if(e.startsWith(`<?`,i)){let t=e.indexOf(`?>`,i+2);if(t<0)throw Error(`Unclosed XML processing instruction.`);r=t+2;continue}if(e.startsWith(`<!`,i)){let t=e.indexOf(`>`,i+2);if(t<0)throw Error(`Unclosed XML declaration.`);r=t+1;continue}let a=ie(e,i+1);if(a<0)throw Error(`Unclosed XML tag.`);let o=e.slice(i+1,a).trim();if(r=a+1,!o)continue;if(o[0]===`/`){let e=o.slice(1).trim().split(/\s+/)[0]??``,r=n.pop();for(;r&&r instanceof j&&r.nodeName!==e&&r.localName!==ee(e)&&n.length>0;)r=n.pop();n.length===0&&n.push(t);continue}let s=o.endsWith(`/`);s&&(o=o.slice(0,-1).trim());let c=o.search(/\s/),l=new j(c<0?o:o.slice(0,c),ae(c<0?``:o.slice(c+1))),u=n[
|
||
|
|
`).replace(/\\L|\\l/g,``).replace(/\\O|\\o/g,``).replace(/\\H[-+]?\d*\.?\d+x;/gi,``).replace(/\\S([^;]+);/gi,`$1`).replace(/\\[A-Za-z][^;]*;/g,``).replace(/\\~/g,` `).replace(/\\\\/g,`\\`).trim()}function Zn(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=(e,a)=>{t=Math.min(t,e),n=Math.min(n,a),r=Math.max(r,e),i=Math.max(i,a)};for(let t of e)if(`points`in t)for(let e=0;e+1<t.points.length;e+=2)a(t.points[e],t.points[e+1]);else if(t.type===`rect`)a(t.x,t.y),a(t.x+t.width,t.y+t.height);else if(t.type===`text`){let e=t.size??12;a(t.x,t.y),a(t.x,t.y+e)}else if(t.type===`path`)for(let e of t.commands)`x`in e&&`y`in e&&a(e.x,e.y),`x1`in e&&`y1`in e&&a(e.x1,e.y1),`x2`in e&&`y2`in e&&a(e.x2,e.y2);return Number.isFinite(t)?{minX:t,minY:n,maxX:r,maxY:i}:void 0}function Qn(e){return e>=48&&e<=57}function $n(e){return Array.from(e,e=>String.fromCharCode(e)).join(``)}function er(e,t,n){return`rgb(${nr(e)}, ${nr(t)}, ${nr(n)})`}function tr(e,t,n,r){return`rgba(${nr(e)}, ${nr(t)}, ${nr(n)}, ${Math.max(0,Math.min(1,r/255))})`}function nr(e){return Math.max(0,Math.min(255,Math.round(e)))}function rr(e){return(e.match(/[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number).filter(Number.isFinite)}function ir(e){return[`#000000`,`#ff0000`,`#ffff00`,`#00ff00`,`#00ffff`,`#0000ff`,`#ff00ff`,`#000000`,`#808080`,`#c0c0c0`][e]??`#000000`}function ar(e){return e.entries.some(e=>/\.w2d$/i.test(e.name)||/manifest\.xml$/i.test(e.name)||/descriptor\.xml$/i.test(e.name)||/\.hsf$/i.test(e.name))}async function or(e){let t=[],n=[],r=e.entries.map(e=>({path:e.name,mediaType:le(e.name),size:e.uncompressedSize})),i=e.entries.find(e=>/(^|\/)manifest\.xml$/i.test(e.name)),a=[];if(i)try{a=lr(C(await e.read(i)),i.name),t.push(_(`info`,`DWF_MANIFEST_FOUND`,`Found DWF manifest with ${a.length} section(s).`,i.name))}catch(e){t.push(_(`warning`,`DWF_MANIFEST_PARSE_FAILED`,`Failed to parse DWF manifest: ${String(e)}`,i.name))}else t.push(_(`info`,`DWF_NO_MANIFEST`,`No manifest.xml was found; falling back to resource discovery.`));if(a.length>0)for(let r of a){let i=hr(r,/2d\s+streaming\s+graphics/i)??r.resources.find(e=>/\.w2d$/i.test(e.path));if(!i)continue;let a=hr(r,/^descriptor$/i)??{path:w(r.name+`/descriptor.xml`)},o={};if(a&&e.has(a.path))try{o=ur(C(await e.read(a.path)),i.path)}catch(e){t.push(_(`warning`,`DWF_DESCRIPTOR_PARSE_FAILED`,`Failed to parse descriptor for ${r.title}: ${String(e)}`,a.path))}let s=[],c=[];try{let t=await cr(e,i.path);c.push(...t.primitives),s.push(...t.diagnostics)}catch(e){s.push(_(`warning`,`DWF_W2D_READ_FAILED`,`Failed to read or parse ${i.path}: ${String(e)}`,i.path))}for(let t of r.resources.filter(e=>/markup\s+private/i.test(e.role??``)&&/\.xml$/i.test(e.path)))if(e.has(t.path))try{let n=dr(C(await e.read(t.path)),t.path,o.w2dTransform);c.push(...n.primitives),s.push(...n.diagnostics)}catch(e){s.push(_(`warning`,`DWF_MARKUP_XML_PARSE_FAILED`,`Failed to parse markup private XML: ${String(e)}`,t.path))}if(c.length>0){let e=mr(c),t=e?Math.max(1,e.maxX-e.minX):o.paperWidth??1e3,a=e?Math.max(1,e.maxY-e.minY):o.paperHeight??1e3;n.push({id:`page-${n.length+1}`,name:r.title||i.title||gr(i.path),kind:`w2d-text`,sourcePath:i.path,width:t,height:a,primitives:c,bounds:e,diagnostics:s})}else{let t=hr(r,/thumbnail|preview/i)??r.resources.find(e=>/\.(png|jpe?g|gif|bmp)$/i.test(e.path));t&&e.has(t.path)&&n.push({id:`image-${n.length+1}`,name:r.title||gr(t.path),kind:`image`,sourcePath:t.path,mediaType:t.mediaType??le(t.path)??`image/png`,width:1e3,height:1e3,diagnostics:[...s,_(`warning`,`DWF_IMAGE_FALLBACK`,`Vector stream did not produce geometry; using section thumbnail as fallback.`,t.path)]})}}n.length===0&&await sr(e,n,t);let o=e.entries.filter(e=>/\.hsf$/i.test(e.name));if(o.length>0&&(t.push(_(`warning`,`DWF_3D_HSF_DETECTED`,`Detected ${o.length} HSF/3D resource(s). This frontend build reports them but does not render 3D HSF.`,o[0]?.name)),n.length===0&&n.push({id:`unsupported-3d`,name:`Unsupported 3D DWF`,kind:`unsupported`,width:1e3,height:1e3,sourcePath:o[0]?.name,reason:`3D HSF resource detected; not implemented in this pure fronten
|
||
|
|
`);if(s){let c=a(t,r),l=B(e,`Height`),u=o.length?B(o[0],`FontHeight`):void 0,d=n&&l?Math.max(10,Math.abs(l/n.sy)):u??12,f=o.length?R(o[0],`Color`):void 0;i.push({type:`text`,x:c.x,y:c.y,text:s,size:d,fill:f?pr(f):fr(e).stroke})}}}}let s=[];return i.length>0&&s.push(_(`info`,`DWF_MARKUP_XML_PARSED`,`Parsed ${i.length} markup primitive(s) from markup private XML.`,t)),{primitives:i,diagnostics:s}}function fr(e){let t=`#0000ff`,n,r=1,i=Array.from(e.getElementsByTagName(`*`)).filter(e=>z(e)===`FormatProperty`);for(let e of i){let i=(R(e,`Name`)??``).toUpperCase(),a=(R(e,`Enabled`)??`true`).toLowerCase()!==`false`,o=R(e,`ModifierUIntVal`)??R(e,`UIntValue`)??R(e,`DblValue`)??R(e,`IntValue`);!a||o===void 0||(i===`LINECOLOR`&&(t=pr(o)),i===`FILLCOLOR`&&(n=pr(o)),i===`LINEWEIGHT`&&(r=Math.max(1,Number(o)||r)),i===`NOFILL`&&/true/i.test(R(e,`BoolValue`)??``)&&(n=void 0))}return{stroke:t,fill:n,lineWidth:r}}function pr(e){let t=Number(e);if(!Number.isFinite(t))return`#000000`;let n=t>>>0;return`rgb(${n>>>16&255}, ${n>>>8&255}, ${n&255})`}function mr(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=(e,a)=>{t=Math.min(t,e),n=Math.min(n,a),r=Math.max(r,e),i=Math.max(i,a)};for(let t of e)if(`points`in t)for(let e=0;e+1<t.points.length;e+=2)a(t.points[e],t.points[e+1]);else if(t.type===`rect`)a(t.x,t.y),a(t.x+t.width,t.y+t.height);else if(t.type===`text`){let e=t.size??12;a(t.x,t.y),a(t.x,t.y+e)}else if(t.type===`path`)for(let e of t.commands)`x`in e&&`y`in e&&a(e.x,e.y),`x1`in e&&`y1`in e&&a(e.x1,e.y1),`x2`in e&&`y2`in e&&a(e.x2,e.y2);return Number.isFinite(t)?{minX:t,minY:n,maxX:r,maxY:i}:void 0}function hr(e,t){return e.resources.find(e=>t.test(e.role??``))}function R(e,t){return e.getAttribute(t)??e.getAttribute(`dwf:${t}`)??e.getAttribute(`ePlot:${t}`)??Array.from(e.attributes).find(e=>e.localName===t)?.value??void 0}function z(e){let t=e.localName||e.nodeName,n=t.indexOf(`:`);return n>=0?t.slice(n+1):t}function B(e,t){let n=R(e,t);if(n===void 0)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function gr(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function _r(e){let t=e.entries.filter(e=>/\.(png|jpe?g|gif|bmp)$/i.test(e.name));if(t.length!==0)return t.sort((e,t)=>vr(t.name,t.uncompressedSize)-vr(e.name,e.uncompressedSize))[0]}function vr(e,t){let n=Math.min(t,1e7)/1e3;return/thumbnail|preview/i.test(e)&&(n+=5e3),ce(e)===`png`&&(n+=100),n}async function yr(e,t={}){let n=await br(e),r=t.fileName??(e instanceof File?e.name:void 0)??`document.dwf`;if(he(n)){let e=me.open(n,t.inflater);return rn(e)?await nn(e):ar(e)?await or(e):e.entries.some(e=>/\.fpage$/i.test(e.name))?await nn(e):await or(e)}if(se(n)){let e=An(n,r),t=[{id:`page-1`,name:r,kind:`w2d-text`,width:e.bounds?Math.max(1,e.bounds.maxX-e.bounds.minX):1e3,height:e.bounds?Math.max(1,e.bounds.maxY-e.bounds.minY):1e3,sourcePath:r,primitives:e.primitives,bounds:e.bounds,diagnostics:e.diagnostics}];return xe({kind:`unknown`,pages:[],resources:[{path:r,mediaType:`text/plain`,size:n.byteLength}],diagnostics:[_(`warning`,`RAW_TEXT_W2D_MODE`,`Input is not a DWF ZIP package; opened it as a textual W2D-like vector stream.`,r)],packageEntries:[r]},t)}let i={id:`unsupported-raw`,name:r,kind:`unsupported`,width:1e3,height:1e3,sourcePath:r,reason:`Input is neither a ZIP-based DWF/DWFx package nor a supported textual W2D stream.`,diagnostics:[_(`error`,`UNSUPPORTED_RAW_FORMAT`,`Unsupported raw DWF input. DWF 6+/DWFx ZIP packages are required for this build.`,r)]};return xe({kind:`unknown`,pages:[],resources:[{path:r,size:n.byteLength}],diagnostics:i.diagnostics,packageEntries:[r]},[i])}async function br(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(await e.arrayBuffer())}var xr={a:1,b:0,c:0,d:1,e:0,f:0};function V(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 Sr(e,t,n){return[e.a*t+e.c*n+e.e,e.b*t+e.d*n+e.f]}function Cr(e){if(!e)return{...xr};let t=N(e);return t.length>=6?{a:t[0],b:t[1],c:t[2],d:t[3],e:t[4],f:t[5]}:{...xr}}function H(e,t=1){if(!e||
|
||
|
|
attribute vec2 a_pos;
|
||
|
|
attribute vec4 a_color;
|
||
|
|
uniform vec4 u_matrix;
|
||
|
|
uniform vec4 u_viewport;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
float x = u_matrix.x * a_pos.x + u_matrix.z * a_pos.y + u_viewport.x;
|
||
|
|
float y = u_matrix.y * a_pos.x + u_matrix.w * a_pos.y + u_viewport.y;
|
||
|
|
vec2 clip = vec2((x / u_viewport.z) * 2.0 - 1.0, 1.0 - (y / u_viewport.w) * 2.0);
|
||
|
|
gl_Position = vec4(clip, 0.0, 1.0);
|
||
|
|
v_color = a_color;
|
||
|
|
}
|
||
|
|
`,hi=`
|
||
|
|
precision mediump float;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
gl_FragColor = v_color;
|
||
|
|
}
|
||
|
|
`,gi=class{constructor(e){this.document=e,this.fontCache=new Map,this.xmlCache=new Map}async render(e,t,n={}){if(!this.document.opc)throw Error(`XPS page requires an OPC package view.`);let r=v(e.diagnostics),i=(await this.getXmlDocument(e.sourcePath)).documentElement,a=t.getContext(`2d`);if(!a)throw Error(`CanvasRenderingContext2D is not available.`);let o=n.background??`#ffffff`,s={dpr:Mr(t),zoom:n.zoom??1},c=kr({canvasWidth:t.width,canvasHeight:t.height,pageWidth:e.width,pageHeight:e.height,zoom:n.zoom,panX:n.panX,panY:n.panY}),l=0;if(n.preferWebgl??!0)try{let o=this.getWebGlBackend(n.webglCanvas);n.webglCanvas&&(n.webglCanvas.style.visibility=`visible`);let u=o.render(e,i,t,{...n,compositeToTarget:!n.webglCanvas});return a.save(),a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,t.width,t.height),a.restore(),l+=u.commands,l+=await this.renderElementToCanvas(i,a,e.sourcePath,c,1,r,{vectors:!1,overlays:!0},n,s),r.push(...u.warnings),{backend:`webgl-xps`,commands:l,warnings:r}}catch(t){n.webglCanvas&&(n.webglCanvas.style.visibility=`hidden`),r.push(_(`warning`,`WEBGL_XPS_BACKEND_FALLBACK`,`WebGL XPS vector path failed, falling back to ${n.preferWasm?`WASM raster`:`Canvas2D`}: ${String(t)}`,e.sourcePath))}if(n.webglCanvas&&(n.webglCanvas.style.visibility=`hidden`),n.preferWasm)try{return this.wasm??=new Lr({wasmUrl:n.wasmUrl}),await this.wasm.init(),this.wasm.begin(t.width,t.height,o),l+=this.renderElementToWasm(i,c,1,r,n,s),a.setTransform(1,0,0,1,0,0),a.putImageData(this.wasm.toImageData(),0,0),l+=await this.renderElementToCanvas(i,a,e.sourcePath,c,1,r,{vectors:!1,overlays:!0},n,s),{backend:`wasm-raster`,commands:l,warnings:r}}catch(e){r.push(_(`warning`,`WASM_BACKEND_FALLBACK`,`WASM raster path failed, falling back to Canvas2D: ${String(e)}`))}return a.save(),a.setTransform(1,0,0,1,0,0),a.fillStyle=o,a.fillRect(0,0,t.width,t.height),a.restore(),l+=await this.renderElementToCanvas(i,a,e.sourcePath,c,1,r,{vectors:!0,overlays:!0},n,s),{backend:`canvas2d`,commands:l,warnings:r}}getWebGlBackend(e){return(!this.webgl||this.webglCanvas!==e)&&(this.webgl?.dispose(),this.webgl=new Hr(e),this.webglCanvas=e),this.webgl}getXmlDocument(e){let t=this.xmlCache.get(e);return t||(t=this.document.opc.readText(e).then(t=>A(t,e)),this.xmlCache.set(e,t)),t}dispose(){this.webgl?.dispose(),this.webgl=void 0,this.webglCanvas=void 0,this.xmlCache.clear(),this.fontCache.clear()}async renderElementToCanvas(e,t,n,r,i,a,o,s,c){let l=D(e),u=V(r,wi(e)),d=i*ki(O(e,`Opacity`)),f=0;if(l===`Path`&&o.vectors){let n=Ti(e);if(n.length>0){t.save(),t.setTransform(u.a,u.b,u.c,u.d,u.e,u.f),t.globalAlpha=d;let r=O(e,`Clip`);r&&(t.beginPath(),Cn(t,Sn(r)),t.clip()),t.beginPath(),Cn(t,n);let i=Di(e,`Fill`,d),a=Di(e,`Stroke`,d),o=Number(O(e,`StrokeThickness`)??1),l=vi(n);i&&Fr(l,u,s,c)&&(t.fillStyle=i,t.fill(Ai(e))),a&&o>0&&(t.strokeStyle=a,t.lineWidth=Nr(o,u,s,c),_i(t,e,t.lineWidth),t.stroke()),t.restore(),f++}}else if(l===`Glyphs`&&o.overlays)f+=await this.drawGlyphs(t,n,e,u,d,a,s,c);else if(l===`Image`&&o.overlays){let r=O(e,`Source`)??O(e,`ImageSource`);if(r)try{await this.drawImageResource(t,n,r,u,d,e),f++}catch(e){a.push(_(`warning`,`XPS_IMAGE_DRAW_FAILED`,`Failed to draw image ${r}: ${String(e)}`,n))}}else l===`Canvas`||l===`FixedPage`||l.endsWith(`.RenderTransform`)||l.endsWith(`.Resources`);if(l===`Path`&&o.overlays){let r=Oi(e,`Fill`,`ImageBrush`),i=r?O(r,`ImageSource`):void 0;if(r&&i)try{await this.drawImageBrush(t,n,i,u,d,e,r),f++}catch(e){a.push(_(`warning`,`XPS_IMAGEBRUSH_FAILED`,`Failed to draw ImageBrush ${i}: ${String(e)}`,n))}}for(let r of k(e))D(r).includes(`.`)||(f+=await this.renderElementToCanvas(r,t,n,u,d,a,o,s,c));return f}renderElementToWasm(e,t,n,r,i,a){if(!this.wasm)return 0;let o=D(e),s=V(t,wi(e)),c=n*ki(O(e,`Opacity`)),l=0;if(o===`Path`){let t=Ti(e);if(t.length>0){let n=Di(e,`Fill`,c),r=Di(e,`Stroke`,c),o=Number(O(e,`StrokeThickness`)??1),u=Nr(o,s,i,a)*Math.max(1e-12,Math.hypot(s.a,s.b)),d=wn(t,.5);if(n)for(let e of d)(e.closed||e.points.length>=6)&&this.wasm.drawPolygon(e.points,s,n);if(r&&o>0)for(let e of d)this.wasm.drawPolyline(e.points,
|
||
|
|
attribute vec2 a_pos;
|
||
|
|
attribute vec4 a_color;
|
||
|
|
uniform vec4 u_matrix;
|
||
|
|
uniform vec4 u_viewport;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
float x = u_matrix.x * a_pos.x + u_matrix.z * a_pos.y + u_viewport.x;
|
||
|
|
float y = u_matrix.y * a_pos.x + u_matrix.w * a_pos.y + u_viewport.y;
|
||
|
|
vec2 clip = vec2((x / u_viewport.z) * 2.0 - 1.0, 1.0 - (y / u_viewport.w) * 2.0);
|
||
|
|
gl_Position = vec4(clip, 0.0, 1.0);
|
||
|
|
v_color = a_color;
|
||
|
|
}
|
||
|
|
`,$i=`
|
||
|
|
precision mediump float;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
gl_FragColor = v_color;
|
||
|
|
}
|
||
|
|
`,ea=class{async render(e,t,n={}){let r=v(e.diagnostics),i=n.background??`#ffffff`;if(n.preferWebgl??!0)try{let i=this.getWebGlBackend(n.webglCanvas);n.webglCanvas&&(n.webglCanvas.style.visibility=`visible`);let a=i.render(e,t,{...n,compositeToTarget:!n.webglCanvas}),o=ra(a.gpuBytes),s=a.cacheHit?`cache hit`:`cache upload`;return r.push(_(`info`,`WEBGL_W2D_RENDERED`,`WebGL rendered ${a.vertexCount} vertices, ${a.textCount} text item(s), GPU cache ${o}, ${s}.`,e.sourcePath)),r.push(...a.warnings),{backend:`webgl`,commands:a.commands,warnings:r}}catch(t){r.push(_(`warning`,`WEBGL_BACKEND_FALLBACK`,`WebGL vector path failed, falling back to ${n.preferWasm?`WASM raster`:`Canvas2D`}: ${String(t)}`,e.sourcePath))}n.webglCanvas&&(n.webglCanvas.style.visibility=`hidden`);let a=t.getContext(`2d`);if(!a)throw Error(`CanvasRenderingContext2D is not available.`);let o=Ar(e,t.width,t.height,n.zoom,n.panX,n.panY),s={dpr:Mr(t),zoom:n.zoom??1},c=0;if(n.preferWasm)try{this.wasm??=new Lr({wasmUrl:n.wasmUrl}),await this.wasm.init(),this.wasm.begin(t.width,t.height,i);for(let t of e.primitives)c+=this.drawPrimitiveWasm(t,o,n,s);a.setTransform(1,0,0,1,0,0),a.putImageData(this.wasm.toImageData(),0,0);for(let t of e.primitives.filter(e=>e.type===`text`))c+=this.drawPrimitiveCanvas(a,t,o,n,s);return{backend:`wasm-raster`,commands:c,warnings:r}}catch(t){r.push(_(`warning`,`WASM_BACKEND_FALLBACK`,`WASM raster path failed, falling back to Canvas2D: ${String(t)}`,e.sourcePath))}a.save(),a.setTransform(1,0,0,1,0,0),a.fillStyle=i,a.fillRect(0,0,t.width,t.height),a.restore();for(let t of e.primitives)c+=this.drawPrimitiveCanvas(a,t,o,n,s);return{backend:`canvas2d`,commands:c,warnings:r}}dispose(){this.webgl?.dispose(),this.webgl=void 0,this.webglCanvas=void 0}getWebGlBackend(e){return(!this.webgl||this.webglCanvas!==e)&&(this.webgl?.dispose(),this.webgl=new Fi(e),this.webglCanvas=e),this.webgl}drawPrimitiveCanvas(e,t,n,r,i){let a=V(n,t.matrix??{a:1,b:0,c:0,d:1,e:0,f:0}),o=H(t.stroke??`#000000`)??`#000000`,s=H(t.fill);if(t.type===`text`){let[n,c]=Sr(a,t.x,t.y),l=Math.max(1,Math.abs((t.size??12)*na(a)));if(!Pr(t.size??12,a,r,i)||n>e.canvas.width+64||c>e.canvas.height+64||n<-e.canvas.width||c<-e.canvas.height)return 0;e.save(),e.setTransform(1,0,0,1,0,0),e.fillStyle=s??o,e.font=`${Math.min(768,l)}px sans-serif`,e.textBaseline=`alphabetic`;for(let[r,i]of t.text.split(/\n/).entries())e.fillText(i,n,c+r*l*1.15);return e.restore(),1}if(e.save(),e.setTransform(a.a,a.b,a.c,a.d,a.e,a.f),e.lineWidth=Nr(t.lineWidth??1,a,r,i),t.type===`polyline`){if(t.points.length>=4){e.beginPath(),e.moveTo(t.points[0],t.points[1]);for(let n=2;n+1<t.points.length;n+=2)e.lineTo(t.points[n],t.points[n+1]);e.strokeStyle=o,e.stroke()}}else if(t.type===`polygon`){if(t.points.length>=6){e.beginPath(),e.moveTo(t.points[0],t.points[1]);for(let n=2;n+1<t.points.length;n+=2)e.lineTo(t.points[n],t.points[n+1]);e.closePath(),s&&(e.fillStyle=s,e.fill()),t.stroke&&(e.strokeStyle=o,e.stroke())}}else t.type===`rect`?(s&&(e.fillStyle=s,e.fillRect(t.x,t.y,t.width,t.height)),t.stroke&&(e.strokeStyle=o,e.strokeRect(t.x,t.y,t.width,t.height))):t.type===`path`&&(e.beginPath(),Cn(e,t.commands),s&&(e.fillStyle=s,e.fill()),t.stroke&&(e.strokeStyle=o,e.stroke()));return e.restore(),1}drawPrimitiveWasm(e,t,n,r){if(!this.wasm||e.type===`text`)return 0;let i=V(t,e.matrix??{a:1,b:0,c:0,d:1,e:0,f:0}),a=jr(i),o=e=>Nr(e??1,i,n,r)*a;if(e.type===`polyline`)this.wasm.drawPolyline(e.points,i,H(e.stroke??`#000000`),o(e.lineWidth));else if(e.type===`polygon`)this.wasm.drawPolygon(e.points,i,H(e.fill)),e.stroke&&this.wasm.drawPolyline(ta(e.points),i,H(e.stroke),o(e.lineWidth));else if(e.type===`rect`){let t=[e.x,e.y,e.x+e.width,e.y,e.x+e.width,e.y+e.height,e.x,e.y+e.height,e.x,e.y];e.fill&&this.wasm.drawPolygon(t,i,H(e.fill)),e.stroke&&this.wasm.drawPolyline(t,i,H(e.stroke),o(e.lineWidth))}else if(e.type===`path`){let t=wn(e.commands,.5),n=H(e.fill),r=H(e.stroke);if(n)for(let e of t)(e.closed||e.points.length>=6)&&this.wasm.drawPolygon(e.points,i,n);if(r)for(let n of t)this.wasm.drawPolyline(n.points,i,r,o(e.lineWidth
|
||
|
|
attribute vec3 a_position;
|
||
|
|
attribute vec3 a_normal;
|
||
|
|
uniform mat4 u_mvp;
|
||
|
|
uniform mat4 u_model;
|
||
|
|
varying vec3 v_normal;
|
||
|
|
void main() {
|
||
|
|
v_normal = normalize((u_model * vec4(a_normal, 0.0)).xyz);
|
||
|
|
gl_Position = u_mvp * vec4(a_position, 1.0);
|
||
|
|
}
|
||
|
|
`),la(e,e.FRAGMENT_SHADER,`
|
||
|
|
precision mediump float;
|
||
|
|
varying vec3 v_normal;
|
||
|
|
uniform vec3 u_color;
|
||
|
|
uniform vec3 u_light0;
|
||
|
|
uniform vec3 u_light1;
|
||
|
|
uniform float u_ambient;
|
||
|
|
void main() {
|
||
|
|
vec3 n = normalize(v_normal);
|
||
|
|
float d0 = max(dot(n, normalize(u_light0)), 0.0);
|
||
|
|
float d1 = max(dot(n, normalize(u_light1)), 0.0) * 0.45;
|
||
|
|
vec3 color = u_color * (u_ambient + d0 * 0.78 + d1);
|
||
|
|
gl_FragColor = vec4(color, 1.0);
|
||
|
|
}
|
||
|
|
`)),n={program:t,aPosition:e.getAttribLocation(t,`a_position`),aNormal:e.getAttribLocation(t,`a_normal`),uMvp:da(e,t,`u_mvp`),uModel:da(e,t,`u_model`),uColor:da(e,t,`u_color`),uLight0:da(e,t,`u_light0`),uLight1:da(e,t,`u_light1`),uAmbient:da(e,t,`u_ambient`)};return this.program=n,n}ensureEdgeProgram(e){if(this.edgeProgram)return this.edgeProgram;let t=ua(e,la(e,e.VERTEX_SHADER,`
|
||
|
|
attribute vec3 a_position;
|
||
|
|
uniform mat4 u_mvp;
|
||
|
|
void main() {
|
||
|
|
gl_Position = u_mvp * vec4(a_position, 1.0);
|
||
|
|
}
|
||
|
|
`),la(e,e.FRAGMENT_SHADER,`
|
||
|
|
precision mediump float;
|
||
|
|
uniform vec3 u_color;
|
||
|
|
void main() {
|
||
|
|
gl_FragColor = vec4(u_color, 0.9);
|
||
|
|
}
|
||
|
|
`));return this.edgeProgram={program:t,aPosition:e.getAttribLocation(t,`a_position`),uMvp:da(e,t,`u_mvp`),uColor:da(e,t,`u_color`)},this.edgeProgram}evictScenes(e,t,n){let r=Array.from(this.cache.values()).reduce((e,t)=>e+t.bytes,0);for(;this.cache.size>Math.max(1,t)||r>n;){let t=this.cache.entries().next().value;if(!t)break;this.cache.delete(t[0]),aa(e,t[1]),r-=t[1].bytes}}ensureScene(e,t){let n=this.cache.get(t);if(n)return n;let r=[],i=0,a=this.ensureProgram(e),o=typeof e.createVertexArray==`function`;for(let n of t.model.meshes){let t=oa(e,e.ARRAY_BUFFER,n.positions),s=n.normals??new Float32Array(n.positions.length),c={mesh:n,pos:t,normal:oa(e,e.ARRAY_BUFFER,s),index:oa(e,e.ELEMENT_ARRAY_BUFFER,n.indices),edgeIndex:n.edgeIndices?oa(e,e.ELEMENT_ARRAY_BUFFER,n.edgeIndices):void 0,indexType:n.indices instanceof Uint32Array?e.UNSIGNED_INT:e.UNSIGNED_SHORT,edgeIndexType:n.edgeIndices instanceof Uint32Array?e.UNSIGNED_INT:e.UNSIGNED_SHORT,indexCount:n.indices.length,edgeIndexCount:n.edgeIndices?.length,bytes:n.positions.byteLength+s.byteLength+n.indices.byteLength+(n.edgeIndices?.byteLength??0)};if((n.indices instanceof Uint32Array||n.edgeIndices instanceof Uint32Array)&&!va(e)&&!e.getExtension(`OES_element_index_uint`))throw Error(`This WebGL implementation does not support 32-bit element indices.`);if(o){let t=e,n=t.createVertexArray();t.bindVertexArray(n),sa(e,a,c),t.bindVertexArray(null),c.vao=n}r.push(c),i+=c.bytes}let s={page:t,meshes:r,bytes:i};return this.cache.set(t,s),s}};function aa(e,t){for(let n of t.meshes)e.deleteBuffer(n.pos),e.deleteBuffer(n.normal),e.deleteBuffer(n.index),n.edgeIndex&&e.deleteBuffer(n.edgeIndex),n.vao&&va(e)&&e.deleteVertexArray(n.vao)}function oa(e,t,n){let r=e.createBuffer();if(!r)throw Error(`Failed to create WebGL buffer.`);return e.bindBuffer(t,r),e.bufferData(t,n,e.STATIC_DRAW),r}function sa(e,t,n){e.bindBuffer(e.ARRAY_BUFFER,n.pos),e.enableVertexAttribArray(t.aPosition),e.vertexAttribPointer(t.aPosition,3,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,n.normal),e.enableVertexAttribArray(t.aNormal),e.vertexAttribPointer(t.aNormal,3,e.FLOAT,!1,0,0)}function ca(e){let t=e.getContext(`2d`);t&&(t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,e.width,e.height))}function la(e,t,n){let r=e.createShader(t);if(!r)throw Error(`Failed to create WebGL shader.`);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){let t=e.getShaderInfoLog(r)??`unknown shader error`;throw e.deleteShader(r),Error(t)}return r}function ua(e,t,n){let r=e.createProgram();if(!r)throw Error(`Failed to create WebGL program.`);if(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS)){let t=e.getProgramInfoLog(r)??`unknown program link error`;throw e.deleteProgram(r),Error(t)}return r}function da(e,t,n){let r=e.getUniformLocation(t,n);if(!r)throw Error(`Missing shader uniform ${n}.`);return r}function fa(e,t,n){let r=e.model.bounds,i=Math.max(1e-6,t.width/Math.max(1,t.height)),a=n.yaw??-.78,o=_a(n.pitch??.55,-1.45,1.45),s=Math.max(.05,Math.min(100,n.zoom??1)),c=Math.max(1e-4,r.radius),l=c*2.55/s,u=Math.cos(o),d=[Math.sin(a)*u,Math.sin(o),Math.cos(a)*u],f=r.center,p=[Math.cos(a),0,-Math.sin(a)],m=[p[1]*d[2]-p[2]*d[1],p[2]*d[0]-p[0]*d[2],p[0]*d[1]-p[1]*d[0]],h=c*2/Math.max(1,Math.min(t.width,t.height))/Math.max(.1,s),g=(n.panX??0)*h,_=(n.panY??0)*h,v=[f[0]-p[0]*g+m[0]*_,f[1]-p[1]*g+m[1]*_,f[2]-p[2]*g+m[2]*_],y=ha([v[0]+d[0]*l,v[1]+d[1]*l,v[2]+d[2]*l],v,[0,1,0]);return{mvp:ga(ma(Math.PI/4,i,Math.max(.001,l-c*2.2),l+c*3.2),y)}}function pa(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function ma(e,t,n,r){let i=1/Math.tan(e/2),a=1/(n-r);return new Float32Array([i/t,0,0,0,0,i,0,0,0,0,(r+n)*a,-1,0,0,2*r*n*a,0])}function ha(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=Math.hypot(r,i,a)||1;r/=o,i/=o,a/=o;let s=n[1]*a-n[2]*i,c=n[2]*r-n[0]*a,l=n[0]*i-n[1]*r;o=Math.hypot(s,c,l)||1,s/=o,c/=o,l/=o;let u=i*l-a*c,d=a*s-r*l,f=r*c-i*s;return new Float32Array([s,u,r,0,c,d,i,0,l,f,a,0,-(s*e[0]+c*e[1]+l*e[2]),-(u*e[0]+d*e[1]+f*e[2]),-(r*e[0]+i*e[1]+a*e[
|
||
|
|
`).replace(/\\~|\\ /g,` `).replace(/\\[A-Za-z][^;]*;/g,``).replace(/[{}]/g,``).replace(/\\[A-Za-z]/g,``).trim()}function co(e,t,n){return Math.min(n,Math.max(t,e))}var lo=class{constructor(e={}){U(this,`id`,`dxf`),U(this,`label`,`DXF / JavaScript parser`),U(this,`formats`,[`dxf`]),U(this,`defaults`),this.defaults=e}accepts(e,t){return Oa(e)===`dxf`||ka(e,t)===`dxf`}async load(e,t={}){({...this.defaults,...t});let n=performance.now(),r=await Ea(e),i=Co(r),a=[],o;try{o=await uo(i)}catch(e){a.push(`dxf-parser failed, using built-in fallback parser: ${e instanceof Error?e.message:String(e)}`),o=wo(i)}let s=fo(o,e.fileName??e.file?.name,a),c=performance.now()-n;return{document:s,raw:o,bytes:r.byteLength,elapsedMs:c,format:`dxf`,warnings:s.warnings}}};async function uo(e){let n=await t(()=>import(`./dist-BzZSLV34.js`),__vite__mapDeps([0,1,2,3]),import.meta.url),r=n.default??n.DxfParser;if(!r)throw Error(`dxf-parser did not expose a parser constructor.`);return new r().parseSync(e)}function fo(e,t,n=[]){let r=e&&typeof e==`object`?e:{},i=mo(r),a=ho(r),o=(Array.isArray(r.entities)?r.entities:[]).filter(e=>!!e&&typeof e==`object`).map(e=>po(e)),s=Ka({format:`dxf`,sourceName:t,header:r.header&&typeof r.header==`object`?r.header:{},layers:i,blocks:a,entities:o,metadata:{parser:`dxf-parser + cad-viewer normalizer`},warnings:n,raw:e});return o.length===0&&s.warnings.push(`DXF file did not expose any ENTITIES.`),s}function po(e){let t=String(e.type??e.entityType??`UNKNOWN`).toUpperCase(),n=Ja(e,t),r=G(e.colorIndex??e.colorNumber??e.aci),i=G(e.color);if(n.colorIndex=r??(i!==void 0&&Math.abs(i)<=257?i:void 0),n.trueColor=e.trueColor??e.true_color??e.colorRGB??e.trueColorValue??(i!==void 0&&Math.abs(i)>257?i:void 0),n.layer=K(e.layer??e.layerName)??`0`,n.isClosed=!!(e.shape??e.closed??e.isClosed)||(Number(e.flag??e.flags??0)&1)==1,t===`LINE`&&(n.startPoint=W(e.startPoint??{x:e.x1??e.x,y:e.y1??e.y,z:e.z1??e.z})??n.startPoint,n.endPoint=W(e.endPoint??{x:e.x2,y:e.y2,z:e.z2})??n.endPoint),(t===`TEXT`||t===`MTEXT`||t===`ATTRIB`||t===`ATTDEF`)&&(n.insertionPoint=W(e.startPoint??e.position??e.insertionPoint)??n.insertionPoint,n.text=K(e.text??e.string??e.value)??n.text,n.textHeight=G(e.textHeight??e.height)??n.textHeight,n.rotation=xo(e.rotation??e.angle)),(t===`ARC`||t===`ELLIPSE`)&&(n.startAngle=So(e.startAngle??e.start_angle),n.endAngle=So(e.endAngle??e.end_angle)),t===`INSERT`){n.blockName=K(e.name??e.blockName)??n.blockName,n.insertionPoint=W(e.position??e.insertionPoint??e.point)??n.insertionPoint;let t=G(e.xScale??e.scaleX??e.xscale),r=G(e.yScale??e.scaleY??e.yscale),i=G(e.zScale??e.scaleZ??e.zscale);(t!==void 0||r!==void 0||i!==void 0)&&(n.scale={x:t??1,y:r??t??1,z:i??1}),n.rotation=xo(e.rotation??e.angle)}if(t===`SPLINE`){let t=vo(e.controlPoints??e.control_points??e.points);t.length&&(n.controlPoints=t);let r=vo(e.fitPoints??e.fit_points);r.length&&(n.fitPoints=r)}return t===`HATCH`&&(n.loops=bo(e),n.fillColorIndex=n.colorIndex),(t===`SOLID`||t===`TRACE`||t===`3DFACE`)&&(n.vertices=yo(e),n.fillColorIndex=n.colorIndex),n}function mo(e){let t={},n=e.tables,r=_o(e.layers??n?.layer??n?.LAYER??n?.layers);for(let e of r){let n=e,r=K(n.name??n.layerName);r&&Za(t,{name:r,color:n.color??n.colorNumber??n.colorIndex,colorIndex:G(n.colorNumber??n.colorIndex??n.color),lineType:K(n.lineType??n.linetype),isVisible:Number(n.colorNumber??n.colorIndex??n.color??1)>=0,isFrozen:!!n.frozen,isLocked:!!n.locked,raw:n})}return t[0]||Za(t,{name:`0`,colorIndex:7,isVisible:!0}),t}function ho(e){let t={},n=e.blocks;if(!n||typeof n!=`object`)return t;if(Array.isArray(n))for(let e of n)go(t,e);else for(let[e,r]of Object.entries(n))go(t,r,e);return t}function go(e,t,n){if(!t||typeof t!=`object`)return;let r=t,i=K(r.name??r.blockName??n);if(!i)return;let a=(Array.isArray(r.entities)?r.entities:[]).filter(e=>!!e&&typeof e==`object`).map(e=>po(e));Qa(e,{name:i,basePoint:W(r.basePoint??r.position)??{x:0,y:0},entities:a,raw:r})}function _o(e){if(!e)return[];if(Array.isArray(e))return e;if(typeof e!=`object`)return[];let t=e;return Array.isArray(t.entries)?t.entries:Arr
|
||
|
|
`).replace(/\r/g,`
|
||
|
|
`).split(`
|
||
|
|
`),n=[];for(let e=0;e<t.length-1;e+=2){let r=Number(t[e]?.trim()),i=t[e+1]??``;Number.isFinite(r)&&n.push({code:r,value:i.trimEnd()})}let r=[],i={},a=``,o=[],s;for(let e=0;e<n.length;e++){let t=n[e];if(t.code===0&&t.value===`SECTION`){a=n[e+1]?.code===2?n[e+1].value.toUpperCase():``,e++;continue}if(t.code===0&&t.value===`ENDSEC`){c(),a=``;continue}a===`ENTITIES`&&(t.code===0?(c(),o=[t]):o.push(t))}return c(),{header:{},tables:{},entities:r,blocks:i};function c(){if(!o.length)return;let e=o[0]?.value.toUpperCase();if(e===`VERTEX`&&s){let e=Q(o,10,20,30);e&&(s.vertices??=[]).push({...e,bulge:Z(o,42)}),o=[];return}if(e===`SEQEND`){s&&r.push(s),s=void 0,o=[];return}if(s&&=(r.push(s),void 0),!e||e===`EOF`){o=[];return}let t=To(e,o);e===`POLYLINE`?s=t:r.push(t),o=[]}}function To(e,t){let n={type:e,handle:Eo(t,5),layer:Eo(t,8)??`0`,colorIndex:Z(t,62),trueColor:Z(t,420),lineType:Eo(t,6),lineweight:Z(t,370)};switch(e){case`LINE`:Object.assign(n,{startPoint:Q(t,10,20,30),endPoint:Q(t,11,21,31)});break;case`CIRCLE`:Object.assign(n,{center:Q(t,10,20,30),radius:Z(t,40)});break;case`ARC`:Object.assign(n,{center:Q(t,10,20,30),radius:Z(t,40),startAngle:Ao(Z(t,50)),endAngle:Ao(Z(t,51))});break;case`POINT`:Object.assign(n,{point:Q(t,10,20,30)});break;case`TEXT`:case`MTEXT`:Object.assign(n,{insertionPoint:Q(t,10,20,30),text:ko(t),textHeight:Z(t,40),rotation:Ao(Z(t,50))});break;case`LWPOLYLINE`:Object.assign(n,{vertices:Oo(t),flag:Z(t,70),isClosed:(Number(Z(t,70)??0)&1)==1});break;case`POLYLINE`:Object.assign(n,{vertices:[],flag:Z(t,70),isClosed:(Number(Z(t,70)??0)&1)==1});break;case`ELLIPSE`:Object.assign(n,{center:Q(t,10,20,30),majorAxisEndPoint:Q(t,11,21,31),axisRatio:Z(t,40),startAngle:Z(t,41),endAngle:Z(t,42)});break;case`SPLINE`:Object.assign(n,{controlPoints:Do(t,10,20,30),degree:Z(t,71),isClosed:(Number(Z(t,70)??0)&1)==1});break;case`INSERT`:Object.assign(n,{name:Eo(t,2),blockName:Eo(t,2),insertionPoint:Q(t,10,20,30),rotation:Ao(Z(t,50)),scale:{x:Z(t,41)??1,y:Z(t,42)??Z(t,41)??1,z:Z(t,43)??1}});break;case`SOLID`:case`TRACE`:case`3DFACE`:Object.assign(n,{vertices:[Q(t,10,20,30),Q(t,11,21,31),Q(t,12,22,32),Q(t,13,23,33)].filter(Boolean)});break}return po(n)}function Z(e,t){let n=e.find(e=>e.code===t)?.value,r=Number(n);return Number.isFinite(r)?r:void 0}function Eo(e,t){let n=e.find(e=>e.code===t)?.value;return n&&n.length>0?n:void 0}function Q(e,t,n,r){let i=Z(e,t),a=Z(e,n),o=Z(e,r);if(!(i===void 0||a===void 0))return o===void 0?{x:i,y:a}:{x:i,y:a,z:o}}function Do(e,t,n,r){let i=[];for(let a=0;a<e.length;a++){if(e[a].code!==t)continue;let o=Number(e[a].value),s=e.slice(a+1).find(e=>e.code===n),c=e.slice(a+1).find(e=>e.code===r),l=Number(s?.value),u=Number(c?.value);Number.isFinite(o)&&Number.isFinite(l)&&i.push(Number.isFinite(u)?{x:o,y:l,z:u}:{x:o,y:l})}return i}function Oo(e){let t=[];for(let n=0;n<e.length;n++){if(e[n].code!==10)continue;let r=Number(e[n].value),i,a;for(let t=n+1;t<e.length&&e[t].code!==10;t++)e[t].code===20&&(i=Number(e[t].value)),e[t].code===42&&(a=Number(e[t].value));Number.isFinite(r)&&Number.isFinite(i)&&t.push({x:r,y:i,bulge:Number.isFinite(a)?a:void 0})}return t}function ko(e){let t=e.filter(e=>e.code===1||e.code===3).map(e=>e.value);return t.length?t.join(``):void 0}function Ao(e){return typeof e==`number`&&Number.isFinite(e)?ro(e):void 0}var jo=class{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,t){let n=Oa(e);if(n===`dwf`||n===`dwfx`||n===`xps`)return!0;let r=ka(e,t);return r===`dwf`||r===`dwfx`||r===`xps`}async load(e,t={}){var n,r,i;let a={...this.defaults,...t},o=performance.now(),s=e.fileName??e.file?.name,c=await Ea(e),l=Ro(ka(e,c),Oa(e));(n=a.onProgress)==null||n.call(a,{phase:`parse`,format:l,message:`Opening DWF/DWFx with dwf-viewer…`,percent:48});let u=await yr(c,{fileName:s});(r=a.onProgress)==null||r.call(a,{phase:`normalize`,format:l,message:`Reading DWF pages, sheets and mod
|
||
|
|
attribute vec2 a_position;
|
||
|
|
attribute vec4 a_color;
|
||
|
|
uniform vec2 u_viewCenter;
|
||
|
|
uniform float u_scale;
|
||
|
|
uniform vec2 u_viewport;
|
||
|
|
uniform float u_pointSize;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
vec2 screen = vec2(
|
||
|
|
u_viewport.x * 0.5 + (a_position.x - u_viewCenter.x) * u_scale,
|
||
|
|
u_viewport.y * 0.5 - (a_position.y - u_viewCenter.y) * u_scale
|
||
|
|
);
|
||
|
|
vec2 clip = vec2(screen.x / u_viewport.x * 2.0 - 1.0, 1.0 - screen.y / u_viewport.y * 2.0);
|
||
|
|
gl_Position = vec4(clip, 0.0, 1.0);
|
||
|
|
gl_PointSize = u_pointSize;
|
||
|
|
v_color = a_color;
|
||
|
|
}
|
||
|
|
`),n=Ls(e,e.FRAGMENT_SHADER,`
|
||
|
|
precision mediump float;
|
||
|
|
varying vec4 v_color;
|
||
|
|
void main() {
|
||
|
|
gl_FragColor = v_color;
|
||
|
|
}
|
||
|
|
`),r=e.createProgram();if(!r)throw Error(`Failed to create WebGL program.`);if(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS)){let t=e.getProgramInfoLog(r)??`Unknown WebGL program link error.`;throw e.deleteProgram(r),Error(t)}e.deleteShader(t),e.deleteShader(n);let i=e.getUniformLocation(r,`u_viewCenter`),a=e.getUniformLocation(r,`u_scale`),o=e.getUniformLocation(r,`u_viewport`),s=e.getUniformLocation(r,`u_pointSize`);if(!i||!a||!o||!s)throw Error(`Failed to resolve WebGL shader uniforms.`);return{program:r,aPosition:e.getAttribLocation(r,`a_position`),aColor:e.getAttribLocation(r,`a_color`),uViewCenter:i,uScale:a,uViewport:o,uPointSize:s}}function Ls(e,t,n){let r=e.createShader(t);if(!r)throw Error(`Failed to create WebGL shader.`);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){let t=e.getShaderInfoLog(r)??`Unknown WebGL shader compile error.`;throw e.deleteShader(r),Error(t)}return r}function Rs(e,t){let n=0,r=t=>t.map(t=>{let r=zs(e,t.positions),i=zs(e,t.colors),a=t.positions.byteLength+t.colors.byteLength;return n+=a,{positionBuffer:r,colorBuffer:i,vertexCount:t.positions.length/2,primitiveCount:t.primitiveCount,bounds:t.bounds,gpuBytes:a}}),i=r(t.lineBatches),a=r(t.triangleBatches),o=r(t.pointBatches);return{origin:t.origin,lineBatches:i,triangleBatches:a,pointBatches:o,textItems:t.textItems,imageItems:t.imageItems,stats:t.stats,primitiveCount:t.primitiveCount,gpuMemoryBytes:n,buildElapsedMs:t.buildElapsedMs}}function zs(e,t){let n=e.createBuffer();if(!n)throw Error(`Failed to create WebGL buffer.`);return e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),n}function Bs(e,t,n){let r=performance.now(),i=new Vs(e,t,n,eo(n)?{x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2}:{x:0,y:0});for(let t of e.entities)i.addEntityTracked(t,0);let a=i.finalize();return a.buildElapsedMs=performance.now()-r,a}var Vs=class{constructor(e,t,n,r){U(this,`lineBuckets`,new Map),U(this,`triangleBuckets`,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=t,this.bounds=n,this.origin=r;let i=eo(n)?Math.max(n.maxX-n.minX,n.maxY-n.minY,1e-9):1;this.tileSize=t.enableSpatialIndex?i/Math.max(8,t.spatialIndexCellCount):1/0,this.maxVerticesPerBatch=Math.max(4096,Math.floor(t.maxVerticesPerBatch))}addEntityTracked(e,t){this.stats.total++;let n=String(e.type??`UNKNOWN`).toUpperCase();this.stats.byType[n]=(this.stats.byType[n]??0)+1;let r=this.lookupLayer(e.layer);if(e.isVisible===!1||!os(r)){this.stats.skipped++;return}this.addEntity(e,n,t)}finalize(){let e=Ws(this.lineBuckets,this.maxVerticesPerBatch),t=Ws(this.triangleBuckets,this.maxVerticesPerBatch),n=Ws(this.pointBuckets,this.maxVerticesPerBatch);return this.stats.primitiveCount=this.primitiveCount,{origin:this.origin,lineBatches:e,triangleBatches:t,pointBatches:n,textItems:this.textItems,imageItems:this.imageItems,stats:this.stats,primitiveCount:this.primitiveCount,buildElapsedMs:0}}addEntity(e,t,n){switch(e.kind??qa(t)){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,n);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(t);default:this.stats.unsupported[t]=(this.stats.unsupported[t]??0)+1,this.stats.skipped++,this.opts.showUnsupportedMarkers&&this.addUnsupportedMarker(e)}}addLineEntity(e){if(
|