@rr0/ufoathome 0.168.2 → 0.170.0

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 (112) hide show
  1. package/dist-embed-interview/rr0-interview.mjs +6 -6
  2. package/dist-embed-scene/{AdsbLolArchiveProvider-C5EeYhpl.js → AdsbLolArchiveProvider-C0eoxzdX.js} +1 -1
  3. package/dist-embed-scene/{BeamEditor-Ba7Ezj8j.js → BeamEditor-ihmgiAKc.js} +1 -1
  4. package/dist-embed-scene/{BeamSystem-DIVpxthT.js → BeamSystem-DXTXXbc7.js} +1 -1
  5. package/dist-embed-scene/{Flightradar24Provider-BeS3XdM3.js → Flightradar24Provider-mKDmwMzz.js} +1 -1
  6. package/dist-embed-scene/{GLTFLoader-CZgH95sS.js → GLTFLoader-BVVGHFvY.js} +1 -1
  7. package/dist-embed-scene/{LanternEditor-G9J4NATU.js → LanternEditor-CcBPfbIH.js} +1 -1
  8. package/dist-embed-scene/{LaserBeam-Brn6Zqr3.js → LaserBeam-DJnJ5Okd.js} +1 -1
  9. package/dist-embed-scene/{LaunchEditor-CwOuZWBk.js → LaunchEditor-B4e1HRMn.js} +1 -1
  10. package/dist-embed-scene/{LaunchPlume-BTM2du_c.js → LaunchPlume-DwOSrKP_.js} +1 -1
  11. package/dist-embed-scene/{LaunchSimulation-DEK6P4Sp.js → LaunchSimulation-ClGdZJHr.js} +1 -1
  12. package/dist-embed-scene/{ModuleSession-C_YbCjpq.js → ModuleSession-BXMnu0b2.js} +2 -2
  13. package/dist-embed-scene/ModuleThree-BoYZTPwx.js +1 -0
  14. package/dist-embed-scene/{ParameterForm-B97-YTVp.js → ParameterForm-DDUXscnR.js} +1 -1
  15. package/dist-embed-scene/{ReentryEditor-BKtcFVDQ.js → ReentryEditor-7E16l_ix.js} +1 -1
  16. package/dist-embed-scene/{ReentrySimulation-CSWgk9pd.js → ReentrySimulation-CrhMgBEf.js} +1 -1
  17. package/dist-embed-scene/ReferenceSystem-Vgg3SwB1.js +1 -0
  18. package/dist-embed-scene/SceneNames_en-DWTnafrN.js +1 -0
  19. package/dist-embed-scene/SceneNames_es-hgd9srr_.js +1 -0
  20. package/dist-embed-scene/SceneNames_fr-CUIrnsZp.js +1 -0
  21. package/dist-embed-scene/SceneNames_it-D5ayHc7C.js +1 -0
  22. package/{dist-embed-sighting/TimelineTracks-DJjaMlgp.js → dist-embed-scene/TimelineTracks-Cjs12pO0.js} +1 -1
  23. package/dist-embed-scene/{UfoMessages_en-BbYI-msn.js → UfoMessages_en-9jQrxDPT.js} +1 -1
  24. package/dist-embed-scene/rr0-scene.mjs +404 -328
  25. package/dist-embed-scene/sightingSchema-B1hstz7u.js +1 -0
  26. package/dist-embed-sighting/{AdsbLolArchiveProvider-Dfc5WtsT.js → AdsbLolArchiveProvider-jkXdr5Fw.js} +1 -1
  27. package/dist-embed-sighting/{BeamEditor-Bg_vNgW4.js → BeamEditor-C1rw_f3H.js} +1 -1
  28. package/dist-embed-sighting/{BeamSystem-MLh1pFB-.js → BeamSystem-Bm8JAQ9L.js} +1 -1
  29. package/dist-embed-sighting/{Flightradar24Provider-BrBeubn2.js → Flightradar24Provider-BPiC5dKg.js} +1 -1
  30. package/dist-embed-sighting/{GLTFLoader-CAFRnQZ-.js → GLTFLoader-C8rVdDv7.js} +1 -1
  31. package/dist-embed-sighting/{LanternEditor-DvZVGtbt.js → LanternEditor-BSCPfcO0.js} +1 -1
  32. package/dist-embed-sighting/{LaserBeam-4AVPXLoY.js → LaserBeam-Dfjpv2LA.js} +1 -1
  33. package/dist-embed-sighting/{LaunchEditor-CKu8hLFs.js → LaunchEditor-BLkzRUDz.js} +2 -2
  34. package/dist-embed-sighting/{LaunchPlume-DpEeDSbj.js → LaunchPlume-DH8ZMXrj.js} +1 -1
  35. package/dist-embed-sighting/{LaunchSimulation-Dnk-ygqj.js → LaunchSimulation-3m1LUs2t.js} +1 -1
  36. package/dist-embed-sighting/{ModuleSession-CY0lPMUP.js → ModuleSession-DtYWI2oD.js} +2 -2
  37. package/dist-embed-sighting/ModuleThree-C7c8etU_.js +1 -0
  38. package/dist-embed-sighting/{ParameterForm-CoffSyiK.js → ParameterForm-BhiE6uRp.js} +1 -1
  39. package/dist-embed-sighting/{ReentryEditor-YnfTvPAi.js → ReentryEditor-C5dzOj_i.js} +1 -1
  40. package/dist-embed-sighting/{ReentrySimulation-Cv3zM7re.js → ReentrySimulation-BfkUcIGM.js} +1 -1
  41. package/dist-embed-sighting/ReferenceSystem-DVbt8GRf.js +1 -0
  42. package/dist-embed-sighting/SceneNames_en-BCismFgW.js +1 -0
  43. package/{dist-embed-scene/SceneNames_es-DuwAjd1R.js → dist-embed-sighting/SceneNames_es-u83jdbyr.js} +1 -1
  44. package/dist-embed-sighting/SceneNames_fr-hA9CGBs-.js +1 -0
  45. package/dist-embed-sighting/SceneNames_it-Bp7twqSK.js +1 -0
  46. package/dist-embed-sighting/ShareMessages_en-B43x8LgJ.js +1 -0
  47. package/dist-embed-sighting/ShareMessages_es-DZCJojSc.js +1 -0
  48. package/dist-embed-sighting/ShareMessages_fr-CzZyVbbX.js +1 -0
  49. package/dist-embed-sighting/ShareMessages_it-C_Z6eDQK.js +1 -0
  50. package/{dist-embed-scene/TimelineTracks-Dn25EuIg.js → dist-embed-sighting/TimelineTracks-CLKDjoN6.js} +1 -1
  51. package/dist-embed-sighting/rr0-sighting.mjs +410 -329
  52. package/dist-embed-sighting/sightingSchema-B1hstz7u.js +1 -0
  53. package/dist-embed-sighting-editor/{GLTFLoader-D7rOFNtH.js → GLTFLoader-DQ9JYWIM.js} +1 -1
  54. package/dist-embed-sighting-editor/{GhostSearchView-UG9G-yF8.js → GhostSearchView-Dlhj3xWa.js} +1 -1
  55. package/dist-embed-sighting-editor/{InterviewEditorElement-DL1YL6dm.js → InterviewEditorElement-DFLz-0ed.js} +2 -2
  56. package/dist-embed-sighting-editor/{ModuleConformance-BRi5HHIj.js → ModuleConformance-H7LbISvs.js} +2 -2
  57. package/dist-embed-sighting-editor/{ModuleSession-DzFSCz3B.js → ModuleSession-BXk5ijvF.js} +2 -2
  58. package/dist-embed-sighting-editor/ModuleThree-DsbRgMxg.js +1 -0
  59. package/dist-embed-sighting-editor/{ModulesPanelElement-B7clvotM.js → ModulesPanelElement-B1KHXTpq.js} +3 -3
  60. package/dist-embed-sighting-editor/PictureFetch-C3wgf1ZV.js +1 -0
  61. package/dist-embed-sighting-editor/ReferenceSystem-DIlZXaIz.js +1 -0
  62. package/dist-embed-sighting-editor/SceneNames_en-DNhr4wdu.js +1 -0
  63. package/dist-embed-sighting-editor/SceneNames_es-DP1RW7Iw.js +1 -0
  64. package/dist-embed-sighting-editor/SceneNames_fr-mGHb5j1M.js +1 -0
  65. package/dist-embed-sighting-editor/SceneNames_it-fxUdb_jZ.js +1 -0
  66. package/dist-embed-sighting-editor/ShareMessages_en-B43x8LgJ.js +1 -0
  67. package/dist-embed-sighting-editor/ShareMessages_es-DZCJojSc.js +1 -0
  68. package/dist-embed-sighting-editor/ShareMessages_fr-CzZyVbbX.js +1 -0
  69. package/dist-embed-sighting-editor/ShareMessages_it-C_Z6eDQK.js +1 -0
  70. package/dist-embed-sighting-editor/SightingEditorMessages_en-B3H7WVDJ.js +12 -0
  71. package/dist-embed-sighting-editor/SightingEditorMessages_es-DDiIjdeY.js +12 -0
  72. package/dist-embed-sighting-editor/SightingEditorMessages_fr-Ynh-3Cma.js +12 -0
  73. package/dist-embed-sighting-editor/SightingEditorMessages_it-DuRnZpaW.js +12 -0
  74. package/dist-embed-sighting-editor/{SightingFileEditor-DB3jyBzw.js → SightingFileEditor-bXm0nVE4.js} +1 -1
  75. package/dist-embed-sighting-editor/{caseSchema-DixCNMzt.js → caseSchema-SAzcVIGZ.js} +1 -1
  76. package/dist-embed-sighting-editor/{interviewSchema-D82l9P1r.js → interviewSchema-DTeTYZOQ.js} +1 -1
  77. package/dist-embed-sighting-editor/rr0-sighting-editor.mjs +511 -429
  78. package/dist-embed-sighting-editor/sightingSchema-B1hstz7u.js +1 -0
  79. package/package.json +1 -3
  80. package/dist-embed-scene/ModuleThree-CW7tVSPl.js +0 -1
  81. package/dist-embed-scene/ReferenceSystem-BgT1nVgA.js +0 -1
  82. package/dist-embed-scene/SceneNames_en-MuZS0swp.js +0 -1
  83. package/dist-embed-scene/SceneNames_fr-ChDjaMY9.js +0 -1
  84. package/dist-embed-scene/SceneNames_it-CWzCQiEh.js +0 -1
  85. package/dist-embed-scene/sightingSchema-CKUYrwgu.js +0 -1
  86. package/dist-embed-sighting/ModuleThree-C7Ss3kvP.js +0 -1
  87. package/dist-embed-sighting/ReferenceSystem-90M3kYiP.js +0 -1
  88. package/dist-embed-sighting/SceneNames_en-CryY5Edh.js +0 -1
  89. package/dist-embed-sighting/SceneNames_es-StyJlKmE.js +0 -1
  90. package/dist-embed-sighting/SceneNames_fr-B3c9bWLO.js +0 -1
  91. package/dist-embed-sighting/SceneNames_it--6HUBaRO.js +0 -1
  92. package/dist-embed-sighting/ShareMessages_en-DE1WoeWH.js +0 -1
  93. package/dist-embed-sighting/ShareMessages_es-BM5hHumO.js +0 -1
  94. package/dist-embed-sighting/ShareMessages_fr-DyOB2E5o.js +0 -1
  95. package/dist-embed-sighting/ShareMessages_it-C9F8UHk_.js +0 -1
  96. package/dist-embed-sighting/sightingSchema-CKUYrwgu.js +0 -1
  97. package/dist-embed-sighting-editor/ModuleThree-CHA3zU14.js +0 -1
  98. package/dist-embed-sighting-editor/PictureFetch-X3UpM6JV.js +0 -1
  99. package/dist-embed-sighting-editor/ReferenceSystem-Dt6JW97S.js +0 -1
  100. package/dist-embed-sighting-editor/SceneNames_en-oNPwLOsb.js +0 -1
  101. package/dist-embed-sighting-editor/SceneNames_es-Z_lHKIao.js +0 -1
  102. package/dist-embed-sighting-editor/SceneNames_fr-CTfqBDCK.js +0 -1
  103. package/dist-embed-sighting-editor/SceneNames_it-Bjfu1PyS.js +0 -1
  104. package/dist-embed-sighting-editor/ShareMessages_en-DE1WoeWH.js +0 -1
  105. package/dist-embed-sighting-editor/ShareMessages_es-BM5hHumO.js +0 -1
  106. package/dist-embed-sighting-editor/ShareMessages_fr-DyOB2E5o.js +0 -1
  107. package/dist-embed-sighting-editor/ShareMessages_it-C9F8UHk_.js +0 -1
  108. package/dist-embed-sighting-editor/SightingEditorMessages_en-fw5f4PmH.js +0 -12
  109. package/dist-embed-sighting-editor/SightingEditorMessages_es-ChZigecC.js +0 -12
  110. package/dist-embed-sighting-editor/SightingEditorMessages_fr-BZamA8fA.js +0 -12
  111. package/dist-embed-sighting-editor/SightingEditorMessages_it-Umt2KSX2.js +0 -12
  112. package/dist-embed-sighting-editor/sightingSchema-CKUYrwgu.js +0 -1
