UNPKG

@kibeo/loaders.gl-textures

Version:

Framework-independent loaders for compressed and super compressed (basis) textures

2 lines 35.2 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=10)}([function(t,e,n){"use strict";(function(t,r){n.d(e,"a",(function(){return o})),n.d(e,"b",(function(){return _})),n.d(e,"c",(function(){return a}));const i={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==t&&t,document:"undefined"!=typeof document&&document},o=i.global||i.self||i.window||{},_="object"!=typeof r||"[object process]"!==String(r)||r.browser,a="function"==typeof importScripts,s=("undefined"!=typeof window&&window.orientation,void 0!==r&&r.version&&/v([0-9]*)/.exec(r.version));s&&parseFloat(s[1])}).call(this,n(4),n(5))},function(t,e){},function(t,e,n){"use strict";(function(t,r){n.d(e,"a",(function(){return o})),n.d(e,"b",(function(){return _}));const i={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==t&&t,document:"undefined"!=typeof document&&document},o=i.global||i.self||i.window,_="object"!=typeof r||"[object process]"!==String(r)||r.browser,a=void 0!==r&&r.version&&/v([0-9]*)/.exec(r.version);a&&parseFloat(a[1])}).call(this,n(4),n(5))},function(t,e){},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function _(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:_}catch(t){r=_}}();var s,c=[],S=!1,u=-1;function E(){S&&s&&(S=!1,s.length?c=s.concat(c):u=-1,c.length&&R())}function R(){if(!S){var t=a(E);S=!0;for(var e=c.length;e;){for(s=c,c=[];++u<e;)s&&s[u].run();u=-1,e=c.length}s=null,S=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===_||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function f(t,e){this.fun=t,this.array=e}function l(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new f(t,e)),1!==c.length||S||a(R)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=l,i.addListener=l,i.once=l,i.off=l,i.removeListener=l,i.removeAllListeners=l,i.emit=l,i.prependListener=l,i.prependOnceListener=l,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},,,function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return o}));var r=n(13);const i=t+"/../../..";async function o(t,e){const n=["texture-compressor","--type","s3tc","--compression","DXT1","--quality","normal","--input",t,"--output",e],o=new r.a;return await o.start({command:"npx",arguments:n,spawn:{cwd:i}}),e}}).call(this,"/")},function(t,e,n){"use strict";n.d(e,"a",(function(){return o}));var r=n(1),i=n.n(r);function o(t=3e3){return new Promise(e=>{i.a.exec("lsof -i -P -n | grep LISTEN",(n,r)=>{if(n)return void e(t);const i=[],o=/:(\d+) \(LISTEN\)/;r.split("\n").forEach(t=>{const e=o.exec(t);e&&i.push(Number(e[1]))});let _=t;for(;i.includes(_);)_++;e(_)})})}},function(t,e,n){(function(e){const r=n(12),i="undefined"==typeof window?e:window;i.loaders=i.loaders||{},t.exports=Object.assign(i.loaders,r)}).call(this,n(4))},,function(t,e,n){"use strict";n.r(e),n.d(e,"BasisLoader",(function(){return R})),n.d(e,"BasisWorkerLoader",(function(){return E})),n.d(e,"CompressedTextureLoader",(function(){return ot})),n.d(e,"CompressedTextureWorkerLoader",(function(){return it})),n.d(e,"CrunchWorkerLoader",(function(){return _t})),n.d(e,"NPYLoader",(function(){return ut})),n.d(e,"NPYWorkerLoader",(function(){return St})),n.d(e,"CompressedTextureWriter",(function(){return Et})),n.d(e,"loadImageTexture",(function(){return Kt})),n.d(e,"loadImageTextureArray",(function(){return Ft})),n.d(e,"loadImageTextureCube",(function(){return Vt})),n.d(e,"GL_CONSTANTS",(function(){return c})),n.d(e,"getSupportedGPUTextureFormats",(function(){return zt}));var r=n(0),i=n(3);const o={};async function _(t,e=null,n={}){return e&&(t=function(t,e,n){if(t.startsWith("http"))return t;const i=n.modules||{};if(i[t])return i[t];if(!r.b)return`modules/${e}/dist/libs/${t}`;if(n.CDN)return function(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}(n.CDN.startsWith("http")),`${n.CDN}/${e}@3.0.17/dist/libs/${t}`;if(r.c)return"../src/libs/"+t;return`modules/${e}/src/libs/${t}`}(t,e,n)),o[t]=o[t]||async function(t){if(t.endsWith("wasm")){const e=await fetch(t);return await e.arrayBuffer()}if(!r.b)return i.requireFromFile&&await i.requireFromFile(t);if(r.c)return importScripts(t);const e=await fetch(t);return function(t,e){if(!r.b)return i.requireFromString&&i.requireFromString(t,e);if(r.c)return eval.call(r.a,t),null;const n=document.createElement("script");n.id=e;try{n.appendChild(document.createTextNode(t))}catch(e){n.text=t}return document.body.appendChild(n),null}(await e.text(),t)}(t),await o[t]}let a;async function s(t){const e=t.modules||{};return e.basis?e.basis:(a=a||async function(t){let e=null,n=null;return[e,n]=await Promise.all([await _("basis_transcoder.js","textures",t),await _("basis_transcoder.wasm","textures",t)]),e=e||globalThis.BASIS,await function(t,e){const n={};e&&(n.wasmBinary=e);return new Promise(e=>{t(n).then(t=>{const{BasisFile:n,initializeBasis:r}=t;r(),e({BasisFile:n})})})}(e,n)}(t),await a)}const c={COMPRESSED_RGB_S3TC_DXT1_EXT:33776,COMPRESSED_RGBA_S3TC_DXT1_EXT:33777,COMPRESSED_RGBA_S3TC_DXT3_EXT:33778,COMPRESSED_RGBA_S3TC_DXT5_EXT:33779,COMPRESSED_R11_EAC:37488,COMPRESSED_SIGNED_R11_EAC:37489,COMPRESSED_RG11_EAC:37490,COMPRESSED_SIGNED_RG11_EAC:37491,COMPRESSED_RGB8_ETC2:37492,COMPRESSED_RGBA8_ETC2_EAC:37493,COMPRESSED_SRGB8_ETC2:37494,COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:37495,COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:37496,COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:37497,COMPRESSED_RGB_PVRTC_4BPPV1_IMG:35840,COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:35842,COMPRESSED_RGB_PVRTC_2BPPV1_IMG:35841,COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:35843,COMPRESSED_RGB_ETC1_WEBGL:36196,COMPRESSED_RGB_ATC_WEBGL:35986,COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL:35987,COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL:34798,COMPRESSED_RGBA_ASTC_4X4_KHR:37808,COMPRESSED_RGBA_ASTC_5X4_KHR:37809,COMPRESSED_RGBA_ASTC_5X5_KHR:37810,COMPRESSED_RGBA_ASTC_6X5_KHR:37811,COMPRESSED_RGBA_ASTC_6X6_KHR:37812,COMPRESSED_RGBA_ASTC_8X5_KHR:37813,COMPRESSED_RGBA_ASTC_8X6_KHR:37814,COMPRESSED_RGBA_ASTC_8X8_KHR:37815,COMPRESSED_RGBA_ASTC_10X5_KHR:37816,COMPRESSED_RGBA_ASTC_10X6_KHR:37817,COMPRESSED_RGBA_ASTC_10X8_KHR:37818,COMPRESSED_RGBA_ASTC_10X10_KHR:37819,COMPRESSED_RGBA_ASTC_12X10_KHR:37820,COMPRESSED_RGBA_ASTC_12X12_KHR:37821,COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR:37840,COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR:37841,COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR:37842,COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR:37843,COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR:37844,COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR:37845,COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR:37846,COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR:37847,COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR:37848,COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR:37849,COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR:37850,COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR:37851,COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR:37852,COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR:37853,COMPRESSED_RED_RGTC1_EXT:36283,COMPRESSED_SIGNED_RED_RGTC1_EXT:36284,COMPRESSED_RED_GREEN_RGTC2_EXT:36285,COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:36286,COMPRESSED_SRGB_S3TC_DXT1_EXT:35916,COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:35917,COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:35918,COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:35919},S={etc1:{basisFormat:0,compressed:!0},etc2:{basisFormat:1,compressed:!0},bc1:{basisFormat:2,compressed:!0,format:c.COMPRESSED_RGB_S3TC_DXT1_EXT},bc3:{basisFormat:3,compressed:!0,format:c.COMPRESSED_RGBA_S3TC_DXT5_EXT},bc4:{basisFormat:4,compressed:!0},bc5:{basisFormat:5,compressed:!0},"bc7-m6-opaque-only":{basisFormat:6,compressed:!0},"bc7-m5":{basisFormat:7,compressed:!0},"pvrtc1-4-rgb":{basisFormat:8,compressed:!0},"pvrtc1-4-rgba":{basisFormat:9,compressed:!0},"astc-4x4":{basisFormat:10,compressed:!0},"atc-rgb":{basisFormat:11,compressed:!0},"atc-rgba-interpolated-alpha":{basisFormat:12,compressed:!0},rgba32:{basisFormat:13,compressed:!1},rgb565:{basisFormat:14,compressed:!1},bgr565:{basisFormat:15,compressed:!1},rgba4444:{basisFormat:16,compressed:!1}};function u(t,e,n,r){const i=t.getImageWidth(e,n),o=t.getImageHeight(e,n),_=t.getHasAlpha(),{compressed:a,format:s,basisFormat:c}=function(t,e){let n=t&&t.basis&&t.basis.format;return"object"==typeof n&&(n=e?n.alpha:n.noAlpha),n=n.toLowerCase(),S[n]}(r,_),u=t.getImageTranscodedSizeInBytes(e,n,c),E=new Uint8Array(u);return t.transcodeImage(E,e,n,c,0,0)?{width:i,height:o,data:E,compressed:a,hasAlpha:_,format:s}:null}const E={name:"Basis",id:"basis",module:"textures",version:"3.0.17",worker:!0,extensions:["basis"],mimeTypes:["application/octet-stream"],tests:["sB"],binary:!0,options:{basis:{format:"rgb565",libraryPath:"libs/"}}},R={...E,parse:async function(t,e){const{BasisFile:n}=await s(e),r=new n(new Uint8Array(t));try{if(!r.startTranscoding())return null;const t=r.getNumImages(),n=[];for(let i=0;i<t;i++){const t=r.getNumLevels(i),o=[];for(let n=0;n<t;n++)o.push(u(r,i,n,e));n.push(o)}return n}finally{r.close(),r.delete()}}},f=(new Uint8Array([0]),[171,75,84,88,32,50,48,187,13,10,26,10]);var l,A,C,d,T,m,P,h;!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB"}(l||(l={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT"}(A||(A={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC"}(C||(C={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB"}(d||(d={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2"}(T||(T={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(m||(m={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA"}(P||(P={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG"}(h||(h={}));class p{constructor(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=l.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:A.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:C.UNSPECIFIED,colorPrimaries:d.SRGB,transferFunction:d.SRGB,flags:m.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null}}class D{constructor(t,e,n,r){this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=r,this._offset=0}_nextUint8(){const t=this._dataView.getUint8(this._offset);return this._offset+=1,t}_nextUint16(){const t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t}_nextUint32(){const t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t}_nextUint64(){const t=this._dataView.getUint32(this._offset,this._littleEndian)+2**32*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,t}_skip(t){return this._offset+=t,this}_scan(t,e=0){const n=this._offset;let r=0;for(;this._dataView.getUint8(this._offset)!==e&&r<t;)r++,this._offset++;return r<t&&this._offset++,new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+n,r)}}function M(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function g(t,e){const n=new Array(e.mipMapLevels);let r=e.width,i=e.height,o=0;for(let _=0;_<e.mipMapLevels;++_){const a=w(e,r,i,t,_),s=G(t,_,o,a);n[_]={compressed:!0,format:e.internalFormat,data:s,width:r,height:i,levelSize:a},r=Math.max(1,r>>1),i=Math.max(1,i>>1),o+=a}return n}function G(t,e,n,r){return Array.isArray(t)?t[e].levelData:new Uint8Array(t.buffer,t.byteOffset+n,r)}function w(t,e,n,r,i){return Array.isArray(r)?t.sizeFunction(r[i]):t.sizeFunction(e,n)}const B={131:c.COMPRESSED_RGB_S3TC_DXT1_EXT,132:c.COMPRESSED_SRGB_S3TC_DXT1_EXT,133:c.COMPRESSED_RGBA_S3TC_DXT1_EXT,134:c.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,135:c.COMPRESSED_RGBA_S3TC_DXT3_EXT,136:c.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,137:c.COMPRESSED_RGBA_S3TC_DXT5_EXT,138:c.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,139:c.COMPRESSED_RED_RGTC1_EXT,140:c.COMPRESSED_SIGNED_RED_RGTC1_EXT,141:c.COMPRESSED_RED_GREEN_RGTC2_EXT,142:c.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,147:c.COMPRESSED_RGB8_ETC2,148:c.COMPRESSED_SRGB8_ETC2,149:c.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,150:c.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,151:c.COMPRESSED_RGBA8_ETC2_EAC,152:c.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,153:c.COMPRESSED_R11_EAC,154:c.COMPRESSED_SIGNED_R11_EAC,155:c.COMPRESSED_RG11_EAC,156:c.COMPRESSED_SIGNED_RG11_EAC,157:c.COMPRESSED_RGBA_ASTC_4x4_KHR,158:c.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,159:c.COMPRESSED_RGBA_ASTC_5x4_KHR,160:c.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR,161:c.COMPRESSED_RGBA_ASTC_5x5_KHR,162:c.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,163:c.COMPRESSED_RGBA_ASTC_6x5_KHR,164:c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,165:c.COMPRESSED_RGBA_ASTC_6x6_KHR,166:c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,167:c.COMPRESSED_RGBA_ASTC_8x5_KHR,168:c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,169:c.COMPRESSED_RGBA_ASTC_8x6_KHR,170:c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,171:c.COMPRESSED_RGBA_ASTC_8x8_KHR,172:c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,173:c.COMPRESSED_RGBA_ASTC_10x5_KHR,174:c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,175:c.COMPRESSED_RGBA_ASTC_10x6_KHR,176:c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,177:c.COMPRESSED_RGBA_ASTC_10x8_KHR,178:c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,179:c.COMPRESSED_RGBA_ASTC_10x10_KHR,180:c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,181:c.COMPRESSED_RGBA_ASTC_12x10_KHR,182:c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,183:c.COMPRESSED_RGBA_ASTC_12x12_KHR,184:c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,1000054e3:c.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,1000054001:c.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,1000066e3:c.COMPRESSED_RGBA_ASTC_4x4_KHR,1000066001:c.COMPRESSED_RGBA_ASTC_5x4_KHR,1000066002:c.COMPRESSED_RGBA_ASTC_5x5_KHR,1000066003:c.COMPRESSED_RGBA_ASTC_6x5_KHR,1000066004:c.COMPRESSED_RGBA_ASTC_6x6_KHR,1000066005:c.COMPRESSED_RGBA_ASTC_8x5_KHR,1000066006:c.COMPRESSED_RGBA_ASTC_8x6_KHR,1000066007:c.COMPRESSED_RGBA_ASTC_8x8_KHR,1000066008:c.COMPRESSED_RGBA_ASTC_10x5_KHR,1000066009:c.COMPRESSED_RGBA_ASTC_10x6_KHR,1000066010:c.COMPRESSED_RGBA_ASTC_10x8_KHR,1000066011:c.COMPRESSED_RGBA_ASTC_10x10_KHR,1000066012:c.COMPRESSED_RGBA_ASTC_12x10_KHR,1000066013:c.COMPRESSED_RGBA_ASTC_12x12_KHR};const O=[171,75,84,88,32,50,48,187,13,10,26,10];function x(t){const e=function(t){const e=new Uint8Array(t.buffer,t.byteOffset,f.length);if(e[0]!==f[0]||e[1]!==f[1]||e[2]!==f[2]||e[3]!==f[3]||e[4]!==f[4]||e[5]!==f[5]||e[6]!==f[6]||e[7]!==f[7]||e[8]!==f[8]||e[9]!==f[9]||e[10]!==f[10]||e[11]!==f[11])throw new Error("Missing KTX 2.0 identifier.");const n=new p,r=17*Uint32Array.BYTES_PER_ELEMENT,i=new D(t,f.length,r,!0);n.vkFormat=i._nextUint32(),n.typeSize=i._nextUint32(),n.pixelWidth=i._nextUint32(),n.pixelHeight=i._nextUint32(),n.pixelDepth=i._nextUint32(),n.layerCount=i._nextUint32(),n.faceCount=i._nextUint32();const o=i._nextUint32();n.supercompressionScheme=i._nextUint32();const _=i._nextUint32(),a=i._nextUint32(),s=i._nextUint32(),c=i._nextUint32(),S=i._nextUint64(),u=i._nextUint64(),E=new D(t,f.length+r,3*o*8,!0);for(let e=0;e<o;e++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+E._nextUint64(),E._nextUint64()),uncompressedByteLength:E._nextUint64()});const R=new D(t,_,a,!0),l={vendorId:R._skip(4)._nextUint16(),descriptorType:R._nextUint16(),versionNumber:R._nextUint16(),descriptorBlockSize:R._nextUint16(),colorModel:R._nextUint8(),colorPrimaries:R._nextUint8(),transferFunction:R._nextUint8(),flags:R._nextUint8(),texelBlockDimension:{x:R._nextUint8()+1,y:R._nextUint8()+1,z:R._nextUint8()+1,w:R._nextUint8()+1},bytesPlane:[R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8()],samples:[]},A=(l.descriptorBlockSize/4-6)/4;for(let t=0;t<A;t++)l.samples[t]={bitOffset:R._nextUint16(),bitLength:R._nextUint8(),channelID:R._nextUint8(),samplePosition:[R._nextUint8(),R._nextUint8(),R._nextUint8(),R._nextUint8()],sampleLower:R._nextUint32(),sampleUpper:R._nextUint32()};n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(l);const C=new D(t,s,c,!0);for(;C._offset<c;){const t=C._nextUint32(),e=C._scan(t),r=M(e),i=C._scan(t-e.byteLength);n.keyValue[r]=r.match(/^ktx/i)?M(i):i,t%4&&C._skip(4-t%4)}if(u<=0)return n;const d=new D(t,S,u,!0),T=d._nextUint16(),m=d._nextUint16(),P=d._nextUint32(),h=d._nextUint32(),g=d._nextUint32(),G=d._nextUint32(),w=[];for(let t=0;t<o;t++)w.push({imageFlags:d._nextUint32(),rgbSliceByteOffset:d._nextUint32(),rgbSliceByteLength:d._nextUint32(),alphaSliceByteOffset:d._nextUint32(),alphaSliceByteLength:d._nextUint32()});const B=S+d._offset,O=B+P,x=O+h,y=x+g,H=new Uint8Array(t.buffer,t.byteOffset+B,P),b=new Uint8Array(t.buffer,t.byteOffset+O,h),U=new Uint8Array(t.buffer,t.byteOffset+x,g),L=new Uint8Array(t.buffer,t.byteOffset+y,G);return n.globalData={endpointCount:T,selectorCount:m,imageDescs:w,endpointsData:H,selectorsData:b,tablesData:U,extendedData:L},n}(new Uint8Array(t)),n=Math.max(1,e.levels.length),r=e.pixelWidth,i=e.pixelHeight,o=(_=e.vkFormat,B[_]);var _;return g(e.levels,{mipMapLevels:n,width:r,height:i,sizeFunction:t=>t.uncompressedByteLength,internalFormat:o})}function y(t,e){if(!t)throw new Error(e||"loader assertion failed.")}const H=I,b=v,U=v,L={MAGIC_NUMBER:542327876,HEADER_LENGTH:31,MAGIC_NUMBER_INDEX:0,HEADER_SIZE_INDEX:1,HEADER_FLAGS_INDEX:2,HEADER_HEIGHT_INDEX:3,HEADER_WIDTH_INDEX:4,MIPMAPCOUNT_INDEX:7,HEADER_PF_FLAGS_INDEX:20,HEADER_PF_FOURCC_INDEX:21,DDSD_MIPMAPCOUNT:131072,DDPF_FOURCC:4,PIXEL_FORMATS:{DXT1:c.COMPRESSED_RGB_S3TC_DXT1_EXT,DXT3:c.COMPRESSED_RGBA_S3TC_DXT3_EXT,DXT5:c.COMPRESSED_RGBA_S3TC_DXT5_EXT,"ATC ":c.COMPRESSED_RGB_ATC_WEBGL,ATCA:c.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,ATCI:c.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL},SIZE_FUNCTIONS:{DXT1:I,DXT3:v,DXT5:v,"ATC ":H,ATCA:b,ATCI:U}};function X(t){const e=new Int32Array(t,0,L.HEADER_LENGTH),n=e[L.HEADER_PF_FOURCC_INDEX];y(Boolean(e[L.HEADER_PF_FLAGS_INDEX]&L.DDPF_FOURCC),"DDS: Unsupported format, must contain a FourCC code");const r=(i=n,String.fromCharCode(255&i,i>>8&255,i>>16&255,i>>24&255));var i;const o=L.PIXEL_FORMATS[r],_=L.SIZE_FUNCTIONS[r];y(o&&_,"DDS: Unknown pixel format "+n);let a=1;e[L.HEADER_FLAGS_INDEX]&L.DDSD_MIPMAPCOUNT&&(a=Math.max(1,e[L.MIPMAPCOUNT_INDEX]));const s=e[L.HEADER_WIDTH_INDEX],c=e[L.HEADER_HEIGHT_INDEX],S=e[L.HEADER_SIZE_INDEX]+4;return g(new Uint8Array(t,S),{mipMapLevels:a,width:s,height:c,sizeFunction:_,internalFormat:o})}function I(t,e){return(t+3>>2)*(e+3>>2)*8}function v(t,e){return(t+3>>2)*(e+3>>2)*16}const K=55727696,N=1347834371,F=13,k=52,V=0,W=2,j=4,$=6,z=7,Z=11,q=12,Y={0:[c.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],1:[c.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],2:[c.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],3:[c.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],6:[c.COMPRESSED_RGB_ETC1_WEBGL],7:[c.COMPRESSED_RGB_S3TC_DXT1_EXT],9:[c.COMPRESSED_RGBA_S3TC_DXT3_EXT],11:[c.COMPRESSED_RGBA_S3TC_DXT5_EXT],22:[c.COMPRESSED_RGB8_ETC2],23:[c.COMPRESSED_RGBA8_ETC2_EAC],24:[c.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],25:[c.COMPRESSED_R11_EAC],26:[c.COMPRESSED_RG11_EAC],27:[c.COMPRESSED_RGBA_ASTC_4X4_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR],28:[c.COMPRESSED_RGBA_ASTC_5X4_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR],29:[c.COMPRESSED_RGBA_ASTC_5X5_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR],30:[c.COMPRESSED_RGBA_ASTC_6X5_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR],31:[c.COMPRESSED_RGBA_ASTC_6X6_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR],32:[c.COMPRESSED_RGBA_ASTC_8X5_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR],33:[c.COMPRESSED_RGBA_ASTC_8X6_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR],34:[c.COMPRESSED_RGBA_ASTC_8X8_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR],35:[c.COMPRESSED_RGBA_ASTC_10X5_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR],36:[c.COMPRESSED_RGBA_ASTC_10X6_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR],37:[c.COMPRESSED_RGBA_ASTC_10X8_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR],38:[c.COMPRESSED_RGBA_ASTC_10X10_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR],39:[c.COMPRESSED_RGBA_ASTC_12X10_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR],40:[c.COMPRESSED_RGBA_ASTC_12X12_KHR,c.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR]},J={0:Q,1:Q,2:tt,3:tt,6:et,7:et,9:nt,11:nt,22:et,23:nt,24:et,25:et,26:nt,27:nt,28:function(t,e){return Math.floor((t+4)/5)*Math.floor((e+3)/4)*16},29:function(t,e){return Math.floor((t+4)/5)*Math.floor((e+4)/5)*16},30:function(t,e){return Math.floor((t+5)/6)*Math.floor((e+4)/5)*16},31:function(t,e){return Math.floor((t+5)/6)*Math.floor((e+5)/6)*16},32:function(t,e){return Math.floor((t+7)/8)*Math.floor((e+4)/5)*16},33:function(t,e){return Math.floor((t+7)/8)*Math.floor((e+5)/6)*16},34:function(t,e){return Math.floor((t+7)/8)*Math.floor((e+7)/8)*16},35:function(t,e){return Math.floor((t+9)/10)*Math.floor((e+4)/5)*16},36:function(t,e){return Math.floor((t+9)/10)*Math.floor((e+5)/6)*16},37:function(t,e){return Math.floor((t+9)/10)*Math.floor((e+7)/8)*16},38:function(t,e){return Math.floor((t+9)/10)*Math.floor((e+9)/10)*16},39:function(t,e){return Math.floor((t+11)/12)*Math.floor((e+9)/10)*16},40:function(t,e){return Math.floor((t+11)/12)*Math.floor((e+11)/12)*16}};function Q(t,e){return(t=Math.max(t,16))*(e=Math.max(e,8))/4}function tt(t,e){return(t=Math.max(t,8))*(e=Math.max(e,8))/2}function et(t,e){return Math.floor((t+3)/4)*Math.floor((e+3)/4)*8}function nt(t,e){return Math.floor((t+3)/4)*Math.floor((e+3)/4)*16}function rt(t){if(function(t){const e=new Uint8Array(t.buffer||t,t.byteOffset||0,O.length);return!(e[0]!==O[0]||e[1]!==O[1]||e[2]!==O[2]||e[3]!==O[3]||e[4]!==O[4]||e[5]!==O[5]||e[6]!==O[6]||e[7]!==O[7]||e[8]!==O[8]||e[9]!==O[9]||e[10]!==O[10]||e[11]!==O[11])}(t))return x(t);if(function(t){return new Uint32Array(t,0,L.HEADER_LENGTH)[L.MAGIC_NUMBER_INDEX]===L.MAGIC_NUMBER}(t))return X(t);if(function(t){const e=new Uint32Array(t,0,F)[V];return e===K||e===N}(t))return function(t){const e=new Uint32Array(t,0,F),n=e[W],r=e[j],i=Y[n]||[],o=i.length>1&&r?i[1]:i[0],_=J[n],a=e[Z],s=e[z],c=e[$],S=k+e[q];return g(new Uint8Array(t,S),{mipMapLevels:a,width:s,height:c,sizeFunction:_,internalFormat:o})}(t);throw new Error("Texture container format not recognized")}const it={name:"Texture Containers",id:"compressed-texture",module:"textures",version:"3.0.17",worker:!0,extensions:["ktx","ktx2","dds","pvr"],mimeTypes:["application/octet-stream","image/vnd-ms.dds","image/ktx","image/ktx2"],binary:!0,options:{"compressed-texture":{libraryPath:"libs/"}}},ot={...it,parse:async t=>rt(t)},_t={id:"crunch",name:"Crunch",module:"textures",version:"3.0.17",worker:!0,extensions:["crn"],mimeTypes:["application/octet-stream"],binary:!0,options:{crunch:{libraryPath:"libs/"}}};const at=function(){const t=new Uint32Array([305419896]);return!(18===new Uint8Array(t.buffer,t.byteOffset,t.byteLength)[0])}(),st={u1:Uint8Array,i1:Int8Array,u2:Uint16Array,i2:Int16Array,u4:Uint32Array,i4:Int32Array,f4:Float32Array,f8:Float64Array};function ct(t,e){if(!t)return null;const n=new DataView(t),{header:r,headerEndOffset:i}=function(t){const e=t.getUint8(6);let n,r=8;e>=2?(n=t.getUint32(8,!0),r+=4):(n=t.getUint16(8,!0),r+=2);const i=new TextDecoder(e<=2?"latin1":"utf-8"),o=new Uint8Array(t.buffer,r,n),_=i.decode(o);r+=n;return{header:JSON.parse(_.replace(/'/g,'"').replace("False","false").replace("(","[").replace(/,*\),*/g,"]")),headerEndOffset:r}}(n),o=r.descr,_=st[o.slice(1,3)];if(!_)return console.warn("Decoding of npy dtype not implemented: "+o),null;const a=r.shape.reduce((t,e)=>t*e)*_.BYTES_PER_ELEMENT,s=new _(t.slice(i,i+a));return(">"===o[0]&&at||"<"===o[0]&&!at)&&console.warn("Data is wrong endianness, byte swapping not yet implemented."),{data:s,header:r}}const St={name:"NPY",id:"npy",module:"textures",version:"3.0.17",worker:!0,extensions:["npy"],mimeTypes:[],tests:[new Uint8Array([147,78,85,77,80,89]).buffer],options:{npy:{}}},ut={...St,parseSync:ct,parse:async(t,e)=>ct(t)};const Et={name:"DDS Texture Container",id:"dds",module:"textures",version:"3.0.17",extensions:["dds"],options:{texture:{format:"auto",compression:"auto",quality:"auto",mipmap:!1,flipY:!1,toolFlags:""}},encodeURLtoURL:n(8).a};function Rt(t,e){if(!t)throw new Error(e)}var ft=n(2);const{_parseImageNode:lt}=ft.a,At="undefined"!=typeof Image,Ct="undefined"!=typeof ImageBitmap,dt=Boolean(lt),Tt=!!ft.b||dt;function mt(t){const e=ht(t);if(!e)throw new Error("Not an image");return e}function Pt(t){switch(mt(t)){case"data":return t;case"image":case"imagebitmap":const e=document.createElement("canvas"),n=e.getContext("2d");if(!n)throw new Error("getImageData");return e.width=t.width,e.height=t.height,n.drawImage(t,0,0),n.getImageData(0,0,t.width,t.height);default:throw new Error("getImageData")}}function ht(t){return"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?"imagebitmap":"undefined"!=typeof Image&&t instanceof Image?"image":t&&"object"==typeof t&&t.data&&t.width&&t.height?"data":null}const pt=/^data:image\/svg\+xml/,Dt=/\.svg((\?|#).*)?$/;function Mt(t){return t&&(pt.test(t)||Dt.test(t))}function gt(t,e){if(Mt(e))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(t)])}async function Gt(t,e,n){const r=function(t,e){if(Mt(e)){const e=(new TextDecoder).decode(t);return"data:image/svg+xml;base64,"+btoa(e)}return gt(t,e)}(t,n),i=self.URL||self.webkitURL,o="string"!=typeof r&&i.createObjectURL(r);try{return await async function(t,e){const n=new Image;if(n.src=t,e.image&&e.image.decode&&n.decode)return await n.decode(),n;return await new Promise((e,r)=>{try{n.onload=()=>e(n),n.onerror=e=>r(new Error(`Could not load image ${t}: ${e}`))}catch(t){r(t)}})}(o||r,e)}finally{o&&i.revokeObjectURL(o)}}const wt={};let Bt=!0;async function Ot(t,e,n){let r;if(Mt(n)){r=await Gt(t,e,n)}else r=gt(t,n);const i=e&&e.imagebitmap;return await async function(t,e=null){!function(t){for(const e in t||wt)return!1;return!0}(e)&&Bt||(e=null);if(e)try{return await createImageBitmap(t,e)}catch(t){console.warn(t),Bt=!1}return await createImageBitmap(t)}(r,i)}function xt(t){const e=yt(t);return function(t){const e=yt(t);if(!(e.byteLength>=24&&2303741511===e.getUint32(0,!1)))return null;return{mimeType:"image/png",width:e.getUint32(16,!1),height:e.getUint32(20,!1)}}(e)||function(t){const e=yt(t);if(!(e.byteLength>=3&&65496===e.getUint16(0,!1)&&255===e.getUint8(2)))return null;const{tableMarkers:n,sofMarkers:r}=function(){const t=new Set([65499,65476,65484,65501,65534]);for(let e=65504;e<65520;++e)t.add(e);const e=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:t,sofMarkers:e}}();let i=2;for(;i+9<e.byteLength;){const t=e.getUint16(i,!1);if(r.has(t))return{mimeType:"image/jpeg",height:e.getUint16(i+5,!1),width:e.getUint16(i+7,!1)};if(!n.has(t))return null;i+=2,i+=e.getUint16(i,!1)}return null}(e)||function(t){const e=yt(t);if(!(e.byteLength>=10&&1195984440===e.getUint32(0,!1)))return null;return{mimeType:"image/gif",width:e.getUint16(6,!0),height:e.getUint16(8,!0)}}(e)||function(t){const e=yt(t);if(!(e.byteLength>=14&&16973===e.getUint16(0,!1)&&e.getUint32(2,!0)===e.byteLength))return null;return{mimeType:"image/bmp",width:e.getUint32(18,!0),height:e.getUint32(22,!0)}}(e)}function yt(t){if(t instanceof DataView)return t;if(ArrayBuffer.isView(t))return new DataView(t.buffer);if(t instanceof ArrayBuffer)return new DataView(t);throw new Error("toDataView")}const Ht={id:"image",module:"images",name:"Images",version:"3.0.17",mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],extensions:["png","jpg","jpeg","gif","webp","bmp","ico","svg"],parse:async function(t,e,n){const r=((e=e||{}).image||{}).type||"auto",{url:i}=n||{};let o;switch(function(t){switch(t){case"auto":case"data":return function(){if(Ct)return"imagebitmap";if(At)return"image";if(Tt)return"data";throw new Error("Install '@kibeo/loaders.gl-polyfills' to parse images under Node.js")}();default:return function(t){switch(t){case"auto":return Ct||At||Tt;case"imagebitmap":return Ct;case"image":return At;case"data":return Tt;default:throw new Error(`@kibeo/loaders.gl-images: image ${t} not supported in this environment`)}}(t),t}}(r)){case"imagebitmap":o=await Ot(t,e,i);break;case"image":o=await Gt(t,e,i);break;case"data":o=await function(t,e){const{mimeType:n}=xt(t)||{},{_parseImageNode:r}=ft.a;return Rt(r),r(t,n,e)}(t,e);break;default:Rt(!1)}return"data"===r&&(o=Pt(o)),o},tests:[t=>Boolean(xt(new DataView(t)))],options:{image:{type:"auto",decode:!0}}};let bt="";const Ut={};function Lt(t,e,n){let r=t;"function"==typeof t&&(r=t({...e,...n})),y("string"==typeof r);const{baseUrl:i}=e;return i&&(r="/"===i[i.length-1]?`${i}${r}`:`${i}/${r}`),function(t){for(const e in Ut)if(t.startsWith(e)){const n=Ut[e];t=t.replace(e,n)}return t.startsWith("http://")||t.startsWith("https://")||(t=`${bt}${t}`),t}(r)}async function Xt(t,e,n){if(Array.isArray(t))return await async function(t,e,n={}){const r=t.map(t=>Xt(t,e,n));return await Promise.all(r)}(t,e,n);if((r=t)&&"object"==typeof r)return await async function(t,e,n){const r=[],i={};for(const o in t){const _=Xt(t[o],e,n).then(t=>{i[o]=t});r.push(_)}return await Promise.all(r),i}(t,e,n);var r;const i=t;return await e(i,n)}async function It(t,e,n){return await async function(t,e,n={}){return await Xt(t,e,n)}(t,t=>vt(t,e,n))}async function vt(t,e,n){const r=await fetch(t,n.fetch),i=await r.arrayBuffer();return await e(i,n)}async function Kt(t,e={}){const n=await Nt(t,e);return await It(n,Ht.parse,e)}async function Nt(t,e,n={}){const r=e&&e.image&&e.image.mipLevels||0;return 0!==r?await async function(t,e,n,r){const i=[];if("auto"===e){const o=Lt(t,n,{...r,lod:0}),_=await vt(o,Ht.parse,n),{width:a,height:s}=function(t){return Pt(t)}(_);e=function({width:t,height:e}){return 1+Math.floor(Math.log2(Math.max(t,e)))}({width:a,height:s}),i.push(o)}y(e>0);for(let o=i.length;o<e;++o){const e=Lt(t,n,{...r,lod:o});i.push(e)}return i}(t,r,e,n):Lt(t,e,n)}async function Ft(t,e,n={}){const r=await async function(t,e,n={}){const r=[];for(let i=0;i<t;i++){const t=Nt(e,n,{index:i});r.push(t)}return await Promise.all(r)}(t,e,n);return await It(r,Ht.parse,n)}const kt=[{face:34069,direction:"right",axis:"x",sign:"positive"},{face:34070,direction:"left",axis:"x",sign:"negative"},{face:34071,direction:"top",axis:"y",sign:"positive"},{face:34072,direction:"bottom",axis:"y",sign:"negative"},{face:34073,direction:"front",axis:"z",sign:"positive"},{face:34074,direction:"back",axis:"z",sign:"negative"}];async function Vt(t,e={}){const n=await async function(t,e){const n={},r=[];let i=0;for(let o=0;o<kt.length;++o){const o=kt[i],_=Nt(t,e,{...o,index:i++}).then(t=>{n[o.face]=t});r.push(_)}return await Promise.all(r),n}(t,e);return await It(n,Ht.parse,e)}const Wt=["","WEBKIT_","MOZ_"],jt={WEBGL_compressed_texture_s3tc:"dxt",WEBGL_compressed_texture_s3tc_srgb:"dxt-srgb",WEBGL_compressed_texture_etc1:"etc1",WEBGL_compressed_texture_etc:"etc2",WEBGL_compressed_texture_pvrtc:"pvrtc",WEBGL_compressed_texture_atc:"atc",WEBGL_compressed_texture_astc:"astc",EXT_texture_compression_rgtc:"rgtc"};let $t=null;function zt(t){if(!$t){t=t||function(){try{return document.createElement("canvas").getContext("webgl")}catch(t){return null}}()||void 0,$t=new Set;for(const e of Wt)for(const n in jt)if(t&&t.getExtension(`${e}${n}`)){const t=jt[n];$t.add(t)}}return $t}},function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return s}));var r=n(1),i=n.n(r),o=n(9);function _(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}const a={command:"",arguments:[],port:5e3,autoPort:!0,wait:2e3,onSuccess:t=>{console.log("Started "+t.props.command)}};class s{constructor({id:t="browser-driver"}={}){_(this,"id",void 0),_(this,"props",{...a}),_(this,"childProcess",null),_(this,"port",0),_(this,"successTimer",void 0),this.id=t}async start(t){t={...a,...t},this.props=t;const e=[...t.arguments];return this.port=Number(t.port),t.portArg&&(t.autoPort&&(this.port=await Object(o.a)(t.port)),e.push(t.portArg,String(this.port))),await new Promise((n,r)=>{try{var o;this._setTimeout(()=>{t.onSuccess&&t.onSuccess(this),n({})}),console.log(`Spawning ${t.command} ${t.arguments.join(" ")}`);const _=null===i.a||void 0===i.a||null===(o=i.a.spawn)||void 0===o?void 0:o.call(i.a,t.command,e,t.spawn);this.childProcess=_,_.stdout.on("data",t=>{console.log(t.toString())}),_.stderr.on("data",t=>{console.log(`Child process wrote to stderr: "${t}".`),this._clearTimeout(),r(new Error(t))}),_.on("error",t=>{console.log("Child process errored with "+t),this._clearTimeout(),r(t)}),_.on("close",t=>{console.log("Child process exited with "+t),this.childProcess=null,this._clearTimeout(),n({})})}catch(t){r(t)}})}async stop(){this.childProcess&&(this.childProcess.kill(),this.childProcess=null)}async exit(e=0){try{await this.stop(),t.exit(e)}catch(e){console.error(e.message||e),t.exit(1)}}_setTimeout(t){Number(this.props.wait)>0&&(this.successTimer=setTimeout(t,this.props.wait))}_clearTimeout(){this.successTimer&&clearTimeout(this.successTimer)}}}).call(this,n(5))}])})); //# sourceMappingURL=dist.min.js.map