@thatopen/components 3.3.2 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,4 @@
1
- "use strict";var t=Object.defineProperty,e=(e,i,s)=>(((e,i,s)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s})(e,"symbol"!=typeof i?i+"":i,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@thatopen/fragments"),s=require("three"),n=require("web-ifc");function r(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const o=r(i),a=r(s),l=r(n);class h{constructor(){e(this,"enabled",!0),e(this,"trigger",t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class c{constructor(t){e(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),e(this,"isResizeable",()=>"resize"in this&&"getSize"in this),e(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),e(this,"isHideable",()=>"visible"in this),e(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),e(this,"isSerializable",()=>"import"in this&&"export"in this),this.components=t}}class d extends c{}class u extends c{constructor(t){super(t),e(this,"worlds",new i.DataMap),e(this,"onWorldChanged",new h),e(this,"_currentWorld",null),this.onWorldChanged.add(({world:t,action:e})=>{"removed"===e&&this.worlds.delete(t.uuid)})}set currentWorld(t){this._currentWorld=t}get currentWorld(){return this._currentWorld}}class p extends u{constructor(){super(...arguments),e(this,"hasCameraControls",()=>"controls"in this)}}class f extends u{constructor(){super(...arguments),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"onResize",new h),e(this,"onClippingPlanesUpdated",new h),e(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i){e.isLocal=i;const s=this.clippingPlanes.indexOf(e);t&&-1===s?this.clippingPlanes.push(e):!t&&s>-1&&this.clippingPlanes.splice(s,1),this.three.clippingPlanes=this.clippingPlanes.filter(t=>!t.isLocal)}}const m=class t extends d{constructor(i){super(i),e(this,"_disposedComponents",new Set),e(this,"enabled",!0),i.add(t.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const s=t;s.dispose&&s.dispose(),this.disposeGeometryAndMaterials(t,e),i&&s.children&&s.children.length&&this.disposeChildren(s),t.children.length=0}disposeGeometry(t){t.boundsTree&&t.disposeBoundsTree&&t.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(e,i){const s=e;s.geometry&&this.disposeGeometry(s.geometry),i&&s.material&&t.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};e(m,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let g=m;class _ extends u{constructor(t){super(t),e(this,"onDisposed",new h),e(this,"directionalLights",new Map),e(this,"ambientLights",new Map)}dispose(){const t=this.components.get(g);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,t]of this.directionalLights)t.removeFromParent(),t.target.removeFromParent(),t.dispose();this.directionalLights.clear();for(const[,t]of this.ambientLights)t.removeFromParent(),t.dispose();this.ambientLights.clear()}}class y extends Set{constructor(t){super(t),e(this,"onItemAdded",new h),e(this,"onItemDeleted",new h),e(this,"onCleared",new h),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}add(...t){for(const e of t){if(this.has(e))continue;this.guard(e)&&(super.add(e),this.onItemAdded||(this.onItemAdded=new h),this.onItemAdded.trigger(e))}return this}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(),e}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}const w=class t{static create(){const e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return`${t._lut[255&e]+t._lut[e>>8&255]+t._lut[e>>16&255]+t._lut[e>>24&255]}-${t._lut[255&i]}${t._lut[i>>8&255]}-${t._lut[i>>16&15|64]}${t._lut[i>>24&255]}-${t._lut[63&s|128]}${t._lut[s>>8&255]}-${t._lut[s>>16&255]}${t._lut[s>>24&255]}${t._lut[255&n]}${t._lut[n>>8&255]}${t._lut[n>>16&255]}${t._lut[n>>24&255]}`.toLowerCase()}static validate(e){if(!t._pattern.test(e))throw new Error(`${e} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};e(w,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),e(w,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let v=w;var b="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function x(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var T={},C={};!function(t){const e=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",i="["+e+"]["+(e+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*",s=new RegExp("^"+i+"$");t.isExist=function(t){return void 0!==t},t.isEmptyObject=function(t){return 0===Object.keys(t).length},t.merge=function(t,e,i){if(e){const s=Object.keys(e),n=s.length;for(let r=0;r<n;r++)t[s[r]]="strict"===i?[e[s[r]]]:e[s[r]]}},t.getValue=function(e){return t.isExist(e)?e:""},t.isName=function(t){const e=s.exec(t);return!(null==e)},t.getAllMatches=function(t,e){const i=[];let s=e.exec(t);for(;s;){const n=[];n.startIndex=e.lastIndex-s[0].length;const r=s.length;for(let t=0;t<r;t++)n.push(s[t]);i.push(n),s=e.exec(t)}return i},t.nameRegexp=i}(C);const E=C,S={allowBooleanAttributes:!1,unpairedTags:[]};function A(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function O(t,e){const i=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const s=t.substr(i,e-i);if(e>5&&"xml"===s)return N("InvalidXml","XML declaration allowed only at the start of the document.",R(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function P(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&(i--,0===i))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}T.validate=function(t,e){e=Object.assign({},S,e);const i=[];let s=!1,n=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=O(t,r),r.err)return r}else{if("<"!==t[r]){if(A(t[r]))continue;return N("InvalidChar","char '"+t[r]+"' is not expected.",R(t,r))}{let o=r;if(r++,"!"===t[r]){r=P(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let l="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)l+=t[r];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),r--),!L(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",N("InvalidTag",e,R(t,r))}const h=D(t,r);if(!1===h)return N("InvalidAttr","Attributes for '"+l+"' have open quote.",R(t,r));let c=h.value;if(r=h.index,"/"===c[c.length-1]){const i=r-c.length;c=c.substring(0,c.length-1);const n=z(c,e);if(!0!==n)return N(n.err.code,n.err.msg,R(t,i+n.err.line));s=!0}else if(a){if(!h.tagClosed)return N("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",R(t,r));if(c.trim().length>0)return N("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",R(t,o));if(0===i.length)return N("InvalidTag","Closing tag '"+l+"' has not been opened.",R(t,o));{const e=i.pop();if(l!==e.tagName){let i=R(t,e.tagStartPos);return N("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+i.line+", col "+i.col+") instead of closing tag '"+l+"'.",R(t,o))}0==i.length&&(n=!0)}}else{const a=z(c,e);if(!0!==a)return N(a.err.code,a.err.msg,R(t,r-c.length+a.err.line));if(!0===n)return N("InvalidXml","Multiple possible root nodes found.",R(t,r));-1!==e.unpairedTags.indexOf(l)||i.push({tagName:l,tagStartPos:o}),s=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=P(t,r);continue}if("?"!==t[r+1])break;if(r=O(t,++r),r.err)return r}else if("&"===t[r]){const e=B(t,r);if(-1==e)return N("InvalidChar","char '&' is not expected.",R(t,r));r=e}else if(!0===n&&!A(t[r]))return N("InvalidXml","Extra text at the end",R(t,r));"<"===t[r]&&r--}}}return s?1==i.length?N("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",R(t,i[0].tagStartPos)):!(i.length>0)||N("InvalidXml","Invalid '"+JSON.stringify(i.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):N("InvalidXml","Start tag expected.",1)};const I='"',M="'";function D(t,e){let i="",s="",n=!1;for(;e<t.length;e++){if(t[e]===I||t[e]===M)""===s?s=t[e]:s!==t[e]||(s="");else if(">"===t[e]&&""===s){n=!0;break}i+=t[e]}return""===s&&{value:i,index:e,tagClosed:n}}const k=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function z(t,e){const i=E.getAllMatches(t,k),s={};for(let t=0;t<i.length;t++){if(0===i[t][1].length)return N("InvalidAttr","Attribute '"+i[t][2]+"' has no space in starting.",F(i[t]));if(void 0!==i[t][3]&&void 0===i[t][4])return N("InvalidAttr","Attribute '"+i[t][2]+"' is without value.",F(i[t]));if(void 0===i[t][3]&&!e.allowBooleanAttributes)return N("InvalidAttr","boolean attribute '"+i[t][2]+"' is not allowed.",F(i[t]));const n=i[t][2];if(!U(n))return N("InvalidAttr","Attribute '"+n+"' is an invalid name.",F(i[t]));if(s.hasOwnProperty(n))return N("InvalidAttr","Attribute '"+n+"' is repeated.",F(i[t]));s[n]=1}return!0}function B(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);let i=0;for(;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function N(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function U(t){return E.isName(t)}function L(t){return E.isName(t)}function R(t,e){const i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function F(t){return t.startIndex+t[1].length}var V={};const j={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t}};V.buildOptions=function(t){return Object.assign({},j,t)},V.defaultOptions=j;const H=C;function Z(t,e){let i="";for(;e<t.length&&"'"!==t[e]&&'"'!==t[e];e++)i+=t[e];if(i=i.trim(),-1!==i.indexOf(" "))throw new Error("External entites are not supported");const s=t[e++];let n="";for(;e<t.length&&t[e]!==s;e++)n+=t[e];return[i,n,e]}function $(t,e){return"!"===t[e+1]&&"-"===t[e+2]&&"-"===t[e+3]}function W(t,e){return"!"===t[e+1]&&"E"===t[e+2]&&"N"===t[e+3]&&"T"===t[e+4]&&"I"===t[e+5]&&"T"===t[e+6]&&"Y"===t[e+7]}function Y(t,e){return"!"===t[e+1]&&"E"===t[e+2]&&"L"===t[e+3]&&"E"===t[e+4]&&"M"===t[e+5]&&"E"===t[e+6]&&"N"===t[e+7]&&"T"===t[e+8]}function G(t,e){return"!"===t[e+1]&&"A"===t[e+2]&&"T"===t[e+3]&&"T"===t[e+4]&&"L"===t[e+5]&&"I"===t[e+6]&&"S"===t[e+7]&&"T"===t[e+8]}function X(t,e){return"!"===t[e+1]&&"N"===t[e+2]&&"O"===t[e+3]&&"T"===t[e+4]&&"A"===t[e+5]&&"T"===t[e+6]&&"I"===t[e+7]&&"O"===t[e+8]&&"N"===t[e+9]}function q(t){if(H.isName(t))return t;throw new Error(`Invalid entity name ${t}`)}const Q=/^[-+]?0x[a-fA-F0-9]+$/,K=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,J={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const tt=C,et=class{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child})}},it=function(t,e){const i={};if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let s=1,n=!1,r=!1,o="";for(;e<t.length;e++)if("<"!==t[e]||r)if(">"===t[e]){if(r?"-"===t[e-1]&&"-"===t[e-2]&&(r=!1,s--):s--,0===s)break}else"["===t[e]?n=!0:o+=t[e];else{if(n&&W(t,e))e+=7,[entityName,val,e]=Z(t,e+1),-1===val.indexOf("&")&&(i[q(entityName)]={regx:RegExp(`&${entityName};`,"g"),val:val});else if(n&&Y(t,e))e+=8;else if(n&&G(t,e))e+=8;else if(n&&X(t,e))e+=9;else{if(!$)throw new Error("Invalid DOCTYPE");r=!0}s++,o=""}if(0!==s)throw new Error("Unclosed DOCTYPE")}return{entities:i,i:e}},st=function(t,e={}){if(e=Object.assign({},J,e),!t||"string"!=typeof t)return t;let i=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===t)return 0;if(e.hex&&Q.test(i))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(i,16);if(-1!==i.search(/[eE]/)){const s=i.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)$/);if(s){if(e.leadingZeros)i=(s[1]||"")+s[3];else if("0"!==s[2]||"."!==s[3][0])return t;return e.eNotation?Number(i):t}return t}{const s=K.exec(i);if(s){const n=s[1],r=s[2];let o=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substr(0,t.length-1)),t;return t}(s[3]);if(!e.leadingZeros&&r.length>0&&n&&"."!==i[2])return t;if(!e.leadingZeros&&r.length>0&&!n&&"."!==i[1])return t;if(e.leadingZeros&&r===t)return 0;{const s=Number(i),a=""+s;return-1!==a.search(/[eE]/)?e.eNotation?s:t:-1!==i.indexOf(".")?"0"===a&&""===o||a===o||n&&a==="-"+o?s:t:r?o===a||n+o===a?s:t:i===a||i===n+a?s:t}}return t}};function nt(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];this.lastEntities[s]={regex:new RegExp("&"+s+";","g"),val:t[s]}}}function rt(t,e,i,s,n,r,o){if(void 0!==t&&(this.options.trimValues&&!s&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t));const s=this.options.tagValueProcessor(e,t,i,n,r);if(null==s)return t;if(typeof s!=typeof t||s!==t)return s;if(this.options.trimValues)return _t(t,this.options.parseTagValue,this.options.numberParseOptions);return t.trim()===t?_t(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function ot(t){if(this.options.removeNSPrefix){const e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}const at=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function lt(t,e,i){if(!this.options.ignoreAttributes&&"string"==typeof t){const i=tt.getAllMatches(t,at),s=i.length,n={};for(let t=0;t<s;t++){const s=this.resolveNameSpace(i[t][1]);let r=i[t][4],o=this.options.attributeNamePrefix+s;if(s.length)if(this.options.transformAttributeName&&(o=this.options.transformAttributeName(o)),"__proto__"===o&&(o="#__proto__"),void 0!==r){this.options.trimValues&&(r=r.trim()),r=this.replaceEntitiesValue(r);const t=this.options.attributeValueProcessor(s,r,e);n[o]=null==t?r:typeof t!=typeof r||t!==r?t:_t(r,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(n[o]=!0)}if(!Object.keys(n).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=n,t}return n}}const ht=function(t){t=t.replace(/\r\n?/g,"\n");const e=new et("!xml");let i=e,s="",n="";for(let r=0;r<t.length;r++){if("<"===t[r])if("/"===t[r+1]){const e=ft(t,">",r,"Closing Tag is not closed.");let o=t.substring(r+2,e).trim();if(this.options.removeNSPrefix){const t=o.indexOf(":");-1!==t&&(o=o.substr(t+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),i&&(s=this.saveTextToParentTag(s,i,n));const a=n.substring(n.lastIndexOf(".")+1);if(o&&-1!==this.options.unpairedTags.indexOf(o))throw new Error(`Unpaired tag can not be used as closing tag: </${o}>`);let l=0;a&&-1!==this.options.unpairedTags.indexOf(a)?(l=n.lastIndexOf(".",n.lastIndexOf(".")-1),this.tagsNodeStack.pop()):l=n.lastIndexOf("."),n=n.substring(0,l),i=this.tagsNodeStack.pop(),s="",r=e}else if("?"===t[r+1]){let e=mt(t,r,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(s=this.saveTextToParentTag(s,i,n),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new et(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,n,e.tagName)),this.addChild(i,t,n)}r=e.closeIndex+1}else if("!--"===t.substr(r+1,3)){const e=ft(t,"--\x3e",r+4,"Comment is not closed.");if(this.options.commentPropName){const o=t.substring(r+4,e-2);s=this.saveTextToParentTag(s,i,n),i.add(this.options.commentPropName,[{[this.options.textNodeName]:o}])}r=e}else if("!D"===t.substr(r+1,2)){const e=it(t,r);this.docTypeEntities=e.entities,r=e.i}else if("!["===t.substr(r+1,2)){const e=ft(t,"]]>",r,"CDATA is not closed.")-2,o=t.substring(r+9,e);s=this.saveTextToParentTag(s,i,n);let a=this.parseTextData(o,i.tagname,n,!0,!1,!0,!0);null==a&&(a=""),this.options.cdataPropName?i.add(this.options.cdataPropName,[{[this.options.textNodeName]:o}]):i.add(this.options.textNodeName,a),r=e+2}else{let o=mt(t,r,this.options.removeNSPrefix),a=o.tagName;const l=o.rawTagName;let h=o.tagExp,c=o.attrExpPresent,d=o.closeIndex;this.options.transformTagName&&(a=this.options.transformTagName(a)),i&&s&&"!xml"!==i.tagname&&(s=this.saveTextToParentTag(s,i,n,!1));const u=i;if(u&&-1!==this.options.unpairedTags.indexOf(u.tagname)&&(i=this.tagsNodeStack.pop(),n=n.substring(0,n.lastIndexOf("."))),a!==e.tagname&&(n+=n?"."+a:a),this.isItStopNode(this.options.stopNodes,n,a)){let e="";if(h.length>0&&h.lastIndexOf("/")===h.length-1)"/"===a[a.length-1]?(a=a.substr(0,a.length-1),n=n.substr(0,n.length-1),h=a):h=h.substr(0,h.length-1),r=o.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(a))r=o.closeIndex;else{const i=this.readStopNodeData(t,l,d+1);if(!i)throw new Error(`Unexpected end of ${l}`);r=i.i,e=i.tagContent}const s=new et(a);a!==h&&c&&(s[":@"]=this.buildAttributesMap(h,n,a)),e&&(e=this.parseTextData(e,a,n,!0,c,!0,!0)),n=n.substr(0,n.lastIndexOf(".")),s.add(this.options.textNodeName,e),this.addChild(i,s,n)}else{if(h.length>0&&h.lastIndexOf("/")===h.length-1){"/"===a[a.length-1]?(a=a.substr(0,a.length-1),n=n.substr(0,n.length-1),h=a):h=h.substr(0,h.length-1),this.options.transformTagName&&(a=this.options.transformTagName(a));const t=new et(a);a!==h&&c&&(t[":@"]=this.buildAttributesMap(h,n,a)),this.addChild(i,t,n),n=n.substr(0,n.lastIndexOf("."))}else{const t=new et(a);this.tagsNodeStack.push(i),a!==h&&c&&(t[":@"]=this.buildAttributesMap(h,n,a)),this.addChild(i,t,n),i=t}s="",r=d}}else s+=t[r]}return e.child};function ct(t,e,i){const s=this.options.updateTag(e.tagname,i,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e)):t.addChild(e))}const dt=function(t){if(this.options.processEntities){for(let e in this.docTypeEntities){const i=this.docTypeEntities[e];t=t.replace(i.regx,i.val)}for(let e in this.lastEntities){const i=this.lastEntities[e];t=t.replace(i.regex,i.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){const i=this.htmlEntities[e];t=t.replace(i.regex,i.val)}t=t.replace(this.ampEntity.regex,this.ampEntity.val)}return t};function ut(t,e,i,s){return t&&(void 0===s&&(s=0===Object.keys(e.child).length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,s))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function pt(t,e,i){const s="*."+i;for(const i in t){const n=t[i];if(s===n||e===n)return!0}return!1}function ft(t,e,i,s){const n=t.indexOf(e,i);if(-1===n)throw new Error(s);return n+e.length-1}function mt(t,e,i,s=">"){const n=function(t,e,i=">"){let s,n="";for(let r=e;r<t.length;r++){let e=t[r];if(s)e===s&&(s="");else if('"'===e||"'"===e)s=e;else if(e===i[0]){if(!i[1])return{data:n,index:r};if(t[r+1]===i[1])return{data:n,index:r}}else"\t"===e&&(e=" ");n+=e}}(t,e+1,s);if(!n)return;let r=n.data;const o=n.index,a=r.search(/\s/);let l=r,h=!0;-1!==a&&(l=r.substring(0,a),r=r.substring(a+1).trimStart());const c=l;if(i){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),h=l!==n.data.substr(t+1))}return{tagName:l,tagExp:r,closeIndex:o,attrExpPresent:h,rawTagName:c}}function gt(t,e,i){const s=i;let n=1;for(;i<t.length;i++)if("<"===t[i])if("/"===t[i+1]){const r=ft(t,">",i,`${e} is not closed`);if(t.substring(i+2,r).trim()===e&&(n--,0===n))return{tagContent:t.substring(s,i),i:r};i=r}else if("?"===t[i+1]){i=ft(t,"?>",i+1,"StopNode is not closed.")}else if("!--"===t.substr(i+1,3)){i=ft(t,"--\x3e",i+3,"StopNode is not closed.")}else if("!["===t.substr(i+1,2)){i=ft(t,"]]>",i,"StopNode is not closed.")-2}else{const s=mt(t,i,">");if(s){(s&&s.tagName)===e&&"/"!==s.tagExp[s.tagExp.length-1]&&n++,i=s.closeIndex}}}function _t(t,e,i){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&st(t,i)}return tt.isExist(t)?t:""}var yt=class{constructor(t){this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>String.fromCharCode(Number.parseInt(e,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>String.fromCharCode(Number.parseInt(e,16))}},this.addExternalEntities=nt,this.parseXml=ht,this.parseTextData=rt,this.resolveNameSpace=ot,this.buildAttributesMap=lt,this.isItStopNode=pt,this.replaceEntitiesValue=dt,this.readStopNodeData=gt,this.saveTextToParentTag=ut,this.addChild=ct}},wt={};function vt(t,e,i){let s;const n={};for(let r=0;r<t.length;r++){const o=t[r],a=bt(o);let l="";if(l=void 0===i?a:i+"."+a,a===e.textNodeName)void 0===s?s=o[a]:s+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=vt(o[a],e,l);const i=Tt(t,e);o[":@"]?xt(t,o[":@"],l,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==n[a]&&n.hasOwnProperty(a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(t)):e.isArray(a,l,i)?n[a]=[t]:n[a]=t}}}return"string"==typeof s?s.length>0&&(n[e.textNodeName]=s):void 0!==s&&(n[e.textNodeName]=s),n}function bt(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const i=e[t];if(":@"!==i)return i}}function xt(t,e,i,s){if(e){const n=Object.keys(e),r=n.length;for(let o=0;o<r;o++){const r=n[o];s.isArray(r,i+"."+r,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function Tt(t,e){const{textNodeName:i}=e,s=Object.keys(t).length;return 0===s||!(1!==s||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}wt.prettify=function(t,e){return vt(t,e)};const{buildOptions:Ct}=V,Et=yt,{prettify:St}=wt,At=T;var Ot=class{constructor(t){this.externalEntities={},this.options=Ct(t)}parse(t,e){if("string"==typeof t);else{if(!t.toString)throw new Error("XML data is accepted in String or Bytes[] form.");t=t.toString()}if(e){!0===e&&(e={});const i=At.validate(t,e);if(!0!==i)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const i=new Et(this.options);i.addExternalEntities(this.externalEntities);const s=i.parseXml(t);return this.options.preserveOrder||void 0===s?s:St(s,this.options)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}};function Pt(t,e,i,s){let n="",r=!1;for(let o=0;o<t.length;o++){const a=t[o],l=It(a);if(void 0===l)continue;let h="";if(h=0===i.length?l:`${i}.${l}`,l===e.textNodeName){let t=a[l];Dt(h,e)||(t=e.tagValueProcessor(l,t),t=kt(t,e)),r&&(n+=s),n+=t,r=!1;continue}if(l===e.cdataPropName){r&&(n+=s),n+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,r=!1;continue}if(l===e.commentPropName){n+=s+`\x3c!--${a[l][0][e.textNodeName]}--\x3e`,r=!0;continue}if("?"===l[0]){const t=Mt(a[":@"],e),i="?xml"===l?"":s;let o=a[l][0][e.textNodeName];o=0!==o.length?" "+o:"",n+=i+`<${l}${o}${t}?>`,r=!0;continue}let c=s;""!==c&&(c+=e.indentBy);const d=s+`<${l}${Mt(a[":@"],e)}`,u=Pt(a[l],e,h,c);-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?n+=d+">":n+=d+"/>":u&&0!==u.length||!e.suppressEmptyNode?u&&u.endsWith(">")?n+=d+`>${u}${s}</${l}>`:(n+=d+">",u&&""!==s&&(u.includes("/>")||u.includes("</"))?n+=s+e.indentBy+u+s:n+=u,n+=`</${l}>`):n+=d+"/>",r=!0}return n}function It(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(t.hasOwnProperty(s)&&":@"!==s)return s}}function Mt(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!t.hasOwnProperty(s))continue;let n=e.attributeValueProcessor(s,t[s]);n=kt(n,e),!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function Dt(t,e){let i=(t=t.substr(0,t.length-e.textNodeName.length-1)).substr(t.lastIndexOf(".")+1);for(let s in e.stopNodes)if(e.stopNodes[s]===t||e.stopNodes[s]==="*."+i)return!0;return!1}function kt(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const zt=function(t,e){let i="";return e.format&&e.indentBy.length>0&&(i="\n"),Pt(t,e,"",i)},Bt={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function Nt(t){this.options=Object.assign({},Bt,t),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Rt),this.processTextOrObjNode=Ut,this.options.format?(this.indentate=Lt,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function Ut(t,e,i){const s=this.j2x(t,i+1);return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,s.attrStr,i):this.buildObjectNode(s.val,e,s.attrStr,i)}function Lt(t){return this.options.indentBy.repeat(t)}function Rt(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}Nt.prototype.build=function(t){return this.options.preserveOrder?zt(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0).val)},Nt.prototype.j2x=function(t,e){let i="",s="";for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))if(void 0===t[n])this.isAttribute(n)&&(s+="");else if(null===t[n])this.isAttribute(n)?s+="":"?"===n[0]?s+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+n+"/"+this.tagEndChar;else if(t[n]instanceof Date)s+=this.buildTextValNode(t[n],n,"",e);else if("object"!=typeof t[n]){const r=this.isAttribute(n);if(r)i+=this.buildAttrPairStr(r,""+t[n]);else if(n===this.options.textNodeName){let e=this.options.tagValueProcessor(n,""+t[n]);s+=this.replaceEntitiesValue(e)}else s+=this.buildTextValNode(t[n],n,"",e)}else if(Array.isArray(t[n])){const i=t[n].length;let r="",o="";for(let a=0;a<i;a++){const i=t[n][a];if(void 0===i);else if(null===i)"?"===n[0]?s+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+n+"/"+this.tagEndChar;else if("object"==typeof i)if(this.options.oneListGroup){const t=this.j2x(i,e+1);r+=t.val,this.options.attributesGroupName&&i.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(i,n,e);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(n,i);t=this.replaceEntitiesValue(t),r+=t}else r+=this.buildTextValNode(i,n,"",e)}this.options.oneListGroup&&(r=this.buildObjectNode(r,n,o,e)),s+=r}else if(this.options.attributesGroupName&&n===this.options.attributesGroupName){const e=Object.keys(t[n]),s=e.length;for(let r=0;r<s;r++)i+=this.buildAttrPairStr(e[r],""+t[n][e[r]])}else s+=this.processTextOrObjNode(t[n],n,e);return{attrStr:i,val:s}},Nt.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},Nt.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+r+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+r+">"+t+n}},Nt.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},Nt.prototype.buildTextValNode=function(t,e,i,s){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(s)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},Nt.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};var Ft={XMLParser:Ot,XMLValidator:T,XMLBuilder:Nt};class Vt{}e(Vt,"parser",new Ft.XMLParser({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0})),e(Vt,"builder",new Ft.XMLBuilder({attributeNamePrefix:"$",ignoreAttributes:!1,suppressBooleanAttributes:!1}));class jt{static join(t){const e={};for(const i of t)for(const t in i)if(e[t])for(const s of i[t])e[t].add(s);else e[t]=new Set(i[t]);return e}static intersect(t){if(0===t.length)return{};let e=jt.clone(t[0]);for(let i=1;i<t.length;i++){const s=t[i],n={};for(const t in e)if(s[t]){const i=new Set;for(const n of e[t])s[t].has(n)&&i.add(n);i.size>0&&(n[t]=i)}e=n}return e}static clone(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}static remove(t,e,i=!1){i&&(t=jt.clone(t));for(const i in e)if(t[i]){for(const s of e[i])t[i].delete(s);0===t[i].size&&delete t[i]}}static add(t,e,i=!1){i&&(t=jt.clone(t));for(const i in e)if(t[i])for(const s of e[i])t[i].add(s);else t[i]=new Set(e[i])}static append(t,e,...i){let s=t[e];s||(s=new Set,t[e]=s);for(const t of i)s.add(t)}static isEqual(t,e){const i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length)return!1;for(const s of i){if(!e[s])return!1;if(t[s].size!==e[s].size)return!1;for(const i of t[s])if(!e[s].has(i))return!1}return!0}static isEmpty(t){return 0===Object.values(t).reduce((t,e)=>t+e.size,0)}static toRaw(t){const e={};for(const i in t)e[i]=Array.from(t[i]);return e}static fromRaw(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}}class Ht extends Map{constructor(t){super(t),e(this,"onItemSet",new h),e(this,"onItemUpdated",new h),e(this,"onItemDeleted",new h),e(this,"onCleared",new h),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}set(t,e){const i=this.has(t);if(!(this.guard??(()=>!0))(t,e))return this;const s=super.set(t,e);return i?(this.onItemUpdated||(this.onItemUpdated=new h),this.onItemUpdated.trigger({key:t,value:e})):(this.onItemSet||(this.onItemSet=new h),this.onItemSet.trigger({key:t,value:e})),s}add(t){const e=v.create();return this.set(e,t),e}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(t),e}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Zt{static isEntry(t){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(t.type)}static copySchema(t,e={}){for(const i in t){const s=t[i];this.isEntry(s)?e[i]=this.copyEntry(s):(e[i]={},this.copySchema(s,e[i]))}return e}static copyEntry(t){if("Boolean"===t.type){const e=t;return{type:e.type,value:e.value}}if("Color"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("Text"===t.type){const e=t;return{type:e.type,value:e.value}}if("Number"===t.type){const e=t;return{type:e.type,value:e.value,min:e.min,max:e.max,interpolable:e.interpolable}}if("Select"===t.type){const e=t;return{type:e.type,value:e.value,multiple:e.multiple,options:new Set(e.options)}}if("Vector3"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("TextSet"===t.type){const e=t;return{type:e.type,value:new Set(e.value)}}if("None"===t.type){const e=t;return{type:e.type,value:e.value}}throw new Error("Invalid entry!")}}class $t{constructor(t,i,s,n){e(this,"_component"),e(this,"name"),e(this,"uuid"),this._component=t,this.name=s,this.uuid=n??v.create();i.get(Yt).list.set(this.uuid,this)}get controls(){return Zt.copySchema(this._config)}set(t){for(const e in t)if(e in this){this[e]=t[e].value}}export(t=this._config,e={}){for(const i in t){const s=t[i];if(Zt.isEntry(s))if("Color"===s.type){const{r:t,g:n,b:r}=s.value;e[i]={...s,value:{r:t,g:n,b:r}}}else if("Vector3"===s.type){const{x:t,y:n,z:r}=s.value;e[i]={...s,value:{x:t,y:n,z:r}}}else if("TextSet"===s.type){const t=Array.from(s.value);e[i]={...s,value:t}}else if("Select"===s.type){const t=Array.from(s.options);e[i]={...s,options:t}}else e[i]={...s};else e[i]={},this.export(s,e[i])}return e}import(t,e={},i=!0){for(const i in t){const s=t[i];if(Zt.isEntry(s))if("Color"===s.type){const{r:t,g:n,b:r}=s.value;e[i]={...s,value:new a.Color(t,n,r)}}else if("Vector3"===s.type){const{x:t,y:n,z:r}=s.value;e[i]={...s,value:new a.Vector3(t,n,r)}}else"TextSet"===s.type?e[i]={...s,value:new Set(s.value)}:"Select"===s.type?e[i]={...s,options:new Set(s.options)}:e[i]={...s};else e[i]={},this.import(s,e[i],!1)}i&&this.set(e)}}const Wt=class t extends d{constructor(s){super(s),e(this,"list",new i.DataMap),e(this,"enabled",!0),s.add(t.uuid,this)}};e(Wt,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let Yt=Wt;class Gt{constructor(t){e(this,"_event"),e(this,"_position",new a.Vector2),e(this,"onDisposed",new h),e(this,"updateMouseInfo",t=>{this._event=t}),this.dom=t,this.setupEvents(!0)}get position(){return this.updatePosition(!1),this._position.clone()}get rawPosition(){return this.updatePosition(!0),this._position.clone()}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}updatePosition(t){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event,t),this._position.y=this.getPositionY(e,this._event,t)}}getPositionY(t,e,i){const s=this.getDataObject(e);return i?s.clientY:-(s.clientY-t.top)/(t.bottom-t.top)*2+1}getPositionX(t,e,i){const s=this.getDataObject(e);return i?s.clientX:(s.clientX-t.left)/(t.right-t.left)*2-1}getDataObject(t){return t instanceof MouseEvent?t:t.touches[0]}setupEvents(t){t?(this.dom.addEventListener("pointermove",this.updateMouseInfo),this.dom.addEventListener("touchstart",this.updateMouseInfo)):(this.dom.removeEventListener("pointermove",this.updateMouseInfo),this.dom.removeEventListener("touchstart",this.updateMouseInfo))}}const Xt=class t extends d{constructor(i){super(i),e(this,"onDisposed",new h),e(this,"onBeforeDispose",new h),e(this,"onFragmentsLoaded",new h),e(this,"baseCoordinationModel",""),e(this,"baseCoordinationMatrix",new a.Matrix4),e(this,"enabled",!0),e(this,"_core"),this.components.add(t.uuid,this)}get initialized(){return!!this._core}get list(){return this.core.models.list}get core(){if(!this._core)throw new Error("FragmentsManager not initialized. Call init() first.");return this._core}get _hasCoordinationModel(){return""!==this.baseCoordinationModel}dispose(){this.onBeforeDispose.trigger(),this._core&&(this.core.dispose(),this._core=void 0),this.baseCoordinationModel="",this.onFragmentsLoaded.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}init(t,e){this._core=new i.FragmentsModels(t,e),this.core.onModelLoaded.add(async()=>{if(this._hasCoordinationModel)return;const t=[...this.list.values()][0];t&&(this.baseCoordinationModel=t.modelId,this.baseCoordinationMatrix=await t.getCoordinationMatrix())}),this.list.onItemDeleted.add(()=>{this.list.size>0||(this.baseCoordinationModel="",this.baseCoordinationMatrix=new a.Matrix4)})}async raycast(t){const e=[];for(const i of this.core.models.list.values())if(t.snappingClasses&&t.snappingClasses.length>0){const s=await i.raycastWithSnapping(t);if(s&&s.length>0)e.push(s[0]);else{const s=await i.raycast(t);s&&e.push(s)}}else{const s=await i.raycast(t);s&&e.push(s)}if(await Promise.all(e),0===e.length)return;let i=e[0],s=i.distance;for(let t=1;t<e.length;t++)e[t].distance<s&&(s=e[t].distance,i=e[t]);return i}async getPositions(t){const e=[],i=async(t,i)=>{const s=await t.getPositions(i);for(const t of s)e.push(t)},s=[];for(const e in t){const n=this.core.models.list.get(e);n&&s.push(i(n,Array.from(t[e])))}return await Promise.all(s),e}async getBBoxes(t){const e=[],i=async(t,i)=>{const s=await t.getBoxes(i);if(s)for(const t of s)e.push(t)},s=[];for(const e in t){const n=this.core.models.list.get(e);n&&s.push(i(n,Array.from(t[e])))}return await Promise.all(s),e}async highlight(t,e){await this.forEachModel(e,"highlight",t)}async getData(t,e){const i={};for(const[s,n]of Object.entries(t)){const t=this.list.get(s);if(!t)continue;if(0===n.size){i[s]=[];continue}const r=await t.getItemsData([...n],e);i[s]=r}return i}async resetHighlight(t){await this.forEachModel(t,"resetHighlight")}async forEachModel(t,e,...i){const s={};if(t)for(const e in t){const i=t[e];s[e]=Array.from(i)}else for(const t of this.core.models.list.keys())s[t]=void 0;const n=[];for(const t in s){const r=this.core.models.list.get(t);if(r){const o=s[t],a=r[e](o,...i);n.push(a)}}await Promise.all(n)}async guidsToModelIdMap(t){const e={};for(const[i,s]of this.list){const n=(await s.getLocalIdsByGuids([...t])).filter(t=>null!==t);e[i]=new Set(n)}return e}async modelIdMapToGuids(t){const e=[];for(const[i,s]of Object.entries(t)){const t=this.list.get(i);if(!t)continue;const n=(await t.getGuidsByLocalIds([...s])).filter(t=>null!==t);e.push(...n)}return e}applyBaseCoordinateSystem(t,e){const i=new a.Matrix4;return e&&i.copy(e.clone()).invert(),i.multiply(this.baseCoordinationMatrix),t.applyMatrix4(i),i}};e(Xt,"uuid","fef46874-46a3-461b-8c44-2922ab77c806");let qt=Xt;class Qt{constructor(){e(this,"wasm",{path:"",absolute:!1,logLevel:l.LogLevel.LOG_LEVEL_OFF}),e(this,"webIfc",{COORDINATE_TO_ORIGIN:!0}),e(this,"autoSetWasm",!0),e(this,"customLocateFileHandler",null)}}const Kt=class t extends d{constructor(i){super(i),e(this,"onDisposed",new h),e(this,"onIfcStartedLoading",new h),e(this,"onIfcImporterInitialized",new h),e(this,"onSetup",new h),e(this,"settings",new Qt),e(this,"webIfc",new l.IfcAPI),e(this,"enabled",!0),this.components.add(t.uuid,this)}dispose(){this.webIfc=null,this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async setup(t){this.settings={...this.settings,...t},this.settings.autoSetWasm&&await this.autoSetWasm(),this.onSetup.trigger()}async load(t,e,i,s){const n=this.components.get(qt);if(!n.initialized)throw new Error("You need to initialize fragments first.");this.settings.autoSetWasm&&await this.autoSetWasm(),n.core.settings.autoCoordinate=e;const r=new o.IfcImporter;r.wasm.path=this.settings.wasm.path,r.wasm.absolute=this.settings.wasm.absolute,r.webIfcSettings=this.settings.webIfc,this.onIfcImporterInitialized.trigger(r),(null==s?void 0:s.instanceCallback)&&s.instanceCallback(r);const a=await r.process({...null==s?void 0:s.processData,bytes:t});return await n.core.load(a,{modelId:i,userData:null==s?void 0:s.userData})}async readIfcFile(t){const{path:e,absolute:i,logLevel:s}=this.settings.wasm;return this.webIfc.SetWasmPath(e,i),await this.webIfc.Init(this.settings.customLocateFileHandler||void 0),s&&this.webIfc.SetLogLevel(s),this.webIfc.OpenModel(t,this.settings.webIfc)}cleanUp(){try{this.webIfc.Dispose()}catch(t){console.log("Web-ifc wasn't disposed.")}this.webIfc=null,this.webIfc=new l.IfcAPI}async autoSetWasm(){const t=await fetch(`https://unpkg.com/@thatopen/components@${Kn.release}/package.json`);if(!t.ok)return void console.warn("Couldn't get openbim-components package.json. Set wasm settings manually.");const e=await t.json();if("web-ifc"in e.peerDependencies){const t=e.peerDependencies["web-ifc"];this.settings.wasm.path=`https://unpkg.com/web-ifc@${t}/`,this.settings.wasm.absolute=!0}else console.warn("Couldn't get web-ifc from peer dependencies in openbim-components. Set wasm settings manually.")}};e(Kt,"uuid","a659add7-1418-4771-a0d6-7d4d438e4624");let Jt=Kt;const te=class t extends d{constructor(i){super(i),e(this,"enabled",!0),this.components.add(t.uuid,this)}async set(t,e){const i=this.components.get(qt),s=[];if(e)for(const[n,r]of Object.entries(e)){const e=i.list.get(n);e&&s.push(e.setVisible([...r],t))}else for(const e of i.list.values())s.push(e.setVisible(void 0,t));await Promise.all(s),await i.core.update(!0)}async isolate(t){await Promise.all([this.set(!1),this.set(!0,t)])}async toggle(t){const e=[],i=this.components.get(qt);for(const[s,n]of Object.entries(t)){const t=i.list.get(s);t&&e.push(t.toggleVisible([...n]))}await Promise.all(e),await i.core.update(!0)}async getVisibilityMap(t,e){const i=[],s=[],n=this.components.get(qt);if(e)for(const r of e){const e=n.list.get(r);e&&(i.push(e.modelId),s.push(e.getItemsByVisibility(t)))}else for(const e of n.list.values())i.push(e.modelId),s.push(e.getItemsByVisibility(t));const r=await Promise.all(s),o={};for(const[t,e]of i.entries())o[e]=r[t];return o}};e(te,"uuid","dd9ccf2d-8a21-4821-b7f6-2949add16a29");let ee=te;const ie=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new h),e(this,"list",new o.DataSet),this.components.add(t.uuid,this)}dispose(e=!0){this.list.clear(),this.onDisposed.trigger(t.uuid),e&&(this.onDisposed.reset(),this.list.eventsEnabled=!1,this.list.dispose())}get(){const t=new a.Box3;for(const e of this.list)t.union(e);return t}async addFromModelIdMap(t){const e=this.components.get(qt),i=new a.Box3;for(const[s,n]of Object.entries(t)){const t=e.list.get(s);if(!t)continue;const r=await t.getMergedBox([...n]);i.union(r)}this.list.add(i)}addFromModels(t){const e=this.components.get(qt);for(const[i,s]of e.list)t&&!t.some(t=>t.test(i))||this.list.add(s.box)}async getCenter(t){this.list.clear(),await this.addFromModelIdMap(t);const e=this.get();this.list.clear();const i=new a.Vector3;return e.getCenter(i),i}async getCameraOrientation(t,e=1){const i=this.components.get(qt);this.list.clear();for(const[t,e]of i.list)this.list.add(e.box);const s=this.get();this.list.clear();const n=new a.Vector3;s.getCenter(n);const r=new a.Vector3;s.getSize(r);const o=Math.max(r.x,r.y,r.z)*e,l=new a.Vector3;switch(t){case"front":default:l.set(n.x,n.y,n.z+o);break;case"back":l.set(n.x,n.y,n.z-o);break;case"left":l.set(n.x-o,n.y,n.z);break;case"right":l.set(n.x+o,n.y,n.z);break;case"top":l.set(n.x,n.y+o,n.z);break;case"bottom":l.set(n.x,n.y-o,n.z)}return{position:l,target:n}}};e(ie,"uuid","d1444724-dba6-4cdd-a0c7-68ee1450d166");let se=ie;class ne{constructor(t,i){e(this,"name","Query"),e(this,"customData",{}),e(this,"_components"),e(this,"_queries",[]),e(this,"_aggregation","exclusive"),e(this,"result",null),e(this,"cache",!0),e(this,"serializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>t.source),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.serializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.serializeQueryParameters(t.relation.query):void 0}:void 0}}),e(this,"deserializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>new RegExp(t)),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.deserializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.deserializeQueryParameters(t.relation.query):void 0}:void 0}}),this._components=t,this.queries=i}set queries(t){this._queries=t,this.clearCache()}get queries(){return this._queries}set aggregation(t){t!==this._aggregation&&this.clearCache(),this._aggregation=t}get aggregation(){return this._aggregation}async test(t){const{modelIds:e,force:i}={force:!1,...t};if(this.result&&!i)return this.result;const s=this._components.get(oe),n=await s.getItems(this.queries,{modelIds:e,aggregation:this.aggregation});return this.cache&&(this.result=n),n}clearCache(){this.result=null}serializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>t.source):t.value instanceof RegExp?t.value.source:t.value;return{name:t.name.source,value:e,type:t.type instanceof RegExp?t.type.source:t.type,negate:t.negate,itemIds:t.itemIds}}toJSON(){return{guid:this._components.get(oe).list.getKey(this)??v.create(),name:this.name,customData:this.customData,queries:this.queries.map(this.serializeQueryParameters),aggregation:this.aggregation,cache:this.cache}}deserializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>new RegExp(t)):"string"==typeof t.value?new RegExp(t.value):t.value;return{name:new RegExp(t.name),value:e,type:t.type?new RegExp(t.type):void 0,negate:t.negate,itemIds:t.itemIds}}fromJSON(t){return this.name=t.name,this.customData=t.customData,this.aggregation=t.aggregation,this.cache=t.cache,this.queries=t.queries.map(this.deserializeQueryParameters),this}}const re=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new o.DataMap),i.add(t.uuid,this)}async getItems(t,e){let i;if(e){const{modelIds:t,items:s}=e;if(s){const t=Object.keys(s);t.length>0&&(i=t.map(t=>new RegExp(`^${t}$`)))}else t&&(i=t)}const s=(null==e?void 0:e.aggregation)??"exclusive",n=this.components.get(qt),r=await Promise.all(t.map(async t=>{const s={};return await Promise.all(Array.from(n.list).map(async([n,r])=>{var o;if(i&&!i.some(t=>t.test(n)))return;const a=null==(o=null==e?void 0:e.items)?void 0:o[n],l=await r.getItemsByQuery(t,{localIds:a?[...a]:void 0});s[n]=new Set(l)})),s}));return"inclusive"===s?jt.join(r):jt.intersect(r)}create(t,e){const i=new ne(this.components,e);return this.list.set(t,i),i}async addFromCategories(t){const e=new Set,i=this.components.get(qt);for(const[s,n]of i.list){if(t&&!t.some(t=>t.test(s)))continue;const i=(await n.getItemsWithGeometryCategories()).filter(t=>null!==t),r=new Set(i);for(const t of r)this.list.has(t)||(this.create(t,[{categories:[new RegExp(`^${t}$`)]}]),e.add(t))}return[...e]}import(t){const{data:e}=t,i=[];if(!e)return i;for(const t of e){const e=this.create(t.guid,[]);e.fromJSON(t),i.push(e)}return i}export(){const t=[];for(const[e,i]of this.list.entries()){const s={...i.toJSON(),name:e};t.push(s)}return{data:t}}};e(re,"uuid","0da7ad77-f734-42ca-942f-a074adfd1e3a");let oe=re;const ae=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new h),e(this,"list",new o.DataMap),e(this,"defaultSaveFunction",t=>"value"in t.Name?t.Name.value:null),e(this,"onBeforeFragmentsDispose",async t=>{const{key:e,value:i}=t,s=await i.getLocalIds(),n={[e]:new Set(s)};this.removeItems(n)}),i.add(t.uuid,this),this.setupEvents();i.get(qt).list.onBeforeDelete.add(this.onBeforeFragmentsDispose)}setupEvents(){this.list.onBeforeDelete.add(({value:t})=>t.dispose())}getClassificationGroups(t){let e=this.list.get(t);return e||(e=new o.DataMap,this.list.set(t,e)),e}getModelItems(t,e,i){const{map:s}=this.getGroupData(t,e);let n=s[i];return n||(n=new Set,s[i]=n),n}getGroupData(t,e){const i=this.components.get(oe),s=this.getClassificationGroups(t);let n=s.get(e);return n||(n={map:{},get:()=>new Promise(t=>{if(n)if(n.query){const{name:e,config:s}=n.query,r=i.list.get(e);if(!r)throw new Error("Classifier: the query name associated with the group doesn't exist in the ItemsFinder component");r.test(s).then(e=>{if(!n)return void t({});const i=jt.join([e,n.map]);t(i)})}else t(n.map);else t({})})},s.set(e,n)),n}async aggregateItems(t,e,i){const s=(null==i?void 0:i.data)??void 0,n=(null==i?void 0:i.aggregationCallback)??this.defaultSaveFunction,r=this.components.get(qt),o=this.components.get(oe),a=await o.getItems([e],{modelIds:null==i?void 0:i.modelIds});for(const[e,i]of Object.entries(a)){const o=r.list.get(e);if(!o)continue;const a=(i,...s)=>{const n=this.getModelItems(t,i,e);for(const t of s)n.add(t)},l=await o.getItemsData([...i],s);for(const t of l)n(t,a)}}addGroupItems(t,e,i){const{map:s}=this.getGroupData(t,e);jt.add(s,i)}setGroupQuery(t,e,i){this.getGroupData(t,e).query=i}async find(t){const e=[];for(const[i,s]of Object.entries(t)){const t=[],n=this.list.get(i);if(!n)continue;for(const e of s){const i=n.get(e);if(!i)continue;const s=await i.get();t.push(s)}const r=jt.join(t);e.push(r)}return jt.intersect(e)}async aggregateItemRelations(t,e,i,s){const n=(null==s?void 0:s.attribute)??"Name",r={relations:{[i]:{attributes:!0,relations:!1}}};await this.aggregateItems(t,e,{modelIds:null==s?void 0:s.modelIds,data:r,aggregationCallback:(t,e)=>{if(!(null==t?void 0:t[n]))return;const s=t[n];if(!("value"in s))return;const r=t[i];if(Array.isArray(r))for(const t of r)"value"in t._localId&&e(s.value,t._localId.value)}})}async byIfcBuildingStorey(t){await this.aggregateItemRelations((null==t?void 0:t.classificationName)??"Storeys",{categories:[/BUILDINGSTOREY/]},"ContainsElements",{modelIds:null==t?void 0:t.modelIds})}async byCategory(t){const e=this.components.get(oe),i=await e.addFromCategories(null==t?void 0:t.modelIds);for(const e of i)this.setGroupQuery((null==t?void 0:t.classificationName)??"Categories",e,{name:e})}dispose(){this.list.clear();this.components.get(qt).list.onBeforeDelete.remove(this.onBeforeFragmentsDispose),this.onDisposed.trigger()}removeItems(t,e){if(e&&e.classificationName){const i=this.list.get(e.classificationName);if(!i)return;if(e.groupName){if(!i.get(e.groupName))return}for(const[,e]of i)jt.remove(e.map,t);return}for(const[,e]of this.list.entries())for(const[,i]of e)jt.remove(i.map,t)}async byModel(t){const e=this.components.get(qt),i=(null==t?void 0:t.classificationName)??"Models";for(const[s,n]of e.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(s)))continue;const e=await n.getItemsIdsWithGeometry(),r={[s]:new Set(e)};this.getGroupData(i,s),this.addGroupItems(i,s,r)}}};e(ae,"uuid","e25a7f3c-46c4-4a14-9d3d-5115f24ebeb7");let le=ae;class he{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new h),e(this,"mouse"),e(this,"world"),e(this,"debugMode",!1),e(this,"colorToModelId",new Map),e(this,"modelIdToColor",new Map),e(this,"renderTarget"),e(this,"renderTargetSize",new a.Vector2),e(this,"debugCanvas"),e(this,"debugContainer"),e(this,"colorMaterials",new Map),e(this,"originalMaterials",new Map),e(this,"originalLodColors",new Map),e(this,"colorsNeedUpdate",!0);const s=i.renderer;if(!s)throw new Error("A renderer is needed for the FastModelPicker to work!");this.world=i,this.mouse=new Gt(s.three.domElement),this.components=t,this.setupRenderTarget(),this.setupFragmentListeners()}setupFragmentListeners(){const t=this.components.get(qt);t.list.onItemSet.add(()=>{this.colorsNeedUpdate=!0}),t.list.onItemDeleted.add(()=>{this.colorsNeedUpdate=!0})}setupRenderTarget(){const t=this.world.renderer.three.getSize(new a.Vector2);this.renderTargetSize.copy(t),this.renderTarget=new a.WebGLRenderTarget(t.x,t.y),this.renderTarget.texture.format=a.RGBAFormat,this.renderTarget.texture.type=a.UnsignedByteType,this.debugMode&&this.setupDebugCanvas(),this.world.renderer.onResize.add(t=>{this.renderTargetSize.copy(t),this.renderTarget.setSize(t.x,t.y),this.debugCanvas&&(this.debugCanvas.width=t.x,this.debugCanvas.height=t.y)})}setupDebugCanvas(){if(this.debugCanvas)return;const t=this.world.renderer.three.getSize(new a.Vector2);this.debugContainer=document.createElement("div"),this.debugContainer.style.position="fixed",this.debugContainer.style.top="10px",this.debugContainer.style.right="10px",this.debugContainer.style.width="300px",this.debugContainer.style.height="300px",this.debugContainer.style.border="2px solid #fff",this.debugContainer.style.backgroundColor="#000",this.debugContainer.style.zIndex="10000",this.debugContainer.style.pointerEvents="none",this.debugCanvas=document.createElement("canvas"),this.debugCanvas.width=t.x,this.debugCanvas.height=t.y,this.debugCanvas.style.width="100%",this.debugCanvas.style.height="100%",this.debugCanvas.style.imageRendering="pixelated",this.debugContainer.appendChild(this.debugCanvas),document.body.appendChild(this.debugContainer)}generateColorForModel(t){let e=0;for(let i=0;i<t.length;i++)e=(e<<5)-e+t.charCodeAt(i),e&=e;let i=Math.abs(e)%16777215;0===i&&(i=1);const s=i>>16&255||1,n=i>>8&255||1,r=255&i||1;return new a.Color(s/255,n/255,r/255)}colorToId(t){return Math.round(255*t.r)<<16|Math.round(255*t.g)<<8|Math.round(255*t.b)}assignColors(){const t=this.components.get(qt);if(t.initialized){if(!this.colorsNeedUpdate){const e=new Set(t.list.keys()),i=new Set(this.modelIdToColor.keys());(e.size!==i.size||[...e].some(t=>!i.has(t)))&&(this.colorsNeedUpdate=!0)}if(this.colorsNeedUpdate){this.colorToModelId.clear(),this.modelIdToColor.clear();for(const t of this.colorMaterials.values())t.dispose();this.colorMaterials.clear();for(const[e]of t.list){const t=this.generateColorForModel(e),i=this.colorToId(t);this.colorToModelId.set(i,e),this.modelIdToColor.set(e,t);const s=new a.MeshBasicMaterial({color:t,depthTest:!0,depthWrite:!0});this.colorMaterials.set(e,s)}this.colorsNeedUpdate=!1}}}applyColorMaterials(){const t=this.components.get(qt);if(t.initialized)for(const[e,i]of t.list){const t=this.colorMaterials.get(e);t&&i.object.traverse(e=>{if(e instanceof a.Mesh){if("isLODGeometry"in e.geometry){const i=e.material[0].uniforms.lodColor;return this.originalLodColors.has(i)||this.originalLodColors.set(i,i.value),void(i.value=t.color)}this.originalMaterials.has(e)||this.originalMaterials.set(e,e.material),e.material=t}})}}restoreOriginalMaterials(){for(const[t,e]of this.originalMaterials)t.material=e;for(const[t,e]of this.originalLodColors)t.value=e;this.originalMaterials.clear()}renderColorCoded(){if(!this.renderTarget||!this.world.renderer)throw new Error("Render target not initialized!");const t=this.world.renderer.three,e=this.world.scene.three,i=this.world.camera.three,s=t.getRenderTarget(),n=t.autoClear,r=new a.Color,o=t.getClearAlpha();t.getClearColor(r),this.applyColorMaterials(),t.setRenderTarget(this.renderTarget),t.autoClear=!0,t.setClearColor(0,1),t.clear(!0,!0,!1),t.render(e,i),t.setRenderTarget(s),t.autoClear=n,t.setClearColor(r,o),this.restoreOriginalMaterials(),this.debugMode&&this.debugCanvas&&this.updateDebugCanvas()}updateDebugCanvas(){if(!this.debugCanvas||!this.renderTarget||!this.world.renderer)return;const t=this.world.renderer.three,e=this.renderTargetSize,i=new Uint8Array(e.x*e.y*4);t.readRenderTargetPixels(this.renderTarget,0,0,e.x,e.y,i);const s=this.debugCanvas.getContext("2d");if(!s)return;const n=s.createImageData(e.x,e.y),r=4*e.x;for(let t=0;t<e.y;t++){const s=t*r,o=(e.y-1-t)*r;n.data.set(i.subarray(s,s+r),o)}s.putImageData(n,0,0)}async getModelAt(t){if(!this.renderTarget||!this.world.renderer)throw new Error("Render target not initialized!");const e=this.components.get(qt);if(!e.initialized||0===e.list.size)return null;this.assignColors(),this.renderColorCoded();const i=t||this.mouse.position,s=this.renderTargetSize,n=Math.floor(.5*(i.x+1)*s.x),r=Math.floor(.5*(i.y+1)*(s.y-1)),o=Math.max(0,Math.min(s.x-1,n)),a=Math.max(0,Math.min(s.y-1,r)),l=this.world.renderer.three,h=new Uint8Array(4);l.readRenderTargetPixels(this.renderTarget,o,a,1,1,h);const c=h[0]<<16|h[1]<<8|h[2];return this.colorToModelId.get(c)||null}setDebugMode(t){this.debugMode=t,t?this.setupDebugCanvas():this.removeDebugCanvas()}removeDebugCanvas(){this.debugContainer&&(this.debugContainer.remove(),this.debugContainer=void 0,this.debugCanvas=void 0)}dispose(){this.mouse.dispose(),this.removeDebugCanvas();for(const t of this.colorMaterials.values())t.dispose();this.colorMaterials.clear(),this.renderTarget&&this.renderTarget.dispose(),this.colorToModelId.clear(),this.modelIdToColor.clear(),this.originalMaterials.clear(),this.originalLodColors.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}}const ce=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new h),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new he(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(ce,"uuid","4a82430c-7ff2-49ea-9401-60807502dad6");let de=ce;class ue{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new h),e(this,"mouse"),e(this,"three",new a.Raycaster),e(this,"world"),e(this,"useFastModelPicking",!1);const s=i.renderer;if(!s)throw new Error("A renderer is needed for the raycaster to work!");this.world=i,this.mouse=new Gt(s.three.domElement),this.components=t}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRayToObjects(t=Array.from(this.world.meshes),e=this.mouse.position){if(!this.world)throw new Error("A world is needed to cast rays!");const i=this.world.camera.three;return this.three.setFromCamera(e,i),this.intersect(t)}async castRay(t){const e=null==t?void 0:t.snappingClasses,i=(null==t?void 0:t.items)??Array.from(this.world.meshes),s=(null==t?void 0:t.position)??this.mouse.position;if(!this.world)throw new Error("A world is needed to cast rays!");const n=this.world.camera.three,r=this.components.get(qt),o=this.world.renderer.three.domElement,a=this.mouse.rawPosition;let l=null;if(r.initialized){if(this.useFastModelPicking){const t=this.components.get(de).get(this.world),i=await t.getModelAt(s);if(i){const t=r.list.get(i);if(t)if(e&&e.length>0){const i=await t.raycastWithSnapping({camera:n,dom:o,mouse:a,snappingClasses:e});l=i&&i.length>0?i[0]:await t.raycast({camera:n,dom:o,mouse:a})}else l=await t.raycast({camera:n,dom:o,mouse:a})}}else l=await r.raycast({camera:n,dom:o,mouse:a,snappingClasses:e});if(0===i.length)return l}this.three.setFromCamera(s,n);const h=this.intersect(i);return l?h&&h.distance<l.distance?h:l:h}castRayFromVector(t,e,i=Array.from(this.world.meshes)){return this.three.set(t,e),this.intersect(i)}intersect(t=Array.from(this.world.meshes)){const e=this.three.intersectObjects(t),i=this.filterClippingPlanes(e);return i.length>0?i[0]:null}filterClippingPlanes(t){if(!this.world.renderer)throw new Error("Renderer not found!");const e=this.world.renderer.three;if(!e.clippingPlanes)return t;const i=e.clippingPlanes;return t.length<=0||!i||(null==i?void 0:i.length)<=0?t:t.filter(t=>i.every(e=>e.distanceToPoint(t.point)>0))}}const pe=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new h),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new ue(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(pe,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let fe=pe;class me extends c{constructor(){super(...arguments),e(this,"onCameraChanged",new h),e(this,"meshes",new Set),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"isDisposing",!1),e(this,"enabled",!0),e(this,"_dynamicAnchor",!1),e(this,"uuid",v.create()),e(this,"name"),e(this,"_scene"),e(this,"_camera"),e(this,"_renderer",null),e(this,"onPointerDown",async t=>{if(!this.camera.hasCameraControls())throw new Error("World: can't set dynamic anchor if the camera doesn't have controls.");const e=this.components.get(fe).get(this),i=await e.castRay();i&&i.point&&0===t.button&&this.camera.controls.setOrbitPoint(i.point.x,i.point.y,i.point.z)}),e(this,"_defaultCamera")}set dynamicAnchor(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(!i)throw new Error("World: the renderer must have a parentElement to set dynamic anchoring.");t?(this.camera.controls&&(this.camera.controls.minDistance=.01),i.addEventListener("pointerdown",this.onPointerDown)):i.removeEventListener("pointerdown",this.onPointerDown)}get dynamicAnchor(){return this._dynamicAnchor}get defaultCamera(){if(!this._defaultCamera)throw new Error("World: there is no default camera defined.");return this._defaultCamera}set defaultCamera(t){this._defaultCamera=t}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera||(this.defaultCamera=t),this._camera=t,t.currentWorld=this,this.onCameraChanged.trigger(t)}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}useDefaultCamera(){this.camera=this.defaultCamera}update(t){this.enabled&&this._scene&&this._camera&&(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger())}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const t=this.components.get(g);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const e of this.meshes)t.destroy(e);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(wi).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class ge{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(t){this._list.directionalLight.color.value=t;for(const[,e]of this._scene.directionalLights)e.color.copy(t)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(t){this._list.directionalLight.intensity.value=t;for(const[,e]of this._scene.directionalLights)e.intensity=t}get position(){return this._list.directionalLight.position.value.clone()}set position(t){this._list.directionalLight.position.value=t;for(const[,e]of this._scene.directionalLights)e.position.copy(t)}}class _e{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(t){this._list.ambientLight.color.value=t;for(const[,e]of this._scene.ambientLights)e.color.copy(t)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(t){this._list.ambientLight.intensity.value=t;for(const[,e]of this._scene.ambientLights)e.intensity=t}}class ye extends $t{constructor(){super(...arguments),e(this,"_config",{backgroundColor:{value:new a.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new a.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new a.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new a.Vector3}}}),e(this,"ambientLight",new _e(this._config,this._component)),e(this,"directionalLight",new ge(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class we extends _{constructor(t){super(t),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"three"),e(this,"config",new ye(this,this.components,"Scene")),e(this,"_defaultConfig",{backgroundColor:new a.Color(2107698),directionalLight:{color:new a.Color("white"),intensity:1.5,position:new a.Vector3(5,10,3)},ambientLight:{color:new a.Color("white"),intensity:1}}),this.three=new a.Scene,this.three.background=new a.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const i=e.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const s=e.directionalLight;this.config.directionalLight.color=s.color,this.config.directionalLight.intensity=s.intensity,this.config.directionalLight.position=s.position,this.deleteAllLights();const{color:n,intensity:r}=this.config.directionalLight,o=new a.DirectionalLight(n,r);o.position.copy(s.position);const{color:l,intensity:h}=this.config.directionalLight,c=new a.AmbientLight(l,h);this.three.add(o,c),this.directionalLights.set(o.uuid,o),this.ambientLights.set(c.uuid,c),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get(Yt).list.delete(this.config.uuid)}}var ve=(t=>(t[t.MANUAL=0]="MANUAL",t[t.AUTO=1]="AUTO",t))(ve||{});
2
- /*!
3
- * camera-controls
4
- * https://github.com/yomotsu/camera-controls
5
- * (c) 2017 @yomotsu
6
- * Released under the MIT License.
7
- */
8
- const be=1,xe=2,Te=4,Ce=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Ee=0,Se=1,Ae=-1;function Oe(t){return t.isPerspectiveCamera}function Pe(t){return t.isOrthographicCamera}const Ie=2*Math.PI,Me=Math.PI/2,De=Math.PI/180;function ke(t,e,i){return Math.max(e,Math.min(i,t))}function ze(t,e=1e-5){return Math.abs(t)<e}function Be(t,e,i=1e-5){return ze(t-e,i)}function Ne(t,e){return Math.round(t/e)*e}function Ue(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Le(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function Re(t,e,i,s,n=1/0,r){const o=2/(s=Math.max(1e-4,s)),a=o*r,l=1/(1+a+.48*a*a+.235*a*a*a);let h=t-e;const c=e,d=n*s;h=ke(h,-d,d),e=t-h;const u=(i.value+o*h)*r;i.value=(i.value-o*u)*l;let p=e+(h+u)*l;return c-t>0==p>c&&(p=c,i.value=(p-c)/r),p}function Fe(t,e,i,s,n=1/0,r,o){const a=2/(s=Math.max(1e-4,s)),l=a*r,h=1/(1+l+.48*l*l+.235*l*l*l);let c=e.x,d=e.y,u=e.z,p=t.x-c,f=t.y-d,m=t.z-u;const g=c,_=d,y=u,w=n*s,v=p*p+f*f+m*m;if(v>w*w){const t=Math.sqrt(v);p=p/t*w,f=f/t*w,m=m/t*w}c=t.x-p,d=t.y-f,u=t.z-m;const b=(i.x+a*p)*r,x=(i.y+a*f)*r,T=(i.z+a*m)*r;i.x=(i.x-a*b)*h,i.y=(i.y-a*x)*h,i.z=(i.z-a*T)*h,o.x=c+(p+b)*h,o.y=d+(f+x)*h,o.z=u+(m+T)*h;const C=g-t.x,E=_-t.y,S=y-t.z;return C*(o.x-g)+E*(o.y-_)+S*(o.z-y)>0&&(o.x=g,o.y=_,o.z=y,i.x=(o.x-g)/r,i.y=(o.y-_)/r,i.z=(o.z-y)/r),o}function Ve(t,e){e.set(0,0),t.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=t.length,e.y/=t.length}function je(t,e){return!!Pe(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class He{constructor(){this._listeners={}}addEventListener(t,e){const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}removeAllEventListeners(t){t?Array.isArray(this._listeners[t])&&(this._listeners[t].length=0):this._listeners={}}dispatchEvent(t){const e=this._listeners[t.type];if(void 0!==e){t.target=this;const i=e.slice(0);for(let e=0,s=i.length;e<s;e++)i[e].call(this,t)}}}var Ze;const $e=1/8,We=/Mac/.test(null===(Ze=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===Ze?void 0:Ze.platform);let Ye,Ge,Xe,qe,Qe,Ke,Je,ti,ei,ii,si,ni,ri,oi,ai,li,hi,ci,di,ui,pi,fi,mi;class gi extends He{static install(t){Ye=t.THREE,Ge=Object.freeze(new Ye.Vector3(0,0,0)),Xe=Object.freeze(new Ye.Vector3(0,1,0)),qe=Object.freeze(new Ye.Vector3(0,0,1)),Qe=new Ye.Vector2,Ke=new Ye.Vector3,Je=new Ye.Vector3,ti=new Ye.Vector3,ei=new Ye.Vector3,ii=new Ye.Vector3,si=new Ye.Vector3,ni=new Ye.Vector3,ri=new Ye.Vector3,oi=new Ye.Vector3,ai=new Ye.Spherical,li=new Ye.Spherical,hi=new Ye.Box3,ci=new Ye.Box3,di=new Ye.Sphere,ui=new Ye.Quaternion,pi=new Ye.Quaternion,fi=new Ye.Matrix4,mi=new Ye.Raycaster}static get ACTION(){return Ce}set verticalDragToForward(t){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=Ce.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Ee,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new Ye.Vector3,this._focalOffsetVelocity=new Ye.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,i,s)=>{let n,r;if(Oe(this._camera)){const i=Ke.copy(this._camera.position).sub(this._target),s=this._camera.getEffectiveFOV()*De,o=i.length()*Math.tan(.5*s);n=this.truckSpeed*t*o/this._elementRect.height,r=this.truckSpeed*e*o/this._elementRect.height}else{if(!Pe(this._camera))return;{const i=this._camera;n=this.truckSpeed*t*(i.right-i.left)/i.zoom/this._elementRect.width,r=this.truckSpeed*e*(i.top-i.bottom)/i.zoom/this._elementRect.height}}s?(i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(n,0,!0),this.forward(-r,!0)):i?this.setFocalOffset(this._focalOffsetEnd.x+n,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(n,r,!0)},this._rotateInternal=(t,e)=>{const i=Ie*this.azimuthRotateSpeed*t/this._elementRect.height,s=Ie*this.polarRotateSpeed*e/this._elementRect.height;this.rotate(i,s,!0)},this._dollyInternal=(t,e,i)=>{const s=Math.pow(.95,-t*this.dollySpeed),n=this._sphericalEnd.radius,r=this._sphericalEnd.radius*s,o=ke(r,this.minDistance,this.maxDistance),a=o-r;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(r,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?r:o)-n,this._dollyControlCoord.set(e,i)),this._lastDollyDirection=Math.sign(-t)},this._zoomInternal=(t,e,i)=>{const s=Math.pow(.95,t*this.dollySpeed),n=this._zoom,r=this._zoom*s;this.zoomTo(r,!0),this.dollyToCursor&&(this._changedZoom+=r-n,this._dollyControlCoord.set(e,i))},void 0===Ye&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=(new Ye.Quaternion).setFromUnitVectors(this._camera.up,Xe),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=Ce.NONE,this._target=new Ye.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new Ye.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new Ye.Spherical).setFromVector3(Ke.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new Ye.Vector3,new Ye.Vector3,new Ye.Vector3,new Ye.Vector3],this._updateNearPlaneCorners(),this._boundary=new Ye.Box3(new Ye.Vector3(-1/0,-1/0,-1/0),new Ye.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new Ye.Vector2,this.mouseButtons={left:Ce.ROTATE,middle:Ce.DOLLY,right:Ce.TRUCK,wheel:Oe(this._camera)?Ce.DOLLY:Pe(this._camera)?Ce.ZOOM:Ce.NONE},this.touches={one:Ce.TOUCH_ROTATE,two:Oe(this._camera)?Ce.TOUCH_DOLLY_TRUCK:Pe(this._camera)?Ce.TOUCH_ZOOM_TRUCK:Ce.NONE,three:Ce.TOUCH_TRUCK};const i=new Ye.Vector2,s=new Ye.Vector2,n=new Ye.Vector2,r=t=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}const e="mouse"!==t.pointerType?null:(t.buttons&be)===be?be:(t.buttons&Te)===Te?Te:(t.buttons&xe)===xe?xe:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&be)===be&&this._lockedPointer)return;const i={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,deltaX:0,deltaY:0,mouseButton:e};this._activePointers.push(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),this._isDragging=!0,d(t)},o=t=>{t.cancelable&&t.preventDefault();const e=t.pointerId,i=this._lockedPointer||this._findPointerById(e);if(i){if(i.clientX=t.clientX,i.clientY=t.clientY,i.deltaX=t.movementX,i.deltaY=t.movementY,this._state=0,"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(t.buttons&be)===be)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&Te)===Te&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&xe)===xe&&(this._state=this._state|this.mouseButtons.right);u()}},a=t=>{const e=this._findPointerById(t.pointerId);if(!e||e!==this._lockedPointer){if(e&&this._disposePointer(e),"touch"===t.pointerType)switch(this._activePointers.length){case 0:this._state=Ce.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._state=Ce.NONE;p()}};let l=-1;const h=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===Ce.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),i=t.clientX/e.width,s=t.clientY/e.height;if(i<this._interactiveArea.left||i>this._interactiveArea.right||s<this._interactiveArea.top||s>this._interactiveArea.bottom)return}if(t.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===Ce.ROTATE||this.mouseButtons.wheel===Ce.TRUCK){const t=performance.now();l-t<1e3&&this._getClientRect(this._elementRect),l=t}const e=We?-1:-3,i=1===t.deltaMode||t.ctrlKey?t.deltaY/e:t.deltaY/(10*e),s=this.dollyToCursor?(t.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,n=this.dollyToCursor?(t.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case Ce.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case Ce.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case Ce.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case Ce.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case Ce.DOLLY:this._dollyInternal(-i,s,n),this._isUserControllingDolly=!0;break;case Ce.ZOOM:this._zoomInternal(-i,s,n),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===gi.ACTION.NONE){const e=t instanceof PointerEvent?t.pointerId:0,i=this._findPointerById(e);return i&&this._disposePointer(i),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}t.preventDefault()}},d=t=>{if(!this._enabled)return;Ve(this._activePointers,Qe),this._getClientRect(this._elementRect),i.copy(Qe),s.copy(Qe);if(this._activePointers.length>=2){const t=Qe.x-this._activePointers[1].clientX,e=Qe.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e);n.set(0,i);const r=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);s.set(r,o)}if(this._state=0,t)if("pointerType"in t&&"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._lockedPointer||(t.buttons&be)!==be||(this._state=this._state|this.mouseButtons.left),(t.buttons&Te)===Te&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&xe)===xe&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&Ce.ROTATE)!==Ce.ROTATE&&(this._state&Ce.TOUCH_ROTATE)!==Ce.TOUCH_ROTATE&&(this._state&Ce.TOUCH_DOLLY_ROTATE)!==Ce.TOUCH_DOLLY_ROTATE&&(this._state&Ce.TOUCH_ZOOM_ROTATE)!==Ce.TOUCH_ZOOM_ROTATE||(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),(this._state&Ce.TRUCK)!==Ce.TRUCK&&(this._state&Ce.SCREEN_PAN)!==Ce.SCREEN_PAN&&(this._state&Ce.TOUCH_TRUCK)!==Ce.TOUCH_TRUCK&&(this._state&Ce.TOUCH_SCREEN_PAN)!==Ce.TOUCH_SCREEN_PAN&&(this._state&Ce.TOUCH_DOLLY_TRUCK)!==Ce.TOUCH_DOLLY_TRUCK&&(this._state&Ce.TOUCH_DOLLY_SCREEN_PAN)!==Ce.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ce.TOUCH_ZOOM_TRUCK)!==Ce.TOUCH_ZOOM_TRUCK&&(this._state&Ce.TOUCH_ZOOM_SCREEN_PAN)!==Ce.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&Ce.DOLLY)!==Ce.DOLLY&&(this._state&Ce.TOUCH_DOLLY)!==Ce.TOUCH_DOLLY&&(this._state&Ce.TOUCH_DOLLY_TRUCK)!==Ce.TOUCH_DOLLY_TRUCK&&(this._state&Ce.TOUCH_DOLLY_SCREEN_PAN)!==Ce.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ce.TOUCH_DOLLY_OFFSET)!==Ce.TOUCH_DOLLY_OFFSET&&(this._state&Ce.TOUCH_DOLLY_ROTATE)!==Ce.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&Ce.ZOOM)!==Ce.ZOOM&&(this._state&Ce.TOUCH_ZOOM)!==Ce.TOUCH_ZOOM&&(this._state&Ce.TOUCH_ZOOM_TRUCK)!==Ce.TOUCH_ZOOM_TRUCK&&(this._state&Ce.TOUCH_ZOOM_SCREEN_PAN)!==Ce.TOUCH_ZOOM_SCREEN_PAN&&(this._state&Ce.TOUCH_ZOOM_OFFSET)!==Ce.TOUCH_ZOOM_OFFSET&&(this._state&Ce.TOUCH_ZOOM_ROTATE)!==Ce.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&Ce.OFFSET)!==Ce.OFFSET&&(this._state&Ce.TOUCH_OFFSET)!==Ce.TOUCH_OFFSET&&(this._state&Ce.TOUCH_DOLLY_OFFSET)!==Ce.TOUCH_DOLLY_OFFSET&&(this._state&Ce.TOUCH_ZOOM_OFFSET)!==Ce.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},u=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,Ve(this._activePointers,Qe);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:s.x-Qe.x,r=t?-t.deltaY:s.y-Qe.y;if(s.copy(Qe),(this._state&Ce.ROTATE)!==Ce.ROTATE&&(this._state&Ce.TOUCH_ROTATE)!==Ce.TOUCH_ROTATE&&(this._state&Ce.TOUCH_DOLLY_ROTATE)!==Ce.TOUCH_DOLLY_ROTATE&&(this._state&Ce.TOUCH_ZOOM_ROTATE)!==Ce.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&Ce.DOLLY)===Ce.DOLLY||(this._state&Ce.ZOOM)===Ce.ZOOM){const t=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,e=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0,s=this.dollyDragInverted?-1:1;(this._state&Ce.DOLLY)===Ce.DOLLY?(this._dollyInternal(s*r*$e,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(s*r*$e,t,e),this._isUserControllingZoom=!0)}if((this._state&Ce.TOUCH_DOLLY)===Ce.TOUCH_DOLLY||(this._state&Ce.TOUCH_ZOOM)===Ce.TOUCH_ZOOM||(this._state&Ce.TOUCH_DOLLY_TRUCK)===Ce.TOUCH_DOLLY_TRUCK||(this._state&Ce.TOUCH_ZOOM_TRUCK)===Ce.TOUCH_ZOOM_TRUCK||(this._state&Ce.TOUCH_DOLLY_SCREEN_PAN)===Ce.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ce.TOUCH_ZOOM_SCREEN_PAN)===Ce.TOUCH_ZOOM_SCREEN_PAN||(this._state&Ce.TOUCH_DOLLY_OFFSET)===Ce.TOUCH_DOLLY_OFFSET||(this._state&Ce.TOUCH_ZOOM_OFFSET)===Ce.TOUCH_ZOOM_OFFSET||(this._state&Ce.TOUCH_DOLLY_ROTATE)===Ce.TOUCH_DOLLY_ROTATE||(this._state&Ce.TOUCH_ZOOM_ROTATE)===Ce.TOUCH_ZOOM_ROTATE){const t=Qe.x-this._activePointers[1].clientX,e=Qe.y-this._activePointers[1].clientY,i=Math.sqrt(t*t+e*e),r=n.y-i;n.set(0,i);const o=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,a=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&Ce.TOUCH_DOLLY)===Ce.TOUCH_DOLLY||(this._state&Ce.TOUCH_DOLLY_ROTATE)===Ce.TOUCH_DOLLY_ROTATE||(this._state&Ce.TOUCH_DOLLY_TRUCK)===Ce.TOUCH_DOLLY_TRUCK||(this._state&Ce.TOUCH_DOLLY_SCREEN_PAN)===Ce.TOUCH_DOLLY_SCREEN_PAN||(this._state&Ce.TOUCH_DOLLY_OFFSET)===Ce.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*$e,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*$e,o,a),this._isUserControllingZoom=!0)}(this._state&Ce.TRUCK)!==Ce.TRUCK&&(this._state&Ce.TOUCH_TRUCK)!==Ce.TOUCH_TRUCK&&(this._state&Ce.TOUCH_DOLLY_TRUCK)!==Ce.TOUCH_DOLLY_TRUCK&&(this._state&Ce.TOUCH_ZOOM_TRUCK)!==Ce.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&Ce.SCREEN_PAN)!==Ce.SCREEN_PAN&&(this._state&Ce.TOUCH_SCREEN_PAN)!==Ce.TOUCH_SCREEN_PAN&&(this._state&Ce.TOUCH_DOLLY_SCREEN_PAN)!==Ce.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Ce.TOUCH_ZOOM_SCREEN_PAN)!==Ce.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&Ce.OFFSET)!==Ce.OFFSET&&(this._state&Ce.TOUCH_OFFSET)!==Ce.TOUCH_OFFSET&&(this._state&Ce.TOUCH_DOLLY_OFFSET)!==Ce.TOUCH_DOLLY_OFFSET&&(this._state&Ce.TOUCH_ZOOM_OFFSET)!==Ce.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{Ve(this._activePointers,Qe),s.copy(Qe),this._dragNeedsUpdate=!1,(0===this._activePointers.length||1===this._activePointers.length&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),0===this._activePointers.length&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{this._enabled&&this._domElement&&(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",m),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),d())},this.unlockPointer=()=>{var t,e,i;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(t=this._domElement)||void 0===t||t.ownerDocument.exitPointerLock(),null===(e=this._domElement)||void 0===e||e.ownerDocument.removeEventListener("pointerlockchange",f),null===(i=this._domElement)||void 0===i||i.ownerDocument.removeEventListener("pointerlockerror",m),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},m=()=>{this.unlockPointer()};this._addAllEventListeners=t=>{this._domElement=t,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",h,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",h,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",m))},this.cancel=()=>{this._state!==Ce.NONE&&(this._state=Ce.NONE,this._activePointers.length=0,p())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=ke(t.width,0,1),this._interactiveArea.height=ke(t.height,0,1),this._interactiveArea.x=ke(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=ke(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,i=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,i)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,i=!1){this._isUserControllingRotate=!1;const s=ke(t,this.minAzimuthAngle,this.maxAzimuthAngle),n=ke(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=s,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,i||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!i||Be(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Be(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Ee,this._changedDolly=0,this._dollyToNoClamp(ke(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const i=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const e=this._collisionTest(),s=Be(e,this._spherical.radius);if(!(i>t)&&s)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,e)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const s=!e||Be(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(s)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(ei).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const i=!e||Be(this._target.x,this._targetEnd.x,this.restThreshold)&&Be(this._target.y,this._targetEnd.y,this.restThreshold)&&Be(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=ke(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const i=!e||Be(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(i)}pan(t,e,i=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,i)}truck(t,e,i=!1){this._camera.updateMatrix(),ii.setFromMatrixColumn(this._camera.matrix,0),si.setFromMatrixColumn(this._camera.matrix,1),ii.multiplyScalar(t),si.multiplyScalar(-e);const s=Ke.copy(ii).add(si),n=Je.copy(this._targetEnd).add(s);return this.moveTo(n.x,n.y,n.z,i)}forward(t,e=!1){Ke.setFromMatrixColumn(this._camera.matrix,0),Ke.crossVectors(this._camera.up,Ke),Ke.multiplyScalar(t);const i=Je.copy(this._targetEnd).add(Ke);return this.moveTo(i.x,i.y,i.z,e)}elevate(t,e=!1){return Ke.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+Ke.x,this._targetEnd.y+Ke.y,this._targetEnd.z+Ke.z,e)}moveTo(t,e,i,s=!1){this._isUserControllingTruck=!1;const n=Ke.set(t,e,i).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,s||this._target.copy(this._targetEnd);const r=!s||Be(this._target.x,this._targetEnd.x,this.restThreshold)&&Be(this._target.y,this._targetEnd.y,this.restThreshold)&&Be(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,i,s=!1){const n=Ke.set(t,e,i).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(n.x,n.y,n.z,s)}fitToBox(t,e,{cover:i=!1,paddingLeft:s=0,paddingRight:n=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],l=t.isBox3?hi.copy(t):hi.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=Ne(this._sphericalEnd.theta,Me),c=Ne(this._sphericalEnd.phi,Me);a.push(this.rotateTo(h,c,e));const d=Ke.setFromSpherical(this._sphericalEnd).normalize(),u=ui.setFromUnitVectors(d,qe),p=Be(Math.abs(d.y),1);p&&u.multiply(pi.setFromAxisAngle(Xe,h)),u.multiply(this._yAxisUpSpaceInverse);const f=ci.makeEmpty();Je.copy(l.min).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.min).setX(l.max.x).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.min).setY(l.max.y).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.max).setZ(l.min.z).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.min).setZ(l.max.z).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.max).setY(l.min.y).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.max).setX(l.min.x).applyQuaternion(u),f.expandByPoint(Je),Je.copy(l.max).applyQuaternion(u),f.expandByPoint(Je),f.min.x-=s,f.min.y-=r,f.max.x+=n,f.max.y+=o,u.setFromUnitVectors(qe,d),p&&u.premultiply(pi.invert()),u.premultiply(this._yAxisUpSpace);const m=f.getSize(Ke),g=f.getCenter(Je).applyQuaternion(u);if(Oe(this._camera)){const t=this.getDistanceToFitBox(m.x,m.y,m.z,i);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.dollyTo(t,e)),a.push(this.setFocalOffset(0,0,0,e))}else if(Pe(this._camera)){const t=this._camera,s=t.right-t.left,n=t.top-t.bottom,r=i?Math.max(s/m.x,n/m.y):Math.min(s/m.x,n/m.y);a.push(this.moveTo(g.x,g.y,g.z,e)),a.push(this.zoomTo(r,e)),a.push(this.setFocalOffset(0,0,0,e))}return Promise.all(a)}fitToSphere(t,e){const i=[],s="isObject3D"in t?gi.createBoundingSphere(t,di):di.copy(t);if(i.push(this.moveTo(s.center.x,s.center.y,s.center.z,e)),Oe(this._camera)){const t=this.getDistanceToFitSphere(s.radius);i.push(this.dollyTo(t,e))}else if(Pe(this._camera)){const t=this._camera.right-this._camera.left,n=this._camera.top-this._camera.bottom,r=2*s.radius,o=Math.min(t/r,n/r);i.push(this.zoomTo(o,e))}return i.push(this.setFocalOffset(0,0,0,e)),Promise.all(i)}setLookAt(t,e,i,s,n,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ee,this._changedDolly=0;const a=Je.set(s,n,r),l=Ke.set(t,e,i);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(l.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||Be(this._target.x,this._targetEnd.x,this.restThreshold)&&Be(this._target.y,this._targetEnd.y,this.restThreshold)&&Be(this._target.z,this._targetEnd.z,this.restThreshold)&&Be(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Be(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Be(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(t,e,i,s,n,r,o,a,l,h,c,d,u,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ee,this._changedDolly=0;const f=Ke.set(s,n,r),m=Je.set(t,e,i);ai.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const g=ti.set(h,c,d),_=Je.set(o,a,l);li.setFromVector3(_.sub(g).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(g,u));const y=li.theta-ai.theta,w=li.phi-ai.phi,v=li.radius-ai.radius;this._sphericalEnd.set(ai.radius+v*u,ai.phi+w*u,ai.theta+y*u),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const b=!p||Be(this._target.x,this._targetEnd.x,this.restThreshold)&&Be(this._target.y,this._targetEnd.y,this.restThreshold)&&Be(this._target.z,this._targetEnd.z,this.restThreshold)&&Be(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Be(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Be(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(b)}setPosition(t,e,i,s=!1){return this.setLookAt(t,e,i,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,s)}setTarget(t,e,i,s=!1){const n=this.getPosition(Ke),r=this.setLookAt(n.x,n.y,n.z,t,e,i,s);return this._sphericalEnd.phi=ke(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,i,s=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,i),this._needsUpdate=!0,s||this._focalOffset.copy(this._focalOffsetEnd);const n=!s||Be(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Be(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Be(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(t,e,i){this._camera.updateMatrixWorld(),ii.setFromMatrixColumn(this._camera.matrixWorldInverse,0),si.setFromMatrixColumn(this._camera.matrixWorldInverse,1),ni.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const s=Ke.set(t,e,i),n=s.distanceTo(this._camera.position),r=s.sub(this._camera.position);ii.multiplyScalar(r.x),si.multiplyScalar(r.y),ni.multiplyScalar(r.z),Ke.copy(ii).add(si).add(ni),Ke.z=Ke.z+n,this.dollyTo(n,!1),this.setFocalOffset(-Ke.x,Ke.y,-Ke.z,!1),this.moveTo(t,e,i,!1)}setBoundary(t){if(!t)return this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),void(this._needsUpdate=!0);this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,i,s){null!==t?(this._viewport=this._viewport||new Ye.Vector4,"number"==typeof t?this._viewport.set(t,e,i,s):this._viewport.copy(t)):this._viewport=null}getDistanceToFitBox(t,e,i,s=!1){if(je(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=t/e,r=this._camera.getEffectiveFOV()*De,o=this._camera.aspect;return.5*((s?n>o:n<o)?e:t/o)/Math.tan(.5*r)+.5*i}getDistanceToFitSphere(t){if(je(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*De,i=2*Math.atan(Math.tan(.5*e)*this._camera.aspect),s=1<this._camera.aspect?e:i;return t/Math.sin(.5*s)}getTarget(t,e=!0){return(t&&t.isVector3?t:new Ye.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new Ye.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new Ye.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new Ye.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Ie,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Ie),this._spherical.theta+=Ie*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Ie)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!Be(this._camera.up.x,this._cameraUp0.x)||!Be(this._camera.up.y,this._cameraUp0.y)||!Be(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(Ke);this.updateCameraUp(),this.setPosition(t.x,t.y,t.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Xe),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=Ke.subVectors(this._target,this._camera.position).normalize(),e=Je.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const i=this.getPosition(Ke);this.updateCameraUp(),this.setPosition(i.x,i.y,i.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,i=this._sphericalEnd.phi-this._spherical.phi,s=this._sphericalEnd.radius-this._spherical.radius,n=ri.subVectors(this._targetEnd,this._target),r=oi.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ze(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Re(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(ze(i))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Re(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(ze(s))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Re(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(ze(n.x)&&ze(n.y)&&ze(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Fe(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(ze(r.x)&&ze(r.y)&&ze(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Fe(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(ze(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Re(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if(Oe(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,i=this._getCameraDirection(ei),s=Ke.copy(i).cross(e.up).normalize();0===s.lengthSq()&&(s.x=1);const n=Je.crossVectors(s,i),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*De*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=ti.copy(this._targetEnd).add(s.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(n.multiplyScalar(this._dollyControlCoord.y*r)),l=Ke.copy(this._targetEnd).lerp(a,o),h=this._lastDollyDirection===Se&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===Ae&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(h||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=Je.copy(i).multiplyScalar(-t);l.add(e)}this._boundary.clampPoint(l,l);const d=Je.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedDolly-=t,ze(this._changedDolly)&&(this._changedDolly=0)}else if(Pe(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,i=Ke.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),s=Je.set(0,0,-1).applyQuaternion(e.quaternion),n=ti.copy(i).add(s.multiplyScalar(-i.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(ei),a=this._targetEnd.dot(o),l=Ke.copy(this._targetEnd).lerp(n,r),h=l.dot(o),c=o.multiplyScalar(h-a);l.sub(c),this._boundary.clampPoint(l,l);const d=Je.subVectors(l,this._targetEnd);this._targetEnd.copy(l),this._target.add(d),this._changedZoom-=t,ze(this._changedZoom)&&(this._changedZoom=0)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target);(!ze(this._focalOffset.x)||!ze(this._focalOffset.y)||!ze(this._focalOffset.z))&&(ii.setFromMatrixColumn(this._camera.matrix,0),si.setFromMatrixColumn(this._camera.matrix,1),ni.setFromMatrixColumn(this._camera.matrix,2),ii.multiplyScalar(this._focalOffset.x),si.multiplyScalar(-this._focalOffset.y),ni.multiplyScalar(this._focalOffset.z),Ke.copy(ii).add(si).add(ni),this._camera.position.add(Ke),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Ke.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const l=this._needsUpdate;return l&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):l?(this.dispatchEvent({type:"update"}),ze(e,this.restThreshold)&&ze(i,this.restThreshold)&&ze(s,this.restThreshold)&&ze(n.x,this.restThreshold)&&ze(n.y,this.restThreshold)&&ze(n.z,this.restThreshold)&&ze(r.x,this.restThreshold)&&ze(r.y,this.restThreshold)&&ze(r.z,this.restThreshold)&&ze(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!l&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=l,this._needsUpdate=!1,l}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:Ue(this.maxDistance),minZoom:this.minZoom,maxZoom:Ue(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Ue(this.maxPolarAngle),minAzimuthAngle:Ue(this.minAzimuthAngle),maxAzimuthAngle:Ue(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:Ke.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const i=JSON.parse(t);this.enabled=i.enabled,this.minDistance=i.minDistance,this.maxDistance=Le(i.maxDistance),this.minZoom=i.minZoom,this.maxZoom=Le(i.maxZoom),this.minPolarAngle=i.minPolarAngle,this.maxPolarAngle=Le(i.maxPolarAngle),this.minAzimuthAngle=Le(i.minAzimuthAngle),this.maxAzimuthAngle=Le(i.maxAzimuthAngle),this.smoothTime=i.smoothTime,this.draggingSmoothTime=i.draggingSmoothTime,this.dollySpeed=i.dollySpeed,this.truckSpeed=i.truckSpeed,this.dollyToCursor=i.dollyToCursor,this._target0.fromArray(i.target0),this._position0.fromArray(i.position0),this._zoom0=i.zoom0,this._focalOffset0.fromArray(i.focalOffset0),this.moveTo(i.target[0],i.target[1],i.target[2],e),ai.setFromVector3(Ke.fromArray(i.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ai.theta,ai.phi,e),this.dollyTo(ai.radius,e),this.zoomTo(i.zoom,e),this.setFocalOffset(i.focalOffset[0],i.focalOffset[1],i.focalOffset[2],e),this._needsUpdate=!0}connect(t){this._domElement?console.warn("camera-controls is already connected."):(t.setAttribute("data-camera-controls-version","2.10.1"),this._addAllEventListeners(t),this._getClientRect(this._elementRect))}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,i){const s=e.lengthSq();if(0===s)return t;const n=Je.copy(e).add(t),r=this._boundary.clampPoint(n,ti).sub(n),o=r.lengthSq();if(0===o)return t.add(e);if(o===s)return t;if(0===i)return t.add(e).add(r);{const s=1+i*o/e.dot(r);return t.add(Je.copy(e).multiplyScalar(s)).add(r.multiplyScalar(1-i))}}_updateNearPlaneCorners(){if(Oe(this._camera)){const t=this._camera,e=t.near,i=t.getEffectiveFOV()*De,s=Math.tan(.5*i)*e,n=s*t.aspect;this._nearPlaneCorners[0].set(-n,-s,0),this._nearPlaneCorners[1].set(n,-s,0),this._nearPlaneCorners[2].set(n,s,0),this._nearPlaneCorners[3].set(-n,s,0)}else if(Pe(this._camera)){const t=this._camera,e=1/t.zoom,i=t.left*e,s=t.right*e,n=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(i,n,0),this._nearPlaneCorners[1].set(s,n,0),this._nearPlaneCorners[2].set(s,r,0),this._nearPlaneCorners[3].set(i,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1))return t;if(je(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(ei);fi.lookAt(Ge,e,this._camera.up);for(let i=0;i<4;i++){const s=Je.copy(this._nearPlaneCorners[i]);s.applyMatrix4(fi);const n=ti.addVectors(this._target,s);mi.set(n,e),mi.far=this._spherical.radius+1;const r=mi.intersectObjects(this.colliderMeshes);0!==r.length&&r[0].distance<t&&(t=r[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new Ye.Sphere){const i=e,s=i.center;hi.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&hi.expandByObject(t)}),hi.getCenter(s);let n=0;return t.traverseVisible(t=>{if(!t.isMesh)return;const e=t;if(!e.geometry)return;const i=e.geometry.clone();i.applyMatrix4(e.matrixWorld);const r=i.attributes.position;for(let t=0,e=r.count;t<e;t++)Ke.fromBufferAttribute(r,t),n=Math.max(n,s.distanceToSquared(Ke))}),i.radius=Math.sqrt(n),i}}class _i extends p{constructor(t){super(t),e(this,"onBeforeUpdate",new h),e(this,"onAfterUpdate",new h),e(this,"onAspectUpdated",new h),e(this,"onDisposed",new h),e(this,"three"),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof a.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.setupEvents(!0),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{const e=this._allControls.get(t.uuid);e&&(e.dispose(),this._allControls.delete(t.uuid))})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(qt),i=this.components.get(se);i.list.clear();const s=new a.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(s),i.list.clear(),s}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new a.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new a.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");gi.install({THREE:_i.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new gi(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:a.MOUSE,Vector2:a.Vector2,Vector3:a.Vector3,Vector4:a.Vector4,Quaternion:a.Quaternion,Matrix4:a.Matrix4,Spherical:a.Spherical,Box3:a.Box3,Sphere:a.Sphere,Raycaster:a.Raycaster,MathUtils:a.MathUtils}}}const yi=class t extends d{constructor(s){super(s),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"list",new i.DataMap),e(this,"enabled",!0),s.add(t.uuid,this)}create(){const t=new me(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(yi,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let wi=yi;class vi extends $t{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new a.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class bi{constructor(t,i){e(this,"onDisposed",new h),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new a.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof _i&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:s,primarySize:n,secondarySize:r,distance:o}=this._defaultConfig;this.components=t,this.config=new vi(this,this.components,"Grid");const l=new a.PlaneGeometry(2,2,1,1),c=new a.ShaderMaterial({side:a.DoubleSide,uniforms:{uSize1:{value:n},uSize2:{value:r},uColor:{value:s},uDistance:{value:o},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new a.Mesh(l,c),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get(Yt).list.delete(this.config.uuid);this.components.get(g).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof _i))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const xi=class t extends d{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new h),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new bi(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(xi,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let Ti=xi;const Ci=1.25,Ei=65535,Si=Math.pow(2,-24),Ai=Symbol("SKIP_GENERATION");function Oi(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function Pi(t,e){if(!t.index){const i=t.attributes.position.count,n=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new s.BufferAttribute(n,1));for(let t=0;t<i;t++)n[t]=t}}function Ii(t){const e=Oi(t),i=t.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),o=Math.min(e,n)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function Mi(t){if(!t.groups||!t.groups.length)return Ii(t);const e=[],i=new Set,s=t.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const e of t.groups){const t=e.start/3,s=(e.start+e.count)/3;i.add(Math.max(n,t)),i.add(Math.min(r,s))}const o=Array.from(i.values()).sort((t,e)=>t-e);for(let t=0;t<o.length-1;t++){const i=o[t],s=o[t+1];e.push({offset:Math.floor(i),count:Math.floor(s-i)})}return e}function Di(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function ki(t){let e=-1,i=-1/0;for(let s=0;s<3;s++){const n=t[s+3]-t[s];n>i&&(i=n,e=s)}return e}function zi(t,e){e.set(t)}function Bi(t,e,i){let s,n;for(let r=0;r<3;r++){const o=r+3;s=t[r],n=e[r],i[r]=s<n?s:n,s=t[o],n=e[o],i[o]=s>n?s:n}}function Ni(t,e,i){for(let s=0;s<3;s++){const n=e[t+2*s],r=e[t+2*s+1],o=n-r,a=n+r;o<i[s]&&(i[s]=o),a>i[s+3]&&(i[s+3]=a)}}function Ui(t){const e=t[3]-t[0],i=t[4]-t[1],s=t[5]-t[2];return 2*(e*i+i*s+s*e)}function Li(t,e,i,s,n=null){let r=1/0,o=1/0,a=1/0,l=-1/0,h=-1/0,c=-1/0,d=1/0,u=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const _=null!==n;for(let s=6*e,n=6*(e+i);s<n;s+=6){const e=t[s+0],i=t[s+1],n=e-i,y=e+i;n<r&&(r=n),y>l&&(l=y),_&&e<d&&(d=e),_&&e>f&&(f=e);const w=t[s+2],v=t[s+3],b=w-v,x=w+v;b<o&&(o=b),x>h&&(h=x),_&&w<u&&(u=w),_&&w>m&&(m=w);const T=t[s+4],C=t[s+5],E=T-C,S=T+C;E<a&&(a=E),S>c&&(c=S),_&&T<p&&(p=T),_&&T>g&&(g=T)}s[0]=r,s[1]=o,s[2]=a,s[3]=l,s[4]=h,s[5]=c,_&&(n[0]=d,n[1]=u,n[2]=p,n[3]=f,n[4]=m,n[5]=g)}const Ri=32,Fi=(t,e)=>t.candidate-e.candidate,Vi=new Array(Ri).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ji=new Float32Array(6);class Hi{constructor(){}}function Zi(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let i=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=i}for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}function $i(t,e,i,s,n,r){let o=s,a=s+n-1;const l=r.pos,h=2*r.axis;for(;;){for(;o<=a&&i[6*o+h]<l;)o++;for(;o<=a&&i[6*a+h]>=l;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}}function Wi(t,e){const i=t.geometry,s=i.index?i.index.array:null,n=e.maxDepth,r=e.verbose,o=e.maxLeafTris,a=e.strategy,l=e.onProgress,h=Oi(i),c=t._indirectBuffer;let d=!1;const u=new Float32Array(6),p=new Float32Array(6),f=function(t,e){var i;(i=e)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const s=t.attributes.position,n=t.index?t.index.array:null,r=Oi(t),o=new Float32Array(6*r),a=s.normalized,l=s.array,h=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const d=["getX","getY","getZ"];for(let t=0;t<r;t++){const i=3*t,r=6*t;let u=i+0,p=i+1,f=i+2;n&&(u=n[u],p=n[p],f=n[f]),a||(u=u*c+h,p=p*c+h,f=f*c+h);for(let t=0;t<3;t++){let i,n,h;a?(i=s[d[t]](u),n=s[d[t]](p),h=s[d[t]](f)):(i=l[u+t],n=l[p+t],h=l[f+t]);let c=i;n<c&&(c=n),h<c&&(c=h);let m=i;n>m&&(m=n),h>m&&(m=h);const g=(m-c)/2,_=2*t;o[r+_+0]=c+g,o[r+_+1]=g+(Math.abs(c)+g)*Si,c<e[t]&&(e[t]=c),m>e[t+3]&&(e[t+3]=m)}}return o}(i,u),m=e.indirect?$i:Zi,g=[],_=e.indirect?Ii(i):Mi(i);if(1===_.length){const t=_[0],e=new Hi;e.boundingData=u,function(t,e,i,s){let n=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,h=-1/0;for(let s=6*e,c=6*(e+i);s<c;s+=6){const e=t[s+0];e<n&&(n=e),e>a&&(a=e);const i=t[s+2];i<r&&(r=i),i>l&&(l=i);const c=t[s+4];c<o&&(o=c),c>h&&(h=c)}s[0]=n,s[1]=r,s[2]=o,s[3]=a,s[4]=l,s[5]=h}(f,t.offset,t.count,p),w(e,t.offset,t.count,p),g.push(e)}else for(let t of _){const e=new Hi;e.boundingData=new Float32Array(6),Li(f,t.offset,t.count,e.boundingData,p),w(e,t.offset,t.count,p),g.push(e)}return g;function y(t){l&&l(t/h)}function w(t,e,l,h=null,u=0){if(!d&&u>=n&&(d=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),l<=o||u>=n)return y(e+l),t.offset=e,t.count=l,t;const g=function(t,e,i,s,n,r){let o=-1,a=0;if(0===r)o=ki(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=ki(t),-1!==o&&(a=function(t,e,i,s){let n=0;for(let r=e,o=e+i;r<o;r++)n+=t[6*r+2*s];return n/i}(i,s,n,o));else if(2===r){const r=Ui(t);let l=Ci*n;const h=6*s,c=6*(s+n);for(let t=0;t<3;t++){const s=e[t],d=(e[t+3]-s)/Ri;if(n<8){const e=[...Vi];e.length=n;let s=0;for(let n=h;n<c;n+=6,s++){const r=e[s];r.candidate=i[n+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Ni(n,i,o)}e.sort(Fi);let d=n;for(let t=0;t<d;t++){const i=e[t];for(;t+1<d&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),d--}for(let s=h;s<c;s+=6){const n=i[s+2*t];for(let t=0;t<d;t++){const r=e[t];n>=r.candidate?Ni(s,i,r.rightCacheBounds):(Ni(s,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<d;i++){const s=e[i],h=s.count,c=n-s.count,d=s.leftCacheBounds,u=s.rightCacheBounds;let p=0;0!==h&&(p=Ui(d)/r);let f=0;0!==c&&(f=Ui(u)/r);const m=1+Ci*(p*h+f*c);m<l&&(o=t,l=m,a=s.candidate)}}else{for(let t=0;t<Ri;t++){const e=Vi[t];e.count=0,e.candidate=s+d+t*d;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=h;e<c;e+=6){let n=~~((i[e+2*t]-s)/d);n>=Ri&&(n=31);const r=Vi[n];r.count++,Ni(e,i,r.bounds)}const e=Vi[31];zi(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Vi[t],i=Vi[t+1];Bi(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let u=0;for(let e=0;e<31;e++){const i=Vi[e],s=i.count,h=i.bounds,c=Vi[e+1].rightCacheBounds;0!==s&&(0===u?zi(h,ji):Bi(h,ji,ji)),u+=s;let d=0,p=0;0!==u&&(d=Ui(ji)/r);const f=n-u;0!==f&&(p=Ui(c)/r);const m=1+Ci*(d*u+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(t.boundingData,h,f,e,l,a);if(-1===g.axis)return y(e+l),t.offset=e,t.count=l,t;const _=m(c,s,f,e,l,g);if(_===e||_===e+l)y(e+l),t.offset=e,t.count=l;else{t.splitAxis=g.axis;const i=new Hi,s=e,n=_-e;t.left=i,i.boundingData=new Float32Array(6),Li(f,s,n,i.boundingData,p),w(i,s,n,p,u+1);const r=new Hi,o=_,a=l-n;t.right=r,r.boundingData=new Float32Array(6),Li(f,o,a,r.boundingData,p),w(r,o,a,p,u+1)}return t}}function Yi(t,e){const i=t.geometry;e.indirect&&(t._indirectBuffer=function(t,e){const i=(t.index?t.index.count:t.attributes.position.count)/3,s=i>65536,n=s?4:2,r=e?new SharedArrayBuffer(i*n):new ArrayBuffer(i*n),o=s?new Uint32Array(r):new Uint16Array(r);for(let t=0,e=o.length;t<e;t++)o[t]=t;return o}(i,e.useSharedArrayBuffer),function(t){if(0===t.groups.length)return!1;const e=Oi(t),i=Mi(t).sort((t,e)=>t.offset-e.offset),s=i[i.length-1];s.count=Math.min(e-s.offset,s.count);let n=0;return i.forEach(({count:t})=>n+=t),e!==n}(i)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),t._indirectBuffer||Pi(i,e);const s=Wi(t,e);let n,r,o;const a=[],l=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let t=0;t<s.length;t++){const e=s[t];const i=new l(32*h(e));n=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),c(0,e),a.push(i)}return void(t._roots=a);function h(t){return t.count?1:1+h(t.left)+h(t.right)}function c(t,e){const i=t/4,s=t/2,a=!!e.count,l=e.boundingData;for(let t=0;t<6;t++)n[i+t]=l[t];if(a){const n=e.offset,a=e.count;return r[i+6]=n,o[s+14]=a,o[s+15]=Ei,t+32}{const s=e.left,n=e.right,o=e.splitAxis;let a;if(a=c(t+32,s),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=c(a,n),r[i+7]=o,a}}}class Gi{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const r=t[n][e];i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const r=e[n],o=t.dot(r);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}Gi.prototype.setFromBox=function(){const t=new s.Vector3;return function(e,i){const s=i.min,n=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=s.x*i+n.x*(1-i),t.y=s.y*a+n.y*(1-a),t.z=s.z*l+n.z*(1-l);const h=e.dot(t);r=Math.min(h,r),o=Math.max(h,o)}this.min=r,this.max=o}}();const Xi=function(){const t=new s.Vector3,e=new s.Vector3,i=new s.Vector3;return function(s,n,r){const o=s.start,a=t,l=n.start,h=e;i.subVectors(o,l),t.subVectors(s.end,s.start),e.subVectors(n.end,n.start);const c=i.dot(h),d=h.dot(a),u=h.dot(h),p=i.dot(a),f=a.dot(a)*u-d*d;let m,g;m=0!==f?(c*d-p*u)/f:0,g=(c+m*d)/u,r.x=m,r.y=g}}(),qi=function(){const t=new s.Vector2,e=new s.Vector3,i=new s.Vector3;return function(s,n,r,o){Xi(s,n,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return s.at(a,r),void n.at(l,o);if(a>=0&&a<=1)return l<0?n.at(0,o):n.at(1,o),void s.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?s.at(0,r):s.at(1,r),void n.closestPointToPoint(r,!0,o);{let t,h;t=a<0?s.start:s.end,h=l<0?n.start:n.end;const c=e,d=i;return s.closestPointToPoint(h,!0,e),n.closestPointToPoint(t,!0,i),c.distanceToSquared(h)<=d.distanceToSquared(t)?(r.copy(c),void o.copy(h)):(r.copy(t),void o.copy(d))}}}(),Qi=function(){const t=new s.Vector3,e=new s.Vector3,i=new s.Plane,n=new s.Line3;return function(s,r){const{radius:o,center:a}=s,{a:l,b:h,c:c}=r;n.start=l,n.end=h;if(n.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;n.start=l,n.end=c;if(n.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;n.start=h,n.end=c;if(n.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const d=r.getPlane(i);if(Math.abs(d.distanceToPoint(a))<=o){const t=d.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}();function Ki(t){return Math.abs(t)<1e-15}class Ji extends s.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new s.Vector3),this.satBounds=new Array(4).fill().map(()=>new Gi),this.points=[this.a,this.b,this.c],this.sphere=new s.Sphere,this.plane=new s.Plane,this.needsUpdate=!0}intersectsSphere(t){return Qi(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,o=n[0],a=r[0];this.getNormal(o),a.setFromPoints(o,s);const l=n[1],h=r[1];l.subVectors(t,e),h.setFromPoints(l,s);const c=n[2],d=r[2];c.subVectors(e,i),d.setFromPoints(c,s);const u=n[3],p=r[3];u.subVectors(i,t),p.setFromPoints(u,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Ji.prototype.closestPointToSegment=function(){const t=new s.Vector3,e=new s.Vector3,i=new s.Line3;return function(s,n=null,r=null){const{start:o,end:a}=s,l=this.points;let h,c=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),qi(i,s,t,e),h=t.distanceToSquared(e),h<c&&(c=h,n&&n.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),h=o.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),h=a.distanceToSquared(t),h<c&&(c=h,n&&n.copy(t),r&&r.copy(a)),Math.sqrt(c)}}(),Ji.prototype.intersectsTriangle=function(){const t=new Ji,e=new Array(3),i=new Array(3),n=new Gi,r=new Gi,o=new s.Vector3,a=new s.Vector3,l=new s.Vector3,h=new s.Vector3,c=new s.Vector3,d=new s.Line3,u=new s.Line3,p=new s.Line3,f=new s.Vector3;function m(t,e,i){const s=t.points;let n=0,r=-1;for(let t=0;t<3;t++){const{start:o,end:l}=d;o.copy(s[t]),l.copy(s[(t+1)%3]),d.delta(a);const h=Ki(e.distanceToPoint(o));if(Ki(e.normal.dot(a))&&h){i.copy(d),n=2;break}const c=e.intersectLine(d,f);if(!c&&h&&f.copy(o),(c||h)&&!Ki(f.distanceTo(l))){if(n<=1){(1===n?i.start:i.end).copy(f),h&&(r=n)}else if(n>=2){(1===r?i.start:i.end).copy(f),n=2;break}if(n++,2===n&&-1===r)break}}return n}return function(s,a=null,d=!1){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(t.copy(s),t.update(),s=t);const f=this.plane,g=s.plane;if(Math.abs(f.normal.dot(g.normal))>1-1e-10){const t=this.satBounds,l=this.satAxes;i[0]=s.a,i[1]=s.b,i[2]=s.c;for(let e=0;e<4;e++){const s=t[e],r=l[e];if(n.setFromPoints(r,i),s.isSeparated(n))return!1}const h=s.satBounds,c=s.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let t=0;t<4;t++){const i=h[t],s=c[t];if(n.setFromPoints(s,e),i.isSeparated(n))return!1}for(let t=0;t<4;t++){const s=l[t];for(let t=0;t<4;t++){const a=c[t];if(o.crossVectors(s,a),n.setFromPoints(o,e),r.setFromPoints(o,i),n.isSeparated(r))return!1}}return a&&(d||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const t=m(this,g,u);if(1===t&&s.containsPoint(u.end))return a&&(a.start.copy(u.end),a.end.copy(u.end)),!0;if(2!==t)return!1;const e=m(s,f,p);if(1===e&&this.containsPoint(p.end))return a&&(a.start.copy(p.end),a.end.copy(p.end)),!0;if(2!==e)return!1;if(u.delta(l),p.delta(h),l.dot(h)<0){let t=p.start;p.start=p.end,p.end=t}const i=u.start.dot(l),n=u.end.dot(l),r=p.start.dot(l),o=p.end.dot(l);return(i===o||r===n||n<r!==i<o)&&(a&&(c.subVectors(u.start,p.start),c.dot(l)>0?a.start.copy(u.start):a.start.copy(p.start),c.subVectors(u.end,p.end),c.dot(l)<0?a.end.copy(u.end):a.end.copy(p.end)),!0)}}}(),Ji.prototype.distanceToPoint=function(){const t=new s.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Ji.prototype.distanceToTriangle=function(){const t=new s.Vector3,e=new s.Vector3,i=["a","b","c"],n=new s.Line3,r=new s.Line3;return function(s,o=null,a=null){const l=o||a?n:null;if(this.intersectsTriangle(s,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let h=1/0;for(let e=0;e<3;e++){let n;const r=i[e],l=s[r];this.closestPointToPoint(l,t),n=l.distanceToSquared(t),n<h&&(h=n,o&&o.copy(t),a&&a.copy(l));const c=this[r];s.closestPointToPoint(c,t),n=c.distanceToSquared(t),n<h&&(h=n,o&&o.copy(c),a&&a.copy(t))}for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];n.set(this[c],this[d]);for(let l=0;l<3;l++){const c=i[l],d=i[(l+1)%3];r.set(s[c],s[d]),qi(n,r,t,e);const u=t.distanceToSquared(e);u<h&&(h=u,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(h)}}();class ts{constructor(t,e,i){this.isOrientedBox=!0,this.min=new s.Vector3,this.max=new s.Vector3,this.matrix=new s.Matrix4,this.invMatrix=new s.Matrix4,this.points=new Array(8).fill().map(()=>new s.Vector3),this.satAxes=new Array(3).fill().map(()=>new s.Vector3),this.satBounds=new Array(3).fill().map(()=>new Gi),this.alignedSatBounds=new Array(3).fill().map(()=>new Gi),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}ts.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let n=0;n<=1;n++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=s[1*n|2*r|4*o];a.x=n?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,o=s[0];for(let t=0;t<3;t++){const e=r[t],i=n[t],a=s[1<<t];e.subVectors(o,a),i.setFromPoints(e,s)}const a=this.alignedSatBounds;a[0].setFromPointsField(s,"x"),a[1].setFromPointsField(s,"y"),a[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),ts.prototype.intersectsBox=function(){const t=new Gi;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=s.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=s.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=s.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const s=r[i],o=n[i];if(t.setFromBox(s,e),o.isSeparated(t))return!1}return!0}}(),ts.prototype.intersectsTriangle=function(){const t=new Ji,e=new Array(3),i=new Gi,n=new Gi,r=new s.Vector3;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(t.copy(s),t.update(),s=t);const o=this.satBounds,a=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let t=0;t<3;t++){const s=o[t],n=a[t];if(i.setFromPoints(n,e),s.isSeparated(i))return!1}const l=s.satBounds,h=s.satAxes,c=this.points;for(let t=0;t<3;t++){const e=l[t],s=h[t];if(i.setFromPoints(s,c),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const s=a[t];for(let t=0;t<4;t++){const o=h[t];if(r.crossVectors(s,o),i.setFromPoints(r,e),n.setFromPoints(r,c),i.isSeparated(n))return!1}}return!0}}(),ts.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),ts.prototype.distanceToPoint=function(){const t=new s.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),ts.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new s.Line3),i=new Array(12).fill().map(()=>new s.Line3),n=new s.Vector3,r=new s.Vector3;return function(s,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(a||l)&&(s.getCenter(r),this.closestPointToPoint(r,n),s.closestPointToPoint(n,r),a&&a.copy(n),l&&l.copy(r)),0;const h=o*o,c=s.min,d=s.max,u=this.points;let p=1/0;for(let t=0;t<8;t++){const e=u[t];r.copy(e).clamp(c,d);const i=e.distanceToSquared(r);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(r),i<h))return Math.sqrt(i)}let f=0;for(let s=0;s<3;s++)for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){const o=(s+1)%3,a=(s+2)%3,l=1<<s|n<<o|r<<a,h=u[n<<o|r<<a],p=u[l];e[f].set(h,p);const m=t[s],g=t[o],_=t[a],y=i[f],w=y.start,v=y.end;w[m]=c[m],w[g]=n?c[g]:d[g],w[_]=r?c[_]:d[g],v[m]=d[m],v[g]=n?c[g]:d[g],v[_]=r?c[_]:d[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){r.x=t?d.x:c.x,r.y=e?d.y:c.y,r.z=i?d.z:c.z,this.closestPointToPoint(r,n);const s=r.distanceToSquared(n);if(s<p&&(p=s,a&&a.copy(n),l&&l.copy(r),s<h))return Math.sqrt(s)}for(let t=0;t<12;t++){const s=e[t];for(let t=0;t<12;t++){const e=i[t];qi(s,e,n,r);const o=n.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(n),l&&l.copy(r),o<h))return Math.sqrt(o)}}return Math.sqrt(p)}}();class es{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class is extends es{constructor(){super(()=>new Ji)}}const ss=new is;function ns(t,e){return 65535===e[t+15]}function rs(t,e){return e[t+6]}function os(t,e){return e[t+14]}function as(t){return t+8}function ls(t,e){return e[t+6]}function hs(t,e){return e[t+7]}function cs(t){return t}const ds=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}};let us,ps;const fs=[],ms=new es(()=>new s.Box3);function gs(t,e,i,s,n,r){us=ms.getPrimitive(),ps=ms.getPrimitive(),fs.push(us,ps),ds.setBuffer(t._roots[e]);const o=_s(0,t.geometry,i,s,n,r);ds.clearBuffer(),ms.releasePrimitive(us),ms.releasePrimitive(ps),fs.pop(),fs.pop();const a=fs.length;return a>0&&(ps=fs[a-1],us=fs[a-2]),o}function _s(t,e,i,s,n=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:h}=ds;let c=2*t;if(ns(c,l)){const e=rs(t,h),i=os(c,l);return Di(t,a,us),s(e,i,!1,o,r+t,us)}{let c=function(t){const{uint16Array:e,uint32Array:i}=ds;let s=2*t;for(;!ns(s,e);)s=2*(t=as(t));return rs(t,i)},d=function(t){const{uint16Array:e,uint32Array:i}=ds;let s=2*t;for(;!ns(s,e);)s=2*(t=ls(t,i));return rs(t,i)+os(s,e)};const u=as(t),p=ls(t,h);let f,m,g,_,y=u,w=p;if(n&&(g=us,_=ps,Di(y,a,g),Di(w,a,_),f=n(g),m=n(_),m<f)){y=p,w=u;const t=f;f=m,m=t,g=_}g||(g=us,Di(y,a,g));const v=i(g,ns(2*y,l),f,o+1,r+y);let b;if(2===v){const t=c(y);b=s(t,d(y)-t,!0,o+1,r+y,g)}else b=v&&_s(y,e,i,s,n,r,o+1);if(b)return!0;_=ps,Di(w,a,_);const x=i(_,ns(2*w,l),m,o+1,r+w);let T;if(2===x){const t=c(w);T=s(t,d(w)-t,!0,o+1,r+w,_)}else T=x&&_s(w,e,i,s,n,r,o+1);return!!T}}const ys=new s.Vector3,ws=new s.Vector3;const vs=new s.Vector3,bs=new s.Vector3,xs=new s.Vector3,Ts=new s.Vector2,Cs=new s.Vector2,Es=new s.Vector2,Ss=new s.Vector3,As=new s.Vector3,Os=new s.Vector3,Ps=new s.Vector3;function Is(t,e,i,n,r,o,a,l,h){vs.fromBufferAttribute(e,o),bs.fromBufferAttribute(e,a),xs.fromBufferAttribute(e,l);const c=function(t,e,i,n,r,o){let a;return a=o===s.BackSide?t.intersectTriangle(n,i,e,!0,r):t.intersectTriangle(e,i,n,o!==s.DoubleSide,r),null===a?null:{distance:t.origin.distanceTo(r),point:r.clone()}}(t,vs,bs,xs,Ps,h);if(c){n&&(Ts.fromBufferAttribute(n,o),Cs.fromBufferAttribute(n,a),Es.fromBufferAttribute(n,l),c.uv=s.Triangle.getInterpolation(Ps,vs,bs,xs,Ts,Cs,Es,new s.Vector2)),r&&(Ts.fromBufferAttribute(r,o),Cs.fromBufferAttribute(r,a),Es.fromBufferAttribute(r,l),c.uv1=s.Triangle.getInterpolation(Ps,vs,bs,xs,Ts,Cs,Es,new s.Vector2)),i&&(Ss.fromBufferAttribute(i,o),As.fromBufferAttribute(i,a),Os.fromBufferAttribute(i,l),c.normal=s.Triangle.getInterpolation(Ps,vs,bs,xs,Ss,As,Os,new s.Vector3),c.normal.dot(t.direction)>0&&c.normal.multiplyScalar(-1));const e={a:o,b:a,c:l,normal:new s.Vector3,materialIndex:0};s.Triangle.getNormal(vs,bs,xs,e.normal),c.face=e,c.faceIndex=o}return c}function Ms(t,e,i,s,n){const r=3*s;let o=r+0,a=r+1,l=r+2;const h=t.index;t.index&&(o=h.getX(o),a=h.getX(a),l=h.getX(l));const{position:c,normal:d,uv:u,uv1:p}=t.attributes,f=Is(i,c,d,u,p,o,a,l,e);return f?(f.faceIndex=s,n&&n.push(f),f):null}function Ds(t,e,i,s){const n=t.a,r=t.b,o=t.c;let a=e,l=e+1,h=e+2;i&&(a=i.getX(a),l=i.getX(l),h=i.getX(h)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),r.x=s.getX(l),r.y=s.getY(l),r.z=s.getZ(l),o.x=s.getX(h),o.y=s.getY(h),o.z=s.getZ(h)}function ks(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,Ds(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}function zs(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(t,i,r=!1){const h=2*t;if(a[h+15]===Ei){const e=o[t+6];let i=1/0,r=1/0,c=1/0,d=-1/0,u=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[h+14]);t<o;t++){let e=s[t];const o=n.getX(e),a=n.getY(e),l=n.getZ(e);o<i&&(i=o),o>d&&(d=o),a<r&&(r=a),a>u&&(u=a),l<c&&(c=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==c||l[t+3]!==d||l[t+4]!==u||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=c,l[t+3]=d,l[t+4]=u,l[t+5]=p,!0)}{const s=t+8,n=o[t+6],a=s+i,h=n+i;let c=r,u=!1,p=!1;e?c||(u=e.has(a),p=e.has(h),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(s,i,c));let g=!1;f&&(g=d(n,i,c));const _=m||g;if(_)for(let e=0;e<3;e++){const i=s+e,r=n+e,o=l[i],a=l[i+3],h=l[r],c=l[r+3];l[t+e]=o<h?o:h,l[t+e+3]=a>c?a:c}return _}}}const Bs=new s.Box3;function Ns(t,e,i,s){return Di(t,e,Bs),i.intersectBox(Bs,s)}function Us(t,e,i,s,n,r,o){const{geometry:a}=i,{index:l}=a,h=a.attributes.position;for(let a=t,c=e+t;a<c;a++){let t;if(t=i.resolveTriangleIndex(a),Ds(o,3*t,l,h),o.needsUpdate=!0,s(o,t,n,r))return!0}return!1}const Ls=new s.Vector3;function Rs(t,e,i,s,n){ds.setBuffer(t._roots[e]),Fs(0,t,i,s,n),ds.clearBuffer()}function Fs(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=ds,l=2*t;if(ns(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,a=s+n;t<a;t++)Ms(o,e,i,t,r)}(e,i,s,rs(t,a),os(l,o),n)}else{const o=as(t);Ns(o,r,s,Ls)&&Fs(o,e,i,s,n);const l=ls(t,a);Ns(l,r,s,Ls)&&Fs(l,e,i,s,n)}}const Vs=new s.Vector3,js=["x","y","z"];function Hs(t,e,i,s){ds.setBuffer(t._roots[e]);const n=Zs(0,t,i,s);return ds.clearBuffer(),n}function Zs(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=ds;let a=2*t;if(ns(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,o=s+n;t<o;t++){let s;s=Ms(r,e,i,t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,rs(t,o),os(a,r))}{const r=hs(t,o),a=js[r],l=s.direction[a]>=0;let h,c;l?(h=as(t),c=ls(t,o)):(h=ls(t,o),c=as(t));const d=Ns(h,n,s,Vs)?Zs(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=Ns(c,n,s,Vs)?Zs(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const $s=new s.Box3,Ws=new Ji,Ys=new Ji,Gs=new s.Matrix4,Xs=new ts,qs=new ts;function Qs(t,e,i,s){ds.setBuffer(t._roots[e]);const n=Ks(0,t,i,s);return ds.clearBuffer(),n}function Ks(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ds;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),Xs.set(i.boundingBox.min,i.boundingBox.max,s),n=Xs);if(!ns(l,o)){const o=t+8,l=a[t+6];Di(o,r,$s);if(n.intersectsBox($s)&&Ks(o,e,i,s,n))return!0;Di(l,r,$s);return!!(n.intersectsBox($s)&&Ks(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=rs(t,a),f=os(l,o);if(Gs.copy(s).invert(),i.boundsTree){Di(t,r,qs),qs.matrix.copy(Gs),qs.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>qs.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(Ds(Ys,e,h,c),Ys.needsUpdate=!0,t.intersectsTriangle(Ys))return!0;return!1}})}for(let t=3*p,e=3*(f+p);t<e;t+=3){Ds(Ws,t,h,c),Ws.a.applyMatrix4(Gs),Ws.b.applyMatrix4(Gs),Ws.c.applyMatrix4(Gs),Ws.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(Ds(Ys,t,d,u),Ys.needsUpdate=!0,Ws.intersectsTriangle(Ys))return!0}}}const Js=new s.Matrix4,tn=new ts,en=new ts,sn=new s.Vector3,nn=new s.Vector3,rn=new s.Vector3,on=new s.Vector3;function an(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),tn.set(e.boundingBox.min,e.boundingBox.max,i),tn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ss.getPrimitive(),p=ss.getPrimitive();let f=sn,m=nn,g=null,_=null;n&&(g=rn,_=on);let y=1/0,w=null,v=null;return Js.copy(i).invert(),en.matrix.copy(Js),t.shapecast({boundsTraverseOrder:t=>tn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(en.min.copy(t.min),en.max.copy(t.max),en.needsUpdate=!0),!0),intersectsRange:(t,s)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>en.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,n)=>{for(let o=e,a=e+n;o<a;o++){Ds(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){Ds(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=o),t<r)return!0}}}})}for(let n=0,o=Oi(e);n<o;n++){Ds(p,3*n,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++){Ds(u,3*e,h,l),u.needsUpdate=!0;const t=u.distanceToTriangle(p,f,g);if(t<y&&(m.copy(f),_&&_.copy(g),y=t,w=e,v=n),t<r)return!0}}}}),ss.releasePrimitive(u),ss.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(Js),m.applyMatrix4(Js),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}function ln(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,l,h=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)r=c[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),d(0,h),h+=r.byteLength;function d(i,r,h=!1){const c=2*i;if(a[c+15]===Ei){const e=o[i+6];let r=1/0,h=1/0,d=1/0,u=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+a[c+14];i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=s?s[i]:i;const o=n.getX(i),a=n.getY(i),l=n.getZ(i);o<r&&(r=o),o>u&&(u=o),a<h&&(h=a),a>p&&(p=a),l<d&&(d=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==h||l[i+2]!==d||l[i+3]!==u||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=h,l[i+2]=d,l[i+3]=u,l[i+4]=p,l[i+5]=f,!0)}{const t=i+8,s=o[i+6],n=t+r,a=s+r;let c=h,u=!1,p=!1;e?c||(u=e.has(n),p=e.has(a),c=!u&&!p):(u=!0,p=!0);const f=c||p;let m=!1;(c||u)&&(m=d(t,r,c));let g=!1;f&&(g=d(s,r,c));const _=m||g;if(_)for(let e=0;e<3;e++){const n=t+e,r=s+e,o=l[n],a=l[n+3],h=l[r],c=l[r+3];l[i+e]=o<h?o:h,l[i+e+3]=a>c?a:c}return _}}}const hn=new s.Vector3;function cn(t,e,i,s,n){ds.setBuffer(t._roots[e]),dn(0,t,i,s,n),ds.clearBuffer()}function dn(t,e,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=ds,l=2*t;if(ns(l,o)){!function(t,e,i,s,n,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=s,l=s+n;t<l;t++)Ms(o,e,i,a?a[t]:t,r)}(e,i,s,rs(t,a),os(l,o),n)}else{const o=as(t);Ns(o,r,s,hn)&&dn(o,e,i,s,n);const l=ls(t,a);Ns(l,r,s,hn)&&dn(l,e,i,s,n)}}const un=new s.Vector3,pn=["x","y","z"];function fn(t,e,i,s){ds.setBuffer(t._roots[e]);const n=mn(0,t,i,s);return ds.clearBuffer(),n}function mn(t,e,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=ds;let a=2*t;if(ns(a,r)){return function(t,e,i,s,n){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=s,h=s+n;t<h;t++){let s;s=Ms(r,e,i,o?o[t]:t),s&&s.distance<a&&(l=s,a=s.distance)}return l}(e,i,s,rs(t,o),os(a,r))}{const r=hs(t,o),a=pn[r],l=s.direction[a]>=0;let h,c;l?(h=as(t),c=ls(t,o)):(h=ls(t,o),c=as(t));const d=Ns(h,n,s,un)?mn(h,e,i,s):null;if(d){const t=d.point[a];if(l?t<=n[c+r]:t>=n[c+r+3])return d}const u=Ns(c,n,s,un)?mn(c,e,i,s):null;return d&&u?d.distance<=u.distance?d:u:d||u||null}}const gn=new s.Box3,_n=new Ji,yn=new Ji,wn=new s.Matrix4,vn=new ts,bn=new ts;function xn(t,e,i,s){ds.setBuffer(t._roots[e]);const n=Tn(0,t,i,s);return ds.clearBuffer(),n}function Tn(t,e,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=ds;let l=2*t;null===n&&(i.boundingBox||i.computeBoundingBox(),vn.set(i.boundingBox.min,i.boundingBox.max,s),n=vn);if(!ns(l,o)){const o=t+8,l=a[t+6];Di(o,r,gn);if(n.intersectsBox(gn)&&Tn(o,e,i,s,n))return!0;Di(l,r,gn);return!!(n.intersectsBox(gn)&&Tn(l,e,i,s,n))}{const n=e.geometry,h=n.index,c=n.attributes.position,d=i.index,u=i.attributes.position,p=rs(t,a),f=os(l,o);if(wn.copy(s).invert(),i.boundsTree){Di(t,r,bn),bn.matrix.copy(wn),bn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>bn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(s),t.b.applyMatrix4(s),t.c.applyMatrix4(s),t.needsUpdate=!0;for(let i=p,s=f+p;i<s;i++)if(Ds(yn,3*e.resolveTriangleIndex(i),h,c),yn.needsUpdate=!0,t.intersectsTriangle(yn))return!0;return!1}})}for(let t=p,i=f+p;t<i;t++){const i=e.resolveTriangleIndex(t);Ds(_n,3*i,h,c),_n.a.applyMatrix4(wn),_n.b.applyMatrix4(wn),_n.c.applyMatrix4(wn),_n.needsUpdate=!0;for(let t=0,e=d.count;t<e;t+=3)if(Ds(yn,t,d,u),yn.needsUpdate=!0,_n.intersectsTriangle(yn))return!0}}}const Cn=new s.Matrix4,En=new ts,Sn=new ts,An=new s.Vector3,On=new s.Vector3,Pn=new s.Vector3,In=new s.Vector3;function Mn(t,e,i,s={},n={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),En.set(e.boundingBox.min,e.boundingBox.max,i),En.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,u=ss.getPrimitive(),p=ss.getPrimitive();let f=An,m=On,g=null,_=null;n&&(g=Pn,_=In);let y=1/0,w=null,v=null;return Cn.copy(i).invert(),Sn.matrix.copy(Cn),t.shapecast({boundsTraverseOrder:t=>En.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o&&(e&&(Sn.min.copy(t.min),Sn.max.copy(t.max),Sn.needsUpdate=!0),!0),intersectsRange:(s,n)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>Sn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<y&&i<o,intersectsRange:(e,o)=>{for(let b=e,x=e+o;b<x;b++){const e=a.resolveTriangleIndex(b);Ds(p,3*e,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);Ds(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=b),s<r)return!0}}}})}for(let o=0,a=Oi(e);o<a;o++){Ds(p,3*o,d,c),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=s,i=s+n;e<i;e++){const i=t.resolveTriangleIndex(e);Ds(u,3*i,h,l),u.needsUpdate=!0;const s=u.distanceToTriangle(p,f,g);if(s<y&&(m.copy(f),_&&_.copy(g),y=s,w=e,v=o),s<r)return!0}}}}),ss.releasePrimitive(u),ss.releasePrimitive(p),y===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=y,s.faceIndex=w,n&&(n.point?n.point.copy(_):n.point=_.clone(),n.point.applyMatrix4(Cn),m.applyMatrix4(Cn),n.distance=m.sub(n.point).length(),n.faceIndex=v),s)}const Dn=new ds.constructor,kn=new ds.constructor,zn=new es(()=>new s.Box3),Bn=new s.Box3,Nn=new s.Box3,Un=new s.Box3,Ln=new s.Box3;let Rn=!1;function Fn(t,e,i,s,n,r=0,o=0,a=0,l=0,h=null,c=!1){let d,u;c?(d=kn,u=Dn):(d=Dn,u=kn);const p=d.float32Array,f=d.uint32Array,m=d.uint16Array,g=u.float32Array,_=u.uint32Array,y=u.uint16Array,w=2*e,v=ns(2*t,m),b=ns(w,y);let x=!1;if(b&&v)x=c?n(rs(e,_),os(2*e,y),rs(t,f),os(2*t,m),l,o+e,a,r+t):n(rs(t,f),os(2*t,m),rs(e,_),os(2*e,y),a,r+t,l,o+e);else if(b){const h=zn.getPrimitive();Di(e,g,h),h.applyMatrix4(i);const d=as(t),u=ls(t,f);Di(d,p,Bn),Di(u,p,Nn);const m=h.intersectsBox(Bn),_=h.intersectsBox(Nn);x=m&&Fn(e,d,s,i,n,o,r,l,a+1,h,!c)||_&&Fn(e,u,s,i,n,o,r,l,a+1,h,!c),zn.releasePrimitive(h)}else{const d=as(e),u=ls(e,_);Di(d,g,Un),Di(u,g,Ln);const m=h.intersectsBox(Un),y=h.intersectsBox(Ln);if(m&&y)x=Fn(t,d,i,s,n,r,o,a,l+1,h,c)||Fn(t,u,i,s,n,r,o,a,l+1,h,c);else if(m)if(v)x=Fn(t,d,i,s,n,r,o,a,l+1,h,c);else{const e=zn.getPrimitive();e.copy(Un).applyMatrix4(i);const h=as(t),u=ls(t,f);Di(h,p,Bn),Di(u,p,Nn);const m=e.intersectsBox(Bn),g=e.intersectsBox(Nn);x=m&&Fn(d,h,s,i,n,o,r,l,a+1,e,!c)||g&&Fn(d,u,s,i,n,o,r,l,a+1,e,!c),zn.releasePrimitive(e)}else if(y)if(v)x=Fn(t,u,i,s,n,r,o,a,l+1,h,c);else{const e=zn.getPrimitive();e.copy(Ln).applyMatrix4(i);const h=as(t),d=ls(t,f);Di(h,p,Bn),Di(d,p,Nn);const m=e.intersectsBox(Bn),g=e.intersectsBox(Nn);x=m&&Fn(u,h,s,i,n,o,r,l,a+1,e,!c)||g&&Fn(u,d,s,i,n,o,r,l,a+1,e,!c),zn.releasePrimitive(e)}}return x}const Vn=new ts,jn=new s.Box3;class Hn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex();let o;return o=e.cloneBuffers?{roots:s.map(t=>t.slice()),index:r.array.slice(),indirectBuffer:n?n.slice():null}:{roots:s,index:r.array,indirectBuffer:n},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:n,roots:r,indirectBuffer:o}=t,a=new Hn(e,{...i,[Ai]:!0});if(a._roots=r,a._indirectBuffer=o||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new s.BufferAttribute(t.index,1,!1);e.setIndex(i)}else i.array!==n&&(i.array.set(n),i.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ai]:!1},e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Ai]||(Yi(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new s.Box3)));const{_indirectBuffer:i}=this;this.resolveTriangleIndex=e.indirect?t=>i[t]:t=>t}refit(t=null){return(this.indirect?ln:zs)(this,t)}traverse(t,e=0){const i=this._roots[e],s=new Uint32Array(i),n=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=n[a+15]===Ei;if(l){const e=s[r+6],h=n[a+14];t(o,l,new Float32Array(i,4*r,6),e,h)}else{const n=r+8,a=s[r+6],h=s[r+7];t(o,l,new Float32Array(i,4*r,6),h)||(e(n,o+1),e(a,o+1))}}(0)}raycast(t,e=s.FrontSide){const i=this._roots,n=this.geometry,r=[],o=e.isMaterial,a=Array.isArray(e),l=n.groups,h=o?e.side:e,c=this.indirect?cn:Rs;for(let s=0,n=i.length;s<n;s++){const i=a?e[l[s].materialIndex].side:h,n=r.length;if(c(this,s,i,t,r),a){const t=l[s].materialIndex;for(let e=n,i=r.length;e<i;e++)r[e].face.materialIndex=t}}return r}raycastFirst(t,e=s.FrontSide){const i=this._roots,n=this.geometry,r=e.isMaterial,o=Array.isArray(e);let a=null;const l=n.groups,h=r?e.side:e,c=this.indirect?fn:Hs;for(let s=0,n=i.length;s<n;s++){const i=c(this,s,o?e[l[s].materialIndex].side:h,t);null!=i&&(null==a||i.distance<a.distance)&&(a=i,o&&(i.face.materialIndex=l[s].materialIndex))}return a}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?xn:Qs;for(let r=0,o=s.length;r<o&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ss.getPrimitive(),i=this.indirect?Us:ks;let{boundsTraverseOrder:s,intersectsBounds:n,intersectsRange:r,intersectsTriangle:o}=t;if(r&&o){const t=r;r=(s,n,r,a,l)=>!!t(s,n,r,a,l)||i(s,n,this,o,r,a,e)}else r||(r=o?(t,s,n,r)=>i(t,s,this,o,n,r,e):(t,e,i)=>i);let a=!1,l=0;const h=this._roots;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(a=gs(this,t,n,r,s,l),a)break;l+=e.byteLength}return ss.releasePrimitive(e),a}bvhcast(t,e,i){let{intersectsRanges:n,intersectsTriangles:r}=i;const o=ss.getPrimitive(),a=this.geometry.index,l=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);Ds(o,3*e,a,l)}:t=>{Ds(o,3*t,a,l)},c=ss.getPrimitive(),d=t.geometry.index,u=t.geometry.attributes.position,p=t.indirect?e=>{const i=t.resolveTriangleIndex(e);Ds(c,3*i,d,u)}:t=>{Ds(c,3*t,d,u)};if(r){const t=(t,i,s,n,a,l,d,u)=>{for(let f=s,m=s+n;f<m;f++){p(f),c.a.applyMatrix4(e),c.b.applyMatrix4(e),c.c.applyMatrix4(e),c.needsUpdate=!0;for(let e=t,s=t+i;e<s;e++)if(h(e),o.needsUpdate=!0,r(o,c,e,f,a,l,d,u))return!0}return!1};if(n){const e=n;n=function(i,s,n,r,o,a,l,h){return!!e(i,s,n,r,o,a,l,h)||t(i,s,n,r,o,a,l,h)}}else n=t}return function(t,e,i,n){if(Rn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Rn=!0;const r=t._roots,o=e._roots;let a,l=0,h=0;const c=(new s.Matrix4).copy(i).invert();for(let t=0,e=r.length;t<e;t++){Dn.setBuffer(r[t]),h=0;const e=zn.getPrimitive();Di(cs(0),Dn.float32Array,e),e.applyMatrix4(c);for(let s=0,r=o.length;s<r&&(kn.setBuffer(o[t]),a=Fn(0,0,i,c,n,l,h,0,0,e),kn.clearBuffer(),h+=o[s].length,!a);s++);if(zn.releasePrimitive(e),Dn.clearBuffer(),l+=r[t].length,a)break}return Rn=!1,a}(this,t,e,n)}intersectsBox(t,e){return Vn.set(t.min,t.max,e),Vn.needsUpdate=!0,this.shapecast({intersectsBounds:t=>Vn.intersectsBox(t),intersectsTriangle:t=>Vn.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Mn:an)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return function(t,e,i={},s=0,n=1/0){const r=s*s,o=n*n;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(ys.copy(e).clamp(t.min,t.max),ys.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,ys);const s=e.distanceToSquared(ys);return s<a&&(ws.copy(ys),a=s,l=i),s<r}}),a===1/0)return null;const h=Math.sqrt(a);return i.point?i.point.copy(ws):i.point=ws.clone(),i.distance=h,i.faceIndex=l,i}(this,t,e,i,s)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{Di(0,new Float32Array(e),jn),t.union(jn)}),t}}function Zn(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t.distance<i.near||t.distance>i.far?null:t)}const $n=new s.Ray,Wn=new s.Matrix4,Yn=s.Mesh.prototype.raycast;function Gn(t,e){if(this.geometry.boundsTree){if(void 0===this.material)return;Wn.copy(this.matrixWorld).invert(),$n.copy(t.ray).applyMatrix4(Wn);const i=this.geometry.boundsTree;if(!0===t.firstHitOnly){const s=Zn(i.raycastFirst($n,this.material),this,t);s&&e.push(s)}else{const s=i.raycast($n,this.material);for(let i=0,n=s.length;i<n;i++){const n=Zn(s[i],this,t);n&&e.push(n)}}}else Yn.call(this,t,e)}function Xn(t){return this.boundsTree=new Hn(this,t),this.boundsTree}function qn(){this.boundsTree=null}const Qn=class t{constructor(){e(this,"onDisposed",new h),e(this,"list",new i.DataMap),e(this,"enabled",!1),e(this,"_clock"),e(this,"onInit",new h),e(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._clock=new a.Clock,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");v.validate(t),this.list.set(t,e)}get(t){var e;const i=t.uuid;if(!this.list.has(i)){const s=new t(this);return(null==(e=s.isDisposeable)?void 0:e.call(s))&&s.onDisposed.add(()=>this.list.delete(i)),this.list.has(i)||this.add(i,s),s}return this.list.get(i)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._clock.start(),this.update(),this.onInit.trigger()}dispose(){let t;this.enabled=!1;for(const[e,i]of this.list)i.enabled=!1,e!==qt.uuid?i.isDisposeable()&&i.dispose():t=i;null==t||t.dispose(),this._clock.stop(),this.onDisposed.trigger()}static setupBVH(){a.BufferGeometry.prototype.computeBoundsTree=Xn,a.BufferGeometry.prototype.disposeBoundsTree=qn,a.Mesh.prototype.raycast=Gn}};e(Qn,"release","2.4.3");let Kn=Qn;class Jn{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new a.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=gi.ACTION.DOLLY,t.touches.two=gi.ACTION.TOUCH_ZOOM_TRUCK}}class tr{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new a.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:s}=this.camera.three,n=new a.Vector3(0,0,-1).applyEuler(s),r=e.addScaledVector(n,i);t.moveTo(r.x,r.y,r.z)}}class er{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=gi.ACTION.TRUCK,e.touches.one=gi.ACTION.TOUCH_TRUCK,e.touches.two=gi.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=gi.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class ir{constructor(t){e(this,"onChanged",new h),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new a.Vector3;this._component.threePersp.getWorldDirection(e);const i=new a.Vector3;this._component.controls.getTarget(i);const s=i.clone().sub(this._component.threePersp.position).dot(e),n=t.renderer.getSize(),r=n.x/n.y,o=this._component.threePersp,l=2*s*Math.atan(o.fov*(Math.PI/180)/2);return{width:l*r,height:l}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=gi.ACTION.ZOOM,this._component.controls.mouseButtons.middle=gi.ACTION.ZOOM;const i=this._component.threePersp,s=this._component.threeOrtho;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this._component.controls.camera=s}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=gi.ACTION.DOLLY,this._component.controls.mouseButtons.middle=gi.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=gi.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class sr extends _i{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new ir(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new tr(this)),this._navigationModes.set("FirstPerson",new Jn(this)),this._navigationModes.set("Plan",new er(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,s=Number.MIN_VALUE,n=new a.Vector3(i,i,i),r=new a.Vector3(s,s,s);for(const e of t){const t=(new a.Box3).setFromObject(e);t.min.x<n.x&&(n.x=t.min.x),t.min.y<n.y&&(n.y=t.min.y),t.min.z<n.z&&(n.z=t.min.z),t.max.x>r.x&&(r.x=t.max.x),t.max.y>r.y&&(r.y=t.max.y),t.max.z>r.z&&(r.z=t.max.z)}const o=new a.Box3(n,r),l=this.components.get(qt);if(l.initialized)for(const[,t]of l.list){const e=t.box;e.min.x<n.x&&(n.x=e.min.x),e.min.y<n.y&&(n.y=e.min.y),e.min.z<n.z&&(n.z=e.min.z),e.max.x>r.x&&(r.x=e.max.x),e.max.y>r.y&&(r.y=e.max.y),e.max.z>r.z&&(r.z=e.max.z)}const h=new a.Vector3;o.getSize(h);const c=new a.Vector3;o.getCenter(c);const d=Math.max(h.x,h.y,h.z)*e,u=new a.Sphere(c,d);await this.controls.fitToSphere(u,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}addCustomNavigationMode(t){this._navigationModes.set(t.id,t)}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new a.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,s=e*(t.y/this.previousSize.y),n=i*(t.x/this.previousSize.x);this.threeOrtho.left=-n,this.threeOrtho.right=n,this.threeOrtho.top=s,this.threeOrtho.bottom=-s,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}function nr(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var rr={exports:{}};
1
+ "use strict";var t=Object.defineProperty,e=(e,i,n)=>(((e,i,n)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n})(e,"symbol"!=typeof i?i+"":i,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@thatopen/fragments"),n=require("three"),s=require("web-ifc"),r=require("camera-controls");function o(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const a=o(i),l=o(n),c=o(s);class h{constructor(){e(this,"enabled",!0),e(this,"trigger",t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class u{constructor(t){e(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),e(this,"isResizeable",()=>"resize"in this&&"getSize"in this),e(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),e(this,"isHideable",()=>"visible"in this),e(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),e(this,"isSerializable",()=>"import"in this&&"export"in this),this.components=t}}class d extends u{}class p extends u{constructor(t){super(t),e(this,"worlds",new i.DataMap),e(this,"onWorldChanged",new h),e(this,"_currentWorld",null),this.onWorldChanged.add(({world:t,action:e})=>{"removed"===e&&this.worlds.delete(t.uuid)})}set currentWorld(t){this._currentWorld=t}get currentWorld(){return this._currentWorld}}class f extends p{constructor(){super(...arguments),e(this,"hasCameraControls",()=>"controls"in this)}}class m extends p{constructor(){super(...arguments),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"onResize",new h),e(this,"onClippingPlanesUpdated",new h),e(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i){e.isLocal=i;const n=this.clippingPlanes.indexOf(e);t&&-1===n?this.clippingPlanes.push(e):!t&&n>-1&&this.clippingPlanes.splice(n,1),this.three.clippingPlanes=this.clippingPlanes.filter(t=>!t.isLocal)}}const g=class t extends d{constructor(i){super(i),e(this,"_disposedComponents",new Set),e(this,"enabled",!0),i.add(t.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const n=t;n.dispose&&n.dispose(),this.disposeGeometryAndMaterials(t,e),i&&n.children&&n.children.length&&this.disposeChildren(n),t.children.length=0}disposeGeometry(t){t.boundsTree&&t.disposeBoundsTree&&t.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(e,i){const n=e;n.geometry&&this.disposeGeometry(n.geometry),i&&n.material&&t.disposeMaterial(n),n.material=[],n.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};e(g,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let y=g;class w extends p{constructor(t){super(t),e(this,"onDisposed",new h),e(this,"directionalLights",new Map),e(this,"ambientLights",new Map)}dispose(){const t=this.components.get(y);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,t]of this.directionalLights)t.removeFromParent(),t.target.removeFromParent(),t.dispose();this.directionalLights.clear();for(const[,t]of this.ambientLights)t.removeFromParent(),t.dispose();this.ambientLights.clear()}}class v extends Set{constructor(t){super(t),e(this,"onItemAdded",new h),e(this,"onItemDeleted",new h),e(this,"onCleared",new h),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}add(...t){for(const e of t){if(this.has(e))continue;this.guard(e)&&(super.add(e),this.onItemAdded||(this.onItemAdded=new h),this.onItemAdded.trigger(e))}return this}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(),e}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}const b=class t{static create(){const e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return`${t._lut[255&e]+t._lut[e>>8&255]+t._lut[e>>16&255]+t._lut[e>>24&255]}-${t._lut[255&i]}${t._lut[i>>8&255]}-${t._lut[i>>16&15|64]}${t._lut[i>>24&255]}-${t._lut[63&n|128]}${t._lut[n>>8&255]}-${t._lut[n>>16&255]}${t._lut[n>>24&255]}${t._lut[255&s]}${t._lut[s>>8&255]}${t._lut[s>>16&255]}${t._lut[s>>24&255]}`.toLowerCase()}static validate(e){if(!t._pattern.test(e))throw new Error(`${e} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};e(b,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),e(b,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let _=b;const x=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",S=new RegExp("^"+("["+x+"]["+(x+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040")+"]*")+"$");function C(t,e){const i=[];let n=e.exec(t);for(;n;){const s=[];s.startIndex=e.lastIndex-n[0].length;const r=n.length;for(let t=0;t<r;t++)s.push(n[t]);i.push(s),n=e.exec(t)}return i}const A=function(t){const e=S.exec(t);return!(null==e)};const E={allowBooleanAttributes:!1,unpairedTags:[]};function T(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function I(t,e){const i=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const n=t.substr(i,e-i);if(e>5&&"xml"===n)return N("InvalidXml","XML declaration allowed only at the start of the document.",R(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function P(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){let i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&(i--,0===i))break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}const M='"',k="'";function D(t,e){let i="",n="",s=!1;for(;e<t.length;e++){if(t[e]===M||t[e]===k)""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){s=!0;break}i+=t[e]}return""===n&&{value:i,index:e,tagClosed:s}}const z=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function B(t,e){const i=C(t,z),n={};for(let t=0;t<i.length;t++){if(0===i[t][1].length)return N("InvalidAttr","Attribute '"+i[t][2]+"' has no space in starting.",L(i[t]));if(void 0!==i[t][3]&&void 0===i[t][4])return N("InvalidAttr","Attribute '"+i[t][2]+"' is without value.",L(i[t]));if(void 0===i[t][3]&&!e.allowBooleanAttributes)return N("InvalidAttr","boolean attribute '"+i[t][2]+"' is not allowed.",L(i[t]));const s=i[t][2];if(!V(s))return N("InvalidAttr","Attribute '"+s+"' is an invalid name.",L(i[t]));if(n.hasOwnProperty(s))return N("InvalidAttr","Attribute '"+s+"' is repeated.",L(i[t]));n[s]=1}return!0}function O(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);let i=0;for(;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function N(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function V(t){return A(t)}function F(t){return A(t)}function R(t,e){const i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function L(t){return t.startIndex+t[1].length}const U={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1};function $(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:t.maxEntitySize??1e4,maxExpansionDepth:t.maxExpansionDepth??10,maxTotalExpansions:t.maxTotalExpansions??1e3,maxExpandedLength:t.maxExpandedLength??1e5,allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null}:$(!0)}const j=function(t){const e=Object.assign({},U,t);return e.processEntities=$(e.processEntities),e};let W;W="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class Z{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][W]={startIndex:e})}static getMetaDataSymbol(){return W}}class G{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const i={};if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");{e+=9;let n=1,s=!1,r=!1,o="";for(;e<t.length;e++)if("<"!==t[e]||r)if(">"===t[e]){if(r?"-"===t[e-1]&&"-"===t[e-2]&&(r=!1,n--):n--,0===n)break}else"["===t[e]?s=!0:o+=t[e];else{if(s&&Y(t,"!ENTITY",e)){let n,s;if(e+=7,[n,s,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===s.indexOf("&")){const t=n.replace(/[.\-+*:]/g,"\\.");i[n]={regx:RegExp(`&${t};`,"g"),val:s}}}else if(s&&Y(t,"!ELEMENT",e)){e+=8;const{index:i}=this.readElementExp(t,e+1);e=i}else if(s&&Y(t,"!ATTLIST",e))e+=8;else if(s&&Y(t,"!NOTATION",e)){e+=9;const{index:i}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=i}else{if(!Y(t,"!--",e))throw new Error("Invalid DOCTYPE");r=!0}n++,o=""}if(0!==n)throw new Error("Unclosed DOCTYPE")}return{entities:i,i:e}}readEntityExp(t,e){e=q(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)i+=t[e],e++;if(H(i),e=q(t,e),!this.suppressValidationErr){if("SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported")}let n="";if([e,n]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&this.options.maxEntitySize&&n.length>this.options.maxEntitySize)throw new Error(`Entity "${i}" size (${n.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[i,n,--e]}readNotationExp(t,e){e=q(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;!this.suppressValidationErr&&H(i),e=q(t,e);const n=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==n&&"PUBLIC"!==n)throw new Error(`Expected SYSTEM or PUBLIC, found "${n}"`);e+=n.length,e=q(t,e);let s=null,r=null;if("PUBLIC"===n)[e,s]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=q(t,e)]&&"'"!==t[e]||([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===n&&([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!r))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:i,publicIdentifier:s,systemIdentifier:r,index:--e}}readIdentifierVal(t,e,i){let n="";const s=t[e];if('"'!==s&&"'"!==s)throw new Error(`Expected quoted string, found "${s}"`);for(e++;e<t.length&&t[e]!==s;)n+=t[e],e++;if(t[e]!==s)throw new Error(`Unterminated ${i} value`);return[++e,n]}readElementExp(t,e){e=q(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!A(i))throw new Error(`Invalid element name: "${i}"`);let n="";if("E"===t[e=q(t,e)]&&Y(t,"MPTY",e))e+=4;else if("A"===t[e]&&Y(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)n+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:i,contentModel:n.trim(),index:e}}readAttlistExp(t,e){e=q(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;H(i),e=q(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!H(n))throw new Error(`Invalid attribute name: "${n}"`);e=q(t,e);let s="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(s="NOTATION","("!==t[e=q(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let i=[];for(;e<t.length&&")"!==t[e];){let n="";for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)n+=t[e],e++;if(n=n.trim(),!H(n))throw new Error(`Invalid notation name: "${n}"`);i.push(n),"|"===t[e]&&(e++,e=q(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,s+=" ("+i.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;const i=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!i.includes(s.toUpperCase()))throw new Error(`Invalid attribute type: "${s}"`)}e=q(t,e);let r="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(r="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(r="#IMPLIED",e+=7):[e,r]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:i,attributeName:n,attributeType:s,defaultValue:r,index:e}}}const q=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function Y(t,e,i){for(let n=0;n<e.length;n++)if(e[n]!==t[i+n+1])return!1;return!0}function H(t){if(A(t))return t;throw new Error(`Invalid entity name ${t}`)}const X=/^[-+]?0x[a-fA-F0-9]+$/,Q=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,K={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function J(t,e={}){if(e=Object.assign({},K,e),!t||"string"!=typeof t)return t;let i=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===t)return 0;if(e.hex&&X.test(i))return function(t,e){if(parseInt)return parseInt(t,e);if(Number.parseInt)return Number.parseInt(t,e);if(window&&window.parseInt)return window.parseInt(t,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(i,16);if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const n=e.match(tt);if(n){let s=n[1]||"";const r=-1===n[3].indexOf("e")?"E":"e",o=n[2],a=s?t[o.length+1]===r:t[o.length]===r;return o.length>1&&a?t:1!==o.length||!n[3].startsWith(`.${r}`)&&n[3][0]!==r?i.leadingZeros&&!a?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,i,e);{const n=Q.exec(i);if(n){const s=n[1]||"",r=n[2];let o=function(t){if(t&&-1!==t.indexOf("."))return"."===(t=t.replace(/0+$/,""))?t="0":"."===t[0]?t="0"+t:"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),t;return t}(n[3]);const a=s?"."===t[r.length+1]:"."===t[r.length];if(!e.leadingZeros&&(r.length>1||1===r.length&&!a))return t;{const n=Number(i),a=String(n);if(0===n)return n;if(-1!==a.search(/[eE]/))return e.eNotation?n:t;if(-1!==i.indexOf("."))return"0"===a||a===o||a===`${s}${o}`?n:t;let l=r?o:i;return r?l===a||s+l===a?n:t:l===a||l===s+a?n:t}}return t}}const tt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function et(t){return"function"==typeof t?t:Array.isArray(t)?e=>{for(const i of t){if("string"==typeof i&&e===i)return!0;if(i instanceof RegExp&&i.test(e))return!0}}:()=>!1}class it{constructor(t){if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>yt(e,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>yt(e,16,"&#x")}},this.addExternalEntities=nt,this.parseXml=lt,this.parseTextData=st,this.resolveNameSpace=rt,this.buildAttributesMap=at,this.isItStopNode=dt,this.replaceEntitiesValue=ht,this.readStopNodeData=mt,this.saveTextToParentTag=ut,this.addChild=ct,this.ignoreAttributesFn=et(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e&&(e.startsWith("*.")?this.stopNodesWildcard.add(e.substring(2)):this.stopNodesExact.add(e))}}}}function nt(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i],s=n.replace(/[.\-+*:]/g,"\\.");this.lastEntities[n]={regex:new RegExp("&"+s+";","g"),val:t[n]}}}function st(t,e,i,n,s,r,o){if(void 0!==t&&(this.options.trimValues&&!n&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));const n=this.options.tagValueProcessor(e,t,i,s,r);if(null==n)return t;if(typeof n!=typeof t||n!==t)return n;if(this.options.trimValues)return gt(t,this.options.parseTagValue,this.options.numberParseOptions);return t.trim()===t?gt(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function rt(t){if(this.options.removeNSPrefix){const e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}const ot=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function at(t,e,i){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const n=C(t,ot),s=n.length,r={};for(let t=0;t<s;t++){const s=this.resolveNameSpace(n[t][1]);if(this.ignoreAttributesFn(s,e))continue;let o=n[t][4],a=this.options.attributeNamePrefix+s;if(s.length)if(this.options.transformAttributeName&&(a=this.options.transformAttributeName(a)),"__proto__"===a&&(a="#__proto__"),void 0!==o){this.options.trimValues&&(o=o.trim()),o=this.replaceEntitiesValue(o,i,e);const t=this.options.attributeValueProcessor(s,o,e);r[a]=null==t?o:typeof t!=typeof o||t!==o?t:gt(o,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(r[a]=!0)}if(!Object.keys(r).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=r,t}return r}}const lt=function(t){t=t.replace(/\r\n?/g,"\n");const e=new Z("!xml");let i=e,n="",s="";this.entityExpansionCount=0,this.currentExpandedLength=0;const r=new G(this.options.processEntities);for(let o=0;o<t.length;o++){if("<"===t[o])if("/"===t[o+1]){const e=pt(t,">",o,"Closing Tag is not closed.");let r=t.substring(o+2,e).trim();if(this.options.removeNSPrefix){const t=r.indexOf(":");-1!==t&&(r=r.substr(t+1))}this.options.transformTagName&&(r=this.options.transformTagName(r)),i&&(n=this.saveTextToParentTag(n,i,s));const a=s.substring(s.lastIndexOf(".")+1);if(r&&-1!==this.options.unpairedTags.indexOf(r))throw new Error(`Unpaired tag can not be used as closing tag: </${r}>`);let l=0;a&&-1!==this.options.unpairedTags.indexOf(a)?(l=s.lastIndexOf(".",s.lastIndexOf(".")-1),this.tagsNodeStack.pop()):l=s.lastIndexOf("."),s=s.substring(0,l),i=this.tagsNodeStack.pop(),n="",o=e}else if("?"===t[o+1]){let e=ft(t,o,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(n=this.saveTextToParentTag(n,i,s),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new Z(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,s,e.tagName)),this.addChild(i,t,s,o)}o=e.closeIndex+1}else if("!--"===t.substr(o+1,3)){const e=pt(t,"--\x3e",o+4,"Comment is not closed.");if(this.options.commentPropName){const r=t.substring(o+4,e-2);n=this.saveTextToParentTag(n,i,s),i.add(this.options.commentPropName,[{[this.options.textNodeName]:r}])}o=e}else if("!D"===t.substr(o+1,2)){const e=r.readDocType(t,o);this.docTypeEntities=e.entities,o=e.i}else if("!["===t.substr(o+1,2)){const e=pt(t,"]]>",o,"CDATA is not closed.")-2,r=t.substring(o+9,e);n=this.saveTextToParentTag(n,i,s);let a=this.parseTextData(r,i.tagname,s,!0,!1,!0,!0);null==a&&(a=""),this.options.cdataPropName?i.add(this.options.cdataPropName,[{[this.options.textNodeName]:r}]):i.add(this.options.textNodeName,a),o=e+2}else{let r=ft(t,o,this.options.removeNSPrefix),a=r.tagName;const l=r.rawTagName;let c=r.tagExp,h=r.attrExpPresent,u=r.closeIndex;if(this.options.transformTagName){const t=this.options.transformTagName(a);c===a&&(c=t),a=t}i&&n&&"!xml"!==i.tagname&&(n=this.saveTextToParentTag(n,i,s,!1));const d=i;d&&-1!==this.options.unpairedTags.indexOf(d.tagname)&&(i=this.tagsNodeStack.pop(),s=s.substring(0,s.lastIndexOf("."))),a!==e.tagname&&(s+=s?"."+a:a);const p=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,s,a)){let e="";if(c.length>0&&c.lastIndexOf("/")===c.length-1)"/"===a[a.length-1]?(a=a.substr(0,a.length-1),s=s.substr(0,s.length-1),c=a):c=c.substr(0,c.length-1),o=r.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(a))o=r.closeIndex;else{const i=this.readStopNodeData(t,l,u+1);if(!i)throw new Error(`Unexpected end of ${l}`);o=i.i,e=i.tagContent}const n=new Z(a);a!==c&&h&&(n[":@"]=this.buildAttributesMap(c,s,a)),e&&(e=this.parseTextData(e,a,s,!0,h,!0,!0)),s=s.substr(0,s.lastIndexOf(".")),n.add(this.options.textNodeName,e),this.addChild(i,n,s,p)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){if("/"===a[a.length-1]?(a=a.substr(0,a.length-1),s=s.substr(0,s.length-1),c=a):c=c.substr(0,c.length-1),this.options.transformTagName){const t=this.options.transformTagName(a);c===a&&(c=t),a=t}const t=new Z(a);a!==c&&h&&(t[":@"]=this.buildAttributesMap(c,s,a)),this.addChild(i,t,s,p),s=s.substr(0,s.lastIndexOf("."))}else{const t=new Z(a);this.tagsNodeStack.push(i),a!==c&&h&&(t[":@"]=this.buildAttributesMap(c,s,a)),this.addChild(i,t,s,p),i=t}n="",o=u}}else n+=t[o]}return e.child};function ct(t,e,i,n){this.options.captureMetaData||(n=void 0);const s=this.options.updateTag(e.tagname,i,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,n)):t.addChild(e,n))}const ht=function(t,e,i){if(-1===t.indexOf("&"))return t;const n=this.options.processEntities;if(!n.enabled)return t;if(n.allowedTags&&!n.allowedTags.includes(e))return t;if(n.tagFilter&&!n.tagFilter(e,i))return t;for(let e in this.docTypeEntities){const i=this.docTypeEntities[e],s=t.match(i.regx);if(s){if(this.entityExpansionCount+=s.length,n.maxTotalExpansions&&this.entityExpansionCount>n.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${n.maxTotalExpansions}`);const e=t.length;if(t=t.replace(i.regx,i.val),n.maxExpandedLength&&(this.currentExpandedLength+=t.length-e,this.currentExpandedLength>n.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${n.maxExpandedLength}`)}}if(-1===t.indexOf("&"))return t;for(let e in this.lastEntities){const i=this.lastEntities[e];t=t.replace(i.regex,i.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(let e in this.htmlEntities){const i=this.htmlEntities[e];t=t.replace(i.regex,i.val)}return t=t.replace(this.ampEntity.regex,this.ampEntity.val)};function ut(t,e,i,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function dt(t,e,i,n){return!(!e||!e.has(n))||!(!t||!t.has(i))}function pt(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s+e.length-1}function ft(t,e,i,n=">"){const s=function(t,e,i=">"){let n,s="";for(let r=e;r<t.length;r++){let e=t[r];if(n)e===n&&(n="");else if('"'===e||"'"===e)n=e;else if(e===i[0]){if(!i[1])return{data:s,index:r};if(t[r+1]===i[1])return{data:s,index:r}}else"\t"===e&&(e=" ");s+=e}}(t,e+1,n);if(!s)return;let r=s.data;const o=s.index,a=r.search(/\s/);let l=r,c=!0;-1!==a&&(l=r.substring(0,a),r=r.substring(a+1).trimStart());const h=l;if(i){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),c=l!==s.data.substr(t+1))}return{tagName:l,tagExp:r,closeIndex:o,attrExpPresent:c,rawTagName:h}}function mt(t,e,i){const n=i;let s=1;for(;i<t.length;i++)if("<"===t[i])if("/"===t[i+1]){const r=pt(t,">",i,`${e} is not closed`);if(t.substring(i+2,r).trim()===e&&(s--,0===s))return{tagContent:t.substring(n,i),i:r};i=r}else if("?"===t[i+1]){i=pt(t,"?>",i+1,"StopNode is not closed.")}else if("!--"===t.substr(i+1,3)){i=pt(t,"--\x3e",i+3,"StopNode is not closed.")}else if("!["===t.substr(i+1,2)){i=pt(t,"]]>",i,"StopNode is not closed.")-2}else{const n=ft(t,i,">");if(n){(n&&n.tagName)===e&&"/"!==n.tagExp[n.tagExp.length-1]&&s++,i=n.closeIndex}}}function gt(t,e,i){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&J(t,i)}return void 0!==t?t:""}function yt(t,e,i){const n=Number.parseInt(t,e);return n>=0&&n<=1114111?String.fromCodePoint(n):i+t+";"}const wt=Z.getMetaDataSymbol();function vt(t,e){return bt(t,e)}function bt(t,e,i){let n;const s={};for(let r=0;r<t.length;r++){const o=t[r],a=_t(o);let l="";if(l=void 0===i?a:i+"."+a,a===e.textNodeName)void 0===n?n=o[a]:n+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=bt(o[a],e,l);const i=St(t,e);void 0!==o[wt]&&(t[wt]=o[wt]),o[":@"]?xt(t,o[":@"],l,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==s[a]&&s.hasOwnProperty(a)?(Array.isArray(s[a])||(s[a]=[s[a]]),s[a].push(t)):e.isArray(a,l,i)?s[a]=[t]:s[a]=t}}}return"string"==typeof n?n.length>0&&(s[e.textNodeName]=n):void 0!==n&&(s[e.textNodeName]=n),s}function _t(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const i=e[t];if(":@"!==i)return i}}function xt(t,e,i,n){if(e){const s=Object.keys(e),r=s.length;for(let o=0;o<r;o++){const r=s[o];n.isArray(r,i+"."+r,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function St(t,e){const{textNodeName:i}=e,n=Object.keys(t).length;return 0===n||!(1!==n||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}class Ct{constructor(t){this.externalEntities={},this.options=j(t)}parse(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");if(e){!0===e&&(e={});const i=function(t,e){e=Object.assign({},E,e);const i=[];let n=!1,s=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=I(t,r),r.err)return r}else{if("<"!==t[r]){if(T(t[r]))continue;return N("InvalidChar","char '"+t[r]+"' is not expected.",R(t,r))}{let o=r;if(r++,"!"===t[r]){r=P(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let l="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)l+=t[r];if(l=l.trim(),"/"===l[l.length-1]&&(l=l.substring(0,l.length-1),r--),!F(l)){let e;return e=0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",N("InvalidTag",e,R(t,r))}const c=D(t,r);if(!1===c)return N("InvalidAttr","Attributes for '"+l+"' have open quote.",R(t,r));let h=c.value;if(r=c.index,"/"===h[h.length-1]){const i=r-h.length;h=h.substring(0,h.length-1);const s=B(h,e);if(!0!==s)return N(s.err.code,s.err.msg,R(t,i+s.err.line));n=!0}else if(a){if(!c.tagClosed)return N("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",R(t,r));if(h.trim().length>0)return N("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",R(t,o));if(0===i.length)return N("InvalidTag","Closing tag '"+l+"' has not been opened.",R(t,o));{const e=i.pop();if(l!==e.tagName){let i=R(t,e.tagStartPos);return N("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+i.line+", col "+i.col+") instead of closing tag '"+l+"'.",R(t,o))}0==i.length&&(s=!0)}}else{const a=B(h,e);if(!0!==a)return N(a.err.code,a.err.msg,R(t,r-h.length+a.err.line));if(!0===s)return N("InvalidXml","Multiple possible root nodes found.",R(t,r));-1!==e.unpairedTags.indexOf(l)||i.push({tagName:l,tagStartPos:o}),n=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=P(t,r);continue}if("?"!==t[r+1])break;if(r=I(t,++r),r.err)return r}else if("&"===t[r]){const e=O(t,r);if(-1==e)return N("InvalidChar","char '&' is not expected.",R(t,r));r=e}else if(!0===s&&!T(t[r]))return N("InvalidXml","Extra text at the end",R(t,r));"<"===t[r]&&r--}}}return n?1==i.length?N("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",R(t,i[0].tagStartPos)):!(i.length>0)||N("InvalidXml","Invalid '"+JSON.stringify(i.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):N("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==i)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const i=new it(this.options);i.addExternalEntities(this.externalEntities);const n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:vt(n,this.options)}addEntity(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return Z.getMetaDataSymbol()}}function At(t,e){let i="";return e.format&&e.indentBy.length>0&&(i="\n"),Et(t,e,"",i)}function Et(t,e,i,n){let s="",r=!1;for(let o=0;o<t.length;o++){const a=t[o],l=Tt(a);if(void 0===l)continue;let c="";if(c=0===i.length?l:`${i}.${l}`,l===e.textNodeName){let t=a[l];Pt(c,e)||(t=e.tagValueProcessor(l,t),t=Mt(t,e)),r&&(s+=n),s+=t,r=!1;continue}if(l===e.cdataPropName){r&&(s+=n),s+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,r=!1;continue}if(l===e.commentPropName){s+=n+`\x3c!--${a[l][0][e.textNodeName]}--\x3e`,r=!0;continue}if("?"===l[0]){const t=It(a[":@"],e),i="?xml"===l?"":n;let o=a[l][0][e.textNodeName];o=0!==o.length?" "+o:"",s+=i+`<${l}${o}${t}?>`,r=!0;continue}let h=n;""!==h&&(h+=e.indentBy);const u=n+`<${l}${It(a[":@"],e)}`,d=Et(a[l],e,c,h);-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?s+=u+">":s+=u+"/>":d&&0!==d.length||!e.suppressEmptyNode?d&&d.endsWith(">")?s+=u+`>${d}${n}</${l}>`:(s+=u+">",d&&""!==n&&(d.includes("/>")||d.includes("</"))?s+=n+e.indentBy+d+n:s+=d,s+=`</${l}>`):s+=u+"/>",r=!0}return s}function Tt(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i];if(t.hasOwnProperty(n)&&":@"!==n)return n}}function It(t,e){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!t.hasOwnProperty(n))continue;let s=e.attributeValueProcessor(n,t[n]);s=Mt(s,e),!0===s&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return i}function Pt(t,e){let i=(t=t.substr(0,t.length-e.textNodeName.length-1)).substr(t.lastIndexOf(".")+1);for(let n in e.stopNodes)if(e.stopNodes[n]===t||e.stopNodes[n]==="*."+i)return!0;return!1}function Mt(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const n=e.entities[i];t=t.replace(n.regex,n.val)}return t}const kt={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function Dt(t){this.options=Object.assign({},kt,t),!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=et(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Ot),this.processTextOrObjNode=zt,this.options.format?(this.indentate=Bt,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function zt(t,e,i,n){const s=this.j2x(t,i+1,n.concat(e));return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,s.attrStr,i):this.buildObjectNode(s.val,e,s.attrStr,i)}function Bt(t){return this.options.indentBy.repeat(t)}function Ot(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}Dt.prototype.build=function(t){return this.options.preserveOrder?At(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)},Dt.prototype.j2x=function(t,e,i){let n="",s="";const r=i.join(".");for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o))if(void 0===t[o])this.isAttribute(o)&&(s+="");else if(null===t[o])this.isAttribute(o)||o===this.options.cdataPropName?s+="":"?"===o[0]?s+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if(t[o]instanceof Date)s+=this.buildTextValNode(t[o],o,"",e);else if("object"!=typeof t[o]){const i=this.isAttribute(o);if(i&&!this.ignoreAttributesFn(i,r))n+=this.buildAttrPairStr(i,""+t[o]);else if(!i)if(o===this.options.textNodeName){let e=this.options.tagValueProcessor(o,""+t[o]);s+=this.replaceEntitiesValue(e)}else s+=this.buildTextValNode(t[o],o,"",e)}else if(Array.isArray(t[o])){const n=t[o].length;let r="",a="";for(let l=0;l<n;l++){const n=t[o][l];if(void 0===n);else if(null===n)"?"===o[0]?s+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){const t=this.j2x(n,e+1,i.concat(o));r+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else r+=this.processTextOrObjNode(n,o,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(o,n);t=this.replaceEntitiesValue(t),r+=t}else r+=this.buildTextValNode(n,o,"",e)}this.options.oneListGroup&&(r=this.buildObjectNode(r,o,a,e)),s+=r}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){const e=Object.keys(t[o]),i=e.length;for(let s=0;s<i;s++)n+=this.buildAttrPairStr(e[s],""+t[o][e[s]])}else s+=this.processTextOrObjNode(t[o],o,e,i);return{attrStr:n,val:s}},Dt.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},Dt.prototype.buildObjectNode=function(t,e,i,n){if(""===t)return"?"===e[0]?this.indentate(n)+"<"+e+i+"?"+this.tagEndChar:this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let s="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",s=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(n)+"<"+e+i+r+this.tagEndChar+t+this.indentate(n)+s:this.indentate(n)+"<"+e+i+r+">"+t+s}},Dt.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},Dt.prototype.buildTextValNode=function(t,e,i,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(n)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(n)+"<"+e+i+"?"+this.tagEndChar;{let s=this.options.tagValueProcessor(e,t);return s=this.replaceEntitiesValue(s),""===s?this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(n)+"<"+e+i+">"+s+"</"+e+this.tagEndChar}},Dt.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};class Nt{}e(Nt,"parser",new Ct({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0})),e(Nt,"builder",new Dt({attributeNamePrefix:"$",ignoreAttributes:!1,suppressBooleanAttributes:!1}));class Vt{static join(t){const e={};for(const i of t)for(const t in i)if(e[t])for(const n of i[t])e[t].add(n);else e[t]=new Set(i[t]);return e}static intersect(t){if(0===t.length)return{};let e=Vt.clone(t[0]);for(let i=1;i<t.length;i++){const n=t[i],s={};for(const t in e)if(n[t]){const i=new Set;for(const s of e[t])n[t].has(s)&&i.add(s);i.size>0&&(s[t]=i)}e=s}return e}static clone(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}static remove(t,e,i=!1){i&&(t=Vt.clone(t));for(const i in e)if(t[i]){for(const n of e[i])t[i].delete(n);0===t[i].size&&delete t[i]}}static add(t,e,i=!1){i&&(t=Vt.clone(t));for(const i in e)if(t[i])for(const n of e[i])t[i].add(n);else t[i]=new Set(e[i])}static append(t,e,...i){let n=t[e];n||(n=new Set,t[e]=n);for(const t of i)n.add(t)}static isEqual(t,e){const i=Object.keys(t),n=Object.keys(e);if(i.length!==n.length)return!1;for(const n of i){if(!e[n])return!1;if(t[n].size!==e[n].size)return!1;for(const i of t[n])if(!e[n].has(i))return!1}return!0}static isEmpty(t){return 0===Object.values(t).reduce((t,e)=>t+e.size,0)}static toRaw(t){const e={};for(const i in t)e[i]=Array.from(t[i]);return e}static fromRaw(t){const e={};for(const i in t)e[i]=new Set(t[i]);return e}}class Ft extends Map{constructor(t){super(t),e(this,"onItemSet",new h),e(this,"onItemUpdated",new h),e(this,"onItemDeleted",new h),e(this,"onCleared",new h),e(this,"guard",()=>!0)}clear(){super.clear(),this.onCleared.trigger()}set(t,e){const i=this.has(t);if(!(this.guard??(()=>!0))(t,e))return this;const n=super.set(t,e);return i?(this.onItemUpdated||(this.onItemUpdated=new h),this.onItemUpdated.trigger({key:t,value:e})):(this.onItemSet||(this.onItemSet=new h),this.onItemSet.trigger({key:t,value:e})),n}add(t){const e=_.create();return this.set(e,t),e}delete(t){const e=super.delete(t);return e&&this.onItemDeleted.trigger(t),e}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Rt{static isEntry(t){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(t.type)}static copySchema(t,e={}){for(const i in t){const n=t[i];this.isEntry(n)?e[i]=this.copyEntry(n):(e[i]={},this.copySchema(n,e[i]))}return e}static copyEntry(t){if("Boolean"===t.type){const e=t;return{type:e.type,value:e.value}}if("Color"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("Text"===t.type){const e=t;return{type:e.type,value:e.value}}if("Number"===t.type){const e=t;return{type:e.type,value:e.value,min:e.min,max:e.max,interpolable:e.interpolable}}if("Select"===t.type){const e=t;return{type:e.type,value:e.value,multiple:e.multiple,options:new Set(e.options)}}if("Vector3"===t.type){const e=t;return{type:e.type,value:e.value.clone()}}if("TextSet"===t.type){const e=t;return{type:e.type,value:new Set(e.value)}}if("None"===t.type){const e=t;return{type:e.type,value:e.value}}throw new Error("Invalid entry!")}}class Lt{constructor(t,i,n,s){e(this,"_component"),e(this,"name"),e(this,"uuid"),this._component=t,this.name=n,this.uuid=s??_.create();i.get($t).list.set(this.uuid,this)}get controls(){return Rt.copySchema(this._config)}set(t){for(const e in t)if(e in this){this[e]=t[e].value}}export(t=this._config,e={}){for(const i in t){const n=t[i];if(Rt.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:{r:t,g:s,b:r}}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:{x:t,y:s,z:r}}}else if("TextSet"===n.type){const t=Array.from(n.value);e[i]={...n,value:t}}else if("Select"===n.type){const t=Array.from(n.options);e[i]={...n,options:t}}else e[i]={...n};else e[i]={},this.export(n,e[i])}return e}import(t,e={},i=!0){for(const i in t){const n=t[i];if(Rt.isEntry(n))if("Color"===n.type){const{r:t,g:s,b:r}=n.value;e[i]={...n,value:new l.Color(t,s,r)}}else if("Vector3"===n.type){const{x:t,y:s,z:r}=n.value;e[i]={...n,value:new l.Vector3(t,s,r)}}else"TextSet"===n.type?e[i]={...n,value:new Set(n.value)}:"Select"===n.type?e[i]={...n,options:new Set(n.options)}:e[i]={...n};else e[i]={},this.import(n,e[i],!1)}i&&this.set(e)}}const Ut=class t extends d{constructor(n){super(n),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}};e(Ut,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let $t=Ut;class jt{constructor(t){e(this,"_event"),e(this,"_position",new l.Vector2),e(this,"onDisposed",new h),e(this,"updateMouseInfo",t=>{this._event=t}),this.dom=t,this.setupEvents(!0)}get position(){return this.updatePosition(!1),this._position.clone()}get rawPosition(){return this.updatePosition(!0),this._position.clone()}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}updatePosition(t){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event,t),this._position.y=this.getPositionY(e,this._event,t)}}getPositionY(t,e,i){const n=this.getDataObject(e);return i?n.clientY:-(n.clientY-t.top)/(t.bottom-t.top)*2+1}getPositionX(t,e,i){const n=this.getDataObject(e);return i?n.clientX:(n.clientX-t.left)/(t.right-t.left)*2-1}getDataObject(t){return t instanceof MouseEvent?t:t.touches[0]}setupEvents(t){t?(this.dom.addEventListener("pointermove",this.updateMouseInfo),this.dom.addEventListener("touchstart",this.updateMouseInfo)):(this.dom.removeEventListener("pointermove",this.updateMouseInfo),this.dom.removeEventListener("touchstart",this.updateMouseInfo))}}const Wt=class t extends d{constructor(i){super(i),e(this,"onDisposed",new h),e(this,"onBeforeDispose",new h),e(this,"onFragmentsLoaded",new h),e(this,"baseCoordinationModel",""),e(this,"baseCoordinationMatrix",new l.Matrix4),e(this,"enabled",!0),e(this,"_core"),this.components.add(t.uuid,this)}get initialized(){return!!this._core}get list(){return this.core.models.list}get core(){if(!this._core)throw new Error("FragmentsManager not initialized. Call init() first.");return this._core}get _hasCoordinationModel(){return""!==this.baseCoordinationModel}dispose(){this.onBeforeDispose.trigger(),this._core&&(this.core.dispose(),this._core=void 0),this.baseCoordinationModel="",this.onFragmentsLoaded.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}init(t,e){this._core=new i.FragmentsModels(t,e),this.core.onModelLoaded.add(async()=>{if(this._hasCoordinationModel)return;const t=[...this.list.values()][0];t&&(this.baseCoordinationModel=t.modelId,this.baseCoordinationMatrix=await t.getCoordinationMatrix())}),this.list.onItemDeleted.add(()=>{this.list.size>0||(this.baseCoordinationModel="",this.baseCoordinationMatrix=new l.Matrix4)})}async raycast(t){const e=[];for(const i of this.core.models.list.values())if(t.snappingClasses&&t.snappingClasses.length>0){const n=await i.raycastWithSnapping(t);if(n&&n.length>0)e.push(n[0]);else{const n=await i.raycast(t);n&&e.push(n)}}else{const n=await i.raycast(t);n&&e.push(n)}if(await Promise.all(e),0===e.length)return;let i=e[0],n=i.distance;for(let t=1;t<e.length;t++)e[t].distance<n&&(n=e[t].distance,i=e[t]);return i}async getPositions(t){const e=[],i=async(t,i)=>{const n=await t.getPositions(i);for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async getBBoxes(t){const e=[],i=async(t,i)=>{const n=await t.getBoxes(i);if(n)for(const t of n)e.push(t)},n=[];for(const e in t){const s=this.core.models.list.get(e);s&&n.push(i(s,Array.from(t[e])))}return await Promise.all(n),e}async highlight(t,e){await this.forEachModel(e,"highlight",t)}async getData(t,e){const i={};for(const[n,s]of Object.entries(t)){const t=this.list.get(n);if(!t)continue;if(0===s.size){i[n]=[];continue}const r=await t.getItemsData([...s],e);i[n]=r}return i}async resetHighlight(t){await this.forEachModel(t,"resetHighlight")}async forEachModel(t,e,...i){const n={};if(t)for(const e in t){const i=t[e];n[e]=Array.from(i)}else for(const t of this.core.models.list.keys())n[t]=void 0;const s=[];for(const t in n){const r=this.core.models.list.get(t);if(r){const o=n[t],a=r[e](o,...i);s.push(a)}}await Promise.all(s)}async guidsToModelIdMap(t){const e={};for(const[i,n]of this.list){const s=(await n.getLocalIdsByGuids([...t])).filter(t=>null!==t);e[i]=new Set(s)}return e}async modelIdMapToGuids(t){const e=[];for(const[i,n]of Object.entries(t)){const t=this.list.get(i);if(!t)continue;const s=(await t.getGuidsByLocalIds([...n])).filter(t=>null!==t);e.push(...s)}return e}applyBaseCoordinateSystem(t,e){const i=new l.Matrix4;return e&&i.copy(e.clone()).invert(),i.multiply(this.baseCoordinationMatrix),t.applyMatrix4(i),i}};e(Wt,"uuid","fef46874-46a3-461b-8c44-2922ab77c806");let Zt=Wt;class Gt{constructor(){e(this,"wasm",{path:"",absolute:!1,logLevel:c.LogLevel.LOG_LEVEL_OFF}),e(this,"webIfc",{COORDINATE_TO_ORIGIN:!0}),e(this,"autoSetWasm",!0),e(this,"customLocateFileHandler",null)}}const qt=class t extends d{constructor(i){super(i),e(this,"onDisposed",new h),e(this,"onIfcStartedLoading",new h),e(this,"onIfcImporterInitialized",new h),e(this,"onSetup",new h),e(this,"settings",new Gt),e(this,"webIfc",new c.IfcAPI),e(this,"enabled",!0),this.components.add(t.uuid,this)}dispose(){this.webIfc=null,this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async setup(t){this.settings={...this.settings,...t},this.settings.autoSetWasm&&await this.autoSetWasm(),this.onSetup.trigger()}async load(t,e,i,n){const s=this.components.get(Zt);if(!s.initialized)throw new Error("You need to initialize fragments first.");this.settings.autoSetWasm&&await this.autoSetWasm(),s.core.settings.autoCoordinate=e;const r=new a.IfcImporter;r.wasm.path=this.settings.wasm.path,r.wasm.absolute=this.settings.wasm.absolute,r.webIfcSettings=this.settings.webIfc,this.onIfcImporterInitialized.trigger(r),(null==n?void 0:n.instanceCallback)&&n.instanceCallback(r);const o=await r.process({...null==n?void 0:n.processData,bytes:t});return await s.core.load(o,{modelId:i,userData:null==n?void 0:n.userData})}async readIfcFile(t){const{path:e,absolute:i,logLevel:n}=this.settings.wasm;return this.webIfc.SetWasmPath(e,i),await this.webIfc.Init(this.settings.customLocateFileHandler||void 0),n&&this.webIfc.SetLogLevel(n),this.webIfc.OpenModel(t,this.settings.webIfc)}cleanUp(){try{this.webIfc.Dispose()}catch(t){console.log("Web-ifc wasn't disposed.")}this.webIfc=null,this.webIfc=new c.IfcAPI}async autoSetWasm(){const t=await fetch(`https://unpkg.com/@thatopen/components@${Qn.release}/package.json`);if(!t.ok)return void console.warn("Couldn't get openbim-components package.json. Set wasm settings manually.");const e=await t.json();if("web-ifc"in e.peerDependencies){const t=e.peerDependencies["web-ifc"];this.settings.wasm.path=`https://unpkg.com/web-ifc@${t}/`,this.settings.wasm.absolute=!0}else console.warn("Couldn't get web-ifc from peer dependencies in openbim-components. Set wasm settings manually.")}};e(qt,"uuid","a659add7-1418-4771-a0d6-7d4d438e4624");let Yt=qt;const Ht=class t extends d{constructor(i){super(i),e(this,"enabled",!0),this.components.add(t.uuid,this)}async set(t,e){const i=this.components.get(Zt),n=[];if(e)for(const[s,r]of Object.entries(e)){const e=i.list.get(s);e&&n.push(e.setVisible([...r],t))}else for(const e of i.list.values())n.push(e.setVisible(void 0,t));await Promise.all(n),await i.core.update(!0)}async isolate(t){await Promise.all([this.set(!1),this.set(!0,t)])}async toggle(t){const e=[],i=this.components.get(Zt);for(const[n,s]of Object.entries(t)){const t=i.list.get(n);t&&e.push(t.toggleVisible([...s]))}await Promise.all(e),await i.core.update(!0)}async getVisibilityMap(t,e){const i=[],n=[],s=this.components.get(Zt);if(e)for(const r of e){const e=s.list.get(r);e&&(i.push(e.modelId),n.push(e.getItemsByVisibility(t)))}else for(const e of s.list.values())i.push(e.modelId),n.push(e.getItemsByVisibility(t));const r=await Promise.all(n),o={};for(const[t,e]of i.entries())o[e]=r[t];return o}};e(Ht,"uuid","dd9ccf2d-8a21-4821-b7f6-2949add16a29");let Xt=Ht;const Qt=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new h),e(this,"list",new a.DataSet),this.components.add(t.uuid,this)}dispose(e=!0){this.list.clear(),this.onDisposed.trigger(t.uuid),e&&(this.onDisposed.reset(),this.list.eventsEnabled=!1,this.list.dispose())}get(){const t=new l.Box3;for(const e of this.list)t.union(e);return t}async addFromModelIdMap(t){const e=this.components.get(Zt),i=new l.Box3;for(const[n,s]of Object.entries(t)){const t=e.list.get(n);if(!t)continue;const r=await t.getMergedBox([...s]);i.union(r)}this.list.add(i)}addFromModels(t){const e=this.components.get(Zt);for(const[i,n]of e.list)t&&!t.some(t=>t.test(i))||this.list.add(n.box)}async getCenter(t){this.list.clear(),await this.addFromModelIdMap(t);const e=this.get();this.list.clear();const i=new l.Vector3;return e.getCenter(i),i}async getCameraOrientation(t,e=1){const i=this.components.get(Zt);this.list.clear();for(const[t,e]of i.list)this.list.add(e.box);const n=this.get();this.list.clear();const s=new l.Vector3;n.getCenter(s);const r=new l.Vector3;n.getSize(r);const o=Math.max(r.x,r.y,r.z)*e,a=new l.Vector3;switch(t){case"front":default:a.set(s.x,s.y,s.z+o);break;case"back":a.set(s.x,s.y,s.z-o);break;case"left":a.set(s.x-o,s.y,s.z);break;case"right":a.set(s.x+o,s.y,s.z);break;case"top":a.set(s.x,s.y+o,s.z);break;case"bottom":a.set(s.x,s.y-o,s.z)}return{position:a,target:s}}};e(Qt,"uuid","d1444724-dba6-4cdd-a0c7-68ee1450d166");let Kt=Qt;class Jt{constructor(t,i){e(this,"name","Query"),e(this,"customData",{}),e(this,"_components"),e(this,"_queries",[]),e(this,"_aggregation","exclusive"),e(this,"result",null),e(this,"cache",!0),e(this,"serializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>t.source),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.serializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.serializeQueryParameters(t.relation.query):void 0}:void 0}}),e(this,"deserializeQueryParameters",t=>{var e;return{categories:null==(e=t.categories)?void 0:e.map(t=>new RegExp(t)),attributes:t.attributes?{aggregation:t.attributes.aggregation,queries:t.attributes.queries.map(this.deserializeAttributeQuery)}:void 0,relation:t.relation?{name:t.relation.name,query:t.relation.query?this.deserializeQueryParameters(t.relation.query):void 0}:void 0}}),this._components=t,this.queries=i}set queries(t){this._queries=t,this.clearCache()}get queries(){return this._queries}set aggregation(t){t!==this._aggregation&&this.clearCache(),this._aggregation=t}get aggregation(){return this._aggregation}async test(t){const{modelIds:e,force:i}={force:!1,...t};if(this.result&&!i)return this.result;const n=this._components.get(ee),s=await n.getItems(this.queries,{modelIds:e,aggregation:this.aggregation});return this.cache&&(this.result=s),s}clearCache(){this.result=null}serializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>t.source):t.value instanceof RegExp?t.value.source:t.value;return{name:t.name.source,value:e,type:t.type instanceof RegExp?t.type.source:t.type,negate:t.negate,itemIds:t.itemIds}}toJSON(){return{guid:this._components.get(ee).list.getKey(this)??_.create(),name:this.name,customData:this.customData,queries:this.queries.map(this.serializeQueryParameters),aggregation:this.aggregation,cache:this.cache}}deserializeAttributeQuery(t){let e;e=Array.isArray(t.value)?t.value.map(t=>new RegExp(t)):"string"==typeof t.value?new RegExp(t.value):t.value;return{name:new RegExp(t.name),value:e,type:t.type?new RegExp(t.type):void 0,negate:t.negate,itemIds:t.itemIds}}fromJSON(t){return this.name=t.name,this.customData=t.customData,this.aggregation=t.aggregation,this.cache=t.cache,this.queries=t.queries.map(this.deserializeQueryParameters),this}}const te=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new a.DataMap),i.add(t.uuid,this)}async getItems(t,e){let i;if(e){const{modelIds:t,items:n}=e;if(n){const t=Object.keys(n);t.length>0&&(i=t.map(t=>new RegExp(`^${t}$`)))}else t&&(i=t)}const n=(null==e?void 0:e.aggregation)??"exclusive",s=this.components.get(Zt),r=await Promise.all(t.map(async t=>{const n={};return await Promise.all(Array.from(s.list).map(async([s,r])=>{var o;if(i&&!i.some(t=>t.test(s)))return;const a=null==(o=null==e?void 0:e.items)?void 0:o[s],l=await r.getItemsByQuery(t,{localIds:a?[...a]:void 0});n[s]=new Set(l)})),n}));return"inclusive"===n?Vt.join(r):Vt.intersect(r)}create(t,e){const i=new Jt(this.components,e);return this.list.set(t,i),i}async addFromCategories(t){const e=new Set,i=this.components.get(Zt);for(const[n,s]of i.list){if(t&&!t.some(t=>t.test(n)))continue;const i=(await s.getItemsWithGeometryCategories()).filter(t=>null!==t),r=new Set(i);for(const t of r)this.list.has(t)||(this.create(t,[{categories:[new RegExp(`^${t}$`)]}]),e.add(t))}return[...e]}import(t){const{data:e}=t,i=[];if(!e)return i;for(const t of e){const e=this.create(t.guid,[]);e.fromJSON(t),i.push(e)}return i}export(){const t=[];for(const[e,i]of this.list.entries()){const n={...i.toJSON(),name:e};t.push(n)}return{data:t}}};e(te,"uuid","0da7ad77-f734-42ca-942f-a074adfd1e3a");let ee=te;const ie=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"onDisposed",new h),e(this,"list",new a.DataMap),e(this,"defaultSaveFunction",t=>"value"in t.Name?t.Name.value:null),e(this,"onBeforeFragmentsDispose",async t=>{const{key:e,value:i}=t,n=await i.getLocalIds(),s={[e]:new Set(n)};this.removeItems(s)}),i.add(t.uuid,this),this.setupEvents();i.get(Zt).list.onBeforeDelete.add(this.onBeforeFragmentsDispose)}setupEvents(){this.list.onBeforeDelete.add(({value:t})=>t.dispose())}getClassificationGroups(t){let e=this.list.get(t);return e||(e=new a.DataMap,this.list.set(t,e)),e}getModelItems(t,e,i){const{map:n}=this.getGroupData(t,e);let s=n[i];return s||(s=new Set,n[i]=s),s}getGroupData(t,e){const i=this.components.get(ee),n=this.getClassificationGroups(t);let s=n.get(e);return s||(s={map:{},get:()=>new Promise(t=>{if(s)if(s.query){const{name:e,config:n}=s.query,r=i.list.get(e);if(!r)throw new Error("Classifier: the query name associated with the group doesn't exist in the ItemsFinder component");r.test(n).then(e=>{if(!s)return void t({});const i=Vt.join([e,s.map]);t(i)})}else t(s.map);else t({})})},n.set(e,s)),s}async aggregateItems(t,e,i){const n=(null==i?void 0:i.data)??void 0,s=(null==i?void 0:i.aggregationCallback)??this.defaultSaveFunction,r=this.components.get(Zt),o=this.components.get(ee),a=await o.getItems([e],{modelIds:null==i?void 0:i.modelIds});for(const[e,i]of Object.entries(a)){const o=r.list.get(e);if(!o)continue;const a=(i,...n)=>{const s=this.getModelItems(t,i,e);for(const t of n)s.add(t)},l=await o.getItemsData([...i],n);for(const t of l)s(t,a)}}addGroupItems(t,e,i){const{map:n}=this.getGroupData(t,e);Vt.add(n,i)}setGroupQuery(t,e,i){this.getGroupData(t,e).query=i}async find(t){const e=[];for(const[i,n]of Object.entries(t)){const t=[],s=this.list.get(i);if(!s)continue;for(const e of n){const i=s.get(e);if(!i)continue;const n=await i.get();t.push(n)}const r=Vt.join(t);e.push(r)}return Vt.intersect(e)}async aggregateItemRelations(t,e,i,n){const s=(null==n?void 0:n.attribute)??"Name",r={relations:{[i]:{attributes:!0,relations:!1}}};await this.aggregateItems(t,e,{modelIds:null==n?void 0:n.modelIds,data:r,aggregationCallback:(t,e)=>{if(!(null==t?void 0:t[s]))return;const n=t[s];if(!("value"in n))return;const r=t[i];if(Array.isArray(r))for(const t of r)"value"in t._localId&&e(n.value,t._localId.value)}})}async byIfcBuildingStorey(t){await this.aggregateItemRelations((null==t?void 0:t.classificationName)??"Storeys",{categories:[/BUILDINGSTOREY/]},"ContainsElements",{modelIds:null==t?void 0:t.modelIds})}async byCategory(t){const e=this.components.get(ee),i=await e.addFromCategories(null==t?void 0:t.modelIds);for(const e of i)this.setGroupQuery((null==t?void 0:t.classificationName)??"Categories",e,{name:e})}dispose(){this.list.clear();this.components.get(Zt).list.onBeforeDelete.remove(this.onBeforeFragmentsDispose),this.onDisposed.trigger()}removeItems(t,e){if(e&&e.classificationName){const i=this.list.get(e.classificationName);if(!i)return;if(e.groupName){if(!i.get(e.groupName))return}for(const[,e]of i)Vt.remove(e.map,t);return}for(const[,e]of this.list.entries())for(const[,i]of e)Vt.remove(i.map,t)}async byModel(t){const e=this.components.get(Zt),i=(null==t?void 0:t.classificationName)??"Models";for(const[n,s]of e.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(n)))continue;const e=await s.getItemsIdsWithGeometry(),r={[n]:new Set(e)};this.getGroupData(i,n),this.addGroupItems(i,n,r)}}};e(ie,"uuid","e25a7f3c-46c4-4a14-9d3d-5115f24ebeb7");let ne=ie;class se{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new h),e(this,"mouse"),e(this,"world"),e(this,"debugMode",!1),e(this,"colorToModelId",new Map),e(this,"modelIdToColor",new Map),e(this,"renderTarget"),e(this,"renderTargetSize",new l.Vector2),e(this,"debugCanvas"),e(this,"debugContainer"),e(this,"colorMaterials",new Map),e(this,"originalMaterials",new Map),e(this,"originalLodColors",new Map),e(this,"colorsNeedUpdate",!0);const n=i.renderer;if(!n)throw new Error("A renderer is needed for the FastModelPicker to work!");this.world=i,this.mouse=new jt(n.three.domElement),this.components=t,this.setupRenderTarget(),this.setupFragmentListeners()}setupFragmentListeners(){const t=this.components.get(Zt);t.list.onItemSet.add(()=>{this.colorsNeedUpdate=!0}),t.list.onItemDeleted.add(()=>{this.colorsNeedUpdate=!0})}setupRenderTarget(){const t=this.world.renderer.three.getSize(new l.Vector2);this.renderTargetSize.copy(t),this.renderTarget=new l.WebGLRenderTarget(t.x,t.y),this.renderTarget.texture.format=l.RGBAFormat,this.renderTarget.texture.type=l.UnsignedByteType,this.debugMode&&this.setupDebugCanvas(),this.world.renderer.onResize.add(t=>{this.renderTargetSize.copy(t),this.renderTarget.setSize(t.x,t.y),this.debugCanvas&&(this.debugCanvas.width=t.x,this.debugCanvas.height=t.y)})}setupDebugCanvas(){if(this.debugCanvas)return;const t=this.world.renderer.three.getSize(new l.Vector2);this.debugContainer=document.createElement("div"),this.debugContainer.style.position="fixed",this.debugContainer.style.top="10px",this.debugContainer.style.right="10px",this.debugContainer.style.width="300px",this.debugContainer.style.height="300px",this.debugContainer.style.border="2px solid #fff",this.debugContainer.style.backgroundColor="#000",this.debugContainer.style.zIndex="10000",this.debugContainer.style.pointerEvents="none",this.debugCanvas=document.createElement("canvas"),this.debugCanvas.width=t.x,this.debugCanvas.height=t.y,this.debugCanvas.style.width="100%",this.debugCanvas.style.height="100%",this.debugCanvas.style.imageRendering="pixelated",this.debugContainer.appendChild(this.debugCanvas),document.body.appendChild(this.debugContainer)}generateColorForModel(t){let e=0;for(let i=0;i<t.length;i++)e=(e<<5)-e+t.charCodeAt(i),e&=e;let i=Math.abs(e)%16777215;0===i&&(i=1);const n=i>>16&255||1,s=i>>8&255||1,r=255&i||1;return new l.Color(n/255,s/255,r/255)}colorToId(t){return Math.round(255*t.r)<<16|Math.round(255*t.g)<<8|Math.round(255*t.b)}assignColors(){const t=this.components.get(Zt);if(t.initialized){if(!this.colorsNeedUpdate){const e=new Set(t.list.keys()),i=new Set(this.modelIdToColor.keys());(e.size!==i.size||[...e].some(t=>!i.has(t)))&&(this.colorsNeedUpdate=!0)}if(this.colorsNeedUpdate){this.colorToModelId.clear(),this.modelIdToColor.clear();for(const t of this.colorMaterials.values())t.dispose();this.colorMaterials.clear();for(const[e]of t.list){const t=this.generateColorForModel(e),i=this.colorToId(t);this.colorToModelId.set(i,e),this.modelIdToColor.set(e,t);const n=new l.MeshBasicMaterial({color:t,depthTest:!0,depthWrite:!0});this.colorMaterials.set(e,n)}this.colorsNeedUpdate=!1}}}applyColorMaterials(){const t=this.components.get(Zt);if(t.initialized)for(const[e,i]of t.list){const t=this.colorMaterials.get(e);t&&i.object.traverse(e=>{if(e instanceof l.Mesh){if("isLODGeometry"in e.geometry){const i=e.material[0].uniforms.lodColor;return this.originalLodColors.has(i)||this.originalLodColors.set(i,i.value),void(i.value=t.color)}this.originalMaterials.has(e)||this.originalMaterials.set(e,e.material),e.material=t}})}}restoreOriginalMaterials(){for(const[t,e]of this.originalMaterials)t.material=e;for(const[t,e]of this.originalLodColors)t.value=e;this.originalMaterials.clear()}renderColorCoded(){if(!this.renderTarget||!this.world.renderer)throw new Error("Render target not initialized!");const t=this.world.renderer.three,e=this.world.scene.three,i=this.world.camera.three,n=t.getRenderTarget(),s=t.autoClear,r=new l.Color,o=t.getClearAlpha();t.getClearColor(r),this.applyColorMaterials(),t.setRenderTarget(this.renderTarget),t.autoClear=!0,t.setClearColor(0,1),t.clear(!0,!0,!1),t.render(e,i),t.setRenderTarget(n),t.autoClear=s,t.setClearColor(r,o),this.restoreOriginalMaterials(),this.debugMode&&this.debugCanvas&&this.updateDebugCanvas()}updateDebugCanvas(){if(!this.debugCanvas||!this.renderTarget||!this.world.renderer)return;const t=this.world.renderer.three,e=this.renderTargetSize,i=new Uint8Array(e.x*e.y*4);t.readRenderTargetPixels(this.renderTarget,0,0,e.x,e.y,i);const n=this.debugCanvas.getContext("2d");if(!n)return;const s=n.createImageData(e.x,e.y),r=4*e.x;for(let t=0;t<e.y;t++){const n=t*r,o=(e.y-1-t)*r;s.data.set(i.subarray(n,n+r),o)}n.putImageData(s,0,0)}async getModelAt(t){if(!this.renderTarget||!this.world.renderer)throw new Error("Render target not initialized!");const e=this.components.get(Zt);if(!e.initialized||0===e.list.size)return null;this.assignColors(),this.renderColorCoded();const i=t||this.mouse.position,n=this.renderTargetSize,s=Math.floor(.5*(i.x+1)*n.x),r=Math.floor(.5*(i.y+1)*(n.y-1)),o=Math.max(0,Math.min(n.x-1,s)),a=Math.max(0,Math.min(n.y-1,r)),l=this.world.renderer.three,c=new Uint8Array(4);l.readRenderTargetPixels(this.renderTarget,o,a,1,1,c);const h=c[0]<<16|c[1]<<8|c[2];return this.colorToModelId.get(h)||null}setDebugMode(t){this.debugMode=t,t?this.setupDebugCanvas():this.removeDebugCanvas()}removeDebugCanvas(){this.debugContainer&&(this.debugContainer.remove(),this.debugContainer=void 0,this.debugCanvas=void 0)}dispose(){this.mouse.dispose(),this.removeDebugCanvas();for(const t of this.colorMaterials.values())t.dispose();this.colorMaterials.clear(),this.renderTarget&&this.renderTarget.dispose(),this.colorToModelId.clear(),this.modelIdToColor.clear(),this.originalMaterials.clear(),this.originalLodColors.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}}const re=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new h),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new se(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(re,"uuid","4a82430c-7ff2-49ea-9401-60807502dad6");let oe=re;class ae{constructor(t,i){e(this,"enabled",!0),e(this,"components"),e(this,"onDisposed",new h),e(this,"mouse"),e(this,"three",new l.Raycaster),e(this,"world"),e(this,"useFastModelPicking",!1);const n=i.renderer;if(!n)throw new Error("A renderer is needed for the raycaster to work!");this.world=i,this.mouse=new jt(n.three.domElement),this.components=t}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRayToObjects(t=Array.from(this.world.meshes),e=this.mouse.position){if(!this.world)throw new Error("A world is needed to cast rays!");const i=this.world.camera.three;return this.three.setFromCamera(e,i),this.intersect(t)}async castRay(t){const e=null==t?void 0:t.snappingClasses,i=(null==t?void 0:t.items)??Array.from(this.world.meshes),n=(null==t?void 0:t.position)??this.mouse.position;if(!this.world)throw new Error("A world is needed to cast rays!");const s=this.world.camera.three,r=this.components.get(Zt),o=this.world.renderer.three.domElement,a=this.mouse.rawPosition;let l=null;if(r.initialized){if(this.useFastModelPicking){const t=this.components.get(oe).get(this.world),i=await t.getModelAt(n);if(i){const t=r.list.get(i);if(t)if(e&&e.length>0){const i=await t.raycastWithSnapping({camera:s,dom:o,mouse:a,snappingClasses:e});l=i&&i.length>0?i[0]:await t.raycast({camera:s,dom:o,mouse:a})}else l=await t.raycast({camera:s,dom:o,mouse:a})}}else l=await r.raycast({camera:s,dom:o,mouse:a,snappingClasses:e});if(0===i.length)return l}this.three.setFromCamera(n,s);const c=this.intersect(i);return l?c&&c.distance<l.distance?c:l:c}castRayFromVector(t,e,i=Array.from(this.world.meshes)){return this.three.set(t,e),this.intersect(i)}intersect(t=Array.from(this.world.meshes)){const e=this.three.intersectObjects(t),i=this.filterClippingPlanes(e);return i.length>0?i[0]:null}filterClippingPlanes(t){if(!this.world.renderer)throw new Error("Renderer not found!");const e=this.world.renderer.three;if(!e.clippingPlanes)return t;const i=e.clippingPlanes;return t.length<=0||!i||(null==i?void 0:i.length)<=0?t:t.filter(t=>i.every(e=>e.distanceToPoint(t.point)>0))}}const le=class t extends d{constructor(i){super(i),e(this,"enabled",!0),e(this,"list",new Map),e(this,"onDisposed",new h),i.add(t.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new ae(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};e(le,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let ce=le;class he extends u{constructor(){super(...arguments),e(this,"onCameraChanged",new h),e(this,"meshes",new Set),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"isDisposing",!1),e(this,"enabled",!0),e(this,"_dynamicAnchor",!1),e(this,"uuid",_.create()),e(this,"name"),e(this,"_scene"),e(this,"_camera"),e(this,"_renderer",null),e(this,"onPointerDown",async t=>{if(!this.camera.hasCameraControls())throw new Error("World: can't set dynamic anchor if the camera doesn't have controls.");const e=this.components.get(ce).get(this),i=await e.castRay();i&&i.point&&0===t.button&&this.camera.controls.setOrbitPoint(i.point.x,i.point.y,i.point.z)}),e(this,"_defaultCamera")}set dynamicAnchor(t){var e;const i=null==(e=this.renderer)?void 0:e.three.domElement.parentElement;if(!i)throw new Error("World: the renderer must have a parentElement to set dynamic anchoring.");t?(this.camera.controls&&(this.camera.controls.minDistance=.01),i.addEventListener("pointerdown",this.onPointerDown)):i.removeEventListener("pointerdown",this.onPointerDown)}get dynamicAnchor(){return this._dynamicAnchor}get defaultCamera(){if(!this._defaultCamera)throw new Error("World: there is no default camera defined.");return this._defaultCamera}set defaultCamera(t){this._defaultCamera=t}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera||(this.defaultCamera=t),this._camera=t,t.currentWorld=this,this.onCameraChanged.trigger(t)}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}useDefaultCamera(){this.camera=this.defaultCamera}update(t){this.enabled&&this._scene&&this._camera&&(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger())}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const t=this.components.get(y);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const e of this.meshes)t.destroy(e);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(we).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class ue{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(t){this._list.directionalLight.color.value=t;for(const[,e]of this._scene.directionalLights)e.color.copy(t)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(t){this._list.directionalLight.intensity.value=t;for(const[,e]of this._scene.directionalLights)e.intensity=t}get position(){return this._list.directionalLight.position.value.clone()}set position(t){this._list.directionalLight.position.value=t;for(const[,e]of this._scene.directionalLights)e.position.copy(t)}}class de{constructor(t,i){e(this,"_list"),e(this,"_scene"),this._list=t,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(t){this._list.ambientLight.color.value=t;for(const[,e]of this._scene.ambientLights)e.color.copy(t)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(t){this._list.ambientLight.intensity.value=t;for(const[,e]of this._scene.ambientLights)e.intensity=t}}class pe extends Lt{constructor(){super(...arguments),e(this,"_config",{backgroundColor:{value:new l.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new l.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new l.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new l.Vector3}}}),e(this,"ambientLight",new de(this._config,this._component)),e(this,"directionalLight",new ue(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class fe extends w{constructor(t){super(t),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"three"),e(this,"config",new pe(this,this.components,"Scene")),e(this,"_defaultConfig",{backgroundColor:new l.Color(2107698),directionalLight:{color:new l.Color("white"),intensity:1.5,position:new l.Vector3(5,10,3)},ambientLight:{color:new l.Color("white"),intensity:1}}),this.three=new l.Scene,this.three.background=new l.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const i=e.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const n=e.directionalLight;this.config.directionalLight.color=n.color,this.config.directionalLight.intensity=n.intensity,this.config.directionalLight.position=n.position,this.deleteAllLights();const{color:s,intensity:r}=this.config.directionalLight,o=new l.DirectionalLight(s,r);o.position.copy(n.position);const{color:a,intensity:c}=this.config.directionalLight,h=new l.AmbientLight(a,c);this.three.add(o,h),this.directionalLights.set(o.uuid,o),this.ambientLights.set(h.uuid,h),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get($t).list.delete(this.config.uuid)}}var me=(t=>(t[t.MANUAL=0]="MANUAL",t[t.AUTO=1]="AUTO",t))(me||{});class ge extends f{constructor(t){super(t),e(this,"onBeforeUpdate",new h),e(this,"onAfterUpdate",new h),e(this,"onAspectUpdated",new h),e(this,"onDisposed",new h),e(this,"three"),e(this,"_resizeObserver",null),e(this,"_allControls",new Map),e(this,"updateAspect",()=>{var t;if(this.currentWorld&&this.currentWorld.renderer)if(this.three instanceof l.OrthographicCamera)this.onAspectUpdated.trigger();else if(null==(t=this.currentWorld.renderer)?void 0:t.isResizeable()){const t=this.currentWorld.renderer.getSize();this.three.aspect=t.width/t.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.worlds.onItemSet.add(({value:t})=>{const e=this.newCameraControls();this.setupEvents(!0),this._allControls.set(t.uuid,e)}),this.worlds.onBeforeDelete.add(({value:t})=>{var e;const i=this._allControls.get(t.uuid);i&&(i.dispose(),this._allControls.delete(t.uuid)),null==(e=this._resizeObserver)||e.disconnect()})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return null!==this.currentWorld&&this.controls.enabled}set enabled(t){null!==this.currentWorld&&(this.controls.enabled=t)}set currentWorld(t){if(super.currentWorld=t,!t)return;this.worlds.get(t.uuid)||this.worlds.set(t.uuid,t)}get currentWorld(){return this._currentWorld}dispose(){this.setupEvents(!1),this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose();this.worlds.clear()}async fitToItems(t){const e=await this.getItemsBounding(t);await this.controls.fitToSphere(e,!0)}async setOrbitToItems(t){const e=await this.getItemsBounding(t);this.controls.setOrbitPoint(e.center.x,e.center.y,e.center.z)}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}async getItemsBounding(t){const e=this.components.get(Zt),i=this.components.get(Kt);i.list.clear();const n=new l.Sphere;if(t)await i.addFromModelIdMap(t);else for(const[,t]of e.list)i.list.add(t.box);return i.get().getBoundingSphere(n),i.list.clear(),n}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new l.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new l.Vector3(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");r.install({THREE:ge.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new r(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){if(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),t){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");const{domElement:t}=this.currentWorld.renderer.three;this._resizeObserver=new ResizeObserver(this.updateAspect),this._resizeObserver.observe(t)}}static getSubsetOfThree(){return{MOUSE:l.MOUSE,Vector2:l.Vector2,Vector3:l.Vector3,Vector4:l.Vector4,Quaternion:l.Quaternion,Matrix4:l.Matrix4,Spherical:l.Spherical,Box3:l.Box3,Sphere:l.Sphere,Raycaster:l.Raycaster,MathUtils:l.MathUtils}}}const ye=class t extends d{constructor(n){super(n),e(this,"onAfterUpdate",new h),e(this,"onBeforeUpdate",new h),e(this,"onDisposed",new h),e(this,"list",new i.DataMap),e(this,"enabled",!0),n.add(t.uuid,this)}create(){const t=new he(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,i]of this.list)i.update(t)}};e(ye,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let we=ye;class ve extends Lt{constructor(){super(...arguments),e(this,"_config",{visible:{value:!0,type:"Boolean"},color:{value:new l.Color,type:"Color"},primarySize:{type:"Number",interpolable:!0,value:1,min:0,max:1e3},secondarySize:{type:"Number",interpolable:!0,value:10,min:0,max:1e3},distance:{type:"Number",interpolable:!0,value:500,min:0,max:500}})}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.uniforms.uColor.value=t,this._component.material.uniformsNeedUpdate=!0}get primarySize(){return this._config.primarySize.value}set primarySize(t){this._config.primarySize.value=t,this._component.material.uniforms.uSize1.value=t,this._component.material.uniformsNeedUpdate=!0}get secondarySize(){return this._config.secondarySize.value}set secondarySize(t){this._config.secondarySize.value=t,this._component.material.uniforms.uSize2.value=t,this._component.material.uniformsNeedUpdate=!0}get distance(){return this._config.distance.value}set distance(t){this._config.distance.value=t,this._component.material.uniforms.uDistance.value=t,this._component.material.uniformsNeedUpdate=!0}}class be{constructor(t,i){e(this,"onDisposed",new h),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"world"),e(this,"components"),e(this,"config"),e(this,"_defaultConfig",{visible:!0,color:new l.Color(12303291),primarySize:1,secondarySize:10,distance:500}),e(this,"three"),e(this,"_fade",3),e(this,"updateZoom",()=>{this.world.camera instanceof ge&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=i;const{color:n,primarySize:s,secondarySize:r,distance:o}=this._defaultConfig;this.components=t,this.config=new ve(this,this.components,"Grid");const a=new l.PlaneGeometry(2,2,1,1),c=new l.ShaderMaterial({side:l.DoubleSide,uniforms:{uSize1:{value:s},uSize2:{value:r},uColor:{value:n},uDistance:{value:o},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:"\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xzy * uDistance;\n pos.xz += cameraPosition.xz;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",fragmentShader:"\n \n varying vec3 worldPosition;\n \n uniform float uZoom;\n uniform float uFade;\n uniform float uSize1;\n uniform float uSize2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xz / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n \n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n // Ortho camera fades the grid away when zooming out\n float minZoom = step(0.2, uZoom);\n float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom;\n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade));\n gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor;\n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",extensions:{derivatives:!0}});this.three=new l.Mesh(a,c),this.three.frustumCulled=!1,i.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(t){if(this.three.visible=t,t){this.world.scene.three.add(this.three)}else this.three.removeFromParent()}get material(){return this.three.material}get fade(){return 3===this._fade}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}setup(t){const e={...this._defaultConfig,...t};this.config.visible=!0,this.config.color=e.color,this.config.primarySize=e.primarySize,this.config.secondarySize=e.secondarySize,this.config.distance=e.distance,this.isSetup=!0,this.onSetup.trigger()}dispose(){this.setupEvents(!1);this.components.get($t).list.delete(this.config.uuid);this.components.get(y).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(this.world.isDisposing)return;if(!(this.world.camera instanceof ge))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}const _e=class t extends d{constructor(i){super(i),e(this,"list",new Map),e(this,"onDisposed",new h),e(this,"enabled",!0),i.add(t.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new be(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(_e,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let xe=_e;const Se=1.25,Ce=65535,Ae=Math.pow(2,-24),Ee=Symbol("SKIP_GENERATION");function Te(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function Ie(t,e){if(!t.index){const i=t.attributes.position.count,s=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(i,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new n.BufferAttribute(s,1));for(let t=0;t<i;t++)s[t]=t}}function Pe(t){const e=Te(t),i=t.drawRange,n=i.start/3,s=(i.start+i.count)/3,r=Math.max(0,n),o=Math.min(e,s)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function Me(t){if(!t.groups||!t.groups.length)return Pe(t);const e=[],i=new Set,n=t.drawRange,s=n.start/3,r=(n.start+n.count)/3;for(const e of t.groups){const t=e.start/3,n=(e.start+e.count)/3;i.add(Math.max(s,t)),i.add(Math.min(r,n))}const o=Array.from(i.values()).sort((t,e)=>t-e);for(let t=0;t<o.length-1;t++){const i=o[t],n=o[t+1];e.push({offset:Math.floor(i),count:Math.floor(n-i)})}return e}function ke(t,e,i){return i.min.x=e[t],i.min.y=e[t+1],i.min.z=e[t+2],i.max.x=e[t+3],i.max.y=e[t+4],i.max.z=e[t+5],i}function De(t){let e=-1,i=-1/0;for(let n=0;n<3;n++){const s=t[n+3]-t[n];s>i&&(i=s,e=n)}return e}function ze(t,e){e.set(t)}function Be(t,e,i){let n,s;for(let r=0;r<3;r++){const o=r+3;n=t[r],s=e[r],i[r]=n<s?n:s,n=t[o],s=e[o],i[o]=n>s?n:s}}function Oe(t,e,i){for(let n=0;n<3;n++){const s=e[t+2*n],r=e[t+2*n+1],o=s-r,a=s+r;o<i[n]&&(i[n]=o),a>i[n+3]&&(i[n+3]=a)}}function Ne(t){const e=t[3]-t[0],i=t[4]-t[1],n=t[5]-t[2];return 2*(e*i+i*n+n*e)}function Ve(t,e,i,n,s=null){let r=1/0,o=1/0,a=1/0,l=-1/0,c=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,g=-1/0;const y=null!==s;for(let n=6*e,s=6*(e+i);n<s;n+=6){const e=t[n+0],i=t[n+1],s=e-i,w=e+i;s<r&&(r=s),w>l&&(l=w),y&&e<u&&(u=e),y&&e>f&&(f=e);const v=t[n+2],b=t[n+3],_=v-b,x=v+b;_<o&&(o=_),x>c&&(c=x),y&&v<d&&(d=v),y&&v>m&&(m=v);const S=t[n+4],C=t[n+5],A=S-C,E=S+C;A<a&&(a=A),E>h&&(h=E),y&&S<p&&(p=S),y&&S>g&&(g=S)}n[0]=r,n[1]=o,n[2]=a,n[3]=l,n[4]=c,n[5]=h,y&&(s[0]=u,s[1]=d,s[2]=p,s[3]=f,s[4]=m,s[5]=g)}const Fe=32,Re=(t,e)=>t.candidate-e.candidate,Le=new Array(Fe).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ue=new Float32Array(6);class $e{constructor(){}}function je(t,e,i,n,s,r){let o=n,a=n+s-1;const l=r.pos,c=2*r.axis;for(;;){for(;o<=a&&i[6*o+c]<l;)o++;for(;o<=a&&i[6*a+c]>=l;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let i=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=i}for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}function We(t,e,i,n,s,r){let o=n,a=n+s-1;const l=r.pos,c=2*r.axis;for(;;){for(;o<=a&&i[6*o+c]<l;)o++;for(;o<=a&&i[6*a+c]>=l;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){let e=i[6*o+t];i[6*o+t]=i[6*a+t],i[6*a+t]=e}o++,a--}}}function Ze(t,e){const i=t.geometry,n=i.index?i.index.array:null,s=e.maxDepth,r=e.verbose,o=e.maxLeafTris,a=e.strategy,l=e.onProgress,c=Te(i),h=t._indirectBuffer;let u=!1;const d=new Float32Array(6),p=new Float32Array(6),f=function(t,e){var i;(i=e)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const n=t.attributes.position,s=t.index?t.index.array:null,r=Te(t),o=new Float32Array(6*r),a=n.normalized,l=n.array,c=n.offset||0;let h=3;n.isInterleavedBufferAttribute&&(h=n.data.stride);const u=["getX","getY","getZ"];for(let t=0;t<r;t++){const i=3*t,r=6*t;let d=i+0,p=i+1,f=i+2;s&&(d=s[d],p=s[p],f=s[f]),a||(d=d*h+c,p=p*h+c,f=f*h+c);for(let t=0;t<3;t++){let i,s,c;a?(i=n[u[t]](d),s=n[u[t]](p),c=n[u[t]](f)):(i=l[d+t],s=l[p+t],c=l[f+t]);let h=i;s<h&&(h=s),c<h&&(h=c);let m=i;s>m&&(m=s),c>m&&(m=c);const g=(m-h)/2,y=2*t;o[r+y+0]=h+g,o[r+y+1]=g+(Math.abs(h)+g)*Ae,h<e[t]&&(e[t]=h),m>e[t+3]&&(e[t+3]=m)}}return o}(i,d),m=e.indirect?We:je,g=[],y=e.indirect?Pe(i):Me(i);if(1===y.length){const t=y[0],e=new $e;e.boundingData=d,function(t,e,i,n){let s=1/0,r=1/0,o=1/0,a=-1/0,l=-1/0,c=-1/0;for(let n=6*e,h=6*(e+i);n<h;n+=6){const e=t[n+0];e<s&&(s=e),e>a&&(a=e);const i=t[n+2];i<r&&(r=i),i>l&&(l=i);const h=t[n+4];h<o&&(o=h),h>c&&(c=h)}n[0]=s,n[1]=r,n[2]=o,n[3]=a,n[4]=l,n[5]=c}(f,t.offset,t.count,p),v(e,t.offset,t.count,p),g.push(e)}else for(let t of y){const e=new $e;e.boundingData=new Float32Array(6),Ve(f,t.offset,t.count,e.boundingData,p),v(e,t.offset,t.count,p),g.push(e)}return g;function w(t){l&&l(t/c)}function v(t,e,l,c=null,d=0){if(!u&&d>=s&&(u=!0,r&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),l<=o||d>=s)return w(e+l),t.offset=e,t.count=l,t;const g=function(t,e,i,n,s,r){let o=-1,a=0;if(0===r)o=De(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===r)o=De(t),-1!==o&&(a=function(t,e,i,n){let s=0;for(let r=e,o=e+i;r<o;r++)s+=t[6*r+2*n];return s/i}(i,n,s,o));else if(2===r){const r=Ne(t);let l=Se*s;const c=6*n,h=6*(n+s);for(let t=0;t<3;t++){const n=e[t],u=(e[t+3]-n)/Fe;if(s<8){const e=[...Le];e.length=s;let n=0;for(let s=c;s<h;s+=6,n++){const r=e[n];r.candidate=i[s+2*t],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:l}=r;for(let t=0;t<3;t++)l[t]=1/0,l[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Oe(s,i,o)}e.sort(Re);let u=s;for(let t=0;t<u;t++){const i=e[t];for(;t+1<u&&e[t+1].candidate===i.candidate;)e.splice(t+1,1),u--}for(let n=c;n<h;n+=6){const s=i[n+2*t];for(let t=0;t<u;t++){const r=e[t];s>=r.candidate?Oe(n,i,r.rightCacheBounds):(Oe(n,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<u;i++){const n=e[i],c=n.count,h=s-n.count,u=n.leftCacheBounds,d=n.rightCacheBounds;let p=0;0!==c&&(p=Ne(u)/r);let f=0;0!==h&&(f=Ne(d)/r);const m=1+Se*(p*c+f*h);m<l&&(o=t,l=m,a=n.candidate)}}else{for(let t=0;t<Fe;t++){const e=Le[t];e.count=0,e.candidate=n+u+t*u;const i=e.bounds;for(let t=0;t<3;t++)i[t]=1/0,i[t+3]=-1/0}for(let e=c;e<h;e+=6){let s=~~((i[e+2*t]-n)/u);s>=Fe&&(s=31);const r=Le[s];r.count++,Oe(e,i,r.bounds)}const e=Le[31];ze(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Le[t],i=Le[t+1];Be(e.bounds,i.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let e=0;e<31;e++){const i=Le[e],n=i.count,c=i.bounds,h=Le[e+1].rightCacheBounds;0!==n&&(0===d?ze(c,Ue):Be(c,Ue,Ue)),d+=n;let u=0,p=0;0!==d&&(u=Ne(Ue)/r);const f=s-d;0!==f&&(p=Ne(h)/r);const m=1+Se*(u*d+p*f);m<l&&(o=t,l=m,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(t.boundingData,c,f,e,l,a);if(-1===g.axis)return w(e+l),t.offset=e,t.count=l,t;const y=m(h,n,f,e,l,g);if(y===e||y===e+l)w(e+l),t.offset=e,t.count=l;else{t.splitAxis=g.axis;const i=new $e,n=e,s=y-e;t.left=i,i.boundingData=new Float32Array(6),Ve(f,n,s,i.boundingData,p),v(i,n,s,p,d+1);const r=new $e,o=y,a=l-s;t.right=r,r.boundingData=new Float32Array(6),Ve(f,o,a,r.boundingData,p),v(r,o,a,p,d+1)}return t}}function Ge(t,e){const i=t.geometry;e.indirect&&(t._indirectBuffer=function(t,e){const i=(t.index?t.index.count:t.attributes.position.count)/3,n=i>65536,s=n?4:2,r=e?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),o=n?new Uint32Array(r):new Uint16Array(r);for(let t=0,e=o.length;t<e;t++)o[t]=t;return o}(i,e.useSharedArrayBuffer),function(t){if(0===t.groups.length)return!1;const e=Te(t),i=Me(t).sort((t,e)=>t.offset-e.offset),n=i[i.length-1];n.count=Math.min(e-n.offset,n.count);let s=0;return i.forEach(({count:t})=>s+=t),e!==s}(i)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),t._indirectBuffer||Ie(i,e);const n=Ze(t,e);let s,r,o;const a=[],l=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let t=0;t<n.length;t++){const e=n[t];const i=new l(32*c(e));s=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),h(0,e),a.push(i)}return void(t._roots=a);function c(t){return t.count?1:1+c(t.left)+c(t.right)}function h(t,e){const i=t/4,n=t/2,a=!!e.count,l=e.boundingData;for(let t=0;t<6;t++)s[i+t]=l[t];if(a){const s=e.offset,a=e.count;return r[i+6]=s,o[n+14]=a,o[n+15]=Ce,t+32}{const n=e.left,s=e.right,o=e.splitAxis;let a;if(a=h(t+32,n),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=h(a,s),r[i+7]=o,a}}}class qe{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,n=-1/0;for(let s=0,r=t.length;s<r;s++){const r=t[s][e];i=r<i?r:i,n=r>n?r:n}this.min=i,this.max=n}setFromPoints(t,e){let i=1/0,n=-1/0;for(let s=0,r=e.length;s<r;s++){const r=e[s],o=t.dot(r);i=o<i?o:i,n=o>n?o:n}this.min=i,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}qe.prototype.setFromBox=function(){const t=new n.Vector3;return function(e,i){const n=i.min,s=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let l=0;l<=1;l++){t.x=n.x*i+s.x*(1-i),t.y=n.y*a+s.y*(1-a),t.z=n.z*l+s.z*(1-l);const c=e.dot(t);r=Math.min(c,r),o=Math.max(c,o)}this.min=r,this.max=o}}();const Ye=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Vector3;return function(n,s,r){const o=n.start,a=t,l=s.start,c=e;i.subVectors(o,l),t.subVectors(n.end,n.start),e.subVectors(s.end,s.start);const h=i.dot(c),u=c.dot(a),d=c.dot(c),p=i.dot(a),f=a.dot(a)*d-u*u;let m,g;m=0!==f?(h*u-p*d)/f:0,g=(h+m*u)/d,r.x=m,r.y=g}}(),He=function(){const t=new n.Vector2,e=new n.Vector3,i=new n.Vector3;return function(n,s,r,o){Ye(n,s,t);let a=t.x,l=t.y;if(a>=0&&a<=1&&l>=0&&l<=1)return n.at(a,r),void s.at(l,o);if(a>=0&&a<=1)return l<0?s.at(0,o):s.at(1,o),void n.closestPointToPoint(o,!0,r);if(l>=0&&l<=1)return a<0?n.at(0,r):n.at(1,r),void s.closestPointToPoint(r,!0,o);{let t,c;t=a<0?n.start:n.end,c=l<0?s.start:s.end;const h=e,u=i;return n.closestPointToPoint(c,!0,e),s.closestPointToPoint(t,!0,i),h.distanceToSquared(c)<=u.distanceToSquared(t)?(r.copy(h),void o.copy(c)):(r.copy(t),void o.copy(u))}}}(),Xe=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Plane,s=new n.Line3;return function(n,r){const{radius:o,center:a}=n,{a:l,b:c,c:h}=r;s.start=l,s.end=c;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=l,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;s.start=c,s.end=h;if(s.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const u=r.getPlane(i);if(Math.abs(u.distanceToPoint(a))<=o){const t=u.projectPoint(a,e);if(r.containsPoint(t))return!0}return!1}}();function Qe(t){return Math.abs(t)<1e-15}class Ke extends n.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new n.Vector3),this.satBounds=new Array(4).fill().map(()=>new qe),this.points=[this.a,this.b,this.c],this.sphere=new n.Sphere,this.plane=new n.Plane,this.needsUpdate=!0}intersectsSphere(t){return Xe(t,this)}update(){const t=this.a,e=this.b,i=this.c,n=this.points,s=this.satAxes,r=this.satBounds,o=s[0],a=r[0];this.getNormal(o),a.setFromPoints(o,n);const l=s[1],c=r[1];l.subVectors(t,e),c.setFromPoints(l,n);const h=s[2],u=r[2];h.subVectors(e,i),u.setFromPoints(h,n);const d=s[3],p=r[3];d.subVectors(i,t),p.setFromPoints(d,n),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Ke.prototype.closestPointToSegment=function(){const t=new n.Vector3,e=new n.Vector3,i=new n.Line3;return function(n,s=null,r=null){const{start:o,end:a}=n,l=this.points;let c,h=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;i.start.copy(l[o]),i.end.copy(l[a]),He(i,n,t,e),c=t.distanceToSquared(e),c<h&&(h=c,s&&s.copy(t),r&&r.copy(e))}return this.closestPointToPoint(o,t),c=o.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(o)),this.closestPointToPoint(a,t),c=a.distanceToSquared(t),c<h&&(h=c,s&&s.copy(t),r&&r.copy(a)),Math.sqrt(h)}}(),Ke.prototype.intersectsTriangle=function(){const t=new Ke,e=new Array(3),i=new Array(3),s=new qe,r=new qe,o=new n.Vector3,a=new n.Vector3,l=new n.Vector3,c=new n.Vector3,h=new n.Vector3,u=new n.Line3,d=new n.Line3,p=new n.Line3,f=new n.Vector3;function m(t,e,i){const n=t.points;let s=0,r=-1;for(let t=0;t<3;t++){const{start:o,end:l}=u;o.copy(n[t]),l.copy(n[(t+1)%3]),u.delta(a);const c=Qe(e.distanceToPoint(o));if(Qe(e.normal.dot(a))&&c){i.copy(u),s=2;break}const h=e.intersectLine(u,f);if(!h&&c&&f.copy(o),(h||c)&&!Qe(f.distanceTo(l))){if(s<=1){(1===s?i.start:i.end).copy(f),c&&(r=s)}else if(s>=2){(1===r?i.start:i.end).copy(f),s=2;break}if(s++,2===s&&-1===r)break}}return s}return function(n,a=null,u=!1){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(t.copy(n),t.update(),n=t);const f=this.plane,g=n.plane;if(Math.abs(f.normal.dot(g.normal))>1-1e-10){const t=this.satBounds,l=this.satAxes;i[0]=n.a,i[1]=n.b,i[2]=n.c;for(let e=0;e<4;e++){const n=t[e],r=l[e];if(s.setFromPoints(r,i),n.isSeparated(s))return!1}const c=n.satBounds,h=n.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let t=0;t<4;t++){const i=c[t],n=h[t];if(s.setFromPoints(n,e),i.isSeparated(s))return!1}for(let t=0;t<4;t++){const n=l[t];for(let t=0;t<4;t++){const a=h[t];if(o.crossVectors(n,a),s.setFromPoints(o,e),r.setFromPoints(o,i),s.isSeparated(r))return!1}}return a&&(u||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const t=m(this,g,d);if(1===t&&n.containsPoint(d.end))return a&&(a.start.copy(d.end),a.end.copy(d.end)),!0;if(2!==t)return!1;const e=m(n,f,p);if(1===e&&this.containsPoint(p.end))return a&&(a.start.copy(p.end),a.end.copy(p.end)),!0;if(2!==e)return!1;if(d.delta(l),p.delta(c),l.dot(c)<0){let t=p.start;p.start=p.end,p.end=t}const i=d.start.dot(l),s=d.end.dot(l),r=p.start.dot(l),o=p.end.dot(l);return(i===o||r===s||s<r!==i<o)&&(a&&(h.subVectors(d.start,p.start),h.dot(l)>0?a.start.copy(d.start):a.start.copy(p.start),h.subVectors(d.end,p.end),h.dot(l)<0?a.end.copy(d.end):a.end.copy(p.end)),!0)}}}(),Ke.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Ke.prototype.distanceToTriangle=function(){const t=new n.Vector3,e=new n.Vector3,i=["a","b","c"],s=new n.Line3,r=new n.Line3;return function(n,o=null,a=null){const l=o||a?s:null;if(this.intersectsTriangle(n,l))return(o||a)&&(o&&l.getCenter(o),a&&l.getCenter(a)),0;let c=1/0;for(let e=0;e<3;e++){let s;const r=i[e],l=n[r];this.closestPointToPoint(l,t),s=l.distanceToSquared(t),s<c&&(c=s,o&&o.copy(t),a&&a.copy(l));const h=this[r];n.closestPointToPoint(h,t),s=h.distanceToSquared(t),s<c&&(c=s,o&&o.copy(h),a&&a.copy(t))}for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];s.set(this[h],this[u]);for(let l=0;l<3;l++){const h=i[l],u=i[(l+1)%3];r.set(n[h],n[u]),He(s,r,t,e);const d=t.distanceToSquared(e);d<c&&(c=d,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(c)}}();class Je{constructor(t,e,i){this.isOrientedBox=!0,this.min=new n.Vector3,this.max=new n.Vector3,this.matrix=new n.Matrix4,this.invMatrix=new n.Matrix4,this.points=new Array(8).fill().map(()=>new n.Vector3),this.satAxes=new Array(3).fill().map(()=>new n.Vector3),this.satBounds=new Array(3).fill().map(()=>new qe),this.alignedSatBounds=new Array(3).fill().map(()=>new qe),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Je.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,n=this.points;for(let s=0;s<=1;s++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=n[1*s|2*r|4*o];a.x=s?i.x:e.x,a.y=r?i.y:e.y,a.z=o?i.z:e.z,a.applyMatrix4(t)}const s=this.satBounds,r=this.satAxes,o=n[0];for(let t=0;t<3;t++){const e=r[t],i=s[t],a=n[1<<t];e.subVectors(o,a),i.setFromPoints(e,n)}const a=this.alignedSatBounds;a[0].setFromPointsField(n,"x"),a[1].setFromPointsField(n,"y"),a[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Je.prototype.intersectsBox=function(){const t=new qe;return function(e){this.needsUpdate&&this.update();const i=e.min,n=e.max,s=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(t.min=i.x,t.max=n.x,o[0].isSeparated(t))return!1;if(t.min=i.y,t.max=n.y,o[1].isSeparated(t))return!1;if(t.min=i.z,t.max=n.z,o[2].isSeparated(t))return!1;for(let i=0;i<3;i++){const n=r[i],o=s[i];if(t.setFromBox(n,e),o.isSeparated(t))return!1}return!0}}(),Je.prototype.intersectsTriangle=function(){const t=new Ke,e=new Array(3),i=new qe,s=new qe,r=new n.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(t.copy(n),t.update(),n=t);const o=this.satBounds,a=this.satAxes;e[0]=n.a,e[1]=n.b,e[2]=n.c;for(let t=0;t<3;t++){const n=o[t],s=a[t];if(i.setFromPoints(s,e),n.isSeparated(i))return!1}const l=n.satBounds,c=n.satAxes,h=this.points;for(let t=0;t<3;t++){const e=l[t],n=c[t];if(i.setFromPoints(n,h),e.isSeparated(i))return!1}for(let t=0;t<3;t++){const n=a[t];for(let t=0;t<4;t++){const o=c[t];if(r.crossVectors(n,o),i.setFromPoints(r,e),s.setFromPoints(r,h),i.isSeparated(s))return!1}}return!0}}(),Je.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Je.prototype.distanceToPoint=function(){const t=new n.Vector3;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Je.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new n.Line3),i=new Array(12).fill().map(()=>new n.Line3),s=new n.Vector3,r=new n.Vector3;return function(n,o=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||l)&&(n.getCenter(r),this.closestPointToPoint(r,s),n.closestPointToPoint(s,r),a&&a.copy(s),l&&l.copy(r)),0;const c=o*o,h=n.min,u=n.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(h,u);const i=e.distanceToSquared(r);if(i<p&&(p=i,a&&a.copy(e),l&&l.copy(r),i<c))return Math.sqrt(i)}let f=0;for(let n=0;n<3;n++)for(let s=0;s<=1;s++)for(let r=0;r<=1;r++){const o=(n+1)%3,a=(n+2)%3,l=1<<n|s<<o|r<<a,c=d[s<<o|r<<a],p=d[l];e[f].set(c,p);const m=t[n],g=t[o],y=t[a],w=i[f],v=w.start,b=w.end;v[m]=h[m],v[g]=s?h[g]:u[g],v[y]=r?h[y]:u[g],b[m]=u[m],b[g]=s?h[g]:u[g],b[y]=r?h[y]:u[g],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let i=0;i<=1;i++){r.x=t?u.x:h.x,r.y=e?u.y:h.y,r.z=i?u.z:h.z,this.closestPointToPoint(r,s);const n=r.distanceToSquared(s);if(n<p&&(p=n,a&&a.copy(s),l&&l.copy(r),n<c))return Math.sqrt(n)}for(let t=0;t<12;t++){const n=e[t];for(let t=0;t<12;t++){const e=i[t];He(n,e,s,r);const o=s.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(s),l&&l.copy(r),o<c))return Math.sqrt(o)}}return Math.sqrt(p)}}();class ti{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class ei extends ti{constructor(){super(()=>new Ke)}}const ii=new ei;function ni(t,e){return 65535===e[t+15]}function si(t,e){return e[t+6]}function ri(t,e){return e[t+14]}function oi(t){return t+8}function ai(t,e){return e[t+6]}function li(t,e){return e[t+7]}function ci(t){return t}const hi=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}};let ui,di;const pi=[],fi=new ti(()=>new n.Box3);function mi(t,e,i,n,s,r){ui=fi.getPrimitive(),di=fi.getPrimitive(),pi.push(ui,di),hi.setBuffer(t._roots[e]);const o=gi(0,t.geometry,i,n,s,r);hi.clearBuffer(),fi.releasePrimitive(ui),fi.releasePrimitive(di),pi.pop(),pi.pop();const a=pi.length;return a>0&&(di=pi[a-1],ui=pi[a-2]),o}function gi(t,e,i,n,s=null,r=0,o=0){const{float32Array:a,uint16Array:l,uint32Array:c}=hi;let h=2*t;if(ni(h,l)){const e=si(t,c),i=ri(h,l);return ke(t,a,ui),n(e,i,!1,o,r+t,ui)}{let h=function(t){const{uint16Array:e,uint32Array:i}=hi;let n=2*t;for(;!ni(n,e);)n=2*(t=oi(t));return si(t,i)},u=function(t){const{uint16Array:e,uint32Array:i}=hi;let n=2*t;for(;!ni(n,e);)n=2*(t=ai(t,i));return si(t,i)+ri(n,e)};const d=oi(t),p=ai(t,c);let f,m,g,y,w=d,v=p;if(s&&(g=ui,y=di,ke(w,a,g),ke(v,a,y),f=s(g),m=s(y),m<f)){w=p,v=d;const t=f;f=m,m=t,g=y}g||(g=ui,ke(w,a,g));const b=i(g,ni(2*w,l),f,o+1,r+w);let _;if(2===b){const t=h(w);_=n(t,u(w)-t,!0,o+1,r+w,g)}else _=b&&gi(w,e,i,n,s,r,o+1);if(_)return!0;y=di,ke(v,a,y);const x=i(y,ni(2*v,l),m,o+1,r+v);let S;if(2===x){const t=h(v);S=n(t,u(v)-t,!0,o+1,r+v,y)}else S=x&&gi(v,e,i,n,s,r,o+1);return!!S}}const yi=new n.Vector3,wi=new n.Vector3;const vi=new n.Vector3,bi=new n.Vector3,_i=new n.Vector3,xi=new n.Vector2,Si=new n.Vector2,Ci=new n.Vector2,Ai=new n.Vector3,Ei=new n.Vector3,Ti=new n.Vector3,Ii=new n.Vector3;function Pi(t,e,i,s,r,o,a,l,c){vi.fromBufferAttribute(e,o),bi.fromBufferAttribute(e,a),_i.fromBufferAttribute(e,l);const h=function(t,e,i,s,r,o){let a;return a=o===n.BackSide?t.intersectTriangle(s,i,e,!0,r):t.intersectTriangle(e,i,s,o!==n.DoubleSide,r),null===a?null:{distance:t.origin.distanceTo(r),point:r.clone()}}(t,vi,bi,_i,Ii,c);if(h){s&&(xi.fromBufferAttribute(s,o),Si.fromBufferAttribute(s,a),Ci.fromBufferAttribute(s,l),h.uv=n.Triangle.getInterpolation(Ii,vi,bi,_i,xi,Si,Ci,new n.Vector2)),r&&(xi.fromBufferAttribute(r,o),Si.fromBufferAttribute(r,a),Ci.fromBufferAttribute(r,l),h.uv1=n.Triangle.getInterpolation(Ii,vi,bi,_i,xi,Si,Ci,new n.Vector2)),i&&(Ai.fromBufferAttribute(i,o),Ei.fromBufferAttribute(i,a),Ti.fromBufferAttribute(i,l),h.normal=n.Triangle.getInterpolation(Ii,vi,bi,_i,Ai,Ei,Ti,new n.Vector3),h.normal.dot(t.direction)>0&&h.normal.multiplyScalar(-1));const e={a:o,b:a,c:l,normal:new n.Vector3,materialIndex:0};n.Triangle.getNormal(vi,bi,_i,e.normal),h.face=e,h.faceIndex=o}return h}function Mi(t,e,i,n,s){const r=3*n;let o=r+0,a=r+1,l=r+2;const c=t.index;t.index&&(o=c.getX(o),a=c.getX(a),l=c.getX(l));const{position:h,normal:u,uv:d,uv1:p}=t.attributes,f=Pi(i,h,u,d,p,o,a,l,e);return f?(f.faceIndex=n,s&&s.push(f),f):null}function ki(t,e,i,n){const s=t.a,r=t.b,o=t.c;let a=e,l=e+1,c=e+2;i&&(a=i.getX(a),l=i.getX(l),c=i.getX(c)),s.x=n.getX(a),s.y=n.getY(a),s.z=n.getZ(a),r.x=n.getX(l),r.y=n.getY(l),r.z=n.getZ(l),o.x=n.getX(c),o.y=n.getY(c),o.z=n.getZ(c)}function Di(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let i=t,a=e+t;i<a;i++){let t;if(t=i,ki(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}function zi(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(t,i,r=!1){const c=2*t;if(a[c+15]===Ce){const e=o[t+6];let i=1/0,r=1/0,h=1/0,u=-1/0,d=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[c+14]);t<o;t++){let e=n[t];const o=s.getX(e),a=s.getY(e),l=s.getZ(e);o<i&&(i=o),o>u&&(u=o),a<r&&(r=a),a>d&&(d=a),l<h&&(h=l),l>p&&(p=l)}return(l[t+0]!==i||l[t+1]!==r||l[t+2]!==h||l[t+3]!==u||l[t+4]!==d||l[t+5]!==p)&&(l[t+0]=i,l[t+1]=r,l[t+2]=h,l[t+3]=u,l[t+4]=d,l[t+5]=p,!0)}{const n=t+8,s=o[t+6],a=n+i,c=s+i;let h=r,d=!1,p=!1;e?h||(d=e.has(a),p=e.has(c),h=!d&&!p):(d=!0,p=!0);const f=h||p;let m=!1;(h||d)&&(m=u(n,i,h));let g=!1;f&&(g=u(s,i,h));const y=m||g;if(y)for(let e=0;e<3;e++){const i=n+e,r=s+e,o=l[i],a=l[i+3],c=l[r],h=l[r+3];l[t+e]=o<c?o:c,l[t+e+3]=a>h?a:h}return y}}}const Bi=new n.Box3;function Oi(t,e,i,n){return ke(t,e,Bi),i.intersectBox(Bi,n)}function Ni(t,e,i,n,s,r,o){const{geometry:a}=i,{index:l}=a,c=a.attributes.position;for(let a=t,h=e+t;a<h;a++){let t;if(t=i.resolveTriangleIndex(a),ki(o,3*t,l,c),o.needsUpdate=!0,n(o,t,s,r))return!0}return!1}const Vi=new n.Vector3;function Fi(t,e,i,n,s){hi.setBuffer(t._roots[e]),Ri(0,t,i,n,s),hi.clearBuffer()}function Ri(t,e,i,n,s){const{float32Array:r,uint16Array:o,uint32Array:a}=hi,l=2*t;if(ni(l,o)){!function(t,e,i,n,s,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=n,a=n+s;t<a;t++)Mi(o,e,i,t,r)}(e,i,n,si(t,a),ri(l,o),s)}else{const o=oi(t);Oi(o,r,n,Vi)&&Ri(o,e,i,n,s);const l=ai(t,a);Oi(l,r,n,Vi)&&Ri(l,e,i,n,s)}}const Li=new n.Vector3,Ui=["x","y","z"];function $i(t,e,i,n){hi.setBuffer(t._roots[e]);const s=ji(0,t,i,n);return hi.clearBuffer(),s}function ji(t,e,i,n){const{float32Array:s,uint16Array:r,uint32Array:o}=hi;let a=2*t;if(ni(a,r)){return function(t,e,i,n,s){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=n,o=n+s;t<o;t++){let n;n=Mi(r,e,i,t),n&&n.distance<a&&(l=n,a=n.distance)}return l}(e,i,n,si(t,o),ri(a,r))}{const r=li(t,o),a=Ui[r],l=n.direction[a]>=0;let c,h;l?(c=oi(t),h=ai(t,o)):(c=ai(t,o),h=oi(t));const u=Oi(c,s,n,Li)?ji(c,e,i,n):null;if(u){const t=u.point[a];if(l?t<=s[h+r]:t>=s[h+r+3])return u}const d=Oi(h,s,n,Li)?ji(h,e,i,n):null;return u&&d?u.distance<=d.distance?u:d:u||d||null}}const Wi=new n.Box3,Zi=new Ke,Gi=new Ke,qi=new n.Matrix4,Yi=new Je,Hi=new Je;function Xi(t,e,i,n){hi.setBuffer(t._roots[e]);const s=Qi(0,t,i,n);return hi.clearBuffer(),s}function Qi(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=hi;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),Yi.set(i.boundingBox.min,i.boundingBox.max,n),s=Yi);if(!ni(l,o)){const o=t+8,l=a[t+6];ke(o,r,Wi);if(s.intersectsBox(Wi)&&Qi(o,e,i,n,s))return!0;ke(l,r,Wi);return!!(s.intersectsBox(Wi)&&Qi(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=si(t,a),f=ri(l,o);if(qi.copy(n).invert(),i.boundsTree){ke(t,r,Hi),Hi.matrix.copy(qi),Hi.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>Hi.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let e=3*p,i=3*(f+p);e<i;e+=3)if(ki(Gi,e,c,h),Gi.needsUpdate=!0,t.intersectsTriangle(Gi))return!0;return!1}})}for(let t=3*p,e=3*(f+p);t<e;t+=3){ki(Zi,t,c,h),Zi.a.applyMatrix4(qi),Zi.b.applyMatrix4(qi),Zi.c.applyMatrix4(qi),Zi.needsUpdate=!0;for(let t=0,e=u.count;t<e;t+=3)if(ki(Gi,t,u,d),Gi.needsUpdate=!0,Zi.intersectsTriangle(Gi))return!0}}}const Ki=new n.Matrix4,Ji=new Je,tn=new Je,en=new n.Vector3,nn=new n.Vector3,sn=new n.Vector3,rn=new n.Vector3;function on(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Ji.set(e.boundingBox.min,e.boundingBox.max,i),Ji.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=ii.getPrimitive(),p=ii.getPrimitive();let f=en,m=nn,g=null,y=null;s&&(g=sn,y=rn);let w=1/0,v=null,b=null;return Ki.copy(i).invert(),tn.matrix.copy(Ki),t.shapecast({boundsTraverseOrder:t=>Ji.distanceToBox(t),intersectsBounds:(t,e,i)=>i<w&&i<o&&(e&&(tn.min.copy(t.min),tn.max.copy(t.max),tn.needsUpdate=!0),!0),intersectsRange:(t,n)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>tn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<w&&i<o,intersectsRange:(e,s)=>{for(let o=e,a=e+s;o<a;o++){ki(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){ki(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<w&&(m.copy(f),y&&y.copy(g),w=t,v=e,b=o),t<r)return!0}}}})}for(let s=0,o=Te(e);s<o;s++){ki(p,3*s,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++){ki(d,3*e,c,l),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,g);if(t<w&&(m.copy(f),y&&y.copy(g),w=t,v=e,b=s),t<r)return!0}}}}),ii.releasePrimitive(d),ii.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=w,n.faceIndex=v,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(Ki),m.applyMatrix4(Ki),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}function an(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const i=t.geometry,n=i.index?i.index.array:null,s=i.attributes.position;let r,o,a,l,c=0;const h=t._roots;for(let t=0,e=h.length;t<e;t++)r=h[t],o=new Uint32Array(r),a=new Uint16Array(r),l=new Float32Array(r),u(0,c),c+=r.byteLength;function u(i,r,c=!1){const h=2*i;if(a[h+15]===Ce){const e=o[i+6];let r=1/0,c=1/0,u=1/0,d=-1/0,p=-1/0,f=-1/0;for(let i=e,o=e+a[h+14];i<o;i++){const e=3*t.resolveTriangleIndex(i);for(let t=0;t<3;t++){let i=e+t;i=n?n[i]:i;const o=s.getX(i),a=s.getY(i),l=s.getZ(i);o<r&&(r=o),o>d&&(d=o),a<c&&(c=a),a>p&&(p=a),l<u&&(u=l),l>f&&(f=l)}}return(l[i+0]!==r||l[i+1]!==c||l[i+2]!==u||l[i+3]!==d||l[i+4]!==p||l[i+5]!==f)&&(l[i+0]=r,l[i+1]=c,l[i+2]=u,l[i+3]=d,l[i+4]=p,l[i+5]=f,!0)}{const t=i+8,n=o[i+6],s=t+r,a=n+r;let h=c,d=!1,p=!1;e?h||(d=e.has(s),p=e.has(a),h=!d&&!p):(d=!0,p=!0);const f=h||p;let m=!1;(h||d)&&(m=u(t,r,h));let g=!1;f&&(g=u(n,r,h));const y=m||g;if(y)for(let e=0;e<3;e++){const s=t+e,r=n+e,o=l[s],a=l[s+3],c=l[r],h=l[r+3];l[i+e]=o<c?o:c,l[i+e+3]=a>h?a:h}return y}}}const ln=new n.Vector3;function cn(t,e,i,n,s){hi.setBuffer(t._roots[e]),hn(0,t,i,n,s),hi.clearBuffer()}function hn(t,e,i,n,s){const{float32Array:r,uint16Array:o,uint32Array:a}=hi,l=2*t;if(ni(l,o)){!function(t,e,i,n,s,r){const{geometry:o,_indirectBuffer:a}=t;for(let t=n,l=n+s;t<l;t++)Mi(o,e,i,a?a[t]:t,r)}(e,i,n,si(t,a),ri(l,o),s)}else{const o=oi(t);Oi(o,r,n,ln)&&hn(o,e,i,n,s);const l=ai(t,a);Oi(l,r,n,ln)&&hn(l,e,i,n,s)}}const un=new n.Vector3,dn=["x","y","z"];function pn(t,e,i,n){hi.setBuffer(t._roots[e]);const s=fn(0,t,i,n);return hi.clearBuffer(),s}function fn(t,e,i,n){const{float32Array:s,uint16Array:r,uint32Array:o}=hi;let a=2*t;if(ni(a,r)){return function(t,e,i,n,s){const{geometry:r,_indirectBuffer:o}=t;let a=1/0,l=null;for(let t=n,c=n+s;t<c;t++){let n;n=Mi(r,e,i,o?o[t]:t),n&&n.distance<a&&(l=n,a=n.distance)}return l}(e,i,n,si(t,o),ri(a,r))}{const r=li(t,o),a=dn[r],l=n.direction[a]>=0;let c,h;l?(c=oi(t),h=ai(t,o)):(c=ai(t,o),h=oi(t));const u=Oi(c,s,n,un)?fn(c,e,i,n):null;if(u){const t=u.point[a];if(l?t<=s[h+r]:t>=s[h+r+3])return u}const d=Oi(h,s,n,un)?fn(h,e,i,n):null;return u&&d?u.distance<=d.distance?u:d:u||d||null}}const mn=new n.Box3,gn=new Ke,yn=new Ke,wn=new n.Matrix4,vn=new Je,bn=new Je;function _n(t,e,i,n){hi.setBuffer(t._roots[e]);const s=xn(0,t,i,n);return hi.clearBuffer(),s}function xn(t,e,i,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=hi;let l=2*t;null===s&&(i.boundingBox||i.computeBoundingBox(),vn.set(i.boundingBox.min,i.boundingBox.max,n),s=vn);if(!ni(l,o)){const o=t+8,l=a[t+6];ke(o,r,mn);if(s.intersectsBox(mn)&&xn(o,e,i,n,s))return!0;ke(l,r,mn);return!!(s.intersectsBox(mn)&&xn(l,e,i,n,s))}{const s=e.geometry,c=s.index,h=s.attributes.position,u=i.index,d=i.attributes.position,p=si(t,a),f=ri(l,o);if(wn.copy(n).invert(),i.boundsTree){ke(t,r,bn),bn.matrix.copy(wn),bn.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:t=>bn.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(n),t.b.applyMatrix4(n),t.c.applyMatrix4(n),t.needsUpdate=!0;for(let i=p,n=f+p;i<n;i++)if(ki(yn,3*e.resolveTriangleIndex(i),c,h),yn.needsUpdate=!0,t.intersectsTriangle(yn))return!0;return!1}})}for(let t=p,i=f+p;t<i;t++){const i=e.resolveTriangleIndex(t);ki(gn,3*i,c,h),gn.a.applyMatrix4(wn),gn.b.applyMatrix4(wn),gn.c.applyMatrix4(wn),gn.needsUpdate=!0;for(let t=0,e=u.count;t<e;t+=3)if(ki(yn,t,u,d),yn.needsUpdate=!0,gn.intersectsTriangle(yn))return!0}}}const Sn=new n.Matrix4,Cn=new Je,An=new Je,En=new n.Vector3,Tn=new n.Vector3,In=new n.Vector3,Pn=new n.Vector3;function Mn(t,e,i,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Cn.set(e.boundingBox.min,e.boundingBox.max,i),Cn.needsUpdate=!0;const a=t.geometry,l=a.attributes.position,c=a.index,h=e.attributes.position,u=e.index,d=ii.getPrimitive(),p=ii.getPrimitive();let f=En,m=Tn,g=null,y=null;s&&(g=In,y=Pn);let w=1/0,v=null,b=null;return Sn.copy(i).invert(),An.matrix.copy(Sn),t.shapecast({boundsTraverseOrder:t=>Cn.distanceToBox(t),intersectsBounds:(t,e,i)=>i<w&&i<o&&(e&&(An.min.copy(t.min),An.max.copy(t.max),An.needsUpdate=!0),!0),intersectsRange:(n,s)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>An.distanceToBox(t),intersectsBounds:(t,e,i)=>i<w&&i<o,intersectsRange:(e,o)=>{for(let _=e,x=e+o;_<x;_++){const e=a.resolveTriangleIndex(_);ki(p,3*e,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);ki(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<w&&(m.copy(f),y&&y.copy(g),w=n,v=e,b=_),n<r)return!0}}}})}for(let o=0,a=Te(e);o<a;o++){ki(p,3*o,u,h),p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let e=n,i=n+s;e<i;e++){const i=t.resolveTriangleIndex(e);ki(d,3*i,c,l),d.needsUpdate=!0;const n=d.distanceToTriangle(p,f,g);if(n<w&&(m.copy(f),y&&y.copy(g),w=n,v=e,b=o),n<r)return!0}}}}),ii.releasePrimitive(d),ii.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=w,n.faceIndex=v,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(Sn),m.applyMatrix4(Sn),s.distance=m.sub(s.point).length(),s.faceIndex=b),n)}const kn=new hi.constructor,Dn=new hi.constructor,zn=new ti(()=>new n.Box3),Bn=new n.Box3,On=new n.Box3,Nn=new n.Box3,Vn=new n.Box3;let Fn=!1;function Rn(t,e,i,n,s,r=0,o=0,a=0,l=0,c=null,h=!1){let u,d;h?(u=Dn,d=kn):(u=kn,d=Dn);const p=u.float32Array,f=u.uint32Array,m=u.uint16Array,g=d.float32Array,y=d.uint32Array,w=d.uint16Array,v=2*e,b=ni(2*t,m),_=ni(v,w);let x=!1;if(_&&b)x=h?s(si(e,y),ri(2*e,w),si(t,f),ri(2*t,m),l,o+e,a,r+t):s(si(t,f),ri(2*t,m),si(e,y),ri(2*e,w),a,r+t,l,o+e);else if(_){const c=zn.getPrimitive();ke(e,g,c),c.applyMatrix4(i);const u=oi(t),d=ai(t,f);ke(u,p,Bn),ke(d,p,On);const m=c.intersectsBox(Bn),y=c.intersectsBox(On);x=m&&Rn(e,u,n,i,s,o,r,l,a+1,c,!h)||y&&Rn(e,d,n,i,s,o,r,l,a+1,c,!h),zn.releasePrimitive(c)}else{const u=oi(e),d=ai(e,y);ke(u,g,Nn),ke(d,g,Vn);const m=c.intersectsBox(Nn),w=c.intersectsBox(Vn);if(m&&w)x=Rn(t,u,i,n,s,r,o,a,l+1,c,h)||Rn(t,d,i,n,s,r,o,a,l+1,c,h);else if(m)if(b)x=Rn(t,u,i,n,s,r,o,a,l+1,c,h);else{const e=zn.getPrimitive();e.copy(Nn).applyMatrix4(i);const c=oi(t),d=ai(t,f);ke(c,p,Bn),ke(d,p,On);const m=e.intersectsBox(Bn),g=e.intersectsBox(On);x=m&&Rn(u,c,n,i,s,o,r,l,a+1,e,!h)||g&&Rn(u,d,n,i,s,o,r,l,a+1,e,!h),zn.releasePrimitive(e)}else if(w)if(b)x=Rn(t,d,i,n,s,r,o,a,l+1,c,h);else{const e=zn.getPrimitive();e.copy(Vn).applyMatrix4(i);const c=oi(t),u=ai(t,f);ke(c,p,Bn),ke(u,p,On);const m=e.intersectsBox(Bn),g=e.intersectsBox(On);x=m&&Rn(d,c,n,i,s,o,r,l,a+1,e,!h)||g&&Rn(d,u,n,i,s,o,r,l,a+1,e,!h),zn.releasePrimitive(e)}}return x}const Ln=new Je,Un=new n.Box3;class $n{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,n=t._roots,s=t._indirectBuffer,r=i.getIndex();let o;return o=e.cloneBuffers?{roots:n.map(t=>t.slice()),index:r.array.slice(),indirectBuffer:s?s.slice():null}:{roots:n,index:r.array,indirectBuffer:s},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:Boolean(t.indirectBuffer),...i};const{index:s,roots:r,indirectBuffer:o}=t,a=new $n(e,{...i,[Ee]:!0});if(a._roots=r,a._indirectBuffer=o||null,i.setIndex){const i=e.getIndex();if(null===i){const i=new n.BufferAttribute(t.index,1,!1);e.setIndex(i)}else i.array!==s&&(i.array.set(s),i.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ee]:!1},e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Ee]||(Ge(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new n.Box3)));const{_indirectBuffer:i}=this;this.resolveTriangleIndex=e.indirect?t=>i[t]:t=>t}refit(t=null){return(this.indirect?an:zi)(this,t)}traverse(t,e=0){const i=this._roots[e],n=new Uint32Array(i),s=new Uint16Array(i);!function e(r,o=0){const a=2*r,l=s[a+15]===Ce;if(l){const e=n[r+6],c=s[a+14];t(o,l,new Float32Array(i,4*r,6),e,c)}else{const s=r+8,a=n[r+6],c=n[r+7];t(o,l,new Float32Array(i,4*r,6),c)||(e(s,o+1),e(a,o+1))}}(0)}raycast(t,e=n.FrontSide){const i=this._roots,s=this.geometry,r=[],o=e.isMaterial,a=Array.isArray(e),l=s.groups,c=o?e.side:e,h=this.indirect?cn:Fi;for(let n=0,s=i.length;n<s;n++){const i=a?e[l[n].materialIndex].side:c,s=r.length;if(h(this,n,i,t,r),a){const t=l[n].materialIndex;for(let e=s,i=r.length;e<i;e++)r[e].face.materialIndex=t}}return r}raycastFirst(t,e=n.FrontSide){const i=this._roots,s=this.geometry,r=e.isMaterial,o=Array.isArray(e);let a=null;const l=s.groups,c=r?e.side:e,h=this.indirect?pn:$i;for(let n=0,s=i.length;n<s;n++){const i=h(this,n,o?e[l[n].materialIndex].side:c,t);null!=i&&(null==a||i.distance<a.distance)&&(a=i,o&&(i.face.materialIndex=l[n].materialIndex))}return a}intersectsGeometry(t,e){let i=!1;const n=this._roots,s=this.indirect?_n:Xi;for(let r=0,o=n.length;r<o&&(i=s(this,r,t,e),!i);r++);return i}shapecast(t){const e=ii.getPrimitive(),i=this.indirect?Ni:Di;let{boundsTraverseOrder:n,intersectsBounds:s,intersectsRange:r,intersectsTriangle:o}=t;if(r&&o){const t=r;r=(n,s,r,a,l)=>!!t(n,s,r,a,l)||i(n,s,this,o,r,a,e)}else r||(r=o?(t,n,s,r)=>i(t,n,this,o,s,r,e):(t,e,i)=>i);let a=!1,l=0;const c=this._roots;for(let t=0,e=c.length;t<e;t++){const e=c[t];if(a=mi(this,t,s,r,n,l),a)break;l+=e.byteLength}return ii.releasePrimitive(e),a}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:r}=i;const o=ii.getPrimitive(),a=this.geometry.index,l=this.geometry.attributes.position,c=this.indirect?t=>{const e=this.resolveTriangleIndex(t);ki(o,3*e,a,l)}:t=>{ki(o,3*t,a,l)},h=ii.getPrimitive(),u=t.geometry.index,d=t.geometry.attributes.position,p=t.indirect?e=>{const i=t.resolveTriangleIndex(e);ki(h,3*i,u,d)}:t=>{ki(h,3*t,u,d)};if(r){const t=(t,i,n,s,a,l,u,d)=>{for(let f=n,m=n+s;f<m;f++){p(f),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++)if(c(e),o.needsUpdate=!0,r(o,h,e,f,a,l,u,d))return!0}return!1};if(s){const e=s;s=function(i,n,s,r,o,a,l,c){return!!e(i,n,s,r,o,a,l,c)||t(i,n,s,r,o,a,l,c)}}else s=t}return function(t,e,i,s){if(Fn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Fn=!0;const r=t._roots,o=e._roots;let a,l=0,c=0;const h=(new n.Matrix4).copy(i).invert();for(let t=0,e=r.length;t<e;t++){kn.setBuffer(r[t]),c=0;const e=zn.getPrimitive();ke(ci(0),kn.float32Array,e),e.applyMatrix4(h);for(let n=0,r=o.length;n<r&&(Dn.setBuffer(o[t]),a=Rn(0,0,i,h,s,l,c,0,0,e),Dn.clearBuffer(),c+=o[n].length,!a);n++);if(zn.releasePrimitive(e),kn.clearBuffer(),l+=r[t].length,a)break}return Fn=!1,a}(this,t,e,s)}intersectsBox(t,e){return Ln.set(t.min,t.max,e),Ln.needsUpdate=!0,this.shapecast({intersectsBounds:t=>Ln.intersectsBox(t),intersectsTriangle:t=>Ln.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},n={},s=0,r=1/0){return(this.indirect?Mn:on)(this,t,e,i,n,s,r)}closestPointToPoint(t,e={},i=0,n=1/0){return function(t,e,i={},n=0,s=1/0){const r=n*n,o=s*s;let a=1/0,l=null;if(t.shapecast({boundsTraverseOrder:t=>(yi.copy(e).clamp(t.min,t.max),yi.distanceToSquared(e)),intersectsBounds:(t,e,i)=>i<a&&i<o,intersectsTriangle:(t,i)=>{t.closestPointToPoint(e,yi);const n=e.distanceToSquared(yi);return n<a&&(wi.copy(yi),a=n,l=i),n<r}}),a===1/0)return null;const c=Math.sqrt(a);return i.point?i.point.copy(wi):i.point=wi.clone(),i.distance=c,i.faceIndex=l,i}(this,t,e,i,n)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{ke(0,new Float32Array(e),Un),t.union(Un)}),t}}function jn(t,e,i){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(i.ray.origin),t.object=e,t.distance<i.near||t.distance>i.far?null:t)}const Wn=new n.Ray,Zn=new n.Matrix4,Gn=n.Mesh.prototype.raycast;function qn(t,e){if(this.geometry.boundsTree){if(void 0===this.material)return;Zn.copy(this.matrixWorld).invert(),Wn.copy(t.ray).applyMatrix4(Zn);const i=this.geometry.boundsTree;if(!0===t.firstHitOnly){const n=jn(i.raycastFirst(Wn,this.material),this,t);n&&e.push(n)}else{const n=i.raycast(Wn,this.material);for(let i=0,s=n.length;i<s;i++){const s=jn(n[i],this,t);s&&e.push(s)}}}else Gn.call(this,t,e)}function Yn(t){return this.boundsTree=new $n(this,t),this.boundsTree}function Hn(){this.boundsTree=null}const Xn=class t{constructor(){e(this,"onDisposed",new h),e(this,"list",new i.DataMap),e(this,"enabled",!1),e(this,"_clock"),e(this,"onInit",new h),e(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(t);requestAnimationFrame(this.update)}),this._clock=new l.Clock,t.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");_.validate(t),this.list.set(t,e)}get(t){var e;const i=t.uuid;if(!this.list.has(i)){const n=new t(this);return(null==(e=n.isDisposeable)?void 0:e.call(n))&&n.onDisposed.add(()=>this.list.delete(i)),this.list.has(i)||this.add(i,n),n}return this.list.get(i)}init(){this.enabled=!0;for(const[t,e]of this.list.entries())e.enabled=!0;this._clock.start(),this.update(),this.onInit.trigger()}dispose(){let t;this.enabled=!1;for(const[e,i]of this.list)i.enabled=!1,e!==Zt.uuid?i.isDisposeable()&&i.dispose():t=i;null==t||t.dispose(),this._clock.stop(),this.onDisposed.trigger()}static setupBVH(){l.BufferGeometry.prototype.computeBoundsTree=Yn,l.BufferGeometry.prototype.disposeBoundsTree=Hn,l.Mesh.prototype.raycast=qn}};e(Xn,"release","2.4.3");let Qn=Xn;class Kn{constructor(t){e(this,"enabled",!1),e(this,"id","FirstPerson"),this.camera=t}set(t){if(this.enabled=t,t){if("Perspective"!==this.camera.projection.current)return void this.camera.set("Orbit");this.setupFirstPersonCamera()}}setupFirstPersonCamera(){const t=this.camera.controls,e=new l.Vector3;t.distance--,t.getPosition(e),t.minDistance=1,t.maxDistance=1,t.distance=1,t.moveTo(e.x,e.y,e.z),t.truckSpeed=50,t.mouseButtons.wheel=r.ACTION.DOLLY,t.touches.two=r.ACTION.TOUCH_ZOOM_TRUCK}}class Jn{constructor(t){e(this,"enabled",!0),e(this,"id","Orbit"),this.camera=t,this.activateOrbitControls()}set(t){this.enabled=t,t&&this.activateOrbitControls()}activateOrbitControls(){const t=this.camera.controls;t.minDistance=1,t.maxDistance=300;const e=new l.Vector3;t.getPosition(e);const i=e.length();t.distance=i,t.truckSpeed=2;const{rotation:n}=this.camera.three,s=new l.Vector3(0,0,-1).applyEuler(n),r=e.addScaledVector(s,i);t.moveTo(r.x,r.y,r.z)}}class ts{constructor(t){e(this,"enabled",!1),e(this,"id","Plan"),e(this,"mouseAction1"),e(this,"mouseAction2"),e(this,"mouseInitialized",!1),e(this,"defaultAzimuthSpeed"),e(this,"defaultPolarSpeed"),this.camera=t,this.defaultAzimuthSpeed=t.controls.azimuthRotateSpeed,this.defaultPolarSpeed=t.controls.polarRotateSpeed}set(t){this.enabled=t;const e=this.camera.controls;e.azimuthRotateSpeed=t?0:this.defaultAzimuthSpeed,e.polarRotateSpeed=t?0:this.defaultPolarSpeed,this.mouseInitialized||(this.mouseAction1=e.touches.one,this.mouseAction2=e.touches.two,this.mouseInitialized=!0),t?(e.mouseButtons.left=r.ACTION.TRUCK,e.touches.one=r.ACTION.TOUCH_TRUCK,e.touches.two=r.ACTION.TOUCH_ZOOM):(e.mouseButtons.left=r.ACTION.ROTATE,e.touches.one=this.mouseAction1,e.touches.two=this.mouseAction2)}}class es{constructor(t){e(this,"onChanged",new h),e(this,"current","Perspective"),e(this,"camera"),e(this,"matchOrthoDistanceEnabled",!1),e(this,"_component"),e(this,"_previousDistance",-1),this._component=t,this.camera=t.three}async set(t){this.current!==t&&("Orthographic"===t?this.setOrthoCamera():await this.setPerspectiveCamera(),this.onChanged.trigger(this.camera))}async toggle(){const t="Perspective"===this.current?"Orthographic":"Perspective";await this.set(t)}setOrthoCamera(){if(null===this._component.mode)return;if("FirstPerson"===this._component.mode.id)return;this._previousDistance=this._component.controls.distance,this._component.controls.distance=200;const t=this.getPerspectiveDims();if(!t)return;const{width:e,height:i}=t;this.setupOrthoCamera(i,e),this.camera=this._component.threeOrtho,this.current="Orthographic"}getPerspectiveDims(){const t=this._component.currentWorld;if(!t||!t.renderer)return null;const e=new l.Vector3;this._component.threePersp.getWorldDirection(e);const i=new l.Vector3;this._component.controls.getTarget(i);const n=i.clone().sub(this._component.threePersp.position).dot(e),s=t.renderer.getSize(),r=s.x/s.y,o=this._component.threePersp,a=2*n*Math.atan(o.fov*(Math.PI/180)/2);return{width:a*r,height:a}}setupOrthoCamera(t,e){this._component.controls.mouseButtons.wheel=r.ACTION.ZOOM,this._component.controls.mouseButtons.middle=r.ACTION.ZOOM;const i=this._component.threePersp,n=this._component.threeOrtho;n.zoom=1,n.left=e/-2,n.right=e/2,n.top=t/2,n.bottom=t/-2,n.updateProjectionMatrix(),n.position.copy(i.position),n.quaternion.copy(i.quaternion),this._component.controls.camera=n}getDistance(){const t=this._component.threePersp,e=this._component.threeOrtho;return(e.top-e.bottom)/e.zoom/(2*Math.atan(t.fov*(Math.PI/180)/2))}async setPerspectiveCamera(){this._component.controls.mouseButtons.wheel=r.ACTION.DOLLY,this._component.controls.mouseButtons.middle=r.ACTION.DOLLY;const t=this._component.threePersp,e=this._component.threeOrtho;t.position.copy(e.position),t.quaternion.copy(e.quaternion),this._component.controls.mouseButtons.wheel=r.ACTION.DOLLY,this.matchOrthoDistanceEnabled?this._component.controls.distance=this.getDistance():this._component.controls.distance=this._previousDistance,await this._component.controls.zoomTo(1),t.updateProjectionMatrix(),this._component.controls.camera=t,this.camera=t,this.current="Perspective"}}class is extends ge{constructor(t){super(t),e(this,"projection"),e(this,"threeOrtho"),e(this,"threePersp"),e(this,"_userInputButtons",{}),e(this,"_frustumSize",50),e(this,"_navigationModes",new Map),e(this,"_mode",null),e(this,"previousSize",null),this.threePersp=this.three,this.threeOrtho=this.newOrthoCamera(),this.projection=new es(this),this.onAspectUpdated.add(()=>{this.setOrthoPerspCameraAspect()}),this.projection.onChanged.add(t=>{this.three=t,this.updateAspect()}),this.worlds.onItemSet.add(()=>{this._navigationModes.clear(),this._navigationModes.set("Orbit",new Jn(this)),this._navigationModes.set("FirstPerson",new Kn(this)),this._navigationModes.set("Plan",new ts(this)),this._mode=this._navigationModes.get("Orbit"),this.mode.set(!0,{preventTargetAdjustment:!0}),this.currentWorld&&this.currentWorld.renderer&&(this.previousSize=this.currentWorld.renderer.getSize().clone())}),this.worlds.onItemDeleted.add(()=>{this._navigationModes.clear()})}get mode(){if(!this._mode)throw new Error("Mode not found, camera not initialized");return this._mode}dispose(){super.dispose(),this.threeOrtho.removeFromParent()}set(t){if(null!==this.mode&&this.mode.id!==t){if(this.mode.set(!1),!this._navigationModes.has(t))throw new Error("The specified mode does not exist!");this._mode=this._navigationModes.get(t),this.mode.set(!0)}}async fit(t,e=1.5){if(!this.enabled)return;const i=Number.MAX_VALUE,n=Number.MIN_VALUE,s=new l.Vector3(i,i,i),r=new l.Vector3(n,n,n);for(const e of t){const t=(new l.Box3).setFromObject(e);t.min.x<s.x&&(s.x=t.min.x),t.min.y<s.y&&(s.y=t.min.y),t.min.z<s.z&&(s.z=t.min.z),t.max.x>r.x&&(r.x=t.max.x),t.max.y>r.y&&(r.y=t.max.y),t.max.z>r.z&&(r.z=t.max.z)}const o=new l.Box3(s,r),a=this.components.get(Zt);if(a.initialized)for(const[,t]of a.list){const e=t.box;e.min.x<s.x&&(s.x=e.min.x),e.min.y<s.y&&(s.y=e.min.y),e.min.z<s.z&&(s.z=e.min.z),e.max.x>r.x&&(r.x=e.max.x),e.max.y>r.y&&(r.y=e.max.y),e.max.z>r.z&&(r.z=e.max.z)}const c=new l.Vector3;o.getSize(c);const h=new l.Vector3;o.getCenter(h);const u=Math.max(c.x,c.y,c.z)*e,d=new l.Sphere(h,u);await this.controls.fitToSphere(d,!0)}setUserInput(t){t?this.enableUserInput():this.disableUserInput()}addCustomNavigationMode(t){this._navigationModes.set(t.id,t)}disableUserInput(){this._userInputButtons.left=this.controls.mouseButtons.left,this._userInputButtons.right=this.controls.mouseButtons.right,this._userInputButtons.middle=this.controls.mouseButtons.middle,this._userInputButtons.wheel=this.controls.mouseButtons.wheel,this.controls.mouseButtons.left=0,this.controls.mouseButtons.right=0,this.controls.mouseButtons.middle=0,this.controls.mouseButtons.wheel=0}enableUserInput(){0!==Object.keys(this._userInputButtons).length&&(this.controls.mouseButtons.left=this._userInputButtons.left,this.controls.mouseButtons.right=this._userInputButtons.right,this.controls.mouseButtons.middle=this._userInputButtons.middle,this.controls.mouseButtons.wheel=this._userInputButtons.wheel)}newOrthoCamera(){const t=window.innerWidth/window.innerHeight;return new l.OrthographicCamera(this._frustumSize*t/-2,this._frustumSize*t/2,this._frustumSize/2,this._frustumSize/-2,.1,1e3)}setOrthoPerspCameraAspect(){if(!this.currentWorld||!this.currentWorld.renderer)return;if(!this.previousSize)return;const t=this.currentWorld.renderer.getSize(),e=this.threeOrtho.top,i=this.threeOrtho.right,n=e*(t.y/this.previousSize.y),s=i*(t.x/this.previousSize.x);this.threeOrtho.left=-s,this.threeOrtho.right=s,this.threeOrtho.top=n,this.threeOrtho.bottom=-n,this.threeOrtho.updateProjectionMatrix(),this.previousSize.copy(t)}}var ns="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ss(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function rs(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var os={exports:{}};
9
2
  /*!
10
3
 
11
4
  JSZip v3.10.1 - A JavaScript class for generating and reading zip files
@@ -16,4 +9,4 @@ Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/js
16
9
 
17
10
  JSZip uses the library pako released under the MIT license :
18
11
  https://github.com/nodeca/pako/blob/main/LICENSE
19
- */const or=x(rr.exports=function t(e,i,s){function n(o,a){if(!i[o]){if(!e[o]){if(!a&&nr)return nr(o);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var h=i[o]={exports:{}};e[o][0].call(h.exports,function(t){return n(e[o][1][t]||t)},h,h.exports,t,e,i,s)}return i[o].exports}for(var r=nr,o=0;o<s.length;o++)n(s[o]);return n}({1:[function(t,e,i){var s=t("./utils"),n=t("./support"),r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.encode=function(t){for(var e,i,n,o,a,l,h,c=[],d=0,u=t.length,p=u,f="string"!==s.getTypeOf(t);d<t.length;)p=u-d,n=f?(e=t[d++],i=d<u?t[d++]:0,d<u?t[d++]:0):(e=t.charCodeAt(d++),i=d<u?t.charCodeAt(d++):0,d<u?t.charCodeAt(d++):0),o=e>>2,a=(3&e)<<4|i>>4,l=1<p?(15&i)<<2|n>>6:64,h=2<p?63&n:64,c.push(r.charAt(o)+r.charAt(a)+r.charAt(l)+r.charAt(h));return c.join("")},i.decode=function(t){var e,i,s,o,a,l,h=0,c=0,d="data:";if(t.substr(0,d.length)===d)throw new Error("Invalid base64 input, it looks like a data url.");var u,p=3*(t=t.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(t.charAt(t.length-1)===r.charAt(64)&&p--,t.charAt(t.length-2)===r.charAt(64)&&p--,p%1!=0)throw new Error("Invalid base64 input, bad content length.");for(u=n.uint8array?new Uint8Array(0|p):new Array(0|p);h<t.length;)e=r.indexOf(t.charAt(h++))<<2|(o=r.indexOf(t.charAt(h++)))>>4,i=(15&o)<<4|(a=r.indexOf(t.charAt(h++)))>>2,s=(3&a)<<6|(l=r.indexOf(t.charAt(h++))),u[c++]=e,64!==a&&(u[c++]=i),64!==l&&(u[c++]=s);return u}},{"./support":30,"./utils":32}],2:[function(t,e,i){var s=t("./external"),n=t("./stream/DataWorker"),r=t("./stream/Crc32Probe"),o=t("./stream/DataLengthProbe");function a(t,e,i,s,n){this.compressedSize=t,this.uncompressedSize=e,this.crc32=i,this.compression=s,this.compressedContent=n}a.prototype={getContentWorker:function(){var t=new n(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o("data_length")),e=this;return t.on("end",function(){if(this.streamInfo.data_length!==e.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),t},getCompressedWorker:function(){return new n(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},a.createWorkerFrom=function(t,e,i){return t.pipe(new r).pipe(new o("uncompressedSize")).pipe(e.compressWorker(i)).pipe(new o("compressedSize")).withStreamInfo("compression",e)},e.exports=a},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(t,e,i){var s=t("./stream/GenericWorker");i.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},i.DEFLATE=t("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(t,e,i){var s=t("./utils"),n=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var s=0;s<8;s++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e){return void 0!==t&&t.length?"string"!==s.getTypeOf(t)?function(t,e,i,s){var r=n,o=s+i;t^=-1;for(var a=s;a<o;a++)t=t>>>8^r[255&(t^e[a])];return-1^t}(0|e,t,t.length,0):function(t,e,i,s){var r=n,o=s+i;t^=-1;for(var a=s;a<o;a++)t=t>>>8^r[255&(t^e.charCodeAt(a))];return-1^t}(0|e,t,t.length,0):0}},{"./utils":32}],5:[function(t,e,i){i.base64=!1,i.binary=!1,i.dir=!1,i.createFolders=!0,i.date=null,i.compression=null,i.compressionOptions=null,i.comment=null,i.unixPermissions=null,i.dosPermissions=null},{}],6:[function(t,e,i){var s=null;s="undefined"!=typeof Promise?Promise:t("lie"),e.exports={Promise:s}},{lie:37}],7:[function(t,e,i){var s="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,n=t("pako"),r=t("./utils"),o=t("./stream/GenericWorker"),a=s?"uint8array":"array";function l(t,e){o.call(this,"FlateWorker/"+t),this._pako=null,this._pakoAction=t,this._pakoOptions=e,this.meta={}}i.magic="\b\0",r.inherits(l,o),l.prototype.processChunk=function(t){this.meta=t.meta,null===this._pako&&this._createPako(),this._pako.push(r.transformTo(a,t.data),!1)},l.prototype.flush=function(){o.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},l.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},l.prototype._createPako=function(){this._pako=new n[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta})}},i.compressWorker=function(t){return new l("Deflate",t)},i.uncompressWorker=function(){return new l("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(t,e,i){function s(t,e){var i,s="";for(i=0;i<e;i++)s+=String.fromCharCode(255&t),t>>>=8;return s}function n(t,e,i,n,o,c){var d,u,p=t.file,f=t.compression,m=c!==a.utf8encode,g=r.transformTo("string",c(p.name)),_=r.transformTo("string",a.utf8encode(p.name)),y=p.comment,w=r.transformTo("string",c(y)),v=r.transformTo("string",a.utf8encode(y)),b=_.length!==p.name.length,x=v.length!==y.length,T="",C="",E="",S=p.dir,A=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};e&&!i||(O.crc32=t.crc32,O.compressedSize=t.compressedSize,O.uncompressedSize=t.uncompressedSize);var P=0;e&&(P|=8),m||!b&&!x||(P|=2048);var I,M,D,k=0,z=0;S&&(k|=16),"UNIX"===o?(z=798,k|=(I=p.unixPermissions,M=S,D=I,I||(D=M?16893:33204),(65535&D)<<16)):(z=20,k|=function(t){return 63&(t||0)}(p.dosPermissions)),d=A.getUTCHours(),d<<=6,d|=A.getUTCMinutes(),d<<=5,d|=A.getUTCSeconds()/2,u=A.getUTCFullYear()-1980,u<<=4,u|=A.getUTCMonth()+1,u<<=5,u|=A.getUTCDate(),b&&(C=s(1,1)+s(l(g),4)+_,T+="up"+s(C.length,2)+C),x&&(E=s(1,1)+s(l(w),4)+v,T+="uc"+s(E.length,2)+E);var B="";return B+="\n\0",B+=s(P,2),B+=f.magic,B+=s(d,2),B+=s(u,2),B+=s(O.crc32,4),B+=s(O.compressedSize,4),B+=s(O.uncompressedSize,4),B+=s(g.length,2),B+=s(T.length,2),{fileRecord:h.LOCAL_FILE_HEADER+B+g+T,dirRecord:h.CENTRAL_FILE_HEADER+s(z,2)+B+s(w.length,2)+"\0\0\0\0"+s(k,4)+s(n,4)+g+T+w}}var r=t("../utils"),o=t("../stream/GenericWorker"),a=t("../utf8"),l=t("../crc32"),h=t("../signature");function c(t,e,i,s){o.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=e,this.zipPlatform=i,this.encodeFileName=s,this.streamFiles=t,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}r.inherits(c,o),c.prototype.push=function(t){var e=t.meta.percent||0,i=this.entriesCount,s=this._sources.length;this.accumulate?this.contentBuffer.push(t):(this.bytesWritten+=t.data.length,o.prototype.push.call(this,{data:t.data,meta:{currentFile:this.currentFile,percent:i?(e+100*(i-s-1))/i:100}}))},c.prototype.openedSource=function(t){this.currentSourceOffset=this.bytesWritten,this.currentFile=t.file.name;var e=this.streamFiles&&!t.file.dir;if(e){var i=n(t,e,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:i.fileRecord,meta:{percent:0}})}else this.accumulate=!0},c.prototype.closedSource=function(t){this.accumulate=!1;var e,i=this.streamFiles&&!t.file.dir,r=n(t,i,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),i)this.push({data:(e=t,h.DATA_DESCRIPTOR+s(e.crc32,4)+s(e.compressedSize,4)+s(e.uncompressedSize,4)),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},c.prototype.flush=function(){for(var t=this.bytesWritten,e=0;e<this.dirRecords.length;e++)this.push({data:this.dirRecords[e],meta:{percent:100}});var i,n,o,a,l,c,d=this.bytesWritten-t,u=(i=this.dirRecords.length,n=d,o=t,a=this.zipComment,l=this.encodeFileName,c=r.transformTo("string",l(a)),h.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(i,2)+s(i,2)+s(n,4)+s(o,4)+s(c.length,2)+c);this.push({data:u,meta:{percent:100}})},c.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},c.prototype.registerPrevious=function(t){this._sources.push(t);var e=this;return t.on("data",function(t){e.processChunk(t)}),t.on("end",function(){e.closedSource(e.previous.streamInfo),e._sources.length?e.prepareNextSource():e.end()}),t.on("error",function(t){e.error(t)}),this},c.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},c.prototype.error=function(t){var e=this._sources;if(!o.prototype.error.call(this,t))return!1;for(var i=0;i<e.length;i++)try{e[i].error(t)}catch(t){}return!0},c.prototype.lock=function(){o.prototype.lock.call(this);for(var t=this._sources,e=0;e<t.length;e++)t[e].lock()},e.exports=c},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(t,e,i){var s=t("../compressions"),n=t("./ZipFileWorker");i.generateWorker=function(t,e,i){var r=new n(e.streamFiles,i,e.platform,e.encodeFileName),o=0;try{t.forEach(function(t,i){o++;var n=function(t,e){var i=t||e,n=s[i];if(!n)throw new Error(i+" is not a valid compression method !");return n}(i.options.compression,e.compression),a=i.options.compressionOptions||e.compressionOptions||{},l=i.dir,h=i.date;i._compressWorker(n,a).withStreamInfo("file",{name:t,dir:l,date:h,comment:i.comment||"",unixPermissions:i.unixPermissions,dosPermissions:i.dosPermissions}).pipe(r)}),r.entriesCount=o}catch(t){r.error(t)}return r}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(t,e,i){function s(){if(!(this instanceof s))return new s;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var t=new s;for(var e in this)"function"!=typeof this[e]&&(t[e]=this[e]);return t}}(s.prototype=t("./object")).loadAsync=t("./load"),s.support=t("./support"),s.defaults=t("./defaults"),s.version="3.10.1",s.loadAsync=function(t,e){return(new s).loadAsync(t,e)},s.external=t("./external"),e.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(t,e,i){var s=t("./utils"),n=t("./external"),r=t("./utf8"),o=t("./zipEntries"),a=t("./stream/Crc32Probe"),l=t("./nodejsUtils");function h(t){return new n.Promise(function(e,i){var s=t.decompressed.getContentWorker().pipe(new a);s.on("error",function(t){i(t)}).on("end",function(){s.streamInfo.crc32!==t.decompressed.crc32?i(new Error("Corrupted zip : CRC32 mismatch")):e()}).resume()})}e.exports=function(t,e){var i=this;return e=s.extend(e||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:r.utf8decode}),l.isNode&&l.isStream(t)?n.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",t,!0,e.optimizedBinaryString,e.base64).then(function(t){var i=new o(e);return i.load(t),i}).then(function(t){var i=[n.Promise.resolve(t)],s=t.files;if(e.checkCRC32)for(var r=0;r<s.length;r++)i.push(h(s[r]));return n.Promise.all(i)}).then(function(t){for(var n=t.shift(),r=n.files,o=0;o<r.length;o++){var a=r[o],l=a.fileNameStr,h=s.resolve(a.fileNameStr);i.file(h,a.decompressed,{binary:!0,optimizedBinaryString:!0,date:a.date,dir:a.dir,comment:a.fileCommentStr.length?a.fileCommentStr:null,unixPermissions:a.unixPermissions,dosPermissions:a.dosPermissions,createFolders:e.createFolders}),a.dir||(i.file(h).unsafeOriginalName=l)}return n.zipComment.length&&(i.comment=n.zipComment),i})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(t,e,i){var s=t("../utils"),n=t("../stream/GenericWorker");function r(t,e){n.call(this,"Nodejs stream input adapter for "+t),this._upstreamEnded=!1,this._bindStream(e)}s.inherits(r,n),r.prototype._bindStream=function(t){var e=this;(this._stream=t).pause(),t.on("data",function(t){e.push({data:t,meta:{percent:0}})}).on("error",function(t){e.isPaused?this.generatedError=t:e.error(t)}).on("end",function(){e.isPaused?e._upstreamEnded=!0:e.end()})},r.prototype.pause=function(){return!!n.prototype.pause.call(this)&&(this._stream.pause(),!0)},r.prototype.resume=function(){return!!n.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},e.exports=r},{"../stream/GenericWorker":28,"../utils":32}],13:[function(t,e,i){var s=t("readable-stream").Readable;function n(t,e,i){s.call(this,e),this._helper=t;var n=this;t.on("data",function(t,e){n.push(t)||n._helper.pause(),i&&i(e)}).on("error",function(t){n.emit("error",t)}).on("end",function(){n.push(null)})}t("../utils").inherits(n,s),n.prototype._read=function(){this._helper.resume()},e.exports=n},{"../utils":32,"readable-stream":16}],14:[function(t,e,i){e.exports={isNode:"undefined"!=typeof Buffer,newBufferFrom:function(t,e){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(t,e);if("number"==typeof t)throw new Error('The "data" argument must not be a number');return new Buffer(t,e)},allocBuffer:function(t){if(Buffer.alloc)return Buffer.alloc(t);var e=new Buffer(t);return e.fill(0),e},isBuffer:function(t){return Buffer.isBuffer(t)},isStream:function(t){return t&&"function"==typeof t.on&&"function"==typeof t.pause&&"function"==typeof t.resume}}},{}],15:[function(t,e,i){function s(t,e,i){var s,n=r.getTypeOf(e),a=r.extend(i||{},l);a.date=a.date||new Date,null!==a.compression&&(a.compression=a.compression.toUpperCase()),"string"==typeof a.unixPermissions&&(a.unixPermissions=parseInt(a.unixPermissions,8)),a.unixPermissions&&16384&a.unixPermissions&&(a.dir=!0),a.dosPermissions&&16&a.dosPermissions&&(a.dir=!0),a.dir&&(t=m(t)),a.createFolders&&(s=f(t))&&g.call(this,s,!0);var d="string"===n&&!1===a.binary&&!1===a.base64;i&&void 0!==i.binary||(a.binary=!d),(e instanceof h&&0===e.uncompressedSize||a.dir||!e||0===e.length)&&(a.base64=!1,a.binary=!0,e="",a.compression="STORE",n="string");var _=null;_=e instanceof h||e instanceof o?e:u.isNode&&u.isStream(e)?new p(t,e):r.prepareContent(t,e,a.binary,a.optimizedBinaryString,a.base64);var y=new c(t,_,a);this.files[t]=y}var n=t("./utf8"),r=t("./utils"),o=t("./stream/GenericWorker"),a=t("./stream/StreamHelper"),l=t("./defaults"),h=t("./compressedObject"),c=t("./zipObject"),d=t("./generate"),u=t("./nodejsUtils"),p=t("./nodejs/NodejsStreamInputAdapter"),f=function(t){"/"===t.slice(-1)&&(t=t.substring(0,t.length-1));var e=t.lastIndexOf("/");return 0<e?t.substring(0,e):""},m=function(t){return"/"!==t.slice(-1)&&(t+="/"),t},g=function(t,e){return e=void 0!==e?e:l.createFolders,t=m(t),this.files[t]||s.call(this,t,null,{dir:!0,createFolders:e}),this.files[t]};function _(t){return"[object RegExp]"===Object.prototype.toString.call(t)}var y={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(t){var e,i,s;for(e in this.files)s=this.files[e],(i=e.slice(this.root.length,e.length))&&e.slice(0,this.root.length)===this.root&&t(i,s)},filter:function(t){var e=[];return this.forEach(function(i,s){t(i,s)&&e.push(s)}),e},file:function(t,e,i){if(1!==arguments.length)return t=this.root+t,s.call(this,t,e,i),this;if(_(t)){var n=t;return this.filter(function(t,e){return!e.dir&&n.test(t)})}var r=this.files[this.root+t];return r&&!r.dir?r:null},folder:function(t){if(!t)return this;if(_(t))return this.filter(function(e,i){return i.dir&&t.test(e)});var e=this.root+t,i=g.call(this,e),s=this.clone();return s.root=i.name,s},remove:function(t){t=this.root+t;var e=this.files[t];if(e||("/"!==t.slice(-1)&&(t+="/"),e=this.files[t]),e&&!e.dir)delete this.files[t];else for(var i=this.filter(function(e,i){return i.name.slice(0,t.length)===t}),s=0;s<i.length;s++)delete this.files[i[s].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(t){var e,i={};try{if((i=r.extend(t||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:n.utf8encode})).type=i.type.toLowerCase(),i.compression=i.compression.toUpperCase(),"binarystring"===i.type&&(i.type="string"),!i.type)throw new Error("No output type specified.");r.checkSupport(i.type),"darwin"!==i.platform&&"freebsd"!==i.platform&&"linux"!==i.platform&&"sunos"!==i.platform||(i.platform="UNIX"),"win32"===i.platform&&(i.platform="DOS");var s=i.comment||this.comment||"";e=d.generateWorker(this,i,s)}catch(t){(e=new o("error")).error(t)}return new a(e,i.type||"string",i.mimeType)},generateAsync:function(t,e){return this.generateInternalStream(t).accumulate(e)},generateNodeStream:function(t,e){return(t=t||{}).type||(t.type="nodebuffer"),this.generateInternalStream(t).toNodejsStream(e)}};e.exports=y},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(t,e,i){e.exports=t("stream")},{stream:void 0}],17:[function(t,e,i){var s=t("./DataReader");function n(t){s.call(this,t);for(var e=0;e<this.data.length;e++)t[e]=255&t[e]}t("../utils").inherits(n,s),n.prototype.byteAt=function(t){return this.data[this.zero+t]},n.prototype.lastIndexOfSignature=function(t){for(var e=t.charCodeAt(0),i=t.charCodeAt(1),s=t.charCodeAt(2),n=t.charCodeAt(3),r=this.length-4;0<=r;--r)if(this.data[r]===e&&this.data[r+1]===i&&this.data[r+2]===s&&this.data[r+3]===n)return r-this.zero;return-1},n.prototype.readAndCheckSignature=function(t){var e=t.charCodeAt(0),i=t.charCodeAt(1),s=t.charCodeAt(2),n=t.charCodeAt(3),r=this.readData(4);return e===r[0]&&i===r[1]&&s===r[2]&&n===r[3]},n.prototype.readData=function(t){if(this.checkOffset(t),0===t)return[];var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=n},{"../utils":32,"./DataReader":18}],18:[function(t,e,i){var s=t("../utils");function n(t){this.data=t,this.length=t.length,this.index=0,this.zero=0}n.prototype={checkOffset:function(t){this.checkIndex(this.index+t)},checkIndex:function(t){if(this.length<this.zero+t||t<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+t+"). Corrupted zip ?")},setIndex:function(t){this.checkIndex(t),this.index=t},skip:function(t){this.setIndex(this.index+t)},byteAt:function(){},readInt:function(t){var e,i=0;for(this.checkOffset(t),e=this.index+t-1;e>=this.index;e--)i=(i<<8)+this.byteAt(e);return this.index+=t,i},readString:function(t){return s.transformTo("string",this.readData(t))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var t=this.readInt(4);return new Date(Date.UTC(1980+(t>>25&127),(t>>21&15)-1,t>>16&31,t>>11&31,t>>5&63,(31&t)<<1))}},e.exports=n},{"../utils":32}],19:[function(t,e,i){var s=t("./Uint8ArrayReader");function n(t){s.call(this,t)}t("../utils").inherits(n,s),n.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=n},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(t,e,i){var s=t("./DataReader");function n(t){s.call(this,t)}t("../utils").inherits(n,s),n.prototype.byteAt=function(t){return this.data.charCodeAt(this.zero+t)},n.prototype.lastIndexOfSignature=function(t){return this.data.lastIndexOf(t)-this.zero},n.prototype.readAndCheckSignature=function(t){return t===this.readData(4)},n.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=n},{"../utils":32,"./DataReader":18}],21:[function(t,e,i){var s=t("./ArrayReader");function n(t){s.call(this,t)}t("../utils").inherits(n,s),n.prototype.readData=function(t){if(this.checkOffset(t),0===t)return new Uint8Array(0);var e=this.data.subarray(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=n},{"../utils":32,"./ArrayReader":17}],22:[function(t,e,i){var s=t("../utils"),n=t("../support"),r=t("./ArrayReader"),o=t("./StringReader"),a=t("./NodeBufferReader"),l=t("./Uint8ArrayReader");e.exports=function(t){var e=s.getTypeOf(t);return s.checkSupport(e),"string"!==e||n.uint8array?"nodebuffer"===e?new a(t):n.uint8array?new l(s.transformTo("uint8array",t)):new r(s.transformTo("array",t)):new o(t)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(t,e,i){i.LOCAL_FILE_HEADER="PK",i.CENTRAL_FILE_HEADER="PK",i.CENTRAL_DIRECTORY_END="PK",i.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",i.ZIP64_CENTRAL_DIRECTORY_END="PK",i.DATA_DESCRIPTOR="PK\b"},{}],24:[function(t,e,i){var s=t("./GenericWorker"),n=t("../utils");function r(t){s.call(this,"ConvertWorker to "+t),this.destType=t}n.inherits(r,s),r.prototype.processChunk=function(t){this.push({data:n.transformTo(this.destType,t.data),meta:t.meta})},e.exports=r},{"../utils":32,"./GenericWorker":28}],25:[function(t,e,i){var s=t("./GenericWorker"),n=t("../crc32");function r(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}t("../utils").inherits(r,s),r.prototype.processChunk=function(t){this.streamInfo.crc32=n(t.data,this.streamInfo.crc32||0),this.push(t)},e.exports=r},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(t,e,i){var s=t("../utils"),n=t("./GenericWorker");function r(t){n.call(this,"DataLengthProbe for "+t),this.propName=t,this.withStreamInfo(t,0)}s.inherits(r,n),r.prototype.processChunk=function(t){if(t){var e=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=e+t.data.length}n.prototype.processChunk.call(this,t)},e.exports=r},{"../utils":32,"./GenericWorker":28}],27:[function(t,e,i){var s=t("../utils"),n=t("./GenericWorker");function r(t){n.call(this,"DataWorker");var e=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,t.then(function(t){e.dataIsReady=!0,e.data=t,e.max=t&&t.length||0,e.type=s.getTypeOf(t),e.isPaused||e._tickAndRepeat()},function(t){e.error(t)})}s.inherits(r,n),r.prototype.cleanUp=function(){n.prototype.cleanUp.call(this),this.data=null},r.prototype.resume=function(){return!!n.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},r.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},r.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var t=null,e=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":t=this.data.substring(this.index,e);break;case"uint8array":t=this.data.subarray(this.index,e);break;case"array":case"nodebuffer":t=this.data.slice(this.index,e)}return this.index=e,this.push({data:t,meta:{percent:this.max?this.index/this.max*100:0}})},e.exports=r},{"../utils":32,"./GenericWorker":28}],28:[function(t,e,i){function s(t){this.name=t||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}s.prototype={push:function(t){this.emit("data",t)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(t){this.emit("error",t)}return!0},error:function(t){return!this.isFinished&&(this.isPaused?this.generatedError=t:(this.isFinished=!0,this.emit("error",t),this.previous&&this.previous.error(t),this.cleanUp()),!0)},on:function(t,e){return this._listeners[t].push(e),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(t,e){if(this._listeners[t])for(var i=0;i<this._listeners[t].length;i++)this._listeners[t][i].call(this,e)},pipe:function(t){return t.registerPrevious(this)},registerPrevious:function(t){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=t.streamInfo,this.mergeStreamInfo(),this.previous=t;var e=this;return t.on("data",function(t){e.processChunk(t)}),t.on("end",function(){e.end()}),t.on("error",function(t){e.error(t)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var t=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),t=!0),this.previous&&this.previous.resume(),!t},flush:function(){},processChunk:function(t){this.push(t)},withStreamInfo:function(t,e){return this.extraStreamInfo[t]=e,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var t in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,t)&&(this.streamInfo[t]=this.extraStreamInfo[t])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var t="Worker "+this.name;return this.previous?this.previous+" -> "+t:t}},e.exports=s},{}],29:[function(t,e,i){var s=t("../utils"),n=t("./ConvertWorker"),r=t("./GenericWorker"),o=t("../base64"),a=t("../support"),l=t("../external"),h=null;if(a.nodestream)try{h=t("../nodejs/NodejsStreamOutputAdapter")}catch(t){}function c(t,e){return new l.Promise(function(i,n){var r=[],a=t._internalType,l=t._outputType,h=t._mimeType;t.on("data",function(t,i){r.push(t),e&&e(i)}).on("error",function(t){r=[],n(t)}).on("end",function(){try{var t=function(t,e,i){switch(t){case"blob":return s.newBlob(s.transformTo("arraybuffer",e),i);case"base64":return o.encode(e);default:return s.transformTo(t,e)}}(l,function(t,e){var i,s=0,n=null,r=0;for(i=0;i<e.length;i++)r+=e[i].length;switch(t){case"string":return e.join("");case"array":return Array.prototype.concat.apply([],e);case"uint8array":for(n=new Uint8Array(r),i=0;i<e.length;i++)n.set(e[i],s),s+=e[i].length;return n;case"nodebuffer":return Buffer.concat(e);default:throw new Error("concat : unsupported type '"+t+"'")}}(a,r),h);i(t)}catch(t){n(t)}r=[]}).resume()})}function d(t,e,i){var o=e;switch(e){case"blob":case"arraybuffer":o="uint8array";break;case"base64":o="string"}try{this._internalType=o,this._outputType=e,this._mimeType=i,s.checkSupport(o),this._worker=t.pipe(new n(o)),t.lock()}catch(t){this._worker=new r("error"),this._worker.error(t)}}d.prototype={accumulate:function(t){return c(this,t)},on:function(t,e){var i=this;return"data"===t?this._worker.on(t,function(t){e.call(i,t.data,t.meta)}):this._worker.on(t,function(){s.delay(e,arguments,i)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(t){if(s.checkSupport("nodestream"),"nodebuffer"!==this._outputType)throw new Error(this._outputType+" is not supported by this method");return new h(this,{objectMode:"nodebuffer"!==this._outputType},t)}},e.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(t,e,i){if(i.base64=!0,i.array=!0,i.string=!0,i.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,i.nodebuffer="undefined"!=typeof Buffer,i.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)i.blob=!1;else{var s=new ArrayBuffer(0);try{i.blob=0===new Blob([s],{type:"application/zip"}).size}catch(t){try{var n=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);n.append(s),i.blob=0===n.getBlob("application/zip").size}catch(t){i.blob=!1}}}try{i.nodestream=!!t("readable-stream").Readable}catch(t){i.nodestream=!1}},{"readable-stream":16}],31:[function(t,e,i){for(var s=t("./utils"),n=t("./support"),r=t("./nodejsUtils"),o=t("./stream/GenericWorker"),a=new Array(256),l=0;l<256;l++)a[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function h(){o.call(this,"utf-8 decode"),this.leftOver=null}function c(){o.call(this,"utf-8 encode")}a[254]=a[254]=1,i.utf8encode=function(t){return n.nodebuffer?r.newBufferFrom(t,"utf-8"):function(t){var e,i,s,r,o,a=t.length,l=0;for(r=0;r<a;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(s=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(s-56320),r++),l+=i<128?1:i<2048?2:i<65536?3:4;for(e=n.uint8array?new Uint8Array(l):new Array(l),r=o=0;o<l;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(s=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(s-56320),r++),i<128?e[o++]=i:(i<2048?e[o++]=192|i>>>6:(i<65536?e[o++]=224|i>>>12:(e[o++]=240|i>>>18,e[o++]=128|i>>>12&63),e[o++]=128|i>>>6&63),e[o++]=128|63&i);return e}(t)},i.utf8decode=function(t){return n.nodebuffer?s.transformTo("nodebuffer",t).toString("utf-8"):function(t){var e,i,n,r,o=t.length,l=new Array(2*o);for(e=i=0;e<o;)if((n=t[e++])<128)l[i++]=n;else if(4<(r=a[n]))l[i++]=65533,e+=r-1;else{for(n&=2===r?31:3===r?15:7;1<r&&e<o;)n=n<<6|63&t[e++],r--;1<r?l[i++]=65533:n<65536?l[i++]=n:(n-=65536,l[i++]=55296|n>>10&1023,l[i++]=56320|1023&n)}return l.length!==i&&(l.subarray?l=l.subarray(0,i):l.length=i),s.applyFromCharCode(l)}(t=s.transformTo(n.uint8array?"uint8array":"array",t))},s.inherits(h,o),h.prototype.processChunk=function(t){var e=s.transformTo(n.uint8array?"uint8array":"array",t.data);if(this.leftOver&&this.leftOver.length){if(n.uint8array){var r=e;(e=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),e.set(r,this.leftOver.length)}else e=this.leftOver.concat(e);this.leftOver=null}var o=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+a[t[i]]>e?i:e}(e),l=e;o!==e.length&&(n.uint8array?(l=e.subarray(0,o),this.leftOver=e.subarray(o,e.length)):(l=e.slice(0,o),this.leftOver=e.slice(o,e.length))),this.push({data:i.utf8decode(l),meta:t.meta})},h.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:i.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},i.Utf8DecodeWorker=h,s.inherits(c,o),c.prototype.processChunk=function(t){this.push({data:i.utf8encode(t.data),meta:t.meta})},i.Utf8EncodeWorker=c},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(t,e,i){var s=t("./support"),n=t("./base64"),r=t("./nodejsUtils"),o=t("./external");function a(t){return t}function l(t,e){for(var i=0;i<t.length;++i)e[i]=255&t.charCodeAt(i);return e}t("setimmediate"),i.newBlob=function(t,e){i.checkSupport("blob");try{return new Blob([t],{type:e})}catch(i){try{var s=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return s.append(t),s.getBlob(e)}catch(t){throw new Error("Bug : can't construct the Blob.")}}};var h={stringifyByChunk:function(t,e,i){var s=[],n=0,r=t.length;if(r<=i)return String.fromCharCode.apply(null,t);for(;n<r;)"array"===e||"nodebuffer"===e?s.push(String.fromCharCode.apply(null,t.slice(n,Math.min(n+i,r)))):s.push(String.fromCharCode.apply(null,t.subarray(n,Math.min(n+i,r)))),n+=i;return s.join("")},stringifyByChar:function(t){for(var e="",i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return e},applyCanBeUsed:{uint8array:function(){try{return s.uint8array&&1===String.fromCharCode.apply(null,new Uint8Array(1)).length}catch(t){return!1}}(),nodebuffer:function(){try{return s.nodebuffer&&1===String.fromCharCode.apply(null,r.allocBuffer(1)).length}catch(t){return!1}}()}};function c(t){var e=65536,s=i.getTypeOf(t),n=!0;if("uint8array"===s?n=h.applyCanBeUsed.uint8array:"nodebuffer"===s&&(n=h.applyCanBeUsed.nodebuffer),n)for(;1<e;)try{return h.stringifyByChunk(t,s,e)}catch(t){e=Math.floor(e/2)}return h.stringifyByChar(t)}function d(t,e){for(var i=0;i<t.length;i++)e[i]=t[i];return e}i.applyFromCharCode=c;var u={};u.string={string:a,array:function(t){return l(t,new Array(t.length))},arraybuffer:function(t){return u.string.uint8array(t).buffer},uint8array:function(t){return l(t,new Uint8Array(t.length))},nodebuffer:function(t){return l(t,r.allocBuffer(t.length))}},u.array={string:c,array:a,arraybuffer:function(t){return new Uint8Array(t).buffer},uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return r.newBufferFrom(t)}},u.arraybuffer={string:function(t){return c(new Uint8Array(t))},array:function(t){return d(new Uint8Array(t),new Array(t.byteLength))},arraybuffer:a,uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return r.newBufferFrom(new Uint8Array(t))}},u.uint8array={string:c,array:function(t){return d(t,new Array(t.length))},arraybuffer:function(t){return t.buffer},uint8array:a,nodebuffer:function(t){return r.newBufferFrom(t)}},u.nodebuffer={string:c,array:function(t){return d(t,new Array(t.length))},arraybuffer:function(t){return u.nodebuffer.uint8array(t).buffer},uint8array:function(t){return d(t,new Uint8Array(t.length))},nodebuffer:a},i.transformTo=function(t,e){if(e=e||"",!t)return e;i.checkSupport(t);var s=i.getTypeOf(e);return u[s][t](e)},i.resolve=function(t){for(var e=t.split("/"),i=[],s=0;s<e.length;s++){var n=e[s];"."===n||""===n&&0!==s&&s!==e.length-1||(".."===n?i.pop():i.push(n))}return i.join("/")},i.getTypeOf=function(t){return"string"==typeof t?"string":"[object Array]"===Object.prototype.toString.call(t)?"array":s.nodebuffer&&r.isBuffer(t)?"nodebuffer":s.uint8array&&t instanceof Uint8Array?"uint8array":s.arraybuffer&&t instanceof ArrayBuffer?"arraybuffer":void 0},i.checkSupport=function(t){if(!s[t.toLowerCase()])throw new Error(t+" is not supported by this platform")},i.MAX_VALUE_16BITS=65535,i.MAX_VALUE_32BITS=-1,i.pretty=function(t){var e,i,s="";for(i=0;i<(t||"").length;i++)s+="\\x"+((e=t.charCodeAt(i))<16?"0":"")+e.toString(16).toUpperCase();return s},i.delay=function(t,e,i){setImmediate(function(){t.apply(i||null,e||[])})},i.inherits=function(t,e){function i(){}i.prototype=e.prototype,t.prototype=new i},i.extend=function(){var t,e,i={};for(t=0;t<arguments.length;t++)for(e in arguments[t])Object.prototype.hasOwnProperty.call(arguments[t],e)&&void 0===i[e]&&(i[e]=arguments[t][e]);return i},i.prepareContent=function(t,e,r,a,h){return o.Promise.resolve(e).then(function(t){return s.blob&&(t instanceof Blob||-1!==["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(t)))&&"undefined"!=typeof FileReader?new o.Promise(function(e,i){var s=new FileReader;s.onload=function(t){e(t.target.result)},s.onerror=function(t){i(t.target.error)},s.readAsArrayBuffer(t)}):t}).then(function(e){var c,d=i.getTypeOf(e);return d?("arraybuffer"===d?e=i.transformTo("uint8array",e):"string"===d&&(h?e=n.decode(e):r&&!0!==a&&(e=l(c=e,s.uint8array?new Uint8Array(c.length):new Array(c.length)))),e):o.Promise.reject(new Error("Can't read the data of '"+t+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(t,e,i){var s=t("./reader/readerFor"),n=t("./utils"),r=t("./signature"),o=t("./zipEntry"),a=t("./support");function l(t){this.files=[],this.loadOptions=t}l.prototype={checkSignature:function(t){if(!this.reader.readAndCheckSignature(t)){this.reader.index-=4;var e=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+n.pretty(e)+", expected "+n.pretty(t)+")")}},isSignature:function(t,e){var i=this.reader.index;this.reader.setIndex(t);var s=this.reader.readString(4)===e;return this.reader.setIndex(i),s},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var t=this.reader.readData(this.zipCommentLength),e=a.uint8array?"uint8array":"array",i=n.transformTo(e,t);this.zipComment=this.loadOptions.decodeFileName(i)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var t,e,i,s=this.zip64EndOfCentralSize-44;0<s;)t=this.reader.readInt(2),e=this.reader.readInt(4),i=this.reader.readData(e),this.zip64ExtensibleData[t]={id:t,length:e,value:i}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var t,e;for(t=0;t<this.files.length;t++)e=this.files[t],this.reader.setIndex(e.localHeaderOffset),this.checkSignature(r.LOCAL_FILE_HEADER),e.readLocalPart(this.reader),e.handleUTF8(),e.processAttributes()},readCentralDir:function(){var t;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(r.CENTRAL_FILE_HEADER);)(t=new o({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(t);if(this.centralDirRecords!==this.files.length&&0!==this.centralDirRecords&&0===this.files.length)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var t=this.reader.lastIndexOfSignature(r.CENTRAL_DIRECTORY_END);if(t<0)throw this.isSignature(0,r.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(t);var e=t;if(this.checkSignature(r.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===n.MAX_VALUE_16BITS||this.diskWithCentralDirStart===n.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===n.MAX_VALUE_16BITS||this.centralDirRecords===n.MAX_VALUE_16BITS||this.centralDirSize===n.MAX_VALUE_32BITS||this.centralDirOffset===n.MAX_VALUE_32BITS){if(this.zip64=!0,(t=this.reader.lastIndexOfSignature(r.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(t),this.checkSignature(r.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,r.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(r.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(r.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var i=this.centralDirOffset+this.centralDirSize;this.zip64&&(i+=20,i+=12+this.zip64EndOfCentralSize);var s=e-i;if(0<s)this.isSignature(e,r.CENTRAL_FILE_HEADER)||(this.reader.zero=s);else if(s<0)throw new Error("Corrupted zip: missing "+Math.abs(s)+" bytes.")},prepareReader:function(t){this.reader=s(t)},load:function(t){this.prepareReader(t),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},e.exports=l},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(t,e,i){var s=t("./reader/readerFor"),n=t("./utils"),r=t("./compressedObject"),o=t("./crc32"),a=t("./utf8"),l=t("./compressions"),h=t("./support");function c(t,e){this.options=t,this.loadOptions=e}c.prototype={isEncrypted:function(){return!(1&~this.bitFlag)},useUTF8:function(){return!(2048&~this.bitFlag)},readLocalPart:function(t){var e,i;if(t.skip(22),this.fileNameLength=t.readInt(2),i=t.readInt(2),this.fileName=t.readData(this.fileNameLength),t.skip(i),-1===this.compressedSize||-1===this.uncompressedSize)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(null===(e=function(t){for(var e in l)if(Object.prototype.hasOwnProperty.call(l,e)&&l[e].magic===t)return l[e];return null}(this.compressionMethod)))throw new Error("Corrupted zip : compression "+n.pretty(this.compressionMethod)+" unknown (inner file : "+n.transformTo("string",this.fileName)+")");this.decompressed=new r(this.compressedSize,this.uncompressedSize,this.crc32,e,t.readData(this.compressedSize))},readCentralPart:function(t){this.versionMadeBy=t.readInt(2),t.skip(2),this.bitFlag=t.readInt(2),this.compressionMethod=t.readString(2),this.date=t.readDate(),this.crc32=t.readInt(4),this.compressedSize=t.readInt(4),this.uncompressedSize=t.readInt(4);var e=t.readInt(2);if(this.extraFieldsLength=t.readInt(2),this.fileCommentLength=t.readInt(2),this.diskNumberStart=t.readInt(2),this.internalFileAttributes=t.readInt(2),this.externalFileAttributes=t.readInt(4),this.localHeaderOffset=t.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");t.skip(e),this.readExtraFields(t),this.parseZIP64ExtraField(t),this.fileComment=t.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var t=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),0==t&&(this.dosPermissions=63&this.externalFileAttributes),3==t&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var t=s(this.extraFields[1].value);this.uncompressedSize===n.MAX_VALUE_32BITS&&(this.uncompressedSize=t.readInt(8)),this.compressedSize===n.MAX_VALUE_32BITS&&(this.compressedSize=t.readInt(8)),this.localHeaderOffset===n.MAX_VALUE_32BITS&&(this.localHeaderOffset=t.readInt(8)),this.diskNumberStart===n.MAX_VALUE_32BITS&&(this.diskNumberStart=t.readInt(4))}},readExtraFields:function(t){var e,i,s,n=t.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});t.index+4<n;)e=t.readInt(2),i=t.readInt(2),s=t.readData(i),this.extraFields[e]={id:e,length:i,value:s};t.setIndex(n)},handleUTF8:function(){var t=h.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=a.utf8decode(this.fileName),this.fileCommentStr=a.utf8decode(this.fileComment);else{var e=this.findExtraFieldUnicodePath();if(null!==e)this.fileNameStr=e;else{var i=n.transformTo(t,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(i)}var s=this.findExtraFieldUnicodeComment();if(null!==s)this.fileCommentStr=s;else{var r=n.transformTo(t,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(r)}}},findExtraFieldUnicodePath:function(){var t=this.extraFields[28789];if(t){var e=s(t.value);return 1!==e.readInt(1)||o(this.fileName)!==e.readInt(4)?null:a.utf8decode(e.readData(t.length-5))}return null},findExtraFieldUnicodeComment:function(){var t=this.extraFields[25461];if(t){var e=s(t.value);return 1!==e.readInt(1)||o(this.fileComment)!==e.readInt(4)?null:a.utf8decode(e.readData(t.length-5))}return null}},e.exports=c},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(t,e,i){function s(t,e,i){this.name=t,this.dir=i.dir,this.date=i.date,this.comment=i.comment,this.unixPermissions=i.unixPermissions,this.dosPermissions=i.dosPermissions,this._data=e,this._dataBinary=i.binary,this.options={compression:i.compression,compressionOptions:i.compressionOptions}}var n=t("./stream/StreamHelper"),r=t("./stream/DataWorker"),o=t("./utf8"),a=t("./compressedObject"),l=t("./stream/GenericWorker");s.prototype={internalStream:function(t){var e=null,i="string";try{if(!t)throw new Error("No output type specified.");var s="string"===(i=t.toLowerCase())||"text"===i;"binarystring"!==i&&"text"!==i||(i="string"),e=this._decompressWorker();var r=!this._dataBinary;r&&!s&&(e=e.pipe(new o.Utf8EncodeWorker)),!r&&s&&(e=e.pipe(new o.Utf8DecodeWorker))}catch(t){(e=new l("error")).error(t)}return new n(e,i,"")},async:function(t,e){return this.internalStream(t).accumulate(e)},nodeStream:function(t,e){return this.internalStream(t||"nodebuffer").toNodejsStream(e)},_compressWorker:function(t,e){if(this._data instanceof a&&this._data.compression.magic===t.magic)return this._data.getCompressedWorker();var i=this._decompressWorker();return this._dataBinary||(i=i.pipe(new o.Utf8EncodeWorker)),a.createWorkerFrom(i,t,e)},_decompressWorker:function(){return this._data instanceof a?this._data.getContentWorker():this._data instanceof l?this._data:new r(this._data)}};for(var h=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],c=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<h.length;d++)s.prototype[h[d]]=c;e.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(t,e,i){(function(t){var i,s,n=t.MutationObserver||t.WebKitMutationObserver;if(n){var r=0,o=new n(c),a=t.document.createTextNode("");o.observe(a,{characterData:!0}),i=function(){a.data=r=++r%2}}else if(t.setImmediate||void 0===t.MessageChannel)i="document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){c(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(c,0)};else{var l=new t.MessageChannel;l.port1.onmessage=c,i=function(){l.port2.postMessage(0)}}var h=[];function c(){var t,e;s=!0;for(var i=h.length;i;){for(e=h,h=[],t=-1;++t<i;)e[t]();i=h.length}s=!1}e.exports=function(t){1!==h.push(t)||s||i()}}).call(this,void 0!==b?b:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],37:[function(t,e,i){var s=t("immediate");function n(){}var r={},o=["REJECTED"],a=["FULFILLED"],l=["PENDING"];function h(t){if("function"!=typeof t)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,t!==n&&p(this,t)}function c(t,e,i){this.promise=t,"function"==typeof e&&(this.onFulfilled=e,this.callFulfilled=this.otherCallFulfilled),"function"==typeof i&&(this.onRejected=i,this.callRejected=this.otherCallRejected)}function d(t,e,i){s(function(){var s;try{s=e(i)}catch(e){return r.reject(t,e)}s===t?r.reject(t,new TypeError("Cannot resolve promise with itself")):r.resolve(t,s)})}function u(t){var e=t&&t.then;if(t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof e)return function(){e.apply(t,arguments)}}function p(t,e){var i=!1;function s(e){i||(i=!0,r.reject(t,e))}function n(e){i||(i=!0,r.resolve(t,e))}var o=f(function(){e(n,s)});"error"===o.status&&s(o.value)}function f(t,e){var i={};try{i.value=t(e),i.status="success"}catch(t){i.status="error",i.value=t}return i}(e.exports=h).prototype.finally=function(t){if("function"!=typeof t)return this;var e=this.constructor;return this.then(function(i){return e.resolve(t()).then(function(){return i})},function(i){return e.resolve(t()).then(function(){throw i})})},h.prototype.catch=function(t){return this.then(null,t)},h.prototype.then=function(t,e){if("function"!=typeof t&&this.state===a||"function"!=typeof e&&this.state===o)return this;var i=new this.constructor(n);return this.state!==l?d(i,this.state===a?t:e,this.outcome):this.queue.push(new c(i,t,e)),i},c.prototype.callFulfilled=function(t){r.resolve(this.promise,t)},c.prototype.otherCallFulfilled=function(t){d(this.promise,this.onFulfilled,t)},c.prototype.callRejected=function(t){r.reject(this.promise,t)},c.prototype.otherCallRejected=function(t){d(this.promise,this.onRejected,t)},r.resolve=function(t,e){var i=f(u,e);if("error"===i.status)return r.reject(t,i.value);var s=i.value;if(s)p(t,s);else{t.state=a,t.outcome=e;for(var n=-1,o=t.queue.length;++n<o;)t.queue[n].callFulfilled(e)}return t},r.reject=function(t,e){t.state=o,t.outcome=e;for(var i=-1,s=t.queue.length;++i<s;)t.queue[i].callRejected(e);return t},h.resolve=function(t){return t instanceof this?t:r.resolve(new this(n),t)},h.reject=function(t){var e=new this(n);return r.reject(e,t)},h.all=function(t){var e=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var i=t.length,s=!1;if(!i)return this.resolve([]);for(var o=new Array(i),a=0,l=-1,h=new this(n);++l<i;)c(t[l],l);return h;function c(t,n){e.resolve(t).then(function(t){o[n]=t,++a!==i||s||(s=!0,r.resolve(h,o))},function(t){s||(s=!0,r.reject(h,t))})}},h.race=function(t){var e=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var i=t.length,s=!1;if(!i)return this.resolve([]);for(var o,a=-1,l=new this(n);++a<i;)o=t[a],e.resolve(o).then(function(t){s||(s=!0,r.resolve(l,t))},function(t){s||(s=!0,r.reject(l,t))});return l}},{immediate:36}],38:[function(t,e,i){var s={};(0,t("./lib/utils/common").assign)(s,t("./lib/deflate"),t("./lib/inflate"),t("./lib/zlib/constants")),e.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(t,e,i){var s=t("./zlib/deflate"),n=t("./utils/common"),r=t("./utils/strings"),o=t("./zlib/messages"),a=t("./zlib/zstream"),l=Object.prototype.toString,h=0,c=-1,d=0,u=8;function p(t){if(!(this instanceof p))return new p(t);this.options=n.assign({level:c,method:u,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},t||{});var e=this.options;e.raw&&0<e.windowBits?e.windowBits=-e.windowBits:e.gzip&&0<e.windowBits&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new a,this.strm.avail_out=0;var i=s.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==h)throw new Error(o[i]);if(e.header&&s.deflateSetHeader(this.strm,e.header),e.dictionary){var f;if(f="string"==typeof e.dictionary?r.string2buf(e.dictionary):"[object ArrayBuffer]"===l.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,(i=s.deflateSetDictionary(this.strm,f))!==h)throw new Error(o[i]);this._dict_set=!0}}function f(t,e){var i=new p(e);if(i.push(t,!0),i.err)throw i.msg||o[i.err];return i.result}p.prototype.push=function(t,e){var i,o,a=this.strm,c=this.options.chunkSize;if(this.ended)return!1;o=e===~~e?e:!0===e?4:0,"string"==typeof t?a.input=r.string2buf(t):"[object ArrayBuffer]"===l.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;do{if(0===a.avail_out&&(a.output=new n.Buf8(c),a.next_out=0,a.avail_out=c),1!==(i=s.deflate(a,o))&&i!==h)return this.onEnd(i),!(this.ended=!0);0!==a.avail_out&&(0!==a.avail_in||4!==o&&2!==o)||("string"===this.options.to?this.onData(r.buf2binstring(n.shrinkBuf(a.output,a.next_out))):this.onData(n.shrinkBuf(a.output,a.next_out)))}while((0<a.avail_in||0===a.avail_out)&&1!==i);return 4===o?(i=s.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===h):2!==o||(this.onEnd(h),!(a.avail_out=0))},p.prototype.onData=function(t){this.chunks.push(t)},p.prototype.onEnd=function(t){t===h&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=n.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},i.Deflate=p,i.deflate=f,i.deflateRaw=function(t,e){return(e=e||{}).raw=!0,f(t,e)},i.gzip=function(t,e){return(e=e||{}).gzip=!0,f(t,e)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(t,e,i){var s=t("./zlib/inflate"),n=t("./utils/common"),r=t("./utils/strings"),o=t("./zlib/constants"),a=t("./zlib/messages"),l=t("./zlib/zstream"),h=t("./zlib/gzheader"),c=Object.prototype.toString;function d(t){if(!(this instanceof d))return new d(t);this.options=n.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&0<=e.windowBits&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(0<=e.windowBits&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),15<e.windowBits&&e.windowBits<48&&!(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var i=s.inflateInit2(this.strm,e.windowBits);if(i!==o.Z_OK)throw new Error(a[i]);this.header=new h,s.inflateGetHeader(this.strm,this.header)}function u(t,e){var i=new d(e);if(i.push(t,!0),i.err)throw i.msg||a[i.err];return i.result}d.prototype.push=function(t,e){var i,a,l,h,d,u,p=this.strm,f=this.options.chunkSize,m=this.options.dictionary,g=!1;if(this.ended)return!1;a=e===~~e?e:!0===e?o.Z_FINISH:o.Z_NO_FLUSH,"string"==typeof t?p.input=r.binstring2buf(t):"[object ArrayBuffer]"===c.call(t)?p.input=new Uint8Array(t):p.input=t,p.next_in=0,p.avail_in=p.input.length;do{if(0===p.avail_out&&(p.output=new n.Buf8(f),p.next_out=0,p.avail_out=f),(i=s.inflate(p,o.Z_NO_FLUSH))===o.Z_NEED_DICT&&m&&(u="string"==typeof m?r.string2buf(m):"[object ArrayBuffer]"===c.call(m)?new Uint8Array(m):m,i=s.inflateSetDictionary(this.strm,u)),i===o.Z_BUF_ERROR&&!0===g&&(i=o.Z_OK,g=!1),i!==o.Z_STREAM_END&&i!==o.Z_OK)return this.onEnd(i),!(this.ended=!0);p.next_out&&(0!==p.avail_out&&i!==o.Z_STREAM_END&&(0!==p.avail_in||a!==o.Z_FINISH&&a!==o.Z_SYNC_FLUSH)||("string"===this.options.to?(l=r.utf8border(p.output,p.next_out),h=p.next_out-l,d=r.buf2string(p.output,l),p.next_out=h,p.avail_out=f-h,h&&n.arraySet(p.output,p.output,l,h,0),this.onData(d)):this.onData(n.shrinkBuf(p.output,p.next_out)))),0===p.avail_in&&0===p.avail_out&&(g=!0)}while((0<p.avail_in||0===p.avail_out)&&i!==o.Z_STREAM_END);return i===o.Z_STREAM_END&&(a=o.Z_FINISH),a===o.Z_FINISH?(i=s.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===o.Z_OK):a!==o.Z_SYNC_FLUSH||(this.onEnd(o.Z_OK),!(p.avail_out=0))},d.prototype.onData=function(t){this.chunks.push(t)},d.prototype.onEnd=function(t){t===o.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=n.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},i.Inflate=d,i.inflate=u,i.inflateRaw=function(t,e){return(e=e||{}).raw=!0,u(t,e)},i.ungzip=u},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(t,e,i){var s="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;i.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var s in i)i.hasOwnProperty(s)&&(t[s]=i[s])}}return t},i.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,i,s,n){if(e.subarray&&t.subarray)t.set(e.subarray(i,i+s),n);else for(var r=0;r<s;r++)t[n+r]=e[i+r]},flattenChunks:function(t){var e,i,s,n,r,o;for(e=s=0,i=t.length;e<i;e++)s+=t[e].length;for(o=new Uint8Array(s),e=n=0,i=t.length;e<i;e++)r=t[e],o.set(r,n),n+=r.length;return o}},r={arraySet:function(t,e,i,s,n){for(var r=0;r<s;r++)t[n+r]=e[i+r]},flattenChunks:function(t){return[].concat.apply([],t)}};i.setTyped=function(t){t?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,n)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,r))},i.setTyped(s)},{}],42:[function(t,e,i){var s=t("./common"),n=!0,r=!0;try{String.fromCharCode.apply(null,[0])}catch(t){n=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){r=!1}for(var o=new s.Buf8(256),a=0;a<256;a++)o[a]=252<=a?6:248<=a?5:240<=a?4:224<=a?3:192<=a?2:1;function l(t,e){if(e<65537&&(t.subarray&&r||!t.subarray&&n))return String.fromCharCode.apply(null,s.shrinkBuf(t,e));for(var i="",o=0;o<e;o++)i+=String.fromCharCode(t[o]);return i}o[254]=o[254]=1,i.string2buf=function(t){var e,i,n,r,o,a=t.length,l=0;for(r=0;r<a;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(n=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(n-56320),r++),l+=i<128?1:i<2048?2:i<65536?3:4;for(e=new s.Buf8(l),r=o=0;o<l;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(n=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(n-56320),r++),i<128?e[o++]=i:(i<2048?e[o++]=192|i>>>6:(i<65536?e[o++]=224|i>>>12:(e[o++]=240|i>>>18,e[o++]=128|i>>>12&63),e[o++]=128|i>>>6&63),e[o++]=128|63&i);return e},i.buf2binstring=function(t){return l(t,t.length)},i.binstring2buf=function(t){for(var e=new s.Buf8(t.length),i=0,n=e.length;i<n;i++)e[i]=t.charCodeAt(i);return e},i.buf2string=function(t,e){var i,s,n,r,a=e||t.length,h=new Array(2*a);for(i=s=0;i<a;)if((n=t[i++])<128)h[s++]=n;else if(4<(r=o[n]))h[s++]=65533,i+=r-1;else{for(n&=2===r?31:3===r?15:7;1<r&&i<a;)n=n<<6|63&t[i++],r--;1<r?h[s++]=65533:n<65536?h[s++]=n:(n-=65536,h[s++]=55296|n>>10&1023,h[s++]=56320|1023&n)}return l(h,s)},i.utf8border=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+o[t[i]]>e?i:e}},{"./common":41}],43:[function(t,e,i){e.exports=function(t,e,i,s){for(var n=65535&t,r=t>>>16&65535,o=0;0!==i;){for(i-=o=2e3<i?2e3:i;r=r+(n=n+e[s++]|0)|0,--o;);n%=65521,r%=65521}return n|r<<16}},{}],44:[function(t,e,i){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(t,e,i){var s=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var s=0;s<8;s++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e,i,n){var r=s,o=n+i;t^=-1;for(var a=n;a<o;a++)t=t>>>8^r[255&(t^e[a])];return-1^t}},{}],46:[function(t,e,i){var s,n=t("../utils/common"),r=t("./trees"),o=t("./adler32"),a=t("./crc32"),l=t("./messages"),h=0,c=4,d=0,u=-2,p=-1,f=4,m=2,g=8,_=9,y=286,w=30,v=19,b=2*y+1,x=15,T=3,C=258,E=C+T+1,S=42,A=113,O=1,P=2,I=3,M=4;function D(t,e){return t.msg=l[e],e}function k(t){return(t<<1)-(4<t?9:0)}function z(t){for(var e=t.length;0<=--e;)t[e]=0}function B(t){var e=t.state,i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(n.arraySet(t.output,e.pending_buf,e.pending_out,i,t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))}function N(t,e){r._tr_flush_block(t,0<=t.block_start?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,B(t.strm)}function U(t,e){t.pending_buf[t.pending++]=e}function L(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function R(t,e){var i,s,n=t.max_chain_length,r=t.strstart,o=t.prev_length,a=t.nice_match,l=t.strstart>t.w_size-E?t.strstart-(t.w_size-E):0,h=t.window,c=t.w_mask,d=t.prev,u=t.strstart+C,p=h[r+o-1],f=h[r+o];t.prev_length>=t.good_match&&(n>>=2),a>t.lookahead&&(a=t.lookahead);do{if(h[(i=e)+o]===f&&h[i+o-1]===p&&h[i]===h[r]&&h[++i]===h[r+1]){r+=2,i++;do{}while(h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&h[++r]===h[++i]&&r<u);if(s=C-(u-r),r=u-C,o<s){if(t.match_start=e,a<=(o=s))break;p=h[r+o-1],f=h[r+o]}}}while((e=d[e&c])>l&&0!=--n);return o<=t.lookahead?o:t.lookahead}function F(t){var e,i,s,r,l,h,c,d,u,p,f=t.w_size;do{if(r=t.window_size-t.lookahead-t.strstart,t.strstart>=f+(f-E)){for(n.arraySet(t.window,t.window,f,f,0),t.match_start-=f,t.strstart-=f,t.block_start-=f,e=i=t.hash_size;s=t.head[--e],t.head[e]=f<=s?s-f:0,--i;);for(e=i=f;s=t.prev[--e],t.prev[e]=f<=s?s-f:0,--i;);r+=f}if(0===t.strm.avail_in)break;if(h=t.strm,c=t.window,d=t.strstart+t.lookahead,p=void 0,(u=r)<(p=h.avail_in)&&(p=u),i=0===p?0:(h.avail_in-=p,n.arraySet(c,h.input,h.next_in,p,d),1===h.state.wrap?h.adler=o(h.adler,c,p,d):2===h.state.wrap&&(h.adler=a(h.adler,c,p,d)),h.next_in+=p,h.total_in+=p,p),t.lookahead+=i,t.lookahead+t.insert>=T)for(l=t.strstart-t.insert,t.ins_h=t.window[l],t.ins_h=(t.ins_h<<t.hash_shift^t.window[l+1])&t.hash_mask;t.insert&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[l+T-1])&t.hash_mask,t.prev[l&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=l,l++,t.insert--,!(t.lookahead+t.insert<T)););}while(t.lookahead<E&&0!==t.strm.avail_in)}function V(t,e){for(var i,s;;){if(t.lookahead<E){if(F(t),t.lookahead<E&&e===h)return O;if(0===t.lookahead)break}if(i=0,t.lookahead>=T&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+T-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-E&&(t.match_length=R(t,i)),t.match_length>=T)if(s=r._tr_tally(t,t.strstart-t.match_start,t.match_length-T),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=T){for(t.match_length--;t.strstart++,t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+T-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart,0!=--t.match_length;);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+1])&t.hash_mask;else s=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(s&&(N(t,!1),0===t.strm.avail_out))return O}return t.insert=t.strstart<T-1?t.strstart:T-1,e===c?(N(t,!0),0===t.strm.avail_out?I:M):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?O:P}function j(t,e){for(var i,s,n;;){if(t.lookahead<E){if(F(t),t.lookahead<E&&e===h)return O;if(0===t.lookahead)break}if(i=0,t.lookahead>=T&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+T-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=T-1,0!==i&&t.prev_length<t.max_lazy_match&&t.strstart-i<=t.w_size-E&&(t.match_length=R(t,i),t.match_length<=5&&(1===t.strategy||t.match_length===T&&4096<t.strstart-t.match_start)&&(t.match_length=T-1)),t.prev_length>=T&&t.match_length<=t.prev_length){for(n=t.strstart+t.lookahead-T,s=r._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-T),t.lookahead-=t.prev_length-1,t.prev_length-=2;++t.strstart<=n&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+T-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!=--t.prev_length;);if(t.match_available=0,t.match_length=T-1,t.strstart++,s&&(N(t,!1),0===t.strm.avail_out))return O}else if(t.match_available){if((s=r._tr_tally(t,0,t.window[t.strstart-1]))&&N(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return O}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(s=r._tr_tally(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<T-1?t.strstart:T-1,e===c?(N(t,!0),0===t.strm.avail_out?I:M):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?O:P}function H(t,e,i,s,n){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=s,this.func=n}function Z(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=g,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new n.Buf16(2*b),this.dyn_dtree=new n.Buf16(2*(2*w+1)),this.bl_tree=new n.Buf16(2*(2*v+1)),z(this.dyn_ltree),z(this.dyn_dtree),z(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new n.Buf16(x+1),this.heap=new n.Buf16(2*y+1),z(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new n.Buf16(2*y+1),z(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function $(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=m,(e=t.state).pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?S:A,t.adler=2===e.wrap?0:1,e.last_flush=h,r._tr_init(e),d):D(t,u)}function W(t){var e,i=$(t);return i===d&&((e=t.state).window_size=2*e.w_size,z(e.head),e.max_lazy_match=s[e.level].max_lazy,e.good_match=s[e.level].good_length,e.nice_match=s[e.level].nice_length,e.max_chain_length=s[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=T-1,e.match_available=0,e.ins_h=0),i}function Y(t,e,i,s,r,o){if(!t)return u;var a=1;if(e===p&&(e=6),s<0?(a=0,s=-s):15<s&&(a=2,s-=16),r<1||_<r||i!==g||s<8||15<s||e<0||9<e||o<0||f<o)return D(t,u);8===s&&(s=9);var l=new Z;return(t.state=l).strm=t,l.wrap=a,l.gzhead=null,l.w_bits=s,l.w_size=1<<l.w_bits,l.w_mask=l.w_size-1,l.hash_bits=r+7,l.hash_size=1<<l.hash_bits,l.hash_mask=l.hash_size-1,l.hash_shift=~~((l.hash_bits+T-1)/T),l.window=new n.Buf8(2*l.w_size),l.head=new n.Buf16(l.hash_size),l.prev=new n.Buf16(l.w_size),l.lit_bufsize=1<<r+6,l.pending_buf_size=4*l.lit_bufsize,l.pending_buf=new n.Buf8(l.pending_buf_size),l.d_buf=1*l.lit_bufsize,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=o,l.method=i,W(t)}s=[new H(0,0,0,0,function(t,e){var i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(F(t),0===t.lookahead&&e===h)return O;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var s=t.block_start+i;if((0===t.strstart||t.strstart>=s)&&(t.lookahead=t.strstart-s,t.strstart=s,N(t,!1),0===t.strm.avail_out))return O;if(t.strstart-t.block_start>=t.w_size-E&&(N(t,!1),0===t.strm.avail_out))return O}return t.insert=0,e===c?(N(t,!0),0===t.strm.avail_out?I:M):(t.strstart>t.block_start&&(N(t,!1),t.strm.avail_out),O)}),new H(4,4,8,4,V),new H(4,5,16,8,V),new H(4,6,32,32,V),new H(4,4,16,16,j),new H(8,16,32,32,j),new H(8,16,128,128,j),new H(8,32,128,256,j),new H(32,128,258,1024,j),new H(32,258,258,4096,j)],i.deflateInit=function(t,e){return Y(t,e,g,15,8,0)},i.deflateInit2=Y,i.deflateReset=W,i.deflateResetKeep=$,i.deflateSetHeader=function(t,e){return t&&t.state?2!==t.state.wrap?u:(t.state.gzhead=e,d):u},i.deflate=function(t,e){var i,n,o,l;if(!t||!t.state||5<e||e<0)return t?D(t,u):u;if(n=t.state,!t.output||!t.input&&0!==t.avail_in||666===n.status&&e!==c)return D(t,0===t.avail_out?-5:u);if(n.strm=t,i=n.last_flush,n.last_flush=e,n.status===S)if(2===n.wrap)t.adler=0,U(n,31),U(n,139),U(n,8),n.gzhead?(U(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),U(n,255&n.gzhead.time),U(n,n.gzhead.time>>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=a(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=A);else{var p=g+(n.w_bits-8<<4)<<8;p|=(2<=n.strategy||n.level<2?0:n.level<6?1:6===n.level?2:3)<<6,0!==n.strstart&&(p|=32),p+=31-p%31,n.status=A,L(n,p),0!==n.strstart&&(L(n,t.adler>>>16),L(n,65535&t.adler)),t.adler=1}if(69===n.status)if(n.gzhead.extra){for(o=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),B(t),o=n.pending,n.pending!==n.pending_buf_size));)U(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){o=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),B(t),o=n.pending,n.pending===n.pending_buf_size)){l=1;break}l=n.gzindex<n.gzhead.name.length?255&n.gzhead.name.charCodeAt(n.gzindex++):0,U(n,l)}while(0!==l);n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),0===l&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){o=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),B(t),o=n.pending,n.pending===n.pending_buf_size)){l=1;break}l=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,U(n,l)}while(0!==l);n.gzhead.hcrc&&n.pending>o&&(t.adler=a(t.adler,n.pending_buf,n.pending-o,o)),0===l&&(n.status=103)}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&B(t),n.pending+2<=n.pending_buf_size&&(U(n,255&t.adler),U(n,t.adler>>8&255),t.adler=0,n.status=A)):n.status=A),0!==n.pending){if(B(t),0===t.avail_out)return n.last_flush=-1,d}else if(0===t.avail_in&&k(e)<=k(i)&&e!==c)return D(t,-5);if(666===n.status&&0!==t.avail_in)return D(t,-5);if(0!==t.avail_in||0!==n.lookahead||e!==h&&666!==n.status){var f=2===n.strategy?function(t,e){for(var i;;){if(0===t.lookahead&&(F(t),0===t.lookahead)){if(e===h)return O;break}if(t.match_length=0,i=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(N(t,!1),0===t.strm.avail_out))return O}return t.insert=0,e===c?(N(t,!0),0===t.strm.avail_out?I:M):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?O:P}(n,e):3===n.strategy?function(t,e){for(var i,s,n,o,a=t.window;;){if(t.lookahead<=C){if(F(t),t.lookahead<=C&&e===h)return O;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=T&&0<t.strstart&&(s=a[n=t.strstart-1])===a[++n]&&s===a[++n]&&s===a[++n]){o=t.strstart+C;do{}while(s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&n<o);t.match_length=C-(o-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=T?(i=r._tr_tally(t,1,t.match_length-T),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(N(t,!1),0===t.strm.avail_out))return O}return t.insert=0,e===c?(N(t,!0),0===t.strm.avail_out?I:M):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?O:P}(n,e):s[n.level].func(n,e);if(f!==I&&f!==M||(n.status=666),f===O||f===I)return 0===t.avail_out&&(n.last_flush=-1),d;if(f===P&&(1===e?r._tr_align(n):5!==e&&(r._tr_stored_block(n,0,0,!1),3===e&&(z(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),B(t),0===t.avail_out))return n.last_flush=-1,d}return e!==c?d:n.wrap<=0?1:(2===n.wrap?(U(n,255&t.adler),U(n,t.adler>>8&255),U(n,t.adler>>16&255),U(n,t.adler>>24&255),U(n,255&t.total_in),U(n,t.total_in>>8&255),U(n,t.total_in>>16&255),U(n,t.total_in>>24&255)):(L(n,t.adler>>>16),L(n,65535&t.adler)),B(t),0<n.wrap&&(n.wrap=-n.wrap),0!==n.pending?d:1)},i.deflateEnd=function(t){var e;return t&&t.state?(e=t.state.status)!==S&&69!==e&&73!==e&&91!==e&&103!==e&&e!==A&&666!==e?D(t,u):(t.state=null,e===A?D(t,-3):d):u},i.deflateSetDictionary=function(t,e){var i,s,r,a,l,h,c,p,f=e.length;if(!t||!t.state)return u;if(2===(a=(i=t.state).wrap)||1===a&&i.status!==S||i.lookahead)return u;for(1===a&&(t.adler=o(t.adler,e,f,0)),i.wrap=0,f>=i.w_size&&(0===a&&(z(i.head),i.strstart=0,i.block_start=0,i.insert=0),p=new n.Buf8(i.w_size),n.arraySet(p,e,f-i.w_size,i.w_size,0),e=p,f=i.w_size),l=t.avail_in,h=t.next_in,c=t.input,t.avail_in=f,t.next_in=0,t.input=e,F(i);i.lookahead>=T;){for(s=i.strstart,r=i.lookahead-(T-1);i.ins_h=(i.ins_h<<i.hash_shift^i.window[s+T-1])&i.hash_mask,i.prev[s&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=s,s++,--r;);i.strstart=s,i.lookahead=T-1,F(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=T-1,i.match_available=0,t.next_in=h,t.input=c,t.avail_in=l,i.wrap=a,d},i.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(t,e,i){e.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(t,e,i){e.exports=function(t,e){var i,s,n,r,o,a,l,h,c,d,u,p,f,m,g,_,y,w,v,b,x,T,C,E,S;i=t.state,s=t.next_in,E=t.input,n=s+(t.avail_in-5),r=t.next_out,S=t.output,o=r-(e-t.avail_out),a=r+(t.avail_out-257),l=i.dmax,h=i.wsize,c=i.whave,d=i.wnext,u=i.window,p=i.hold,f=i.bits,m=i.lencode,g=i.distcode,_=(1<<i.lenbits)-1,y=(1<<i.distbits)-1;t:do{f<15&&(p+=E[s++]<<f,f+=8,p+=E[s++]<<f,f+=8),w=m[p&_];e:for(;;){if(p>>>=v=w>>>24,f-=v,0==(v=w>>>16&255))S[r++]=65535&w;else{if(!(16&v)){if(!(64&v)){w=m[(65535&w)+(p&(1<<v)-1)];continue e}if(32&v){i.mode=12;break t}t.msg="invalid literal/length code",i.mode=30;break t}b=65535&w,(v&=15)&&(f<v&&(p+=E[s++]<<f,f+=8),b+=p&(1<<v)-1,p>>>=v,f-=v),f<15&&(p+=E[s++]<<f,f+=8,p+=E[s++]<<f,f+=8),w=g[p&y];i:for(;;){if(p>>>=v=w>>>24,f-=v,!(16&(v=w>>>16&255))){if(!(64&v)){w=g[(65535&w)+(p&(1<<v)-1)];continue i}t.msg="invalid distance code",i.mode=30;break t}if(x=65535&w,f<(v&=15)&&(p+=E[s++]<<f,(f+=8)<v&&(p+=E[s++]<<f,f+=8)),l<(x+=p&(1<<v)-1)){t.msg="invalid distance too far back",i.mode=30;break t}if(p>>>=v,f-=v,(v=r-o)<x){if(c<(v=x-v)&&i.sane){t.msg="invalid distance too far back",i.mode=30;break t}if(C=u,(T=0)===d){if(T+=h-v,v<b){for(b-=v;S[r++]=u[T++],--v;);T=r-x,C=S}}else if(d<v){if(T+=h+d-v,(v-=d)<b){for(b-=v;S[r++]=u[T++],--v;);if(T=0,d<b){for(b-=v=d;S[r++]=u[T++],--v;);T=r-x,C=S}}}else if(T+=d-v,v<b){for(b-=v;S[r++]=u[T++],--v;);T=r-x,C=S}for(;2<b;)S[r++]=C[T++],S[r++]=C[T++],S[r++]=C[T++],b-=3;b&&(S[r++]=C[T++],1<b&&(S[r++]=C[T++]))}else{for(T=r-x;S[r++]=S[T++],S[r++]=S[T++],S[r++]=S[T++],2<(b-=3););b&&(S[r++]=S[T++],1<b&&(S[r++]=S[T++]))}break}}break}}while(s<n&&r<a);s-=b=f>>3,p&=(1<<(f-=b<<3))-1,t.next_in=s,t.next_out=r,t.avail_in=s<n?n-s+5:5-(s-n),t.avail_out=r<a?a-r+257:257-(r-a),i.hold=p,i.bits=f}},{}],49:[function(t,e,i){var s=t("../utils/common"),n=t("./adler32"),r=t("./crc32"),o=t("./inffast"),a=t("./inftrees"),l=1,h=2,c=0,d=-2,u=1,p=852,f=592;function m(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function g(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=u,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new s.Buf32(p),e.distcode=e.distdyn=new s.Buf32(f),e.sane=1,e.back=-1,c):d}function y(t){var e;return t&&t.state?((e=t.state).wsize=0,e.whave=0,e.wnext=0,_(t)):d}function w(t,e){var i,s;return t&&t.state?(s=t.state,e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||15<e)?d:(null!==s.window&&s.wbits!==e&&(s.window=null),s.wrap=i,s.wbits=e,y(t))):d}function v(t,e){var i,s;return t?(s=new g,(t.state=s).window=null,(i=w(t,e))!==c&&(t.state=null),i):d}var b,x,T=!0;function C(t){if(T){var e;for(b=new s.Buf32(512),x=new s.Buf32(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(a(l,t.lens,0,288,b,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;a(h,t.lens,0,32,x,0,t.work,{bits:5}),T=!1}t.lencode=b,t.lenbits=9,t.distcode=x,t.distbits=5}function E(t,e,i,n){var r,o=t.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new s.Buf8(o.wsize)),n>=o.wsize?(s.arraySet(o.window,e,i-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(n<(r=o.wsize-o.wnext)&&(r=n),s.arraySet(o.window,e,i-n,r,o.wnext),(n-=r)?(s.arraySet(o.window,e,i-n,n,0),o.wnext=n,o.whave=o.wsize):(o.wnext+=r,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=r))),0}i.inflateReset=y,i.inflateReset2=w,i.inflateResetKeep=_,i.inflateInit=function(t){return v(t,15)},i.inflateInit2=v,i.inflate=function(t,e){var i,p,f,g,_,y,w,v,b,x,T,S,A,O,P,I,M,D,k,z,B,N,U,L,R=0,F=new s.Buf8(4),V=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return d;12===(i=t.state).mode&&(i.mode=13),_=t.next_out,f=t.output,w=t.avail_out,g=t.next_in,p=t.input,y=t.avail_in,v=i.hold,b=i.bits,x=y,T=w,N=c;t:for(;;)switch(i.mode){case u:if(0===i.wrap){i.mode=13;break}for(;b<16;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(2&i.wrap&&35615===v){F[i.check=0]=255&v,F[1]=v>>>8&255,i.check=r(i.check,F,2,0),b=v=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&v)<<8)+(v>>8))%31){t.msg="incorrect header check",i.mode=30;break}if(8!=(15&v)){t.msg="unknown compression method",i.mode=30;break}if(b-=4,B=8+(15&(v>>>=4)),0===i.wbits)i.wbits=B;else if(B>i.wbits){t.msg="invalid window size",i.mode=30;break}i.dmax=1<<B,t.adler=i.check=1,i.mode=512&v?10:12,b=v=0;break;case 2:for(;b<16;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(i.flags=v,8!=(255&i.flags)){t.msg="unknown compression method",i.mode=30;break}if(57344&i.flags){t.msg="unknown header flags set",i.mode=30;break}i.head&&(i.head.text=v>>8&1),512&i.flags&&(F[0]=255&v,F[1]=v>>>8&255,i.check=r(i.check,F,2,0)),b=v=0,i.mode=3;case 3:for(;b<32;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.head&&(i.head.time=v),512&i.flags&&(F[0]=255&v,F[1]=v>>>8&255,F[2]=v>>>16&255,F[3]=v>>>24&255,i.check=r(i.check,F,4,0)),b=v=0,i.mode=4;case 4:for(;b<16;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.head&&(i.head.xflags=255&v,i.head.os=v>>8),512&i.flags&&(F[0]=255&v,F[1]=v>>>8&255,i.check=r(i.check,F,2,0)),b=v=0,i.mode=5;case 5:if(1024&i.flags){for(;b<16;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.length=v,i.head&&(i.head.extra_len=v),512&i.flags&&(F[0]=255&v,F[1]=v>>>8&255,i.check=r(i.check,F,2,0)),b=v=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(y<(S=i.length)&&(S=y),S&&(i.head&&(B=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),s.arraySet(i.head.extra,p,g,S,B)),512&i.flags&&(i.check=r(i.check,p,S,g)),y-=S,g+=S,i.length-=S),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===y)break t;for(S=0;B=p[g+S++],i.head&&B&&i.length<65536&&(i.head.name+=String.fromCharCode(B)),B&&S<y;);if(512&i.flags&&(i.check=r(i.check,p,S,g)),y-=S,g+=S,B)break t}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===y)break t;for(S=0;B=p[g+S++],i.head&&B&&i.length<65536&&(i.head.comment+=String.fromCharCode(B)),B&&S<y;);if(512&i.flags&&(i.check=r(i.check,p,S,g)),y-=S,g+=S,B)break t}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;b<16;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(v!==(65535&i.check)){t.msg="header crc mismatch",i.mode=30;break}b=v=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=12;break;case 10:for(;b<32;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}t.adler=i.check=m(v),b=v=0,i.mode=11;case 11:if(0===i.havedict)return t.next_out=_,t.avail_out=w,t.next_in=g,t.avail_in=y,i.hold=v,i.bits=b,2;t.adler=i.check=1,i.mode=12;case 12:if(5===e||6===e)break t;case 13:if(i.last){v>>>=7&b,b-=7&b,i.mode=27;break}for(;b<3;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}switch(i.last=1&v,b-=1,3&(v>>>=1)){case 0:i.mode=14;break;case 1:if(C(i),i.mode=20,6!==e)break;v>>>=2,b-=2;break t;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=30}v>>>=2,b-=2;break;case 14:for(v>>>=7&b,b-=7&b;b<32;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if((65535&v)!=(v>>>16^65535)){t.msg="invalid stored block lengths",i.mode=30;break}if(i.length=65535&v,b=v=0,i.mode=15,6===e)break t;case 15:i.mode=16;case 16:if(S=i.length){if(y<S&&(S=y),w<S&&(S=w),0===S)break t;s.arraySet(f,p,g,S,_),y-=S,g+=S,w-=S,_+=S,i.length-=S;break}i.mode=12;break;case 17:for(;b<14;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(i.nlen=257+(31&v),v>>>=5,b-=5,i.ndist=1+(31&v),v>>>=5,b-=5,i.ncode=4+(15&v),v>>>=4,b-=4,286<i.nlen||30<i.ndist){t.msg="too many length or distance symbols",i.mode=30;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;b<3;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.lens[V[i.have++]]=7&v,v>>>=3,b-=3}for(;i.have<19;)i.lens[V[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},N=a(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,N){t.msg="invalid code lengths set",i.mode=30;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;I=(R=i.lencode[v&(1<<i.lenbits)-1])>>>16&255,M=65535&R,!((P=R>>>24)<=b);){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(M<16)v>>>=P,b-=P,i.lens[i.have++]=M;else{if(16===M){for(L=P+2;b<L;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(v>>>=P,b-=P,0===i.have){t.msg="invalid bit length repeat",i.mode=30;break}B=i.lens[i.have-1],S=3+(3&v),v>>>=2,b-=2}else if(17===M){for(L=P+3;b<L;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}b-=P,B=0,S=3+(7&(v>>>=P)),v>>>=3,b-=3}else{for(L=P+7;b<L;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}b-=P,B=0,S=11+(127&(v>>>=P)),v>>>=7,b-=7}if(i.have+S>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=30;break}for(;S--;)i.lens[i.have++]=B}}if(30===i.mode)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=30;break}if(i.lenbits=9,U={bits:i.lenbits},N=a(l,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,N){t.msg="invalid literal/lengths set",i.mode=30;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},N=a(h,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,N){t.msg="invalid distances set",i.mode=30;break}if(i.mode=20,6===e)break t;case 20:i.mode=21;case 21:if(6<=y&&258<=w){t.next_out=_,t.avail_out=w,t.next_in=g,t.avail_in=y,i.hold=v,i.bits=b,o(t,T),_=t.next_out,f=t.output,w=t.avail_out,g=t.next_in,p=t.input,y=t.avail_in,v=i.hold,b=i.bits,12===i.mode&&(i.back=-1);break}for(i.back=0;I=(R=i.lencode[v&(1<<i.lenbits)-1])>>>16&255,M=65535&R,!((P=R>>>24)<=b);){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(I&&!(240&I)){for(D=P,k=I,z=M;I=(R=i.lencode[z+((v&(1<<D+k)-1)>>D)])>>>16&255,M=65535&R,!(D+(P=R>>>24)<=b);){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}v>>>=D,b-=D,i.back+=D}if(v>>>=P,b-=P,i.back+=P,i.length=M,0===I){i.mode=26;break}if(32&I){i.back=-1,i.mode=12;break}if(64&I){t.msg="invalid literal/length code",i.mode=30;break}i.extra=15&I,i.mode=22;case 22:if(i.extra){for(L=i.extra;b<L;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.length+=v&(1<<i.extra)-1,v>>>=i.extra,b-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;I=(R=i.distcode[v&(1<<i.distbits)-1])>>>16&255,M=65535&R,!((P=R>>>24)<=b);){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(!(240&I)){for(D=P,k=I,z=M;I=(R=i.distcode[z+((v&(1<<D+k)-1)>>D)])>>>16&255,M=65535&R,!(D+(P=R>>>24)<=b);){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}v>>>=D,b-=D,i.back+=D}if(v>>>=P,b-=P,i.back+=P,64&I){t.msg="invalid distance code",i.mode=30;break}i.offset=M,i.extra=15&I,i.mode=24;case 24:if(i.extra){for(L=i.extra;b<L;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}i.offset+=v&(1<<i.extra)-1,v>>>=i.extra,b-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=30;break}i.mode=25;case 25:if(0===w)break t;if(S=T-w,i.offset>S){if((S=i.offset-S)>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=30;break}A=S>i.wnext?(S-=i.wnext,i.wsize-S):i.wnext-S,S>i.length&&(S=i.length),O=i.window}else O=f,A=_-i.offset,S=i.length;for(w<S&&(S=w),w-=S,i.length-=S;f[_++]=O[A++],--S;);0===i.length&&(i.mode=21);break;case 26:if(0===w)break t;f[_++]=i.length,w--,i.mode=21;break;case 27:if(i.wrap){for(;b<32;){if(0===y)break t;y--,v|=p[g++]<<b,b+=8}if(T-=w,t.total_out+=T,i.total+=T,T&&(t.adler=i.check=i.flags?r(i.check,f,T,_-T):n(i.check,f,T,_-T)),T=w,(i.flags?v:m(v))!==i.check){t.msg="incorrect data check",i.mode=30;break}b=v=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;b<32;){if(0===y)break t;y--,v+=p[g++]<<b,b+=8}if(v!==(4294967295&i.total)){t.msg="incorrect length check",i.mode=30;break}b=v=0}i.mode=29;case 29:N=1;break t;case 30:N=-3;break t;case 31:return-4;default:return d}return t.next_out=_,t.avail_out=w,t.next_in=g,t.avail_in=y,i.hold=v,i.bits=b,(i.wsize||T!==t.avail_out&&i.mode<30&&(i.mode<27||4!==e))&&E(t,t.output,t.next_out,T-t.avail_out)?(i.mode=31,-4):(x-=t.avail_in,T-=t.avail_out,t.total_in+=x,t.total_out+=T,i.total+=T,i.wrap&&T&&(t.adler=i.check=i.flags?r(i.check,f,T,t.next_out-T):n(i.check,f,T,t.next_out-T)),t.data_type=i.bits+(i.last?64:0)+(12===i.mode?128:0)+(20===i.mode||15===i.mode?256:0),(0==x&&0===T||4===e)&&N===c&&(N=-5),N)},i.inflateEnd=function(t){if(!t||!t.state)return d;var e=t.state;return e.window&&(e.window=null),t.state=null,c},i.inflateGetHeader=function(t,e){var i;return t&&t.state&&2&(i=t.state).wrap?((i.head=e).done=!1,c):d},i.inflateSetDictionary=function(t,e){var i,s=e.length;return t&&t.state?0!==(i=t.state).wrap&&11!==i.mode?d:11===i.mode&&n(1,e,s,0)!==i.check?-3:E(t,e,s,s)?(i.mode=31,-4):(i.havedict=1,c):d},i.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(t,e,i){var s=t("../utils/common"),n=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],r=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],o=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],a=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];e.exports=function(t,e,i,l,h,c,d,u){var p,f,m,g,_,y,w,v,b,x=u.bits,T=0,C=0,E=0,S=0,A=0,O=0,P=0,I=0,M=0,D=0,k=null,z=0,B=new s.Buf16(16),N=new s.Buf16(16),U=null,L=0;for(T=0;T<=15;T++)B[T]=0;for(C=0;C<l;C++)B[e[i+C]]++;for(A=x,S=15;1<=S&&0===B[S];S--);if(S<A&&(A=S),0===S)return h[c++]=20971520,h[c++]=20971520,u.bits=1,0;for(E=1;E<S&&0===B[E];E++);for(A<E&&(A=E),T=I=1;T<=15;T++)if(I<<=1,(I-=B[T])<0)return-1;if(0<I&&(0===t||1!==S))return-1;for(N[1]=0,T=1;T<15;T++)N[T+1]=N[T]+B[T];for(C=0;C<l;C++)0!==e[i+C]&&(d[N[e[i+C]]++]=C);if(y=0===t?(k=U=d,19):1===t?(k=n,z-=257,U=r,L-=257,256):(k=o,U=a,-1),T=E,_=c,P=C=D=0,m=-1,g=(M=1<<(O=A))-1,1===t&&852<M||2===t&&592<M)return 1;for(;;){for(w=T-P,b=d[C]<y?(v=0,d[C]):d[C]>y?(v=U[L+d[C]],k[z+d[C]]):(v=96,0),p=1<<T-P,E=f=1<<O;h[_+(D>>P)+(f-=p)]=w<<24|v<<16|b,0!==f;);for(p=1<<T-1;D&p;)p>>=1;if(0!==p?(D&=p-1,D+=p):D=0,C++,0==--B[T]){if(T===S)break;T=e[i+d[C]]}if(A<T&&(D&g)!==m){for(0===P&&(P=A),_+=E,I=1<<(O=T-P);O+P<S&&!((I-=B[O+P])<=0);)O++,I<<=1;if(M+=1<<O,1===t&&852<M||2===t&&592<M)return 1;h[m=D&g]=A<<24|O<<16|_-c}}return 0!==D&&(h[_+D]=T-P<<24|64<<16),u.bits=A,0}},{"../utils/common":41}],51:[function(t,e,i){e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(t,e,i){var s=t("../utils/common"),n=0,r=1;function o(t){for(var e=t.length;0<=--e;)t[e]=0}var a=0,l=29,h=256,c=h+1+l,d=30,u=19,p=2*c+1,f=15,m=16,g=7,_=256,y=16,w=17,v=18,b=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],x=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],T=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],C=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],E=new Array(2*(c+2));o(E);var S=new Array(2*d);o(S);var A=new Array(512);o(A);var O=new Array(256);o(O);var P=new Array(l);o(P);var I,M,D,k=new Array(d);function z(t,e,i,s,n){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=s,this.max_length=n,this.has_stree=t&&t.length}function B(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function N(t){return t<256?A[t]:A[256+(t>>>7)]}function U(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function L(t,e,i){t.bi_valid>m-i?(t.bi_buf|=e<<t.bi_valid&65535,U(t,t.bi_buf),t.bi_buf=e>>m-t.bi_valid,t.bi_valid+=i-m):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=i)}function R(t,e,i){L(t,i[2*e],i[2*e+1])}function F(t,e){for(var i=0;i|=1&t,t>>>=1,i<<=1,0<--e;);return i>>>1}function V(t,e,i){var s,n,r=new Array(f+1),o=0;for(s=1;s<=f;s++)r[s]=o=o+i[s-1]<<1;for(n=0;n<=e;n++){var a=t[2*n+1];0!==a&&(t[2*n]=F(r[a]++,a))}}function j(t){var e;for(e=0;e<c;e++)t.dyn_ltree[2*e]=0;for(e=0;e<d;e++)t.dyn_dtree[2*e]=0;for(e=0;e<u;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*_]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function H(t){8<t.bi_valid?U(t,t.bi_buf):0<t.bi_valid&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function Z(t,e,i,s){var n=2*e,r=2*i;return t[n]<t[r]||t[n]===t[r]&&s[e]<=s[i]}function $(t,e,i){for(var s=t.heap[i],n=i<<1;n<=t.heap_len&&(n<t.heap_len&&Z(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!Z(e,s,t.heap[n],t.depth));)t.heap[i]=t.heap[n],i=n,n<<=1;t.heap[i]=s}function W(t,e,i){var s,n,r,o,a=0;if(0!==t.last_lit)for(;s=t.pending_buf[t.d_buf+2*a]<<8|t.pending_buf[t.d_buf+2*a+1],n=t.pending_buf[t.l_buf+a],a++,0===s?R(t,n,e):(R(t,(r=O[n])+h+1,e),0!==(o=b[r])&&L(t,n-=P[r],o),R(t,r=N(--s),i),0!==(o=x[r])&&L(t,s-=k[r],o)),a<t.last_lit;);R(t,_,e)}function Y(t,e){var i,s,n,r=e.dyn_tree,o=e.stat_desc.static_tree,a=e.stat_desc.has_stree,l=e.stat_desc.elems,h=-1;for(t.heap_len=0,t.heap_max=p,i=0;i<l;i++)0!==r[2*i]?(t.heap[++t.heap_len]=h=i,t.depth[i]=0):r[2*i+1]=0;for(;t.heap_len<2;)r[2*(n=t.heap[++t.heap_len]=h<2?++h:0)]=1,t.depth[n]=0,t.opt_len--,a&&(t.static_len-=o[2*n+1]);for(e.max_code=h,i=t.heap_len>>1;1<=i;i--)$(t,r,i);for(n=l;i=t.heap[1],t.heap[1]=t.heap[t.heap_len--],$(t,r,1),s=t.heap[1],t.heap[--t.heap_max]=i,t.heap[--t.heap_max]=s,r[2*n]=r[2*i]+r[2*s],t.depth[n]=(t.depth[i]>=t.depth[s]?t.depth[i]:t.depth[s])+1,r[2*i+1]=r[2*s+1]=n,t.heap[1]=n++,$(t,r,1),2<=t.heap_len;);t.heap[--t.heap_max]=t.heap[1],function(t,e){var i,s,n,r,o,a,l=e.dyn_tree,h=e.max_code,c=e.stat_desc.static_tree,d=e.stat_desc.has_stree,u=e.stat_desc.extra_bits,m=e.stat_desc.extra_base,g=e.stat_desc.max_length,_=0;for(r=0;r<=f;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,i=t.heap_max+1;i<p;i++)g<(r=l[2*l[2*(s=t.heap[i])+1]+1]+1)&&(r=g,_++),l[2*s+1]=r,h<s||(t.bl_count[r]++,o=0,m<=s&&(o=u[s-m]),a=l[2*s],t.opt_len+=a*(r+o),d&&(t.static_len+=a*(c[2*s+1]+o)));if(0!==_){do{for(r=g-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[g]--,_-=2}while(0<_);for(r=g;0!==r;r--)for(s=t.bl_count[r];0!==s;)h<(n=t.heap[--i])||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),s--)}}(t,e),V(r,h,t.bl_count)}function G(t,e,i){var s,n,r=-1,o=e[1],a=0,l=7,h=4;for(0===o&&(l=138,h=3),e[2*(i+1)+1]=65535,s=0;s<=i;s++)n=o,o=e[2*(s+1)+1],++a<l&&n===o||(a<h?t.bl_tree[2*n]+=a:0!==n?(n!==r&&t.bl_tree[2*n]++,t.bl_tree[2*y]++):a<=10?t.bl_tree[2*w]++:t.bl_tree[2*v]++,r=n,h=(a=0)===o?(l=138,3):n===o?(l=6,3):(l=7,4))}function X(t,e,i){var s,n,r=-1,o=e[1],a=0,l=7,h=4;for(0===o&&(l=138,h=3),s=0;s<=i;s++)if(n=o,o=e[2*(s+1)+1],!(++a<l&&n===o)){if(a<h)for(;R(t,n,t.bl_tree),0!=--a;);else 0!==n?(n!==r&&(R(t,n,t.bl_tree),a--),R(t,y,t.bl_tree),L(t,a-3,2)):a<=10?(R(t,w,t.bl_tree),L(t,a-3,3)):(R(t,v,t.bl_tree),L(t,a-11,7));r=n,h=(a=0)===o?(l=138,3):n===o?(l=6,3):(l=7,4)}}o(k);var q=!1;function Q(t,e,i,n){var r,o,l;L(t,(a<<1)+(n?1:0),3),o=e,l=i,H(r=t),U(r,l),U(r,~l),s.arraySet(r.pending_buf,r.window,o,l,r.pending),r.pending+=l}i._tr_init=function(t){q||(function(){var t,e,i,s,n,r=new Array(f+1);for(s=i=0;s<l-1;s++)for(P[s]=i,t=0;t<1<<b[s];t++)O[i++]=s;for(O[i-1]=s,s=n=0;s<16;s++)for(k[s]=n,t=0;t<1<<x[s];t++)A[n++]=s;for(n>>=7;s<d;s++)for(k[s]=n<<7,t=0;t<1<<x[s]-7;t++)A[256+n++]=s;for(e=0;e<=f;e++)r[e]=0;for(t=0;t<=143;)E[2*t+1]=8,t++,r[8]++;for(;t<=255;)E[2*t+1]=9,t++,r[9]++;for(;t<=279;)E[2*t+1]=7,t++,r[7]++;for(;t<=287;)E[2*t+1]=8,t++,r[8]++;for(V(E,c+1,r),t=0;t<d;t++)S[2*t+1]=5,S[2*t]=F(t,5);I=new z(E,b,h+1,c,f),M=new z(S,x,0,d,f),D=new z(new Array(0),T,0,u,g)}(),q=!0),t.l_desc=new B(t.dyn_ltree,I),t.d_desc=new B(t.dyn_dtree,M),t.bl_desc=new B(t.bl_tree,D),t.bi_buf=0,t.bi_valid=0,j(t)},i._tr_stored_block=Q,i._tr_flush_block=function(t,e,i,s){var o,a,l=0;0<t.level?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return n;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return r;for(e=32;e<h;e++)if(0!==t.dyn_ltree[2*e])return r;return n}(t)),Y(t,t.l_desc),Y(t,t.d_desc),l=function(t){var e;for(G(t,t.dyn_ltree,t.l_desc.max_code),G(t,t.dyn_dtree,t.d_desc.max_code),Y(t,t.bl_desc),e=u-1;3<=e&&0===t.bl_tree[2*C[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),o=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=o&&(o=a)):o=a=i+5,i+4<=o&&-1!==e?Q(t,e,i,s):4===t.strategy||a===o?(L(t,2+(s?1:0),3),W(t,E,S)):(L(t,4+(s?1:0),3),function(t,e,i,s){var n;for(L(t,e-257,5),L(t,i-1,5),L(t,s-4,4),n=0;n<s;n++)L(t,t.bl_tree[2*C[n]+1],3);X(t,t.dyn_ltree,e-1),X(t,t.dyn_dtree,i-1)}(t,t.l_desc.max_code+1,t.d_desc.max_code+1,l+1),W(t,t.dyn_ltree,t.dyn_dtree)),j(t),s&&H(t)},i._tr_tally=function(t,e,i){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(O[i]+h+1)]++,t.dyn_dtree[2*N(e)]++),t.last_lit===t.lit_bufsize-1},i._tr_align=function(t){var e;L(t,2,3),R(t,_,E),16===(e=t).bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},{"../utils/common":41}],53:[function(t,e,i){e.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(t,e,i){(function(t){!function(t,e){if(!t.setImmediate){var i,s,n,r,o=1,a={},l=!1,h=t.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(t);c=c&&c.setTimeout?c:t,i="[object process]"==={}.toString.call(t.process)?function(t){process.nextTick(function(){u(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,i=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=i,e}}()?(r="setImmediate$"+Math.random()+"$",t.addEventListener?t.addEventListener("message",p,!1):t.attachEvent("onmessage",p),function(e){t.postMessage(r+e,"*")}):t.MessageChannel?((n=new MessageChannel).port1.onmessage=function(t){u(t.data)},function(t){n.port2.postMessage(t)}):h&&"onreadystatechange"in h.createElement("script")?(s=h.documentElement,function(t){var e=h.createElement("script");e.onreadystatechange=function(){u(t),e.onreadystatechange=null,s.removeChild(e),e=null},s.appendChild(e)}):function(t){setTimeout(u,0,t)},c.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),s=0;s<e.length;s++)e[s]=arguments[s+1];var n={callback:t,args:e};return a[o]=n,i(o),o++},c.clearImmediate=d}function d(t){delete a[t]}function u(t){if(l)setTimeout(u,0,t);else{var i=a[t];if(i){l=!0;try{!function(t){var i=t.callback,s=t.args;switch(s.length){case 0:i();break;case 1:i(s[0]);break;case 2:i(s[0],s[1]);break;case 3:i(s[0],s[1],s[2]);break;default:i.apply(e,s)}}(i)}finally{d(t),l=!1}}}}function p(e){e.source===t&&"string"==typeof e.data&&0===e.data.indexOf(r)&&u(+e.data.slice(r.length))}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,void 0!==b?b:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[10])(10));class ar{constructor(t,i){e(this,"date",new Date),e(this,"author"),e(this,"guid",v.create()),e(this,"viewpoint"),e(this,"modifiedAuthor"),e(this,"modifiedDate"),e(this,"topic"),e(this,"_components"),e(this,"_comment",""),this._components=t,this._comment=i;const s=this._components.get(pr);this.author=s.config.author}set comment(t){var e;const i=this._components.get(pr);this._comment=t,this.modifiedDate=new Date,this.modifiedAuthor=i.config.author,null==(e=this.topic)||e.comments.set(this.guid,this)}get comment(){return this._comment}toJSON(){var t,e;const i={guid:this.guid,date:this.date.toISOString(),author:this.author,comment:this.comment,topic_guid:null==(t=this.topic)?void 0:t.guid,viewpoint_guid:this.viewpoint,modified_date:null==(e=this.modifiedDate)?void 0:e.toISOString(),modified_author:this.modifiedAuthor};for(const[t,e]of Object.entries(i))void 0===e&&delete i[t];return i}}const lr=class t{constructor(s){e(this,"guid",v.create()),e(this,"title",t.default.title),e(this,"creationDate",new Date),e(this,"creationAuthor",""),e(this,"viewpoints",new i.DataSet),e(this,"relatedTopics",new i.DataSet),e(this,"comments",new i.DataMap),e(this,"documentReferences",new i.DataSet),e(this,"customData",{}),e(this,"description"),e(this,"serverAssignedId"),e(this,"dueDate"),e(this,"modifiedAuthor"),e(this,"modifiedDate"),e(this,"index"),e(this,"_type",t.default.type),e(this,"_status",t.default.status),e(this,"_priority",t.default.priority),e(this,"_stage",t.default.stage),e(this,"_assignedTo",t.default.assignedTo),e(this,"_labels",t.default.labels??new Set),e(this,"_components"),this._components=s;const n=s.get(pr);this.creationAuthor=n.config.author,this.relatedTopics.guard=t=>t!==this.guid}set type(t){const e=this._components.get(pr),{strict:i,types:s}=e.config;(!i||s.has(t))&&(this._type=t)}get type(){return this._type}set status(t){const e=this._components.get(pr),{strict:i,statuses:s}=e.config;(!i||s.has(t))&&(this._status=t)}get status(){return this._status}set priority(t){const e=this._components.get(pr);if(t){const{strict:i,priorities:s}=e.config;if(!(!i||s.has(t)))return;this._priority=t}else this._priority=t}get priority(){return this._priority}set stage(t){const e=this._components.get(pr);if(t){const{strict:i,stages:s}=e.config;if(!(!i||s.has(t)))return;this._stage=t}else this._stage=t}get stage(){return this._stage}set assignedTo(t){const e=this._components.get(pr);if(t){const{strict:i,users:s}=e.config;if(!(!i||s.has(t)))return;this._assignedTo=t}else this._assignedTo=t}get assignedTo(){return this._assignedTo}set labels(t){const e=this._components.get(pr),{strict:i,labels:s}=e.config;if(i){const e=new Set;for(const n of t){(!i||s.has(n))&&e.add(n)}this._labels=e}else this._labels=t}get labels(){return this._labels}get _managerVersion(){return this._components.get(pr).config.version}set(t){const e=t,i=this;for(const s in t){if("guid"===s)continue;const t=e[s];s in this&&(i[s]=t)}return this._components.get(pr).list.set(this.guid,this),this}createComment(t,e){const i=new ar(this._components,t);return i.viewpoint=e,i.topic=this,this.comments.set(i.guid,i),i}createLabelTags(){const t=[...this.labels];if(this._components.get(pr).config.exportCustomDataAsLabels)for(const e in this.customData){const i=this.customData[e];"string"==typeof i&&t.push(i)}return t}createCommentTags(){return[...this.comments.values()].map(t=>{var e;return{$Guid:t.guid,Date:t.date.toISOString(),Author:t.author,Comment:t.comment,ModifiedAuthor:t.modifiedAuthor,ModifiedDate:null==(e=t.modifiedDate)?void 0:e.toISOString(),Viewpoint:t.viewpoint?{$Guid:t.viewpoint}:void 0}})}createViewpointTags(){const t=this._components.get(to);return[...this.viewpoints].map(e=>t.list.get(e)).filter(t=>t).map(e=>{const i={$Guid:e.guid,Viewpoint:`${e.title??e.guid}.bcfv`};if(t.snapshots.get(e.snapshot)){const s=t.getSnapshotExtension(e.snapshot);i.Snapshot=`${e.snapshot}.${s}`}return i})}createRelatedTopicTags(){return[...this.relatedTopics].map(t=>({$Guid:t}))}createDocumentReferencesTag(t=this._managerVersion){const e=[];if("3"!==t&&"2.1"!==t)return e;const i=this._components.get(pr);for(const s of this.documentReferences){const n=i.documents.get(s);if(!n)continue;let r={$Guid:v.create(),Description:n.description};"2.1"===t&&(r={...r,$isExternal:"external"===n.type||void 0,ReferencedDocument:"external"===n.type?n.url:`../${n.fileName}`}),"3"===t&&(r={...r,DocumentGuid:"internal"===n.type?s:void 0,Url:"external"===n.type?n.url:void 0}),Object.keys(r).length>0&&e.push(r)}return e}toJSON(){var t,e;const i={guid:this.guid,server_assigned_id:this.serverAssignedId,topic_type:this.type,topic_status:this.status,title:this.title,priority:this.priority,index:this.index,labels:[...this.labels],creation_date:this.creationDate.toISOString(),creation_author:this.creationAuthor,modified_date:null==(t=this.modifiedDate)?void 0:t.toISOString(),modified_author:this.modifiedAuthor,assigned_to:this.assignedTo,stage:this.stage,description:this.description,due_date:null==(e=this.dueDate)?void 0:e.toISOString(),comments:[...this.comments].map(([t,e])=>e.toJSON()),relatedTopics:[...this.relatedTopics].map(t=>({related_topic_guid:t}))},s=this._components.get(to);for(const t of this.viewpoints){const e=s.list.get(t);e&&(i.viewpoints||(i.viewpoints=[]),i.viewpoints.push(e.toJSON()))}const n=this._components.get(pr);for(const t of this.documentReferences){const e=n.documents.get(t);e&&(i.document_references||(i.document_references=[]),"external"===e.type?i.document_references.push({guid:v.create(),description:e.description,url:e.url}):i.document_references.push({guid:v.create(),description:e.description,document_guid:t}))}for(const[t,e]of Object.entries(i))(void 0===e||Array.isArray(e)&&0===e.length)&&delete i[t];return i}serialize(){var t,e;const i=this._managerVersion,s={$Guid:this.guid,$TopicType:this.type,$TopicStatus:this.status,$ServerAssignedId:this.serverAssignedId,Title:this.title,CreationAuthor:this.creationAuthor,CreationDate:this.creationDate.toISOString(),Priority:this.priority,Index:"2.1"===i?this.index:void 0,ModifiedDate:null==(t=this.modifiedDate)?void 0:t.toISOString(),ModifiedAuthor:this.modifiedAuthor,DueDate:null==(e=this.dueDate)?void 0:e.toISOString(),AssignedTo:this.assignedTo,Description:this.description,Stage:this.stage,DocumentReferences:"3"===i?{DocumentReference:this.createDocumentReferencesTag(i)}:void 0,RelatedTopics:"3"===i?{RelatedTopic:this.createRelatedTopicTags()}:void 0,RelatedTopic:"2.1"===i?this.createRelatedTopicTags():void 0,Labels:"3"===i?{Label:this.createLabelTags()}:void 0,Viewpoints:"3"===i?{ViewPoint:this.createViewpointTags()}:void 0,Comments:"3"===i?{Comment:this.createCommentTags()}:void 0};"2.1"===i&&(s.Labels=this.createLabelTags(),s.DocumentReference=this.createDocumentReferencesTag(i));const n={Markup:{Topic:s}};return"2.1"===i&&(n.Markup.Viewpoints=this.createViewpointTags(),n.Markup.Comment=this.createCommentTags()),`<?xml version="1.0" encoding="UTF-8"?>\n ${Vt.builder.build(n)}`}};e(lr,"default",{title:"BCF Topic",type:"Issue",status:"Active"});let hr=lr;const cr=(t,e)=>{if(""===e.trim())return;const i=pr.xmlParser.parse(e).Extensions;if(!i)return;const{Priorities:s,TopicStatuses:n,TopicTypes:r,Users:o}=i;if(s&&s.Priority){const e=Array.isArray(s.Priority)?s.Priority:[s.Priority];for(const i of e)t.config.priorities.add(i)}if(n&&n.TopicStatus){const e=Array.isArray(n.TopicStatus)?n.TopicStatus:[n.TopicStatus];for(const i of e)t.config.statuses.add(i)}if(r&&r.TopicType){const e=Array.isArray(r.TopicType)?r.TopicType:[r.TopicType];for(const i of e)t.config.types.add(i)}if(o&&o.User){const e=Array.isArray(o.User)?o.User:[o.User];for(const i of e)t.config.users.add(i)}};class dr extends $t{constructor(){super(...arguments),e(this,"_config",{version:{type:"Select",options:new Set(["2.1","3"]),multiple:!1,value:""},author:{type:"Text",value:""},types:{type:"TextSet",value:new Set},statuses:{type:"TextSet",value:new Set},priorities:{type:"TextSet",value:new Set},labels:{type:"TextSet",value:new Set},stages:{type:"TextSet",value:new Set},users:{type:"TextSet",value:new Set},includeSelectionTag:{type:"Boolean",value:!1},updateExtensionsOnImport:{type:"Boolean",value:!1},strict:{type:"Boolean",value:!1},includeAllExtensionsOnExport:{type:"Boolean",value:!1},fallbackVersionOnImport:{type:"Select",multiple:!1,options:new Set(["2.1","3"]),value:""},ignoreIncompleteTopicsOnImport:{type:"Boolean",value:!1},exportCustomDataAsLabels:{type:"Boolean",value:!1}})}get version(){return this._config.version.value}set version(t){this._config.version.value=t}get author(){return this._config.author.value}set author(t){this._config.author.value=t}get types(){return this._config.types.value}set types(t){this._config.types.value=t}get statuses(){return this._config.statuses.value}set statuses(t){this._config.statuses.value=t}get priorities(){return this._config.priorities.value}set priorities(t){this._config.priorities.value=t}get labels(){return this._config.labels.value}set labels(t){this._config.labels.value=t}get stages(){return this._config.stages.value}set stages(t){this._config.stages.value=t}get users(){return this._config.users.value}set users(t){this._config.users.value=t}get includeSelectionTag(){return this._config.includeSelectionTag.value}set includeSelectionTag(t){this._config.includeSelectionTag.value=t}get updateExtensionsOnImport(){return this._config.updateExtensionsOnImport.value}set updateExtensionsOnImport(t){this._config.updateExtensionsOnImport.value=t}get strict(){return this._config.strict.value}set strict(t){this._config.strict.value=t}get includeAllExtensionsOnExport(){return this._config.includeAllExtensionsOnExport.value}set includeAllExtensionsOnExport(t){this._config.includeAllExtensionsOnExport.value=t}get fallbackVersionOnImport(){return this._config.fallbackVersionOnImport.value}set fallbackVersionOnImport(t){this._config.fallbackVersionOnImport.value=t}get ignoreIncompleteTopicsOnImport(){return this._config.ignoreIncompleteTopicsOnImport.value}set ignoreIncompleteTopicsOnImport(t){this._config.ignoreIncompleteTopicsOnImport.value=t}get exportCustomDataAsLabels(){return this._config.exportCustomDataAsLabels.value}set exportCustomDataAsLabels(t){this._config.exportCustomDataAsLabels.value=t}}const ur=class t extends d{constructor(){super(...arguments),e(this,"enabled",!1),e(this,"_defaultConfig",{author:"jhon.doe@example.com",version:"2.1",types:new Set(["Clash","Failure","Fault","Inquiry","Issue","Remark","Request"]),statuses:new Set(["Active","In Progress","Done","In Review","Closed"]),priorities:new Set(["On hold","Minor","Normal","Major","Critical"]),labels:new Set,stages:new Set,users:new Set,includeSelectionTag:!1,updateExtensionsOnImport:!0,strict:!1,includeAllExtensionsOnExport:!0,fallbackVersionOnImport:"2.1",ignoreIncompleteTopicsOnImport:!1,exportCustomDataAsLabels:!1}),e(this,"config",new dr(this,this.components,"BCF Topics",t.uuid)),e(this,"list",new i.DataMap),e(this,"documents",new i.DataMap),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"onBCFImported",new h),e(this,"onDisposed",new h)}setup(t){if(this.isSetup)return;const e={...this._defaultConfig,...t};this.config.version=e.version,this.config.author=e.author,this.config.types=e.types,this.config.statuses=e.statuses,this.config.priorities=e.priorities,this.config.labels=e.labels,this.config.stages=e.stages,this.config.users=e.users,this.config.includeSelectionTag=e.includeSelectionTag,this.config.updateExtensionsOnImport=e.updateExtensionsOnImport,this.config.strict=e.strict,this.config.includeAllExtensionsOnExport=e.includeAllExtensionsOnExport,this.config.fallbackVersionOnImport=e.fallbackVersionOnImport||"",this.config.ignoreIncompleteTopicsOnImport=e.ignoreIncompleteTopicsOnImport,this.isSetup=!0,this.enabled=!0,this.onSetup.trigger()}create(t){const e=new hr(this.components);return t?(e.guid=t.guid??e.guid,e.set(t)):this.list.set(e.guid,e),e}dispose(){this.list.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}get usedTypes(){const t=[...this.list].map(([t,e])=>e.type);return new Set(t)}get usedStatuses(){const t=[...this.list].map(([t,e])=>e.status);return new Set(t)}get usedPriorities(){const t=[...this.list].map(([t,e])=>e.priority).filter(t=>t);return new Set(t)}get usedStages(){const t=[...this.list].map(([t,e])=>e.stage).filter(t=>t);return new Set(t)}get usedUsers(){const t=[];for(const[e,i]of this.list){t.push(i.creationAuthor),i.assignedTo&&t.push(i.assignedTo),i.modifiedAuthor&&t.push(i.modifiedAuthor);for(const[e,s]of i.comments)t.push(s.author),s.modifiedAuthor&&t.push(s.modifiedAuthor)}return new Set(t)}get usedLabels(){const t=[];for(const[e,i]of this.list)t.push(...i.labels);return new Set(t)}updateExtensions(){for(const[t,e]of this.list){for(const t of e.labels)this.config.labels.add(t);this.config.types.add(e.type),e.priority&&this.config.priorities.add(e.priority),e.stage&&this.config.stages.add(e.stage),this.config.statuses.add(e.status),this.config.users.add(e.creationAuthor),e.assignedTo&&this.config.users.add(e.assignedTo),e.modifiedAuthor&&this.config.users.add(e.modifiedAuthor);for(const[t,i]of e.comments)this.config.users.add(i.author),i.modifiedAuthor&&this.config.users.add(i.modifiedAuthor)}}updateViewpointReferences(){const t=this.components.get(to);for(const[e,i]of this.list)for(const e of i.viewpoints){t.list.has(e)||i.viewpoints.delete(e)}}async export(t=this.list.values()){const e=new or;e.file("bcf.version",`<?xml version="1.0" encoding="UTF-8"?>\n <Version VersionId="${this.config.version}" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/buildingSMART/BCF-XML/release_3_0/Schemas/version.xsd"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n </Version>`);for(const[t,i]of this.documents.entries())"external"!==i.type&&e.file("2.1"===this.config.version?i.fileName:`documents/${t}`,i.data);if("3"===this.config.version){const t=[];for(const[e,i]of this.documents.entries()){const{type:s,description:n}=i;"external"!==s&&t.push(`<Document Guid="${e}">\n <Filename>${i.fileName}</Filename>\n ${n?`<Description>${n}</Description>`:""}\n </Document>`)}t.length>0&&e.file("documents.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n <DocumentInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="documents.xsd">\n <Documents>\n ${t.join("\n")}\n </Documents>\n </DocumentInfo>`)}e.file("bcf.extensions",this.serializeExtensions());const i=this.components.get(to);for(const s of t){const t=e.folder(s.guid);t.file("markup.bcf",s.serialize());for(const e of s.viewpoints){const s=i.list.get(e);if(!s)continue;const n=s.title??s.guid;t.file(`${n}.bcfv`,await s.serialize());const r=i.snapshots.get(s.snapshot);if(!r)continue;const o=r?s.snapshot:s.guid,a=i.getSnapshotExtension(s.snapshot);t.file(`${o}.${a}`,r,{binary:!0})}}return await e.generateAsync({type:"blob"})}serializeExtensions(){const t=[...this.config.types].map(t=>`<TopicType>${t}</TopicType>`).join("\n"),e=[...this.config.statuses].map(t=>`<TopicStatus>${t}</TopicStatus>`).join("\n"),i=[...this.config.priorities].map(t=>`<Priority>${t}</Priority>`).join("\n"),s=[...this.config.labels].map(t=>`<TopicLabel>${t}</TopicLabel>`).join("\n"),n=[...this.config.stages].map(t=>`<Stage>${t}</Stage>`).join("\n"),r=[...this.config.users].map(t=>`<User>${t}</User>`).join("\n");return`\n <?xml version="1.0" encoding="UTF-8"?>\n <Extensions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="your-schema-location.xsd">\n ${0!==t.length?`<TopicTypes>\n${t}\n</TopicTypes>`:""}\n ${0!==e.length?`<TopicStatuses>\n${e}\n</TopicStatuses>`:""}\n ${0!==i.length?`<Priorities>\n${i}\n</Priorities>`:""}\n ${0!==s.length?`<TopicLabels>\n${s}\n</TopicLabels>`:""}\n ${0!==n.length?`<Stages>\n${n}\n</Stages>`:""}\n ${0!==r.length?`<Users>\n${r}\n</Users>`:""}\n </Extensions>\n `}processMarkupComment(t){const{Guid:e,Date:i,Author:s,Comment:n,Viewpoint:r}=t;if(!(e&&i&&s&&(ar||r)))return null;const o=new ar(this.components,n??"");return o.guid=e,o.date=new Date(i),o.author=s,o.viewpoint=null==r?void 0:r.Guid,o.modifiedAuthor=t.ModifiedAuthor,o.modifiedDate=t.ModifiedDate?new Date(t.ModifiedDate):void 0,o}getMarkupComments(t,e){var i;let s;if("2.1"===e&&(s=t.Comment),"3"===e&&(s=null==(i=t.Topic.Comments)?void 0:i.Comment),!s)return[];s=Array.isArray(s)?s:[s];const n=s.map(t=>this.processMarkupComment(t)).filter(t=>t);return Array.isArray(n)?n:[n]}getMarkupLabels(t,e){var i;let s;if("2.1"===e&&(s=t.Topic.Labels),"3"===e&&(s=null==(i=t.Topic.Labels)?void 0:i.Label),!s)return[];return Array.isArray(s)?s:[s]}getMarkupViewpoints(t,e){var i;let s;return"2.1"===e&&(s=t.Viewpoints),"3"===e&&(s=null==(i=t.Topic.Viewpoints)?void 0:i.ViewPoint),s?(s=Array.isArray(s)?s:[s],s):[]}getMarkupRelatedTopics(t,e){var i;let s;if("2.1"===e&&(s=t.Topic.RelatedTopic),"3"===e&&(s=null==(i=t.Topic.RelatedTopics)?void 0:i.RelatedTopic),!s)return[];return(Array.isArray(s)?s:[s]).map(t=>t.Guid)}getMarkupDocumentReferences(t,e){var i;let s;if("2.1"===e&&(s=t.Topic.DocumentReference),"3"===e&&(s=null==(i=t.Topic.DocumentReferences)?void 0:i.DocumentReference),!s)return[];return Array.isArray(s)?s:[s]}async load(e){var i,s,n;const{fallbackVersionOnImport:r,ignoreIncompleteTopicsOnImport:o,updateExtensionsOnImport:l}=this.config,h=new or;await h.loadAsync(e);const c=Object.values(h.files);let d=r;const u=c.find(t=>t.name.endsWith(".version"));if(u){const e=await u.async("string"),i=t.xmlParser.parse(e).Version.VersionId;d=String(i)}if(!d||"2.1"!==d&&"3"!==d)throw new Error(`BCFTopics: ${d} is not supported.`);const p=c.find(t=>t.name.endsWith(".extensions"));if(l&&p){const t=await p.async("string");cr(this,t)}const f=[],m=this.components.get(to),g=c.filter(t=>t.name.endsWith(".bcfv"));for(const e of g){const s=await e.async("string"),n=t.xmlParser.parse(s).VisualizationInfo;if(!n){console.warn("Missing VisualizationInfo in Viewpoint");continue}const r={},{Guid:o,ClippingPlanes:l,Components:h,OrthogonalCamera:c,PerspectiveCamera:u}=n;if(o&&(r.guid=o),h){const t={selection:[],coloring:[],visibility:{default_visibility:!1,exceptions:[],view_setup_hints:{spaces_visible:!1,space_boundaries_visible:!1,openings_visible:!1}}};r.components=t;const{Selection:e,Visibility:s}=h;if(e&&e.Component){const i=Array.isArray(e.Component)?e.Component:[e.Component];t.selection=i.map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t)}if(s&&"DefaultVisibility"in s&&(t.visibility.default_visibility=s.DefaultVisibility),s&&s.Exceptions&&"Component"in s.Exceptions){const{Component:e}=s.Exceptions,i=Array.isArray(e)?e:[e];t.visibility.exceptions=i.map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t)}let n;"2.1"===d&&(n=h.ViewSetupHints),"3"===d&&(n=null==(i=h.Visibility)?void 0:i.ViewSetupHints),n&&("OpeningsVisible"in n&&(t.visibility.view_setup_hints.openings_visible=n.OpeningsVisible),"SpacesVisible"in n&&(t.visibility.view_setup_hints.spaces_visible=n.SpacesVisible),"SpaceBoundariesVisible"in n&&(t.visibility.view_setup_hints.space_boundaries_visible=n.SpaceBoundariesVisible));const{Coloring:o}=h;if(o&&o.Color){const e=Array.isArray(o.Color)?o.Color:[o.Color];for(const i of e){const{Color:e,Component:s}=i;if(6!==e.length&&8!==e.length)continue;const n=6===e.length?e:e.slice(2),r=(Array.isArray(s)?s:[s]).map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t);t.coloring.push({color:n,components:r})}}}if(c||u){const t=n.PerspectiveCamera??n.OrthogonalCamera,{CameraViewPoint:e,CameraDirection:i}=t,s=new a.Vector3(Number(e.X),Number(e.Z),Number(-e.Y)),o=new a.Vector3(Number(i.X),Number(i.Z),Number(-i.Y)),l={camera_view_point:{x:s.x,y:s.y,z:s.z},camera_direction:{x:o.x,y:o.y,z:o.z},aspect_ratio:"AspectRatio"in t?t.AspectRatio:1,camera_up_vector:{x:0,y:0,z:0}};"ViewToWorldScale"in t&&(r.orthogonal_camera={...l,view_to_world_scale:t.ViewToWorldScale}),"FieldOfView"in t&&(r.perspective_camera={...l,field_of_view:t.FieldOfView})}if(l){const t=(Array.isArray(l.ClippingPlane)?l.ClippingPlane:[l.ClippingPlane]).map(({Location:t,Direction:e})=>({location:{x:t.x,y:t.y,z:t.z},direction:{x:e.x,y:e.y,z:e.z}}));r.clipping_planes=t}const p=new Qr(this.components,r);f.push(p)}const _={},y=[],w=c.filter(t=>t.name.endsWith(".bcf"));for(const e of w){const i=await e.async("string"),r=t.xmlParser.parse(i).Markup,a=r.Topic,{Guid:l,TopicType:h,TopicStatus:u,Title:p,CreationDate:f,CreationAuthor:g}=a;if(o&&!(l&&h&&u&&p&&f&&g))continue;const w=new hr(this.components);w.guid=l??w.guid;const v=this.getMarkupRelatedTopics(r,d);_[w.guid]=new Set(v),w.type=h??w.type,w.status=u??w.status,w.title=p??w.title,w.creationDate=f?new Date(f):w.creationDate,w.creationAuthor=g??w.creationAuthor,w.serverAssignedId=a.ServerAssignedId,w.priority=a.Priority,w.index=a.Index,w.modifiedDate=a.ModifiedDate?new Date(a.ModifiedDate):void 0,w.modifiedAuthor=a.ModifiedAuthor,w.dueDate=a.DueDate?new Date(a.DueDate):void 0,w.assignedTo=a.AssignedTo,w.description=a.Description,w.stage=a.Stage;const b=this.getMarkupLabels(r,d);for(const t of b)w.labels.add(t);const x=this.getMarkupComments(r,d);for(const t of x)w.comments.set(t.guid,t);const T=this.getMarkupViewpoints(r,d);for(const t of T){if(!t||!t.Guid)continue;const e=m.list.get(t.Guid);if(!e)continue;w.viewpoints.add(e.guid);const i=`${w.guid}/${t.Snapshot}`,s=c.find(({name:t})=>t===i);if(s){const t=await s.async("arraybuffer"),i=new Uint8Array(t);m.snapshots.set(e.guid,i),e.snapshot=e.guid??null}}const C=this.getMarkupDocumentReferences(r,d),E=c.find(t=>"documents.xml"===t.name);let S=[];const A=await(null==E?void 0:E.async("string"));if(A){const t=null==(n=null==(s=Vt.parser.parse(A).DocumentInfo)?void 0:s.Documents)?void 0:n.Document;S=Array.isArray(t)?t:[t]}for(const t of C){const{Description:e,DocumentGuid:i,Url:s,isExternal:n,ReferencedDocument:r}=t;if(i&&S.length>0){const t=S.find(({Guid:t})=>t===i),e=c.find(t=>t.name.endsWith(i)),s=await(null==e?void 0:e.async("uint8array"));if(!t||!s)continue;const{Description:n,Filename:r}=t;this.documents.set(i,{type:"internal",fileName:r,description:n,data:s}),w.documentReferences.add(i)}if(s){const t=this.documents.add({type:"external",url:s,description:e});w.documentReferences.add(t)}if(r){let t=null;if(n)t=this.documents.add({type:"external",url:r,description:e});else{const i=r.split("/"),s=i[i.length-1],n=c.find(t=>t.name.endsWith(s)),o=await(null==n?void 0:n.async("uint8array"));if(!o)continue;t=this.documents.add({type:"internal",fileName:s,data:o,description:e})}w.documentReferences.add(t)}}this.list.set(w.guid,w),y.push(w)}for(const t in _){const e=this.list.get(t);if(!e)continue;const i=_[t];for(const t of i)e.relatedTopics.add(t)}return this.onBCFImported.trigger(y),{viewpoints:f,topics:y}}};e(ur,"uuid","de977976-e4f6-4e4f-a01a-204727839802"),e(ur,"xmlParser",new Ft.XMLParser({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0}));let pr=ur;const fr=new s.Raycaster,mr=new s.Vector3,gr=new s.Vector3,_r=new s.Quaternion,yr={X:new s.Vector3(1,0,0),Y:new s.Vector3(0,1,0),Z:new s.Vector3(0,0,1)},wr={type:"change"},vr={type:"mouseDown",mode:null},br={type:"mouseUp",mode:null},xr={type:"objectChange"};class Tr extends s.Controls{constructor(t,e=null){super(void 0,e);const i=new Zr(this);this._root=i;const n=new $r;this._gizmo=n,i.add(n);const r=new Wr;this._plane=r,i.add(r);const o=this;function a(t,e){let i=e;Object.defineProperty(o,t,{get:function(){return void 0!==i?i:e},set:function(e){i!==e&&(i=e,r[t]=e,n[t]=e,o.dispatchEvent({type:t+"-changed",value:e}),o.dispatchEvent(wr))}}),o[t]=e,r[t]=e,n[t]=e}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const l=new s.Vector3,h=new s.Vector3,c=new s.Quaternion,d=new s.Quaternion,u=new s.Vector3,p=new s.Quaternion,f=new s.Vector3,m=new s.Vector3,g=new s.Vector3,_=new s.Vector3;a("worldPosition",l),a("worldPositionStart",h),a("worldQuaternion",c),a("worldQuaternionStart",d),a("cameraPosition",u),a("cameraQuaternion",p),a("pointStart",f),a("pointEnd",m),a("rotationAxis",g),a("rotationAngle",0),a("eye",_),this._offset=new s.Vector3,this._startNorm=new s.Vector3,this._endNorm=new s.Vector3,this._cameraScale=new s.Vector3,this._parentPosition=new s.Vector3,this._parentQuaternion=new s.Quaternion,this._parentQuaternionInv=new s.Quaternion,this._parentScale=new s.Vector3,this._worldScaleStart=new s.Vector3,this._worldQuaternionInv=new s.Quaternion,this._worldScale=new s.Vector3,this._positionStart=new s.Vector3,this._quaternionStart=new s.Quaternion,this._scaleStart=new s.Vector3,this._getPointer=Cr.bind(this),this._onPointerDown=Sr.bind(this),this._onPointerHover=Er.bind(this),this._onPointerMove=Ar.bind(this),this._onPointerUp=Or.bind(this),null!==e&&this.connect(e)}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(void 0===this.object||!0===this.dragging)return;null!==t&&fr.setFromCamera(t,this.camera);const e=Pr(this._gizmo.picker[this.mode],fr);this.axis=e?e.object.name:null}pointerDown(t){if(void 0!==this.object&&!0!==this.dragging&&(null==t||0===t.button)&&null!==this.axis){null!==t&&fr.setFromCamera(t,this.camera);const e=Pr(this._plane,fr,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,vr.mode=this.mode,this.dispatchEvent(vr)}}pointerMove(t){const e=this.axis,i=this.mode,s=this.object;let n=this.space;if("scale"===i?n="local":"E"!==e&&"XYZE"!==e&&"XYZ"!==e||(n="world"),void 0===s||null===e||!1===this.dragging||null!==t&&-1!==t.button)return;null!==t&&fr.setFromCamera(t,this.camera);const r=Pr(this._plane,fr,!0);if(r){if(this.pointEnd.copy(r.point).sub(this.worldPositionStart),"translate"===i)this._offset.copy(this.pointEnd).sub(this.pointStart),"local"===n&&"XYZ"!==e&&this._offset.applyQuaternion(this._worldQuaternionInv),-1===e.indexOf("X")&&(this._offset.x=0),-1===e.indexOf("Y")&&(this._offset.y=0),-1===e.indexOf("Z")&&(this._offset.z=0),"local"===n&&"XYZ"!==e?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),s.position.copy(this._offset).add(this._positionStart),this.translationSnap&&("local"===n&&(s.position.applyQuaternion(_r.copy(this._quaternionStart).invert()),-1!==e.search("X")&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.position.applyQuaternion(this._quaternionStart)),"world"===n&&(s.parent&&s.position.add(mr.setFromMatrixPosition(s.parent.matrixWorld)),-1!==e.search("X")&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.parent&&s.position.sub(mr.setFromMatrixPosition(s.parent.matrixWorld)))),s.position.x=Math.max(this.minX,Math.min(this.maxX,s.position.x)),s.position.y=Math.max(this.minY,Math.min(this.maxY,s.position.y)),s.position.z=Math.max(this.minZ,Math.min(this.maxZ,s.position.z));else if("scale"===i){if(-1!==e.search("XYZ")){let t=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(t*=-1),gr.set(t,t,t)}else mr.copy(this.pointStart),gr.copy(this.pointEnd),mr.applyQuaternion(this._worldQuaternionInv),gr.applyQuaternion(this._worldQuaternionInv),gr.divide(mr),-1===e.search("X")&&(gr.x=1),-1===e.search("Y")&&(gr.y=1),-1===e.search("Z")&&(gr.z=1);s.scale.copy(this._scaleStart).multiply(gr),this.scaleSnap&&(-1!==e.search("X")&&(s.scale.x=Math.round(s.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Y")&&(s.scale.y=Math.round(s.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Z")&&(s.scale.z=Math.round(s.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if("rotate"===i){this._offset.copy(this.pointEnd).sub(this.pointStart);const t=20/this.worldPosition.distanceTo(mr.setFromMatrixPosition(this.camera.matrixWorld));let i=!1;"XYZE"===e?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(mr.copy(this.rotationAxis).cross(this.eye))*t):"X"!==e&&"Y"!==e&&"Z"!==e||(this.rotationAxis.copy(yr[e]),mr.copy(yr[e]),"local"===n&&mr.applyQuaternion(this.worldQuaternion),mr.cross(this.eye),0===mr.length()?i=!0:this.rotationAngle=this._offset.dot(mr.normalize())*t),("E"===e||i)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),"local"===n&&"E"!==e&&"XYZE"!==e?(s.quaternion.copy(this._quaternionStart),s.quaternion.multiply(_r.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),s.quaternion.copy(_r.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),s.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(wr),this.dispatchEvent(xr)}}pointerUp(t){null!==t&&0!==t.button||(this.dragging&&null!==this.axis&&(br.mode=this.mode,this.dispatchEvent(br)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(wr),this.dispatchEvent(xr),this.pointStart.copy(this.pointEnd))}getRaycaster(){return fr}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}}function Cr(t){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:t.button};{const e=this.domElement.getBoundingClientRect();return{x:(t.clientX-e.left)/e.width*2-1,y:-(t.clientY-e.top)/e.height*2+1,button:t.button}}}function Er(t){if(this.enabled)switch(t.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(t))}}function Sr(t){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(t)),this.pointerDown(this._getPointer(t)))}function Ar(t){this.enabled&&this.pointerMove(this._getPointer(t))}function Or(t){this.enabled&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(t)))}function Pr(t,e,i){const s=e.intersectObject(t,!0);for(let t=0;t<s.length;t++)if(s[t].object.visible||i)return s[t];return!1}const Ir=new s.Euler,Mr=new s.Vector3(0,1,0),Dr=new s.Vector3(0,0,0),kr=new s.Matrix4,zr=new s.Quaternion,Br=new s.Quaternion,Nr=new s.Vector3,Ur=new s.Matrix4,Lr=new s.Vector3(1,0,0),Rr=new s.Vector3(0,1,0),Fr=new s.Vector3(0,0,1),Vr=new s.Vector3,jr=new s.Vector3,Hr=new s.Vector3;class Zr extends s.Object3D{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;void 0!==e.object&&(e.object.updateMatrixWorld(),null===e.object.parent?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class $r extends s.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new s.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new s.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=t.clone();i.opacity=.15;const n=e.clone();n.opacity=.5;const r=t.clone();r.color.setHex(16711680);const o=t.clone();o.color.setHex(65280);const a=t.clone();a.color.setHex(255);const l=t.clone();l.color.setHex(16711680),l.opacity=.5;const h=t.clone();h.color.setHex(65280),h.opacity=.5;const c=t.clone();c.color.setHex(255),c.opacity=.5;const d=t.clone();d.opacity=.25;const u=t.clone();u.color.setHex(16776960),u.opacity=.25;t.clone().color.setHex(16776960);const p=t.clone();p.color.setHex(7895160);const f=new s.CylinderGeometry(0,.04,.1,12);f.translate(0,.05,0);const m=new s.BoxGeometry(.08,.08,.08);m.translate(0,.04,0);const g=new s.BufferGeometry;g.setAttribute("position",new s.Float32BufferAttribute([0,0,0,1,0,0],3));const _=new s.CylinderGeometry(.0075,.0075,.5,3);function y(t,e){const i=new s.TorusGeometry(t,.0075,3,64,e*Math.PI*2);return i.rotateY(Math.PI/2),i.rotateX(Math.PI/2),i}_.translate(0,.25,0);const w={X:[[new s.Mesh(f,r),[.5,0,0],[0,0,-Math.PI/2]],[new s.Mesh(f,r),[-.5,0,0],[0,0,Math.PI/2]],[new s.Mesh(_,r),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new s.Mesh(f,o),[0,.5,0]],[new s.Mesh(f,o),[0,-.5,0],[Math.PI,0,0]],[new s.Mesh(_,o)]],Z:[[new s.Mesh(f,a),[0,0,.5],[Math.PI/2,0,0]],[new s.Mesh(f,a),[0,0,-.5],[-Math.PI/2,0,0]],[new s.Mesh(_,a),null,[Math.PI/2,0,0]]],XYZ:[[new s.Mesh(new s.OctahedronGeometry(.1,0),d.clone()),[0,0,0]]],XY:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),c.clone()),[.15,.15,0]]],YZ:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),l.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),h.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},v={X:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,.3,0]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new s.Mesh(new s.OctahedronGeometry(.2,0),i)]],XY:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},b={START:[[new s.Mesh(new s.OctahedronGeometry(.01,2),n),null,null,null,"helper"]],END:[[new s.Mesh(new s.OctahedronGeometry(.01,2),n),null,null,null,"helper"]],DELTA:[[new s.Line(function(){const t=new s.BufferGeometry;return t.setAttribute("position",new s.Float32BufferAttribute([0,0,0,1,1,1],3)),t}(),n),null,null,null,"helper"]],X:[[new s.Line(g,n.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new s.Line(g,n.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new s.Line(g,n.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},x={XYZE:[[new s.Mesh(y(.5,1),p),null,[0,Math.PI/2,0]]],X:[[new s.Mesh(y(.5,.5),r)]],Y:[[new s.Mesh(y(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new s.Mesh(y(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new s.Mesh(y(.75,1),u),null,[0,Math.PI/2,0]]]},T={AXIS:[[new s.Line(g,n.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},C={XYZE:[[new s.Mesh(new s.SphereGeometry(.25,10,8),i)]],X:[[new s.Mesh(new s.TorusGeometry(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new s.Mesh(new s.TorusGeometry(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new s.Mesh(new s.TorusGeometry(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new s.Mesh(new s.TorusGeometry(.75,.1,2,24),i)]]},E={X:[[new s.Mesh(m,r),[.5,0,0],[0,0,-Math.PI/2]],[new s.Mesh(_,r),[0,0,0],[0,0,-Math.PI/2]],[new s.Mesh(m,r),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new s.Mesh(m,o),[0,.5,0]],[new s.Mesh(_,o)],[new s.Mesh(m,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new s.Mesh(m,a),[0,0,.5],[Math.PI/2,0,0]],[new s.Mesh(_,a),[0,0,0],[Math.PI/2,0,0]],[new s.Mesh(m,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),c),[.15,.15,0]]],YZ:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new s.Mesh(new s.BoxGeometry(.15,.15,.01),h),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new s.Mesh(new s.BoxGeometry(.1,.1,.1),d.clone())]]},S={X:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,.3,0]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new s.Mesh(new s.CylinderGeometry(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new s.Mesh(new s.BoxGeometry(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new s.Mesh(new s.BoxGeometry(.2,.2,.2),i),[0,0,0]]]},A={X:[[new s.Line(g,n.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new s.Line(g,n.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new s.Line(g,n.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function O(t){const e=new s.Object3D;for(const i in t)for(let s=t[i].length;s--;){const n=t[i][s][0].clone(),r=t[i][s][1],o=t[i][s][2],a=t[i][s][3],l=t[i][s][4];n.name=i,n.tag=l,r&&n.position.set(r[0],r[1],r[2]),o&&n.rotation.set(o[0],o[1],o[2]),a&&n.scale.set(a[0],a[1],a[2]),n.updateMatrix();const h=n.geometry.clone();h.applyMatrix4(n.matrix),n.geometry=h,n.renderOrder=1/0,n.position.set(0,0,0),n.rotation.set(0,0,0),n.scale.set(1,1,1),e.add(n)}return e}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=O(w)),this.add(this.gizmo.rotate=O(x)),this.add(this.gizmo.scale=O(E)),this.add(this.picker.translate=O(v)),this.add(this.picker.rotate=O(C)),this.add(this.picker.scale=O(S)),this.add(this.helper.translate=O(b)),this.add(this.helper.rotate=O(T)),this.add(this.helper.scale=O(A)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const e="local"===("scale"===this.mode?"local":this.space)?this.worldQuaternion:Br;this.gizmo.translate.visible="translate"===this.mode,this.gizmo.rotate.visible="rotate"===this.mode,this.gizmo.scale.visible="scale"===this.mode,this.helper.translate.visible="translate"===this.mode,this.helper.rotate.visible="rotate"===this.mode,this.helper.scale.visible="scale"===this.mode;let i=[];i=i.concat(this.picker[this.mode].children),i=i.concat(this.gizmo[this.mode].children),i=i.concat(this.helper[this.mode].children);for(let t=0;t<i.length;t++){const s=i[t];let n;if(s.visible=!0,s.rotation.set(0,0,0),s.position.copy(this.worldPosition),n=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),s.scale.set(1,1,1).multiplyScalar(n*this.size/4),"helper"!==s.tag){if(s.quaternion.copy(e),"translate"===this.mode||"scale"===this.mode){const t=.99,i=.2;"X"===s.name&&Math.abs(Mr.copy(Lr).applyQuaternion(e).dot(this.eye))>t&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1),"Y"===s.name&&Math.abs(Mr.copy(Rr).applyQuaternion(e).dot(this.eye))>t&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1),"Z"===s.name&&Math.abs(Mr.copy(Fr).applyQuaternion(e).dot(this.eye))>t&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1),"XY"===s.name&&Math.abs(Mr.copy(Fr).applyQuaternion(e).dot(this.eye))<i&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1),"YZ"===s.name&&Math.abs(Mr.copy(Lr).applyQuaternion(e).dot(this.eye))<i&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1),"XZ"===s.name&&Math.abs(Mr.copy(Rr).applyQuaternion(e).dot(this.eye))<i&&(s.scale.set(1e-10,1e-10,1e-10),s.visible=!1)}else"rotate"===this.mode&&(zr.copy(e),Mr.copy(this.eye).applyQuaternion(_r.copy(e).invert()),-1!==s.name.search("E")&&s.quaternion.setFromRotationMatrix(kr.lookAt(this.eye,Dr,Rr)),"X"===s.name&&(_r.setFromAxisAngle(Lr,Math.atan2(-Mr.y,Mr.z)),_r.multiplyQuaternions(zr,_r),s.quaternion.copy(_r)),"Y"===s.name&&(_r.setFromAxisAngle(Rr,Math.atan2(Mr.x,Mr.z)),_r.multiplyQuaternions(zr,_r),s.quaternion.copy(_r)),"Z"===s.name&&(_r.setFromAxisAngle(Fr,Math.atan2(Mr.y,Mr.x)),_r.multiplyQuaternions(zr,_r),s.quaternion.copy(_r)));s.visible=s.visible&&(-1===s.name.indexOf("X")||this.showX),s.visible=s.visible&&(-1===s.name.indexOf("Y")||this.showY),s.visible=s.visible&&(-1===s.name.indexOf("Z")||this.showZ),s.visible=s.visible&&(-1===s.name.indexOf("E")||this.showX&&this.showY&&this.showZ),s.material._color=s.material._color||s.material.color.clone(),s.material._opacity=s.material._opacity||s.material.opacity,s.material.color.copy(s.material._color),s.material.opacity=s.material._opacity,this.enabled&&this.axis&&(s.name===this.axis||this.axis.split("").some(function(t){return s.name===t}))&&(s.material.color.setHex(16776960),s.material.opacity=1)}else s.visible=!1,"AXIS"===s.name?(s.visible=!!this.axis,"X"===this.axis&&(_r.setFromEuler(Ir.set(0,0,0)),s.quaternion.copy(e).multiply(_r),Math.abs(Mr.copy(Lr).applyQuaternion(e).dot(this.eye))>.9&&(s.visible=!1)),"Y"===this.axis&&(_r.setFromEuler(Ir.set(0,0,Math.PI/2)),s.quaternion.copy(e).multiply(_r),Math.abs(Mr.copy(Rr).applyQuaternion(e).dot(this.eye))>.9&&(s.visible=!1)),"Z"===this.axis&&(_r.setFromEuler(Ir.set(0,Math.PI/2,0)),s.quaternion.copy(e).multiply(_r),Math.abs(Mr.copy(Fr).applyQuaternion(e).dot(this.eye))>.9&&(s.visible=!1)),"XYZE"===this.axis&&(_r.setFromEuler(Ir.set(0,Math.PI/2,0)),Mr.copy(this.rotationAxis),s.quaternion.setFromRotationMatrix(kr.lookAt(Dr,Mr,Rr)),s.quaternion.multiply(_r),s.visible=this.dragging),"E"===this.axis&&(s.visible=!1)):"START"===s.name?(s.position.copy(this.worldPositionStart),s.visible=this.dragging):"END"===s.name?(s.position.copy(this.worldPosition),s.visible=this.dragging):"DELTA"===s.name?(s.position.copy(this.worldPositionStart),s.quaternion.copy(this.worldQuaternionStart),mr.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),mr.applyQuaternion(this.worldQuaternionStart.clone().invert()),s.scale.copy(mr),s.visible=this.dragging):(s.quaternion.copy(e),this.dragging?s.position.copy(this.worldPositionStart):s.position.copy(this.worldPosition),this.axis&&(s.visible=-1!==this.axis.search(s.name)))}super.updateMatrixWorld(t)}}class Wr extends s.Mesh{constructor(){super(new s.PlaneGeometry(1e5,1e5,2,2),new s.MeshBasicMaterial({visible:!1,wireframe:!0,side:s.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),"scale"===this.mode&&(e="local"),Vr.copy(Lr).applyQuaternion("local"===e?this.worldQuaternion:Br),jr.copy(Rr).applyQuaternion("local"===e?this.worldQuaternion:Br),Hr.copy(Fr).applyQuaternion("local"===e?this.worldQuaternion:Br),Mr.copy(jr),this.mode){case"translate":case"scale":switch(this.axis){case"X":Mr.copy(this.eye).cross(Vr),Nr.copy(Vr).cross(Mr);break;case"Y":Mr.copy(this.eye).cross(jr),Nr.copy(jr).cross(Mr);break;case"Z":Mr.copy(this.eye).cross(Hr),Nr.copy(Hr).cross(Mr);break;case"XY":Nr.copy(Hr);break;case"YZ":Nr.copy(Vr);break;case"XZ":Mr.copy(Hr),Nr.copy(jr);break;case"XYZ":case"E":Nr.set(0,0,0)}break;default:Nr.set(0,0,0)}0===Nr.length()?this.quaternion.copy(this.cameraQuaternion):(Ur.lookAt(mr.set(0,0,0),Nr,Mr),this.quaternion.setFromRotationMatrix(Ur)),super.updateMatrixWorld(t)}}class Yr{constructor(t,i,s,n,r,o=5,l=!0){if(e(this,"onDraggingStarted",new h),e(this,"onDraggingEnded",new h),e(this,"onDisposed",new h),e(this,"normal"),e(this,"origin"),e(this,"three",new a.Plane),e(this,"components"),e(this,"world"),e(this,"type","default"),e(this,"_title","Clipping Plane"),e(this,"_helper"),e(this,"_visible",!0),e(this,"_enabled",!0),e(this,"_controlsActive",!1),e(this,"_arrowBoundBox",new a.Mesh),e(this,"_planeMesh"),e(this,"_controls"),e(this,"_hiddenMaterial",new a.MeshBasicMaterial({visible:!1})),e(this,"_visibilityBeforeDisabled",!0),e(this,"notifyManager",()=>{const t=this.components.get(qr),e=t.list.getKey(this);e&&t.list.set(e,this)}),e(this,"update",()=>{this._enabled&&this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position)}),e(this,"changeDrag",t=>{this._visible=!t.value,this.preventCameraMovement(),this.notifyDraggingChanged(t)}),this.components=t,this.world=i,!i.renderer)throw new Error("The given world must have a renderer!");this.normal=n,this.origin=s,i.renderer.setPlane(!0,this.three),this._planeMesh=Yr.newPlaneMesh(o,r),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(n,s),l&&this.toggleControls(!0)}set title(t){this._title=t,this.notifyManager()}get title(){return this._title}get enabled(){return this._enabled}set enabled(t){if(!this.world.isDisposing){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=t,t?this.visible=this._visibilityBeforeDisabled:(this._visibilityBeforeDisabled=this.visible,this.visible=!1),this.world.renderer.setPlane(t,this.three),this.notifyManager()}}get visible(){return this._visible}set visible(t){this._visible=t,this._controls.getHelper().visible=t,this._helper.visible=t,this.toggleControls(t),this.notifyManager()}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(t){this._planeMesh.material=t}get size(){return this._planeMesh.scale.x}set size(t){this._planeMesh.scale.set(t,t,t)}get helper(){return this._helper}get controls(){return this._controls}setFromNormalAndCoplanarPoint(t,e){this.reset(),this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix(),this.update()}dispose(){this._enabled=!1,this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.getHelper().removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const t=new a.Vector3(1,0,0),e=new a.Vector3;this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix()}toggleControls(t){if(t){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=t}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const t=this.world.camera.three,e=this.world.renderer.three.domElement,i=new Tr(t,e);return this.initializeControls(i),this.world.scene.three.add(i.getHelper()),i}initializeControls(t){t.attach(this._helper),t.showX=!1,t.showY=!1,t.setSpace("local"),this.createArrowBoundingBox(),t.getHelper().children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new a.CylinderGeometry(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(t){t.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const t=new a.Object3D;return t.lookAt(this.normal),t.position.copy(this.origin),this._planeMesh.position.z+=.01,t.add(this._planeMesh),this.world.scene.three.add(t),t}static newPlaneMesh(t,e){const i=new a.PlaneGeometry(1),s=new a.Mesh(i,e);return s.scale.set(t,t,t),s}}class Gr extends $t{constructor(){super(...arguments),e(this,"_config",{enabled:{value:!0,type:"Boolean"},visible:{value:!0,type:"Boolean"},color:{value:new a.Color,type:"Color"},opacity:{type:"Number",interpolable:!0,value:1,min:0,max:1},size:{type:"Number",interpolable:!0,value:2,min:0,max:100}})}get enabled(){return this._config.enabled.value}set enabled(t){this._config.enabled.value=t,this._component.enabled=t}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.color.copy(t)}get opacity(){return this._config.opacity.value}set opacity(t){this._config.opacity.value=t,this._component.material.opacity=t}get size(){return this._config.size.value}set size(t){this._config.size.value=t,this._component.size=t}}const Xr=class t extends d{constructor(i){super(i),e(this,"onSetup",new h),e(this,"onBeforeDrag",new h),e(this,"onAfterDrag",new h),e(this,"onBeforeCreate",new h),e(this,"onBeforeCancel",new h),e(this,"onAfterCancel",new h),e(this,"onBeforeDelete",new h),e(this,"onAfterCreate",new h),e(this,"onAfterDelete",new h),e(this,"onDisposed",new h),e(this,"isSetup",!1),e(this,"orthogonalY",!1),e(this,"toleranceOrthogonalY",.7),e(this,"Type",Yr),e(this,"list",new o.DataMap),e(this,"config",new Gr(this,this.components,"Clipper",t.uuid)),e(this,"_defaultConfig",{color:new a.Color(12255487),opacity:.2,size:2}),e(this,"_material",new a.MeshBasicMaterial({color:12255487,side:a.DoubleSide,transparent:!0,opacity:.2})),e(this,"_size",5),e(this,"_enabled",!1),e(this,"_visible",!0),e(this,"onStateChanged",new h),e(this,"_onStartDragging",()=>{this.onBeforeDrag.trigger()}),e(this,"_onEndDragging",()=>{this.onAfterDrag.trigger()}),this.components.add(t.uuid,this),this.setEvents()}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this.onStateChanged.trigger(["enabled"])}get visible(){return this._visible}set visible(t){this._visible=t;for(const[e,i]of this.list)i.visible=t;this.onStateChanged.trigger(["visibility"])}get material(){return this._material}set material(t){this._material=t;for(const[e,i]of this.list)i.planeMaterial=t;this.onStateChanged.trigger(["material"])}get size(){return this._size}set size(t){this._size=t;for(const[e,i]of this.list)i.size=t;this.onStateChanged.trigger(["size"])}setEvents(){this.list.onBeforeDelete.add(({value:t})=>{if(!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)})}dispose(){this._enabled=!1;this.components.get(Yt).list.delete(this.config.uuid),this.list.clear(),this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async create(t){const e=this.components.get(fe).get(t),i=await e.castRay();return i?this.createPlaneFromIntersection(t,i):null}createFromNormalAndCoplanarPoint(t,e,i){const s=this.newPlane(t,i,e);return this.updateMaterialsAndPlanes(),s}async delete(t,e){if(!e){const i=await this.pickPlane(t);if(!i)return;e=this.list.getKey(i)}e&&this.list.delete(e)}deleteAll(t){for(const[e,i]of this.list)t&&!t.has(i.type)||this.list.delete(e)}setup(t){const e={...this._defaultConfig,...t};this.config.color=e.color,this.config.opacity=e.opacity,this.config.size=e.size,this.isSetup=!0,this.onSetup.trigger()}async pickPlane(t){const e=this.components.get(fe).get(t),i=this.getAllPlaneMeshes(),s=await e.castRay({items:i});if(s){const t=s.object;return[...this.list.values()].find(e=>e.meshes.includes(t))}}getAllPlaneMeshes(){const t=[];for(const[e,i]of this.list)t.push(...i.meshes);return t}createPlaneFromIntersection(t,e){var i;if(!t.renderer)throw new Error("The given world must have a renderer!");const s=e.point.distanceTo(new a.Vector3(0,0,0)),n=e.normal||(null==(i=e.face)?void 0:i.normal);if(!s||!n)return null;const r=this.getWorldNormal(e,n),o=this.newPlane(t,e.point,r.negate()),l=this.list.get(o);return l.visible=this._visible,l.size=this._size,t.renderer.setPlane(!0,l.three),this.updateMaterialsAndPlanes(),l}getWorldNormal(t,e){const i=t.object;let s=t.object.matrixWorld.clone();if(i instanceof a.InstancedMesh&&void 0!==t.instanceId){const e=new a.Matrix4;i.getMatrixAt(t.instanceId,e),s=e.multiply(s)}const n=(new a.Matrix3).getNormalMatrix(s),r=e.clone().applyMatrix3(n).normalize();return this.normalizePlaneDirectionY(r),r}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,e,i){const s=new this.Type(this.components,t,e,i,this._material);s.onDraggingStarted.add(this._onStartDragging),s.onDraggingEnded.add(this._onEndDragging);const n=v.create();return this.list.set(n,s),this.onAfterCreate.trigger(s),n}updateMaterialsAndPlanes(){const t=this.components.get(wi);for(const[e,i]of t.list){if(!i.renderer)continue;i.renderer.updateClippingPlanes();const{clippingPlanes:t}=i.renderer;for(const e of i.meshes)if(e.material)if(Array.isArray(e.material))for(const i of e.material)i.clippingPlanes=t;else e.material.clippingPlanes=t}}};e(Xr,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");let qr=Xr;class Qr{constructor(t,i){e(this,"title"),e(this,"guid",v.create()),e(this,"clippingPlanes",new o.DataSet),e(this,"camera",{aspect_ratio:1,field_of_view:60,camera_direction:{x:0,y:0,z:0},camera_view_point:{x:0,y:0,z:0},camera_up_vector:{x:0,y:1,z:0}}),e(this,"customData",{}),e(this,"exceptionComponents",new o.DataSet),e(this,"selectionComponents",new o.DataSet),e(this,"componentColors",new o.DataMap),e(this,"spacesVisible",!1),e(this,"spaceBoundariesVisible",!1),e(this,"openingsVisible",!1),e(this,"defaultVisibility",!0),e(this,"snapshot",this.guid),e(this,"_components"),e(this,"_world",null),e(this,"notifyUpdate",()=>{this._components.get(to).list.set(this.guid,this)}),this._components=t,i&&(this.guid=i.guid??this.guid,this.set(i)),this.setEvents()}async getSelectionMap(){const t=this._components.get(qt);return await t.guidsToModelIdMap([...this.selectionComponents])}async getExceptionMap(){const t=this._components.get(qt);return await t.guidsToModelIdMap([...this.exceptionComponents])}get projection(){return"field_of_view"in this.camera?"Perspective":"Orthographic"}get position(){const t=this._components.get(qt),{camera_view_point:e}=this.camera,{x:i,y:s,z:n}=e,r=new a.Vector3(i,s,n);return t.applyBaseCoordinateSystem(r,new a.Matrix4),r}set position(t){const e=t.clone(),i=this._components.get(qt);t.clone().applyMatrix4(i.baseCoordinationMatrix.clone().invert()),this.camera.camera_view_point={x:e.x,y:e.y,z:e.z}}get direction(){const{camera_direction:t}=this.camera,{x:e,y:i,z:s}=t;return new a.Vector3(e,i,s)}set world(t){this._world=t}get world(){return this._world}get _managerVersion(){return this._components.get(pr).config.version}get topics(){return[...this._components.get(pr).list.values()].filter(t=>t.viewpoints.has(this.guid))}setEvents(){this.selectionComponents.onUpdated.add(this.notifyUpdate),this.exceptionComponents.onUpdated.add(this.notifyUpdate),this.clippingPlanes.onUpdated.add(this.notifyUpdate),this.componentColors.onItemSet.add(this.notifyUpdate),this.componentColors.onItemDeleted.add(this.notifyUpdate),this.componentColors.onItemUpdated.add(this.notifyUpdate),this.componentColors.onCleared.add(this.notifyUpdate)}set(t){this.title=t.title;const{components:e,perspective_camera:i,orthogonal_camera:s,clipping_planes:n}=t;if(e){const{selection:t,visibility:i,coloring:s}=e;if(t){this.selectionComponents.clear();for(const{ifc_guid:e}of t)e&&this.selectionComponents.add(e)}if(i){const{default_visibility:t,exceptions:e,view_setup_hints:s}=i;if(void 0!==t&&(this.defaultVisibility=t),e){this.exceptionComponents.clear();for(const{ifc_guid:t}of e)t&&this.exceptionComponents.add(t)}if(s){const{spaces_visible:t,space_boundaries_visible:e,openings_visible:i}=s;void 0!==t&&(this.spacesVisible=t),void 0!==e&&(this.spaceBoundariesVisible=e),void 0!==i&&(this.openingsVisible=i)}}if(s){this.componentColors.clear();for(const t of s){const{color:e,components:i}=t,s=i.map(t=>t.ifc_guid).filter(t=>null!==t);this.componentColors.set(e,s)}}}if((i||s)&&(this.camera=i??s),n&&this.world){const t=this._components.get(qr);for(const e of n){const{location:i,direction:s}=e,n=new a.Vector3(i.x,i.z,-i.y),r=new a.Vector3(s.x,s.z,-s.y),o=t.createFromNormalAndCoplanarPoint(this.world,r,n);this.clippingPlanes.add(o),t.list.get(o).enabled=!1,t.list.get(o).visible=!1}}this.notifyUpdate()}async go(t){if(!this.world)return;const{camera:e}=this.world;if(!(e instanceof sr))throw new Error("Viewpoint: the world's camera component must be of type OrthoPerspectiveCamera to switch between perspective and orthographic projections.");const{transition:i,applyClippings:s,applyVisibility:n,clippingsVisibility:r}={transition:!0,applyClippings:!0,applyVisibility:!0,clippingsVisibility:!0,...t};e.projection.set(this.projection);const o=new a.Vector3(this.camera.camera_view_point.x,this.camera.camera_view_point.y,this.camera.camera_view_point.z),l=new a.Vector3(this.camera.camera_direction.x,this.camera.camera_direction.y,this.camera.camera_direction.z);if(o.equals(new a.Vector3)&&l.equals(new a.Vector3))return;const h=this.position,c=this.direction,d={x:h.x+80*c.x,y:h.y+80*c.y,z:h.z+80*c.z},u=[];s&&this.setClippingState(!0),n&&u.push(this.applyVisibility()),this.setClippingVisibility(r),u.push(e.controls.setLookAt(h.x,h.y,h.z,d.x,d.y,d.z,i)),await Promise.all(u)}async updateCamera(t=!0){return new Promise(e=>{if(!this.world)return void e(!1);const{camera:i,renderer:s}=this.world;if(!s)throw new Error("Viewpoint: the world needs to have a renderer!");if(!i.hasCameraControls())throw new Error("Viewpoint: world's camera need camera controls!");const n=new a.Vector3;i.controls.getPosition(n);const r=i.three,o=new a.Vector3(0,0,-1).applyEuler(r.rotation),{width:l,height:h}=s.getSize();let c=l/h;Number.isNaN(c)&&(c=1);const d=this._components.get(qt);n.applyMatrix4(d.baseCoordinationMatrix.clone().invert());const u={aspect_ratio:c,camera_view_point:{x:n.x,y:n.y,z:n.z},camera_direction:{x:o.x,y:o.y,z:o.z},camera_up_vector:{x:0,y:1,z:0}};if(r instanceof a.PerspectiveCamera?this.camera={...u,field_of_view:r.fov}:r instanceof a.OrthographicCamera&&(this.camera={...u,view_to_world_scale:r.top-r.bottom}),t){const t=this._components.get(to),n=s.three.domElement;s.three.render(this.world.scene.three,i.three),n.toBlob(async i=>{if(i){const e=await i.arrayBuffer(),s=new Uint8Array(e);t.snapshots.set(this.guid,s)}this.notifyUpdate(),e(!0)})}else this.notifyUpdate(),e(!0)})}takeSnapshot(){return new Promise(t=>{if(!this.world)return void t(!1);const{camera:e,renderer:i}=this.world;if(!i)throw new Error("Viewpoint: the world needs to have a renderer!");const s=this._components.get(to),n=i.three.domElement;i.three.render(this.world.scene.three,e.three),n.toBlob(async e=>{if(e){const t=await e.arrayBuffer(),i=new Uint8Array(t);s.snapshots.set(this.guid,i)}this.notifyUpdate(),t(!0)})})}updateClippingPlanes(){this.clippingPlanes.clear();const t=this._components.get(qr);for(const[e,i]of t.list)i.enabled&&this.clippingPlanes.add(e)}async applyVisibility(){const t=this._components.get(ee);t.set(this.defaultVisibility);const e=await this.getExceptionMap();t.set(!this.defaultVisibility,e);const i=await this.getSelectionMap();t.set(!0,i)}async setColorizationState(t){const e=this._components.get(qt),i=[];if(t)for(const[t,s]of this.componentColors){const n=`#${t}`,r=await e.guidsToModelIdMap(s);for(const[t,s]of Object.entries(r)){const r=e.list.get(t);r&&i.push(r.highlight([...s],{customId:n,color:new a.Color(n),renderedFaces:o.RenderedFaces.ONE,opacity:1,transparent:!1}))}}else for(const[t,s]of this.componentColors){const t=await e.guidsToModelIdMap(s);for(const[s,n]of Object.entries(t)){const t=e.list.get(s);t&&i.push(t.resetHighlight([...n]))}}i.push(e.core.update(!0)),await Promise.all(i)}setClippingState(t){const e=this._components.get(qr);for(const[i,s]of e.list)s.enabled=t&&this.clippingPlanes.has(i)}setClippingVisibility(t){const e=this._components.get(qr);for(const i of this.clippingPlanes){const s=e.list.get(i);s&&(s.visible=t)}}async createComponentTags(t){var e;const i=this._components.get(qt);let s="";if(this._components.get(pr).config.includeSelectionTag){const n="selection"===t?await this.getSelectionMap():await this.getExceptionMap();for(const t in n){const r=i.list.get(t);if(!r)continue;const o=n[t];for(const t of o){const i=r.getItem(t),n=await i.getGuid();if(!n)continue;const o=null==(e=await i.getAttributes())?void 0:e.getValue("Tag");let a=null;o&&(a=`AuthoringToolId="${o}"`),s+=`\n<Component IfcGuid="${n}" ${a??""} />`}}}else s=[...this.selectionComponents].map(t=>`<Component IfcGuid="${t}" />`).join("\n");return s}createColorTags(){let t="";for(const[e,i]of this.componentColors.entries()){t+=`<Color Color="${e}">\n${i.map(t=>`\n<Component IfcGuid="${t}" />`).join("\n")}\n</Color>`}return 0!==t.length?`<Coloring>\n${t}\n</Coloring>`:"<Coloring />"}toJSON(){const t=this._components.get(qr),e={guid:this.guid,components:{selection:[...this.selectionComponents].map(t=>({ifc_guid:t,authoring_tool_id:null})),coloring:[...this.componentColors].map(([t,e])=>({color:t,components:e.map(t=>({ifc_guid:t,authoring_tool_id:null}))})),visibility:{default_visibility:this.defaultVisibility,exceptions:[...this.exceptionComponents].map(t=>({ifc_guid:t,authoring_tool_id:null})),view_setup_hints:{spaces_visible:this.spacesVisible,space_boundaries_visible:this.spaceBoundariesVisible,openings_visible:this.openingsVisible}}},clipping_planes:[...this.clippingPlanes].map(e=>{const i=t.list.get(e);if(!i)return null;const s=i._controls.worldPosition??i.origin,{normal:n}=i;return{location:{x:s.x,y:-s.z,z:s.y},direction:{x:n.x,y:-n.z,z:n.y}}}).filter(t=>null!==t)};"field_of_view"in this.camera?e.perspective_camera=this.camera:e.orthogonal_camera=this.camera;const i=this._components.get(to),s=i.snapshots.get(this.snapshot);if(s){const t=s.toString(),n=btoa(t),r=i.getSnapshotExtension(this.snapshot);e.snapshot={snapshot_type:r,snapshot_data:n}}return e}async serialize(t=this._managerVersion){const e=this._components.get(qt),i=this.position;i.applyMatrix4(e.baseCoordinationMatrix.clone().invert());const s=this.direction;s.normalize();const n=(new a.Matrix4).makeRotationX(Math.PI/2),r=s.clone().applyMatrix4(n);r.normalize();const o=`<CameraViewPoint>\n <X>${i.x}</X>\n <Y>${-i.z}</Y>\n <Z>${i.y}</Z>\n </CameraViewPoint>`,l=`<CameraDirection>\n <X>${s.x}</X>\n <Y>${-s.z}</Y>\n <Z>${s.y}</Z>\n </CameraDirection>`,h=`<CameraUpVector>\n <X>${r.x}</X>\n <Y>${-r.z}</Y>\n <Z>${r.y}</Z>\n </CameraUpVector>`,c=`<AspectRatio>${this.camera.aspect_ratio}</AspectRatio>`;let d="";"view_to_world_scale"in this.camera?d=`<OrthogonalCamera>\n ${o}\n ${l}\n ${h}\n ${c}\n <ViewToWorldScale>${this.camera.view_to_world_scale}</ViewToWorldScale>\n </OrthogonalCamera>`:"field_of_view"in this.camera&&(d=`<PerspectiveCamera>\n ${o}\n ${l}\n ${h}\n ${c}\n <FieldOfView>${this.camera.field_of_view}</FieldOfView>\n </PerspectiveCamera>`);const u=`<ViewSetupHints SpacesVisible="${this.spacesVisible??!1}" SpaceBoundariesVisible="${this.spaceBoundariesVisible??!1}" OpeningsVisible="${this.openingsVisible??!1}" />`,p=(await this.createComponentTags("selection")).trim(),f=(await this.createComponentTags("exception")).trim(),m=this.createColorTags();return`<?xml version="1.0" encoding="UTF-8"?>\n <VisualizationInfo Guid="${this.guid}">\n <Components>\n ${"2.1"===t?u:""}\n ${0!==p.length?`<Selection>${p}</Selection>`:""}\n <Visibility DefaultVisibility="${this.defaultVisibility}">\n ${"3"===t?u:""}\n ${0!==f.length?`<Exceptions>${f}</Exceptions>`:""}\n </Visibility>\n ${m}\n </Components>\n ${d}\n </VisualizationInfo>`}}class Kr extends $t{constructor(){super(...arguments),e(this,"_config",{overwriteColors:{value:!1,type:"Boolean"}})}get overwriteColors(){return this._config.overwriteColors.value}set overwriteColors(t){this._config.overwriteColors.value=t}}const Jr=class t extends d{constructor(s){super(s),e(this,"enabled",!0),e(this,"world",null),e(this,"list",new i.DataMap),e(this,"snapshots",new i.DataMap),e(this,"isSetup",!1),e(this,"onSetup",new h),e(this,"config",new Kr(this,this.components,"Viewpoints",t.uuid)),e(this,"onDisposed",new h),s.add(t.uuid,this)}create(t){const e=new Qr(this.components,t);return e.world=this.world,t||this.list.set(e.guid,e),e}getSnapshotExtension(t){let e="jpeg";const i=this.snapshots.get(t);if(!i)return e;const s=i.subarray(0,4);let n="";for(let t=0;t<s.length;t++)n+=s[t].toString(16);return n.startsWith("89504e47")&&(e="png"),n.startsWith("ffd8ffe")&&(e="jpeg"),e}setup(){}dispose(){this.list.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(Jr,"uuid","ee867824-a796-408d-8aa0-4e5962a83c66");let to=Jr;class eo{constructor(t,i){e(this,"_components"),e(this,"_cameraOffset",10),e(this,"_planeHelper"),e(this,"_farPlaneHelper"),e(this,"_cameraHelper"),e(this,"onStateChanged",new h),e(this,"onUpdated",new h),e(this,"onDisposed",new h),e(this,"camera"),e(this,"plane",new a.Plane),e(this,"farPlane",new a.Plane),e(this,"id",v.create()),e(this,"_open",!1),e(this,"_range",so.defaultRange),e(this,"_world",null),e(this,"_helpersVisible",!1),e(this,"_planesEnabled",!1),this._components=t,this.camera=new sr(this._components);const{threeOrtho:s}=this.camera;if((null==i?void 0:i.id)&&(this.id=i.id),(null==i?void 0:i.normal)&&(null==i?void 0:i.point)){const{normal:t,point:e}=i;this.plane.setFromNormalAndCoplanarPoint(t,e)}this._cameraHelper=new a.CameraHelper(s),this._planeHelper=new a.PlaneHelper(this.plane,50),this._farPlaneHelper=new a.PlaneHelper(this.farPlane,50),this.farPlaneHelperColor=new a.Color("blue"),this.update()}get _planeNormalOpposite(){return this.plane.normal.clone().negate()}get _planePosition(){return this.plane.normal.clone().multiplyScalar(-this.plane.constant)}get _cameraPosition(){return this._planePosition.addScaledVector(this._planeNormalOpposite,this._cameraOffset)}set open(t){this._open=t,this.onStateChanged.trigger(["open"])}get open(){return this._open}set planeHelperColor(t){!Array.isArray(this._planeHelper.material)&&"color"in this._planeHelper.material&&this._planeHelper.material.color instanceof a.Color&&(this._planeHelper.material.color=t)}set farPlaneHelperColor(t){!Array.isArray(this._farPlaneHelper.material)&&"color"in this._farPlaneHelper.material&&this._farPlaneHelper.material.color instanceof a.Color&&(this._farPlaneHelper.material.color=t)}set range(t){this._range=t,this.update()}get range(){return this._range}set distance(t){this.plane.constant=t,this.update()}get distance(){return this.plane.constant}set world(t){this._world=t,this.camera.currentWorld=t,t&&(this.camera.projection.set("Orthographic"),this.camera.set("Plan"),this.camera.controls.dollySpeed=6,this.camera.controls.restThreshold=.005,this.update())}get world(){return this._world}set helpersVisible(t){if(!t)return this._helpersVisible=t,this._planeHelper.removeFromParent(),this._farPlaneHelper.removeFromParent(),void this._cameraHelper.removeFromParent();this.world&&(this._helpersVisible=t,this.world.scene.three.add(this._planeHelper,this._farPlaneHelper))}get helpersVisible(){return this._helpersVisible}set planesEnabled(t){const{world:e}=this;if(!e)return;const{renderer:i}=e;i&&(i.setPlane(t,this.plane),i.setPlane(t,this.farPlane),this._planesEnabled=t)}get planesEnabled(){return this._planesEnabled}dispose(){this.helpersVisible=!1;const t=this._components.get(g);t.destroy(this._planeHelper),t.destroy(this._farPlaneHelper),t.destroy(this._cameraHelper),this.camera.dispose(),this.onDisposed.trigger()}update(){if(this.world){const t=this._cameraPosition,e=this._planePosition;this.camera.controls.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,!1)}this.farPlane.normal.copy(this._planeNormalOpposite),this.farPlane.constant=this.range-this.plane.constant,this.onUpdated.trigger()}flip(){this.plane.normal.negate(),this.update()}}const io=class t extends d{constructor(s){super(s),e(this,"list",new i.DataMap),e(this,"enabled",!0),e(this,"world",null),e(this,"_fragmentsUpdateEvent",()=>{this.components.get(qt).core.update(!0)}),s.add(t.uuid,this),this.setupEvents()}get hasOpenViews(){return[...this.list.values()].some(t=>t.open)}setupEvents(){this.list.onBeforeDelete.add(({key:t,value:e})=>{e.open&&this.close(t),e.dispose()})}create(t,e,i){const s=new eo(this.components,{id:null==i?void 0:i.id,normal:t,point:e});return s.world=(null==i?void 0:i.world)??this.world,this.list.set(s.id,s),s}createFromPlane(t,e){const i=new eo(this.components,{id:null==e?void 0:e.id});return i.plane.copy(t),i.update(),i.world=(null==e?void 0:e.world)??this.world,this.list.set(i.id,i),i}async createFromIfcStoreys(t){const e=[],i=this.components.get(qt),s=void 0===(null==t?void 0:t.offset)?.25:t.offset;for(const[n,r]of i.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(n)))continue;const i=Object.values(await r.getItemsOfCategories([/BUILDINGSTOREY/])).flat();if(0===i.length)continue;const o=await r.getItemsData(i),[,l]=await r.getCoordinates(),h=new a.Vector3(0,-1,0);for(const i of o){if(!("value"in i.Name)||!("value"in i.Elevation))continue;const{value:n}=i.Name;if((null==t?void 0:t.storeyNames)&&!t.storeyNames.some(t=>t.test(n)))continue;const r=i.Elevation.value+l+s,o=new a.Plane(h,r),c=this.createFromPlane(o,{id:n,world:null==t?void 0:t.world});e.push(c)}}return e}createElevations(t){const e=[],i=this.components.get(qt),s=void 0!==(null==t?void 0:t.combine)&&t.combine,n=(null==t?void 0:t.namingCallback)??(t=>({front:""+(s?"Front":`${t}: Front`),back:""+(s?"Back":`${t}: Back`),left:""+(s?"Left":`${t}: Left`),right:""+(s?"Right":`${t}: Right`)}));let r=[];for(const[e,s]of i.list)t&&t.modelIds&&!t.modelIds.some(t=>t.test(e))||r.push({id:e,box:s.box});if(s){const t=this.components.get(se);t.list.clear(),t.list.add(...r.map(t=>t.box));r=[{id:"combined",box:t.get()}]}for(const{id:i,box:s}of r){const{min:r,max:o}=s,l=Math.abs(o.x-r.x),h=Math.abs(o.z-r.z),c=new a.Vector3;s.getCenter(c);const d=new a.Plane(new a.Vector3(0,0,-1),o.z),u=new a.Plane(new a.Vector3(0,0,1),-r.z),p=new a.Plane(new a.Vector3(-1,0,0),o.x),f=new a.Plane(new a.Vector3(1,0,0),-r.x),{front:m,back:g,left:_,right:y}=n(i),w=this.createFromPlane(d,{id:m,world:null==t?void 0:t.world});w.range=h;const v=this.createFromPlane(u,{id:g,world:null==t?void 0:t.world});v.range=h;const b=this.createFromPlane(p,{id:_,world:null==t?void 0:t.world});b.range=l;const x=this.createFromPlane(f,{id:y,world:null==t?void 0:t.world});x.range=l,e.push(w,v,b,x)}return e}open(t){const e=this.list.get(t);if(!e)throw new Error(`Views: the view with id ${t} doesn't exist.`);if(e.open)return;const{world:i}=e;if(!i)throw new Error(`Views: no world found for view with id ${t}.`);const{renderer:s}=i;if(!s)throw new Error(`Views: no renderer found for world with id ${i.uuid}.`);for(const[,t]of this.list)t.world===i&&this.close(t.id);s.setPlane(!0,e.plane),s.setPlane(!0,e.farPlane),e.camera.controls.addEventListener("rest",this._fragmentsUpdateEvent),i.camera=e.camera,e.open=!0}close(t){let e;if(e=t?this.list.get(t):[...this.list.values()].find(t=>t.open),t&&!e)throw new Error(`Views: the view with id ${t} doesn't exist.`);if(!e)return;if(!e.open)return;const{world:i}=e;if(!i)throw new Error(`Views: no world found for view with id ${t}.`);const{renderer:s}=i;if(!s)throw new Error(`Views: no renderer found for world with id ${i.uuid}.`);s.setPlane(!1,e.plane),s.setPlane(!1,e.farPlane),e.camera.controls.removeEventListener("rest",this._fragmentsUpdateEvent),i.useDefaultCamera(),e.open=!1}};e(io,"uuid","fb22f1f5-6598-4664-a11d-de8963ae420f"),e(io,"defaultRange",15);let so=io;async function no(t,e,i,s,n,r,o){const a=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),await function(t,e,i,s){return new Promise((n,r)=>{!function o(){const a=t.clientWaitSync(e,i,0);a!==t.WAIT_FAILED?a!==t.TIMEOUT_EXPIRED?n():setTimeout(o,s):r()}()})}(t,a,0,10),t.deleteSync(a),t.bindBuffer(e,i),t.getBufferSubData(e,s,n,r,o),t.bindBuffer(e,null)}class ro{constructor(t,i){if(e(this,"onDisposed",new h),e(this,"onDistanceComputed",new h),e(this,"excludedObjects",new Set),e(this,"enabled",!0),e(this,"renderDebugFrame",!1),e(this,"components"),e(this,"scene",new a.Scene),e(this,"camera",new a.OrthographicCamera(-1,1,1,-1,0,1)),e(this,"depthMaterial"),e(this,"world"),e(this,"worker"),e(this,"_width",512),e(this,"_height",512),e(this,"_postQuad"),e(this,"tempRT"),e(this,"resultRT"),e(this,"bufferSize"),e(this,"_buffer"),e(this,"_isWorkerBusy",!1),e(this,"compute",async()=>{if(!this.enabled||this.world.isDisposing)return;if(this._isWorkerBusy)return;this._isWorkerBusy=!0,this.world.camera.three.updateMatrix();const t=this.world.renderer.three;t.setRenderTarget(this.tempRT);const e="visibilityBeforeDistanceCheck";for(const t of this.excludedObjects)t.userData[e]=t.visible,t.visible=!1;t.render(this.world.scene.three,this.world.camera.three);for(const t of this.excludedObjects)void 0!==t.userData[e]&&(t.visible=t.userData[e]);this.depthMaterial.uniforms.tDiffuse.value=this.tempRT.texture,this.depthMaterial.uniforms.tDepth.value=this.tempRT.depthTexture,t.setRenderTarget(this.resultRT),t.render(this.scene,this.camera);const i=t.getContext();try{await async function(t,e,i,s,n,r,o,a){const l=t.createBuffer();return t.bindBuffer(t.PIXEL_PACK_BUFFER,l),t.bufferData(t.PIXEL_PACK_BUFFER,a.byteLength,t.STREAM_READ),t.readPixels(e,i,s,n,r,o,0),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),await no(t,t.PIXEL_PACK_BUFFER,l,0,a),t.deleteBuffer(l),a}(i,0,0,this._width,this._height,i.RGBA,i.UNSIGNED_BYTE,this._buffer)}catch(e){return t.setRenderTarget(null),void(this._isWorkerBusy=!1)}t.setRenderTarget(null),this.renderDebugFrame&&t.render(this.scene,this.camera),this.worker.postMessage({buffer:this._buffer})}),e(this,"handleWorkerMessage",t=>{if(!this.enabled||this.world.isDisposing)return;const e=t.data.colors;let i=Number.MAX_VALUE;for(const t of e)0!==t&&t<i&&(i=t);const s=this.world.camera.three||a.OrthographicCamera,n=-1*(i/255-1)*(s.far-s.near),r=Math.min(n,s.far);this.onDistanceComputed.trigger(r),this._isWorkerBusy=!1}),!i.renderer)throw new Error("The given world must have a renderer!");this.components=t,this.world=i;const s=i.camera.three;this.tempRT=new a.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.tempRT.texture.minFilter=a.NearestFilter,this.tempRT.texture.magFilter=a.NearestFilter,this.tempRT.stencilBuffer=!1,this.tempRT.samples=0,this.tempRT.depthTexture=new a.DepthTexture(this._width,this._height),this.tempRT.depthTexture.format=a.DepthFormat,this.tempRT.depthTexture.type=a.UnsignedShortType,this.resultRT=new a.WebGLRenderTarget(this._width,this._height),this.depthMaterial=new a.ShaderMaterial({vertexShader:"\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n ",fragmentShader:"\n#include <packing>\n\nvarying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform sampler2D tDepth;\nuniform float cameraNear;\nuniform float cameraFar;\n\n\nfloat readDepth( sampler2D depthSampler, vec2 coord ) {\n float fragCoordZ = texture2D( depthSampler, coord ).x;\n float viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );\n return viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );\n}\n\nvoid main() {\n //vec3 diffuse = texture2D( tDiffuse, vUv ).rgb;\n float depth = readDepth( tDepth, vUv );\n\n gl_FragColor.rgb = 1.0 - vec3( depth );\n gl_FragColor.a = 1.0;\n}\n ",uniforms:{cameraNear:{value:s.near},cameraFar:{value:s.far},tDiffuse:{value:null},tDepth:{value:null}}});const n=new a.PlaneGeometry(2,2);this._postQuad=new a.Mesh(n,this.depthMaterial),this.scene.add(this._postQuad);const r=new Blob(['\n addEventListener("message", (event) => {\n const { buffer } = event.data;\n const colors = new Set();\n for (let i = 0; i < buffer.length; i += 4) {\n const r = buffer[i];\n colors.add(r);\n }\n postMessage({ colors });\n });\n '],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(r)),this.worker.addEventListener("message",this.handleWorkerMessage)}dispose(){this.enabled=!1,this.onDistanceComputed.reset(),this.worker.terminate(),this.tempRT.dispose(),this.resultRT.dispose();const t=[...this.scene.children];this.excludedObjects.clear();for(const e of t)e.removeFromParent();this._postQuad.geometry.dispose(),this._postQuad.removeFromParent(),this._buffer=null,this.onDisposed.reset()}}class oo{constructor(t){e(this,"cardinality","required"),e(this,"instructions"),e(this,"evalRequirement",(t,e,i,s)=>{const n={parameter:i,currentValue:t,requiredValue:e,pass:!1};s&&this.addCheckResult(n,s);let r=!1;if("simple"===e.type&&(r=t===e.parameter),"enumeration"===e.type&&(r=e.parameter.includes(t)),"pattern"===e.type){r=new RegExp(e.parameter).test(String(t))}if("length"===e.type){const{min:i,length:s,max:n}=e.parameter;void 0!==s&&(r=String(t).length===s),void 0!==i&&(r=String(t).length>=i),void 0!==n&&(r=String(t).length<=n)}if("bounds"===e.type&&"number"==typeof t){const{min:i,minInclusive:s,max:n,maxInclusive:o}=e.parameter;let a=!0,l=!0;void 0!==i&&(a=s?t>=i:t>i),void 0!==n&&(l=o?t<=n:t<n),r=a&&l}return"prohibited"===this.cardinality&&(r=!r),"optional"===this.cardinality&&(r=!0),n.pass=r,n.pass}),this._components=t}addCheckResult(t,e){const i=e.findIndex(({parameter:e})=>e===t.parameter);-1!==i?e[i]=t:e.push(t)}getItemChecks(t,e,i,s){if(!("value"in i._localId)||"number"!=typeof i._localId.value)return null;let n=t.get(e);n||(n=new o.DataMap,t.set(e,n));let r=n.get(i._localId.value);if(r&&s&&!r.pass)return null;if(!r){const t=[];r={guid:Array.isArray(i._guid)?void 0:i._guid.value,pass:!1,checks:t},Object.defineProperty(r,"pass",{get:()=>t.every(({pass:t})=>t)}),n.set(i._localId.value,r)}const a=[],l={facetType:this.facetType,cardinality:this.cardinality,checks:a,pass:!1};return Object.defineProperty(l,"pass",{get:()=>a.every(({pass:t})=>t)}),r.checks.push(l),l.checks}}const ao=(t,e)=>{let i="";if(!e)return i;if("simple"===e.type&&(i=`<simpleValue>${e.parameter}</simpleValue>`),"enumeration"===e.type){i=`<xs:restriction base="xs:string">\n ${e.parameter.map(t=>`<xs:enumeration value="${t}" />`).join("\n")}\n </xs:restriction>`}if("pattern"===e.type){i=`<xs:restriction base="xs:string">\n <xs:pattern value="${e.parameter}" />\n </xs:restriction>`}if("bounds"===e.type){const{min:t,minInclusive:s,max:n,maxInclusive:r}=e.parameter;let o="";void 0!==t&&(o=`<xs:min${s?"Inclusive":"Exclusive"} value="${t}">`);let a="";void 0!==n&&(a=`<xs:max${r?"Inclusive":"Exclusive"} value="${n}">`),i=`<xs:restriction base="xs:double">\n ${o}\n ${a}\n </xs:restriction>`}if("length"===e.type){const{length:t,min:s,max:n}=e.parameter;let r="";void 0!==t&&void 0===s&&void 0===n&&(r=`<xs:length value="${t}" />`);let o="";void 0!==s&&void 0===t&&(o=`<xs:minLength value="${s}" />`);let a="";void 0!==n&&void 0===t&&(a=`<xs:maxLength value="${n}" />`),i=`<xs:restriction base="xs:string">\n ${r}\n ${o}\n ${a}\n </xs:restriction>`}return`<${t[0].toLowerCase()+t.slice(1)}>\n ${i}\n </${t[0].toLowerCase()+t.slice(1)}>`};class lo extends oo{constructor(t,i){super(t),e(this,"facetType","Attribute"),e(this,"name"),e(this,"value"),this.name=i}serialize(t){const e=ao("Name",this.name),i=ao("Value",this.value);let s="";return"requirement"===t&&(s+=`cardinality="${this.cardinality}"`,s+=this.instructions?`instructions="${this.instructions}"`:""),`<attribute ${s}>\n ${e}\n ${i}\n</attribute>`}async getEntities(){}async test(t,e,i={skipIfFails:!0}){const s=this._components.get(qt);for(const[n,r]of Object.entries(t)){const t=s.list.get(n);if(!t)continue;const o=await t.getItemsData([...r]);for(const t of o){const s=this.getItemChecks(e,n,t,i.skipIfFails);if(!s)continue;const r=Object.keys(t).filter(e=>{const i=this.evalRequirement(e,this.name,"Name");if(!i)return!1;const s=t[e];return!!Array.isArray(s)||(null===s||null===s.value?"optional"===this.cardinality||"prohibited"===this.cardinality:(!Array.isArray(s.value)||0!==s.value.length)&&(("string"!=typeof s.value||""!==s.value.trim())&&i))}),o=r.length>0;if(s.push({parameter:"Name",currentValue:o?r[0]:null,requiredValue:this.name,pass:"prohibited"===this.cardinality?!o:o}),this.value)if(r[0]){const e=t[r[0]];if(Array.isArray(e))s.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality});else{Array.isArray(e.value)?s.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality}):this.evalRequirement(e.value,this.value,"Value",s)}}else s.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality})}}}}class ho extends oo{constructor(t,i){super(t),e(this,"facetType","Classification"),e(this,"system"),e(this,"value"),e(this,"uri"),this.system=i}serialize(t){const e=ao("System",this.system),i=ao("Value",this.value);let s="";return"requirement"===t&&(s+=`cardinality="${this.cardinality}"`,s+=this.uri?`uri=${this.uri}`:"",s+=this.instructions?`instructions="${this.instructions}"`:""),`<classification ${s}>\n ${e}\n ${i}\n</classification>`}async getEntities(t,e){}async test(t,e){}}class co extends oo{constructor(t,i){super(t),e(this,"facetType","Entity"),e(this,"name"),e(this,"predefinedType"),this.name=i}serialize(t){const e=ao("Name",this.name),i=ao("Name",this.predefinedType);let s="";return"requirement"===t&&(s+=`cardinality="${this.cardinality}"`,s+=this.instructions?`instructions="${this.instructions}"`:""),`<entity ${s}>\n ${e}\n ${i}\n</entity>`}async getEntities(t,e){const i=this._components.get(qt),s=new Map;for(const[e,n]of i.list){if(!t.find(t=>t.test(e)))continue;const i=await n.getCategories();for(const t of i){if(!await this.evalName(t))continue;let i=s.get(e);i||(i=[],s.set(e,i)),i.push(t)}}const n={};if(await Promise.all(Array.from(s.entries()).map(async([t,e])=>{const s=i.list.get(t);if(!s)return;const r=e.map(t=>new RegExp(`^${t}$`)),o=await s.getItemsOfCategories(r),a=Object.values(o).flat();n[t]=new Set(a)})),this.predefinedType)for(const[t,s]of Object.entries(n)){const n=i.list.get(t);if(!n)continue;const r=await n.getItemsData([...s]);for(const i of r){if(!("value"in i._localId))continue;await this.evalPredefinedType(t,i)&&jt.append(e,t,i._localId.value)}}else jt.add(e,n)}async test(t,e,i){const s=this._components.get(qt);for(const[n,r]of Object.entries(t)){const t=s.list.get(n);if(!t)continue;const o=await t.getItemsData([...r]);for(const t of o){if(!("value"in t._category))continue;const s=this.getItemChecks(e,n,t,i.skipIfFails);s&&(await this.evalName(t._category.value,s),await this.evalPredefinedType(n,t,s))}}}async evalName(t,e){return this.evalRequirement(t,this.name,"Name",e)}async evalPredefinedType(t,e,i){if(!this.predefinedType)return null;if(!("value"in e.PredefinedType))return null;const s="string"==typeof this.predefinedType.parameter&&"USERDEFINED"===this.predefinedType.parameter;let n=e.PredefinedType.value;if("USERDEFINED"===n&&!s){const t=Object.keys(e).find(t=>/^((?!Predefined).)*Type$/.test(t));if(t){const i=e[t];"value"in i&&(n=i.value)}else n="USERDEFINED"}if(!n){const i=this._components.get(qt).list.get(t);if(i&&"value"in e._localId){const[t]=await i.getItemsData([e._localId.value],{relations:{IsTypedBy:{attributes:!0,relations:!1}}});if(Array.isArray(t.IsTypedBy)){const e=t.IsTypedBy[0];if(e&&"value"in e.PredefinedType&&(n=e.PredefinedType.value,"USERDEFINED"===n&&!s)){const t=Object.keys(e).find(t=>/^((?!Predefined).)*Type$/.test(t));if(t){const i=e[t];"value"in i&&(n=i.value)}else n="USERDEFINED"}}}}return this.evalRequirement(n,this.predefinedType,"PredefinedType",i)}}class uo extends oo{constructor(t,i,s){super(t),e(this,"facetType","Property"),e(this,"propertySet"),e(this,"baseName"),e(this,"value"),e(this,"dataType"),e(this,"uri"),e(this,"_unsupportedTypes",["IFCCOMPLEXPROPERTY","IFCPHYSICALCOMPLEXQUANTITY"]),this.propertySet=i,this.baseName=s}serialize(t){const e=ao("PropertySet",this.propertySet),i=ao("BaseName",this.baseName),s=ao("Value",this.value),n=this.dataType?`dataType=${this.dataType}`:"";let r="";return"requirement"===t&&(r+=`cardinality="${this.cardinality}"`,r+=this.uri?`uri=${this.uri}`:"",r+=this.instructions?`instructions="${this.instructions}"`:""),`<property ${n} ${r}>\n ${e}\n ${i}\n ${s}\n</property>`}async getEntities(t,e){const i=this._components.get(qt);for(const[s,n]of i.list){if(!t.find(t=>t.test(s)))continue;const i=await n.getItemsOfCategories([/PROPERTYSET/,/ELEMENTQUANTITY/]),r=Object.values(i).flat();if(0===r.length)continue;const o=await n.getItemsData(r,{relations:{HasProperties:{attributes:!0,relations:!1},DefinesOcurrence:{attributes:!0,relations:!1}}});for(const t of o){if(!("value"in t._localId&&"value"in t._category&&"value"in t.Name&&Array.isArray(t.DefinesOcurrence)))continue;if(!this.evalRequirement(t.Name.value,this.propertySet,"PropertySet"))continue;let i;if("IFCPROPERTYSET"===t._category.value&&(i="HasProperties"),"IFCELEMENTQUANTITY"===t._category.value&&(i="Quantities"),!i)continue;const n=t[i];if(Array.isArray(n))for(const i of n){const n=Object.keys(i),r=n.find(t=>/Name/.test(t));if(!r||!("value"in i[r]))continue;const o=i[r];if(!("value"in o))continue;if(!this.evalRequirement(o.value,this.baseName,"BaseName"))continue;if(this.value){const t=n.find(t=>/Value/.test(t));if(!t)continue;const e=i[t];if(!("value"in e))continue;if(!this.evalRequirement(e.value,this.value,"Value"))continue}const a=t.DefinesOcurrence.map(t=>"value"in t._localId&&"number"==typeof t._localId.value?t._localId.value:null).filter(t=>null!==t);jt.append(e,s,...a)}}}}async test(t,e,i={skipIfFails:!0}){const s=this._components.get(qt);for(const[n,r]of Object.entries(t)){const t=s.list.get(n);if(!t)continue;const o=await t.getItemsData([...r],{relations:{IsDefinedBy:{attributes:!0,relations:!0},IsTypedBy:{attributes:!0,relations:!1},HasPropertySets:{attributes:!0,relations:!0},DefinesOcurrence:{attributes:!1,relations:!1}}});for(const t of o){const s=this.getItemChecks(e,n,t,i.skipIfFails);if(!s)continue;const r=(await this.getPsets(t)).filter(t=>{if(!("value"in t.Name))return!1;return!!this.evalRequirement(t.Name.value,this.propertySet,"PropertySet")&&(s.push({currentValue:t.Name.value,parameter:"PropertySet",pass:!0,requiredValue:this.propertySet}),!0)});if(0!==r.length)for(const t of r){const e=this.getPropertyListName(t);if(!e)continue;const i=t[e];if(!Array.isArray(i)){s.push({currentValue:null,parameter:"BaseName",pass:!1,requiredValue:this.baseName});continue}const n=i.filter(t=>{if(!("value"in t._category)||!("value"in t.Name))return!1;if(this._unsupportedTypes.includes(t._category.value))return!1;return!!this.evalRequirement(t.Name.value,this.baseName,"BaseName")&&(s.push({currentValue:t.Name.value,parameter:"BaseName",pass:!0,requiredValue:this.baseName}),!0)});if(0!==n.length)for(const t of n)this.evalValue(t,s),this.evalDataType(t,s),this.evalURI();else s.push({currentValue:null,parameter:"BaseName",pass:!1,requiredValue:this.baseName})}else s.push({currentValue:null,parameter:"PropertySet",pass:!1,requiredValue:this.propertySet})}}}getPropertyListName(t){let e;return"value"in t._category?("IFCPROPERTYSET"===t._category.value&&(e="HasProperties"),"IFCELEMENTQUANTITY"===t._category.value&&(e="Quantities"),e):e}getValueKey(t){return Object.keys(t).find(t=>/Value/.test(t)||/Values/.test(t))}getTypePsets(t){if(!Array.isArray(t.IsTypedBy))return[];const[e]=t.IsTypedBy;return e&&Array.isArray(e.HasPropertySets)?e.HasPropertySets:[]}async getPsets(t){const e=this.getTypePsets(t);if(!Array.isArray(t.IsDefinedBy))return e;const i=[];for(const s of t.IsDefinedBy){if(!("value"in s.Name))continue;const t=s.Name.value,n=this.getPropertyListName(s);if(!t||!n)continue;const r=e.find(e=>"value"in e.Name&&e.Name.value===t);if(r&&Array.isArray(r.HasProperties)&&Array.isArray(s.HasProperties))for(const t of r.HasProperties){if(!("value"in t.Name))continue;const e=t.Name.value;s.HasProperties.find(t=>"value"in t.Name&&t.Name.value===e)||s.HasProperties.push(t)}i.push(s)}return i}evalValue(t,e){const i=this.getValueKey(t),s=t[i];if(!("value"in s))return!1;if(this.value){if(!i)return null==e||e.push({parameter:"Value",currentValue:null,pass:!1,requiredValue:this.value}),!1;const t=structuredClone(this.value);"IFCLABEL"===s.type&&"simple"===t.type&&(t.parameter=String(t.parameter));return this.evalRequirement(s.value,t,"Value",e)}return!i||("string"!=typeof s.value||""!==s.value.trim()||(null==e||e.push({parameter:"Value",currentValue:"",pass:!1,requiredValue:this.value}),!1))}evalDataType(t,e){if(!this.dataType)return!0;const i=this.getValueKey(t);if(!i||!("value"in t[i]))return null==e||e.push({parameter:"DataType",currentValue:null,pass:!1,requiredValue:this.dataType}),!1;const s=t[i];return this.evalRequirement(s.type??null,{type:"simple",parameter:this.dataType},"DataType",e)}evalURI(){return!0}}class po extends oo{constructor(){super(...arguments),e(this,"_ifcMaterialEntities",[/^IFCMATERIALLAYERSETUSAGE$/,/^IFCMATERIALCONSTITUENTSET$/,/^IFCMATERIAL$/,/^IFCMATERIALLIST$/]),e(this,"facetType","Material"),e(this,"value"),e(this,"uri")}serialize(t){if(!this.value||!this.uri)return"<material />";const e=ao("Value",this.value);let i="";return"requirement"===t&&(i+=`cardinality="${this.cardinality}"`,i+=this.uri?`uri=${this.uri}`:"",i+=this.instructions?`instructions="${this.instructions}"`:""),`<material ${i}>\n ${e}\n</material>`}async getEntities(t,e){const i=this._components.get(qt);for(const[s,n]of i.list){if(!t.find(t=>t.test(s)))continue;const i=await n.getItemsOfCategories(this._ifcMaterialEntities),r=Object.values(i).flat();if(0===r.length)continue;const o=await n.getItemsData(r,{relations:{AssociatedTo:{attributes:!0,relations:!1},MaterialConstituents:{attributes:!0,relations:!0},ForLayerSet:{attributes:!0,relations:!0},MaterialLayers:{attributes:!0,relations:!0},Materials:{attributes:!0,relations:!1}}});for(const t of o){if(!("value"in t._localId&&"value"in t._category&&Array.isArray(t.AssociatedTo)))continue;if(!this.hasValidMaterial(t))continue;const i=t.AssociatedTo.map(t=>"value"in t._localId&&t._localId.value?t._localId.value:null).filter(t=>null!==t);jt.append(e,s,...i)}}}async test(t,e,i={skipIfFails:!0}){const s=this._components.get(qt);for(const[n,r]of Object.entries(t)){const t=s.list.get(n);if(!t)continue;const o=await t.getItemsData([[...r][0]],{relations:{AssociatedTo:{attributes:!1,relations:!1},HasAssociations:{attributes:!0,relations:!0},MaterialConstituents:{attributes:!0,relations:!0},ForLayerSet:{attributes:!0,relations:!0},MaterialLayers:{attributes:!0,relations:!0},Materials:{attributes:!0,relations:!1}}});for(const t of o){const s=this.getItemChecks(e,n,t,i.skipIfFails);if(s)if(Array.isArray(t.HasAssociations))for(const e of t.HasAssociations){if(!this._ifcMaterialEntities.some(t=>"value"in e._category&&t.test(e._category.value)))continue;if(this.hasValidMaterial(e,s))break}else s.push({parameter:null,currentValue:null,requiredValue:this.value,pass:!1})}}}hasValidMaterial(t,e){let i=!1;if("value"in t._category&&"IFCMATERIAL"===t._category.value){this.evalValue(t,e)&&(i=!0)}else for(const[s,n]of Object.entries(t))if(["ForLayerSet","MaterialLayers","Material","MaterialConstituents","Materials"].includes(s)&&Array.isArray(n))for(const t of n){if("value"in t._category&&"IFCMATERIAL"===t._category.value){if(this.evalValue(t,e)){i=!0;break}}else{if(this.hasValidMaterial(t)){i=!0;break}}}return i}evalValue(t,e){if(!this.value)return null==e||e.push({parameter:null,currentValue:t.Name&&"value"in t.Name?t.Name.value:null,pass:!0}),!0;if(!("value"in t._category)||"IFCMATERIAL"!==t._category.value)return null;let i=!1;return t.Name&&"value"in t.Name&&(i=this.evalRequirement(t.Name.value,this.value,"Value",e)),i||(t.Category&&"value"in t.Category&&(i=this.evalRequirement(t.Category.value,this.value,"Value",e)),i)}}class fo extends oo{constructor(t,i){super(t),e(this,"facetType","PartOf"),e(this,"_entityFacet"),e(this,"_entity"),e(this,"relation"),e(this,"cardinality","required"),this._entity=i,this._entityFacet=new co(t,i.name),this._entityFacet.predefinedType=i.predefinedType}set entity(t){this._entity=t;const{name:e,predefinedType:i}=t;this._entityFacet=new co(this._components,e),this._entityFacet.predefinedType=i}get entity(){return this._entity}serialize(){return""}async getEntities(t,e){}async test(t){}}class mo{constructor(t,i,s){e(this,"name"),e(this,"ifcVersion",new Set),e(this,"identifier",v.create()),e(this,"description"),e(this,"instructions"),e(this,"requirementsDescription"),e(this,"applicability",new o.DataSet),e(this,"requirements",new o.DataSet),e(this,"components"),this.components=t,this.name=i;for(const t of s)this.ifcVersion.add(t)}set(t){const e=t,i=this;for(const s in t){if("identifier"===s)continue;const t=e[s];s in this&&(i[s]=t)}return this.components.get(Co).list.set(this.identifier,this),this}async test(t,e={skipIfFails:!0}){const i=new o.DataMap;if(0===this.requirements.size)return i;const s={},n=[];for(const e of this.applicability)n.push(e.getEntities(t,s));await Promise.all(n);const r=[];for(const t of this.requirements)r.push(t.test(s,i,e));return await Promise.all(r),i}serialize(){const t=`name="${this.name}"`,e=this.identifier?`identifier="${this.identifier}"`:"",i=this.description?`description="${this.description}"`:"",s=this.instructions?`instructions="${this.instructions}"`:"";return`<specification ifcVersion="${[...this.ifcVersion].join(" ")}" ${t} ${e} ${i} ${s}>\n <applicability minOccurs="1" maxOccurs="unbounded">\n ${[...this.applicability].map(t=>t.serialize("applicability")).join("\n")}\n </applicability>\n <requirements>\n ${[...this.requirements].map(t=>t.serialize("requirement")).join("\n")}\n </requirements>\n </specification>`}}const go=t=>{if(!t)return;const e={};if("simpleValue"in t&&(e.type="simple",e.parameter=t.simpleValue),"restriction"in t){const i=t.restriction,s=Object.keys(i);if("pattern"in i&&(e.type="pattern",e.parameter=i.pattern.value),"enumeration"in i){e.type="enumeration";const t=i.enumeration.map(({value:t})=>i.base.includes("string")?String(t):i.base.includes("integer")||i.base.includes("double")?Number(t):t);e.parameter=t}if(s.some(t=>["minInclusive","minExclusive","maxInclusive","maxExclusive"].includes(t))){e.type="bounds";const t={},n=s.find(t=>t.includes("min")),r=s.find(t=>t.includes("max"));n&&(t.minInclusive="minInclusive"===n,t.min=i[n].value),r&&(t.maxInclusive="maxInclusive"===r,t.max=i[r].value),e.parameter=t}if(s.some(t=>["minLength","length","maxLength"].includes(t))){e.type="length";const t={};void 0!==i.length&&(t.length=i.length.value),void 0!==i.minLength&&(t.min=i.minLength.value),void 0!==i.maxLength&&(t.max=i.maxLength.value),e.parameter=t}}return void 0!==e.parameter?e:void 0},_o=(t,e)=>{const i=[];for(const s of e){const e=s.name,n=go(e);if(!n)continue;const r=new co(t,n);s.cardinality&&(r.cardinality=s.cardinality),r.predefinedType=go(s.predefinedType),r.instructions=s.instructions,i.push(r)}return i},yo=(t,e)=>{const i=[];for(const s of e){const e=s.name,n=go(e);if(!n)continue;const r=new lo(t,n);s.cardinality&&(r.cardinality=s.cardinality),r.value=go(s.value),r.instructions=s.instructions,i.push(r)}return i},wo=(t,e)=>{const i=[];for(const s of e){const e=new po(t);s.cardinality&&(e.cardinality=s.cardinality);const n=go(s.value);"enumeration"===(null==n?void 0:n.type)&&Array.isArray(n.parameter)&&(n.parameter=n.parameter.map(String)),e.value=n,e.uri=s.uri,e.instructions=s.instructions,i.push(e)}return i},vo=(t,e)=>{const i=[];for(const s of e){const e=s.propertySet,n=s.baseName,r=go(e),o=go(n);if(!o||!r)continue;const a=new uo(t,r,o);s.cardinality&&(a.cardinality=s.cardinality);const l=go(s.value);a.value=l,a.dataType=s.dataType,a.uri=s.uri,a.instructions=s.instructions,i.push(a)}return i},bo=(t,e)=>{const i=[];for(const s of e){const e=s.system,n=go(e);if(!n)continue;const r=new ho(t,n);s.cardinality&&(r.cardinality=s.cardinality);const o=go(s.value);"simple"===(null==o?void 0:o.type)&&(o.parameter=String(o.parameter)),"enumeration"===(null==o?void 0:o.type)&&Array.isArray(o.parameter)&&(o.parameter=o.parameter.map(String)),r.value=o,r.uri=s.uri,r.instructions=s.instructions,i.push(r)}return i},xo=(t,e)=>{const i=[];for(const s of e){const e=go(s.entity.name);if(!e)continue;const n=go(s.entity.predefinedType),r=new fo(t,{name:e,predefinedType:n});r.relation=s.relation,s.cardinality&&(r.cardinality=s.cardinality),r.instructions=s.instructions,i.push(r)}return i},To=class t extends d{constructor(s){super(s),e(this,"enabled",!0),e(this,"IDSInfo"),e(this,"list",new i.DataMap),s.add(t.uuid,this)}getModelIdMap(t){const e={},i={};for(const[s,n]of t){const t=[...n].filter(([,t])=>t.pass).map(([t])=>t);jt.append(e,s,...t);const r=[...n].filter(([,t])=>!t.pass).map(([t])=>t);jt.append(i,s,...r)}return{pass:e,fail:i}}create(t,e,i){const s=new mo(this.components,t,e);return i&&(s.identifier=i),this.list.set(s.identifier,s),s}load(e){const i=[],s=t.xmlParser.parse(e).ids,{specifications:n,info:r}=s;if(this.IDSInfo={...r},n&&n.specification){const t=Array.isArray(n.specification)?n.specification:[n.specification];for(const e of t){const{name:t,ifcVersion:s,description:n,instructions:r,identifier:o}=e;if(!t||!s)continue;const a=[],l=[],{applicability:h,requirements:c}=e;if(h){const{maxOccurs:t,...e}=h,i=Array.isArray(e)?e:[e];for(const t of i)for(const e in t){const i=Array.isArray(t[e])?t[e]:[t[e]];if("entity"===e){const t=_o(this.components,i);a.push(...t)}if("attribute"===e){const t=yo(this.components,i);a.push(...t)}if("material"===e){const t=wo(this.components,i);a.push(...t)}if("classification"===e){const t=bo(this.components,i);a.push(...t)}if("property"===e){const t=vo(this.components,i);a.push(...t)}if("partOf"===e){const t=xo(this.components,i);a.push(...t)}}}let d;if(c){const{maxOccurs:t,...e}=c;d=c.description;const i=Array.isArray(e)?e:[e];for(const t of i)for(const e in t){const i=Array.isArray(t[e])?t[e]:[t[e]];if("entity"===e){const t=_o(this.components,i);l.push(...t)}if("attribute"===e){const t=yo(this.components,i);l.push(...t)}if("material"===e){const t=wo(this.components,i);l.push(...t)}if("classification"===e){const t=bo(this.components,i);l.push(...t)}if("property"===e){const t=vo(this.components,i);l.push(...t)}if("partOf"===e){const t=xo(this.components,i);l.push(...t)}}}const u=this.create(t,s.split(/\s+/),o);u.description=n,u.instructions=r,u.requirementsDescription=d,u.applicability.add(...a),u.requirements.add(...l),i.push(u)}}return i}export(t,e=this.list.values()){const i=e??this.list;return`<ids xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://standards.buildingsmart.org/IDS http://standards.buildingsmart.org/IDS/1.0/ids.xsd" xmlns:ids="http://standards.buildingsmart.org/IDS">\n \x3c!-- Made with That Open Engine ${Kn.release} (https://github.com/thatopen/engine_components) --\x3e\n <info>\n <title>${t.title}</title>\n ${t.copyright?`<copyright>${t.copyright}</copyright>`:""}\n ${t.version?`<version>${t.version}</version>`:""}\n ${t.description?`<description>${t.description}</description>`:""}\n ${t.author?`<author>${t.author}</author>`:""}\n ${t.date?`<date>${t.date.toISOString().split("T")[0]}</date>`:""}\n ${t.purpose?`<purpose>${t.purpose}</purpose>`:""}\n ${t.milestone?`<milestone>${t.milestone}</milestone>`:""}\n </info>\n <specifications>\n ${[...i].map(t=>t.serialize()).join("\n")}\n </specifications>\n</ids>`}};e(To,"uuid","9f0b9f78-9b2e-481a-b766-2fbfd01f342c"),e(To,"xmlParser",new Ft.XMLParser({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0}));let Co=To;const Eo=class t extends d{constructor(i){super(i),e(this,"enabled",!0),i.add(t.uuid,this)}static distanceFromPointToLine(t,e,i,s=!1){const n=new a.Line3,r=new a.Vector3;return n.set(e,i),n.closestPointToPoint(t,s,r),r.distanceTo(t)}round(t){const e=1e3;t.x=Math.trunc(t.x*e)/e,t.y=Math.trunc(t.y*e)/e,t.z=Math.trunc(t.z*e)/e}async getVolumeFromFragments(t){return console.warn("getVolumeFromFragments is deprecated. Use getItemsVolume instead."),this.getItemsVolume(t)}async getItemsVolume(t){let e=0;const i=this.components.get(qt);for(const[s,n]of Object.entries(t)){const t=i.list.get(s);t&&(e+=await t.getItemsVolume([...n]))}return e}static convertUnits(t,e,i,s=2){const n={m:1,cm:.01,mm:.001,km:1e3,m2:1,cm2:1e-4,mm2:1e-6,km2:1e6,m3:1,cm3:1e-6,mm3:1e-9,km3:1e9};if(!n[e]||!n[i])throw new Error("Invalid units provided for conversion.");if(!Number.isInteger(s)||s<0||s>5)throw new Error("Precision must be an integer between 0 and 5.");const r=t*(n[e]/n[i]),o=10**s;return Math.round(r*o)/o}};e(Eo,"uuid","267ca032-672f-4cb0-afa9-d24e904f39d6");let So=Eo;exports.AsyncEvent=class{constructor(){e(this,"enabled",!0),e(this,"trigger",async t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)await i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}},exports.BCFTopics=pr,exports.BCFTopicsConfigManager=dr,exports.Base=c,exports.BaseCamera=p,exports.BaseRenderer=f,exports.BaseScene=_,exports.BaseWorldItem=u,exports.BoundingBoxer=se,exports.Classifier=le,exports.Clipper=qr,exports.Comment=ar,exports.Component=d,exports.Components=Kn,exports.ConfigManager=Yt,exports.Configurator=$t,exports.ControlsUtils=Zt,exports.DataMap=Ht,exports.DataSet=y,exports.Disposer=g,exports.Event=h,exports.EventManager=class{constructor(){e(this,"list",new Set)}add(t){for(const e of t)this.list.add(e)}remove(t){for(const e of t)this.list.delete(e)}set(t){for(const e of this.list)e.enabled=t}reset(){for(const t of this.list)t.reset()}},exports.FastModelPicker=he,exports.FastModelPickers=de,exports.FinderQuery=ne,exports.FirstPersonMode=Jn,exports.FragmentsManager=qt,exports.Grids=Ti,exports.Hider=ee,exports.IDSAttribute=lo,exports.IDSClassification=ho,exports.IDSEntity=co,exports.IDSFacet=oo,exports.IDSMaterial=po,exports.IDSPartOf=fo,exports.IDSProperty=uo,exports.IDSSpecification=mo,exports.IDSSpecifications=Co,exports.IfcFragmentSettings=Qt,exports.IfcLoader=Jt,exports.ItemsFinder=oe,exports.MeasurementUtils=So,exports.ModelIdMapUtils=jt,exports.Mouse=Gt,exports.OrbitMode=tr,exports.OrthoPerspectiveCamera=sr,exports.PlanMode=er,exports.ProjectionManager=ir,exports.Raycasters=fe,exports.RendererMode=ve,exports.ShadowedScene=class extends we{constructor(){super(...arguments),e(this,"_distanceRenderer"),e(this,"autoBias",!0),e(this,"_defaultShadowConfig",{cascade:1,resolution:512}),e(this,"_lightsWithShadow",new Map),e(this,"_isComputingShadows",!1),e(this,"_shadowsEnabled",!0),e(this,"_bias",0),e(this,"recomputeShadows",t=>{if(!this._shadowsEnabled)return;this.autoBias&&(this.bias=-.005);if(t*=1.5,!this.currentWorld)throw new Error("A world needs to be assigned to the scene before computing shadows!");if(!this._lightsWithShadow.size)throw new Error("No shadows found!");const e=this.currentWorld.camera.three;if(!(e instanceof a.PerspectiveCamera||e instanceof a.OrthographicCamera))throw new Error("Invalid camera type!");const i=new a.Vector3;e.getWorldDirection(i);let s=t;const n=new a.Vector3;n.copy(this.config.directionalLight.position),n.normalize();for(const[t,r]of this._lightsWithShadow){const o=this.directionalLights.get(r);if(!o)throw new Error("Light not found.");const l=new a.Vector3;l.copy(i);const h=t===this._lightsWithShadow.size-1,c=h?s/2:2*s/3;l.multiplyScalar(c),l.add(e.position);const d=s-c,u=new a.Vector3;u.copy(n),u.multiplyScalar(d),o.target.position.copy(l),o.position.copy(l),o.position.add(u),o.shadow.camera.right=d,o.shadow.camera.left=-d,o.shadow.camera.top=d,o.shadow.camera.bottom=-d,o.shadow.camera.far=2*d,o.shadow.camera.updateProjectionMatrix(),o.shadow.camera.updateMatrix(),h||(s/=3)}this._isComputingShadows=!1})}get bias(){return this._bias}set bias(t){this._bias=t;for(const[,e]of this._lightsWithShadow){const i=this.directionalLights.get(e);i&&(i.shadow.bias=t)}}get shadowsEnabled(){return this._shadowsEnabled}set shadowsEnabled(t){this._shadowsEnabled=t;for(const[,e]of this.directionalLights)e.castShadow=t}get distanceRenderer(){if(!this._distanceRenderer)throw new Error("You must set up this component before accessing the distance renderer!");return this._distanceRenderer}setup(t){super.setup(t);const e={...this._defaultConfig,...this._defaultShadowConfig,...t};if(e.cascade<=0)throw new Error("Config.shadows.cascade must be a natural number greater than 0!");if(e.cascade>1)throw new Error("Multiple shadows not supported yet!");if(!this.currentWorld)throw new Error("A world needs to be assigned to the scene before setting it up!");for(const[,t]of this.directionalLights)t.target.removeFromParent(),t.removeFromParent(),t.dispose();this.directionalLights.clear(),this._distanceRenderer||(this._distanceRenderer=new ro(this.components,this.currentWorld),this._distanceRenderer.onDistanceComputed.add(this.recomputeShadows)),this._lightsWithShadow.clear();for(let t=0;t<e.cascade;t++){const i=new a.DirectionalLight;i.intensity=this.config.directionalLight.intensity,i.color=this.config.directionalLight.color,i.position.copy(this.config.directionalLight.position),i.shadow.mapSize.width=e.resolution,i.shadow.mapSize.height=e.resolution,this.three.add(i,i.target),this.directionalLights.set(i.uuid,i),this._lightsWithShadow.set(t,i.uuid),i.castShadow=!0,i.shadow.bias=this._bias}}dispose(){super.dispose(),this._distanceRenderer&&this._distanceRenderer.dispose(),this._lightsWithShadow.clear()}async updateShadows(){!this._isComputingShadows&&this._shadowsEnabled&&(this._isComputingShadows=!0,await this.distanceRenderer.compute())}},exports.SimpleCamera=_i,exports.SimpleGrid=bi,exports.SimpleGridConfigManager=vi,exports.SimplePlane=Yr,exports.SimpleRaycaster=ue,exports.SimpleRenderer=class extends f{constructor(t,i,s){super(t),e(this,"enabled",!0),e(this,"container"),e(this,"three"),e(this,"mode",1),e(this,"needsUpdate",!1),e(this,"_canvas"),e(this,"_parameters"),e(this,"_resizeObserver",null),e(this,"onContainerUpdated",new h),e(this,"_resizing",!1),e(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(e,i),this.onResize.trigger(new a.Vector2(e,i)),this._resizing=!1}),e(this,"resizeEvent",()=>{this.resize()}),e(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1}),e(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new a.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0}),this.container=i,this._parameters=s,this.three=new a.WebGLRenderer({antialias:!0,alpha:!0,...s}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const n=this.three.getContext(),{canvas:r}=n;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;if(0===this.mode&&!this.needsUpdate)return;this.needsUpdate=!1,this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,e=this.currentWorld.camera.three;this.three.render(t,e),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new a.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}},exports.SimpleScene=we,exports.SimpleSceneConfigManager=ye,exports.SimpleWorld=me,exports.Topic=hr,exports.UUID=v,exports.VertexPicker=class extends d{constructor(t,i){super(t),e(this,"onDisposed",new h),e(this,"onVertexFound",new h),e(this,"onVertexLost",new h),e(this,"onEnabled",new h),e(this,"components"),e(this,"workingPlane",null),e(this,"_pickedPoint",null),e(this,"_config"),e(this,"_enabled",!1),this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...i},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}async get(t){if(!this.enabled)return this._pickedPoint;const e=this.components.get(fe).get(t),i=await e.castRay();if(!i)return null!==this._pickedPoint&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const s=i.point;return null!==this._pickedPoint&&this._pickedPoint.equals(s)||(this._pickedPoint=s.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint}},exports.View=eo,exports.Viewpoint=Qr,exports.Viewpoints=to,exports.Views=so,exports.Worlds=wi,exports.XML=Vt,exports.extensionsImporter=cr;
12
+ */const as=ss(os.exports=function t(e,i,n){function s(o,a){if(!i[o]){if(!e[o]){if(!a&&rs)return rs(o);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[o]={exports:{}};e[o][0].call(c.exports,function(t){return s(e[o][1][t]||t)},c,c.exports,t,e,i,n)}return i[o].exports}for(var r=rs,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,i){var n=t("./utils"),s=t("./support"),r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.encode=function(t){for(var e,i,s,o,a,l,c,h=[],u=0,d=t.length,p=d,f="string"!==n.getTypeOf(t);u<t.length;)p=d-u,s=f?(e=t[u++],i=u<d?t[u++]:0,u<d?t[u++]:0):(e=t.charCodeAt(u++),i=u<d?t.charCodeAt(u++):0,u<d?t.charCodeAt(u++):0),o=e>>2,a=(3&e)<<4|i>>4,l=1<p?(15&i)<<2|s>>6:64,c=2<p?63&s:64,h.push(r.charAt(o)+r.charAt(a)+r.charAt(l)+r.charAt(c));return h.join("")},i.decode=function(t){var e,i,n,o,a,l,c=0,h=0,u="data:";if(t.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var d,p=3*(t=t.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(t.charAt(t.length-1)===r.charAt(64)&&p--,t.charAt(t.length-2)===r.charAt(64)&&p--,p%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=s.uint8array?new Uint8Array(0|p):new Array(0|p);c<t.length;)e=r.indexOf(t.charAt(c++))<<2|(o=r.indexOf(t.charAt(c++)))>>4,i=(15&o)<<4|(a=r.indexOf(t.charAt(c++)))>>2,n=(3&a)<<6|(l=r.indexOf(t.charAt(c++))),d[h++]=e,64!==a&&(d[h++]=i),64!==l&&(d[h++]=n);return d}},{"./support":30,"./utils":32}],2:[function(t,e,i){var n=t("./external"),s=t("./stream/DataWorker"),r=t("./stream/Crc32Probe"),o=t("./stream/DataLengthProbe");function a(t,e,i,n,s){this.compressedSize=t,this.uncompressedSize=e,this.crc32=i,this.compression=n,this.compressedContent=s}a.prototype={getContentWorker:function(){var t=new s(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o("data_length")),e=this;return t.on("end",function(){if(this.streamInfo.data_length!==e.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),t},getCompressedWorker:function(){return new s(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},a.createWorkerFrom=function(t,e,i){return t.pipe(new r).pipe(new o("uncompressedSize")).pipe(e.compressWorker(i)).pipe(new o("compressedSize")).withStreamInfo("compression",e)},e.exports=a},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(t,e,i){var n=t("./stream/GenericWorker");i.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},i.DEFLATE=t("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(t,e,i){var n=t("./utils"),s=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e){return void 0!==t&&t.length?"string"!==n.getTypeOf(t)?function(t,e,i,n){var r=s,o=n+i;t^=-1;for(var a=n;a<o;a++)t=t>>>8^r[255&(t^e[a])];return-1^t}(0|e,t,t.length,0):function(t,e,i,n){var r=s,o=n+i;t^=-1;for(var a=n;a<o;a++)t=t>>>8^r[255&(t^e.charCodeAt(a))];return-1^t}(0|e,t,t.length,0):0}},{"./utils":32}],5:[function(t,e,i){i.base64=!1,i.binary=!1,i.dir=!1,i.createFolders=!0,i.date=null,i.compression=null,i.compressionOptions=null,i.comment=null,i.unixPermissions=null,i.dosPermissions=null},{}],6:[function(t,e,i){var n=null;n="undefined"!=typeof Promise?Promise:t("lie"),e.exports={Promise:n}},{lie:37}],7:[function(t,e,i){var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,s=t("pako"),r=t("./utils"),o=t("./stream/GenericWorker"),a=n?"uint8array":"array";function l(t,e){o.call(this,"FlateWorker/"+t),this._pako=null,this._pakoAction=t,this._pakoOptions=e,this.meta={}}i.magic="\b\0",r.inherits(l,o),l.prototype.processChunk=function(t){this.meta=t.meta,null===this._pako&&this._createPako(),this._pako.push(r.transformTo(a,t.data),!1)},l.prototype.flush=function(){o.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},l.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},l.prototype._createPako=function(){this._pako=new s[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta})}},i.compressWorker=function(t){return new l("Deflate",t)},i.uncompressWorker=function(){return new l("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(t,e,i){function n(t,e){var i,n="";for(i=0;i<e;i++)n+=String.fromCharCode(255&t),t>>>=8;return n}function s(t,e,i,s,o,h){var u,d,p=t.file,f=t.compression,m=h!==a.utf8encode,g=r.transformTo("string",h(p.name)),y=r.transformTo("string",a.utf8encode(p.name)),w=p.comment,v=r.transformTo("string",h(w)),b=r.transformTo("string",a.utf8encode(w)),_=y.length!==p.name.length,x=b.length!==w.length,S="",C="",A="",E=p.dir,T=p.date,I={crc32:0,compressedSize:0,uncompressedSize:0};e&&!i||(I.crc32=t.crc32,I.compressedSize=t.compressedSize,I.uncompressedSize=t.uncompressedSize);var P=0;e&&(P|=8),m||!_&&!x||(P|=2048);var M,k,D,z=0,B=0;E&&(z|=16),"UNIX"===o?(B=798,z|=(M=p.unixPermissions,k=E,D=M,M||(D=k?16893:33204),(65535&D)<<16)):(B=20,z|=function(t){return 63&(t||0)}(p.dosPermissions)),u=T.getUTCHours(),u<<=6,u|=T.getUTCMinutes(),u<<=5,u|=T.getUTCSeconds()/2,d=T.getUTCFullYear()-1980,d<<=4,d|=T.getUTCMonth()+1,d<<=5,d|=T.getUTCDate(),_&&(C=n(1,1)+n(l(g),4)+y,S+="up"+n(C.length,2)+C),x&&(A=n(1,1)+n(l(v),4)+b,S+="uc"+n(A.length,2)+A);var O="";return O+="\n\0",O+=n(P,2),O+=f.magic,O+=n(u,2),O+=n(d,2),O+=n(I.crc32,4),O+=n(I.compressedSize,4),O+=n(I.uncompressedSize,4),O+=n(g.length,2),O+=n(S.length,2),{fileRecord:c.LOCAL_FILE_HEADER+O+g+S,dirRecord:c.CENTRAL_FILE_HEADER+n(B,2)+O+n(v.length,2)+"\0\0\0\0"+n(z,4)+n(s,4)+g+S+v}}var r=t("../utils"),o=t("../stream/GenericWorker"),a=t("../utf8"),l=t("../crc32"),c=t("../signature");function h(t,e,i,n){o.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=e,this.zipPlatform=i,this.encodeFileName=n,this.streamFiles=t,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}r.inherits(h,o),h.prototype.push=function(t){var e=t.meta.percent||0,i=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(t):(this.bytesWritten+=t.data.length,o.prototype.push.call(this,{data:t.data,meta:{currentFile:this.currentFile,percent:i?(e+100*(i-n-1))/i:100}}))},h.prototype.openedSource=function(t){this.currentSourceOffset=this.bytesWritten,this.currentFile=t.file.name;var e=this.streamFiles&&!t.file.dir;if(e){var i=s(t,e,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:i.fileRecord,meta:{percent:0}})}else this.accumulate=!0},h.prototype.closedSource=function(t){this.accumulate=!1;var e,i=this.streamFiles&&!t.file.dir,r=s(t,i,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),i)this.push({data:(e=t,c.DATA_DESCRIPTOR+n(e.crc32,4)+n(e.compressedSize,4)+n(e.uncompressedSize,4)),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},h.prototype.flush=function(){for(var t=this.bytesWritten,e=0;e<this.dirRecords.length;e++)this.push({data:this.dirRecords[e],meta:{percent:100}});var i,s,o,a,l,h,u=this.bytesWritten-t,d=(i=this.dirRecords.length,s=u,o=t,a=this.zipComment,l=this.encodeFileName,h=r.transformTo("string",l(a)),c.CENTRAL_DIRECTORY_END+"\0\0\0\0"+n(i,2)+n(i,2)+n(s,4)+n(o,4)+n(h.length,2)+h);this.push({data:d,meta:{percent:100}})},h.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},h.prototype.registerPrevious=function(t){this._sources.push(t);var e=this;return t.on("data",function(t){e.processChunk(t)}),t.on("end",function(){e.closedSource(e.previous.streamInfo),e._sources.length?e.prepareNextSource():e.end()}),t.on("error",function(t){e.error(t)}),this},h.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},h.prototype.error=function(t){var e=this._sources;if(!o.prototype.error.call(this,t))return!1;for(var i=0;i<e.length;i++)try{e[i].error(t)}catch(t){}return!0},h.prototype.lock=function(){o.prototype.lock.call(this);for(var t=this._sources,e=0;e<t.length;e++)t[e].lock()},e.exports=h},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(t,e,i){var n=t("../compressions"),s=t("./ZipFileWorker");i.generateWorker=function(t,e,i){var r=new s(e.streamFiles,i,e.platform,e.encodeFileName),o=0;try{t.forEach(function(t,i){o++;var s=function(t,e){var i=t||e,s=n[i];if(!s)throw new Error(i+" is not a valid compression method !");return s}(i.options.compression,e.compression),a=i.options.compressionOptions||e.compressionOptions||{},l=i.dir,c=i.date;i._compressWorker(s,a).withStreamInfo("file",{name:t,dir:l,date:c,comment:i.comment||"",unixPermissions:i.unixPermissions,dosPermissions:i.dosPermissions}).pipe(r)}),r.entriesCount=o}catch(t){r.error(t)}return r}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(t,e,i){function n(){if(!(this instanceof n))return new n;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var t=new n;for(var e in this)"function"!=typeof this[e]&&(t[e]=this[e]);return t}}(n.prototype=t("./object")).loadAsync=t("./load"),n.support=t("./support"),n.defaults=t("./defaults"),n.version="3.10.1",n.loadAsync=function(t,e){return(new n).loadAsync(t,e)},n.external=t("./external"),e.exports=n},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(t,e,i){var n=t("./utils"),s=t("./external"),r=t("./utf8"),o=t("./zipEntries"),a=t("./stream/Crc32Probe"),l=t("./nodejsUtils");function c(t){return new s.Promise(function(e,i){var n=t.decompressed.getContentWorker().pipe(new a);n.on("error",function(t){i(t)}).on("end",function(){n.streamInfo.crc32!==t.decompressed.crc32?i(new Error("Corrupted zip : CRC32 mismatch")):e()}).resume()})}e.exports=function(t,e){var i=this;return e=n.extend(e||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:r.utf8decode}),l.isNode&&l.isStream(t)?s.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):n.prepareContent("the loaded zip file",t,!0,e.optimizedBinaryString,e.base64).then(function(t){var i=new o(e);return i.load(t),i}).then(function(t){var i=[s.Promise.resolve(t)],n=t.files;if(e.checkCRC32)for(var r=0;r<n.length;r++)i.push(c(n[r]));return s.Promise.all(i)}).then(function(t){for(var s=t.shift(),r=s.files,o=0;o<r.length;o++){var a=r[o],l=a.fileNameStr,c=n.resolve(a.fileNameStr);i.file(c,a.decompressed,{binary:!0,optimizedBinaryString:!0,date:a.date,dir:a.dir,comment:a.fileCommentStr.length?a.fileCommentStr:null,unixPermissions:a.unixPermissions,dosPermissions:a.dosPermissions,createFolders:e.createFolders}),a.dir||(i.file(c).unsafeOriginalName=l)}return s.zipComment.length&&(i.comment=s.zipComment),i})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(t,e,i){var n=t("../utils"),s=t("../stream/GenericWorker");function r(t,e){s.call(this,"Nodejs stream input adapter for "+t),this._upstreamEnded=!1,this._bindStream(e)}n.inherits(r,s),r.prototype._bindStream=function(t){var e=this;(this._stream=t).pause(),t.on("data",function(t){e.push({data:t,meta:{percent:0}})}).on("error",function(t){e.isPaused?this.generatedError=t:e.error(t)}).on("end",function(){e.isPaused?e._upstreamEnded=!0:e.end()})},r.prototype.pause=function(){return!!s.prototype.pause.call(this)&&(this._stream.pause(),!0)},r.prototype.resume=function(){return!!s.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},e.exports=r},{"../stream/GenericWorker":28,"../utils":32}],13:[function(t,e,i){var n=t("readable-stream").Readable;function s(t,e,i){n.call(this,e),this._helper=t;var s=this;t.on("data",function(t,e){s.push(t)||s._helper.pause(),i&&i(e)}).on("error",function(t){s.emit("error",t)}).on("end",function(){s.push(null)})}t("../utils").inherits(s,n),s.prototype._read=function(){this._helper.resume()},e.exports=s},{"../utils":32,"readable-stream":16}],14:[function(t,e,i){e.exports={isNode:"undefined"!=typeof Buffer,newBufferFrom:function(t,e){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(t,e);if("number"==typeof t)throw new Error('The "data" argument must not be a number');return new Buffer(t,e)},allocBuffer:function(t){if(Buffer.alloc)return Buffer.alloc(t);var e=new Buffer(t);return e.fill(0),e},isBuffer:function(t){return Buffer.isBuffer(t)},isStream:function(t){return t&&"function"==typeof t.on&&"function"==typeof t.pause&&"function"==typeof t.resume}}},{}],15:[function(t,e,i){function n(t,e,i){var n,s=r.getTypeOf(e),a=r.extend(i||{},l);a.date=a.date||new Date,null!==a.compression&&(a.compression=a.compression.toUpperCase()),"string"==typeof a.unixPermissions&&(a.unixPermissions=parseInt(a.unixPermissions,8)),a.unixPermissions&&16384&a.unixPermissions&&(a.dir=!0),a.dosPermissions&&16&a.dosPermissions&&(a.dir=!0),a.dir&&(t=m(t)),a.createFolders&&(n=f(t))&&g.call(this,n,!0);var u="string"===s&&!1===a.binary&&!1===a.base64;i&&void 0!==i.binary||(a.binary=!u),(e instanceof c&&0===e.uncompressedSize||a.dir||!e||0===e.length)&&(a.base64=!1,a.binary=!0,e="",a.compression="STORE",s="string");var y=null;y=e instanceof c||e instanceof o?e:d.isNode&&d.isStream(e)?new p(t,e):r.prepareContent(t,e,a.binary,a.optimizedBinaryString,a.base64);var w=new h(t,y,a);this.files[t]=w}var s=t("./utf8"),r=t("./utils"),o=t("./stream/GenericWorker"),a=t("./stream/StreamHelper"),l=t("./defaults"),c=t("./compressedObject"),h=t("./zipObject"),u=t("./generate"),d=t("./nodejsUtils"),p=t("./nodejs/NodejsStreamInputAdapter"),f=function(t){"/"===t.slice(-1)&&(t=t.substring(0,t.length-1));var e=t.lastIndexOf("/");return 0<e?t.substring(0,e):""},m=function(t){return"/"!==t.slice(-1)&&(t+="/"),t},g=function(t,e){return e=void 0!==e?e:l.createFolders,t=m(t),this.files[t]||n.call(this,t,null,{dir:!0,createFolders:e}),this.files[t]};function y(t){return"[object RegExp]"===Object.prototype.toString.call(t)}var w={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(t){var e,i,n;for(e in this.files)n=this.files[e],(i=e.slice(this.root.length,e.length))&&e.slice(0,this.root.length)===this.root&&t(i,n)},filter:function(t){var e=[];return this.forEach(function(i,n){t(i,n)&&e.push(n)}),e},file:function(t,e,i){if(1!==arguments.length)return t=this.root+t,n.call(this,t,e,i),this;if(y(t)){var s=t;return this.filter(function(t,e){return!e.dir&&s.test(t)})}var r=this.files[this.root+t];return r&&!r.dir?r:null},folder:function(t){if(!t)return this;if(y(t))return this.filter(function(e,i){return i.dir&&t.test(e)});var e=this.root+t,i=g.call(this,e),n=this.clone();return n.root=i.name,n},remove:function(t){t=this.root+t;var e=this.files[t];if(e||("/"!==t.slice(-1)&&(t+="/"),e=this.files[t]),e&&!e.dir)delete this.files[t];else for(var i=this.filter(function(e,i){return i.name.slice(0,t.length)===t}),n=0;n<i.length;n++)delete this.files[i[n].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(t){var e,i={};try{if((i=r.extend(t||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:s.utf8encode})).type=i.type.toLowerCase(),i.compression=i.compression.toUpperCase(),"binarystring"===i.type&&(i.type="string"),!i.type)throw new Error("No output type specified.");r.checkSupport(i.type),"darwin"!==i.platform&&"freebsd"!==i.platform&&"linux"!==i.platform&&"sunos"!==i.platform||(i.platform="UNIX"),"win32"===i.platform&&(i.platform="DOS");var n=i.comment||this.comment||"";e=u.generateWorker(this,i,n)}catch(t){(e=new o("error")).error(t)}return new a(e,i.type||"string",i.mimeType)},generateAsync:function(t,e){return this.generateInternalStream(t).accumulate(e)},generateNodeStream:function(t,e){return(t=t||{}).type||(t.type="nodebuffer"),this.generateInternalStream(t).toNodejsStream(e)}};e.exports=w},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(t,e,i){e.exports=t("stream")},{stream:void 0}],17:[function(t,e,i){var n=t("./DataReader");function s(t){n.call(this,t);for(var e=0;e<this.data.length;e++)t[e]=255&t[e]}t("../utils").inherits(s,n),s.prototype.byteAt=function(t){return this.data[this.zero+t]},s.prototype.lastIndexOfSignature=function(t){for(var e=t.charCodeAt(0),i=t.charCodeAt(1),n=t.charCodeAt(2),s=t.charCodeAt(3),r=this.length-4;0<=r;--r)if(this.data[r]===e&&this.data[r+1]===i&&this.data[r+2]===n&&this.data[r+3]===s)return r-this.zero;return-1},s.prototype.readAndCheckSignature=function(t){var e=t.charCodeAt(0),i=t.charCodeAt(1),n=t.charCodeAt(2),s=t.charCodeAt(3),r=this.readData(4);return e===r[0]&&i===r[1]&&n===r[2]&&s===r[3]},s.prototype.readData=function(t){if(this.checkOffset(t),0===t)return[];var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./DataReader":18}],18:[function(t,e,i){var n=t("../utils");function s(t){this.data=t,this.length=t.length,this.index=0,this.zero=0}s.prototype={checkOffset:function(t){this.checkIndex(this.index+t)},checkIndex:function(t){if(this.length<this.zero+t||t<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+t+"). Corrupted zip ?")},setIndex:function(t){this.checkIndex(t),this.index=t},skip:function(t){this.setIndex(this.index+t)},byteAt:function(){},readInt:function(t){var e,i=0;for(this.checkOffset(t),e=this.index+t-1;e>=this.index;e--)i=(i<<8)+this.byteAt(e);return this.index+=t,i},readString:function(t){return n.transformTo("string",this.readData(t))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var t=this.readInt(4);return new Date(Date.UTC(1980+(t>>25&127),(t>>21&15)-1,t>>16&31,t>>11&31,t>>5&63,(31&t)<<1))}},e.exports=s},{"../utils":32}],19:[function(t,e,i){var n=t("./Uint8ArrayReader");function s(t){n.call(this,t)}t("../utils").inherits(s,n),s.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(t,e,i){var n=t("./DataReader");function s(t){n.call(this,t)}t("../utils").inherits(s,n),s.prototype.byteAt=function(t){return this.data.charCodeAt(this.zero+t)},s.prototype.lastIndexOfSignature=function(t){return this.data.lastIndexOf(t)-this.zero},s.prototype.readAndCheckSignature=function(t){return t===this.readData(4)},s.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./DataReader":18}],21:[function(t,e,i){var n=t("./ArrayReader");function s(t){n.call(this,t)}t("../utils").inherits(s,n),s.prototype.readData=function(t){if(this.checkOffset(t),0===t)return new Uint8Array(0);var e=this.data.subarray(this.zero+this.index,this.zero+this.index+t);return this.index+=t,e},e.exports=s},{"../utils":32,"./ArrayReader":17}],22:[function(t,e,i){var n=t("../utils"),s=t("../support"),r=t("./ArrayReader"),o=t("./StringReader"),a=t("./NodeBufferReader"),l=t("./Uint8ArrayReader");e.exports=function(t){var e=n.getTypeOf(t);return n.checkSupport(e),"string"!==e||s.uint8array?"nodebuffer"===e?new a(t):s.uint8array?new l(n.transformTo("uint8array",t)):new r(n.transformTo("array",t)):new o(t)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(t,e,i){i.LOCAL_FILE_HEADER="PK",i.CENTRAL_FILE_HEADER="PK",i.CENTRAL_DIRECTORY_END="PK",i.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",i.ZIP64_CENTRAL_DIRECTORY_END="PK",i.DATA_DESCRIPTOR="PK\b"},{}],24:[function(t,e,i){var n=t("./GenericWorker"),s=t("../utils");function r(t){n.call(this,"ConvertWorker to "+t),this.destType=t}s.inherits(r,n),r.prototype.processChunk=function(t){this.push({data:s.transformTo(this.destType,t.data),meta:t.meta})},e.exports=r},{"../utils":32,"./GenericWorker":28}],25:[function(t,e,i){var n=t("./GenericWorker"),s=t("../crc32");function r(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}t("../utils").inherits(r,n),r.prototype.processChunk=function(t){this.streamInfo.crc32=s(t.data,this.streamInfo.crc32||0),this.push(t)},e.exports=r},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(t,e,i){var n=t("../utils"),s=t("./GenericWorker");function r(t){s.call(this,"DataLengthProbe for "+t),this.propName=t,this.withStreamInfo(t,0)}n.inherits(r,s),r.prototype.processChunk=function(t){if(t){var e=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=e+t.data.length}s.prototype.processChunk.call(this,t)},e.exports=r},{"../utils":32,"./GenericWorker":28}],27:[function(t,e,i){var n=t("../utils"),s=t("./GenericWorker");function r(t){s.call(this,"DataWorker");var e=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,t.then(function(t){e.dataIsReady=!0,e.data=t,e.max=t&&t.length||0,e.type=n.getTypeOf(t),e.isPaused||e._tickAndRepeat()},function(t){e.error(t)})}n.inherits(r,s),r.prototype.cleanUp=function(){s.prototype.cleanUp.call(this),this.data=null},r.prototype.resume=function(){return!!s.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},r.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},r.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var t=null,e=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":t=this.data.substring(this.index,e);break;case"uint8array":t=this.data.subarray(this.index,e);break;case"array":case"nodebuffer":t=this.data.slice(this.index,e)}return this.index=e,this.push({data:t,meta:{percent:this.max?this.index/this.max*100:0}})},e.exports=r},{"../utils":32,"./GenericWorker":28}],28:[function(t,e,i){function n(t){this.name=t||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}n.prototype={push:function(t){this.emit("data",t)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(t){this.emit("error",t)}return!0},error:function(t){return!this.isFinished&&(this.isPaused?this.generatedError=t:(this.isFinished=!0,this.emit("error",t),this.previous&&this.previous.error(t),this.cleanUp()),!0)},on:function(t,e){return this._listeners[t].push(e),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(t,e){if(this._listeners[t])for(var i=0;i<this._listeners[t].length;i++)this._listeners[t][i].call(this,e)},pipe:function(t){return t.registerPrevious(this)},registerPrevious:function(t){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=t.streamInfo,this.mergeStreamInfo(),this.previous=t;var e=this;return t.on("data",function(t){e.processChunk(t)}),t.on("end",function(){e.end()}),t.on("error",function(t){e.error(t)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var t=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),t=!0),this.previous&&this.previous.resume(),!t},flush:function(){},processChunk:function(t){this.push(t)},withStreamInfo:function(t,e){return this.extraStreamInfo[t]=e,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var t in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,t)&&(this.streamInfo[t]=this.extraStreamInfo[t])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var t="Worker "+this.name;return this.previous?this.previous+" -> "+t:t}},e.exports=n},{}],29:[function(t,e,i){var n=t("../utils"),s=t("./ConvertWorker"),r=t("./GenericWorker"),o=t("../base64"),a=t("../support"),l=t("../external"),c=null;if(a.nodestream)try{c=t("../nodejs/NodejsStreamOutputAdapter")}catch(t){}function h(t,e){return new l.Promise(function(i,s){var r=[],a=t._internalType,l=t._outputType,c=t._mimeType;t.on("data",function(t,i){r.push(t),e&&e(i)}).on("error",function(t){r=[],s(t)}).on("end",function(){try{var t=function(t,e,i){switch(t){case"blob":return n.newBlob(n.transformTo("arraybuffer",e),i);case"base64":return o.encode(e);default:return n.transformTo(t,e)}}(l,function(t,e){var i,n=0,s=null,r=0;for(i=0;i<e.length;i++)r+=e[i].length;switch(t){case"string":return e.join("");case"array":return Array.prototype.concat.apply([],e);case"uint8array":for(s=new Uint8Array(r),i=0;i<e.length;i++)s.set(e[i],n),n+=e[i].length;return s;case"nodebuffer":return Buffer.concat(e);default:throw new Error("concat : unsupported type '"+t+"'")}}(a,r),c);i(t)}catch(t){s(t)}r=[]}).resume()})}function u(t,e,i){var o=e;switch(e){case"blob":case"arraybuffer":o="uint8array";break;case"base64":o="string"}try{this._internalType=o,this._outputType=e,this._mimeType=i,n.checkSupport(o),this._worker=t.pipe(new s(o)),t.lock()}catch(t){this._worker=new r("error"),this._worker.error(t)}}u.prototype={accumulate:function(t){return h(this,t)},on:function(t,e){var i=this;return"data"===t?this._worker.on(t,function(t){e.call(i,t.data,t.meta)}):this._worker.on(t,function(){n.delay(e,arguments,i)}),this},resume:function(){return n.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(t){if(n.checkSupport("nodestream"),"nodebuffer"!==this._outputType)throw new Error(this._outputType+" is not supported by this method");return new c(this,{objectMode:"nodebuffer"!==this._outputType},t)}},e.exports=u},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(t,e,i){if(i.base64=!0,i.array=!0,i.string=!0,i.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,i.nodebuffer="undefined"!=typeof Buffer,i.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)i.blob=!1;else{var n=new ArrayBuffer(0);try{i.blob=0===new Blob([n],{type:"application/zip"}).size}catch(t){try{var s=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);s.append(n),i.blob=0===s.getBlob("application/zip").size}catch(t){i.blob=!1}}}try{i.nodestream=!!t("readable-stream").Readable}catch(t){i.nodestream=!1}},{"readable-stream":16}],31:[function(t,e,i){for(var n=t("./utils"),s=t("./support"),r=t("./nodejsUtils"),o=t("./stream/GenericWorker"),a=new Array(256),l=0;l<256;l++)a[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function c(){o.call(this,"utf-8 decode"),this.leftOver=null}function h(){o.call(this,"utf-8 encode")}a[254]=a[254]=1,i.utf8encode=function(t){return s.nodebuffer?r.newBufferFrom(t,"utf-8"):function(t){var e,i,n,r,o,a=t.length,l=0;for(r=0;r<a;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(n=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(n-56320),r++),l+=i<128?1:i<2048?2:i<65536?3:4;for(e=s.uint8array?new Uint8Array(l):new Array(l),r=o=0;o<l;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(n=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(n-56320),r++),i<128?e[o++]=i:(i<2048?e[o++]=192|i>>>6:(i<65536?e[o++]=224|i>>>12:(e[o++]=240|i>>>18,e[o++]=128|i>>>12&63),e[o++]=128|i>>>6&63),e[o++]=128|63&i);return e}(t)},i.utf8decode=function(t){return s.nodebuffer?n.transformTo("nodebuffer",t).toString("utf-8"):function(t){var e,i,s,r,o=t.length,l=new Array(2*o);for(e=i=0;e<o;)if((s=t[e++])<128)l[i++]=s;else if(4<(r=a[s]))l[i++]=65533,e+=r-1;else{for(s&=2===r?31:3===r?15:7;1<r&&e<o;)s=s<<6|63&t[e++],r--;1<r?l[i++]=65533:s<65536?l[i++]=s:(s-=65536,l[i++]=55296|s>>10&1023,l[i++]=56320|1023&s)}return l.length!==i&&(l.subarray?l=l.subarray(0,i):l.length=i),n.applyFromCharCode(l)}(t=n.transformTo(s.uint8array?"uint8array":"array",t))},n.inherits(c,o),c.prototype.processChunk=function(t){var e=n.transformTo(s.uint8array?"uint8array":"array",t.data);if(this.leftOver&&this.leftOver.length){if(s.uint8array){var r=e;(e=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),e.set(r,this.leftOver.length)}else e=this.leftOver.concat(e);this.leftOver=null}var o=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+a[t[i]]>e?i:e}(e),l=e;o!==e.length&&(s.uint8array?(l=e.subarray(0,o),this.leftOver=e.subarray(o,e.length)):(l=e.slice(0,o),this.leftOver=e.slice(o,e.length))),this.push({data:i.utf8decode(l),meta:t.meta})},c.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:i.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},i.Utf8DecodeWorker=c,n.inherits(h,o),h.prototype.processChunk=function(t){this.push({data:i.utf8encode(t.data),meta:t.meta})},i.Utf8EncodeWorker=h},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(t,e,i){var n=t("./support"),s=t("./base64"),r=t("./nodejsUtils"),o=t("./external");function a(t){return t}function l(t,e){for(var i=0;i<t.length;++i)e[i]=255&t.charCodeAt(i);return e}t("setimmediate"),i.newBlob=function(t,e){i.checkSupport("blob");try{return new Blob([t],{type:e})}catch(i){try{var n=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return n.append(t),n.getBlob(e)}catch(t){throw new Error("Bug : can't construct the Blob.")}}};var c={stringifyByChunk:function(t,e,i){var n=[],s=0,r=t.length;if(r<=i)return String.fromCharCode.apply(null,t);for(;s<r;)"array"===e||"nodebuffer"===e?n.push(String.fromCharCode.apply(null,t.slice(s,Math.min(s+i,r)))):n.push(String.fromCharCode.apply(null,t.subarray(s,Math.min(s+i,r)))),s+=i;return n.join("")},stringifyByChar:function(t){for(var e="",i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return e},applyCanBeUsed:{uint8array:function(){try{return n.uint8array&&1===String.fromCharCode.apply(null,new Uint8Array(1)).length}catch(t){return!1}}(),nodebuffer:function(){try{return n.nodebuffer&&1===String.fromCharCode.apply(null,r.allocBuffer(1)).length}catch(t){return!1}}()}};function h(t){var e=65536,n=i.getTypeOf(t),s=!0;if("uint8array"===n?s=c.applyCanBeUsed.uint8array:"nodebuffer"===n&&(s=c.applyCanBeUsed.nodebuffer),s)for(;1<e;)try{return c.stringifyByChunk(t,n,e)}catch(t){e=Math.floor(e/2)}return c.stringifyByChar(t)}function u(t,e){for(var i=0;i<t.length;i++)e[i]=t[i];return e}i.applyFromCharCode=h;var d={};d.string={string:a,array:function(t){return l(t,new Array(t.length))},arraybuffer:function(t){return d.string.uint8array(t).buffer},uint8array:function(t){return l(t,new Uint8Array(t.length))},nodebuffer:function(t){return l(t,r.allocBuffer(t.length))}},d.array={string:h,array:a,arraybuffer:function(t){return new Uint8Array(t).buffer},uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return r.newBufferFrom(t)}},d.arraybuffer={string:function(t){return h(new Uint8Array(t))},array:function(t){return u(new Uint8Array(t),new Array(t.byteLength))},arraybuffer:a,uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return r.newBufferFrom(new Uint8Array(t))}},d.uint8array={string:h,array:function(t){return u(t,new Array(t.length))},arraybuffer:function(t){return t.buffer},uint8array:a,nodebuffer:function(t){return r.newBufferFrom(t)}},d.nodebuffer={string:h,array:function(t){return u(t,new Array(t.length))},arraybuffer:function(t){return d.nodebuffer.uint8array(t).buffer},uint8array:function(t){return u(t,new Uint8Array(t.length))},nodebuffer:a},i.transformTo=function(t,e){if(e=e||"",!t)return e;i.checkSupport(t);var n=i.getTypeOf(e);return d[n][t](e)},i.resolve=function(t){for(var e=t.split("/"),i=[],n=0;n<e.length;n++){var s=e[n];"."===s||""===s&&0!==n&&n!==e.length-1||(".."===s?i.pop():i.push(s))}return i.join("/")},i.getTypeOf=function(t){return"string"==typeof t?"string":"[object Array]"===Object.prototype.toString.call(t)?"array":n.nodebuffer&&r.isBuffer(t)?"nodebuffer":n.uint8array&&t instanceof Uint8Array?"uint8array":n.arraybuffer&&t instanceof ArrayBuffer?"arraybuffer":void 0},i.checkSupport=function(t){if(!n[t.toLowerCase()])throw new Error(t+" is not supported by this platform")},i.MAX_VALUE_16BITS=65535,i.MAX_VALUE_32BITS=-1,i.pretty=function(t){var e,i,n="";for(i=0;i<(t||"").length;i++)n+="\\x"+((e=t.charCodeAt(i))<16?"0":"")+e.toString(16).toUpperCase();return n},i.delay=function(t,e,i){setImmediate(function(){t.apply(i||null,e||[])})},i.inherits=function(t,e){function i(){}i.prototype=e.prototype,t.prototype=new i},i.extend=function(){var t,e,i={};for(t=0;t<arguments.length;t++)for(e in arguments[t])Object.prototype.hasOwnProperty.call(arguments[t],e)&&void 0===i[e]&&(i[e]=arguments[t][e]);return i},i.prepareContent=function(t,e,r,a,c){return o.Promise.resolve(e).then(function(t){return n.blob&&(t instanceof Blob||-1!==["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(t)))&&"undefined"!=typeof FileReader?new o.Promise(function(e,i){var n=new FileReader;n.onload=function(t){e(t.target.result)},n.onerror=function(t){i(t.target.error)},n.readAsArrayBuffer(t)}):t}).then(function(e){var h,u=i.getTypeOf(e);return u?("arraybuffer"===u?e=i.transformTo("uint8array",e):"string"===u&&(c?e=s.decode(e):r&&!0!==a&&(e=l(h=e,n.uint8array?new Uint8Array(h.length):new Array(h.length)))),e):o.Promise.reject(new Error("Can't read the data of '"+t+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(t,e,i){var n=t("./reader/readerFor"),s=t("./utils"),r=t("./signature"),o=t("./zipEntry"),a=t("./support");function l(t){this.files=[],this.loadOptions=t}l.prototype={checkSignature:function(t){if(!this.reader.readAndCheckSignature(t)){this.reader.index-=4;var e=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+s.pretty(e)+", expected "+s.pretty(t)+")")}},isSignature:function(t,e){var i=this.reader.index;this.reader.setIndex(t);var n=this.reader.readString(4)===e;return this.reader.setIndex(i),n},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var t=this.reader.readData(this.zipCommentLength),e=a.uint8array?"uint8array":"array",i=s.transformTo(e,t);this.zipComment=this.loadOptions.decodeFileName(i)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var t,e,i,n=this.zip64EndOfCentralSize-44;0<n;)t=this.reader.readInt(2),e=this.reader.readInt(4),i=this.reader.readData(e),this.zip64ExtensibleData[t]={id:t,length:e,value:i}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var t,e;for(t=0;t<this.files.length;t++)e=this.files[t],this.reader.setIndex(e.localHeaderOffset),this.checkSignature(r.LOCAL_FILE_HEADER),e.readLocalPart(this.reader),e.handleUTF8(),e.processAttributes()},readCentralDir:function(){var t;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(r.CENTRAL_FILE_HEADER);)(t=new o({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(t);if(this.centralDirRecords!==this.files.length&&0!==this.centralDirRecords&&0===this.files.length)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var t=this.reader.lastIndexOfSignature(r.CENTRAL_DIRECTORY_END);if(t<0)throw this.isSignature(0,r.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(t);var e=t;if(this.checkSignature(r.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===s.MAX_VALUE_16BITS||this.diskWithCentralDirStart===s.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===s.MAX_VALUE_16BITS||this.centralDirRecords===s.MAX_VALUE_16BITS||this.centralDirSize===s.MAX_VALUE_32BITS||this.centralDirOffset===s.MAX_VALUE_32BITS){if(this.zip64=!0,(t=this.reader.lastIndexOfSignature(r.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(t),this.checkSignature(r.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,r.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(r.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(r.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var i=this.centralDirOffset+this.centralDirSize;this.zip64&&(i+=20,i+=12+this.zip64EndOfCentralSize);var n=e-i;if(0<n)this.isSignature(e,r.CENTRAL_FILE_HEADER)||(this.reader.zero=n);else if(n<0)throw new Error("Corrupted zip: missing "+Math.abs(n)+" bytes.")},prepareReader:function(t){this.reader=n(t)},load:function(t){this.prepareReader(t),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},e.exports=l},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(t,e,i){var n=t("./reader/readerFor"),s=t("./utils"),r=t("./compressedObject"),o=t("./crc32"),a=t("./utf8"),l=t("./compressions"),c=t("./support");function h(t,e){this.options=t,this.loadOptions=e}h.prototype={isEncrypted:function(){return!(1&~this.bitFlag)},useUTF8:function(){return!(2048&~this.bitFlag)},readLocalPart:function(t){var e,i;if(t.skip(22),this.fileNameLength=t.readInt(2),i=t.readInt(2),this.fileName=t.readData(this.fileNameLength),t.skip(i),-1===this.compressedSize||-1===this.uncompressedSize)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(null===(e=function(t){for(var e in l)if(Object.prototype.hasOwnProperty.call(l,e)&&l[e].magic===t)return l[e];return null}(this.compressionMethod)))throw new Error("Corrupted zip : compression "+s.pretty(this.compressionMethod)+" unknown (inner file : "+s.transformTo("string",this.fileName)+")");this.decompressed=new r(this.compressedSize,this.uncompressedSize,this.crc32,e,t.readData(this.compressedSize))},readCentralPart:function(t){this.versionMadeBy=t.readInt(2),t.skip(2),this.bitFlag=t.readInt(2),this.compressionMethod=t.readString(2),this.date=t.readDate(),this.crc32=t.readInt(4),this.compressedSize=t.readInt(4),this.uncompressedSize=t.readInt(4);var e=t.readInt(2);if(this.extraFieldsLength=t.readInt(2),this.fileCommentLength=t.readInt(2),this.diskNumberStart=t.readInt(2),this.internalFileAttributes=t.readInt(2),this.externalFileAttributes=t.readInt(4),this.localHeaderOffset=t.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");t.skip(e),this.readExtraFields(t),this.parseZIP64ExtraField(t),this.fileComment=t.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var t=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),0==t&&(this.dosPermissions=63&this.externalFileAttributes),3==t&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var t=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=t.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=t.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=t.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=t.readInt(4))}},readExtraFields:function(t){var e,i,n,s=t.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});t.index+4<s;)e=t.readInt(2),i=t.readInt(2),n=t.readData(i),this.extraFields[e]={id:e,length:i,value:n};t.setIndex(s)},handleUTF8:function(){var t=c.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=a.utf8decode(this.fileName),this.fileCommentStr=a.utf8decode(this.fileComment);else{var e=this.findExtraFieldUnicodePath();if(null!==e)this.fileNameStr=e;else{var i=s.transformTo(t,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(i)}var n=this.findExtraFieldUnicodeComment();if(null!==n)this.fileCommentStr=n;else{var r=s.transformTo(t,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(r)}}},findExtraFieldUnicodePath:function(){var t=this.extraFields[28789];if(t){var e=n(t.value);return 1!==e.readInt(1)||o(this.fileName)!==e.readInt(4)?null:a.utf8decode(e.readData(t.length-5))}return null},findExtraFieldUnicodeComment:function(){var t=this.extraFields[25461];if(t){var e=n(t.value);return 1!==e.readInt(1)||o(this.fileComment)!==e.readInt(4)?null:a.utf8decode(e.readData(t.length-5))}return null}},e.exports=h},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(t,e,i){function n(t,e,i){this.name=t,this.dir=i.dir,this.date=i.date,this.comment=i.comment,this.unixPermissions=i.unixPermissions,this.dosPermissions=i.dosPermissions,this._data=e,this._dataBinary=i.binary,this.options={compression:i.compression,compressionOptions:i.compressionOptions}}var s=t("./stream/StreamHelper"),r=t("./stream/DataWorker"),o=t("./utf8"),a=t("./compressedObject"),l=t("./stream/GenericWorker");n.prototype={internalStream:function(t){var e=null,i="string";try{if(!t)throw new Error("No output type specified.");var n="string"===(i=t.toLowerCase())||"text"===i;"binarystring"!==i&&"text"!==i||(i="string"),e=this._decompressWorker();var r=!this._dataBinary;r&&!n&&(e=e.pipe(new o.Utf8EncodeWorker)),!r&&n&&(e=e.pipe(new o.Utf8DecodeWorker))}catch(t){(e=new l("error")).error(t)}return new s(e,i,"")},async:function(t,e){return this.internalStream(t).accumulate(e)},nodeStream:function(t,e){return this.internalStream(t||"nodebuffer").toNodejsStream(e)},_compressWorker:function(t,e){if(this._data instanceof a&&this._data.compression.magic===t.magic)return this._data.getCompressedWorker();var i=this._decompressWorker();return this._dataBinary||(i=i.pipe(new o.Utf8EncodeWorker)),a.createWorkerFrom(i,t,e)},_decompressWorker:function(){return this._data instanceof a?this._data.getContentWorker():this._data instanceof l?this._data:new r(this._data)}};for(var c=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],h=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},u=0;u<c.length;u++)n.prototype[c[u]]=h;e.exports=n},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(t,e,i){(function(t){var i,n,s=t.MutationObserver||t.WebKitMutationObserver;if(s){var r=0,o=new s(h),a=t.document.createTextNode("");o.observe(a,{characterData:!0}),i=function(){a.data=r=++r%2}}else if(t.setImmediate||void 0===t.MessageChannel)i="document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){h(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(h,0)};else{var l=new t.MessageChannel;l.port1.onmessage=h,i=function(){l.port2.postMessage(0)}}var c=[];function h(){var t,e;n=!0;for(var i=c.length;i;){for(e=c,c=[],t=-1;++t<i;)e[t]();i=c.length}n=!1}e.exports=function(t){1!==c.push(t)||n||i()}}).call(this,void 0!==ns?ns:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],37:[function(t,e,i){var n=t("immediate");function s(){}var r={},o=["REJECTED"],a=["FULFILLED"],l=["PENDING"];function c(t){if("function"!=typeof t)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,t!==s&&p(this,t)}function h(t,e,i){this.promise=t,"function"==typeof e&&(this.onFulfilled=e,this.callFulfilled=this.otherCallFulfilled),"function"==typeof i&&(this.onRejected=i,this.callRejected=this.otherCallRejected)}function u(t,e,i){n(function(){var n;try{n=e(i)}catch(e){return r.reject(t,e)}n===t?r.reject(t,new TypeError("Cannot resolve promise with itself")):r.resolve(t,n)})}function d(t){var e=t&&t.then;if(t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof e)return function(){e.apply(t,arguments)}}function p(t,e){var i=!1;function n(e){i||(i=!0,r.reject(t,e))}function s(e){i||(i=!0,r.resolve(t,e))}var o=f(function(){e(s,n)});"error"===o.status&&n(o.value)}function f(t,e){var i={};try{i.value=t(e),i.status="success"}catch(t){i.status="error",i.value=t}return i}(e.exports=c).prototype.finally=function(t){if("function"!=typeof t)return this;var e=this.constructor;return this.then(function(i){return e.resolve(t()).then(function(){return i})},function(i){return e.resolve(t()).then(function(){throw i})})},c.prototype.catch=function(t){return this.then(null,t)},c.prototype.then=function(t,e){if("function"!=typeof t&&this.state===a||"function"!=typeof e&&this.state===o)return this;var i=new this.constructor(s);return this.state!==l?u(i,this.state===a?t:e,this.outcome):this.queue.push(new h(i,t,e)),i},h.prototype.callFulfilled=function(t){r.resolve(this.promise,t)},h.prototype.otherCallFulfilled=function(t){u(this.promise,this.onFulfilled,t)},h.prototype.callRejected=function(t){r.reject(this.promise,t)},h.prototype.otherCallRejected=function(t){u(this.promise,this.onRejected,t)},r.resolve=function(t,e){var i=f(d,e);if("error"===i.status)return r.reject(t,i.value);var n=i.value;if(n)p(t,n);else{t.state=a,t.outcome=e;for(var s=-1,o=t.queue.length;++s<o;)t.queue[s].callFulfilled(e)}return t},r.reject=function(t,e){t.state=o,t.outcome=e;for(var i=-1,n=t.queue.length;++i<n;)t.queue[i].callRejected(e);return t},c.resolve=function(t){return t instanceof this?t:r.resolve(new this(s),t)},c.reject=function(t){var e=new this(s);return r.reject(e,t)},c.all=function(t){var e=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var i=t.length,n=!1;if(!i)return this.resolve([]);for(var o=new Array(i),a=0,l=-1,c=new this(s);++l<i;)h(t[l],l);return c;function h(t,s){e.resolve(t).then(function(t){o[s]=t,++a!==i||n||(n=!0,r.resolve(c,o))},function(t){n||(n=!0,r.reject(c,t))})}},c.race=function(t){var e=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var i=t.length,n=!1;if(!i)return this.resolve([]);for(var o,a=-1,l=new this(s);++a<i;)o=t[a],e.resolve(o).then(function(t){n||(n=!0,r.resolve(l,t))},function(t){n||(n=!0,r.reject(l,t))});return l}},{immediate:36}],38:[function(t,e,i){var n={};(0,t("./lib/utils/common").assign)(n,t("./lib/deflate"),t("./lib/inflate"),t("./lib/zlib/constants")),e.exports=n},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(t,e,i){var n=t("./zlib/deflate"),s=t("./utils/common"),r=t("./utils/strings"),o=t("./zlib/messages"),a=t("./zlib/zstream"),l=Object.prototype.toString,c=0,h=-1,u=0,d=8;function p(t){if(!(this instanceof p))return new p(t);this.options=s.assign({level:h,method:d,chunkSize:16384,windowBits:15,memLevel:8,strategy:u,to:""},t||{});var e=this.options;e.raw&&0<e.windowBits?e.windowBits=-e.windowBits:e.gzip&&0<e.windowBits&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new a,this.strm.avail_out=0;var i=n.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==c)throw new Error(o[i]);if(e.header&&n.deflateSetHeader(this.strm,e.header),e.dictionary){var f;if(f="string"==typeof e.dictionary?r.string2buf(e.dictionary):"[object ArrayBuffer]"===l.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,(i=n.deflateSetDictionary(this.strm,f))!==c)throw new Error(o[i]);this._dict_set=!0}}function f(t,e){var i=new p(e);if(i.push(t,!0),i.err)throw i.msg||o[i.err];return i.result}p.prototype.push=function(t,e){var i,o,a=this.strm,h=this.options.chunkSize;if(this.ended)return!1;o=e===~~e?e:!0===e?4:0,"string"==typeof t?a.input=r.string2buf(t):"[object ArrayBuffer]"===l.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;do{if(0===a.avail_out&&(a.output=new s.Buf8(h),a.next_out=0,a.avail_out=h),1!==(i=n.deflate(a,o))&&i!==c)return this.onEnd(i),!(this.ended=!0);0!==a.avail_out&&(0!==a.avail_in||4!==o&&2!==o)||("string"===this.options.to?this.onData(r.buf2binstring(s.shrinkBuf(a.output,a.next_out))):this.onData(s.shrinkBuf(a.output,a.next_out)))}while((0<a.avail_in||0===a.avail_out)&&1!==i);return 4===o?(i=n.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===c):2!==o||(this.onEnd(c),!(a.avail_out=0))},p.prototype.onData=function(t){this.chunks.push(t)},p.prototype.onEnd=function(t){t===c&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},i.Deflate=p,i.deflate=f,i.deflateRaw=function(t,e){return(e=e||{}).raw=!0,f(t,e)},i.gzip=function(t,e){return(e=e||{}).gzip=!0,f(t,e)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(t,e,i){var n=t("./zlib/inflate"),s=t("./utils/common"),r=t("./utils/strings"),o=t("./zlib/constants"),a=t("./zlib/messages"),l=t("./zlib/zstream"),c=t("./zlib/gzheader"),h=Object.prototype.toString;function u(t){if(!(this instanceof u))return new u(t);this.options=s.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&0<=e.windowBits&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(0<=e.windowBits&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),15<e.windowBits&&e.windowBits<48&&!(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var i=n.inflateInit2(this.strm,e.windowBits);if(i!==o.Z_OK)throw new Error(a[i]);this.header=new c,n.inflateGetHeader(this.strm,this.header)}function d(t,e){var i=new u(e);if(i.push(t,!0),i.err)throw i.msg||a[i.err];return i.result}u.prototype.push=function(t,e){var i,a,l,c,u,d,p=this.strm,f=this.options.chunkSize,m=this.options.dictionary,g=!1;if(this.ended)return!1;a=e===~~e?e:!0===e?o.Z_FINISH:o.Z_NO_FLUSH,"string"==typeof t?p.input=r.binstring2buf(t):"[object ArrayBuffer]"===h.call(t)?p.input=new Uint8Array(t):p.input=t,p.next_in=0,p.avail_in=p.input.length;do{if(0===p.avail_out&&(p.output=new s.Buf8(f),p.next_out=0,p.avail_out=f),(i=n.inflate(p,o.Z_NO_FLUSH))===o.Z_NEED_DICT&&m&&(d="string"==typeof m?r.string2buf(m):"[object ArrayBuffer]"===h.call(m)?new Uint8Array(m):m,i=n.inflateSetDictionary(this.strm,d)),i===o.Z_BUF_ERROR&&!0===g&&(i=o.Z_OK,g=!1),i!==o.Z_STREAM_END&&i!==o.Z_OK)return this.onEnd(i),!(this.ended=!0);p.next_out&&(0!==p.avail_out&&i!==o.Z_STREAM_END&&(0!==p.avail_in||a!==o.Z_FINISH&&a!==o.Z_SYNC_FLUSH)||("string"===this.options.to?(l=r.utf8border(p.output,p.next_out),c=p.next_out-l,u=r.buf2string(p.output,l),p.next_out=c,p.avail_out=f-c,c&&s.arraySet(p.output,p.output,l,c,0),this.onData(u)):this.onData(s.shrinkBuf(p.output,p.next_out)))),0===p.avail_in&&0===p.avail_out&&(g=!0)}while((0<p.avail_in||0===p.avail_out)&&i!==o.Z_STREAM_END);return i===o.Z_STREAM_END&&(a=o.Z_FINISH),a===o.Z_FINISH?(i=n.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===o.Z_OK):a!==o.Z_SYNC_FLUSH||(this.onEnd(o.Z_OK),!(p.avail_out=0))},u.prototype.onData=function(t){this.chunks.push(t)},u.prototype.onEnd=function(t){t===o.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},i.Inflate=u,i.inflate=d,i.inflateRaw=function(t,e){return(e=e||{}).raw=!0,d(t,e)},i.ungzip=d},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(t,e,i){var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;i.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])}}return t},i.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var s={arraySet:function(t,e,i,n,s){if(e.subarray&&t.subarray)t.set(e.subarray(i,i+n),s);else for(var r=0;r<n;r++)t[s+r]=e[i+r]},flattenChunks:function(t){var e,i,n,s,r,o;for(e=n=0,i=t.length;e<i;e++)n+=t[e].length;for(o=new Uint8Array(n),e=s=0,i=t.length;e<i;e++)r=t[e],o.set(r,s),s+=r.length;return o}},r={arraySet:function(t,e,i,n,s){for(var r=0;r<n;r++)t[s+r]=e[i+r]},flattenChunks:function(t){return[].concat.apply([],t)}};i.setTyped=function(t){t?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,s)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,r))},i.setTyped(n)},{}],42:[function(t,e,i){var n=t("./common"),s=!0,r=!0;try{String.fromCharCode.apply(null,[0])}catch(t){s=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){r=!1}for(var o=new n.Buf8(256),a=0;a<256;a++)o[a]=252<=a?6:248<=a?5:240<=a?4:224<=a?3:192<=a?2:1;function l(t,e){if(e<65537&&(t.subarray&&r||!t.subarray&&s))return String.fromCharCode.apply(null,n.shrinkBuf(t,e));for(var i="",o=0;o<e;o++)i+=String.fromCharCode(t[o]);return i}o[254]=o[254]=1,i.string2buf=function(t){var e,i,s,r,o,a=t.length,l=0;for(r=0;r<a;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(s=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(s-56320),r++),l+=i<128?1:i<2048?2:i<65536?3:4;for(e=new n.Buf8(l),r=o=0;o<l;r++)55296==(64512&(i=t.charCodeAt(r)))&&r+1<a&&56320==(64512&(s=t.charCodeAt(r+1)))&&(i=65536+(i-55296<<10)+(s-56320),r++),i<128?e[o++]=i:(i<2048?e[o++]=192|i>>>6:(i<65536?e[o++]=224|i>>>12:(e[o++]=240|i>>>18,e[o++]=128|i>>>12&63),e[o++]=128|i>>>6&63),e[o++]=128|63&i);return e},i.buf2binstring=function(t){return l(t,t.length)},i.binstring2buf=function(t){for(var e=new n.Buf8(t.length),i=0,s=e.length;i<s;i++)e[i]=t.charCodeAt(i);return e},i.buf2string=function(t,e){var i,n,s,r,a=e||t.length,c=new Array(2*a);for(i=n=0;i<a;)if((s=t[i++])<128)c[n++]=s;else if(4<(r=o[s]))c[n++]=65533,i+=r-1;else{for(s&=2===r?31:3===r?15:7;1<r&&i<a;)s=s<<6|63&t[i++],r--;1<r?c[n++]=65533:s<65536?c[n++]=s:(s-=65536,c[n++]=55296|s>>10&1023,c[n++]=56320|1023&s)}return l(c,n)},i.utf8border=function(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;0<=i&&128==(192&t[i]);)i--;return i<0||0===i?e:i+o[t[i]]>e?i:e}},{"./common":41}],43:[function(t,e,i){e.exports=function(t,e,i,n){for(var s=65535&t,r=t>>>16&65535,o=0;0!==i;){for(i-=o=2e3<i?2e3:i;r=r+(s=s+e[n++]|0)|0,--o;);s%=65521,r%=65521}return s|r<<16}},{}],44:[function(t,e,i){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(t,e,i){var n=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();e.exports=function(t,e,i,s){var r=n,o=s+i;t^=-1;for(var a=s;a<o;a++)t=t>>>8^r[255&(t^e[a])];return-1^t}},{}],46:[function(t,e,i){var n,s=t("../utils/common"),r=t("./trees"),o=t("./adler32"),a=t("./crc32"),l=t("./messages"),c=0,h=4,u=0,d=-2,p=-1,f=4,m=2,g=8,y=9,w=286,v=30,b=19,_=2*w+1,x=15,S=3,C=258,A=C+S+1,E=42,T=113,I=1,P=2,M=3,k=4;function D(t,e){return t.msg=l[e],e}function z(t){return(t<<1)-(4<t?9:0)}function B(t){for(var e=t.length;0<=--e;)t[e]=0}function O(t){var e=t.state,i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(s.arraySet(t.output,e.pending_buf,e.pending_out,i,t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))}function N(t,e){r._tr_flush_block(t,0<=t.block_start?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,O(t.strm)}function V(t,e){t.pending_buf[t.pending++]=e}function F(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function R(t,e){var i,n,s=t.max_chain_length,r=t.strstart,o=t.prev_length,a=t.nice_match,l=t.strstart>t.w_size-A?t.strstart-(t.w_size-A):0,c=t.window,h=t.w_mask,u=t.prev,d=t.strstart+C,p=c[r+o-1],f=c[r+o];t.prev_length>=t.good_match&&(s>>=2),a>t.lookahead&&(a=t.lookahead);do{if(c[(i=e)+o]===f&&c[i+o-1]===p&&c[i]===c[r]&&c[++i]===c[r+1]){r+=2,i++;do{}while(c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&r<d);if(n=C-(d-r),r=d-C,o<n){if(t.match_start=e,a<=(o=n))break;p=c[r+o-1],f=c[r+o]}}}while((e=u[e&h])>l&&0!=--s);return o<=t.lookahead?o:t.lookahead}function L(t){var e,i,n,r,l,c,h,u,d,p,f=t.w_size;do{if(r=t.window_size-t.lookahead-t.strstart,t.strstart>=f+(f-A)){for(s.arraySet(t.window,t.window,f,f,0),t.match_start-=f,t.strstart-=f,t.block_start-=f,e=i=t.hash_size;n=t.head[--e],t.head[e]=f<=n?n-f:0,--i;);for(e=i=f;n=t.prev[--e],t.prev[e]=f<=n?n-f:0,--i;);r+=f}if(0===t.strm.avail_in)break;if(c=t.strm,h=t.window,u=t.strstart+t.lookahead,p=void 0,(d=r)<(p=c.avail_in)&&(p=d),i=0===p?0:(c.avail_in-=p,s.arraySet(h,c.input,c.next_in,p,u),1===c.state.wrap?c.adler=o(c.adler,h,p,u):2===c.state.wrap&&(c.adler=a(c.adler,h,p,u)),c.next_in+=p,c.total_in+=p,p),t.lookahead+=i,t.lookahead+t.insert>=S)for(l=t.strstart-t.insert,t.ins_h=t.window[l],t.ins_h=(t.ins_h<<t.hash_shift^t.window[l+1])&t.hash_mask;t.insert&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[l+S-1])&t.hash_mask,t.prev[l&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=l,l++,t.insert--,!(t.lookahead+t.insert<S)););}while(t.lookahead<A&&0!==t.strm.avail_in)}function U(t,e){for(var i,n;;){if(t.lookahead<A){if(L(t),t.lookahead<A&&e===c)return I;if(0===t.lookahead)break}if(i=0,t.lookahead>=S&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+S-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-A&&(t.match_length=R(t,i)),t.match_length>=S)if(n=r._tr_tally(t,t.strstart-t.match_start,t.match_length-S),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=S){for(t.match_length--;t.strstart++,t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+S-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart,0!=--t.match_length;);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+1])&t.hash_mask;else n=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(N(t,!1),0===t.strm.avail_out))return I}return t.insert=t.strstart<S-1?t.strstart:S-1,e===h?(N(t,!0),0===t.strm.avail_out?M:k):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?I:P}function $(t,e){for(var i,n,s;;){if(t.lookahead<A){if(L(t),t.lookahead<A&&e===c)return I;if(0===t.lookahead)break}if(i=0,t.lookahead>=S&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+S-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=S-1,0!==i&&t.prev_length<t.max_lazy_match&&t.strstart-i<=t.w_size-A&&(t.match_length=R(t,i),t.match_length<=5&&(1===t.strategy||t.match_length===S&&4096<t.strstart-t.match_start)&&(t.match_length=S-1)),t.prev_length>=S&&t.match_length<=t.prev_length){for(s=t.strstart+t.lookahead-S,n=r._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-S),t.lookahead-=t.prev_length-1,t.prev_length-=2;++t.strstart<=s&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+S-1])&t.hash_mask,i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!=--t.prev_length;);if(t.match_available=0,t.match_length=S-1,t.strstart++,n&&(N(t,!1),0===t.strm.avail_out))return I}else if(t.match_available){if((n=r._tr_tally(t,0,t.window[t.strstart-1]))&&N(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return I}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=r._tr_tally(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<S-1?t.strstart:S-1,e===h?(N(t,!0),0===t.strm.avail_out?M:k):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?I:P}function j(t,e,i,n,s){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=s}function W(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=g,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new s.Buf16(2*_),this.dyn_dtree=new s.Buf16(2*(2*v+1)),this.bl_tree=new s.Buf16(2*(2*b+1)),B(this.dyn_ltree),B(this.dyn_dtree),B(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new s.Buf16(x+1),this.heap=new s.Buf16(2*w+1),B(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new s.Buf16(2*w+1),B(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Z(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=m,(e=t.state).pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?E:T,t.adler=2===e.wrap?0:1,e.last_flush=c,r._tr_init(e),u):D(t,d)}function G(t){var e,i=Z(t);return i===u&&((e=t.state).window_size=2*e.w_size,B(e.head),e.max_lazy_match=n[e.level].max_lazy,e.good_match=n[e.level].good_length,e.nice_match=n[e.level].nice_length,e.max_chain_length=n[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=S-1,e.match_available=0,e.ins_h=0),i}function q(t,e,i,n,r,o){if(!t)return d;var a=1;if(e===p&&(e=6),n<0?(a=0,n=-n):15<n&&(a=2,n-=16),r<1||y<r||i!==g||n<8||15<n||e<0||9<e||o<0||f<o)return D(t,d);8===n&&(n=9);var l=new W;return(t.state=l).strm=t,l.wrap=a,l.gzhead=null,l.w_bits=n,l.w_size=1<<l.w_bits,l.w_mask=l.w_size-1,l.hash_bits=r+7,l.hash_size=1<<l.hash_bits,l.hash_mask=l.hash_size-1,l.hash_shift=~~((l.hash_bits+S-1)/S),l.window=new s.Buf8(2*l.w_size),l.head=new s.Buf16(l.hash_size),l.prev=new s.Buf16(l.w_size),l.lit_bufsize=1<<r+6,l.pending_buf_size=4*l.lit_bufsize,l.pending_buf=new s.Buf8(l.pending_buf_size),l.d_buf=1*l.lit_bufsize,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=o,l.method=i,G(t)}n=[new j(0,0,0,0,function(t,e){var i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(L(t),0===t.lookahead&&e===c)return I;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,N(t,!1),0===t.strm.avail_out))return I;if(t.strstart-t.block_start>=t.w_size-A&&(N(t,!1),0===t.strm.avail_out))return I}return t.insert=0,e===h?(N(t,!0),0===t.strm.avail_out?M:k):(t.strstart>t.block_start&&(N(t,!1),t.strm.avail_out),I)}),new j(4,4,8,4,U),new j(4,5,16,8,U),new j(4,6,32,32,U),new j(4,4,16,16,$),new j(8,16,32,32,$),new j(8,16,128,128,$),new j(8,32,128,256,$),new j(32,128,258,1024,$),new j(32,258,258,4096,$)],i.deflateInit=function(t,e){return q(t,e,g,15,8,0)},i.deflateInit2=q,i.deflateReset=G,i.deflateResetKeep=Z,i.deflateSetHeader=function(t,e){return t&&t.state?2!==t.state.wrap?d:(t.state.gzhead=e,u):d},i.deflate=function(t,e){var i,s,o,l;if(!t||!t.state||5<e||e<0)return t?D(t,d):d;if(s=t.state,!t.output||!t.input&&0!==t.avail_in||666===s.status&&e!==h)return D(t,0===t.avail_out?-5:d);if(s.strm=t,i=s.last_flush,s.last_flush=e,s.status===E)if(2===s.wrap)t.adler=0,V(s,31),V(s,139),V(s,8),s.gzhead?(V(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),V(s,255&s.gzhead.time),V(s,s.gzhead.time>>8&255),V(s,s.gzhead.time>>16&255),V(s,s.gzhead.time>>24&255),V(s,9===s.level?2:2<=s.strategy||s.level<2?4:0),V(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(V(s,255&s.gzhead.extra.length),V(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(t.adler=a(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=69):(V(s,0),V(s,0),V(s,0),V(s,0),V(s,0),V(s,9===s.level?2:2<=s.strategy||s.level<2?4:0),V(s,3),s.status=T);else{var p=g+(s.w_bits-8<<4)<<8;p|=(2<=s.strategy||s.level<2?0:s.level<6?1:6===s.level?2:3)<<6,0!==s.strstart&&(p|=32),p+=31-p%31,s.status=T,F(s,p),0!==s.strstart&&(F(s,t.adler>>>16),F(s,65535&t.adler)),t.adler=1}if(69===s.status)if(s.gzhead.extra){for(o=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),O(t),o=s.pending,s.pending!==s.pending_buf_size));)V(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=73)}else s.status=73;if(73===s.status)if(s.gzhead.name){o=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),O(t),o=s.pending,s.pending===s.pending_buf_size)){l=1;break}l=s.gzindex<s.gzhead.name.length?255&s.gzhead.name.charCodeAt(s.gzindex++):0,V(s,l)}while(0!==l);s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),0===l&&(s.gzindex=0,s.status=91)}else s.status=91;if(91===s.status)if(s.gzhead.comment){o=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),O(t),o=s.pending,s.pending===s.pending_buf_size)){l=1;break}l=s.gzindex<s.gzhead.comment.length?255&s.gzhead.comment.charCodeAt(s.gzindex++):0,V(s,l)}while(0!==l);s.gzhead.hcrc&&s.pending>o&&(t.adler=a(t.adler,s.pending_buf,s.pending-o,o)),0===l&&(s.status=103)}else s.status=103;if(103===s.status&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&O(t),s.pending+2<=s.pending_buf_size&&(V(s,255&t.adler),V(s,t.adler>>8&255),t.adler=0,s.status=T)):s.status=T),0!==s.pending){if(O(t),0===t.avail_out)return s.last_flush=-1,u}else if(0===t.avail_in&&z(e)<=z(i)&&e!==h)return D(t,-5);if(666===s.status&&0!==t.avail_in)return D(t,-5);if(0!==t.avail_in||0!==s.lookahead||e!==c&&666!==s.status){var f=2===s.strategy?function(t,e){for(var i;;){if(0===t.lookahead&&(L(t),0===t.lookahead)){if(e===c)return I;break}if(t.match_length=0,i=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(N(t,!1),0===t.strm.avail_out))return I}return t.insert=0,e===h?(N(t,!0),0===t.strm.avail_out?M:k):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?I:P}(s,e):3===s.strategy?function(t,e){for(var i,n,s,o,a=t.window;;){if(t.lookahead<=C){if(L(t),t.lookahead<=C&&e===c)return I;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=S&&0<t.strstart&&(n=a[s=t.strstart-1])===a[++s]&&n===a[++s]&&n===a[++s]){o=t.strstart+C;do{}while(n===a[++s]&&n===a[++s]&&n===a[++s]&&n===a[++s]&&n===a[++s]&&n===a[++s]&&n===a[++s]&&n===a[++s]&&s<o);t.match_length=C-(o-s),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=S?(i=r._tr_tally(t,1,t.match_length-S),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=r._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(N(t,!1),0===t.strm.avail_out))return I}return t.insert=0,e===h?(N(t,!0),0===t.strm.avail_out?M:k):t.last_lit&&(N(t,!1),0===t.strm.avail_out)?I:P}(s,e):n[s.level].func(s,e);if(f!==M&&f!==k||(s.status=666),f===I||f===M)return 0===t.avail_out&&(s.last_flush=-1),u;if(f===P&&(1===e?r._tr_align(s):5!==e&&(r._tr_stored_block(s,0,0,!1),3===e&&(B(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),O(t),0===t.avail_out))return s.last_flush=-1,u}return e!==h?u:s.wrap<=0?1:(2===s.wrap?(V(s,255&t.adler),V(s,t.adler>>8&255),V(s,t.adler>>16&255),V(s,t.adler>>24&255),V(s,255&t.total_in),V(s,t.total_in>>8&255),V(s,t.total_in>>16&255),V(s,t.total_in>>24&255)):(F(s,t.adler>>>16),F(s,65535&t.adler)),O(t),0<s.wrap&&(s.wrap=-s.wrap),0!==s.pending?u:1)},i.deflateEnd=function(t){var e;return t&&t.state?(e=t.state.status)!==E&&69!==e&&73!==e&&91!==e&&103!==e&&e!==T&&666!==e?D(t,d):(t.state=null,e===T?D(t,-3):u):d},i.deflateSetDictionary=function(t,e){var i,n,r,a,l,c,h,p,f=e.length;if(!t||!t.state)return d;if(2===(a=(i=t.state).wrap)||1===a&&i.status!==E||i.lookahead)return d;for(1===a&&(t.adler=o(t.adler,e,f,0)),i.wrap=0,f>=i.w_size&&(0===a&&(B(i.head),i.strstart=0,i.block_start=0,i.insert=0),p=new s.Buf8(i.w_size),s.arraySet(p,e,f-i.w_size,i.w_size,0),e=p,f=i.w_size),l=t.avail_in,c=t.next_in,h=t.input,t.avail_in=f,t.next_in=0,t.input=e,L(i);i.lookahead>=S;){for(n=i.strstart,r=i.lookahead-(S-1);i.ins_h=(i.ins_h<<i.hash_shift^i.window[n+S-1])&i.hash_mask,i.prev[n&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=n,n++,--r;);i.strstart=n,i.lookahead=S-1,L(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=S-1,i.match_available=0,t.next_in=c,t.input=h,t.avail_in=l,i.wrap=a,u},i.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(t,e,i){e.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(t,e,i){e.exports=function(t,e){var i,n,s,r,o,a,l,c,h,u,d,p,f,m,g,y,w,v,b,_,x,S,C,A,E;i=t.state,n=t.next_in,A=t.input,s=n+(t.avail_in-5),r=t.next_out,E=t.output,o=r-(e-t.avail_out),a=r+(t.avail_out-257),l=i.dmax,c=i.wsize,h=i.whave,u=i.wnext,d=i.window,p=i.hold,f=i.bits,m=i.lencode,g=i.distcode,y=(1<<i.lenbits)-1,w=(1<<i.distbits)-1;t:do{f<15&&(p+=A[n++]<<f,f+=8,p+=A[n++]<<f,f+=8),v=m[p&y];e:for(;;){if(p>>>=b=v>>>24,f-=b,0==(b=v>>>16&255))E[r++]=65535&v;else{if(!(16&b)){if(!(64&b)){v=m[(65535&v)+(p&(1<<b)-1)];continue e}if(32&b){i.mode=12;break t}t.msg="invalid literal/length code",i.mode=30;break t}_=65535&v,(b&=15)&&(f<b&&(p+=A[n++]<<f,f+=8),_+=p&(1<<b)-1,p>>>=b,f-=b),f<15&&(p+=A[n++]<<f,f+=8,p+=A[n++]<<f,f+=8),v=g[p&w];i:for(;;){if(p>>>=b=v>>>24,f-=b,!(16&(b=v>>>16&255))){if(!(64&b)){v=g[(65535&v)+(p&(1<<b)-1)];continue i}t.msg="invalid distance code",i.mode=30;break t}if(x=65535&v,f<(b&=15)&&(p+=A[n++]<<f,(f+=8)<b&&(p+=A[n++]<<f,f+=8)),l<(x+=p&(1<<b)-1)){t.msg="invalid distance too far back",i.mode=30;break t}if(p>>>=b,f-=b,(b=r-o)<x){if(h<(b=x-b)&&i.sane){t.msg="invalid distance too far back",i.mode=30;break t}if(C=d,(S=0)===u){if(S+=c-b,b<_){for(_-=b;E[r++]=d[S++],--b;);S=r-x,C=E}}else if(u<b){if(S+=c+u-b,(b-=u)<_){for(_-=b;E[r++]=d[S++],--b;);if(S=0,u<_){for(_-=b=u;E[r++]=d[S++],--b;);S=r-x,C=E}}}else if(S+=u-b,b<_){for(_-=b;E[r++]=d[S++],--b;);S=r-x,C=E}for(;2<_;)E[r++]=C[S++],E[r++]=C[S++],E[r++]=C[S++],_-=3;_&&(E[r++]=C[S++],1<_&&(E[r++]=C[S++]))}else{for(S=r-x;E[r++]=E[S++],E[r++]=E[S++],E[r++]=E[S++],2<(_-=3););_&&(E[r++]=E[S++],1<_&&(E[r++]=E[S++]))}break}}break}}while(n<s&&r<a);n-=_=f>>3,p&=(1<<(f-=_<<3))-1,t.next_in=n,t.next_out=r,t.avail_in=n<s?s-n+5:5-(n-s),t.avail_out=r<a?a-r+257:257-(r-a),i.hold=p,i.bits=f}},{}],49:[function(t,e,i){var n=t("../utils/common"),s=t("./adler32"),r=t("./crc32"),o=t("./inffast"),a=t("./inftrees"),l=1,c=2,h=0,u=-2,d=1,p=852,f=592;function m(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function g(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new n.Buf16(320),this.work=new n.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function y(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=d,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new n.Buf32(p),e.distcode=e.distdyn=new n.Buf32(f),e.sane=1,e.back=-1,h):u}function w(t){var e;return t&&t.state?((e=t.state).wsize=0,e.whave=0,e.wnext=0,y(t)):u}function v(t,e){var i,n;return t&&t.state?(n=t.state,e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||15<e)?u:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,w(t))):u}function b(t,e){var i,n;return t?(n=new g,(t.state=n).window=null,(i=v(t,e))!==h&&(t.state=null),i):u}var _,x,S=!0;function C(t){if(S){var e;for(_=new n.Buf32(512),x=new n.Buf32(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(a(l,t.lens,0,288,_,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;a(c,t.lens,0,32,x,0,t.work,{bits:5}),S=!1}t.lencode=_,t.lenbits=9,t.distcode=x,t.distbits=5}function A(t,e,i,s){var r,o=t.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new n.Buf8(o.wsize)),s>=o.wsize?(n.arraySet(o.window,e,i-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(s<(r=o.wsize-o.wnext)&&(r=s),n.arraySet(o.window,e,i-s,r,o.wnext),(s-=r)?(n.arraySet(o.window,e,i-s,s,0),o.wnext=s,o.whave=o.wsize):(o.wnext+=r,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=r))),0}i.inflateReset=w,i.inflateReset2=v,i.inflateResetKeep=y,i.inflateInit=function(t){return b(t,15)},i.inflateInit2=b,i.inflate=function(t,e){var i,p,f,g,y,w,v,b,_,x,S,E,T,I,P,M,k,D,z,B,O,N,V,F,R=0,L=new n.Buf8(4),U=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return u;12===(i=t.state).mode&&(i.mode=13),y=t.next_out,f=t.output,v=t.avail_out,g=t.next_in,p=t.input,w=t.avail_in,b=i.hold,_=i.bits,x=w,S=v,N=h;t:for(;;)switch(i.mode){case d:if(0===i.wrap){i.mode=13;break}for(;_<16;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(2&i.wrap&&35615===b){L[i.check=0]=255&b,L[1]=b>>>8&255,i.check=r(i.check,L,2,0),_=b=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&b)<<8)+(b>>8))%31){t.msg="incorrect header check",i.mode=30;break}if(8!=(15&b)){t.msg="unknown compression method",i.mode=30;break}if(_-=4,O=8+(15&(b>>>=4)),0===i.wbits)i.wbits=O;else if(O>i.wbits){t.msg="invalid window size",i.mode=30;break}i.dmax=1<<O,t.adler=i.check=1,i.mode=512&b?10:12,_=b=0;break;case 2:for(;_<16;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(i.flags=b,8!=(255&i.flags)){t.msg="unknown compression method",i.mode=30;break}if(57344&i.flags){t.msg="unknown header flags set",i.mode=30;break}i.head&&(i.head.text=b>>8&1),512&i.flags&&(L[0]=255&b,L[1]=b>>>8&255,i.check=r(i.check,L,2,0)),_=b=0,i.mode=3;case 3:for(;_<32;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.head&&(i.head.time=b),512&i.flags&&(L[0]=255&b,L[1]=b>>>8&255,L[2]=b>>>16&255,L[3]=b>>>24&255,i.check=r(i.check,L,4,0)),_=b=0,i.mode=4;case 4:for(;_<16;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.head&&(i.head.xflags=255&b,i.head.os=b>>8),512&i.flags&&(L[0]=255&b,L[1]=b>>>8&255,i.check=r(i.check,L,2,0)),_=b=0,i.mode=5;case 5:if(1024&i.flags){for(;_<16;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.length=b,i.head&&(i.head.extra_len=b),512&i.flags&&(L[0]=255&b,L[1]=b>>>8&255,i.check=r(i.check,L,2,0)),_=b=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(w<(E=i.length)&&(E=w),E&&(i.head&&(O=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),n.arraySet(i.head.extra,p,g,E,O)),512&i.flags&&(i.check=r(i.check,p,E,g)),w-=E,g+=E,i.length-=E),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===w)break t;for(E=0;O=p[g+E++],i.head&&O&&i.length<65536&&(i.head.name+=String.fromCharCode(O)),O&&E<w;);if(512&i.flags&&(i.check=r(i.check,p,E,g)),w-=E,g+=E,O)break t}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===w)break t;for(E=0;O=p[g+E++],i.head&&O&&i.length<65536&&(i.head.comment+=String.fromCharCode(O)),O&&E<w;);if(512&i.flags&&(i.check=r(i.check,p,E,g)),w-=E,g+=E,O)break t}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;_<16;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(b!==(65535&i.check)){t.msg="header crc mismatch",i.mode=30;break}_=b=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=12;break;case 10:for(;_<32;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}t.adler=i.check=m(b),_=b=0,i.mode=11;case 11:if(0===i.havedict)return t.next_out=y,t.avail_out=v,t.next_in=g,t.avail_in=w,i.hold=b,i.bits=_,2;t.adler=i.check=1,i.mode=12;case 12:if(5===e||6===e)break t;case 13:if(i.last){b>>>=7&_,_-=7&_,i.mode=27;break}for(;_<3;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}switch(i.last=1&b,_-=1,3&(b>>>=1)){case 0:i.mode=14;break;case 1:if(C(i),i.mode=20,6!==e)break;b>>>=2,_-=2;break t;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=30}b>>>=2,_-=2;break;case 14:for(b>>>=7&_,_-=7&_;_<32;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if((65535&b)!=(b>>>16^65535)){t.msg="invalid stored block lengths",i.mode=30;break}if(i.length=65535&b,_=b=0,i.mode=15,6===e)break t;case 15:i.mode=16;case 16:if(E=i.length){if(w<E&&(E=w),v<E&&(E=v),0===E)break t;n.arraySet(f,p,g,E,y),w-=E,g+=E,v-=E,y+=E,i.length-=E;break}i.mode=12;break;case 17:for(;_<14;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(i.nlen=257+(31&b),b>>>=5,_-=5,i.ndist=1+(31&b),b>>>=5,_-=5,i.ncode=4+(15&b),b>>>=4,_-=4,286<i.nlen||30<i.ndist){t.msg="too many length or distance symbols",i.mode=30;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;_<3;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.lens[U[i.have++]]=7&b,b>>>=3,_-=3}for(;i.have<19;)i.lens[U[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,V={bits:i.lenbits},N=a(0,i.lens,0,19,i.lencode,0,i.work,V),i.lenbits=V.bits,N){t.msg="invalid code lengths set",i.mode=30;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;M=(R=i.lencode[b&(1<<i.lenbits)-1])>>>16&255,k=65535&R,!((P=R>>>24)<=_);){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(k<16)b>>>=P,_-=P,i.lens[i.have++]=k;else{if(16===k){for(F=P+2;_<F;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(b>>>=P,_-=P,0===i.have){t.msg="invalid bit length repeat",i.mode=30;break}O=i.lens[i.have-1],E=3+(3&b),b>>>=2,_-=2}else if(17===k){for(F=P+3;_<F;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}_-=P,O=0,E=3+(7&(b>>>=P)),b>>>=3,_-=3}else{for(F=P+7;_<F;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}_-=P,O=0,E=11+(127&(b>>>=P)),b>>>=7,_-=7}if(i.have+E>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=30;break}for(;E--;)i.lens[i.have++]=O}}if(30===i.mode)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=30;break}if(i.lenbits=9,V={bits:i.lenbits},N=a(l,i.lens,0,i.nlen,i.lencode,0,i.work,V),i.lenbits=V.bits,N){t.msg="invalid literal/lengths set",i.mode=30;break}if(i.distbits=6,i.distcode=i.distdyn,V={bits:i.distbits},N=a(c,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,V),i.distbits=V.bits,N){t.msg="invalid distances set",i.mode=30;break}if(i.mode=20,6===e)break t;case 20:i.mode=21;case 21:if(6<=w&&258<=v){t.next_out=y,t.avail_out=v,t.next_in=g,t.avail_in=w,i.hold=b,i.bits=_,o(t,S),y=t.next_out,f=t.output,v=t.avail_out,g=t.next_in,p=t.input,w=t.avail_in,b=i.hold,_=i.bits,12===i.mode&&(i.back=-1);break}for(i.back=0;M=(R=i.lencode[b&(1<<i.lenbits)-1])>>>16&255,k=65535&R,!((P=R>>>24)<=_);){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(M&&!(240&M)){for(D=P,z=M,B=k;M=(R=i.lencode[B+((b&(1<<D+z)-1)>>D)])>>>16&255,k=65535&R,!(D+(P=R>>>24)<=_);){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}b>>>=D,_-=D,i.back+=D}if(b>>>=P,_-=P,i.back+=P,i.length=k,0===M){i.mode=26;break}if(32&M){i.back=-1,i.mode=12;break}if(64&M){t.msg="invalid literal/length code",i.mode=30;break}i.extra=15&M,i.mode=22;case 22:if(i.extra){for(F=i.extra;_<F;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.length+=b&(1<<i.extra)-1,b>>>=i.extra,_-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;M=(R=i.distcode[b&(1<<i.distbits)-1])>>>16&255,k=65535&R,!((P=R>>>24)<=_);){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(!(240&M)){for(D=P,z=M,B=k;M=(R=i.distcode[B+((b&(1<<D+z)-1)>>D)])>>>16&255,k=65535&R,!(D+(P=R>>>24)<=_);){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}b>>>=D,_-=D,i.back+=D}if(b>>>=P,_-=P,i.back+=P,64&M){t.msg="invalid distance code",i.mode=30;break}i.offset=k,i.extra=15&M,i.mode=24;case 24:if(i.extra){for(F=i.extra;_<F;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}i.offset+=b&(1<<i.extra)-1,b>>>=i.extra,_-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=30;break}i.mode=25;case 25:if(0===v)break t;if(E=S-v,i.offset>E){if((E=i.offset-E)>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=30;break}T=E>i.wnext?(E-=i.wnext,i.wsize-E):i.wnext-E,E>i.length&&(E=i.length),I=i.window}else I=f,T=y-i.offset,E=i.length;for(v<E&&(E=v),v-=E,i.length-=E;f[y++]=I[T++],--E;);0===i.length&&(i.mode=21);break;case 26:if(0===v)break t;f[y++]=i.length,v--,i.mode=21;break;case 27:if(i.wrap){for(;_<32;){if(0===w)break t;w--,b|=p[g++]<<_,_+=8}if(S-=v,t.total_out+=S,i.total+=S,S&&(t.adler=i.check=i.flags?r(i.check,f,S,y-S):s(i.check,f,S,y-S)),S=v,(i.flags?b:m(b))!==i.check){t.msg="incorrect data check",i.mode=30;break}_=b=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;_<32;){if(0===w)break t;w--,b+=p[g++]<<_,_+=8}if(b!==(4294967295&i.total)){t.msg="incorrect length check",i.mode=30;break}_=b=0}i.mode=29;case 29:N=1;break t;case 30:N=-3;break t;case 31:return-4;default:return u}return t.next_out=y,t.avail_out=v,t.next_in=g,t.avail_in=w,i.hold=b,i.bits=_,(i.wsize||S!==t.avail_out&&i.mode<30&&(i.mode<27||4!==e))&&A(t,t.output,t.next_out,S-t.avail_out)?(i.mode=31,-4):(x-=t.avail_in,S-=t.avail_out,t.total_in+=x,t.total_out+=S,i.total+=S,i.wrap&&S&&(t.adler=i.check=i.flags?r(i.check,f,S,t.next_out-S):s(i.check,f,S,t.next_out-S)),t.data_type=i.bits+(i.last?64:0)+(12===i.mode?128:0)+(20===i.mode||15===i.mode?256:0),(0==x&&0===S||4===e)&&N===h&&(N=-5),N)},i.inflateEnd=function(t){if(!t||!t.state)return u;var e=t.state;return e.window&&(e.window=null),t.state=null,h},i.inflateGetHeader=function(t,e){var i;return t&&t.state&&2&(i=t.state).wrap?((i.head=e).done=!1,h):u},i.inflateSetDictionary=function(t,e){var i,n=e.length;return t&&t.state?0!==(i=t.state).wrap&&11!==i.mode?u:11===i.mode&&s(1,e,n,0)!==i.check?-3:A(t,e,n,n)?(i.mode=31,-4):(i.havedict=1,h):u},i.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(t,e,i){var n=t("../utils/common"),s=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],r=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],o=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],a=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];e.exports=function(t,e,i,l,c,h,u,d){var p,f,m,g,y,w,v,b,_,x=d.bits,S=0,C=0,A=0,E=0,T=0,I=0,P=0,M=0,k=0,D=0,z=null,B=0,O=new n.Buf16(16),N=new n.Buf16(16),V=null,F=0;for(S=0;S<=15;S++)O[S]=0;for(C=0;C<l;C++)O[e[i+C]]++;for(T=x,E=15;1<=E&&0===O[E];E--);if(E<T&&(T=E),0===E)return c[h++]=20971520,c[h++]=20971520,d.bits=1,0;for(A=1;A<E&&0===O[A];A++);for(T<A&&(T=A),S=M=1;S<=15;S++)if(M<<=1,(M-=O[S])<0)return-1;if(0<M&&(0===t||1!==E))return-1;for(N[1]=0,S=1;S<15;S++)N[S+1]=N[S]+O[S];for(C=0;C<l;C++)0!==e[i+C]&&(u[N[e[i+C]]++]=C);if(w=0===t?(z=V=u,19):1===t?(z=s,B-=257,V=r,F-=257,256):(z=o,V=a,-1),S=A,y=h,P=C=D=0,m=-1,g=(k=1<<(I=T))-1,1===t&&852<k||2===t&&592<k)return 1;for(;;){for(v=S-P,_=u[C]<w?(b=0,u[C]):u[C]>w?(b=V[F+u[C]],z[B+u[C]]):(b=96,0),p=1<<S-P,A=f=1<<I;c[y+(D>>P)+(f-=p)]=v<<24|b<<16|_,0!==f;);for(p=1<<S-1;D&p;)p>>=1;if(0!==p?(D&=p-1,D+=p):D=0,C++,0==--O[S]){if(S===E)break;S=e[i+u[C]]}if(T<S&&(D&g)!==m){for(0===P&&(P=T),y+=A,M=1<<(I=S-P);I+P<E&&!((M-=O[I+P])<=0);)I++,M<<=1;if(k+=1<<I,1===t&&852<k||2===t&&592<k)return 1;c[m=D&g]=T<<24|I<<16|y-h}}return 0!==D&&(c[y+D]=S-P<<24|64<<16),d.bits=T,0}},{"../utils/common":41}],51:[function(t,e,i){e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(t,e,i){var n=t("../utils/common"),s=0,r=1;function o(t){for(var e=t.length;0<=--e;)t[e]=0}var a=0,l=29,c=256,h=c+1+l,u=30,d=19,p=2*h+1,f=15,m=16,g=7,y=256,w=16,v=17,b=18,_=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],x=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],S=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],C=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],A=new Array(2*(h+2));o(A);var E=new Array(2*u);o(E);var T=new Array(512);o(T);var I=new Array(256);o(I);var P=new Array(l);o(P);var M,k,D,z=new Array(u);function B(t,e,i,n,s){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=s,this.has_stree=t&&t.length}function O(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function N(t){return t<256?T[t]:T[256+(t>>>7)]}function V(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function F(t,e,i){t.bi_valid>m-i?(t.bi_buf|=e<<t.bi_valid&65535,V(t,t.bi_buf),t.bi_buf=e>>m-t.bi_valid,t.bi_valid+=i-m):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=i)}function R(t,e,i){F(t,i[2*e],i[2*e+1])}function L(t,e){for(var i=0;i|=1&t,t>>>=1,i<<=1,0<--e;);return i>>>1}function U(t,e,i){var n,s,r=new Array(f+1),o=0;for(n=1;n<=f;n++)r[n]=o=o+i[n-1]<<1;for(s=0;s<=e;s++){var a=t[2*s+1];0!==a&&(t[2*s]=L(r[a]++,a))}}function $(t){var e;for(e=0;e<h;e++)t.dyn_ltree[2*e]=0;for(e=0;e<u;e++)t.dyn_dtree[2*e]=0;for(e=0;e<d;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*y]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function j(t){8<t.bi_valid?V(t,t.bi_buf):0<t.bi_valid&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function W(t,e,i,n){var s=2*e,r=2*i;return t[s]<t[r]||t[s]===t[r]&&n[e]<=n[i]}function Z(t,e,i){for(var n=t.heap[i],s=i<<1;s<=t.heap_len&&(s<t.heap_len&&W(e,t.heap[s+1],t.heap[s],t.depth)&&s++,!W(e,n,t.heap[s],t.depth));)t.heap[i]=t.heap[s],i=s,s<<=1;t.heap[i]=n}function G(t,e,i){var n,s,r,o,a=0;if(0!==t.last_lit)for(;n=t.pending_buf[t.d_buf+2*a]<<8|t.pending_buf[t.d_buf+2*a+1],s=t.pending_buf[t.l_buf+a],a++,0===n?R(t,s,e):(R(t,(r=I[s])+c+1,e),0!==(o=_[r])&&F(t,s-=P[r],o),R(t,r=N(--n),i),0!==(o=x[r])&&F(t,n-=z[r],o)),a<t.last_lit;);R(t,y,e)}function q(t,e){var i,n,s,r=e.dyn_tree,o=e.stat_desc.static_tree,a=e.stat_desc.has_stree,l=e.stat_desc.elems,c=-1;for(t.heap_len=0,t.heap_max=p,i=0;i<l;i++)0!==r[2*i]?(t.heap[++t.heap_len]=c=i,t.depth[i]=0):r[2*i+1]=0;for(;t.heap_len<2;)r[2*(s=t.heap[++t.heap_len]=c<2?++c:0)]=1,t.depth[s]=0,t.opt_len--,a&&(t.static_len-=o[2*s+1]);for(e.max_code=c,i=t.heap_len>>1;1<=i;i--)Z(t,r,i);for(s=l;i=t.heap[1],t.heap[1]=t.heap[t.heap_len--],Z(t,r,1),n=t.heap[1],t.heap[--t.heap_max]=i,t.heap[--t.heap_max]=n,r[2*s]=r[2*i]+r[2*n],t.depth[s]=(t.depth[i]>=t.depth[n]?t.depth[i]:t.depth[n])+1,r[2*i+1]=r[2*n+1]=s,t.heap[1]=s++,Z(t,r,1),2<=t.heap_len;);t.heap[--t.heap_max]=t.heap[1],function(t,e){var i,n,s,r,o,a,l=e.dyn_tree,c=e.max_code,h=e.stat_desc.static_tree,u=e.stat_desc.has_stree,d=e.stat_desc.extra_bits,m=e.stat_desc.extra_base,g=e.stat_desc.max_length,y=0;for(r=0;r<=f;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,i=t.heap_max+1;i<p;i++)g<(r=l[2*l[2*(n=t.heap[i])+1]+1]+1)&&(r=g,y++),l[2*n+1]=r,c<n||(t.bl_count[r]++,o=0,m<=n&&(o=d[n-m]),a=l[2*n],t.opt_len+=a*(r+o),u&&(t.static_len+=a*(h[2*n+1]+o)));if(0!==y){do{for(r=g-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[g]--,y-=2}while(0<y);for(r=g;0!==r;r--)for(n=t.bl_count[r];0!==n;)c<(s=t.heap[--i])||(l[2*s+1]!==r&&(t.opt_len+=(r-l[2*s+1])*l[2*s],l[2*s+1]=r),n--)}}(t,e),U(r,c,t.bl_count)}function Y(t,e,i){var n,s,r=-1,o=e[1],a=0,l=7,c=4;for(0===o&&(l=138,c=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)s=o,o=e[2*(n+1)+1],++a<l&&s===o||(a<c?t.bl_tree[2*s]+=a:0!==s?(s!==r&&t.bl_tree[2*s]++,t.bl_tree[2*w]++):a<=10?t.bl_tree[2*v]++:t.bl_tree[2*b]++,r=s,c=(a=0)===o?(l=138,3):s===o?(l=6,3):(l=7,4))}function H(t,e,i){var n,s,r=-1,o=e[1],a=0,l=7,c=4;for(0===o&&(l=138,c=3),n=0;n<=i;n++)if(s=o,o=e[2*(n+1)+1],!(++a<l&&s===o)){if(a<c)for(;R(t,s,t.bl_tree),0!=--a;);else 0!==s?(s!==r&&(R(t,s,t.bl_tree),a--),R(t,w,t.bl_tree),F(t,a-3,2)):a<=10?(R(t,v,t.bl_tree),F(t,a-3,3)):(R(t,b,t.bl_tree),F(t,a-11,7));r=s,c=(a=0)===o?(l=138,3):s===o?(l=6,3):(l=7,4)}}o(z);var X=!1;function Q(t,e,i,s){var r,o,l;F(t,(a<<1)+(s?1:0),3),o=e,l=i,j(r=t),V(r,l),V(r,~l),n.arraySet(r.pending_buf,r.window,o,l,r.pending),r.pending+=l}i._tr_init=function(t){X||(function(){var t,e,i,n,s,r=new Array(f+1);for(n=i=0;n<l-1;n++)for(P[n]=i,t=0;t<1<<_[n];t++)I[i++]=n;for(I[i-1]=n,n=s=0;n<16;n++)for(z[n]=s,t=0;t<1<<x[n];t++)T[s++]=n;for(s>>=7;n<u;n++)for(z[n]=s<<7,t=0;t<1<<x[n]-7;t++)T[256+s++]=n;for(e=0;e<=f;e++)r[e]=0;for(t=0;t<=143;)A[2*t+1]=8,t++,r[8]++;for(;t<=255;)A[2*t+1]=9,t++,r[9]++;for(;t<=279;)A[2*t+1]=7,t++,r[7]++;for(;t<=287;)A[2*t+1]=8,t++,r[8]++;for(U(A,h+1,r),t=0;t<u;t++)E[2*t+1]=5,E[2*t]=L(t,5);M=new B(A,_,c+1,h,f),k=new B(E,x,0,u,f),D=new B(new Array(0),S,0,d,g)}(),X=!0),t.l_desc=new O(t.dyn_ltree,M),t.d_desc=new O(t.dyn_dtree,k),t.bl_desc=new O(t.bl_tree,D),t.bi_buf=0,t.bi_valid=0,$(t)},i._tr_stored_block=Q,i._tr_flush_block=function(t,e,i,n){var o,a,l=0;0<t.level?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return s;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return r;for(e=32;e<c;e++)if(0!==t.dyn_ltree[2*e])return r;return s}(t)),q(t,t.l_desc),q(t,t.d_desc),l=function(t){var e;for(Y(t,t.dyn_ltree,t.l_desc.max_code),Y(t,t.dyn_dtree,t.d_desc.max_code),q(t,t.bl_desc),e=d-1;3<=e&&0===t.bl_tree[2*C[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),o=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=o&&(o=a)):o=a=i+5,i+4<=o&&-1!==e?Q(t,e,i,n):4===t.strategy||a===o?(F(t,2+(n?1:0),3),G(t,A,E)):(F(t,4+(n?1:0),3),function(t,e,i,n){var s;for(F(t,e-257,5),F(t,i-1,5),F(t,n-4,4),s=0;s<n;s++)F(t,t.bl_tree[2*C[s]+1],3);H(t,t.dyn_ltree,e-1),H(t,t.dyn_dtree,i-1)}(t,t.l_desc.max_code+1,t.d_desc.max_code+1,l+1),G(t,t.dyn_ltree,t.dyn_dtree)),$(t),n&&j(t)},i._tr_tally=function(t,e,i){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(I[i]+c+1)]++,t.dyn_dtree[2*N(e)]++),t.last_lit===t.lit_bufsize-1},i._tr_align=function(t){var e;F(t,2,3),R(t,y,A),16===(e=t).bi_valid?(V(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}},{"../utils/common":41}],53:[function(t,e,i){e.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(t,e,i){(function(t){!function(t,e){if(!t.setImmediate){var i,n,s,r,o=1,a={},l=!1,c=t.document,h=Object.getPrototypeOf&&Object.getPrototypeOf(t);h=h&&h.setTimeout?h:t,i="[object process]"==={}.toString.call(t.process)?function(t){process.nextTick(function(){d(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,i=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=i,e}}()?(r="setImmediate$"+Math.random()+"$",t.addEventListener?t.addEventListener("message",p,!1):t.attachEvent("onmessage",p),function(e){t.postMessage(r+e,"*")}):t.MessageChannel?((s=new MessageChannel).port1.onmessage=function(t){d(t.data)},function(t){s.port2.postMessage(t)}):c&&"onreadystatechange"in c.createElement("script")?(n=c.documentElement,function(t){var e=c.createElement("script");e.onreadystatechange=function(){d(t),e.onreadystatechange=null,n.removeChild(e),e=null},n.appendChild(e)}):function(t){setTimeout(d,0,t)},h.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n<e.length;n++)e[n]=arguments[n+1];var s={callback:t,args:e};return a[o]=s,i(o),o++},h.clearImmediate=u}function u(t){delete a[t]}function d(t){if(l)setTimeout(d,0,t);else{var i=a[t];if(i){l=!0;try{!function(t){var i=t.callback,n=t.args;switch(n.length){case 0:i();break;case 1:i(n[0]);break;case 2:i(n[0],n[1]);break;case 3:i(n[0],n[1],n[2]);break;default:i.apply(e,n)}}(i)}finally{u(t),l=!1}}}}function p(e){e.source===t&&"string"==typeof e.data&&0===e.data.indexOf(r)&&d(+e.data.slice(r.length))}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,void 0!==ns?ns:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[10])(10));class ls{constructor(t,i){e(this,"date",new Date),e(this,"author"),e(this,"guid",_.create()),e(this,"viewpoint"),e(this,"modifiedAuthor"),e(this,"modifiedDate"),e(this,"topic"),e(this,"_components"),e(this,"_comment",""),this._components=t,this._comment=i;const n=this._components.get(fs);this.author=n.config.author}set comment(t){var e;const i=this._components.get(fs);this._comment=t,this.modifiedDate=new Date,this.modifiedAuthor=i.config.author,null==(e=this.topic)||e.comments.set(this.guid,this)}get comment(){return this._comment}toJSON(){var t,e;const i={guid:this.guid,date:this.date.toISOString(),author:this.author,comment:this.comment,topic_guid:null==(t=this.topic)?void 0:t.guid,viewpoint_guid:this.viewpoint,modified_date:null==(e=this.modifiedDate)?void 0:e.toISOString(),modified_author:this.modifiedAuthor};for(const[t,e]of Object.entries(i))void 0===e&&delete i[t];return i}}const cs=class t{constructor(n){e(this,"guid",_.create()),e(this,"title",t.default.title),e(this,"creationDate",new Date),e(this,"creationAuthor",""),e(this,"viewpoints",new i.DataSet),e(this,"relatedTopics",new i.DataSet),e(this,"comments",new i.DataMap),e(this,"documentReferences",new i.DataSet),e(this,"customData",{}),e(this,"description"),e(this,"serverAssignedId"),e(this,"dueDate"),e(this,"modifiedAuthor"),e(this,"modifiedDate"),e(this,"index"),e(this,"_type",t.default.type),e(this,"_status",t.default.status),e(this,"_priority",t.default.priority),e(this,"_stage",t.default.stage),e(this,"_assignedTo",t.default.assignedTo),e(this,"_labels",t.default.labels??new Set),e(this,"_components"),this._components=n;const s=n.get(fs);this.creationAuthor=s.config.author,this.relatedTopics.guard=t=>t!==this.guid}set type(t){const e=this._components.get(fs),{strict:i,types:n}=e.config;(!i||n.has(t))&&(this._type=t)}get type(){return this._type}set status(t){const e=this._components.get(fs),{strict:i,statuses:n}=e.config;(!i||n.has(t))&&(this._status=t)}get status(){return this._status}set priority(t){const e=this._components.get(fs);if(t){const{strict:i,priorities:n}=e.config;if(!(!i||n.has(t)))return;this._priority=t}else this._priority=t}get priority(){return this._priority}set stage(t){const e=this._components.get(fs);if(t){const{strict:i,stages:n}=e.config;if(!(!i||n.has(t)))return;this._stage=t}else this._stage=t}get stage(){return this._stage}set assignedTo(t){const e=this._components.get(fs);if(t){const{strict:i,users:n}=e.config;if(!(!i||n.has(t)))return;this._assignedTo=t}else this._assignedTo=t}get assignedTo(){return this._assignedTo}set labels(t){const e=this._components.get(fs),{strict:i,labels:n}=e.config;if(i){const e=new Set;for(const s of t){(!i||n.has(s))&&e.add(s)}this._labels=e}else this._labels=t}get labels(){return this._labels}get _managerVersion(){return this._components.get(fs).config.version}set(t){const e=t,i=this;for(const n in t){if("guid"===n)continue;const t=e[n];n in this&&(i[n]=t)}return this._components.get(fs).list.set(this.guid,this),this}createComment(t,e){const i=new ls(this._components,t);return i.viewpoint=e,i.topic=this,this.comments.set(i.guid,i),i}createLabelTags(){const t=[...this.labels];if(this._components.get(fs).config.exportCustomDataAsLabels)for(const e in this.customData){const i=this.customData[e];"string"==typeof i&&t.push(i)}return t}createCommentTags(){return[...this.comments.values()].map(t=>{var e;return{$Guid:t.guid,Date:t.date.toISOString(),Author:t.author,Comment:t.comment,ModifiedAuthor:t.modifiedAuthor,ModifiedDate:null==(e=t.modifiedDate)?void 0:e.toISOString(),Viewpoint:t.viewpoint?{$Guid:t.viewpoint}:void 0}})}createViewpointTags(){const t=this._components.get(er);return[...this.viewpoints].map(e=>t.list.get(e)).filter(t=>t).map(e=>{const i={$Guid:e.guid,Viewpoint:`${e.title??e.guid}.bcfv`};if(t.snapshots.get(e.snapshot)){const n=t.getSnapshotExtension(e.snapshot);i.Snapshot=`${e.snapshot}.${n}`}return i})}createRelatedTopicTags(){return[...this.relatedTopics].map(t=>({$Guid:t}))}createDocumentReferencesTag(t=this._managerVersion){const e=[];if("3"!==t&&"2.1"!==t)return e;const i=this._components.get(fs);for(const n of this.documentReferences){const s=i.documents.get(n);if(!s)continue;let r={$Guid:_.create(),Description:s.description};"2.1"===t&&(r={...r,$isExternal:"external"===s.type||void 0,ReferencedDocument:"external"===s.type?s.url:`../${s.fileName}`}),"3"===t&&(r={...r,DocumentGuid:"internal"===s.type?n:void 0,Url:"external"===s.type?s.url:void 0}),Object.keys(r).length>0&&e.push(r)}return e}toJSON(){var t,e;const i={guid:this.guid,server_assigned_id:this.serverAssignedId,topic_type:this.type,topic_status:this.status,title:this.title,priority:this.priority,index:this.index,labels:[...this.labels],creation_date:this.creationDate.toISOString(),creation_author:this.creationAuthor,modified_date:null==(t=this.modifiedDate)?void 0:t.toISOString(),modified_author:this.modifiedAuthor,assigned_to:this.assignedTo,stage:this.stage,description:this.description,due_date:null==(e=this.dueDate)?void 0:e.toISOString(),comments:[...this.comments].map(([t,e])=>e.toJSON()),relatedTopics:[...this.relatedTopics].map(t=>({related_topic_guid:t}))},n=this._components.get(er);for(const t of this.viewpoints){const e=n.list.get(t);e&&(i.viewpoints||(i.viewpoints=[]),i.viewpoints.push(e.toJSON()))}const s=this._components.get(fs);for(const t of this.documentReferences){const e=s.documents.get(t);e&&(i.document_references||(i.document_references=[]),"external"===e.type?i.document_references.push({guid:_.create(),description:e.description,url:e.url}):i.document_references.push({guid:_.create(),description:e.description,document_guid:t}))}for(const[t,e]of Object.entries(i))(void 0===e||Array.isArray(e)&&0===e.length)&&delete i[t];return i}serialize(){var t,e;const i=this._managerVersion,n={$Guid:this.guid,$TopicType:this.type,$TopicStatus:this.status,$ServerAssignedId:this.serverAssignedId,Title:this.title,CreationAuthor:this.creationAuthor,CreationDate:this.creationDate.toISOString(),Priority:this.priority,Index:"2.1"===i?this.index:void 0,ModifiedDate:null==(t=this.modifiedDate)?void 0:t.toISOString(),ModifiedAuthor:this.modifiedAuthor,DueDate:null==(e=this.dueDate)?void 0:e.toISOString(),AssignedTo:this.assignedTo,Description:this.description,Stage:this.stage,DocumentReferences:"3"===i?{DocumentReference:this.createDocumentReferencesTag(i)}:void 0,RelatedTopics:"3"===i?{RelatedTopic:this.createRelatedTopicTags()}:void 0,RelatedTopic:"2.1"===i?this.createRelatedTopicTags():void 0,Labels:"3"===i?{Label:this.createLabelTags()}:void 0,Viewpoints:"3"===i?{ViewPoint:this.createViewpointTags()}:void 0,Comments:"3"===i?{Comment:this.createCommentTags()}:void 0};"2.1"===i&&(n.Labels=this.createLabelTags(),n.DocumentReference=this.createDocumentReferencesTag(i));const s={Markup:{Topic:n}};return"2.1"===i&&(s.Markup.Viewpoints=this.createViewpointTags(),s.Markup.Comment=this.createCommentTags()),`<?xml version="1.0" encoding="UTF-8"?>\n ${Nt.builder.build(s)}`}};e(cs,"default",{title:"BCF Topic",type:"Issue",status:"Active"});let hs=cs;const us=(t,e)=>{if(""===e.trim())return;const i=fs.xmlParser.parse(e).Extensions;if(!i)return;const{Priorities:n,TopicStatuses:s,TopicTypes:r,Users:o}=i;if(n&&n.Priority){const e=Array.isArray(n.Priority)?n.Priority:[n.Priority];for(const i of e)t.config.priorities.add(i)}if(s&&s.TopicStatus){const e=Array.isArray(s.TopicStatus)?s.TopicStatus:[s.TopicStatus];for(const i of e)t.config.statuses.add(i)}if(r&&r.TopicType){const e=Array.isArray(r.TopicType)?r.TopicType:[r.TopicType];for(const i of e)t.config.types.add(i)}if(o&&o.User){const e=Array.isArray(o.User)?o.User:[o.User];for(const i of e)t.config.users.add(i)}};class ds extends Lt{constructor(){super(...arguments),e(this,"_config",{version:{type:"Select",options:new Set(["2.1","3"]),multiple:!1,value:""},author:{type:"Text",value:""},types:{type:"TextSet",value:new Set},statuses:{type:"TextSet",value:new Set},priorities:{type:"TextSet",value:new Set},labels:{type:"TextSet",value:new Set},stages:{type:"TextSet",value:new Set},users:{type:"TextSet",value:new Set},includeSelectionTag:{type:"Boolean",value:!1},updateExtensionsOnImport:{type:"Boolean",value:!1},strict:{type:"Boolean",value:!1},includeAllExtensionsOnExport:{type:"Boolean",value:!1},fallbackVersionOnImport:{type:"Select",multiple:!1,options:new Set(["2.1","3"]),value:""},ignoreIncompleteTopicsOnImport:{type:"Boolean",value:!1},exportCustomDataAsLabels:{type:"Boolean",value:!1}})}get version(){return this._config.version.value}set version(t){this._config.version.value=t}get author(){return this._config.author.value}set author(t){this._config.author.value=t}get types(){return this._config.types.value}set types(t){this._config.types.value=t}get statuses(){return this._config.statuses.value}set statuses(t){this._config.statuses.value=t}get priorities(){return this._config.priorities.value}set priorities(t){this._config.priorities.value=t}get labels(){return this._config.labels.value}set labels(t){this._config.labels.value=t}get stages(){return this._config.stages.value}set stages(t){this._config.stages.value=t}get users(){return this._config.users.value}set users(t){this._config.users.value=t}get includeSelectionTag(){return this._config.includeSelectionTag.value}set includeSelectionTag(t){this._config.includeSelectionTag.value=t}get updateExtensionsOnImport(){return this._config.updateExtensionsOnImport.value}set updateExtensionsOnImport(t){this._config.updateExtensionsOnImport.value=t}get strict(){return this._config.strict.value}set strict(t){this._config.strict.value=t}get includeAllExtensionsOnExport(){return this._config.includeAllExtensionsOnExport.value}set includeAllExtensionsOnExport(t){this._config.includeAllExtensionsOnExport.value=t}get fallbackVersionOnImport(){return this._config.fallbackVersionOnImport.value}set fallbackVersionOnImport(t){this._config.fallbackVersionOnImport.value=t}get ignoreIncompleteTopicsOnImport(){return this._config.ignoreIncompleteTopicsOnImport.value}set ignoreIncompleteTopicsOnImport(t){this._config.ignoreIncompleteTopicsOnImport.value=t}get exportCustomDataAsLabels(){return this._config.exportCustomDataAsLabels.value}set exportCustomDataAsLabels(t){this._config.exportCustomDataAsLabels.value=t}}const ps=class t extends d{constructor(){super(...arguments),e(this,"enabled",!1),e(this,"_defaultConfig",{author:"jhon.doe@example.com",version:"2.1",types:new Set(["Clash","Failure","Fault","Inquiry","Issue","Remark","Request"]),statuses:new Set(["Active","In Progress","Done","In Review","Closed"]),priorities:new Set(["On hold","Minor","Normal","Major","Critical"]),labels:new Set,stages:new Set,users:new Set,includeSelectionTag:!1,updateExtensionsOnImport:!0,strict:!1,includeAllExtensionsOnExport:!0,fallbackVersionOnImport:"2.1",ignoreIncompleteTopicsOnImport:!1,exportCustomDataAsLabels:!1}),e(this,"config",new ds(this,this.components,"BCF Topics",t.uuid)),e(this,"list",new i.DataMap),e(this,"documents",new i.DataMap),e(this,"onSetup",new h),e(this,"isSetup",!1),e(this,"onBCFImported",new h),e(this,"onDisposed",new h)}setup(t){if(this.isSetup)return;const e={...this._defaultConfig,...t};this.config.version=e.version,this.config.author=e.author,this.config.types=e.types,this.config.statuses=e.statuses,this.config.priorities=e.priorities,this.config.labels=e.labels,this.config.stages=e.stages,this.config.users=e.users,this.config.includeSelectionTag=e.includeSelectionTag,this.config.updateExtensionsOnImport=e.updateExtensionsOnImport,this.config.strict=e.strict,this.config.includeAllExtensionsOnExport=e.includeAllExtensionsOnExport,this.config.fallbackVersionOnImport=e.fallbackVersionOnImport||"",this.config.ignoreIncompleteTopicsOnImport=e.ignoreIncompleteTopicsOnImport,this.isSetup=!0,this.enabled=!0,this.onSetup.trigger()}create(t){const e=new hs(this.components);return t?(e.guid=t.guid??e.guid,e.set(t)):this.list.set(e.guid,e),e}dispose(){this.list.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}get usedTypes(){const t=[...this.list].map(([t,e])=>e.type);return new Set(t)}get usedStatuses(){const t=[...this.list].map(([t,e])=>e.status);return new Set(t)}get usedPriorities(){const t=[...this.list].map(([t,e])=>e.priority).filter(t=>t);return new Set(t)}get usedStages(){const t=[...this.list].map(([t,e])=>e.stage).filter(t=>t);return new Set(t)}get usedUsers(){const t=[];for(const[e,i]of this.list){t.push(i.creationAuthor),i.assignedTo&&t.push(i.assignedTo),i.modifiedAuthor&&t.push(i.modifiedAuthor);for(const[e,n]of i.comments)t.push(n.author),n.modifiedAuthor&&t.push(n.modifiedAuthor)}return new Set(t)}get usedLabels(){const t=[];for(const[e,i]of this.list)t.push(...i.labels);return new Set(t)}updateExtensions(){for(const[t,e]of this.list){for(const t of e.labels)this.config.labels.add(t);this.config.types.add(e.type),e.priority&&this.config.priorities.add(e.priority),e.stage&&this.config.stages.add(e.stage),this.config.statuses.add(e.status),this.config.users.add(e.creationAuthor),e.assignedTo&&this.config.users.add(e.assignedTo),e.modifiedAuthor&&this.config.users.add(e.modifiedAuthor);for(const[t,i]of e.comments)this.config.users.add(i.author),i.modifiedAuthor&&this.config.users.add(i.modifiedAuthor)}}updateViewpointReferences(){const t=this.components.get(er);for(const[e,i]of this.list)for(const e of i.viewpoints){t.list.has(e)||i.viewpoints.delete(e)}}async export(t=this.list.values()){const e=new as;e.file("bcf.version",`<?xml version="1.0" encoding="UTF-8"?>\n <Version VersionId="${this.config.version}" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/buildingSMART/BCF-XML/release_3_0/Schemas/version.xsd"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n </Version>`);for(const[t,i]of this.documents.entries())"external"!==i.type&&e.file("2.1"===this.config.version?i.fileName:`documents/${t}`,i.data);if("3"===this.config.version){const t=[];for(const[e,i]of this.documents.entries()){const{type:n,description:s}=i;"external"!==n&&t.push(`<Document Guid="${e}">\n <Filename>${i.fileName}</Filename>\n ${s?`<Description>${s}</Description>`:""}\n </Document>`)}t.length>0&&e.file("documents.xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n <DocumentInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="documents.xsd">\n <Documents>\n ${t.join("\n")}\n </Documents>\n </DocumentInfo>`)}e.file("bcf.extensions",this.serializeExtensions());const i=this.components.get(er);for(const n of t){const t=e.folder(n.guid);t.file("markup.bcf",n.serialize());for(const e of n.viewpoints){const n=i.list.get(e);if(!n)continue;const s=n.title??n.guid;t.file(`${s}.bcfv`,await n.serialize());const r=i.snapshots.get(n.snapshot);if(!r)continue;const o=r?n.snapshot:n.guid,a=i.getSnapshotExtension(n.snapshot);t.file(`${o}.${a}`,r,{binary:!0})}}return await e.generateAsync({type:"blob"})}serializeExtensions(){const t=[...this.config.types].map(t=>`<TopicType>${t}</TopicType>`).join("\n"),e=[...this.config.statuses].map(t=>`<TopicStatus>${t}</TopicStatus>`).join("\n"),i=[...this.config.priorities].map(t=>`<Priority>${t}</Priority>`).join("\n"),n=[...this.config.labels].map(t=>`<TopicLabel>${t}</TopicLabel>`).join("\n"),s=[...this.config.stages].map(t=>`<Stage>${t}</Stage>`).join("\n"),r=[...this.config.users].map(t=>`<User>${t}</User>`).join("\n");return`\n <?xml version="1.0" encoding="UTF-8"?>\n <Extensions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="your-schema-location.xsd">\n ${0!==t.length?`<TopicTypes>\n${t}\n</TopicTypes>`:""}\n ${0!==e.length?`<TopicStatuses>\n${e}\n</TopicStatuses>`:""}\n ${0!==i.length?`<Priorities>\n${i}\n</Priorities>`:""}\n ${0!==n.length?`<TopicLabels>\n${n}\n</TopicLabels>`:""}\n ${0!==s.length?`<Stages>\n${s}\n</Stages>`:""}\n ${0!==r.length?`<Users>\n${r}\n</Users>`:""}\n </Extensions>\n `}processMarkupComment(t){const{Guid:e,Date:i,Author:n,Comment:s,Viewpoint:r}=t;if(!(e&&i&&n&&(ls||r)))return null;const o=new ls(this.components,s??"");return o.guid=e,o.date=new Date(i),o.author=n,o.viewpoint=null==r?void 0:r.Guid,o.modifiedAuthor=t.ModifiedAuthor,o.modifiedDate=t.ModifiedDate?new Date(t.ModifiedDate):void 0,o}getMarkupComments(t,e){var i;let n;if("2.1"===e&&(n=t.Comment),"3"===e&&(n=null==(i=t.Topic.Comments)?void 0:i.Comment),!n)return[];n=Array.isArray(n)?n:[n];const s=n.map(t=>this.processMarkupComment(t)).filter(t=>t);return Array.isArray(s)?s:[s]}getMarkupLabels(t,e){var i;let n;if("2.1"===e&&(n=t.Topic.Labels),"3"===e&&(n=null==(i=t.Topic.Labels)?void 0:i.Label),!n)return[];return Array.isArray(n)?n:[n]}getMarkupViewpoints(t,e){var i;let n;return"2.1"===e&&(n=t.Viewpoints),"3"===e&&(n=null==(i=t.Topic.Viewpoints)?void 0:i.ViewPoint),n?(n=Array.isArray(n)?n:[n],n):[]}getMarkupRelatedTopics(t,e){var i;let n;if("2.1"===e&&(n=t.Topic.RelatedTopic),"3"===e&&(n=null==(i=t.Topic.RelatedTopics)?void 0:i.RelatedTopic),!n)return[];return(Array.isArray(n)?n:[n]).map(t=>t.Guid)}getMarkupDocumentReferences(t,e){var i;let n;if("2.1"===e&&(n=t.Topic.DocumentReference),"3"===e&&(n=null==(i=t.Topic.DocumentReferences)?void 0:i.DocumentReference),!n)return[];return Array.isArray(n)?n:[n]}async load(e){var i,n,s;const{fallbackVersionOnImport:r,ignoreIncompleteTopicsOnImport:o,updateExtensionsOnImport:a}=this.config,c=new as;await c.loadAsync(e);const h=Object.values(c.files);let u=r;const d=h.find(t=>t.name.endsWith(".version"));if(d){const e=await d.async("string"),i=t.xmlParser.parse(e).Version.VersionId;u=String(i)}if(!u||"2.1"!==u&&"3"!==u)throw new Error(`BCFTopics: ${u} is not supported.`);const p=h.find(t=>t.name.endsWith(".extensions"));if(a&&p){const t=await p.async("string");us(this,t)}const f=[],m=this.components.get(er),g=h.filter(t=>t.name.endsWith(".bcfv"));for(const e of g){const n=await e.async("string"),s=t.xmlParser.parse(n).VisualizationInfo;if(!s){console.warn("Missing VisualizationInfo in Viewpoint");continue}const r={},{Guid:o,ClippingPlanes:a,Components:c,OrthogonalCamera:h,PerspectiveCamera:d}=s;if(o&&(r.guid=o),c){const t={selection:[],coloring:[],visibility:{default_visibility:!1,exceptions:[],view_setup_hints:{spaces_visible:!1,space_boundaries_visible:!1,openings_visible:!1}}};r.components=t;const{Selection:e,Visibility:n}=c;if(e&&e.Component){const i=Array.isArray(e.Component)?e.Component:[e.Component];t.selection=i.map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t)}if(n&&"DefaultVisibility"in n&&(t.visibility.default_visibility=n.DefaultVisibility),n&&n.Exceptions&&"Component"in n.Exceptions){const{Component:e}=n.Exceptions,i=Array.isArray(e)?e:[e];t.visibility.exceptions=i.map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t)}let s;"2.1"===u&&(s=c.ViewSetupHints),"3"===u&&(s=null==(i=c.Visibility)?void 0:i.ViewSetupHints),s&&("OpeningsVisible"in s&&(t.visibility.view_setup_hints.openings_visible=s.OpeningsVisible),"SpacesVisible"in s&&(t.visibility.view_setup_hints.spaces_visible=s.SpacesVisible),"SpaceBoundariesVisible"in s&&(t.visibility.view_setup_hints.space_boundaries_visible=s.SpaceBoundariesVisible));const{Coloring:o}=c;if(o&&o.Color){const e=Array.isArray(o.Color)?o.Color:[o.Color];for(const i of e){const{Color:e,Component:n}=i;if(6!==e.length&&8!==e.length)continue;const s=6===e.length?e:e.slice(2),r=(Array.isArray(n)?n:[n]).map(t=>t.IfcGuid?{ifc_guid:t.IfcGuid}:null).filter(t=>null!==t);t.coloring.push({color:s,components:r})}}}if(h||d){const t=s.PerspectiveCamera??s.OrthogonalCamera,{CameraViewPoint:e,CameraDirection:i}=t,n=new l.Vector3(Number(e.X),Number(e.Z),Number(-e.Y)),o=new l.Vector3(Number(i.X),Number(i.Z),Number(-i.Y)),a={camera_view_point:{x:n.x,y:n.y,z:n.z},camera_direction:{x:o.x,y:o.y,z:o.z},aspect_ratio:"AspectRatio"in t?t.AspectRatio:1,camera_up_vector:{x:0,y:0,z:0}};"ViewToWorldScale"in t&&(r.orthogonal_camera={...a,view_to_world_scale:t.ViewToWorldScale}),"FieldOfView"in t&&(r.perspective_camera={...a,field_of_view:t.FieldOfView})}if(a){const t=(Array.isArray(a.ClippingPlane)?a.ClippingPlane:[a.ClippingPlane]).map(({Location:t,Direction:e})=>({location:{x:t.x,y:t.y,z:t.z},direction:{x:e.x,y:e.y,z:e.z}}));r.clipping_planes=t}const p=new Ks(this.components,r);f.push(p)}const y={},w=[],v=h.filter(t=>t.name.endsWith(".bcf"));for(const e of v){const i=await e.async("string"),r=t.xmlParser.parse(i).Markup,a=r.Topic,{Guid:l,TopicType:c,TopicStatus:d,Title:p,CreationDate:f,CreationAuthor:g}=a;if(o&&!(l&&c&&d&&p&&f&&g))continue;const v=new hs(this.components);v.guid=l??v.guid;const b=this.getMarkupRelatedTopics(r,u);y[v.guid]=new Set(b),v.type=c??v.type,v.status=d??v.status,v.title=p??v.title,v.creationDate=f?new Date(f):v.creationDate,v.creationAuthor=g??v.creationAuthor,v.serverAssignedId=a.ServerAssignedId,v.priority=a.Priority,v.index=a.Index,v.modifiedDate=a.ModifiedDate?new Date(a.ModifiedDate):void 0,v.modifiedAuthor=a.ModifiedAuthor,v.dueDate=a.DueDate?new Date(a.DueDate):void 0,v.assignedTo=a.AssignedTo,v.description=a.Description,v.stage=a.Stage;const _=this.getMarkupLabels(r,u);for(const t of _)v.labels.add(t);const x=this.getMarkupComments(r,u);for(const t of x)v.comments.set(t.guid,t);const S=this.getMarkupViewpoints(r,u);for(const t of S){if(!t||!t.Guid)continue;const e=m.list.get(t.Guid);if(!e)continue;v.viewpoints.add(e.guid);const i=`${v.guid}/${t.Snapshot}`,n=h.find(({name:t})=>t===i);if(n){const t=await n.async("arraybuffer"),i=new Uint8Array(t);m.snapshots.set(e.guid,i),e.snapshot=e.guid??null}}const C=this.getMarkupDocumentReferences(r,u),A=h.find(t=>"documents.xml"===t.name);let E=[];const T=await(null==A?void 0:A.async("string"));if(T){const t=null==(s=null==(n=Nt.parser.parse(T).DocumentInfo)?void 0:n.Documents)?void 0:s.Document;E=Array.isArray(t)?t:[t]}for(const t of C){const{Description:e,DocumentGuid:i,Url:n,isExternal:s,ReferencedDocument:r}=t;if(i&&E.length>0){const t=E.find(({Guid:t})=>t===i),e=h.find(t=>t.name.endsWith(i)),n=await(null==e?void 0:e.async("uint8array"));if(!t||!n)continue;const{Description:s,Filename:r}=t;this.documents.set(i,{type:"internal",fileName:r,description:s,data:n}),v.documentReferences.add(i)}if(n){const t=this.documents.add({type:"external",url:n,description:e});v.documentReferences.add(t)}if(r){let t=null;if(s)t=this.documents.add({type:"external",url:r,description:e});else{const i=r.split("/"),n=i[i.length-1],s=h.find(t=>t.name.endsWith(n)),o=await(null==s?void 0:s.async("uint8array"));if(!o)continue;t=this.documents.add({type:"internal",fileName:n,data:o,description:e})}v.documentReferences.add(t)}}this.list.set(v.guid,v),w.push(v)}for(const t in y){const e=this.list.get(t);if(!e)continue;const i=y[t];for(const t of i)e.relatedTopics.add(t)}return this.onBCFImported.trigger(w),{viewpoints:f,topics:w}}};e(ps,"uuid","de977976-e4f6-4e4f-a01a-204727839802"),e(ps,"xmlParser",new Ct({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0}));let fs=ps;const ms=new n.Raycaster,gs=new n.Vector3,ys=new n.Vector3,ws=new n.Quaternion,vs={X:new n.Vector3(1,0,0),Y:new n.Vector3(0,1,0),Z:new n.Vector3(0,0,1)},bs={type:"change"},_s={type:"mouseDown",mode:null},xs={type:"mouseUp",mode:null},Ss={type:"objectChange"};class Cs extends n.Controls{constructor(t,e=null){super(void 0,e);const i=new Zs(this);this._root=i;const s=new Gs;this._gizmo=s,i.add(s);const r=new qs;this._plane=r,i.add(r);const o=this;function a(t,e){let i=e;Object.defineProperty(o,t,{get:function(){return void 0!==i?i:e},set:function(e){i!==e&&(i=e,r[t]=e,s[t]=e,o.dispatchEvent({type:t+"-changed",value:e}),o.dispatchEvent(bs))}}),o[t]=e,r[t]=e,s[t]=e}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const l=new n.Vector3,c=new n.Vector3,h=new n.Quaternion,u=new n.Quaternion,d=new n.Vector3,p=new n.Quaternion,f=new n.Vector3,m=new n.Vector3,g=new n.Vector3,y=new n.Vector3;a("worldPosition",l),a("worldPositionStart",c),a("worldQuaternion",h),a("worldQuaternionStart",u),a("cameraPosition",d),a("cameraQuaternion",p),a("pointStart",f),a("pointEnd",m),a("rotationAxis",g),a("rotationAngle",0),a("eye",y),this._offset=new n.Vector3,this._startNorm=new n.Vector3,this._endNorm=new n.Vector3,this._cameraScale=new n.Vector3,this._parentPosition=new n.Vector3,this._parentQuaternion=new n.Quaternion,this._parentQuaternionInv=new n.Quaternion,this._parentScale=new n.Vector3,this._worldScaleStart=new n.Vector3,this._worldQuaternionInv=new n.Quaternion,this._worldScale=new n.Vector3,this._positionStart=new n.Vector3,this._quaternionStart=new n.Quaternion,this._scaleStart=new n.Vector3,this._getPointer=As.bind(this),this._onPointerDown=Ts.bind(this),this._onPointerHover=Es.bind(this),this._onPointerMove=Is.bind(this),this._onPointerUp=Ps.bind(this),null!==e&&this.connect(e)}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(void 0===this.object||!0===this.dragging)return;null!==t&&ms.setFromCamera(t,this.camera);const e=Ms(this._gizmo.picker[this.mode],ms);this.axis=e?e.object.name:null}pointerDown(t){if(void 0!==this.object&&!0!==this.dragging&&(null==t||0===t.button)&&null!==this.axis){null!==t&&ms.setFromCamera(t,this.camera);const e=Ms(this._plane,ms,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,_s.mode=this.mode,this.dispatchEvent(_s)}}pointerMove(t){const e=this.axis,i=this.mode,n=this.object;let s=this.space;if("scale"===i?s="local":"E"!==e&&"XYZE"!==e&&"XYZ"!==e||(s="world"),void 0===n||null===e||!1===this.dragging||null!==t&&-1!==t.button)return;null!==t&&ms.setFromCamera(t,this.camera);const r=Ms(this._plane,ms,!0);if(r){if(this.pointEnd.copy(r.point).sub(this.worldPositionStart),"translate"===i)this._offset.copy(this.pointEnd).sub(this.pointStart),"local"===s&&"XYZ"!==e&&this._offset.applyQuaternion(this._worldQuaternionInv),-1===e.indexOf("X")&&(this._offset.x=0),-1===e.indexOf("Y")&&(this._offset.y=0),-1===e.indexOf("Z")&&(this._offset.z=0),"local"===s&&"XYZ"!==e?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),n.position.copy(this._offset).add(this._positionStart),this.translationSnap&&("local"===s&&(n.position.applyQuaternion(ws.copy(this._quaternionStart).invert()),-1!==e.search("X")&&(n.position.x=Math.round(n.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(n.position.y=Math.round(n.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(n.position.z=Math.round(n.position.z/this.translationSnap)*this.translationSnap),n.position.applyQuaternion(this._quaternionStart)),"world"===s&&(n.parent&&n.position.add(gs.setFromMatrixPosition(n.parent.matrixWorld)),-1!==e.search("X")&&(n.position.x=Math.round(n.position.x/this.translationSnap)*this.translationSnap),-1!==e.search("Y")&&(n.position.y=Math.round(n.position.y/this.translationSnap)*this.translationSnap),-1!==e.search("Z")&&(n.position.z=Math.round(n.position.z/this.translationSnap)*this.translationSnap),n.parent&&n.position.sub(gs.setFromMatrixPosition(n.parent.matrixWorld)))),n.position.x=Math.max(this.minX,Math.min(this.maxX,n.position.x)),n.position.y=Math.max(this.minY,Math.min(this.maxY,n.position.y)),n.position.z=Math.max(this.minZ,Math.min(this.maxZ,n.position.z));else if("scale"===i){if(-1!==e.search("XYZ")){let t=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(t*=-1),ys.set(t,t,t)}else gs.copy(this.pointStart),ys.copy(this.pointEnd),gs.applyQuaternion(this._worldQuaternionInv),ys.applyQuaternion(this._worldQuaternionInv),ys.divide(gs),-1===e.search("X")&&(ys.x=1),-1===e.search("Y")&&(ys.y=1),-1===e.search("Z")&&(ys.z=1);n.scale.copy(this._scaleStart).multiply(ys),this.scaleSnap&&(-1!==e.search("X")&&(n.scale.x=Math.round(n.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Y")&&(n.scale.y=Math.round(n.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),-1!==e.search("Z")&&(n.scale.z=Math.round(n.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if("rotate"===i){this._offset.copy(this.pointEnd).sub(this.pointStart);const t=20/this.worldPosition.distanceTo(gs.setFromMatrixPosition(this.camera.matrixWorld));let i=!1;"XYZE"===e?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(gs.copy(this.rotationAxis).cross(this.eye))*t):"X"!==e&&"Y"!==e&&"Z"!==e||(this.rotationAxis.copy(vs[e]),gs.copy(vs[e]),"local"===s&&gs.applyQuaternion(this.worldQuaternion),gs.cross(this.eye),0===gs.length()?i=!0:this.rotationAngle=this._offset.dot(gs.normalize())*t),("E"===e||i)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),"local"===s&&"E"!==e&&"XYZE"!==e?(n.quaternion.copy(this._quaternionStart),n.quaternion.multiply(ws.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),n.quaternion.copy(ws.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),n.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(bs),this.dispatchEvent(Ss)}}pointerUp(t){null!==t&&0!==t.button||(this.dragging&&null!==this.axis&&(xs.mode=this.mode,this.dispatchEvent(xs)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(bs),this.dispatchEvent(Ss),this.pointStart.copy(this.pointEnd))}getRaycaster(){return ms}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}}function As(t){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:t.button};{const e=this.domElement.getBoundingClientRect();return{x:(t.clientX-e.left)/e.width*2-1,y:-(t.clientY-e.top)/e.height*2+1,button:t.button}}}function Es(t){if(this.enabled)switch(t.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(t))}}function Ts(t){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(t)),this.pointerDown(this._getPointer(t)))}function Is(t){this.enabled&&this.pointerMove(this._getPointer(t))}function Ps(t){this.enabled&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(t)))}function Ms(t,e,i){const n=e.intersectObject(t,!0);for(let t=0;t<n.length;t++)if(n[t].object.visible||i)return n[t];return!1}const ks=new n.Euler,Ds=new n.Vector3(0,1,0),zs=new n.Vector3(0,0,0),Bs=new n.Matrix4,Os=new n.Quaternion,Ns=new n.Quaternion,Vs=new n.Vector3,Fs=new n.Matrix4,Rs=new n.Vector3(1,0,0),Ls=new n.Vector3(0,1,0),Us=new n.Vector3(0,0,1),$s=new n.Vector3,js=new n.Vector3,Ws=new n.Vector3;class Zs extends n.Object3D{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;void 0!==e.object&&(e.object.updateMatrixWorld(),null===e.object.parent?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class Gs extends n.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new n.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new n.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=t.clone();i.opacity=.15;const s=e.clone();s.opacity=.5;const r=t.clone();r.color.setHex(16711680);const o=t.clone();o.color.setHex(65280);const a=t.clone();a.color.setHex(255);const l=t.clone();l.color.setHex(16711680),l.opacity=.5;const c=t.clone();c.color.setHex(65280),c.opacity=.5;const h=t.clone();h.color.setHex(255),h.opacity=.5;const u=t.clone();u.opacity=.25;const d=t.clone();d.color.setHex(16776960),d.opacity=.25;t.clone().color.setHex(16776960);const p=t.clone();p.color.setHex(7895160);const f=new n.CylinderGeometry(0,.04,.1,12);f.translate(0,.05,0);const m=new n.BoxGeometry(.08,.08,.08);m.translate(0,.04,0);const g=new n.BufferGeometry;g.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,0,0],3));const y=new n.CylinderGeometry(.0075,.0075,.5,3);function w(t,e){const i=new n.TorusGeometry(t,.0075,3,64,e*Math.PI*2);return i.rotateY(Math.PI/2),i.rotateX(Math.PI/2),i}y.translate(0,.25,0);const v={X:[[new n.Mesh(f,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(f,r),[-.5,0,0],[0,0,Math.PI/2]],[new n.Mesh(y,r),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new n.Mesh(f,o),[0,.5,0]],[new n.Mesh(f,o),[0,-.5,0],[Math.PI,0,0]],[new n.Mesh(y,o)]],Z:[[new n.Mesh(f,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(f,a),[0,0,-.5],[-Math.PI/2,0,0]],[new n.Mesh(y,a),null,[Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.1,0),u.clone()),[0,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),h.clone()),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),c.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},b={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.OctahedronGeometry(.2,0),i)]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},_={START:[[new n.Mesh(new n.OctahedronGeometry(.01,2),s),null,null,null,"helper"]],END:[[new n.Mesh(new n.OctahedronGeometry(.01,2),s),null,null,null,"helper"]],DELTA:[[new n.Line(function(){const t=new n.BufferGeometry;return t.setAttribute("position",new n.Float32BufferAttribute([0,0,0,1,1,1],3)),t}(),s),null,null,null,"helper"]],X:[[new n.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(g,s.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(g,s.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},x={XYZE:[[new n.Mesh(w(.5,1),p),null,[0,Math.PI/2,0]]],X:[[new n.Mesh(w(.5,.5),r)]],Y:[[new n.Mesh(w(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new n.Mesh(w(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new n.Mesh(w(.75,1),d),null,[0,Math.PI/2,0]]]},S={AXIS:[[new n.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},C={XYZE:[[new n.Mesh(new n.SphereGeometry(.25,10,8),i)]],X:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new n.Mesh(new n.TorusGeometry(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new n.Mesh(new n.TorusGeometry(.75,.1,2,24),i)]]},A={X:[[new n.Mesh(m,r),[.5,0,0],[0,0,-Math.PI/2]],[new n.Mesh(y,r),[0,0,0],[0,0,-Math.PI/2]],[new n.Mesh(m,r),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(m,o),[0,.5,0]],[new n.Mesh(y,o)],[new n.Mesh(m,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new n.Mesh(m,a),[0,0,.5],[Math.PI/2,0,0]],[new n.Mesh(y,a),[0,0,0],[Math.PI/2,0,0]],[new n.Mesh(m,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),h),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.1,.1,.1),u.clone())]]},E={X:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,.3,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new n.Mesh(new n.CylinderGeometry(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new n.Mesh(new n.BoxGeometry(.2,.2,.2),i),[0,0,0]]]},T={X:[[new n.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new n.Line(g,s.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new n.Line(g,s.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function I(t){const e=new n.Object3D;for(const i in t)for(let n=t[i].length;n--;){const s=t[i][n][0].clone(),r=t[i][n][1],o=t[i][n][2],a=t[i][n][3],l=t[i][n][4];s.name=i,s.tag=l,r&&s.position.set(r[0],r[1],r[2]),o&&s.rotation.set(o[0],o[1],o[2]),a&&s.scale.set(a[0],a[1],a[2]),s.updateMatrix();const c=s.geometry.clone();c.applyMatrix4(s.matrix),s.geometry=c,s.renderOrder=1/0,s.position.set(0,0,0),s.rotation.set(0,0,0),s.scale.set(1,1,1),e.add(s)}return e}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=I(v)),this.add(this.gizmo.rotate=I(x)),this.add(this.gizmo.scale=I(A)),this.add(this.picker.translate=I(b)),this.add(this.picker.rotate=I(C)),this.add(this.picker.scale=I(E)),this.add(this.helper.translate=I(_)),this.add(this.helper.rotate=I(S)),this.add(this.helper.scale=I(T)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const e="local"===("scale"===this.mode?"local":this.space)?this.worldQuaternion:Ns;this.gizmo.translate.visible="translate"===this.mode,this.gizmo.rotate.visible="rotate"===this.mode,this.gizmo.scale.visible="scale"===this.mode,this.helper.translate.visible="translate"===this.mode,this.helper.rotate.visible="rotate"===this.mode,this.helper.scale.visible="scale"===this.mode;let i=[];i=i.concat(this.picker[this.mode].children),i=i.concat(this.gizmo[this.mode].children),i=i.concat(this.helper[this.mode].children);for(let t=0;t<i.length;t++){const n=i[t];let s;if(n.visible=!0,n.rotation.set(0,0,0),n.position.copy(this.worldPosition),s=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),n.scale.set(1,1,1).multiplyScalar(s*this.size/4),"helper"!==n.tag){if(n.quaternion.copy(e),"translate"===this.mode||"scale"===this.mode){const t=.99,i=.2;"X"===n.name&&Math.abs(Ds.copy(Rs).applyQuaternion(e).dot(this.eye))>t&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),"Y"===n.name&&Math.abs(Ds.copy(Ls).applyQuaternion(e).dot(this.eye))>t&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),"Z"===n.name&&Math.abs(Ds.copy(Us).applyQuaternion(e).dot(this.eye))>t&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),"XY"===n.name&&Math.abs(Ds.copy(Us).applyQuaternion(e).dot(this.eye))<i&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),"YZ"===n.name&&Math.abs(Ds.copy(Rs).applyQuaternion(e).dot(this.eye))<i&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),"XZ"===n.name&&Math.abs(Ds.copy(Ls).applyQuaternion(e).dot(this.eye))<i&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)}else"rotate"===this.mode&&(Os.copy(e),Ds.copy(this.eye).applyQuaternion(ws.copy(e).invert()),-1!==n.name.search("E")&&n.quaternion.setFromRotationMatrix(Bs.lookAt(this.eye,zs,Ls)),"X"===n.name&&(ws.setFromAxisAngle(Rs,Math.atan2(-Ds.y,Ds.z)),ws.multiplyQuaternions(Os,ws),n.quaternion.copy(ws)),"Y"===n.name&&(ws.setFromAxisAngle(Ls,Math.atan2(Ds.x,Ds.z)),ws.multiplyQuaternions(Os,ws),n.quaternion.copy(ws)),"Z"===n.name&&(ws.setFromAxisAngle(Us,Math.atan2(Ds.y,Ds.x)),ws.multiplyQuaternions(Os,ws),n.quaternion.copy(ws)));n.visible=n.visible&&(-1===n.name.indexOf("X")||this.showX),n.visible=n.visible&&(-1===n.name.indexOf("Y")||this.showY),n.visible=n.visible&&(-1===n.name.indexOf("Z")||this.showZ),n.visible=n.visible&&(-1===n.name.indexOf("E")||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis||this.axis.split("").some(function(t){return n.name===t}))&&(n.material.color.setHex(16776960),n.material.opacity=1)}else n.visible=!1,"AXIS"===n.name?(n.visible=!!this.axis,"X"===this.axis&&(ws.setFromEuler(ks.set(0,0,0)),n.quaternion.copy(e).multiply(ws),Math.abs(Ds.copy(Rs).applyQuaternion(e).dot(this.eye))>.9&&(n.visible=!1)),"Y"===this.axis&&(ws.setFromEuler(ks.set(0,0,Math.PI/2)),n.quaternion.copy(e).multiply(ws),Math.abs(Ds.copy(Ls).applyQuaternion(e).dot(this.eye))>.9&&(n.visible=!1)),"Z"===this.axis&&(ws.setFromEuler(ks.set(0,Math.PI/2,0)),n.quaternion.copy(e).multiply(ws),Math.abs(Ds.copy(Us).applyQuaternion(e).dot(this.eye))>.9&&(n.visible=!1)),"XYZE"===this.axis&&(ws.setFromEuler(ks.set(0,Math.PI/2,0)),Ds.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix(Bs.lookAt(zs,Ds,Ls)),n.quaternion.multiply(ws),n.visible=this.dragging),"E"===this.axis&&(n.visible=!1)):"START"===n.name?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):"END"===n.name?(n.position.copy(this.worldPosition),n.visible=this.dragging):"DELTA"===n.name?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),gs.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),gs.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(gs),n.visible=this.dragging):(n.quaternion.copy(e),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=-1!==this.axis.search(n.name)))}super.updateMatrixWorld(t)}}class qs extends n.Mesh{constructor(){super(new n.PlaneGeometry(1e5,1e5,2,2),new n.MeshBasicMaterial({visible:!1,wireframe:!0,side:n.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),"scale"===this.mode&&(e="local"),$s.copy(Rs).applyQuaternion("local"===e?this.worldQuaternion:Ns),js.copy(Ls).applyQuaternion("local"===e?this.worldQuaternion:Ns),Ws.copy(Us).applyQuaternion("local"===e?this.worldQuaternion:Ns),Ds.copy(js),this.mode){case"translate":case"scale":switch(this.axis){case"X":Ds.copy(this.eye).cross($s),Vs.copy($s).cross(Ds);break;case"Y":Ds.copy(this.eye).cross(js),Vs.copy(js).cross(Ds);break;case"Z":Ds.copy(this.eye).cross(Ws),Vs.copy(Ws).cross(Ds);break;case"XY":Vs.copy(Ws);break;case"YZ":Vs.copy($s);break;case"XZ":Ds.copy(Ws),Vs.copy(js);break;case"XYZ":case"E":Vs.set(0,0,0)}break;default:Vs.set(0,0,0)}0===Vs.length()?this.quaternion.copy(this.cameraQuaternion):(Fs.lookAt(gs.set(0,0,0),Vs,Ds),this.quaternion.setFromRotationMatrix(Fs)),super.updateMatrixWorld(t)}}class Ys{constructor(t,i,n,s,r,o=5,a=!0){var c;if(e(this,"onDraggingStarted",new h),e(this,"onDraggingEnded",new h),e(this,"onDisposed",new h),e(this,"normal"),e(this,"origin"),e(this,"three",new l.Plane),e(this,"components"),e(this,"world"),e(this,"type","default"),e(this,"_title","Clipping Plane"),e(this,"_helper"),e(this,"_visible",!0),e(this,"_enabled",!0),e(this,"_controlsActive",!1),e(this,"_arrowBoundBox",new l.Mesh),e(this,"_planeMesh"),e(this,"_controls"),e(this,"_hiddenMaterial",new l.MeshBasicMaterial({visible:!1})),e(this,"_sizeMultiplier",5),e(this,"_autoScale",!0),e(this,"_visibilityBeforeDisabled",!0),e(this,"notifyManager",()=>{const t=this.components.get(Qs),e=t.list.getKey(this);e&&t.list.set(e,this)}),e(this,"update",()=>{this._enabled&&(this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position),this.updateScale())}),e(this,"updateScale",()=>{var t;if(!this.autoScale)return;const e=null==(t=this.world.camera)?void 0:t.three;if(!e)return;if(!(e instanceof l.PerspectiveCamera))return;const i=new l.Vector3;e.getWorldPosition(i);const n=i.distanceTo(this._helper.position)/7*this._sizeMultiplier;this._planeMesh.scale.set(n,n,n)}),e(this,"changeDrag",t=>{this._visible=!t.value,this.preventCameraMovement(),this.notifyDraggingChanged(t)}),this.components=t,this.world=i,!i.renderer)throw new Error("The given world must have a renderer!");this.normal=s,this.origin=n,this._sizeMultiplier=o,i.renderer.setPlane(!0,this.three),this._planeMesh=Ys.newPlaneMesh(o,r),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(s,n),a&&this.toggleControls(!0),this.updateScale(),(null==(c=i.camera)?void 0:c.controls)&&i.camera.controls.addEventListener("update",this.updateScale)}set title(t){this._title=t,this.notifyManager()}get title(){return this._title}get autoScale(){return this._autoScale}set autoScale(t){this._autoScale=t,t&&this.updateScale()}get enabled(){return this._enabled}set enabled(t){if(!this.world.isDisposing){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=t,t?this.visible=this._visibilityBeforeDisabled:(this._visibilityBeforeDisabled=this.visible,this.visible=!1),this.world.renderer.setPlane(t,this.three),this.notifyManager()}}get visible(){return this._visible}set visible(t){this._visible=t,this._controls.getHelper().visible=t,this._helper.visible=t,this.toggleControls(t),this.notifyManager()}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(t){this._planeMesh.material=t}get size(){return this._sizeMultiplier}set size(t){this._sizeMultiplier=t,this.autoScale?this.updateScale():this._planeMesh.scale.set(t,t,t)}get helper(){return this._helper}get controls(){return this._controls}setFromNormalAndCoplanarPoint(t,e){this.reset(),this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix(),this.update()}dispose(){var t;this._enabled=!1,(null==(t=this.world.camera)?void 0:t.controls)&&this.world.camera.controls.removeEventListener("update",this.updateScale),this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.getHelper().removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const t=new l.Vector3(1,0,0),e=new l.Vector3;this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix()}toggleControls(t){if(t){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=t}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const t=this.world.camera.three,e=this.world.renderer.three.domElement,i=new Cs(t,e);return this.initializeControls(i),this.world.scene.three.add(i.getHelper()),i}initializeControls(t){t.attach(this._helper),t.showX=!1,t.showY=!1,t.setSpace("local"),this.createArrowBoundingBox(),t.getHelper().children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new l.CylinderGeometry(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(t){t.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const t=new l.Object3D;return t.lookAt(this.normal),t.position.copy(this.origin),this._planeMesh.position.z+=.01,t.add(this._planeMesh),this.world.scene.three.add(t),t}static newPlaneMesh(t,e){const i=new l.PlaneGeometry(1),n=new l.Mesh(i,e);return n.scale.set(t,t,t),n}}class Hs extends Lt{constructor(){super(...arguments),e(this,"_config",{enabled:{value:!0,type:"Boolean"},visible:{value:!0,type:"Boolean"},color:{value:new l.Color,type:"Color"},opacity:{type:"Number",interpolable:!0,value:1,min:0,max:1},size:{type:"Number",interpolable:!0,value:2,min:0,max:100}})}get enabled(){return this._config.enabled.value}set enabled(t){this._config.enabled.value=t,this._component.enabled=t}get visible(){return this._config.visible.value}set visible(t){this._config.visible.value=t,this._component.visible=t}get color(){return this._config.color.value}set color(t){this._config.color.value=t,this._component.material.color.copy(t)}get opacity(){return this._config.opacity.value}set opacity(t){this._config.opacity.value=t,this._component.material.opacity=t}get size(){return this._config.size.value}set size(t){this._config.size.value=t,this._component.size=t}}const Xs=class t extends d{constructor(i){super(i),e(this,"onSetup",new h),e(this,"onBeforeDrag",new h),e(this,"onAfterDrag",new h),e(this,"onBeforeCreate",new h),e(this,"onBeforeCancel",new h),e(this,"onAfterCancel",new h),e(this,"onBeforeDelete",new h),e(this,"onAfterCreate",new h),e(this,"onAfterDelete",new h),e(this,"onDisposed",new h),e(this,"isSetup",!1),e(this,"orthogonalY",!1),e(this,"toleranceOrthogonalY",.7),e(this,"autoScalePlanes",!0),e(this,"Type",Ys),e(this,"list",new a.DataMap),e(this,"config",new Hs(this,this.components,"Clipper",t.uuid)),e(this,"_defaultConfig",{color:new l.Color(12255487),opacity:.2,size:2}),e(this,"_material",new l.MeshBasicMaterial({color:12255487,side:l.DoubleSide,transparent:!0,opacity:.2})),e(this,"_size",5),e(this,"_enabled",!1),e(this,"_visible",!0),e(this,"onStateChanged",new h),this.components.add(t.uuid,this),this.setEvents()}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this.onStateChanged.trigger(["enabled"])}get visible(){return this._visible}set visible(t){this._visible=t;for(const[e,i]of this.list)i.visible=t;this.onStateChanged.trigger(["visibility"])}get material(){return this._material}set material(t){this._material=t;for(const[e,i]of this.list)i.planeMaterial=t;this.onStateChanged.trigger(["material"])}get size(){return this._size}set size(t){this._size=t;for(const[e,i]of this.list)i.size=t;this.onStateChanged.trigger(["size"])}setEvents(){this.list.onBeforeDelete.add(({value:t})=>{if(!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)})}dispose(){this._enabled=!1;this.components.get($t).list.delete(this.config.uuid),this.list.clear(),this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(t.uuid),this.onDisposed.reset()}async create(t){const e=this.components.get(ce).get(t),i=await e.castRay();return i?this.createPlaneFromIntersection(t,i):null}createFromNormalAndCoplanarPoint(t,e,i){const n=this.newPlane(t,i,e);return this.updateMaterialsAndPlanes(),n}async delete(t,e){if(!e){const i=await this.pickPlane(t);if(!i)return;e=this.list.getKey(i)}e&&this.list.delete(e)}deleteAll(t){for(const[e,i]of this.list)t&&!t.has(i.type)||this.list.delete(e)}setup(t){const e={...this._defaultConfig,...t};this.config.color=e.color,this.config.opacity=e.opacity,this.config.size=e.size,this.isSetup=!0,this.onSetup.trigger()}pickPlane(t){const e=this.components.get(ce).get(t),i=this.getAllPlaneMeshes(),n=e.castRayToObjects(i);if(n){const t=n.object;return[...this.list.values()].find(e=>e.meshes.includes(t))}}getAllPlaneMeshes(){const t=[];for(const[e,i]of this.list)t.push(...i.meshes);return t}createPlaneFromIntersection(t,e){var i;if(!t.renderer)throw new Error("The given world must have a renderer!");const n=e.point.distanceTo(new l.Vector3(0,0,0)),s=e.normal||(null==(i=e.face)?void 0:i.normal);if(!n||!s)return null;const r=this.getWorldNormal(e,s),o=this.newPlane(t,e.point,r.negate()),a=this.list.get(o);return a.visible=this._visible,a.size=this._size,t.renderer.setPlane(!0,a.three),this.updateMaterialsAndPlanes(),a}getWorldNormal(t,e){const i=t.object;let n=t.object.matrixWorld.clone();if(i instanceof l.InstancedMesh&&void 0!==t.instanceId){const e=new l.Matrix4;i.getMatrixAt(t.instanceId,e),n=e.multiply(n)}const s=(new l.Matrix3).getNormalMatrix(n),r=e.clone().applyMatrix3(s).normalize();return this.normalizePlaneDirectionY(r),r}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,e,i){const n=new this.Type(this.components,t,e,i,this._material);n.autoScale=this.autoScalePlanes,n.onDraggingStarted.add(()=>this.onBeforeDrag.trigger(n)),n.onDraggingEnded.add(()=>this.onAfterDrag.trigger(n));const s=_.create();return this.list.set(s,n),this.onAfterCreate.trigger(n),s}updateMaterialsAndPlanes(){const t=this.components.get(we);for(const[e,i]of t.list){if(!i.renderer)continue;i.renderer.updateClippingPlanes();const{clippingPlanes:t}=i.renderer;for(const e of i.meshes)if(e.material)if(Array.isArray(e.material))for(const i of e.material)i.clippingPlanes=t;else e.material.clippingPlanes=t}}};e(Xs,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");let Qs=Xs;class Ks{constructor(t,i){e(this,"title"),e(this,"guid",_.create()),e(this,"clippingPlanes",new a.DataSet),e(this,"camera",{aspect_ratio:1,field_of_view:60,camera_direction:{x:0,y:0,z:0},camera_view_point:{x:0,y:0,z:0},camera_up_vector:{x:0,y:1,z:0}}),e(this,"customData",{}),e(this,"exceptionComponents",new a.DataSet),e(this,"selectionComponents",new a.DataSet),e(this,"componentColors",new a.DataMap),e(this,"spacesVisible",!1),e(this,"spaceBoundariesVisible",!1),e(this,"openingsVisible",!1),e(this,"defaultVisibility",!0),e(this,"snapshot",this.guid),e(this,"_components"),e(this,"_world",null),e(this,"notifyUpdate",()=>{this._components.get(er).list.set(this.guid,this)}),this._components=t,i&&(this.guid=i.guid??this.guid,this.set(i)),this.setEvents()}async getSelectionMap(){const t=this._components.get(Zt);return await t.guidsToModelIdMap([...this.selectionComponents])}async getExceptionMap(){const t=this._components.get(Zt);return await t.guidsToModelIdMap([...this.exceptionComponents])}get projection(){return"field_of_view"in this.camera?"Perspective":"Orthographic"}get position(){const t=this._components.get(Zt),{camera_view_point:e}=this.camera,{x:i,y:n,z:s}=e,r=new l.Vector3(i,n,s);return t.applyBaseCoordinateSystem(r,new l.Matrix4),r}set position(t){const e=t.clone(),i=this._components.get(Zt);t.clone().applyMatrix4(i.baseCoordinationMatrix.clone().invert()),this.camera.camera_view_point={x:e.x,y:e.y,z:e.z}}get direction(){const{camera_direction:t}=this.camera,{x:e,y:i,z:n}=t;return new l.Vector3(e,i,n)}set world(t){this._world=t}get world(){return this._world}get _managerVersion(){return this._components.get(fs).config.version}get topics(){return[...this._components.get(fs).list.values()].filter(t=>t.viewpoints.has(this.guid))}setEvents(){this.selectionComponents.onUpdated.add(this.notifyUpdate),this.exceptionComponents.onUpdated.add(this.notifyUpdate),this.clippingPlanes.onUpdated.add(this.notifyUpdate),this.componentColors.onItemSet.add(this.notifyUpdate),this.componentColors.onItemDeleted.add(this.notifyUpdate),this.componentColors.onItemUpdated.add(this.notifyUpdate),this.componentColors.onCleared.add(this.notifyUpdate)}set(t){this.title=t.title;const{components:e,perspective_camera:i,orthogonal_camera:n,clipping_planes:s}=t;if(e){const{selection:t,visibility:i,coloring:n}=e;if(t){this.selectionComponents.clear();for(const{ifc_guid:e}of t)e&&this.selectionComponents.add(e)}if(i){const{default_visibility:t,exceptions:e,view_setup_hints:n}=i;if(void 0!==t&&(this.defaultVisibility=t),e){this.exceptionComponents.clear();for(const{ifc_guid:t}of e)t&&this.exceptionComponents.add(t)}if(n){const{spaces_visible:t,space_boundaries_visible:e,openings_visible:i}=n;void 0!==t&&(this.spacesVisible=t),void 0!==e&&(this.spaceBoundariesVisible=e),void 0!==i&&(this.openingsVisible=i)}}if(n){this.componentColors.clear();for(const t of n){const{color:e,components:i}=t,n=i.map(t=>t.ifc_guid).filter(t=>null!==t);this.componentColors.set(e,n)}}}if((i||n)&&(this.camera=i??n),s&&this.world){const t=this._components.get(Qs);for(const e of s){const{location:i,direction:n}=e,s=new l.Vector3(i.x,i.z,-i.y),r=new l.Vector3(n.x,n.z,-n.y),o=t.createFromNormalAndCoplanarPoint(this.world,r,s);this.clippingPlanes.add(o),t.list.get(o).enabled=!1,t.list.get(o).visible=!1}}this.notifyUpdate()}async go(t){if(!this.world)return;const{camera:e}=this.world;if(!(e instanceof is))throw new Error("Viewpoint: the world's camera component must be of type OrthoPerspectiveCamera to switch between perspective and orthographic projections.");const{transition:i,applyClippings:n,applyVisibility:s,clippingsVisibility:r}={transition:!0,applyClippings:!0,applyVisibility:!0,clippingsVisibility:!0,...t};e.projection.set(this.projection);const o=new l.Vector3(this.camera.camera_view_point.x,this.camera.camera_view_point.y,this.camera.camera_view_point.z),a=new l.Vector3(this.camera.camera_direction.x,this.camera.camera_direction.y,this.camera.camera_direction.z);if(o.equals(new l.Vector3)&&a.equals(new l.Vector3))return;const c=this.position,h=this.direction,u={x:c.x+80*h.x,y:c.y+80*h.y,z:c.z+80*h.z},d=[];n&&this.setClippingState(!0),s&&d.push(this.applyVisibility()),this.setClippingVisibility(r),d.push(e.controls.setLookAt(c.x,c.y,c.z,u.x,u.y,u.z,i)),await Promise.all(d)}async updateCamera(t=!0){return new Promise(e=>{if(!this.world)return void e(!1);const{camera:i,renderer:n}=this.world;if(!n)throw new Error("Viewpoint: the world needs to have a renderer!");if(!i.hasCameraControls())throw new Error("Viewpoint: world's camera need camera controls!");const s=new l.Vector3;i.controls.getPosition(s);const r=i.three,o=new l.Vector3(0,0,-1).applyEuler(r.rotation),{width:a,height:c}=n.getSize();let h=a/c;Number.isNaN(h)&&(h=1);const u=this._components.get(Zt);s.applyMatrix4(u.baseCoordinationMatrix.clone().invert());const d={aspect_ratio:h,camera_view_point:{x:s.x,y:s.y,z:s.z},camera_direction:{x:o.x,y:o.y,z:o.z},camera_up_vector:{x:0,y:1,z:0}};if(r instanceof l.PerspectiveCamera?this.camera={...d,field_of_view:r.fov}:r instanceof l.OrthographicCamera&&(this.camera={...d,view_to_world_scale:r.top-r.bottom}),t){const t=this._components.get(er),s=n.three.domElement;n.three.render(this.world.scene.three,i.three),s.toBlob(async i=>{if(i){const e=await i.arrayBuffer(),n=new Uint8Array(e);t.snapshots.set(this.guid,n)}this.notifyUpdate(),e(!0)})}else this.notifyUpdate(),e(!0)})}takeSnapshot(){return new Promise(t=>{if(!this.world)return void t(!1);const{camera:e,renderer:i}=this.world;if(!i)throw new Error("Viewpoint: the world needs to have a renderer!");const n=this._components.get(er),s=i.three.domElement;i.three.render(this.world.scene.three,e.three),s.toBlob(async e=>{if(e){const t=await e.arrayBuffer(),i=new Uint8Array(t);n.snapshots.set(this.guid,i)}this.notifyUpdate(),t(!0)})})}updateClippingPlanes(){this.clippingPlanes.clear();const t=this._components.get(Qs);for(const[e,i]of t.list)i.enabled&&this.clippingPlanes.add(e)}async applyVisibility(){const t=this._components.get(Xt);t.set(this.defaultVisibility);const e=await this.getExceptionMap();t.set(!this.defaultVisibility,e);const i=await this.getSelectionMap();t.set(!0,i)}async setColorizationState(t){const e=this._components.get(Zt),i=[];if(t)for(const[t,n]of this.componentColors){const s=`#${t}`,r=await e.guidsToModelIdMap(n);for(const[t,n]of Object.entries(r)){const r=e.list.get(t);r&&i.push(r.highlight([...n],{customId:s,color:new l.Color(s),renderedFaces:a.RenderedFaces.ONE,opacity:1,transparent:!1}))}}else for(const[t,n]of this.componentColors){const t=await e.guidsToModelIdMap(n);for(const[n,s]of Object.entries(t)){const t=e.list.get(n);t&&i.push(t.resetHighlight([...s]))}}i.push(e.core.update(!0)),await Promise.all(i)}setClippingState(t){const e=this._components.get(Qs);for(const[i,n]of e.list)n.enabled=t&&this.clippingPlanes.has(i)}setClippingVisibility(t){const e=this._components.get(Qs);for(const i of this.clippingPlanes){const n=e.list.get(i);n&&(n.visible=t)}}async createComponentTags(t){var e;const i=this._components.get(Zt);let n="";if(this._components.get(fs).config.includeSelectionTag){const s="selection"===t?await this.getSelectionMap():await this.getExceptionMap();for(const t in s){const r=i.list.get(t);if(!r)continue;const o=s[t];for(const t of o){const i=r.getItem(t),s=await i.getGuid();if(!s)continue;const o=null==(e=await i.getAttributes())?void 0:e.getValue("Tag");let a=null;o&&(a=`AuthoringToolId="${o}"`),n+=`\n<Component IfcGuid="${s}" ${a??""} />`}}}else n=[...this.selectionComponents].map(t=>`<Component IfcGuid="${t}" />`).join("\n");return n}createColorTags(){let t="";for(const[e,i]of this.componentColors.entries()){t+=`<Color Color="${e}">\n${i.map(t=>`\n<Component IfcGuid="${t}" />`).join("\n")}\n</Color>`}return 0!==t.length?`<Coloring>\n${t}\n</Coloring>`:"<Coloring />"}toJSON(){const t=this._components.get(Qs),e={guid:this.guid,components:{selection:[...this.selectionComponents].map(t=>({ifc_guid:t,authoring_tool_id:null})),coloring:[...this.componentColors].map(([t,e])=>({color:t,components:e.map(t=>({ifc_guid:t,authoring_tool_id:null}))})),visibility:{default_visibility:this.defaultVisibility,exceptions:[...this.exceptionComponents].map(t=>({ifc_guid:t,authoring_tool_id:null})),view_setup_hints:{spaces_visible:this.spacesVisible,space_boundaries_visible:this.spaceBoundariesVisible,openings_visible:this.openingsVisible}}},clipping_planes:[...this.clippingPlanes].map(e=>{const i=t.list.get(e);if(!i)return null;const n=i._controls.worldPosition??i.origin,{normal:s}=i;return{location:{x:n.x,y:-n.z,z:n.y},direction:{x:s.x,y:-s.z,z:s.y}}}).filter(t=>null!==t)};"field_of_view"in this.camera?e.perspective_camera=this.camera:e.orthogonal_camera=this.camera;const i=this._components.get(er),n=i.snapshots.get(this.snapshot);if(n){const t=n.toString(),s=btoa(t),r=i.getSnapshotExtension(this.snapshot);e.snapshot={snapshot_type:r,snapshot_data:s}}return e}async serialize(t=this._managerVersion){const e=this._components.get(Zt),i=this.position;i.applyMatrix4(e.baseCoordinationMatrix.clone().invert());const n=this.direction;n.normalize();const s=(new l.Matrix4).makeRotationX(Math.PI/2),r=n.clone().applyMatrix4(s);r.normalize();const o=`<CameraViewPoint>\n <X>${i.x}</X>\n <Y>${-i.z}</Y>\n <Z>${i.y}</Z>\n </CameraViewPoint>`,a=`<CameraDirection>\n <X>${n.x}</X>\n <Y>${-n.z}</Y>\n <Z>${n.y}</Z>\n </CameraDirection>`,c=`<CameraUpVector>\n <X>${r.x}</X>\n <Y>${-r.z}</Y>\n <Z>${r.y}</Z>\n </CameraUpVector>`,h=`<AspectRatio>${this.camera.aspect_ratio}</AspectRatio>`;let u="";"view_to_world_scale"in this.camera?u=`<OrthogonalCamera>\n ${o}\n ${a}\n ${c}\n ${h}\n <ViewToWorldScale>${this.camera.view_to_world_scale}</ViewToWorldScale>\n </OrthogonalCamera>`:"field_of_view"in this.camera&&(u=`<PerspectiveCamera>\n ${o}\n ${a}\n ${c}\n ${h}\n <FieldOfView>${this.camera.field_of_view}</FieldOfView>\n </PerspectiveCamera>`);const d=`<ViewSetupHints SpacesVisible="${this.spacesVisible??!1}" SpaceBoundariesVisible="${this.spaceBoundariesVisible??!1}" OpeningsVisible="${this.openingsVisible??!1}" />`,p=(await this.createComponentTags("selection")).trim(),f=(await this.createComponentTags("exception")).trim(),m=this.createColorTags();return`<?xml version="1.0" encoding="UTF-8"?>\n <VisualizationInfo Guid="${this.guid}">\n <Components>\n ${"2.1"===t?d:""}\n ${0!==p.length?`<Selection>${p}</Selection>`:""}\n <Visibility DefaultVisibility="${this.defaultVisibility}">\n ${"3"===t?d:""}\n ${0!==f.length?`<Exceptions>${f}</Exceptions>`:""}\n </Visibility>\n ${m}\n </Components>\n ${u}\n </VisualizationInfo>`}}class Js extends Lt{constructor(){super(...arguments),e(this,"_config",{overwriteColors:{value:!1,type:"Boolean"}})}get overwriteColors(){return this._config.overwriteColors.value}set overwriteColors(t){this._config.overwriteColors.value=t}}const tr=class t extends d{constructor(n){super(n),e(this,"enabled",!0),e(this,"world",null),e(this,"list",new i.DataMap),e(this,"snapshots",new i.DataMap),e(this,"isSetup",!1),e(this,"onSetup",new h),e(this,"config",new Js(this,this.components,"Viewpoints",t.uuid)),e(this,"onDisposed",new h),n.add(t.uuid,this)}create(t){const e=new Ks(this.components,t);return e.world=this.world,t||this.list.set(e.guid,e),e}getSnapshotExtension(t){let e="jpeg";const i=this.snapshots.get(t);if(!i)return e;const n=i.subarray(0,4);let s="";for(let t=0;t<n.length;t++)s+=n[t].toString(16);return s.startsWith("89504e47")&&(e="png"),s.startsWith("ffd8ffe")&&(e="jpeg"),e}setup(){}dispose(){this.list.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}};e(tr,"uuid","ee867824-a796-408d-8aa0-4e5962a83c66");let er=tr;class ir{constructor(t,i){e(this,"_components"),e(this,"_cameraOffset",10),e(this,"_planeHelper"),e(this,"_farPlaneHelper"),e(this,"_cameraHelper"),e(this,"onStateChanged",new h),e(this,"onUpdated",new h),e(this,"onDisposed",new h),e(this,"camera"),e(this,"plane",new l.Plane),e(this,"farPlane",new l.Plane),e(this,"id",_.create()),e(this,"_open",!1),e(this,"_range",sr.defaultRange),e(this,"_world",null),e(this,"_helpersVisible",!1),e(this,"_planesEnabled",!1),this._components=t,this.camera=new is(this._components);const{threeOrtho:n}=this.camera;if((null==i?void 0:i.id)&&(this.id=i.id),(null==i?void 0:i.normal)&&(null==i?void 0:i.point)){const{normal:t,point:e}=i;this.plane.setFromNormalAndCoplanarPoint(t,e)}this._cameraHelper=new l.CameraHelper(n),this._planeHelper=new l.PlaneHelper(this.plane,50),this._farPlaneHelper=new l.PlaneHelper(this.farPlane,50),this.farPlaneHelperColor=new l.Color("blue"),this.update()}get _planeNormalOpposite(){return this.plane.normal.clone().negate()}get _planePosition(){return this.plane.normal.clone().multiplyScalar(-this.plane.constant)}get _cameraPosition(){return this._planePosition.addScaledVector(this._planeNormalOpposite,this._cameraOffset)}set open(t){this._open=t,this.onStateChanged.trigger(["open"])}get open(){return this._open}set planeHelperColor(t){!Array.isArray(this._planeHelper.material)&&"color"in this._planeHelper.material&&this._planeHelper.material.color instanceof l.Color&&(this._planeHelper.material.color=t)}set farPlaneHelperColor(t){!Array.isArray(this._farPlaneHelper.material)&&"color"in this._farPlaneHelper.material&&this._farPlaneHelper.material.color instanceof l.Color&&(this._farPlaneHelper.material.color=t)}set range(t){this._range=t,this.update()}get range(){return this._range}set distance(t){this.plane.constant=t,this.update()}get distance(){return this.plane.constant}set world(t){this._world=t,this.camera.currentWorld=t,t&&(this.camera.projection.set("Orthographic"),this.camera.set("Plan"),this.camera.controls.dollySpeed=6,this.camera.controls.restThreshold=.005,this.update())}get world(){return this._world}set helpersVisible(t){if(!t)return this._helpersVisible=t,this._planeHelper.removeFromParent(),this._farPlaneHelper.removeFromParent(),void this._cameraHelper.removeFromParent();this.world&&(this._helpersVisible=t,this.world.scene.three.add(this._planeHelper,this._farPlaneHelper))}get helpersVisible(){return this._helpersVisible}set planesEnabled(t){const{world:e}=this;if(!e)return;const{renderer:i}=e;i&&(i.setPlane(t,this.plane),i.setPlane(t,this.farPlane),this._planesEnabled=t)}get planesEnabled(){return this._planesEnabled}dispose(){this.helpersVisible=!1;const t=this._components.get(y);t.destroy(this._planeHelper),t.destroy(this._farPlaneHelper),t.destroy(this._cameraHelper),this.camera.dispose(),this.onDisposed.trigger()}update(){if(this.world){const t=this._cameraPosition,e=this._planePosition;this.camera.controls.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,!1)}this.farPlane.normal.copy(this._planeNormalOpposite),this.farPlane.constant=this.range-this.plane.constant,this.onUpdated.trigger()}flip(){this.plane.normal.negate(),this.update()}}const nr=class t extends d{constructor(n){super(n),e(this,"list",new i.DataMap),e(this,"enabled",!0),e(this,"world",null),e(this,"_fragmentsUpdateEvent",()=>{this.components.get(Zt).core.update(!0)}),n.add(t.uuid,this),this.setupEvents()}get hasOpenViews(){return[...this.list.values()].some(t=>t.open)}setupEvents(){this.list.onBeforeDelete.add(({key:t,value:e})=>{e.open&&this.close(t),e.dispose()})}create(t,e,i){const n=new ir(this.components,{id:null==i?void 0:i.id,normal:t,point:e});return n.world=(null==i?void 0:i.world)??this.world,this.list.set(n.id,n),n}createFromPlane(t,e){const i=new ir(this.components,{id:null==e?void 0:e.id});return i.plane.copy(t),i.update(),i.world=(null==e?void 0:e.world)??this.world,this.list.set(i.id,i),i}async createFromIfcStoreys(t){const e=[],i=this.components.get(Zt),n=void 0===(null==t?void 0:t.offset)?.25:t.offset;for(const[s,r]of i.list){if(t&&t.modelIds&&!t.modelIds.some(t=>t.test(s)))continue;const i=Object.values(await r.getItemsOfCategories([/BUILDINGSTOREY/])).flat();if(0===i.length)continue;const o=await r.getItemsData(i),[,a]=await r.getCoordinates(),c=new l.Vector3(0,-1,0);for(const i of o){if(!("value"in i.Name)||!("value"in i.Elevation))continue;const{value:s}=i.Name;if((null==t?void 0:t.storeyNames)&&!t.storeyNames.some(t=>t.test(s)))continue;const r=i.Elevation.value+a+n,o=new l.Plane(c,r),h=this.createFromPlane(o,{id:s,world:null==t?void 0:t.world});e.push(h)}}return e}createElevations(t){const e=[],i=this.components.get(Zt),n=void 0!==(null==t?void 0:t.combine)&&t.combine,s=(null==t?void 0:t.namingCallback)??(t=>({front:""+(n?"Front":`${t}: Front`),back:""+(n?"Back":`${t}: Back`),left:""+(n?"Left":`${t}: Left`),right:""+(n?"Right":`${t}: Right`)}));let r=[];for(const[e,n]of i.list)t&&t.modelIds&&!t.modelIds.some(t=>t.test(e))||r.push({id:e,box:n.box});if(0===r.length)return e;if(n){const t=this.components.get(Kt);t.list.clear(),t.list.add(...r.map(t=>t.box));r=[{id:"combined",box:t.get()}]}for(const{id:i,box:n}of r){const{min:r,max:o}=n,a=Math.abs(o.x-r.x),c=Math.abs(o.z-r.z),h=new l.Vector3;n.getCenter(h);const u=new l.Plane(new l.Vector3(0,0,-1),o.z),d=new l.Plane(new l.Vector3(0,0,1),-r.z),p=new l.Plane(new l.Vector3(-1,0,0),o.x),f=new l.Plane(new l.Vector3(1,0,0),-r.x),{front:m,back:g,left:y,right:w}=s(i),v=this.createFromPlane(u,{id:m,world:null==t?void 0:t.world});v.range=c;const b=this.createFromPlane(d,{id:g,world:null==t?void 0:t.world});b.range=c;const _=this.createFromPlane(p,{id:y,world:null==t?void 0:t.world});_.range=a;const x=this.createFromPlane(f,{id:w,world:null==t?void 0:t.world});x.range=a,e.push(v,b,_,x)}return e}open(t){const e=this.list.get(t);if(!e)throw new Error(`Views: the view with id ${t} doesn't exist.`);if(e.open)return;const{world:i}=e;if(!i)throw new Error(`Views: no world found for view with id ${t}.`);const{renderer:n}=i;if(!n)throw new Error(`Views: no renderer found for world with id ${i.uuid}.`);for(const[,t]of this.list)t.world===i&&this.close(t.id);n.setPlane(!0,e.plane),n.setPlane(!0,e.farPlane),e.camera.controls.addEventListener("rest",this._fragmentsUpdateEvent),i.camera=e.camera,e.open=!0}close(t){let e;if(e=t?this.list.get(t):[...this.list.values()].find(t=>t.open),t&&!e)throw new Error(`Views: the view with id ${t} doesn't exist.`);if(!e)return;if(!e.open)return;const{world:i}=e;if(!i)throw new Error(`Views: no world found for view with id ${t}.`);const{renderer:n}=i;if(!n)throw new Error(`Views: no renderer found for world with id ${i.uuid}.`);n.setPlane(!1,e.plane),n.setPlane(!1,e.farPlane),e.camera.controls.removeEventListener("rest",this._fragmentsUpdateEvent),i.useDefaultCamera(),e.open=!1}};e(nr,"uuid","fb22f1f5-6598-4664-a11d-de8963ae420f"),e(nr,"defaultRange",15);let sr=nr;async function rr(t,e,i,n,s,r,o){const a=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),await function(t,e,i,n){return new Promise((s,r)=>{!function o(){const a=t.clientWaitSync(e,i,0);a!==t.WAIT_FAILED?a!==t.TIMEOUT_EXPIRED?s():setTimeout(o,n):r()}()})}(t,a,0,10),t.deleteSync(a),t.bindBuffer(e,i),t.getBufferSubData(e,n,s,r,o),t.bindBuffer(e,null)}class or{constructor(t,i){if(e(this,"onDisposed",new h),e(this,"onDistanceComputed",new h),e(this,"excludedObjects",new Set),e(this,"enabled",!0),e(this,"renderDebugFrame",!1),e(this,"components"),e(this,"scene",new l.Scene),e(this,"camera",new l.OrthographicCamera(-1,1,1,-1,0,1)),e(this,"depthMaterial"),e(this,"world"),e(this,"worker"),e(this,"_width",512),e(this,"_height",512),e(this,"_postQuad"),e(this,"tempRT"),e(this,"resultRT"),e(this,"bufferSize"),e(this,"_buffer"),e(this,"_isWorkerBusy",!1),e(this,"compute",async()=>{if(!this.enabled||this.world.isDisposing)return;if(this._isWorkerBusy)return;this._isWorkerBusy=!0,this.world.camera.three.updateMatrix();const t=this.world.renderer.three;t.setRenderTarget(this.tempRT);const e="visibilityBeforeDistanceCheck";for(const t of this.excludedObjects)t.userData[e]=t.visible,t.visible=!1;t.render(this.world.scene.three,this.world.camera.three);for(const t of this.excludedObjects)void 0!==t.userData[e]&&(t.visible=t.userData[e]);this.depthMaterial.uniforms.tDiffuse.value=this.tempRT.texture,this.depthMaterial.uniforms.tDepth.value=this.tempRT.depthTexture,t.setRenderTarget(this.resultRT),t.render(this.scene,this.camera);const i=t.getContext();try{await async function(t,e,i,n,s,r,o,a){const l=t.createBuffer();return t.bindBuffer(t.PIXEL_PACK_BUFFER,l),t.bufferData(t.PIXEL_PACK_BUFFER,a.byteLength,t.STREAM_READ),t.readPixels(e,i,n,s,r,o,0),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),await rr(t,t.PIXEL_PACK_BUFFER,l,0,a),t.deleteBuffer(l),a}(i,0,0,this._width,this._height,i.RGBA,i.UNSIGNED_BYTE,this._buffer)}catch(e){return t.setRenderTarget(null),void(this._isWorkerBusy=!1)}t.setRenderTarget(null),this.renderDebugFrame&&t.render(this.scene,this.camera),this.worker.postMessage({buffer:this._buffer})}),e(this,"handleWorkerMessage",t=>{if(!this.enabled||this.world.isDisposing)return;const e=t.data.colors;let i=Number.MAX_VALUE;for(const t of e)0!==t&&t<i&&(i=t);const n=this.world.camera.three||l.OrthographicCamera,s=-1*(i/255-1)*(n.far-n.near),r=Math.min(s,n.far);this.onDistanceComputed.trigger(r),this._isWorkerBusy=!1}),!i.renderer)throw new Error("The given world must have a renderer!");this.components=t,this.world=i;const n=i.camera.three;this.tempRT=new l.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.tempRT.texture.minFilter=l.NearestFilter,this.tempRT.texture.magFilter=l.NearestFilter,this.tempRT.stencilBuffer=!1,this.tempRT.samples=0,this.tempRT.depthTexture=new l.DepthTexture(this._width,this._height),this.tempRT.depthTexture.format=l.DepthFormat,this.tempRT.depthTexture.type=l.UnsignedShortType,this.resultRT=new l.WebGLRenderTarget(this._width,this._height),this.depthMaterial=new l.ShaderMaterial({vertexShader:"\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n ",fragmentShader:"\n#include <packing>\n\nvarying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform sampler2D tDepth;\nuniform float cameraNear;\nuniform float cameraFar;\n\n\nfloat readDepth( sampler2D depthSampler, vec2 coord ) {\n float fragCoordZ = texture2D( depthSampler, coord ).x;\n float viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );\n return viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );\n}\n\nvoid main() {\n //vec3 diffuse = texture2D( tDiffuse, vUv ).rgb;\n float depth = readDepth( tDepth, vUv );\n\n gl_FragColor.rgb = 1.0 - vec3( depth );\n gl_FragColor.a = 1.0;\n}\n ",uniforms:{cameraNear:{value:n.near},cameraFar:{value:n.far},tDiffuse:{value:null},tDepth:{value:null}}});const s=new l.PlaneGeometry(2,2);this._postQuad=new l.Mesh(s,this.depthMaterial),this.scene.add(this._postQuad);const r=new Blob(['\n addEventListener("message", (event) => {\n const { buffer } = event.data;\n const colors = new Set();\n for (let i = 0; i < buffer.length; i += 4) {\n const r = buffer[i];\n colors.add(r);\n }\n postMessage({ colors });\n });\n '],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(r)),this.worker.addEventListener("message",this.handleWorkerMessage)}dispose(){this.enabled=!1,this.onDistanceComputed.reset(),this.worker.terminate(),this.tempRT.dispose(),this.resultRT.dispose();const t=[...this.scene.children];this.excludedObjects.clear();for(const e of t)e.removeFromParent();this._postQuad.geometry.dispose(),this._postQuad.removeFromParent(),this._buffer=null,this.onDisposed.reset()}}class ar{constructor(t){e(this,"cardinality","required"),e(this,"instructions"),e(this,"evalRequirement",(t,e,i,n)=>{const s={parameter:i,currentValue:t,requiredValue:e,pass:!1};n&&this.addCheckResult(s,n);let r=!1;if("simple"===e.type&&(r=t===e.parameter),"enumeration"===e.type&&(r=e.parameter.includes(t)),"pattern"===e.type){r=new RegExp(e.parameter).test(String(t))}if("length"===e.type){const{min:i,length:n,max:s}=e.parameter;void 0!==n&&(r=String(t).length===n),void 0!==i&&(r=String(t).length>=i),void 0!==s&&(r=String(t).length<=s)}if("bounds"===e.type&&"number"==typeof t){const{min:i,minInclusive:n,max:s,maxInclusive:o}=e.parameter;let a=!0,l=!0;void 0!==i&&(a=n?t>=i:t>i),void 0!==s&&(l=o?t<=s:t<s),r=a&&l}return"prohibited"===this.cardinality&&(r=!r),"optional"===this.cardinality&&(r=!0),s.pass=r,s.pass}),this._components=t}addCheckResult(t,e){const i=e.findIndex(({parameter:e})=>e===t.parameter);-1!==i?e[i]=t:e.push(t)}getItemChecks(t,e,i,n){if(!("value"in i._localId)||"number"!=typeof i._localId.value)return null;let s=t.get(e);s||(s=new a.DataMap,t.set(e,s));let r=s.get(i._localId.value);if(r&&n&&!r.pass)return null;if(!r){const t=[];r={guid:Array.isArray(i._guid)?void 0:i._guid.value,pass:!1,checks:t},Object.defineProperty(r,"pass",{get:()=>t.every(({pass:t})=>t)}),s.set(i._localId.value,r)}const o=[],l={facetType:this.facetType,cardinality:this.cardinality,checks:o,pass:!1};return Object.defineProperty(l,"pass",{get:()=>o.every(({pass:t})=>t)}),r.checks.push(l),l.checks}}const lr=(t,e)=>{let i="";if(!e)return i;if("simple"===e.type&&(i=`<simpleValue>${e.parameter}</simpleValue>`),"enumeration"===e.type){i=`<xs:restriction base="xs:string">\n ${e.parameter.map(t=>`<xs:enumeration value="${t}" />`).join("\n")}\n </xs:restriction>`}if("pattern"===e.type){i=`<xs:restriction base="xs:string">\n <xs:pattern value="${e.parameter}" />\n </xs:restriction>`}if("bounds"===e.type){const{min:t,minInclusive:n,max:s,maxInclusive:r}=e.parameter;let o="";void 0!==t&&(o=`<xs:min${n?"Inclusive":"Exclusive"} value="${t}">`);let a="";void 0!==s&&(a=`<xs:max${r?"Inclusive":"Exclusive"} value="${s}">`),i=`<xs:restriction base="xs:double">\n ${o}\n ${a}\n </xs:restriction>`}if("length"===e.type){const{length:t,min:n,max:s}=e.parameter;let r="";void 0!==t&&void 0===n&&void 0===s&&(r=`<xs:length value="${t}" />`);let o="";void 0!==n&&void 0===t&&(o=`<xs:minLength value="${n}" />`);let a="";void 0!==s&&void 0===t&&(a=`<xs:maxLength value="${s}" />`),i=`<xs:restriction base="xs:string">\n ${r}\n ${o}\n ${a}\n </xs:restriction>`}return`<${t[0].toLowerCase()+t.slice(1)}>\n ${i}\n </${t[0].toLowerCase()+t.slice(1)}>`};class cr extends ar{constructor(t,i){super(t),e(this,"facetType","Attribute"),e(this,"name"),e(this,"value"),this.name=i}serialize(t){const e=lr("Name",this.name),i=lr("Value",this.value);let n="";return"requirement"===t&&(n+=`cardinality="${this.cardinality}"`,n+=this.instructions?`instructions="${this.instructions}"`:""),`<attribute ${n}>\n ${e}\n ${i}\n</attribute>`}async getEntities(){}async test(t,e,i={skipIfFails:!0}){const n=this._components.get(Zt);for(const[s,r]of Object.entries(t)){const t=n.list.get(s);if(!t)continue;const o=await t.getItemsData([...r]);for(const t of o){const n=this.getItemChecks(e,s,t,i.skipIfFails);if(!n)continue;const r=Object.keys(t).filter(e=>{const i=this.evalRequirement(e,this.name,"Name");if(!i)return!1;const n=t[e];return!!Array.isArray(n)||(null===n||null===n.value?"optional"===this.cardinality||"prohibited"===this.cardinality:(!Array.isArray(n.value)||0!==n.value.length)&&(("string"!=typeof n.value||""!==n.value.trim())&&i))}),o=r.length>0;if(n.push({parameter:"Name",currentValue:o?r[0]:null,requiredValue:this.name,pass:"prohibited"===this.cardinality?!o:o}),this.value)if(r[0]){const e=t[r[0]];if(Array.isArray(e))n.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality});else{Array.isArray(e.value)?n.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality}):this.evalRequirement(e.value,this.value,"Value",n)}}else n.push({parameter:"Value",currentValue:null,requiredValue:this.value,pass:"prohibited"===this.cardinality})}}}}class hr extends ar{constructor(t,i){super(t),e(this,"facetType","Classification"),e(this,"system"),e(this,"value"),e(this,"uri"),this.system=i}serialize(t){const e=lr("System",this.system),i=lr("Value",this.value);let n="";return"requirement"===t&&(n+=`cardinality="${this.cardinality}"`,n+=this.uri?`uri=${this.uri}`:"",n+=this.instructions?`instructions="${this.instructions}"`:""),`<classification ${n}>\n ${e}\n ${i}\n</classification>`}async getEntities(t,e){}async test(t,e){}}class ur extends ar{constructor(t,i){super(t),e(this,"facetType","Entity"),e(this,"name"),e(this,"predefinedType"),this.name=i}serialize(t){const e=lr("Name",this.name),i=lr("Name",this.predefinedType);let n="";return"requirement"===t&&(n+=`cardinality="${this.cardinality}"`,n+=this.instructions?`instructions="${this.instructions}"`:""),`<entity ${n}>\n ${e}\n ${i}\n</entity>`}async getEntities(t,e){const i=this._components.get(Zt),n=new Map;for(const[e,s]of i.list){if(!t.find(t=>t.test(e)))continue;const i=await s.getCategories();for(const t of i){if(!await this.evalName(t))continue;let i=n.get(e);i||(i=[],n.set(e,i)),i.push(t)}}const s={};if(await Promise.all(Array.from(n.entries()).map(async([t,e])=>{const n=i.list.get(t);if(!n)return;const r=e.map(t=>new RegExp(`^${t}$`)),o=await n.getItemsOfCategories(r),a=Object.values(o).flat();s[t]=new Set(a)})),this.predefinedType)for(const[t,n]of Object.entries(s)){const s=i.list.get(t);if(!s)continue;const r=await s.getItemsData([...n]);for(const i of r){if(!("value"in i._localId))continue;await this.evalPredefinedType(t,i)&&Vt.append(e,t,i._localId.value)}}else Vt.add(e,s)}async test(t,e,i){const n=this._components.get(Zt);for(const[s,r]of Object.entries(t)){const t=n.list.get(s);if(!t)continue;const o=await t.getItemsData([...r]);for(const t of o){if(!("value"in t._category))continue;const n=this.getItemChecks(e,s,t,i.skipIfFails);n&&(await this.evalName(t._category.value,n),await this.evalPredefinedType(s,t,n))}}}async evalName(t,e){return this.evalRequirement(t,this.name,"Name",e)}async evalPredefinedType(t,e,i){if(!this.predefinedType)return null;if(!("value"in e.PredefinedType))return null;const n="string"==typeof this.predefinedType.parameter&&"USERDEFINED"===this.predefinedType.parameter;let s=e.PredefinedType.value;if("USERDEFINED"===s&&!n){const t=Object.keys(e).find(t=>/^((?!Predefined).)*Type$/.test(t));if(t){const i=e[t];"value"in i&&(s=i.value)}else s="USERDEFINED"}if(!s){const i=this._components.get(Zt).list.get(t);if(i&&"value"in e._localId){const[t]=await i.getItemsData([e._localId.value],{relations:{IsTypedBy:{attributes:!0,relations:!1}}});if(Array.isArray(t.IsTypedBy)){const e=t.IsTypedBy[0];if(e&&"value"in e.PredefinedType&&(s=e.PredefinedType.value,"USERDEFINED"===s&&!n)){const t=Object.keys(e).find(t=>/^((?!Predefined).)*Type$/.test(t));if(t){const i=e[t];"value"in i&&(s=i.value)}else s="USERDEFINED"}}}}return this.evalRequirement(s,this.predefinedType,"PredefinedType",i)}}class dr extends ar{constructor(t,i,n){super(t),e(this,"facetType","Property"),e(this,"propertySet"),e(this,"baseName"),e(this,"value"),e(this,"dataType"),e(this,"uri"),e(this,"_unsupportedTypes",["IFCCOMPLEXPROPERTY","IFCPHYSICALCOMPLEXQUANTITY"]),this.propertySet=i,this.baseName=n}serialize(t){const e=lr("PropertySet",this.propertySet),i=lr("BaseName",this.baseName),n=lr("Value",this.value),s=this.dataType?`dataType=${this.dataType}`:"";let r="";return"requirement"===t&&(r+=`cardinality="${this.cardinality}"`,r+=this.uri?`uri=${this.uri}`:"",r+=this.instructions?`instructions="${this.instructions}"`:""),`<property ${s} ${r}>\n ${e}\n ${i}\n ${n}\n</property>`}async getEntities(t,e){const i=this._components.get(Zt);for(const[n,s]of i.list){if(!t.find(t=>t.test(n)))continue;const i=await s.getItemsOfCategories([/PROPERTYSET/,/ELEMENTQUANTITY/]),r=Object.values(i).flat();if(0===r.length)continue;const o=await s.getItemsData(r,{relations:{HasProperties:{attributes:!0,relations:!1},DefinesOcurrence:{attributes:!0,relations:!1}}});for(const t of o){if(!("value"in t._localId&&"value"in t._category&&"value"in t.Name&&Array.isArray(t.DefinesOcurrence)))continue;if(!this.evalRequirement(t.Name.value,this.propertySet,"PropertySet"))continue;let i;if("IFCPROPERTYSET"===t._category.value&&(i="HasProperties"),"IFCELEMENTQUANTITY"===t._category.value&&(i="Quantities"),!i)continue;const s=t[i];if(Array.isArray(s))for(const i of s){const s=Object.keys(i),r=s.find(t=>/Name/.test(t));if(!r||!("value"in i[r]))continue;const o=i[r];if(!("value"in o))continue;if(!this.evalRequirement(o.value,this.baseName,"BaseName"))continue;if(this.value){const t=s.find(t=>/Value/.test(t));if(!t)continue;const e=i[t];if(!("value"in e))continue;if(!this.evalRequirement(e.value,this.value,"Value"))continue}const a=t.DefinesOcurrence.map(t=>"value"in t._localId&&"number"==typeof t._localId.value?t._localId.value:null).filter(t=>null!==t);Vt.append(e,n,...a)}}}}async test(t,e,i={skipIfFails:!0}){const n=this._components.get(Zt);for(const[s,r]of Object.entries(t)){const t=n.list.get(s);if(!t)continue;const o=await t.getItemsData([...r],{relations:{IsDefinedBy:{attributes:!0,relations:!0},IsTypedBy:{attributes:!0,relations:!1},HasPropertySets:{attributes:!0,relations:!0},DefinesOcurrence:{attributes:!1,relations:!1}}});for(const t of o){const n=this.getItemChecks(e,s,t,i.skipIfFails);if(!n)continue;const r=(await this.getPsets(t)).filter(t=>{if(!("value"in t.Name))return!1;return!!this.evalRequirement(t.Name.value,this.propertySet,"PropertySet")&&(n.push({currentValue:t.Name.value,parameter:"PropertySet",pass:!0,requiredValue:this.propertySet}),!0)});if(0!==r.length)for(const t of r){const e=this.getPropertyListName(t);if(!e)continue;const i=t[e];if(!Array.isArray(i)){n.push({currentValue:null,parameter:"BaseName",pass:!1,requiredValue:this.baseName});continue}const s=i.filter(t=>{if(!("value"in t._category)||!("value"in t.Name))return!1;if(this._unsupportedTypes.includes(t._category.value))return!1;return!!this.evalRequirement(t.Name.value,this.baseName,"BaseName")&&(n.push({currentValue:t.Name.value,parameter:"BaseName",pass:!0,requiredValue:this.baseName}),!0)});if(0!==s.length)for(const t of s)this.evalValue(t,n),this.evalDataType(t,n),this.evalURI();else n.push({currentValue:null,parameter:"BaseName",pass:!1,requiredValue:this.baseName})}else n.push({currentValue:null,parameter:"PropertySet",pass:!1,requiredValue:this.propertySet})}}}getPropertyListName(t){let e;return"value"in t._category?("IFCPROPERTYSET"===t._category.value&&(e="HasProperties"),"IFCELEMENTQUANTITY"===t._category.value&&(e="Quantities"),e):e}getValueKey(t){return Object.keys(t).find(t=>/Value/.test(t)||/Values/.test(t))}getTypePsets(t){if(!Array.isArray(t.IsTypedBy))return[];const[e]=t.IsTypedBy;return e&&Array.isArray(e.HasPropertySets)?e.HasPropertySets:[]}async getPsets(t){const e=this.getTypePsets(t);if(!Array.isArray(t.IsDefinedBy))return e;const i=[];for(const n of t.IsDefinedBy){if(!("value"in n.Name))continue;const t=n.Name.value,s=this.getPropertyListName(n);if(!t||!s)continue;const r=e.find(e=>"value"in e.Name&&e.Name.value===t);if(r&&Array.isArray(r.HasProperties)&&Array.isArray(n.HasProperties))for(const t of r.HasProperties){if(!("value"in t.Name))continue;const e=t.Name.value;n.HasProperties.find(t=>"value"in t.Name&&t.Name.value===e)||n.HasProperties.push(t)}i.push(n)}return i}evalValue(t,e){const i=this.getValueKey(t),n=t[i];if(!("value"in n))return!1;if(this.value){if(!i)return null==e||e.push({parameter:"Value",currentValue:null,pass:!1,requiredValue:this.value}),!1;const t=structuredClone(this.value);"IFCLABEL"===n.type&&"simple"===t.type&&(t.parameter=String(t.parameter));return this.evalRequirement(n.value,t,"Value",e)}return!i||("string"!=typeof n.value||""!==n.value.trim()||(null==e||e.push({parameter:"Value",currentValue:"",pass:!1,requiredValue:this.value}),!1))}evalDataType(t,e){if(!this.dataType)return!0;const i=this.getValueKey(t);if(!i||!("value"in t[i]))return null==e||e.push({parameter:"DataType",currentValue:null,pass:!1,requiredValue:this.dataType}),!1;const n=t[i];return this.evalRequirement(n.type??null,{type:"simple",parameter:this.dataType},"DataType",e)}evalURI(){return!0}}class pr extends ar{constructor(){super(...arguments),e(this,"_ifcMaterialEntities",[/^IFCMATERIALLAYERSETUSAGE$/,/^IFCMATERIALCONSTITUENTSET$/,/^IFCMATERIAL$/,/^IFCMATERIALLIST$/]),e(this,"facetType","Material"),e(this,"value"),e(this,"uri")}serialize(t){if(!this.value||!this.uri)return"<material />";const e=lr("Value",this.value);let i="";return"requirement"===t&&(i+=`cardinality="${this.cardinality}"`,i+=this.uri?`uri=${this.uri}`:"",i+=this.instructions?`instructions="${this.instructions}"`:""),`<material ${i}>\n ${e}\n</material>`}async getEntities(t,e){const i=this._components.get(Zt);for(const[n,s]of i.list){if(!t.find(t=>t.test(n)))continue;const i=await s.getItemsOfCategories(this._ifcMaterialEntities),r=Object.values(i).flat();if(0===r.length)continue;const o=await s.getItemsData(r,{relations:{AssociatedTo:{attributes:!0,relations:!1},MaterialConstituents:{attributes:!0,relations:!0},ForLayerSet:{attributes:!0,relations:!0},MaterialLayers:{attributes:!0,relations:!0},Materials:{attributes:!0,relations:!1}}});for(const t of o){if(!("value"in t._localId&&"value"in t._category&&Array.isArray(t.AssociatedTo)))continue;if(!this.hasValidMaterial(t))continue;const i=t.AssociatedTo.map(t=>"value"in t._localId&&t._localId.value?t._localId.value:null).filter(t=>null!==t);Vt.append(e,n,...i)}}}async test(t,e,i={skipIfFails:!0}){const n=this._components.get(Zt);for(const[s,r]of Object.entries(t)){const t=n.list.get(s);if(!t)continue;const o=await t.getItemsData([[...r][0]],{relations:{AssociatedTo:{attributes:!1,relations:!1},HasAssociations:{attributes:!0,relations:!0},MaterialConstituents:{attributes:!0,relations:!0},ForLayerSet:{attributes:!0,relations:!0},MaterialLayers:{attributes:!0,relations:!0},Materials:{attributes:!0,relations:!1}}});for(const t of o){const n=this.getItemChecks(e,s,t,i.skipIfFails);if(n)if(Array.isArray(t.HasAssociations))for(const e of t.HasAssociations){if(!this._ifcMaterialEntities.some(t=>"value"in e._category&&t.test(e._category.value)))continue;if(this.hasValidMaterial(e,n))break}else n.push({parameter:null,currentValue:null,requiredValue:this.value,pass:!1})}}}hasValidMaterial(t,e){let i=!1;if("value"in t._category&&"IFCMATERIAL"===t._category.value){this.evalValue(t,e)&&(i=!0)}else for(const[n,s]of Object.entries(t))if(["ForLayerSet","MaterialLayers","Material","MaterialConstituents","Materials"].includes(n)&&Array.isArray(s))for(const t of s){if("value"in t._category&&"IFCMATERIAL"===t._category.value){if(this.evalValue(t,e)){i=!0;break}}else{if(this.hasValidMaterial(t)){i=!0;break}}}return i}evalValue(t,e){if(!this.value)return null==e||e.push({parameter:null,currentValue:t.Name&&"value"in t.Name?t.Name.value:null,pass:!0}),!0;if(!("value"in t._category)||"IFCMATERIAL"!==t._category.value)return null;let i=!1;return t.Name&&"value"in t.Name&&(i=this.evalRequirement(t.Name.value,this.value,"Value",e)),i||(t.Category&&"value"in t.Category&&(i=this.evalRequirement(t.Category.value,this.value,"Value",e)),i)}}class fr extends ar{constructor(t,i){super(t),e(this,"facetType","PartOf"),e(this,"_entityFacet"),e(this,"_entity"),e(this,"relation"),e(this,"cardinality","required"),this._entity=i,this._entityFacet=new ur(t,i.name),this._entityFacet.predefinedType=i.predefinedType}set entity(t){this._entity=t;const{name:e,predefinedType:i}=t;this._entityFacet=new ur(this._components,e),this._entityFacet.predefinedType=i}get entity(){return this._entity}serialize(){return""}async getEntities(t,e){}async test(t){}}class mr{constructor(t,i,n){e(this,"name"),e(this,"ifcVersion",new Set),e(this,"identifier",_.create()),e(this,"description"),e(this,"instructions"),e(this,"requirementsDescription"),e(this,"applicability",new a.DataSet),e(this,"requirements",new a.DataSet),e(this,"components"),this.components=t,this.name=i;for(const t of n)this.ifcVersion.add(t)}set(t){const e=t,i=this;for(const n in t){if("identifier"===n)continue;const t=e[n];n in this&&(i[n]=t)}return this.components.get(Cr).list.set(this.identifier,this),this}async test(t,e={skipIfFails:!0}){const i=new a.DataMap;if(0===this.requirements.size)return i;const n={},s=[];for(const e of this.applicability)s.push(e.getEntities(t,n));await Promise.all(s);const r=[];for(const t of this.requirements)r.push(t.test(n,i,e));return await Promise.all(r),i}serialize(){const t=`name="${this.name}"`,e=this.identifier?`identifier="${this.identifier}"`:"",i=this.description?`description="${this.description}"`:"",n=this.instructions?`instructions="${this.instructions}"`:"";return`<specification ifcVersion="${[...this.ifcVersion].join(" ")}" ${t} ${e} ${i} ${n}>\n <applicability minOccurs="1" maxOccurs="unbounded">\n ${[...this.applicability].map(t=>t.serialize("applicability")).join("\n")}\n </applicability>\n <requirements>\n ${[...this.requirements].map(t=>t.serialize("requirement")).join("\n")}\n </requirements>\n </specification>`}}const gr=t=>{if(!t)return;const e={};if("simpleValue"in t&&(e.type="simple",e.parameter=t.simpleValue),"restriction"in t){const i=t.restriction,n=Object.keys(i);if("pattern"in i&&(e.type="pattern",e.parameter=i.pattern.value),"enumeration"in i){e.type="enumeration";const t=i.enumeration.map(({value:t})=>i.base.includes("string")?String(t):i.base.includes("integer")||i.base.includes("double")?Number(t):t);e.parameter=t}if(n.some(t=>["minInclusive","minExclusive","maxInclusive","maxExclusive"].includes(t))){e.type="bounds";const t={},s=n.find(t=>t.includes("min")),r=n.find(t=>t.includes("max"));s&&(t.minInclusive="minInclusive"===s,t.min=i[s].value),r&&(t.maxInclusive="maxInclusive"===r,t.max=i[r].value),e.parameter=t}if(n.some(t=>["minLength","length","maxLength"].includes(t))){e.type="length";const t={};void 0!==i.length&&(t.length=i.length.value),void 0!==i.minLength&&(t.min=i.minLength.value),void 0!==i.maxLength&&(t.max=i.maxLength.value),e.parameter=t}}return void 0!==e.parameter?e:void 0},yr=(t,e)=>{const i=[];for(const n of e){const e=n.name,s=gr(e);if(!s)continue;const r=new ur(t,s);n.cardinality&&(r.cardinality=n.cardinality),r.predefinedType=gr(n.predefinedType),r.instructions=n.instructions,i.push(r)}return i},wr=(t,e)=>{const i=[];for(const n of e){const e=n.name,s=gr(e);if(!s)continue;const r=new cr(t,s);n.cardinality&&(r.cardinality=n.cardinality),r.value=gr(n.value),r.instructions=n.instructions,i.push(r)}return i},vr=(t,e)=>{const i=[];for(const n of e){const e=new pr(t);n.cardinality&&(e.cardinality=n.cardinality);const s=gr(n.value);"enumeration"===(null==s?void 0:s.type)&&Array.isArray(s.parameter)&&(s.parameter=s.parameter.map(String)),e.value=s,e.uri=n.uri,e.instructions=n.instructions,i.push(e)}return i},br=(t,e)=>{const i=[];for(const n of e){const e=n.propertySet,s=n.baseName,r=gr(e),o=gr(s);if(!o||!r)continue;const a=new dr(t,r,o);n.cardinality&&(a.cardinality=n.cardinality);const l=gr(n.value);a.value=l,a.dataType=n.dataType,a.uri=n.uri,a.instructions=n.instructions,i.push(a)}return i},_r=(t,e)=>{const i=[];for(const n of e){const e=n.system,s=gr(e);if(!s)continue;const r=new hr(t,s);n.cardinality&&(r.cardinality=n.cardinality);const o=gr(n.value);"simple"===(null==o?void 0:o.type)&&(o.parameter=String(o.parameter)),"enumeration"===(null==o?void 0:o.type)&&Array.isArray(o.parameter)&&(o.parameter=o.parameter.map(String)),r.value=o,r.uri=n.uri,r.instructions=n.instructions,i.push(r)}return i},xr=(t,e)=>{const i=[];for(const n of e){const e=gr(n.entity.name);if(!e)continue;const s=gr(n.entity.predefinedType),r=new fr(t,{name:e,predefinedType:s});r.relation=n.relation,n.cardinality&&(r.cardinality=n.cardinality),r.instructions=n.instructions,i.push(r)}return i},Sr=class t extends d{constructor(n){super(n),e(this,"enabled",!0),e(this,"IDSInfo"),e(this,"list",new i.DataMap),n.add(t.uuid,this)}getModelIdMap(t){const e={},i={};for(const[n,s]of t){const t=[...s].filter(([,t])=>t.pass).map(([t])=>t);Vt.append(e,n,...t);const r=[...s].filter(([,t])=>!t.pass).map(([t])=>t);Vt.append(i,n,...r)}return{pass:e,fail:i}}create(t,e,i){const n=new mr(this.components,t,e);return i&&(n.identifier=i),this.list.set(n.identifier,n),n}load(e){const i=[],n=t.xmlParser.parse(e).ids,{specifications:s,info:r}=n;if(this.IDSInfo={...r},s&&s.specification){const t=Array.isArray(s.specification)?s.specification:[s.specification];for(const e of t){const{name:t,ifcVersion:n,description:s,instructions:r,identifier:o}=e;if(!t||!n)continue;const a=[],l=[],{applicability:c,requirements:h}=e;if(c){const{maxOccurs:t,...e}=c,i=Array.isArray(e)?e:[e];for(const t of i)for(const e in t){const i=Array.isArray(t[e])?t[e]:[t[e]];if("entity"===e){const t=yr(this.components,i);a.push(...t)}if("attribute"===e){const t=wr(this.components,i);a.push(...t)}if("material"===e){const t=vr(this.components,i);a.push(...t)}if("classification"===e){const t=_r(this.components,i);a.push(...t)}if("property"===e){const t=br(this.components,i);a.push(...t)}if("partOf"===e){const t=xr(this.components,i);a.push(...t)}}}let u;if(h){const{maxOccurs:t,...e}=h;u=h.description;const i=Array.isArray(e)?e:[e];for(const t of i)for(const e in t){const i=Array.isArray(t[e])?t[e]:[t[e]];if("entity"===e){const t=yr(this.components,i);l.push(...t)}if("attribute"===e){const t=wr(this.components,i);l.push(...t)}if("material"===e){const t=vr(this.components,i);l.push(...t)}if("classification"===e){const t=_r(this.components,i);l.push(...t)}if("property"===e){const t=br(this.components,i);l.push(...t)}if("partOf"===e){const t=xr(this.components,i);l.push(...t)}}}const d=this.create(t,n.split(/\s+/),o);d.description=s,d.instructions=r,d.requirementsDescription=u,d.applicability.add(...a),d.requirements.add(...l),i.push(d)}}return i}export(t,e=this.list.values()){const i=e??this.list;return`<ids xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://standards.buildingsmart.org/IDS http://standards.buildingsmart.org/IDS/1.0/ids.xsd" xmlns:ids="http://standards.buildingsmart.org/IDS">\n \x3c!-- Made with That Open Engine ${Qn.release} (https://github.com/thatopen/engine_components) --\x3e\n <info>\n <title>${t.title}</title>\n ${t.copyright?`<copyright>${t.copyright}</copyright>`:""}\n ${t.version?`<version>${t.version}</version>`:""}\n ${t.description?`<description>${t.description}</description>`:""}\n ${t.author?`<author>${t.author}</author>`:""}\n ${t.date?`<date>${t.date.toISOString().split("T")[0]}</date>`:""}\n ${t.purpose?`<purpose>${t.purpose}</purpose>`:""}\n ${t.milestone?`<milestone>${t.milestone}</milestone>`:""}\n </info>\n <specifications>\n ${[...i].map(t=>t.serialize()).join("\n")}\n </specifications>\n</ids>`}};e(Sr,"uuid","9f0b9f78-9b2e-481a-b766-2fbfd01f342c"),e(Sr,"xmlParser",new Ct({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,ignoreDeclaration:!0,ignorePiTags:!0,numberParseOptions:{leadingZeros:!0,hex:!0},parseAttributeValue:!0,preserveOrder:!1,processEntities:!1,removeNSPrefix:!0,trimValues:!0}));let Cr=Sr;const Ar=class t extends d{constructor(i){super(i),e(this,"enabled",!0),i.add(t.uuid,this)}static distanceFromPointToLine(t,e,i,n=!1){const s=new l.Line3,r=new l.Vector3;return s.set(e,i),s.closestPointToPoint(t,n,r),r.distanceTo(t)}round(t){const e=1e3;t.x=Math.trunc(t.x*e)/e,t.y=Math.trunc(t.y*e)/e,t.z=Math.trunc(t.z*e)/e}async getVolumeFromFragments(t){return console.warn("getVolumeFromFragments is deprecated. Use getItemsVolume instead."),this.getItemsVolume(t)}async getItemsVolume(t){let e=0;const i=this.components.get(Zt);for(const[n,s]of Object.entries(t)){const t=i.list.get(n);t&&(e+=await t.getItemsVolume([...s]))}return e}static convertUnits(t,e,i,n=2){const s={m:1,cm:.01,mm:.001,km:1e3,m2:1,cm2:1e-4,mm2:1e-6,km2:1e6,m3:1,cm3:1e-6,mm3:1e-9,km3:1e9};if(!s[e]||!s[i])throw new Error("Invalid units provided for conversion.");if(!Number.isInteger(n)||n<0||n>5)throw new Error("Precision must be an integer between 0 and 5.");const r=t*(s[e]/s[i]),o=10**n;return Math.round(r*o)/o}};e(Ar,"uuid","267ca032-672f-4cb0-afa9-d24e904f39d6");let Er=Ar;exports.AsyncEvent=class{constructor(){e(this,"enabled",!0),e(this,"trigger",async t=>{if(!this.enabled)return;const e=this.handlers.slice(0);for(const i of e)await i(t)}),e(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}},exports.BCFTopics=fs,exports.BCFTopicsConfigManager=ds,exports.Base=u,exports.BaseCamera=f,exports.BaseRenderer=m,exports.BaseScene=w,exports.BaseWorldItem=p,exports.BoundingBoxer=Kt,exports.Classifier=ne,exports.Clipper=Qs,exports.Comment=ls,exports.Component=d,exports.Components=Qn,exports.ConfigManager=$t,exports.Configurator=Lt,exports.ControlsUtils=Rt,exports.DataMap=Ft,exports.DataSet=v,exports.Disposer=y,exports.Event=h,exports.EventManager=class{constructor(){e(this,"list",new Set)}add(t){for(const e of t)this.list.add(e)}remove(t){for(const e of t)this.list.delete(e)}set(t){for(const e of this.list)e.enabled=t}reset(){for(const t of this.list)t.reset()}},exports.FastModelPicker=se,exports.FastModelPickers=oe,exports.FinderQuery=Jt,exports.FirstPersonMode=Kn,exports.FragmentsManager=Zt,exports.Grids=xe,exports.Hider=Xt,exports.IDSAttribute=cr,exports.IDSClassification=hr,exports.IDSEntity=ur,exports.IDSFacet=ar,exports.IDSMaterial=pr,exports.IDSPartOf=fr,exports.IDSProperty=dr,exports.IDSSpecification=mr,exports.IDSSpecifications=Cr,exports.IfcFragmentSettings=Gt,exports.IfcLoader=Yt,exports.ItemsFinder=ee,exports.MeasurementUtils=Er,exports.ModelIdMapUtils=Vt,exports.Mouse=jt,exports.OrbitMode=Jn,exports.OrthoPerspectiveCamera=is,exports.PlanMode=ts,exports.ProjectionManager=es,exports.Raycasters=ce,exports.RendererMode=me,exports.ShadowedScene=class extends fe{constructor(){super(...arguments),e(this,"_distanceRenderer"),e(this,"autoBias",!0),e(this,"_defaultShadowConfig",{cascade:1,resolution:512}),e(this,"_lightsWithShadow",new Map),e(this,"_isComputingShadows",!1),e(this,"_shadowsEnabled",!0),e(this,"_bias",0),e(this,"recomputeShadows",t=>{if(!this._shadowsEnabled)return;this.autoBias&&(this.bias=-.005);if(t*=1.5,!this.currentWorld)throw new Error("A world needs to be assigned to the scene before computing shadows!");if(!this._lightsWithShadow.size)throw new Error("No shadows found!");const e=this.currentWorld.camera.three;if(!(e instanceof l.PerspectiveCamera||e instanceof l.OrthographicCamera))throw new Error("Invalid camera type!");const i=new l.Vector3;e.getWorldDirection(i);let n=t;const s=new l.Vector3;s.copy(this.config.directionalLight.position),s.normalize();for(const[t,r]of this._lightsWithShadow){const o=this.directionalLights.get(r);if(!o)throw new Error("Light not found.");const a=new l.Vector3;a.copy(i);const c=t===this._lightsWithShadow.size-1,h=c?n/2:2*n/3;a.multiplyScalar(h),a.add(e.position);const u=n-h,d=new l.Vector3;d.copy(s),d.multiplyScalar(u),o.target.position.copy(a),o.position.copy(a),o.position.add(d),o.shadow.camera.right=u,o.shadow.camera.left=-u,o.shadow.camera.top=u,o.shadow.camera.bottom=-u,o.shadow.camera.far=2*u,o.shadow.camera.updateProjectionMatrix(),o.shadow.camera.updateMatrix(),c||(n/=3)}this._isComputingShadows=!1})}get bias(){return this._bias}set bias(t){this._bias=t;for(const[,e]of this._lightsWithShadow){const i=this.directionalLights.get(e);i&&(i.shadow.bias=t)}}get shadowsEnabled(){return this._shadowsEnabled}set shadowsEnabled(t){this._shadowsEnabled=t;for(const[,e]of this.directionalLights)e.castShadow=t}get distanceRenderer(){if(!this._distanceRenderer)throw new Error("You must set up this component before accessing the distance renderer!");return this._distanceRenderer}setup(t){super.setup(t);const e={...this._defaultConfig,...this._defaultShadowConfig,...t};if(e.cascade<=0)throw new Error("Config.shadows.cascade must be a natural number greater than 0!");if(e.cascade>1)throw new Error("Multiple shadows not supported yet!");if(!this.currentWorld)throw new Error("A world needs to be assigned to the scene before setting it up!");for(const[,t]of this.directionalLights)t.target.removeFromParent(),t.removeFromParent(),t.dispose();this.directionalLights.clear(),this._distanceRenderer||(this._distanceRenderer=new or(this.components,this.currentWorld),this._distanceRenderer.onDistanceComputed.add(this.recomputeShadows)),this._lightsWithShadow.clear();for(let t=0;t<e.cascade;t++){const i=new l.DirectionalLight;i.intensity=this.config.directionalLight.intensity,i.color=this.config.directionalLight.color,i.position.copy(this.config.directionalLight.position),i.shadow.mapSize.width=e.resolution,i.shadow.mapSize.height=e.resolution,this.three.add(i,i.target),this.directionalLights.set(i.uuid,i),this._lightsWithShadow.set(t,i.uuid),i.castShadow=!0,i.shadow.bias=this._bias}}dispose(){super.dispose(),this._distanceRenderer&&this._distanceRenderer.dispose(),this._lightsWithShadow.clear()}async updateShadows(){!this._isComputingShadows&&this._shadowsEnabled&&(this._isComputingShadows=!0,await this.distanceRenderer.compute())}},exports.SimpleCamera=ge,exports.SimpleGrid=be,exports.SimpleGridConfigManager=ve,exports.SimplePlane=Ys,exports.SimpleRaycaster=ae,exports.SimpleRenderer=class extends m{constructor(t,i,n){super(t),e(this,"enabled",!0),e(this,"container"),e(this,"three"),e(this,"mode",1),e(this,"needsUpdate",!1),e(this,"_canvas"),e(this,"_parameters"),e(this,"_resizeObserver",null),e(this,"onContainerUpdated",new h),e(this,"_resizing",!1),e(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(e,i),this.onResize.trigger(new l.Vector2(e,i)),this._resizing=!1}),e(this,"resizeEvent",()=>{this.resize()}),e(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1}),e(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new l.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0}),this.container=i,this._parameters=n,this.three=new l.WebGLRenderer({antialias:!0,alpha:!0,...n}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const s=this.three.getContext(),{canvas:r}=s;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;if(0===this.mode&&!this.needsUpdate)return;this.needsUpdate=!1,this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,e=this.currentWorld.camera.three;this.three.render(t,e),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new l.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}},exports.SimpleScene=fe,exports.SimpleSceneConfigManager=pe,exports.SimpleWorld=he,exports.Topic=hs,exports.UUID=_,exports.VertexPicker=class extends d{constructor(t,i){super(t),e(this,"onDisposed",new h),e(this,"onVertexFound",new h),e(this,"onVertexLost",new h),e(this,"onEnabled",new h),e(this,"components"),e(this,"workingPlane",null),e(this,"_pickedPoint",null),e(this,"_config"),e(this,"_enabled",!1),this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...i},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}async get(t){if(!this.enabled)return this._pickedPoint;const e=this.components.get(ce).get(t),i=await e.castRay();if(!i)return null!==this._pickedPoint&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const n=i.point;return null!==this._pickedPoint&&this._pickedPoint.equals(n)||(this._pickedPoint=n.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint}},exports.View=ir,exports.Viewpoint=Ks,exports.Viewpoints=er,exports.Views=sr,exports.Worlds=we,exports.XML=Nt,exports.extensionsImporter=us;