@quick-threejs/reactive 0.1.46 → 0.1.48
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-D3WA1QGd.js → FontLoader-76d20F_i.js} +6 -6
- package/dist/{FontLoader-ejhD_xZ1.mjs → FontLoader-YhZm0TOQ.mjs} +31 -30
- package/dist/common/blueprints/props.blueprint.d.ts +78 -43
- package/dist/common/interfaces/core.interface.d.ts +13 -1
- package/dist/common/interfaces/proxy-event.interface.d.ts +2 -0
- package/dist/core/app/app.module.d.ts +2 -2
- package/dist/core/app/app.service.d.ts +2 -1
- package/dist/core/app/app.worker.d.ts +1 -1
- package/dist/core/app/camera/camera.module.d.ts +2 -4
- package/dist/core/app/camera/camera.service.d.ts +3 -2
- package/dist/core/app/debug/debug.module.d.ts +1 -1
- package/dist/core/app/debug/debug.service.d.ts +2 -2
- package/dist/core/app/loader/loader.module.d.ts +1 -1
- package/dist/core/app/renderer/renderer.module.d.ts +4 -4
- package/dist/core/app/renderer/renderer.service.d.ts +5 -5
- package/dist/core/app/sizes/sizes.module.d.ts +13 -4
- package/dist/core/app/sizes/sizes.service.d.ts +13 -2
- package/dist/core/register/register.module.d.ts +3 -5
- package/dist/core/register/register.service.d.ts +18 -7
- package/dist/main.js +4 -4
- package/dist/main.mjs +904 -914
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +551 -510
- package/package.json +5 -5
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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.5.7/"),(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
|
-
${
|
|
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 _=require("./FontLoader-76d20F_i.js"),f=require("three");class ie{constructor(){L(this,"location");L(this,"initOnConstruct");L(this,"mainThread");L(this,"canvas");L(this,"canvasWrapper");L(this,"fullScreen");L(this,"pixelRatio");L(this,"autoRenderResize");L(this,"defaultCamera");L(this,"startTimer");L(this,"loaderDataSources",[]);L(this,"loaderDracoDecoderPath");L(this,"loadResourcesOnInit");L(this,"debug");L(this,"onReady")}}class _t{constructor(){L(this,"canvas");L(this,"onReady")}}var K={},_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 h,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(/\/[^\/]+$/,"/")),(!((h=l==null?void 0:l.CORSWorkaround)!==null&&h!==void 0)||h)&&(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 h=window.URL.createObjectURL(u);super(h,l)}static fromText(u,l){const h=new window.Blob([u],{type:"text/javascript"});return new a(h,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 h=typeof u;if(h==="string"&&u.length>0)return o(u);if(h==="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 h=parseFloat(l[1]),p=(l[2]||"ms").toLowerCase();switch(p){case"years":case"year":case"yrs":case"yr":case"y":return h*i;case"weeks":case"week":case"w":return h*r;case"days":case"day":case"d":return h*n;case"hours":case"hour":case"hrs":case"hr":case"h":return h*t;case"minutes":case"minute":case"mins":case"min":case"m":return h*e;case"seconds":case"second":case"secs":case"sec":case"s":return h*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return h;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,h,p){var E=l>=h*1.5;return Math.round(u/h)+" "+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 h=0;for(let p=0;p<l.length;p++)h=(h<<5)-h+l.charCodeAt(p),h|=0;return n.colors[Math.abs(h)%n.colors.length]}n.selectColor=t;function n(l){let h,p=null,E,C;function v(...m){if(!v.enabled)return;const b=v,g=Number(new Date),T=g-(h||g);b.diff=T,b.prev=h,b.curr=g,h=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 x=n.formatters[S];if(typeof x=="function"){const A=m[y];R=x.call(b,A),m.splice(y,1),y--}return R}),n.formatArgs.call(b,m),(b.log||n.log).apply(b,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,h){const p=n(this.namespace+(typeof h>"u"?":":h)+l);return p.log=this.log,p}function i(l){n.save(l),n.namespaces=l,n.names=[],n.skips=[];let h;const p=(typeof l=="string"?l:"").split(/[\s,]+/),E=p.length;for(h=0;h<E;h++)p[h]&&(l=p[h].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(h=>"-"+h)].join(",");return n.enable(""),l}function c(l){if(l[l.length-1]==="*")return!0;let h,p;for(h=0,p=n.skips.length;h<p;h++)if(n.skips[h].test(l))return!1;for(h=0,p=n.names.length;h<p;h++)if(n.names[h].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 Ue;function Ie(){return Ue||(Ue=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,h=>{h!=="%%"&&(u++,h==="%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 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=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"),Me=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()}})}[Me](){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,Me);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:Me,hostReportError:J},configurable:!0});function X(s){typeof s=="function"?s():s&&typeof s.unsubscribe=="function"&&s.unsubscribe()}var xt=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 Mt(s){return e=>new O(t=>{const n=new fe(t),r=e.subscribe({complete(){n.complete()},error(i){n.error(i)},next(i){n.schedule(o=>xt(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 fe(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 h=l.value;o(h)}}catch(h){c={error:h}}finally{try{l&&!l.done&&(a=u.return)&&(yield a.call(u))}finally{if(c)throw c.error}}else d.map(h=>o(h))}))}});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 fe(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 Ut(s,e){return t=>new O(n=>{let r,i=0;const o=new fe(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 Bt=Object.freeze(Object.defineProperty({__proto__:null,Observable:O,Subject:ut,filter:Mt,flatMap:Ot,interval:It,map:Dt,merge:Ft,multicast:jt,scan:Ut,unsubscribe:X},Symbol.toStringTag,{value:"Module"})),pe=_.getAugmentedNamespace(Bt);var ee={},Be;function Gt(){if(Be)return ee;Be=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=_.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 ze;function zt(){return ze||(ze=1,function(s){var e=V&&V.__awaiter||function(m,b,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 x(k){try{A(T.throw(k))}catch(N){R(N)}}function A(k){k.done?w(k.value):y(k.value).then(S,x)}A((T=T.apply(m,b||[])).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 b=[];for(let g=0;g<m;g++)b.push(g);return b}function l(m){return new Promise(b=>setTimeout(b,m))}function h(m,b){return m.reduce((g,T)=>[...g,...b(T)],[])}function p(m){return m.replace(/\W/g," ").trim().replace(/\s+/g,"-")}function E(m,b){return u(b).map(()=>({init:m(),runningTasks:[]}))}class C{constructor(b,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(b,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:b=1}=this.options;return this.workers.find(g=>g.runningTasks.length<b)}runPoolTask(b,g){return e(this,void 0,void 0,function*(){const T=this.workers.indexOf(b)+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 b.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(b,g){return e(this,void 0,void 0,function*(){const T=e(this,void 0,void 0,function*(){const y=()=>{b.runningTasks=b.runningTasks.filter(w=>w!==T)};yield l(0);try{yield this.runPoolTask(b,g)}finally{y(),this.isClosing||this.scheduleWork()}});b.runningTasks.push(T)})}scheduleWork(){this.debug("Attempt de-queueing a task in order to run it...");const b=this.findIdlingWorker();if(!b)return;const g=this.taskQueue.shift();if(!g){this.debug("Task queue is empty"),this.eventSubject.next({type:c.PoolEventType.taskQueueDrained});return}this.run(b,g)}taskCompletion(b){return new Promise((g,T)=>{const y=this.events().subscribe(w=>{w.type===c.PoolEventType.taskCompleted&&w.taskID===b?(y.unsubscribe(),g(w.returnValue)):w.type===c.PoolEventType.taskFailed&&w.taskID===b?(y.unsubscribe(),T(w.error)):w.type===c.PoolEventType.terminated&&(y.unsubscribe(),T(Error("Pool has been terminated before task was run.")))})})}settled(b=!1){return e(this,void 0,void 0,function*(){const g=()=>h(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]):b&&this.taskQueue.length===0?(yield i.allSettled(g()),T):(yield new Promise((w,R)=>{const S=this.eventObservable.subscribe({next(x){x.type===c.PoolEventType.taskQueueDrained&&(S.unsubscribe(),w(void 0))},error:R})}),yield i.allSettled(g()),y.unsubscribe(),T)})}completed(b=!1){return e(this,void 0,void 0,function*(){const g=this.settled(b),T=new Promise((w,R)=>{const S=this.eventObservable.subscribe({next(x){x.type===c.PoolEventType.taskQueueDrained?(S.unsubscribe(),w(g)):x.type===c.PoolEventType.taskFailed&&(S.unsubscribe(),R(x.error))},error:R})}),y=yield Promise.race([g,T]);if(y.length>0)throw y[0]})}events(){return this.eventObservable}queue(b){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:b,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(b){return e(this,void 0,void 0,function*(){this.isClosing=!0,b||(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,b){return new C(m,b)}v.EventType=c.PoolEventType,s.Pool=v}(V)),V}var j={},ne={},Ke;function Kt(){if(Ke)return ne;Ke=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(h){d.error(h),u.onError(h)},next(h){d.next(h),u.onNext(h)}});try{return this.initHasRun=!0,a(l)}catch(h){l.error(h)}}),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 h=!1;return new Promise((p,E)=>{const C=m=>{if(!h){h=!0;try{p(l(m))}catch(b){E(b)}}},v=m=>{try{p(u(m))}catch(b){C(b)}};if(this.initHasRun||this.subscribe({error:C}),this.state==="fulfilled")return p(u(this.firstValue));if(this.state==="rejected")return h=!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=h=>{d.next(h),d.complete()},l=h=>{d.error(h)};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=_.requireCommon(),r=Vt(),i=_.requireTransferable(),o=_.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,h=m=>m&&m.type===o.WorkerMessageType.running;function p(m,b){return new t.Observable(g=>{let T;const y=w=>{if(c("Message from worker:",w.data),!(!w.data||w.data.uid!==b)){if(h(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:b};m.postMessage(w)}m.removeEventListener("message",y)}})}function E(m){if(m.length===0)return{args:[],transferables:[]};const b=[],g=[];for(const T of m)i.isTransferDescriptor(T)?(b.push(n.serialize(T.send)),g.push(...T.transferables)):b.push(n.serialize(T));return{args:b,transferables:g.length===0?g:d(g)}}function C(m,b){return(...g)=>{const T=a++,{args:y,transferables:w}=E(g),R={type:o.MasterMessageType.run,uid:T,method:b,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,b){const g={};for(const T of b)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 x(A){return A instanceof R?A:new R(function(k){k(A)})}return new(R||(R=Promise))(function(A,k){function N(z){try{me(S.next(z))}catch(ge){k(ge)}}function W(z){try{me(S.throw(z))}catch(ge){k(ge)}}function me(z){z.done?A(z.value):x(z.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=_.requireCommon(),i=Kt(),o=_.requireSymbols(),c=$t(),a=qt(),d=t.default("threads:master:messages"),u=t.default("threads:master:spawn"),l=t.default("threads:master:thread-utils"),h=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 x=new Promise((k,N)=>{S=setTimeout(()=>N(Error(R)),w)}),A=yield Promise.race([y,x]);return clearTimeout(S),A})}function v(y){return new Promise((w,R)=>{const S=x=>{d("Message from worker before finishing initialization:",x.data),h(x.data)?(y.removeEventListener("message",S),w(x.data)):p(x.data)&&(y.removeEventListener("message",S),R(r.deserialize(x.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)},x=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",x),w.then(()=>{const A={type:c.WorkerEventType.termination};y.removeEventListener("message",S),y.removeEventListener("unhandledrejection",x),R.next(A),R.complete()})})}function b(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 x=R.filter(A=>A.type===c.WorkerEventType.internalError).map(A=>A.error);return Object.assign(y,{[o.$errors]:x,[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,x=(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}=b(y),N=m(y,A);if(x.type==="function"){const W=a.createProxyFunction(y);return g(W,y,N,k)}else if(x.type==="module"){const W=a.createProxyModule(y,x.methods);return g(W,y,N,k)}else{const W=x.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=zt();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=K&&K.__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=K&&K.__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=_.requireCommon();Object.defineProperty(s,"registerSerializer",{enumerable:!0,get:function(){return n.registerSerializer}}),t(Qt(),s);var r=_.requireWorker();Object.defineProperty(s,"expose",{enumerable:!0,get:function(){return r.expose}});var i=_.requireSerializers();Object.defineProperty(s,"DefaultSerializer",{enumerable:!0,get:function(){return i.DefaultSerializer}});var o=_.requireTransferable();Object.defineProperty(s,"Transfer",{enumerable:!0,get:function(){return o.Transfer}})}(K)),K}var Jt=Yt();const G=_.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,U=(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){U(this,"_handleTerminate"),U(this,"_handleError"),U(this,"_task"),U(this,"id",cn+=1),U(this,"idle",!0),U(this,"worker"),U(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){U(this,"_workerThreads",[]),U(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 hn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,pn=(s,e,t,n)=>{for(var r=n>1?void 0:n?fn(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&&hn(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,"canvasWrapper");L(this,"offscreenCanvas");L(this,"workerThread");var e;this._props=s,this.workerPool=dn(void 0,!!((e=this._props.debug)!=null&&e.enabled))}preventDefaultHandler(s){return s.preventDefault(),{type:s.type}}getScreenSizes(){var s,e,t,n;return{width:(s=this.canvas)==null?void 0:s.width,height:(e=this.canvas)==null?void 0:e.height,wrapperWidth:((t=this.canvasWrapper)==null?void 0:t.clientWidth)??0,wrapperHeight:((n=this.canvasWrapper)==null?void 0:n.clientHeight)??0,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(),..._.U(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(),..._.U(s,["deltaX","deltaY"])}}keyEventHandler(s){if(_.KEYBOARD_EVENT_CODES.includes(s.code))return s.preventDefault(),{...this.getScreenSizes(),..._.U(s,["ctrlKey","metaKey","shiftKey","keyCode"])}}};le=pn([_.scoped(_.Lifecycle.ContainerScoped),mn(0,_.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 _.ProxyEventHandlersBlueprint{constructor(s){super(),this._service=s}init(){let s;try{s=_.instance.resolve("MAIN_THREAD_APP")}catch{s=void 0}for(const e of _.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 _.Subject,_.fromEvent(e==="resize"?window:this._service.canvas,e).pipe(_.map(n=>t.bind(this)(n)),_.filter(n=>!(e==="keydown"&&!n))).subscribe(n=>{this[`${e}$$`].next(n)}),this[`${e}$`]=this[`${e}$$`].asObservable(),this[`${e}$`].subscribe(n=>{var r,i,o,c;(o=(i=(r=this._service.workerThread)==null?void 0:r.thread)==null?void 0:i[e])==null||o.call(i,n),(c=s==null?void 0:s[e])==null||c.call(s,n)})}}};Ae=bn([_.scoped(_.Lifecycle.ContainerScoped),yn(0,_.inject(le))],Ae);function Je(s,e){if(e===f.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),s;if(e===f.TriangleFanDrawMode||e===f.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===f.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 f.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 f.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,f.SRGBColorSpace,n).catch(n)}decodeDracoFile(e,t,n,r,i=f.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 f.BufferGeometry;e.index&&t.setIndex(new f.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 f.BufferAttribute(i,o);else{const u=new f.InterleavedBuffer(i,c);d=new f.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!==f.SRGBColorSpace)return;const n=new f.Color;for(let r=0,i=e.count;r<i;r++)n.fromBufferAttribute(e,r),f.ColorManagement.colorSpaceToWorking(n,f.SRGBColorSpace),e.setXYZ(r,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new f.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,h=new l.Decoder;try{const p=t(l,h,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(h)}});break}};function t(o,c,a,d){const u=d.attributeIDs,l=d.attributeTypes;let h,p;const E=c.GetEncodedGeometryType(a);if(E===o.TRIANGULAR_MESH)h=new o.Mesh,p=c.DecodeArrayToMesh(a,a.byteLength,h);else if(E===o.POINT_CLOUD)h=new o.PointCloud,p=c.DecodeArrayToPointCloud(a,a.byteLength,h);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!p.ok()||h.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 b,g;if(d.useUniqueIDs)g=u[v],b=c.GetAttributeByUniqueId(h,g);else{if(g=c.GetAttributeId(h,o[u[v]]),g===-1)continue;b=c.GetAttribute(h,g)}const T=r(o,c,h,v,m,b);v==="color"&&(T.vertexColorSpace=d.vertexColorSpace),C.attributes.push(T)}return E===o.TRIANGULAR_MESH&&(C.index=n(o,c,h)),o.destroy(h),C}function n(o,c,a){const u=a.num_faces()*3,l=u*4,h=o._malloc(l);c.GetTrianglesUInt32Array(a,l,h);const p=new Uint32Array(o.HEAPF32.buffer,h,u).slice();return o._free(h),{array:p,itemSize:1}}function r(o,c,a,d,u,l){const h=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,b=h*C,g=h*v,T=o._malloc(b);c.GetAttributeDataArrayForAllPoints(a,l,E,b,T);const y=new u(o.HEAPF32.buffer,T,b/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,x=y.length;S<x;S++){for(let A=0;A<p;A++)w[R+A]=y[S*p+A];R+=m}}return o._free(T),{name:d,count:h,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 ht(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 ht(s,e,t){t(s,e);for(let n=0;n<s.children.length;n++)ht(s.children[n],e.children[n],t)}class vn extends f.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new xn(t)}),this.register(function(t){return new Mn(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,M.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new Ze(t,M.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new Un(t)})}load(e,t,n,r){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const d=f.LoaderUtils.extractUrlBase(e);o=f.LoaderUtils.resolveURL(d,this.path)}else o=f.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 f.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))===ft){try{o[M.KHR_BINARY_GLTF]=new Bn(e)}catch(l){r&&r(l);return}i=JSON.parse(o[M.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],h=i.extensionsRequired||[];switch(l){case M.KHR_MATERIALS_UNLIT:o[l]=new Cn;break;case M.KHR_DRACO_MESH_COMPRESSION:o[l]=new Gn(i,this.dracoLoader);break;case M.KHR_TEXTURE_TRANSFORM:o[l]=new Wn;break;case M.KHR_MESH_QUANTIZATION:o[l]=new zn;break;default:h.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 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",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Rn{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 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 f.Color(16777215);a.color!==void 0&&u.setRGB(a.color[0],a.color[1],a.color[2],f.LinearSRGBColorSpace);const l=a.range!==void 0?a.range:0;switch(a.type){case"directional":d=new f.DirectionalLight(u),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new f.PointLight(u),d.distance=l;break;case"spot":d=new f.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=M.KHR_MATERIALS_UNLIT}getMaterialType(){return f.MeshBasicMaterial}extendParams(e,t,n){const r=[];e.color=new f.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],f.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,"map",i.baseColorTexture,f.SRGBColorSpace))}return Promise.all(r)}}class Sn{constructor(e){this.parser=e,this.name=M.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 xn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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 f.Vector2(i,i)}return Promise.all(r)}}class Mn{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_DISPERSION}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=M.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=M.KHR_MATERIALS_SHEEN}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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 f.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],f.LinearSRGBColorSpace)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"sheenColorMap",n.sheenColorTexture,f.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=M.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=M.KHR_MATERIALS_VOLUME}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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 f.Color().setRGB(i[0],i[1],i[2],f.LinearSRGBColorSpace),Promise.all(r)}}class On{constructor(e){this.parser=e,this.name=M.KHR_MATERIALS_IOR}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=M.KHR_MATERIALS_SPECULAR}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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 f.Color().setRGB(i[0],i[1],i[2],f.LinearSRGBColorSpace),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"specularColorMap",n.specularColorTexture,f.SRGBColorSpace)),Promise.all(r)}}class Nn{constructor(e){this.parser=e,this.name=M.EXT_MATERIALS_BUMP}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=M.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return P(this.parser,e,this.name)!==null?f.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=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 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=M.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=M.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,h=new Uint8Array(c,a,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,l,h,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,h,r.mode,r.filter),p})})}else return null}}class Un{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!==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],h=d[0].count,p=[];for(const E of l){const C=new f.Matrix4,v=new f.Vector3,m=new f.Quaternion,b=new f.Vector3(1,1,1),g=new f.InstancedMesh(E.geometry,E.material,h);for(let T=0;T<h;T++)a.TRANSLATION&&v.fromBufferAttribute(a.TRANSLATION,T),a.ROTATION&&m.fromBufferAttribute(a.ROTATION,T),a.SCALE&&b.fromBufferAttribute(a.SCALE,T),g.setMatrixAt(T,C.compose(v,m,b));for(const T in a)if(T==="_COLOR_0"){const y=a[T];g.instanceColor=new f.InstancedBufferAttribute(y.array,y.itemSize,y.normalized)}else T!=="TRANSLATION"&&T!=="ROTATION"&&T!=="SCALE"&&E.geometry.setAttribute(T,a[T]);f.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 ft="glTF",se=12,et={JSON:1313821514,BIN:5130562};class Bn{constructor(e){this.name=M.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!==ft)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=M.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 h=n.accessors[e.attributes[u]],p=Y[h.componentType];d[l]=p.name,a[l]=h.normalized===!0}}return t.getDependency("bufferView",i).then(function(u){return new Promise(function(l,h){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,f.LinearSRGBColorSpace,h)})})}}class Wn{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 zn{constructor(){this.name=M.KHR_MESH_QUANTIZATION}}class pt extends f.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,h=l*l,p=h*l,E=e*d,C=E-d,v=-2*p+3*h,m=p-h,b=1-v,g=m-h+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]=b*y+g*w+v*R+m*S}return i}}const Kn=new f.Quaternion;class $n extends pt{interpolate_(e,t,n,r){const i=super.interpolate_(e,t,n,r);return Kn.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:f.NearestFilter,9729:f.LinearFilter,9984:f.NearestMipmapNearestFilter,9985:f.LinearMipmapNearestFilter,9986:f.NearestMipmapLinearFilter,9987:f.LinearMipmapLinearFilter},nt={33071:f.ClampToEdgeWrapping,33648:f.MirroredRepeatWrapping,10497:f.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"},B={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Vn={CUBICSPLINE:void 0,LINEAR:f.InterpolateLinear,STEP:f.InterpolateDiscrete},Ce={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function qn(s){return s.DefaultMaterial===void 0&&(s.DefaultMaterial=new f.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:f.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 h=l.POSITION!==void 0?t.getDependency("accessor",l.POSITION):s.attributes.position;o.push(h)}if(r){const h=l.NORMAL!==void 0?t.getDependency("accessor",l.NORMAL):s.attributes.normal;c.push(h)}if(i){const h=l.COLOR_0!==void 0?t.getDependency("accessor",l.COLOR_0):s.attributes.color;a.push(h)}}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(a)]).then(function(d){const u=d[0],l=d[1],h=d[2];return n&&(s.morphAttributes.position=u),r&&(s.morphAttributes.normal=l),i&&(s.morphAttributes.color=h),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[M.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 f.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 f.TextureLoader(this.options.manager):this.textureLoader=new f.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new f.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[M.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(i,o){n.load(f.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 f.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,h=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(h/p),b="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+m+":"+r.count;let g=t.cache.get(b);g||(C=new d(c,m*p,r.count*p/u),g=new f.InterleavedBuffer(C,p/u),t.cache.add(b,g)),v=new f.InterleavedBufferAttribute(g,a,h%p/u,E)}else c===null?C=new d(r.count*a):C=new d(c,h,r.count*a),v=new f.BufferAttribute(C,a,E);if(r.sparse!==void 0){const m=Re.SCALAR,b=Y[r.sparse.indices.componentType],g=r.sparse.indices.byteOffset||0,T=r.sparse.values.byteOffset||0,y=new b(o[1],g,r.sparse.count*m),w=new d(o[2],T,r.sparse.count*a);c!==null&&(v=new f.BufferAttribute(v.array.slice(),v.itemSize,v.normalized)),v.normalized=!1;for(let R=0,S=y.length;R<S;R++){const x=y[R];if(v.setX(x,w[R*a]),a>=2&&v.setY(x,w[R*a+1]),a>=3&&v.setZ(x,w[R*a+2]),a>=4&&v.setW(x,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 h=(i.samplers||{})[o.sampler]||{};return u.magFilter=tt[h.magFilter]||f.LinearFilter,u.minFilter=tt[h.minFilter]||f.LinearMipmapLinearFilter,u.wrapS=nt[h.wrapS]||f.RepeatWrapping,u.wrapT=nt[h.wrapT]||f.RepeatWrapping,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==f.NearestFilter&&u.minFilter!==f.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 h=new Blob([l],{type:o.mimeType});return a=c.createObjectURL(h),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(h,p){let E=h;t.isImageBitmapLoader===!0&&(E=function(C){const v=new f.Texture(C);v.needsUpdate=!0,h(v)}),t.load(f.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[M.KHR_TEXTURE_TRANSFORM]){const c=n.extensions!==void 0?n.extensions[M.KHR_TEXTURE_TRANSFORM]:void 0;if(c){const a=i.associations.get(o);o=i.extensions[M.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 f.PointsMaterial,f.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 f.LineBasicMaterial,f.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 f.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[M.KHR_MATERIALS_UNLIT]){const l=r[M.KHR_MATERIALS_UNLIT];o=l.getMaterialType(),d.push(l.extendParams(c,i,t))}else{const l=i.pbrMetallicRoughness||{};if(c.color=new f.Color(1,1,1),c.opacity=1,Array.isArray(l.baseColorFactor)){const h=l.baseColorFactor;c.color.setRGB(h[0],h[1],h[2],f.LinearSRGBColorSpace),c.opacity=h[3]}l.baseColorTexture!==void 0&&d.push(t.assignTexture(c,"map",l.baseColorTexture,f.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(h){return h.getMaterialType&&h.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(h){return h.extendMaterialParams&&h.extendMaterialParams(e,c)})))}i.doubleSided===!0&&(c.side=f.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!==f.MeshBasicMaterial&&(d.push(t.assignTexture(c,"normalMap",i.normalTexture)),c.normalScale=new f.Vector2(1,1),i.normalTexture.scale!==void 0)){const l=i.normalTexture.scale;c.normalScale.set(l,l)}if(i.occlusionTexture!==void 0&&o!==f.MeshBasicMaterial&&(d.push(t.assignTexture(c,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(c.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==f.MeshBasicMaterial){const l=i.emissiveFactor;c.emissive=new f.Color().setRGB(l[0],l[1],l[2],f.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==f.MeshBasicMaterial&&d.push(t.assignTexture(c,"emissiveMap",i.emissiveTexture,f.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=f.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[M.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 h;d.extensions&&d.extensions[M.KHR_DRACO_MESH_COMPRESSION]?h=i(d):h=rt(new f.BufferGeometry,d,t),r[u]={primitive:d,promise:h},o.push(h)}}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 b=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 f.SkinnedMesh(C,b):new f.Mesh(C,b),m.isSkinnedMesh===!0&&m.normalizeSkinWeights(),v.mode===I.TRIANGLE_STRIP?m.geometry=Je(m.geometry,f.TriangleStripDrawMode):v.mode===I.TRIANGLE_FAN&&(m.geometry=Je(m.geometry,f.TriangleFanDrawMode));else if(v.mode===I.LINES)m=new f.LineSegments(C,b);else if(v.mode===I.LINE_STRIP)m=new f.Line(C,b);else if(v.mode===I.LINE_LOOP)m=new f.LineLoop(C,b);else if(v.mode===I.POINTS)m=new f.Points(C,b);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 h=new f.Group;i.extensions&&q(r,h,i),t.associations.set(h,{meshes:e});for(let p=0,E=l.length;p<E;p++)h.add(l[p]);return h})}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 f.PerspectiveCamera(f.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type==="orthographic"&&(t=new f.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 h=new f.Matrix4;i!==null&&h.fromArray(i.array,d*16),a.push(h)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[d])}return new f.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,h=r.channels.length;l<h;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,b=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",b)),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 h=l[0],p=l[1],E=l[2],C=l[3],v=l[4],m=[];for(let g=0,T=h.length;g<T;g++){const y=h[g],w=p[g],R=E[g],S=C[g],x=v[g];if(y===void 0)continue;y.updateMatrix&&y.updateMatrix();const A=n._createAnimationTracks(y,w,R,S,x);if(A)for(let k=0;k<A.length;k++)m.push(A[k])}const b=new f.AnimationClip(i,void 0,m);return D(b,r),b})}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],h=d[2];h!==null&&u.traverse(function(p){p.isSkinnedMesh&&p.bind(h,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 f.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 f.Bone:d.length>1?u=new f.Group:d.length===1?u=d[0]:u=new f.Object3D,u!==d[0])for(let l=0,h=d.length;l<h;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 f.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 f.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 h=a[u];h.parent!==null?i.add(wn(h)):i.add(h)}const d=u=>{const l=new Map;for(const[h,p]of r.associations)(h instanceof f.Material||h instanceof f.Texture)&&l.set(h,p);return u.traverse(h=>{const p=r.associations.get(h);p!=null&&l.set(h,p)}),l};return r.associations=d(i),i})}_createAnimationTracks(e,t,n,r,i){const o=[],c=e.name?e.name:e.uuid,a=[];B[i.path]===B.weights?e.traverse(function(h){h.morphTargetInfluences&&a.push(h.name?h.name:h.uuid)}):a.push(c);let d;switch(B[i.path]){case B.weights:d=f.NumberKeyframeTrack;break;case B.rotation:d=f.QuaternionKeyframeTrack;break;case B.translation:case B.scale:d=f.VectorKeyframeTrack;break;default:switch(n.itemSize){case 1:d=f.NumberKeyframeTrack;break;case 2:case 3:default:d=f.VectorKeyframeTrack;break}break}const u=r.interpolation!==void 0?Vn[r.interpolation]:f.InterpolateLinear,l=this._getArrayFromAccessor(n);for(let h=0,p=a.length;h<p;h++){const E=new d(a[h]+"."+B[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 f.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 f.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 f.Vector3(a[0],a[1],a[2]),new f.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 f.Vector3,a=new f.Vector3;for(let d=0,u=i.length;d<u;d++){const l=i[d];if(l.POSITION!==void 0){const h=t.json.accessors[l.POSITION],p=h.min,E=h.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]))),h.normalized){const C=Pe(Y[h.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 f.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 f.ColorManagement.workingColorSpace!==f.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${f.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 f.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 f.AudioLoader(this.loadingManager),this.loaders.fontLoader=new _.FontLoader(this.loadingManager),this.loaders.gltfLoader=new vn(this.loadingManager),this.loaders.imageLoader=new f.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.5.7/"),(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([_.scoped(_.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 he=class{constructor(s){L(this,"load$$",new _.Subject);L(this,"load$",this.load$$.pipe(_.map(s=>({...s,loadedCount:s.resource?this._service.loadedCount+1:this._service.loadedCount,toLoadCount:this._service.toLoadCount})),_.share()));L(this,"serializedLoad$",this.load$.pipe(_.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=>_.g(c));e={animations:(s==null?void 0:s.resource).animations.map(c=>c.toJSON()),cameras:i.cameras.map(c=>_.g(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={..._.U(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?_.J(s.resource.error,[]):{},played:s.resource.played.length,seekable:s.resource.seekable.length,textTracks:s.resource.textTracks.length}),{...s,resource:e}}),_.share()));L(this,"loadCompleted$",this.load$.pipe(_.filter(s=>s.toLoadCount===s.loadedCount),_.map(()=>_.U(this._service,["loadedCount","loadedResources","toLoadCount"])),_.share()));this._service=s}};he=ar([_.scoped(_.Lifecycle.ContainerScoped),cr(0,_.inject(de))],he);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},xe=(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([_.scoped(_.Lifecycle.ContainerScoped),xe(0,_.inject(he)),xe(1,_.inject(de)),xe(2,_.inject(ie))],Oe);var hr=Object.defineProperty,fr=Object.getOwnPropertyDescriptor,pr=(s,e,t,n)=>{for(var r=n>1?void 0:n?fr(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&&hr(e,t,r),r},Q=(s,e)=>(t,n)=>e(t,n,s);exports.RegisterModule=class extends _.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(){var t;return this.props.mainThread?self:(t=this._service.workerThread)==null?void 0:t.worker}async _initCanvas(){var t;try{this._service.canvas=this.props.canvas instanceof HTMLCanvasElement?this.props.canvas:void 0,this._service.canvas||(this._service.canvas=document.createElement("canvas"),this._service.canvas.dataset.reactive="true",document.body.appendChild(this._service.canvas)),this._service.canvasWrapper=this.props.canvasWrapper instanceof HTMLElement?this.props.canvasWrapper:this.props.canvasWrapper==="parent"?((t=this.props.canvas)==null?void 0:t.parentElement)??void 0:void 0}catch(n){console.error(`🛑 Unable to initialize the canvas:
|
|
4
|
+
${n instanceof Error?n.message:"Something went wrong"}`)}}async _initEvents(){if(!this._service.canvas)throw new Error("Canvas element is not initialized.");this._controller.init(),this.props.mainThread||this._subscriptions.push(this._controller.resize$.subscribe(i=>{const o=this._service.canvas;if(!this.props.autoRenderResize||!o)return;const c=this._service.canvasWrapper,a=this.props.fullScreen,d=a?i.windowWidth:c?i.wrapperWidth:i.width,u=a?i.windowHeight:c?i.wrapperHeight:i.height;o.style.width=d+"px",o.style.height=u+"px"}));const t=this._service.canvas,n=this._service.canvasWrapper,r=new UIEvent("resize");r.width=(t==null?void 0:t.width)??0,r.height=(t==null?void 0:t.height)??0,r.wrapperWidth=(n==null?void 0:n.clientWidth)??0,r.wrapperHeight=(n==null?void 0:n.clientHeight)??0,r.windowWidth=window.innerWidth,r.windowHeight=window.innerHeight,this._controller.resize$$.next(this._service.uiEventHandler(r))}async _initCore(){const t={..._.J(this.props,["canvas","canvasWrapper","location","onReady","loaderDataSources"]),pixelRatio:this.props.pixelRatio,initApp:!0,hasCanvasWrapper:!!this.props.canvasWrapper};if(this.props.mainThread){await import(`${this.props.location}`),await new Promise(o=>{const c=a=>{a.data.mainThread&&(o(),self.removeEventListener("message",c))};self.addEventListener("message",c),self.postMessage(t)});return}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 n={...t,canvas:this._service.offscreenCanvas},[r,i]=await this._service.workerPool.run({payload:{path:this.props.location,subject:n,transferSubject:[this._service.offscreenCanvas]}})||[];if(!r||i)throw new Error("Unable to retrieve the worker-thread info.");this._service.workerThread=r}async _initObservables(){_.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:_.LOADER_SERIALIZED_LOAD_TOKEN,payload:t})}))}async init(){var t,n;this._initialized||(this._initialized=!0,await this._initCanvas(),await this._initCore(),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}getWorkerThread(){return this._service.workerThread}getWorkerPool(){return this._service.workerPool}getProps(){return this.props}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([_.scoped(_.Lifecycle.ContainerScoped),Q(0,_.inject(le)),Q(1,_.inject(Ae)),Q(2,_.inject(he)),Q(3,_.inject(_.CONTAINER_TOKEN)),Q(4,_.inject(ie)),Q(5,_.inject(Oe))],exports.RegisterModule);const mr=s=>{var n;if(!(s!=null&&s.location)||!URL.canParse(s.location))throw new Error("Invalid register props detected. location path is required");const e=_.instance.createChildContainer();s.initOnConstruct=_.N(s.initOnConstruct)||!_.D(s.initOnConstruct)?!0:s.initOnConstruct,s.defaultCamera=s!=null&&s.defaultCamera&&s.defaultCamera in _.DefaultCameraType?s.defaultCamera:_.DefaultCameraType.PERSPECTIVE,s.fullScreen=_.N(s.fullScreen)||!_.D(s.fullScreen)?!0:s.fullScreen,s.autoRenderResize=_.N(s.autoRenderResize)||!_.D(s.autoRenderResize)?!0:s.autoRenderResize,s.startTimer=_.N(s.startTimer)||!_.D(s.startTimer)?!0:s.startTimer,s.pixelRatio=_.N(s.pixelRatio)||!_.R(s.pixelRatio)?Math.min(window.devicePixelRatio,2):s.pixelRatio,s.onReady=_.E(s.onReady)?s.onReady:void 0,s.debug&&(s.debug.withMiniCamera=_.N((n=s.debug)==null?void 0:n.withMiniCamera)||!_.D(s.debug.withMiniCamera)?!1:s.debug.withMiniCamera,s.debug.enableControls=_.N(s.debug.enableControls)||!_.D(s.debug.enableControls)?!1:s.debug.enableControls,s.debug.axesSizes=_.N(s.debug.axesSizes)||!_.R(s.debug.axesSizes)?void 0:s.debug.axesSizes),e.register(_.CONTAINER_TOKEN,{useValue:e}),e.register(ie,{useValue:s});const t=e.resolve(exports.RegisterModule);return{container:e,module:t}};exports.AppProxyEventHandlersBlueprint=_.AppProxyEventHandlersBlueprint;exports.CONTAINER_TOKEN=_.CONTAINER_TOKEN;exports.DefaultCameraType=_.DefaultCameraType;exports.KEYBOARD_EVENT_CODES=_.KEYBOARD_EVENT_CODES;exports.LOADER_SERIALIZED_LOAD_TOKEN=_.LOADER_SERIALIZED_LOAD_TOKEN;exports.PROXY_EVENT_LISTENERS=_.PROXY_EVENT_LISTENERS;exports.ProxyEventHandlersBlueprint=_.ProxyEventHandlersBlueprint;exports.ProxyEventObservablesBlueprint=_.ProxyEventObservablesBlueprint;exports.ProxyEventSubjectsBlueprint=_.ProxyEventSubjectsBlueprint;exports.RegisterProxyEventHandlersBlueprint=_.RegisterProxyEventHandlersBlueprint;exports.LaunchAppProps=_t;exports.RegisterPropsBlueprint=ie;exports.register=mr;
|