@nebula-spatial/viewer 0.2.1 → 0.2.3
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/CHANGELOG.md +10 -0
- package/dist/assets/geo-prepare.worker-vIEmqos1.js +1 -0
- package/dist/cad/types.d.ts +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5936 -5767
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
- package/dist/assets/geo-prepare.worker-ClQZBxyx.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this package are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.2.3
|
|
6
|
+
|
|
7
|
+
- Start rendering base CAD geometry before external block sidecars finish loading.
|
|
8
|
+
- Reuse the CAD geometry Worker and retained main buffer during incremental variant loading.
|
|
9
|
+
- Expose CAD session load timing through the public viewer CAD document model.
|
|
10
|
+
|
|
11
|
+
## 0.2.2
|
|
12
|
+
|
|
13
|
+
- Refreshed selected INSERT details and overlays when incremental CAD content expands their bounding boxes.
|
|
14
|
+
|
|
5
15
|
## 0.2.1
|
|
6
16
|
|
|
7
17
|
- Resolved the geometry preparation Worker from the published package instead of the site root.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Xr=Object.defineProperty;var Be=u=>{throw TypeError(u)};var Yr=(u,C,O)=>C in u?Xr(u,C,{enumerable:!0,configurable:!0,writable:!0,value:O}):u[C]=O;var et=(u,C,O)=>Yr(u,typeof C!="symbol"?C+"":C,O),zr=(u,C,O)=>C.has(u)||Be("Cannot "+O);var st=(u,C,O)=>(zr(u,C,"read from private field"),O?O.call(u):C.get(u)),$e=(u,C,O)=>C.has(u)?Be("Cannot add the same private member more than once"):C instanceof WeakSet?C.add(u):C.set(u,O);(function(){"use strict";var W;class u extends Error{constructor(n,r){super(r);et(this,"code");this.name="GeoLoaderError",this.code=n}}const C=4096;function O(t){return t>=6?"u16_lw":t>=5?"u8_lw":t>=4?"u16":"u8"}function Dt(t){return t==="u16_lw"?13:t==="u8_lw"?12:t==="u16"?9:8}function kt(t,e,n){return n==="u16"||n==="u16_lw"?t.getUint16(e+7,!0):t.getUint8(e+7)}function Oe(t){return t==="u16"||t==="u16_lw"?2:1}function Lt(t,e,n){if(!(n!=="u8_lw"&&n!=="u16_lw"))return t.getFloat32(e+7+Oe(n),!0)}function Ft(t,e,n,r,s=t.byteLength,o="u8"){if(n>s||s>t.byteLength)throw new u("E_GROUP_RANGE","Group byte range exceeds payload length");let i=n;const a=r*2,c=a*4;if(i+c>s)throw new u("E_GROUP_RANGE","Group position bytes exceed payload length");let l;if(a>0){const w=new Uint8Array(t,i,c),y=new Uint8Array(c),f=a;for(let x=0;x<a;x++)y[x*4]=w[x],y[x*4+1]=w[f+x],y[x*4+2]=w[f*2+x],y[x*4+3]=w[f*3+x];l=new Float32Array(y.buffer)}else l=new Float32Array(0);if(i+=c,i+4>s)throw new u("E_GROUP_RANGE","Missing seg_count field for group");const m=e.getUint32(i,!0);i+=4;const g=[];let d=0;const h=Dt(o);for(let w=0;w<m;w++){if(i+h>s)throw new u("E_GROUP_RANGE","Segment record exceeds payload length");const y=e.getUint32(i,!0),f=e.getUint8(i+4),x=e.getUint8(i+5),p=e.getUint8(i+6),E=kt(e,i,o),b=Lt(e,i,o);if(d+y>r)throw new u("E_SEGMENT_SUM","Segment vertex_count sum exceeds group count");g.push({startVertex:d,vertexCount:y,color:[f,x,p],layerIndex:E,...b===void 0?{}:{lineweightPx:b}}),i+=h;const T=d*2;if(y>1){let N=l[T],S=l[T+1];for(let G=1;G<y;G++){const U=T+G*2;N+=l[U],S+=l[U+1],l[U]=N,l[U+1]=S}}d+=y}if(d!==r)throw new u("E_SEGMENT_SUM",`Segment vertex_count sum ${d} does not match group count ${r}`);return{chunk:{pos:l,count:r,segments:g},offset:i}}function Me(t,e,n,r,s="u8"){const o=r*2,i=o*4;if(n+i>t.byteLength)throw new u("E_GROUP_RANGE","Group position bytes exceed payload length");const a=new Uint8Array(t,n,i);let c=n+i;if(c+4>t.byteLength)throw new u("E_GROUP_RANGE","Missing seg_count field for group");const l=e.getUint32(c,!0);c+=4;const m=[];let g=0;const d=Dt(s);for(let h=0;h<l;h++){if(c+d>t.byteLength)throw new u("E_GROUP_RANGE","Segment record exceeds payload length");const w=e.getUint32(c,!0),y=e.getUint8(c+4),f=e.getUint8(c+5),x=e.getUint8(c+6),p=kt(e,c,s),E=Lt(e,c,s);if(c+=d,g+w>r)throw new u("E_SEGMENT_SUM","Segment vertex_count sum exceeds group count");m.push({startVertex:g,vertexCount:w,color:[y,f,x],layerIndex:p,...E===void 0?{}:{lineweightPx:E}}),g+=w}if(g!==r)throw new u("E_SEGMENT_SUM",`Segment vertex_count sum ${g} does not match group count ${r}`);return{shuffled:a,plane:o,segments:m,offset:c}}function ve(t,e,n,r){if(r===0)return new Float32Array(0);const s=new Uint8Array(r*4);for(let o=0;o<r;o++)s[o*4]=t[n+o],s[o*4+1]=t[e+n+o],s[o*4+2]=t[e*2+n+o],s[o*4+3]=t[e*3+n+o];return new Float32Array(s.buffer)}function De(t,e,n,r,s){const o=ve(t.shuffled,t.plane,(e.startVertex+n)*2,r*2);let i=(s==null?void 0:s[0])??0,a=(s==null?void 0:s[1])??0;if(r>0){n===0?(i=o[0],a=o[1]):(i+=o[0],a+=o[1],o[0]=i,o[1]=a);for(let l=1;l<r;l++){const m=l*2;i+=o[m],a+=o[m+1],o[m]=i,o[m+1]=a}}const c=r>0?[{startVertex:0,vertexCount:r,color:[e.color[0],e.color[1],e.color[2]],layerIndex:e.layerIndex,...e.lineweightPx===void 0?{}:{lineweightPx:e.lineweightPx}}]:[];return{chunk:{pos:o,count:r,segments:c},lastPoint:r>0?[i,a]:s}}function*ke(t,e,n,r,s="u8"){const o=Me(t,e,n,r,s);if(r===0)return yield{pos:new Float32Array(0),count:0,segments:[]},o.offset;for(const i of o.segments){let a=null;for(let c=0;c<i.vertexCount;c+=C){const l=Math.min(C,i.vertexCount-c),m=De(o,i,c,l,a);a=m.lastPoint,yield m.chunk}}return o.offset}function Xt(){const t=globalThis.TextDecoder;if(!t)throw new u("E_HEADER_JSON","TextDecoder is required to parse CAD pack metadata");return new t}function it(t){return t?{minX:t.minX,minY:t.minY,maxX:t.maxX,maxY:t.maxY}:null}function _t(t){return!!t&&Number.isFinite(t.minX)&&Number.isFinite(t.minY)&&Number.isFinite(t.maxX)&&Number.isFinite(t.maxY)}function ct(t){return _t(t)?it(t):null}function Yt(t,e){const n=_t(t)?t:null,r=_t(e)?e:null;return n?r?{minX:Math.min(n.minX,r.minX),minY:Math.min(n.minY,r.minY),maxX:Math.max(n.maxX,r.maxX),maxY:Math.max(n.maxY,r.maxY)}:it(n):it(r)}function Le(t,e,n,r=0,s=1){if(e<=0||n<=0)return null;let o=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=!1;for(let m=0;m<e;m+=1){const g=m*n,d=t[g+r],h=t[g+s];!Number.isFinite(d)||!Number.isFinite(h)||(d<o&&(o=d),h<i&&(i=h),d>a&&(a=d),h>c&&(c=h),l=!0)}return l?{minX:o,minY:i,maxX:a,maxY:c}:null}function zt(t,e){const n=t.minX,r=t.minY,s=t.maxX,o=t.maxY,{matA:i,matB:a,matC:c,matD:l,tx:m,ty:g}=e;let d=i*n+c*r+m,h=a*n+l*r+g,w=d,y=h,f=d,x=h;return d=i*n+c*o+m,h=a*n+l*o+g,d<w&&(w=d),h<y&&(y=h),d>f&&(f=d),h>x&&(x=h),d=i*s+c*r+m,h=a*s+l*r+g,d<w&&(w=d),h<y&&(y=h),d>f&&(f=d),h>x&&(x=h),d=i*s+c*o+m,h=a*s+l*o+g,d<w&&(w=d),h<y&&(y=h),d>f&&(f=d),h>x&&(x=h),{minX:w,minY:y,maxX:f,maxY:x}}function Fe(t){return Math.hypot(t.maxX-t.minX,t.maxY-t.minY)}function Xe(t,e){const n=(t.minX+t.maxX)/2,r=(t.minY+t.maxY)/2,s=(e.minX+e.maxX)/2,o=(e.minY+e.maxY)/2;return Math.hypot(n-s,r-o)}const Ye={};function Ht(t){return typeof t=="object"&&t!==null}function ut(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function j(t){if(t.length===0)return"$";let e="";for(const n of t){if(typeof n=="number"){e+=`[${n}]`;continue}e+=e.length===0?n:`.${n}`}return e}function Kt(t,e,n,r){return new u("E_TEXT_ROUNDTRIP",`Text roundtrip mismatch at stage=${t} index=${e} path=${n}: ${r}`)}function xt(t,e,n){if(Object.is(t,e))return null;if(Array.isArray(t)){if(!Array.isArray(e))return{path:j(n),reason:`expected array but found ${typeof e}`};if(t.length!==e.length)return{path:j([...n,"length"]),reason:`array length ${t.length} !== ${e.length}`};for(let r=0;r<t.length;r+=1){const s=xt(t[r],e[r],[...n,r]);if(s)return s}return null}if(Ht(t)){if(!Ht(e)||Array.isArray(e))return{path:j(n),reason:`expected object but found ${Array.isArray(e)?"array":typeof e}`};const r=Object.keys(t),s=Object.keys(e);if(r.length!==s.length){const o=r.find(a=>!ut(e,a));if(o!==void 0)return{path:j([...n,o]),reason:"missing key on actual"};const i=s.find(a=>!ut(t,a));if(i!==void 0)return{path:j([...n,i]),reason:"extra key on actual"}}for(const o of r){if(!ut(e,o))return{path:j([...n,o]),reason:"missing key on actual"};const i=xt(t[o],e[o],[...n,o]);if(i)return i}for(const o of s)if(!ut(t,o))return{path:j([...n,o]),reason:"extra key on actual"};return null}return{path:j(n),reason:`expected ${String(t)} but found ${String(e)}`}}function ze(t,e){return xt(t,e,[])}function jt(t){if(t===!0||t==="1"||t==="true")return!0;if(t===!1||t==="0"||t==="false")return!1}function He(){var s,o;const t=globalThis.process,e=jt(((s=t==null?void 0:t.env)==null?void 0:s.DXF_STRICT_TEXT_ROUNDTRIP)??((o=t==null?void 0:t.env)==null?void 0:o.VITE_DXF_STRICT_TEXT_ROUNDTRIP));if(e!==void 0)return e;const n=Ye,r=jt(n==null?void 0:n.VITE_DXF_STRICT_TEXT_ROUNDTRIP);return r!==void 0?r:!1}function Ke(t,e,n){if(e.length!==n.length)throw Kt(t,Math.min(e.length,n.length),"$length",`text count ${e.length} !== ${n.length}`);for(let r=0;r<e.length;r+=1){const s=ze(e[r],n[r]);if(s)throw Kt(t,r,s.path,s.reason)}}Xt();function Wt(t,e){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new u("E_GROUP_RANGE",`${e} exceeds safe integer range`);return Number(t)}function qt(t,e,n,r){if(!Number.isInteger(t)||!Number.isInteger(e)||t<0||e<0||t+e>n)throw new u("E_GROUP_RANGE",`${r} exceeds payload length`)}function je(t){if(t.byteLength<4)return!1;const e=new Uint8Array(t,0,4);return e[0]===68&&e[1]===88&&e[2]===66&&e[3]===83}function We(t){if(t.byteLength<20)throw new u("E_HEADER","DXBS payload too small: missing container header");if(!je(t))throw new u("E_HEADER","DXBS payload missing magic");const e=new DataView(t),n=e.getUint16(4,!0),r=e.getUint16(6,!0),s=e.getUint16(8,!0),o=e.getUint16(10,!0),i=e.getUint16(12,!0),a=e.getUint16(14,!0),c=e.getUint32(16,!0);if(n!==3||r<3||r>6)throw new u("E_GROUP_RANGE",`Unsupported DXBS version: ${n}.${r}`);if(s!==0)throw new u("E_GROUP_RANGE",`Unsupported DXBS sidecar kind: ${s}`);if(a!==0)throw new u("E_GROUP_RANGE",`Invalid DXBS reserved field: ${a}`);if(o<24)throw new u("E_GROUP_RANGE",`Invalid DXBS directory entry size: ${o}`);if(c!==o*i)throw new u("E_GROUP_RANGE","DXBS directory byte size mismatch");const l=20;qt(l,c,t.byteLength,"DXBS section directory");const m=new Map;for(let g=0;g<i;g+=1){const d=l+g*o,h=e.getUint16(d,!0),w=e.getUint16(d+2,!0),y=e.getUint32(d+4,!0),f=Wt(e.getBigUint64(d+8,!0),"DXBS section offset"),x=Wt(e.getBigUint64(d+16,!0),"DXBS section length");if(w!==0)throw new u("E_GROUP_RANGE",`Unsupported DXBS section flags for type ${h}: ${w}`);if(y!==0)throw new u("E_GROUP_RANGE",`Invalid DXBS section reserved field for type ${h}: ${y}`);qt(f,x,t.byteLength,`DXBS section ${h}`),m.set(h,{type:h,flags:w,offset:f,length:x})}return{versionMajor:n,versionMinor:r,sections:m}}function qe(t,e,n){const r=t.sections.get(e);if(!r)throw new u("E_GROUP_RANGE",`Missing DXBS section ${n}`);return r}function Je(){return{pos:new Float32Array(0),count:0,segments:[]}}function Et(t){if(t.segments&&t.segments.length>0)return Qe(t.segments,t.count),t.segments;if(t.count<=0)return[];if(!t.col||!t.lay)throw new u("E_GROUP_RANGE","Geometry chunk is missing segment or expanded color/layer metadata");return Ze(t.col,t.lay,t.count)}function Jt(t){const e=[];for(const n of t){const r=e[e.length-1];if(r&&r.startVertex+r.vertexCount===n.startVertex&&r.layerIndex===n.layerIndex&&r.color[0]===n.color[0]&&r.color[1]===n.color[1]&&r.color[2]===n.color[2]&&r.lineweightPx===n.lineweightPx){e[e.length-1]={...r,vertexCount:r.vertexCount+n.vertexCount};continue}e.push({startVertex:n.startVertex,vertexCount:n.vertexCount,color:tn(n),layerIndex:n.layerIndex,...n.lineweightPx===void 0?{}:{lineweightPx:n.lineweightPx}})}return e}function Ze(t,e,n){if(t.length<n*3||e.length<n)throw new u("E_GROUP_RANGE","Expanded color/layer metadata is shorter than geometry count");const r=[];let s=0;for(;s<n;){const o=s*3,i=t[o]??0,a=t[o+1]??0,c=t[o+2]??0,l=e[s]??0;let m=s+1;for(;m<n;){const g=m*3;if(e[m]!==l||t[g]!==i||t[g+1]!==a||t[g+2]!==c)break;m+=1}r.push({startVertex:s,vertexCount:m-s,color:[i,a,c],layerIndex:l}),s=m}return r}function Qe(t,e){let n=0;for(const r of t){if(r.vertexCount<0||r.startVertex!==n)throw new u("E_SEGMENT_SUM","Geometry segments must be contiguous and non-negative");n+=r.vertexCount}if(n!==e)throw new u("E_SEGMENT_SUM",`Geometry segment vertex sum ${n} does not match count ${e}`)}function tn(t){return[t.color[0],t.color[1],t.color[2]]}const en=8e6,wt=Xt(),nn=["left","center","right"],rn=["top","middle","bottom","alphabetic"];function Zt(t,e,n){for(const r of t)n(r);for(const r of e)n(r)}function nt(t){return typeof t=="object"&&t!==null}function on(t){return Array.isArray(t)?"array":t===null?"null":typeof t}function sn(t){return!(!nt(t)||Array.isArray(t)||typeof t.t!="string"||typeof t.x!="number"||typeof t.y!="number"||typeof t.h!="number"||typeof t.r!="number"||!Array.isArray(t.c)||t.c.length!==3||!t.c.every(e=>typeof e=="number")||typeof t.li!="number"||t.ha!=="left"&&t.ha!=="center"&&t.ha!=="right"||t.va!=="top"&&t.va!=="middle"&&t.va!=="bottom"&&t.va!=="alphabetic"||typeof t.lh!="number"||t.w!==void 0&&typeof t.w!="number"||t.wf!==void 0&&typeof t.wf!="number"||t.iv!==void 0&&typeof t.iv!="number"||t.io!==void 0&&typeof t.io!="number"||t.mx!==void 0&&t.mx!==!0||t.my!==void 0&&t.my!==!0)}function an(t){return t.map((e,n)=>({index:n,name:e.name,color:[...e.color],lw_px:e.lw_px,visible:e.visible??!0}))}function Qt(t){const e=t.texts,n=Array.isArray(e)?e:[],r=n.filter(sn),s=He();if(s&&e!==void 0&&!Array.isArray(e))throw new u("E_TEXT_ROUNDTRIP",`Text roundtrip mismatch at stage=Boundary-2:header->stream index=0 path=$: expected array but found ${on(e)}`);return s&&Ke("Boundary-2:header->stream",n,r),{bounds:[...t.bounds],entityCount:Number(t.entity_count||0),lineCount:Number(t.line_count||0),fillCount:Number(t.fill_count||0),dotCount:Number(t.dot_count||0),textCount:r.length,layers:an(t.layers??[]),texts:r}}function cn(t){const e=t==null?void 0:t.maxExpandedInstanceVertices,n=typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):en;return{hiddenInstanceIds:t!=null&&t.hiddenInstanceIds?new Set(t.hiddenInstanceIds):new Set,keepTextsForHiddenInstances:(t==null?void 0:t.keepTextsForHiddenInstances)===!0,loadBlocks:(t==null?void 0:t.loadBlocks)!==!1,suppressExpandedInsertGeometry:(t==null?void 0:t.suppressExpandedInsertGeometry)===!0,maxExpandedInstanceVertices:n,expandedInstanceVertices:0,externalVariantBuffers:t==null?void 0:t.externalVariantBuffers,requiredExternalVariantIds:t==null?void 0:t.requiredExternalVariantIds,externalVariantDeltaOnly:(t==null?void 0:t.externalVariantDeltaOnly)===!0,deferExternalVariantGeometry:(t==null?void 0:t.deferExternalVariantGeometry)===!0}}function un(t){return t.loadBlocks&&!t.suppressExpandedInsertGeometry}function te(t,e){return un(e)&&!e.hiddenInstanceIds.has(t)}function ln(t,e,n){if(n<=0)return;const r=t.expandedInstanceVertices+n;if(r>t.maxExpandedInstanceVertices)throw new u("E_EXPANSION_BUDGET",`CPU-expanded ${e} instance vertices exceed budget: ${r}/${t.maxExpandedInstanceVertices}. Disable block loading or raise maxExpandedInstanceVertices.`);t.expandedInstanceVertices=r}function fn(t,e,n){return n.loadBlocks?n.hiddenInstanceIds.size===0||n.keepTextsForHiddenInstances?t:t.filter(r=>{if(!Number.isInteger(r.iv)||!Number.isInteger(r.io))return!0;const s=e.get(`${r.iv}:${r.io}`);return s===void 0||!n.hiddenInstanceIds.has(s)}):t.filter(r=>!Number.isInteger(r.iv)||!Number.isInteger(r.io))}function dn(t,e){const n=new Map;return t.forEach((r,s)=>{if(!Number.isInteger(r.iv)||!Number.isInteger(r.io))return;const o=e.get(`${r.iv}:${r.io}`);if(o===void 0)return;const i=n.get(o);i?i.push(s):n.set(o,[s])}),n}function mn(t,e,n,r,s,o,i){const a=e.map((c,l)=>({id:c.id,blockName:ee(c,l),line:n[l].line,fill:n[l].fill,dot:n[l].dot,texts:r.get(c.id)??[]}));return{layer0Index:t,variants:a,instances:s,textIndexesByInstanceId:dn(o,i),ownerInstanceIdByVariantOrdinal:i}}function hn(t){if(t.byteLength<4)throw new u("E_HEADER","Payload too small: missing header length");const e=new DataView(t),n=e.getUint32(0,!0),r=4,s=r+n;if(s>t.byteLength)throw new u("E_HEADER","Header length exceeds payload length");let o;try{o=JSON.parse(wt.decode(new Uint8Array(t,r,n)))}catch(i){throw new u("E_HEADER_JSON",`Invalid JSON header: ${i.message}`)}return{meta:o,header:Qt(o),dataOffset:s,view:e}}function ee(t,e){var o,i,a;const n=(o=t.name)==null?void 0:o.trim();if(n)return n;const r=(i=t.block_name)==null?void 0:i.trim();if(r)return r;const s=(a=t.blockName)==null?void 0:a.trim();return s||`block_${e}`}function gn(t){const e=Number(t.version??1),n=String(t.encoding??"").toLowerCase();if(e===2){const r=n?` ${n}`:"";throw new u("E_UNSUPPORTED_PACK_VERSION",`当前文件是 V2${r} pack,前端不再兼容解析;请升级到最新版本后再打开。`)}}function yn(t){const e=hn(t);return gn(e.meta),e}function _n(t){if(t.byteLength<4)return!1;const e=new Uint8Array(t,0,4);return e[0]===68&&e[1]===88&&e[2]===66&&e[3]===51}function ne(t,e){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new u("E_GROUP_RANGE",`${e} exceeds safe integer range`);return Number(t)}function at(t,e,n,r){if(!Number.isInteger(t)||!Number.isInteger(e)||t<0||e<0||t+e>n)throw new u("E_GROUP_RANGE",`${r} exceeds payload length`)}function xn(t){if(t.byteLength<20)throw new u("E_HEADER","V3 payload too small: missing container header");const e=new DataView(t),n=e.getUint16(4,!0),r=e.getUint16(6,!0),s=e.getUint32(8,!0),o=e.getUint16(12,!0),i=e.getUint16(14,!0),a=e.getUint32(16,!0);if(n!==3||r>6)throw new u("E_GROUP_RANGE",`Unsupported V3 version: ${n}.${r}`);if(s!==0)throw new u("E_GROUP_RANGE",`Unsupported V3 file flags: ${s}`);if(o<24)throw new u("E_GROUP_RANGE",`Invalid V3 directory entry size: ${o}`);if(a!==o*i)throw new u("E_GROUP_RANGE","V3 directory byte size mismatch");const c=20;at(c,a,t.byteLength,"V3 section directory");const l=new Map;for(let m=0;m<i;m+=1){const g=c+m*o,d=e.getUint16(g,!0),h=e.getUint16(g+2,!0),w=e.getUint32(g+4,!0),y=ne(e.getBigUint64(g+8,!0),"V3 section offset"),f=ne(e.getBigUint64(g+16,!0),"V3 section length");if(h!==0)throw new u("E_GROUP_RANGE",`Unsupported V3 section flags for type ${d}: ${h}`);if(w!==0)throw new u("E_GROUP_RANGE",`Invalid V3 section reserved field for type ${d}: ${w}`);at(y,f,t.byteLength,`V3 section ${d}`),l.set(d,{type:d,flags:h,offset:y,length:f})}return{versionMinor:r,sections:l}}function J(t,e,n){const r=t.get(e);if(!r)throw new u("E_GROUP_RANGE",`Missing V3 section ${n}`);return r}function pt(t,e){return t.get(e)??{type:e,flags:0,offset:0,length:0}}function En(t,e,n){try{return JSON.parse(wt.decode(new Uint8Array(t,e.offset,e.length)))}catch(r){throw new u("E_HEADER_JSON",`Invalid V3 ${n} JSON: ${r.message}`)}}function wn(t){const e=String(t.encoding??"").toLowerCase();return e==="nested_instanced_external"||e==="nested_instanced_external_annotations"}function pn(t){return String(t.encoding??"").toLowerCase()==="nested_instanced_external_annotations"}function bn(t,e,n){const r=t.features,s=r&&typeof r=="object"&&!Array.isArray(r)?{...r}:{};return e&&(s.has_external_variant_geometry=!0),n&&(s.has_external_annotations=!0),Object.keys(s).length?s:void 0}function k(t,e){if(!Number.isInteger(t)||Number(t)<0)throw new u("E_HEADER",`${e} must be a non-negative integer`);return Number(t)}function re(t,e){if(typeof t!="string"||!t.trim())throw new u("E_HEADER",`${e} must be a non-empty string`);return t}function oe(t,e){if(t==null)return null;if(!Array.isArray(t)||t.length!==4||t.some(n=>typeof n!="number"||!Number.isFinite(n)))throw new u("E_HEADER",`${e} must be null or [minX, minY, maxX, maxY]`);return[t[0],t[1],t[2],t[3]]}function bt(t,e){if(!nt(t)||Array.isArray(t))throw new u("E_HEADER",`${e} must be an object`);return{line_count:k(t.line_count,`${e}.line_count`),fill_count:k(t.fill_count,`${e}.fill_count`),dot_count:k(t.dot_count,`${e}.dot_count`),bbox:oe(t.bbox,`${e}.bbox`),own_bbox:oe(t.own_bbox,`${e}.own_bbox`)}}function An(t){return t?{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}:null}function In(t,e){const n=t.external_variants;if(!Array.isArray(n))throw new u("E_HEADER","V3 external SCENE_META.external_variants must be an array");if(n.length!==e)throw new u("E_GROUP_RANGE",`V3 external variant manifest count mismatch: manifest=${n.length}, table=${e}`);return n.map((r,s)=>{if(!nt(r)||Array.isArray(r))throw new u("E_HEADER",`V3 external_variants[${s}] must be an object`);const o=k(r.id,`V3 external_variants[${s}].id`);if(o!==s)throw new u("E_GROUP_RANGE",`V3 external_variants[${s}].id must equal ${s}, found ${o}`);const i=re(r.href,`V3 external_variants[${s}].href`),a=k(r.raw_size,`V3 external_variants[${s}].raw_size`);if("normal"in r||"annotation"in r){const c=bt(r.annotation,`V3 external_variants[${s}].annotation`);return{id:o,href:i,raw_size:a,normal:bt(r.normal,`V3 external_variants[${s}].normal`),annotation:{...c,text_count:k(nt(r.annotation)&&!Array.isArray(r.annotation)?r.annotation.text_count:void 0,`V3 external_variants[${s}].annotation.text_count`)}}}return{id:o,href:i,raw_size:a,line_count:k(r.line_count,`V3 external_variants[${s}].line_count`),fill_count:k(r.fill_count,`V3 external_variants[${s}].fill_count`),dot_count:k(r.dot_count,`V3 external_variants[${s}].dot_count`)}})}function Rn(t){const e=t.external_annotations;if(e==null)return null;if(!nt(e)||Array.isArray(e))throw new u("E_HEADER","V3 external_annotations must be an object");const n=e.scene;if(n==null)return{};if(!nt(n)||Array.isArray(n))throw new u("E_HEADER","V3 external_annotations.scene must be an object");const r=bt(n,"V3 external_annotations.scene");return{scene:{href:re(n.href,"V3 external_annotations.scene.href"),raw_size:k(n.raw_size,"V3 external_annotations.scene.raw_size"),...r,text_count:k(n.text_count,"V3 external_annotations.scene.text_count")}}}function lt(t,e,n,r){return at(e,n,t.byteLength,r),wt.decode(t.subarray(e,e+n))}function Vn(t,e,n){if(e.length%20!==0)throw new u("E_GROUP_RANGE","V3 LAYER_TABLE length must be a multiple of 20");const r=new DataView(t),s=[];for(let o=e.offset;o<e.offset+e.length;o+=20){const i=r.getUint32(o,!0),a=r.getUint32(o+4,!0);s.push({name:lt(n,i,a,"V3 layer name"),color:[r.getUint8(o+8),r.getUint8(o+9),r.getUint8(o+10)],visible:r.getUint8(o+11)!==0,lw_px:r.getFloat32(o+12,!0)})}return s}function ft(t,e,n,r,s,o){if(n+4>r)throw new u("E_GROUP_RANGE",`Missing ${s} vertex_count`);const i=e.getUint32(n,!0),a=n+4,c=Ft(t,e,a,i,r,o);if(c.offset>r)throw new u("E_GROUP_RANGE",`${s} exceeds section bounds`);return{chunk:c.chunk,offset:c.offset}}function se(t,e,n,r,s,o){const i=ft(t,e,n,r,s,o),a=n+4;return{chunk:i.chunk,snapshot:{count:i.chunk.count,raw:new Uint8Array(t,a,i.offset-a).slice(),groupLayerEncoding:o},offset:i.offset}}function dt(t="u8"){return{chunk:{pos:new Float32Array(0),col:new Uint8Array(0),lay:new Uint8Array(0),count:0},snapshot:{count:0,raw:new Uint8Array(0),groupLayerEncoding:t}}}function Nn(t="u8"){return{line:dt(t),fill:dt(t),dot:dt(t)}}function Gn(t,e,n){var r;return!!(e&&n&&t.deferExternalVariantGeometry&&!((r=t.externalVariantBuffers)!=null&&r.has(e.id)))}function At(t,e,n,r,s,o,i){if(s===0)return dt(i);at(r,s,n.length,o);const a=n.offset+r,c=a+s,l=se(t,e,a,c,o,i);if(l.offset!==c)throw new u("E_GROUP_RANGE",`${o} has trailing bytes`);return{chunk:l.chunk,snapshot:l.snapshot}}function ie(t,e,n){if([t.getUint32(e+8,!0),t.getUint32(e+12,!0),t.getUint32(e+16,!0),t.getUint32(e+20,!0),t.getUint32(e+24,!0),t.getUint32(e+28,!0)].some(s=>s!==0))throw new u("E_GROUP_RANGE",`V3 external variant ${n} must use zero inline geometry offsets`)}function rt(t,e,n,r,s,o){const i=se(t,e,n,t.byteLength,s,o);if(i.chunk.count!==r)throw new u("E_GROUP_RANGE",`${s} vertex_count mismatch: manifest=${r}, sidecar=${i.chunk.count}`);return i}function It(t){return"normal"in t?t.normal:t}function Un(t,e,n){const r=It(t),s=new DataView(e);let o=0;const i=rt(e,s,o,r.line_count,`V3 external variant ${t.id} line blob`,n);o=i.offset;const a=rt(e,s,o,r.fill_count,`V3 external variant ${t.id} fill blob`,n);o=a.offset;const c=rt(e,s,o,r.dot_count,`V3 external variant ${t.id} dot blob`,n);if(o=c.offset,o!==e.byteLength)throw new u("E_GROUP_RANGE",`V3 external variant ${t.id} sidecar has trailing bytes`);return{line:{chunk:i.chunk,snapshot:i.snapshot},fill:{chunk:a.chunk,snapshot:a.snapshot},dot:{chunk:c.chunk,snapshot:c.snapshot}}}function Cn(t,e){const n=We(e),r=qe(n,257,"BLOCK_NORMAL_GEOMETRY"),s=new DataView(e);let o=r.offset;const i=r.offset+r.length,a=O(n.versionMinor),c=rt(e,s,o,t.normal.line_count,`V3.3 external variant ${t.id} normal line blob`,a);o=c.offset;const l=rt(e,s,o,t.normal.fill_count,`V3.3 external variant ${t.id} normal fill blob`,a);o=l.offset;const m=rt(e,s,o,t.normal.dot_count,`V3.3 external variant ${t.id} normal dot blob`,a);if(o=m.offset,o!==i)throw new u("E_GROUP_RANGE",`V3.3 external variant ${t.id} normal geometry section has trailing bytes`);return{line:{chunk:c.chunk,snapshot:c.snapshot},fill:{chunk:l.chunk,snapshot:l.snapshot},dot:{chunk:m.chunk,snapshot:m.snapshot}}}function Sn(t,e,n="u8"){if(e.byteLength!==t.raw_size)throw new u("E_GROUP_RANGE",`V3 external variant ${t.id} raw_size mismatch: manifest=${t.raw_size}, sidecar=${e.byteLength}`);return"normal"in t?Cn(t,e):Un(t,e,n)}function Pn(t,e,n){const r=e==null?void 0:e.get(t.id);if(!r)throw new u("E_GROUP_RANGE",`Missing V3 external sidecar buffer for variant ${t.id}`);return Sn(t,r,n)}function Rt(t,e,n,r,s){if(r===0)return 0;if(at(n,r,e.length,s),r<4)throw new u("E_GROUP_RANGE",`Missing ${s} vertex_count`);return t.getUint32(e.offset+n,!0)}function Tn(t,e,n,r){const s=n.offset+n.length;let o=n.offset;const i=ft(t,e,o,s,"V3 BASE_GEOMETRY line",r);o=i.offset;const a=ft(t,e,o,s,"V3 BASE_GEOMETRY fill",r);o=a.offset;const c=ft(t,e,o,s,"V3 BASE_GEOMETRY dot",r);if(o=c.offset,o!==s)throw new u("E_GROUP_RANGE","V3 BASE_GEOMETRY has trailing bytes");return{line:i.chunk,fill:a.chunk,dot:c.chunk}}function Vt(t){return Le(t.pos,t.count,2)}function Bn(t,e,n){return Gt(Gt(Vt(t),Vt(e)),Vt(n))}function ae(t){return"normal"in t?An(t.normal.bbox??t.normal.own_bbox??null):null}function $n(t,e,n,r,s,o,i,a){if(n.length%60!==0)throw new u("E_GROUP_RANGE","V3 VARIANT_TABLE length must be a multiple of 60");const c=[],l=new Map,m=[],g=n.length/60;for(let d=0;d<g;d+=1){const h=n.offset+d*60,w=e.getUint32(h,!0),y=e.getUint32(h+4,!0),f=(o==null?void 0:o[d])??null,x=!f||!a.requiredExternalVariantIds||a.requiredExternalVariantIds.has(d),p=Gn(a,f,x),E=f?(ie(e,h,d),!x||p?Nn(i):Pn(f,a.externalVariantBuffers,i)):{line:At(t,e,r,e.getUint32(h+8,!0),e.getUint32(h+12,!0),`V3 variant ${d} line blob`,i),fill:At(t,e,r,e.getUint32(h+16,!0),e.getUint32(h+20,!0),`V3 variant ${d} fill blob`,i),dot:At(t,e,r,e.getUint32(h+24,!0),e.getUint32(h+28,!0),`V3 variant ${d} dot blob`,i)},b=f?It(f):null,T=(b==null?void 0:b.line_count)??E.line.chunk.count,N=(b==null?void 0:b.fill_count)??E.fill.chunk.count,S=(b==null?void 0:b.dot_count)??E.dot.chunk.count,G=f&&(!x||p)?ae(f):Bn(E.line.chunk,E.fill.chunk,E.dot.chunk),U={id:d,name:lt(s,w,y,`V3 variant ${d} name`),line_count:p?T:E.line.chunk.count,fill_count:p?N:E.fill.chunk.count,dot_count:p?S:E.dot.chunk.count,sourceLineCount:T,sourceFillCount:N,sourceDotCount:S,nestedStart:e.getUint32(h+32,!0),nestedCount:e.getUint32(h+36,!0),textStart:e.getUint32(h+40,!0),textCount:e.getUint32(h+44,!0),precisionOriginX:e.getFloat32(h+48,!0),precisionOriginY:e.getFloat32(h+52,!0),lineSnapshot:E.line.snapshot,fillSnapshot:E.fill.snapshot,dotSnapshot:E.dot.snapshot,bbox:G};c.push(U),l.set(d,{line:E.line.chunk,fill:E.fill.chunk,dot:E.dot.chunk}),m.push({line:E.line.snapshot,fill:E.fill.snapshot,dot:E.dot.snapshot})}return{variantsById:c,variants:l,snapshots:m}}function On(t,e,n,r,s){if(e.length%60!==0)throw new u("E_GROUP_RANGE","V3 VARIANT_TABLE length must be a multiple of 60");const o=[],i=e.length/60;for(let a=0;a<i;a+=1){const c=e.offset+a*60,l=t.getUint32(c,!0),m=t.getUint32(c+4,!0),g=(s==null?void 0:s[a])??null;g&&ie(t,c,a);const d=g?It(g):null,h=t.getFloat32(c+48,!0),w=t.getFloat32(c+52,!0);o.push({id:a,name:lt(r,l,m,`V3 variant ${a} name`),line_count:g?d.line_count:Rt(t,n,t.getUint32(c+8,!0),t.getUint32(c+12,!0),`V3 variant ${a} line blob`),fill_count:g?d.fill_count:Rt(t,n,t.getUint32(c+16,!0),t.getUint32(c+20,!0),`V3 variant ${a} fill blob`),dot_count:g?d.dot_count:Rt(t,n,t.getUint32(c+24,!0),t.getUint32(c+28,!0),`V3 variant ${a} dot blob`),nestedStart:t.getUint32(c+32,!0),nestedCount:t.getUint32(c+36,!0),textStart:t.getUint32(c+40,!0),textCount:t.getUint32(c+44,!0),precisionOriginX:h,precisionOriginY:w,bbox:g?ae(g):null})}return o}function mt(t,e,n){if(e.length%32!==0)throw new u("E_GROUP_RANGE",`${n} length must be a multiple of 32`);const r=new DataView(t),s=[];for(let o=e.offset;o<e.offset+e.length;o+=32){const i=r.getUint16(o+30,!0);Kn(i),s.push({variantId:r.getUint32(o,!0),matA:r.getFloat32(o+4,!0),matB:r.getFloat32(o+8,!0),matC:r.getFloat32(o+12,!0),matD:r.getFloat32(o+16,!0),tx:r.getFloat32(o+20,!0),ty:r.getFloat32(o+24,!0),insLayerIdx:r.getUint16(o+28,!0),flags:i})}return s}function Mn(t,e,n){const r=t.getUint32(e,!0),s=t.getUint32(e+4,!0),o=t.getUint8(e+42),i=t.getUint8(e+43),a=t.getFloat32(e+24,!0),c=t.getFloat32(e+28,!0);return{t:lt(n,r,s,"V3 text value"),x:t.getFloat32(e+8,!0),y:t.getFloat32(e+12,!0),h:t.getFloat32(e+16,!0),r:t.getFloat32(e+20,!0),c:[t.getUint8(e+36),t.getUint8(e+37),t.getUint8(e+38)],li:t.getUint16(e+40,!0),ha:nn[o&3]??"left",va:rn[o>>2&3]??"alphabetic",lh:t.getFloat32(e+32,!0),...a?{w:a}:{},...c!==1?{wf:c}:{},...i&1?{mx:!0}:{},...i&2?{my:!0}:{}}}function Nt(t,e,n,r){if(e.length%44!==0)throw new u("E_GROUP_RANGE",`${r} length must be a multiple of 44`);const s=[],o=new DataView(t);for(let i=e.offset;i<e.offset+e.length;i+=44)s.push(Mn(o,i,n));return s}function vn(t,e){if(t.length%44!==0)throw new u("E_GROUP_RANGE",`${e} length must be a multiple of 44`);return t.length/44}function Dn(t,e,n,r){return{instanceId:n,variantId:e.variantId,matA:t.matA*e.matA+t.matC*e.matB,matB:t.matB*e.matA+t.matD*e.matB,matC:t.matA*e.matC+t.matC*e.matD,matD:t.matB*e.matC+t.matD*e.matD,tx:t.matA*e.tx+t.matC*e.ty+t.tx,ty:t.matB*e.tx+t.matD*e.ty+t.ty,insLayerIdx:r}}function kn(t,e,n,r){var y;const s=((y=r[e.insLayerIdx])==null?void 0:y.visible)===!1,o=e.matA*t.x+e.matC*t.y+e.tx,i=e.matB*t.x+e.matD*t.y+e.ty,a=Math.hypot(e.matA,e.matB),c=Math.hypot(e.matC,e.matD),l=c>1e-12?c:a>1e-12?a:1,m=a>1e-12&&l>1e-12?a/l:1,g=Ln(t,e),{mx:d,my:h,...w}=t;return{...w,x:o,y:i,h:t.h*l,w:t.w===void 0?void 0:t.w*l,wf:(t.wf??1)*m,r:g.r,...g.mx?{mx:!0}:{},...g.my?{my:!0}:{},li:s||t.li===n?e.insLayerIdx:t.li}}function Ln(t,e){const n=t.r*Math.PI/180,r=Math.cos(n),s=Math.sin(n),o=t.mx?-1:1,i=t.my?-1:1,a=o*(e.matA*r+e.matC*s),c=o*(e.matB*r+e.matD*s),l=i*(e.matC*r-e.matA*s),m=i*(e.matD*r-e.matB*s),g=a*m-c*l,d=Math.atan2(c,a)*180/Math.PI;return g<0?{r:Math.atan2(-c,-a)*180/Math.PI,mx:!0}:{r:d}}function Fn(t,e){return t===e?e:t}function Xn(t,e,n){return t===n?e:t}function Yn(t,e){const n=new DataView(t),{versionMinor:r,sections:s}=xn(t),o=O(r),i=J(s,1,"SCENE_META"),a=J(s,2,"LAYER_TABLE"),c=J(s,3,"STRING_TABLE"),l=J(s,4,"BASE_GEOMETRY"),m=J(s,5,"VARIANT_TABLE"),g=J(s,6,"VARIANT_GEOMETRY"),d=J(s,7,"SCENE_INSTANCE_TABLE"),h=pt(s,8),w=pt(s,9),y=pt(s,10),f=En(t,i,"SCENE_META"),x=wn(f)?In(f,m.length/60):null,p=pn(f),E=p?Rn(f):null,b=bn(f,x,p),T=p?"nested_instanced_external_annotations":x?"nested_instanced_external":"nested_instanced",N=new Uint8Array(t,c.offset,c.length),S=Vn(t,a,N),G=Number(f.layer0_index??0),U=Qt({bounds:f.bounds??[0,0,0,0],entity_count:Number(f.entity_count??0),line_count:Number(f.base_line_count??0),fill_count:Number(f.base_fill_count??0),dot_count:Number(f.base_dot_count??0),layers:S,texts:[]});Hn(G,U.layers);const R=Tn(t,n,l,o);if(!e.loadBlocks){const _=On(n,m,g,N,x),A=mt(t,d,"V3 SCENE_INSTANCE_TABLE"),v=mt(t,h,"V3 NESTED_INSTANCE_TABLE"),P=Nt(t,w,N,"V3 SCENE_TEXT_TABLE"),B=vn(y,"V3 VARIANT_TEXT_TABLE");if(Number(f.variant_count??_.length)!==_.length)throw new u("E_GROUP_RANGE","V3 variant count mismatch");if(Number(f.scene_instance_count??A.length)!==A.length)throw new u("E_GROUP_RANGE","V3 scene instance count mismatch");if(Number(f.nested_instance_count??v.length)!==v.length)throw new u("E_GROUP_RANGE","V3 nested instance count mismatch");if(Number(f.scene_text_count??P.length)!==P.length)throw new u("E_GROUP_RANGE","V3 scene text count mismatch");if(Number(f.variant_text_count??B)!==B)throw new u("E_GROUP_RANGE","V3 variant text count mismatch");for(const I of _){if(I.nestedStart+I.nestedCount>v.length)throw new u("E_GROUP_RANGE",`V3 variant ${I.id} nested range exceeds table`);if(I.textStart+I.textCount>B)throw new u("E_GROUP_RANGE",`V3 variant ${I.id} text range exceeds table`)}return Zt(A,v,I=>{if(!_[I.variantId])throw new u("E_GROUP_RANGE",`Unknown V3 variantId ${I.variantId}`);de(I.insLayerIdx,S.length)}),{meta:{bounds:f.bounds??[0,0,0,0],entity_count:Number(f.entity_count??0),line_count:R.line.count,fill_count:R.fill.count,dot_count:R.dot.count,version:3,version_minor:r,encoding:T,...b?{features:b}:{},...x?{external_variants:[...x]}:{},...E?{external_annotations:E}:{},layer0_index:G,block_variants:_.map(I=>({id:I.id,name:I.name,line_count:I.line_count,fill_count:I.fill_count,dot_count:I.dot_count})),instance_count:A.length,layers:S,texts:P},header:{...U,lineCount:R.line.count,fillCount:R.fill.count,dotCount:R.dot.count,textCount:P.length,texts:P},decoded:{baseLine:R.line,baseFill:R.fill,baseDot:R.dot,variants:new Map,instances:[],instanceIdByVariantOrdinal:new Map}}}const{variantsById:V,variants:Y,snapshots:z}=$n(t,n,m,g,N,x,o,e),q=mt(t,d,"V3 SCENE_INSTANCE_TABLE"),M=mt(t,h,"V3 NESTED_INSTANCE_TABLE"),D=Nt(t,w,N,"V3 SCENE_TEXT_TABLE"),$=Nt(t,y,N,"V3 VARIANT_TEXT_TABLE");if(Number(f.variant_count??V.length)!==V.length)throw new u("E_GROUP_RANGE","V3 variant count mismatch");if(Number(f.scene_instance_count??q.length)!==q.length)throw new u("E_GROUP_RANGE","V3 scene instance count mismatch");if(Number(f.nested_instance_count??M.length)!==M.length)throw new u("E_GROUP_RANGE","V3 nested instance count mismatch");if(Number(f.scene_text_count??D.length)!==D.length)throw new u("E_GROUP_RANGE","V3 scene text count mismatch");if(Number(f.variant_text_count??$.length)!==$.length)throw new u("E_GROUP_RANGE","V3 variant text count mismatch");for(const _ of V){if(_.nestedStart+_.nestedCount>M.length)throw new u("E_GROUP_RANGE",`V3 variant ${_.id} nested range exceeds table`);if(_.textStart+_.textCount>$.length)throw new u("E_GROUP_RANGE",`V3 variant ${_.id} text range exceeds table`)}Zt(q,M,_=>{if(!V[_.variantId])throw new u("E_GROUP_RANGE",`Unknown V3 variantId ${_.variantId}`);de(_.insLayerIdx,S.length)});const Ie=new Map;for(const _ of V)Ie.set(_.id,$.slice(_.textStart,_.textStart+_.textCount));const ht=[],F=e.externalVariantDeltaOnly,Re=F?[]:[...D],Mt=new Map,gt=new Map,Ve=new Map,Or=(_,A)=>{Mt.set(_,Gt(Mt.get(_)??null,A))},Ne=(_,A,v,P,B,Z)=>{var Te;if(B>64)throw new u("E_GROUP_RANGE","V3 nested instance depth exceeds limit");if(Z.has(_))throw new u("E_GROUP_RANGE",`V3 nested variant cycle detected at ${_}`);const I=V[_];if(!I)throw new u("E_GROUP_RANGE",`Unknown V3 variantId ${_}`);Z.add(_);const Q=!e.requiredExternalVariantIds||e.requiredExternalVariantIds.has(_),K=F?((Te=e.requiredExternalVariantIds)==null?void 0:Te.has(_))===!0:Q;let X=!1;const Pe=!!(I.line_count||I.fill_count||I.dot_count),Dr=I.textCount>0;if(K&&(Pe||Dr)&&(ht.push({instanceId:A.instanceId,variantId:_,matA:A.matA,matB:A.matB,matC:A.matC,matD:A.matD,tx:A.tx,ty:A.ty,insLayerIdx:A.insLayerIdx}),Pe&&Or(A.instanceId,I.bbox?ce(I.bbox,A):null),X=!0),K){I.textCount>0&&(X=!0);for(let tt=0;tt<I.textCount;tt+=1){const ot=kn($[I.textStart+tt],A,G,U.layers);Re.push({...ot,iv:v,io:P})}}for(let tt=0;tt<I.nestedCount;tt+=1){const ot=M[I.nestedStart+tt],kr=Xn(ot.insLayerIdx,A.insLayerIdx,G),Lr=zn(ot,I,V[ot.variantId]),Fr=Dn(A,Lr,A.instanceId,kr);X=Ne(ot.variantId,Fr,v,P,B+1,Z)||X}return Z.delete(_),X},vt=new Map;q.forEach((_,A)=>{if(!V[_.variantId])throw new u("E_GROUP_RANGE",`Unknown V3 scene variantId ${_.variantId}`);const P=Ve.get(_.variantId)??0;Ve.set(_.variantId,P+1),gt.set(`${_.variantId}:${P}`,A);const B=Fn(_.insLayerIdx,G),Z={instanceId:A,variantId:_.variantId,matA:_.matA,matB:_.matB,matC:_.matC,matD:_.matD,tx:_.tx,ty:_.ty,insLayerIdx:B},I=Ne(_.variantId,Z,_.variantId,P,0,new Set);if(F&&!I)return;let Q=vt.get(B);Q||(Q=new Map,vt.set(B,Q));let K=Q.get(_.variantId);K||(K={count:0,bboxes:[],inserts:[]},Q.set(_.variantId,K)),K.count+=1;const X=Mt.get(A)??null;X&&K.bboxes.push(X),K.inserts.push({instanceId:A,variantId:_.variantId,label:`#${A+1} (${_.tx.toFixed(1)}, ${_.ty.toFixed(1)})`,tx:_.tx,ty:_.ty,canHighlight:X!==null,...X?{bbox:X}:{}})});const Ge=new Map;for(const[_,A]of vt){const v=[];for(const[P,B]of A)v.push({variantId:P,blockName:ee(V[P],P),instanceCount:B.count,bboxes:B.bboxes,inserts:B.inserts});v.sort((P,B)=>B.instanceCount-P.instanceCount),Ge.set(_,v)}let Ue=F?0:R.line.count,Ce=F?0:R.fill.count,Se=F?0:R.dot.count;for(const _ of ht){const A=V[_.variantId];e.deferExternalVariantGeometry&&A.lineSnapshot.count===0&&A.fillSnapshot.count===0&&A.dotSnapshot.count===0||!te(_.instanceId,e)||(Ue+=A.line_count,Ce+=A.fill_count,Se+=A.dot_count)}const yt=fn(Re,gt,e),Mr={bounds:f.bounds??[0,0,0,0],entity_count:F?0:Number(f.entity_count??0),line_count:R.line.count,fill_count:R.fill.count,dot_count:R.dot.count,version:3,version_minor:r,encoding:T,...b?{features:b}:{},...x?{external_variants:[...x]}:{},...E?{external_annotations:E}:{},layer0_index:G,block_variants:V.map(_=>({id:_.id,name:_.name,line_count:_.sourceLineCount,fill_count:_.sourceFillCount,dot_count:_.sourceDotCount})),instance_count:q.length,layers:S,texts:yt},vr={...U,entityCount:F?0:U.entityCount,lineCount:Ue,fillCount:Ce,dotCount:Se,textCount:yt.length,texts:yt,...e.loadBlocks?{layerBlockUsages:Ge,insertRuntime:mn(G,V,z,Ie,ht,yt,gt)}:{}};return{meta:Mr,header:vr,decoded:{baseLine:F?Ct():R.line,baseFill:F?Ct():R.fill,baseDot:F?Ct():R.dot,variants:Y,instances:ht,instanceIdByVariantOrdinal:gt}}}function Gt(t,e){return Yt(t,e)}function ce(t,e){return zt(t,e)}function ue(t){return Fe(t)}function le(t,e){return Xe(t,e)}function fe(t,e){return ce(t,{variantId:e.variantId,matA:e.matA,matB:e.matB,matC:e.matC,matD:e.matD,tx:e.tx,ty:e.ty,insLayerIdx:e.insLayerIdx})}function zn(t,e,n){if(!(n!=null&&n.bbox)||!e.bbox)return t;const r=e.precisionOriginX,s=e.precisionOriginY;if(!Number.isFinite(r)||!Number.isFinite(s)||r===0&&s===0)return t;const o={...t,tx:t.tx-r,ty:t.ty-s},i=fe(n.bbox,t),a=fe(n.bbox,o),c=Math.max(ue(e.bbox),ue(n.bbox),1),l=Math.hypot(r,s),m=Math.hypot(t.tx,t.ty),g=Math.hypot(o.tx,o.ty);if(l<=c*16||m<=c*16)return t;const d=le(e.bbox,i),h=le(e.bbox,a);return d>c*16&&h*4<d&&g*4<m?o:t}function de(t,e){if(t>=e)throw new u("E_GROUP_RANGE",`Instance layer index ${t} exceeds layer count ${e}`)}function Hn(t,e){if(!Number.isInteger(t)||t<0||t>=e.length)throw new u("E_GROUP_RANGE",`layer0_index out of range: ${t}`);if(e[t].name!=="0")throw new u("E_GROUP_RANGE",`layer0_index must reference layer "0": ${t}`)}function Kn(t){if(t!==0)throw new u("E_GROUP_RANGE",`Instance flags must be zero for Stage 1, found ${t}`)}function*jn(t,e,n,r,s){let o=n;const i=[{kind:"line",count:r.lineCount},{kind:"fill",count:r.fillCount},{kind:"dot",count:r.dotCount}];for(const a of i){const c=ke(t,e,o,a.count);for(;;){const l=c.next();if(l.done){o=l.value;break}yield{kind:a.kind,payload:l.value}}}if(o!==t.byteLength)throw new u("E_GROUP_RANGE",`Trailing bytes detected: offset=${o}, size=${t.byteLength}`);for(const a of r.texts)yield{kind:"text",payload:a}}function*Wn(t,e,n,r){yield*jn(t,e,n,r)}function*Ut(t,e,n,r,s,o,i,a){if(ln(a,t,Math.max(0,e-n.count)),e===0){yield{kind:t,payload:Je()};return}const c=C;let l=new Float32Array(c*2),m=[],g=0,d=0;const h=function*(){if(g<=0)return;const f=g===c?{pos:l,count:g,segments:Jt(m)}:{pos:l.slice(0,g*2),count:g,segments:Jt(m)};yield{kind:t,payload:f},d+=g,g=0,l=new Float32Array(c*2),m=[]},w=(f,x,p,E)=>{if(f<=0)return;const b=m[m.length-1];if(b&&b.startVertex+b.vertexCount===g&&b.layerIndex===p&&b.color[0]===x[0]&&b.color[1]===x[1]&&b.color[2]===x[2]&&b.lineweightPx===E){m[m.length-1]={...b,vertexCount:b.vertexCount+f};return}m.push({startVertex:g,vertexCount:f,color:[x[0],x[1],x[2]],layerIndex:p,...E===void 0?{}:{lineweightPx:E}})};yield*function*(){for(const f of Et(n)){let x=f.startVertex;const p=f.startVertex+f.vertexCount;for(;x<p;){const E=Math.min(c-g,p-x),b=x*2,T=g*2;l.set(n.pos.subarray(b,b+E*2),T),w(E,f.color,f.layerIndex,f.lineweightPx),x+=E,g+=E,g===c&&(yield*h())}}}();for(const f of s){if(!te(f.instanceId,a))continue;const x=r.get(f.variantId);if(!x)throw new u("E_GROUP_RANGE",`Unknown variantId ${f.variantId}`);const p=x[t],E=i[f.insLayerIdx].visible===!1;for(const b of Et(p)){const T=E||b.layerIndex===o?f.insLayerIdx:b.layerIndex;let N=b.startVertex;const S=b.startVertex+b.vertexCount;for(;N<S;){const G=Math.min(c-g,S-N);for(let U=0;U<G;U+=1){const R=(N+U)*2,V=(g+U)*2,Y=p.pos[R],z=p.pos[R+1];l[V]=f.matA*Y+f.matC*z+f.tx,l[V+1]=f.matB*Y+f.matD*z+f.ty}w(G,b.color,T,b.lineweightPx),N+=G,g+=G,g===c&&(yield*h())}}}if(yield*h(),d!==e)throw new u("E_GROUP_RANGE",`Expanded ${t} count mismatch: header=${e}, emitted=${d}`)}function*qn(t,e,n,r){yield*Ut("line",e.lineCount,t.baseLine,t.variants,t.instances,n.layer0_index,e.layers,r),yield*Ut("fill",e.fillCount,t.baseFill,t.variants,t.instances,n.layer0_index,e.layers,r),yield*Ut("dot",e.dotCount,t.baseDot,t.variants,t.instances,n.layer0_index,e.layers,r);for(const s of e.texts)yield{kind:"text",payload:s}}function Jn(t,e){const n=cn(e),r=Yn(t,n);return{header:r.header,chunks:qn(r.decoded,r.header,{layer0_index:r.meta.layer0_index??0},n)}}function Zn(t,e){if(_n(t))return Jn(t,e);const n=yn(t);return{header:n.header,chunks:Wn(t,n.view,n.dataOffset,n.header)}}function Ct(){return{pos:new Float32Array(0),col:new Uint8Array(0),lay:new Uint8Array(0),count:0}}function Qn(t,e){return t?ct(zt(t,e)):null}async function tr(t){const e=me(),n=t.fetchImpl??fetch,r=new Map(t.entries.map(l=>[l.id,l])),s=Array.from(new Set(t.requiredVariantIds)).sort((l,m)=>l-m),o=new Map,i=er(t.concurrency);let a=0;async function c(){var l;for(;a<s.length;){const m=s[a++],g=r.get(m);if(!g)throw new Error(`External block ${m} is missing from manifest`);const d=new URL(g.href,t.baseUrl).href,h=await n(d,{signal:t.signal});if(!h.ok){const y="status"in h?h.status:void 0,f="statusText"in h?h.statusText:void 0,x=[y,f].filter(p=>p!==void 0&&p!=="").join(" ");throw new Error(`External block ${m} fetch failed${x?`: ${x}`:""}`)}const w=await h.arrayBuffer();if(w.byteLength!==g.raw_size)throw new Error(`External block ${m} raw_size mismatch: manifest=${g.raw_size}, response=${w.byteLength}`);o.set(m,w),await((l=t.onBuffer)==null?void 0:l.call(t,m,w))}}return await Promise.all(Array.from({length:Math.min(i,s.length)},c)),{buffers:o,fetchMs:me()-e}}function er(t){const e=Math.floor(t??3);return Number.isFinite(e)?Math.max(1,Math.min(e,8)):3}function me(){var t,e;return((e=(t=globalThis.performance)==null?void 0:t.now)==null?void 0:e.call(t))??Date.now()}class nr{constructor(){$e(this,W,new Map)}get size(){return st(this,W).size}append(e){let n=0;for(const r of e){if(r.count<=0)continue;const s=Pt(r.layerIndex,r.lineweightPx);let o=st(this,W).get(s),i=r.pos,a=r.positionItemSize;const c=r.linePositionKind??null;o?o.positionItemSize!==a&&(ye(o),a!==3&&(i=ge(i,r.count,a)),o.positionItemSize=3,a=3,o.linePositionKind=null):(o={layerIndex:r.layerIndex,...r.lineweightPx===void 0?{}:{lineweightPx:r.lineweightPx},posParts:[],positionItemSize:a,colParts:[],colorRunParts:[],linePositionKind:c,count:0,bbox:null},st(this,W).set(s,o));const l=o.count>0;o.posParts.push(i),o.colParts.push(r.col);const m=lr(r.colorRuns??fr(r.col),o.count);o.colorRunParts.push(m),o.linePositionKind!==c&&(o.linePositionKind=null),o.positionItemSize===2&&o.linePositionKind===null&&ye(o),o.count+=r.count,o.bbox=l&&o.bbox===null?null:or(o.bbox,r.bbox),n+=r.count}return n}drain(){const e=[];for(const n of st(this,W).values()){if(n.count<=0)continue;const r=n.posParts.length===1?n.posParts[0]:cr(n.posParts,n.count*n.positionItemSize),s=n.colParts.length===1?n.colParts[0]:ur(n.colParts,n.count*3),o=_e(n.colorRunParts.flat()),i={layerIndex:n.layerIndex,pos:r,positionItemSize:n.positionItemSize,col:s,count:n.count,bbox:ct(n.bbox),colorRuns:o};n.lineweightPx!==void 0&&(i.lineweightPx=n.lineweightPx),n.linePositionKind&&(i.linePositionKind=n.linePositionKind),e.push(i)}return st(this,W).clear(),e}}W=new WeakMap;function St(){return new nr}function rr(){return{line:St(),fill:St(),dot:St()}}function or(t,e){const n=ct(e);return t?n?{minX:Math.min(t.minX,n.minX),minY:Math.min(t.minY,n.minY),maxX:Math.max(t.maxX,n.maxX),maxY:Math.max(t.maxY,n.maxY)}:null:n}function he(t,e={}){if(t.count<=0)return[];const n=Et(t),r=[],s=new Map,o=new Map,i=new Map,a=e.markLinePositionXy===!0||e.splitLineweight===!0;for(const y of n){if(y.vertexCount<=0)continue;const f=y.layerIndex,x=a?y.lineweightPx:void 0,p=Pt(f,x),E=s.get(p);E===void 0?(s.set(p,y.vertexCount),o.set(p,f),i.set(p,x),r.push(p)):s.set(p,E+y.vertexCount)}const c=new Map,l=new Map,m=new Map,g=new Set,d=e.markLinePositionXy===!0?"xy-zero-z":void 0,h=d?2:3;for(const y of r){const f=o.get(y),x=i.get(y),p=s.get(y)??0,E={layerIndex:f,...x===void 0?{}:{lineweightPx:x},pos:new Float32Array(p*h),positionItemSize:h,col:new Uint8Array(p*3),count:p,bbox:null,colorRuns:[]};d&&(E.linePositionKind=d),c.set(y,E),l.set(y,0),m.set(y,null)}for(const y of n){if(y.vertexCount<=0)continue;const f=y.layerIndex,x=a?y.lineweightPx:void 0,p=Pt(f,x),E=c.get(p),b=l.get(p),T=b,N=y.color[0],S=y.color[1],G=y.color[2];for(let U=0;U<y.vertexCount;U+=1){const R=y.startVertex+U,V=b+U,Y=V*h,z=V*3,q=R*2,M=t.pos[q],D=t.pos[q+1];E.pos[Y]=M,E.pos[Y+1]=D,h===3&&(E.pos[Y+2]=0),E.col[z]=N,E.col[z+1]=S,E.col[z+2]=G;const $=m.get(p);!Number.isFinite(M)||!Number.isFinite(D)?g.add(p):$?(M<$.minX&&($.minX=M),D<$.minY&&($.minY=D),M>$.maxX&&($.maxX=M),D>$.maxY&&($.maxY=D)):m.set(p,{minX:M,minY:D,maxX:M,maxY:D})}E.colorRuns.push({startVertex:T,vertexCount:y.vertexCount,color:[N,S,G]}),l.set(p,b+y.vertexCount)}const w=[];for(const y of r){const f=c.get(y);f&&(f.bbox=g.has(y)?null:ct(m.get(y)??null),f.colorRuns=_e(f.colorRuns??[]),w.push(f))}return w}function Pt(t,e){return e===void 0?`${t}:`:`${t}:${e}`}function sr(t,e){return t.append(e)}function ir(t){return t.drain()}function ar(t){const e=[],n=new Set;for(const r of t)xe(e,n,r.pos.buffer),xe(e,n,r.col.buffer);return e}function cr(t,e){const n=new Float32Array(e);let r=0;for(const s of t)n.set(s,r),r+=s.length;return n}function ge(t,e,n){if(n===3)return t;const r=new Float32Array(e*3);for(let s=0;s<e;s+=1){const o=s*2,i=s*3;r[i]=t[o]??0,r[i+1]=t[o+1]??0,r[i+2]=0}return r}function ye(t){if(t.positionItemSize===3)return;const e=t.positionItemSize;t.posParts=t.posParts.map(n=>ge(n,n.length/e,e)),t.positionItemSize=3,t.linePositionKind=null}function ur(t,e){const n=new Uint8Array(e);let r=0;for(const s of t)n.set(s,r),r+=s.length;return n}function lr(t,e){return t.map(n=>({startVertex:n.startVertex+e,vertexCount:n.vertexCount,color:[n.color[0],n.color[1],n.color[2]]}))}function _e(t){const e=[];for(const n of t){const r=e[e.length-1];if(r&&r.startVertex+r.vertexCount===n.startVertex&&r.color[0]===n.color[0]&&r.color[1]===n.color[1]&&r.color[2]===n.color[2]){e[e.length-1]={...r,vertexCount:r.vertexCount+n.vertexCount};continue}e.push({startVertex:n.startVertex,vertexCount:n.vertexCount,color:[n.color[0],n.color[1],n.color[2]]})}return e}function fr(t){const e=Math.floor(t.length/3),n=[];let r=0;for(;r<e;){const s=r*3,o=t[s]??0,i=t[s+1]??0,a=t[s+2]??0;let c=r+1;for(;c<e;){const l=c*3;if(t[l]!==o||t[l+1]!==i||t[l+2]!==a)break;c+=1}n.push({startVertex:r,vertexCount:c-r,color:[o,i,a]}),r=c}return n}function xe(t,e,n){n instanceof ArrayBuffer&&(e.has(n)||(e.add(n),t.push(n)))}function dr(t,e,n="u8"){if(e<=0&&t.byteLength===0)return{pos:new Float32Array(0),count:0,segments:[]};const{buffer:r,startOffset:s,endOffset:o}=yr(t),i=new DataView(r),a=Ft(r,i,s,e,o,n);if(a.offset!==o)throw new u("E_GROUP_RANGE",`Insert runtime geometry chunk has trailing bytes: offset=${a.offset-s}, length=${t.byteLength}`);return a.chunk}function mr(t){const e=n=>{const r=t[n],s=dr(r.raw,r.count,r.groupLayerEncoding),o=he(s,{splitLineweight:n==="line"}),i=new Map;for(const a of o)i.set(hr(a.layerIndex,a.lineweightPx),{layerIndex:a.layerIndex,...a.lineweightPx===void 0?{}:{lineweightPx:a.lineweightPx},pos:a.pos,col:a.col,count:a.count,bbox:it(a.bbox)});return i};return{line:e("line"),fill:e("fill"),dot:e("dot")}}function hr(t,e){return e===void 0?`${t}:`:`${t}:${e}`}function gr(t,e){let n=e?it(e):null;for(const r of["line","fill","dot"])for(const s of t[r].values())n=Yt(n,s.bbox);return n}function yr(t){if(t.buffer instanceof ArrayBuffer)return{buffer:t.buffer,startOffset:t.byteOffset,endOffset:t.byteOffset+t.byteLength};const e=Uint8Array.from(t);return{buffer:e.buffer,startOffset:e.byteOffset,endOffset:e.byteOffset+e.byteLength}}function _r(t){const e=t.insertRuntime;if(!e||e.instances.length===0)return null;const n=[],r=new Map,s=new Set;for(const c of e.variants){const l=mr(c),m=Tt(l.line),g=Tt(l.fill),d=Tt(l.dot),h=m.length>0||g.length>0||d.length>0;r.set(c.id,h?gr(l,null):null),h&&(s.add(c.id),n.push({variantId:c.id,line:m,fill:g,dot:d}))}const o=e.instances.filter(c=>s.has(c.variantId));if(o.length===0)return null;const i=wr(o,r),a=br(n,i);return{variants:n,instances:i,bytes:a,cost:i.count}}function xr(t){const e=[],n=new Set,r=s=>{n.has(s)||(n.add(s),e.push(s))};r(t.instances.meta.buffer),r(t.instances.mats.buffer),r(t.instances.bboxes.buffer);for(const s of t.variants)$t(s.line,r),$t(s.fill,r),$t(s.dot,r);return e}function Tt(t){const e=[];for(const n of t.values())n.count<=0||e.push(Er(n));return e}function Er(t){return{pos:t.pos,col:t.col,count:t.count,layerIndex:t.layerIndex,...t.lineweightPx===void 0?{}:{lineweightPx:t.lineweightPx},bbox:t.bbox}}function wr(t,e){const n=t.length,r=new Uint32Array(n*3),s=new Float32Array(n*6),o=new Float32Array(n*4);for(let i=0;i<n;i+=1){const a=t[i],c=i*3;r[c]=a.instanceId,r[c+1]=a.variantId,r[c+2]=a.insLayerIdx;const l=i*6;s[l]=a.matA,s[l+1]=a.matB,s[l+2]=a.matC,s[l+3]=a.matD,s[l+4]=a.tx,s[l+5]=a.ty;const m=Qn(e.get(a.variantId)??null,a);pr(o,i*4,m)}return{meta:r,mats:s,bboxes:o,count:n}}function pr(t,e,n){if(!n){t[e]=Number.POSITIVE_INFINITY,t[e+1]=Number.POSITIVE_INFINITY,t[e+2]=Number.NEGATIVE_INFINITY,t[e+3]=Number.NEGATIVE_INFINITY;return}t[e]=n.minX,t[e+1]=n.minY,t[e+2]=n.maxX,t[e+3]=n.maxY}function br(t,e){let n=e.meta.byteLength+e.mats.byteLength+e.bboxes.byteLength;for(const r of t)n+=Bt(r.line),n+=Bt(r.fill),n+=Bt(r.dot);return n}function Bt(t){return t.reduce((e,n)=>e+n.pos.byteLength+n.col.byteLength,0)}function $t(t,e){for(const n of t)e(n.pos.buffer),e(n.col.buffer)}function Ee(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}class Ar{constructor(){et(this,"geometryCredits",0);et(this,"textCredits",0);et(this,"cancelled",!1);et(this,"geometryWaiters",[]);et(this,"textWaiters",[])}grant(e){this.cancelled||(this.geometryCredits+=Math.max(0,e.geometryCredits),this.textCredits+=Math.max(0,e.textCredits),this.flushWaiters())}cancel(){if(!this.cancelled){this.cancelled=!0,this.geometryCredits=0,this.textCredits=0;for(const e of this.geometryWaiters.splice(0,this.geometryWaiters.length))e(!1);for(const e of this.textWaiters.splice(0,this.textWaiters.length))e(!1)}}take(e){return this.cancelled?Promise.resolve(!1):e==="geometry"&&this.geometryCredits>0?(this.geometryCredits-=1,Promise.resolve(!0)):e==="text"&&this.textCredits>0?(this.textCredits-=1,Promise.resolve(!0)):new Promise(n=>{this.getWaiters(e).push(n)})}flushWaiters(){this.flushKind("geometry"),this.flushKind("text")}flushKind(e){const n=this.getWaiters(e);for(;n.length>0&&this.getCredits(e)>0;){this.setCredits(e,this.getCredits(e)-1);const r=n.shift();r==null||r(!0)}}getCredits(e){return e==="geometry"?this.geometryCredits:this.textCredits}setCredits(e,n){if(e==="geometry"){this.geometryCredits=n;return}this.textCredits=n}getWaiters(e){return e==="geometry"?this.geometryWaiters:this.textWaiters}}const we=262144,Ir=Number.MAX_SAFE_INTEGER,pe=524288,Rr=Number.MAX_SAFE_INTEGER,Vr=5e6,Nr=64,H=self;let L=null,be=null;async function Ot(t,e,n){const r=ir(e);if(!r.length||!await n.take("geometry"))return 0;const o=r.reduce((a,c)=>a+c.count,0),i={type:"geometry",kind:t,layers:r,cost:o};return H.postMessage(i,ar(r)),o}async function Gr(t,e){return await Ot("line",t.line,e)+await Ot("fill",t.fill,e)+await Ot("dot",t.dot,e)}async function Ae(t,e){if(!t.length||!await e.take("text"))return 0;const r=t.slice();t.length=0;const s={type:"text",texts:r,cost:r.length};return H.postMessage(s),r.length}function Ur(t){return t.lineCount+t.fillCount+t.dotCount}function Cr(t,e){return Ur(t)>=Vr?{initial:pe,steady:e?pe:Rr}:{initial:we,steady:e?we:Ir}}function Sr(t){return t instanceof Error?t:new Error(String(t))}function Pr(t){if(!(!t||t.length===0))return new Map(t.map(e=>[e.variantId,e.buffer]))}function Tr(t){if(t!==void 0)return new Set(t)}async function Br(t,e,n){const r=Pr(e);if(!t||!n||n.length===0)return r;const s=Array.from(new Set(n)).filter(a=>!(r!=null&&r.has(a))).sort((a,c)=>a-c);if(s.length===0)return r;const o=await tr({baseUrl:t.baseUrl,entries:t.entries,requiredVariantIds:s}),i=new Map(r??[]);for(const[a,c]of o.buffers)i.set(a,c);return i}async function $r(t,e,n,r,s=!0,o,i,a,c,l,m,g,d){const h=rr(),w=[];let y=0,f=!1;const x=c===!0,p=typeof i=="number"&&Number.isFinite(i)&&i>=0,E=await Br(a,l,g),b=Tr(m),T=n&&n.length>0||r===!0||s===!1||o===!0||p||x||E||b!==void 0||d===!0?{...n&&n.length>0?{hiddenInstanceIds:new Set(n)}:{},...r===!0?{keepTextsForHiddenInstances:!0}:{},...s===!1?{loadBlocks:!1}:{},...o===!0?{suppressExpandedInsertGeometry:!0}:{},...p?{maxExpandedInstanceVertices:i}:{},...x?{deferExternalVariantGeometry:!0}:{},...E?{externalVariantBuffers:E}:{},...b!==void 0?{requiredExternalVariantIds:b}:{},...d===!0?{externalVariantDeltaOnly:!0}:{}}:void 0,N=Zn(t,T),S=Cr(N.header,d===!0);H.postMessage({type:"header",header:N.header});const G=async()=>{const V=await Gr(h,e);return y=0,V>0&&(f=!0),V};for(const V of N.chunks){if(V.kind==="text"){w.push(V.payload),w.length>=Nr&&await Ae(w,e);continue}const Y=he(V.payload,{markLinePositionXy:V.kind==="line"});y+=sr(h[V.kind],Y);const z=f?S.steady:S.initial;y>=z&&await G()}await G(),await Ae(w,e),H.postMessage({type:"done"});const U=Ee(),R=_r(N.header);R&&H.postMessage({type:"insertModel",variants:R.variants,instances:R.instances,cost:R.cost,bytes:R.bytes,planMs:Ee()-U},xr(R)),H.postMessage({type:"complete"})}self.addEventListener("message",t=>{const e=t.data;if(!e)return;if(e.type==="grant"){L==null||L.grant({geometryCredits:e.geometryCredits,textCredits:e.textCredits});return}if(e.type==="cancel"){L==null||L.cancel();return}if(e.type!=="parse")return;const n=new Ar;L=n;const r=e.useRetainedMainBuffer===!0;if(r&&e.buffer!==void 0){const o=new Error("Geo prepare worker parse request cannot include both a retained and transferred main buffer");o.code="E_MAIN_BUFFER_PROTOCOL",H.postMessage({type:"error",message:o.message,code:"E_MAIN_BUFFER_PROTOCOL"}),L=null;return}const s=r?be:e.buffer;if(!s){const o=new Error(r?"Geo prepare worker has no retained main buffer for this delta parse":"Geo prepare worker parse request is missing its main buffer");o.code="E_MAIN_BUFFER_MISSING",H.postMessage({type:"error",message:o.message,code:"E_MAIN_BUFFER_MISSING"}),L=null;return}r||(be=s),$r(s,n,e.hiddenInstanceIds,e.keepTextsForHiddenInstances,e.loadBlocks,e.suppressExpandedInsertGeometry,e.maxExpandedInstanceVertices,e.externalVariantFetchSource,e.deferExternalVariantGeometry,e.externalVariantBuffers,e.requiredExternalVariantIds,e.externalVariantGeometryFetchIds,e.externalVariantDeltaOnly).catch(o=>{const i=Sr(o),a=i.code;H.postMessage({type:"error",message:i.message,code:typeof a=="string"?a:void 0})}).finally(()=>{L===n&&(L=null)})})})();
|
package/dist/cad/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { RenderDebugBreakdownEntry, SplitBlockLayerDetail } from '@nebula-spatial/cad-loader';
|
|
2
|
+
import type { CadSessionLoadTiming } from '@nebula-spatial/cad-loader';
|
|
3
|
+
export type { CadSessionLoadTiming } from '@nebula-spatial/cad-loader';
|
|
2
4
|
export type CadSessionPhase = 'created' | 'header-ready' | 'initial-loading' | 'interactive' | 'failed' | 'disposed';
|
|
3
5
|
export interface CadWorldBounds {
|
|
4
6
|
readonly minX: number;
|
|
@@ -212,6 +214,9 @@ export interface CadViewerEventMap {
|
|
|
212
214
|
'hud-change': {
|
|
213
215
|
hud: CadHudModel;
|
|
214
216
|
};
|
|
217
|
+
'load-timing': {
|
|
218
|
+
timing: CadSessionLoadTiming;
|
|
219
|
+
};
|
|
215
220
|
}
|
|
216
221
|
export interface CadViewerCapability {
|
|
217
222
|
readonly document: CadDocumentHandle | null;
|
|
@@ -219,6 +224,7 @@ export interface CadViewerCapability {
|
|
|
219
224
|
readonly blocks: CadBlockModel;
|
|
220
225
|
readonly inspector: CadInspectorModel;
|
|
221
226
|
readonly hud: CadHudModel;
|
|
227
|
+
readonly loadTiming: CadSessionLoadTiming | null;
|
|
222
228
|
open(source: CadLoadSource, options?: CadOpenOptions): Promise<CadDocumentHandle>;
|
|
223
229
|
close(): void;
|
|
224
230
|
selectInsert?(insertId: string | null): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createViewer } from './viewer';
|
|
2
|
-
export type { CadBlockModel, CadDocumentHandle, CadFontResolver, CadResolvedTextFont, CadHudModel, CadInspectorModel, CadLayerModel, CadLoadSource, CadOpenOptions, CadTextDetails, CadTextSelection, CadTextSelectionId, CadViewerCapability, ResolveTextFont, CadViewerEventMap, CameraStateStore, Viewer, ViewerEventMap, ViewerEnvironment, ViewerFitViewOptions, ViewerHighlightOptions, ViewerOptions, ViewerPickOptions, ViewerPickResult, ViewerPointerEvent, ViewerUiOptions, ViewerUiParts, ViewerUiPreset, ViewerUiTheme, ViewerViewMode, } from './types';
|
|
2
|
+
export type { CadBlockModel, CadDocumentHandle, CadFontResolver, CadResolvedTextFont, CadHudModel, CadInspectorModel, CadLayerModel, CadLoadSource, CadOpenOptions, CadSessionLoadTiming, CadTextDetails, CadTextSelection, CadTextSelectionId, CadViewerCapability, ResolveTextFont, CadViewerEventMap, CameraStateStore, Viewer, ViewerEventMap, ViewerEnvironment, ViewerFitViewOptions, ViewerHighlightOptions, ViewerOptions, ViewerPickOptions, ViewerPickResult, ViewerPointerEvent, ViewerUiOptions, ViewerUiParts, ViewerUiPreset, ViewerUiTheme, ViewerViewMode, } from './types';
|