@quick-threejs/reactive 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{FontLoader-DvGzwRip.js → FontLoader-D3WA1QGd.js} +8 -8
- package/dist/{FontLoader-Dz0z8aMc.mjs → FontLoader-ejhD_xZ1.mjs} +430 -423
- package/dist/core/app/app.controller.d.ts +1 -1
- package/dist/core/app/app.module.d.ts +3 -2
- package/dist/core/app/app.service.d.ts +1 -1
- package/dist/core/app/app.worker.d.ts +1 -2
- package/dist/core/app/camera/camera.module.d.ts +1 -1
- package/dist/core/app/camera/camera.service.d.ts +2 -2
- package/dist/core/app/debug/debug.service.d.ts +1 -1
- package/dist/core/app/loader/loader.controller.d.ts +1 -1
- package/dist/core/app/loader/loader.module.d.ts +4 -4
- package/dist/core/app/loader/loader.service.d.ts +1 -1
- package/dist/core/app/renderer/renderer.controller.d.ts +1 -1
- package/dist/core/app/renderer/renderer.module.d.ts +1 -1
- package/dist/core/app/renderer/renderer.service.d.ts +1 -1
- package/dist/core/app/sizes/sizes.controller.d.ts +1 -1
- package/dist/core/app/sizes/sizes.module.d.ts +1 -2
- package/dist/core/app/sizes/sizes.service.d.ts +1 -1
- package/dist/core/app/timer/timer.controller.d.ts +2 -1
- package/dist/core/app/timer/timer.module.d.ts +3 -2
- package/dist/core/app/timer/timer.service.d.ts +4 -2
- package/dist/core/app/world/world.module.d.ts +1 -1
- package/dist/core/register/loader/loader.controller.d.ts +2 -2
- package/dist/core/register/loader/loader.module.d.ts +3 -3
- package/dist/core/register/loader/loader.service.d.ts +1 -1
- package/dist/core/register/register.controller.d.ts +1 -1
- package/dist/core/register/register.module.d.ts +1 -1
- package/dist/main.js +4 -4
- package/dist/main.mjs +1502 -1479
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +241 -184
- package/package.json +7 -7
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ft=Object.defineProperty;var ht=(s,e,t)=>e in s?ft(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var x=(s,e,t)=>ht(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./FontLoader-DvGzwRip.js"),h=require("three");class se{constructor(){x(this,"location");x(this,"initOnConstruct");x(this,"mainThread");x(this,"canvas");x(this,"fullScreen");x(this,"defaultCamera");x(this,"startTimer");x(this,"loaderDataSources",[]);x(this,"loaderDracoDecoderPath");x(this,"loadResourcesOnInit");x(this,"enableDebug");x(this,"enableControls");x(this,"axesSizes");x(this,"gridSizes");x(this,"withMiniCamera");x(this,"onReady")}}class pt{constructor(){x(this,"canvas");x(this,"onReady")}}var K={},ge={},D={},z={},Ne;function mt(){if(Ne)return z;Ne=1,Object.defineProperty(z,"__esModule",{value:!0}),z.getBundleURL=z.getBaseURL=void 0;let s;function e(){return s||(s=t()),s}z.getBundleURL=e;function t(){try{throw new Error}catch(r){const o=(""+r.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(o)return n(o[0])}return"/"}function n(r){return(""+r).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}return z.getBaseURL=n,z}var De;function nt(){if(De)return D;De=1,Object.defineProperty(D,"__esModule",{value:!0}),D.isWorkerRuntime=D.getWorkerImplementation=D.defaultPoolSize=void 0;const s=mt();D.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const e=a=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(a);function t(a){const c=new Blob([a],{type:"application/javascript"});return URL.createObjectURL(c)}function n(){if(typeof Worker>"u")return class{constructor(){throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.")}};class a extends Worker{constructor(u,l){var f,p;typeof u=="string"&&l&&l._baseURL?u=new URL(u,l._baseURL):typeof u=="string"&&!e(u)&&s.getBundleURL().match(/^file:\/\//i)&&(u=new URL(u,s.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((f=l==null?void 0:l.CORSWorkaround)!==null&&f!==void 0)||f)&&(u=t(`importScripts(${JSON.stringify(u)});`))),typeof u=="string"&&e(u)&&(!((p=l==null?void 0:l.CORSWorkaround)!==null&&p!==void 0)||p)&&(u=t(`importScripts(${JSON.stringify(u)});`)),super(u,l)}}class c extends a{constructor(u,l){const f=window.URL.createObjectURL(u);super(f,l)}static fromText(u,l){const f=new window.Blob([u],{type:"text/javascript"});return new c(f,l)}}return{blob:c,default:a}}let r;function o(){return r||(r=n()),r}D.getWorkerImplementation=o;function i(){const a=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!a)}return D.isWorkerRuntime=i,D}var $={},oe={exports:{}},_e,Fe;function gt(){if(Fe)return _e;Fe=1;var s=1e3,e=s*60,t=e*60,n=t*24,r=n*7,o=n*365.25;_e=function(u,l){l=l||{};var f=typeof u;if(f==="string"&&u.length>0)return i(u);if(f==="number"&&isFinite(u))return l.long?c(u):a(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function i(u){if(u=String(u),!(u.length>100)){var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(l){var f=parseFloat(l[1]),p=(l[2]||"ms").toLowerCase();switch(p){case"years":case"year":case"yrs":case"yr":case"y":return f*o;case"weeks":case"week":case"w":return f*r;case"days":case"day":case"d":return f*n;case"hours":case"hour":case"hrs":case"hr":case"h":return f*t;case"minutes":case"minute":case"mins":case"min":case"m":return f*e;case"seconds":case"second":case"secs":case"sec":case"s":return f*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return f;default:return}}}}function a(u){var l=Math.abs(u);return l>=n?Math.round(u/n)+"d":l>=t?Math.round(u/t)+"h":l>=e?Math.round(u/e)+"m":l>=s?Math.round(u/s)+"s":u+"ms"}function c(u){var l=Math.abs(u);return l>=n?d(u,l,n,"day"):l>=t?d(u,l,t,"hour"):l>=e?d(u,l,e,"minute"):l>=s?d(u,l,s,"second"):u+" ms"}function d(u,l,f,p){var E=l>=f*1.5;return Math.round(u/f)+" "+p+(E?"s":"")}return _e}var ye,je;function _t(){if(je)return ye;je=1;function s(e){n.debug=n,n.default=n,n.coerce=d,n.disable=i,n.enable=o,n.enabled=a,n.humanize=gt(),n.destroy=u,Object.keys(e).forEach(l=>{n[l]=e[l]}),n.names=[],n.skips=[],n.formatters={};function t(l){let f=0;for(let p=0;p<l.length;p++)f=(f<<5)-f+l.charCodeAt(p),f|=0;return n.colors[Math.abs(f)%n.colors.length]}n.selectColor=t;function n(l){let f,p=null,E,R;function v(...m){if(!v.enabled)return;const _=v,g=Number(new Date),T=g-(f||g);_.diff=T,_.prev=f,_.curr=g,f=g,m[0]=n.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let b=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(C,L)=>{if(C==="%%")return"%";b++;const S=n.formatters[L];if(typeof S=="function"){const A=m[b];C=S.call(_,A),m.splice(b,1),b--}return C}),n.formatArgs.call(_,m),(_.log||n.log).apply(_,m)}return v.namespace=l,v.useColors=n.useColors(),v.color=n.selectColor(l),v.extend=r,v.destroy=n.destroy,Object.defineProperty(v,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(E!==n.namespaces&&(E=n.namespaces,R=n.enabled(l)),R),set:m=>{p=m}}),typeof n.init=="function"&&n.init(v),v}function r(l,f){const p=n(this.namespace+(typeof f>"u"?":":f)+l);return p.log=this.log,p}function o(l){n.save(l),n.namespaces=l,n.names=[],n.skips=[];let f;const p=(typeof l=="string"?l:"").split(/[\s,]+/),E=p.length;for(f=0;f<E;f++)p[f]&&(l=p[f].replace(/\*/g,".*?"),l[0]==="-"?n.skips.push(new RegExp("^"+l.slice(1)+"$")):n.names.push(new RegExp("^"+l+"$")))}function i(){const l=[...n.names.map(c),...n.skips.map(c).map(f=>"-"+f)].join(",");return n.enable(""),l}function a(l){if(l[l.length-1]==="*")return!0;let f,p;for(f=0,p=n.skips.length;f<p;f++)if(n.skips[f].test(l))return!1;for(f=0,p=n.names.length;f<p;f++)if(n.names[f].test(l))return!0;return!1}function c(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function d(l){return l instanceof Error?l.stack||l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}return ye=s,ye}var He;function Oe(){return He||(He=1,function(s,e){e.formatArgs=n,e.save=r,e.load=o,e.useColors=t,e.storage=i(),e.destroy=(()=>{let c=!1;return()=>{c||(c=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let c;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(c=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(c[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function n(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+s.exports.humanize(this.diff),!this.useColors)return;const d="color: "+this.color;c.splice(1,0,d,"color: inherit");let u=0,l=0;c[0].replace(/%[a-zA-Z%]/g,f=>{f!=="%%"&&(u++,f==="%c"&&(l=u))}),c.splice(l,0,d)}e.log=console.debug||console.log||(()=>{});function r(c){try{c?e.storage.setItem("debug",c):e.storage.removeItem("debug")}catch{}}function o(){let c;try{c=e.storage.getItem("debug")}catch{}return!c&&typeof process<"u"&&"env"in process&&(c=process.env.DEBUG),c}function i(){try{return localStorage}catch{}}s.exports=_t()(e);const{formatters:a}=s.exports;a.j=function(c){try{return JSON.stringify(c)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}}(oe,oe.exports)),oe.exports}var yt=function(s,e,t,n){function r(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{d(n.next(u))}catch(l){i(l)}}function c(u){try{d(n.throw(u))}catch(l){i(l)}}function d(u){u.done?o(u.value):r(u.value).then(a,c)}d((n=n.apply(s,e||[])).next())})};class fe{constructor(e){this._baseObserver=e,this._pendingPromises=new Set}complete(){Promise.all(this._pendingPromises).then(()=>this._baseObserver.complete()).catch(e=>this._baseObserver.error(e))}error(e){this._baseObserver.error(e)}schedule(e){const t=Promise.all(this._pendingPromises),n=[],r=i=>n.push(i),o=Promise.resolve().then(()=>yt(this,void 0,void 0,function*(){yield t,yield e(r),this._pendingPromises.delete(o);for(const i of n)this._baseObserver.next(i)})).catch(i=>{this._pendingPromises.delete(o),this._baseObserver.error(i)});this._pendingPromises.add(o)}}const rt=()=>typeof Symbol=="function",ie=s=>rt()&&!!Symbol[s],Ie=s=>ie(s)?Symbol[s]:"@@"+s;ie("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const bt=Ie("iterator"),xe=Ie("observable"),st=Ie("species");function ce(s,e){const t=s[e];if(t!=null){if(typeof t!="function")throw new TypeError(t+" is not a function");return t}}function J(s){let e=s.constructor;return e!==void 0&&(e=e[st],e===null&&(e=void 0)),e!==void 0?e:P}function Tt(s){return s instanceof P}function Y(s){Y.log?Y.log(s):setTimeout(()=>{throw s},0)}function ae(s){Promise.resolve().then(()=>{try{s()}catch(e){Y(e)}})}function it(s){const e=s._cleanup;if(e!==void 0&&(s._cleanup=void 0,!!e))try{if(typeof e=="function")e();else{const t=ce(e,"unsubscribe");t&&t.call(e)}}catch(t){Y(t)}}function Me(s){s._observer=void 0,s._queue=void 0,s._state="closed"}function wt(s){const e=s._queue;if(e){s._queue=void 0,s._state="ready";for(const t of e)if(ot(s,t.type,t.value),s._state==="closed")break}}function ot(s,e,t){s._state="running";const n=s._observer;try{const r=n?ce(n,e):void 0;switch(e){case"next":r&&r.call(n,t);break;case"error":if(Me(s),r)r.call(n,t);else throw t;break;case"complete":Me(s),r&&r.call(n);break}}catch(r){Y(r)}s._state==="closed"?it(s):s._state==="running"&&(s._state="ready")}function be(s,e,t){if(s._state!=="closed"){if(s._state==="buffering"){s._queue=s._queue||[],s._queue.push({type:e,value:t});return}if(s._state!=="ready"){s._state="buffering",s._queue=[{type:e,value:t}],ae(()=>wt(s));return}ot(s,e,t)}}class vt{constructor(e,t){this._cleanup=void 0,this._observer=e,this._queue=void 0,this._state="initializing";const n=new Et(this);try{this._cleanup=t.call(void 0,n)}catch(r){n.error(r)}this._state==="initializing"&&(this._state="ready")}get closed(){return this._state==="closed"}unsubscribe(){this._state!=="closed"&&(Me(this),it(this))}}class Et{constructor(e){this._subscription=e}get closed(){return this._subscription._state==="closed"}next(e){be(this._subscription,"next",e)}error(e){be(this._subscription,"error",e)}complete(){be(this._subscription,"complete")}}class P{constructor(e){if(!(this instanceof P))throw new TypeError("Observable cannot be called as a function");if(typeof e!="function")throw new TypeError("Observable initializer must be a function");this._subscriber=e}subscribe(e,t,n){return(typeof e!="object"||e===null)&&(e={next:e,error:t,complete:n}),new vt(e,this._subscriber)}pipe(e,...t){let n=this;for(const r of[e,...t])n=r(n);return n}tap(e,t,n){const r=typeof e!="object"||e===null?{next:e,error:t,complete:n}:e;return new P(o=>this.subscribe({next(i){r.next&&r.next(i),o.next(i)},error(i){r.error&&r.error(i),o.error(i)},complete(){r.complete&&r.complete(),o.complete()},start(i){r.start&&r.start(i)}}))}forEach(e){return new Promise((t,n)=>{if(typeof e!="function"){n(new TypeError(e+" is not a function"));return}function r(){o.unsubscribe(),t(void 0)}const o=this.subscribe({next(i){try{e(i,r)}catch(a){n(a),o.unsubscribe()}},error(i){n(i)},complete(){t(void 0)}})})}map(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=J(this);return new t(n=>this.subscribe({next(r){let o=r;try{o=e(r)}catch(i){return n.error(i)}n.next(o)},error(r){n.error(r)},complete(){n.complete()}}))}filter(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=J(this);return new t(n=>this.subscribe({next(r){try{if(!e(r))return}catch(o){return n.error(o)}n.next(r)},error(r){n.error(r)},complete(){n.complete()}}))}reduce(e,t){if(typeof e!="function")throw new TypeError(e+" is not a function");const n=J(this),r=arguments.length>1;let o=!1,i=t;return new n(a=>this.subscribe({next(c){const d=!o;if(o=!0,!d||r)try{i=e(i,c)}catch(u){return a.error(u)}else i=c},error(c){a.error(c)},complete(){if(!o&&!r)return a.error(new TypeError("Cannot reduce an empty sequence"));a.next(i),a.complete()}}))}concat(...e){const t=J(this);return new t(n=>{let r,o=0;function i(a){r=a.subscribe({next(c){n.next(c)},error(c){n.error(c)},complete(){o===e.length?(r=void 0,n.complete()):i(t.from(e[o++]))}})}return i(this),()=>{r&&(r.unsubscribe(),r=void 0)}})}flatMap(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=J(this);return new t(n=>{const r=[],o=this.subscribe({next(a){let c;if(e)try{c=e(a)}catch(u){return n.error(u)}else c=a;const d=t.from(c).subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){const u=r.indexOf(d);u>=0&&r.splice(u,1),i()}});r.push(d)},error(a){n.error(a)},complete(){i()}});function i(){o.closed&&r.length===0&&n.complete()}return()=>{r.forEach(a=>a.unsubscribe()),o.unsubscribe()}})}[xe](){return this}static from(e){const t=typeof this=="function"?this:P;if(e==null)throw new TypeError(e+" is not an object");const n=ce(e,xe);if(n){const r=n.call(e);if(Object(r)!==r)throw new TypeError(r+" is not an object");return Tt(r)&&r.constructor===t?r:new t(o=>r.subscribe(o))}if(ie("iterator")){const r=ce(e,bt);if(r)return new t(o=>{ae(()=>{if(!o.closed){for(const i of r.call(e))if(o.next(i),o.closed)return;o.complete()}})})}if(Array.isArray(e))return new t(r=>{ae(()=>{if(!r.closed){for(const o of e)if(r.next(o),r.closed)return;r.complete()}})});throw new TypeError(e+" is not observable")}static of(...e){const t=typeof this=="function"?this:P;return new t(n=>{ae(()=>{if(!n.closed){for(const r of e)if(n.next(r),n.closed)return;n.complete()}})})}static get[st](){return this}}rt()&&Object.defineProperty(P,Symbol("extensions"),{value:{symbol:xe,hostReportError:Y},configurable:!0});function q(s){typeof s=="function"?s():s&&typeof s.unsubscribe=="function"&&s.unsubscribe()}var Ct=function(s,e,t,n){function r(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{d(n.next(u))}catch(l){i(l)}}function c(u){try{d(n.throw(u))}catch(l){i(l)}}function d(u){u.done?o(u.value):r(u.value).then(a,c)}d((n=n.apply(s,e||[])).next())})};function Rt(s){return e=>new P(t=>{const n=new fe(t),r=e.subscribe({complete(){n.complete()},error(o){n.error(o)},next(o){n.schedule(i=>Ct(this,void 0,void 0,function*(){(yield s(o))&&i(o)}))}});return()=>q(r)})}function St(s){return s&&ie("asyncIterator")&&s[Symbol.asyncIterator]}function xt(s){return s&&ie("iterator")&&s[Symbol.iterator]}var Mt=function(s,e,t,n){function r(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{d(n.next(u))}catch(l){i(l)}}function c(u){try{d(n.throw(u))}catch(l){i(l)}}function d(u){u.done?o(u.value):r(u.value).then(a,c)}d((n=n.apply(s,e||[])).next())})},Lt=function(s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=s[Symbol.asyncIterator],t;return e?e.call(s):(s=typeof __values=="function"?__values(s):s[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=s[o]&&function(i){return new Promise(function(a,c){i=s[o](i),r(a,c,i.done,i.value)})}}function r(o,i,a,c){Promise.resolve(c).then(function(d){o({value:d,done:a})},i)}};function At(s){return e=>new P(t=>{const n=new fe(t),r=e.subscribe({complete(){n.complete()},error(o){n.error(o)},next(o){n.schedule(i=>Mt(this,void 0,void 0,function*(){var a,c;const d=yield s(o);if(xt(d)||St(d))try{for(var u=Lt(d),l;l=yield u.next(),!l.done;){const f=l.value;i(f)}}catch(f){a={error:f}}finally{try{l&&!l.done&&(c=u.return)&&(yield c.call(u))}finally{if(a)throw a.error}}else d.map(f=>i(f))}))}});return()=>q(r)})}function kt(s){return new P(e=>{let t=0;const n=setInterval(()=>{e.next(t++)},s);return()=>clearInterval(n)})}var Pt=function(s,e,t,n){function r(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{d(n.next(u))}catch(l){i(l)}}function c(u){try{d(n.throw(u))}catch(l){i(l)}}function d(u){u.done?o(u.value):r(u.value).then(a,c)}d((n=n.apply(s,e||[])).next())})};function Ot(s){return e=>new P(t=>{const n=new fe(t),r=e.subscribe({complete(){n.complete()},error(o){n.error(o)},next(o){n.schedule(i=>Pt(this,void 0,void 0,function*(){const a=yield s(o);i(a)}))}});return()=>q(r)})}function It(...s){return s.length===0?P.from([]):new P(e=>{let t=0;const n=s.map(o=>o.subscribe({error(i){e.error(i),r()},next(i){e.next(i)},complete(){++t===s.length&&(e.complete(),r())}})),r=()=>{n.forEach(o=>q(o))};return r})}class at extends P{constructor(){super(e=>(this._observers.add(e),()=>this._observers.delete(e))),this._observers=new Set}next(e){for(const t of this._observers)t.next(e)}error(e){for(const t of this._observers)t.error(e)}complete(){for(const e of this._observers)e.complete()}}function Nt(s){const e=new at;let t,n=0;return new P(r=>{t||(t=s.subscribe(e));const o=e.subscribe(r);return n++,()=>{n--,o.unsubscribe(),n===0&&(q(t),t=void 0)}})}var Dt=function(s,e,t,n){function r(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{d(n.next(u))}catch(l){i(l)}}function c(u){try{d(n.throw(u))}catch(l){i(l)}}function d(u){u.done?o(u.value):r(u.value).then(a,c)}d((n=n.apply(s,e||[])).next())})};function Ft(s,e){return t=>new P(n=>{let r,o=0;const i=new fe(n),a=t.subscribe({complete(){i.complete()},error(c){i.error(c)},next(c){i.schedule(d=>Dt(this,void 0,void 0,function*(){r=yield s(o===0?typeof e>"u"?c:e:r,c,o++),d(r)}))}});return()=>q(a)})}const jt=Object.freeze(Object.defineProperty({__proto__:null,Observable:P,Subject:at,filter:Rt,flatMap:At,interval:kt,map:Ot,merge:It,multicast:Nt,scan:Ft,unsubscribe:q},Symbol.toStringTag,{value:"Module"})),he=y.getAugmentedNamespace(jt);var Z={},Ue;function Ht(){if(Ue)return Z;Ue=1,Object.defineProperty(Z,"__esModule",{value:!0}),Z.allSettled=void 0;function s(e){return Promise.all(e.map(t=>{const n=i=>({status:"fulfilled",value:i}),r=i=>({status:"rejected",reason:i}),o=Promise.resolve(t);try{return o.then(n,r)}catch(i){return Promise.reject(i)}}))}return Z.allSettled=s,Z}var Te={},Be;function Ut(){return Be||(Be=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.PoolEventType=void 0,function(e){e.initialized="initialized",e.taskCanceled="taskCanceled",e.taskCompleted="taskCompleted",e.taskFailed="taskFailed",e.taskQueued="taskQueued",e.taskQueueDrained="taskQueueDrained",e.taskStart="taskStart",e.terminated="terminated"}(s.PoolEventType||(s.PoolEventType={}))}(Te)),Te}var ee={},Ge;function ct(){if(Ge)return ee;Ge=1,Object.defineProperty(ee,"__esModule",{value:!0}),ee.Thread=void 0;const s=y.requireSymbols();function e(t){throw Error(t)}return ee.Thread={errors(t){return t[s.$errors]||e("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(t){return t[s.$events]||e("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(t){return t[s.$terminate]()}},ee}var We;function Bt(){return We||(We=1,function(s){var e=$&&$.__awaiter||function(m,_,g,T){function b(w){return w instanceof g?w:new g(function(C){C(w)})}return new(g||(g=Promise))(function(w,C){function L(k){try{A(T.next(k))}catch(I){C(I)}}function S(k){try{A(T.throw(k))}catch(I){C(I)}}function A(k){k.done?w(k.value):b(k.value).then(L,S)}A((T=T.apply(m,_||[])).next())})},t=$&&$.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(s,"__esModule",{value:!0}),s.Pool=s.Thread=s.PoolEventType=void 0;const n=t(Oe()),r=he,o=Ht(),i=nt(),a=Ut();Object.defineProperty(s,"PoolEventType",{enumerable:!0,get:function(){return a.PoolEventType}});const c=ct();Object.defineProperty(s,"Thread",{enumerable:!0,get:function(){return c.Thread}});let d=1;function u(m){const _=[];for(let g=0;g<m;g++)_.push(g);return _}function l(m){return new Promise(_=>setTimeout(_,m))}function f(m,_){return m.reduce((g,T)=>[...g,..._(T)],[])}function p(m){return m.replace(/\W/g," ").trim().replace(/\s+/g,"-")}function E(m,_){return u(_).map(()=>({init:m(),runningTasks:[]}))}class R{constructor(_,g){this.eventSubject=new r.Subject,this.initErrors=[],this.isClosing=!1,this.nextTaskID=1,this.taskQueue=[];const T=typeof g=="number"?{size:g}:g||{},{size:b=i.defaultPoolSize}=T;this.debug=n.default(`threads:pool:${p(T.name||String(d++))}`),this.options=T,this.workers=E(_,b),this.eventObservable=r.multicast(r.Observable.from(this.eventSubject)),Promise.all(this.workers.map(w=>w.init)).then(()=>this.eventSubject.next({type:a.PoolEventType.initialized,size:this.workers.length}),w=>{this.debug("Error while initializing pool worker:",w),this.eventSubject.error(w),this.initErrors.push(w)})}findIdlingWorker(){const{concurrency:_=1}=this.options;return this.workers.find(g=>g.runningTasks.length<_)}runPoolTask(_,g){return e(this,void 0,void 0,function*(){const T=this.workers.indexOf(_)+1;this.debug(`Running task #${g.id} on worker #${T}...`),this.eventSubject.next({type:a.PoolEventType.taskStart,taskID:g.id,workerID:T});try{const b=yield g.run(yield _.init);this.debug(`Task #${g.id} completed successfully`),this.eventSubject.next({type:a.PoolEventType.taskCompleted,returnValue:b,taskID:g.id,workerID:T})}catch(b){this.debug(`Task #${g.id} failed`),this.eventSubject.next({type:a.PoolEventType.taskFailed,taskID:g.id,error:b,workerID:T})}})}run(_,g){return e(this,void 0,void 0,function*(){const T=e(this,void 0,void 0,function*(){const b=()=>{_.runningTasks=_.runningTasks.filter(w=>w!==T)};yield l(0);try{yield this.runPoolTask(_,g)}finally{b(),this.isClosing||this.scheduleWork()}});_.runningTasks.push(T)})}scheduleWork(){this.debug("Attempt de-queueing a task in order to run it...");const _=this.findIdlingWorker();if(!_)return;const g=this.taskQueue.shift();if(!g){this.debug("Task queue is empty"),this.eventSubject.next({type:a.PoolEventType.taskQueueDrained});return}this.run(_,g)}taskCompletion(_){return new Promise((g,T)=>{const b=this.events().subscribe(w=>{w.type===a.PoolEventType.taskCompleted&&w.taskID===_?(b.unsubscribe(),g(w.returnValue)):w.type===a.PoolEventType.taskFailed&&w.taskID===_?(b.unsubscribe(),T(w.error)):w.type===a.PoolEventType.terminated&&(b.unsubscribe(),T(Error("Pool has been terminated before task was run.")))})})}settled(_=!1){return e(this,void 0,void 0,function*(){const g=()=>f(this.workers,w=>w.runningTasks),T=[],b=this.eventObservable.subscribe(w=>{w.type===a.PoolEventType.taskFailed&&T.push(w.error)});return this.initErrors.length>0?Promise.reject(this.initErrors[0]):_&&this.taskQueue.length===0?(yield o.allSettled(g()),T):(yield new Promise((w,C)=>{const L=this.eventObservable.subscribe({next(S){S.type===a.PoolEventType.taskQueueDrained&&(L.unsubscribe(),w(void 0))},error:C})}),yield o.allSettled(g()),b.unsubscribe(),T)})}completed(_=!1){return e(this,void 0,void 0,function*(){const g=this.settled(_),T=new Promise((w,C)=>{const L=this.eventObservable.subscribe({next(S){S.type===a.PoolEventType.taskQueueDrained?(L.unsubscribe(),w(g)):S.type===a.PoolEventType.taskFailed&&(L.unsubscribe(),C(S.error))},error:C})}),b=yield Promise.race([g,T]);if(b.length>0)throw b[0]})}events(){return this.eventObservable}queue(_){const{maxQueuedJobs:g=1/0}=this.options;if(this.isClosing)throw Error("Cannot schedule pool tasks after terminate() has been called.");if(this.initErrors.length>0)throw this.initErrors[0];const T=this.nextTaskID++,b=this.taskCompletion(T);b.catch(C=>{this.debug(`Task #${T} errored:`,C)});const w={id:T,run:_,cancel:()=>{this.taskQueue.indexOf(w)!==-1&&(this.taskQueue=this.taskQueue.filter(C=>C!==w),this.eventSubject.next({type:a.PoolEventType.taskCanceled,taskID:w.id}))},then:b.then.bind(b)};if(this.taskQueue.length>=g)throw Error(`Maximum number of pool tasks queued. Refusing to queue another one.
|
|
2
|
-
This usually happens for one of two reasons: We are either at peak workload right now or some tasks just won't finish, thus blocking the pool.`);return this.debug(`Queueing task #${w.id}...`),this.taskQueue.push(w),this.eventSubject.next({type:a.PoolEventType.taskQueued,taskID:w.id}),this.scheduleWork(),w}terminate(_){return e(this,void 0,void 0,function*(){this.isClosing=!0,_||(yield this.completed(!0)),this.eventSubject.next({type:a.PoolEventType.terminated,remainingQueue:[...this.taskQueue]}),this.eventSubject.complete(),yield Promise.all(this.workers.map(g=>e(this,void 0,void 0,function*(){return c.Thread.terminate(yield g.init)})))})}}R.EventType=a.PoolEventType;function v(m,_){return new R(m,_)}v.EventType=a.PoolEventType,s.Pool=v}($)),$}var F={},te={},Ke;function Gt(){if(Ke)return te;Ke=1,Object.defineProperty(te,"__esModule",{value:!0}),te.createPromiseWithResolver=void 0;const s=()=>{};function e(){let t=!1,n,r=s;return[new Promise(a=>{t?a(n):r=a}),a=>{t=!0,n=a,r(n)}]}return te.createPromiseWithResolver=e,te}var we={},ze;function Wt(){return ze||(ze=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.WorkerEventType=void 0,function(e){e.internalError="internalError",e.message="message",e.termination="termination"}(s.WorkerEventType||(s.WorkerEventType={}))}(we)),we}var j={},ne={},$e;function Kt(){if($e)return ne;$e=1,Object.defineProperty(ne,"__esModule",{value:!0}),ne.ObservablePromise=void 0;const s=he,e=()=>{},t=a=>a,n=a=>Promise.resolve().then(a);function r(a){throw a}function o(a){return a&&typeof a.then=="function"}class i extends s.Observable{constructor(c){super(d=>{const u=this,l=Object.assign(Object.assign({},d),{complete(){d.complete(),u.onCompletion()},error(f){d.error(f),u.onError(f)},next(f){d.next(f),u.onNext(f)}});try{return this.initHasRun=!0,c(l)}catch(f){l.error(f)}}),this.initHasRun=!1,this.fulfillmentCallbacks=[],this.rejectionCallbacks=[],this.firstValueSet=!1,this.state="pending"}onNext(c){this.firstValueSet||(this.firstValue=c,this.firstValueSet=!0)}onError(c){this.state="rejected",this.rejection=c;for(const d of this.rejectionCallbacks)n(()=>d(c))}onCompletion(){this.state="fulfilled";for(const c of this.fulfillmentCallbacks)n(()=>c(this.firstValue))}then(c,d){const u=c||t,l=d||r;let f=!1;return new Promise((p,E)=>{const R=m=>{if(!f){f=!0;try{p(l(m))}catch(_){E(_)}}},v=m=>{try{p(u(m))}catch(_){R(_)}};if(this.initHasRun||this.subscribe({error:R}),this.state==="fulfilled")return p(u(this.firstValue));if(this.state==="rejected")return f=!0,p(l(this.rejection));this.fulfillmentCallbacks.push(v),this.rejectionCallbacks.push(R)})}catch(c){return this.then(void 0,c)}finally(c){const d=c||e;return this.then(u=>(d(),u),()=>d())}static from(c){return o(c)?new i(d=>{const u=f=>{d.next(f),d.complete()},l=f=>{d.error(f)};c.then(u,l)}):super.from(c)}}return ne.ObservablePromise=i,ne}var Ve;function zt(){if(Ve)return j;Ve=1;var s=j&&j.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(j,"__esModule",{value:!0}),j.createProxyModule=j.createProxyFunction=void 0;const e=s(Oe()),t=he,n=y.requireCommon(),r=Kt(),o=y.requireTransferable(),i=y.requireMessages(),a=e.default("threads:master:messages");let c=1;const d=m=>Array.from(new Set(m)),u=m=>m&&m.type===i.WorkerMessageType.error,l=m=>m&&m.type===i.WorkerMessageType.result,f=m=>m&&m.type===i.WorkerMessageType.running;function p(m,_){return new t.Observable(g=>{let T;const b=w=>{if(a("Message from worker:",w.data),!(!w.data||w.data.uid!==_)){if(f(w.data))T=w.data.resultType;else if(l(w.data))T==="promise"?(typeof w.data.payload<"u"&&g.next(n.deserialize(w.data.payload)),g.complete(),m.removeEventListener("message",b)):(w.data.payload&&g.next(n.deserialize(w.data.payload)),w.data.complete&&(g.complete(),m.removeEventListener("message",b)));else if(u(w.data)){const C=n.deserialize(w.data.error);g.error(C),m.removeEventListener("message",b)}}};return m.addEventListener("message",b),()=>{if(T==="observable"||!T){const w={type:i.MasterMessageType.cancel,uid:_};m.postMessage(w)}m.removeEventListener("message",b)}})}function E(m){if(m.length===0)return{args:[],transferables:[]};const _=[],g=[];for(const T of m)o.isTransferDescriptor(T)?(_.push(n.serialize(T.send)),g.push(...T.transferables)):_.push(n.serialize(T));return{args:_,transferables:g.length===0?g:d(g)}}function R(m,_){return(...g)=>{const T=c++,{args:b,transferables:w}=E(g),C={type:i.MasterMessageType.run,uid:T,method:_,args:b};a("Sending command to run function to worker:",C);try{m.postMessage(C,w)}catch(L){return r.ObservablePromise.from(Promise.reject(L))}return r.ObservablePromise.from(t.multicast(p(m,T)))}}j.createProxyFunction=R;function v(m,_){const g={};for(const T of _)g[T]=R(m,T);return g}return j.createProxyModule=v,j}var qe;function $t(){if(qe)return F;qe=1;var s=F&&F.__awaiter||function(b,w,C,L){function S(A){return A instanceof C?A:new C(function(k){k(A)})}return new(C||(C=Promise))(function(A,k){function I(W){try{pe(L.next(W))}catch(me){k(me)}}function G(W){try{pe(L.throw(W))}catch(me){k(me)}}function pe(W){W.done?A(W.value):S(W.value).then(I,G)}pe((L=L.apply(b,w||[])).next())})},e=F&&F.__importDefault||function(b){return b&&b.__esModule?b:{default:b}};Object.defineProperty(F,"__esModule",{value:!0}),F.spawn=void 0;const t=e(Oe()),n=he,r=y.requireCommon(),o=Gt(),i=y.requireSymbols(),a=Wt(),c=zt(),d=t.default("threads:master:messages"),u=t.default("threads:master:spawn"),l=t.default("threads:master:thread-utils"),f=b=>b&&b.type==="init",p=b=>b&&b.type==="uncaughtError",E=typeof process<"u"&&process.env.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt(process.env.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function R(b,w,C){return s(this,void 0,void 0,function*(){let L;const S=new Promise((k,I)=>{L=setTimeout(()=>I(Error(C)),w)}),A=yield Promise.race([b,S]);return clearTimeout(L),A})}function v(b){return new Promise((w,C)=>{const L=S=>{d("Message from worker before finishing initialization:",S.data),f(S.data)?(b.removeEventListener("message",L),w(S.data)):p(S.data)&&(b.removeEventListener("message",L),C(r.deserialize(S.data.error)))};b.addEventListener("message",L)})}function m(b,w){return new n.Observable(C=>{const L=A=>{const k={type:a.WorkerEventType.message,data:A.data};C.next(k)},S=A=>{l("Unhandled promise rejection event in thread:",A);const k={type:a.WorkerEventType.internalError,error:Error(A.reason)};C.next(k)};b.addEventListener("message",L),b.addEventListener("unhandledrejection",S),w.then(()=>{const A={type:a.WorkerEventType.termination};b.removeEventListener("message",L),b.removeEventListener("unhandledrejection",S),C.next(A),C.complete()})})}function _(b){const[w,C]=o.createPromiseWithResolver();return{terminate:()=>s(this,void 0,void 0,function*(){l("Terminating worker"),yield b.terminate(),C()}),termination:w}}function g(b,w,C,L){const S=C.filter(A=>A.type===a.WorkerEventType.internalError).map(A=>A.error);return Object.assign(b,{[i.$errors]:S,[i.$events]:C,[i.$terminate]:L,[i.$worker]:w})}function T(b,w){return s(this,void 0,void 0,function*(){u("Initializing new thread");const C=w&&w.timeout?w.timeout:E,S=(yield R(v(b),C,`Timeout: Did not receive an init message from worker after ${C}ms. Make sure the worker calls expose().`)).exposed,{termination:A,terminate:k}=_(b),I=m(b,A);if(S.type==="function"){const G=c.createProxyFunction(b);return g(G,b,I,k)}else if(S.type==="module"){const G=c.createProxyModule(b,S.methods);return g(G,b,I,k)}else{const G=S.type;throw Error(`Worker init message states unexpected type of expose(): ${G}`)}})}return F.spawn=T,F}var Xe;function Vt(){return Xe||(Xe=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.Worker=s.BlobWorker=s.isWorkerRuntime=s.Thread=s.spawn=s.Pool=void 0;const e=nt();Object.defineProperty(s,"isWorkerRuntime",{enumerable:!0,get:function(){return e.isWorkerRuntime}});var t=Bt();Object.defineProperty(s,"Pool",{enumerable:!0,get:function(){return t.Pool}});var n=$t();Object.defineProperty(s,"spawn",{enumerable:!0,get:function(){return n.spawn}});var r=ct();Object.defineProperty(s,"Thread",{enumerable:!0,get:function(){return r.Thread}}),s.BlobWorker=e.getWorkerImplementation().blob,s.Worker=e.getWorkerImplementation().default}(ge)),ge}var Qe;function qt(){return Qe||(Qe=1,function(s){var e=K&&K.__createBinding||(Object.create?function(a,c,d,u){u===void 0&&(u=d),Object.defineProperty(a,u,{enumerable:!0,get:function(){return c[d]}})}:function(a,c,d,u){u===void 0&&(u=d),a[u]=c[d]}),t=K&&K.__exportStar||function(a,c){for(var d in a)d!=="default"&&!Object.prototype.hasOwnProperty.call(c,d)&&e(c,a,d)};Object.defineProperty(s,"__esModule",{value:!0}),s.Transfer=s.DefaultSerializer=s.expose=s.registerSerializer=void 0;var n=y.requireCommon();Object.defineProperty(s,"registerSerializer",{enumerable:!0,get:function(){return n.registerSerializer}}),t(Vt(),s);var r=y.requireWorker();Object.defineProperty(s,"expose",{enumerable:!0,get:function(){return r.expose}});var o=y.requireSerializers();Object.defineProperty(s,"DefaultSerializer",{enumerable:!0,get:function(){return o.DefaultSerializer}});var i=y.requireTransferable();Object.defineProperty(s,"Transfer",{enumerable:!0,get:function(){return i.Transfer}})}(K)),K}var Xt=qt();const B=y.getDefaultExportFromCjs(Xt);B.registerSerializer;const Qt=B.spawn;B.BlobWorker;B.DefaultSerializer;B.Pool;const Yt=B.Thread;B.Transfer;const Jt=B.Worker;var Zt=Object.defineProperty,en=(s,e,t)=>e in s?Zt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,H=(s,e,t)=>en(s,typeof e!="symbol"?e+"":e,t);const tn=()=>{try{if(window){if(navigator!=null&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;throw new Error("Unable to determine the number of cores")}else return require("os").cpus().length}catch(s){return console.error("🛑 Unable to detect available cores",s),2}},nn=()=>tn()-1,rn="TERMINATE_THREAD_FROM_WORKER";let sn=-1;class on{constructor(e){H(this,"_handleTerminate"),H(this,"_handleError"),H(this,"_task"),H(this,"id",sn+=1),H(this,"idle",!0),H(this,"worker"),H(this,"thread"),this._handleTerminate=e==null?void 0:e.onTerminate,this._handleError=e==null?void 0:e.onError}_handleMessages(e){var t;e instanceof MessageEvent&&((t=e.data)==null?void 0:t.token)===rn&&this.terminate()}async run(e){var t;try{const{payload:n,options:r}=e;return this.idle=!1,this.worker=new Jt(n.path,{type:"module",...r==null?void 0:r.worker}),this.thread=await Qt(this.worker,{timeout:1e4,...r==null?void 0:r.spawn}),this._task=e,this.worker.postMessage(n.subject,n.transferSubject),this.worker.addEventListener("message",this._handleMessages.bind(this)),this}catch(n){(t=this._handleError)==null||t.call(this,n);return}}get task(){return this._task}async terminate(){var e,t,n;(e=this.worker)==null||e.removeEventListener("message",this._handleMessages.bind(this)),this.thread&&await Yt.terminate(this.thread),await((t=this.worker)==null?void 0:t.terminate()),this.worker=void 0,this.thread=void 0,this._task=void 0,this.idle=!0,(n=this._handleTerminate)==null||n.call(this)}}class an{constructor(e,t,n){H(this,"_workerThreads",[]),H(this,"_tasksQueue",[]),this.maxWorkersCount=e,this.debugMode=t,this.onWorkerThreadRun=n;for(let r=0;r<this.maxWorkersCount;r++)this._workerThreads.push(this._createWorkerThread())}_handleWorkerThreadTerminate(e){this.debugMode&&console.log(`WorkerThread #${e.id} freed`),this.runNext()}_handleWorkerThreadError(e,t){console.error(`Error from worker #${t.id}:`,e),this.runNext()}_createWorkerThread(){const e=new on({onTerminate:()=>this._handleWorkerThreadTerminate(e),onError:t=>this._handleWorkerThreadError(t,e)});return e}get workerThreads(){return this._workerThreads}get tasksQueue(){return this._tasksQueue}get nextAvailableWorkerThread(){return this._workerThreads.find(e=>e.idle)}getAvailableWorkerThreads(e=!1){return this._workerThreads.filter(t=>e?!t.idle:t.idle)}async runNext(){if(!this.nextAvailableWorkerThread||this._tasksQueue.length===0)return;const e=this._tasksQueue.shift();e&&await this.run(e)}async run(e,t=!1){var n;if(t){const i=this._createWorkerThread();return this.debugMode&&console.log(`Running On Untracked Thread #${i==null?void 0:i.id}. Task:`,e),[await i.run(e),!0]}const r=this.nextAvailableWorkerThread;if(!r)return this._tasksQueue.push(e),this.debugMode&&console.log("Queued Thread Task:",e),[void 0,!0];this.debugMode&&console.log(`Running On Thread #${r==null?void 0:r.id}. Task:`,e);const o=await r.run(e);if(o)return(n=this.onWorkerThreadRun)==null||n.call(this,o),[o,!1]}async terminateAll(){this._tasksQueue=[],await Promise.all(this._workerThreads.map(e=>e.terminate()))}}const cn=(s,e)=>new an(nn(),!!e);var un=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(s,e,t,n)=>{for(var r=n>1?void 0:n?ln(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&un(e,t,r),r},fn=(s,e)=>(t,n)=>e(t,n,s);let ue=class{constructor(s){x(this,"workerPool");x(this,"canvas");x(this,"offscreenCanvas");x(this,"worker");x(this,"thread");this._props=s,this.workerPool=cn(void 0,this._props.enableDebug)}init(s){this.worker=s.worker,this.thread=s.thread}preventDefaultHandler(s){return s.preventDefault(),{type:s.type}}getScreenSizes(){var s,e;return{width:(s=this.canvas)==null?void 0:s.width,height:(e=this.canvas)==null?void 0:e.height,windowWidth:(window==null?void 0:window.innerWidth)??0,windowHeight:(window==null?void 0:window.innerHeight)??0}}uiEventHandler(s){var t;const e=(t=this.canvas)==null?void 0:t.getBoundingClientRect();return{...this.getScreenSizes(),type:s.type,top:e==null?void 0:e.top,left:e==null?void 0:e.left}}mouseEventHandler(s){return{...this.getScreenSizes(),...y.R(s,["ctrlKey","metaKey","shiftKey","button","pointerType","clientX","clientY","pageX","pageY"])}}touchEventHandler(s){const e=[],t={type:s.type,touches:e};for(let n=0;n<s.touches.length;++n){const r=s.touches[n];e.push({pageX:(r==null?void 0:r.pageX)??0,pageY:(r==null?void 0:r.pageY)??0})}return{...this.getScreenSizes(),...t}}wheelEventHandler(s){return s.preventDefault(),{...this.getScreenSizes(),...y.R(s,["deltaX","deltaY"])}}keyEventHandler(s){if(y.KEYBOARD_EVENT_CODES.includes(s.code))return s.preventDefault(),{...this.getScreenSizes(),...y.R(s,["ctrlKey","metaKey","shiftKey","keyCode"])}}};ue=dn([y.scoped(y.Lifecycle.ContainerScoped),fn(0,y.inject(se))],ue);var hn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,mn=(s,e,t,n)=>{for(var r=n>1?void 0:n?pn(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&hn(e,t,r),r},gn=(s,e)=>(t,n)=>e(t,n,s);let Le=class extends y.ProxyEventHandlersBlueprint{constructor(s){super(),this._service=s}init(){let s;try{s=y.instance.resolve("MAIN_THREAD_APP")}catch{s=void 0}for(const e of y.PROXY_EVENT_LISTENERS){const t=e.startsWith("mouse")||e.startsWith("pointer")||e.startsWith("touch")?this._service.mouseEventHandler.bind(this._service):e.startsWith("key")?this._service.keyEventHandler.bind(this._service):e==="resize"?this._service.uiEventHandler.bind(this._service):e==="wheel"?this._service.wheelEventHandler.bind(this._service):this._service.preventDefaultHandler.bind(this._service);this[`${e}$$`]=new y.Subject,y.fromEvent(e==="resize"?window:this._service.canvas,e).pipe(y.map(t.bind(this)),y.filter(n=>!(e==="keydown"&&!n))).subscribe(n=>{this[`${e}$$`].next(n)}),this[`${e}$`]=this[`${e}$$`].asObservable(),this[`${e}$`].subscribe(n=>{var r,o,i;(o=(r=this._service.thread)==null?void 0:r[e])==null||o.call(r,n),(i=s==null?void 0:s[e])==null||i.call(s,n)})}}};Le=mn([y.scoped(y.Lifecycle.ContainerScoped),gn(0,y.inject(ue))],Le);function Ye(s,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),s;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=s.getIndex();if(t===null){const i=[],a=s.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)i.push(c);s.setIndex(i),t=s.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),s}const n=t.count-2,r=[];if(e===h.TriangleFanDrawMode)for(let i=1;i<=n;i++)r.push(t.getX(0)),r.push(t.getX(i)),r.push(t.getX(i+1));else for(let i=0;i<n;i++)i%2===0?(r.push(t.getX(i)),r.push(t.getX(i+1)),r.push(t.getX(i+2))):(r.push(t.getX(i+2)),r.push(t.getX(i+1)),r.push(t.getX(i)));r.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=s.clone();return o.setIndex(r),o.clearGroups(),o}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),s}const ve=new WeakMap;class ut extends h.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,r){const o=new h.FileLoader(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,i=>{this.parse(i,t,r)},n,r)}parse(e,t,n=()=>{}){this.decodeDracoFile(e,t,null,null,h.SRGBColorSpace,n).catch(n)}decodeDracoFile(e,t,n,r,o=h.LinearSRGBColorSpace,i=()=>{}){const a={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:r||this.defaultAttributeTypes,useUniqueIDs:!!n,vertexColorSpace:o};return this.decodeGeometry(e,a).then(t).catch(i)}decodeGeometry(e,t){const n=JSON.stringify(t);if(ve.has(e)){const c=ve.get(e);if(c.key===n)return c.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const o=this.workerNextTaskID++,i=e.byteLength,a=this._getWorker(o,i).then(c=>(r=c,new Promise((d,u)=>{r._callbacks[o]={resolve:d,reject:u},r.postMessage({type:"decode",id:o,taskConfig:t,buffer:e},[e])}))).then(c=>this._createGeometry(c.geometry));return a.catch(()=>!0).then(()=>{r&&o&&this._releaseTask(r,o)}),ve.set(e,{key:n,promise:a}),a}_createGeometry(e){const t=new h.BufferGeometry;e.index&&t.setIndex(new h.BufferAttribute(e.index.array,1));for(let n=0;n<e.attributes.length;n++){const r=e.attributes[n],o=r.name,i=r.array,a=r.itemSize,c=new h.BufferAttribute(i,a);o==="color"&&(this._assignVertexColorSpace(c,r.vertexColorSpace),c.normalized=!(i instanceof Float32Array)),t.setAttribute(o,c)}return t}_assignVertexColorSpace(e,t){if(t!==h.SRGBColorSpace)return;const n=new h.Color;for(let r=0,o=e.count;r<o;r++)n.fromBufferAttribute(e,r),h.ColorManagement.colorSpaceToWorking(n,h.SRGBColorSpace),e.setXYZ(r,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new h.FileLoader(this.manager);return n.setPath(this.decoderPath),n.setResponseType(t),n.setWithCredentials(this.withCredentials),new Promise((r,o)=>{n.load(e,r,void 0,o)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(n=>{const r=n[0];e||(this.decoderConfig.wasmBinary=n[1]);const o=_n.toString(),i=["/* draco decoder */",r,"","/* worker */",o.substring(o.indexOf("{")+1,o.lastIndexOf("}"))].join(`
|
|
3
|
-
`);this.workerSourceURL=URL.createObjectURL(new Blob([i]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const r=new Worker(this.workerSourceURL);r._callbacks={},r._taskCosts={},r._taskLoad=0,r.postMessage({type:"init",decoderConfig:this.decoderConfig}),r.onmessage=function(o){const i=o.data;switch(i.type){case"decode":r._callbacks[i.id].resolve(i);break;case"error":r._callbacks[i.id].reject(i);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+i.type+'"')}},this.workerPool.push(r)}else this.workerPool.sort(function(r,o){return r._taskLoad>o._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this.workerSourceURL!==""&&URL.revokeObjectURL(this.workerSourceURL),this}}function _n(){let s,e;onmessage=function(i){const a=i.data;switch(a.type){case"init":s=a.decoderConfig,e=new Promise(function(u){s.onModuleLoaded=function(l){u({draco:l})},DracoDecoderModule(s)});break;case"decode":const c=a.buffer,d=a.taskConfig;e.then(u=>{const l=u.draco,f=new l.Decoder;try{const p=t(l,f,new Int8Array(c),d),E=p.attributes.map(R=>R.array.buffer);p.index&&E.push(p.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:p},E)}catch(p){console.error(p),self.postMessage({type:"error",id:a.id,error:p.message})}finally{l.destroy(f)}});break}};function t(i,a,c,d){const u=d.attributeIDs,l=d.attributeTypes;let f,p;const E=a.GetEncodedGeometryType(c);if(E===i.TRIANGULAR_MESH)f=new i.Mesh,p=a.DecodeArrayToMesh(c,c.byteLength,f);else if(E===i.POINT_CLOUD)f=new i.PointCloud,p=a.DecodeArrayToPointCloud(c,c.byteLength,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!p.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+p.error_msg());const R={index:null,attributes:[]};for(const v in u){const m=self[l[v]];let _,g;if(d.useUniqueIDs)g=u[v],_=a.GetAttributeByUniqueId(f,g);else{if(g=a.GetAttributeId(f,i[u[v]]),g===-1)continue;_=a.GetAttribute(f,g)}const T=r(i,a,f,v,m,_);v==="color"&&(T.vertexColorSpace=d.vertexColorSpace),R.attributes.push(T)}return E===i.TRIANGULAR_MESH&&(R.index=n(i,a,f)),i.destroy(f),R}function n(i,a,c){const u=c.num_faces()*3,l=u*4,f=i._malloc(l);a.GetTrianglesUInt32Array(c,l,f);const p=new Uint32Array(i.HEAPF32.buffer,f,u).slice();return i._free(f),{array:p,itemSize:1}}function r(i,a,c,d,u,l){const f=l.num_components(),E=c.num_points()*f,R=E*u.BYTES_PER_ELEMENT,v=o(i,u),m=i._malloc(R);a.GetAttributeDataArrayForAllPoints(c,l,v,R,m);const _=new u(i.HEAPF32.buffer,m,E).slice();return i._free(m),{name:d,array:_,itemSize:f}}function o(i,a){switch(a){case Float32Array:return i.DT_FLOAT32;case Int8Array:return i.DT_INT8;case Int16Array:return i.DT_INT16;case Int32Array:return i.DT_INT32;case Uint8Array:return i.DT_UINT8;case Uint16Array:return i.DT_UINT16;case Uint32Array:return i.DT_UINT32}}}class yn extends h.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new En(t)}),this.register(function(t){return new Cn(t)}),this.register(function(t){return new On(t)}),this.register(function(t){return new In(t)}),this.register(function(t){return new Nn(t)}),this.register(function(t){return new Sn(t)}),this.register(function(t){return new xn(t)}),this.register(function(t){return new Mn(t)}),this.register(function(t){return new Ln(t)}),this.register(function(t){return new vn(t)}),this.register(function(t){return new An(t)}),this.register(function(t){return new Rn(t)}),this.register(function(t){return new Pn(t)}),this.register(function(t){return new kn(t)}),this.register(function(t){return new Tn(t)}),this.register(function(t){return new Dn(t)}),this.register(function(t){return new Fn(t)})}load(e,t,n,r){const o=this;let i;if(this.resourcePath!=="")i=this.resourcePath;else if(this.path!==""){const d=h.LoaderUtils.extractUrlBase(e);i=h.LoaderUtils.resolveURL(d,this.path)}else i=h.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(d){r?r(d):console.error(d),o.manager.itemError(e),o.manager.itemEnd(e)},c=new h.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(d){try{o.parse(d,i,function(u){t(u),o.manager.itemEnd(e)},a)}catch(u){a(u)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let o;const i={},a={},c=new TextDecoder;if(typeof e=="string")o=JSON.parse(e);else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===lt){try{i[M.KHR_BINARY_GLTF]=new jn(e)}catch(l){r&&r(l);return}o=JSON.parse(i[M.KHR_BINARY_GLTF].content)}else o=JSON.parse(c.decode(e));else o=e;if(o.asset===void 0||o.asset.version[0]<2){r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const d=new Yn(o,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});d.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const l=this.pluginCallbacks[u](d);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[l.name]=l,i[l.name]=!0}if(o.extensionsUsed)for(let u=0;u<o.extensionsUsed.length;++u){const l=o.extensionsUsed[u],f=o.extensionsRequired||[];switch(l){case M.KHR_MATERIALS_UNLIT:i[l]=new wn;break;case M.KHR_DRACO_MESH_COMPRESSION:i[l]=new Hn(o,this.dracoLoader);break;case M.KHR_TEXTURE_TRANSFORM:i[l]=new Un;break;case M.KHR_MESH_QUANTIZATION:i[l]=new Bn;break;default:f.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}d.setExtensions(i),d.setPlugins(a),d.parse(n,r)}parseAsync(e,t){const n=this;return new Promise(function(r,o){n.parse(e,t,r,o)})}}function bn(){let s={};return{get:function(e){return s[e]},add:function(e,t){s[e]=t},remove:function(e){delete s[e]},removeAll:function(){s={}}}}const M={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",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Tn{constructor(e){this.parser=e,this.name=M.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){const o=t[n];o.extensions&&o.extensions[this.name]&&o.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,o.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let r=t.cache.get(n);if(r)return r;const o=t.json,c=((o.extensions&&o.extensions[this.name]||{}).lights||[])[e];let d;const u=new h.Color(16777215);c.color!==void 0&&u.setRGB(c.color[0],c.color[1],c.color[2],h.LinearSRGBColorSpace);const l=c.range!==void 0?c.range:0;switch(c.type){case"directional":d=new h.DirectionalLight(u),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new h.PointLight(u),d.distance=l;break;case"spot":d=new h.SpotLight(u),d.distance=l,c.spot=c.spot||{},c.spot.innerConeAngle=c.spot.innerConeAngle!==void 0?c.spot.innerConeAngle:0,c.spot.outerConeAngle=c.spot.outerConeAngle!==void 0?c.spot.outerConeAngle:Math.PI/4,d.angle=c.spot.outerConeAngle,d.penumbra=1-c.spot.innerConeAngle/c.spot.outerConeAngle,d.target.position.set(0,0,-1),d.add(d.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+c.type)}return d.position.set(0,0,0),N(d,c),c.intensity!==void 0&&(d.intensity=c.intensity),d.name=t.createUniqueName(c.name||"light_"+e),r=Promise.resolve(d),t.cache.add(n,r),r}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,o=n.json.nodes[e],a=(o.extensions&&o.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(c){return n._getNodeRef(t.cache,a,c)})}}class wn{constructor(){this.name=M.KHR_MATERIALS_UNLIT}getMaterialType(){return h.MeshBasicMaterial}extendParams(e,t,n){const r=[];e.color=new h.Color(1,1,1),e.opacity=1;const o=t.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const i=o.baseColorFactor;e.color.setRGB(i[0],i[1],i[2],h.LinearSRGBColorSpace),e.opacity=i[3]}o.baseColorTexture!==void 0&&r.push(n.assignTexture(e,"map",o.baseColorTexture,h.SRGBColorSpace))}return Promise.all(r)}}class vn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const r=this.parser.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=r.extensions[this.name].emissiveStrength;return o!==void 0&&(t.emissiveIntensity=o),Promise.resolve()}}class En{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];if(i.clearcoatFactor!==void 0&&(t.clearcoat=i.clearcoatFactor),i.clearcoatTexture!==void 0&&o.push(n.assignTexture(t,"clearcoatMap",i.clearcoatTexture)),i.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=i.clearcoatRoughnessFactor),i.clearcoatRoughnessTexture!==void 0&&o.push(n.assignTexture(t,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),i.clearcoatNormalTexture!==void 0&&(o.push(n.assignTexture(t,"clearcoatNormalMap",i.clearcoatNormalTexture)),i.clearcoatNormalTexture.scale!==void 0)){const a=i.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new h.Vector2(a,a)}return Promise.all(o)}}class Cn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_DISPERSION}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const r=this.parser.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=r.extensions[this.name];return t.dispersion=o.dispersion!==void 0?o.dispersion:0,Promise.resolve()}}class Rn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];return i.iridescenceFactor!==void 0&&(t.iridescence=i.iridescenceFactor),i.iridescenceTexture!==void 0&&o.push(n.assignTexture(t,"iridescenceMap",i.iridescenceTexture)),i.iridescenceIor!==void 0&&(t.iridescenceIOR=i.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),i.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=i.iridescenceThicknessMinimum),i.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=i.iridescenceThicknessMaximum),i.iridescenceThicknessTexture!==void 0&&o.push(n.assignTexture(t,"iridescenceThicknessMap",i.iridescenceThicknessTexture)),Promise.all(o)}}class Sn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_SHEEN}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];t.sheenColor=new h.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const i=r.extensions[this.name];if(i.sheenColorFactor!==void 0){const a=i.sheenColorFactor;t.sheenColor.setRGB(a[0],a[1],a[2],h.LinearSRGBColorSpace)}return i.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=i.sheenRoughnessFactor),i.sheenColorTexture!==void 0&&o.push(n.assignTexture(t,"sheenColorMap",i.sheenColorTexture,h.SRGBColorSpace)),i.sheenRoughnessTexture!==void 0&&o.push(n.assignTexture(t,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(o)}}class xn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];return i.transmissionFactor!==void 0&&(t.transmission=i.transmissionFactor),i.transmissionTexture!==void 0&&o.push(n.assignTexture(t,"transmissionMap",i.transmissionTexture)),Promise.all(o)}}class Mn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_VOLUME}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];t.thickness=i.thicknessFactor!==void 0?i.thicknessFactor:0,i.thicknessTexture!==void 0&&o.push(n.assignTexture(t,"thicknessMap",i.thicknessTexture)),t.attenuationDistance=i.attenuationDistance||1/0;const a=i.attenuationColor||[1,1,1];return t.attenuationColor=new h.Color().setRGB(a[0],a[1],a[2],h.LinearSRGBColorSpace),Promise.all(o)}}class Ln{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_IOR}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const r=this.parser.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=r.extensions[this.name];return t.ior=o.ior!==void 0?o.ior:1.5,Promise.resolve()}}class An{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_SPECULAR}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];t.specularIntensity=i.specularFactor!==void 0?i.specularFactor:1,i.specularTexture!==void 0&&o.push(n.assignTexture(t,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return t.specularColor=new h.Color().setRGB(a[0],a[1],a[2],h.LinearSRGBColorSpace),i.specularColorTexture!==void 0&&o.push(n.assignTexture(t,"specularColorMap",i.specularColorTexture,h.SRGBColorSpace)),Promise.all(o)}}class kn{constructor(e){this.parser=e,this.name=M.EXT_MATERIALS_BUMP}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];return t.bumpScale=i.bumpFactor!==void 0?i.bumpFactor:1,i.bumpTexture!==void 0&&o.push(n.assignTexture(t,"bumpMap",i.bumpTexture)),Promise.all(o)}}class Pn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:h.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];return i.anisotropyStrength!==void 0&&(t.anisotropy=i.anisotropyStrength),i.anisotropyRotation!==void 0&&(t.anisotropyRotation=i.anisotropyRotation),i.anisotropyTexture!==void 0&&o.push(n.assignTexture(t,"anisotropyMap",i.anisotropyTexture)),Promise.all(o)}}class On{constructor(e){this.parser=e,this.name=M.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const o=r.extensions[this.name],i=t.options.ktx2Loader;if(!i){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,o.source,i)}}class In{constructor(e){this.parser=e,this.name=M.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,n=this.parser,r=n.json,o=r.textures[e];if(!o.extensions||!o.extensions[t])return null;const i=o.extensions[t],a=r.images[i.source];let c=n.textureLoader;if(a.uri){const d=n.options.manager.getHandler(a.uri);d!==null&&(c=d)}return n.loadTextureImage(e,i.source,c)}}class Nn{constructor(e){this.parser=e,this.name=M.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,n=this.parser,r=n.json,o=r.textures[e];if(!o.extensions||!o.extensions[t])return null;const i=o.extensions[t],a=r.images[i.source];let c=n.textureLoader;if(a.uri){const d=n.options.manager.getHandler(a.uri);d!==null&&(c=d)}return n.loadTextureImage(e,i.source,c)}}class Dn{constructor(e){this.name=M.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const r=n.extensions[this.name],o=this.parser.getDependency("buffer",r.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return o.then(function(a){const c=r.byteOffset||0,d=r.byteLength||0,u=r.count,l=r.byteStride,f=new Uint8Array(a,c,d);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(u,l,f,r.mode,r.filter).then(function(p){return p.buffer}):i.ready.then(function(){const p=new ArrayBuffer(u*l);return i.decodeGltfBuffer(new Uint8Array(p),u,l,f,r.mode,r.filter),p})})}else return null}}class Fn{constructor(e){this.name=M.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;const r=t.meshes[n.mesh];for(const d of r.primitives)if(d.mode!==O.TRIANGLES&&d.mode!==O.TRIANGLE_STRIP&&d.mode!==O.TRIANGLE_FAN&&d.mode!==void 0)return null;const i=n.extensions[this.name].attributes,a=[],c={};for(const d in i)a.push(this.parser.getDependency("accessor",i[d]).then(u=>(c[d]=u,c[d])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(d=>{const u=d.pop(),l=u.isGroup?u.children:[u],f=d[0].count,p=[];for(const E of l){const R=new h.Matrix4,v=new h.Vector3,m=new h.Quaternion,_=new h.Vector3(1,1,1),g=new h.InstancedMesh(E.geometry,E.material,f);for(let T=0;T<f;T++)c.TRANSLATION&&v.fromBufferAttribute(c.TRANSLATION,T),c.ROTATION&&m.fromBufferAttribute(c.ROTATION,T),c.SCALE&&_.fromBufferAttribute(c.SCALE,T),g.setMatrixAt(T,R.compose(v,m,_));for(const T in c)if(T==="_COLOR_0"){const b=c[T];g.instanceColor=new h.InstancedBufferAttribute(b.array,b.itemSize,b.normalized)}else T!=="TRANSLATION"&&T!=="ROTATION"&&T!=="SCALE"&&E.geometry.setAttribute(T,c[T]);h.Object3D.prototype.copy.call(g,E),this.parser.assignFinalMaterial(g),p.push(g)}return u.isGroup?(u.clear(),u.add(...p),u):p[0]}))}}const lt="glTF",re=12,Je={JSON:1313821514,BIN:5130562};class jn{constructor(e){this.name=M.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,re),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==lt)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-re,o=new DataView(e,re);let i=0;for(;i<r;){const a=o.getUint32(i,!0);i+=4;const c=o.getUint32(i,!0);if(i+=4,c===Je.JSON){const d=new Uint8Array(e,re+i,a);this.content=n.decode(d)}else if(c===Je.BIN){const d=re+i;this.body=e.slice(d,d+a)}i+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Hn{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=M.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,r=this.dracoLoader,o=e.extensions[this.name].bufferView,i=e.extensions[this.name].attributes,a={},c={},d={};for(const u in i){const l=Ae[u]||u.toLowerCase();a[l]=i[u]}for(const u in e.attributes){const l=Ae[u]||u.toLowerCase();if(i[u]!==void 0){const f=n.accessors[e.attributes[u]],p=Q[f.componentType];d[l]=p.name,c[l]=f.normalized===!0}}return t.getDependency("bufferView",o).then(function(u){return new Promise(function(l,f){r.decodeDracoFile(u,function(p){for(const E in p.attributes){const R=p.attributes[E],v=c[E];v!==void 0&&(R.normalized=v)}l(p)},a,d,h.LinearSRGBColorSpace,f)})})}}class Un{constructor(){this.name=M.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Bn{constructor(){this.name=M.KHR_MESH_QUANTIZATION}}class dt extends h.Interpolant{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,o=e*r*3+r;for(let i=0;i!==r;i++)t[i]=n[o+i];return t}interpolate_(e,t,n,r){const o=this.resultBuffer,i=this.sampleValues,a=this.valueSize,c=a*2,d=a*3,u=r-t,l=(n-t)/u,f=l*l,p=f*l,E=e*d,R=E-d,v=-2*p+3*f,m=p-f,_=1-v,g=m-f+l;for(let T=0;T!==a;T++){const b=i[R+T+a],w=i[R+T+c]*u,C=i[E+T+a],L=i[E+T]*u;o[T]=_*b+g*w+v*C+m*L}return o}}const Gn=new h.Quaternion;class Wn extends dt{interpolate_(e,t,n,r){const o=super.interpolate_(e,t,n,r);return Gn.fromArray(o).normalize().toArray(o),o}}const O={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},Q={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ze={9728:h.NearestFilter,9729:h.LinearFilter,9984:h.NearestMipmapNearestFilter,9985:h.LinearMipmapNearestFilter,9986:h.NearestMipmapLinearFilter,9987:h.LinearMipmapLinearFilter},et={33071:h.ClampToEdgeWrapping,33648:h.MirroredRepeatWrapping,10497:h.RepeatWrapping},Ee={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ae={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"},U={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Kn={CUBICSPLINE:void 0,LINEAR:h.InterpolateLinear,STEP:h.InterpolateDiscrete},Ce={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function zn(s){return s.DefaultMaterial===void 0&&(s.DefaultMaterial=new h.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:h.FrontSide})),s.DefaultMaterial}function V(s,e,t){for(const n in t.extensions)s[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function N(s,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(s.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function $n(s,e,t){let n=!1,r=!1,o=!1;for(let d=0,u=e.length;d<u;d++){const l=e[d];if(l.POSITION!==void 0&&(n=!0),l.NORMAL!==void 0&&(r=!0),l.COLOR_0!==void 0&&(o=!0),n&&r&&o)break}if(!n&&!r&&!o)return Promise.resolve(s);const i=[],a=[],c=[];for(let d=0,u=e.length;d<u;d++){const l=e[d];if(n){const f=l.POSITION!==void 0?t.getDependency("accessor",l.POSITION):s.attributes.position;i.push(f)}if(r){const f=l.NORMAL!==void 0?t.getDependency("accessor",l.NORMAL):s.attributes.normal;a.push(f)}if(o){const f=l.COLOR_0!==void 0?t.getDependency("accessor",l.COLOR_0):s.attributes.color;c.push(f)}}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(c)]).then(function(d){const u=d[0],l=d[1],f=d[2];return n&&(s.morphAttributes.position=u),r&&(s.morphAttributes.normal=l),o&&(s.morphAttributes.color=f),s.morphTargetsRelative=!0,s})}function Vn(s,e){if(s.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)s.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(s.morphTargetInfluences.length===t.length){s.morphTargetDictionary={};for(let n=0,r=t.length;n<r;n++)s.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function qn(s){let e;const t=s.extensions&&s.extensions[M.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Re(t.attributes):e=s.indices+":"+Re(s.attributes)+":"+s.mode,s.targets!==void 0)for(let n=0,r=s.targets.length;n<r;n++)e+=":"+Re(s.targets[n]);return e}function Re(s){let e="";const t=Object.keys(s).sort();for(let n=0,r=t.length;n<r;n++)e+=t[n]+":"+s[t[n]]+";";return e}function ke(s){switch(s){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 Xn(s){return s.search(/\.jpe?g($|\?)/i)>0||s.search(/^data\:image\/jpeg/)===0?"image/jpeg":s.search(/\.webp($|\?)/i)>0||s.search(/^data\:image\/webp/)===0?"image/webp":s.search(/\.ktx2($|\?)/i)>0||s.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Qn=new h.Matrix4;class Yn{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new bn,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 n=!1,r=-1,o=!1,i=-1;if(typeof navigator<"u"){const a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;const c=a.match(/Version\/(\d+)/);r=n&&c?parseInt(c[1],10):-1,o=a.indexOf("Firefox")>-1,i=o?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&r<17||o&&i<98?this.textureLoader=new h.TextureLoader(this.options.manager):this.textureLoader=new h.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new h.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,r=this.json,o=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(i){return i._markDefs&&i._markDefs()}),Promise.all(this._invokeAll(function(i){return i.beforeRoot&&i.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(i){const a={scene:i[0][r.scene||0],scenes:i[0],animations:i[1],cameras:i[2],asset:r.asset,parser:n,userData:{}};return V(o,a,r),N(a,r),Promise.all(n._invokeAll(function(c){return c.afterRoot&&c.afterRoot(a)})).then(function(){for(const c of a.scenes)c.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let r=0,o=t.length;r<o;r++){const i=t[r].joints;for(let a=0,c=i.length;a<c;a++)e[i[a]].isBone=!0}for(let r=0,o=e.length;r<o;r++){const i=e[r];i.mesh!==void 0&&(this._addNodeRef(this.meshCache,i.mesh),i.skin!==void 0&&(n[i.mesh].isSkinnedMesh=!0)),i.camera!==void 0&&this._addNodeRef(this.cameraCache,i.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const r=n.clone(),o=(i,a)=>{const c=this.associations.get(i);c!=null&&this.associations.set(a,c);for(const[d,u]of i.children.entries())o(u,a.children[d])};return o(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const r=e(t[n]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let r=0;r<t.length;r++){const o=e(t[r]);o&&n.push(o)}return n}getDependency(e,t){const n=e+":"+t;let r=this.cache.get(n);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne(function(o){return o.loadNode&&o.loadNode(t)});break;case"mesh":r=this._invokeOne(function(o){return o.loadMesh&&o.loadMesh(t)});break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne(function(o){return o.loadBufferView&&o.loadBufferView(t)});break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne(function(o){return o.loadMaterial&&o.loadMaterial(t)});break;case"texture":r=this._invokeOne(function(o){return o.loadTexture&&o.loadTexture(t)});break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne(function(o){return o.loadAnimation&&o.loadAnimation(t)});break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(o){return o!=this&&o.getDependency&&o.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e);break}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,r=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(r.map(function(o,i){return n.getDependency(e,i)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[M.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(o,i){n.load(h.LoaderUtils.resolveURL(t.uri,r.path),o,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){const r=t.byteLength||0,o=t.byteOffset||0;return n.slice(o,o+r)})}loadAccessor(e){const t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){const i=Ee[r.type],a=Q[r.componentType],c=r.normalized===!0,d=new a(r.count*i);return Promise.resolve(new h.BufferAttribute(d,i,c))}const o=[];return r.bufferView!==void 0?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),r.sparse!==void 0&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then(function(i){const a=i[0],c=Ee[r.type],d=Q[r.componentType],u=d.BYTES_PER_ELEMENT,l=u*c,f=r.byteOffset||0,p=r.bufferView!==void 0?n.bufferViews[r.bufferView].byteStride:void 0,E=r.normalized===!0;let R,v;if(p&&p!==l){const m=Math.floor(f/p),_="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+m+":"+r.count;let g=t.cache.get(_);g||(R=new d(a,m*p,r.count*p/u),g=new h.InterleavedBuffer(R,p/u),t.cache.add(_,g)),v=new h.InterleavedBufferAttribute(g,c,f%p/u,E)}else a===null?R=new d(r.count*c):R=new d(a,f,r.count*c),v=new h.BufferAttribute(R,c,E);if(r.sparse!==void 0){const m=Ee.SCALAR,_=Q[r.sparse.indices.componentType],g=r.sparse.indices.byteOffset||0,T=r.sparse.values.byteOffset||0,b=new _(i[1],g,r.sparse.count*m),w=new d(i[2],T,r.sparse.count*c);a!==null&&(v=new h.BufferAttribute(v.array.slice(),v.itemSize,v.normalized)),v.normalized=!1;for(let C=0,L=b.length;C<L;C++){const S=b[C];if(v.setX(S,w[C*c]),c>=2&&v.setY(S,w[C*c+1]),c>=3&&v.setZ(S,w[C*c+2]),c>=4&&v.setW(S,w[C*c+3]),c>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}v.normalized=E}return v})}loadTexture(e){const t=this.json,n=this.options,o=t.textures[e].source,i=t.images[o];let a=this.textureLoader;if(i.uri){const c=n.manager.getHandler(i.uri);c!==null&&(a=c)}return this.loadTextureImage(e,o,a)}loadTextureImage(e,t,n){const r=this,o=this.json,i=o.textures[e],a=o.images[t],c=(a.uri||a.bufferView)+":"+i.sampler;if(this.textureCache[c])return this.textureCache[c];const d=this.loadImageSource(t,n).then(function(u){u.flipY=!1,u.name=i.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);const f=(o.samplers||{})[i.sampler]||{};return u.magFilter=Ze[f.magFilter]||h.LinearFilter,u.minFilter=Ze[f.minFilter]||h.LinearMipmapLinearFilter,u.wrapS=et[f.wrapS]||h.RepeatWrapping,u.wrapT=et[f.wrapT]||h.RepeatWrapping,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==h.NearestFilter&&u.minFilter!==h.LinearFilter,r.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[c]=d,d}loadImageSource(e,t){const n=this,r=this.json,o=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(l=>l.clone());const i=r.images[e],a=self.URL||self.webkitURL;let c=i.uri||"",d=!1;if(i.bufferView!==void 0)c=n.getDependency("bufferView",i.bufferView).then(function(l){d=!0;const f=new Blob([l],{type:i.mimeType});return c=a.createObjectURL(f),c});else if(i.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(c).then(function(l){return new Promise(function(f,p){let E=f;t.isImageBitmapLoader===!0&&(E=function(R){const v=new h.Texture(R);v.needsUpdate=!0,f(v)}),t.load(h.LoaderUtils.resolveURL(l,o.path),E,void 0,p)})}).then(function(l){return d===!0&&a.revokeObjectURL(c),N(l,i),l.userData.mimeType=i.mimeType||Xn(i.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),l});return this.sourceCache[e]=u,u}assignTexture(e,t,n,r){const o=this;return this.getDependency("texture",n.index).then(function(i){if(!i)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(i=i.clone(),i.channel=n.texCoord),o.extensions[M.KHR_TEXTURE_TRANSFORM]){const a=n.extensions!==void 0?n.extensions[M.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const c=o.associations.get(i);i=o.extensions[M.KHR_TEXTURE_TRANSFORM].extendTexture(i,a),o.associations.set(i,c)}}return r!==void 0&&(i.colorSpace=r),e[t]=i,i})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const r=t.attributes.tangent===void 0,o=t.attributes.color!==void 0,i=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+n.uuid;let c=this.cache.get(a);c||(c=new h.PointsMaterial,h.Material.prototype.copy.call(c,n),c.color.copy(n.color),c.map=n.map,c.sizeAttenuation=!1,this.cache.add(a,c)),n=c}else if(e.isLine){const a="LineBasicMaterial:"+n.uuid;let c=this.cache.get(a);c||(c=new h.LineBasicMaterial,h.Material.prototype.copy.call(c,n),c.color.copy(n.color),c.map=n.map,this.cache.add(a,c)),n=c}if(r||o||i){let a="ClonedMaterial:"+n.uuid+":";r&&(a+="derivative-tangents:"),o&&(a+="vertex-colors:"),i&&(a+="flat-shading:");let c=this.cache.get(a);c||(c=n.clone(),o&&(c.vertexColors=!0),i&&(c.flatShading=!0),r&&(c.normalScale&&(c.normalScale.y*=-1),c.clearcoatNormalScale&&(c.clearcoatNormalScale.y*=-1)),this.cache.add(a,c),this.associations.set(c,this.associations.get(n))),n=c}e.material=n}getMaterialType(){return h.MeshStandardMaterial}loadMaterial(e){const t=this,n=this.json,r=this.extensions,o=n.materials[e];let i;const a={},c=o.extensions||{},d=[];if(c[M.KHR_MATERIALS_UNLIT]){const l=r[M.KHR_MATERIALS_UNLIT];i=l.getMaterialType(),d.push(l.extendParams(a,o,t))}else{const l=o.pbrMetallicRoughness||{};if(a.color=new h.Color(1,1,1),a.opacity=1,Array.isArray(l.baseColorFactor)){const f=l.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],h.LinearSRGBColorSpace),a.opacity=f[3]}l.baseColorTexture!==void 0&&d.push(t.assignTexture(a,"map",l.baseColorTexture,h.SRGBColorSpace)),a.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,a.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(a,"metalnessMap",l.metallicRoughnessTexture)),d.push(t.assignTexture(a,"roughnessMap",l.metallicRoughnessTexture))),i=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,a)})))}o.doubleSided===!0&&(a.side=h.DoubleSide);const u=o.alphaMode||Ce.OPAQUE;if(u===Ce.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===Ce.MASK&&(a.alphaTest=o.alphaCutoff!==void 0?o.alphaCutoff:.5)),o.normalTexture!==void 0&&i!==h.MeshBasicMaterial&&(d.push(t.assignTexture(a,"normalMap",o.normalTexture)),a.normalScale=new h.Vector2(1,1),o.normalTexture.scale!==void 0)){const l=o.normalTexture.scale;a.normalScale.set(l,l)}if(o.occlusionTexture!==void 0&&i!==h.MeshBasicMaterial&&(d.push(t.assignTexture(a,"aoMap",o.occlusionTexture)),o.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=o.occlusionTexture.strength)),o.emissiveFactor!==void 0&&i!==h.MeshBasicMaterial){const l=o.emissiveFactor;a.emissive=new h.Color().setRGB(l[0],l[1],l[2],h.LinearSRGBColorSpace)}return o.emissiveTexture!==void 0&&i!==h.MeshBasicMaterial&&d.push(t.assignTexture(a,"emissiveMap",o.emissiveTexture,h.SRGBColorSpace)),Promise.all(d).then(function(){const l=new i(a);return o.name&&(l.name=o.name),N(l,o),t.associations.set(l,{materials:e}),o.extensions&&V(r,l,o),l})}createUniqueName(e){const t=h.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,r=this.primitiveCache;function o(a){return n[M.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(c){return tt(c,a,t)})}const i=[];for(let a=0,c=e.length;a<c;a++){const d=e[a],u=qn(d),l=r[u];if(l)i.push(l.promise);else{let f;d.extensions&&d.extensions[M.KHR_DRACO_MESH_COMPRESSION]?f=o(d):f=tt(new h.BufferGeometry,d,t),r[u]={primitive:d,promise:f},i.push(f)}}return Promise.all(i)}loadMesh(e){const t=this,n=this.json,r=this.extensions,o=n.meshes[e],i=o.primitives,a=[];for(let c=0,d=i.length;c<d;c++){const u=i[c].material===void 0?zn(this.cache):this.getDependency("material",i[c].material);a.push(u)}return a.push(t.loadGeometries(i)),Promise.all(a).then(function(c){const d=c.slice(0,c.length-1),u=c[c.length-1],l=[];for(let p=0,E=u.length;p<E;p++){const R=u[p],v=i[p];let m;const _=d[p];if(v.mode===O.TRIANGLES||v.mode===O.TRIANGLE_STRIP||v.mode===O.TRIANGLE_FAN||v.mode===void 0)m=o.isSkinnedMesh===!0?new h.SkinnedMesh(R,_):new h.Mesh(R,_),m.isSkinnedMesh===!0&&m.normalizeSkinWeights(),v.mode===O.TRIANGLE_STRIP?m.geometry=Ye(m.geometry,h.TriangleStripDrawMode):v.mode===O.TRIANGLE_FAN&&(m.geometry=Ye(m.geometry,h.TriangleFanDrawMode));else if(v.mode===O.LINES)m=new h.LineSegments(R,_);else if(v.mode===O.LINE_STRIP)m=new h.Line(R,_);else if(v.mode===O.LINE_LOOP)m=new h.LineLoop(R,_);else if(v.mode===O.POINTS)m=new h.Points(R,_);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+v.mode);Object.keys(m.geometry.morphAttributes).length>0&&Vn(m,o),m.name=t.createUniqueName(o.name||"mesh_"+e),N(m,o),v.extensions&&V(r,m,v),t.assignFinalMaterial(m),l.push(m)}for(let p=0,E=l.length;p<E;p++)t.associations.set(l[p],{meshes:e,primitives:p});if(l.length===1)return o.extensions&&V(r,l[0],o),l[0];const f=new h.Group;o.extensions&&V(r,f,o),t.associations.set(f,{meshes:e});for(let p=0,E=l.length;p<E;p++)f.add(l[p]);return f})}loadCamera(e){let t;const n=this.json.cameras[e],r=n[n.type];if(!r){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new h.PerspectiveCamera(h.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type==="orthographic"&&(t=new h.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),N(t,n),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],n=[];for(let r=0,o=t.joints.length;r<o;r++)n.push(this._loadNodeShallow(t.joints[r]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(r){const o=r.pop(),i=r,a=[],c=[];for(let d=0,u=i.length;d<u;d++){const l=i[d];if(l){a.push(l);const f=new h.Matrix4;o!==null&&f.fromArray(o.array,d*16),c.push(f)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[d])}return new h.Skeleton(a,c)})}loadAnimation(e){const t=this.json,n=this,r=t.animations[e],o=r.name?r.name:"animation_"+e,i=[],a=[],c=[],d=[],u=[];for(let l=0,f=r.channels.length;l<f;l++){const p=r.channels[l],E=r.samplers[p.sampler],R=p.target,v=R.node,m=r.parameters!==void 0?r.parameters[E.input]:E.input,_=r.parameters!==void 0?r.parameters[E.output]:E.output;R.node!==void 0&&(i.push(this.getDependency("node",v)),a.push(this.getDependency("accessor",m)),c.push(this.getDependency("accessor",_)),d.push(E),u.push(R))}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(c),Promise.all(d),Promise.all(u)]).then(function(l){const f=l[0],p=l[1],E=l[2],R=l[3],v=l[4],m=[];for(let g=0,T=f.length;g<T;g++){const b=f[g],w=p[g],C=E[g],L=R[g],S=v[g];if(b===void 0)continue;b.updateMatrix&&b.updateMatrix();const A=n._createAnimationTracks(b,w,C,L,S);if(A)for(let k=0;k<A.length;k++)m.push(A[k])}const _=new h.AnimationClip(o,void 0,m);return N(_,r),_})}createNodeMesh(e){const t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency("mesh",r.mesh).then(function(o){const i=n._getNodeRef(n.meshCache,r.mesh,o);return r.weights!==void 0&&i.traverse(function(a){if(a.isMesh)for(let c=0,d=r.weights.length;c<d;c++)a.morphTargetInfluences[c]=r.weights[c]}),i})}loadNode(e){const t=this.json,n=this,r=t.nodes[e],o=n._loadNodeShallow(e),i=[],a=r.children||[];for(let d=0,u=a.length;d<u;d++)i.push(n.getDependency("node",a[d]));const c=r.skin===void 0?Promise.resolve(null):n.getDependency("skin",r.skin);return Promise.all([o,Promise.all(i),c]).then(function(d){const u=d[0],l=d[1],f=d[2];f!==null&&u.traverse(function(p){p.isSkinnedMesh&&p.bind(f,Qn)});for(let p=0,E=l.length;p<E;p++)u.add(l[p]);return u})}_loadNodeShallow(e){const t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const o=t.nodes[e],i=o.name?r.createUniqueName(o.name):"",a=[],c=r._invokeOne(function(d){return d.createNodeMesh&&d.createNodeMesh(e)});return c&&a.push(c),o.camera!==void 0&&a.push(r.getDependency("camera",o.camera).then(function(d){return r._getNodeRef(r.cameraCache,o.camera,d)})),r._invokeAll(function(d){return d.createNodeAttachment&&d.createNodeAttachment(e)}).forEach(function(d){a.push(d)}),this.nodeCache[e]=Promise.all(a).then(function(d){let u;if(o.isBone===!0?u=new h.Bone:d.length>1?u=new h.Group:d.length===1?u=d[0]:u=new h.Object3D,u!==d[0])for(let l=0,f=d.length;l<f;l++)u.add(d[l]);if(o.name&&(u.userData.name=o.name,u.name=i),N(u,o),o.extensions&&V(n,u,o),o.matrix!==void 0){const l=new h.Matrix4;l.fromArray(o.matrix),u.applyMatrix4(l)}else o.translation!==void 0&&u.position.fromArray(o.translation),o.rotation!==void 0&&u.quaternion.fromArray(o.rotation),o.scale!==void 0&&u.scale.fromArray(o.scale);if(!r.associations.has(u))r.associations.set(u,{});else if(o.mesh!==void 0&&r.meshCache.refs[o.mesh]>1){const l=r.associations.get(u);r.associations.set(u,{...l})}return r.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],r=this,o=new h.Group;n.name&&(o.name=r.createUniqueName(n.name)),N(o,n),n.extensions&&V(t,o,n);const i=n.nodes||[],a=[];for(let c=0,d=i.length;c<d;c++)a.push(r.getDependency("node",i[c]));return Promise.all(a).then(function(c){for(let u=0,l=c.length;u<l;u++)o.add(c[u]);const d=u=>{const l=new Map;for(const[f,p]of r.associations)(f instanceof h.Material||f instanceof h.Texture)&&l.set(f,p);return u.traverse(f=>{const p=r.associations.get(f);p!=null&&l.set(f,p)}),l};return r.associations=d(o),o})}_createAnimationTracks(e,t,n,r,o){const i=[],a=e.name?e.name:e.uuid,c=[];U[o.path]===U.weights?e.traverse(function(f){f.morphTargetInfluences&&c.push(f.name?f.name:f.uuid)}):c.push(a);let d;switch(U[o.path]){case U.weights:d=h.NumberKeyframeTrack;break;case U.rotation:d=h.QuaternionKeyframeTrack;break;case U.translation:case U.scale:d=h.VectorKeyframeTrack;break;default:switch(n.itemSize){case 1:d=h.NumberKeyframeTrack;break;case 2:case 3:default:d=h.VectorKeyframeTrack;break}break}const u=r.interpolation!==void 0?Kn[r.interpolation]:h.InterpolateLinear,l=this._getArrayFromAccessor(n);for(let f=0,p=c.length;f<p;f++){const E=new d(c[f]+"."+U[o.path],t.array,l,u);r.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(E),i.push(E)}return i}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const n=ke(t.constructor),r=new Float32Array(t.length);for(let o=0,i=t.length;o<i;o++)r[o]=t[o]*n;t=r}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){const r=this instanceof h.QuaternionKeyframeTrack?Wn:dt;return new r(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Jn(s,e,t){const n=e.attributes,r=new h.Box3;if(n.POSITION!==void 0){const a=t.json.accessors[n.POSITION],c=a.min,d=a.max;if(c!==void 0&&d!==void 0){if(r.set(new h.Vector3(c[0],c[1],c[2]),new h.Vector3(d[0],d[1],d[2])),a.normalized){const u=ke(Q[a.componentType]);r.min.multiplyScalar(u),r.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const o=e.targets;if(o!==void 0){const a=new h.Vector3,c=new h.Vector3;for(let d=0,u=o.length;d<u;d++){const l=o[d];if(l.POSITION!==void 0){const f=t.json.accessors[l.POSITION],p=f.min,E=f.max;if(p!==void 0&&E!==void 0){if(c.setX(Math.max(Math.abs(p[0]),Math.abs(E[0]))),c.setY(Math.max(Math.abs(p[1]),Math.abs(E[1]))),c.setZ(Math.max(Math.abs(p[2]),Math.abs(E[2]))),f.normalized){const R=ke(Q[f.componentType]);c.multiplyScalar(R)}a.max(c)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}r.expandByVector(a)}s.boundingBox=r;const i=new h.Sphere;r.getCenter(i.center),i.radius=r.min.distanceTo(r.max)/2,s.boundingSphere=i}function tt(s,e,t){const n=e.attributes,r=[];function o(i,a){return t.getDependency("accessor",i).then(function(c){s.setAttribute(a,c)})}for(const i in n){const a=Ae[i]||i.toLowerCase();a in s.attributes||r.push(o(n[i],a))}if(e.indices!==void 0&&!s.index){const i=t.getDependency("accessor",e.indices).then(function(a){s.setIndex(a)});r.push(i)}return h.ColorManagement.workingColorSpace!==h.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${h.ColorManagement.workingColorSpace}" not supported.`),N(s,e),Jn(s,e,t),Promise.all(r).then(function(){return e.targets!==void 0?$n(s,e.targets,t):s})}var Zn=Object.defineProperty,er=Object.getOwnPropertyDescriptor,tr=(s,e,t,n)=>{for(var r=n>1?void 0:n?er(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&Zn(e,t,r),r};let le=class{constructor(){x(this,"loadingManager",new h.LoadingManager);x(this,"loaders",{});x(this,"sources",[]);x(this,"loadedResources",{});x(this,"toLoadCount",0);x(this,"loadedCount",0)}get videoLoader(){return{load:(s,e)=>{const t=document.createElement("video");t.muted=!0,t.loop=!0,t.crossOrigin="anonymous",t.controls=!1,t.playsInline=!0,t.src=s,t.autoplay=!0;const n=async()=>{e(t),t.removeEventListener("canplaythrough",n)};t.addEventListener("canplaythrough",n)}}}_initLoaders(){this.loaders.dracoLoader=new ut(this.loadingManager),this.loaders.audioLoader=new h.AudioLoader(this.loadingManager),this.loaders.fontLoader=new y.FontLoader(this.loadingManager),this.loaders.gltfLoader=new yn(this.loadingManager),this.loaders.imageLoader=new h.ImageBitmapLoader(this.loadingManager),this.loaders.videoLoader=this.videoLoader}_initSources(s){this.sources=s,this.toLoadCount=this.sources.length,this.loadedCount=0}init(s=[]){this._initLoaders(),this._initSources(s)}setDracoDecoder(s){var e;this.loaders.dracoLoader&&(this.loaders.dracoLoader.setDecoderPath(s??"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),(e=this.loaders.gltfLoader)==null||e.setDRACOLoader(this.loaders.dracoLoader))}handleLoad({source:s,resource:e,toLoadCount:t,loadedCount:n}){e&&(this.loadedResources[s.name]=e,this.loadedCount=n,this.toLoadCount=t)}launchLoad(s){var t,n,r,o,i;const e=this.sources[0];if(e){s==null||s(e);for(const a of this.sources){if(this.loadedResources[a.name]||typeof a.path!="string")return;a.type==="gltf"&&((t=this.loaders.gltfLoader)==null||t.load(a.path,c=>s==null?void 0:s(a,c))),a.type==="audio"&&((n=this.loaders.audioLoader)==null||n.load(a.path,c=>s==null?void 0:s(a,c))),a.type==="image"&&((r=this.loaders.imageLoader)==null||r.load(a.path,c=>s==null?void 0:s(a,c))),a.type==="video"&&((o=this.loaders.videoLoader)==null||o.load(a.path,c=>s==null?void 0:s(a,c))),a.type==="font"&&((i=this.loaders.fontLoader)==null||i.load(a.path,c=>s==null?void 0:s(a,c)))}}}};le=tr([y.scoped(y.Lifecycle.ContainerScoped)],le);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,sr=(s,e,t,n)=>{for(var r=n>1?void 0:n?rr(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&nr(e,t,r),r},ir=(s,e)=>(t,n)=>e(t,n,s);let de=class{constructor(s){x(this,"load$$",new y.Subject);x(this,"load$",this.load$$.pipe(y.map(s=>({...s,loadedCount:s.resource?this._service.loadedCount+1:this._service.loadedCount,toLoadCount:this._service.toLoadCount})),y.share()));x(this,"serializedLoad$",this.load$.pipe(y.map(s=>{var t,n,r;let e=s.resource;if((t=s==null?void 0:s.resource)!=null&&t.parser){const o=s.resource,i=o.scenes.map(a=>y.g(a));e={animations:(s==null?void 0:s.resource).animations.map(a=>a.toJSON()),cameras:o.cameras.map(a=>y.g(a)),parser:{json:o.parser.json},scene:i==null?void 0:i[0],scenes:i,userData:o.userData}}return((n=s==null?void 0:s.source)==null?void 0:n.type)==="audio"&&s.resource instanceof AudioBuffer&&(e={arrayBuffer:s.resource.getChannelData(0),length:s.resource.length,sampleRate:s.resource.sampleRate,duration:s.resource.duration}),((r=s==null?void 0:s.source)==null?void 0:r.type)==="video"&&s.resource instanceof HTMLVideoElement&&(e={...y.R(s.resource,["autoplay","baseURI","controls","crossOrigin","currentTime","defaultMuted","disablePictureInPicture","draggable","duration","ended","height","hidden","loop","muted","nodeName","nodeType","paused","playbackRate","playsInline","poster","preload","readyState","seeking","spellcheck","src","tabIndex","translate","videoHeight","videoWidth","volume","width"]),buffered:s.resource.buffered.length,error:s.resource.error?y.E(s.resource.error,[]):{},played:s.resource.played.length,seekable:s.resource.seekable.length,textTracks:s.resource.textTracks.length}),{...s,resource:e}}),y.share()));x(this,"loadCompleted$",this.load$.pipe(y.filter(s=>s.toLoadCount===s.loadedCount),y.map(()=>y.R(this._service,["loadedCount","loadedResources","toLoadCount"])),y.share()));this._service=s}};de=sr([y.scoped(y.Lifecycle.ContainerScoped),ir(0,y.inject(le))],de);var or=Object.defineProperty,ar=Object.getOwnPropertyDescriptor,cr=(s,e,t,n)=>{for(var r=n>1?void 0:n?ar(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&or(e,t,r),r},Se=(s,e)=>(t,n)=>e(t,n,s);let Pe=class{constructor(s,e,t){x(this,"_subscriptions",[]);this._controller=s,this._service=e,this._props=t,this._subscriptions.push(this._controller.load$.subscribe(this._service.handleLoad.bind(this._service)))}init(s){this._service.init(s.sources||[]),this._service.setDracoDecoder(s.dracoDecoderPath),[void 0,!0].includes(this._props.loadResourcesOnInit)&&this.load()}load(){this._service.launchLoad((s,e)=>this._controller.load$$.next({source:s,resource:e}))}getLoadedResources(){return this._service.loadedResources}getLoaders(){return this._service.loaders}getSources(){return this._service.sources}getLoadedCount(){return this._service.loadedCount}getToLoadCount(){return this._service.toLoadCount}getLoad$(){return this._controller.load$}getLoadCompleted$(){return this._controller.loadCompleted$}setDracoDecoder(s){this._service.setDracoDecoder(s)}dispose(){this._subscriptions.forEach(s=>s.unsubscribe()),Object.keys(this._service.loaders).forEach(s=>{const e=this._service.loaders[s];e instanceof ut&&e.dispose(),this._service.loaders[s]=void 0}),this._controller.load$$.complete()}};Pe=cr([y.scoped(y.Lifecycle.ContainerScoped),Se(0,y.inject(de)),Se(1,y.inject(le)),Se(2,y.inject(se))],Pe);var ur=Object.defineProperty,lr=Object.getOwnPropertyDescriptor,dr=(s,e,t,n)=>{for(var r=n>1?void 0:n?lr(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&ur(e,t,r),r},X=(s,e)=>(t,n)=>e(t,n,s);exports.RegisterModule=class extends y.RegisterProxyEventHandlersBlueprint{constructor(t,n,r,o,i,a){super();x(this,"_subscriptions",[]);x(this,"_initialized",!1);this._service=t,this._controller=n,this._loaderController=r,this.container=o,this.props=i,this.loader=a,this.props.initOnConstruct&&this.init()}get currentWorker(){return this.props.mainThread?self:this._service.worker}async _initCanvas(){try{if(this.props.canvas instanceof HTMLCanvasElement&&(this._service.canvas=this.props.canvas),typeof this.props.canvas=="string"){const t=document.querySelector(this.props.canvas);t instanceof HTMLCanvasElement&&(this._service.canvas=t)}this._service.canvas||(this._service.canvas=document.createElement("canvas"),this._service.canvas.dataset.reactive="true",document.body.appendChild(this._service.canvas))}catch(t){console.error(`🛑 Unable to initialize the canvas:
|
|
4
|
-
${t instanceof Error?t.message:"Something went wrong"}`)}}async _initServiceWorker(){this._service.init({worker:this._service.worker,thread:this._service.thread})}async _initEvents(){if(!this._service.canvas)throw new Error("Canvas element is not initialized.");this._controller.init(),setTimeout(()=>{const t=new UIEvent("resize");t.width=window.innerWidth,t.height=window.innerHeight,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,this._controller.resize$$.next(this._service.uiEventHandler(t))},0)}async _initOnMainThread(){await import(`${this.props.location}`),self.postMessage({mainThread:!0,...
|
|
1
|
+
"use strict";var mt=Object.defineProperty;var gt=(s,e,t)=>e in s?mt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var L=(s,e,t)=>gt(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./FontLoader-D3WA1QGd.js"),h=require("three");class ie{constructor(){L(this,"location");L(this,"initOnConstruct");L(this,"mainThread");L(this,"canvas");L(this,"fullScreen");L(this,"defaultCamera");L(this,"startTimer");L(this,"loaderDataSources",[]);L(this,"loaderDracoDecoderPath");L(this,"loadResourcesOnInit");L(this,"enableDebug");L(this,"enableControls");L(this,"axesSizes");L(this,"gridSizes");L(this,"withMiniCamera");L(this,"onReady")}}class _t{constructor(){L(this,"canvas");L(this,"onReady")}}var z={},_e={},F={},$={},De;function bt(){if(De)return $;De=1,Object.defineProperty($,"__esModule",{value:!0}),$.getBundleURL=$.getBaseURL=void 0;let s;function e(){return s||(s=t()),s}$.getBundleURL=e;function t(){try{throw new Error}catch(r){const i=(""+r.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(i)return n(i[0])}return"/"}function n(r){return(""+r).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}return $.getBaseURL=n,$}var Fe;function st(){if(Fe)return F;Fe=1,Object.defineProperty(F,"__esModule",{value:!0}),F.isWorkerRuntime=F.getWorkerImplementation=F.defaultPoolSize=void 0;const s=bt();F.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const e=c=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(c);function t(c){const a=new Blob([c],{type:"application/javascript"});return URL.createObjectURL(a)}function n(){if(typeof Worker>"u")return class{constructor(){throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.")}};class c extends Worker{constructor(u,l){var f,p;typeof u=="string"&&l&&l._baseURL?u=new URL(u,l._baseURL):typeof u=="string"&&!e(u)&&s.getBundleURL().match(/^file:\/\//i)&&(u=new URL(u,s.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((f=l==null?void 0:l.CORSWorkaround)!==null&&f!==void 0)||f)&&(u=t(`importScripts(${JSON.stringify(u)});`))),typeof u=="string"&&e(u)&&(!((p=l==null?void 0:l.CORSWorkaround)!==null&&p!==void 0)||p)&&(u=t(`importScripts(${JSON.stringify(u)});`)),super(u,l)}}class a extends c{constructor(u,l){const f=window.URL.createObjectURL(u);super(f,l)}static fromText(u,l){const f=new window.Blob([u],{type:"text/javascript"});return new a(f,l)}}return{blob:a,default:c}}let r;function i(){return r||(r=n()),r}F.getWorkerImplementation=i;function o(){const c=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!c)}return F.isWorkerRuntime=o,F}var V={},ae={exports:{}},be,je;function yt(){if(je)return be;je=1;var s=1e3,e=s*60,t=e*60,n=t*24,r=n*7,i=n*365.25;be=function(u,l){l=l||{};var f=typeof u;if(f==="string"&&u.length>0)return o(u);if(f==="number"&&isFinite(u))return l.long?a(u):c(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function o(u){if(u=String(u),!(u.length>100)){var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(l){var f=parseFloat(l[1]),p=(l[2]||"ms").toLowerCase();switch(p){case"years":case"year":case"yrs":case"yr":case"y":return f*i;case"weeks":case"week":case"w":return f*r;case"days":case"day":case"d":return f*n;case"hours":case"hour":case"hrs":case"hr":case"h":return f*t;case"minutes":case"minute":case"mins":case"min":case"m":return f*e;case"seconds":case"second":case"secs":case"sec":case"s":return f*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return f;default:return}}}}function c(u){var l=Math.abs(u);return l>=n?Math.round(u/n)+"d":l>=t?Math.round(u/t)+"h":l>=e?Math.round(u/e)+"m":l>=s?Math.round(u/s)+"s":u+"ms"}function a(u){var l=Math.abs(u);return l>=n?d(u,l,n,"day"):l>=t?d(u,l,t,"hour"):l>=e?d(u,l,e,"minute"):l>=s?d(u,l,s,"second"):u+" ms"}function d(u,l,f,p){var E=l>=f*1.5;return Math.round(u/f)+" "+p+(E?"s":"")}return be}var ye,He;function Tt(){if(He)return ye;He=1;function s(e){n.debug=n,n.default=n,n.coerce=d,n.disable=o,n.enable=i,n.enabled=c,n.humanize=yt(),n.destroy=u,Object.keys(e).forEach(l=>{n[l]=e[l]}),n.names=[],n.skips=[],n.formatters={};function t(l){let f=0;for(let p=0;p<l.length;p++)f=(f<<5)-f+l.charCodeAt(p),f|=0;return n.colors[Math.abs(f)%n.colors.length]}n.selectColor=t;function n(l){let f,p=null,E,C;function v(...m){if(!v.enabled)return;const _=v,g=Number(new Date),T=g-(f||g);_.diff=T,_.prev=f,_.curr=g,f=g,m[0]=n.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let y=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(R,S)=>{if(R==="%%")return"%";y++;const M=n.formatters[S];if(typeof M=="function"){const A=m[y];R=M.call(_,A),m.splice(y,1),y--}return R}),n.formatArgs.call(_,m),(_.log||n.log).apply(_,m)}return v.namespace=l,v.useColors=n.useColors(),v.color=n.selectColor(l),v.extend=r,v.destroy=n.destroy,Object.defineProperty(v,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(E!==n.namespaces&&(E=n.namespaces,C=n.enabled(l)),C),set:m=>{p=m}}),typeof n.init=="function"&&n.init(v),v}function r(l,f){const p=n(this.namespace+(typeof f>"u"?":":f)+l);return p.log=this.log,p}function i(l){n.save(l),n.namespaces=l,n.names=[],n.skips=[];let f;const p=(typeof l=="string"?l:"").split(/[\s,]+/),E=p.length;for(f=0;f<E;f++)p[f]&&(l=p[f].replace(/\*/g,".*?"),l[0]==="-"?n.skips.push(new RegExp("^"+l.slice(1)+"$")):n.names.push(new RegExp("^"+l+"$")))}function o(){const l=[...n.names.map(a),...n.skips.map(a).map(f=>"-"+f)].join(",");return n.enable(""),l}function c(l){if(l[l.length-1]==="*")return!0;let f,p;for(f=0,p=n.skips.length;f<p;f++)if(n.skips[f].test(l))return!1;for(f=0,p=n.names.length;f<p;f++)if(n.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function d(l){return l instanceof Error?l.stack||l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}return ye=s,ye}var Be;function Ie(){return Be||(Be=1,function(s,e){e.formatArgs=n,e.save=r,e.load=i,e.useColors=t,e.storage=o(),e.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function n(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+s.exports.humanize(this.diff),!this.useColors)return;const d="color: "+this.color;a.splice(1,0,d,"color: inherit");let u=0,l=0;a[0].replace(/%[a-zA-Z%]/g,f=>{f!=="%%"&&(u++,f==="%c"&&(l=u))}),a.splice(l,0,d)}e.log=console.debug||console.log||(()=>{});function r(a){try{a?e.storage.setItem("debug",a):e.storage.removeItem("debug")}catch{}}function i(){let a;try{a=e.storage.getItem("debug")}catch{}return!a&&typeof process<"u"&&"env"in process&&(a=process.env.DEBUG),a}function o(){try{return localStorage}catch{}}s.exports=Tt()(e);const{formatters:c}=s.exports;c.j=function(a){try{return JSON.stringify(a)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}}(ae,ae.exports)),ae.exports}var wt=function(s,e,t,n){function r(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(u){try{d(n.next(u))}catch(l){o(l)}}function a(u){try{d(n.throw(u))}catch(l){o(l)}}function d(u){u.done?i(u.value):r(u.value).then(c,a)}d((n=n.apply(s,e||[])).next())})};class he{constructor(e){this._baseObserver=e,this._pendingPromises=new Set}complete(){Promise.all(this._pendingPromises).then(()=>this._baseObserver.complete()).catch(e=>this._baseObserver.error(e))}error(e){this._baseObserver.error(e)}schedule(e){const t=Promise.all(this._pendingPromises),n=[],r=o=>n.push(o),i=Promise.resolve().then(()=>wt(this,void 0,void 0,function*(){yield t,yield e(r),this._pendingPromises.delete(i);for(const o of n)this._baseObserver.next(o)})).catch(o=>{this._pendingPromises.delete(i),this._baseObserver.error(o)});this._pendingPromises.add(i)}}const it=()=>typeof Symbol=="function",oe=s=>it()&&!!Symbol[s],Ne=s=>oe(s)?Symbol[s]:"@@"+s;oe("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const vt=Ne("iterator"),xe=Ne("observable"),ot=Ne("species");function ue(s,e){const t=s[e];if(t!=null){if(typeof t!="function")throw new TypeError(t+" is not a function");return t}}function Z(s){let e=s.constructor;return e!==void 0&&(e=e[ot],e===null&&(e=void 0)),e!==void 0?e:O}function Et(s){return s instanceof O}function J(s){J.log?J.log(s):setTimeout(()=>{throw s},0)}function ce(s){Promise.resolve().then(()=>{try{s()}catch(e){J(e)}})}function at(s){const e=s._cleanup;if(e!==void 0&&(s._cleanup=void 0,!!e))try{if(typeof e=="function")e();else{const t=ue(e,"unsubscribe");t&&t.call(e)}}catch(t){J(t)}}function Le(s){s._observer=void 0,s._queue=void 0,s._state="closed"}function Rt(s){const e=s._queue;if(e){s._queue=void 0,s._state="ready";for(const t of e)if(ct(s,t.type,t.value),s._state==="closed")break}}function ct(s,e,t){s._state="running";const n=s._observer;try{const r=n?ue(n,e):void 0;switch(e){case"next":r&&r.call(n,t);break;case"error":if(Le(s),r)r.call(n,t);else throw t;break;case"complete":Le(s),r&&r.call(n);break}}catch(r){J(r)}s._state==="closed"?at(s):s._state==="running"&&(s._state="ready")}function Te(s,e,t){if(s._state!=="closed"){if(s._state==="buffering"){s._queue=s._queue||[],s._queue.push({type:e,value:t});return}if(s._state!=="ready"){s._state="buffering",s._queue=[{type:e,value:t}],ce(()=>Rt(s));return}ct(s,e,t)}}class Ct{constructor(e,t){this._cleanup=void 0,this._observer=e,this._queue=void 0,this._state="initializing";const n=new St(this);try{this._cleanup=t.call(void 0,n)}catch(r){n.error(r)}this._state==="initializing"&&(this._state="ready")}get closed(){return this._state==="closed"}unsubscribe(){this._state!=="closed"&&(Le(this),at(this))}}class St{constructor(e){this._subscription=e}get closed(){return this._subscription._state==="closed"}next(e){Te(this._subscription,"next",e)}error(e){Te(this._subscription,"error",e)}complete(){Te(this._subscription,"complete")}}class O{constructor(e){if(!(this instanceof O))throw new TypeError("Observable cannot be called as a function");if(typeof e!="function")throw new TypeError("Observable initializer must be a function");this._subscriber=e}subscribe(e,t,n){return(typeof e!="object"||e===null)&&(e={next:e,error:t,complete:n}),new Ct(e,this._subscriber)}pipe(e,...t){let n=this;for(const r of[e,...t])n=r(n);return n}tap(e,t,n){const r=typeof e!="object"||e===null?{next:e,error:t,complete:n}:e;return new O(i=>this.subscribe({next(o){r.next&&r.next(o),i.next(o)},error(o){r.error&&r.error(o),i.error(o)},complete(){r.complete&&r.complete(),i.complete()},start(o){r.start&&r.start(o)}}))}forEach(e){return new Promise((t,n)=>{if(typeof e!="function"){n(new TypeError(e+" is not a function"));return}function r(){i.unsubscribe(),t(void 0)}const i=this.subscribe({next(o){try{e(o,r)}catch(c){n(c),i.unsubscribe()}},error(o){n(o)},complete(){t(void 0)}})})}map(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=Z(this);return new t(n=>this.subscribe({next(r){let i=r;try{i=e(r)}catch(o){return n.error(o)}n.next(i)},error(r){n.error(r)},complete(){n.complete()}}))}filter(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=Z(this);return new t(n=>this.subscribe({next(r){try{if(!e(r))return}catch(i){return n.error(i)}n.next(r)},error(r){n.error(r)},complete(){n.complete()}}))}reduce(e,t){if(typeof e!="function")throw new TypeError(e+" is not a function");const n=Z(this),r=arguments.length>1;let i=!1,o=t;return new n(c=>this.subscribe({next(a){const d=!i;if(i=!0,!d||r)try{o=e(o,a)}catch(u){return c.error(u)}else o=a},error(a){c.error(a)},complete(){if(!i&&!r)return c.error(new TypeError("Cannot reduce an empty sequence"));c.next(o),c.complete()}}))}concat(...e){const t=Z(this);return new t(n=>{let r,i=0;function o(c){r=c.subscribe({next(a){n.next(a)},error(a){n.error(a)},complete(){i===e.length?(r=void 0,n.complete()):o(t.from(e[i++]))}})}return o(this),()=>{r&&(r.unsubscribe(),r=void 0)}})}flatMap(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const t=Z(this);return new t(n=>{const r=[],i=this.subscribe({next(c){let a;if(e)try{a=e(c)}catch(u){return n.error(u)}else a=c;const d=t.from(a).subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){const u=r.indexOf(d);u>=0&&r.splice(u,1),o()}});r.push(d)},error(c){n.error(c)},complete(){o()}});function o(){i.closed&&r.length===0&&n.complete()}return()=>{r.forEach(c=>c.unsubscribe()),i.unsubscribe()}})}[xe](){return this}static from(e){const t=typeof this=="function"?this:O;if(e==null)throw new TypeError(e+" is not an object");const n=ue(e,xe);if(n){const r=n.call(e);if(Object(r)!==r)throw new TypeError(r+" is not an object");return Et(r)&&r.constructor===t?r:new t(i=>r.subscribe(i))}if(oe("iterator")){const r=ue(e,vt);if(r)return new t(i=>{ce(()=>{if(!i.closed){for(const o of r.call(e))if(i.next(o),i.closed)return;i.complete()}})})}if(Array.isArray(e))return new t(r=>{ce(()=>{if(!r.closed){for(const i of e)if(r.next(i),r.closed)return;r.complete()}})});throw new TypeError(e+" is not observable")}static of(...e){const t=typeof this=="function"?this:O;return new t(n=>{ce(()=>{if(!n.closed){for(const r of e)if(n.next(r),n.closed)return;n.complete()}})})}static get[ot](){return this}}it()&&Object.defineProperty(O,Symbol("extensions"),{value:{symbol:xe,hostReportError:J},configurable:!0});function X(s){typeof s=="function"?s():s&&typeof s.unsubscribe=="function"&&s.unsubscribe()}var Mt=function(s,e,t,n){function r(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(u){try{d(n.next(u))}catch(l){o(l)}}function a(u){try{d(n.throw(u))}catch(l){o(l)}}function d(u){u.done?i(u.value):r(u.value).then(c,a)}d((n=n.apply(s,e||[])).next())})};function xt(s){return e=>new O(t=>{const n=new he(t),r=e.subscribe({complete(){n.complete()},error(i){n.error(i)},next(i){n.schedule(o=>Mt(this,void 0,void 0,function*(){(yield s(i))&&o(i)}))}});return()=>X(r)})}function Lt(s){return s&&oe("asyncIterator")&&s[Symbol.asyncIterator]}function At(s){return s&&oe("iterator")&&s[Symbol.iterator]}var kt=function(s,e,t,n){function r(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(u){try{d(n.next(u))}catch(l){o(l)}}function a(u){try{d(n.throw(u))}catch(l){o(l)}}function d(u){u.done?i(u.value):r(u.value).then(c,a)}d((n=n.apply(s,e||[])).next())})},Pt=function(s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=s[Symbol.asyncIterator],t;return e?e.call(s):(s=typeof __values=="function"?__values(s):s[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=s[i]&&function(o){return new Promise(function(c,a){o=s[i](o),r(c,a,o.done,o.value)})}}function r(i,o,c,a){Promise.resolve(a).then(function(d){i({value:d,done:c})},o)}};function Ot(s){return e=>new O(t=>{const n=new he(t),r=e.subscribe({complete(){n.complete()},error(i){n.error(i)},next(i){n.schedule(o=>kt(this,void 0,void 0,function*(){var c,a;const d=yield s(i);if(At(d)||Lt(d))try{for(var u=Pt(d),l;l=yield u.next(),!l.done;){const f=l.value;o(f)}}catch(f){c={error:f}}finally{try{l&&!l.done&&(a=u.return)&&(yield a.call(u))}finally{if(c)throw c.error}}else d.map(f=>o(f))}))}});return()=>X(r)})}function It(s){return new O(e=>{let t=0;const n=setInterval(()=>{e.next(t++)},s);return()=>clearInterval(n)})}var Nt=function(s,e,t,n){function r(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(u){try{d(n.next(u))}catch(l){o(l)}}function a(u){try{d(n.throw(u))}catch(l){o(l)}}function d(u){u.done?i(u.value):r(u.value).then(c,a)}d((n=n.apply(s,e||[])).next())})};function Dt(s){return e=>new O(t=>{const n=new he(t),r=e.subscribe({complete(){n.complete()},error(i){n.error(i)},next(i){n.schedule(o=>Nt(this,void 0,void 0,function*(){const c=yield s(i);o(c)}))}});return()=>X(r)})}function Ft(...s){return s.length===0?O.from([]):new O(e=>{let t=0;const n=s.map(i=>i.subscribe({error(o){e.error(o),r()},next(o){e.next(o)},complete(){++t===s.length&&(e.complete(),r())}})),r=()=>{n.forEach(i=>X(i))};return r})}class ut extends O{constructor(){super(e=>(this._observers.add(e),()=>this._observers.delete(e))),this._observers=new Set}next(e){for(const t of this._observers)t.next(e)}error(e){for(const t of this._observers)t.error(e)}complete(){for(const e of this._observers)e.complete()}}function jt(s){const e=new ut;let t,n=0;return new O(r=>{t||(t=s.subscribe(e));const i=e.subscribe(r);return n++,()=>{n--,i.unsubscribe(),n===0&&(X(t),t=void 0)}})}var Ht=function(s,e,t,n){function r(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(u){try{d(n.next(u))}catch(l){o(l)}}function a(u){try{d(n.throw(u))}catch(l){o(l)}}function d(u){u.done?i(u.value):r(u.value).then(c,a)}d((n=n.apply(s,e||[])).next())})};function Bt(s,e){return t=>new O(n=>{let r,i=0;const o=new he(n),c=t.subscribe({complete(){o.complete()},error(a){o.error(a)},next(a){o.schedule(d=>Ht(this,void 0,void 0,function*(){r=yield s(i===0?typeof e>"u"?a:e:r,a,i++),d(r)}))}});return()=>X(c)})}const Ut=Object.freeze(Object.defineProperty({__proto__:null,Observable:O,Subject:ut,filter:xt,flatMap:Ot,interval:It,map:Dt,merge:Ft,multicast:jt,scan:Bt,unsubscribe:X},Symbol.toStringTag,{value:"Module"})),pe=b.getAugmentedNamespace(Ut);var ee={},Ue;function Gt(){if(Ue)return ee;Ue=1,Object.defineProperty(ee,"__esModule",{value:!0}),ee.allSettled=void 0;function s(e){return Promise.all(e.map(t=>{const n=o=>({status:"fulfilled",value:o}),r=o=>({status:"rejected",reason:o}),i=Promise.resolve(t);try{return i.then(n,r)}catch(o){return Promise.reject(o)}}))}return ee.allSettled=s,ee}var we={},Ge;function Wt(){return Ge||(Ge=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.PoolEventType=void 0,function(e){e.initialized="initialized",e.taskCanceled="taskCanceled",e.taskCompleted="taskCompleted",e.taskFailed="taskFailed",e.taskQueued="taskQueued",e.taskQueueDrained="taskQueueDrained",e.taskStart="taskStart",e.terminated="terminated"}(s.PoolEventType||(s.PoolEventType={}))}(we)),we}var te={},We;function lt(){if(We)return te;We=1,Object.defineProperty(te,"__esModule",{value:!0}),te.Thread=void 0;const s=b.requireSymbols();function e(t){throw Error(t)}return te.Thread={errors(t){return t[s.$errors]||e("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(t){return t[s.$events]||e("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(t){return t[s.$terminate]()}},te}var Ke;function Kt(){return Ke||(Ke=1,function(s){var e=V&&V.__awaiter||function(m,_,g,T){function y(w){return w instanceof g?w:new g(function(R){R(w)})}return new(g||(g=Promise))(function(w,R){function S(k){try{A(T.next(k))}catch(N){R(N)}}function M(k){try{A(T.throw(k))}catch(N){R(N)}}function A(k){k.done?w(k.value):y(k.value).then(S,M)}A((T=T.apply(m,_||[])).next())})},t=V&&V.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(s,"__esModule",{value:!0}),s.Pool=s.Thread=s.PoolEventType=void 0;const n=t(Ie()),r=pe,i=Gt(),o=st(),c=Wt();Object.defineProperty(s,"PoolEventType",{enumerable:!0,get:function(){return c.PoolEventType}});const a=lt();Object.defineProperty(s,"Thread",{enumerable:!0,get:function(){return a.Thread}});let d=1;function u(m){const _=[];for(let g=0;g<m;g++)_.push(g);return _}function l(m){return new Promise(_=>setTimeout(_,m))}function f(m,_){return m.reduce((g,T)=>[...g,..._(T)],[])}function p(m){return m.replace(/\W/g," ").trim().replace(/\s+/g,"-")}function E(m,_){return u(_).map(()=>({init:m(),runningTasks:[]}))}class C{constructor(_,g){this.eventSubject=new r.Subject,this.initErrors=[],this.isClosing=!1,this.nextTaskID=1,this.taskQueue=[];const T=typeof g=="number"?{size:g}:g||{},{size:y=o.defaultPoolSize}=T;this.debug=n.default(`threads:pool:${p(T.name||String(d++))}`),this.options=T,this.workers=E(_,y),this.eventObservable=r.multicast(r.Observable.from(this.eventSubject)),Promise.all(this.workers.map(w=>w.init)).then(()=>this.eventSubject.next({type:c.PoolEventType.initialized,size:this.workers.length}),w=>{this.debug("Error while initializing pool worker:",w),this.eventSubject.error(w),this.initErrors.push(w)})}findIdlingWorker(){const{concurrency:_=1}=this.options;return this.workers.find(g=>g.runningTasks.length<_)}runPoolTask(_,g){return e(this,void 0,void 0,function*(){const T=this.workers.indexOf(_)+1;this.debug(`Running task #${g.id} on worker #${T}...`),this.eventSubject.next({type:c.PoolEventType.taskStart,taskID:g.id,workerID:T});try{const y=yield g.run(yield _.init);this.debug(`Task #${g.id} completed successfully`),this.eventSubject.next({type:c.PoolEventType.taskCompleted,returnValue:y,taskID:g.id,workerID:T})}catch(y){this.debug(`Task #${g.id} failed`),this.eventSubject.next({type:c.PoolEventType.taskFailed,taskID:g.id,error:y,workerID:T})}})}run(_,g){return e(this,void 0,void 0,function*(){const T=e(this,void 0,void 0,function*(){const y=()=>{_.runningTasks=_.runningTasks.filter(w=>w!==T)};yield l(0);try{yield this.runPoolTask(_,g)}finally{y(),this.isClosing||this.scheduleWork()}});_.runningTasks.push(T)})}scheduleWork(){this.debug("Attempt de-queueing a task in order to run it...");const _=this.findIdlingWorker();if(!_)return;const g=this.taskQueue.shift();if(!g){this.debug("Task queue is empty"),this.eventSubject.next({type:c.PoolEventType.taskQueueDrained});return}this.run(_,g)}taskCompletion(_){return new Promise((g,T)=>{const y=this.events().subscribe(w=>{w.type===c.PoolEventType.taskCompleted&&w.taskID===_?(y.unsubscribe(),g(w.returnValue)):w.type===c.PoolEventType.taskFailed&&w.taskID===_?(y.unsubscribe(),T(w.error)):w.type===c.PoolEventType.terminated&&(y.unsubscribe(),T(Error("Pool has been terminated before task was run.")))})})}settled(_=!1){return e(this,void 0,void 0,function*(){const g=()=>f(this.workers,w=>w.runningTasks),T=[],y=this.eventObservable.subscribe(w=>{w.type===c.PoolEventType.taskFailed&&T.push(w.error)});return this.initErrors.length>0?Promise.reject(this.initErrors[0]):_&&this.taskQueue.length===0?(yield i.allSettled(g()),T):(yield new Promise((w,R)=>{const S=this.eventObservable.subscribe({next(M){M.type===c.PoolEventType.taskQueueDrained&&(S.unsubscribe(),w(void 0))},error:R})}),yield i.allSettled(g()),y.unsubscribe(),T)})}completed(_=!1){return e(this,void 0,void 0,function*(){const g=this.settled(_),T=new Promise((w,R)=>{const S=this.eventObservable.subscribe({next(M){M.type===c.PoolEventType.taskQueueDrained?(S.unsubscribe(),w(g)):M.type===c.PoolEventType.taskFailed&&(S.unsubscribe(),R(M.error))},error:R})}),y=yield Promise.race([g,T]);if(y.length>0)throw y[0]})}events(){return this.eventObservable}queue(_){const{maxQueuedJobs:g=1/0}=this.options;if(this.isClosing)throw Error("Cannot schedule pool tasks after terminate() has been called.");if(this.initErrors.length>0)throw this.initErrors[0];const T=this.nextTaskID++,y=this.taskCompletion(T);y.catch(R=>{this.debug(`Task #${T} errored:`,R)});const w={id:T,run:_,cancel:()=>{this.taskQueue.indexOf(w)!==-1&&(this.taskQueue=this.taskQueue.filter(R=>R!==w),this.eventSubject.next({type:c.PoolEventType.taskCanceled,taskID:w.id}))},then:y.then.bind(y)};if(this.taskQueue.length>=g)throw Error(`Maximum number of pool tasks queued. Refusing to queue another one.
|
|
2
|
+
This usually happens for one of two reasons: We are either at peak workload right now or some tasks just won't finish, thus blocking the pool.`);return this.debug(`Queueing task #${w.id}...`),this.taskQueue.push(w),this.eventSubject.next({type:c.PoolEventType.taskQueued,taskID:w.id}),this.scheduleWork(),w}terminate(_){return e(this,void 0,void 0,function*(){this.isClosing=!0,_||(yield this.completed(!0)),this.eventSubject.next({type:c.PoolEventType.terminated,remainingQueue:[...this.taskQueue]}),this.eventSubject.complete(),yield Promise.all(this.workers.map(g=>e(this,void 0,void 0,function*(){return a.Thread.terminate(yield g.init)})))})}}C.EventType=c.PoolEventType;function v(m,_){return new C(m,_)}v.EventType=c.PoolEventType,s.Pool=v}(V)),V}var j={},ne={},ze;function zt(){if(ze)return ne;ze=1,Object.defineProperty(ne,"__esModule",{value:!0}),ne.createPromiseWithResolver=void 0;const s=()=>{};function e(){let t=!1,n,r=s;return[new Promise(c=>{t?c(n):r=c}),c=>{t=!0,n=c,r(n)}]}return ne.createPromiseWithResolver=e,ne}var ve={},$e;function $t(){return $e||($e=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.WorkerEventType=void 0,function(e){e.internalError="internalError",e.message="message",e.termination="termination"}(s.WorkerEventType||(s.WorkerEventType={}))}(ve)),ve}var H={},re={},Ve;function Vt(){if(Ve)return re;Ve=1,Object.defineProperty(re,"__esModule",{value:!0}),re.ObservablePromise=void 0;const s=pe,e=()=>{},t=c=>c,n=c=>Promise.resolve().then(c);function r(c){throw c}function i(c){return c&&typeof c.then=="function"}class o extends s.Observable{constructor(a){super(d=>{const u=this,l=Object.assign(Object.assign({},d),{complete(){d.complete(),u.onCompletion()},error(f){d.error(f),u.onError(f)},next(f){d.next(f),u.onNext(f)}});try{return this.initHasRun=!0,a(l)}catch(f){l.error(f)}}),this.initHasRun=!1,this.fulfillmentCallbacks=[],this.rejectionCallbacks=[],this.firstValueSet=!1,this.state="pending"}onNext(a){this.firstValueSet||(this.firstValue=a,this.firstValueSet=!0)}onError(a){this.state="rejected",this.rejection=a;for(const d of this.rejectionCallbacks)n(()=>d(a))}onCompletion(){this.state="fulfilled";for(const a of this.fulfillmentCallbacks)n(()=>a(this.firstValue))}then(a,d){const u=a||t,l=d||r;let f=!1;return new Promise((p,E)=>{const C=m=>{if(!f){f=!0;try{p(l(m))}catch(_){E(_)}}},v=m=>{try{p(u(m))}catch(_){C(_)}};if(this.initHasRun||this.subscribe({error:C}),this.state==="fulfilled")return p(u(this.firstValue));if(this.state==="rejected")return f=!0,p(l(this.rejection));this.fulfillmentCallbacks.push(v),this.rejectionCallbacks.push(C)})}catch(a){return this.then(void 0,a)}finally(a){const d=a||e;return this.then(u=>(d(),u),()=>d())}static from(a){return i(a)?new o(d=>{const u=f=>{d.next(f),d.complete()},l=f=>{d.error(f)};a.then(u,l)}):super.from(a)}}return re.ObservablePromise=o,re}var qe;function qt(){if(qe)return H;qe=1;var s=H&&H.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(H,"__esModule",{value:!0}),H.createProxyModule=H.createProxyFunction=void 0;const e=s(Ie()),t=pe,n=b.requireCommon(),r=Vt(),i=b.requireTransferable(),o=b.requireMessages(),c=e.default("threads:master:messages");let a=1;const d=m=>Array.from(new Set(m)),u=m=>m&&m.type===o.WorkerMessageType.error,l=m=>m&&m.type===o.WorkerMessageType.result,f=m=>m&&m.type===o.WorkerMessageType.running;function p(m,_){return new t.Observable(g=>{let T;const y=w=>{if(c("Message from worker:",w.data),!(!w.data||w.data.uid!==_)){if(f(w.data))T=w.data.resultType;else if(l(w.data))T==="promise"?(typeof w.data.payload<"u"&&g.next(n.deserialize(w.data.payload)),g.complete(),m.removeEventListener("message",y)):(w.data.payload&&g.next(n.deserialize(w.data.payload)),w.data.complete&&(g.complete(),m.removeEventListener("message",y)));else if(u(w.data)){const R=n.deserialize(w.data.error);g.error(R),m.removeEventListener("message",y)}}};return m.addEventListener("message",y),()=>{if(T==="observable"||!T){const w={type:o.MasterMessageType.cancel,uid:_};m.postMessage(w)}m.removeEventListener("message",y)}})}function E(m){if(m.length===0)return{args:[],transferables:[]};const _=[],g=[];for(const T of m)i.isTransferDescriptor(T)?(_.push(n.serialize(T.send)),g.push(...T.transferables)):_.push(n.serialize(T));return{args:_,transferables:g.length===0?g:d(g)}}function C(m,_){return(...g)=>{const T=a++,{args:y,transferables:w}=E(g),R={type:o.MasterMessageType.run,uid:T,method:_,args:y};c("Sending command to run function to worker:",R);try{m.postMessage(R,w)}catch(S){return r.ObservablePromise.from(Promise.reject(S))}return r.ObservablePromise.from(t.multicast(p(m,T)))}}H.createProxyFunction=C;function v(m,_){const g={};for(const T of _)g[T]=C(m,T);return g}return H.createProxyModule=v,H}var Xe;function Xt(){if(Xe)return j;Xe=1;var s=j&&j.__awaiter||function(y,w,R,S){function M(A){return A instanceof R?A:new R(function(k){k(A)})}return new(R||(R=Promise))(function(A,k){function N(K){try{me(S.next(K))}catch(ge){k(ge)}}function W(K){try{me(S.throw(K))}catch(ge){k(ge)}}function me(K){K.done?A(K.value):M(K.value).then(N,W)}me((S=S.apply(y,w||[])).next())})},e=j&&j.__importDefault||function(y){return y&&y.__esModule?y:{default:y}};Object.defineProperty(j,"__esModule",{value:!0}),j.spawn=void 0;const t=e(Ie()),n=pe,r=b.requireCommon(),i=zt(),o=b.requireSymbols(),c=$t(),a=qt(),d=t.default("threads:master:messages"),u=t.default("threads:master:spawn"),l=t.default("threads:master:thread-utils"),f=y=>y&&y.type==="init",p=y=>y&&y.type==="uncaughtError",E=typeof process<"u"&&process.env.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt(process.env.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function C(y,w,R){return s(this,void 0,void 0,function*(){let S;const M=new Promise((k,N)=>{S=setTimeout(()=>N(Error(R)),w)}),A=yield Promise.race([y,M]);return clearTimeout(S),A})}function v(y){return new Promise((w,R)=>{const S=M=>{d("Message from worker before finishing initialization:",M.data),f(M.data)?(y.removeEventListener("message",S),w(M.data)):p(M.data)&&(y.removeEventListener("message",S),R(r.deserialize(M.data.error)))};y.addEventListener("message",S)})}function m(y,w){return new n.Observable(R=>{const S=A=>{const k={type:c.WorkerEventType.message,data:A.data};R.next(k)},M=A=>{l("Unhandled promise rejection event in thread:",A);const k={type:c.WorkerEventType.internalError,error:Error(A.reason)};R.next(k)};y.addEventListener("message",S),y.addEventListener("unhandledrejection",M),w.then(()=>{const A={type:c.WorkerEventType.termination};y.removeEventListener("message",S),y.removeEventListener("unhandledrejection",M),R.next(A),R.complete()})})}function _(y){const[w,R]=i.createPromiseWithResolver();return{terminate:()=>s(this,void 0,void 0,function*(){l("Terminating worker"),yield y.terminate(),R()}),termination:w}}function g(y,w,R,S){const M=R.filter(A=>A.type===c.WorkerEventType.internalError).map(A=>A.error);return Object.assign(y,{[o.$errors]:M,[o.$events]:R,[o.$terminate]:S,[o.$worker]:w})}function T(y,w){return s(this,void 0,void 0,function*(){u("Initializing new thread");const R=w&&w.timeout?w.timeout:E,M=(yield C(v(y),R,`Timeout: Did not receive an init message from worker after ${R}ms. Make sure the worker calls expose().`)).exposed,{termination:A,terminate:k}=_(y),N=m(y,A);if(M.type==="function"){const W=a.createProxyFunction(y);return g(W,y,N,k)}else if(M.type==="module"){const W=a.createProxyModule(y,M.methods);return g(W,y,N,k)}else{const W=M.type;throw Error(`Worker init message states unexpected type of expose(): ${W}`)}})}return j.spawn=T,j}var Qe;function Qt(){return Qe||(Qe=1,function(s){Object.defineProperty(s,"__esModule",{value:!0}),s.Worker=s.BlobWorker=s.isWorkerRuntime=s.Thread=s.spawn=s.Pool=void 0;const e=st();Object.defineProperty(s,"isWorkerRuntime",{enumerable:!0,get:function(){return e.isWorkerRuntime}});var t=Kt();Object.defineProperty(s,"Pool",{enumerable:!0,get:function(){return t.Pool}});var n=Xt();Object.defineProperty(s,"spawn",{enumerable:!0,get:function(){return n.spawn}});var r=lt();Object.defineProperty(s,"Thread",{enumerable:!0,get:function(){return r.Thread}}),s.BlobWorker=e.getWorkerImplementation().blob,s.Worker=e.getWorkerImplementation().default}(_e)),_e}var Ye;function Yt(){return Ye||(Ye=1,function(s){var e=z&&z.__createBinding||(Object.create?function(c,a,d,u){u===void 0&&(u=d),Object.defineProperty(c,u,{enumerable:!0,get:function(){return a[d]}})}:function(c,a,d,u){u===void 0&&(u=d),c[u]=a[d]}),t=z&&z.__exportStar||function(c,a){for(var d in c)d!=="default"&&!Object.prototype.hasOwnProperty.call(a,d)&&e(a,c,d)};Object.defineProperty(s,"__esModule",{value:!0}),s.Transfer=s.DefaultSerializer=s.expose=s.registerSerializer=void 0;var n=b.requireCommon();Object.defineProperty(s,"registerSerializer",{enumerable:!0,get:function(){return n.registerSerializer}}),t(Qt(),s);var r=b.requireWorker();Object.defineProperty(s,"expose",{enumerable:!0,get:function(){return r.expose}});var i=b.requireSerializers();Object.defineProperty(s,"DefaultSerializer",{enumerable:!0,get:function(){return i.DefaultSerializer}});var o=b.requireTransferable();Object.defineProperty(s,"Transfer",{enumerable:!0,get:function(){return o.Transfer}})}(z)),z}var Jt=Yt();const G=b.getDefaultExportFromCjs(Jt);G.registerSerializer;const Zt=G.spawn;G.BlobWorker;G.DefaultSerializer;G.Pool;const en=G.Thread;G.Transfer;const tn=G.Worker;var nn=Object.defineProperty,rn=(s,e,t)=>e in s?nn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,B=(s,e,t)=>rn(s,typeof e!="symbol"?e+"":e,t);const sn=()=>{try{if(window){if(navigator!=null&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;throw new Error("Unable to determine the number of cores")}else return require("os").cpus().length}catch(s){return console.error("🛑 Unable to detect available cores",s),2}},on=()=>sn()-1,an="TERMINATE_THREAD_FROM_WORKER";let cn=-1;class un{constructor(e){B(this,"_handleTerminate"),B(this,"_handleError"),B(this,"_task"),B(this,"id",cn+=1),B(this,"idle",!0),B(this,"worker"),B(this,"thread"),this._handleTerminate=e==null?void 0:e.onTerminate,this._handleError=e==null?void 0:e.onError}_handleMessages(e){var t;e instanceof MessageEvent&&((t=e.data)==null?void 0:t.token)===an&&this.terminate()}async run(e){var t;try{const{payload:n,options:r}=e;return this.idle=!1,this.worker=new tn(n.path,{type:"module",...r==null?void 0:r.worker}),this.thread=await Zt(this.worker,{timeout:1e4,...r==null?void 0:r.spawn}),this._task=e,this.worker.postMessage(n.subject,n.transferSubject),this.worker.addEventListener("message",this._handleMessages.bind(this)),this}catch(n){(t=this._handleError)==null||t.call(this,n);return}}get task(){return this._task}async terminate(){var e,t,n;(e=this.worker)==null||e.removeEventListener("message",this._handleMessages.bind(this)),this.thread&&await en.terminate(this.thread),await((t=this.worker)==null?void 0:t.terminate()),this.worker=void 0,this.thread=void 0,this._task=void 0,this.idle=!0,(n=this._handleTerminate)==null||n.call(this)}}class ln{constructor(e,t,n){B(this,"_workerThreads",[]),B(this,"_tasksQueue",[]),this.maxWorkersCount=e,this.debugMode=t,this.onWorkerThreadRun=n;for(let r=0;r<this.maxWorkersCount;r++)this._workerThreads.push(this._createWorkerThread())}_handleWorkerThreadTerminate(e){this.debugMode&&console.log(`WorkerThread #${e.id} freed`),this.runNext()}_handleWorkerThreadError(e,t){console.error(`Error from worker #${t.id}:`,e),this.runNext()}_createWorkerThread(){const e=new un({onTerminate:()=>this._handleWorkerThreadTerminate(e),onError:t=>this._handleWorkerThreadError(t,e)});return e}get workerThreads(){return this._workerThreads}get tasksQueue(){return this._tasksQueue}get nextAvailableWorkerThread(){return this._workerThreads.find(e=>e.idle)}getAvailableWorkerThreads(e=!1){return this._workerThreads.filter(t=>e?!t.idle:t.idle)}async runNext(){if(!this.nextAvailableWorkerThread||this._tasksQueue.length===0)return;const e=this._tasksQueue.shift();e&&await this.run(e)}async run(e,t=!1){var n;if(t){const o=this._createWorkerThread();return this.debugMode&&console.log(`Running On Untracked Thread #${o==null?void 0:o.id}. Task:`,e),[await o.run(e),!0]}const r=this.nextAvailableWorkerThread;if(!r)return this._tasksQueue.push(e),this.debugMode&&console.log("Queued Thread Task:",e),[void 0,!0];this.debugMode&&console.log(`Running On Thread #${r==null?void 0:r.id}. Task:`,e);const i=await r.run(e);if(i)return(n=this.onWorkerThreadRun)==null||n.call(this,i),[i,!1]}async terminateAll(){this._tasksQueue=[],await Promise.all(this._workerThreads.map(e=>e.terminate()))}}const dn=(s,e)=>new ln(on(),!!e);var fn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,pn=(s,e,t,n)=>{for(var r=n>1?void 0:n?hn(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&fn(e,t,r),r},mn=(s,e)=>(t,n)=>e(t,n,s);let le=class{constructor(s){L(this,"workerPool");L(this,"canvas");L(this,"offscreenCanvas");L(this,"worker");L(this,"thread");this._props=s,this.workerPool=dn(void 0,this._props.enableDebug)}init(s){this.worker=s.worker,this.thread=s.thread}preventDefaultHandler(s){return s.preventDefault(),{type:s.type}}getScreenSizes(){var s,e;return{width:(s=this.canvas)==null?void 0:s.width,height:(e=this.canvas)==null?void 0:e.height,windowWidth:(window==null?void 0:window.innerWidth)??0,windowHeight:(window==null?void 0:window.innerHeight)??0}}uiEventHandler(s){var t;const e=(t=this.canvas)==null?void 0:t.getBoundingClientRect();return{...this.getScreenSizes(),type:s.type,top:e==null?void 0:e.top,left:e==null?void 0:e.left}}mouseEventHandler(s){return{...this.getScreenSizes(),...b.E(s,["ctrlKey","metaKey","shiftKey","button","pointerType","clientX","clientY","pageX","pageY"])}}touchEventHandler(s){const e=[],t={type:s.type,touches:e};for(let n=0;n<s.touches.length;++n){const r=s.touches[n];e.push({pageX:(r==null?void 0:r.pageX)??0,pageY:(r==null?void 0:r.pageY)??0})}return{...this.getScreenSizes(),...t}}wheelEventHandler(s){return s.preventDefault(),{...this.getScreenSizes(),...b.E(s,["deltaX","deltaY"])}}keyEventHandler(s){if(b.KEYBOARD_EVENT_CODES.includes(s.code))return s.preventDefault(),{...this.getScreenSizes(),...b.E(s,["ctrlKey","metaKey","shiftKey","keyCode"])}}};le=pn([b.scoped(b.Lifecycle.ContainerScoped),mn(0,b.inject(ie))],le);var gn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,bn=(s,e,t,n)=>{for(var r=n>1?void 0:n?_n(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&gn(e,t,r),r},yn=(s,e)=>(t,n)=>e(t,n,s);let Ae=class extends b.ProxyEventHandlersBlueprint{constructor(s){super(),this._service=s}init(){let s;try{s=b.instance.resolve("MAIN_THREAD_APP")}catch{s=void 0}for(const e of b.PROXY_EVENT_LISTENERS){const t=e.startsWith("mouse")||e.startsWith("pointer")||e.startsWith("touch")?this._service.mouseEventHandler.bind(this._service):e.startsWith("key")?this._service.keyEventHandler.bind(this._service):e==="resize"?this._service.uiEventHandler.bind(this._service):e==="wheel"?this._service.wheelEventHandler.bind(this._service):this._service.preventDefaultHandler.bind(this._service);this[`${e}$$`]=new b.Subject,b.fromEvent(e==="resize"?window:this._service.canvas,e).pipe(b.map(t.bind(this)),b.filter(n=>!(e==="keydown"&&!n))).subscribe(n=>{this[`${e}$$`].next(n)}),this[`${e}$`]=this[`${e}$$`].asObservable(),this[`${e}$`].subscribe(n=>{var r,i,o;(i=(r=this._service.thread)==null?void 0:r[e])==null||i.call(r,n),(o=s==null?void 0:s[e])==null||o.call(s,n)})}}};Ae=bn([b.scoped(b.Lifecycle.ContainerScoped),yn(0,b.inject(le))],Ae);function Je(s,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),s;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=s.getIndex();if(t===null){const o=[],c=s.getAttribute("position");if(c!==void 0){for(let a=0;a<c.count;a++)o.push(a);s.setIndex(o),t=s.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),s}const n=t.count-2,r=[];if(e===h.TriangleFanDrawMode)for(let o=1;o<=n;o++)r.push(t.getX(0)),r.push(t.getX(o)),r.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(r.push(t.getX(o)),r.push(t.getX(o+1)),r.push(t.getX(o+2))):(r.push(t.getX(o+2)),r.push(t.getX(o+1)),r.push(t.getX(o)));r.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=s.clone();return i.setIndex(r),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),s}const Ee=new WeakMap;class dt extends h.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,r){const i=new h.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,o=>{this.parse(o,t,r)},n,r)}parse(e,t,n=()=>{}){this.decodeDracoFile(e,t,null,null,h.SRGBColorSpace,n).catch(n)}decodeDracoFile(e,t,n,r,i=h.LinearSRGBColorSpace,o=()=>{}){const c={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:r||this.defaultAttributeTypes,useUniqueIDs:!!n,vertexColorSpace:i};return this.decodeGeometry(e,c).then(t).catch(o)}decodeGeometry(e,t){const n=JSON.stringify(t);if(Ee.has(e)){const a=Ee.get(e);if(a.key===n)return a.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const i=this.workerNextTaskID++,o=e.byteLength,c=this._getWorker(i,o).then(a=>(r=a,new Promise((d,u)=>{r._callbacks[i]={resolve:d,reject:u},r.postMessage({type:"decode",id:i,taskConfig:t,buffer:e},[e])}))).then(a=>this._createGeometry(a.geometry));return c.catch(()=>!0).then(()=>{r&&i&&this._releaseTask(r,i)}),Ee.set(e,{key:n,promise:c}),c}_createGeometry(e){const t=new h.BufferGeometry;e.index&&t.setIndex(new h.BufferAttribute(e.index.array,1));for(let n=0;n<e.attributes.length;n++){const{name:r,array:i,itemSize:o,stride:c,vertexColorSpace:a}=e.attributes[n];let d;if(o===c)d=new h.BufferAttribute(i,o);else{const u=new h.InterleavedBuffer(i,c);d=new h.InterleavedBufferAttribute(u,o,0)}r==="color"&&(this._assignVertexColorSpace(d,a),d.normalized=!(i instanceof Float32Array)),t.setAttribute(r,d)}return t}_assignVertexColorSpace(e,t){if(t!==h.SRGBColorSpace)return;const n=new h.Color;for(let r=0,i=e.count;r<i;r++)n.fromBufferAttribute(e,r),h.ColorManagement.colorSpaceToWorking(n,h.SRGBColorSpace),e.setXYZ(r,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new h.FileLoader(this.manager);return n.setPath(this.decoderPath),n.setResponseType(t),n.setWithCredentials(this.withCredentials),new Promise((r,i)=>{n.load(e,r,void 0,i)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(n=>{const r=n[0];e||(this.decoderConfig.wasmBinary=n[1]);const i=Tn.toString(),o=["/* draco decoder */",r,"","/* worker */",i.substring(i.indexOf("{")+1,i.lastIndexOf("}"))].join(`
|
|
3
|
+
`);this.workerSourceURL=URL.createObjectURL(new Blob([o]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const r=new Worker(this.workerSourceURL);r._callbacks={},r._taskCosts={},r._taskLoad=0,r.postMessage({type:"init",decoderConfig:this.decoderConfig}),r.onmessage=function(i){const o=i.data;switch(o.type){case"decode":r._callbacks[o.id].resolve(o);break;case"error":r._callbacks[o.id].reject(o);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+o.type+'"')}},this.workerPool.push(r)}else this.workerPool.sort(function(r,i){return r._taskLoad>i._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this.workerSourceURL!==""&&URL.revokeObjectURL(this.workerSourceURL),this}}function Tn(){let s,e;onmessage=function(o){const c=o.data;switch(c.type){case"init":s=c.decoderConfig,e=new Promise(function(u){s.onModuleLoaded=function(l){u({draco:l})},DracoDecoderModule(s)});break;case"decode":const a=c.buffer,d=c.taskConfig;e.then(u=>{const l=u.draco,f=new l.Decoder;try{const p=t(l,f,new Int8Array(a),d),E=p.attributes.map(C=>C.array.buffer);p.index&&E.push(p.index.array.buffer),self.postMessage({type:"decode",id:c.id,geometry:p},E)}catch(p){console.error(p),self.postMessage({type:"error",id:c.id,error:p.message})}finally{l.destroy(f)}});break}};function t(o,c,a,d){const u=d.attributeIDs,l=d.attributeTypes;let f,p;const E=c.GetEncodedGeometryType(a);if(E===o.TRIANGULAR_MESH)f=new o.Mesh,p=c.DecodeArrayToMesh(a,a.byteLength,f);else if(E===o.POINT_CLOUD)f=new o.PointCloud,p=c.DecodeArrayToPointCloud(a,a.byteLength,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!p.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+p.error_msg());const C={index:null,attributes:[]};for(const v in u){const m=self[l[v]];let _,g;if(d.useUniqueIDs)g=u[v],_=c.GetAttributeByUniqueId(f,g);else{if(g=c.GetAttributeId(f,o[u[v]]),g===-1)continue;_=c.GetAttribute(f,g)}const T=r(o,c,f,v,m,_);v==="color"&&(T.vertexColorSpace=d.vertexColorSpace),C.attributes.push(T)}return E===o.TRIANGULAR_MESH&&(C.index=n(o,c,f)),o.destroy(f),C}function n(o,c,a){const u=a.num_faces()*3,l=u*4,f=o._malloc(l);c.GetTrianglesUInt32Array(a,l,f);const p=new Uint32Array(o.HEAPF32.buffer,f,u).slice();return o._free(f),{array:p,itemSize:1}}function r(o,c,a,d,u,l){const f=a.num_points(),p=l.num_components(),E=i(o,u),C=p*u.BYTES_PER_ELEMENT,v=Math.ceil(C/4)*4,m=v/u.BYTES_PER_ELEMENT,_=f*C,g=f*v,T=o._malloc(_);c.GetAttributeDataArrayForAllPoints(a,l,E,_,T);const y=new u(o.HEAPF32.buffer,T,_/u.BYTES_PER_ELEMENT);let w;if(C===v)w=y.slice();else{w=new u(g/u.BYTES_PER_ELEMENT);let R=0;for(let S=0,M=y.length;S<M;S++){for(let A=0;A<p;A++)w[R+A]=y[S*p+A];R+=m}}return o._free(T),{name:d,count:f,itemSize:p,array:w,stride:m}}function i(o,c){switch(c){case Float32Array:return o.DT_FLOAT32;case Int8Array:return o.DT_INT8;case Int16Array:return o.DT_INT16;case Int32Array:return o.DT_INT32;case Uint8Array:return o.DT_UINT8;case Uint16Array:return o.DT_UINT16;case Uint32Array:return o.DT_UINT32}}}function wn(s){const e=new Map,t=new Map,n=s.clone();return ft(s,n,function(r,i){e.set(i,r),t.set(r,i)}),n.traverse(function(r){if(!r.isSkinnedMesh)return;const i=r,o=e.get(r),c=o.skeleton.bones;i.skeleton=o.skeleton.clone(),i.bindMatrix.copy(o.bindMatrix),i.skeleton.bones=c.map(function(a){return t.get(a)}),i.bind(i.skeleton,i.bindMatrix)}),n}function ft(s,e,t){t(s,e);for(let n=0;n<s.children.length;n++)ft(s.children[n],e.children[n],t)}class vn extends h.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Mn(t)}),this.register(function(t){return new xn(t)}),this.register(function(t){return new Fn(t)}),this.register(function(t){return new jn(t)}),this.register(function(t){return new Hn(t)}),this.register(function(t){return new An(t)}),this.register(function(t){return new kn(t)}),this.register(function(t){return new Pn(t)}),this.register(function(t){return new On(t)}),this.register(function(t){return new Sn(t)}),this.register(function(t){return new In(t)}),this.register(function(t){return new Ln(t)}),this.register(function(t){return new Dn(t)}),this.register(function(t){return new Nn(t)}),this.register(function(t){return new Rn(t)}),this.register(function(t){return new Ze(t,x.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new Ze(t,x.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new Bn(t)})}load(e,t,n,r){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const d=h.LoaderUtils.extractUrlBase(e);o=h.LoaderUtils.resolveURL(d,this.path)}else o=h.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const c=function(d){r?r(d):console.error(d),i.manager.itemError(e),i.manager.itemEnd(e)},a=new h.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(d){try{i.parse(d,o,function(u){t(u),i.manager.itemEnd(e)},c)}catch(u){c(u)}},n,c)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i;const o={},c={},a=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(a.decode(new Uint8Array(e,0,4))===ht){try{o[x.KHR_BINARY_GLTF]=new Un(e)}catch(l){r&&r(l);return}i=JSON.parse(o[x.KHR_BINARY_GLTF].content)}else i=JSON.parse(a.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const d=new er(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});d.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const l=this.pluginCallbacks[u](d);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),c[l.name]=l,o[l.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const l=i.extensionsUsed[u],f=i.extensionsRequired||[];switch(l){case x.KHR_MATERIALS_UNLIT:o[l]=new Cn;break;case x.KHR_DRACO_MESH_COMPRESSION:o[l]=new Gn(i,this.dracoLoader);break;case x.KHR_TEXTURE_TRANSFORM:o[l]=new Wn;break;case x.KHR_MESH_QUANTIZATION:o[l]=new Kn;break;default:f.indexOf(l)>=0&&c[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}d.setExtensions(o),d.setPlugins(c),d.parse(n,r)}parseAsync(e,t){const n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function En(){let s={};return{get:function(e){return s[e]},add:function(e,t){s[e]=t},remove:function(e){delete s[e]},removeAll:function(){s={}}}}function P(s,e,t){const n=s.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}const x={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 Rn{constructor(e){this.parser=e,this.name=x.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){const i=t[n];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let r=t.cache.get(n);if(r)return r;const i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let d;const u=new h.Color(16777215);a.color!==void 0&&u.setRGB(a.color[0],a.color[1],a.color[2],h.LinearSRGBColorSpace);const l=a.range!==void 0?a.range:0;switch(a.type){case"directional":d=new h.DirectionalLight(u),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new h.PointLight(u),d.distance=l;break;case"spot":d=new h.SpotLight(u),d.distance=l,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle!==void 0?a.spot.innerConeAngle:0,a.spot.outerConeAngle=a.spot.outerConeAngle!==void 0?a.spot.outerConeAngle:Math.PI/4,d.angle=a.spot.outerConeAngle,d.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,d.target.position.set(0,0,-1),d.add(d.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return d.position.set(0,0,0),D(d,a),a.intensity!==void 0&&(d.intensity=a.intensity),d.name=t.createUniqueName(a.name||"light_"+e),r=Promise.resolve(d),t.cache.add(n,r),r}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,i=n.json.nodes[e],c=(i.extensions&&i.extensions[this.name]||{}).light;return c===void 0?null:this._loadLight(c).then(function(a){return n._getNodeRef(t.cache,c,a)})}}class Cn{constructor(){this.name=x.KHR_MATERIALS_UNLIT}getMaterialType(){return h.MeshBasicMaterial}extendParams(e,t,n){const r=[];e.color=new h.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],h.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,"map",i.baseColorTexture,h.SRGBColorSpace))}return Promise.all(r)}}class Sn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}}class Mn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const i=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new h.Vector2(i,i)}return Promise.all(r)}}class xn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_DISPERSION}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion!==void 0?n.dispersion:0),Promise.resolve()}}class Ln{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(r)}}class An{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_SHEEN}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];if(t.sheenColor=new h.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){const i=n.sheenColorFactor;t.sheenColor.setRGB(i[0],i[1],i[2],h.LinearSRGBColorSpace)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"sheenColorMap",n.sheenColorTexture,h.SRGBColorSpace)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(r)}}class kn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,"transmissionMap",n.transmissionTexture)),Promise.all(r)}}class Pn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_VOLUME}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];t.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,"thicknessMap",n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;const i=n.attenuationColor||[1,1,1];return t.attenuationColor=new h.Color().setRGB(i[0],i[1],i[2],h.LinearSRGBColorSpace),Promise.all(r)}}class On{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_IOR}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);return n===null||(t.ior=n.ior!==void 0?n.ior:1.5),Promise.resolve()}}class In{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_SPECULAR}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];t.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,"specularIntensityMap",n.specularTexture));const i=n.specularColorFactor||[1,1,1];return t.specularColor=new h.Color().setRGB(i[0],i[1],i[2],h.LinearSRGBColorSpace),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"specularColorMap",n.specularColorTexture,h.SRGBColorSpace)),Promise.all(r)}}class Nn{constructor(e){this.parser=e,this.name=x.EXT_MATERIALS_BUMP}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];return t.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,"bumpMap",n.bumpTexture)),Promise.all(r)}}class Dn{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return P(this.parser,e,this.name)!==null?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();const r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,"anisotropyMap",n.anisotropyTexture)),Promise.all(r)}}class Fn{constructor(e){this.parser=e,this.name=x.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const i=r.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class jn{constructor(e){this.parser=e,this.name=x.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],c=r.images[o.source];let a=n.textureLoader;if(c.uri){const d=n.options.manager.getHandler(c.uri);d!==null&&(a=d)}return n.loadTextureImage(e,o.source,a)}}class Hn{constructor(e){this.parser=e,this.name=x.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],c=r.images[o.source];let a=n.textureLoader;if(c.uri){const d=n.options.manager.getHandler(c.uri);d!==null&&(a=d)}return n.loadTextureImage(e,o.source,a)}}class Ze{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const r=n.extensions[this.name],i=this.parser.getDependency("buffer",r.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(c){const a=r.byteOffset||0,d=r.byteLength||0,u=r.count,l=r.byteStride,f=new Uint8Array(c,a,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,l,f,r.mode,r.filter).then(function(p){return p.buffer}):o.ready.then(function(){const p=new ArrayBuffer(u*l);return o.decodeGltfBuffer(new Uint8Array(p),u,l,f,r.mode,r.filter),p})})}else return null}}class Bn{constructor(e){this.name=x.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;const r=t.meshes[n.mesh];for(const d of r.primitives)if(d.mode!==I.TRIANGLES&&d.mode!==I.TRIANGLE_STRIP&&d.mode!==I.TRIANGLE_FAN&&d.mode!==void 0)return null;const o=n.extensions[this.name].attributes,c=[],a={};for(const d in o)c.push(this.parser.getDependency("accessor",o[d]).then(u=>(a[d]=u,a[d])));return c.length<1?null:(c.push(this.parser.createNodeMesh(e)),Promise.all(c).then(d=>{const u=d.pop(),l=u.isGroup?u.children:[u],f=d[0].count,p=[];for(const E of l){const C=new h.Matrix4,v=new h.Vector3,m=new h.Quaternion,_=new h.Vector3(1,1,1),g=new h.InstancedMesh(E.geometry,E.material,f);for(let T=0;T<f;T++)a.TRANSLATION&&v.fromBufferAttribute(a.TRANSLATION,T),a.ROTATION&&m.fromBufferAttribute(a.ROTATION,T),a.SCALE&&_.fromBufferAttribute(a.SCALE,T),g.setMatrixAt(T,C.compose(v,m,_));for(const T in a)if(T==="_COLOR_0"){const y=a[T];g.instanceColor=new h.InstancedBufferAttribute(y.array,y.itemSize,y.normalized)}else T!=="TRANSLATION"&&T!=="ROTATION"&&T!=="SCALE"&&E.geometry.setAttribute(T,a[T]);h.Object3D.prototype.copy.call(g,E),this.parser.assignFinalMaterial(g),p.push(g)}return u.isGroup?(u.clear(),u.add(...p),u):p[0]}))}}const ht="glTF",se=12,et={JSON:1313821514,BIN:5130562};class Un{constructor(e){this.name=x.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,se),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==ht)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-se,i=new DataView(e,se);let o=0;for(;o<r;){const c=i.getUint32(o,!0);o+=4;const a=i.getUint32(o,!0);if(o+=4,a===et.JSON){const d=new Uint8Array(e,se+o,c);this.content=n.decode(d)}else if(a===et.BIN){const d=se+o;this.body=e.slice(d,d+c)}o+=c}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Gn{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=x.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,c={},a={},d={};for(const u in o){const l=ke[u]||u.toLowerCase();c[l]=o[u]}for(const u in e.attributes){const l=ke[u]||u.toLowerCase();if(o[u]!==void 0){const f=n.accessors[e.attributes[u]],p=Y[f.componentType];d[l]=p.name,a[l]=f.normalized===!0}}return t.getDependency("bufferView",i).then(function(u){return new Promise(function(l,f){r.decodeDracoFile(u,function(p){for(const E in p.attributes){const C=p.attributes[E],v=a[E];v!==void 0&&(C.normalized=v)}l(p)},c,d,h.LinearSRGBColorSpace,f)})})}}class Wn{constructor(){this.name=x.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Kn{constructor(){this.name=x.KHR_MESH_QUANTIZATION}}class pt extends h.Interpolant{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let o=0;o!==r;o++)t[o]=n[i+o];return t}interpolate_(e,t,n,r){const i=this.resultBuffer,o=this.sampleValues,c=this.valueSize,a=c*2,d=c*3,u=r-t,l=(n-t)/u,f=l*l,p=f*l,E=e*d,C=E-d,v=-2*p+3*f,m=p-f,_=1-v,g=m-f+l;for(let T=0;T!==c;T++){const y=o[C+T+c],w=o[C+T+a]*u,R=o[E+T+c],S=o[E+T]*u;i[T]=_*y+g*w+v*R+m*S}return i}}const zn=new h.Quaternion;class $n extends pt{interpolate_(e,t,n,r){const i=super.interpolate_(e,t,n,r);return zn.fromArray(i).normalize().toArray(i),i}}const I={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},Y={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},tt={9728:h.NearestFilter,9729:h.LinearFilter,9984:h.NearestMipmapNearestFilter,9985:h.LinearMipmapNearestFilter,9986:h.NearestMipmapLinearFilter,9987:h.LinearMipmapLinearFilter},nt={33071:h.ClampToEdgeWrapping,33648:h.MirroredRepeatWrapping,10497:h.RepeatWrapping},Re={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},ke={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"},U={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Vn={CUBICSPLINE:void 0,LINEAR:h.InterpolateLinear,STEP:h.InterpolateDiscrete},Ce={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function qn(s){return s.DefaultMaterial===void 0&&(s.DefaultMaterial=new h.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:h.FrontSide})),s.DefaultMaterial}function q(s,e,t){for(const n in t.extensions)s[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function D(s,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(s.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Xn(s,e,t){let n=!1,r=!1,i=!1;for(let d=0,u=e.length;d<u;d++){const l=e[d];if(l.POSITION!==void 0&&(n=!0),l.NORMAL!==void 0&&(r=!0),l.COLOR_0!==void 0&&(i=!0),n&&r&&i)break}if(!n&&!r&&!i)return Promise.resolve(s);const o=[],c=[],a=[];for(let d=0,u=e.length;d<u;d++){const l=e[d];if(n){const f=l.POSITION!==void 0?t.getDependency("accessor",l.POSITION):s.attributes.position;o.push(f)}if(r){const f=l.NORMAL!==void 0?t.getDependency("accessor",l.NORMAL):s.attributes.normal;c.push(f)}if(i){const f=l.COLOR_0!==void 0?t.getDependency("accessor",l.COLOR_0):s.attributes.color;a.push(f)}}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(a)]).then(function(d){const u=d[0],l=d[1],f=d[2];return n&&(s.morphAttributes.position=u),r&&(s.morphAttributes.normal=l),i&&(s.morphAttributes.color=f),s.morphTargetsRelative=!0,s})}function Qn(s,e){if(s.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)s.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(s.morphTargetInfluences.length===t.length){s.morphTargetDictionary={};for(let n=0,r=t.length;n<r;n++)s.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Yn(s){let e;const t=s.extensions&&s.extensions[x.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Se(t.attributes):e=s.indices+":"+Se(s.attributes)+":"+s.mode,s.targets!==void 0)for(let n=0,r=s.targets.length;n<r;n++)e+=":"+Se(s.targets[n]);return e}function Se(s){let e="";const t=Object.keys(s).sort();for(let n=0,r=t.length;n<r;n++)e+=t[n]+":"+s[t[n]]+";";return e}function Pe(s){switch(s){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 Jn(s){return s.search(/\.jpe?g($|\?)/i)>0||s.search(/^data\:image\/jpeg/)===0?"image/jpeg":s.search(/\.webp($|\?)/i)>0||s.search(/^data\:image\/webp/)===0?"image/webp":s.search(/\.ktx2($|\?)/i)>0||s.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Zn=new h.Matrix4;class er{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new En,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 n=!1,r=-1,i=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const c=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(c)===!0;const a=c.match(/Version\/(\d+)/);r=n&&a?parseInt(a[1],10):-1,i=c.indexOf("Firefox")>-1,o=i?c.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&r<17||i&&o<98?this.textureLoader=new h.TextureLoader(this.options.manager):this.textureLoader=new h.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new h.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){const c={scene:o[0][r.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:r.asset,parser:n,userData:{}};return q(i,c,r),D(c,r),Promise.all(n._invokeAll(function(a){return a.afterRoot&&a.afterRoot(c)})).then(function(){for(const a of c.scenes)a.updateMatrixWorld();e(c)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let r=0,i=t.length;r<i;r++){const o=t[r].joints;for(let c=0,a=o.length;c<a;c++)e[o[c]].isBone=!0}for(let r=0,i=e.length;r<i;r++){const o=e[r];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(n[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const r=n.clone(),i=(o,c)=>{const a=this.associations.get(o);a!=null&&this.associations.set(c,a);for(const[d,u]of o.children.entries())i(u,c.children[d])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const r=e(t[n]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let r=0;r<t.length;r++){const i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){const n=e+":"+t;let r=this.cache.get(n);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":r=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":r=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e);break}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,r=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(r.map(function(i,o){return n.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[x.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(i,o){n.load(h.LoaderUtils.resolveURL(t.uri,r.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){const r=t.byteLength||0,i=t.byteOffset||0;return n.slice(i,i+r)})}loadAccessor(e){const t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){const o=Re[r.type],c=Y[r.componentType],a=r.normalized===!0,d=new c(r.count*o);return Promise.resolve(new h.BufferAttribute(d,o,a))}const i=[];return r.bufferView!==void 0?i.push(this.getDependency("bufferView",r.bufferView)):i.push(null),r.sparse!==void 0&&(i.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(i).then(function(o){const c=o[0],a=Re[r.type],d=Y[r.componentType],u=d.BYTES_PER_ELEMENT,l=u*a,f=r.byteOffset||0,p=r.bufferView!==void 0?n.bufferViews[r.bufferView].byteStride:void 0,E=r.normalized===!0;let C,v;if(p&&p!==l){const m=Math.floor(f/p),_="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+m+":"+r.count;let g=t.cache.get(_);g||(C=new d(c,m*p,r.count*p/u),g=new h.InterleavedBuffer(C,p/u),t.cache.add(_,g)),v=new h.InterleavedBufferAttribute(g,a,f%p/u,E)}else c===null?C=new d(r.count*a):C=new d(c,f,r.count*a),v=new h.BufferAttribute(C,a,E);if(r.sparse!==void 0){const m=Re.SCALAR,_=Y[r.sparse.indices.componentType],g=r.sparse.indices.byteOffset||0,T=r.sparse.values.byteOffset||0,y=new _(o[1],g,r.sparse.count*m),w=new d(o[2],T,r.sparse.count*a);c!==null&&(v=new h.BufferAttribute(v.array.slice(),v.itemSize,v.normalized)),v.normalized=!1;for(let R=0,S=y.length;R<S;R++){const M=y[R];if(v.setX(M,w[R*a]),a>=2&&v.setY(M,w[R*a+1]),a>=3&&v.setZ(M,w[R*a+2]),a>=4&&v.setW(M,w[R*a+3]),a>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}v.normalized=E}return v})}loadTexture(e){const t=this.json,n=this.options,i=t.textures[e].source,o=t.images[i];let c=this.textureLoader;if(o.uri){const a=n.manager.getHandler(o.uri);a!==null&&(c=a)}return this.loadTextureImage(e,i,c)}loadTextureImage(e,t,n){const r=this,i=this.json,o=i.textures[e],c=i.images[t],a=(c.uri||c.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];const d=this.loadImageSource(t,n).then(function(u){u.flipY=!1,u.name=o.name||c.name||"",u.name===""&&typeof c.uri=="string"&&c.uri.startsWith("data:image/")===!1&&(u.name=c.uri);const f=(i.samplers||{})[o.sampler]||{};return u.magFilter=tt[f.magFilter]||h.LinearFilter,u.minFilter=tt[f.minFilter]||h.LinearMipmapLinearFilter,u.wrapS=nt[f.wrapS]||h.RepeatWrapping,u.wrapT=nt[f.wrapT]||h.RepeatWrapping,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==h.NearestFilter&&u.minFilter!==h.LinearFilter,r.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[a]=d,d}loadImageSource(e,t){const n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(l=>l.clone());const o=r.images[e],c=self.URL||self.webkitURL;let a=o.uri||"",d=!1;if(o.bufferView!==void 0)a=n.getDependency("bufferView",o.bufferView).then(function(l){d=!0;const f=new Blob([l],{type:o.mimeType});return a=c.createObjectURL(f),a});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(a).then(function(l){return new Promise(function(f,p){let E=f;t.isImageBitmapLoader===!0&&(E=function(C){const v=new h.Texture(C);v.needsUpdate=!0,f(v)}),t.load(h.LoaderUtils.resolveURL(l,i.path),E,void 0,p)})}).then(function(l){return d===!0&&c.revokeObjectURL(a),D(l,o),l.userData.mimeType=o.mimeType||Jn(o.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",a),l});return this.sourceCache[e]=u,u}assignTexture(e,t,n,r){const i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),i.extensions[x.KHR_TEXTURE_TRANSFORM]){const c=n.extensions!==void 0?n.extensions[x.KHR_TEXTURE_TRANSFORM]:void 0;if(c){const a=i.associations.get(o);o=i.extensions[x.KHR_TEXTURE_TRANSFORM].extendTexture(o,c),i.associations.set(o,a)}}return r!==void 0&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const c="PointsMaterial:"+n.uuid;let a=this.cache.get(c);a||(a=new h.PointsMaterial,h.Material.prototype.copy.call(a,n),a.color.copy(n.color),a.map=n.map,a.sizeAttenuation=!1,this.cache.add(c,a)),n=a}else if(e.isLine){const c="LineBasicMaterial:"+n.uuid;let a=this.cache.get(c);a||(a=new h.LineBasicMaterial,h.Material.prototype.copy.call(a,n),a.color.copy(n.color),a.map=n.map,this.cache.add(c,a)),n=a}if(r||i||o){let c="ClonedMaterial:"+n.uuid+":";r&&(c+="derivative-tangents:"),i&&(c+="vertex-colors:"),o&&(c+="flat-shading:");let a=this.cache.get(c);a||(a=n.clone(),i&&(a.vertexColors=!0),o&&(a.flatShading=!0),r&&(a.normalScale&&(a.normalScale.y*=-1),a.clearcoatNormalScale&&(a.clearcoatNormalScale.y*=-1)),this.cache.add(c,a),this.associations.set(a,this.associations.get(n))),n=a}e.material=n}getMaterialType(){return h.MeshStandardMaterial}loadMaterial(e){const t=this,n=this.json,r=this.extensions,i=n.materials[e];let o;const c={},a=i.extensions||{},d=[];if(a[x.KHR_MATERIALS_UNLIT]){const l=r[x.KHR_MATERIALS_UNLIT];o=l.getMaterialType(),d.push(l.extendParams(c,i,t))}else{const l=i.pbrMetallicRoughness||{};if(c.color=new h.Color(1,1,1),c.opacity=1,Array.isArray(l.baseColorFactor)){const f=l.baseColorFactor;c.color.setRGB(f[0],f[1],f[2],h.LinearSRGBColorSpace),c.opacity=f[3]}l.baseColorTexture!==void 0&&d.push(t.assignTexture(c,"map",l.baseColorTexture,h.SRGBColorSpace)),c.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,c.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(c,"metalnessMap",l.metallicRoughnessTexture)),d.push(t.assignTexture(c,"roughnessMap",l.metallicRoughnessTexture))),o=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,c)})))}i.doubleSided===!0&&(c.side=h.DoubleSide);const u=i.alphaMode||Ce.OPAQUE;if(u===Ce.BLEND?(c.transparent=!0,c.depthWrite=!1):(c.transparent=!1,u===Ce.MASK&&(c.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==h.MeshBasicMaterial&&(d.push(t.assignTexture(c,"normalMap",i.normalTexture)),c.normalScale=new h.Vector2(1,1),i.normalTexture.scale!==void 0)){const l=i.normalTexture.scale;c.normalScale.set(l,l)}if(i.occlusionTexture!==void 0&&o!==h.MeshBasicMaterial&&(d.push(t.assignTexture(c,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(c.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==h.MeshBasicMaterial){const l=i.emissiveFactor;c.emissive=new h.Color().setRGB(l[0],l[1],l[2],h.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==h.MeshBasicMaterial&&d.push(t.assignTexture(c,"emissiveMap",i.emissiveTexture,h.SRGBColorSpace)),Promise.all(d).then(function(){const l=new o(c);return i.name&&(l.name=i.name),D(l,i),t.associations.set(l,{materials:e}),i.extensions&&q(r,l,i),l})}createUniqueName(e){const t=h.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,r=this.primitiveCache;function i(c){return n[x.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(c,t).then(function(a){return rt(a,c,t)})}const o=[];for(let c=0,a=e.length;c<a;c++){const d=e[c],u=Yn(d),l=r[u];if(l)o.push(l.promise);else{let f;d.extensions&&d.extensions[x.KHR_DRACO_MESH_COMPRESSION]?f=i(d):f=rt(new h.BufferGeometry,d,t),r[u]={primitive:d,promise:f},o.push(f)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,r=this.extensions,i=n.meshes[e],o=i.primitives,c=[];for(let a=0,d=o.length;a<d;a++){const u=o[a].material===void 0?qn(this.cache):this.getDependency("material",o[a].material);c.push(u)}return c.push(t.loadGeometries(o)),Promise.all(c).then(function(a){const d=a.slice(0,a.length-1),u=a[a.length-1],l=[];for(let p=0,E=u.length;p<E;p++){const C=u[p],v=o[p];let m;const _=d[p];if(v.mode===I.TRIANGLES||v.mode===I.TRIANGLE_STRIP||v.mode===I.TRIANGLE_FAN||v.mode===void 0)m=i.isSkinnedMesh===!0?new h.SkinnedMesh(C,_):new h.Mesh(C,_),m.isSkinnedMesh===!0&&m.normalizeSkinWeights(),v.mode===I.TRIANGLE_STRIP?m.geometry=Je(m.geometry,h.TriangleStripDrawMode):v.mode===I.TRIANGLE_FAN&&(m.geometry=Je(m.geometry,h.TriangleFanDrawMode));else if(v.mode===I.LINES)m=new h.LineSegments(C,_);else if(v.mode===I.LINE_STRIP)m=new h.Line(C,_);else if(v.mode===I.LINE_LOOP)m=new h.LineLoop(C,_);else if(v.mode===I.POINTS)m=new h.Points(C,_);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+v.mode);Object.keys(m.geometry.morphAttributes).length>0&&Qn(m,i),m.name=t.createUniqueName(i.name||"mesh_"+e),D(m,i),v.extensions&&q(r,m,v),t.assignFinalMaterial(m),l.push(m)}for(let p=0,E=l.length;p<E;p++)t.associations.set(l[p],{meshes:e,primitives:p});if(l.length===1)return i.extensions&&q(r,l[0],i),l[0];const f=new h.Group;i.extensions&&q(r,f,i),t.associations.set(f,{meshes:e});for(let p=0,E=l.length;p<E;p++)f.add(l[p]);return f})}loadCamera(e){let t;const n=this.json.cameras[e],r=n[n.type];if(!r){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new h.PerspectiveCamera(h.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type==="orthographic"&&(t=new h.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),D(t,n),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],n=[];for(let r=0,i=t.joints.length;r<i;r++)n.push(this._loadNodeShallow(t.joints[r]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(r){const i=r.pop(),o=r,c=[],a=[];for(let d=0,u=o.length;d<u;d++){const l=o[d];if(l){c.push(l);const f=new h.Matrix4;i!==null&&f.fromArray(i.array,d*16),a.push(f)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[d])}return new h.Skeleton(c,a)})}loadAnimation(e){const t=this.json,n=this,r=t.animations[e],i=r.name?r.name:"animation_"+e,o=[],c=[],a=[],d=[],u=[];for(let l=0,f=r.channels.length;l<f;l++){const p=r.channels[l],E=r.samplers[p.sampler],C=p.target,v=C.node,m=r.parameters!==void 0?r.parameters[E.input]:E.input,_=r.parameters!==void 0?r.parameters[E.output]:E.output;C.node!==void 0&&(o.push(this.getDependency("node",v)),c.push(this.getDependency("accessor",m)),a.push(this.getDependency("accessor",_)),d.push(E),u.push(C))}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(a),Promise.all(d),Promise.all(u)]).then(function(l){const f=l[0],p=l[1],E=l[2],C=l[3],v=l[4],m=[];for(let g=0,T=f.length;g<T;g++){const y=f[g],w=p[g],R=E[g],S=C[g],M=v[g];if(y===void 0)continue;y.updateMatrix&&y.updateMatrix();const A=n._createAnimationTracks(y,w,R,S,M);if(A)for(let k=0;k<A.length;k++)m.push(A[k])}const _=new h.AnimationClip(i,void 0,m);return D(_,r),_})}createNodeMesh(e){const t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency("mesh",r.mesh).then(function(i){const o=n._getNodeRef(n.meshCache,r.mesh,i);return r.weights!==void 0&&o.traverse(function(c){if(c.isMesh)for(let a=0,d=r.weights.length;a<d;a++)c.morphTargetInfluences[a]=r.weights[a]}),o})}loadNode(e){const t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),o=[],c=r.children||[];for(let d=0,u=c.length;d<u;d++)o.push(n.getDependency("node",c[d]));const a=r.skin===void 0?Promise.resolve(null):n.getDependency("skin",r.skin);return Promise.all([i,Promise.all(o),a]).then(function(d){const u=d[0],l=d[1],f=d[2];f!==null&&u.traverse(function(p){p.isSkinnedMesh&&p.bind(f,Zn)});for(let p=0,E=l.length;p<E;p++)u.add(l[p]);if(u.userData.pivot!==void 0&&l.length>0){const p=u.userData.pivot,E=l[0];u.pivot=new h.Vector3().fromArray(p),u.position.x-=p[0],u.position.y-=p[1],u.position.z-=p[2],E.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(e){const t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],o=i.name?r.createUniqueName(i.name):"",c=[],a=r._invokeOne(function(d){return d.createNodeMesh&&d.createNodeMesh(e)});return a&&c.push(a),i.camera!==void 0&&c.push(r.getDependency("camera",i.camera).then(function(d){return r._getNodeRef(r.cameraCache,i.camera,d)})),r._invokeAll(function(d){return d.createNodeAttachment&&d.createNodeAttachment(e)}).forEach(function(d){c.push(d)}),this.nodeCache[e]=Promise.all(c).then(function(d){let u;if(i.isBone===!0?u=new h.Bone:d.length>1?u=new h.Group:d.length===1?u=d[0]:u=new h.Object3D,u!==d[0])for(let l=0,f=d.length;l<f;l++)u.add(d[l]);if(i.name&&(u.userData.name=i.name,u.name=o),D(u,i),i.extensions&&q(n,u,i),i.matrix!==void 0){const l=new h.Matrix4;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(!r.associations.has(u))r.associations.set(u,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){const l=r.associations.get(u);r.associations.set(u,{...l})}return r.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],r=this,i=new h.Group;n.name&&(i.name=r.createUniqueName(n.name)),D(i,n),n.extensions&&q(t,i,n);const o=n.nodes||[],c=[];for(let a=0,d=o.length;a<d;a++)c.push(r.getDependency("node",o[a]));return Promise.all(c).then(function(a){for(let u=0,l=a.length;u<l;u++){const f=a[u];f.parent!==null?i.add(wn(f)):i.add(f)}const d=u=>{const l=new Map;for(const[f,p]of r.associations)(f instanceof h.Material||f instanceof h.Texture)&&l.set(f,p);return u.traverse(f=>{const p=r.associations.get(f);p!=null&&l.set(f,p)}),l};return r.associations=d(i),i})}_createAnimationTracks(e,t,n,r,i){const o=[],c=e.name?e.name:e.uuid,a=[];U[i.path]===U.weights?e.traverse(function(f){f.morphTargetInfluences&&a.push(f.name?f.name:f.uuid)}):a.push(c);let d;switch(U[i.path]){case U.weights:d=h.NumberKeyframeTrack;break;case U.rotation:d=h.QuaternionKeyframeTrack;break;case U.translation:case U.scale:d=h.VectorKeyframeTrack;break;default:switch(n.itemSize){case 1:d=h.NumberKeyframeTrack;break;case 2:case 3:default:d=h.VectorKeyframeTrack;break}break}const u=r.interpolation!==void 0?Vn[r.interpolation]:h.InterpolateLinear,l=this._getArrayFromAccessor(n);for(let f=0,p=a.length;f<p;f++){const E=new d(a[f]+"."+U[i.path],t.array,l,u);r.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(E),o.push(E)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const n=Pe(t.constructor),r=new Float32Array(t.length);for(let i=0,o=t.length;i<o;i++)r[i]=t[i]*n;t=r}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){const r=this instanceof h.QuaternionKeyframeTrack?$n:pt;return new r(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function tr(s,e,t){const n=e.attributes,r=new h.Box3;if(n.POSITION!==void 0){const c=t.json.accessors[n.POSITION],a=c.min,d=c.max;if(a!==void 0&&d!==void 0){if(r.set(new h.Vector3(a[0],a[1],a[2]),new h.Vector3(d[0],d[1],d[2])),c.normalized){const u=Pe(Y[c.componentType]);r.min.multiplyScalar(u),r.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const c=new h.Vector3,a=new h.Vector3;for(let d=0,u=i.length;d<u;d++){const l=i[d];if(l.POSITION!==void 0){const f=t.json.accessors[l.POSITION],p=f.min,E=f.max;if(p!==void 0&&E!==void 0){if(a.setX(Math.max(Math.abs(p[0]),Math.abs(E[0]))),a.setY(Math.max(Math.abs(p[1]),Math.abs(E[1]))),a.setZ(Math.max(Math.abs(p[2]),Math.abs(E[2]))),f.normalized){const C=Pe(Y[f.componentType]);a.multiplyScalar(C)}c.max(a)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}r.expandByVector(c)}s.boundingBox=r;const o=new h.Sphere;r.getCenter(o.center),o.radius=r.min.distanceTo(r.max)/2,s.boundingSphere=o}function rt(s,e,t){const n=e.attributes,r=[];function i(o,c){return t.getDependency("accessor",o).then(function(a){s.setAttribute(c,a)})}for(const o in n){const c=ke[o]||o.toLowerCase();c in s.attributes||r.push(i(n[o],c))}if(e.indices!==void 0&&!s.index){const o=t.getDependency("accessor",e.indices).then(function(c){s.setIndex(c)});r.push(o)}return h.ColorManagement.workingColorSpace!==h.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${h.ColorManagement.workingColorSpace}" not supported.`),D(s,e),tr(s,e,t),Promise.all(r).then(function(){return e.targets!==void 0?Xn(s,e.targets,t):s})}var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,sr=(s,e,t,n)=>{for(var r=n>1?void 0:n?rr(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&nr(e,t,r),r};let de=class{constructor(){L(this,"loadingManager",new h.LoadingManager);L(this,"loaders",{});L(this,"sources",[]);L(this,"loadedResources",{});L(this,"toLoadCount",0);L(this,"loadedCount",0)}get videoLoader(){return{load:(s,e)=>{const t=document.createElement("video");t.muted=!0,t.loop=!0,t.crossOrigin="anonymous",t.controls=!1,t.playsInline=!0,t.src=s,t.autoplay=!0;const n=async()=>{e(t),t.removeEventListener("canplaythrough",n)};t.addEventListener("canplaythrough",n)}}}_initLoaders(){this.loaders.dracoLoader=new dt(this.loadingManager),this.loaders.audioLoader=new h.AudioLoader(this.loadingManager),this.loaders.fontLoader=new b.FontLoader(this.loadingManager),this.loaders.gltfLoader=new vn(this.loadingManager),this.loaders.imageLoader=new h.ImageBitmapLoader(this.loadingManager),this.loaders.videoLoader=this.videoLoader}_initSources(s){this.sources=s,this.toLoadCount=this.sources.length,this.loadedCount=0}init(s=[]){this._initLoaders(),this._initSources(s)}setDracoDecoder(s){var e;this.loaders.dracoLoader&&(this.loaders.dracoLoader.setDecoderPath(s??"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),(e=this.loaders.gltfLoader)==null||e.setDRACOLoader(this.loaders.dracoLoader))}handleLoad({source:s,resource:e,toLoadCount:t,loadedCount:n}){e&&(this.loadedResources[s.name]=e,this.loadedCount=n,this.toLoadCount=t)}launchLoad(s){var t,n,r,i,o;const e=this.sources[0];if(e){s==null||s(e);for(const c of this.sources){if(this.loadedResources[c.name]||typeof c.path!="string")return;c.type==="gltf"&&((t=this.loaders.gltfLoader)==null||t.load(c.path,a=>s==null?void 0:s(c,a))),c.type==="audio"&&((n=this.loaders.audioLoader)==null||n.load(c.path,a=>s==null?void 0:s(c,a))),c.type==="image"&&((r=this.loaders.imageLoader)==null||r.load(c.path,a=>s==null?void 0:s(c,a))),c.type==="video"&&((i=this.loaders.videoLoader)==null||i.load(c.path,a=>s==null?void 0:s(c,a))),c.type==="font"&&((o=this.loaders.fontLoader)==null||o.load(c.path,a=>s==null?void 0:s(c,a)))}}}};de=sr([b.scoped(b.Lifecycle.ContainerScoped)],de);var ir=Object.defineProperty,or=Object.getOwnPropertyDescriptor,ar=(s,e,t,n)=>{for(var r=n>1?void 0:n?or(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&ir(e,t,r),r},cr=(s,e)=>(t,n)=>e(t,n,s);let fe=class{constructor(s){L(this,"load$$",new b.Subject);L(this,"load$",this.load$$.pipe(b.map(s=>({...s,loadedCount:s.resource?this._service.loadedCount+1:this._service.loadedCount,toLoadCount:this._service.toLoadCount})),b.share()));L(this,"serializedLoad$",this.load$.pipe(b.map(s=>{var t,n,r;let e=s.resource;if((t=s==null?void 0:s.resource)!=null&&t.parser){const i=s.resource,o=i.scenes.map(c=>b.b(c));e={animations:(s==null?void 0:s.resource).animations.map(c=>c.toJSON()),cameras:i.cameras.map(c=>b.b(c)),parser:{json:i.parser.json},scene:o==null?void 0:o[0],scenes:o,userData:i.userData}}return((n=s==null?void 0:s.source)==null?void 0:n.type)==="audio"&&s.resource instanceof AudioBuffer&&(e={arrayBuffer:s.resource.getChannelData(0),length:s.resource.length,sampleRate:s.resource.sampleRate,duration:s.resource.duration}),((r=s==null?void 0:s.source)==null?void 0:r.type)==="video"&&s.resource instanceof HTMLVideoElement&&(e={...b.E(s.resource,["autoplay","baseURI","controls","crossOrigin","currentTime","defaultMuted","disablePictureInPicture","draggable","duration","ended","height","hidden","loop","muted","nodeName","nodeType","paused","playbackRate","playsInline","poster","preload","readyState","seeking","spellcheck","src","tabIndex","translate","videoHeight","videoWidth","volume","width"]),buffered:s.resource.buffered.length,error:s.resource.error?b.U(s.resource.error,[]):{},played:s.resource.played.length,seekable:s.resource.seekable.length,textTracks:s.resource.textTracks.length}),{...s,resource:e}}),b.share()));L(this,"loadCompleted$",this.load$.pipe(b.filter(s=>s.toLoadCount===s.loadedCount),b.map(()=>b.E(this._service,["loadedCount","loadedResources","toLoadCount"])),b.share()));this._service=s}};fe=ar([b.scoped(b.Lifecycle.ContainerScoped),cr(0,b.inject(de))],fe);var ur=Object.defineProperty,lr=Object.getOwnPropertyDescriptor,dr=(s,e,t,n)=>{for(var r=n>1?void 0:n?lr(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&ur(e,t,r),r},Me=(s,e)=>(t,n)=>e(t,n,s);let Oe=class{constructor(s,e,t){L(this,"_subscriptions",[]);this._controller=s,this._service=e,this._props=t,this._subscriptions.push(this._controller.load$.subscribe(this._service.handleLoad.bind(this._service)))}init(s){this._service.init(s.sources||[]),this._service.setDracoDecoder(s.dracoDecoderPath),[void 0,!0].includes(this._props.loadResourcesOnInit)&&this.load()}load(){this._service.launchLoad((s,e)=>this._controller.load$$.next({source:s,resource:e}))}getLoadedResources(){return this._service.loadedResources}getLoaders(){return this._service.loaders}getSources(){return this._service.sources}getLoadedCount(){return this._service.loadedCount}getToLoadCount(){return this._service.toLoadCount}getLoad$(){return this._controller.load$}getLoadCompleted$(){return this._controller.loadCompleted$}setDracoDecoder(s){this._service.setDracoDecoder(s)}dispose(){this._subscriptions.forEach(s=>s.unsubscribe()),Object.keys(this._service.loaders).forEach(s=>{const e=this._service.loaders[s];e instanceof dt&&e.dispose(),this._service.loaders[s]=void 0}),this._controller.load$$.complete()}};Oe=dr([b.scoped(b.Lifecycle.ContainerScoped),Me(0,b.inject(fe)),Me(1,b.inject(de)),Me(2,b.inject(ie))],Oe);var fr=Object.defineProperty,hr=Object.getOwnPropertyDescriptor,pr=(s,e,t,n)=>{for(var r=n>1?void 0:n?hr(e,t):e,i=s.length-1,o;i>=0;i--)(o=s[i])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&fr(e,t,r),r},Q=(s,e)=>(t,n)=>e(t,n,s);exports.RegisterModule=class extends b.RegisterProxyEventHandlersBlueprint{constructor(t,n,r,i,o,c){super();L(this,"_subscriptions",[]);L(this,"_initialized",!1);this._service=t,this._controller=n,this._loaderController=r,this.container=i,this.props=o,this.loader=c,this.props.initOnConstruct&&this.init()}get currentWorker(){return this.props.mainThread?self:this._service.worker}async _initCanvas(){try{if(this.props.canvas instanceof HTMLCanvasElement&&(this._service.canvas=this.props.canvas),typeof this.props.canvas=="string"){const t=document.querySelector(this.props.canvas);t instanceof HTMLCanvasElement&&(this._service.canvas=t)}this._service.canvas||(this._service.canvas=document.createElement("canvas"),this._service.canvas.dataset.reactive="true",document.body.appendChild(this._service.canvas))}catch(t){console.error(`🛑 Unable to initialize the canvas:
|
|
4
|
+
${t instanceof Error?t.message:"Something went wrong"}`)}}async _initServiceWorker(){this._service.init({worker:this._service.worker,thread:this._service.thread})}async _initEvents(){if(!this._service.canvas)throw new Error("Canvas element is not initialized.");this._controller.init(),setTimeout(()=>{const t=new UIEvent("resize");t.width=window.innerWidth,t.height=window.innerHeight,t.windowWidth=window.innerWidth,t.windowHeight=window.innerHeight,this._controller.resize$$.next(this._service.uiEventHandler(t))},0)}async _initOnMainThread(){await import(`${this.props.location}`),self.postMessage({mainThread:!0,...b.U(this.props,["mainThread","canvas","location","onReady","loaderDataSources"])})}async _initOnWorkerThread(){if(!this._service.canvas)throw new Error("Canvas element is not initialized.");this._service.offscreenCanvas=this._service.canvas.transferControlToOffscreen(),this._service.offscreenCanvas.width=this._service.canvas.clientWidth,this._service.offscreenCanvas.height=this._service.canvas.clientHeight;const[t,n]=await this._service.workerPool.run({payload:{path:this.props.location,subject:{...b.U(this.props,["canvas","location","onReady","loaderDataSources"]),canvas:this._service.offscreenCanvas},transferSubject:[this._service.offscreenCanvas]}})||[];if(!t||n)throw new Error("Unable to retrieve the worker-thread info.");this._service.worker=t.worker,this._service.thread=t.thread}async _initObservables(){b.PROXY_EVENT_LISTENERS.forEach(t=>this[`${t}$`]=()=>{var n;return(n=this._controller)==null?void 0:n[`${t}$`]})}async _initLoader(){this.loader.init({sources:this.props.loaderDataSources,dracoDecoderPath:this.props.loaderDracoDecoderPath}),this._subscriptions.push(this._loaderController.serializedLoad$.subscribe(t=>{var n,r;if(t.resource instanceof ArrayBuffer)return(n=this.currentWorker)==null?void 0:n.postMessage(t.resource,[t.resource]);(r=this.currentWorker)==null||r.postMessage({token:b.LOADER_SERIALIZED_LOAD_TOKEN,payload:t})}))}async init(){var t,n;this._initialized||(this._initialized=!0,await this._initCanvas(),this.props.mainThread?await this._initOnMainThread():await this._initOnWorkerThread(),await this._initServiceWorker(),await this._initObservables(),await this._initLoader(),await this._initEvents(),(n=(t=this.props).onReady)==null||n.call(t,{module:this,container:this.container}))}getCanvas(){return this._service.canvas}getOffscreenCanvas(){return this._service.offscreenCanvas}getThread(){return this._service.thread}getWorker(){return this._service.worker}getWorkerPool(){return this._service.workerPool}isInitialized(){return this._initialized}async dispose(){var t;this._subscriptions.map(n=>n.unsubscribe()),await this._service.workerPool.terminateAll(),((t=this._service.canvas)==null?void 0:t.dataset.reactive)==="true"&&(document.body.removeChild(this._service.canvas),this._service.canvas.remove(),this._service.canvas=void 0),this._initialized=!1}};exports.RegisterModule=pr([b.scoped(b.Lifecycle.ContainerScoped),Q(0,b.inject(le)),Q(1,b.inject(Ae)),Q(2,b.inject(fe)),Q(3,b.inject(b.CONTAINER_TOKEN)),Q(4,b.inject(ie)),Q(5,b.inject(Oe))],exports.RegisterModule);const mr=s=>{if(!(s!=null&&s.location)||!URL.canParse(s.location))throw new Error("Invalid register props detected. location path is required");const e=b.instance.createChildContainer();s.initOnConstruct=b.z(s.initOnConstruct)||!b.N(s.initOnConstruct)?!0:s.initOnConstruct,s.defaultCamera=s!=null&&s.defaultCamera&&s.defaultCamera in b.DefaultCameraType?s.defaultCamera:b.DefaultCameraType.PERSPECTIVE,s.withMiniCamera=b.z(s.withMiniCamera)||!b.N(s.withMiniCamera)?!1:s.withMiniCamera,s.startTimer=b.z(s.startTimer)||!b.N(s.startTimer)?!0:s.startTimer,s.fullScreen=b.z(s.fullScreen)||!b.N(s.fullScreen)?!0:s.fullScreen,s.onReady=b.R(s.onReady)?s.onReady:void 0,e.register(b.CONTAINER_TOKEN,{useValue:e}),e.register(ie,{useValue:s});const t=e.resolve(exports.RegisterModule);return{container:e,module:t}};exports.AppProxyEventHandlersBlueprint=b.AppProxyEventHandlersBlueprint;exports.CONTAINER_TOKEN=b.CONTAINER_TOKEN;exports.DefaultCameraType=b.DefaultCameraType;exports.KEYBOARD_EVENT_CODES=b.KEYBOARD_EVENT_CODES;exports.LOADER_SERIALIZED_LOAD_TOKEN=b.LOADER_SERIALIZED_LOAD_TOKEN;exports.PROXY_EVENT_LISTENERS=b.PROXY_EVENT_LISTENERS;exports.ProxyEventHandlersBlueprint=b.ProxyEventHandlersBlueprint;exports.ProxyEventObservablesBlueprint=b.ProxyEventObservablesBlueprint;exports.ProxyEventSubjectsBlueprint=b.ProxyEventSubjectsBlueprint;exports.RegisterProxyEventHandlersBlueprint=b.RegisterProxyEventHandlersBlueprint;exports.LaunchAppProps=_t;exports.RegisterPropsBlueprint=ie;exports.register=mr;
|