@loaders.gl/core
Advanced tools
Comparing version 1.2.2 to 1.3.0-beta.1
@@ -1,1 +0,1 @@ | ||
!function(e,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t=n();for(var r in t)("object"==typeof exports?exports:e)[r]=t[r]}}(window,function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=5)}([function(e,n,t){"use strict";(function(e,r){t.d(n,"c",function(){return o}),t.d(n,"e",function(){return u}),t.d(n,"f",function(){return c}),t.d(n,"b",function(){return a}),t.d(n,"a",function(){return s}),t.d(n,"d",function(){return l});const o="object"!=typeof e||"[object process]"!==String(e)||e.browser,i={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==r&&r,document:"undefined"!=typeof document&&document},u=i.self||i.window||i.global,c=i.window||i.self||i.global,a=i.global||i.self||i.window,s=i.document||{},f=void 0!==e&&e.version&&e.version.match(/v([0-9]*)/),l=f&&parseFloat(f[1])||0}).call(this,t(6),t(4))},function(e,n){},function(e,n){},function(e,n){},function(e,n){var t;t=function(){return this}();try{t=t||new Function("return this")()}catch(e){"object"==typeof window&&(t=window)}e.exports=t},function(e,n,t){(function(n){const r=t(7),o="undefined"==typeof window?n:window;o.loaders=o.loaders||{},e.exports=Object.assign(o.loaders,r)}).call(this,t(4))},function(e,n){var t,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function c(e){if(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i}catch(e){t=i}try{r="function"==typeof clearTimeout?clearTimeout:u}catch(e){r=u}}();var a,s=[],f=!1,l=-1;function d(){f&&a&&(f=!1,a.length?s=a.concat(s):l=-1,s.length&&y())}function y(){if(!f){var e=c(d);f=!0;for(var n=s.length;n;){for(a=s,s=[];++l<n;)a&&a[l].run();l=-1,n=s.length}a=null,f=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===u||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(n){try{return r.call(null,e)}catch(n){return r.call(this,e)}}}(e)}}function p(e,n){this.fun=e,this.array=n}function w(){}o.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)n[t-1]=arguments[t];s.push(new p(e,n)),1!==s.length||f||c(y)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=w,o.addListener=w,o.once=w,o.off=w,o.removeListener=w,o.removeAllListeners=w,o.emit=w,o.prependListener=w,o.prependOnceListener=w,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,n,t){"use strict";t.r(n);var r={};function o(e,n){if(!e)throw new Error(n||"loader assertion failed.")}function i(e){if(!e)return!1;return Array.isArray(e)&&(e=e[0]),e.parseTextSync||e.parseSync||e.parse||e.loadAndParse||e.parseStream||e.parseInBatches||e.worker}function u(e){let n;return o(i(e)),Array.isArray(e)&&(n=e[1],e=e[0],e={...e,options:{...e.options,...n}}),e.extension&&(e.extensions=e.extensions||e.extension,delete e.extension),Array.isArray(e.extensions)||(e.extensions=[e.extensions]),o(e.extensions&&e.extensions.length>0&&e.extensions[0]),e.parseTextSync&&(e.text=!0),e.text||(e.binary=!0),e}t.r(r),t.d(r,"dirname",function(){return te});const c=/[^.]+$/;function a(e,n,{url:t=""}={}){t=t.replace(/\?.*/,"");let r=null;return r=(r=r||function(e,n){const t=n.match(c),r=t&&t[0];return r&&function(e,n){n=n.toLowerCase();for(const t of e){u(t);for(const e of t.extensions)if(e.toLowerCase()===n)return t}return null}(e,r)}(n,t))||function(e,n){for(const t of e)if("string"==typeof n){if(s(n,t))return t}else if(n instanceof ArrayBuffer&&f(n,t))return t;return null}(n,e)}function s(e,n){return n.testText&&n.testText(e)}function f(e,n){switch(Array.isArray(n.test)?"array":typeof n.test){case"function":return n.test(e,n);case"string":case"array":const t=0;return(Array.isArray(n.test)?n.test:[n.test]).some(n=>{return n===function(e,n,t){if(e.byteLength<=n+t)return"";const r=new DataView(e);let o="";for(let e=0;e<t;e++)o+=String.fromCharCode(r.getUint8(n+e));return o}(e,t,n.length)});default:return!1}}class l{log(){}info(){}warn(){}error(){}}function d(e,n){return null===(e=Object.assign({},n&&n.DEFAULT_OPTIONS,n&&n.defaultOptions,n&&n.options,e,{dataType:"arraybuffer"})).log&&(e.log=new l),"log"in e||(e.log=console),e}const y=e=>"boolean"==typeof e,p=e=>"function"==typeof e,w=e=>null!==e&&"object"==typeof e,h=e=>w(e)&&p(e.then),b=e=>e&&"function"==typeof e[Symbol.iterator],g=e=>e&&"function"==typeof e[Symbol.asyncIterator],m=e=>e&&p(e.next),A=e=>"undefined"!=typeof Response&&e instanceof Response||e.arrayBuffer&&e.text&&e.json,x=e=>(e=>"undefined"!=typeof File&&e instanceof File)(e)||(e=>"undefined"!=typeof Blob&&e instanceof Blob)(e),S=e=>(e=>w(e)&&p(e.tee)&&p(e.cancel)&&p(e.pipeTo)&&p(e.getReader))(e)||(e=>w(e)&&p(e.read)&&p(e.pipe)&&y(e.readable))(e),T=e=>(e=>w(e)&&p(e.abort)&&p(e.getWriter))(e)||(e=>w(e)&&p(e.end)&&p(e.write)&&y(e.writable))(e);var v=t(0);function B(e){if(v.c||v.d>=10){if("function"==typeof e[Symbol.asyncIterator])return e;if("function"==typeof e.getIterator)return e.getIterator()}return v.c?async function*(e){const n=e.getReader();try{for(;;){const{done:e,value:t}=await n.read();if(e)return;yield t}}finally{n.releaseLock()}}(e):async function*(e){e=await e;for(;;){const n=e.read();if(null===n){if(e._readableState.ended)return;await F(e)}else yield n}}(e)}async function F(e){return new Promise(n=>{e.once("readable",n)})}class O{constructor(e){this._fileOrBlob=e,this.bodyUsed=!1}get headers(){return new Headers({"Content-Length":this._fileOrBlob.size,"Content-Type":this._fileOrBlob.type})}get ok(){return!0}get status(){return 200}url(){return this._fileOrBlob.name||""}async arrayBuffer(){const{reader:e,promise:n}=this._getFileReader();return e.readAsArrayBuffer(this._fileOrBlob),n}async text(){const{reader:e,promise:n}=this._getFileReader();return e.readAsText(this._fileOrBlob),n}async json(){const e=await this.text();return JSON.parse(e)}_getFileReader(){let e;o(!this.bodyUsed),this.bodyUsed=!0;const n=new Promise((n,t)=>{try{(e=new FileReader).onerror=e=>t(new Error(e)),e.onabort=()=>t(new Error("Read aborted.")),e.onload=()=>n(e.result)}catch(e){t(e)}});return{reader:e,promise:n}}}function j(e,n){return Promise.resolve(new O(e,n))}const I="Cannot convert supplied data type";function E(e,n){if(n.text&&"string"==typeof e)return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)){const t=e.buffer||e;if(n.text&&!n.binary){return new TextDecoder("utf8").decode(t)}return t}throw new Error(I)}async function P(e,n){const t=(e=await e)instanceof ArrayBuffer||ArrayBuffer.isView(e);if("string"==typeof e||t)return E(e,n);if(x(e)&&(e=await j(e)),A(e))return await async function(e){if(!e.ok){let n=`fetch failed ${e.status} `;try{n+=await e.text()}catch(e){}throw new Error(n)}}(e),n.binary?await e.arrayBuffer():await e.text();throw new Error(I)}function L(e){return m(e)?e:A(e)&&e.body?(function(e){if(!e.ok)throw new Error(`fetch failed ${e.status}`)}(e),B(e.body)):S(e)?B(e):g(e)?e[Symbol.asyncIterator]():_(e)}function _(e){if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return function*(){yield e.buffer||e}();if(m(e))return e;if(b(e))return e[Symbol.iterator]();throw new Error(I)}const R={};function k(e){e=Array.isArray(e)?e:[e];for(const n of e){const e=u(n);for(const n of e.extensions)R[n]=e}}function U(){return Object.values(R)}var $=t(3);function C(e){if($.toArrayBuffer&&(e=Object($.toArrayBuffer)(e)),e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return e.buffer;if("string"==typeof e){const n=e;return(new TextEncoder).encode(n).buffer}return o(!1)}const M=new Map,W={};function D(e){const n=e?e.toLowerCase():"unnamed";return W[n]=W[n]||0,`loaders.gl-${n}-worker-${W[n]++}`}function V(e,n,t,r){const o=function(e,n){let t=M.get(e);if(!t){const n=new Blob([e],{type:"application/javascript"});t=URL.createObjectURL(n),M.set(e,t)}return new Worker(t,{name:D(n)})}(e,n);r=function(e){null!==(e=Object.assign({},e)).log&&delete e.log;return e}(r);const i=(e,n)=>new Promise((t,r)=>{o.onmessage=e=>{switch(e.data.type){case"done":t(e.data.result),o.terminate();break;case"error":r(new Error(e.data.message))}};const i=C(e);o.postMessage({arraybuffer:i,opts:n},[i])});return t?i(t,r):i}function N(e,n,t,r){if(n.parseInBatches){const o=L(e);return n.parseInBatches(o,t,r,n)}return null}async function z(e,n,t,r){Array.isArray(n)||i(n)||(r=t,t=n,n=null);const c=function(e,n){return A(e)?n=n||e.url:x(n)&&(n=n.name),"string"==typeof n?n.replace(/\?.*/,""):n}(e,r);n=n||U();const s=Array.isArray(n)?a(e,n,{url:c}):n;return s?(u(s),t=d(t,s),await async function(e,n,t,r){return e=await P(e,n),n.parseTextSync&&"string"==typeof e?(t.dataType="text",n.parseTextSync(e,t,r,n)):n.parse?await n.parse(e,t,r,n):n.parseSync?n.parseSync(e,t,r,n):n.worker?V(n.worker,n.name,e,t):o(!1)}(e,s,t,c)):null}function H(e,n,t,r){Array.isArray(n)||i(n)||(r=t,t=n,n=null),n=n||U();const c=Array.isArray(n)?a(e,n,{url:r}):n;return u(c),function(e,n,t,r){return e=E(e,n),n.parseTextSync&&"string"==typeof e?n.parseTextSync(e,t,r,n):n.parseSync?n.parseSync(e,t,r,n):o(!1)}(e,c,t=d(t,c),r)}async function J(e,n,t,r){Array.isArray(n)||i(n)||(r=t,t=n,n=null),n=n||U();const o=Array.isArray(n)?a(null,n,{url:r}):n;return u(o),N(e,o,t=d(t,o),r)}async function q(e,n,t,r){Array.isArray(n)||i(n)||(r=t,t=n,n=null),n=n||U();const o=Array.isArray(n)?a(null,n,{url:r}):n;return u(o),N(e,o,t=d(t,o),r)}let G="";const K={};function Q(e){G=e}function X(){return G}function Y(e){for(const n in K)if(e.startsWith(n)){const t=K[n];return e.replace(n,t)}return e+=G}async function Z(e,n){return x(e)?j(e,n):(e=Y(e),fetch(e,n))}async function ee(e,n,t){return J(await Z(e,t),n,t,e)}async function ne(e,n,t){Array.isArray(n)||i(n)||(t=n,n=null);const r=x(e)?e.name:e;n=n||U();const o=Array.isArray(n)?a(null,n,{url:r}):n;if(t=d(t,o),o&&o.loadAndParse)return await o.loadAndParse(e,t);let u=e;return(x(u)||"string"==typeof u)&&(u=await Z(e,t)),z(u,n,t,r)}function te(e){const n=e&&e.lastIndexOf("/");return n>=0?e.substr(0,n):""}var re=t(2);const oe={dataType:"arraybuffer",nothrow:!0},ie=e=>e.startsWith("data:");function ue(e,n){return n=function(e={}){return(e=Object.assign({},oe,e)).responseType=e.responseType||e.dataType,e}(n),ie(e),n.nothrow||o(!1),null}function ce(e,n={}){return e=Y(e),!v.c&&re.readFileSync?re.readFileSync(e,n):ue(e,n)}var ae=t(1);function se(e,n,t){return e=Y(e),!v.c&&ae.writeFile?ae.writeFile(e,n,t):o(!1)}function fe(e,n,t){return e=Y(e),!v.c&&ae.writeFileSync?ae.writeFileSync(e,n,t):o(!1)}function le(e){return`Failed to fetch resource ${e.url}(${e.status}): ${e.statusText} `}async function de(e){let n=`Failed to fetch resource ${e.url} (${e.status}): `;try{e.headers.get("Content-Type").includes("application/json")?n+=await e.text():n+=e.statusText}catch(e){return n}return n}function ye(e,n,t,r){if(n.encode)return n.encode(e,t);if(n.encodeSync)return Promise.resolve(n.encodeSync(e,t));throw new Error("Writer could not encode data")}function pe(e,n,t,r){if(n.encodeSync)return n.encodeSync(e,t);throw new Error("Writer could not synchronously encode data")}function we(e,n,t,r){if(n.encodeInBatches)return n.encodeInBatches(e,t);throw new Error("Writer could not encode data in batches")}function he(e,n,t,r){return se(n,ye(e,t,r))}function be(e,n,t,r){return fe(n,pe(e,t,r))}function ge(e,n){const t=e instanceof ArrayBuffer?new Uint8Array(e):e,r=n instanceof ArrayBuffer?new Uint8Array(n):n,o=new Uint8Array(t.byteLength+r.byteLength);return o.set(t,0),o.set(r,t.byteLength),o}async function me(e,n){for(;;){const{done:t,value:r}=await e.next();if(t)return void e.return();if(n(r))return}}async function Ae(e){let n=new ArrayBuffer,t="";for await(const r of e)"string"==typeof r?t+=r:n=ge(n,r);return t||n}async function*xe(e,n){const t=new TextDecoder(n);for await(const n of e)yield"string"==typeof n?n:t.decode(n,{stream:!0})}async function*Se(e){let n="";for await(const t of e){let e;for(n+=t;(e=n.indexOf("\n"))>=0;){const t=n.slice(0,e+1);n=n.slice(e+1),yield t}}n.length>0&&(yield n)}async function*Te(e){let n=1;for await(const t of e)yield{counter:n,line:t},n++}t.d(n,"TextEncoder",function(){return ve}),t.d(n,"TextDecoder",function(){return Be}),t.d(n,"createReadStream",function(){return Fe}),t.d(n,"parseFile",function(){return Oe}),t.d(n,"parseFileSync",function(){return je}),t.d(n,"loadFile",function(){return Ie}),t.d(n,"path",function(){return r}),t.d(n,"setPathPrefix",function(){return Q}),t.d(n,"getPathPrefix",function(){return X}),t.d(n,"resolvePath",function(){return Y}),t.d(n,"fetchFile",function(){return Z}),t.d(n,"readFileSync",function(){return ce}),t.d(n,"writeFile",function(){return se}),t.d(n,"writeFileSync",function(){return fe}),t.d(n,"_getErrorMessageFromResponseSync",function(){return le}),t.d(n,"_getErrorMessageFromResponse",function(){return de}),t.d(n,"registerLoaders",function(){return k}),t.d(n,"parse",function(){return z}),t.d(n,"parseSync",function(){return H}),t.d(n,"parseInBatches",function(){return J}),t.d(n,"parseInBatchesSync",function(){return q}),t.d(n,"load",function(){return ne}),t.d(n,"loadInBatches",function(){return ee}),t.d(n,"encode",function(){return ye}),t.d(n,"encodeSync",function(){return pe}),t.d(n,"encodeInBatches",function(){return we}),t.d(n,"save",function(){return he}),t.d(n,"saveSync",function(){return be}),t.d(n,"isPromise",function(){return h}),t.d(n,"isIterable",function(){return b}),t.d(n,"isAsyncIterable",function(){return g}),t.d(n,"isIterator",function(){return m}),t.d(n,"isFetchResponse",function(){return A}),t.d(n,"isReadableStream",function(){return S}),t.d(n,"isWritableStream",function(){return T}),t.d(n,"toArrayBuffer",function(){return C}),t.d(n,"getStreamIterator",function(){return B}),t.d(n,"forEach",function(){return me}),t.d(n,"concatenateAsyncIterator",function(){return Ae}),t.d(n,"lineAsyncIterator",function(){return Se}),t.d(n,"textDecoderAsyncIterator",function(){return xe}),t.d(n,"numberedLineAsyncIterator",function(){return Te}),t.d(n,"isBrowser",function(){return v.c}),t.d(n,"self",function(){return v.e}),t.d(n,"window",function(){return v.f}),t.d(n,"global",function(){return v.b}),t.d(n,"document",function(){return v.a}),t.d(n,"assert",function(){return o});const ve=v.b.TextEncoder,Be=v.b.TextDecoder;async function Fe(e,n){return console.warn("createReadStream() deprecated, use fetch().then(resp => resp.body)"),e=Y(e),(await Z(e,n)).body}function Oe(...e){return console.warn("parse() deprecated, use parse()"),z(...e)}function je(...e){return console.warn("parseSync() deprecated, use parseSync()"),H(...e)}function Ie(...e){return console.warn("loadFile() deprecated, use load()"),ne(...e)}}])}); | ||
!function(e,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var r=n();for(var t in r)("object"==typeof exports?exports:e)[t]=r[t]}}(window,function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)r.d(t,o,function(n){return e[n]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=5)}([function(e,n,r){"use strict";(function(e,t){r.d(n,"c",function(){return o}),r.d(n,"e",function(){return u}),r.d(n,"f",function(){return s}),r.d(n,"b",function(){return c}),r.d(n,"a",function(){return a}),r.d(n,"d",function(){return l});const o="object"!=typeof e||"[object process]"!==String(e)||e.browser,i={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==t&&t,document:"undefined"!=typeof document&&document},u=i.self||i.window||i.global,s=i.window||i.self||i.global,c=i.global||i.self||i.window,a=i.document||{},f=void 0!==e&&e.version&&e.version.match(/v([0-9]*)/),l=f&&parseFloat(f[1])||0}).call(this,r(6),r(4))},function(e,n){},function(e,n){},function(e,n){},function(e,n){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,n,r){(function(n){const t=r(7),o="undefined"==typeof window?n:window;o.loaders=o.loaders||{},e.exports=Object.assign(o.loaders,t)}).call(this,r(4))},function(e,n){var r,t,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function s(e){if(r===setTimeout)return setTimeout(e,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(n){try{return r.call(null,e,0)}catch(n){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{t="function"==typeof clearTimeout?clearTimeout:u}catch(e){t=u}}();var c,a=[],f=!1,l=-1;function d(){f&&c&&(f=!1,c.length?a=c.concat(a):l=-1,a.length&&y())}function y(){if(!f){var e=s(d);f=!0;for(var n=a.length;n;){for(c=a,a=[];++l<n;)c&&c[l].run();l=-1,n=a.length}c=null,f=!1,function(e){if(t===clearTimeout)return clearTimeout(e);if((t===u||!t)&&clearTimeout)return t=clearTimeout,clearTimeout(e);try{t(e)}catch(n){try{return t.call(null,e)}catch(n){return t.call(this,e)}}}(e)}}function h(e,n){this.fun=e,this.array=n}function p(){}o.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)n[r-1]=arguments[r];a.push(new h(e,n)),1!==a.length||f||s(y)},h.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=p,o.addListener=p,o.once=p,o.off=p,o.removeListener=p,o.removeAllListeners=p,o.emit=p,o.prependListener=p,o.prependOnceListener=p,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,n,r){"use strict";r.r(n);var t={};function o(e,n){if(!e)throw new Error(n||"loader assertion failed.")}function i(e){if(!e)return!1;return Array.isArray(e)&&(e=e[0]),e.parseTextSync||e.parseSync||e.parse||e.loadAndParse||e.parseStream||e.parseInBatches||e.worker}function u(e){let n;return o(i(e)),Array.isArray(e)&&(n=e[1],e=e[0],e={...e,options:{...e.options,...n}}),e.extension&&(e.extensions=e.extensions||e.extension,delete e.extension),Array.isArray(e.extensions)||(e.extensions=[e.extensions]),o(e.extensions&&e.extensions.length>0&&e.extensions[0]),e.parseTextSync&&(e.text=!0),e.text||(e.binary=!0),e}r.r(t),r.d(t,"dirname",function(){return ue});let s={};function c(e){e=Array.isArray(e)?e:[e];for(const n of e){const e=u(n);for(const n of e.extensions)s[n]=e}}function a(){s={}}const f=/[^.]+$/;function l(e,n="",r=null,{nothrow:t=!1}={}){if(n=n||"",e&&!Array.isArray(e)){const n=e;return u(n),n}(function(e){for(const n of e)u(n)})(e=e||Object.values(s)),n=n.replace(/\?.*/,"");let o=null;if(!(o=(o=o||function(e,n){const r=n.match(f),t=r&&r[0];return t&&function(e,n){n=n.toLowerCase();for(const r of e)for(const e of r.extensions)if(e.toLowerCase()===n)return r;return null}(e,t)}(e,n))||function(e,n){if(!n)return null;for(const r of e)if("string"==typeof n){if(d(n,r))return r}else if(n instanceof ArrayBuffer&&y(n,r))return r;return null}(e,r))){if(t)return null;throw new Error(`No valid loader found for ${n}`)}return o}function d(e,n){return n.testText&&n.testText(e)}function y(e,n){switch(Array.isArray(n.test)?"array":typeof n.test){case"function":return n.test(e,n);case"string":case"array":const r=0;return(Array.isArray(n.test)?n.test:[n.test]).some(n=>{return n===function(e,n,r){if(e.byteLength<=n+r)return"";const t=new DataView(e);let o="";for(let e=0;e<r;e++)o+=String.fromCharCode(t.getUint8(n+e));return o}(e,r,n.length)});default:return!1}}class h{log(){}info(){}warn(){}error(){}}function p(e,n){return null===(e=Object.assign({},n&&n.DEFAULT_OPTIONS,n&&n.defaultOptions,n&&n.options,e,{dataType:"arraybuffer"})).log&&(e.log=new h),"log"in e||(e.log=console),e}const w=e=>"boolean"==typeof e,b=e=>"function"==typeof e,g=e=>null!==e&&"object"==typeof e,m=e=>g(e)&&b(e.then),x=e=>e&&"function"==typeof e[Symbol.iterator],A=e=>e&&"function"==typeof e[Symbol.asyncIterator],S=e=>e&&b(e.next),v=e=>"undefined"!=typeof Response&&e instanceof Response||e.arrayBuffer&&e.text&&e.json,T=e=>(e=>"undefined"!=typeof File&&e instanceof File)(e)||(e=>"undefined"!=typeof Blob&&e instanceof Blob)(e),B=e=>(e=>g(e)&&b(e.tee)&&b(e.cancel)&&b(e.pipeTo)&&b(e.getReader))(e)||(e=>g(e)&&b(e.read)&&b(e.pipe)&&w(e.readable))(e),j=e=>(e=>g(e)&&b(e.abort)&&b(e.getWriter))(e)||(e=>g(e)&&b(e.end)&&b(e.write)&&w(e.writable))(e);var k=r(0);function _(e){if(k.c||k.d>=10){if("function"==typeof e[Symbol.asyncIterator])return e;if("function"==typeof e.getIterator)return e.getIterator()}return k.c?async function*(e){const n=e.getReader();try{for(;;){const{done:e,value:r}=await n.read();if(e)return;yield r}}catch(e){n.releaseLock()}}(e):async function*(e){e=await e;for(;;){const n=e.read();if(null===n){if(e._readableState.ended)return;await P(e)}else yield n}}(e)}async function P(e){return new Promise(n=>{e.once("readable",n)})}class F{constructor(e){this._fileOrBlob=e,this.bodyUsed=!1}get headers(){return new Headers({"Content-Length":this._fileOrBlob.size,"Content-Type":this._fileOrBlob.type})}get ok(){return!0}get status(){return 200}url(){return this._fileOrBlob.name||""}async arrayBuffer(){const{reader:e,promise:n}=this._getFileReader();return e.readAsArrayBuffer(this._fileOrBlob),n}async text(){const{reader:e,promise:n}=this._getFileReader();return e.readAsText(this._fileOrBlob),n}async json(){const e=await this.text();return JSON.parse(e)}_getFileReader(){let e;o(!this.bodyUsed),this.bodyUsed=!0;const n=new Promise((n,r)=>{try{(e=new FileReader).onerror=e=>r(new Error(e)),e.onabort=()=>r(new Error("Read aborted.")),e.onload=()=>n(e.result)}catch(e){r(e)}});return{reader:e,promise:n}}}function O(e,n){return Promise.resolve(new F(e,n))}const E="Cannot convert supplied data type";function D(e,n){if(n.text&&"string"==typeof e)return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)){const r=e.buffer||e;if(n.text&&!n.binary){return new TextDecoder("utf8").decode(r)}return r}throw new Error(E)}async function I(e,n){const r=(e=await e)instanceof ArrayBuffer||ArrayBuffer.isView(e);if("string"==typeof e||r)return D(e,n);if(T(e)&&(e=await O(e)),v(e))return await async function(e){if(!e.ok){let n=`fetch failed ${e.status} `;try{n+=await e.text()}catch(e){}throw new Error(n)}}(e),n.binary?await e.arrayBuffer():await e.text();throw new Error(E)}function C(e){return S(e)?e:v(e)&&e.body?(function(e){if(!e.ok)throw new Error(`fetch failed ${e.status}`)}(e),_(e.body)):B(e)?_(e):A(e)?e[Symbol.asyncIterator]():L(e)}function L(e){if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return function*(){yield e.buffer||e}();if(S(e))return e;if(x(e))return e[Symbol.iterator]();throw new Error(E)}var R=r(3);function W(e){if(R.toArrayBuffer&&(e=Object(R.toArrayBuffer)(e)),e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return e.buffer;if("string"==typeof e){const n=e;return(new TextEncoder).encode(n).buffer}return o(!1)}const $=new Map;let Q=0;class U{constructor(e,n=`web-worker-${Q++}`){const r=function(e){let n=$.get(e);if(!n){const r=new Blob([e],{type:"application/javascript"});n=URL.createObjectURL(r),$.set(e,n)}return n}(e);this.worker=new Worker(r,{name:n}),this.name=n}async process(e){return new Promise((n,r)=>{this.worker.onmessage=e=>n(e.data),this.worker.onerror=e=>r(e);const t=function e(n,r=!0,t=[]){if(n){if(n instanceof ArrayBuffer)t.push(n);else if(n.buffer&&n.buffer instanceof ArrayBuffer)t.push(n.buffer);else if(r&&"object"==typeof n)for(const r in n)e(n[r],!1,t)}else;return t}(e);this.worker.postMessage(e,t)})}destroy(){this.worker.terminate(),this.worker=null}}class M{constructor({source:e,name:n="unnamed",maxConcurrency:r=1,onDebug:t=(()=>{})}){this.source=e,this.name=n,this.maxConcurrency=r,this.onDebug=t,this.jobQueue=[],this.idleQueue=[],this.count=0,this.isDestroyed=!1}destroy(){this.idleQueue.forEach(e=>e.destroy()),this.isDestroyed=!0}async process(e,n){return new Promise((r,t)=>{this.jobQueue.push({data:e,jobName:n,resolve:r,reject:t}),this._startQueuedJob()})}_startQueuedJob(){if(!this.jobQueue.length)return;const e=this._getAvailableWorker();if(!e)return;const n=this.jobQueue.shift();this.onDebug({message:"processing",worker:e.name,job:n.jobName,backlog:this.jobQueue.length}),e.process(n.data).then(e=>n.resolve(e)).catch(e=>n.reject(e)).then(()=>this._onWorkerDone(e))}_onWorkerDone(e){this.isDestroyed?e.destroy():(this.idleQueue.push(e),this._startQueuedJob())}_getAvailableWorker(){if(this.idleQueue.length>0)return this.idleQueue.shift();if(this.count<this.maxConcurrency){this.count++;const e=`${this.name.toLowerCase()}-worker-${this.count}-of-${this.maxConcurrency}`;return new U(this.source,e)}return null}}const N=5;class V{constructor({maxConcurrency:e=N,onDebug:n=(()=>{})}){this.maxConcurrency=e,this.onDebug=n,this.workerPools=new Map}setProps(e){"maxConcurrency"in e&&(this.maxConcurrency=e.maxConcurrency),"onDebug"in e&&(this.onDebug=e.onDebug)}destroy(){this.workerPools.forEach(e=>e.destroy())}async process(e,n,r){return this._getWorkerPool(e,n).process(r)}_getWorkerPool(e,n){let r=this.workerPools.get(n);return r||(r=new M({source:e,name:n,maxConcurrency:this.maxConcurrency,onDebug:this.onDebug}),this.workerPools.set(n,r)),r}}let J=null;async function z(e,n,r,t){const o=function(e={}){const n={};return e.maxConcurrency&&(n.maxConcurrency=e.maxConcurrency),e.onDebug&&(n.onDebug=e.onDebug),(J=J||new V({})).setProps(n),J}(t);t=function(e){return null!==(e=Object.assign({},e)).log&&delete e.log,e}(t);const i=await o.process(e,`loaders.gl-${n}`,{arraybuffer:W(r),options:t,source:"loaders.gl",type:"process"});switch(i.type){case"done":return i.result;case"error":throw new Error(i.message);default:return i}}function H(e,n,r,t){if(n.parseInBatches){const o=C(e);return n.parseInBatches(o,r,t,n)}return null}async function q(e,n,r,t){!n||Array.isArray(n)||i(n)||(t=r,r=n,n=null),r=r||{};const u=function(e,n){return v(e)?n=n||e.url:T(n)&&(n=n.name),"string"==typeof n?n.replace(/\?.*/,""):n}(e,t),s=l(n,u,e);return r=p(r,s),await async function(e,n,r,t){return e=await I(e,n),n.parseTextSync&&"string"==typeof e?(r.dataType="text",n.parseTextSync(e,r,t,n)):n.parse?await n.parse(e,r,t,n):n.parseSync?n.parseSync(e,r,t,n):n.worker?z(n.worker,n.name,e,r):o(!1)}(e,s,r,u)}function G(e,n,r,t){Array.isArray(n)||i(n)||(t=r,r=n,n=null);const u=l(n,t,e);return u?function(e,n,r,t){return e=D(e,n),n.parseTextSync&&"string"==typeof e?n.parseTextSync(e,r,t,n):n.parseSync?n.parseSync(e,r,t,n):o(!1)}(e,u,r=p(r,u),t):null}async function K(e,n,r,t){Array.isArray(n)||i(n)||(t=r,r=n,n=null);const o=l(n,t,null);return H(e,o,r=p(r,o),t)}async function X(e,n,r,t){Array.isArray(n)||i(n)||(t=r,r=n,n=null);const o=l(n,t,null);return H(e,o,r=p(r,o),t)}let Y="";const Z={};function ee(e){Y=e}function ne(){return Y}function re(e){for(const n in Z)if(e.startsWith(n)){const r=Z[n];return e.replace(n,r)}return e+=Y}async function te(e,n){return T(e)?O(e,n):(e=re(e),fetch(e,n))}async function oe(e,n,r){return K(await te(e,r),n,r,e)}async function ie(e,n,r){Array.isArray(n)||i(n)||(r=n,n=null);const t=l(n,T(e)?e.name:e,null,{nothrow:!0});if(t&&t.loadAndParse){const n=p(r,t);return await t.loadAndParse(e,n)}let o=e;return(T(o)||"string"==typeof o)&&(o=await te(e,r)),q(o,n,r,e)}function ue(e){const n=e&&e.lastIndexOf("/");return n>=0?e.substr(0,n):""}var se=r(2);const ce={dataType:"arraybuffer",nothrow:!0},ae=e=>e.startsWith("data:");function fe(e,n){return n=function(e={}){return(e=Object.assign({},ce,e)).responseType=e.responseType||e.dataType,e}(n),ae(e),n.nothrow||o(!1),null}function le(e,n={}){return e=re(e),!k.c&&se.readFileSync?se.readFileSync(e,n):fe(e,n)}var de=r(1);function ye(e,n,r){return e=re(e),!k.c&&de.writeFile?de.writeFile(e,n,r):o(!1)}function he(e,n,r){return e=re(e),!k.c&&de.writeFileSync?de.writeFileSync(e,n,r):o(!1)}function pe(e){return`Failed to fetch resource ${e.url}(${e.status}): ${e.statusText} `}async function we(e){let n=`Failed to fetch resource ${e.url} (${e.status}): `;try{e.headers.get("Content-Type").includes("application/json")?n+=await e.text():n+=e.statusText}catch(e){return n}return n}function be(e,n,r,t){if(n.encode)return n.encode(e,r);if(n.encodeSync)return Promise.resolve(n.encodeSync(e,r));throw new Error("Writer could not encode data")}function ge(e,n,r,t){if(n.encodeSync)return n.encodeSync(e,r);throw new Error("Writer could not synchronously encode data")}function me(e,n,r,t){if(n.encodeInBatches)return n.encodeInBatches(e,r);throw new Error("Writer could not encode data in batches")}function xe(e,n,r,t){return ye(n,be(e,r,t))}function Ae(e,n,r,t){return he(n,ge(e,r,t))}function Se(e,n){const r=e instanceof ArrayBuffer?new Uint8Array(e):e,t=n instanceof ArrayBuffer?new Uint8Array(n):n,o=new Uint8Array(r.byteLength+t.byteLength);return o.set(r,0),o.set(t,r.byteLength),o}async function ve(e,n){for(;;){const{done:r,value:t}=await e.next();if(r)return void e.return();if(n(t))return}}async function Te(e){let n=new ArrayBuffer,r="";for await(const t of e)"string"==typeof t?r+=t:n=Se(n,t);return r||n}async function*Be(e,n){const r=new TextDecoder(n);for await(const n of e)yield"string"==typeof n?n:r.decode(n,{stream:!0})}async function*je(e){let n="";for await(const r of e){let e;for(n+=r;(e=n.indexOf("\n"))>=0;){const r=n.slice(0,e+1);n=n.slice(e+1),yield r}}n.length>0&&(yield n)}async function*ke(e){let n=1;for await(const r of e)yield{counter:n,line:r},n++}r.d(n,"TextEncoder",function(){return _e}),r.d(n,"TextDecoder",function(){return Pe}),r.d(n,"createReadStream",function(){return Fe}),r.d(n,"parseFile",function(){return Oe}),r.d(n,"parseFileSync",function(){return Ee}),r.d(n,"loadFile",function(){return De}),r.d(n,"path",function(){return t}),r.d(n,"setPathPrefix",function(){return ee}),r.d(n,"getPathPrefix",function(){return ne}),r.d(n,"resolvePath",function(){return re}),r.d(n,"fetchFile",function(){return te}),r.d(n,"readFileSync",function(){return le}),r.d(n,"writeFile",function(){return ye}),r.d(n,"writeFileSync",function(){return he}),r.d(n,"_getErrorMessageFromResponseSync",function(){return pe}),r.d(n,"_getErrorMessageFromResponse",function(){return we}),r.d(n,"registerLoaders",function(){return c}),r.d(n,"parse",function(){return q}),r.d(n,"parseSync",function(){return G}),r.d(n,"parseInBatches",function(){return K}),r.d(n,"parseInBatchesSync",function(){return X}),r.d(n,"load",function(){return ie}),r.d(n,"loadInBatches",function(){return oe}),r.d(n,"encode",function(){return be}),r.d(n,"encodeSync",function(){return ge}),r.d(n,"encodeInBatches",function(){return me}),r.d(n,"save",function(){return xe}),r.d(n,"saveSync",function(){return Ae}),r.d(n,"isPromise",function(){return m}),r.d(n,"isIterable",function(){return x}),r.d(n,"isAsyncIterable",function(){return A}),r.d(n,"isIterator",function(){return S}),r.d(n,"isFetchResponse",function(){return v}),r.d(n,"isReadableStream",function(){return B}),r.d(n,"isWritableStream",function(){return j}),r.d(n,"toArrayBuffer",function(){return W}),r.d(n,"getStreamIterator",function(){return _}),r.d(n,"forEach",function(){return ve}),r.d(n,"concatenateAsyncIterator",function(){return Te}),r.d(n,"lineAsyncIterator",function(){return je}),r.d(n,"textDecoderAsyncIterator",function(){return Be}),r.d(n,"numberedLineAsyncIterator",function(){return ke}),r.d(n,"isBrowser",function(){return k.c}),r.d(n,"self",function(){return k.e}),r.d(n,"window",function(){return k.f}),r.d(n,"global",function(){return k.b}),r.d(n,"document",function(){return k.a}),r.d(n,"assert",function(){return o}),r.d(n,"_selectLoader",function(){return l}),r.d(n,"_WorkerThread",function(){return U}),r.d(n,"_WorkerFarm",function(){return V}),r.d(n,"_WorkerPool",function(){return M}),r.d(n,"_unregisterLoaders",function(){return a});const _e=k.b.TextEncoder,Pe=k.b.TextDecoder;async function Fe(e,n){return console.warn("createReadStream() deprecated, use fetch().then(resp => resp.body)"),e=re(e),(await te(e,n)).body}function Oe(...e){return console.warn("parse() deprecated, use parse()"),q(...e)}function Ee(...e){return console.warn("parseSync() deprecated, use parseSync()"),G(...e)}function De(...e){return console.warn("loadFile() deprecated, use load()"),ie(...e)}}])}); |
@@ -140,2 +140,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "_unregisterLoaders", { | ||
enumerable: true, | ||
get: function get() { | ||
return _registerLoaders._unregisterLoaders; | ||
} | ||
}); | ||
Object.defineProperty(exports, "encode", { | ||
@@ -261,2 +267,26 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "_selectLoader", { | ||
enumerable: true, | ||
get: function get() { | ||
return _selectLoader.selectLoader; | ||
} | ||
}); | ||
Object.defineProperty(exports, "_WorkerThread", { | ||
enumerable: true, | ||
get: function get() { | ||
return _workerThread["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "_WorkerFarm", { | ||
enumerable: true, | ||
get: function get() { | ||
return _workerFarm["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "_WorkerPool", { | ||
enumerable: true, | ||
get: function get() { | ||
return _workerPool["default"]; | ||
} | ||
}); | ||
exports.path = exports.TextDecoder = exports.TextEncoder = void 0; | ||
@@ -306,2 +336,10 @@ | ||
var _selectLoader = require("./lib/select-loader"); | ||
var _workerThread = _interopRequireDefault(require("./worker-utils/worker-thread")); | ||
var _workerFarm = _interopRequireDefault(require("./worker-utils/worker-farm")); | ||
var _workerPool = _interopRequireDefault(require("./worker-utils/worker-pool")); | ||
var TextEncoder = _globals.global.TextEncoder; | ||
@@ -308,0 +346,0 @@ exports.TextEncoder = TextEncoder; |
@@ -79,7 +79,11 @@ "use strict"; | ||
case 14: | ||
_context.prev = 14; | ||
_context.next = 19; | ||
break; | ||
case 16: | ||
_context.prev = 16; | ||
_context.t0 = _context["catch"](1); | ||
reader.releaseLock(); | ||
return _context.finish(14); | ||
case 17: | ||
case 19: | ||
case "end": | ||
@@ -89,3 +93,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[1,, 14, 17]]); | ||
}, _callee, null, [[1, 16]]); | ||
})); | ||
@@ -92,0 +96,0 @@ return _makeBrowserStreamIterator.apply(this, arguments); |
@@ -23,8 +23,6 @@ "use strict"; | ||
var _autoDetectLoader = require("./loader-utils/auto-detect-loader"); | ||
var _selectLoader = require("./select-loader"); | ||
var _parse = require("./parse"); | ||
var _registerLoaders = require("./register-loaders"); | ||
function loadInBatches(_x, _x2, _x3) { | ||
@@ -64,3 +62,3 @@ return _loadInBatches.apply(this, arguments); | ||
_load = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(url, loaders, options) { | ||
var autoUrl, loader, data; | ||
var autoUrl, loader, loaderOptions, data; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
@@ -76,9 +74,7 @@ while (1) { | ||
autoUrl = (0, _isType.isFileReadable)(url) ? url.name : url; | ||
loaders = loaders || (0, _registerLoaders.getRegisteredLoaders)(); | ||
loader = Array.isArray(loaders) ? (0, _autoDetectLoader.autoDetectLoader)(null, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
options = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
loader = (0, _selectLoader.selectLoader)(loaders, autoUrl, null, { | ||
nothrow: true | ||
}); | ||
if (!(loader && loader.loadAndParse)) { | ||
if (!loader) { | ||
_context2.next = 9; | ||
@@ -88,4 +84,10 @@ break; | ||
if (!loader.loadAndParse) { | ||
_context2.next = 9; | ||
break; | ||
} | ||
loaderOptions = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
_context2.next = 8; | ||
return loader.loadAndParse(url, options); | ||
return loader.loadAndParse(url, loaderOptions); | ||
@@ -110,3 +112,3 @@ case 8: | ||
case 14: | ||
return _context2.abrupt("return", (0, _parse.parse)(data, loaders, options, autoUrl)); | ||
return _context2.abrupt("return", (0, _parse.parse)(data, loaders, options, url)); | ||
@@ -113,0 +115,0 @@ case 15: |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,71 +10,78 @@ value: true | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _binaryUtils = require("../javascript-utils/binary-utils"); | ||
var workerCache = new Map(); | ||
var counters = {}; | ||
var _workerFarm2 = _interopRequireDefault(require("../worker-utils/worker-farm")); | ||
function getDecoratedWorkerName(workerName) { | ||
var lowerCaseName = workerName ? workerName.toLowerCase() : 'unnamed'; | ||
counters[lowerCaseName] = counters[lowerCaseName] || 0; | ||
var counter = counters[lowerCaseName]++; | ||
return "loaders.gl-".concat(lowerCaseName, "-worker-").concat(counter); | ||
} | ||
var _workerUtils = require("../worker-utils/worker-utils"); | ||
function getWorker(workerSource, workerName) { | ||
var workerURL = workerCache.get(workerSource); | ||
var _workerFarm = null; | ||
if (!workerURL) { | ||
var blob = new Blob([workerSource], { | ||
type: 'application/javascript' | ||
}); | ||
workerURL = URL.createObjectURL(blob); | ||
workerCache.set(workerSource, workerURL); | ||
function getWorkerFarm() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var props = {}; | ||
if (options.maxConcurrency) { | ||
props.maxConcurrency = options.maxConcurrency; | ||
} | ||
return new Worker(workerURL, { | ||
name: getDecoratedWorkerName(workerName) | ||
}); | ||
if (options.onDebug) { | ||
props.onDebug = options.onDebug; | ||
} | ||
_workerFarm = _workerFarm || new _workerFarm2["default"]({}); | ||
_workerFarm.setProps(props); | ||
return _workerFarm; | ||
} | ||
function parseWithWorker(workerSource, workerName, data, options) { | ||
var worker = getWorker(workerSource, workerName); | ||
options = removeNontransferableOptions(options); | ||
function parseWithWorker(_x, _x2, _x3, _x4) { | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
var parse = function parse(rawData, opts) { | ||
return new Promise(function (resolve, reject) { | ||
worker.onmessage = function (evt) { | ||
switch (evt.data.type) { | ||
case 'done': | ||
resolve(evt.data.result); | ||
worker.terminate(); | ||
break; | ||
function _parseWithWorker() { | ||
_parseWithWorker = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(workerSource, workerName, data, options) { | ||
var workerFarm, result; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
workerFarm = getWorkerFarm(options); | ||
options = (0, _workerUtils.removeNontransferableValues)(options); | ||
_context.next = 4; | ||
return workerFarm.process(workerSource, "loaders.gl-".concat(workerName), { | ||
arraybuffer: (0, _binaryUtils.toArrayBuffer)(data), | ||
options: options, | ||
source: 'loaders.gl', | ||
type: 'process' | ||
}); | ||
case 'error': | ||
reject(new Error(evt.data.message)); | ||
case 4: | ||
result = _context.sent; | ||
_context.t0 = result.type; | ||
_context.next = _context.t0 === 'done' ? 8 : _context.t0 === 'error' ? 9 : 10; | ||
break; | ||
default: | ||
} | ||
}; | ||
case 8: | ||
return _context.abrupt("return", result.result); | ||
var arraybuffer = (0, _binaryUtils.toArrayBuffer)(rawData); | ||
worker.postMessage({ | ||
arraybuffer: arraybuffer, | ||
opts: opts | ||
}, [arraybuffer]); | ||
}); | ||
}; | ||
case 9: | ||
throw new Error(result.message); | ||
return data ? parse(data, options) : parse; | ||
} | ||
case 10: | ||
return _context.abrupt("return", result); | ||
function removeNontransferableOptions(options) { | ||
options = Object.assign({}, options); | ||
if (options.log !== null) { | ||
delete options.log; | ||
} | ||
return options; | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
//# sourceMappingURL=parse-with-worker.js.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
var _autoDetectLoader = require("./loader-utils/auto-detect-loader"); | ||
var _selectLoader = require("./select-loader"); | ||
@@ -26,4 +26,2 @@ var _normalizeLoader = require("./loader-utils/normalize-loader"); | ||
var _registerLoaders = require("./register-loaders"); | ||
var _parseWithLoader = require("./parse-with-loader"); | ||
@@ -42,3 +40,3 @@ | ||
case 0: | ||
if (!Array.isArray(loaders) && !(0, _normalizeLoader.isLoaderObject)(loaders)) { | ||
if (loaders && !Array.isArray(loaders) && !(0, _normalizeLoader.isLoaderObject)(loaders)) { | ||
url = options; | ||
@@ -49,25 +47,13 @@ options = loaders; | ||
options = options || {}; | ||
autoUrl = (0, _getData.getUrlFromData)(data, url); | ||
loaders = loaders || (0, _registerLoaders.getRegisteredLoaders)(); | ||
loader = Array.isArray(loaders) ? (0, _autoDetectLoader.autoDetectLoader)(data, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
if (loader) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt("return", null); | ||
case 6: | ||
(0, _normalizeLoader.normalizeLoader)(loader); | ||
loader = (0, _selectLoader.selectLoader)(loaders, autoUrl, data); | ||
options = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
_context.next = 10; | ||
_context.next = 7; | ||
return (0, _parseWithLoader.parseWithLoader)(data, loader, options, autoUrl); | ||
case 10: | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 11: | ||
case 8: | ||
case "end": | ||
@@ -89,7 +75,8 @@ return _context.stop(); | ||
loaders = loaders || (0, _registerLoaders.getRegisteredLoaders)(); | ||
var loader = Array.isArray(loaders) ? (0, _autoDetectLoader.autoDetectLoader)(data, loaders, { | ||
url: url | ||
}) : loaders; | ||
(0, _normalizeLoader.normalizeLoader)(loader); | ||
var loader = (0, _selectLoader.selectLoader)(loaders, url, data); | ||
if (!loader) { | ||
return null; | ||
} | ||
options = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
@@ -116,11 +103,7 @@ return (0, _parseWithLoader.parseWithLoaderSync)(data, loader, options, url); | ||
loaders = loaders || (0, _registerLoaders.getRegisteredLoaders)(); | ||
loader = Array.isArray(loaders) ? (0, _autoDetectLoader.autoDetectLoader)(null, loaders, { | ||
url: url | ||
}) : loaders; | ||
(0, _normalizeLoader.normalizeLoader)(loader); | ||
loader = (0, _selectLoader.selectLoader)(loaders, url, null); | ||
options = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
return _context2.abrupt("return", (0, _parseWithLoader.parseWithLoaderInBatches)(data, loader, options, url)); | ||
case 6: | ||
case 4: | ||
case "end": | ||
@@ -152,11 +135,7 @@ return _context2.stop(); | ||
loaders = loaders || (0, _registerLoaders.getRegisteredLoaders)(); | ||
loader = Array.isArray(loaders) ? (0, _autoDetectLoader.autoDetectLoader)(null, loaders, { | ||
url: url | ||
}) : loaders; | ||
(0, _normalizeLoader.normalizeLoader)(loader); | ||
loader = (0, _selectLoader.selectLoader)(loaders, url, null); | ||
options = (0, _normalizeOptions.mergeLoaderAndUserOptions)(options, loader); | ||
return _context3.abrupt("return", (0, _parseWithLoader.parseWithLoaderInBatches)(data, loader, options, url)); | ||
case 6: | ||
case 4: | ||
case "end": | ||
@@ -163,0 +142,0 @@ return _context3.stop(); |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.getRegisteredLoaders = getRegisteredLoaders; | ||
exports._unregisterLoaders = _unregisterLoaders; | ||
@@ -67,2 +68,6 @@ var _normalizeLoader = require("./loader-utils/normalize-loader"); | ||
} | ||
function _unregisterLoaders() { | ||
registeredLoaders = {}; | ||
} | ||
//# sourceMappingURL=register-loaders.js.map |
@@ -25,2 +25,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
export { default as assert } from './utils/assert'; | ||
export { selectLoader as _selectLoader } from './lib/select-loader'; | ||
export { default as _WorkerThread } from './worker-utils/worker-thread'; | ||
export { default as _WorkerFarm } from './worker-utils/worker-farm'; | ||
export { default as _WorkerPool } from './worker-utils/worker-pool'; | ||
export { _unregisterLoaders } from './lib/register-loaders'; | ||
export var TextEncoder = global.TextEncoder; | ||
@@ -27,0 +32,0 @@ export var TextDecoder = global.TextDecoder; |
@@ -40,3 +40,3 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
} | ||
} finally { | ||
} catch (error) { | ||
reader.releaseLock(); | ||
@@ -43,0 +43,0 @@ } |
@@ -6,5 +6,4 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import { mergeLoaderAndUserOptions } from './loader-utils/normalize-options'; | ||
import { autoDetectLoader } from './loader-utils/auto-detect-loader'; | ||
import { selectLoader } from './select-loader'; | ||
import { parse, parseInBatches } from './parse'; | ||
import { getRegisteredLoaders } from './register-loaders'; | ||
export function loadInBatches(_x, _x2, _x3) { | ||
@@ -34,10 +33,11 @@ return _loadInBatches.apply(this, arguments); | ||
var autoUrl = isFileReadable(url) ? url.name : url; | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
var loader = selectLoader(loaders, autoUrl, null, { | ||
nothrow: true | ||
}); | ||
if (loader && loader.loadAndParse) { | ||
return yield loader.loadAndParse(url, options); | ||
if (loader) { | ||
if (loader.loadAndParse) { | ||
var loaderOptions = mergeLoaderAndUserOptions(options, loader); | ||
return yield loader.loadAndParse(url, loaderOptions); | ||
} | ||
} | ||
@@ -51,3 +51,3 @@ | ||
return parse(data, loaders, options, autoUrl); | ||
return parse(data, loaders, options, url); | ||
}); | ||
@@ -54,0 +54,0 @@ return _load.apply(this, arguments); |
@@ -0,67 +1,54 @@ | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import { toArrayBuffer } from '../javascript-utils/binary-utils'; | ||
var workerCache = new Map(); | ||
var counters = {}; | ||
import WorkerFarm from '../worker-utils/worker-farm'; | ||
import { removeNontransferableValues } from '../worker-utils/worker-utils'; | ||
var _workerFarm = null; | ||
function getDecoratedWorkerName(workerName) { | ||
var lowerCaseName = workerName ? workerName.toLowerCase() : 'unnamed'; | ||
counters[lowerCaseName] = counters[lowerCaseName] || 0; | ||
var counter = counters[lowerCaseName]++; | ||
return "loaders.gl-".concat(lowerCaseName, "-worker-").concat(counter); | ||
} | ||
function getWorkerFarm() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var props = {}; | ||
function getWorker(workerSource, workerName) { | ||
var workerURL = workerCache.get(workerSource); | ||
if (options.maxConcurrency) { | ||
props.maxConcurrency = options.maxConcurrency; | ||
} | ||
if (!workerURL) { | ||
var blob = new Blob([workerSource], { | ||
type: 'application/javascript' | ||
}); | ||
workerURL = URL.createObjectURL(blob); | ||
workerCache.set(workerSource, workerURL); | ||
if (options.onDebug) { | ||
props.onDebug = options.onDebug; | ||
} | ||
return new Worker(workerURL, { | ||
name: getDecoratedWorkerName(workerName) | ||
}); | ||
_workerFarm = _workerFarm || new WorkerFarm({}); | ||
_workerFarm.setProps(props); | ||
return _workerFarm; | ||
} | ||
export default function parseWithWorker(workerSource, workerName, data, options) { | ||
var worker = getWorker(workerSource, workerName); | ||
options = removeNontransferableOptions(options); | ||
export default function parseWithWorker(_x, _x2, _x3, _x4) { | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
var parse = (rawData, opts) => new Promise((resolve, reject) => { | ||
worker.onmessage = evt => { | ||
switch (evt.data.type) { | ||
case 'done': | ||
resolve(evt.data.result); | ||
worker.terminate(); | ||
break; | ||
function _parseWithWorker() { | ||
_parseWithWorker = _asyncToGenerator(function* (workerSource, workerName, data, options) { | ||
var workerFarm = getWorkerFarm(options); | ||
options = removeNontransferableValues(options); | ||
var result = yield workerFarm.process(workerSource, "loaders.gl-".concat(workerName), { | ||
arraybuffer: toArrayBuffer(data), | ||
options, | ||
source: 'loaders.gl', | ||
type: 'process' | ||
}); | ||
case 'error': | ||
reject(new Error(evt.data.message)); | ||
break; | ||
switch (result.type) { | ||
case 'done': | ||
return result.result; | ||
default: | ||
} | ||
}; | ||
case 'error': | ||
throw new Error(result.message); | ||
var arraybuffer = toArrayBuffer(rawData); | ||
worker.postMessage({ | ||
arraybuffer, | ||
opts | ||
}, [arraybuffer]); | ||
default: | ||
return result; | ||
} | ||
}); | ||
return data ? parse(data, options) : parse; | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
function removeNontransferableOptions(options) { | ||
options = Object.assign({}, options); | ||
if (options.log !== null) { | ||
delete options.log; | ||
} | ||
return options; | ||
} | ||
//# sourceMappingURL=parse-with-worker.js.map |
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import { autoDetectLoader } from './loader-utils/auto-detect-loader'; | ||
import { normalizeLoader, isLoaderObject } from './loader-utils/normalize-loader'; | ||
import { selectLoader } from './select-loader'; | ||
import { isLoaderObject } from './loader-utils/normalize-loader'; | ||
import { mergeLoaderAndUserOptions } from './loader-utils/normalize-options'; | ||
import { getUrlFromData } from './loader-utils/get-data'; | ||
import { getRegisteredLoaders } from './register-loaders'; | ||
import { parseWithLoader, parseWithLoaderInBatches, parseWithLoaderSync } from './parse-with-loader'; | ||
@@ -14,3 +13,3 @@ export function parse(_x, _x2, _x3, _x4) { | ||
_parse = _asyncToGenerator(function* (data, loaders, options, url) { | ||
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
url = options; | ||
@@ -21,13 +20,5 @@ options = loaders; | ||
options = options || {}; | ||
var autoUrl = getUrlFromData(data, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
if (!loader) { | ||
return null; | ||
} | ||
normalizeLoader(loader); | ||
var loader = selectLoader(loaders, autoUrl, data); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
@@ -46,7 +37,8 @@ return yield parseWithLoader(data, loader, options, autoUrl); | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, { | ||
url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
var loader = selectLoader(loaders, url, data); | ||
if (!loader) { | ||
return null; | ||
} | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
@@ -67,7 +59,3 @@ return parseWithLoaderSync(data, loader, options, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
var loader = selectLoader(loaders, url, null); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
@@ -91,7 +79,3 @@ return parseWithLoaderInBatches(data, loader, options, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
var loader = selectLoader(loaders, url, null); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
@@ -98,0 +82,0 @@ return parseWithLoaderInBatches(data, loader, options, url); |
@@ -17,2 +17,5 @@ import { normalizeLoader } from './loader-utils/normalize-loader'; | ||
} | ||
export function _unregisterLoaders() { | ||
registeredLoaders = {}; | ||
} | ||
//# sourceMappingURL=register-loaders.js.map |
@@ -26,2 +26,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
export { default as assert } from './utils/assert'; | ||
export { selectLoader as _selectLoader } from './lib/select-loader'; | ||
export { default as _WorkerThread } from './worker-utils/worker-thread'; | ||
export { default as _WorkerFarm } from './worker-utils/worker-farm'; | ||
export { default as _WorkerPool } from './worker-utils/worker-pool'; | ||
export { _unregisterLoaders } from './lib/register-loaders'; | ||
export var TextEncoder = global.TextEncoder; | ||
@@ -28,0 +33,0 @@ export var TextDecoder = global.TextDecoder; |
@@ -65,7 +65,11 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
case 14: | ||
_context.prev = 14; | ||
_context.next = 19; | ||
break; | ||
case 16: | ||
_context.prev = 16; | ||
_context.t0 = _context["catch"](1); | ||
reader.releaseLock(); | ||
return _context.finish(14); | ||
case 17: | ||
case 19: | ||
case "end": | ||
@@ -75,3 +79,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[1,, 14, 17]]); | ||
}, _callee, null, [[1, 16]]); | ||
})); | ||
@@ -78,0 +82,0 @@ return _makeBrowserStreamIterator.apply(this, arguments); |
@@ -7,5 +7,4 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import { mergeLoaderAndUserOptions } from './loader-utils/normalize-options'; | ||
import { autoDetectLoader } from './loader-utils/auto-detect-loader'; | ||
import { selectLoader } from './select-loader'; | ||
import { parse, parseInBatches } from './parse'; | ||
import { getRegisteredLoaders } from './register-loaders'; | ||
export function loadInBatches(_x, _x2, _x3) { | ||
@@ -45,3 +44,3 @@ return _loadInBatches.apply(this, arguments); | ||
_load = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(url, loaders, options) { | ||
var autoUrl, loader, data; | ||
var autoUrl, loader, loaderOptions, data; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
@@ -57,9 +56,7 @@ while (1) { | ||
autoUrl = isFileReadable(url) ? url.name : url; | ||
loaders = loaders || getRegisteredLoaders(); | ||
loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
loader = selectLoader(loaders, autoUrl, null, { | ||
nothrow: true | ||
}); | ||
if (!(loader && loader.loadAndParse)) { | ||
if (!loader) { | ||
_context2.next = 9; | ||
@@ -69,4 +66,10 @@ break; | ||
if (!loader.loadAndParse) { | ||
_context2.next = 9; | ||
break; | ||
} | ||
loaderOptions = mergeLoaderAndUserOptions(options, loader); | ||
_context2.next = 8; | ||
return loader.loadAndParse(url, options); | ||
return loader.loadAndParse(url, loaderOptions); | ||
@@ -91,3 +94,3 @@ case 8: | ||
case 14: | ||
return _context2.abrupt("return", parse(data, loaders, options, autoUrl)); | ||
return _context2.abrupt("return", parse(data, loaders, options, url)); | ||
@@ -94,0 +97,0 @@ case 15: |
@@ -0,69 +1,72 @@ | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import { toArrayBuffer } from '../javascript-utils/binary-utils'; | ||
var workerCache = new Map(); | ||
var counters = {}; | ||
import WorkerFarm from '../worker-utils/worker-farm'; | ||
import { removeNontransferableValues } from '../worker-utils/worker-utils'; | ||
var _workerFarm = null; | ||
function getDecoratedWorkerName(workerName) { | ||
var lowerCaseName = workerName ? workerName.toLowerCase() : 'unnamed'; | ||
counters[lowerCaseName] = counters[lowerCaseName] || 0; | ||
var counter = counters[lowerCaseName]++; | ||
return "loaders.gl-".concat(lowerCaseName, "-worker-").concat(counter); | ||
} | ||
function getWorkerFarm() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var props = {}; | ||
function getWorker(workerSource, workerName) { | ||
var workerURL = workerCache.get(workerSource); | ||
if (options.maxConcurrency) { | ||
props.maxConcurrency = options.maxConcurrency; | ||
} | ||
if (!workerURL) { | ||
var blob = new Blob([workerSource], { | ||
type: 'application/javascript' | ||
}); | ||
workerURL = URL.createObjectURL(blob); | ||
workerCache.set(workerSource, workerURL); | ||
if (options.onDebug) { | ||
props.onDebug = options.onDebug; | ||
} | ||
return new Worker(workerURL, { | ||
name: getDecoratedWorkerName(workerName) | ||
}); | ||
_workerFarm = _workerFarm || new WorkerFarm({}); | ||
_workerFarm.setProps(props); | ||
return _workerFarm; | ||
} | ||
export default function parseWithWorker(workerSource, workerName, data, options) { | ||
var worker = getWorker(workerSource, workerName); | ||
options = removeNontransferableOptions(options); | ||
export default function parseWithWorker(_x, _x2, _x3, _x4) { | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
var parse = function parse(rawData, opts) { | ||
return new Promise(function (resolve, reject) { | ||
worker.onmessage = function (evt) { | ||
switch (evt.data.type) { | ||
case 'done': | ||
resolve(evt.data.result); | ||
worker.terminate(); | ||
break; | ||
function _parseWithWorker() { | ||
_parseWithWorker = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(workerSource, workerName, data, options) { | ||
var workerFarm, result; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
workerFarm = getWorkerFarm(options); | ||
options = removeNontransferableValues(options); | ||
_context.next = 4; | ||
return workerFarm.process(workerSource, "loaders.gl-".concat(workerName), { | ||
arraybuffer: toArrayBuffer(data), | ||
options: options, | ||
source: 'loaders.gl', | ||
type: 'process' | ||
}); | ||
case 'error': | ||
reject(new Error(evt.data.message)); | ||
case 4: | ||
result = _context.sent; | ||
_context.t0 = result.type; | ||
_context.next = _context.t0 === 'done' ? 8 : _context.t0 === 'error' ? 9 : 10; | ||
break; | ||
default: | ||
} | ||
}; | ||
case 8: | ||
return _context.abrupt("return", result.result); | ||
var arraybuffer = toArrayBuffer(rawData); | ||
worker.postMessage({ | ||
arraybuffer: arraybuffer, | ||
opts: opts | ||
}, [arraybuffer]); | ||
}); | ||
}; | ||
case 9: | ||
throw new Error(result.message); | ||
return data ? parse(data, options) : parse; | ||
} | ||
case 10: | ||
return _context.abrupt("return", result); | ||
function removeNontransferableOptions(options) { | ||
options = Object.assign({}, options); | ||
if (options.log !== null) { | ||
delete options.log; | ||
} | ||
return options; | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _parseWithWorker.apply(this, arguments); | ||
} | ||
//# sourceMappingURL=parse-with-worker.js.map |
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import { autoDetectLoader } from './loader-utils/auto-detect-loader'; | ||
import { normalizeLoader, isLoaderObject } from './loader-utils/normalize-loader'; | ||
import { selectLoader } from './select-loader'; | ||
import { isLoaderObject } from './loader-utils/normalize-loader'; | ||
import { mergeLoaderAndUserOptions } from './loader-utils/normalize-options'; | ||
import { getUrlFromData } from './loader-utils/get-data'; | ||
import { getRegisteredLoaders } from './register-loaders'; | ||
import { parseWithLoader, parseWithLoaderInBatches, parseWithLoaderSync } from './parse-with-loader'; | ||
@@ -20,3 +19,3 @@ export function parse(_x, _x2, _x3, _x4) { | ||
case 0: | ||
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
url = options; | ||
@@ -27,25 +26,13 @@ options = loaders; | ||
options = options || {}; | ||
autoUrl = getUrlFromData(data, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, { | ||
url: autoUrl | ||
}) : loaders; | ||
if (loader) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt("return", null); | ||
case 6: | ||
normalizeLoader(loader); | ||
loader = selectLoader(loaders, autoUrl, data); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
_context.next = 10; | ||
_context.next = 7; | ||
return parseWithLoader(data, loader, options, autoUrl); | ||
case 10: | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 11: | ||
case 8: | ||
case "end": | ||
@@ -67,7 +54,8 @@ return _context.stop(); | ||
loaders = loaders || getRegisteredLoaders(); | ||
var loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, { | ||
url: url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
var loader = selectLoader(loaders, url, data); | ||
if (!loader) { | ||
return null; | ||
} | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
@@ -93,11 +81,7 @@ return parseWithLoaderSync(data, loader, options, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url: url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
loader = selectLoader(loaders, url, null); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
return _context2.abrupt("return", parseWithLoaderInBatches(data, loader, options, url)); | ||
case 6: | ||
case 4: | ||
case "end": | ||
@@ -129,11 +113,7 @@ return _context2.stop(); | ||
loaders = loaders || getRegisteredLoaders(); | ||
loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, { | ||
url: url | ||
}) : loaders; | ||
normalizeLoader(loader); | ||
loader = selectLoader(loaders, url, null); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
return _context3.abrupt("return", parseWithLoaderInBatches(data, loader, options, url)); | ||
case 6: | ||
case 4: | ||
case "end": | ||
@@ -140,0 +120,0 @@ return _context3.stop(); |
@@ -55,2 +55,5 @@ import { normalizeLoader } from './loader-utils/normalize-loader'; | ||
} | ||
export function _unregisterLoaders() { | ||
registeredLoaders = {}; | ||
} | ||
//# sourceMappingURL=register-loaders.js.map |
{ | ||
"name": "@loaders.gl/core", | ||
"version": "1.2.2", | ||
"version": "1.3.0-beta.1", | ||
"description": "Framework-independent loaders for 3D graphics formats", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "c8bd2fef7bc686e5cf2ae68926f2ee51d95b50cf" | ||
"gitHead": "deabcc69303bc19eeadb1bb6cf9082ee94e74f3e" | ||
} |
@@ -61,2 +61,12 @@ import {parse, parseSync} from './lib/parse'; | ||
// EXPERIMENTAL | ||
export {selectLoader as _selectLoader} from './lib/select-loader'; | ||
export {default as _WorkerThread} from './worker-utils/worker-thread'; | ||
export {default as _WorkerFarm} from './worker-utils/worker-farm'; | ||
export {default as _WorkerPool} from './worker-utils/worker-pool'; | ||
// FOR TESTING | ||
export {_unregisterLoaders} from './lib/register-loaders'; | ||
// DEPRECATED | ||
@@ -63,0 +73,0 @@ |
@@ -39,3 +39,5 @@ import {isBrowser, nodeVersion} from '../utils/globals'; | ||
} | ||
} finally { | ||
} catch (error) { | ||
// TODO - examples makes it look like this should always be called, | ||
// but that generates exceptions so only call it if we do not reach the end | ||
reader.releaseLock(); | ||
@@ -42,0 +44,0 @@ } |
@@ -5,6 +5,5 @@ import {isFileReadable} from '../javascript-utils/is-type'; | ||
import {mergeLoaderAndUserOptions} from './loader-utils/normalize-options'; | ||
import {autoDetectLoader} from './loader-utils/auto-detect-loader'; | ||
import {selectLoader} from './select-loader'; | ||
import {parse, parseInBatches} from './parse'; | ||
import {getRegisteredLoaders} from './register-loaders'; | ||
@@ -21,3 +20,2 @@ export async function loadInBatches(url, loaders, options) { | ||
// Signature: load(url, options) | ||
// Uses registered loaders | ||
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
@@ -31,10 +29,14 @@ options = loaders; | ||
loaders = loaders || getRegisteredLoaders(); | ||
const loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, {url: autoUrl}) : loaders; | ||
// Initial loader autodection (Use registered loaders if none provided) | ||
// This only uses URL extensions to detect loaders. | ||
const loader = selectLoader(loaders, autoUrl, null, {nothrow: true}); | ||
options = mergeLoaderAndUserOptions(options, loader); | ||
// Some loaders can not separate reading and parsing of data (e.g ImageLoader) | ||
if (loader && loader.loadAndParse) { | ||
return await loader.loadAndParse(url, options); | ||
if (loader) { | ||
// Some loaders do not separate reading and parsing of data (e.g ImageLoader) | ||
// These can only be handled by `load`, not `parse` | ||
// TODO - ImageLoaders can be rewritten to separate load and parse, phase out this variant? | ||
if (loader.loadAndParse) { | ||
const loaderOptions = mergeLoaderAndUserOptions(options, loader); | ||
return await loader.loadAndParse(url, loaderOptions); | ||
} | ||
} | ||
@@ -47,3 +49,7 @@ | ||
} | ||
return parse(data, loaders, options, autoUrl); | ||
// Fall back to parse | ||
// Note: An improved round of autodetection is possible now that data has been loaded | ||
// This means that another loader might be selected | ||
return parse(data, loaders, options, url); | ||
} |
import {toArrayBuffer} from '../javascript-utils/binary-utils'; | ||
import WorkerFarm from '../worker-utils/worker-farm'; | ||
const workerCache = new Map(); | ||
import {removeNontransferableValues} from '../worker-utils/worker-utils'; | ||
const counters = {}; | ||
let _workerFarm = null; | ||
function getDecoratedWorkerName(workerName) { | ||
const lowerCaseName = workerName ? workerName.toLowerCase() : 'unnamed'; | ||
counters[lowerCaseName] = counters[lowerCaseName] || 0; | ||
const counter = counters[lowerCaseName]++; | ||
return `loaders.gl-${lowerCaseName}-worker-${counter}`; | ||
} | ||
/* global Worker, Blob, URL */ | ||
function getWorker(workerSource, workerName) { | ||
let workerURL = workerCache.get(workerSource); | ||
if (!workerURL) { | ||
const blob = new Blob([workerSource], {type: 'application/javascript'}); | ||
workerURL = URL.createObjectURL(blob); | ||
workerCache.set(workerSource, workerURL); | ||
function getWorkerFarm(options = {}) { | ||
const props = {}; | ||
if (options.maxConcurrency) { | ||
props.maxConcurrency = options.maxConcurrency; | ||
} | ||
return new Worker(workerURL, {name: getDecoratedWorkerName(workerName)}); | ||
} | ||
if (options.onDebug) { | ||
props.onDebug = options.onDebug; | ||
} | ||
export default function parseWithWorker(workerSource, workerName, data, options) { | ||
const worker = getWorker(workerSource, workerName); | ||
_workerFarm = _workerFarm || new WorkerFarm({}); | ||
_workerFarm.setProps(props); | ||
options = removeNontransferableOptions(options); | ||
return _workerFarm; | ||
} | ||
const parse = (rawData, opts) => | ||
new Promise((resolve, reject) => { | ||
worker.onmessage = evt => { | ||
switch (evt.data.type) { | ||
case 'done': | ||
resolve(evt.data.result); | ||
worker.terminate(); | ||
break; | ||
/** | ||
* this function expects that the worker function sends certain messages, | ||
* this can be automated if the worker is wrapper by a call to createWorker in @loaders.gl/loader-utils. | ||
*/ | ||
export default async function parseWithWorker(workerSource, workerName, data, options) { | ||
const workerFarm = getWorkerFarm(options); | ||
case 'error': | ||
reject(new Error(evt.data.message)); | ||
break; | ||
// Note that options are documented for each loader, we are just passing them through to the worker | ||
// `options` can contain functions etc that can not be serialized/deserialized, they need to be stripped | ||
// TODO - Since the `options` object can contain options not intended for the loader, we currently cannot | ||
// treat this as an error case, but we just silently remove such values. | ||
options = removeNontransferableValues(options); | ||
default: | ||
} | ||
}; | ||
const result = await workerFarm.process(workerSource, `loaders.gl-${workerName}`, { | ||
arraybuffer: toArrayBuffer(data), | ||
options, | ||
source: 'loaders.gl', // Lets worker ignore unrelated messages | ||
type: 'process' // For future extension | ||
}); | ||
const arraybuffer = toArrayBuffer(rawData); | ||
worker.postMessage({arraybuffer, opts}, [arraybuffer]); | ||
}); | ||
switch (result.type) { | ||
case 'done': | ||
return result.result; | ||
return data ? parse(data, options) : parse; | ||
} | ||
case 'error': | ||
throw new Error(result.message); | ||
function removeNontransferableOptions(options) { | ||
options = Object.assign({}, options); | ||
// log object contains functions which cannot be transferred | ||
// TODO - decide how to handle logging on workers | ||
if (options.log !== null) { | ||
delete options.log; | ||
default: | ||
// TODO - is this not an error case? Log a warning? | ||
return result; | ||
} | ||
return options; | ||
} |
@@ -1,6 +0,5 @@ | ||
import {autoDetectLoader} from './loader-utils/auto-detect-loader'; | ||
import {normalizeLoader, isLoaderObject} from './loader-utils/normalize-loader'; | ||
import {selectLoader} from './select-loader'; | ||
import {isLoaderObject} from './loader-utils/normalize-loader'; | ||
import {mergeLoaderAndUserOptions} from './loader-utils/normalize-options'; | ||
import {getUrlFromData} from './loader-utils/get-data'; | ||
import {getRegisteredLoaders} from './register-loaders'; | ||
import {parseWithLoader, parseWithLoaderInBatches, parseWithLoaderSync} from './parse-with-loader'; | ||
@@ -11,3 +10,3 @@ | ||
// Uses registered loaders | ||
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) { | ||
url = options; | ||
@@ -18,15 +17,10 @@ options = loaders; | ||
options = options || {}; | ||
// Extract a url for auto detection | ||
const autoUrl = getUrlFromData(data, url); | ||
loaders = loaders || getRegisteredLoaders(); | ||
const loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, {url: autoUrl}) : loaders; | ||
if (!loader) { | ||
// no loader available | ||
// TODO: throw error? | ||
return null; | ||
} | ||
// Chooses a loader and normalize it | ||
const loader = selectLoader(loaders, autoUrl, data); | ||
normalizeLoader(loader); | ||
// Normalize options | ||
@@ -47,6 +41,8 @@ options = mergeLoaderAndUserOptions(options, loader); | ||
// Choose loader and normalize it | ||
loaders = loaders || getRegisteredLoaders(); | ||
const loader = Array.isArray(loaders) ? autoDetectLoader(data, loaders, {url}) : loaders; | ||
normalizeLoader(loader); | ||
// Chooses a loader and normalize it | ||
const loader = selectLoader(loaders, url, data); | ||
// Note: if nothrow option was set, it is possible that no loader was found, if so just return null | ||
if (!loader) { | ||
return null; | ||
} | ||
@@ -68,6 +64,5 @@ // Normalize options | ||
// Choose loader and normalize it | ||
loaders = loaders || getRegisteredLoaders(); | ||
const loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, {url}) : loaders; | ||
normalizeLoader(loader); | ||
// Chooses a loader and normalizes it | ||
// TODO - only uses URL, need a selectLoader variant that peeks at first stream chunk... | ||
const loader = selectLoader(loaders, url, null); | ||
@@ -89,6 +84,5 @@ // Normalize options | ||
// Choose loader and normalize it | ||
loaders = loaders || getRegisteredLoaders(); | ||
const loader = Array.isArray(loaders) ? autoDetectLoader(null, loaders, {url}) : loaders; | ||
normalizeLoader(loader); | ||
// Chooses a loader and normalizes it | ||
// TODO - only uses URL, need a selectLoader variant that peeks at first stream chunk... | ||
const loader = selectLoader(loaders, url, null); | ||
@@ -95,0 +89,0 @@ // Normalize options |
import {normalizeLoader} from './loader-utils/normalize-loader'; | ||
const registeredLoaders = {}; | ||
let registeredLoaders = {}; | ||
@@ -18,1 +18,6 @@ export function registerLoaders(loaders) { | ||
} | ||
// For testing | ||
export function _unregisterLoaders() { | ||
registeredLoaders = {}; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
726952
271
9871
2
337
5
9
0
48