@liveroom-tech/react-immersive 6.1.1 → 6.1.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.
Files changed (43) hide show
  1. package/dist/{SequencesTab-LWGOVQ6Y.mjs → SequencesTab-66VBWTO5.mjs} +1 -1
  2. package/dist/binding-builder.css +1 -1
  3. package/dist/binding-builder.d.mts +3 -3
  4. package/dist/binding-builder.d.ts +3 -3
  5. package/dist/binding-builder.js +75 -27
  6. package/dist/binding-builder.mjs +1 -1
  7. package/dist/{chunk-KNCABWVN.mjs → chunk-4RYMXBK6.mjs} +2 -2
  8. package/dist/chunk-5P7ETEAN.mjs +50 -0
  9. package/dist/{chunk-EV6THDXD.mjs → chunk-6Q6YZ7O5.mjs} +1 -1
  10. package/dist/{chunk-MLT4JQAY.mjs → chunk-B75URXOE.mjs} +1 -1
  11. package/dist/chunk-EC542N4J.mjs +1 -0
  12. package/dist/{chunk-5PJ5MLKE.mjs → chunk-JK7GRGRG.mjs} +1 -1
  13. package/dist/{chunk-DEFZEXTA.mjs → chunk-LKKH4PO7.mjs} +1 -1
  14. package/dist/chunk-U3BQMOC3.mjs +83 -0
  15. package/dist/{chunk-Z2VQGUC2.mjs → chunk-VMYNX63T.mjs} +2 -2
  16. package/dist/hosted.css +1 -1
  17. package/dist/hosted.d.mts +3 -3
  18. package/dist/hosted.d.ts +3 -3
  19. package/dist/hosted.js +74 -26
  20. package/dist/hosted.mjs +1 -1
  21. package/dist/index.css +1 -1
  22. package/dist/index.d.mts +4 -4
  23. package/dist/index.d.ts +4 -4
  24. package/dist/index.js +72 -24
  25. package/dist/index.mjs +1 -1
  26. package/dist/{modelFileResolver-B8ADn9Nl.d.mts → modelFileResolver-B2B3F3d1.d.mts} +7 -0
  27. package/dist/{modelFileResolver-B8ADn9Nl.d.ts → modelFileResolver-B2B3F3d1.d.ts} +7 -0
  28. package/dist/{modelViewerProps-BE4D56Ti.d.ts → modelViewerProps-Bo48RDq6.d.ts} +4 -2
  29. package/dist/{modelViewerProps-DBwh-fmu.d.mts → modelViewerProps-DkvYb1GH.d.mts} +4 -2
  30. package/dist/{publicProps-3LNTAskZ.d.ts → publicProps-DJSccx3b.d.ts} +1 -1
  31. package/dist/{publicProps-Clr1nSE6.d.mts → publicProps-DN0-8tBm.d.mts} +1 -1
  32. package/dist/simple-model-viewer.d.mts +2 -2
  33. package/dist/simple-model-viewer.d.ts +2 -2
  34. package/dist/simple-model-viewer.js +1 -1
  35. package/dist/simple-model-viewer.mjs +1 -1
  36. package/dist/utils.d.mts +4 -4
  37. package/dist/utils.d.ts +4 -4
  38. package/dist/utils.js +50 -2
  39. package/dist/utils.mjs +1 -1
  40. package/package.json +1 -1
  41. package/dist/chunk-5FLX45O5.mjs +0 -2
  42. package/dist/chunk-644OGSQJ.mjs +0 -83
  43. package/dist/chunk-OPDRK3GS.mjs +0 -1
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- import{a as ce,b as se,c as pe}from"./chunk-F5QSXMME.mjs";import{$ as f,Aa as oe,Ba as ne,C as a,Ca as re,D as c,Da as ie,E as s,F as p,Ha as ae,Ja as ue,K as u,Ka as de,La as me,M as d,Ma as Se,N as m,Na as le,X as S,Z as l,aa as g,ba as C,ca as y,da as x,ea as P,fa as A,ga as H,ha as F,ia as K,ja as W,oa as z,pa as Q,sa as J,ta as Y,va as Z,za as te}from"./chunk-5FLX45O5.mjs";import{b as $,c as ee}from"./chunk-CCBFMNAU.mjs";import{a as e,b as t,e as o,f as n,g as r}from"./chunk-LX3GXQNU.mjs";import{b,c as E,d as h,e as j,f as R,g as T,h as V,i as I,j as L,k as w,l as D,m as _,n as N,o as q,p as k,q as v,r as U,s as G}from"./chunk-7JCFNZJM.mjs";import{b as O,c as B}from"./chunk-GV4ZRXL6.mjs";import{n as X}from"./chunk-EV6THDXD.mjs";import{a as i}from"./chunk-OPDRK3GS.mjs";import{c as M}from"./chunk-BNKTI3CY.mjs";import"./chunk-JR557W27.mjs";export{Y as ACTION_CATALOG,i as DEFAULT_MODEL_VIEWER_LABELS,c as DEFAULT_SCENE_CONFIG,a as DEFAULT_SECTION_CONFIG,de as MATERIAL_BLENDING_MODES,ue as MATERIAL_SIDES,H as MAX_VIEWER_STATE_BYTES,S as MEASUREMENT_UNITS,t as SEQUENCE_EASINGS,e as SEQUENCE_OBJECT_PROPERTIES,oe as applyIsolation,G as applyProductOptions,ee as applyStyleRules,ie as buildBindingsFromNodes,f as calibrateMeasurements,M as chooseMaterialVariant,me as collectObjectHierarchy,$ as colorScaleValue,ae as compareViewerConfigurations,Se as copyBindingStyle,z as createARHandoffUrl,re as createDefaultBinding,D as decodeProductSelections,j as defaultProductSelections,pe as defineObjectBindings,w as encodeProductSelections,R as evaluateProductConfiguration,J as exportConfiguredUSDZ,Z as findCatalogAction,I as formatProductPrice,_ as generateProductSkus,m as groundAsset,ne as inferType,X as inspectAsset,te as isolatedBindingKeys,E as material,C as measurementResult,l as measurementScale,g as measurementValue,P as measurementsToCsv,u as parseAssetTransform,y as parseMeasurements,U as parseProductConfiguration,h as parseProductDefinition,k as parseSceneProduct,s as parseSectionConfig,A as parseSelectionSets,o as parseSequences,K as parseViewerState,le as pasteBindingStyle,b as patchBindings,ce as patchSceneConfig,W as prepareViewerState,L as productCheckoutUrl,N as productDefinitionWarnings,q as productOptionStates,V as productPriceFromDefinition,Q as readARHandoffUrl,T as resolveProductSelections,n as sampleSequenceTrack,se as sceneLight,p as sectionSnapshot,O as selectBindingKeys,B as selectBindings,x as serializeMeasurements,v as serializeProductConfiguration,F as serializeViewerState,d as snapAssetToGrid,r as upsertSequenceKeyframe};
1
+ import{a as ce,b as se,c as pe}from"./chunk-F5QSXMME.mjs";import{Aa as Q,Fa as J,Ga as Y,Ia as Z,Ma as te,N as a,Na as oe,O as c,Oa as ne,P as s,Pa as re,Q as p,Qa as ie,Ua as ae,V as u,Wa as ue,X as d,Xa as de,Y as m,Ya as me,Za as Se,_a as le,ga as S,ia as l,ka as f,la as g,ma as C,na as y,oa as x,pa as P,qa as A,ra as H,sa as F,ta as K,ua as W,za as z}from"./chunk-5P7ETEAN.mjs";import{b as $,c as ee}from"./chunk-CCBFMNAU.mjs";import"./chunk-7OWHW66D.mjs";import{a as e,b as t,e as o,f as n,g as r}from"./chunk-LX3GXQNU.mjs";import{b,c as E,d as h,e as j,f as R,g as T,h as V,i as I,j as L,k as w,l as D,m as _,n as N,o as q,p as k,q as v,r as U,s as G}from"./chunk-7JCFNZJM.mjs";import{b as O,c as B}from"./chunk-GV4ZRXL6.mjs";import{E as X}from"./chunk-6Q6YZ7O5.mjs";import{a as i}from"./chunk-EC542N4J.mjs";import{c as M}from"./chunk-BNKTI3CY.mjs";import"./chunk-JR557W27.mjs";export{Y as ACTION_CATALOG,i as DEFAULT_MODEL_VIEWER_LABELS,c as DEFAULT_SCENE_CONFIG,a as DEFAULT_SECTION_CONFIG,de as MATERIAL_BLENDING_MODES,ue as MATERIAL_SIDES,H as MAX_VIEWER_STATE_BYTES,S as MEASUREMENT_UNITS,t as SEQUENCE_EASINGS,e as SEQUENCE_OBJECT_PROPERTIES,oe as applyIsolation,G as applyProductOptions,ee as applyStyleRules,ie as buildBindingsFromNodes,f as calibrateMeasurements,M as chooseMaterialVariant,me as collectObjectHierarchy,$ as colorScaleValue,ae as compareViewerConfigurations,Se as copyBindingStyle,z as createARHandoffUrl,re as createDefaultBinding,D as decodeProductSelections,j as defaultProductSelections,pe as defineObjectBindings,w as encodeProductSelections,R as evaluateProductConfiguration,J as exportConfiguredUSDZ,Z as findCatalogAction,I as formatProductPrice,_ as generateProductSkus,m as groundAsset,ne as inferType,X as inspectAsset,te as isolatedBindingKeys,E as material,C as measurementResult,l as measurementScale,g as measurementValue,P as measurementsToCsv,u as parseAssetTransform,y as parseMeasurements,U as parseProductConfiguration,h as parseProductDefinition,k as parseSceneProduct,s as parseSectionConfig,A as parseSelectionSets,o as parseSequences,K as parseViewerState,le as pasteBindingStyle,b as patchBindings,ce as patchSceneConfig,W as prepareViewerState,L as productCheckoutUrl,N as productDefinitionWarnings,q as productOptionStates,V as productPriceFromDefinition,Q as readARHandoffUrl,T as resolveProductSelections,n as sampleSequenceTrack,se as sceneLight,p as sectionSnapshot,O as selectBindingKeys,B as selectBindings,x as serializeMeasurements,v as serializeProductConfiguration,F as serializeViewerState,d as snapAssetToGrid,r as upsertSequenceKeyframe};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveroom-tech/react-immersive",
3
- "version": "6.1.1",
3
+ "version": "6.1.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -1,2 +0,0 @@
1
- import{e as Fe}from"./chunk-LX3GXQNU.mjs";import{p as He}from"./chunk-7JCFNZJM.mjs";import{b as ue}from"./chunk-GV4ZRXL6.mjs";import{a as de,e as Ge,h as We,p as Ke}from"./chunk-EV6THDXD.mjs";function Lt(e){let n=e.trim();return n?/\.(hdr|exr|jpg|jpeg|png|webp)(?:[?#].*)?$/i.test(n):!1}var Dt=["none","directional","point","spot","hemisphere"],_t=["pbr","matcap","uv-checker"],Ut=["apartment","city","dawn","forest","lobby","night","park","studio","sunset","warehouse"];var zt=["sporadic","constantMild","constantWild"],$t=["linear","radial","mirroredLinear"],Ft=["verySmall","small","medium","large","veryLarge","huge"];var Oe={enabled:!1,axis:"y",position:.5,flip:!1},Un={clips:[],autoplayClip:null},zn={autofocus:{enabled:!1,focusDistance:5,focusRange:5,focalLength:.02,bokehScale:6,target:[0,0,0],mouse:!0,debug:0,manual:!1,smoothTime:.25},toneMapping:{enabled:!1,mode:"aces",exposure:1,resolution:256,whitePoint:4,middleGrey:.6,minLuminance:.01,averageLuminance:1,adaptationRate:1},brightnessContrast:{enabled:!1,brightness:0,contrast:0},hueSaturation:{enabled:!1,hue:0,saturation:0},colorAverage:{enabled:!1},dotScreen:{enabled:!1,angle:Math.PI/2,scale:1},glitch:{enabled:!1,mode:"sporadic",delay:[1.5,3.5],duration:[.6,1],strength:[.3,1],chromaticAberrationOffset:[0,0],columns:.05,ratio:.85},ssao:{enabled:!1,samples:30,rings:4,intensity:8,radius:.25,bias:.025,luminanceInfluence:.6,fade:.01,minRadiusScale:.33,worldDistanceThreshold:20,worldDistanceFalloff:5,worldProximityThreshold:6,worldProximityFalloff:3},bloom:{enabled:!1,intensity:.3,luminanceThreshold:.9,luminanceSmoothing:.2,mipmapBlur:!0,radius:0,levels:8},godRays:{enabled:!1,sunPosition:[5,10,5],samples:60,density:.96,decay:.9,weight:.4,exposure:.6,clampMax:1,blur:!0,kernelSize:"small"},grid:{enabled:!1,scale:1,lineWidth:0},noise:{enabled:!1,opacity:1,premultiply:!1},depthOfField:{enabled:!1,focusDistance:5,focusRange:5,focalLength:.02,bokehScale:6},chromaticAberration:{enabled:!1,offsetX:.002,offsetY:.002,radialModulation:!1,modulationOffset:.15},lensflare:{enabled:!1,lensPosition:[-25,6,-60],smoothTime:.07,glareSize:.2,flareSize:.01,flareSpeed:.01,flareShape:.01,animated:!0,anamorphic:!1,colorGain:"#141414",haloScale:.5,secondaryGhosts:!0,aditionalStreaks:!0,ghostScale:0,opacity:1,starBurst:!1},vignette:{enabled:!1,offset:.3,darkness:.3,eskil:!1},smaa:{enabled:!1},sepia:{enabled:!1,intensity:0},scanline:{enabled:!1,density:1.25},pixelation:{enabled:!1,granularity:5},outline:{enabled:!1,selectionLayer:10,edgeStrength:2.5,pulseSpeed:0,visibleEdgeColor:"#ffffff",hiddenEdgeColor:"#22090a",kernelSize:"large",blur:!1,xRay:!0},selectiveBloom:{enabled:!1,selectionLayer:10,intensity:1,luminanceThreshold:.9,luminanceSmoothing:.025,kernelSize:"large",mipmapBlur:!0,inverted:!1,ignoreBackground:!1},ramp:{enabled:!1,rampType:"linear",rampStart:[.5,.5],rampEnd:[1,1],startColor:"#000000",endColor:"#ffffff",opacity:.5,rampBias:.5,rampGain:.5,rampMask:!1,rampInvert:!1}},Z={model:{rotation:[0,0,0],showAdvancedRotation:!1,renderer:"pbr",shading:"lit",autoRotate:!1,autoRotateSpeed:1},camera:{fieldOfView:50,showAdvancedSettings:!1},lighting:{ambient:{intensity:.25,color:"#ffffff"},lights:[{id:"light-hemi",type:"hemisphere",color:"#ffffff",intensity:.3,position:[0,1,0],attachedToCamera:!1,castShadow:!1,shadowBias:-5e-4,visible:!0},{id:"light-key",type:"directional",color:"#ffffff",intensity:2.5,position:[6,12,6],attachedToCamera:!1,castShadow:!0,shadowBias:-5e-4,visible:!0},{id:"light-fill",type:"directional",color:"#ffffff",intensity:0,position:[-6,8,-6],attachedToCamera:!1,castShadow:!1,shadowBias:-5e-4,visible:!0}]},shadows:{enabled:!0,mapSize:2048,bias:-5e-4,normalBias:.02,radius:3},environment:{source:"preset",preset:"apartment",customEnvironmentUrl:"",intensity:.25,rotation:0,shadowLight:{enabled:!1,intensity:2.5,bias:-5e-4}},wireframe:{enabled:!1,color:"#000000",opacity:1},background:{enabled:!1,type:"color",color:"#1c1c1d",imageUrl:""},groundShadows:{enabled:!1,mode:"shadowCatcher",intensity:.7,borderFade:1,height:0,size:10},postProcessing:zn,animations:Un,annotations:[]};function ee(e){let n=m=>{throw new Error(`Invalid section: ${m}`)},t=m=>m&&typeof m=="object"&&!Array.isArray(m)?m:n("expected an object"),r=m=>typeof m=="string"&&m.trim().length>0&&m.length<=200?m:n("expected a nonempty name or id (up to 200 characters)"),o=m=>typeof m=="number"&&Number.isFinite(m)&&m>=0&&m<=1?m:n("position must be between 0 and 1"),i=m=>!Array.isArray(m)||m.length!==3||!m.every(u=>typeof u=="number"&&Number.isFinite(u))||Math.hypot(...m)<1e-8?n("normal must be a finite, nonzero vector"):[...m],a=m=>{let u=t(m);return!["x","y","z"].includes(u.axis)||typeof u.enabled!="boolean"||typeof u.flip!="boolean"?n("invalid plane"):{enabled:u.enabled,axis:u.axis,position:o(u.position),flip:u.flip,...u.normal!==void 0?{normal:i(u.normal)}:{}}},s=m=>{let u=t(m),l=a(u);if(u.mode!==void 0){if(!["plane","planes","box"].includes(u.mode))return n("invalid mode");l.mode=u.mode}if(u.planes!==void 0){if(!Array.isArray(u.planes)||u.planes.length>6)return n("at most six planes are supported");let f=new Set;l.planes=u.planes.map(g=>{let y=t(g),p=r(y.id);return f.has(p)?n("duplicate plane id"):(f.add(p),{...a(y),id:p,name:r(y.name)})})}if(u.activePlaneId!==void 0&&(l.activePlaneId=r(u.activePlaneId)),u.invertBox!==void 0){if(typeof u.invertBox!="boolean")return n("invalid box inversion");l.invertBox=u.invertBox}if(u.box!==void 0){let f=t(u.box),g=b=>!Array.isArray(b)||b.length!==3?n("invalid box bounds"):b.map(o),y=g(f.min),p=g(f.max);if(y.some((b,h)=>b>=p[h]))return n("box minimum must be below its maximum on every axis");l.box={min:y,max:p}}return l},c=t(e),d=s(c);if(c.presets!==void 0){if(!Array.isArray(c.presets)||c.presets.length>32)return n("at most 32 presets are supported");let m=new Set;d.presets=c.presets.map(u=>{let l=t(u),f=r(l.id);return m.has(f)?n("duplicate preset id"):(m.add(f),{id:f,name:r(l.name),settings:s(l.settings)})})}return d}function Ht(e){let{presets:n,...t}=ee(e);return t}function Kt(e){try{return ee(e)}catch{return Oe}}function Yt(e,n){if(!n||typeof n!="object"||Array.isArray(n))throw new Error("Invalid section: expected an object");let t=["enabled","axis","position","flip"].every(r=>Object.prototype.hasOwnProperty.call(n,r));return ee(t?n:{...Oe,...e,...n})}import{Box3 as Ye,Matrix4 as fe,Quaternion as $n,Vector3 as me,Euler as Fn}from"three";var Zt={version:1,placements:{},gridSize:1};function je(e){return e.id??e.url}function ne(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Expected an asset transform object.");let n={};for(let t of["position","rotation","scale"]){let r=e[t];if(r!==void 0){if(!Array.isArray(r)||r.length!==3||!r.every(o=>typeof o=="number"&&Number.isFinite(o))||t==="scale"&&r.some(o=>o===0))throw new Error(`Invalid asset ${t}: expected three finite ${t==="scale"?"nonzero ":""}numbers.`);n[t]=[...r]}}return n}function Jt(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Invalid scene composition.");let n=e;if(n.version!==1||!Number.isFinite(n.gridSize)||n.gridSize<=0||!n.placements||typeof n.placements!="object"||Array.isArray(n.placements)||Object.keys(n.placements).length>256)throw new Error("Invalid scene composition version, grid size or placements (maximum 256).");let t={};for(let[r,o]of Object.entries(n.placements)){if(!r||["__proto__","constructor","prototype"].includes(r))throw new Error("Invalid asset instance ID.");let i=ne(o);if(o.label!==void 0&&(typeof o.label!="string"||o.label.length>512))throw new Error("Invalid asset label.");for(let a of["visible","deleted"])if(o[a]!==void 0&&typeof o[a]!="boolean")throw new Error(`Invalid asset ${a}.`);t[r]={...i,...o.label!==void 0?{label:o.label}:{},...o.visible!==void 0?{visible:o.visible}:{},...o.deleted!==void 0?{deleted:o.deleted}:{}}}return{version:1,gridSize:n.gridSize,placements:t}}function Qt(e,n){if(!Number.isFinite(n)||n<=0)throw new Error("Grid size must be positive.");let t=ne(e),[r,o,i]=t.position??[0,0,0];return{...t,position:[Math.round(r/n)*n,o,Math.round(i/n)*n]}}function er(e,n){let t=ne(e),r=t.position??[0,0,0],o=new fe().compose(new me(...r),new $n().setFromEuler(new Fn(...t.rotation??[0,0,0])),new me(...t.scale??[1,1,1])),i=new Ye(new me(...n.min),new me(...n.max)).applyMatrix4(o);if(!Number.isFinite(i.min.y))throw new Error("Cannot place an asset with empty bounds.");return{...t,position:[r[0],r[1]-i.min.y,r[2]]}}function nr(e){e.updateWorldMatrix(!0,!0);let n=new fe().copy(e.parent?.parent?.matrixWorld??new fe).invert(),t=new Ye;return e.traverse(r=>{let o=r;o.geometry&&(o.geometry.computeBoundingBox(),o.geometry.boundingBox&&t.union(o.geometry.boundingBox.clone().applyMatrix4(new fe().multiplyMatrices(n,o.matrixWorld))))}),t.isEmpty()||![...t.min.toArray(),...t.max.toArray()].every(Number.isFinite)?null:{min:t.min.toArray(),max:t.max.toArray()}}import{BufferGeometry as Gn,Float32BufferAttribute as Wn,Matrix4 as qe,Mesh as ve,ShapeUtils as Hn,Vector2 as Ze,Vector3 as I,Vector4 as Kn}from"three";function Je(e){if(e.length!==3)return null;let n=new I(...e[0]).sub(new I(...e[1])),t=new I(...e[2]).sub(new I(...e[1]));return n.lengthSq()===0||t.lengthSq()===0?null:Math.acos(Math.max(-1,Math.min(1,n.normalize().dot(t.normalize()))))*180/Math.PI}function Qe(e,n){if(!e.normal)return null;let t=new I(...e.normal);if(t.lengthSq()===0)return null;t.normalize();let r=new I(...n),o=r.clone().sub(new I(...e.position)).dot(t);return{distance:Math.abs(o),projection:r.addScaledVector(t,-o).toArray()}}function en(e){if(e.length<3)return{error:"Pick at least three points to finish the area."};let n=new I(...e[0]),t=e.map(p=>new I(...p).sub(n)),r=Math.max(...t.map(p=>p.length()));if(r===0)return{error:"Area points must be distinct."};let o=new I;for(let p=1;p<t.length-1;p+=1){let b=t[p].clone().cross(t[p+1]);b.lengthSq()>o.lengthSq()&&o.copy(b)}if(o.length()<=r*r*1e-10)return{error:"Area points must not lie on one straight line."};o.normalize();let i=Math.max(r*1e-5,Number.EPSILON*Math.max(...e.flat().map(Math.abs))*32);if(t.some(p=>Math.abs(p.dot(o))>i))return{error:"Area points must lie on one plane."};let a=t.find(p=>p.length()>r*1e-10).clone().normalize(),s=o.clone().cross(a).normalize(),c=t.map(p=>new Ze(p.dot(a),p.dot(s))),d=(p,b,h)=>(b.x-p.x)*(h.y-p.y)-(b.y-p.y)*(h.x-p.x),m=r*r*1e-10,u=(p,b,h)=>Math.abs(d(p,b,h))<=m&&h.x>=Math.min(p.x,b.x)-r*1e-10&&h.x<=Math.max(p.x,b.x)+r*1e-10&&h.y>=Math.min(p.y,b.y)-r*1e-10&&h.y<=Math.max(p.y,b.y)+r*1e-10;for(let p=0;p<c.length;p+=1){let b=c[p],h=c[(p+1)%c.length];if(b.distanceTo(h)<=r*1e-10)return{error:"Area points must be distinct."};for(let w=p+1;w<c.length;w+=1){if(w===p+1||p===0&&w===c.length-1)continue;let A=c[w],x=c[(w+1)%c.length],M=d(b,h,A),R=d(b,h,x),B=d(A,x,b),Q=d(A,x,h);if(M*R<0&&B*Q<0||u(b,h,A)||u(b,h,x)||u(A,x,b)||u(A,x,h))return{error:"Area edges must not cross or touch each other."}}}let l=0,f=0,g=0;for(let p=0;p<c.length;p+=1){let b=c[p],h=c[(p+1)%c.length],w=b.x*h.y-h.x*b.y;l+=w,f+=(b.x+h.x)*w,g+=(b.y+h.y)*w}if(Math.abs(l)<=m)return{error:"The polygon has no measurable area."};let y=n.clone().addScaledVector(a,f/(3*l)).addScaledVector(s,g/(3*l));return{area:Math.abs(l)/2,center:y.toArray(),triangles:Hn.triangulateShape(c,[])}}function Ie(e,n){if(e.length<2)return 0;let t=0;for(let r=1;r<e.length;r+=1)t+=new I(...e[r]).distanceTo(new I(...e[r-1]));return n&&(t+=new I(...e[e.length-1]).distanceTo(new I(...e[0]))),t}var Yn=1e-5;function Xn(e,n){let t=e.getAttribute("position"),r=e.getIndex(),o=t.count,i=Math.max(n,1e-9),a=(g,y,p)=>`${Math.round(g/i)}_${Math.round(y/i)}_${Math.round(p/i)}`,s=new Int32Array(o),c=[],d=new Map;for(let g=0;g<o;g+=1){let y=t.getX(g),p=t.getY(g),b=t.getZ(g),h=a(y,p,b),w=d.get(h);w===void 0&&(w=c.length,c.push(new I(y,p,b)),d.set(h,w)),s[g]=w}let m=c.map(()=>new Map),u=(g,y)=>{if(g===y)return;let p=c[g].distanceTo(c[y]);m[g].has(y)||m[g].set(y,p),m[y].has(g)||m[y].set(g,p)},l=(r?r.count:o)/3,f=g=>r?r.getX(g):g;for(let g=0;g<l;g+=1)u(s[f(g*3)],s[f(g*3+1)]),u(s[f(g*3+1)],s[f(g*3+2)]),u(s[f(g*3+2)],s[f(g*3)]);return{weldedId:s,weldedPosition:c,neighbors:m}}function qn(e,n,t){let r=new Map([[n,0]]),o=[n];for(let i=0;i<t&&o.length>0;i+=1){let a=[];for(let s of o){let c=r.get(s)??0;for(let[d,m]of e[s]??[])r.has(d)||(r.set(d,c+m),a.push(d))}o=a}return r}function Zn(e){let t=(Math.abs(e.y)<.9?new I(0,1,0):new I(1,0,0)).clone().cross(e).normalize(),r=e.clone().cross(t).normalize();return[t,r]}function Jn(e,n,t){let[r,o]=Zn(n),i=0,a=0,s=0;for(let y of t){let p=y.clone().sub(e),b=p.dot(r),h=p.dot(o);i+=b*b,a+=b*h,s+=h*h}let c=i+s,d=i*s-a*a,m=Math.sqrt(Math.max(0,c*c/4-d)),u=c/2+m,l=1,f=0;Math.abs(a)>1e-12?(l=u-s,f=a):s>i&&(l=0,f=1);let g=Math.hypot(l,f)||1;return r.clone().multiplyScalar(l/g).add(o.clone().multiplyScalar(f/g)).normalize()}function Qn(e,n,t,r){let o=e.getAttribute("position"),i=e.getIndex(),a=o.count,s=(i?i.count:a)/3,c=l=>i?i.getX(l):l,d=l=>new I(o.getX(l),o.getY(l),o.getZ(l)).applyMatrix4(n),m=l=>l.clone().sub(t).dot(r),u=[];for(let l=0;l<s;l+=1){let f=d(c(l*3)),g=d(c(l*3+1)),y=d(c(l*3+2)),p=m(f),b=m(g),h=m(y),w=[],A=(x,M,R,B)=>{M>0!=B>0&&w.push(x.clone().lerp(R,M/(M-B)))};A(f,p,g,b),A(g,b,y,h),A(y,h,f,p),w.length===2&&u.push([w[0],w[1]])}return u}function et(e,n){let t=Math.max(n,1e-9),r=l=>`${Math.round(l.x/t)}_${Math.round(l.y/t)}_${Math.round(l.z/t)}`,o=new Map,i=[],a=l=>{let f=r(l),g=o.get(f);return g===void 0&&(g=i.length,i.push(l),o.set(f,g)),g},s=[],c=l=>{for(;s.length<=l;)s.push(new Map)};for(let[l,f]of e){let g=a(l),y=a(f);g!==y&&(c(g),c(y),s[g].set(y,(s[g].get(y)??0)+1),s[y].set(g,(s[y].get(g)??0)+1))}let d=(l,f)=>l<f?`${l}_${f}`:`${f}_${l}`,m=new Set,u=[];for(let l=0;l<s.length;l+=1)for(let f of s[l]?.keys()??[]){if(m.has(d(l,f)))continue;let g=[l],y=l,p=f;m.add(d(y,p));let b=0;for(;p!==l&&p>=0&&b<s.length+4;){g.push(p);let h=[...s[p].keys()].filter(A=>A!==y),w;if(h.length<=1)w=h[0];else{let A=i[p].clone().sub(i[y]).normalize(),x=-1/0;for(let M of h){let R=i[M].clone().sub(i[p]).normalize(),B=A.dot(R);B>x&&(x=B,w=M)}}if(w===void 0){p=-1;break}m.add(d(p,w)),y=p,p=w,b+=1}p===l&&g.length>=3&&u.push(g.map(h=>i[h]))}return u}function Xe(e,n){let t=1/0;for(let r of e)t=Math.min(t,r.distanceTo(n));return t}function nt(e,n){let t=0,r=1/0;return e.forEach((o,i)=>{let a=o.distanceTo(n);a<r&&(r=a,t=i)}),[...e.slice(t),...e.slice(0,t)]}function nn(e,n,t,r,o){let i=Qn(e,n,r,o);if(i.length===0)return{error:"Couldn't trace a loop around this point."};let a=et(i,t*n.getMaxScaleOnAxis());if(a.length===0)return{error:"The surface here doesn't form a closed loop around this point (it may be near an open edge)."};let s=a[0],c=Xe(s,r);for(let m of a.slice(1)){let u=Xe(m,r);u<c&&(c=u,s=m)}let d=nt(s,r).map(m=>m.toArray());return{points:d,length:Ie(d,!0)}}function tn(e){if(!(e.object instanceof ve)||!e.face)return null;let n=e.object,t=n.geometry;if(n.isSkinnedMesh||n.morphTargetInfluences?.some(i=>i!==0)){let i=t.getAttribute("position"),a=new Wn(new Float32Array(i.count*3),3),s=new I;for(let c=0;c<i.count;c++)n.getVertexPosition(c,s),a.setXYZ(c,s.x,s.y,s.z);t=new Gn().setAttribute("position",a).setIndex(t.getIndex())}let r=n.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in n){let i=new qe;n.getMatrixAt(e.instanceId,i),r.multiply(i)}t.computeBoundingSphere();let o=t.boundingSphere&&t.boundingSphere.radius>0?t.boundingSphere.radius:1;return{face:e.face,geometry:t,matrix:r,weldTolerance:o*Yn}}function or(e,n=6){let t=tn(e);if(!t)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{face:r,geometry:o,matrix:i,weldTolerance:a}=t,s=rn(e);if(!s)return{error:"Pick a point on the mesh surface to trace a loop around it."};let c=s[1].clone().sub(s[0]).cross(s[2].clone().sub(s[0]));if(c.lengthSq()===0)return{error:"Couldn't determine the surface direction at this point."};c.normalize();let{weldedId:d,weldedPosition:m,neighbors:u}=Xn(o,a),l=o.getAttribute("position"),f=e.point.clone().applyMatrix4(i.clone().invert()),g=[r.a,r.b,r.c],y=g[0],p=1/0;for(let M of g){let B=new I(l.getX(M),l.getY(M),l.getZ(M)).distanceTo(f);B<p&&(p=B,y=M)}let b=d[y],h=m[b].clone().applyMatrix4(i),w=qn(u,b,n),A=[];for(let M of w.keys())A.push(m[M].clone().applyMatrix4(i));if(A.length<6)return{error:"Not enough surface detail near this point to trace a loop. Try a different spot."};let x=Jn(h,c,A);return nn(o,i,a,e.point.clone(),x)}function ir(e,n=new I(0,1,0)){let t=tn(e);if(!t)return{error:"Pick a point on the mesh surface to trace a loop around it."};let{geometry:r,matrix:o,weldTolerance:i}=t,a=n.clone().normalize();return a.lengthSq()===0?{error:"Couldn't determine a horizontal direction."}:nn(r,o,i,e.point.clone(),a)}function rn(e){if(!(e.object instanceof ve)||!e.face)return null;let n=e.object,t=n.matrixWorld.clone();if(e.instanceId!==void 0&&"getMatrixAt"in n){let r=new qe;n.getMatrixAt(e.instanceId,r),t.multiply(r)}return[e.face.a,e.face.b,e.face.c].map(r=>n.getVertexPosition(r,new I).applyMatrix4(t))}function sr(e){if(!(e.object instanceof ve))return!1;for(let t=e.object;t;t=t.parent)if(!t.visible||t.userData.riEditorGizmo||t.userData.riDecal)return!1;return(Array.isArray(e.object.material)?e.object.material:[e.object.material])[e.face?.materialIndex??0]?.visible!==!1}function ar(e,n,t,r,o,i=12){let a=rn(e),s=a?a[1].clone().sub(a[0]).cross(a[2].clone().sub(a[0])).normalize():null,c={position:e.point.toArray(),...s&&s.lengthSq()>0?{normal:s.toArray()}:{},...a?{faceVertices:a.map(l=>l.toArray())}:{}};if(!a||o==="none")return c;let d=l=>{let f=new Kn(l.x,l.y,l.z,1).applyMatrix4(n.matrixWorldInverse).applyMatrix4(n.projectionMatrix);return f.w<=0||f.z/f.w<-1||f.z/f.w>1?null:{screen:new Ze((f.x/f.w+1)*r.width/2,(1-f.y/f.w)*r.height/2),w:f.w}},m=a.map(d),u=i;if((o==="vertex"||o==="auto")&&(m.forEach((l,f)=>{let g=l?.screen.distanceTo(t)??1/0;g<=u&&(u=g,c.position=a[f].toArray(),c.snapped="vertex")}),c.snapped))return c;if(o==="edge"||o==="auto")for(let l=0;l<3;l+=1){let f=(l+1)%3,g=m[l],y=m[f];if(!g||!y)continue;let p=y.screen.clone().sub(g.screen);if(p.lengthSq()===0)continue;let b=Math.max(0,Math.min(1,t.clone().sub(g.screen).dot(p)/p.lengthSq())),h=g.screen.clone().addScaledVector(p,b).distanceTo(t);if(h<=u){u=h;let w=b*g.w/((1-b)*y.w+b*g.w);c.position=a[l].clone().lerp(a[f],w).toArray(),c.snapped="edge"}}return c}var tt=["m","cm","mm","in","ft"],Te={m:1,cm:.01,mm:.001,in:.0254,ft:.3048},rt=["distance","angle","area","pointToPlane","wrap","wrapHorizontal"];function Ee(e){return tt.includes(e)}function ot(e={},n="m"){let t=e.displayUnit??n,r=e.metersPerUnit??Te[e.sourceUnit??"m"];if(!Number.isFinite(r)||r<=0)throw new Error("Measurement scale must be a positive finite number.");return{displayUnit:t,metersPerUnit:r,factor:Ee(t)?r/Te[t]:1}}function dr(e){try{return new URL(e,typeof window<"u"?window.location?.href:void 0).href}catch{return e}}function ur(e,n,t,r={}){if(!Ee(t)||!Number.isFinite(e)||e<=0||!Number.isFinite(n)||n<=0)throw new Error("Calibration needs two distinct points and a positive known distance.");let o=n*Te[t]/e;if(!Number.isFinite(o)||o<=0)throw new Error("Calibration scale is outside the supported range.");return{...r,metersPerUnit:o}}function on(e,n){let t=n.map(r=>r.position);if(e==="angle"){let r=Je(t);return r===null?null:{value:r,dimension:0}}if(e==="area"){let r=en(t);return"error"in r?null:{value:r.area,dimension:2}}if(e==="pointToPlane"){let r=n.length===2?Qe(n[0],n[1].position):null;return r?{value:r.distance,dimension:1}:null}return n.length<(e==="distance"?2:3)?null:{value:Ie(t,e!=="distance"),dimension:1}}function it(e,n={},t="m",r=e.points,o=e.approximate?"approximate":"ready"){let i=on(e.tool,r),{factor:a,displayUnit:s}=ot(n,t),c=o==="ready"||o==="approximate",d=c&&i?i.value*a**i.dimension:null;return{id:e.id,status:c?i&&d!==null&&Number.isFinite(d)?o:"invalid":o,rawValue:c&&i&&Number.isFinite(i.value)?i.value:null,value:d!==null&&Number.isFinite(d)?d:null,unit:e.tool==="angle"?"\xB0":e.tool==="area"?`${s}\xB2`:s}}function te(e){function n(){throw new Error("Invalid measurements: expected settings and valid named measurements with finite points.")}let t=s=>!!s&&typeof s=="object"&&!Array.isArray(s),r=s=>Array.isArray(s)&&s.length===3&&s.every(c=>typeof c=="number"&&Number.isFinite(c));typeof e=="string"&&(e.length>5*1024*1024&&n(),e=JSON.parse(e)),(!t(e)||e.version!==void 0&&e.version!==1||!t(e.settings)||!Array.isArray(e.items)||e.items.length>256)&&n();let o={};for(let s of["sourceUnit","displayUnit"])e.settings[s]!==void 0&&(Ee(e.settings[s])||n(),o[s]=e.settings[s]);e.settings.metersPerUnit!==void 0&&((typeof e.settings.metersPerUnit!="number"||!Number.isFinite(e.settings.metersPerUnit)||e.settings.metersPerUnit<=0)&&n(),o.metersPerUnit=e.settings.metersPerUnit);let i=new Set,a=e.items.map(s=>{(!t(s)||typeof s.id!="string"||!s.id||i.has(s.id)||typeof s.name!="string"||!s.name.trim()||typeof s.modelId!="string"||!s.modelId||!rt.includes(s.tool)||!Array.isArray(s.points)||s.points.length>8192||typeof s.createdAt!="string"||!Number.isFinite(Date.parse(s.createdAt)))&&n(),i.add(s.id),s.tilesetUrl!==void 0&&s.tilesetUrl!==null&&typeof s.tilesetUrl!="string"&&n(),(s.visible!==void 0&&typeof s.visible!="boolean"||s.approximate!==void 0&&typeof s.approximate!="boolean")&&n();let c=new Set,d=s.points.map(u=>{if((!t(u)||typeof u.id!="number"||!Number.isFinite(u.id)||!r(u.position))&&n(),c.has(u.id)&&n(),c.add(u.id),u.normal!==void 0&&!r(u.normal)&&n(),u.faceVertices!==void 0&&(!Array.isArray(u.faceVertices)||u.faceVertices.length!==3||!u.faceVertices.every(r))&&n(),u.snapped!==void 0&&!["vertex","edge"].includes(u.snapped)&&n(),u.anchor!==void 0){let f=u.anchor;(!t(f)||typeof f.nodeId!="string"||!f.nodeId||!r(f.localPosition)||typeof f.geometrySignature!="string"||typeof f.poseSignature!="string")&&n(),f.localNormal!==void 0&&!r(f.localNormal)&&n(),f.localFaceVertices!==void 0&&(!Array.isArray(f.localFaceVertices)||f.localFaceVertices.length!==3||!f.localFaceVertices.every(r))&&n(),f.instanceId!==void 0&&(!Number.isInteger(f.instanceId)||f.instanceId<0)&&n()}let l=u.anchor;return{id:u.id,position:[...u.position],...u.normal?{normal:[...u.normal]}:{},...u.faceVertices?{faceVertices:u.faceVertices.map(f=>[...f])}:{},...u.snapped?{snapped:u.snapped}:{},...l?{anchor:{nodeId:l.nodeId,localPosition:[...l.localPosition],geometrySignature:l.geometrySignature,poseSignature:l.poseSignature,...l.localNormal?{localNormal:[...l.localNormal]}:{},...l.localFaceVertices?{localFaceVertices:l.localFaceVertices.map(f=>[...f])}:{},...l.instanceId!==void 0?{instanceId:l.instanceId}:{}}}:{}}}),m={id:s.id,name:s.name,modelId:s.modelId,tool:s.tool,points:d,createdAt:s.createdAt,...s.tilesetUrl!==void 0?{tilesetUrl:s.tilesetUrl}:{},...s.visible!==void 0?{visible:s.visible}:{},...s.approximate!==void 0?{approximate:s.approximate}:{}};return on(m.tool,d)||n(),m});return{settings:o,items:a}}function mr(e){return JSON.stringify({version:1,...te(e)},null,2)}function fr(e,n,t="m"){let r=te(e),o=new Map(n?.map(a=>[a.id,a])),i=a=>{let s=String(a??"");return/^[=+@-]/.test(s)&&(s=`'${s}`),`"${s.replace(/"/g,'""')}"`};return[["id","name","modelId","type","status","value","unit","createdAt"],...r.items.map(a=>{let s=o.get(a.id)??it(a,r.settings,t);return[a.id,a.name,a.modelId,a.tool,s.status,s.value,s.unit,a.createdAt]})].map(a=>a.map(i).join(",")).join(`\r
2
- `)}function sn(e){if(!Array.isArray(e)||e.length>128)throw new Error("Invalid selections: expected up to 128 named selection sets.");let n=new Set;return e.map(t=>{if(!t||typeof t!="object"||typeof t.id!="string"||!t.id||n.has(t.id)||typeof t.name!="string"||!t.name.trim()||t.name.length>200||!Array.isArray(t.objectIds)||t.objectIds.length>1e5||t.objectIds.some(r=>typeof r!="string"||!r))throw new Error("Invalid selections: each set needs a unique id, a name, and model object ids.");return n.add(t.id),{id:t.id,name:t.name.trim(),objectIds:[...new Set(t.objectIds)]}})}import{CanvasTexture as an,Color as cn,ImageLoader as st,NoColorSpace as pe,RepeatWrapping as ge,SRGBColorSpace as Pe,Texture as at}from"three";var H=new Map,Be={color:"#93c5fd",intensity:.07},hr=new cn(Be.color).multiplyScalar(Be.intensity),yr=new cn(Be.color),Sr=.28,J=new Map,Ne=new Map;function ct(e){return`${e.name}|${e.size}|${e.lastModified}`}function xr(e){let n=ct(e),t=e.name.lastIndexOf("."),r=t>0?e.name.slice(0,t):e.name,o=t>0?e.name.slice(t):"",i=`materials/${e.name}`,a=2;for(;;){let s=Ne.get(i);if(s===void 0||s===n)return Ne.set(i,n),i;i=`materials/${r}-${a}${o}`,a+=1}}function be(e){return J.get(e)}function ln(e,n){let t=++e.loadGeneration;e.loaded=!1,e.failed=!1;let r=()=>{if(e.loadGeneration!==t)return;e.loaded=!0;let o=e.pending;e.pending=[];for(let i of o)i()};new st().load(n,o=>{e.loadGeneration===t&&(e.texture.image=o,e.texture.needsUpdate=!0,r())},void 0,()=>{e.loadGeneration===t&&(e.failed=!0,console.warn(`Failed to load texture: ${n}`),r())})}function dn(e,n){for(let t of[Pe,pe]){let r=H.get(re(e,t));r&&ln(r,n)}}function wr(e,n){let t=J.get(e);t&&t!==n&&t.startsWith("blob:")&&URL.revokeObjectURL(t),J.set(e,n),dn(e,n)}function Ar(e){let n=J.get(e);n&&(n.startsWith("blob:")&&URL.revokeObjectURL(n),J.delete(e),Ne.delete(e),dn(e,e))}function re(e,n){return`${n}|${e}`}function lt(e,n=pe,t){let r=re(e,n),o=H.get(r);if(o)return t&&!o.loaded&&o.pending.push(t),o.texture;let i=J.get(e)??e,a={texture:new at,refCount:0,loaded:!1,pending:t?[t]:[],loadGeneration:0};return a.texture.flipY=!1,a.texture.colorSpace=n,H.set(r,a),ln(a,i),a.texture}function Mr(e,n=pe,t){let r=lt(e,n,t);return H.get(re(e,n)).refCount+=1,r}function Cr(e,n=pe){let t=H.get(re(e,n));t&&(t.refCount-=1,t.refCount<=0&&(t.loadGeneration+=1,t.pending=[],t.texture.dispose(),H.delete(re(e,n))))}function Or(e,n,t,r,o,i=1,a=0){let s=e.offsetTextures??(e.offsetTextures={}),c=s[n],d=c;if(!d||d.sourcePath!==r||d.base!==t){c?.texture.dispose();let u=t.clone();u.wrapS=ge,u.wrapT=ge,u.center.set(.5,.5),u.needsUpdate=!0,d={texture:u,sourcePath:r,base:t},s[n]=d}let m=i>0?i:1;return d.texture.offset.set(o[0],o[1]),d.texture.repeat.set(1/m,1/m),d.texture.rotation=a,d.texture}function jr(e,n){let t=e.offsetTextures,r=t?.[n];r&&(r.texture.dispose(),delete t[n])}function vr(e){let n=e.offsetTextures;if(n){for(let t of Object.values(n))t.texture.dispose();delete e.offsetTextures}}var ke=null;function Ir(){if(ke)return ke;let e=256,n=document.createElement("canvas");n.width=e,n.height=e;let t=n.getContext("2d"),r=t.createRadialGradient(e*.35,e*.35,e*.02,e*.5,e*.5,e*.55);r.addColorStop(0,"#ffffff"),r.addColorStop(.4,"#b5b5b5"),r.addColorStop(1,"#3a3a3a"),t.fillStyle=r,t.fillRect(0,0,e,e);let o=new an(n);return o.colorSpace=Pe,ke=o,o}var Re=null;function Tr(){if(Re)return Re;let e=1024,n=8,t=e/n,r=["#ef4444","#f59e0b","#22c55e","#6366f1"],o=document.createElement("canvas");o.width=e,o.height=e;let i=o.getContext("2d");i.textAlign="center",i.textBaseline="middle";for(let s=0;s<n;s+=1)for(let c=0;c<n;c+=1){let d=c*t,m=s*t,u=(Math.floor(c/2)+Math.floor(s/2))%4;i.fillStyle=r[u],i.fillRect(d,m,t,t),i.strokeStyle="rgba(0, 0, 0, 0.28)",i.lineWidth=2;for(let h=1;h<4;h+=1){let w=h*t/4;i.beginPath(),i.moveTo(d+w,m),i.lineTo(d+w,m+t),i.moveTo(d,m+w),i.lineTo(d+t,m+w),i.stroke()}i.strokeStyle="#09090b",i.lineWidth=7,i.strokeRect(d,m,t,t);let l=d+t*.23,f=m+t*.72,g=d+t*.72,y=m+t*.23;i.lineCap="round",i.lineJoin="round",i.beginPath(),i.moveTo(l,f),i.lineTo(g,y),i.lineTo(g-t*.2,y),i.moveTo(g,y),i.lineTo(g,y+t*.2),i.stroke();let p=s*n+c+1;i.font=`700 ${Math.round(t*.2)}px ui-monospace, SFMono-Regular, Menlo, monospace`,i.fillStyle="#ffffff",i.strokeStyle="rgba(0, 0, 0, 0.85)",i.lineWidth=6;let b=String(p).padStart(2,"0");i.strokeText(b,d+t/2,m+t*.82),i.fillText(b,d+t/2,m+t*.82)}let a=new an(o);return a.colorSpace=Pe,a.wrapS=ge,a.wrapT=ge,a.flipY=!1,a.anisotropy=8,a.needsUpdate=!0,Re=a,a}function un(e){for(let n of H.values())if(n.texture.source===e.source&&(!n.loaded||n.failed))return!0;return!1}var K=5*1024*1024,dt=["activeModelId","modelUrl","modelFormat","tilesetUrl","models","mergeModels","sceneConfig","isolation","multiSelectedKeys","activeAnnotation","annotationCategories","backgroundColor","shadows","cinematic","cameraControllerType","objectTransformSpace","arScaleMode","usdzUrl","measurements","measurementSettings","measurementUnit","measurementModelId"];function S(e,n){throw new Error(`Invalid viewer state at ${e}: ${n}`)}function T(e,n){(!e||typeof e!="object"||Array.isArray(e))&&S(n,"expected an object.")}function oe(e,n){(!Array.isArray(e)||!e.every(t=>typeof t=="string"))&&S(n,"expected strings.")}function D(e,n,t){(!Array.isArray(e)||e.length!==n||!e.every(r=>typeof r=="number"&&Number.isFinite(r)))&&S(t,`expected ${n} finite numbers.`)}function ut(e){let n=new Set,t=0;function r(o,i,a){if((++t>2e5||a>64)&&S(i,"configuration is too complex."),o===null||typeof o=="string"||typeof o=="boolean"||typeof o=="number"&&Number.isFinite(o))return o;(typeof o!="object"||!o)&&S(i,"expected JSON data (finite numbers, no functions)."),n.has(o)&&S(i,"cyclic data."),!Array.isArray(o)&&Object.getPrototypeOf(o)!==Object.prototype&&Object.getPrototypeOf(o)!==null&&S(i,"expected plain JSON data."),n.add(o);let s=Array.isArray(o)?[]:{};for(let[c,d]of Object.entries(o))["__proto__","constructor","prototype"].includes(c)&&S(`${i}.${c}`,"reserved property."),d!==void 0?s[c]=r(d,`${i}.${c}`,a+1):Array.isArray(o)&&S(i,"undefined array entry.");return n.delete(o),s}return r(e,"state",0)}function _(e,n,t,r,o=!1,i){let a=e[n];if(a==null||a==="")return;typeof a!="string"&&S(t,"expected a URL.");let s=o?be(a)??a:a;if(s.trim().startsWith("blob:")){if(o&&i){i.set(a,{source:s,path:t});return}S(t,o?"this image is temporary. Use getStateAsync() for JSON or createShareUrl() to include it.":"upload this model/environment asset to a durable URL before saving or sharing.")}if(s!==a&&(a=s,e[n]=s),o&&/^data:image\//i.test(a))return;let c;try{c=new URL(a,r??"https://relative.invalid/")}catch{S(t,"invalid asset URL.")}["http:","https:"].includes(c.protocol)||S(t,"use an HTTP(S) asset URL."),r&&(e[n]=c.href)}function mt(e,n){T(e,n),D(e.position,3,`${n}.position`),D(e.target,3,`${n}.target`),(typeof e.zoom!="number"||e.zoom<=0)&&S(n,"zoom must be positive."),e.fov!==null&&(typeof e.fov!="number"||e.fov<=0||e.fov>=180)&&S(n,"fov must be null or between 0 and 180.");for(let t of["azimuthAngle","polarAngle"])e[t]!==void 0&&typeof e[t]!="number"&&S(n,`${t} must be a number.`)}function gn(e,n,t,r){T(e,n),(typeof e.id!="number"||typeof e.title!="string"||typeof e.description!="string")&&S(n,"expected an annotation id, title and description.");for(let o of["worldPosition","localPosition"])D(e[o],3,`${n}.${o}`);e.images!==void 0&&(Array.isArray(e.images)||S(n,"images must be an array."),e.images.forEach(o=>{T(o,n),_(o,"src",n,t,!0,r)})),e.links!==void 0&&(Array.isArray(e.links)||S(n,"links must be an array."),e.links.forEach(o=>{T(o,n),_(o,"href",n,t,!1,r)}))}function pn(e,n){T(e,n),e.waypoints!==void 0&&(Array.isArray(e.waypoints)||S(n,"expected waypoints."),e.waypoints.forEach(t=>{T(t,n),D(t.position,3,n),D(t.target,3,n)}));for(let t of["enabled","loop","autoPlay"])e[t]!==void 0&&typeof e[t]!="boolean"&&S(n,`${t} must be boolean.`);e.duration!==void 0&&(typeof e.duration!="number"||e.duration<=0)&&S(n,"duration must be positive.")}function Ve(e,n,t){if(n!==null)if(Array.isArray(n))Array.isArray(e)||S(t,"expected an array."),n.length&&e.forEach(r=>Ve(r,n[0],t));else if(typeof n=="object"){T(e,t);for(let[r,o]of Object.entries(n))Ve(e[r],o,`${t}.${r}`)}else typeof e!=typeof n&&S(t,`expected ${typeof n}.`)}function mn(e,n,t,r){if(Ve(e,Z,n),e.measurements!==void 0&&(e.measurements=te(e.measurements)),e.sequences!==void 0&&(e.sequences=Fe(e.sequences)),e.selectionSets!==void 0&&(e.selectionSets=sn(e.selectionSets)),e.product!==void 0&&(e.product=He(e.product),e.product.definition.groups.forEach(o=>o.options.forEach(i=>i.appearance?.forEach(a=>{for(let[s,c]of Object.entries(a.material??{}))c&&typeof c=="object"&&!Array.isArray(c)&&"path"in c&&_(c,"path",`${n}.product.material.${s}.path`,t,!0,r)})))),D(e.model.rotation,3,`${n}.model.rotation`),e.lighting.lights.forEach(o=>D(o.position,3,`${n}.lighting.lights`)),e.annotations.forEach(o=>gn(o,`${n}.annotations`,t,r)),e.animations.autoplayClip!==null&&typeof e.animations.autoplayClip!="string"&&S(n,"invalid autoplay clip."),e.animations.clips.forEach(o=>{T(o,n),(typeof o.sourceName!="string"||typeof o.displayName!="string"||typeof o.hidden!="boolean"||typeof o.speed!="number"||!["repeat","once","ping-pong"].includes(o.loopMode))&&S(n,"invalid animation clip settings.")}),e.cinematic!==void 0&&pn(e.cinematic,`${n}.cinematic`),e.styleRules!==void 0&&!Array.isArray(e.styleRules)&&S(n,"styleRules must be an array."),_(e.environment,"customEnvironmentUrl",`${n}.environment`,t,!1,r),_(e.background,"imageUrl",`${n}.background`,t,!0,r),e.model.activeVariants!==void 0&&oe(e.model.activeVariants,n),e.section!==void 0)try{e.section=ee(e.section)}catch(o){S(`${n}.section`,o.message)}}function bn(e,n,t,r){T(e,n);for(let[o,i]of Object.entries(e)){let a=`${n}.${o}`;T(i,a),(typeof i.id!="string"||typeof i.modelObjectId!="string")&&S(a,"expected binding id and modelObjectId.");for(let s of["label","group","type","status"])i[s]!==void 0&&typeof i[s]!="string"&&S(a,`${s} must be a string.`);i.tags!==void 0&&oe(i.tags,a),i.metadata!==void 0&&T(i.metadata,`${a}.metadata`),i.metrics!==void 0&&(T(i.metrics,a),Object.values(i.metrics).some(s=>typeof s!="number")&&S(a,"metrics must be numbers.")),i.actions!==void 0&&(Array.isArray(i.actions)||S(a,"actions must be an array."),i.actions.forEach(s=>{T(s,a),(typeof s.id!="string"||typeof s.label!="string"||s.type!=="command"||s.effects!==void 0&&!Array.isArray(s.effects))&&S(a,"invalid action.")}));for(let s of["visible","removed","selectable","hoverable"])i[s]!==void 0&&typeof i[s]!="boolean"&&S(a,`${s} must be boolean.`);if(i.transform!==void 0){T(i.transform,a);for(let s of["position","rotation","scale","shear"])i.transform[s]!==void 0&&D(i.transform[s],3,`${a}.transform.${s}`);i.transform.pivot!==void 0&&(T(i.transform.pivot,a),D(i.transform.pivot.point,3,a),D(i.transform.pivot.offset,3,a))}if(i.style!==void 0&&(T(i.style,a),i.style.material!==void 0)){T(i.style.material,a);for(let[s,c]of Object.entries(i.style.material))c&&typeof c=="object"&&!Array.isArray(c)&&"path"in c&&_(c,"path",`${a}.style.material.${s}.path`,t,!0,r)}i.decals!==void 0&&(Array.isArray(i.decals)||S(a,"decals must be an array."),i.decals.forEach(s=>{T(s,a),(typeof s.id!="string"||typeof s.size!="number"||s.size<=0)&&S(a,"invalid decal."),D(s.position,3,a),D(s.normal,3,a),_(s,"image",a,t,!0,r)}))}}function fn(e,n,t,r){Array.isArray(e)||S(n,"expected merge sources."),e.forEach(o=>{T(o,n),(typeof o.url!="string"||!o.url||typeof o.namePrefix!="string")&&S(n,"expected source URL and prefix."),_(o,"url",n,t,!1,r)})}function ft(e,n,t){T(e,"configuration");let r=Object.fromEntries(dt.filter(o=>e[o]!==void 0).map(o=>[o,e[o]]));(typeof r.modelUrl!="string"||!r.modelUrl)&&S("configuration.modelUrl","expected the active model URL.");for(let o of["modelUrl","tilesetUrl","usdzUrl"])_(r,o,`configuration.${o}`,n,!1,t);if(r.sceneConfig!==void 0&&mn(r.sceneConfig,"configuration.sceneConfig",n,t),r.mergeModels!==void 0&&fn(r.mergeModels,"configuration.mergeModels",n,t),r.models!==void 0){(!Array.isArray(r.models)||r.models.length===0)&&S("configuration.models","expected model entries.");let o=new Set,i=new Set;r.models.forEach(a=>{T(a,"model"),(typeof a.url!="string"||!a.url)&&S("model.url","expected a URL."),_(a,"url","model.url",n,!1,t),a.id!==void 0&&(typeof a.id!="string"||!a.id.trim())&&S("model.id","expected a nonempty instance ID.");let s=je({id:a.id,url:a.url});i.has(s)&&S("configuration.models","instance identities must be unique; assign IDs when reusing a URL."),i.add(s),a.transform!==void 0&&(a.transform=ne(a.transform)),a.visible!==void 0&&typeof a.visible!="boolean"&&S("model.visible","expected boolean."),o.add(a.url),bn(a.objectBindings,"model.objectBindings",n,t),a.sceneConfig!==void 0&&mn(a.sceneConfig,"model.sceneConfig",n,t),a.mergeModels!==void 0&&fn(a.mergeModels,"model.mergeModels",n,t)}),r.activeModelId!==void 0&&(typeof r.activeModelId!="string"||!i.has(r.activeModelId))&&S("configuration.activeModelId","active instance is not in models."),r.activeModelId!==void 0&&r.models.find(a=>je(a)===r.activeModelId)?.url!==r.modelUrl&&S("configuration.modelUrl","source does not match the active instance."),o.has(r.modelUrl)||S("configuration.modelUrl","active model is not in models.")}if(r.multiSelectedKeys!==void 0&&oe(r.multiSelectedKeys,"configuration.multiSelectedKeys"),r.annotationCategories!==void 0&&r.annotationCategories!==null&&oe(r.annotationCategories,"configuration.annotationCategories"),r.activeAnnotation!==void 0&&r.activeAnnotation!==null&&gn(r.activeAnnotation,"configuration.activeAnnotation",n,t),r.measurements!==void 0||r.measurementSettings!==void 0){let o=te({items:r.measurements??[],settings:r.measurementSettings??{}});r.measurements!==void 0&&(r.measurements=o.items),r.measurementSettings!==void 0&&(r.measurementSettings=o.settings)}r.measurementModelId!==void 0&&typeof r.measurementModelId!="string"&&S("configuration.measurementModelId","expected a stable id."),r.measurementUnit!==void 0&&typeof r.measurementUnit!="string"&&S("configuration.measurementUnit","expected a unit label.");for(let o of["backgroundColor"])r[o]!==void 0&&typeof r[o]!="string"&&S(o,"expected a string.");r.shadows!==void 0&&typeof r.shadows!="boolean"&&S("shadows","expected boolean.");for(let[o,i]of Object.entries({modelFormat:["glb","gltf","obj","fbx","usdz","stl","ply"],cameraControllerType:["orbit","pointerLock"],objectTransformSpace:["world","local"],arScaleMode:["normalized","real-world"]}))r[o]!==void 0&&!i.includes(r[o])&&S(o,"unsupported value.");if(r.cinematic!==void 0&&pn(r.cinematic,"cinematic"),r.isolation!==void 0&&r.isolation!==null){let{target:o,mode:i,ghostOpacity:a}=r.isolation;typeof o=="string"||Array.isArray(o)&&o.every(s=>typeof s=="string")||o&&typeof o=="object"&&["group","tag","type"].some(s=>typeof o[s]=="string")||S("configuration.isolation","invalid target."),i!==void 0&&!["ghost","hide"].includes(i)&&S("configuration.isolation","invalid mode."),a!==void 0&&(typeof a!="number"||a<0||a>1)&&S("configuration.isolation","opacity must be between 0 and 1.")}return r}function hn(e,n,t,r){if(!(!e||typeof e!="object"))for(let[o,i]of Object.entries(e))o!=="metadata"&&(typeof i=="string"&&["url","modelUrl","tilesetUrl","usdzUrl","path","image","src","href","imageUrl","customEnvironmentUrl"].includes(o)?_(e,o,`${n}.${o}`,t,["path","image","src","imageUrl"].includes(o),r):hn(i,`${n}.${o}`,t,r))}function yn(e,n,t){typeof e=="string"&&(new TextEncoder().encode(e).length>K&&S("state","exceeds the 5 MiB limit."),e=JSON.parse(e));let r=ut(e);T(r,"state"),new TextEncoder().encode(JSON.stringify(r)).length>K&&S("state","exceeds the 5 MiB limit."),r.version!==void 0&&r.version!==1&&S("version","unsupported version."),r.version===void 0&&(r.objectBindings!==void 0||r.configuration!==void 0)&&S("version","full configurations require version 1.");let o={};return r.version!==void 0&&(o.version=1),r.camera!==void 0&&(mt(r.camera,"camera"),o.camera=r.camera),r.hidden!==void 0&&(oe(r.hidden,"hidden"),o.hidden=r.hidden),r.selected!==void 0&&(r.selected!==null&&typeof r.selected!="string"&&S("selected","expected an object id or null."),o.selected=r.selected),r.objectBindings!==void 0&&(bn(r.objectBindings,"objectBindings",n,t),o.objectBindings=r.objectBindings),r.configuration!==void 0&&(o.configuration=ft(r.configuration,n,t)),hn(o,"state",n,t),new TextEncoder().encode(JSON.stringify(o)).length>K&&S("state","exceeds the 5 MiB limit."),o}function _r(e,n){return JSON.stringify(he(e,n))}function he(e,n){return yn(e,n)}async function Sn(e,n){let t=new Map,r=yn(e,n,t),o=new Map,i=new Map;for(let[s,{source:c,path:d}]of t){let m=o.get(c);m||(m=(async()=>{let u;try{u=await fetch(c)}catch{S(d,"this temporary image is no longer available. Reload or reselect it before saving.")}u.ok||S(d,"could not read the temporary image. Reload or reselect it before saving.");let l=await u.blob();l.size>K*3/4&&S(d,"embedded image exceeds the 5 MiB configuration limit. Use a hosted image URL.");let f=new Uint8Array(await l.arrayBuffer()),g=l.type.split(";")[0].toLowerCase(),y=g.startsWith("image/")?g:gt(f);y||S(d,"temporary asset is not a supported image. Use a hosted asset URL.");let p="";for(let b=0;b<f.length;b+=32768)p+=String.fromCharCode(...f.subarray(b,b+32768));return`data:${y};base64,${btoa(p)}`})(),o.set(c,m)),i.set(s,await m)}function a(s){if(!(!s||typeof s!="object"))for(let[c,d]of Object.entries(s))c!=="metadata"&&(["path","image","src","imageUrl"].includes(c)&&typeof d=="string"&&i.has(d)?s[c]=i.get(d):a(d))}return a(r),he(r,n)}function gt(e){let n=(t,r)=>String.fromCharCode(...e.subarray(t,r));if(e[0]===137&&n(1,4)==="PNG")return"image/png";if(e[0]===255&&e[1]===216&&e[2]===255)return"image/jpeg";if(n(0,3)==="GIF")return"image/gif";if(n(0,4)==="RIFF"&&n(8,12)==="WEBP")return"image/webp";if(n(4,8)==="ftyp"&&["avif","avis"].includes(n(8,12)))return"image/avif";if(/<svg[\s>]/i.test(new TextDecoder().decode(e.subarray(0,1024))))return"image/svg+xml"}import{strFromU8 as pt,strToU8 as xn,unzlibSync as bt,zlibSync as ht}from"fflate";var ye="ri-ar",Se="ri-ar-id",wn=4096,yt=2200,St=xn(JSON.stringify(Z)).byteLength;function An(e){return e==="localhost"||e.endsWith(".localhost")||/^127\./.test(e)||e==="[::1]"||e==="0.0.0.0"}function Mn(e){if(typeof e=="string"&&/^https?:\/\//i.test(e)&&An(new URL(e).hostname))throw new Error("An asset URL points to this computer. Use model and texture URLs reachable from the phone.");if(e&&typeof e=="object")for(let n of Object.values(e))Mn(n)}function Wr(e){return e&&typeof e=="object"?e:void 0}function Hr(e){let n=new URLSearchParams(new URL(e,"https://viewer.invalid/").hash.slice(1));return n.has(ye)||n.has(Se)}function xt(e,n){let t=new URL(e,n);if(!["https:","http:"].includes(t.protocol))throw new Error("AR handoff requires an HTTP(S) URL.");return t.toString()}function Kr(e,n="",t=2048){let r=new Set,o=i=>{if(typeof i=="string")return be(i)??i;if(i===null||typeof i!="object")return i;if(r.has(i))throw new Error("AR configuration cannot contain cycles.");r.add(i);let a=Array.isArray(i)?i.map(o):Object.fromEntries(Object.keys(i).sort().map(s=>[s,o(i[s])]));return r.delete(i),a};return JSON.stringify([n,t,o({...e,camera:void 0})])}function Cn(e,n){if(JSON.stringify(e)!==JSON.stringify(n))return e&&n&&typeof e=="object"&&typeof n=="object"&&!Array.isArray(e)&&!Array.isArray(n)?Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Cn(r,n[t])]).filter(([,t])=>t!==void 0)):e}function On(e,n,t=0){if(t>64)throw new Error("AR configuration is too deeply nested.");if(e&&n&&typeof e=="object"&&typeof n=="object"&&!Array.isArray(e)&&!Array.isArray(n)){let r=e,o=n;return Object.fromEntries([...new Set([...Object.keys(o),...Object.keys(r)])].map(i=>[i,Object.prototype.hasOwnProperty.call(r,i)?On(r[i],o[i],t+1):o[i]]))}return e}function jn(e,n){let t=structuredClone(e);if(t.configuration){t.configuration.sceneConfig&&(t.configuration.sceneConfig=n(t.configuration.sceneConfig));for(let r of t.configuration.models??[])r.sceneConfig&&(r.sceneConfig=n(r.sceneConfig))}return t}function ie(e){e?.throwIfAborted()}async function Yr(e,n,t,r){ie(r);let o=new URL(xt(n));if(An(o.hostname))throw new Error("Phone links need a viewer URL reachable from your phone. Download the USDZ for local uploads, or provide a public viewer URL.");let i=await Sn(e,o.toString());ie(r),Mn(i);let a=new URLSearchParams(o.hash.slice(1));if(a.delete(ye),a.delete(Se),a.delete("view"),a.delete("viewId"),a.delete("view-id"),t){let s=await t.save(i);if(ie(r),typeof s!="string"||!s||s.length>512)throw new Error("AR storage returned an invalid configuration ID.");a.set(Se,s)}else{let s=ht(xn(JSON.stringify({ar:1,state:jn(i,d=>Cn(d,Z)??{})})),{level:9});if(s.byteLength>wn)throw new Error("This configuration needs an AR storage adapter to share on a phone. The USDZ download is still available.");let c="";for(let d of s)c+=String.fromCharCode(d);a.set(ye,btoa(c).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""))}if(o.hash=a.toString(),o.toString().length>yt)throw new Error("This configuration is too large for a reliable QR code. Use an AR storage adapter or download the USDZ.");return o.toString()}async function Xr(e,n,t){let r=new URL(e),o=new URLSearchParams(r.hash.slice(1)),i=o.get(Se),a=o.get(ye);if(i!==null&&a!==null)throw new Error("AR link contains conflicting configurations.");if(i===null&&a===null)return null;ie(t);let s;if(i!==null){if(!n)throw new Error("This AR link requires the application's configuration storage adapter.");if(!i||i.length>512)throw new Error("Invalid AR configuration ID.");s=await n.load(i)}else{if(!a||a.length>Math.ceil(wn*4/3)||!/^[\w-]+$/.test(a))throw new Error("Invalid or oversized AR link.");let d=atob(a.replace(/-/g,"+").replace(/_/g,"/")),m=Uint8Array.from(d,f=>f.charCodeAt(0)),u=bt(m);if(u.byteLength>K)throw new Error("AR configuration exceeds the 5 MiB limit.");let l=JSON.parse(pt(u));if(l?.ar===1&&l.state){let f=l.state.configuration,g=(f?.sceneConfig?1:0)+(Array.isArray(f?.models)?f.models.filter(y=>y?.sceneConfig).length:0);if(u.byteLength+g*St>K)throw new Error("Expanded AR configuration exceeds the 5 MiB limit.");s=jn(l.state,y=>On(y,Z))}else s=l}ie(t);let c=he(s,r.toString());if(c.version!==1||!c.configuration)throw new Error("AR handoff requires a complete versioned viewer configuration.");return c}var Le=new WeakMap;function Zr(e,n){n?Le.set(e,n):Le.delete(e)}function vn(e){e.traverse(n=>{let t=Le.get(n);if(t)throw new Error(t)})}import{Box3 as At,BufferAttribute as In,BufferGeometry as Tn,Color as Mt,DoubleSide as Ct,FrontSide as Ue,Group as En,Matrix4 as Ot,Mesh as jt,Vector3 as xe}from"three";import{PropertyBinding as De}from"three";var _e=Symbol("react-immersive.model-node-id");function wt(e,n){Object.defineProperty(e,_e,{value:n,configurable:!0})}function se(e){let n=new Map;e.traverse(c=>{if(!c.name)return;let d=n.get(c.name);d?d.push(c):n.set(c.name,[c])});let t=Object.create(null),r=new WeakMap,o=new Map,i=new Set(Array.from(n,([c,d])=>d.length===1?c:null).filter(c=>c!==null)),a=new Set,s=(c,d)=>{wt(c,d),t[d]=c,r.set(c,d),a.add(d)};for(let[c,d]of n)d.length===1&&s(d[0],c);for(let[c,d]of n){if(d.length<2)continue;let m=[];d.forEach((u,l)=>{let f=`${c} [${l+1}]`,g=f,y=2;for(;i.has(g)||a.has(g);)g=`${f}.${y++}`;s(u,g),m.push(g)}),o.set(c,m)}return{nodesById:t,idByNode:r,duplicateNames:o}}function ae(e){return e[_e]??e.name??null}function eo(e,n){let t=n.replace(/\.[^./\\]+$/,"");e.traverse(r=>{r.name&&(r.name=De.sanitizeNodeName(`${t}_${r.name}`))})}function no(e,n){let t=n.replace(/\.[^./\\]+$/,""),r=e.clone();for(let o of r.tracks){let a=De.parseTrackName(o.name).nodeName??"",s=De.sanitizeNodeName(`${t}_${a}`);o.name=s+o.name.slice(a.length)}return r}function to(e,n){let t=null,r=[];return e.traverse(o=>{o[_e]===n&&(t=o),o.name===n&&r.push(o)}),t??(r.length===1?r[0]:null)}function vt(e,n={}){n.signal?.throwIfAborted();let t=new En,r=new En;t.add(r);let o=new Set,i=[],a=[],s=[],c=new Map,d=0,m=0,u=()=>{i.forEach(l=>l.dispose()),a.forEach(l=>l.dispose()),s.forEach(l=>l.dispose())};try{for(let{scene:p,objectBindings:b={},materialOverrides:h={}}of e){vn(p),p.updateWorldMatrix(!0,!0);let w=new Map(Object.entries(b).map(([A,x])=>[x.modelObjectId??A,A]));p.traverse(A=>{let x=A;if(!x.isMesh||!x.geometry)return;for(let P=A;P;P=P.parent){let F=ae(P)??P.name??P.uuid;if(!P.visible||b[w.get(F)??F]?.visible===!1||b[w.get(F)??F]?.removed)return}let M=ae(x)??x.name??x.uuid,R=h[w.get(M)??M]??x.material;if(!R)throw new Error(`Material for ${M} is not ready. Wait for the model to finish loading.`);let B=Array.isArray(R)?R:[R],Q=x.isInstancedMesh?x.count:1;if(x.userData.riDecal&&de(x)&&x.parent){let P=Ge(x.parent);P&&x.bindMatrixInverse.copy(P)}let E=de(x)?We(x):x.geometry.clone();try{if(!de(x)&&x.morphTargetInfluences?.some(U=>U!==0)){let U=E.getAttribute("position"),$=new xe;for(let V=0;V<U.count;V++)x.getVertexPosition(V,$),U.setXYZ(V,$.x,$.y,$.z);E.morphAttributes={},E.computeVertexNormals()}if(!E.getAttribute("position"))throw new Error(`Mesh ${M} has no positions.`);let P=E.index?.count??E.getAttribute("position").count,F=Array.isArray(R)?E.groups:[{start:0,count:P,materialIndex:0}];if(!F.length)throw new Error(`Mesh ${M} has multiple materials without geometry groups.`);for(let U=0;U<Q;U++){let $=x.matrixWorld.clone();if(x.isInstancedMesh){let V=new Ot;x.getMatrixAt(U,V),$.multiply(V)}for(let V of F){let ce=B[V.materialIndex??0];if(!ce)throw new Error(`A material group on ${M} is missing its material.`);if(!ce.visible)continue;let G=ce;if(!G.isMeshStandardMaterial||G.wireframe||G.vertexColors)throw new Error(`AR snapshot cannot preserve ${ce.type}${G.wireframe?" wireframe":G.vertexColors?" vertex colors":""} on ${M}. Use a PBR material or provide arHandoff.createUSDZ.`);let X=Math.max(V.start,E.drawRange.start),Me=Math.min(P,V.start+V.count,E.drawRange.start+E.drawRange.count);if(Me<=X)continue;if(X%3||(Me-X)%3)throw new Error(`Mesh ${M} has an incomplete triangle range.`);let k=new Tn;i.push(k);let z=Array.from({length:Me-X},(C,j)=>E.index?E.index.getX(X+j):X+j);if($.determinant()<0)for(let C=0;C<z.length;C+=3)[z[C+1],z[C+2]]=[z[C+2],z[C+1]];for(let[C,j]of Object.entries(E.attributes)){let O=new Float32Array(z.length*j.itemSize);for(let v=0;v<z.length;v++)for(let L=0;L<j.itemSize;L++)O[v*j.itemSize+L]=j.getComponent(z[v],L);k.setAttribute(C,new In(O,j.itemSize))}k.setIndex(z.map((C,j)=>j)),k.applyMatrix4($);let le=k.getAttribute("position");for(let C=0;C<le.count;C++)if(![le.getX(C),le.getY(C),le.getZ(C)].every(Number.isFinite))throw new Error(`Mesh ${M} contains invalid coordinates.`);k.getAttribute("normal")||k.computeVertexNormals();let N=G.clone();a.push(N);let ze=G.userData.reactImmersiveConfiguredEmissive;if(ze?.isColor&&N.emissive.copy(ze),N.side===Ct){let C=k.toNonIndexed();i.push(C);let j=C.getAttribute("position").count,O=new Tn;i.push(O);for(let[v,L]of Object.entries(C.attributes)){let Ce=new Float32Array(j*L.itemSize*2);for(let W=0;W<j;W++)for(let q=0;q<L.itemSize;q++){Ce[W*L.itemSize+q]=L.getComponent(W,q);let _n=Math.floor(W/3)*3+(2-W%3);Ce[(j+W)*L.itemSize+q]=L.getComponent(_n,q)*(v==="normal"?-1:1)}O.setAttribute(v,new In(Ce,L.itemSize))}N.side=Ue,k.copy(O)}else if(N.side!==Ue){let C=k.getIndex();for(let O=0;O<C.count;O+=3){let v=C.getX(O+1);C.setX(O+1,C.getX(O+2)),C.setX(O+2,v)}let j=k.getAttribute("normal");for(let O=0;O<j.count;O++)j.setXYZ(O,-j.getX(O),-j.getY(O),-j.getZ(O));N.side=Ue}if(x.isInstancedMesh&&x.instanceColor){let C=new Mt;x.getColorAt(U,C),N.color.multiply(C)}for(let[C,j]of Object.entries(N)){if(!j?.isTexture)continue;let O=j;if(un(O)||!O.image||O.image.complete===!1)throw new Error(`Texture on ${M} is not ready. Wait for image loading or replace failed textures before preparing AR.`);let v=c.get(O);if(v||(v=O.clone(),c.set(O,v),s.push(v)),N[C]=v,!k.getAttribute(v.channel?`uv${v.channel}`:"uv"))throw new Error(`Texture on ${M} needs UV coordinates missing from this geometry.`)}if(x.userData.riDecal){k.computeBoundingBox();let C=Math.max(1e-6,k.boundingBox.getSize(new xe).length()*1e-4),j=k.getAttribute("position"),O=k.getAttribute("normal");for(let v=0;v<j.count;v++)j.setXYZ(v,j.getX(v)+O.getX(v)*C,j.getY(v)+O.getY(v)*C,j.getZ(v)+O.getZ(v)*C)}let $e=new jt(k,N);$e.name=`AR_${d++}`,r.add($e),m+=(k.index?.count??k.getAttribute("position").count)/3,(N.clearcoat||N.transmission||N.iridescence||N.anisotropy)&&o.add("Advanced PBR effects may look different in Quick Look.")}}}finally{E.dispose()}})}if(!d||!m)throw new Error("There is no visible model geometry to send to AR.");let l=new At().setFromObject(r),f=l.getSize(new xe),g=l.getCenter(new xe),y=n.scaleMode==="real-world"?1:1/Math.max(f.x,f.y,f.z,1e-9);return r.position.set(-g.x*y,-l.min.y*y,-g.z*y),r.scale.setScalar(y),t.updateMatrixWorld(!0),o.add("USDZ is a static snapshot. Viewer lighting, background, post-processing, annotations and measurement overlays stay in the web viewer."),{root:t,meshCount:d,triangleCount:m,scale:y,warnings:[...o],textures:s,dispose:u}}catch(l){throw u(),l}}async function fo(e,n={}){let t=n.maxTextureSize??2048;if(!Number.isInteger(t)||t<256||t>4096)throw new Error("AR maxTextureSize must be an integer from 256 to 4096.");let r=vt(e,n),o=[];try{let{USDZExporter:i}=await import("three/examples/jsm/exporters/USDZExporter.js");n.signal?.throwIfAborted();for(let s of r.textures){if(!s.isCompressedTexture)continue;let{decompress:c}=await import("three/examples/jsm/utils/WebGLTextureUtils.js"),d=c(s,t);o.push(d),r.root.traverse(m=>{let u=m.material;if(u)for(let l of Object.keys(u))u[l]===s&&(u[l]=d)})}let a=await new i().parseAsync(r.root,{onlyVisible:!0,quickLookCompatible:!0,maxTextureSize:t});return n.signal?.throwIfAborted(),{blob:new Blob([new Uint8Array(a)],{type:"model/vnd.usdz+zip"}),meshCount:r.meshCount,triangleCount:r.triangleCount,scale:r.scale,warnings:r.warnings}}catch(i){throw n.signal?.aborted?i:new Error(`Could not prepare the configured USDZ: ${i instanceof Error?i.message:"export failed"}. Textures must allow cross-origin canvas access.`)}finally{r.dispose(),o.forEach(i=>i.dispose())}}var we=Object.freeze([{id:"change-color",label:"Change Color",handling:"viewer",description:"Opens a color picker docked under the action and commits the result to style.material.baseColor."},{id:"change-material",label:"Change Material",handling:"viewer",description:"Opens the material picker so the viewer can swap the object's texture."},{id:"add-text",label:"Add Text",handling:"viewer",description:"Opens a text box docked under the action; the viewer's user types, clicks the object to place it, and can resize, turn, move, or remove it. Saved to the binding's decals."},{id:"add-image",label:"Add Image",handling:"viewer",description:"Lets the viewer's user choose an image, click the object to place it, and resize, turn, move, or remove it. Saved to the binding's decals."},{id:"toggle-visibility",label:"Toggle Visibility",handling:"viewer",description:"Flips the binding's visible flag."},{id:"toggle-light",label:"Toggle Light",handling:"viewer",description:"Turns the scene lights attached to this object on or off, or the object's own glow when none is attached."},{id:"change-light-color",label:"Change Light Color",handling:"viewer",description:"Opens a color picker docked under the action for the scene lights attached to this object, or the object's own glow."},{id:"set-brightness",label:"Set Brightness",handling:"viewer",description:"Opens a brightness slider docked under the action for the scene lights attached to this object, or the object's own glow."}]),po="__custom__";function It(e){return we.find(n=>n.id===e)}var Rn=we.filter(e=>e.handling==="viewer").map(e=>e.id),Tt=new Set(["","New Action",...we.map(e=>e.label)]);function bo(e){return Tt.has(e.trim())}function kn(e,n){let t=Array.from({length:n.length+1},(r,o)=>o);for(let r=1;r<=e.length;r+=1){let o=[r];for(let i=1;i<=n.length;i+=1){let a=t[i-1]+(e[r-1]===n[i-1]?0:1);o[i]=Math.min(o[i-1]+1,t[i]+1,a)}t=o}return t[n.length]}function ho(e){if(It(e))return null;let n=e.trim().toLowerCase();if(!n)return null;let t=n.replace(/[^a-z0-9]/g,""),r=null;for(let o of we){let i=Math.min(kn(n,o.id),kn(t,o.id.replace(/[^a-z0-9]/g,"")));(!r||i<r.distance)&&(r={id:o.id,distance:i})}return r&&r.distance<=2?r.id:null}var Et=.12,Bn=new Set;function kt(e,n){return n?new Set(ue(e,n.target)):Bn}function xo(e,n){let t=kt(e.bindings,n);if(!n||t.size===0)return{...e,setAside:Bn};let r=Math.min(Math.max(n.ghostOpacity??Et,0),1),o={...e.bindings},i=new WeakMap,a=new Set;for(let[s,c]of Object.entries(e.bindings)){if(t.has(s))continue;a.add(s);let d=n.mode==="hide"?{...c,visible:!1}:{...c,style:{...c.style,material:{...c.style?.material,opacity:Math.min(c.style?.material?.opacity??1,r)}}};o[s]=d,i.set(d,e.sourceOf(c))}return{bindings:o,pulses:e.pulses,sourceOf:s=>i.get(s)??e.sourceOf(s),setAside:a}}function Rt(e){return e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").replace(/[^a-zA-Z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function Bt(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,n=>n.toUpperCase())}function Nt(e){let n=e.toLowerCase();return n.includes("light")?"light":n.includes("wheel")||n.includes("rim")||n.includes("tire")?"wheel":n.includes("glass")||n.includes("window")||n.includes("windshield")||n.includes("sunroof")?"glass":n.includes("seat")||n.includes("dashboard")||n.includes("console")||n.includes("doorpanel")?"interior":n.includes("floor")?"floor":n.includes("wall")?"wall":n.includes("door")?"door":n.includes("chair")||n.includes("table")||n.includes("sofa")||n.includes("bed")?"furniture":"other"}function Nn(e,n=!0){return e==="light"||e.endsWith("light")?[{id:"toggle-light",label:"Toggle Light",type:"command"},{id:"change-light-color",label:"Change Light Color",type:"command"},{id:"set-brightness",label:"Set Brightness",type:"command"}]:[{id:"change-color",label:"Change Color",type:"command"},...n?[{id:"change-material",label:"Change Material",type:"command"}]:[],{id:"toggle-visibility",label:"Toggle Visibility",type:"command"}]}function Pn(e,n=!0){let t=Nt(e);return{id:Rt(e),modelObjectId:e,type:t,label:Bt(e),status:"normal",selectable:!0,hoverable:!0,visible:!0,style:{},actions:Nn(t,n),metrics:{},metadata:{}}}function Oo(e,n){return Object.fromEntries(e.map(t=>[t,Pn(t,!n?.has(t))]))}function jo(e,n){let t=new Set,r={};for(let o of e){let i=Pn(o,!n?.has(o)),a=i.id||"object",s=a;for(let d=2;t.has(s);d++)s=`${a}-${d}`;t.add(s),i.id=s;let c=(i.actions??[]).filter(d=>Rn.includes(d.id));i.actions=c.length>0?c:Nn("other",!n?.has(o)),r[o]=i}return r}function vo(e){let n=new Set;for(let[t,r]of Object.entries(se(e).nodesById))Ke(r)||n.add(t);return n}function Io(e){let{nodesById:n}=se(e),t=[];for(let[r,o]of Object.entries(n)){let i=o;i.isMesh&&i.geometry&&o.name&&t.push(r)}return t.sort((r,o)=>r.localeCompare(o))}var Dn={id:"identity",modelObjectId:"identity",label:"identity",type:"identity",group:"identity",tags:"identity",style:"appearance",decals:"appearance",transform:"transform",visible:"visibility",removed:"visibility",status:"visibility",selectable:"behavior",hoverable:"behavior",actions:"behavior",cameraState:"behavior",metadata:"data",metrics:"data"},Pt=Object.keys(Dn),Vt=new Set(["__proto__","prototype","constructor"]);function Y(e,n=new Set){if(e==null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number"){if(!Number.isFinite(e))throw new Error("Comparison values must be finite JSON data");return e}if(typeof e!="object"||n.has(e))throw new Error("Comparison values must be acyclic JSON data");n.add(e);let t=Array.isArray(e)?e.map(r=>Y(r,n)):Object.fromEntries(Object.entries(e).filter(([r,o])=>!Vt.has(r)&&o!==void 0).map(([r,o])=>[r,Y(o,n)]));return n.delete(e),t}var Vn=e=>e&&typeof e=="object"&&!Array.isArray(e)&&!Object.keys(e).length;function Ln(e,n){let t=Y(e);t.visible=e.visible??!0,t.selectable=e.selectable??!0,t.hoverable=e.hoverable??!0,t.status=e.status??"normal",t.type=e.type??"other",t.tags=[...new Set(e.tags??[])].sort(),Vn(t.transform)&&delete t.transform,t.metadata=Object.fromEntries(Object.entries(e.metadata??{}).filter(([r])=>!n.includes(r)));for(let r of["metrics","style","metadata"])Vn(t[r])&&delete t[r];for(let r of["actions","decals"])Array.isArray(t[r])&&!t[r].length&&delete t[r];return t}function Ae(e,n,t,r,o,i){let a=c=>c===void 0||Array.isArray(c)&&c.length===0;if(Object.is(e,n)||a(e)&&a(n)||typeof e=="number"&&typeof n=="number"&&Math.abs(e-n)<=o)return;let s=c=>!!c&&typeof c=="object"&&!Array.isArray(c);if(s(e)&&s(n)){for(let c of[...new Set([...Object.keys(e),...Object.keys(n)])].sort())Ae(e[c],n[c],`${t}.${c}`,r,o,i);return}if(Array.isArray(e)&&Array.isArray(n)&&e.length===n.length){for(let c=0;c<e.length;c++)Ae(e[c],n[c],`${t}[${c}]`,r,o,i);return}i.push({path:t,category:r,...e!==void 0?{before:Y(e)}:{},...n!==void 0?{after:Y(n)}:{}})}function Eo(e,n,t={}){let r=t.tolerance??1e-6;if(!Number.isFinite(r)||r<0)throw new Error("Comparison tolerance must be finite and nonnegative");let o=Object.entries(e.objectBindings).filter(([,b])=>!b.removed),i=Object.entries(n.objectBindings).filter(([,b])=>!b.removed),a=new Map(o),s=new Map(i),c=new Set,d=new Set,m=[],u=b=>{let h=t.matchBy??"modelObjectId",w=typeof h=="object"?b.metadata?.[h.metadataKey]:b[h];return typeof w=="string"&&w.length>0||typeof w=="number"?`${typeof w}:${w}`:null};function l(b,h,w){let A=b===void 0?void 0:a.get(b),x=h===void 0?void 0:s.get(h),M=[];if(A||x){let B=A?Ln(A,t.ignoreMetadataKeys??[]):{},Q=x?Ln(x,t.ignoreMetadataKeys??[]):{};for(let E of Pt)Ae(B[E],Q[E],E,Dn[E],r,M)}let R=A?x?M.length?"modified":"unchanged":"removed":"added";m.push({id:JSON.stringify([b??null,h??null]),identity:w,label:x?.label??A?.label??x?.modelObjectId??A?.modelObjectId??w,status:R,beforeKey:b,afterKey:h,beforeObjectId:A?.modelObjectId,afterObjectId:x?.modelObjectId,changes:M}),b!==void 0&&c.add(b),h!==void 0&&d.add(h)}let f=new Set;for(let[b,h]of Object.entries(t.mapping??{})){if(!a.has(b)||!s.has(h)||f.has(h))throw new Error("Comparison mapping must reference existing, unique binding keys");f.add(h),l(b,h,`mapped:${b}`)}let g=new Map;for(let[b,h,w]of[[o,c,"a"],[i,d,"b"]])for(let[A,x]of b){if(h.has(A))continue;let M=u(x);if(M===null){m.push({id:JSON.stringify([w,A]),identity:"",label:x.label??x.modelObjectId,status:"ambiguous",...w==="a"?{beforeKey:A,beforeObjectId:x.modelObjectId}:{afterKey:A,afterObjectId:x.modelObjectId},changes:[],message:"Missing match identity. Supply an explicit mapping or another match field."});continue}let R=g.get(M)??{a:[],b:[]};R[w].push(A),g.set(M,R)}for(let[b,h]of g){if(h.a.length<=1&&h.b.length<=1){l(h.a[0],h.b[0],b);continue}for(let w of["a","b"])for(let A of h[w]){let x=(w==="a"?a:s).get(A);m.push({id:JSON.stringify([w,A]),identity:b,label:x.label??x.modelObjectId,status:"ambiguous",...w==="a"?{beforeKey:A,beforeObjectId:x.modelObjectId}:{afterKey:A,afterObjectId:x.modelObjectId},changes:[],message:"Duplicate match identity. Supply an explicit one-to-one mapping."})}}m.sort((b,h)=>b.label.localeCompare(h.label)||b.id.localeCompare(h.id));let y=[];Ae(Y(e.sceneConfig??{}),Y(n.sceneConfig??{}),"sceneConfig","scene",r,y);let p={added:0,removed:0,modified:0,unchanged:0,ambiguous:0};for(let b of m)p[b.status]++;return{version:1,objects:m,counts:p,sceneChanges:y}}function ko(e,n,t){let r={added:"#22c55e",removed:"#f87171",modified:"#fbbf24",unchanged:"#94a3b8",ambiguous:"#c084fc"};return e.objects.flatMap(o=>{let i=n==="before"?o.beforeObjectId:o.afterObjectId;return i&&(o.status!=="unchanged"||o.id===t)?[{objectId:i,color:o.id===t?"#22d3ee":r[o.status]}]:[]})}var Bo=["front","back","double"],No=["normal","additive"];function Lo(e){se(e);let n=[],t=[{node:e,path:"0",parentId:null}];for(;t.length;){let{node:o,path:i,parentId:a}=t.pop(),s=`node:${i}`,c=o.isMesh&&o.name?ae(o):null;n.push({id:s,parentId:a,name:o.name||o.type||"Group",...c?{objectId:c}:{}});for(let d=o.children.length-1;d>=0;d--)t.push({node:o.children[d],path:`${i}/${d}`,parentId:s})}let r=new Set;for(let o=n.length-1;o>=0;o--){let i=n[o];(i.objectId||r.has(i.id))&&(r.add(i.id),i.parentId&&r.add(i.parentId))}return n.filter(o=>r.has(o.id))}function Uo(e){return structuredClone(e.style??{})}function zo(e,n,t){let r=ue(e,n).filter(i=>!e[i].removed);if(!r.length)return e;let o={...e};for(let i of r)o[i]={...e[i],style:structuredClone(t)};return o}export{se as a,ae as b,eo as c,no as d,to as e,Be as f,hr as g,yr as h,Sr as i,xr as j,be as k,wr as l,Ar as m,lt as n,Mr as o,Cr as p,Or as q,jr as r,vr as s,Ir as t,Tr as u,Lt as v,Dt as w,_t as x,Ut as y,zt as z,$t as A,Ft as B,Oe as C,Z as D,ee as E,Ht as F,Kt as G,Yt as H,Zt as I,je as J,ne as K,Jt as L,Qt as M,er as N,nr as O,Je as P,Qe as Q,en as R,Ie as S,or as T,ir as U,sr as V,ar as W,tt as X,Ee as Y,ot as Z,dr as _,ur as $,on as aa,it as ba,te as ca,mr as da,fr as ea,sn as fa,K as ga,_r as ha,he as ia,Sn as ja,Wr as ka,Hr as la,xt as ma,Kr as na,Yr as oa,Xr as pa,Zr as qa,vn as ra,fo as sa,we as ta,po as ua,It as va,Rn as wa,bo as xa,ho as ya,kt as za,xo as Aa,Nt as Ba,Pn as Ca,Oo as Da,jo as Ea,vo as Fa,Io as Ga,Eo as Ha,ko as Ia,Bo as Ja,No as Ka,Lo as La,Uo as Ma,zo as Na};