@@ -1 +1 @@
1
- import{bh as be,bi as Q,bj as he,bk as Le,bl as v,bm as de,aP as y,aR as pe,aE as F,bn as w,bc as U,b9 as Me,bo as Se,ai as ye,w as K,bp as we,V as C,Q as me,bq as Ne,u as ge,br as Ie,bs as Oe,ao as V,bt as Ce,bu as Te,bv as Fe,bw as Pe,bx as He,bd as J,by as Re,bz as Z,bA as ke,bB as De,b5 as Ge,bC as X,bD as ve,ad as Ee,aq as Ue,ap as G,bE as Ke,an as Be,bF as je,ab as Ve,bG as Xe,bH as ze,bI as qe,aC as We,a8 as z,aj as Ye,b3 as Qe,bJ as Je,bK as Ze,bL as $e,bM as en,bN as nn,bO as tn,bP as xe,aX as sn,bb as ne,bQ as te,bR as se,bS as ie,bT as re,bU as rn,bV as on,ae as an,af as cn}from"./rr0-sighting-editor.mjs";function oe(f,n){if(n===be)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),f;if(n===Q||n===he){let e=f.getIndex();if(e===null){const r=[],a=f.getAttribute("position");if(a!==void 0){for(let o=0;o<a.count;o++)r.push(o);f.setIndex(r),e=f.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),f}const s=e.count-2,t=[];if(n===Q)for(let r=1;r<=s;r++)t.push(e.getX(0)),t.push(e.getX(r)),t.push(e.getX(r+1));else for(let r=0;r<s;r++)r%2===0?(t.push(e.getX(r)),t.push(e.getX(r+1)),t.push(e.getX(r+2))):(t.push(e.getX(r+2)),t.push(e.getX(r+1)),t.push(e.getX(r)));t.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=f.clone();return i.setIndex(t),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",n),f}class jn extends Le{constructor(n){super(n),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new dn(e)}),this.register(function(e){return new pn(e)}),this.register(function(e){return new bn(e)}),this.register(function(e){return new Ln(e)}),this.register(function(e){return new Mn(e)}),this.register(function(e){return new gn(e)}),this.register(function(e){return new Tn(e)}),this.register(function(e){return new Rn(e)}),this.register(function(e){return new En(e)}),this.register(function(e){return new hn(e)}),this.register(function(e){return new xn(e)}),this.register(function(e){return new mn(e)}),this.register(function(e){return new _n(e)}),this.register(function(e){return new An(e)}),this.register(function(e){return new ln(e)}),this.register(function(e){return new ae(e,g.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new ae(e,g.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new Sn(e)})}load(n,e,s,t){const i=this;let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const c=v.extractUrlBase(n);r=v.resolveURL(c,this.path)}else r=v.extractUrlBase(n);this.manager.itemStart(n);const a=function(c){t?t(c):console.error(c),i.manager.itemError(n),i.manager.itemEnd(n)},o=new de(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(n,function(c){try{i.parse(c,r,function(u){e(u),i.manager.itemEnd(n)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(n){return this.dracoLoader=n,this}setKTX2Loader(n){return this.ktx2Loader=n,this}setMeshoptDecoder(n){return this.meshoptDecoder=n,this}register(n){return this.pluginCallbacks.indexOf(n)===-1&&this.pluginCallbacks.push(n),this}unregister(n){return this.pluginCallbacks.indexOf(n)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(n),1),this}parse(n,e,s,t){let i;const r={},a={},o=new TextDecoder;if(typeof n=="string")i=JSON.parse(n);else if(n instanceof ArrayBuffer)if(o.decode(new Uint8Array(n,0,4))===Ae){try{r[g.KHR_BINARY_GLTF]=new yn(n)}catch(l){t&&t(l);return}i=JSON.parse(r[g.KHR_BINARY_GLTF].content)}else i=JSON.parse(o.decode(n));else i=n;if(i.asset===void 0||i.asset.version[0]<2){t&&t(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new Un(i,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const l=this.pluginCallbacks[u](c);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[l.name]=l,r[l.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const l=i.extensionsUsed[u],h=i.extensionsRequired||[];switch(l){case g.KHR_MATERIALS_UNLIT:r[l]=new fn;break;case g.KHR_DRACO_MESH_COMPRESSION:r[l]=new wn(i,this.dracoLoader);break;case g.KHR_TEXTURE_TRANSFORM:r[l]=new Nn;break;case g.KHR_MESH_QUANTIZATION:r[l]=new In;break;default:h.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}c.setExtensions(r),c.setPlugins(a),c.parse(s,t)}parseAsync(n,e){const s=this;return new Promise(function(t,i){s.parse(n,e,t,i)})}}function un(){let f={};return{get:function(n){return f[n]},add:function(n,e){f[n]=e},remove:function(n){delete f[n]},removeAll:function(){f={}}}}function _(f,n,e){const s=f.json.materials[n];return s.extensions&&s.extensions[e]?s.extensions[e]:null}const g={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class ln{constructor(n){this.parser=n,this.name=g.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const n=this.parser,e=this.parser.json.nodes||[];for(let s=0,t=e.length;s<t;s++){const i=e[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&n._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(n){const e=this.parser,s="light:"+n;let t=e.cache.get(s);if(t)return t;const i=e.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[n];let c;const u=new F(16777215);o.color!==void 0&&u.setRGB(o.color[0],o.color[1],o.color[2],w);const l=o.range!==void 0?o.range:0;switch(o.type){case"directional":c=new ye(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new Se(u),c.distance=l;break;case"spot":c=new Me(u),c.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=o.spot.innerConeAngle!==void 0?o.spot.innerConeAngle:0,o.spot.outerConeAngle=o.spot.outerConeAngle!==void 0?o.spot.outerConeAngle:Math.PI/4,c.angle=o.spot.outerConeAngle,c.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return c.position.set(0,0,0),S(c,o),o.intensity!==void 0&&(c.intensity=o.intensity),c.name=e.createUniqueName(o.name||"light_"+n),t=Promise.resolve(c),e.cache.add(s,t),t}getDependency(n,e){if(n==="light")return this._loadLight(e)}createNodeAttachment(n){const e=this,s=this.parser,i=s.json.nodes[n],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(o){return s._getNodeRef(e.cache,a,o)})}}class fn{constructor(){this.name=g.KHR_MATERIALS_UNLIT}getMaterialType(){return G}extendParams(n,e,s){const t=[];n.color=new F(1,1,1),n.opacity=1;const i=e.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;n.color.setRGB(r[0],r[1],r[2],w),n.opacity=r[3]}i.baseColorTexture!==void 0&&t.push(s.assignTexture(n,"map",i.baseColorTexture,U))}return Promise.all(t)}}class hn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||s.emissiveStrength!==void 0&&(e.emissiveIntensity=s.emissiveStrength),Promise.resolve()}}class dn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_CLEARCOAT}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];if(s.clearcoatFactor!==void 0&&(e.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&t.push(this.parser.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&t.push(this.parser.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(t.push(this.parser.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){const i=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new pe(i,i)}return Promise.all(t)}}class pn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_DISPERSION}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||(e.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}}class mn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_IRIDESCENCE}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.iridescenceFactor!==void 0&&(e.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&t.push(this.parser.assignTexture(e,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(e.iridescenceIOR=s.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&t.push(this.parser.assignTexture(e,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(t)}}class gn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_SHEEN}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];if(e.sheenColor=new F(0,0,0),e.sheenRoughness=0,e.sheen=1,s.sheenColorFactor!==void 0){const i=s.sheenColorFactor;e.sheenColor.setRGB(i[0],i[1],i[2],w)}return s.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&t.push(this.parser.assignTexture(e,"sheenColorMap",s.sheenColorTexture,U)),s.sheenRoughnessTexture!==void 0&&t.push(this.parser.assignTexture(e,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(t)}}class Tn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_TRANSMISSION}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.transmissionFactor!==void 0&&(e.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&t.push(this.parser.assignTexture(e,"transmissionMap",s.transmissionTexture)),Promise.all(t)}}class Rn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_VOLUME}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];e.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&t.push(this.parser.assignTexture(e,"thicknessMap",s.thicknessTexture)),e.attenuationDistance=s.attenuationDistance||1/0;const i=s.attenuationColor||[1,1,1];return e.attenuationColor=new F().setRGB(i[0],i[1],i[2],w),Promise.all(t)}}class En{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_IOR}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||(e.ior=s.ior!==void 0?s.ior:1.5,e.ior===0&&(e.ior=1e3)),Promise.resolve()}}class xn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_SPECULAR}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];e.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&t.push(this.parser.assignTexture(e,"specularIntensityMap",s.specularTexture));const i=s.specularColorFactor||[1,1,1];return e.specularColor=new F().setRGB(i[0],i[1],i[2],w),s.specularColorTexture!==void 0&&t.push(this.parser.assignTexture(e,"specularColorMap",s.specularColorTexture,U)),Promise.all(t)}}class An{constructor(n){this.parser=n,this.name=g.EXT_MATERIALS_BUMP}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return e.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&t.push(this.parser.assignTexture(e,"bumpMap",s.bumpTexture)),Promise.all(t)}}class _n{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_ANISOTROPY}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.anisotropyStrength!==void 0&&(e.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(e.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&t.push(this.parser.assignTexture(e,"anisotropyMap",s.anisotropyTexture)),Promise.all(t)}}class bn{constructor(n){this.parser=n,this.name=g.KHR_TEXTURE_BASISU}loadTexture(n){const e=this.parser,s=e.json,t=s.textures[n];if(!t.extensions||!t.extensions[this.name])return null;const i=t.extensions[this.name],r=e.options.ktx2Loader;if(!r){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(n,i.source,r)}}class Ln{constructor(n){this.parser=n,this.name=g.EXT_TEXTURE_WEBP}loadTexture(n){const e=this.name,s=this.parser,t=s.json,i=t.textures[n];if(!i.extensions||!i.extensions[e])return null;const r=i.extensions[e],a=t.images[r.source];let o=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(n,r.source,o)}}class Mn{constructor(n){this.parser=n,this.name=g.EXT_TEXTURE_AVIF}loadTexture(n){const e=this.name,s=this.parser,t=s.json,i=t.textures[n];if(!i.extensions||!i.extensions[e])return null;const r=i.extensions[e],a=t.images[r.source];let o=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(n,r.source,o)}}class ae{constructor(n,e){this.name=e,this.parser=n}loadBufferView(n){const e=this.parser.json,s=e.bufferViews[n];if(s.extensions&&s.extensions[this.name]){const t=s.extensions[this.name],i=this.parser.getDependency("buffer",t.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const o=t.byteOffset||0,c=t.byteLength||0,u=t.count,l=t.byteStride,h=new Uint8Array(a,o,c);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(u,l,h,t.mode,t.filter).then(function(d){return d.buffer}):r.ready.then(function(){const d=new ArrayBuffer(u*l);return r.decodeGltfBuffer(new Uint8Array(d),u,l,h,t.mode,t.filter),d})})}else return null}}class Sn{constructor(n){this.name=g.EXT_MESH_GPU_INSTANCING,this.parser=n}createNodeMesh(n){const e=this.parser.json,s=e.nodes[n];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const t=e.meshes[s.mesh];for(const c of t.primitives)if(c.mode!==L.TRIANGLES&&c.mode!==L.TRIANGLE_STRIP&&c.mode!==L.TRIANGLE_FAN&&c.mode!==void 0)return null;const r=s.extensions[this.name].attributes,a=[],o={};for(const c in r)a.push(this.parser.getDependency("accessor",r[c]).then(u=>(o[c]=u,o[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(n)),Promise.all(a).then(c=>{const u=c.pop(),l=u.isGroup?u.children:[u],h=c[0].count,d=[];for(const p of l){const R=new K,m=new C,T=new me,A=new C(1,1,1),x=new we(p.geometry,p.material,h);for(let E=0;E<h;E++)o.TRANSLATION&&m.fromBufferAttribute(o.TRANSLATION,E),o.ROTATION&&T.fromBufferAttribute(o.ROTATION,E),o.SCALE&&A.fromBufferAttribute(o.SCALE,E),x.setMatrixAt(E,R.compose(m,T,A));for(const E in o)if(E==="_COLOR_0"){const b=o[E];x.instanceColor=new Ne(b.array,b.itemSize,b.normalized)}else E!=="TRANSLATION"&&E!=="ROTATION"&&E!=="SCALE"&&p.geometry.setAttribute(E,o[E]);ge.prototype.copy.call(x,p),this.parser.assignFinalMaterial(x),d.push(x)}return u.isGroup?(u.clear(),u.add(...d),u):d[0]}))}}const Ae="glTF",D=12,ce={JSON:1313821514,BIN:5130562};class yn{constructor(n){this.name=g.KHR_BINARY_GLTF,this.content=null,this.body=null;const e=new DataView(n,0,D),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(n.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==Ae)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const t=this.header.length-D,i=new DataView(n,D);let r=0;for(;r<t;){const a=i.getUint32(r,!0);r+=4;const o=i.getUint32(r,!0);if(r+=4,o===ce.JSON){const c=new Uint8Array(n,D+r,a);this.content=s.decode(c)}else if(o===ce.BIN){const c=D+r;this.body=n.slice(c,c+a)}r+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class wn{constructor(n,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=g.KHR_DRACO_MESH_COMPRESSION,this.json=n,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(n,e){const s=this.json,t=this.dracoLoader,i=n.extensions[this.name].bufferView,r=n.extensions[this.name].attributes,a={},o={},c={};for(const u in r){const l=$[u]||u.toLowerCase();a[l]=r[u]}for(const u in n.attributes){const l=$[u]||u.toLowerCase();if(r[u]!==void 0){const h=s.accessors[n.attributes[u]],d=H[h.componentType];c[l]=d.name,o[l]=h.normalized===!0}}return e.getDependency("bufferView",i).then(function(u){return new Promise(function(l,h){t.decodeDracoFile(u,function(d){for(const p in d.attributes){const R=d.attributes[p],m=o[p];m!==void 0&&(R.normalized=m)}l(d)},a,c,w,h)})})}}class Nn{constructor(){this.name=g.KHR_TEXTURE_TRANSFORM}extendTexture(n,e){return(e.texCoord===void 0||e.texCoord===n.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(n=n.clone(),e.texCoord!==void 0&&(n.channel=e.texCoord),e.offset!==void 0&&n.offset.fromArray(e.offset),e.rotation!==void 0&&(n.rotation=e.rotation),e.scale!==void 0&&n.repeat.fromArray(e.scale),n.needsUpdate=!0),n}}class In{constructor(){this.name=g.KHR_MESH_QUANTIZATION}}class _e extends on{constructor(n,e,s,t){super(n,e,s,t)}copySampleValue_(n){const e=this.resultBuffer,s=this.sampleValues,t=this.valueSize,i=n*t*3+t;for(let r=0;r!==t;r++)e[r]=s[i+r];return e}interpolate_(n,e,s,t){const i=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=a*2,c=a*3,u=t-e,l=(s-e)/u,h=l*l,d=h*l,p=n*c,R=p-c,m=-2*d+3*h,T=d-h,A=1-m,x=T-h+l;for(let E=0;E!==a;E++){const b=r[R+E+a],N=r[R+E+o]*u,M=r[p+E+a],k=r[p+E]*u;i[E]=A*b+x*N+m*M+T*k}return i}}const On=new me;class Cn extends _e{interpolate_(n,e,s,t){const i=super.interpolate_(n,e,s,t);return On.fromArray(i).normalize().toArray(i),i}}const L={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},H={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},ue={9728:Re,9729:J,9984:He,9985:Pe,9986:Fe,9987:Te},le={33071:De,33648:ke,10497:Z},q={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},$={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},I={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Fn={CUBICSPLINE:void 0,LINEAR:xe,STEP:tn},W={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Pn(f){return f.DefaultMaterial===void 0&&(f.DefaultMaterial=new Ee({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:rn})),f.DefaultMaterial}function O(f,n,e){for(const s in e.extensions)f[s]===void 0&&(n.userData.gltfExtensions=n.userData.gltfExtensions||{},n.userData.gltfExtensions[s]=e.extensions[s])}function S(f,n){n.extras!==void 0&&(typeof n.extras=="object"?Object.assign(f.userData,n.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+n.extras))}function Hn(f,n,e){let s=!1,t=!1,i=!1;for(let c=0,u=n.length;c<u;c++){const l=n[c];if(l.POSITION!==void 0&&(s=!0),l.NORMAL!==void 0&&(t=!0),l.COLOR_0!==void 0&&(i=!0),s&&t&&i)break}if(!s&&!t&&!i)return Promise.resolve(f);const r=[],a=[],o=[];for(let c=0,u=n.length;c<u;c++){const l=n[c];if(s){const h=l.POSITION!==void 0?e.getDependency("accessor",l.POSITION):f.attributes.position;r.push(h)}if(t){const h=l.NORMAL!==void 0?e.getDependency("accessor",l.NORMAL):f.attributes.normal;a.push(h)}if(i){const h=l.COLOR_0!==void 0?e.getDependency("accessor",l.COLOR_0):f.attributes.color;o.push(h)}}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(o)]).then(function(c){const u=c[0],l=c[1],h=c[2];return s&&(f.morphAttributes.position=u),t&&(f.morphAttributes.normal=l),i&&(f.morphAttributes.color=h),f.morphTargetsRelative=!0,f})}function kn(f,n){if(f.updateMorphTargets(),n.weights!==void 0)for(let e=0,s=n.weights.length;e<s;e++)f.morphTargetInfluences[e]=n.weights[e];if(n.extras&&Array.isArray(n.extras.targetNames)){const e=n.extras.targetNames;if(f.morphTargetInfluences.length===e.length){f.morphTargetDictionary={};for(let s=0,t=e.length;s<t;s++)f.morphTargetDictionary[e[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Dn(f){let n;const e=f.extensions&&f.extensions[g.KHR_DRACO_MESH_COMPRESSION];if(e?n="draco:"+e.bufferView+":"+e.indices+":"+Y(e.attributes):n=f.indices+":"+Y(f.attributes)+":"+f.mode,f.targets!==void 0)for(let s=0,t=f.targets.length;s<t;s++)n+=":"+Y(f.targets[s]);return n}function Y(f){let n="";const e=Object.keys(f).sort();for(let s=0,t=e.length;s<t;s++)n+=e[s]+":"+f[e[s]]+";";return n}function ee(f){switch(f){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Gn(f){return f.search(/\.jpe?g($|\?)/i)>0||f.search(/^data\:image\/jpeg/)===0?"image/jpeg":f.search(/\.webp($|\?)/i)>0||f.search(/^data\:image\/webp/)===0?"image/webp":f.search(/\.ktx2($|\?)/i)>0||f.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const vn=new K;class Un{constructor(n={},e={}){this.json=n,this.extensions={},this.plugins={},this.options=e,this.cache=new un,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,t=-1,i=!1,r=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;const o=a.match(/Version\/(\d+)/);t=s&&o?parseInt(o[1],10):-1,i=a.indexOf("Firefox")>-1,r=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&t<17||i&&r<98?this.textureLoader=new Ie(this.options.manager):this.textureLoader=new Oe(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new de(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(n){this.extensions=n}setPlugins(n){this.plugins=n}parse(n,e){const s=this,t=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(r){return r._markDefs&&r._markDefs()}),Promise.all(this._invokeAll(function(r){return r.beforeRoot&&r.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(r){const a={scene:r[0][t.scene||0],scenes:r[0],animations:r[1],cameras:r[2],asset:t.asset,parser:s,userData:{}};return O(i,a,t),S(a,t),Promise.all(s._invokeAll(function(o){return o.afterRoot&&o.afterRoot(a)})).then(function(){for(const o of a.scenes)o.updateMatrixWorld();n(a)})}).catch(e)}_markDefs(){const n=this.json.nodes||[],e=this.json.skins||[],s=this.json.meshes||[];for(let t=0,i=e.length;t<i;t++){const r=e[t].joints;for(let a=0,o=r.length;a<o;a++)n[r[a]].isBone=!0}for(let t=0,i=n.length;t<i;t++){const r=n[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(s[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(n,e){e!==void 0&&(n.refs[e]===void 0&&(n.refs[e]=n.uses[e]=0),n.refs[e]++)}_getNodeRef(n,e,s){if(n.refs[e]<=1)return s;const t=s.clone(),i=(r,a)=>{const o=this.associations.get(r);o!=null&&this.associations.set(a,o);for(const[c,u]of r.children.entries())i(u,a.children[c])};return i(s,t),t.name+="_instance_"+n.uses[e]++,t}_invokeOne(n){const e=Object.values(this.plugins);e.push(this);for(let s=0;s<e.length;s++){const t=n(e[s]);if(t)return t}return null}_invokeAll(n){const e=Object.values(this.plugins);e.unshift(this);const s=[];for(let t=0;t<e.length;t++){const i=n(e[t]);i&&s.push(i)}return s}getDependency(n,e){const s=n+":"+e;let t=this.cache.get(s);if(!t){switch(n){case"scene":t=this.loadScene(e);break;case"node":t=this._invokeOne(function(i){return i.loadNode&&i.loadNode(e)});break;case"mesh":t=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(e)});break;case"accessor":t=this.loadAccessor(e);break;case"bufferView":t=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(e)});break;case"buffer":t=this.loadBuffer(e);break;case"material":t=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(e)});break;case"texture":t=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(e)});break;case"skin":t=this.loadSkin(e);break;case"animation":t=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(e)});break;case"camera":t=this.loadCamera(e);break;default:if(t=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(n,e)}),!t)throw new Error("Unknown type: "+n);break}this.cache.add(s,t)}return t}getDependencies(n){let e=this.cache.get(n);if(!e){const s=this,t=this.json[n+(n==="mesh"?"es":"s")]||[];e=Promise.all(t.map(function(i,r){return s.getDependency(n,r)})),this.cache.add(n,e)}return e}loadBuffer(n){const e=this.json.buffers[n],s=this.fileLoader;if(e.type&&e.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+e.type+" buffer type is not supported.");if(e.uri===void 0&&n===0)return Promise.resolve(this.extensions[g.KHR_BINARY_GLTF].body);const t=this.options;return new Promise(function(i,r){s.load(v.resolveURL(e.uri,t.path),i,void 0,function(){r(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(n){const e=this.json.bufferViews[n];return this.getDependency("buffer",e.buffer).then(function(s){const t=e.byteLength||0,i=e.byteOffset||0;return s.slice(i,i+t)})}loadAccessor(n){const e=this,s=this.json,t=this.json.accessors[n];if(t.bufferView===void 0&&t.sparse===void 0){const r=q[t.type],a=H[t.componentType],o=t.normalized===!0,c=new a(t.count*r);return Promise.resolve(new V(c,r,o))}const i=[];return t.bufferView!==void 0?i.push(this.getDependency("bufferView",t.bufferView)):i.push(null),t.sparse!==void 0&&(i.push(this.getDependency("bufferView",t.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",t.sparse.values.bufferView))),Promise.all(i).then(function(r){const a=r[0],o=q[t.type],c=H[t.componentType],u=c.BYTES_PER_ELEMENT,l=u*o,h=t.byteOffset||0,d=t.bufferView!==void 0?s.bufferViews[t.bufferView].byteStride:void 0,p=t.normalized===!0;let R,m;if(d&&d!==l){const T=Math.floor(h/d),A="InterleavedBuffer:"+t.bufferView+":"+t.componentType+":"+T+":"+t.count;let x=e.cache.get(A);x||(R=new c(a,T*d,t.count*d/u),x=new Ce(R,d/u),e.cache.add(A,x)),m=new sn(x,o,h%d/u,p)}else a===null?R=new c(t.count*o):R=new c(a,h,t.count*o),m=new V(R,o,p);if(t.sparse!==void 0){const T=q.SCALAR,A=H[t.sparse.indices.componentType],x=t.sparse.indices.byteOffset||0,E=t.sparse.values.byteOffset||0,b=new A(r[1],x,t.sparse.count*T),N=new c(r[2],E,t.sparse.count*o);a!==null&&(m=new V(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let M=0,k=b.length;M<k;M++){const P=b[M];if(m.setX(P,N[M*o]),o>=2&&m.setY(P,N[M*o+1]),o>=3&&m.setZ(P,N[M*o+2]),o>=4&&m.setW(P,N[M*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=p}return m})}loadTexture(n){const e=this.json,s=this.options,i=e.textures[n].source,r=e.images[i];let a=this.textureLoader;if(r.uri){const o=s.manager.getHandler(r.uri);o!==null&&(a=o)}return this.loadTextureImage(n,i,a)}loadTextureImage(n,e,s){const t=this,i=this.json,r=i.textures[n],a=i.images[e],o=(a.uri||a.bufferView)+":"+r.sampler;if(this.textureCache[o])return this.textureCache[o];const c=this.loadImageSource(e,s).then(function(u){u.flipY=!1,u.name=r.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);const h=(i.samplers||{})[r.sampler]||{};return u.magFilter=ue[h.magFilter]||J,u.minFilter=ue[h.minFilter]||Te,u.wrapS=le[h.wrapS]||Z,u.wrapT=le[h.wrapT]||Z,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Re&&u.minFilter!==J,t.associations.set(u,{textures:n}),u}).catch(function(){return null});return this.textureCache[o]=c,c}loadImageSource(n,e){const s=this,t=this.json,i=this.options;if(this.sourceCache[n]!==void 0)return this.sourceCache[n].then(l=>l.clone());const r=t.images[n],a=self.URL||self.webkitURL;let o=r.uri||"",c=!1;if(r.bufferView!==void 0)o=s.getDependency("bufferView",r.bufferView).then(function(l){c=!0;const h=new Blob([l],{type:r.mimeType});return o=a.createObjectURL(h),o});else if(r.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+n+" is missing URI and bufferView");const u=Promise.resolve(o).then(function(l){return new Promise(function(h,d){let p=h;e.isImageBitmapLoader===!0&&(p=function(R){const m=new ne(R);m.needsUpdate=!0,h(m)}),e.load(v.resolveURL(l,i.path),p,void 0,d)})}).then(function(l){return c===!0&&a.revokeObjectURL(o),S(l,r),l.userData.mimeType=r.mimeType||Gn(r.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),l});return this.sourceCache[n]=u,u}assignTexture(n,e,s,t){const i=this;return this.getDependency("texture",s.index).then(function(r){if(!r)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(r=r.clone(),r.channel=s.texCoord),i.extensions[g.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[g.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const o=i.associations.get(r);r=i.extensions[g.KHR_TEXTURE_TRANSFORM].extendTexture(r,a),i.associations.set(r,o)}}return t!==void 0&&(r.colorSpace=t),n[e]=r,r})}assignFinalMaterial(n){const e=n.geometry;let s=n.material;const t=e.attributes.tangent===void 0,i=e.attributes.color!==void 0,r=e.attributes.normal===void 0;if(n.isPoints){const a="PointsMaterial:"+s.uuid;let o=this.cache.get(a);o||(o=new Ge,X.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,o.sizeAttenuation=!1,this.cache.add(a,o)),s=o}else if(n.isLine){const a="LineBasicMaterial:"+s.uuid;let o=this.cache.get(a);o||(o=new ve,X.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,this.cache.add(a,o)),s=o}if(t||i||r){let a="ClonedMaterial:"+s.uuid+":";t&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),r&&(a+="flat-shading:");let o=this.cache.get(a);o||(o=s.clone(),i&&(o.vertexColors=!0),r&&(o.flatShading=!0),t&&(o.normalScale&&(o.normalScale.y*=-1),o.clearcoatNormalScale&&(o.clearcoatNormalScale.y*=-1)),this.cache.add(a,o),this.associations.set(o,this.associations.get(s))),s=o}n.material=s}getMaterialType(){return Ee}loadMaterial(n){const e=this,s=this.json,t=this.extensions,i=s.materials[n];let r;const a={},o=i.extensions||{},c=[];if(o[g.KHR_MATERIALS_UNLIT]){const l=t[g.KHR_MATERIALS_UNLIT];r=l.getMaterialType(),c.push(l.extendParams(a,i,e))}else{const l=i.pbrMetallicRoughness||{};if(a.color=new F(1,1,1),a.opacity=1,Array.isArray(l.baseColorFactor)){const h=l.baseColorFactor;a.color.setRGB(h[0],h[1],h[2],w),a.opacity=h[3]}l.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",l.baseColorTexture,U)),a.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,a.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",l.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",l.metallicRoughnessTexture))),r=this._invokeOne(function(h){return h.getMaterialType&&h.getMaterialType(n)}),c.push(Promise.all(this._invokeAll(function(h){return h.extendMaterialParams&&h.extendMaterialParams(n,a)})))}i.doubleSided===!0&&(a.side=Ue);const u=i.alphaMode||W.OPAQUE;if(u===W.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===W.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&r!==G&&(c.push(e.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new pe(1,1),i.normalTexture.scale!==void 0)){const l=i.normalTexture.scale;a.normalScale.set(l,l)}if(i.occlusionTexture!==void 0&&r!==G&&(c.push(e.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&r!==G){const l=i.emissiveFactor;a.emissive=new F().setRGB(l[0],l[1],l[2],w)}return i.emissiveTexture!==void 0&&r!==G&&c.push(e.assignTexture(a,"emissiveMap",i.emissiveTexture,U)),Promise.all(c).then(function(){const l=new r(a);return i.name&&(l.name=i.name),S(l,i),e.associations.set(l,{materials:n}),i.extensions&&O(t,l,i),l})}createUniqueName(n){const e=Ke.sanitizeNodeName(n||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(n){const e=this,s=this.extensions,t=this.primitiveCache;function i(a){return s[g.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(o){return fe(o,a,e)})}const r=[];for(let a=0,o=n.length;a<o;a++){const c=n[a],u=Dn(c),l=t[u];if(l)r.push(l.promise);else{let h;c.extensions&&c.extensions[g.KHR_DRACO_MESH_COMPRESSION]?h=i(c):h=fe(new Be,c,e),t[u]={primitive:c,promise:h},r.push(h)}}return Promise.all(r)}loadMesh(n){const e=this,s=this.json,t=this.extensions,i=s.meshes[n],r=i.primitives,a=[];for(let o=0,c=r.length;o<c;o++){const u=r[o].material===void 0?Pn(this.cache):this.getDependency("material",r[o].material);a.push(u)}return a.push(e.loadGeometries(r)),Promise.all(a).then(function(o){const c=o.slice(0,o.length-1),u=o[o.length-1],l=[];for(let d=0,p=u.length;d<p;d++){const R=u[d],m=r[d];let T;const A=c[d];if(m.mode===L.TRIANGLES||m.mode===L.TRIANGLE_STRIP||m.mode===L.TRIANGLE_FAN||m.mode===void 0)T=i.isSkinnedMesh===!0?new je(R,A):new Ve(R,A),T.isSkinnedMesh===!0&&T.normalizeSkinWeights(),m.mode===L.TRIANGLE_STRIP?T.geometry=oe(T.geometry,he):m.mode===L.TRIANGLE_FAN&&(T.geometry=oe(T.geometry,Q));else if(m.mode===L.LINES)T=new Xe(R,A);else if(m.mode===L.LINE_STRIP)T=new ze(R,A);else if(m.mode===L.LINE_LOOP)T=new qe(R,A);else if(m.mode===L.POINTS)T=new We(R,A);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(T.geometry.morphAttributes).length>0&&kn(T,i),T.name=e.createUniqueName(i.name||"mesh_"+n),S(T,i),m.extensions&&O(t,T,m),e.assignFinalMaterial(T),l.push(T)}for(let d=0,p=l.length;d<p;d++)e.associations.set(l[d],{meshes:n,primitives:d});if(l.length===1)return i.extensions&&O(t,l[0],i),l[0];const h=new z;i.extensions&&O(t,h,i),e.associations.set(h,{meshes:n});for(let d=0,p=l.length;d<p;d++)h.add(l[d]);return h})}loadCamera(n){let e;const s=this.json.cameras[n],t=s[s.type];if(!t){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?e=new Ye(Qe.radToDeg(t.yfov),t.aspectRatio||1,t.znear||1,t.zfar||2e6):s.type==="orthographic"&&(e=new Je(-t.xmag,t.xmag,t.ymag,-t.ymag,t.znear,t.zfar)),s.name&&(e.name=this.createUniqueName(s.name)),S(e,s),Promise.resolve(e)}loadSkin(n){const e=this.json.skins[n],s=[];for(let t=0,i=e.joints.length;t<i;t++)s.push(this._loadNodeShallow(e.joints[t]));return e.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",e.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(t){const i=t.pop(),r=t,a=[],o=[];for(let c=0,u=r.length;c<u;c++){const l=r[c];if(l){a.push(l);const h=new K;i!==null&&h.fromArray(i.array,c*16),o.push(h)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new Ze(a,o)})}loadAnimation(n){const e=this.json,s=this,t=e.animations[n],i=t.name?t.name:"animation_"+n,r=[],a=[],o=[],c=[],u=[];for(let l=0,h=t.channels.length;l<h;l++){const d=t.channels[l],p=t.samplers[d.sampler],R=d.target,m=R.node,T=t.parameters!==void 0?t.parameters[p.input]:p.input,A=t.parameters!==void 0?t.parameters[p.output]:p.output;R.node!==void 0&&(r.push(this.getDependency("node",m)),a.push(this.getDependency("accessor",T)),o.push(this.getDependency("accessor",A)),c.push(p),u.push(R))}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(o),Promise.all(c),Promise.all(u)]).then(function(l){const h=l[0],d=l[1],p=l[2],R=l[3],m=l[4],T=[];for(let x=0,E=h.length;x<E;x++){const b=h[x],N=d[x],M=p[x],k=R[x],P=m[x];if(b===void 0)continue;b.updateMatrix&&b.updateMatrix();const B=s._createAnimationTracks(b,N,M,k,P);if(B)for(let j=0;j<B.length;j++)T.push(B[j])}const A=new $e(i,void 0,T);return S(A,t),A})}createNodeMesh(n){const e=this.json,s=this,t=e.nodes[n];return t.mesh===void 0?null:s.getDependency("mesh",t.mesh).then(function(i){const r=s._getNodeRef(s.meshCache,t.mesh,i);return t.weights!==void 0&&r.traverse(function(a){if(a.isMesh)for(let o=0,c=t.weights.length;o<c;o++)a.morphTargetInfluences[o]=t.weights[o]}),r})}loadNode(n){const e=this.json,s=this,t=e.nodes[n],i=s._loadNodeShallow(n),r=[],a=t.children||[];for(let c=0,u=a.length;c<u;c++)r.push(s.getDependency("node",a[c]));const o=t.skin===void 0?Promise.resolve(null):s.getDependency("skin",t.skin);return Promise.all([i,Promise.all(r),o]).then(function(c){const u=c[0],l=c[1],h=c[2];h!==null&&u.traverse(function(d){d.isSkinnedMesh&&d.bind(h,vn)});for(let d=0,p=l.length;d<p;d++)u.add(l[d]);if(u.userData.pivot!==void 0&&l.length>0){const d=u.userData.pivot,p=l[0];u.pivot=new C().fromArray(d),u.position.x-=d[0],u.position.y-=d[1],u.position.z-=d[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(n){const e=this.json,s=this.extensions,t=this;if(this.nodeCache[n]!==void 0)return this.nodeCache[n];const i=e.nodes[n],r=i.name?t.createUniqueName(i.name):"",a=[],o=t._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(n)});return o&&a.push(o),i.camera!==void 0&&a.push(t.getDependency("camera",i.camera).then(function(c){return t._getNodeRef(t.cameraCache,i.camera,c)})),t._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(n)}).forEach(function(c){a.push(c)}),this.nodeCache[n]=Promise.all(a).then(function(c){let u;if(i.isBone===!0?u=new en:c.length>1?u=new z:c.length===1?u=c[0]:u=new ge,u!==c[0])for(let l=0,h=c.length;l<h;l++)u.add(c[l]);if(i.name&&(u.userData.name=i.name,u.name=r),S(u,i),i.extensions&&O(s,u,i),i.matrix!==void 0){const l=new K;l.fromArray(i.matrix),u.applyMatrix4(l)}else i.translation!==void 0&&u.position.fromArray(i.translation),i.rotation!==void 0&&u.quaternion.fromArray(i.rotation),i.scale!==void 0&&u.scale.fromArray(i.scale);if(!t.associations.has(u))t.associations.set(u,{});else if(i.mesh!==void 0&&t.meshCache.refs[i.mesh]>1){const l=t.associations.get(u);t.associations.set(u,{...l})}return t.associations.get(u).nodes=n,u}),this.nodeCache[n]}loadScene(n){const e=this.extensions,s=this.json.scenes[n],t=this,i=new z;s.name&&(i.name=t.createUniqueName(s.name)),S(i,s),s.extensions&&O(e,i,s);const r=s.nodes||[],a=[];for(let o=0,c=r.length;o<c;o++)a.push(t.getDependency("node",r[o]));return Promise.all(a).then(function(o){for(let u=0,l=o.length;u<l;u++){const h=o[u];h.parent!==null?i.add(nn(h)):i.add(h)}const c=u=>{const l=new Map;for(const[h,d]of t.associations)(h instanceof X||h instanceof ne)&&l.set(h,d);return u.traverse(h=>{const d=t.associations.get(h);d!=null&&l.set(h,d)}),l};return t.associations=c(i),i})}_createAnimationTracks(n,e,s,t,i){const r=[],a=n.name?n.name:n.uuid,o=[];function c(d){d.morphTargetInfluences&&o.push(d.name?d.name:d.uuid)}I[i.path]===I.weights?(c(n),n.isGroup&&n.children.forEach(c)):o.push(a);let u;switch(I[i.path]){case I.weights:u=se;break;case I.rotation:u=ie;break;case I.translation:case I.scale:u=te;break;default:switch(s.itemSize){case 1:u=se;break;case 2:case 3:default:u=te;break}break}const l=t.interpolation!==void 0?Fn[t.interpolation]:xe,h=this._getArrayFromAccessor(s);for(let d=0,p=o.length;d<p;d++){const R=new u(o[d]+"."+I[i.path],e.array,h,l);t.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(R),r.push(R)}return r}_getArrayFromAccessor(n){let e=n.array;if(n.normalized){const s=ee(e.constructor),t=new Float32Array(e.length);for(let i=0,r=e.length;i<r;i++)t[i]=e[i]*s;e=t}return e}_createCubicSplineTrackInterpolant(n){n.createInterpolant=function(s){const t=this instanceof ie?Cn:_e;return new t(this.times,this.values,this.getValueSize()/3,s)},n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Kn(f,n,e){const s=n.attributes,t=new an;if(s.POSITION!==void 0){const a=e.json.accessors[s.POSITION],o=a.min,c=a.max;if(o!==void 0&&c!==void 0){if(t.set(new C(o[0],o[1],o[2]),new C(c[0],c[1],c[2])),a.normalized){const u=ee(H[a.componentType]);t.min.multiplyScalar(u),t.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=n.targets;if(i!==void 0){const a=new C,o=new C;for(let c=0,u=i.length;c<u;c++){const l=i[c];if(l.POSITION!==void 0){const h=e.json.accessors[l.POSITION],d=h.min,p=h.max;if(d!==void 0&&p!==void 0){if(o.setX(Math.max(Math.abs(d[0]),Math.abs(p[0]))),o.setY(Math.max(Math.abs(d[1]),Math.abs(p[1]))),o.setZ(Math.max(Math.abs(d[2]),Math.abs(p[2]))),h.normalized){const R=ee(H[h.componentType]);o.multiplyScalar(R)}a.max(o)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}t.expandByVector(a)}f.boundingBox=t;const r=new cn;t.getCenter(r.center),r.radius=t.min.distanceTo(t.max)/2,f.boundingSphere=r}function fe(f,n,e){const s=n.attributes,t=[];function i(r,a){return e.getDependency("accessor",r).then(function(o){f.setAttribute(a,o)})}for(const r in s){const a=$[r]||r.toLowerCase();a in f.attributes||t.push(i(s[r],a))}if(n.indices!==void 0&&!f.index){const r=e.getDependency("accessor",n.indices).then(function(a){f.setIndex(a)});t.push(r)}return re.workingColorSpace!==w&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${re.workingColorSpace}" not supported.`),S(f,n),Kn(f,n,e),Promise.all(t).then(function(){return n.targets!==void 0?Hn(f,n.targets,e):f})}export{jn as GLTFLoader};
1
+ import{bj as be,bk as Q,bl as he,bm as Le,bn as v,bo as de,aP as y,aR as pe,aE as F,bp as w,bd as U,b9 as Me,bq as Se,ai as ye,w as K,br as we,V as C,Q as me,bs as Ne,u as ge,bt as Ie,bu as Oe,ao as V,bv as Ce,bw as Te,bx as Fe,by as Pe,bz as He,be as J,bA as Re,bB as Z,bC as ke,bD as De,b5 as Ge,bE as X,bF as ve,ad as Ee,aq as Ue,ap as G,bG as Ke,an as Be,bH as je,ab as Ve,bI as Xe,bJ as ze,bK as qe,aC as We,a8 as z,aj as Ye,b3 as Qe,bL as Je,bM as Ze,bN as $e,bO as en,bP as nn,bQ as tn,bR as xe,aX as sn,bf as ne,bS as te,bT as se,bU as ie,bV as re,bW as rn,bX as on,ae as an,af as cn}from"./rr0-sighting-editor.mjs";function oe(f,n){if(n===be)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),f;if(n===Q||n===he){let e=f.getIndex();if(e===null){const r=[],a=f.getAttribute("position");if(a!==void 0){for(let o=0;o<a.count;o++)r.push(o);f.setIndex(r),e=f.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),f}const s=e.count-2,t=[];if(n===Q)for(let r=1;r<=s;r++)t.push(e.getX(0)),t.push(e.getX(r)),t.push(e.getX(r+1));else for(let r=0;r<s;r++)r%2===0?(t.push(e.getX(r)),t.push(e.getX(r+1)),t.push(e.getX(r+2))):(t.push(e.getX(r+2)),t.push(e.getX(r+1)),t.push(e.getX(r)));t.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=f.clone();return i.setIndex(t),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",n),f}class jn extends Le{constructor(n){super(n),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new dn(e)}),this.register(function(e){return new pn(e)}),this.register(function(e){return new bn(e)}),this.register(function(e){return new Ln(e)}),this.register(function(e){return new Mn(e)}),this.register(function(e){return new gn(e)}),this.register(function(e){return new Tn(e)}),this.register(function(e){return new Rn(e)}),this.register(function(e){return new En(e)}),this.register(function(e){return new hn(e)}),this.register(function(e){return new xn(e)}),this.register(function(e){return new mn(e)}),this.register(function(e){return new _n(e)}),this.register(function(e){return new An(e)}),this.register(function(e){return new ln(e)}),this.register(function(e){return new ae(e,g.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new ae(e,g.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new Sn(e)})}load(n,e,s,t){const i=this;let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const c=v.extractUrlBase(n);r=v.resolveURL(c,this.path)}else r=v.extractUrlBase(n);this.manager.itemStart(n);const a=function(c){t?t(c):console.error(c),i.manager.itemError(n),i.manager.itemEnd(n)},o=new de(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(n,function(c){try{i.parse(c,r,function(u){e(u),i.manager.itemEnd(n)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(n){return this.dracoLoader=n,this}setKTX2Loader(n){return this.ktx2Loader=n,this}setMeshoptDecoder(n){return this.meshoptDecoder=n,this}register(n){return this.pluginCallbacks.indexOf(n)===-1&&this.pluginCallbacks.push(n),this}unregister(n){return this.pluginCallbacks.indexOf(n)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(n),1),this}parse(n,e,s,t){let i;const r={},a={},o=new TextDecoder;if(typeof n=="string")i=JSON.parse(n);else if(n instanceof ArrayBuffer)if(o.decode(new Uint8Array(n,0,4))===Ae){try{r[g.KHR_BINARY_GLTF]=new yn(n)}catch(l){t&&t(l);return}i=JSON.parse(r[g.KHR_BINARY_GLTF].content)}else i=JSON.parse(o.decode(n));else i=n;if(i.asset===void 0||i.asset.version[0]<2){t&&t(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new Un(i,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const l=this.pluginCallbacks[u](c);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[l.name]=l,r[l.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const l=i.extensionsUsed[u],h=i.extensionsRequired||[];switch(l){case g.KHR_MATERIALS_UNLIT:r[l]=new fn;break;case g.KHR_DRACO_MESH_COMPRESSION:r[l]=new wn(i,this.dracoLoader);break;case g.KHR_TEXTURE_TRANSFORM:r[l]=new Nn;break;case g.KHR_MESH_QUANTIZATION:r[l]=new In;break;default:h.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}c.setExtensions(r),c.setPlugins(a),c.parse(s,t)}parseAsync(n,e){const s=this;return new Promise(function(t,i){s.parse(n,e,t,i)})}}function un(){let f={};return{get:function(n){return f[n]},add:function(n,e){f[n]=e},remove:function(n){delete f[n]},removeAll:function(){f={}}}}function _(f,n,e){const s=f.json.materials[n];return s.extensions&&s.extensions[e]?s.extensions[e]:null}const g={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class ln{constructor(n){this.parser=n,this.name=g.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const n=this.parser,e=this.parser.json.nodes||[];for(let s=0,t=e.length;s<t;s++){const i=e[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&n._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(n){const e=this.parser,s="light:"+n;let t=e.cache.get(s);if(t)return t;const i=e.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[n];let c;const u=new F(16777215);o.color!==void 0&&u.setRGB(o.color[0],o.color[1],o.color[2],w);const l=o.range!==void 0?o.range:0;switch(o.type){case"directional":c=new ye(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new Se(u),c.distance=l;break;case"spot":c=new Me(u),c.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=o.spot.innerConeAngle!==void 0?o.spot.innerConeAngle:0,o.spot.outerConeAngle=o.spot.outerConeAngle!==void 0?o.spot.outerConeAngle:Math.PI/4,c.angle=o.spot.outerConeAngle,c.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return c.position.set(0,0,0),S(c,o),o.intensity!==void 0&&(c.intensity=o.intensity),c.name=e.createUniqueName(o.name||"light_"+n),t=Promise.resolve(c),e.cache.add(s,t),t}getDependency(n,e){if(n==="light")return this._loadLight(e)}createNodeAttachment(n){const e=this,s=this.parser,i=s.json.nodes[n],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(o){return s._getNodeRef(e.cache,a,o)})}}class fn{constructor(){this.name=g.KHR_MATERIALS_UNLIT}getMaterialType(){return G}extendParams(n,e,s){const t=[];n.color=new F(1,1,1),n.opacity=1;const i=e.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;n.color.setRGB(r[0],r[1],r[2],w),n.opacity=r[3]}i.baseColorTexture!==void 0&&t.push(s.assignTexture(n,"map",i.baseColorTexture,U))}return Promise.all(t)}}class hn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||s.emissiveStrength!==void 0&&(e.emissiveIntensity=s.emissiveStrength),Promise.resolve()}}class dn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_CLEARCOAT}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];if(s.clearcoatFactor!==void 0&&(e.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&t.push(this.parser.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&t.push(this.parser.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(t.push(this.parser.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){const i=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new pe(i,i)}return Promise.all(t)}}class pn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_DISPERSION}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||(e.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}}class mn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_IRIDESCENCE}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.iridescenceFactor!==void 0&&(e.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&t.push(this.parser.assignTexture(e,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(e.iridescenceIOR=s.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&t.push(this.parser.assignTexture(e,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(t)}}class gn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_SHEEN}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];if(e.sheenColor=new F(0,0,0),e.sheenRoughness=0,e.sheen=1,s.sheenColorFactor!==void 0){const i=s.sheenColorFactor;e.sheenColor.setRGB(i[0],i[1],i[2],w)}return s.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&t.push(this.parser.assignTexture(e,"sheenColorMap",s.sheenColorTexture,U)),s.sheenRoughnessTexture!==void 0&&t.push(this.parser.assignTexture(e,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(t)}}class Tn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_TRANSMISSION}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.transmissionFactor!==void 0&&(e.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&t.push(this.parser.assignTexture(e,"transmissionMap",s.transmissionTexture)),Promise.all(t)}}class Rn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_VOLUME}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];e.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&t.push(this.parser.assignTexture(e,"thicknessMap",s.thicknessTexture)),e.attenuationDistance=s.attenuationDistance||1/0;const i=s.attenuationColor||[1,1,1];return e.attenuationColor=new F().setRGB(i[0],i[1],i[2],w),Promise.all(t)}}class En{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_IOR}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);return s===null||(e.ior=s.ior!==void 0?s.ior:1.5,e.ior===0&&(e.ior=1e3)),Promise.resolve()}}class xn{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_SPECULAR}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];e.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&t.push(this.parser.assignTexture(e,"specularIntensityMap",s.specularTexture));const i=s.specularColorFactor||[1,1,1];return e.specularColor=new F().setRGB(i[0],i[1],i[2],w),s.specularColorTexture!==void 0&&t.push(this.parser.assignTexture(e,"specularColorMap",s.specularColorTexture,U)),Promise.all(t)}}class An{constructor(n){this.parser=n,this.name=g.EXT_MATERIALS_BUMP}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return e.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&t.push(this.parser.assignTexture(e,"bumpMap",s.bumpTexture)),Promise.all(t)}}class _n{constructor(n){this.parser=n,this.name=g.KHR_MATERIALS_ANISOTROPY}getMaterialType(n){return _(this.parser,n,this.name)!==null?y:null}extendMaterialParams(n,e){const s=_(this.parser,n,this.name);if(s===null)return Promise.resolve();const t=[];return s.anisotropyStrength!==void 0&&(e.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(e.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&t.push(this.parser.assignTexture(e,"anisotropyMap",s.anisotropyTexture)),Promise.all(t)}}class bn{constructor(n){this.parser=n,this.name=g.KHR_TEXTURE_BASISU}loadTexture(n){const e=this.parser,s=e.json,t=s.textures[n];if(!t.extensions||!t.extensions[this.name])return null;const i=t.extensions[this.name],r=e.options.ktx2Loader;if(!r){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(n,i.source,r)}}class Ln{constructor(n){this.parser=n,this.name=g.EXT_TEXTURE_WEBP}loadTexture(n){const e=this.name,s=this.parser,t=s.json,i=t.textures[n];if(!i.extensions||!i.extensions[e])return null;const r=i.extensions[e],a=t.images[r.source];let o=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(n,r.source,o)}}class Mn{constructor(n){this.parser=n,this.name=g.EXT_TEXTURE_AVIF}loadTexture(n){const e=this.name,s=this.parser,t=s.json,i=t.textures[n];if(!i.extensions||!i.extensions[e])return null;const r=i.extensions[e],a=t.images[r.source];let o=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(n,r.source,o)}}class ae{constructor(n,e){this.name=e,this.parser=n}loadBufferView(n){const e=this.parser.json,s=e.bufferViews[n];if(s.extensions&&s.extensions[this.name]){const t=s.extensions[this.name],i=this.parser.getDependency("buffer",t.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const o=t.byteOffset||0,c=t.byteLength||0,u=t.count,l=t.byteStride,h=new Uint8Array(a,o,c);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(u,l,h,t.mode,t.filter).then(function(d){return d.buffer}):r.ready.then(function(){const d=new ArrayBuffer(u*l);return r.decodeGltfBuffer(new Uint8Array(d),u,l,h,t.mode,t.filter),d})})}else return null}}class Sn{constructor(n){this.name=g.EXT_MESH_GPU_INSTANCING,this.parser=n}createNodeMesh(n){const e=this.parser.json,s=e.nodes[n];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const t=e.meshes[s.mesh];for(const c of t.primitives)if(c.mode!==L.TRIANGLES&&c.mode!==L.TRIANGLE_STRIP&&c.mode!==L.TRIANGLE_FAN&&c.mode!==void 0)return null;const r=s.extensions[this.name].attributes,a=[],o={};for(const c in r)a.push(this.parser.getDependency("accessor",r[c]).then(u=>(o[c]=u,o[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(n)),Promise.all(a).then(c=>{const u=c.pop(),l=u.isGroup?u.children:[u],h=c[0].count,d=[];for(const p of l){const R=new K,m=new C,T=new me,A=new C(1,1,1),x=new we(p.geometry,p.material,h);for(let E=0;E<h;E++)o.TRANSLATION&&m.fromBufferAttribute(o.TRANSLATION,E),o.ROTATION&&T.fromBufferAttribute(o.ROTATION,E),o.SCALE&&A.fromBufferAttribute(o.SCALE,E),x.setMatrixAt(E,R.compose(m,T,A));for(const E in o)if(E==="_COLOR_0"){const b=o[E];x.instanceColor=new Ne(b.array,b.itemSize,b.normalized)}else E!=="TRANSLATION"&&E!=="ROTATION"&&E!=="SCALE"&&p.geometry.setAttribute(E,o[E]);ge.prototype.copy.call(x,p),this.parser.assignFinalMaterial(x),d.push(x)}return u.isGroup?(u.clear(),u.add(...d),u):d[0]}))}}const Ae="glTF",D=12,ce={JSON:1313821514,BIN:5130562};class yn{constructor(n){this.name=g.KHR_BINARY_GLTF,this.content=null,this.body=null;const e=new DataView(n,0,D),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(n.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==Ae)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const t=this.header.length-D,i=new DataView(n,D);let r=0;for(;r<t;){const a=i.getUint32(r,!0);r+=4;const o=i.getUint32(r,!0);if(r+=4,o===ce.JSON){const c=new Uint8Array(n,D+r,a);this.content=s.decode(c)}else if(o===ce.BIN){const c=D+r;this.body=n.slice(c,c+a)}r+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class wn{constructor(n,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=g.KHR_DRACO_MESH_COMPRESSION,this.json=n,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(n,e){const s=this.json,t=this.dracoLoader,i=n.extensions[this.name].bufferView,r=n.extensions[this.name].attributes,a={},o={},c={};for(const u in r){const l=$[u]||u.toLowerCase();a[l]=r[u]}for(const u in n.attributes){const l=$[u]||u.toLowerCase();if(r[u]!==void 0){const h=s.accessors[n.attributes[u]],d=H[h.componentType];c[l]=d.name,o[l]=h.normalized===!0}}return e.getDependency("bufferView",i).then(function(u){return new Promise(function(l,h){t.decodeDracoFile(u,function(d){for(const p in d.attributes){const R=d.attributes[p],m=o[p];m!==void 0&&(R.normalized=m)}l(d)},a,c,w,h)})})}}class Nn{constructor(){this.name=g.KHR_TEXTURE_TRANSFORM}extendTexture(n,e){return(e.texCoord===void 0||e.texCoord===n.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(n=n.clone(),e.texCoord!==void 0&&(n.channel=e.texCoord),e.offset!==void 0&&n.offset.fromArray(e.offset),e.rotation!==void 0&&(n.rotation=e.rotation),e.scale!==void 0&&n.repeat.fromArray(e.scale),n.needsUpdate=!0),n}}class In{constructor(){this.name=g.KHR_MESH_QUANTIZATION}}class _e extends on{constructor(n,e,s,t){super(n,e,s,t)}copySampleValue_(n){const e=this.resultBuffer,s=this.sampleValues,t=this.valueSize,i=n*t*3+t;for(let r=0;r!==t;r++)e[r]=s[i+r];return e}interpolate_(n,e,s,t){const i=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=a*2,c=a*3,u=t-e,l=(s-e)/u,h=l*l,d=h*l,p=n*c,R=p-c,m=-2*d+3*h,T=d-h,A=1-m,x=T-h+l;for(let E=0;E!==a;E++){const b=r[R+E+a],N=r[R+E+o]*u,M=r[p+E+a],k=r[p+E]*u;i[E]=A*b+x*N+m*M+T*k}return i}}const On=new me;class Cn extends _e{interpolate_(n,e,s,t){const i=super.interpolate_(n,e,s,t);return On.fromArray(i).normalize().toArray(i),i}}const L={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},H={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},ue={9728:Re,9729:J,9984:He,9985:Pe,9986:Fe,9987:Te},le={33071:De,33648:ke,10497:Z},q={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},$={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},I={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Fn={CUBICSPLINE:void 0,LINEAR:xe,STEP:tn},W={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Pn(f){return f.DefaultMaterial===void 0&&(f.DefaultMaterial=new Ee({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:rn})),f.DefaultMaterial}function O(f,n,e){for(const s in e.extensions)f[s]===void 0&&(n.userData.gltfExtensions=n.userData.gltfExtensions||{},n.userData.gltfExtensions[s]=e.extensions[s])}function S(f,n){n.extras!==void 0&&(typeof n.extras=="object"?Object.assign(f.userData,n.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+n.extras))}function Hn(f,n,e){let s=!1,t=!1,i=!1;for(let c=0,u=n.length;c<u;c++){const l=n[c];if(l.POSITION!==void 0&&(s=!0),l.NORMAL!==void 0&&(t=!0),l.COLOR_0!==void 0&&(i=!0),s&&t&&i)break}if(!s&&!t&&!i)return Promise.resolve(f);const r=[],a=[],o=[];for(let c=0,u=n.length;c<u;c++){const l=n[c];if(s){const h=l.POSITION!==void 0?e.getDependency("accessor",l.POSITION):f.attributes.position;r.push(h)}if(t){const h=l.NORMAL!==void 0?e.getDependency("accessor",l.NORMAL):f.attributes.normal;a.push(h)}if(i){const h=l.COLOR_0!==void 0?e.getDependency("accessor",l.COLOR_0):f.attributes.color;o.push(h)}}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(o)]).then(function(c){const u=c[0],l=c[1],h=c[2];return s&&(f.morphAttributes.position=u),t&&(f.morphAttributes.normal=l),i&&(f.morphAttributes.color=h),f.morphTargetsRelative=!0,f})}function kn(f,n){if(f.updateMorphTargets(),n.weights!==void 0)for(let e=0,s=n.weights.length;e<s;e++)f.morphTargetInfluences[e]=n.weights[e];if(n.extras&&Array.isArray(n.extras.targetNames)){const e=n.extras.targetNames;if(f.morphTargetInfluences.length===e.length){f.morphTargetDictionary={};for(let s=0,t=e.length;s<t;s++)f.morphTargetDictionary[e[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Dn(f){let n;const e=f.extensions&&f.extensions[g.KHR_DRACO_MESH_COMPRESSION];if(e?n="draco:"+e.bufferView+":"+e.indices+":"+Y(e.attributes):n=f.indices+":"+Y(f.attributes)+":"+f.mode,f.targets!==void 0)for(let s=0,t=f.targets.length;s<t;s++)n+=":"+Y(f.targets[s]);return n}function Y(f){let n="";const e=Object.keys(f).sort();for(let s=0,t=e.length;s<t;s++)n+=e[s]+":"+f[e[s]]+";";return n}function ee(f){switch(f){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Gn(f){return f.search(/\.jpe?g($|\?)/i)>0||f.search(/^data\:image\/jpeg/)===0?"image/jpeg":f.search(/\.webp($|\?)/i)>0||f.search(/^data\:image\/webp/)===0?"image/webp":f.search(/\.ktx2($|\?)/i)>0||f.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const vn=new K;class Un{constructor(n={},e={}){this.json=n,this.extensions={},this.plugins={},this.options=e,this.cache=new un,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,t=-1,i=!1,r=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;const o=a.match(/Version\/(\d+)/);t=s&&o?parseInt(o[1],10):-1,i=a.indexOf("Firefox")>-1,r=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&t<17||i&&r<98?this.textureLoader=new Ie(this.options.manager):this.textureLoader=new Oe(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new de(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(n){this.extensions=n}setPlugins(n){this.plugins=n}parse(n,e){const s=this,t=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(r){return r._markDefs&&r._markDefs()}),Promise.all(this._invokeAll(function(r){return r.beforeRoot&&r.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(r){const a={scene:r[0][t.scene||0],scenes:r[0],animations:r[1],cameras:r[2],asset:t.asset,parser:s,userData:{}};return O(i,a,t),S(a,t),Promise.all(s._invokeAll(function(o){return o.afterRoot&&o.afterRoot(a)})).then(function(){for(const o of a.scenes)o.updateMatrixWorld();n(a)})}).catch(e)}_markDefs(){const n=this.json.nodes||[],e=this.json.skins||[],s=this.json.meshes||[];for(let t=0,i=e.length;t<i;t++){const r=e[t].joints;for(let a=0,o=r.length;a<o;a++)n[r[a]].isBone=!0}for(let t=0,i=n.length;t<i;t++){const r=n[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(s[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(n,e){e!==void 0&&(n.refs[e]===void 0&&(n.refs[e]=n.uses[e]=0),n.refs[e]++)}_getNodeRef(n,e,s){if(n.refs[e]<=1)return s;const t=s.clone(),i=(r,a)=>{const o=this.associations.get(r);o!=null&&this.associations.set(a,o);for(const[c,u]of r.children.entries())i(u,a.children[c])};return i(s,t),t.name+="_instance_"+n.uses[e]++,t}_invokeOne(n){const e=Object.values(this.plugins);e.push(this);for(let s=0;s<e.length;s++){const t=n(e[s]);if(t)return t}return null}_invokeAll(n){const e=Object.values(this.plugins);e.unshift(this);const s=[];for(let t=0;t<e.length;t++){const i=n(e[t]);i&&s.push(i)}return s}getDependency(n,e){const s=n+":"+e;let t=this.cache.get(s);if(!t){switch(n){case"scene":t=this.loadScene(e);break;case"node":t=this._invokeOne(function(i){return i.loadNode&&i.loadNode(e)});break;case"mesh":t=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(e)});break;case"accessor":t=this.loadAccessor(e);break;case"bufferView":t=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(e)});break;case"buffer":t=this.loadBuffer(e);break;case"material":t=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(e)});break;case"texture":t=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(e)});break;case"skin":t=this.loadSkin(e);break;case"animation":t=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(e)});break;case"camera":t=this.loadCamera(e);break;default:if(t=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(n,e)}),!t)throw new Error("Unknown type: "+n);break}this.cache.add(s,t)}return t}getDependencies(n){let e=this.cache.get(n);if(!e){const s=this,t=this.json[n+(n==="mesh"?"es":"s")]||[];e=Promise.all(t.map(function(i,r){return s.getDependency(n,r)})),this.cache.add(n,e)}return e}loadBuffer(n){const e=this.json.buffers[n],s=this.fileLoader;if(e.type&&e.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+e.type+" buffer type is not supported.");if(e.uri===void 0&&n===0)return Promise.resolve(this.extensions[g.KHR_BINARY_GLTF].body);const t=this.options;return new Promise(function(i,r){s.load(v.resolveURL(e.uri,t.path),i,void 0,function(){r(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(n){const e=this.json.bufferViews[n];return this.getDependency("buffer",e.buffer).then(function(s){const t=e.byteLength||0,i=e.byteOffset||0;return s.slice(i,i+t)})}loadAccessor(n){const e=this,s=this.json,t=this.json.accessors[n];if(t.bufferView===void 0&&t.sparse===void 0){const r=q[t.type],a=H[t.componentType],o=t.normalized===!0,c=new a(t.count*r);return Promise.resolve(new V(c,r,o))}const i=[];return t.bufferView!==void 0?i.push(this.getDependency("bufferView",t.bufferView)):i.push(null),t.sparse!==void 0&&(i.push(this.getDependency("bufferView",t.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",t.sparse.values.bufferView))),Promise.all(i).then(function(r){const a=r[0],o=q[t.type],c=H[t.componentType],u=c.BYTES_PER_ELEMENT,l=u*o,h=t.byteOffset||0,d=t.bufferView!==void 0?s.bufferViews[t.bufferView].byteStride:void 0,p=t.normalized===!0;let R,m;if(d&&d!==l){const T=Math.floor(h/d),A="InterleavedBuffer:"+t.bufferView+":"+t.componentType+":"+T+":"+t.count;let x=e.cache.get(A);x||(R=new c(a,T*d,t.count*d/u),x=new Ce(R,d/u),e.cache.add(A,x)),m=new sn(x,o,h%d/u,p)}else a===null?R=new c(t.count*o):R=new c(a,h,t.count*o),m=new V(R,o,p);if(t.sparse!==void 0){const T=q.SCALAR,A=H[t.sparse.indices.componentType],x=t.sparse.indices.byteOffset||0,E=t.sparse.values.byteOffset||0,b=new A(r[1],x,t.sparse.count*T),N=new c(r[2],E,t.sparse.count*o);a!==null&&(m=new V(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let M=0,k=b.length;M<k;M++){const P=b[M];if(m.setX(P,N[M*o]),o>=2&&m.setY(P,N[M*o+1]),o>=3&&m.setZ(P,N[M*o+2]),o>=4&&m.setW(P,N[M*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=p}return m})}loadTexture(n){const e=this.json,s=this.options,i=e.textures[n].source,r=e.images[i];let a=this.textureLoader;if(r.uri){const o=s.manager.getHandler(r.uri);o!==null&&(a=o)}return this.loadTextureImage(n,i,a)}loadTextureImage(n,e,s){const t=this,i=this.json,r=i.textures[n],a=i.images[e],o=(a.uri||a.bufferView)+":"+r.sampler;if(this.textureCache[o])return this.textureCache[o];const c=this.loadImageSource(e,s).then(function(u){u.flipY=!1,u.name=r.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);const h=(i.samplers||{})[r.sampler]||{};return u.magFilter=ue[h.magFilter]||J,u.minFilter=ue[h.minFilter]||Te,u.wrapS=le[h.wrapS]||Z,u.wrapT=le[h.wrapT]||Z,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Re&&u.minFilter!==J,t.associations.set(u,{textures:n}),u}).catch(function(){return null});return this.textureCache[o]=c,c}loadImageSource(n,e){const s=this,t=this.json,i=this.options;if(this.sourceCache[n]!==void 0)return this.sourceCache[n].then(l=>l.clone());const r=t.images[n],a=self.URL||self.webkitURL;let o=r.uri||"",c=!1;if(r.bufferView!==void 0)o=s.getDependency("bufferView",r.bufferView).then(function(l){c=!0;const h=new Blob([l],{type:r.mimeType});return o=a.createObjectURL(h),o});else if(r.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+n+" is missing URI and bufferView");const u=Promise.resolve(o).then(function(l){return new Promise(function(h,d){let p=h;e.isImageBitmapLoader===!0&&(p=function(R){const m=new ne(R);m.needsUpdate=!0,h(m)}),e.load(v.resolveURL(l,i.path),p,void 0,d)})}).then(function(l){return c===!0&&a.revokeObjectURL(o),S(l,r),l.userData.mimeType=r.mimeType||Gn(r.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),l});return this.sourceCache[n]=u,u}assignTexture(n,e,s,t){const i=this;return this.getDependency("texture",s.index).then(function(r){if(!r)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(r=r.clone(),r.channel=s.texCoord),i.extensions[g.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[g.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const o=i.associations.get(r);r=i.extensions[g.KHR_TEXTURE_TRANSFORM].extendTexture(r,a),i.associations.set(r,o)}}return t!==void 0&&(r.colorSpace=t),n[e]=r,r})}assignFinalMaterial(n){const e=n.geometry;let s=n.material;const t=e.attributes.tangent===void 0,i=e.attributes.color!==void 0,r=e.attributes.normal===void 0;if(n.isPoints){const a="PointsMaterial:"+s.uuid;let o=this.cache.get(a);o||(o=new Ge,X.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,o.sizeAttenuation=!1,this.cache.add(a,o)),s=o}else if(n.isLine){const a="LineBasicMaterial:"+s.uuid;let o=this.cache.get(a);o||(o=new ve,X.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,this.cache.add(a,o)),s=o}if(t||i||r){let a="ClonedMaterial:"+s.uuid+":";t&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),r&&(a+="flat-shading:");let o=this.cache.get(a);o||(o=s.clone(),i&&(o.vertexColors=!0),r&&(o.flatShading=!0),t&&(o.normalScale&&(o.normalScale.y*=-1),o.clearcoatNormalScale&&(o.clearcoatNormalScale.y*=-1)),this.cache.add(a,o),this.associations.set(o,this.associations.get(s))),s=o}n.material=s}getMaterialType(){return Ee}loadMaterial(n){const e=this,s=this.json,t=this.extensions,i=s.materials[n];let r;const a={},o=i.extensions||{},c=[];if(o[g.KHR_MATERIALS_UNLIT]){const l=t[g.KHR_MATERIALS_UNLIT];r=l.getMaterialType(),c.push(l.extendParams(a,i,e))}else{const l=i.pbrMetallicRoughness||{};if(a.color=new F(1,1,1),a.opacity=1,Array.isArray(l.baseColorFactor)){const h=l.baseColorFactor;a.color.setRGB(h[0],h[1],h[2],w),a.opacity=h[3]}l.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",l.baseColorTexture,U)),a.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,a.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",l.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",l.metallicRoughnessTexture))),r=this._invokeOne(function(h){return h.getMaterialType&&h.getMaterialType(n)}),c.push(Promise.all(this._invokeAll(function(h){return h.extendMaterialParams&&h.extendMaterialParams(n,a)})))}i.doubleSided===!0&&(a.side=Ue);const u=i.alphaMode||W.OPAQUE;if(u===W.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===W.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&r!==G&&(c.push(e.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new pe(1,1),i.normalTexture.scale!==void 0)){const l=i.normalTexture.scale;a.normalScale.set(l,l)}if(i.occlusionTexture!==void 0&&r!==G&&(c.push(e.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&r!==G){const l=i.emissiveFactor;a.emissive=new F().setRGB(l[0],l[1],l[2],w)}return i.emissiveTexture!==void 0&&r!==G&&c.push(e.assignTexture(a,"emissiveMap",i.emissiveTexture,U)),Promise.all(c).then(function(){const l=new r(a);return i.name&&(l.name=i.name),S(l,i),e.associations.set(l,{materials:n}),i.extensions&&O(t,l,i),l})}createUniqueName(n){const e=Ke.sanitizeNodeName(n||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(n){const e=this,s=this.extensions,t=this.primitiveCache;function i(a){return s[g.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(o){return fe(o,a,e)})}const r=[];for(let a=0,o=n.length;a<o;a++){const c=n[a],u=Dn(c),l=t[u];if(l)r.push(l.promise);else{let h;c.extensions&&c.extensions[g.KHR_DRACO_MESH_COMPRESSION]?h=i(c):h=fe(new Be,c,e),t[u]={primitive:c,promise:h},r.push(h)}}return Promise.all(r)}loadMesh(n){const e=this,s=this.json,t=this.extensions,i=s.meshes[n],r=i.primitives,a=[];for(let o=0,c=r.length;o<c;o++){const u=r[o].material===void 0?Pn(this.cache):this.getDependency("material",r[o].material);a.push(u)}return a.push(e.loadGeometries(r)),Promise.all(a).then(function(o){const c=o.slice(0,o.length-1),u=o[o.length-1],l=[];for(let d=0,p=u.length;d<p;d++){const R=u[d],m=r[d];let T;const A=c[d];if(m.mode===L.TRIANGLES||m.mode===L.TRIANGLE_STRIP||m.mode===L.TRIANGLE_FAN||m.mode===void 0)T=i.isSkinnedMesh===!0?new je(R,A):new Ve(R,A),T.isSkinnedMesh===!0&&T.normalizeSkinWeights(),m.mode===L.TRIANGLE_STRIP?T.geometry=oe(T.geometry,he):m.mode===L.TRIANGLE_FAN&&(T.geometry=oe(T.geometry,Q));else if(m.mode===L.LINES)T=new Xe(R,A);else if(m.mode===L.LINE_STRIP)T=new ze(R,A);else if(m.mode===L.LINE_LOOP)T=new qe(R,A);else if(m.mode===L.POINTS)T=new We(R,A);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(T.geometry.morphAttributes).length>0&&kn(T,i),T.name=e.createUniqueName(i.name||"mesh_"+n),S(T,i),m.extensions&&O(t,T,m),e.assignFinalMaterial(T),l.push(T)}for(let d=0,p=l.length;d<p;d++)e.associations.set(l[d],{meshes:n,primitives:d});if(l.length===1)return i.extensions&&O(t,l[0],i),l[0];const h=new z;i.extensions&&O(t,h,i),e.associations.set(h,{meshes:n});for(let d=0,p=l.length;d<p;d++)h.add(l[d]);return h})}loadCamera(n){let e;const s=this.json.cameras[n],t=s[s.type];if(!t){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?e=new Ye(Qe.radToDeg(t.yfov),t.aspectRatio||1,t.znear||1,t.zfar||2e6):s.type==="orthographic"&&(e=new Je(-t.xmag,t.xmag,t.ymag,-t.ymag,t.znear,t.zfar)),s.name&&(e.name=this.createUniqueName(s.name)),S(e,s),Promise.resolve(e)}loadSkin(n){const e=this.json.skins[n],s=[];for(let t=0,i=e.joints.length;t<i;t++)s.push(this._loadNodeShallow(e.joints[t]));return e.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",e.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(t){const i=t.pop(),r=t,a=[],o=[];for(let c=0,u=r.length;c<u;c++){const l=r[c];if(l){a.push(l);const h=new K;i!==null&&h.fromArray(i.array,c*16),o.push(h)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new Ze(a,o)})}loadAnimation(n){const e=this.json,s=this,t=e.animations[n],i=t.name?t.name:"animation_"+n,r=[],a=[],o=[],c=[],u=[];for(let l=0,h=t.channels.length;l<h;l++){const d=t.channels[l],p=t.samplers[d.sampler],R=d.target,m=R.node,T=t.parameters!==void 0?t.parameters[p.input]:p.input,A=t.parameters!==void 0?t.parameters[p.output]:p.output;R.node!==void 0&&(r.push(this.getDependency("node",m)),a.push(this.getDependency("accessor",T)),o.push(this.getDependency("accessor",A)),c.push(p),u.push(R))}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(o),Promise.all(c),Promise.all(u)]).then(function(l){const h=l[0],d=l[1],p=l[2],R=l[3],m=l[4],T=[];for(let x=0,E=h.length;x<E;x++){const b=h[x],N=d[x],M=p[x],k=R[x],P=m[x];if(b===void 0)continue;b.updateMatrix&&b.updateMatrix();const B=s._createAnimationTracks(b,N,M,k,P);if(B)for(let j=0;j<B.length;j++)T.push(B[j])}const A=new $e(i,void 0,T);return S(A,t),A})}createNodeMesh(n){const e=this.json,s=this,t=e.nodes[n];return t.mesh===void 0?null:s.getDependency("mesh",t.mesh).then(function(i){const r=s._getNodeRef(s.meshCache,t.mesh,i);return t.weights!==void 0&&r.traverse(function(a){if(a.isMesh)for(let o=0,c=t.weights.length;o<c;o++)a.morphTargetInfluences[o]=t.weights[o]}),r})}loadNode(n){const e=this.json,s=this,t=e.nodes[n],i=s._loadNodeShallow(n),r=[],a=t.children||[];for(let c=0,u=a.length;c<u;c++)r.push(s.getDependency("node",a[c]));const o=t.skin===void 0?Promise.resolve(null):s.getDependency("skin",t.skin);return Promise.all([i,Promise.all(r),o]).then(function(c){const u=c[0],l=c[1],h=c[2];h!==null&&u.traverse(function(d){d.isSkinnedMesh&&d.bind(h,vn)});for(let d=0,p=l.length;d<p;d++)u.add(l[d]);if(u.userData.pivot!==void 0&&l.length>0){const d=u.userData.pivot,p=l[0];u.pivot=new C().fromArray(d),u.position.x-=d[0],u.position.y-=d[1],u.position.z-=d[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(n){const e=this.json,s=this.extensions,t=this;if(this.nodeCache[n]!==void 0)return this.nodeCache[n];const i=e.nodes[n],r=i.name?t.createUniqueName(i.name):"",a=[],o=t._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(n)});return o&&a.push(o),i.camera!==void 0&&a.push(t.getDependency("camera",i.camera).then(function(c){return t._getNodeRef(t.cameraCache,i.camera,c)})),t._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(n)}).forEach(function(c){a.push(c)}),this.nodeCache[n]=Promise.all(a).then(function(c){let u;if(i.isBone===!0?u=new en:c.length>1?u=new z:c.length===1?u=c[0]:u=new ge,u!==c[0])for(let l=0,h=c.length;l<h;l++)u.add(c[l]);if(i.name&&(u.userData.name=i.name,u.name=r),S(u,i),i.extensions&&O(s,u,i),i.matrix!==void 0){const l=new K;l.fromArray(i.matrix),u.applyMatrix4(l)}else i.translation!==void 0&&u.position.fromArray(i.translation),i.rotation!==void 0&&u.quaternion.fromArray(i.rotation),i.scale!==void 0&&u.scale.fromArray(i.scale);if(!t.associations.has(u))t.associations.set(u,{});else if(i.mesh!==void 0&&t.meshCache.refs[i.mesh]>1){const l=t.associations.get(u);t.associations.set(u,{...l})}return t.associations.get(u).nodes=n,u}),this.nodeCache[n]}loadScene(n){const e=this.extensions,s=this.json.scenes[n],t=this,i=new z;s.name&&(i.name=t.createUniqueName(s.name)),S(i,s),s.extensions&&O(e,i,s);const r=s.nodes||[],a=[];for(let o=0,c=r.length;o<c;o++)a.push(t.getDependency("node",r[o]));return Promise.all(a).then(function(o){for(let u=0,l=o.length;u<l;u++){const h=o[u];h.parent!==null?i.add(nn(h)):i.add(h)}const c=u=>{const l=new Map;for(const[h,d]of t.associations)(h instanceof X||h instanceof ne)&&l.set(h,d);return u.traverse(h=>{const d=t.associations.get(h);d!=null&&l.set(h,d)}),l};return t.associations=c(i),i})}_createAnimationTracks(n,e,s,t,i){const r=[],a=n.name?n.name:n.uuid,o=[];function c(d){d.morphTargetInfluences&&o.push(d.name?d.name:d.uuid)}I[i.path]===I.weights?(c(n),n.isGroup&&n.children.forEach(c)):o.push(a);let u;switch(I[i.path]){case I.weights:u=se;break;case I.rotation:u=ie;break;case I.translation:case I.scale:u=te;break;default:switch(s.itemSize){case 1:u=se;break;case 2:case 3:default:u=te;break}break}const l=t.interpolation!==void 0?Fn[t.interpolation]:xe,h=this._getArrayFromAccessor(s);for(let d=0,p=o.length;d<p;d++){const R=new u(o[d]+"."+I[i.path],e.array,h,l);t.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(R),r.push(R)}return r}_getArrayFromAccessor(n){let e=n.array;if(n.normalized){const s=ee(e.constructor),t=new Float32Array(e.length);for(let i=0,r=e.length;i<r;i++)t[i]=e[i]*s;e=t}return e}_createCubicSplineTrackInterpolant(n){n.createInterpolant=function(s){const t=this instanceof ie?Cn:_e;return new t(this.times,this.values,this.getValueSize()/3,s)},n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Kn(f,n,e){const s=n.attributes,t=new an;if(s.POSITION!==void 0){const a=e.json.accessors[s.POSITION],o=a.min,c=a.max;if(o!==void 0&&c!==void 0){if(t.set(new C(o[0],o[1],o[2]),new C(c[0],c[1],c[2])),a.normalized){const u=ee(H[a.componentType]);t.min.multiplyScalar(u),t.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=n.targets;if(i!==void 0){const a=new C,o=new C;for(let c=0,u=i.length;c<u;c++){const l=i[c];if(l.POSITION!==void 0){const h=e.json.accessors[l.POSITION],d=h.min,p=h.max;if(d!==void 0&&p!==void 0){if(o.setX(Math.max(Math.abs(d[0]),Math.abs(p[0]))),o.setY(Math.max(Math.abs(d[1]),Math.abs(p[1]))),o.setZ(Math.max(Math.abs(d[2]),Math.abs(p[2]))),h.normalized){const R=ee(H[h.componentType]);o.multiplyScalar(R)}a.max(o)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}t.expandByVector(a)}f.boundingBox=t;const r=new cn;t.getCenter(r.center),r.radius=t.min.distanceTo(t.max)/2,f.boundingSphere=r}function fe(f,n,e){const s=n.attributes,t=[];function i(r,a){return e.getDependency("accessor",r).then(function(o){f.setAttribute(a,o)})}for(const r in s){const a=$[r]||r.toLowerCase();a in f.attributes||t.push(i(s[r],a))}if(n.indices!==void 0&&!f.index){const r=e.getDependency("accessor",n.indices).then(function(a){f.setIndex(a)});t.push(r)}return re.workingColorSpace!==w&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${re.workingColorSpace}" not supported.`),S(f,n),Kn(f,n,e),Promise.all(t).then(function(){return n.targets!==void 0?Hn(f,n.targets,e):f})}export{jn as GLTFLoader};
@@ -1 +1 @@
1
- import{P as K,a as W}from"./PictureFetch-X3UpM6JV.js";class I{static SIZE=360;static LIGHT=230;static DARK=80;static STANDS_OUT=12;static GROUND=.025;static WHOLE_GROUND=.08;static GROWN_DRIFT=.02;static INSIDE_WEIGHT=.4;static LINE_LENGTH=12;static LINE_FILL=.2;static STANDING_FULLY=60;static NEAREST=.08;static REACH=.08;static RING=[.04,.08];static SHARE_OF_PEAK=.15;static MAX_PAIRS=6e6;static find(a,s){const e=Math.min(1,I.SIZE/Math.max(a.width,a.height)),o=Math.max(1,Math.round(a.width*e)),i=Math.max(1,Math.round(a.height*e)),r=I.luminanceOf(a,o,i),n=I.blurred(r,o,i,Math.max(4,Math.round(Math.hypot(o,i)*I.GROUND))),c=[],l=[];for(let R=0;R<i;R++)for(let m=0;m<o;m++){const L=R*o+m,M=r[L];M>=I.LIGHT?c.push({x:m,y:R,weight:(M-I.LIGHT+5)/30}):n[L]<I.DARK&&M-n[L]>I.STANDS_OUT&&l.push({x:m,y:R,weight:Math.min(1,(M-n[L])/I.STANDING_FULLY)})}if(l.splice(0,l.length,...I.withoutLines(l,o,i)),c.splice(0,c.length,...I.withoutLines(c,o,i)),l.push(...I.insides(l,c,o,i)),c.length===0||l.length===0)return;const t=I.NEAREST*Math.hypot(o,i),f=I.peak(I.vote(c,l,o,i,t),o,i);if(f.value<=0||f.sharpness<s)return;const u={x:f.x/2,y:f.y/2},{pairs:y,matched:x}=I.pairsAt(u,c,l,r,n,o,i,t);if(y.length===0)return;const p=1/e,A=R=>({...R,x:(R.x+.5)*p-.5,y:(R.y+.5)*p-.5,radius:R.radius*p});return{centre:{x:(u.x+.5)*p-.5,y:(u.y+.5)*p-.5},pairs:y.map(R=>({ghost:A(R.ghost),light:A(R.light),residualPx:R.residualPx*p})),sharpness:f.sharpness,matched:x}}static vote(a,s,e,o,i){const r=new Float32Array(2*e*2*o),n=Math.max(1,Math.ceil(Math.sqrt(a.length*s.length/I.MAX_PAIRS))),c=i*i;for(let l=0;l<a.length;l+=n){const t=a[l];for(let f=0;f<s.length;f+=n){const u=s[f],y=u.x-t.x,x=u.y-t.y;y*y+x*x<c||(r[(t.y+u.y)*2*e+t.x+u.x]+=t.weight*u.weight)}}return r}static peak(a,s,e){const o=2*s,i=2*e,r=I.blurred(a,o,i,3);let n={x:0,y:0,value:0,sharpness:0};const c=I.REACH*Math.hypot(o,i);for(let y=Math.max(0,Math.round(i/2-c));y<Math.min(i,Math.round(i/2+c));y++)for(let x=Math.max(0,Math.round(o/2-c));x<Math.min(o,Math.round(o/2+c));x++){if(Math.hypot(x-o/2,y-i/2)>c)continue;const p=r[y*o+x];p>n.value&&(n={x,y,value:p,sharpness:0})}const l=Math.hypot(o,i),t=I.RING[0]*l,f=I.RING[1]*l;let u=0;for(let y=Math.max(0,Math.floor(n.y-f));y<Math.min(i,Math.ceil(n.y+f));y++)for(let x=Math.max(0,Math.floor(n.x-f));x<Math.min(o,Math.ceil(n.x+f));x++){const p=Math.hypot(x-n.x,y-n.y);p>t&&p<f&&(u=Math.max(u,r[y*o+x]))}return n.sharpness=u>0?n.value/u:1/0,n}static pairsAt(a,s,e,o,i,r,n,c){const l=new Float32Array(r*n);for(const M of s)l[M.y*r+M.x]=M.weight;const t=M=>{const E=Math.round(2*a.x-M.x),O=Math.round(2*a.y-M.y);let P=0;for(let N=-2;N<=2;N++)for(let C=-2;C<=2;C++){const T=E+C,h=O+N;T>=0&&h>=0&&T<r&&h<n&&(P+=l[h*r+T])}return M.weight*P},f=new Float32Array(r*n),u=new Uint8Array(r*n);for(const M of e){if(Math.hypot(M.x-(2*a.x-M.x),M.y-(2*a.y-M.y))<c)continue;const E=t(M);E<=0||(u[M.y*r+M.x]=1,f[M.y*r+M.x]=E)}let y;const x=()=>y??=I.blurred(o,r,n,Math.max(4,Math.round(Math.hypot(r,n)*I.WHOLE_GROUND))),p=new Uint8Array(r*n),A=[];for(let M=0;M<u.length;M++){if(!u[M]||p[M])continue;const E=[],O=[M];for(p[M]=1;O.length>0;){const h=O.pop();E.push(h);const d=h%r,S=(h-d)/r;for(let k=-2;k<=2;k++)for(let D=-2;D<=2;D++){const H=d+D,v=S+k;if(H<0||v<0||H>=r||v>=n)continue;const b=v*r+H;u[b]&&!p[b]&&(p[b]=1,O.push(b))}}if(E.length<3)continue;const P=E.reduce((h,d)=>h+f[d],0),N=I.spotOf(I.whole(E,o,x(),r,n),o,x(),r),C=s.filter(h=>Math.hypot(h.x-(2*a.x-N.x),h.y-(2*a.y-N.y))<=N.radius+2);if(C.length===0)continue;const T=I.spotOf(C.map(h=>h.y*r+h.x),o,i,r);A.push({pair:{ghost:N,light:T,residualPx:Math.hypot(N.x+T.x-2*a.x,N.y+T.y-2*a.y)},vote:P,size:E.length})}const R=A.reduce((M,E)=>Math.max(M,E.vote),0),m=[];let L=0;for(const{pair:M,size:E}of A.filter(O=>O.vote>=I.SHARE_OF_PEAK*R).sort((O,P)=>P.vote-O.vote))L+=E,!m.some(O=>Math.hypot(O.ghost.x-M.ghost.x,O.ghost.y-M.ghost.y)<Math.max(O.ghost.radius,M.ghost.radius))&&m.push(M);return{pairs:m.slice(0,12),matched:L}}static withoutLines(a,s,e){const o=new Int32Array(s*e).fill(-1);a.forEach((n,c)=>o[n.y*s+n.x]=c);const i=new Uint8Array(a.length),r=[];for(let n=0;n<a.length;n++){if(i[n])continue;const c=[n];i[n]=1;let l=1/0,t=-1/0,f=1/0,u=-1/0;for(let x=0;x<c.length;x++){const{x:p,y:A}=a[c[x]];l=Math.min(l,p),t=Math.max(t,p),f=Math.min(f,A),u=Math.max(u,A);for(let R=-1;R<=1;R++)for(let m=-1;m<=1;m++){const L=p+m,M=A+R;if(L<0||M<0||L>=s||M>=e)continue;const E=o[M*s+L];E>=0&&!i[E]&&(i[E]=1,c.push(E))}}const y=c.length/((t-l+1)*(u-f+1));if(!(c.length>=I.LINE_LENGTH&&y<I.LINE_FILL))for(const x of c)r.push(a[x])}return r}static insides(a,s,e,o){const i=new Uint8Array(e*o);for(const t of a)i[t.y*e+t.x]=1;for(const t of s)i[t.y*e+t.x]=2;const r=new Uint8Array(e*o),n=[],c=t=>{i[t]||r[t]||(r[t]=1,n.push(t))};for(let t=0;t<e;t++)c(t),c((o-1)*e+t);for(let t=0;t<o;t++)c(t*e),c(t*e+e-1);for(;n.length>0;){const t=n.pop(),f=t%e,u=(t-f)/e;f>0&&c(t-1),f<e-1&&c(t+1),u>0&&c(t-e),u<o-1&&c(t+e)}const l=[];for(let t=0;t<i.length;t++)!i[t]&&!r[t]&&l.push({x:t%e,y:Math.floor(t/e),weight:I.INSIDE_WEIGHT});return l}static whole(a,s,e,o,i){const r=4*Math.sqrt(a.length/Math.PI)+.06*Math.hypot(o,i);let n=0,c=0;for(const A of a)n+=A%o,c+=Math.floor(A/o);n/=a.length,c/=a.length;const l=A=>s[A]<I.LIGHT&&s[A]-e[A]>I.STANDS_OUT/2,t=new Uint8Array(o*i),f=a.filter(l);for(const A of f)t[A]=1;const u=[...f];for(;f.length>0;){const A=f.pop(),R=A%o,m=(A-R)/o;for(const[L,M]of[[1,0],[-1,0],[0,1],[0,-1]]){const E=R+L,O=m+M;if(E<0||O<0||E>=o||O>=i)continue;const P=O*o+E;t[P]||!l(P)||Math.hypot(E-n,O-c)>r||(t[P]=1,u.push(P),f.push(P))}}if(u.length<a.length)return a;let y=0,x=0;for(const A of u)y+=A%o,x+=Math.floor(A/o);return Math.hypot(y/u.length-n,x/u.length-c)<=Math.sqrt(a.length/Math.PI)+I.GROWN_DRIFT*Math.hypot(o,i)?u:a}static spotOf(a,s,e,o){let i=0,r=0,n=0,c=0,l=0;for(const f of a){const u=Math.max(1,s[f]-e[f]);i+=u,r+=u*(f%o),n+=u*Math.floor(f/o),c=Math.max(c,s[f]),l+=e[f]}const t=l/a.length;return{x:r/i,y:n/i,peak:c,contrast:c-t,background:t,radius:Math.sqrt(a.length/Math.PI),color:[c,c,c]}}static luminanceOf(a,s,e){const o=new Float32Array(s*e),i=new Float32Array(s*e),r=s/a.width,n=e/a.height;for(let c=0;c<a.height;c++){const l=Math.min(e-1,Math.floor(c*n));for(let t=0;t<a.width;t++){const f=(c*a.width+t)*4,u=l*s+Math.min(s-1,Math.floor(t*r));o[u]+=.2126*a.data[f]+.7152*a.data[f+1]+.0722*a.data[f+2],i[u]++}}for(let c=0;c<o.length;c++)o[c]/=Math.max(1,i[c]);return o}static blurred(a,s,e,o){const i=new Float64Array((s+1)*(e+1));for(let n=0;n<e;n++){let c=0;for(let l=0;l<s;l++)c+=a[n*s+l],i[(n+1)*(s+1)+l+1]=i[n*(s+1)+l+1]+c}const r=new Float32Array(s*e);for(let n=0;n<e;n++){const c=Math.max(0,n-o),l=Math.min(e,n+o+1);for(let t=0;t<s;t++){const f=Math.max(0,t-o),u=Math.min(s,t+o+1),y=i[l*(s+1)+u]-i[c*(s+1)+u]-i[l*(s+1)+f]+i[c*(s+1)+f];r[n*s+t]=y/((u-f)*(l-c))}}return r}}class g{static OTHER_SCALES=[-2,-1.8,-1.6,-1.4,-1.3,-1.2,-1.1,-.9,-.8,-.7,-.6,-.5,-.4,-.3,.3,.4,.5,.6,.7,.8];static DARK=80;static LARGE_LIGHT_CONTRAST=80;static DOMINATED=.4;static GRID_STEP=2;static GRID_REACH=.12;static ABOVE_CHANCE=1.5;static GREAT_LIGHTS=3;static LONE_REACH=.15;static GROUND_ALIKE=40;static EVEN_ALIKE=20;static CHANCE_ALONE=.5;static CROPPED=.04;static GLARE_SIZE=2;static GLARE_REACH=2.5;static SATURATED=250;static LOST_IN_GLARE=40;static OUT_OF_GLARE=2.5;static SPOT_GHOST_CONTRAST=40;static SHARP_MIRROR=1.5;static SHAPE_MATCHED=25;static MAX_SPOTS=2e3;static find(a){const s=g.searched(a);return{...s,pairs:s.pairs.map(e=>({...e,light:g.glaringOver(e.light,s.lights)}))}}static searched(a){const{width:s,height:e}=a,o=Math.hypot(s,e),i=g.spotsOf(a),r=i.reduce((h,d)=>Math.max(h,d.peak),0),n=Math.min(235,.9*r),c=g.linesOfLight(a,n),l=i.filter(h=>!c[Math.round(h.y)*s+Math.round(h.x)]),t=l.filter(h=>h.peak>=n&&(h.radius<=.025*o?h.contrast>=40:h.contrast>=g.LARGE_LIGHT_CONTRAST)),f=t.reduce((h,d)=>Math.max(h,d.radius),0),u=l.filter(h=>t.includes(h)?h.radius<=g.DOMINATED*f&&h.contrast>=g.LARGE_LIGHT_CONTRAST:h.background<g.DARK&&h.peak>=2*h.background),y={width:s,height:e,lights:t,spots:l,pairs:[],confidence:"none"},x=()=>g.mirrored(a,t,l);if(t.length===0||u.length===0)return x()??y;const p=.006*o,A=h=>h.reduce((d,S)=>d+Math.max(0,1-S.residualPx/p)**2,0),R=g.GRID_STEP*p,m=g.GRID_REACH*o,L=[];for(let h=e/2-m;h<=e/2+m;h+=R)for(let d=s/2-m;d<=s/2+m;d+=R)L.push({x:d,y:h});const M=(h,d=u)=>{let S;for(const k of[...g.voted(d,t,h,s,e),...h===-1?L:[]]){const D=g.fit(d,t,k,h,p);if(!D)continue;const H=A(D.pairs);(!S||H>S.score)&&(S={...D,scale:h,score:H})}return S};let E=M(-1);for(const h of g.OTHER_SCALES){const d=M(h),S=E?.pairs.length??0;d&&d.pairs.length>=Math.max(3,1.5*S,S+2)&&d.score>(E?.score??0)&&(E=d)}let O;if(E&&E.pairs.length>=2){const h=E.scale,d=[[-1,1],[1,-1],[-1,-1]].map(([k,D])=>M(h,u.map(H=>({...H,x:k<0?s-H.x:H.x,y:D<0?e-H.y:H.y})))?.score??0),S=d.reduce((k,D)=>k+D,0)/d.length;if(E.score>g.ABOVE_CHANCE*S){const k=Math.hypot(E.centre.x-s/2,E.centre.y-e/2)/o;if(O={width:s,height:e,lights:t,spots:l,pairs:E.pairs,centre:E.centre,scale:E.scale,cropped:k>g.CROPPED,confidence:E.pairs.length>=3?"high":"low"},O.confidence==="high")return O}}const P=l.filter(h=>u.includes(h)||h.contrast>=g.LARGE_LIGHT_CONTRAST&&h.peak>=Math.min(g.SATURATED,1.5*h.background)),N=x(),C=[...t,...l.filter(h=>h.peak>=g.SATURATED&&!t.includes(h))],T=()=>g.loneGhost(l,C,P,s,e,p,t);if(N&&N.pairs.length===1){const h=T(),d=S=>Math.hypot(S.centre.x-s/2,S.centre.y-e/2);return h&&d(h)<d(N)?h:N}return N??O??T()??y}static mirrored(a,s,e){const o=I.find(a,g.SHARP_MIRROR);if(!o)return;const{width:i,height:r}=a,n=Math.hypot(i,r),c=g.atAxis(e,s,o.centre,.006*n),l=c.length>=2?[...c,...o.pairs.filter(u=>!c.some(y=>Math.hypot(y.ghost.x-u.ghost.x,y.ghost.y-u.ghost.y)<=u.ghost.radius))]:o.pairs,t=o.centre,f=Math.hypot(t.x-i/2,t.y-r/2)/n;return{width:i,height:r,lights:s,spots:e,pairs:l,centre:t,scale:-1,cropped:f>g.CROPPED,confidence:l.length>=2||o.matched>=g.SHAPE_MATCHED?"high":"low"}}static glaringOver(a,s){let e=a;for(const o of s)o.radius>=g.GLARE_SIZE*a.radius&&o.radius>e.radius&&Math.hypot(o.x-a.x,o.y-a.y)<=g.GLARE_REACH*o.radius&&(e=o);return e}static atAxis(a,s,e,o){const i=[];for(const r of a.filter(n=>n.contrast>=g.SPOT_GHOST_CONTRAST)){const n={x:2*e.x-r.x,y:2*e.y-r.y};let c;for(const l of s){if(!g.canBeGhostOf(r,l))continue;const t=Math.max(0,Math.hypot(l.x-n.x,l.y-n.y)-l.radius);t<=o&&(!c||t<c.beyond)&&(c={light:l,beyond:t})}!c||!g.apart(r,c.light)||i.some(l=>Math.hypot(l.ghost.x-r.x,l.ghost.y-r.y)<Math.max(2,l.ghost.radius,r.radius))||i.push({ghost:r,light:{...c.light,...n},residualPx:c.beyond})}return i.filter(r=>!i.some(n=>n!==r&&n.ghost.radius<r.ghost.radius&&Math.hypot(n.ghost.x-r.ghost.x,n.ghost.y-r.ghost.y)<r.ghost.radius))}static loneGhost(a,s,e,o,i,r,n){const c=Math.hypot(o,i),l=[...s].sort((p,A)=>A.contrast*A.radius**2-p.contrast*p.radius**2).slice(0,g.GREAT_LIGHTS);let t;for(const p of l){const A={x:o-p.x,y:i-p.y},R=e.filter(m=>m!==p&&g.canBeGhostOf(m,p)&&Math.hypot(m.x-A.x,m.y-A.y)<=g.LONE_REACH*c&&g.apart(m,p));for(const m of R){const L=e.filter(O=>O.contrast>=m.contrast&&g.canBeGhostOf(O,p)&&g.groundsAlike(O,m)).length,M=Math.hypot(m.x-A.x,m.y-A.y)+r,E=L*Math.PI*M**2/(o*i);(!t||E<t.chance)&&(t={pair:{ghost:m,light:p,residualPx:0},chance:E})}}if(!t||t.chance>=g.CHANCE_ALONE)return;const{ghost:f,light:u}=t.pair,y={x:(f.x+u.x)/2,y:(f.y+u.y)/2},x=Math.hypot(y.x-o/2,y.y-i/2)/c;return{width:o,height:i,lights:n,spots:a,pairs:[t.pair],centre:y,scale:-1,cropped:x>g.CROPPED,confidence:"low"}}static groundsAlike(a,s){const e=Math.max(g.EVEN_ALIKE,a.spread??0,s.spread??0);return Math.abs(a.background-s.background)<=g.GROUND_ALIKE&&Math.abs((a.spread??0)-(s.spread??0))<=e/2}static lightCells=new WeakMap;static lightsNear(a,s){let e=g.lightCells.get(a);if(!e||e.cell!==s){const i=new Map;for(const r of a){const n=g.cellKey(Math.floor(r.x/s),Math.floor(r.y/s)),c=i.get(n);c?c.push(r):i.set(n,[r])}e={cell:s,cells:i},g.lightCells.set(a,e)}const{cells:o}=e;return(i,r)=>{const n=Math.floor(i/s),c=Math.floor(r/s),l=[];for(let t=-1;t<=1;t++)for(let f=-1;f<=1;f++){const u=o.get(g.cellKey(n+t,c+f));u&&l.push(...u)}return l}}static cellKey(a,s){return(a+5e4)*1e5+s+5e4}static linesOfLight(a,s){const{width:e,height:o,data:i}=a,r=[];for(let c=0;c<o;c++)for(let l=0;l<e;l++){const t=(c*e+l)*4;.2126*i[t]+.7152*i[t+1]+.0722*i[t+2]>=s&&r.push({x:l,y:c})}const n=new Uint8Array(e*o);for(const c of r)n[c.y*e+c.x]=1;for(const c of I.withoutLines(r,e,o))n[c.y*e+c.x]=0;return n}static apart(a,s){return Math.hypot(a.x-s.x,a.y-s.y)>=Math.max(4*a.radius,g.OUT_OF_GLARE*s.radius)}static canBeGhostOf(a,s){return a!==s&&(a.peak<s.peak-5||a.radius<=g.DOMINATED*s.radius)}static voted(a,s,e,o,i){const r=.01*Math.hypot(o,i),n=new Map;for(const l of a)for(const t of s){if(!g.canBeGhostOf(l,t))continue;const f=(l.x-e*t.x)/(1-e),u=(l.y-e*t.y)/(1-e);if(f<-.25*o||f>1.25*o||u<-.25*i||u>1.25*i||!g.apart(l,t))continue;const y=`${Math.floor(f/r)},${Math.floor(u/r)}`,x=n.get(y)??{count:0,x:0,y:0};x.count++,x.x+=f,x.y+=u,n.set(y,x)}const c=[...n.entries()].map(([l,t])=>{const[f,u]=l.split(",").map(Number);let y=0,x=0,p=0;for(let A=-1;A<=1;A++)for(let R=-1;R<=1;R++){const m=n.get(`${f+A},${u+R}`);m&&(y+=m.count,x+=m.x,p+=m.y)}return{count:y,centre:{x:x/y,y:p/y},own:t.count}});return c.sort((l,t)=>t.count-l.count||t.own-l.own),c.filter(l=>l.count>=1).slice(0,60).map(l=>l.centre)}static fit(a,s,e,o,i){let r=e,n=[];const c=g.lightsNear(s,3*i);for(const t of[3,2,1,1]){const f=[];for(const y of a){const x=r.x+(y.x-r.x)/o,p=r.y+(y.y-r.y)/o;let A,R=1/0;for(const m of c(x,p)){if(!g.canBeGhostOf(y,m))continue;const L=Math.hypot(m.x-x,m.y-p);L<R&&(R=L,A=m)}A&&R<=t*i&&g.apart(y,A)&&f.push({ghost:y,light:A,residualPx:R*Math.abs(o)})}const u=new Map;for(const y of f){const x=u.get(y.light);(!x||y.residualPx<x.residualPx)&&u.set(y.light,y)}if(n=[...u.values()],n.length===0)return;r={x:n.reduce((y,x)=>y+(x.ghost.x-o*x.light.x)/(1-o),0)/n.length,y:n.reduce((y,x)=>y+(x.ghost.y-o*x.light.y)/(1-o),0)/n.length}}for(const t of n)t.residualPx=Math.hypot(t.ghost.x-(r.x+o*(t.light.x-r.x)),t.ghost.y-(r.y+o*(t.light.y-r.y)));const l=Math.sqrt(n.reduce((t,f)=>t+f.residualPx**2,0)/n.length);return{pairs:n,centre:r,error:l}}static spotsOf(a){const{width:s,height:e,data:o}=a,i=new Float32Array(s*e);for(let t=0;t<s*e;t++)i[t]=.2126*o[t*4]+.7152*o[t*4+1]+.0722*o[t*4+2];const r=Math.max(2,Math.round(Math.hypot(s,e)/500)),n=3*r,c=[];for(let t=n;t<e-n;t++)for(let f=n;f<s-n;f++){const u=i[t*s+f];if(u<40)continue;let y=!0;for(let T=-r;T<=r&&y;T++)for(let h=-r;h<=r;h++){const d=i[(t+T)*s+f+h];if(d>u||d===u&&(T<0||T===0&&h<0)){y=!1;break}}if(!y)continue;let x=-1/0,p=0,A=n,R=0;for(const T of[n,2*n,4*n,8*n,16*n]){if(f<T||t<T||f>=s-T||t>=e-T||T>4*n&&(u<g.SATURATED||x>=g.LOST_IN_GLARE))break;const h=[];for(let S=0;S<32;S++){const k=S/32*2*Math.PI;h.push(i[Math.round(t+T*Math.sin(k))*s+Math.round(f+T*Math.cos(k))])}h.sort((S,k)=>S-k);const d=h[16];u-d>x+5&&(x=u-d,p=d,A=T,R=h[24]-h[8])}if(x<20)continue;const m=p+x/2;let L=0,M=0,E=0,O=0,P=0,N=0,C=0;for(let T=-A+1;T<A;T++)for(let h=-A+1;h<A;h++){const d=(t+T)*s+f+h;if(i[d]<m)continue;L++,M+=o[d*4],E+=o[d*4+1],O+=o[d*4+2];const S=i[d]-m+1;P+=S,N+=S*h,C+=S*T}c.push({x:f+N/P,y:t+C/P,peak:u,contrast:x,background:p,radius:Math.sqrt(L/Math.PI),color:[M/L,E/L,O/L],spread:R})}c.sort((t,f)=>f.contrast-t.contrast);const l=[];for(const t of c){if(l.length>=g.MAX_SPOTS)break;l.some(f=>f.peak>=t.peak&&Math.hypot(f.x-t.x,f.y-t.y)<Math.max(f.radius,r))||l.push(t)}return l}}class U{constructor(a,s){this.status=a,this.texts=s}static ANALYSIS_SIZE=1600;async search(a){this.status.textContent=this.texts.searching;let s;try{s=await U.load(a)}catch{this.status.textContent="";return}const e=Math.min(1,U.ANALYSIS_SIZE/Math.max(s.naturalWidth,s.naturalHeight)),o=Math.round(s.naturalWidth*e),i=Math.round(s.naturalHeight*e),r=document.createElement("canvas");r.width=o,r.height=i;const n=r.getContext("2d",{willReadFrequently:!0});n.drawImage(s,0,0,o,i);const c=n.getImageData(0,0,o,i);await new Promise(t=>setTimeout(t,0));const l=g.find(c);return this.status.textContent=this.sentence(l),l}sentence(a){const s=String(a.pairs.length);if(a.confidence==="none")return this.texts.none;const e=a.confidence==="low"?this.texts.low.replace("{count}",s):a.scale===-1?this.texts.found.replace("{count}",s):this.texts.foundScaled.replace("{count}",s).replace("{scale}",(a.scale??0).toLocaleString(void 0,{maximumFractionDigits:2}));return a.cropped?`${e} ${this.texts.cropped}`:e}static async load(a){const s=URL.createObjectURL(await K.blob(a));try{const e=new Image;return e.src=s,await e.decode().catch(()=>{throw new W(a,{kind:"notPicture"})}),e}finally{URL.revokeObjectURL(s)}}}export{U as GhostSearchView};
1
+ import{P as K,a as W}from"./PictureFetch-C3wgf1ZV.js";class I{static SIZE=360;static LIGHT=230;static DARK=80;static STANDS_OUT=12;static GROUND=.025;static WHOLE_GROUND=.08;static GROWN_DRIFT=.02;static INSIDE_WEIGHT=.4;static LINE_LENGTH=12;static LINE_FILL=.2;static STANDING_FULLY=60;static NEAREST=.08;static REACH=.08;static RING=[.04,.08];static SHARE_OF_PEAK=.15;static MAX_PAIRS=6e6;static find(a,s){const e=Math.min(1,I.SIZE/Math.max(a.width,a.height)),o=Math.max(1,Math.round(a.width*e)),i=Math.max(1,Math.round(a.height*e)),r=I.luminanceOf(a,o,i),n=I.blurred(r,o,i,Math.max(4,Math.round(Math.hypot(o,i)*I.GROUND))),c=[],l=[];for(let R=0;R<i;R++)for(let m=0;m<o;m++){const L=R*o+m,M=r[L];M>=I.LIGHT?c.push({x:m,y:R,weight:(M-I.LIGHT+5)/30}):n[L]<I.DARK&&M-n[L]>I.STANDS_OUT&&l.push({x:m,y:R,weight:Math.min(1,(M-n[L])/I.STANDING_FULLY)})}if(l.splice(0,l.length,...I.withoutLines(l,o,i)),c.splice(0,c.length,...I.withoutLines(c,o,i)),l.push(...I.insides(l,c,o,i)),c.length===0||l.length===0)return;const t=I.NEAREST*Math.hypot(o,i),f=I.peak(I.vote(c,l,o,i,t),o,i);if(f.value<=0||f.sharpness<s)return;const u={x:f.x/2,y:f.y/2},{pairs:y,matched:x}=I.pairsAt(u,c,l,r,n,o,i,t);if(y.length===0)return;const p=1/e,A=R=>({...R,x:(R.x+.5)*p-.5,y:(R.y+.5)*p-.5,radius:R.radius*p});return{centre:{x:(u.x+.5)*p-.5,y:(u.y+.5)*p-.5},pairs:y.map(R=>({ghost:A(R.ghost),light:A(R.light),residualPx:R.residualPx*p})),sharpness:f.sharpness,matched:x}}static vote(a,s,e,o,i){const r=new Float32Array(2*e*2*o),n=Math.max(1,Math.ceil(Math.sqrt(a.length*s.length/I.MAX_PAIRS))),c=i*i;for(let l=0;l<a.length;l+=n){const t=a[l];for(let f=0;f<s.length;f+=n){const u=s[f],y=u.x-t.x,x=u.y-t.y;y*y+x*x<c||(r[(t.y+u.y)*2*e+t.x+u.x]+=t.weight*u.weight)}}return r}static peak(a,s,e){const o=2*s,i=2*e,r=I.blurred(a,o,i,3);let n={x:0,y:0,value:0,sharpness:0};const c=I.REACH*Math.hypot(o,i);for(let y=Math.max(0,Math.round(i/2-c));y<Math.min(i,Math.round(i/2+c));y++)for(let x=Math.max(0,Math.round(o/2-c));x<Math.min(o,Math.round(o/2+c));x++){if(Math.hypot(x-o/2,y-i/2)>c)continue;const p=r[y*o+x];p>n.value&&(n={x,y,value:p,sharpness:0})}const l=Math.hypot(o,i),t=I.RING[0]*l,f=I.RING[1]*l;let u=0;for(let y=Math.max(0,Math.floor(n.y-f));y<Math.min(i,Math.ceil(n.y+f));y++)for(let x=Math.max(0,Math.floor(n.x-f));x<Math.min(o,Math.ceil(n.x+f));x++){const p=Math.hypot(x-n.x,y-n.y);p>t&&p<f&&(u=Math.max(u,r[y*o+x]))}return n.sharpness=u>0?n.value/u:1/0,n}static pairsAt(a,s,e,o,i,r,n,c){const l=new Float32Array(r*n);for(const M of s)l[M.y*r+M.x]=M.weight;const t=M=>{const E=Math.round(2*a.x-M.x),O=Math.round(2*a.y-M.y);let P=0;for(let N=-2;N<=2;N++)for(let C=-2;C<=2;C++){const T=E+C,h=O+N;T>=0&&h>=0&&T<r&&h<n&&(P+=l[h*r+T])}return M.weight*P},f=new Float32Array(r*n),u=new Uint8Array(r*n);for(const M of e){if(Math.hypot(M.x-(2*a.x-M.x),M.y-(2*a.y-M.y))<c)continue;const E=t(M);E<=0||(u[M.y*r+M.x]=1,f[M.y*r+M.x]=E)}let y;const x=()=>y??=I.blurred(o,r,n,Math.max(4,Math.round(Math.hypot(r,n)*I.WHOLE_GROUND))),p=new Uint8Array(r*n),A=[];for(let M=0;M<u.length;M++){if(!u[M]||p[M])continue;const E=[],O=[M];for(p[M]=1;O.length>0;){const h=O.pop();E.push(h);const d=h%r,S=(h-d)/r;for(let k=-2;k<=2;k++)for(let D=-2;D<=2;D++){const H=d+D,v=S+k;if(H<0||v<0||H>=r||v>=n)continue;const b=v*r+H;u[b]&&!p[b]&&(p[b]=1,O.push(b))}}if(E.length<3)continue;const P=E.reduce((h,d)=>h+f[d],0),N=I.spotOf(I.whole(E,o,x(),r,n),o,x(),r),C=s.filter(h=>Math.hypot(h.x-(2*a.x-N.x),h.y-(2*a.y-N.y))<=N.radius+2);if(C.length===0)continue;const T=I.spotOf(C.map(h=>h.y*r+h.x),o,i,r);A.push({pair:{ghost:N,light:T,residualPx:Math.hypot(N.x+T.x-2*a.x,N.y+T.y-2*a.y)},vote:P,size:E.length})}const R=A.reduce((M,E)=>Math.max(M,E.vote),0),m=[];let L=0;for(const{pair:M,size:E}of A.filter(O=>O.vote>=I.SHARE_OF_PEAK*R).sort((O,P)=>P.vote-O.vote))L+=E,!m.some(O=>Math.hypot(O.ghost.x-M.ghost.x,O.ghost.y-M.ghost.y)<Math.max(O.ghost.radius,M.ghost.radius))&&m.push(M);return{pairs:m.slice(0,12),matched:L}}static withoutLines(a,s,e){const o=new Int32Array(s*e).fill(-1);a.forEach((n,c)=>o[n.y*s+n.x]=c);const i=new Uint8Array(a.length),r=[];for(let n=0;n<a.length;n++){if(i[n])continue;const c=[n];i[n]=1;let l=1/0,t=-1/0,f=1/0,u=-1/0;for(let x=0;x<c.length;x++){const{x:p,y:A}=a[c[x]];l=Math.min(l,p),t=Math.max(t,p),f=Math.min(f,A),u=Math.max(u,A);for(let R=-1;R<=1;R++)for(let m=-1;m<=1;m++){const L=p+m,M=A+R;if(L<0||M<0||L>=s||M>=e)continue;const E=o[M*s+L];E>=0&&!i[E]&&(i[E]=1,c.push(E))}}const y=c.length/((t-l+1)*(u-f+1));if(!(c.length>=I.LINE_LENGTH&&y<I.LINE_FILL))for(const x of c)r.push(a[x])}return r}static insides(a,s,e,o){const i=new Uint8Array(e*o);for(const t of a)i[t.y*e+t.x]=1;for(const t of s)i[t.y*e+t.x]=2;const r=new Uint8Array(e*o),n=[],c=t=>{i[t]||r[t]||(r[t]=1,n.push(t))};for(let t=0;t<e;t++)c(t),c((o-1)*e+t);for(let t=0;t<o;t++)c(t*e),c(t*e+e-1);for(;n.length>0;){const t=n.pop(),f=t%e,u=(t-f)/e;f>0&&c(t-1),f<e-1&&c(t+1),u>0&&c(t-e),u<o-1&&c(t+e)}const l=[];for(let t=0;t<i.length;t++)!i[t]&&!r[t]&&l.push({x:t%e,y:Math.floor(t/e),weight:I.INSIDE_WEIGHT});return l}static whole(a,s,e,o,i){const r=4*Math.sqrt(a.length/Math.PI)+.06*Math.hypot(o,i);let n=0,c=0;for(const A of a)n+=A%o,c+=Math.floor(A/o);n/=a.length,c/=a.length;const l=A=>s[A]<I.LIGHT&&s[A]-e[A]>I.STANDS_OUT/2,t=new Uint8Array(o*i),f=a.filter(l);for(const A of f)t[A]=1;const u=[...f];for(;f.length>0;){const A=f.pop(),R=A%o,m=(A-R)/o;for(const[L,M]of[[1,0],[-1,0],[0,1],[0,-1]]){const E=R+L,O=m+M;if(E<0||O<0||E>=o||O>=i)continue;const P=O*o+E;t[P]||!l(P)||Math.hypot(E-n,O-c)>r||(t[P]=1,u.push(P),f.push(P))}}if(u.length<a.length)return a;let y=0,x=0;for(const A of u)y+=A%o,x+=Math.floor(A/o);return Math.hypot(y/u.length-n,x/u.length-c)<=Math.sqrt(a.length/Math.PI)+I.GROWN_DRIFT*Math.hypot(o,i)?u:a}static spotOf(a,s,e,o){let i=0,r=0,n=0,c=0,l=0;for(const f of a){const u=Math.max(1,s[f]-e[f]);i+=u,r+=u*(f%o),n+=u*Math.floor(f/o),c=Math.max(c,s[f]),l+=e[f]}const t=l/a.length;return{x:r/i,y:n/i,peak:c,contrast:c-t,background:t,radius:Math.sqrt(a.length/Math.PI),color:[c,c,c]}}static luminanceOf(a,s,e){const o=new Float32Array(s*e),i=new Float32Array(s*e),r=s/a.width,n=e/a.height;for(let c=0;c<a.height;c++){const l=Math.min(e-1,Math.floor(c*n));for(let t=0;t<a.width;t++){const f=(c*a.width+t)*4,u=l*s+Math.min(s-1,Math.floor(t*r));o[u]+=.2126*a.data[f]+.7152*a.data[f+1]+.0722*a.data[f+2],i[u]++}}for(let c=0;c<o.length;c++)o[c]/=Math.max(1,i[c]);return o}static blurred(a,s,e,o){const i=new Float64Array((s+1)*(e+1));for(let n=0;n<e;n++){let c=0;for(let l=0;l<s;l++)c+=a[n*s+l],i[(n+1)*(s+1)+l+1]=i[n*(s+1)+l+1]+c}const r=new Float32Array(s*e);for(let n=0;n<e;n++){const c=Math.max(0,n-o),l=Math.min(e,n+o+1);for(let t=0;t<s;t++){const f=Math.max(0,t-o),u=Math.min(s,t+o+1),y=i[l*(s+1)+u]-i[c*(s+1)+u]-i[l*(s+1)+f]+i[c*(s+1)+f];r[n*s+t]=y/((u-f)*(l-c))}}return r}}class g{static OTHER_SCALES=[-2,-1.8,-1.6,-1.4,-1.3,-1.2,-1.1,-.9,-.8,-.7,-.6,-.5,-.4,-.3,.3,.4,.5,.6,.7,.8];static DARK=80;static LARGE_LIGHT_CONTRAST=80;static DOMINATED=.4;static GRID_STEP=2;static GRID_REACH=.12;static ABOVE_CHANCE=1.5;static GREAT_LIGHTS=3;static LONE_REACH=.15;static GROUND_ALIKE=40;static EVEN_ALIKE=20;static CHANCE_ALONE=.5;static CROPPED=.04;static GLARE_SIZE=2;static GLARE_REACH=2.5;static SATURATED=250;static LOST_IN_GLARE=40;static OUT_OF_GLARE=2.5;static SPOT_GHOST_CONTRAST=40;static SHARP_MIRROR=1.5;static SHAPE_MATCHED=25;static MAX_SPOTS=2e3;static find(a){const s=g.searched(a);return{...s,pairs:s.pairs.map(e=>({...e,light:g.glaringOver(e.light,s.lights)}))}}static searched(a){const{width:s,height:e}=a,o=Math.hypot(s,e),i=g.spotsOf(a),r=i.reduce((h,d)=>Math.max(h,d.peak),0),n=Math.min(235,.9*r),c=g.linesOfLight(a,n),l=i.filter(h=>!c[Math.round(h.y)*s+Math.round(h.x)]),t=l.filter(h=>h.peak>=n&&(h.radius<=.025*o?h.contrast>=40:h.contrast>=g.LARGE_LIGHT_CONTRAST)),f=t.reduce((h,d)=>Math.max(h,d.radius),0),u=l.filter(h=>t.includes(h)?h.radius<=g.DOMINATED*f&&h.contrast>=g.LARGE_LIGHT_CONTRAST:h.background<g.DARK&&h.peak>=2*h.background),y={width:s,height:e,lights:t,spots:l,pairs:[],confidence:"none"},x=()=>g.mirrored(a,t,l);if(t.length===0||u.length===0)return x()??y;const p=.006*o,A=h=>h.reduce((d,S)=>d+Math.max(0,1-S.residualPx/p)**2,0),R=g.GRID_STEP*p,m=g.GRID_REACH*o,L=[];for(let h=e/2-m;h<=e/2+m;h+=R)for(let d=s/2-m;d<=s/2+m;d+=R)L.push({x:d,y:h});const M=(h,d=u)=>{let S;for(const k of[...g.voted(d,t,h,s,e),...h===-1?L:[]]){const D=g.fit(d,t,k,h,p);if(!D)continue;const H=A(D.pairs);(!S||H>S.score)&&(S={...D,scale:h,score:H})}return S};let E=M(-1);for(const h of g.OTHER_SCALES){const d=M(h),S=E?.pairs.length??0;d&&d.pairs.length>=Math.max(3,1.5*S,S+2)&&d.score>(E?.score??0)&&(E=d)}let O;if(E&&E.pairs.length>=2){const h=E.scale,d=[[-1,1],[1,-1],[-1,-1]].map(([k,D])=>M(h,u.map(H=>({...H,x:k<0?s-H.x:H.x,y:D<0?e-H.y:H.y})))?.score??0),S=d.reduce((k,D)=>k+D,0)/d.length;if(E.score>g.ABOVE_CHANCE*S){const k=Math.hypot(E.centre.x-s/2,E.centre.y-e/2)/o;if(O={width:s,height:e,lights:t,spots:l,pairs:E.pairs,centre:E.centre,scale:E.scale,cropped:k>g.CROPPED,confidence:E.pairs.length>=3?"high":"low"},O.confidence==="high")return O}}const P=l.filter(h=>u.includes(h)||h.contrast>=g.LARGE_LIGHT_CONTRAST&&h.peak>=Math.min(g.SATURATED,1.5*h.background)),N=x(),C=[...t,...l.filter(h=>h.peak>=g.SATURATED&&!t.includes(h))],T=()=>g.loneGhost(l,C,P,s,e,p,t);if(N&&N.pairs.length===1){const h=T(),d=S=>Math.hypot(S.centre.x-s/2,S.centre.y-e/2);return h&&d(h)<d(N)?h:N}return N??O??T()??y}static mirrored(a,s,e){const o=I.find(a,g.SHARP_MIRROR);if(!o)return;const{width:i,height:r}=a,n=Math.hypot(i,r),c=g.atAxis(e,s,o.centre,.006*n),l=c.length>=2?[...c,...o.pairs.filter(u=>!c.some(y=>Math.hypot(y.ghost.x-u.ghost.x,y.ghost.y-u.ghost.y)<=u.ghost.radius))]:o.pairs,t=o.centre,f=Math.hypot(t.x-i/2,t.y-r/2)/n;return{width:i,height:r,lights:s,spots:e,pairs:l,centre:t,scale:-1,cropped:f>g.CROPPED,confidence:l.length>=2||o.matched>=g.SHAPE_MATCHED?"high":"low"}}static glaringOver(a,s){let e=a;for(const o of s)o.radius>=g.GLARE_SIZE*a.radius&&o.radius>e.radius&&Math.hypot(o.x-a.x,o.y-a.y)<=g.GLARE_REACH*o.radius&&(e=o);return e}static atAxis(a,s,e,o){const i=[];for(const r of a.filter(n=>n.contrast>=g.SPOT_GHOST_CONTRAST)){const n={x:2*e.x-r.x,y:2*e.y-r.y};let c;for(const l of s){if(!g.canBeGhostOf(r,l))continue;const t=Math.max(0,Math.hypot(l.x-n.x,l.y-n.y)-l.radius);t<=o&&(!c||t<c.beyond)&&(c={light:l,beyond:t})}!c||!g.apart(r,c.light)||i.some(l=>Math.hypot(l.ghost.x-r.x,l.ghost.y-r.y)<Math.max(2,l.ghost.radius,r.radius))||i.push({ghost:r,light:{...c.light,...n},residualPx:c.beyond})}return i.filter(r=>!i.some(n=>n!==r&&n.ghost.radius<r.ghost.radius&&Math.hypot(n.ghost.x-r.ghost.x,n.ghost.y-r.ghost.y)<r.ghost.radius))}static loneGhost(a,s,e,o,i,r,n){const c=Math.hypot(o,i),l=[...s].sort((p,A)=>A.contrast*A.radius**2-p.contrast*p.radius**2).slice(0,g.GREAT_LIGHTS);let t;for(const p of l){const A={x:o-p.x,y:i-p.y},R=e.filter(m=>m!==p&&g.canBeGhostOf(m,p)&&Math.hypot(m.x-A.x,m.y-A.y)<=g.LONE_REACH*c&&g.apart(m,p));for(const m of R){const L=e.filter(O=>O.contrast>=m.contrast&&g.canBeGhostOf(O,p)&&g.groundsAlike(O,m)).length,M=Math.hypot(m.x-A.x,m.y-A.y)+r,E=L*Math.PI*M**2/(o*i);(!t||E<t.chance)&&(t={pair:{ghost:m,light:p,residualPx:0},chance:E})}}if(!t||t.chance>=g.CHANCE_ALONE)return;const{ghost:f,light:u}=t.pair,y={x:(f.x+u.x)/2,y:(f.y+u.y)/2},x=Math.hypot(y.x-o/2,y.y-i/2)/c;return{width:o,height:i,lights:n,spots:a,pairs:[t.pair],centre:y,scale:-1,cropped:x>g.CROPPED,confidence:"low"}}static groundsAlike(a,s){const e=Math.max(g.EVEN_ALIKE,a.spread??0,s.spread??0);return Math.abs(a.background-s.background)<=g.GROUND_ALIKE&&Math.abs((a.spread??0)-(s.spread??0))<=e/2}static lightCells=new WeakMap;static lightsNear(a,s){let e=g.lightCells.get(a);if(!e||e.cell!==s){const i=new Map;for(const r of a){const n=g.cellKey(Math.floor(r.x/s),Math.floor(r.y/s)),c=i.get(n);c?c.push(r):i.set(n,[r])}e={cell:s,cells:i},g.lightCells.set(a,e)}const{cells:o}=e;return(i,r)=>{const n=Math.floor(i/s),c=Math.floor(r/s),l=[];for(let t=-1;t<=1;t++)for(let f=-1;f<=1;f++){const u=o.get(g.cellKey(n+t,c+f));u&&l.push(...u)}return l}}static cellKey(a,s){return(a+5e4)*1e5+s+5e4}static linesOfLight(a,s){const{width:e,height:o,data:i}=a,r=[];for(let c=0;c<o;c++)for(let l=0;l<e;l++){const t=(c*e+l)*4;.2126*i[t]+.7152*i[t+1]+.0722*i[t+2]>=s&&r.push({x:l,y:c})}const n=new Uint8Array(e*o);for(const c of r)n[c.y*e+c.x]=1;for(const c of I.withoutLines(r,e,o))n[c.y*e+c.x]=0;return n}static apart(a,s){return Math.hypot(a.x-s.x,a.y-s.y)>=Math.max(4*a.radius,g.OUT_OF_GLARE*s.radius)}static canBeGhostOf(a,s){return a!==s&&(a.peak<s.peak-5||a.radius<=g.DOMINATED*s.radius)}static voted(a,s,e,o,i){const r=.01*Math.hypot(o,i),n=new Map;for(const l of a)for(const t of s){if(!g.canBeGhostOf(l,t))continue;const f=(l.x-e*t.x)/(1-e),u=(l.y-e*t.y)/(1-e);if(f<-.25*o||f>1.25*o||u<-.25*i||u>1.25*i||!g.apart(l,t))continue;const y=`${Math.floor(f/r)},${Math.floor(u/r)}`,x=n.get(y)??{count:0,x:0,y:0};x.count++,x.x+=f,x.y+=u,n.set(y,x)}const c=[...n.entries()].map(([l,t])=>{const[f,u]=l.split(",").map(Number);let y=0,x=0,p=0;for(let A=-1;A<=1;A++)for(let R=-1;R<=1;R++){const m=n.get(`${f+A},${u+R}`);m&&(y+=m.count,x+=m.x,p+=m.y)}return{count:y,centre:{x:x/y,y:p/y},own:t.count}});return c.sort((l,t)=>t.count-l.count||t.own-l.own),c.filter(l=>l.count>=1).slice(0,60).map(l=>l.centre)}static fit(a,s,e,o,i){let r=e,n=[];const c=g.lightsNear(s,3*i);for(const t of[3,2,1,1]){const f=[];for(const y of a){const x=r.x+(y.x-r.x)/o,p=r.y+(y.y-r.y)/o;let A,R=1/0;for(const m of c(x,p)){if(!g.canBeGhostOf(y,m))continue;const L=Math.hypot(m.x-x,m.y-p);L<R&&(R=L,A=m)}A&&R<=t*i&&g.apart(y,A)&&f.push({ghost:y,light:A,residualPx:R*Math.abs(o)})}const u=new Map;for(const y of f){const x=u.get(y.light);(!x||y.residualPx<x.residualPx)&&u.set(y.light,y)}if(n=[...u.values()],n.length===0)return;r={x:n.reduce((y,x)=>y+(x.ghost.x-o*x.light.x)/(1-o),0)/n.length,y:n.reduce((y,x)=>y+(x.ghost.y-o*x.light.y)/(1-o),0)/n.length}}for(const t of n)t.residualPx=Math.hypot(t.ghost.x-(r.x+o*(t.light.x-r.x)),t.ghost.y-(r.y+o*(t.light.y-r.y)));const l=Math.sqrt(n.reduce((t,f)=>t+f.residualPx**2,0)/n.length);return{pairs:n,centre:r,error:l}}static spotsOf(a){const{width:s,height:e,data:o}=a,i=new Float32Array(s*e);for(let t=0;t<s*e;t++)i[t]=.2126*o[t*4]+.7152*o[t*4+1]+.0722*o[t*4+2];const r=Math.max(2,Math.round(Math.hypot(s,e)/500)),n=3*r,c=[];for(let t=n;t<e-n;t++)for(let f=n;f<s-n;f++){const u=i[t*s+f];if(u<40)continue;let y=!0;for(let T=-r;T<=r&&y;T++)for(let h=-r;h<=r;h++){const d=i[(t+T)*s+f+h];if(d>u||d===u&&(T<0||T===0&&h<0)){y=!1;break}}if(!y)continue;let x=-1/0,p=0,A=n,R=0;for(const T of[n,2*n,4*n,8*n,16*n]){if(f<T||t<T||f>=s-T||t>=e-T||T>4*n&&(u<g.SATURATED||x>=g.LOST_IN_GLARE))break;const h=[];for(let S=0;S<32;S++){const k=S/32*2*Math.PI;h.push(i[Math.round(t+T*Math.sin(k))*s+Math.round(f+T*Math.cos(k))])}h.sort((S,k)=>S-k);const d=h[16];u-d>x+5&&(x=u-d,p=d,A=T,R=h[24]-h[8])}if(x<20)continue;const m=p+x/2;let L=0,M=0,E=0,O=0,P=0,N=0,C=0;for(let T=-A+1;T<A;T++)for(let h=-A+1;h<A;h++){const d=(t+T)*s+f+h;if(i[d]<m)continue;L++,M+=o[d*4],E+=o[d*4+1],O+=o[d*4+2];const S=i[d]-m+1;P+=S,N+=S*h,C+=S*T}c.push({x:f+N/P,y:t+C/P,peak:u,contrast:x,background:p,radius:Math.sqrt(L/Math.PI),color:[M/L,E/L,O/L],spread:R})}c.sort((t,f)=>f.contrast-t.contrast);const l=[];for(const t of c){if(l.length>=g.MAX_SPOTS)break;l.some(f=>f.peak>=t.peak&&Math.hypot(f.x-t.x,f.y-t.y)<Math.max(f.radius,r))||l.push(t)}return l}}class U{constructor(a,s){this.status=a,this.texts=s}static ANALYSIS_SIZE=1600;async search(a){this.status.textContent=this.texts.searching;let s;try{s=await U.load(a)}catch{this.status.textContent="";return}const e=Math.min(1,U.ANALYSIS_SIZE/Math.max(s.naturalWidth,s.naturalHeight)),o=Math.round(s.naturalWidth*e),i=Math.round(s.naturalHeight*e),r=document.createElement("canvas");r.width=o,r.height=i;const n=r.getContext("2d",{willReadFrequently:!0});n.drawImage(s,0,0,o,i);const c=n.getImageData(0,0,o,i);await new Promise(t=>setTimeout(t,0));const l=g.find(c);return this.status.textContent=this.sentence(l),l}sentence(a){const s=String(a.pairs.length);if(a.confidence==="none")return this.texts.none;const e=a.confidence==="low"?this.texts.low.replace("{count}",s):a.scale===-1?this.texts.found.replace("{count}",s):this.texts.foundScaled.replace("{count}",s).replace("{scale}",(a.scale??0).toLocaleString(void 0,{maximumFractionDigits:2}));return a.cropped?`${e} ${this.texts.cropped}`:e}static async load(a){const s=URL.createObjectURL(await K.blob(a));try{const e=new Image;return e.src=s,await e.decode().catch(()=>{throw new W(a,{kind:"notPicture"})}),e}finally{URL.revokeObjectURL(s)}}}export{U as GhostSearchView};
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SightingFileEditor-DB3jyBzw.js","./index-DSNA74v6.js","./sightingSchema-CKUYrwgu.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SightingFileEditor-bXm0nVE4.js","./index-DSNA74v6.js","./sightingSchema-B1hstz7u.js"])))=>i.map(i=>d[i]);
2
2
  import{S as L,a as T,H as M,s as P,U as j,I as H,b as W,P as z,c as y,W as N,r as D,d as J,E as S,e as I,A as B,f as E,M as U,_ as C,l as V}from"./rr0-sighting-editor.mjs";import{InterviewMedia as A}from"./InterviewMedia-CvAxC62V.js";import{InterviewFile as g}from"./interviewJson-DXD8FSBX.js";const $="rr0-interview",G=`
3
3
  rr0-interview { display: block; --rr0-interview-line: color-mix(in srgb, currentColor 35%, transparent); }
4
4
  rr0-interview [hidden] { display: none !important; }
@@ -228,4 +228,4 @@ rr0-interview .turn .ref svg { width: 1.1em; height: 1.1em; }
228
228
  </section>
229
229
  </div>
230
230
  `;class m extends HTMLElement{shadow=this.attachShadow({mode:"open"});get importInput(){return this.shadow.getElementById("import")}messages;said=new L(["en"]);language="en";localeToken=0;current;options=[];group="summary";base;text;fileEditor;fileEditorLoading;shownFor;ready=Promise.resolve();player;drawn;takenOut=new Map;constructor(){super(),this.shadow.innerHTML=K,customElements.upgrade(this.shadow),this.importInput.build();for(const e of["title","time","by","url","summary","witness","medium"])this.shadow.getElementById(e).addEventListener(e==="witness"||e==="medium"?"change":"input",()=>this.write(e));for(const e of this.shadow.querySelectorAll("#tabs .group-tab"))e.addEventListener("click",()=>this.openGroup(m.GROUPS[e.getAttribute("aria-controls")]??"summary"));this.shadow.getElementById("url").addEventListener("change",()=>{this.shownFor=void 0,this.text===void 0&&this.group==="file"&&this.showTranscript()}),this.importInput.addEventListener("filepick",e=>{const t=e.detail;t.file?this.importFromFile(t.file):this.importFromUrl(t.url)}),this.shadow.getElementById("save").addEventListener("click",()=>this.save()),this.shadow.getElementById("redact-selection").addEventListener("click",()=>void this.redactSelection()),this.shadow.getElementById("exchanges").addEventListener("click",e=>{const t=e.target.closest(".bar[data-restorable]");t&&this.restore(t.dataset.restorable)})}static GROUPS={"group-summary":"summary","group-exchanges":"exchanges","group-transcript":"file"};static get observedAttributes(){return["readonly"]}attributeChangedCallback(){this.applyReadonly()}connectedCallback(){this.ready=this.loadLocale()}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.releaseFileEditor()})}releaseFileEditor(){this.fileEditor&&(this.text=this.fileEditor.text,this.fileEditor.destroy(),this.fileEditor=void 0,this.fileEditorLoading=void 0,this.shownFor=void 0)}get event(){return this.current}set event(e){e!==this.current&&(this.shownFor=void 0),this.current=e,this.render(),this.takenOut.clear(),this.group==="file"&&this.showTranscript(),queueMicrotask(()=>{this.current===e&&this.showExchanges()})}set witnesses(e){this.options=e,this.render()}set documentUrl(e){this.base=e}get transcriptText(){return this.text}set transcriptText(e){this.text=e,this.shownFor=void 0}field(e){return this.shadow.getElementById(e)}async loadLocale(){const e=++this.localeToken,t=M.preferencesFor(this),r=P(t,j),s=await H.load(r);e===this.localeToken&&(this.language=r,this.said=new L(t),this.messages=s,this.player||(this.player=new q(this.shadow.getElementById("player"),{timeChanged:i=>this.markCurrentTurn(i),recordingsChanged:i=>void this.editTranscript(a=>{i.length===0?delete a.recordings:a.recordings=i})},s),this.render()),this.render())}applyReadonly(){const e=this.hasAttribute("readonly");for(const t of["title","time","by","url","summary"])this.field(t).readOnly=e;for(const t of this.shadow.querySelectorAll("#witness input"))t.disabled=e;this.field("medium").disabled=e,this.importInput.disabled=e}static byText(e){return(e??[]).map(t=>"people"in t?t.people:"org"in t?t.org:t.title??"").filter(t=>t!=="").join(", ")}render(){const e=this.messages;if(!e)return;const t=(o,d)=>{this.shadow.getElementById(o).textContent=d};t("label-summary-group",e.summaryTab),t("label-file-group",e.fileTab),t("label-exchanges-group",e.exchangesTab),t("label-title",e.title),t("label-witness",e.witness),t("label-medium",e.medium),t("label-time",e.time),t("label-by",e.by),t("label-summary",e.summary),t("label-url",e.transcript),I.say(this.shadow.getElementById("label-import-file"),e.importFile,e.importFileHint),t("redact-selection",e.redactSelection),this.player?.setMessages(e),this.importInput.messages=e,t("save",e.saveButton),this.field("url").title=e.transcriptHint,this.field("by").title=e.byHint;const r=this.current,s=this.shadow.activeElement,i=(o,d)=>{this.field(o)!==s&&(this.field(o).value=d)};i("title",this.said.read(r?.title)??""),i("time",r?.time??""),i("by",m.byText(r?.by)),i("url",r?.url??""),i("summary",this.said.read(r?.summary)??"");const a=[r?.interviewOf].flat().filter(o=>typeof o=="string"),n=this.shadow.getElementById("witness"),l=[...this.options,...a.filter(o=>!this.options.some(d=>d.id===o)).map(o=>({id:o,label:o}))];n.replaceChildren(n.querySelector("legend"),...l.map(o=>{const d=document.createElement("label"),h=document.createElement("input");return h.type="checkbox",h.value=o.id,h.checked=a.includes(o.id),d.append(h,o.label),d}));const c=this.shadow.getElementById("medium");if(c.replaceChildren(...A.ALL.map(o=>new Option(A.label(o,this.language),o))),r?.medium!==void 0&&!A.ALL.includes(r.medium)&&c.append(new Option(String(r.medium),String(r.medium))),r?.medium===void 0){const o=new Option(e.witnessNone,"");o.disabled=!0,o.hidden=!0,c.prepend(o)}c.value=r?.medium??"",this.applyReadonly()}write(e){const t=this.current;if(!t)return;const r=e==="witness"?"":this.field(e).value;switch(e){case"title":{const s=this.said.write(t.title,r,this.language);s===void 0?delete t.title:t.title=s;break}case"summary":{const s=this.said.write(t.summary,r,this.language);s===void 0?delete t.summary:t.summary=s;break}case"time":r.trim()===""?delete t.time:t.time=r.trim();break;case"url":r.trim()===""?delete t.url:t.url=r.trim();break;case"by":{const s=r.split(",").map(i=>i.trim()).filter(i=>i!=="");s.length===0?delete t.by:t.by=s.map(i=>({people:i}));break}case"witness":{const s=[...this.shadow.querySelectorAll("#witness input:checked")].map(i=>i.value);if(s.length===0){this.render();return}t.interviewOf=s.length===1?s[0]:s;break}case"medium":r===""?delete t.medium:t.medium=r;break}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:e,event:t}})),e==="medium"&&this.render(),e!=="url"&&this.syncFileFromEvent()}openGroup(e){this.group=e;const t={summary:"group-summary",exchanges:"group-exchanges",file:"group-transcript"};for(const r of this.shadow.querySelectorAll("#tabs .group-tab"))r.setAttribute("aria-expanded",String(r.getAttribute("aria-controls")===t[e]));for(const[r,s]of Object.entries(t))this.shadow.getElementById(s).hidden=r!==e;e==="file"&&this.showTranscript(),e==="exchanges"&&this.showExchanges()}exchangesToken=0;async transcriptJson(e){try{const t=this.fileEditor?.text??this.text;if(t!==void 0)return g.read(JSON.parse(t));const r=this.transcriptUrl(e);if(r!==void 0)return g.read(await T.json(r))}catch{}}async showExchanges(){const e=this.current;if(!e)return;const t=++this.exchangesToken,r=await this.transcriptJson(e);await this.ready,!(t!==this.exchangesToken||this.current!==e)&&this.drawExchanges(r)}drawExchanges(e){const t=this.shadow.getElementById("exchanges");t.documentUrl=this.current?this.transcriptUrl(this.current):void 0,t.interview=e,this.drawn=e,this.player?.show(e,this.current?this.transcriptUrl(this.current):void 0),this.renderReview(e),this.decorateExchanges(e)}async editTranscript(e){const t=this.current;if(!t||this.hasAttribute("readonly"))return;const r=await this.transcriptJson(t)??JSON.parse(this.template(t));Array.isArray(r.segments)||(r.segments=[]),e(r);const s=m.pretty(m.withEventFields(r,t));this.fileEditor?.replaceText(s,!1),this.onEdited(s)}get redactReason(){return this.said.write(void 0,this.messages.redactReason,this.language)??this.messages.redactReason}speakerLabel(e,t){const r=g.speakerName(e,t),s=e.speakers?.[t]?.role;return r===s&&s in this.messages.roles?this.messages.roles[s]:r}renderReview(e){const t=this.shadow.getElementById("review"),r=Object.keys(e?.speakers??{});if(t.hidden=!e||r.length===0,!e||r.length===0)return;const s=l=>["approved","covered"].includes(e.proofreading?.[l]?.status??""),i=r.filter(l=>!s(l)),a=document.createElement("span");a.textContent=i.length===0?this.messages.proofreadAll:this.messages.proofreadPending.replace("{names}",i.map(l=>this.speakerLabel(e,l)).join(", ")),t.toggleAttribute("data-done",i.length===0);const n=document.createElement("span");n.className="review-boxes";for(const l of r){const c=document.createElement("label"),o=document.createElement("input");o.type="checkbox",o.checked=s(l),o.disabled=this.hasAttribute("readonly"),o.addEventListener("change",()=>void this.editTranscript(d=>{d.proofreading??={},o.checked?d.proofreading[l]={status:"approved",date:new Date().toISOString().slice(0,10)}:d.proofreading[l]={status:"pending"}})),c.append(o,this.messages.reviewedBy.replace("{name}",this.speakerLabel(e,l))),n.append(c)}t.replaceChildren(a,n)}momentsOf(e,t){const r=e.speakers?.[t]?.of??g.sightingsOf(e)[0];return this.options.find(s=>s.id===r)?.moments??this.options.flatMap(s=>s.moments??[])}decorateExchanges(e){if(!e)return;const t=this.messages,r=this.hasAttribute("readonly");for(const s of this.shadow.querySelectorAll("#exchanges .turn[data-segment]")){const i=Number(s.dataset.segment),a=e.segments[i];if(!a)continue;if(a.start!==void 0){const c=document.createElement("button");c.type="button",c.className="turn-time",c.textContent=g.clock(a.start),c.addEventListener("click",()=>this.player?.seek(a.start)),s.prepend(c)}const n=a.redacted?[a.redacted]:f.partsOf(a).flatMap(c=>"redacted"in c?[c.redacted]:[]);s.querySelectorAll(".bar").forEach((c,o)=>{const d=n[o]?.words;c.textContent=d!==void 0?t.redactedWords.replace("{n}",String(d)):t.redacted,c.classList.add("redacted-label");const h=a.redacted?`${i}:all`:`${i}:${o}`;this.takenOut.has(h)&&(c.dataset.restorable=h)});const l=this.momentsOf(e,a.speaker);s.querySelectorAll(".ref").forEach((c,o)=>{const d=a.refs?.[o];if(!d)return;const h=l.find(p=>Math.abs(p.at-d.at)<.05);if(h){const p=document.createElement("span");p.className="moment-letter",p.textContent=h.label.slice(0,2),c.replaceChildren(p,t.momentLabel.replace("{k}",h.label).replace("{text}",h.note??g.clock(d.at)))}if(r)return;const u=document.createElement("button");u.type="button",u.className="ref-unlink",u.textContent="×",u.title=t.unlinkMoment,u.setAttribute("aria-label",t.unlinkMoment),u.addEventListener("click",()=>void this.editTranscript(p=>{p.segments[i].refs?.splice(o,1),p.segments[i].refs?.length===0&&delete p.segments[i].refs})),c.after(u)}),r||s.append(this.turnTools(e,i,a,l))}}turnTools(e,t,r,s){const i=this.messages,a=document.createElement("div");a.className="turn-tools";const n=(o,d)=>{const h=document.createElement("button");return h.type="button",h.textContent=o,h.addEventListener("click",d),h};if(e.speakers?.[r.speaker]?.role==="witness"&&!r.redacted){const o=n(i.linkMoment,()=>{});a.append(o),new B(o,`moment-menu-${t}`,h=>void this.editTranscript(u=>{const p=u.segments[t].refs??[];p.some(b=>Math.abs(b.at-Number(h))<.05)||p.push({at:Number(h)}),u.segments[t].refs=p}),h=>`moment-${t}-${h}`).setKinds(s.length>0?s.map(h=>({value:String(h.at),label:i.momentLabel.replace("{k}",h.label).replace("{text}",h.note??g.clock(h.at))})):[{value:"",label:i.noMoments,disabledReason:i.noMoments}])}r.redacted||a.append(n(i.editTurn,()=>this.editTurn(t)));const l=this.takenOut.has(`${t}:all`)||[...this.takenOut.keys()].some(o=>o.startsWith(`${t}:`));if(r.redacted||r.parts&&l){const o=n(i.restoreAll,()=>void this.restoreAll(t));o.disabled=!l,a.append(o)}else a.append(n(i.redactAll,()=>void this.editTranscript(o=>{this.forget(t),this.takenOut.set(`${t}:all`,f.redactWhole(o.segments[t],this.redactReason))})));const c=n("",()=>void this.editTranscript(o=>{o.segments.splice(t,1),this.shiftTakenOut(t)}));return c.className="icon-btn",c.innerHTML=y.TRASH,c.title=i.deleteTurn,c.setAttribute("aria-label",i.deleteTurn),a.append(c),a}async redactSelection(){const e=this.messages,t=this.shadow.getElementById("redact-note"),r=(h,u=!1)=>{t.textContent=h,t.classList.toggle("error",u)},s=this.shadow.getSelection?.()??document.getSelection(),i=s&&s.rangeCount>0?s.getRangeAt(0):void 0;if(!i||i.collapsed){r(e.selectionNone);return}const a=h=>h instanceof Element?h:h.parentElement,n=a(i.startContainer)?.closest(".said");if(!n||a(i.endContainer)?.closest(".said")!==n||a(i.startContainer)?.closest(".bar")||a(i.endContainer)?.closest(".bar")){r(e.selectionOnePassage,!0);return}const l=Number(n.closest(".turn").dataset.segment),c=m.offsetIn(n,i.startContainer,i.startOffset),o=m.offsetIn(n,i.endContainer,i.endOffset);let d=!1;await this.editTranscript(h=>{const u=f.redact(h.segments[l],Math.min(c,o),Math.max(c,o),this.redactReason);u&&(d=!0,this.shiftParts(l,u.nth),this.takenOut.set(`${l}:${u.nth}`,u.text))}),s?.removeAllRanges(),r(d?"":e.selectionOnePassage,!d)}static offsetIn(e,t,r){let s=0;const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:a=>a.parentElement?.closest(".bar")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let a=i.nextNode();a;a=i.nextNode()){if(a===t)return s+r;if(t.contains(a)&&t!==a){const l=[...t.childNodes].slice(0,r);return s+l.reduce((c,o)=>c+(o instanceof Element&&o.closest(".bar")?0:(o.textContent??"").length),0)}s+=(a.textContent??"").length}return s}async restore(e){const t=this.takenOut.get(e);if(t===void 0)return;const[r,s]=e.split(":"),i=Number(r);await this.editTranscript(a=>{s==="all"?f.restoreWhole(a.segments[i],t):(f.restorePart(a.segments[i],Number(s),t),this.shiftParts(i,Number(s),-1)),this.takenOut.delete(e)})}async restoreAll(e){if(this.takenOut.has(`${e}:all`)){await this.restore(`${e}:all`);return}const t=[...this.takenOut.keys()].filter(r=>r.startsWith(`${e}:`)).map(r=>Number(r.split(":")[1])).sort((r,s)=>s-r);for(const r of t)await this.restore(`${e}:${r}`)}editTurn(e){const r=this.drawn?.segments[e],s=this.shadow.querySelector(`#exchanges .turn[data-segment="${e}"] .said`);if(!r||!s)return;const i=this.messages,a=document.createElement("div");a.className="turn-edit";const n=document.createElement("textarea");n.value=f.raw(r,h=>this.takenOut.get(`${e}:${h}`));const l=document.createElement("span");l.className="hint",l.textContent=i.turnEditHint;const c=document.createElement("div");c.className="buttons";const o=document.createElement("button");o.type="button",o.className="pill-btn primary",o.textContent=i.saveTurn,o.addEventListener("click",()=>void this.editTranscript(h=>{const u=f.fromRaw(h.segments[e],n.value,this.redactReason);this.forget(e);for(const[p,b]of u)this.takenOut.set(`${e}:${p}`,b)}));const d=document.createElement("button");d.type="button",d.className="pill-btn",d.textContent=i.cancelTurn,d.addEventListener("click",()=>this.drawExchanges(this.drawn)),c.append(o,d),a.append(n,l,c),s.replaceWith(a),n.focus()}forget(e){for(const t of[...this.takenOut.keys()])t.startsWith(`${e}:`)&&this.takenOut.delete(t)}shiftParts(e,t,r=1){const s=[...this.takenOut].filter(([i])=>i.startsWith(`${e}:`)&&i!==`${e}:all`&&Number(i.split(":")[1])>=t+(r<0?1:0));for(const[i]of s)this.takenOut.delete(i);for(const[i,a]of s)this.takenOut.set(`${e}:${Number(i.split(":")[1])+r}`,a)}shiftTakenOut(e){const t=[...this.takenOut];this.takenOut.clear();for(const[r,s]of t){const[i,a]=r.split(":"),n=Number(i);n<e?this.takenOut.set(r,s):n>e&&this.takenOut.set(`${n-1}:${a}`,s)}}markCurrentTurn(e){const t=this.drawn?.segments??[];let r=-1;t.forEach((a,n)=>{a.start!==void 0&&a.start<=e&&(r=n)});for(const a of this.shadow.querySelectorAll("#exchanges .turn.current"))a.classList.remove("current");const s=this.shadow.querySelector(`#exchanges .turn[data-segment="${r}"]`);if(!s)return;s.classList.add("current");const i=s.closest(".rr0-interview-turns");i&&(s.offsetTop<i.scrollTop||s.offsetTop>i.scrollTop+i.clientHeight-s.offsetHeight)&&i.scrollTo({top:s.offsetTop-i.clientHeight/3,behavior:"smooth"})}async revealSegment(e){this.openGroup("exchanges"),await this.showExchanges(),this.shadow.getElementById("exchanges").revealSegment(e)}note(e,t="info"){U.show(this.shadow.getElementById("file-note"),e,t)}transcriptUrl(e){return e.url?new URL(e.url,this.base??location.href).href:void 0}static pretty(e){return JSON.stringify(e,null,2)+`
231
- `}static SHARED=["title","time","medium","by","interviewOf","summary"];static ORDER=["version","id","language","title","time","medium","by","interviewOf","summary","speakers","transcription","proofreading","anonymization","recordings","segments"];static ordered(e){const t={};for(const r of m.ORDER)r in e&&(t[r]=e[r]);for(const r of Object.keys(e))r in t||(t[r]=e[r]);return t}static witnessesOf(e){return[e].flat().filter(t=>typeof t=="string")}static withEventFields(e,t){const r={...e};for(const i of m.SHARED)t[i]===void 0?delete r[i]:r[i]=structuredClone(t[i]);const s=r.speakers;if(typeof s=="object"&&s!==null){const i={...s},a=(n,l,c)=>{c.forEach((o,d)=>{const h=d===0?n:`${n}${d+1}`;i[h]?i[h]={...i[h],[l]:o}:d>0&&(i[h]={role:n,[l]:o})})};a("interviewer","by",t.by??[]),a("witness","of",m.witnessesOf(t.interviewOf)),r.speakers=i}return m.ordered(r)}applyFileToEvent(e,t){const r=this.current;if(!r)return!1;const s=JSON.stringify(m.SHARED.map(n=>r[n])),i=n=>typeof n=="string"||typeof n=="object"&&n!==null&&!Array.isArray(n),a={title:i,summary:i,time:n=>typeof n=="string",medium:n=>typeof n=="string",by:n=>Array.isArray(n),interviewOf:n=>typeof n=="string"||Array.isArray(n)};for(const n of m.SHARED){const l=e[n];l!==void 0&&a[n](l)?r[n]=structuredClone(l):t&&delete r[n]}return JSON.stringify(m.SHARED.map(n=>r[n]))!==s}syncFileFromEvent(){const e=this.current,t=this.fileEditor?.text??this.text;if(!e||t===void 0)return;let r;try{r=JSON.parse(t)}catch{return}if(typeof r!="object"||r===null||Array.isArray(r))return;const s=m.pretty(m.withEventFields(r,e));s!==t&&(this.text=s,this.fileEditor?.replaceText(s,!1),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:e,text:s}})))}template(e){return m.pretty(m.withEventFields({version:1,language:this.language,speakers:{interviewer:{role:"interviewer"},witness:{role:"witness"}},segments:[]},e))}loadFileEditor(e){return this.fileEditorLoading??=(async()=>{try{const[{SightingFileEditor:t},{default:r},s]=await Promise.all([C(()=>import("./SightingFileEditor-DB3jyBzw.js"),__vite__mapDeps([0,1,2]),import.meta.url),C(()=>import("./interviewSchema-D82l9P1r.js"),[],import.meta.url),V(this.language)]);return this.fileEditor=new t(this.shadow.getElementById("file-editor"),e,i=>this.onEdited(i),this.messages.editorLabel,{baseline:e,phrases:s.fileSearchPhrases,schema:r}),this.fileEditor}catch(t){throw this.fileEditorLoading=void 0,t}})(),this.fileEditorLoading}async showTranscript(){const e=this.current;if(!e||this.shownFor===e)return;this.note(this.messages.loading);let t=this.text;if(t===void 0){const r=this.transcriptUrl(e);if(r!==void 0)try{const s=await T.json(r);this.current===e&&typeof s=="object"&&s!==null&&!Array.isArray(s)?(this.applyFileToEvent(s,!1)&&this.fileChangedEvent(),t=m.pretty(m.withEventFields(s,e))):t=m.pretty(s)}catch{this.note(this.messages.loadFailed,"error")}t??=this.template(e)}if(this.current===e)try{const r=await this.loadFileEditor(t);if(this.current!==e)return;r.replaceText(t,!1),this.shownFor=e,this.text!==void 0||this.transcriptUrl(e)===void 0?this.note(void 0):this.shadow.getElementById("file-note").textContent===this.messages.loading&&this.note(void 0)}catch{this.note(this.messages.loadFailed,"error")}}onEdited(e){this.text=e;let t,r=!0;try{t=JSON.parse(e)}catch{r=!1}this.note(r?void 0:this.messages.invalid,"error");const s=this.current;if(r&&s&&typeof t=="object"&&t!==null&&!Array.isArray(t)&&this.applyFileToEvent(t,!0)&&this.fileChangedEvent(),s&&!s.url&&e.trim()!==""){const i=s.id??"1";s.url=`${i.startsWith("interview")?i:`interview-${i}`}.json`,this.field("url").value=s.url,this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"url",event:s}}))}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:s,text:e}})),this.showExchanges()}fileChangedEvent(){this.render(),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"file",event:this.current}}))}async take(e){if(typeof e!="object"||e===null||!Array.isArray(e.segments)){this.note(this.messages.notATranscript,"error");return}const t=this.current;t&&this.applyFileToEvent(e,!1)&&this.fileChangedEvent();const r=m.pretty(t?m.withEventFields(e,t):e);await this.loadFileEditor(r).then(s=>s.replaceText(r,!1),()=>{}),this.shownFor=this.current,this.note(void 0),this.onEdited(r)}async importFromFile(e){try{const t=await e.text();let r;try{r=JSON.parse(t)}catch{r=void 0}if(typeof r!="object"||r===null){const{InterviewImport:s}=await C(async()=>{const{InterviewImport:l}=await import("./interviewImport-C-TiARLK.js");return{InterviewImport:l}},[],import.meta.url),i=this.current,a=[i?.interviewOf].flat().filter(l=>typeof l=="string"),n=s.parse(t,{by:(i?.by??[]).map(l=>m.byText([l])).filter(l=>l!==""),witnesses:this.options.filter(l=>a.length===0||a.includes(l.id))});r=n&&{...n,transcription:{note:`Imported from ${e.name}: who speaks and when are as the file gave them, to be checked.`}}}r===void 0?this.note(this.messages.notATranscript,"error"):await this.take(r)}catch{this.note(this.messages.loadFailed,"error")}}async importFromUrl(e){try{await this.take(await T.json(new URL(e,this.base??location.href).href))}catch{this.note(this.messages.loadFailed,"error")}}save(){const e=this.fileEditor?.text??this.text;if(e===void 0)return;const t=(this.current?.url??"").split("/").pop()||`${this.current?.id??"interview"}.json`,r=URL.createObjectURL(new Blob([e],{type:"application/json"})),s=document.createElement("a");s.href=r,s.download=t,s.click(),URL.revokeObjectURL(r)}}function ee(){Y(),D(),customElements.get(F)||customElements.define(F,m)}export{E as INTERVIEW_CHANGE_EVENT,F as INTERVIEW_EDITOR_ELEMENT_NAME,W as INTERVIEW_SEEK_EVENT,m as InterviewEditorElement,ee as register};
231
+ `}static SHARED=["title","time","medium","by","interviewOf","summary"];static ORDER=["version","id","language","title","time","medium","by","interviewOf","summary","speakers","transcription","proofreading","anonymization","recordings","segments"];static ordered(e){const t={};for(const r of m.ORDER)r in e&&(t[r]=e[r]);for(const r of Object.keys(e))r in t||(t[r]=e[r]);return t}static witnessesOf(e){return[e].flat().filter(t=>typeof t=="string")}static withEventFields(e,t){const r={...e};for(const i of m.SHARED)t[i]===void 0?delete r[i]:r[i]=structuredClone(t[i]);const s=r.speakers;if(typeof s=="object"&&s!==null){const i={...s},a=(n,l,c)=>{c.forEach((o,d)=>{const h=d===0?n:`${n}${d+1}`;i[h]?i[h]={...i[h],[l]:o}:d>0&&(i[h]={role:n,[l]:o})})};a("interviewer","by",t.by??[]),a("witness","of",m.witnessesOf(t.interviewOf)),r.speakers=i}return m.ordered(r)}applyFileToEvent(e,t){const r=this.current;if(!r)return!1;const s=JSON.stringify(m.SHARED.map(n=>r[n])),i=n=>typeof n=="string"||typeof n=="object"&&n!==null&&!Array.isArray(n),a={title:i,summary:i,time:n=>typeof n=="string",medium:n=>typeof n=="string",by:n=>Array.isArray(n),interviewOf:n=>typeof n=="string"||Array.isArray(n)};for(const n of m.SHARED){const l=e[n];l!==void 0&&a[n](l)?r[n]=structuredClone(l):t&&delete r[n]}return JSON.stringify(m.SHARED.map(n=>r[n]))!==s}syncFileFromEvent(){const e=this.current,t=this.fileEditor?.text??this.text;if(!e||t===void 0)return;let r;try{r=JSON.parse(t)}catch{return}if(typeof r!="object"||r===null||Array.isArray(r))return;const s=m.pretty(m.withEventFields(r,e));s!==t&&(this.text=s,this.fileEditor?.replaceText(s,!1),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:e,text:s}})))}template(e){return m.pretty(m.withEventFields({version:1,language:this.language,speakers:{interviewer:{role:"interviewer"},witness:{role:"witness"}},segments:[]},e))}loadFileEditor(e){return this.fileEditorLoading??=(async()=>{try{const[{SightingFileEditor:t},{default:r},s]=await Promise.all([C(()=>import("./SightingFileEditor-bXm0nVE4.js"),__vite__mapDeps([0,1,2]),import.meta.url),C(()=>import("./interviewSchema-DTeTYZOQ.js"),[],import.meta.url),V(this.language)]);return this.fileEditor=new t(this.shadow.getElementById("file-editor"),e,i=>this.onEdited(i),this.messages.editorLabel,{baseline:e,phrases:s.fileSearchPhrases,schema:r}),this.fileEditor}catch(t){throw this.fileEditorLoading=void 0,t}})(),this.fileEditorLoading}async showTranscript(){const e=this.current;if(!e||this.shownFor===e)return;this.note(this.messages.loading);let t=this.text;if(t===void 0){const r=this.transcriptUrl(e);if(r!==void 0)try{const s=await T.json(r);this.current===e&&typeof s=="object"&&s!==null&&!Array.isArray(s)?(this.applyFileToEvent(s,!1)&&this.fileChangedEvent(),t=m.pretty(m.withEventFields(s,e))):t=m.pretty(s)}catch{this.note(this.messages.loadFailed,"error")}t??=this.template(e)}if(this.current===e)try{const r=await this.loadFileEditor(t);if(this.current!==e)return;r.replaceText(t,!1),this.shownFor=e,this.text!==void 0||this.transcriptUrl(e)===void 0?this.note(void 0):this.shadow.getElementById("file-note").textContent===this.messages.loading&&this.note(void 0)}catch{this.note(this.messages.loadFailed,"error")}}onEdited(e){this.text=e;let t,r=!0;try{t=JSON.parse(e)}catch{r=!1}this.note(r?void 0:this.messages.invalid,"error");const s=this.current;if(r&&s&&typeof t=="object"&&t!==null&&!Array.isArray(t)&&this.applyFileToEvent(t,!0)&&this.fileChangedEvent(),s&&!s.url&&e.trim()!==""){const i=s.id??"1";s.url=`${i.startsWith("interview")?i:`interview-${i}`}.json`,this.field("url").value=s.url,this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"url",event:s}}))}this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"transcript",event:s,text:e}})),this.showExchanges()}fileChangedEvent(){this.render(),this.dispatchEvent(new CustomEvent(E,{bubbles:!0,composed:!0,detail:{field:"file",event:this.current}}))}async take(e){if(typeof e!="object"||e===null||!Array.isArray(e.segments)){this.note(this.messages.notATranscript,"error");return}const t=this.current;t&&this.applyFileToEvent(e,!1)&&this.fileChangedEvent();const r=m.pretty(t?m.withEventFields(e,t):e);await this.loadFileEditor(r).then(s=>s.replaceText(r,!1),()=>{}),this.shownFor=this.current,this.note(void 0),this.onEdited(r)}async importFromFile(e){try{const t=await e.text();let r;try{r=JSON.parse(t)}catch{r=void 0}if(typeof r!="object"||r===null){const{InterviewImport:s}=await C(async()=>{const{InterviewImport:l}=await import("./interviewImport-C-TiARLK.js");return{InterviewImport:l}},[],import.meta.url),i=this.current,a=[i?.interviewOf].flat().filter(l=>typeof l=="string"),n=s.parse(t,{by:(i?.by??[]).map(l=>m.byText([l])).filter(l=>l!==""),witnesses:this.options.filter(l=>a.length===0||a.includes(l.id))});r=n&&{...n,transcription:{note:`Imported from ${e.name}: who speaks and when are as the file gave them, to be checked.`}}}r===void 0?this.note(this.messages.notATranscript,"error"):await this.take(r)}catch{this.note(this.messages.loadFailed,"error")}}async importFromUrl(e){try{await this.take(await T.json(new URL(e,this.base??location.href).href))}catch{this.note(this.messages.loadFailed,"error")}}save(){const e=this.fileEditor?.text??this.text;if(e===void 0)return;const t=(this.current?.url??"").split("/").pop()||`${this.current?.id??"interview"}.json`,r=URL.createObjectURL(new Blob([e],{type:"application/json"})),s=document.createElement("a");s.href=r,s.download=t,s.click(),URL.revokeObjectURL(r)}}function ee(){Y(),D(),customElements.get(F)||customElements.define(F,m)}export{E as INTERVIEW_CHANGE_EVENT,F as INTERVIEW_EDITOR_ELEMENT_NAME,W as INTERVIEW_SEEK_EVENT,m as InterviewEditorElement,ee as register};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleThree-CHA3zU14.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
2
- import{_ as w}from"./rr0-sighting-editor.mjs";class n{static MEMBERS={weather:["getWeather"],place:["attribution","search","reverse"],timeZone:["zoneAt"],narrative:["settings","draft"],assessment:["assess"],lightPollution:["year","citation","lookUp"],aircraft:["citation","between"],upperAir:["between"],elevation:["getElevationGrid"],imagery:["attribution","getImageryTexture"],surroundings:["id","name","attribution","creditUrl","contemporary","covers","getSurroundings"],decorModels:["attribution","entries","entry"],skyEvents:["key","messages","simulation"],interpretations:["key","messages","bodiesOf"],perception:["id","messages","sources","settings","perceive"]};static WEATHER_SHARES=["cloudCover","cloudDarkness","precipitationIntensity","highCloudCover","lowerCloudCover","iceCrystalAlignment","rareIceCrystals","relativeHumidity"];static WEATHER_REQUIRED=["cloudCover","cloudDarkness","precipitationIntensity"];static PRECIPITATIONS=["none","rain","snow","hail"];static HIGH_WIND_MS=60;static TIMEOUT_MS=3e4;static async check(e,a={}){const s=[];e.hasScript&&!e.scriptRun&&s.push({level:"note",code:"scriptNotRun"});for(const[t,r]of Object.entries(e.module.contributes))Object.hasOwn(n.MEMBERS,t)?Array.isArray(r)?await n.checkPoint(t,r,a,s):s.push({level:"failed",code:"notAList",point:t}):s.push({level:"failed",code:"unknownPoint",point:t});return s}static async checkPoint(e,a,s,t){const r=new Set;for(const i of a){const c=(l,d,g="failed")=>{t.push({level:g,code:l,point:e,source:typeof i?.id=="string"?i.id:void 0,detail:d})};if(r.has(i?.id)&&c("duplicateId"),r.add(i?.id),n.checkEntry(i,c),typeof i?.create!="function"){c("createMissing");continue}const o=n.build(i,c);if(o===void 0)continue;const h=n.MEMBERS[e].filter(l=>o[l]===void 0);for(const l of h)c("missingMember",l);h.length>0||(e==="weather"&&await n.checkWeather(i.id,o,s,c),e==="skyEvents"&&await n.checkSkyEventKind(i.id,o,s,c),e==="interpretations"&&await n.checkInterpretationKind(i.id,o,s,c))}}static checkEntry(e,a){for(const s of["id","name","credit","creditUrl"]){const t=e?.[s];(typeof t!="string"||t.trim()==="")&&a("entryField",s)}typeof e?.creditUrl=="string"&&e.creditUrl!==""&&!URL.canParse(e.creditUrl)&&a("entryField","creditUrl")}static build(e,a){let s=!1;const t=(async()=>(s=!0,new Response("",{status:503}))),r=globalThis.fetch;globalThis.fetch=t;try{const i=e.create(t);if(s&&a("createAsked"),i==null){a("createEmpty");return}return i}catch(i){a("createThrew",n.told(i));return}finally{globalThis.fetch=r}}static async checkWeather(e,a,s,t){const r=s.weatherQuery;if(!r){t("weatherNotAsked",void 0,"note");return}let i;try{i=await n.within(a.getWeather(r),s)}catch(l){t("weatherThrew",n.told(l));return}if(i===void 0){t("weatherNoRecord",void 0,"note");return}const c=i?.samples;if(!Array.isArray(c)||c.length!==r.points.length){t("weatherSamples",`${Array.isArray(c)?c.length:0}/${r.points.length}`);return}c.some((l,d)=>l?.time?.getTime?.()!==r.points[d].time.getTime())&&t("weatherOrder");const o=new Set;let h=!1;for(const l of c){const d=l?.weather??{};for(const g of n.WEATHER_SHARES){const u=d[g],p=n.WEATHER_REQUIRED.includes(g);(u!==void 0||p)&&!n.between(u,0,1)&&o.add(`${g} = ${String(u)}`)}n.between(d.windDirectionDeg,0,360)||o.add(`windDirectionDeg = ${String(d.windDirectionDeg)}`),n.between(d.windSpeed,0,1/0)?d.windSpeed>n.HIGH_WIND_MS&&(h=!0):o.add(`windSpeed = ${String(d.windSpeed)}`),n.PRECIPITATIONS.includes(d.precipitationType)||o.add(`precipitationType = ${String(d.precipitationType)}`),typeof d.storm!="boolean"&&o.add(`storm = ${String(d.storm)}`)}for(const l of o)t("weatherValue",l);h&&t("weatherWindHigh",void 0,"note"),i.source?.id!==e&&t("weatherSource","id"),(typeof i.source?.name!="string"||i.source.name==="")&&t("weatherSource","name"),(typeof i.source?.url!="string"||i.source.url==="")&&t("weatherSource","url")}static async checkSkyEventKind(e,a,s,t){a.key!==e&&t("kindKey",String(a.key)),await n.checkTexts(a.messages,["title","name"],s,t);let r;try{r=(await n.within(a.simulation(),s))()}catch(o){t("simulationFailed",n.told(o));return}const{MODULE_THREE:i}=await w(async()=>{const{MODULE_THREE:o}=await import("./ModuleThree-CHA3zU14.js");return{MODULE_THREE:o}},__vite__mapDeps([0,1]),import.meta.url);if(!(r?.object instanceof i.Object3D)){t("secondThree");return}try{r.update([],0,n.frame(new i.Vector3)),r.drawnCount!==0&&t("drawnWithoutEvents",String(r.drawnCount))}catch(o){t("updateThrew",n.told(o))}const c=new i.Group;c.add(r.object);try{r.dispose(),r.object.parent===c&&t("disposeLeft")}catch(o){t("disposeThrew",n.told(o))}}static async checkInterpretationKind(e,a,s,t){a.key!==e&&t("kindKey",String(a.key)),await n.checkTexts(a.messages,["title"],s,t);const r=s.interpretation?.[a.key];if(!Array.isArray(r)||r.length===0){t("readingNotTried",void 0,"note");return}for(const i of r)try{const c=a.bodiesOf(i);Array.isArray(c)||t("readingNotAList")}catch(c){t("readingThrew",n.told(c))}}static async checkTexts(e,a,s,t){for(const r of["en","fr"])try{const i=await n.within(e.load(r),s);for(const c of a)(typeof i?.[c]!="string"||i[c]==="")&&t("kindMessages",`${r}: ${c}`)}catch(i){t("kindMessages",`${r}: ${n.told(i)}`)}}static frame(e){return{reference:{lat:0,lng:0},origin:{x:0,z:0},eastScale:1,siteElevationM:0,eye:e,pixelRad:.001,relativeScale:1,air:{},transmittanceTo:()=>[1,1,1],groundYAt:()=>0,wind:{eastMS:0,northMS:0},observer:{lat:0,lng:0,heightM:0},date:new Date(0),magnitudeLimit:6,cloudTransmission:()=>1,arrivingIlluminance:()=>[0,0,0],transmittanceFromSpace:()=>[1,1,1],lightFrom:()=>{},glareFrom:()=>{}}}static between(e,a,s){return typeof e=="number"&&!Number.isNaN(e)&&e>=a&&e<=s}static told(e){return e instanceof Error?e.message:String(e)}static within(e,a){const s=a.timeoutMs??n.TIMEOUT_MS;let t;const r=new Promise((i,c)=>{t=setTimeout(()=>c(new Error(`> ${s/1e3} s`)),s)});return Promise.race([e,r]).finally(()=>clearTimeout(t))}}export{n as ModuleConformance};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleThree-DsbRgMxg.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
2
+ import{_ as w}from"./rr0-sighting-editor.mjs";class n{static MEMBERS={weather:["getWeather"],place:["attribution","search","reverse"],timeZone:["zoneAt"],narrative:["settings","draft"],assessment:["assess"],lightPollution:["year","citation","lookUp"],aircraft:["citation","between"],upperAir:["between"],elevation:["getElevationGrid"],imagery:["attribution","getImageryTexture"],surroundings:["id","name","attribution","creditUrl","contemporary","covers","getSurroundings"],decorModels:["attribution","entries","entry"],skyEvents:["key","messages","simulation"],interpretations:["key","messages","bodiesOf"],perception:["id","messages","sources","settings","perceive"]};static WEATHER_SHARES=["cloudCover","cloudDarkness","precipitationIntensity","highCloudCover","lowerCloudCover","iceCrystalAlignment","rareIceCrystals","relativeHumidity"];static WEATHER_REQUIRED=["cloudCover","cloudDarkness","precipitationIntensity"];static PRECIPITATIONS=["none","rain","snow","hail"];static HIGH_WIND_MS=60;static TIMEOUT_MS=3e4;static async check(e,a={}){const s=[];e.hasScript&&!e.scriptRun&&s.push({level:"note",code:"scriptNotRun"});for(const[t,r]of Object.entries(e.module.contributes))Object.hasOwn(n.MEMBERS,t)?Array.isArray(r)?await n.checkPoint(t,r,a,s):s.push({level:"failed",code:"notAList",point:t}):s.push({level:"failed",code:"unknownPoint",point:t});return s}static async checkPoint(e,a,s,t){const r=new Set;for(const i of a){const c=(l,d,g="failed")=>{t.push({level:g,code:l,point:e,source:typeof i?.id=="string"?i.id:void 0,detail:d})};if(r.has(i?.id)&&c("duplicateId"),r.add(i?.id),n.checkEntry(i,c),typeof i?.create!="function"){c("createMissing");continue}const o=n.build(i,c);if(o===void 0)continue;const h=n.MEMBERS[e].filter(l=>o[l]===void 0);for(const l of h)c("missingMember",l);h.length>0||(e==="weather"&&await n.checkWeather(i.id,o,s,c),e==="skyEvents"&&await n.checkSkyEventKind(i.id,o,s,c),e==="interpretations"&&await n.checkInterpretationKind(i.id,o,s,c))}}static checkEntry(e,a){for(const s of["id","name","credit","creditUrl"]){const t=e?.[s];(typeof t!="string"||t.trim()==="")&&a("entryField",s)}typeof e?.creditUrl=="string"&&e.creditUrl!==""&&!URL.canParse(e.creditUrl)&&a("entryField","creditUrl")}static build(e,a){let s=!1;const t=(async()=>(s=!0,new Response("",{status:503}))),r=globalThis.fetch;globalThis.fetch=t;try{const i=e.create(t);if(s&&a("createAsked"),i==null){a("createEmpty");return}return i}catch(i){a("createThrew",n.told(i));return}finally{globalThis.fetch=r}}static async checkWeather(e,a,s,t){const r=s.weatherQuery;if(!r){t("weatherNotAsked",void 0,"note");return}let i;try{i=await n.within(a.getWeather(r),s)}catch(l){t("weatherThrew",n.told(l));return}if(i===void 0){t("weatherNoRecord",void 0,"note");return}const c=i?.samples;if(!Array.isArray(c)||c.length!==r.points.length){t("weatherSamples",`${Array.isArray(c)?c.length:0}/${r.points.length}`);return}c.some((l,d)=>l?.time?.getTime?.()!==r.points[d].time.getTime())&&t("weatherOrder");const o=new Set;let h=!1;for(const l of c){const d=l?.weather??{};for(const g of n.WEATHER_SHARES){const u=d[g],p=n.WEATHER_REQUIRED.includes(g);(u!==void 0||p)&&!n.between(u,0,1)&&o.add(`${g} = ${String(u)}`)}n.between(d.windDirectionDeg,0,360)||o.add(`windDirectionDeg = ${String(d.windDirectionDeg)}`),n.between(d.windSpeed,0,1/0)?d.windSpeed>n.HIGH_WIND_MS&&(h=!0):o.add(`windSpeed = ${String(d.windSpeed)}`),n.PRECIPITATIONS.includes(d.precipitationType)||o.add(`precipitationType = ${String(d.precipitationType)}`),typeof d.storm!="boolean"&&o.add(`storm = ${String(d.storm)}`)}for(const l of o)t("weatherValue",l);h&&t("weatherWindHigh",void 0,"note"),i.source?.id!==e&&t("weatherSource","id"),(typeof i.source?.name!="string"||i.source.name==="")&&t("weatherSource","name"),(typeof i.source?.url!="string"||i.source.url==="")&&t("weatherSource","url")}static async checkSkyEventKind(e,a,s,t){a.key!==e&&t("kindKey",String(a.key)),await n.checkTexts(a.messages,["title","name"],s,t);let r;try{r=(await n.within(a.simulation(),s))()}catch(o){t("simulationFailed",n.told(o));return}const{MODULE_THREE:i}=await w(async()=>{const{MODULE_THREE:o}=await import("./ModuleThree-DsbRgMxg.js");return{MODULE_THREE:o}},__vite__mapDeps([0,1]),import.meta.url);if(!(r?.object instanceof i.Object3D)){t("secondThree");return}try{r.update([],0,n.frame(new i.Vector3)),r.drawnCount!==0&&t("drawnWithoutEvents",String(r.drawnCount))}catch(o){t("updateThrew",n.told(o))}const c=new i.Group;c.add(r.object);try{r.dispose(),r.object.parent===c&&t("disposeLeft")}catch(o){t("disposeThrew",n.told(o))}}static async checkInterpretationKind(e,a,s,t){a.key!==e&&t("kindKey",String(a.key)),await n.checkTexts(a.messages,["title"],s,t);const r=s.interpretation?.[a.key];if(!Array.isArray(r)||r.length===0){t("readingNotTried",void 0,"note");return}for(const i of r)try{const c=a.bodiesOf(i);Array.isArray(c)||t("readingNotAList")}catch(c){t("readingThrew",n.told(c))}}static async checkTexts(e,a,s,t){for(const r of["en","fr"])try{const i=await n.within(e.load(r),s);for(const c of a)(typeof i?.[c]!="string"||i[c]==="")&&t("kindMessages",`${r}: ${c}`)}catch(i){t("kindMessages",`${r}: ${n.told(i)}`)}}static frame(e){return{reference:{lat:0,lng:0},origin:{x:0,z:0},eastScale:1,siteElevationM:0,eye:e,pixelRad:.001,relativeScale:1,air:{},transmittanceTo:()=>[1,1,1],groundYAt:()=>0,wind:{eastMS:0,northMS:0},observer:{lat:0,lng:0,heightM:0},date:new Date(0),magnitudeLimit:6,cloudTransmission:()=>1,arrivingIlluminance:()=>[0,0,0],transmittanceFromSpace:()=>[1,1,1],lightFrom:()=>{},glareFrom:()=>{}}}static between(e,a,s){return typeof e=="number"&&!Number.isNaN(e)&&e>=a&&e<=s}static told(e){return e instanceof Error?e.message:String(e)}static within(e,a){const s=a.timeoutMs??n.TIMEOUT_MS;let t;const r=new Promise((i,c)=>{t=setTimeout(()=>c(new Error(`> ${s/1e3} s`)),s)});return Promise.race([e,r]).finally(()=>clearTimeout(t))}}export{n as ModuleConformance};
@@ -1,3 +1,3 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleThree-CHA3zU14.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleThree-DsbRgMxg.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
2
2
  import{q as g,t as w,_ as b,n as p}from"./rr0-sighting-editor.mjs";class n{static STORAGE_KEY="ufoathome.modules";static FORMAT=1;static empty(){return{format:1,modules:[]}}static read(t=n.storage()){try{const e=t?.getItem(n.STORAGE_KEY);return e?n.parse(e):n.empty()}catch{return n.empty()}}static write(t,e=n.storage()){try{return e?(t.modules.length===0?e.removeItem(n.STORAGE_KEY):e.setItem(n.STORAGE_KEY,n.text(t)),!0):!1}catch{return!1}}static parse(t){const e=JSON.parse(t);if(e===null||typeof e!="object"||!Array.isArray(e.modules))throw new Error("not a UFO@home module list");if(typeof e.format=="number"&&e.format>n.FORMAT)throw new Error(`format ${e.format} is newer than ${n.FORMAT}`);const r=new Set,s=[];for(const i of e.modules)typeof i?.url!="string"||r.has(i.url)||(r.add(i.url),s.push({url:i.url,enabled:i.enabled!==!1}));return{format:1,modules:s}}static text(t){return JSON.stringify({format:n.FORMAT,modules:t.modules},null,2)+`
3
- `}static storage(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}}class E{constructor(t,e){this.attribution=t,this.models=e}async entries(t){return t?this.models.filter(e=>[e.kind].flat().includes(t)):[...this.models]}async entry(t){return this.models.find(e=>e.id===t)}}class f{attribution;fetchImpl;tileUrlTemplate;constructor(t){this.attribution=t.attribution,this.tileUrlTemplate=t.tileUrlTemplate,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis)}getImageryTexture(t,e){return g(t,e,r=>f.tileUrl(this.tileUrlTemplate,r),this.fetchImpl)}static tileUrl(t,e){return t.replaceAll("{z}",String(e.z)).replaceAll("{x}",String(e.x)).replaceAll("{y}",String(e.y))}}class v extends Error{constructor(t,e){super(`${t}: ${e}`),this.url=t,this.reason=e,this.name="ModuleManifestError"}}class d{static FORMAT=1;static check(t,e){const r=o=>{throw new v(e,o)};(t===null||typeof t!="object"||Array.isArray(t))&&r("not a JSON object");const s=t;typeof s.format!="number"&&r('no "format"'),s.format>d.FORMAT&&r(`format ${s.format} is newer than ${d.FORMAT}, which this version reads`),(typeof s.id!="string"||!/^[a-z0-9][a-z0-9._-]*$/.test(s.id))&&r(`"id" must be lowercase letters, digits, '.', '_' or '-'`),(typeof s.name!="string"||s.name.trim()==="")&&r('no "name"'),s.script!==void 0&&typeof s.script!="string"&&r('"script" must be an address');const i=s.contributes??{};for(const o of["imagery","elevation"]){const c=i[o];c!==void 0&&(Array.isArray(c)||r(`"contributes.${o}" must be a list`),c.forEach((l,h)=>{for(const m of["id","name","credit","creditUrl","tiles"])(typeof l?.[m]!="string"||l[m]==="")&&r(`"contributes.${o}[${h}].${m}" is missing`);["{z}","{x}","{y}"].every(m=>l.tiles.includes(m))||r(`"contributes.${o}[${h}].tiles" must hold {z}, {x} and {y}`)}))}const a=i.models;return a!==void 0&&(Array.isArray(a)||r('"contributes.models" must be a list'),a.forEach((o,c)=>{for(const l of["id","name","file"])(typeof o?.[l]!="string"||o[l]==="")&&r(`"contributes.models[${c}].${l}" is missing`);o.kind===void 0&&r(`"contributes.models[${c}].kind" is missing`),(!o.credit||typeof o.credit!="object")&&r(`"contributes.models[${c}].credit" is missing: a model is shown with its author and licence`)})),s}static contributions(t,e){const r=t.contributes??{},s={};if(r.imagery?.length&&(s.imagery=r.imagery.map(i=>({id:i.id,name:i.name,credit:i.credit,creditUrl:i.creditUrl,create:a=>new f({tileUrlTemplate:d.absoluteTemplate(i.tiles,e),attribution:i.credit,fetchImpl:a})}))),r.elevation?.length&&(s.elevation=r.elevation.map(i=>({id:i.id,name:i.name,credit:i.credit,creditUrl:i.creditUrl,create:a=>new w({tileUrlTemplate:d.absoluteTemplate(i.tiles,e),fetchImpl:a})}))),r.models?.length){const i=r.models.map(({file:o,...c})=>({...c,url:new URL(o,e).href})),a=t.credit??t.name;s.decorModels=[{id:`${t.id}-models`,name:t.name,credit:a,creditUrl:t.creditUrl??e,create:()=>new E(a,i)}]}return s}static module(t,e,r={}){const s=d.contributions(t,e);for(const[i,a]of Object.entries(r))Array.isArray(a)&&(s[i]=[...s[i]??[],...a]);return{id:t.id,name:t.name,credit:t.credit,creditUrl:t.creditUrl,url:e,contributes:s}}static absoluteTemplate(t,e){const r=t.replaceAll("{z}","__Z__").replaceAll("{x}","__X__").replaceAll("{y}","__Y__");return new URL(r,e).href.replaceAll("__Z__","{z}").replaceAll("__X__","{x}").replaceAll("__Y__","{y}")}}class T{fetchImpl;importImpl;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.importImpl=t.importImpl??(e=>import(e))}async load(t,e){const r=await this.fetchImpl(t);if(!r.ok)throw new Error(`${t}: HTTP ${r.status}`);const s=d.check(await r.json(),t),i=s.script!==void 0;let a={};if(i&&e.runScript){const o=new URL(s.script,t).href,c=await this.importImpl(o);if(typeof c.default!="function")throw new Error(`${o}: its default export is not a function`);const{MODULE_THREE:l}=await b(async()=>{const{MODULE_THREE:h}=await import("./ModuleThree-CHA3zU14.js");return{MODULE_THREE:h}},__vite__mapDeps([0,1]),import.meta.url);a=await c.default({manifestUrl:t,three:l})??{}}return{url:t,manifest:s,module:d.module(s,t,a),hasScript:i,scriptRun:i&&e.runScript}}}class y{constructor(t=new T,e){this.loader=t,this.storage=e}static shared=new y;changes=new EventTarget;states=new Map;config=n.empty();started;list(){const t=[...this.states.values()];return[...t.filter(e=>e.addedByPerson),...t.filter(e=>!e.addedByPerson)]}state(t){return this.states.get(t)}start(){return this.started??=this.applyConfig(n.read(this.storage)),this.started}async add(t){await this.start();const e=new URL(t,typeof location>"u"?void 0:location.href).href;return this.config.modules.some(r=>r.url===e)||(this.config={...this.config,modules:[...this.config.modules,{url:e,enabled:!0}]},this.save()),this.reload(e)}async remove(t){this.config={...this.config,modules:this.config.modules.filter(e=>e.url!==t)},this.save(),await this.reload(t)}async setEnabled(t,e){this.config={...this.config,modules:this.config.modules.map(r=>r.url===t?{...r,enabled:e}:r)},this.save(),await this.reload(t)}exportText(){return n.text(this.config)}async importText(t){const e=n.parse(t);await this.start();const r=this.config.modules.map(s=>s.url);this.config=e,this.save(),await Promise.all([...new Set([...r,...e.modules.map(s=>s.url)])].map(s=>this.reload(s)))}async require(t,e){t?.length&&(await this.start(),await Promise.all(t.map(async r=>{let s;try{s=new URL(r,e??(typeof location>"u"?void 0:location.href)).href}catch{return}const i=this.states.get(s);if(i&&i.status!=="off")return i.status==="loading"?this.pending.get(s):void 0;this.named.add(s),await this.reload(s)})))}named=new Set;pending=new Map;async applyConfig(t){this.config=t,await Promise.all(t.modules.map(e=>this.reload(e.url)))}reload(t){const e=this.reloadNow(t);return this.pending.set(t,e),e}async reloadNow(t){const e=this.config.modules.find(a=>a.url===t),r=this.states.get(t);r?.loaded&&p.uninstall(r.loaded.module.id);const s=e!==void 0,i=e?.enabled??!0;if(!s&&!this.named.has(t))return this.states.delete(t),this.announce(),{url:t,addedByPerson:s,enabled:i,status:"off"};if(s&&!i&&!this.named.has(t))return this.set({url:t,addedByPerson:s,enabled:i,status:"off"});this.set({url:t,addedByPerson:s,enabled:i,status:"loading"});try{const a=await this.loader.load(t,{runScript:s&&i});return p.install(a.module),this.set({url:t,addedByPerson:s,enabled:i,status:"installed",loaded:a})}catch(a){return this.set({url:t,addedByPerson:s,enabled:i,status:"failed",error:a instanceof Error?a.message:String(a)})}}set(t){return this.states.set(t.url,t),this.announce(),t}save(){n.write(this.config,this.storage)}announce(){this.changes.dispatchEvent(new Event("change"))}}export{y as ModuleSession};
3
+ `}static storage(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}}class E{constructor(t,e){this.attribution=t,this.models=e}async entries(t){return t?this.models.filter(e=>[e.kind].flat().includes(t)):[...this.models]}async entry(t){return this.models.find(e=>e.id===t)}}class f{attribution;fetchImpl;tileUrlTemplate;constructor(t){this.attribution=t.attribution,this.tileUrlTemplate=t.tileUrlTemplate,this.fetchImpl=t.fetchImpl??fetch.bind(globalThis)}getImageryTexture(t,e){return g(t,e,r=>f.tileUrl(this.tileUrlTemplate,r),this.fetchImpl)}static tileUrl(t,e){return t.replaceAll("{z}",String(e.z)).replaceAll("{x}",String(e.x)).replaceAll("{y}",String(e.y))}}class v extends Error{constructor(t,e){super(`${t}: ${e}`),this.url=t,this.reason=e,this.name="ModuleManifestError"}}class d{static FORMAT=1;static check(t,e){const r=o=>{throw new v(e,o)};(t===null||typeof t!="object"||Array.isArray(t))&&r("not a JSON object");const s=t;typeof s.format!="number"&&r('no "format"'),s.format>d.FORMAT&&r(`format ${s.format} is newer than ${d.FORMAT}, which this version reads`),(typeof s.id!="string"||!/^[a-z0-9][a-z0-9._-]*$/.test(s.id))&&r(`"id" must be lowercase letters, digits, '.', '_' or '-'`),(typeof s.name!="string"||s.name.trim()==="")&&r('no "name"'),s.script!==void 0&&typeof s.script!="string"&&r('"script" must be an address');const i=s.contributes??{};for(const o of["imagery","elevation"]){const c=i[o];c!==void 0&&(Array.isArray(c)||r(`"contributes.${o}" must be a list`),c.forEach((l,h)=>{for(const m of["id","name","credit","creditUrl","tiles"])(typeof l?.[m]!="string"||l[m]==="")&&r(`"contributes.${o}[${h}].${m}" is missing`);["{z}","{x}","{y}"].every(m=>l.tiles.includes(m))||r(`"contributes.${o}[${h}].tiles" must hold {z}, {x} and {y}`)}))}const a=i.models;return a!==void 0&&(Array.isArray(a)||r('"contributes.models" must be a list'),a.forEach((o,c)=>{for(const l of["id","name","file"])(typeof o?.[l]!="string"||o[l]==="")&&r(`"contributes.models[${c}].${l}" is missing`);o.kind===void 0&&r(`"contributes.models[${c}].kind" is missing`),(!o.credit||typeof o.credit!="object")&&r(`"contributes.models[${c}].credit" is missing: a model is shown with its author and licence`)})),s}static contributions(t,e){const r=t.contributes??{},s={};if(r.imagery?.length&&(s.imagery=r.imagery.map(i=>({id:i.id,name:i.name,credit:i.credit,creditUrl:i.creditUrl,create:a=>new f({tileUrlTemplate:d.absoluteTemplate(i.tiles,e),attribution:i.credit,fetchImpl:a})}))),r.elevation?.length&&(s.elevation=r.elevation.map(i=>({id:i.id,name:i.name,credit:i.credit,creditUrl:i.creditUrl,create:a=>new w({tileUrlTemplate:d.absoluteTemplate(i.tiles,e),fetchImpl:a})}))),r.models?.length){const i=r.models.map(({file:o,...c})=>({...c,url:new URL(o,e).href})),a=t.credit??t.name;s.decorModels=[{id:`${t.id}-models`,name:t.name,credit:a,creditUrl:t.creditUrl??e,create:()=>new E(a,i)}]}return s}static module(t,e,r={}){const s=d.contributions(t,e);for(const[i,a]of Object.entries(r))Array.isArray(a)&&(s[i]=[...s[i]??[],...a]);return{id:t.id,name:t.name,credit:t.credit,creditUrl:t.creditUrl,url:e,contributes:s}}static absoluteTemplate(t,e){const r=t.replaceAll("{z}","__Z__").replaceAll("{x}","__X__").replaceAll("{y}","__Y__");return new URL(r,e).href.replaceAll("__Z__","{z}").replaceAll("__X__","{x}").replaceAll("__Y__","{y}")}}class T{fetchImpl;importImpl;constructor(t={}){this.fetchImpl=t.fetchImpl??fetch.bind(globalThis),this.importImpl=t.importImpl??(e=>import(e))}async load(t,e){const r=await this.fetchImpl(t);if(!r.ok)throw new Error(`${t}: HTTP ${r.status}`);const s=d.check(await r.json(),t),i=s.script!==void 0;let a={};if(i&&e.runScript){const o=new URL(s.script,t).href,c=await this.importImpl(o);if(typeof c.default!="function")throw new Error(`${o}: its default export is not a function`);const{MODULE_THREE:l}=await b(async()=>{const{MODULE_THREE:h}=await import("./ModuleThree-DsbRgMxg.js");return{MODULE_THREE:h}},__vite__mapDeps([0,1]),import.meta.url);a=await c.default({manifestUrl:t,three:l})??{}}return{url:t,manifest:s,module:d.module(s,t,a),hasScript:i,scriptRun:i&&e.runScript}}}class y{constructor(t=new T,e){this.loader=t,this.storage=e}static shared=new y;changes=new EventTarget;states=new Map;config=n.empty();started;list(){const t=[...this.states.values()];return[...t.filter(e=>e.addedByPerson),...t.filter(e=>!e.addedByPerson)]}state(t){return this.states.get(t)}start(){return this.started??=this.applyConfig(n.read(this.storage)),this.started}async add(t){await this.start();const e=new URL(t,typeof location>"u"?void 0:location.href).href;return this.config.modules.some(r=>r.url===e)||(this.config={...this.config,modules:[...this.config.modules,{url:e,enabled:!0}]},this.save()),this.reload(e)}async remove(t){this.config={...this.config,modules:this.config.modules.filter(e=>e.url!==t)},this.save(),await this.reload(t)}async setEnabled(t,e){this.config={...this.config,modules:this.config.modules.map(r=>r.url===t?{...r,enabled:e}:r)},this.save(),await this.reload(t)}exportText(){return n.text(this.config)}async importText(t){const e=n.parse(t);await this.start();const r=this.config.modules.map(s=>s.url);this.config=e,this.save(),await Promise.all([...new Set([...r,...e.modules.map(s=>s.url)])].map(s=>this.reload(s)))}async require(t,e){t?.length&&(await this.start(),await Promise.all(t.map(async r=>{let s;try{s=new URL(r,e??(typeof location>"u"?void 0:location.href)).href}catch{return}const i=this.states.get(s);if(i&&i.status!=="off")return i.status==="loading"?this.pending.get(s):void 0;this.named.add(s),await this.reload(s)})))}named=new Set;pending=new Map;async applyConfig(t){this.config=t,await Promise.all(t.modules.map(e=>this.reload(e.url)))}reload(t){const e=this.reloadNow(t);return this.pending.set(t,e),e}async reloadNow(t){const e=this.config.modules.find(a=>a.url===t),r=this.states.get(t);r?.loaded&&p.uninstall(r.loaded.module.id);const s=e!==void 0,i=e?.enabled??!0;if(!s&&!this.named.has(t))return this.states.delete(t),this.announce(),{url:t,addedByPerson:s,enabled:i,status:"off"};if(s&&!i&&!this.named.has(t))return this.set({url:t,addedByPerson:s,enabled:i,status:"off"});this.set({url:t,addedByPerson:s,enabled:i,status:"loading"});try{const a=await this.loader.load(t,{runScript:s&&i});return p.install(a.module),this.set({url:t,addedByPerson:s,enabled:i,status:"installed",loaded:a})}catch(a){return this.set({url:t,addedByPerson:s,enabled:i,status:"failed",error:a instanceof Error?a.message:String(a)})}}set(t){return this.states.set(t.url,t),this.announce(),t}save(){n.write(this.config,this.storage)}announce(){this.changes.dispatchEvent(new Event("change"))}}export{y as ModuleSession};
@@ -0,0 +1 @@
1
+ import{V as a,aR as e,bY as s,b6 as t,b8 as r,bh as i,aZ as o,Q as b,b5 as n,aC as l,bq as u,bi as d,u as m,bZ as M,ad as c,ap as B,ab as S,w as y,bI as G,bF as f,bJ as h,a8 as p,bW as g,aT as x,v as C,aq as E,b_ as L,b$ as T,c0 as D,aE as P,b7 as v,an as A,ao as F,c1 as V,bg as q,ar as O}from"./rr0-sighting-editor.mjs";const R={AdditiveBlending:O,BackSide:q,BoxGeometry:V,BufferAttribute:F,BufferGeometry:A,CanvasTexture:v,Color:P,ConeGeometry:D,CylinderGeometry:T,DataTexture:L,DoubleSide:E,Euler:C,Float32BufferAttribute:x,FrontSide:g,Group:p,Line:h,LineBasicMaterial:f,LineSegments:G,Matrix4:y,Mesh:S,MeshBasicMaterial:B,MeshStandardMaterial:c,NormalBlending:M,Object3D:m,PlaneGeometry:d,PointLight:u,Points:l,PointsMaterial:n,Quaternion:b,ShaderMaterial:o,SphereGeometry:i,Sprite:r,SpriteMaterial:t,TorusGeometry:s,Vector2:e,Vector3:a};export{R as MODULE_THREE};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleConformance-BRi5HHIj.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
2
- import{o as _,_ as x,H as y,p as L,M as m}from"./rr0-sighting-editor.mjs";import{ModuleSession as C}from"./ModuleSession-DzFSCz3B.js";const M=_.catalog({en:()=>x(()=>import("./ModulesPanelMessages_en-t8LOPRx0.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_en),fr:()=>x(()=>import("./ModulesPanelMessages_fr-DZMwqDs0.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_fr),es:()=>x(()=>import("./ModulesPanelMessages_es-DQFuXaUa.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_es),it:()=>x(()=>import("./ModulesPanelMessages_it-DfX1ObVK.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_it)}),N="rr0-modules-panel",P=`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ModuleConformance-H7LbISvs.js","./rr0-sighting-editor.mjs"])))=>i.map(i=>d[i]);
2
+ import{o as _,_ as x,H as y,p as L,M as m}from"./rr0-sighting-editor.mjs";import{ModuleSession as C}from"./ModuleSession-BXk5ijvF.js";const M=_.catalog({en:()=>x(()=>import("./ModulesPanelMessages_en-t8LOPRx0.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_en),fr:()=>x(()=>import("./ModulesPanelMessages_fr-DZMwqDs0.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_fr),es:()=>x(()=>import("./ModulesPanelMessages_es-DQFuXaUa.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_es),it:()=>x(()=>import("./ModulesPanelMessages_it-DfX1ObVK.js"),[],import.meta.url).then(b=>b.modulesPanelMessages_it)}),N="rr0-modules-panel",P=`
3
3
  rr0-modules-panel { display: block; }
4
4
  rr0-modules-panel .mp-add { display: flex; gap: .4em; align-items: center; margin: .4em 0; }
5
5
  rr0-modules-panel .mp-add input { flex: 1 1 16em; min-width: 0; }
@@ -12,4 +12,4 @@ rr0-modules-panel .mp-head .mp-remove { margin-left: auto; }
12
12
  rr0-modules-panel .mp-module p { margin: .2em 0; }
13
13
  rr0-modules-panel .mp-findings { margin: .3em 0; padding-left: 1.2em; }
14
14
  rr0-modules-panel .mp-files { display: flex; gap: .6em; flex-wrap: wrap; align-items: center; margin-top: .6em; }
15
- `;class A extends HTMLElement{session=C.shared;messages;languageAsked=!1;named=[];recordingBase;note;languageToken=0;draft="";onChange=()=>this.render();checkContext;checks=new Map;set moduleSession(e){this.session.changes.removeEventListener("change",this.onChange),this.session=e,this.isConnected&&this.session.changes.addEventListener("change",this.onChange),this.render()}get recordingModules(){return[...this.named]}set recordingModules(e){this.named=[...e??[]],this.render()}set base(e){this.recordingBase=e,this.render()}async setLanguage(e){this.languageAsked=!0;const t=++this.languageToken,n=await M.load(e);t===this.languageToken&&(this.messages=n,this.render())}connectedCallback(){this.languageAsked||this.setLanguage(y.preferencesFor(this)[0]??"en"),this.session.changes.addEventListener("change",this.onChange),this.session.start(),this.render()}disconnectedCallback(){this.session.changes.removeEventListener("change",this.onChange)}absolute(e){try{return new URL(e,this.recordingBase??location.href).href}catch{return}}isNamed(e){return this.named.some(t=>this.absolute(t)===e)}setNamed(e,t){t!==this.isNamed(e)&&(this.named=t?[...this.named,L.of(e,this.recordingBase)]:this.named.filter(n=>this.absolute(n)!==e),t&&this.session.require([e]),this.dispatchEvent(new Event("recordingmoduleschange",{bubbles:!0})),this.render())}render(){const e=this.messages;if(!this.isConnected||!this.messages)return;const t=this.ownerDocument,n=t.createElement("style");n.textContent=P;const s=t.createElement("p");s.className=m.INFO,s.textContent=e.intro;const a=t.createElement("form");a.className="mp-add";const i=t.createElement("input");i.type="url",i.id="module-url",i.required=!0,i.placeholder=e.urlPlaceholder,i.value=this.draft,i.addEventListener("input",()=>{this.draft=i.value}),i.setAttribute("aria-label",e.urlPlaceholder);const u=t.createElement("button");u.type="submit",u.textContent=e.add,a.append(i,u),a.addEventListener("submit",r=>{r.preventDefault();const w=i.value.trim();w&&(this.draft="",this.session.add(w))});const l=t.createElement("p");l.className=m.WARNING,l.textContent=e.codeWarning;const c=this.session.list(),h=new Set(c.map(r=>r.url)),v=this.named.map(r=>this.absolute(r)).filter(r=>r!==void 0&&!h.has(r)),g=t.createElement("ul");g.className="mp-list",g.append(...c.map(r=>this.item(r)),...v.map(r=>this.item({url:r,addedByPerson:!1,enabled:!0,status:"loading"})));const k=t.createElement("p");k.className=m.INFO,k.textContent=e.none,k.hidden=g.childElementCount>0;const f=t.createElement("div");f.className="mp-files";const E=t.createElement("button");E.type="button",E.id="modules-export",E.textContent=e.exportConfig,E.disabled=!c.some(r=>r.addedByPerson),E.addEventListener("click",()=>this.download());const p=t.createElement("input");p.type="file",p.id="modules-import",p.accept="application/json,.json",p.hidden=!0;const o=t.createElement("button");o.type="button",o.textContent=e.importConfig,o.addEventListener("click",()=>p.click()),p.addEventListener("change",()=>{const r=p.files?.[0];r&&this.importFile(r),p.value=""}),f.append(E,o,p);const d=t.createElement("p");d.id="modules-note",d.setAttribute("role","status"),m.show(d,this.note?.text,this.note?.kind),this.replaceChildren(n,s,a,l,g,k,f,d)}item(e){const t=this.messages,n=this.ownerDocument,s=e.loaded,a=n.createElement("li");a.className="mp-module",a.dataset.url=e.url;const i=n.createElement("div");if(i.className="mp-head",e.addedByPerson){const o=n.createElement("label"),d=n.createElement("input");d.type="checkbox",d.className="mp-enabled",d.checked=e.enabled,d.addEventListener("change",()=>void this.session.setEnabled(e.url,d.checked)),o.append(d,n.createTextNode(` ${t.enabled}`)),i.append(o)}const u=n.createElement("span");u.className="mp-name",u.textContent=e.loaded?.module.name??e.url,i.append(u);const l=e.loaded?.module.credit;if(l){const o=n.createElement(e.loaded?.module.creditUrl?"a":"span");o.className=m.INFO,o.textContent=l,o instanceof HTMLAnchorElement&&(o.href=e.loaded.module.creditUrl,o.target="_blank",o.rel="noopener noreferrer"),i.append(o)}const c=n.createElement("button");if(c.type="button",c.className="mp-remove",e.addedByPerson?(c.textContent=t.remove,c.addEventListener("click",()=>void this.session.remove(e.url))):(c.textContent=t.addToMine,c.addEventListener("click",()=>void this.session.add(e.url))),e.status==="installed"&&s){const o=n.createElement("button");o.type="button",o.className="mp-check";const d=this.checks.get(e.url),r=d?.of===s&&d.findings===void 0&&d.crash===void 0;o.textContent=r?t.checking:t.check,o.disabled=r,o.addEventListener("click",()=>void this.check(e.url,s)),i.append(o)}i.append(c);const h=n.createElement("p");h.className=`${m.INFO} mp-url`,h.textContent=e.url;const v=n.createElement("p");v.className="mp-status",e.status==="loading"?m.show(v,t.loading):e.status==="failed"?m.show(v,t.failed.replace("{error}",e.error??""),"error"):e.status==="off"?m.show(v,t.off):m.show(v,this.brings(e));const g=n.createElement("p");g.className="mp-code",s?.scriptRun?m.show(g,t.runsCode,"warning"):s?.hasScript?m.show(g,t.codeNotRun,"info"):g.hidden=!0;const k=n.createElement("label");k.title=t.namedByRecordingHint;const f=n.createElement("input");f.type="checkbox",f.className="mp-named",f.checked=this.isNamed(e.url),f.addEventListener("change",()=>this.setNamed(e.url,f.checked)),k.append(f,n.createTextNode(` ${t.namedByRecording}`));const E=n.createElement("p");E.append(k),a.append(i,h,v,g,E);const p=this.checks.get(e.url);return p&&p.of===s&&a.append(...this.checkResult(p)),a}async check(e,t){const n={of:t};this.checks.set(e,n),this.render();try{const{ModuleConformance:s}=await x(async()=>{const{ModuleConformance:a}=await import("./ModuleConformance-BRi5HHIj.js");return{ModuleConformance:a}},__vite__mapDeps([0,1]),import.meta.url);n.findings=await s.check(t,this.checkContext?.())}catch(s){n.crash=s instanceof Error?s.message:String(s)}this.render()}checkResult(e){const t=this.messages,n=this.ownerDocument,s=(l,c)=>{const h=n.createElement("p");return h.className="mp-check-result",h.setAttribute("role","status"),m.show(h,l,c),h};if(e.crash!==void 0)return[s(t.checkCrashed.replace("{error}",()=>e.crash),"error")];if(!e.findings)return[];const a=e.findings.filter(l=>l.level==="failed"),i=e.findings.filter(l=>l.level==="note"),u=[];if(a.length===0&&u.push(s(t.checkPassed,"info")),a.length+i.length>0){const l=n.createElement("ul");l.className="mp-findings";for(const c of[...a,...i]){const h=n.createElement("li");m.show(h,this.finding(c),c.level==="failed"?"error":"info"),l.append(h)}u.push(l)}return u}finding(e){const t=this.messages,n=e.point===void 0?"":t.points[e.point]??e.point,s=t.checks[e.code].replace("{point}",()=>e.point??"").replace("{detail}",()=>e.detail??""),a=e.source??(e.code==="unknownPoint"||e.code==="notAList"?void 0:n);return a?t.checkAbout.replace("{about}",()=>a).replace("{text}",()=>s):s}brings(e){const t=Object.entries(e.loaded?.module.contributes??{}).filter(([,n])=>Array.isArray(n)&&n.length>0).map(([n,s])=>`${this.messages.points[n]??n} (${s.length})`);return t.length>0?this.messages.brings.replace("{points}",t.join(", ")):this.messages.bringsNothing}download(){const e=new Blob([this.session.exportText()],{type:"application/json"}),t=URL.createObjectURL(e),n=this.ownerDocument.createElement("a");n.href=t,n.download="ufoathome-modules.json",n.click(),URL.revokeObjectURL(t)}async importFile(e){try{await this.session.importText(await e.text());const t=this.session.list().filter(n=>n.addedByPerson).length;this.note={text:this.messages.imported.replace("{count}",String(t)),kind:"info"}}catch(t){this.note={text:this.messages.importFailed.replace("{error}",t instanceof Error?t.message:String(t)),kind:"error"}}this.render()}}function B(){customElements.get(N)||customElements.define(N,A)}export{N as MODULES_PANEL_ELEMENT_NAME,A as ModulesPanelElement,B as register};
15
+ `;class A extends HTMLElement{session=C.shared;messages;languageAsked=!1;named=[];recordingBase;note;languageToken=0;draft="";onChange=()=>this.render();checkContext;checks=new Map;set moduleSession(e){this.session.changes.removeEventListener("change",this.onChange),this.session=e,this.isConnected&&this.session.changes.addEventListener("change",this.onChange),this.render()}get recordingModules(){return[...this.named]}set recordingModules(e){this.named=[...e??[]],this.render()}set base(e){this.recordingBase=e,this.render()}async setLanguage(e){this.languageAsked=!0;const t=++this.languageToken,n=await M.load(e);t===this.languageToken&&(this.messages=n,this.render())}connectedCallback(){this.languageAsked||this.setLanguage(y.preferencesFor(this)[0]??"en"),this.session.changes.addEventListener("change",this.onChange),this.session.start(),this.render()}disconnectedCallback(){this.session.changes.removeEventListener("change",this.onChange)}absolute(e){try{return new URL(e,this.recordingBase??location.href).href}catch{return}}isNamed(e){return this.named.some(t=>this.absolute(t)===e)}setNamed(e,t){t!==this.isNamed(e)&&(this.named=t?[...this.named,L.of(e,this.recordingBase)]:this.named.filter(n=>this.absolute(n)!==e),t&&this.session.require([e]),this.dispatchEvent(new Event("recordingmoduleschange",{bubbles:!0})),this.render())}render(){const e=this.messages;if(!this.isConnected||!this.messages)return;const t=this.ownerDocument,n=t.createElement("style");n.textContent=P;const s=t.createElement("p");s.className=m.INFO,s.textContent=e.intro;const a=t.createElement("form");a.className="mp-add";const i=t.createElement("input");i.type="url",i.id="module-url",i.required=!0,i.placeholder=e.urlPlaceholder,i.value=this.draft,i.addEventListener("input",()=>{this.draft=i.value}),i.setAttribute("aria-label",e.urlPlaceholder);const u=t.createElement("button");u.type="submit",u.textContent=e.add,a.append(i,u),a.addEventListener("submit",r=>{r.preventDefault();const w=i.value.trim();w&&(this.draft="",this.session.add(w))});const l=t.createElement("p");l.className=m.WARNING,l.textContent=e.codeWarning;const c=this.session.list(),h=new Set(c.map(r=>r.url)),v=this.named.map(r=>this.absolute(r)).filter(r=>r!==void 0&&!h.has(r)),g=t.createElement("ul");g.className="mp-list",g.append(...c.map(r=>this.item(r)),...v.map(r=>this.item({url:r,addedByPerson:!1,enabled:!0,status:"loading"})));const k=t.createElement("p");k.className=m.INFO,k.textContent=e.none,k.hidden=g.childElementCount>0;const f=t.createElement("div");f.className="mp-files";const E=t.createElement("button");E.type="button",E.id="modules-export",E.textContent=e.exportConfig,E.disabled=!c.some(r=>r.addedByPerson),E.addEventListener("click",()=>this.download());const p=t.createElement("input");p.type="file",p.id="modules-import",p.accept="application/json,.json",p.hidden=!0;const o=t.createElement("button");o.type="button",o.textContent=e.importConfig,o.addEventListener("click",()=>p.click()),p.addEventListener("change",()=>{const r=p.files?.[0];r&&this.importFile(r),p.value=""}),f.append(E,o,p);const d=t.createElement("p");d.id="modules-note",d.setAttribute("role","status"),m.show(d,this.note?.text,this.note?.kind),this.replaceChildren(n,s,a,l,g,k,f,d)}item(e){const t=this.messages,n=this.ownerDocument,s=e.loaded,a=n.createElement("li");a.className="mp-module",a.dataset.url=e.url;const i=n.createElement("div");if(i.className="mp-head",e.addedByPerson){const o=n.createElement("label"),d=n.createElement("input");d.type="checkbox",d.className="mp-enabled",d.checked=e.enabled,d.addEventListener("change",()=>void this.session.setEnabled(e.url,d.checked)),o.append(d,n.createTextNode(` ${t.enabled}`)),i.append(o)}const u=n.createElement("span");u.className="mp-name",u.textContent=e.loaded?.module.name??e.url,i.append(u);const l=e.loaded?.module.credit;if(l){const o=n.createElement(e.loaded?.module.creditUrl?"a":"span");o.className=m.INFO,o.textContent=l,o instanceof HTMLAnchorElement&&(o.href=e.loaded.module.creditUrl,o.target="_blank",o.rel="noopener noreferrer"),i.append(o)}const c=n.createElement("button");if(c.type="button",c.className="mp-remove",e.addedByPerson?(c.textContent=t.remove,c.addEventListener("click",()=>void this.session.remove(e.url))):(c.textContent=t.addToMine,c.addEventListener("click",()=>void this.session.add(e.url))),e.status==="installed"&&s){const o=n.createElement("button");o.type="button",o.className="mp-check";const d=this.checks.get(e.url),r=d?.of===s&&d.findings===void 0&&d.crash===void 0;o.textContent=r?t.checking:t.check,o.disabled=r,o.addEventListener("click",()=>void this.check(e.url,s)),i.append(o)}i.append(c);const h=n.createElement("p");h.className=`${m.INFO} mp-url`,h.textContent=e.url;const v=n.createElement("p");v.className="mp-status",e.status==="loading"?m.show(v,t.loading):e.status==="failed"?m.show(v,t.failed.replace("{error}",e.error??""),"error"):e.status==="off"?m.show(v,t.off):m.show(v,this.brings(e));const g=n.createElement("p");g.className="mp-code",s?.scriptRun?m.show(g,t.runsCode,"warning"):s?.hasScript?m.show(g,t.codeNotRun,"info"):g.hidden=!0;const k=n.createElement("label");k.title=t.namedByRecordingHint;const f=n.createElement("input");f.type="checkbox",f.className="mp-named",f.checked=this.isNamed(e.url),f.addEventListener("change",()=>this.setNamed(e.url,f.checked)),k.append(f,n.createTextNode(` ${t.namedByRecording}`));const E=n.createElement("p");E.append(k),a.append(i,h,v,g,E);const p=this.checks.get(e.url);return p&&p.of===s&&a.append(...this.checkResult(p)),a}async check(e,t){const n={of:t};this.checks.set(e,n),this.render();try{const{ModuleConformance:s}=await x(async()=>{const{ModuleConformance:a}=await import("./ModuleConformance-H7LbISvs.js");return{ModuleConformance:a}},__vite__mapDeps([0,1]),import.meta.url);n.findings=await s.check(t,this.checkContext?.())}catch(s){n.crash=s instanceof Error?s.message:String(s)}this.render()}checkResult(e){const t=this.messages,n=this.ownerDocument,s=(l,c)=>{const h=n.createElement("p");return h.className="mp-check-result",h.setAttribute("role","status"),m.show(h,l,c),h};if(e.crash!==void 0)return[s(t.checkCrashed.replace("{error}",()=>e.crash),"error")];if(!e.findings)return[];const a=e.findings.filter(l=>l.level==="failed"),i=e.findings.filter(l=>l.level==="note"),u=[];if(a.length===0&&u.push(s(t.checkPassed,"info")),a.length+i.length>0){const l=n.createElement("ul");l.className="mp-findings";for(const c of[...a,...i]){const h=n.createElement("li");m.show(h,this.finding(c),c.level==="failed"?"error":"info"),l.append(h)}u.push(l)}return u}finding(e){const t=this.messages,n=e.point===void 0?"":t.points[e.point]??e.point,s=t.checks[e.code].replace("{point}",()=>e.point??"").replace("{detail}",()=>e.detail??""),a=e.source??(e.code==="unknownPoint"||e.code==="notAList"?void 0:n);return a?t.checkAbout.replace("{about}",()=>a).replace("{text}",()=>s):s}brings(e){const t=Object.entries(e.loaded?.module.contributes??{}).filter(([,n])=>Array.isArray(n)&&n.length>0).map(([n,s])=>`${this.messages.points[n]??n} (${s.length})`);return t.length>0?this.messages.brings.replace("{points}",t.join(", ")):this.messages.bringsNothing}download(){const e=new Blob([this.session.exportText()],{type:"application/json"}),t=URL.createObjectURL(e),n=this.ownerDocument.createElement("a");n.href=t,n.download="ufoathome-modules.json",n.click(),URL.revokeObjectURL(t)}async importFile(e){try{await this.session.importText(await e.text());const t=this.session.list().filter(n=>n.addedByPerson).length;this.note={text:this.messages.imported.replace("{count}",String(t)),kind:"info"}}catch(t){this.note={text:this.messages.importFailed.replace("{error}",t instanceof Error?t.message:String(t)),kind:"error"}}this.render()}}function B(){customElements.get(N)||customElements.define(N,A)}export{N as MODULES_PANEL_ELEMENT_NAME,A as ModulesPanelElement,B as register};
@@ -0,0 +1 @@
1
+ class n extends Error{constructor(t,a){super(`${t}: ${a.kind==="status"?a.status:a.kind}`),this.src=t,this.failure=a}}class s{static async blob(t){let a;try{a=await fetch(t)}catch{throw new n(t,await s.whyUnread(t))}if(!a.ok)throw new n(t,{kind:"status",status:a.status});const e=await a.blob();if(e.type&&!e.type.startsWith("image/"))throw new n(t,{kind:"notPicture"});return e}static failureOf(t){return t instanceof n?t.failure:{kind:"notPicture"}}static async whyVideoUnread(t){if(t.startsWith("data:")||t.startsWith("blob:"))return{kind:"notVideo"};let a;try{a=await fetch(t,{method:"HEAD"})}catch{return s.whyUnread(t)}return a.ok?{kind:"notVideo"}:{kind:"status",status:a.status}}static async whyUnread(t){try{return await fetch(t,{mode:"no-cors"}),{kind:"notShared"}}catch{return{kind:"unreachable"}}}}export{s as P,n as a};
@@ -0,0 +1 @@
1
+ import{aQ as v,bb as d,bc as M,bd as m,be as l,bf as b,ab as k,ap as y,bg as O,bh as E,bi as I,u as T}from"./rr0-sighting-editor.mjs";import{P as g,a as f}from"./PictureFetch-C3wgf1ZV.js";const w=3,u=800,c=Math.PI/180;class h{constructor(t,i,a=h.fetchImage,s=h.openVideo){this.scene=t,this.onImageLoaded=i,this.loadImage=a,this.loadVideo=s}meshes=new Map;signatures=new Map;images=new Map;loading=new Map;failed=new Map;references=[];views=new Map;shown=!0;observerAt;clock={t:0,playing:!1,timeScale:1};static PRESENT_WITHIN_M=2;static GONE_BEYOND_M=20;static presenceAt(t,i){if(!t.from||!i)return 1;const a=v(i.lat,i.lng,t.from.lat,t.from.lng),e=(Math.hypot(a.x,a.z)-h.PRESENT_WITHIN_M)/(h.GONE_BEYOND_M-h.PRESENT_WITHIN_M),o=Math.min(Math.max(e,0),1);return 1-o*o*(3-2*o)}set(t,i=this.views,a){this.references=t,this.observerAt=a,this.views=i;const s=new Set(t.map(e=>e.id));for(const[e,o]of this.meshes)s.has(e)||(this.dispose(o),this.meshes.delete(e),this.signatures.delete(e));for(const[e,o]of this.images){const n=t.find(p=>p.id===e);if(n&&n.src===o.texture.userData.src&&n.kind==="video"==(o.video!==void 0))continue;h.release(o),this.images.delete(e);const r=this.meshes.get(e);r&&(this.dispose(r),this.meshes.delete(e),this.signatures.delete(e))}for(const e of t){const o=this.images.get(e.id);if(!o){this.load(e);continue}this.build(e,o)}this.follow()}setTime(t){this.clock=t,this.follow()}setShown(t){this.shown=t;for(const i of this.meshes.values())i.visible=t&&this.opacityOf(i.userData.id)>0}setView(t,i){this.views.set(t,i);const a=this.meshes.get(t);a&&this.applyOpacity(a,t)}layer=w;get any(){for(const t of this.meshes.values())if(t.visible)return!0;return!1}place(t){for(const i of this.meshes.values())i.visible&&(i.position.copy(t.position),i.updateMatrixWorld())}get furthestM(){return this.meshes.size>0?u:0}directionOfPixel(t,i,a,s){const e=this.images.get(t.id),o=e?e.width/e.height:1,n=d.registrationAt(t,this.clock.t),r=Math.tan(n.fovDeg/2*c),p=r*o;return s.set((i*2-1)*p,(1-a*2)*r,-1).normalize(),s.applyQuaternion(h.orientation(n))}aspectOf(t){const i=this.images.get(t);return i?i.width/i.height:void 0}failureOf(t){return this.failed.get(t)}follow(){for(const t of this.references){const i=this.meshes.get(t.id),a=this.images.get(t.id)?.video;a&&this.sync(t,a),i&&(t.registrationTrack?.length&&h.point(i,t,d.registrationAt(t,this.clock.t)),t.kind==="video"&&this.applyOpacity(i,t.id))}}sync(t,i){const a=d.mediaSecondsAt(t,this.clock.t,this.clock.timeScale,Number.isFinite(i.duration)?i.duration:void 0);if(a===void 0){i.paused||i.pause();return}const s=d.command(i.currentTime,a,this.clock.playing,d.rateOf(t));i.playbackRate=s.rate,s.seekS!==void 0&&!i.seeking&&(i.currentTime=s.seekS),s.play&&i.paused&&i.play().catch(()=>{}),!s.play&&!i.paused&&i.pause()}load(t){const i=t.src;if(this.loading.has(t.id)||this.failed.has(i))return;const a=t.kind==="video",e=(a?this.loadVideo(i,()=>this.onVideoFrame()):this.loadImage(i)).then(o=>{this.loading.delete(t.id);const n=this.references.find(r=>r.id===t.id);if(!n||n.src!==i||n.kind==="video"!==a){h.release(o);return}o.texture.userData.src=i,this.images.set(t.id,o),this.build(n,o),this.follow(),this.onImageLoaded()},o=>{this.loading.delete(t.id),this.failed.set(i,g.failureOf(o)),this.onImageLoaded()});this.loading.set(t.id,e)}onVideoFrame(){this.follow(),this.onFrame?.()}onFrame;static openVideo(t,i){return new Promise((a,s)=>{const e=document.createElement("video");e.crossOrigin="anonymous",e.muted=!0,e.playsInline=!0,e.preload="auto",e.addEventListener("loadeddata",()=>{const o=new M(e);o.colorSpace=m,o.minFilter=l,o.magFilter=l,o.generateMipmaps=!1,e.addEventListener("seeked",i);const n=()=>{e.paused&&i(),e.src&&e.requestVideoFrameCallback(n)};"requestVideoFrameCallback"in e&&e.requestVideoFrameCallback(n),a({texture:o,width:e.videoWidth,height:e.videoHeight,video:e})},{once:!0}),e.addEventListener("error",()=>{g.whyVideoUnread(t).then(o=>s(new f(t,o)))},{once:!0}),e.src=t})}static release(t){t.texture.dispose();const i=t.video;i&&(i.pause(),i.removeAttribute?.("src"),i.load?.())}static async fetchImage(t){const i=await g.blob(t),a=await createImageBitmap(i,{imageOrientation:"flipY"}).catch(()=>{throw new f(t,{kind:"notPicture"})}),s=new b(a);return s.flipY=!1,s.colorSpace=m,s.minFilter=l,s.magFilter=l,s.generateMipmaps=!1,s.needsUpdate=!0,{texture:s,width:a.width,height:a.height}}build(t,i){const a=h.signatureOf(t,i);let s=this.meshes.get(t.id);if(s&&this.signatures.get(t.id)===a){this.applyOpacity(s,t.id);return}s&&(this.dispose(s),this.meshes.delete(t.id)),s=new k(h.geometryOf(t,i),new y({map:i.texture,transparent:!0,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),t.kind==="panorama"&&(s.material.side=O),s.frustumCulled=!1,s.layers.set(w),s.userData.id=t.id,h.point(s,t,d.registrationAt(t,this.clock.t)),this.scene.add(s),this.meshes.set(t.id,s),this.signatures.set(t.id,a),this.applyOpacity(s,t.id)}static geometryOf(t,i){if(t.kind==="panorama"){const o=new E(u,64,32,Math.PI/2,Math.PI*2),n=o.attributes.uv;for(let r=0;r<n.count;r++)n.setX(r,1-n.getX(r));return n.needsUpdate=!0,o}const a=2*u*Math.tan(t.registration.fovDeg/2*c),s=a*(i.width/Math.max(i.height,1)),e=new I(s,a);return e.translate(0,0,-u),e}static orientation({headingDeg:t,pitchDeg:i,rollDeg:a}){const s=new T;return s.rotation.set(i*c,-t*c,-(a??0)*c,"YXZ"),s.quaternion}static point(t,i,a){if(t.quaternion.copy(h.orientation(a)),i.kind==="panorama")return;const s=Math.tan(a.fovDeg/2*c)/Math.tan(i.registration.fovDeg/2*c);t.scale.set(s,s,1)}inTime(t){if(t.kind!=="video")return!0;const i=this.images.get(t.id)?.video?.duration;return d.mediaSecondsAt(t,this.clock.t,this.clock.timeScale,i!==void 0&&Number.isFinite(i)?i:void 0)!==void 0}opacityOf(t){const i=this.references.find(e=>e.id===t);if(i&&!this.inTime(i))return 0;const a=this.views.get(t),s=i?h.presenceAt(i,this.observerAt):1;return(a?.opacity??i?.opacity??0)*s}applyOpacity(t,i){const a=this.opacityOf(i);t.material.opacity=a,t.visible=this.shown&&a>0}static signatureOf(t,i){const{headingDeg:a,pitchDeg:s,rollDeg:e,fovDeg:o}=t.registration;return[t.kind,t.src,i.width,i.height,a,s,e??0,o].join("|")}dispose(t){this.scene.remove(t),t.geometry.dispose(),t.material.dispose()}disposeAll(){for(const t of this.meshes.values())this.dispose(t);this.meshes.clear(),this.signatures.clear();for(const t of this.images.values())h.release(t);this.images.clear()}}export{w as REFERENCE_LAYER,h as ReferenceSystem};