@loaders.gl/json 3.1.0-alpha.2 → 4.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -4
- package/dist/bundle.js.map +1 -1
- package/dist/geojson-loader.js +1 -1
- package/dist/geojson-worker.js +1702 -2
- package/dist/json-loader.js +1 -1
- package/dist/lib/clarinet/clarinet.js +222 -260
- package/dist/lib/clarinet/clarinet.js.map +1 -1
- package/dist/lib/parse-ndjson-in-batches.js +1 -1
- package/dist/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/lib/parse-ndjson.js +1 -1
- package/dist/lib/parse-ndjson.js.map +1 -1
- package/dist/lib/parser/json-parser.js +48 -47
- package/dist/lib/parser/json-parser.js.map +1 -1
- package/dist/lib/parser/streaming-json-parser.js +29 -34
- package/dist/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/ndjson-loader.js +3 -1
- package/dist/ndjson-loader.js.map +1 -1
- package/package.json +7 -7
- package/src/bundle.ts +2 -3
- package/src/lib/clarinet/clarinet.ts +539 -0
- package/src/lib/parser/json-parser.ts +52 -55
- package/src/lib/parser/streaming-json-parser.ts +28 -32
- package/src/ndjson-loader.ts +3 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/geojson-worker.js.map +0 -1
- package/src/lib/clarinet/clarinet.js +0 -578
package/dist/geojson-worker.js
CHANGED
|
@@ -1,2 +1,1702 @@
|
|
|
1
|
-
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=30)}([function(t,e){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){t.exports=r(20)},function(t,e,r){var n=r(12);t.exports=function(t){return new n(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(22),o=r(23),i=r(14),s=r(24);t.exports=function(t){return n(t)||o(t)||i(t)||s()},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(21);t.exports=function(t){return function(){return new n(t.apply(this,arguments))}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){var e;if("undefined"!=typeof Symbol&&(Symbol.asyncIterator&&(e=t[Symbol.asyncIterator]),null==e&&Symbol.iterator&&(e=t[Symbol.iterator])),null==e&&(e=t["@@asyncIterator"]),null==e&&(e=t["@@iterator"]),null==e)throw new TypeError("Object is not async iterable");return e.call(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=r=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=r=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),r(e)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(t,e,r,n,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,o)}t.exports=function(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var s=t.apply(e,n);function a(t){r(s,o,i,a,u,"next",t)}function u(t){r(s,o,i,a,u,"throw",t)}a(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e){return t.exports=r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,r(e)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){this.wrapped=t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(13);t.exports=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(25),o=r(26),i=r(14),s=r(27);t.exports=function(t,e){return n(t)||o(t,e)||i(t,e)||s()},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(28);function o(e,r,i){return"undefined"!=typeof Reflect&&Reflect.get?(t.exports=o=Reflect.get,t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=o=function(t,e,r){var o=n(t,e);if(o){var i=Object.getOwnPropertyDescriptor(o,e);return i.get?i.get.call(r):i.value}},t.exports.default=t.exports,t.exports.__esModule=!0),o(e,r,i||e)}t.exports=o,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(29);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(9).default,o=r(8);t.exports=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?o(t):e},t.exports.default=t.exports,t.exports.__esModule=!0},,function(t,e,r){var n=function(t){"use strict";var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof h?e:h,i=Object.create(o.prototype),s=new j(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=w(s,r);if(a){if(a===l)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,s),i}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function h(){}function f(){}function p(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(_([])));v&&v!==e&&r.call(v,o)&&(d=v);var g=p.prototype=h.prototype=Object.create(d);function b(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(o,i){function s(){return new e((function(n,s){!function n(o,i,s,a){var u=c(t[o],t,i);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,s,a)}),(function(t){n("throw",t,s,a)})):e.resolve(h).then((function(t){l.value=t,s(l)}),(function(t){return n("throw",t,s,a)}))}a(u.arg)}(o,i,n,s)}))}return n=n?n.then(s,s):s()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return f.prototype=g.constructor=p,p.constructor=f,f.displayName=a(p,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,s,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(m.prototype),m.prototype[i]=function(){return this},t.AsyncIterator=m,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var s=new m(u(e,r,n,o),i);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},b(g),a(g,s,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(a&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=n}catch(t){Function("r","regeneratorRuntime = r")(n)}},function(t,e,r){var n=r(12);function o(t){var e,r;function o(e,r){try{var s=t[e](r),a=s.value,u=a instanceof n;Promise.resolve(u?a.wrapped:a).then((function(t){u?o("return"===e?"return":"next",t):i(s.done?"return":"normal",t)}),(function(t){o("throw",t)}))}catch(t){i("throw",t)}}function i(t,n){switch(t){case"return":e.resolve({value:n,done:!0});break;case"throw":e.reject(n);break;default:e.resolve({value:n,done:!1})}(e=e.next)?o(e.key,e.arg):r=null}this._invoke=function(t,n){return new Promise((function(i,s){var a={key:t,arg:n,resolve:i,reject:s,next:null};r?r=r.next=a:(e=r=a,o(t,n))}))},"function"!=typeof t.return&&(this.return=void 0)}o.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},o.prototype.next=function(t){return this._invoke("next",t)},o.prototype.throw=function(t){return this._invoke("throw",t)},o.prototype.return=function(t){return this._invoke("return",t)},t.exports=o,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(13);t.exports=function(t){if(Array.isArray(t))return n(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t,e){var r=t&&("undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"]);if(null!=r){var n,o,i=[],s=!0,a=!1;try{for(r=r.call(t);!(s=(n=r.next()).done)&&(i.push(n.value),!e||i.length!==e);s=!0);}catch(t){a=!0,o=t}finally{try{s||null==r.return||r.return()}finally{if(a)throw o}}return i}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(11);t.exports=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=n(t)););return t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e,n){return t.exports=r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,r(e,n)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){"use strict";r.r(e);var n=r(0),o=r.n(n),i=r(10),s=r.n(i),a=r(1),u=r.n(a),c=r(3),l=r.n(c),h=r(4),f=r.n(h),p=r(9),d=r.n(p);function y(t){return!!t&&(t instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&t instanceof MessagePort||("undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas)))}var v=new Map,g=function(){function t(){l()(this,t)}return f()(t,null,[{key:"onmessage",set:function(t){self.onmessage=function(e){if(b(e)){var r=e.data,n=r.type,o=r.payload;t(n,o)}}}},{key:"addEventListener",value:function(t){var e=v.get(t);e||(e=function(e){if(b(e)){var r=e.data,n=r.type,o=r.payload;t(n,o)}}),self.addEventListener("message",e)}},{key:"removeEventListener",value:function(t){var e=v.get(t);v.delete(t),self.removeEventListener("message",e)}},{key:"postMessage",value:function(t,e){if(self){var r={source:"loaders.gl",type:t,payload:e},n=function t(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2?arguments[2]:void 0,o=n||new Set;if(e){if(y(e))o.add(e);else if(y(e.buffer))o.add(e.buffer);else if(ArrayBuffer.isView(e));else if(r&&"object"===d()(e))for(var i in e)t(e[i],r,o)}else;return void 0===n?Array.from(o):[]}(e);self.postMessage(r,n)}}}]),t}();function b(t){var e=t.type,r=t.data;return"message"===e&&r&&"string"==typeof r.source&&r.source.startsWith("loaders.gl")}function m(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function w(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?m(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var x=0;function O(t,e){return new Promise((function(r,n){var o=x++;g.addEventListener((function t(e,i){if(i.id===o)switch(e){case"done":g.removeEventListener(t),r(i.result);break;case"error":g.removeEventListener(t),n(i.error)}}));var i={id:o,input:t,options:e};g.postMessage("process",i)}))}function j(t){return _.apply(this,arguments)}function _(){return(_=s()(u.a.mark((function t(e){var r,n,o,i,s,a,c;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.loader,n=e.arrayBuffer,o=e.options,i=e.context,!r.parseSync&&!r.parse){t.next=6;break}s=n,a=r.parseSync||r.parse,t.next=13;break;case 6:if(!r.parseTextSync){t.next=12;break}c=new TextDecoder,s=c.decode(n),a=r.parseTextSync,t.next=13;break;case 12:throw new Error("Could not load data with ".concat(r.name," loader"));case 13:return o=w(w({},o),{},{modules:r&&r.options&&r.options.modules||{},worker:!1}),t.next=16,a(s,w({},o),i,r);case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var k=r(2),A=r.n(k),P=r(6),E=r.n(P),S=r(7),L=r.n(S),C=r(5),I=r.n(C);function N(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function R(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?N(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):N(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function M(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return B(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return B(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function B(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function U(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=T(t);return F(t,r,{coordLength:e.coordLength||r.coordLength,numericPropKeys:e.numericPropKeys||r.numericPropKeys,PositionDataType:e.PositionDataType||Float32Array})}function T(t){var e,r,n=0,o=0,i=0,s=0,a=0,u=0,c=0,l=0,h=0,f=new Set,p={},d=M(t);try{for(d.s();!(e=d.n()).done;){var y=e.value,v=y.geometry;switch(v.type){case"Point":o++,n++,f.add(v.coordinates.length);break;case"MultiPoint":o++,n+=v.coordinates.length;var g,b=M(v.coordinates);try{for(b.s();!(g=b.n()).done;){var m=g.value;f.add(m.length)}}catch(t){b.e(t)}finally{b.f()}break;case"LineString":a++,i+=v.coordinates.length,s++;var w,x=M(v.coordinates);try{for(x.s();!(w=x.n()).done;){var O=w.value;f.add(O.length)}}catch(t){x.e(t)}finally{x.f()}break;case"MultiLineString":a++;var j,_=M(v.coordinates);try{for(_.s();!(j=_.n()).done;){var k=j.value;i+=k.length,s++;var A,P=M(k);try{for(P.s();!(A=P.n()).done;){var E=A.value;f.add(E.length)}}catch(t){P.e(t)}finally{P.f()}}}catch(t){_.e(t)}finally{_.f()}break;case"Polygon":h++,c++,l+=v.coordinates.length,u+=X(v.coordinates).length;var S,L=M(X(v.coordinates));try{for(L.s();!(S=L.n()).done;){var C=S.value;f.add(C.length)}}catch(t){L.e(t)}finally{L.f()}break;case"MultiPolygon":h++;var N,R=M(v.coordinates);try{for(R.s();!(N=R.n()).done;){var B=N.value;c++,l+=B.length,u+=X(B).length;var U,T=M(X(B));try{for(T.s();!(U=T.n()).done;){var F=U.value;f.add(F.length)}}catch(t){T.e(t)}finally{T.f()}}}catch(t){R.e(t)}finally{R.f()}break;default:throw new Error("Unsupported geometry type: ".concat(v.type))}if(y.properties)for(var D in y.properties){var J=y.properties[D];p[D]=p[D]||void 0===p[D]?(r=J,Number.isFinite(r)):p[D]}}}catch(t){d.e(t)}finally{d.f()}return{coordLength:f.size>0?Math.max.apply(Math,I()(f)):2,pointPositionsCount:n,pointFeaturesCount:o,linePositionsCount:i,linePathsCount:s,lineFeaturesCount:a,polygonPositionsCount:u,polygonObjectsCount:c,polygonRingsCount:l,polygonFeaturesCount:h,numericPropKeys:Object.keys(p).filter((function(t){return p[t]}))}}function F(t,e,r){for(var n=e.pointPositionsCount,o=e.pointFeaturesCount,i=e.linePositionsCount,s=e.linePathsCount,a=e.lineFeaturesCount,u=e.polygonPositionsCount,c=e.polygonObjectsCount,l=e.polygonRingsCount,h=e.polygonFeaturesCount,f=r.coordLength,p=r.numericPropKeys,d=r.PositionDataType,y=void 0===d?Float32Array:d,v=t.length>65535?Uint32Array:Uint16Array,g={positions:new y(n*f),globalFeatureIds:new v(n),featureIds:o>65535?new Uint32Array(n):new Uint16Array(n),numericProps:{},properties:Array(),fields:Array()},b={positions:new y(i*f),pathIndices:i>65535?new Uint32Array(s+1):new Uint16Array(s+1),globalFeatureIds:new v(i),featureIds:a>65535?new Uint32Array(i):new Uint16Array(i),numericProps:{},properties:Array(),fields:Array()},m={positions:new y(u*f),polygonIndices:u>65535?new Uint32Array(c+1):new Uint16Array(c+1),primitivePolygonIndices:u>65535?new Uint32Array(l+1):new Uint16Array(l+1),globalFeatureIds:new v(u),featureIds:h>65535?new Uint32Array(u):new Uint16Array(u),numericProps:{},properties:Array(),fields:Array()},w=0,x=[g,b,m];w<x.length;w++){var O,j=x[w],_=M(p||[]);try{for(_.s();!(O=_.n()).done;){var k=O.value;j.numericProps[k]=new Float32Array(j.positions.length/f)}}catch(t){_.e(t)}finally{_.f()}}b.pathIndices[s]=i,m.polygonIndices[c]=u,m.primitivePolygonIndices[l]=u;var A,P={pointPosition:0,pointFeature:0,linePosition:0,linePath:0,lineFeature:0,polygonPosition:0,polygonObject:0,polygonRing:0,polygonFeature:0,feature:0},E=M(t);try{for(E.s();!(A=E.n()).done;){var S=A.value,L=S.geometry,C=S.properties||{};switch(L.type){case"Point":D(L.coordinates,g,P,f,C),g.properties.push($(C,p)),P.pointFeature++;break;case"MultiPoint":J(L.coordinates,g,P,f,C),g.properties.push($(C,p)),P.pointFeature++;break;case"LineString":z(L.coordinates,b,P,f,C),b.properties.push($(C,p)),P.lineFeature++;break;case"MultiLineString":G(L.coordinates,b,P,f,C),b.properties.push($(C,p)),P.lineFeature++;break;case"Polygon":Y(L.coordinates,m,P,f,C),m.properties.push($(C,p)),P.polygonFeature++;break;case"MultiPolygon":V(L.coordinates,m,P,f,C),m.properties.push($(C,p)),P.polygonFeature++;break;default:throw new Error("Invalid geometry type")}P.feature++}}catch(t){E.e(t)}finally{E.f()}return function(t,e,r,n){var o={points:R(R({},t),{},{positions:{value:t.positions,size:n},globalFeatureIds:{value:t.globalFeatureIds,size:1},featureIds:{value:t.featureIds,size:1},type:"Point"}),lines:R(R({},e),{},{pathIndices:{value:e.pathIndices,size:1},positions:{value:e.positions,size:n},globalFeatureIds:{value:e.globalFeatureIds,size:1},featureIds:{value:e.featureIds,size:1},type:"LineString"}),polygons:R(R({},r),{},{polygonIndices:{value:r.polygonIndices,size:1},primitivePolygonIndices:{value:r.primitivePolygonIndices,size:1},positions:{value:r.positions,size:n},globalFeatureIds:{value:r.globalFeatureIds,size:1},featureIds:{value:r.featureIds,size:1},type:"Polygon"})};for(var i in o)for(var s in o[i].numericProps)o[i].numericProps[s]={value:o[i].numericProps[s],size:1};return o}(g,b,m,f)}function D(t,e,r,n,o){e.positions.set(t,r.pointPosition*n),e.globalFeatureIds[r.pointPosition]=r.feature,e.featureIds[r.pointPosition]=r.pointFeature,K(e,o,r.pointPosition,1),r.pointPosition++}function J(t,e,r,n,o){var i,s=M(t);try{for(s.s();!(i=s.n()).done;){D(i.value,e,r,n,o)}}catch(t){s.e(t)}finally{s.f()}}function z(t,e,r,n,o){e.pathIndices[r.linePath]=r.linePosition,r.linePath++,q(e.positions,t,r.linePosition,n);var i=t.length;K(e,o,r.linePosition,i),e.globalFeatureIds.set(new Uint32Array(i).fill(r.feature),r.linePosition),e.featureIds.set(new Uint32Array(i).fill(r.lineFeature),r.linePosition),r.linePosition+=i}function G(t,e,r,n,o){var i,s=M(t);try{for(s.s();!(i=s.n()).done;){z(i.value,e,r,n,o)}}catch(t){s.e(t)}finally{s.f()}}function Y(t,e,r,n,o){e.polygonIndices[r.polygonObject]=r.polygonPosition,r.polygonObject++;var i,s=M(t);try{for(s.s();!(i=s.n()).done;){var a=i.value;e.primitivePolygonIndices[r.polygonRing]=r.polygonPosition,r.polygonRing++,q(e.positions,a,r.polygonPosition,n);var u=a.length;K(e,o,r.polygonPosition,u),e.globalFeatureIds.set(new Uint32Array(u).fill(r.feature),r.polygonPosition),e.featureIds.set(new Uint32Array(u).fill(r.polygonFeature),r.polygonPosition),r.polygonPosition+=u}}catch(t){s.e(t)}finally{s.f()}}function V(t,e,r,n,o){var i,s=M(t);try{for(s.s();!(i=s.n()).done;){Y(i.value,e,r,n,o)}}catch(t){s.e(t)}finally{s.f()}}function K(t,e,r,n){for(var o in t.numericProps)o in e&&t.numericProps[o].set(new Array(n).fill(e[o]),r)}function $(t,e){var r={};for(var n in t)e.includes(n)||(r[n]=t[n]);return r}function q(t,e,r,n){var o,i=r*n,s=M(e);try{for(s.s();!(o=s.n()).done;){var a=o.value;t.set(a,i),i+=n}}catch(t){s.e(t)}finally{s.f()}}function X(t){var e;return(e=[]).concat.apply(e,I()(t))}function H(t,e){try{var r,n=JSON.parse(t);return null!==(r=e.json)&&void 0!==r&&r.table&&function t(e){if(Array.isArray(e))return e;if(e&&"object"===d()(e))for(var r=0,n=Object.values(e);r<n.length;r++){var o=n[r],i=t(o);if(i)return i}return null}(n)||n}catch(t){throw new Error("JSONLoader: failed to parse JSON")}}var W=function(){function t(e,r){if(l()(this,t),o()(this,"schema",void 0),o()(this,"options",void 0),o()(this,"length",0),o()(this,"rows",null),o()(this,"cursor",0),o()(this,"_headers",[]),this.options=r,this.schema=e,!Array.isArray(e))for(var n in this._headers=[],e)this._headers[e[n].index]=e[n].name}return f()(t,[{key:"rowCount",value:function(){return this.length}},{key:"addArrayRow",value:function(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}},{key:"addObjectRow",value:function(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}},{key:"getBatch",value:function(){var t=this.rows;return t?(t=t.slice(0,this.length),this.rows=null,{shape:this.options.shape,batchType:"data",data:t,length:this.length,schema:this.schema,cursor:this.cursor}):null}}]),t}();var Q=function(){function t(e,r){if(l()(this,t),o()(this,"schema",void 0),o()(this,"options",void 0),o()(this,"length",0),o()(this,"objectRows",null),o()(this,"arrayRows",null),o()(this,"cursor",0),o()(this,"_headers",[]),this.options=r,this.schema=e,!Array.isArray(e))for(var n in this._headers=[],e)this._headers[e[n].index]=e[n].name}return f()(t,[{key:"rowCount",value:function(){return this.length}},{key:"addArrayRow",value:function(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"object-row-table":var r=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");for(var r={},n=0;n<e.length;n++)r[e[n]]=t[n];return r}(t,this._headers);this.addObjectRow(r,e);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=t,this.length++}}},{key:"addObjectRow",value:function(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"array-row-table":var r=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");for(var r=new Array(e.length),n=0;n<e.length;n++)r[n]=t[e[n]];return r}(t,this._headers);this.addArrayRow(r,e);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=t,this.length++}}},{key:"getBatch",value:function(){var t=this.arrayRows||this.objectRows;return t?(t=t.slice(0,this.length),this.arrayRows=null,this.objectRows=null,{shape:this.options.shape,batchType:"data",data:t,length:this.length,schema:this.schema,cursor:this.cursor}):null}}]),t}(),Z=r(15),tt=r.n(Z),et=function(){function t(e,r){l()(this,t),o()(this,"schema",void 0),o()(this,"length",0),o()(this,"allocated",0),o()(this,"columns",{}),this.schema=e,this._reallocateColumns()}return f()(t,[{key:"rowCount",value:function(){return this.length}},{key:"addArrayRow",value:function(t){this._reallocateColumns();var e=0;for(var r in this.columns)this.columns[r][this.length]=t[e++];this.length++}},{key:"addObjectRow",value:function(t){for(var e in this._reallocateColumns(),t)this.columns[e][this.length]=t[e];this.length++}},{key:"getBatch",value:function(){this._pruneColumns();var t=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(var e in this.schema){var r=this.schema[e];t[r.name]=this.columns[r.index]}return this.columns={},{shape:"columnar-table",batchType:"data",data:t,schema:this.schema,length:this.length}}},{key:"_reallocateColumns",value:function(){if(!(this.length<this.allocated))for(var t in this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={},this.schema){var e=this.schema[t],r=e.type||Float32Array,n=this.columns[e.index];if(n&&ArrayBuffer.isView(n)){var o=new r(this.allocated);o.set(n),this.columns[e.index]=o}else n?(n.length=this.allocated,this.columns[e.index]=n):this.columns[e.index]=new r(this.allocated)}}},{key:"_pruneColumns",value:function(){for(var t=0,e=Object.entries(this.columns);t<e.length;t++){var r=tt()(e[t],2),n=r[0],o=r[1];this.columns[n]=o.slice(0,this.length)}}}]),t}();function rt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function nt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):rt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var ot={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0},it=function(){function t(e,r){l()(this,t),o()(this,"schema",void 0),o()(this,"options",void 0),o()(this,"aggregator",null),o()(this,"batchCount",0),o()(this,"bytesUsed",0),o()(this,"isChunkComplete",!1),o()(this,"lastBatchEmittedMs",Date.now()),o()(this,"totalLength",0),o()(this,"totalBytes",0),o()(this,"rowBytes",0),this.schema=e,this.options=nt(nt({},ot),r)}return f()(t,[{key:"limitReached",value:function(){var t,e;return!!(Boolean(null===(t=this.options)||void 0===t?void 0:t.limit)&&this.totalLength>=this.options.limit)||!!(Boolean(null===(e=this.options)||void 0===e?void 0:e._limitMB)&&this.totalBytes/1e6>=this.options._limitMB)}},{key:"addRow",value:function(t){this.limitReached()||(this.totalLength++,this.rowBytes=this.rowBytes||this._estimateRowMB(t),this.totalBytes+=this.rowBytes,Array.isArray(t)?this.addArrayRow(t):this.addObjectRow(t))}},{key:"addArrayRow",value:function(t){if(!this.aggregator){var e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addArrayRow(t)}},{key:"addObjectRow",value:function(t){if(!this.aggregator){var e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addObjectRow(t)}},{key:"chunkComplete",value:function(t){t instanceof ArrayBuffer&&(this.bytesUsed+=t.byteLength),"string"==typeof t&&(this.bytesUsed+=t.length),this.isChunkComplete=!0}},{key:"getFullBatch",value:function(t){return this._isFull()?this._getBatch(t):null}},{key:"getFinalBatch",value:function(t){return this._getBatch(t)}},{key:"_estimateRowMB",value:function(t){return Array.isArray(t)?8*t.length:8*Object.keys(t).length}},{key:"_isFull",value:function(){if(!this.aggregator||0===this.aggregator.rowCount())return!1;if("auto"===this.options.batchSize){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return!(this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs)&&(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}},{key:"_getBatch",value:function(t){if(!this.aggregator)return null;null!=t&&t.bytesUsed&&(this.bytesUsed=t.bytesUsed);var e=this.aggregator.getBatch();return e.count=this.batchCount,e.bytesUsed=this.bytesUsed,Object.assign(e,t),this.batchCount++,this.aggregator=null,e}},{key:"_getTableBatchType",value:function(){switch(this.options.shape){case"row-table":return W;case"array-row-table":case"object-row-table":return Q;case"columnar-table":return et;case"arrow-table":if(!t.ArrowBatch)throw new Error("TableBatchBuilder");return t.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}]),t}();function st(t){return at.apply(this,arguments)}function at(){return(at=E()(u.a.mark((function t(e){var r,n,o,i,s,a,c,l,h,f=arguments;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=f.length>1&&void 0!==f[1]?f[1]:{},n=new TextDecoder(void 0,r),o=!0,i=!1,t.prev=4,a=L()(e);case 6:return t.next=8,A()(a.next());case 8:return c=t.sent,o=c.done,t.next=12,A()(c.value);case 12:if(l=t.sent,o){t.next=20;break}return h=l,t.next=17,"string"==typeof h?h:n.decode(h,{stream:!0});case 17:o=!0,t.next=6;break;case 20:t.next=26;break;case 22:t.prev=22,t.t0=t.catch(4),i=!0,s=t.t0;case 26:if(t.prev=26,t.prev=27,o||null==a.return){t.next=31;break}return t.next=31,A()(a.return());case 31:if(t.prev=31,!i){t.next=34;break}throw s;case 34:return t.finish(31);case 35:return t.finish(26);case 36:case"end":return t.stop()}}),t,null,[[4,22,26,36],[27,,31,35]])})))).apply(this,arguments)}o()(it,"ArrowBatch",void 0);var ut=r(8),ct=r.n(ut),lt=r(16),ht=r.n(lt),ft=r(17),pt=r.n(ft),dt=r(18),yt=r.n(dt),vt=r(11),gt=r.n(vt),bt=Number.MAX_SAFE_INTEGER,mt="debug"==={}.CDEBUG,wt={textNode:void 0,numberNode:""},xt=0,Ot={BEGIN:xt++,VALUE:xt++,OPEN_OBJECT:xt++,CLOSE_OBJECT:xt++,OPEN_ARRAY:xt++,CLOSE_ARRAY:xt++,TEXT_ESCAPE:xt++,STRING:xt++,BACKSLASH:xt++,END:xt++,OPEN_KEY:xt++,CLOSE_KEY:xt++,TRUE:xt++,TRUE2:xt++,TRUE3:xt++,FALSE:xt++,FALSE2:xt++,FALSE3:xt++,FALSE4:xt++,NULL:xt++,NULL2:xt++,NULL3:xt++,NUMBER_DECIMAL_POINT:xt++,NUMBER_DIGIT:xt++};for(var jt in Ot)Ot[Ot[jt]]=jt;xt=Ot;var _t=9,kt=10,At=13,Pt=32,Et=34,St=43,Lt=44,Ct=45,It=46,Nt=48,Rt=57,Mt=58,Bt=69,Ut=91,Tt=92,Ft=93,Dt=97,Jt=98,zt=101,Gt=102,Yt=108,Vt=110,Kt=114,$t=115,qt=116,Xt=117,Ht=123,Wt=125;var Qt=/[\\"\n]/g,Zt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};l()(this,t),this._initialize(e)}return f()(t,[{key:"_initialize",value:function(t){this._clearBuffers(this),this.bufferCheckPosition=bt,this.q="",this.c="",this.p="",this.options=t||{},this.closed=!1,this.closedRoot=!1,this.sawRoot=!1,this.tag=null,this.error=null,this.state=xt.BEGIN,this.stack=new Array,this.position=this.column=0,this.line=1,this.slashed=!1,this.unicodeI=0,this.unicodeS=null,this.depth=0,"onready"in t&&(this.onready=t.onready),"onopenobject"in t&&(this.onopenobject=t.onopenobject),"onkey"in t&&(this.onkey=t.onkey),"oncloseobject"in t&&(this.oncloseobject=t.oncloseobject),"onopenarray"in t&&(this.onopenarray=t.onopenarray),"onclosearray"in t&&(this.onclosearray=t.onclosearray),"onvalue"in t&&(this.onvalue=t.onvalue),"onerror"in t&&(this.onerror=t.onerror),"onend"in t&&(this.onend=t.onend),"onchunkparsed"in t&&(this.onchunkparsed=t.onchunkparsed),te(this,"onready")}},{key:"_clearBuffers",value:function(){for(var t in wt)this[t]=wt[t]}},{key:"end",value:function(){return this.state===xt.VALUE&&0===this.depth||oe(this,"Unexpected end"),re(this),this.c="",this.closed=!0,te(this,"onend"),this._initialize(this.options),this}},{key:"resume",value:function(){return this.error=null,this}},{key:"close",value:function(){return this.write(null)}},{key:"write",value:function(t){if(this.error)throw this.error;if(this.closed)return oe(this,"Cannot write after close. Assign an onready handler.");if(null===t)return this.end();var e=0,r=t.charCodeAt(0),n=this.p;for(mt&&console.log("write -> ["+t+"]");r&&(n=r,this.c=r=t.charCodeAt(e++),n!==r?this.p=n:n=this.p,r);)switch(mt&&console.log(e,r,Ot[this.state]),this.position++,r===kt?(this.line++,this.column=0):this.column++,this.state){case xt.BEGIN:r===Ht?this.state=xt.OPEN_OBJECT:r===Ut?this.state=xt.OPEN_ARRAY:ie(r)||oe(this,"Non-whitespace before {[.");continue;case xt.OPEN_KEY:case xt.OPEN_OBJECT:if(ie(r))continue;if(this.state===xt.OPEN_KEY)this.stack.push(xt.CLOSE_KEY);else{if(r===Wt){te(this,"onopenobject"),this.depth++,te(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||xt.VALUE;continue}this.stack.push(xt.CLOSE_OBJECT)}r===Et?this.state=xt.STRING:oe(this,'Malformed object key should start with "');continue;case xt.CLOSE_KEY:case xt.CLOSE_OBJECT:if(ie(r))continue;this.state,xt.CLOSE_KEY;r===Mt?(this.state===xt.CLOSE_OBJECT?(this.stack.push(xt.CLOSE_OBJECT),re(this,"onopenobject"),this.depth++):re(this,"onkey"),this.state=xt.VALUE):r===Wt?(ee(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||xt.VALUE):r===Lt?(this.state===xt.CLOSE_OBJECT&&this.stack.push(xt.CLOSE_OBJECT),re(this),this.state=xt.OPEN_KEY):oe(this,"Bad object");continue;case xt.OPEN_ARRAY:case xt.VALUE:if(ie(r))continue;if(this.state===xt.OPEN_ARRAY){if(te(this,"onopenarray"),this.depth++,this.state=xt.VALUE,r===Ft){te(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||xt.VALUE;continue}this.stack.push(xt.CLOSE_ARRAY)}r===Et?this.state=xt.STRING:r===Ht?this.state=xt.OPEN_OBJECT:r===Ut?this.state=xt.OPEN_ARRAY:r===qt?this.state=xt.TRUE:r===Gt?this.state=xt.FALSE:r===Vt?this.state=xt.NULL:r===Ct?this.numberNode+="-":Nt<=r&&r<=Rt?(this.numberNode+=String.fromCharCode(r),this.state=xt.NUMBER_DIGIT):oe(this,"Bad value");continue;case xt.CLOSE_ARRAY:if(r===Lt)this.stack.push(xt.CLOSE_ARRAY),re(this,"onvalue"),this.state=xt.VALUE;else if(r===Ft)ee(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||xt.VALUE;else{if(ie(r))continue;oe(this,"Bad array")}continue;case xt.STRING:void 0===this.textNode&&(this.textNode="");var o=e-1,i=this.slashed,s=this.unicodeI;t:for(;;){for(mt&&console.log(e,r,Ot[this.state],i);s>0;)if(this.unicodeS+=String.fromCharCode(r),r=t.charCodeAt(e++),this.position++,4===s?(this.textNode+=String.fromCharCode(parseInt(this.unicodeS,16)),s=0,o=e-1):s++,!r)break t;if(r===Et&&!i){this.state=this.stack.pop()||xt.VALUE,this.textNode+=t.substring(o,e-1),this.position+=e-1-o;break}if(r===Tt&&!i&&(i=!0,this.textNode+=t.substring(o,e-1),this.position+=e-1-o,r=t.charCodeAt(e++),this.position++,!r))break;if(i){if(i=!1,r===Vt?this.textNode+="\n":r===Kt?this.textNode+="\r":r===qt?this.textNode+="\t":r===Gt?this.textNode+="\f":r===Jt?this.textNode+="\b":r===Xt?(s=1,this.unicodeS=""):this.textNode+=String.fromCharCode(r),r=t.charCodeAt(e++),this.position++,o=e-1,r)continue;break}Qt.lastIndex=e;var a=Qt.exec(t);if(null===a){e=t.length+1,this.textNode+=t.substring(o,e-1),this.position+=e-1-o;break}if(e=a.index+1,!(r=t.charCodeAt(a.index))){this.textNode+=t.substring(o,e-1),this.position+=e-1-o;break}}this.slashed=i,this.unicodeI=s;continue;case xt.TRUE:r===Kt?this.state=xt.TRUE2:oe(this,"Invalid true started with t"+r);continue;case xt.TRUE2:r===Xt?this.state=xt.TRUE3:oe(this,"Invalid true started with tr"+r);continue;case xt.TRUE3:r===zt?(te(this,"onvalue",!0),this.state=this.stack.pop()||xt.VALUE):oe(this,"Invalid true started with tru"+r);continue;case xt.FALSE:r===Dt?this.state=xt.FALSE2:oe(this,"Invalid false started with f"+r);continue;case xt.FALSE2:r===Yt?this.state=xt.FALSE3:oe(this,"Invalid false started with fa"+r);continue;case xt.FALSE3:r===$t?this.state=xt.FALSE4:oe(this,"Invalid false started with fal"+r);continue;case xt.FALSE4:r===zt?(te(this,"onvalue",!1),this.state=this.stack.pop()||xt.VALUE):oe(this,"Invalid false started with fals"+r);continue;case xt.NULL:r===Xt?this.state=xt.NULL2:oe(this,"Invalid null started with n"+r);continue;case xt.NULL2:r===Yt?this.state=xt.NULL3:oe(this,"Invalid null started with nu"+r);continue;case xt.NULL3:r===Yt?(te(this,"onvalue",null),this.state=this.stack.pop()||xt.VALUE):oe(this,"Invalid null started with nul"+r);continue;case xt.NUMBER_DECIMAL_POINT:r===It?(this.numberNode+=".",this.state=xt.NUMBER_DIGIT):oe(this,"Leading zero not followed by .");continue;case xt.NUMBER_DIGIT:Nt<=r&&r<=Rt?this.numberNode+=String.fromCharCode(r):r===It?(-1!==this.numberNode.indexOf(".")&&oe(this,"Invalid number has two dots"),this.numberNode+="."):r===zt||r===Bt?(-1===this.numberNode.indexOf("e")&&-1===this.numberNode.indexOf("E")||oe(this,"Invalid number has two exponential"),this.numberNode+="e"):r===St||r===Ct?(n!==zt&&n!==Bt&&oe(this,"Invalid symbol in number"),this.numberNode+=String.fromCharCode(r)):(ne(this),e--,this.state=this.stack.pop()||xt.VALUE);continue;default:oe(this,"Unknown state: "+this.state)}return this.position>=this.bufferCheckPosition&&function(t){var e=Math.max(bt,10),r=0;for(var n in wt){var o=void 0===t[n]?0:t[n].length;if(o>e)switch(n){case"text":closeText(t);break;default:oe(t,"Max buffer length exceeded: "+n)}r=Math.max(r,o)}t.bufferCheckPosition=bt-r+t.position}(this),te(this,"onchunkparsed"),this}}]),t}();function te(t,e,r){mt&&console.log("-- emit",e,r),t[e]&&t[e](r,t)}function ee(t,e,r){re(t),te(t,e,r)}function re(t,e){t.textNode=function(t,e){if(void 0===e)return e;t.trim&&(e=e.trim());t.normalize&&(e=e.replace(/\s+/g," "));return e}(t.options,t.textNode),void 0!==t.textNode&&te(t,e||"onvalue",t.textNode),t.textNode=void 0}function ne(t){t.numberNode&&te(t,"onvalue",parseFloat(t.numberNode)),t.numberNode=""}function oe(t,e){return re(t),e+="\nLine: "+t.line+"\nColumn: "+t.column+"\nChar: "+t.c,e=new Error(e),t.error=e,te(t,"onerror",e),t}function ie(t){return t===At||t===kt||t===Pt||t===_t}function se(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return ae(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return ae(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function ae(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var ue=function(){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(l()(this,t),o()(this,"path",void 0),this.path=["$"],r instanceof t)this.path=I()(r.path);else if(Array.isArray(r))(e=this.path).push.apply(e,I()(r));else if("string"==typeof r&&(this.path=r.split("."),"$"!==this.path[0]))throw new Error("JSONPaths must start with $")}return f()(t,[{key:"clone",value:function(){return new t(this)}},{key:"toString",value:function(){return this.path.join(".")}},{key:"push",value:function(t){this.path.push(t)}},{key:"pop",value:function(){return this.path.pop()}},{key:"set",value:function(t){this.path[this.path.length-1]=t}},{key:"equals",value:function(t){if(!this||!t||this.path.length!==t.path.length)return!1;for(var e=0;e<this.path.length;++e)if(this.path[e]!==t.path[e])return!1;return!0}},{key:"setFieldAtPath",value:function(t,e){var r=I()(this.path);r.shift();var n,o=r.pop(),i=se(r);try{for(i.s();!(n=i.n()).done;){t=t[n.value]}}catch(t){i.e(t)}finally{i.f()}t[o]=e}},{key:"getFieldAtPath",value:function(t){var e=I()(this.path);e.shift();var r,n=e.pop(),o=se(e);try{for(o.s();!(r=o.n()).done;){t=t[r.value]}}catch(t){o.e(t)}finally{o.f()}return t[n]}}]),t}();function ce(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return le(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return le(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function le(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function he(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=gt()(t);if(e){var o=gt()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return yt()(this,r)}}var fe=function(t){pt()(r,t);var e=he(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};l()(this,r),t=e.call(this),o()(ct()(t),"jsonPaths",void 0),o()(ct()(t),"streamingJsonPath",null),o()(ct()(t),"streamingArray",null),o()(ct()(t),"topLevelObject",null);var i=n.jsonpaths||[];return t.jsonPaths=i.map((function(t){return new ue(t)})),t._extendParser(),t}return f()(r,[{key:"write",value:function(t){ht()(gt()(r.prototype),"write",this).call(this,t);var e=[];return this.streamingArray&&(e=I()(this.streamingArray),this.streamingArray.length=0),e}},{key:"getPartialResult",value:function(){return this.topLevelObject}},{key:"getStreamingJsonPath",value:function(){return this.streamingJsonPath}},{key:"getStreamingJsonPathAsString",value:function(){return this.streamingJsonPath&&this.streamingJsonPath.toString()}},{key:"getJsonPath",value:function(){return this.jsonpath}},{key:"_matchJSONPath",value:function(){var t=this.getJsonPath();if(0===this.jsonPaths.length)return!0;var e,r=ce(this.jsonPaths);try{for(r.s();!(e=r.n()).done;){if(e.value.equals(t))return!0}}catch(t){r.e(t)}finally{r.f()}return!1}},{key:"_extendParser",value:function(){var t=this;this.parser.onopenarray=function(){if(!t.streamingArray&&t._matchJSONPath())return t.streamingJsonPath=t.getJsonPath().clone(),t.streamingArray=[],void t._openArray(t.streamingArray);t._openArray()},this.parser.onopenobject=function(e){t.topLevelObject?t._openObject({}):(t.topLevelObject={},t._openObject(t.topLevelObject)),void 0!==e&&t.parser.onkey(e)}}}]),r}(function(){function t(){l()(this,t),o()(this,"jsonpath",void 0),o()(this,"_parser",void 0),this.reset(),this._initializeParser()}return f()(t,[{key:"reset",value:function(){this.result=void 0,this.previousStates=[],this.currentState=Object.freeze({container:[],key:null}),this.jsonpath=new ue}},{key:"write",value:function(t){this.parser.write(t)}},{key:"close",value:function(){this.parser.close()}},{key:"_pushOrSet",value:function(t){var e=this.currentState,r=e.container,n=e.key;null!==n?(r[n]=t,this.currentState.key=null):r.push(t)}},{key:"_openArray",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!0,key:null}}},{key:"_closeArray",value:function(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}},{key:"_openObject",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!1,key:null}}},{key:"_closeObject",value:function(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}},{key:"_initializeParser",value:function(){var t=this;this._parser=new Zt({onready:function(){t.jsonpath=new ue,t.previousStates.length=0,t.currentState.container.length=0},onopenobject:function(e){t._openObject({}),void 0!==e&&t.parser.onkey(e)},onkey:function(e){t.jsonpath.set(e),t.currentState.key=e},oncloseobject:function(){t._closeObject()},onopenarray:function(){t._openArray()},onclosearray:function(){t._closeArray()},onvalue:function(e){t._pushOrSet(e)},onerror:function(t){throw t},onend:function(){t.result=t.currentState.container.pop()}})}},{key:"parser",get:function(){return this._parser}}]),t}());function pe(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return de(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return de(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function de(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function ye(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function ve(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ye(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ye(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function ge(){return(ge=E()(u.a.mark((function t(e,r){var n,o,i,s,a,c,l,h,f,p,d,y,v,g,b,m,w,x,O,j,_,k,P,E,S,C,I;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=st(e),i=r.metadata,s=r.json||{},a=s.jsonpaths,c=!0,null,l=(null==r||null===(n=r.json)||void 0===n?void 0:n.shape)||"row-table",h=new it(null,ve(ve({},r),{},{shape:l})),f=new fe({jsonpaths:a}),p=!0,d=!1,t.prev=10,v=L()(o);case 12:return t.next=14,A()(v.next());case 14:return g=t.sent,p=g.done,t.next=18,A()(g.value);case 18:if(b=t.sent,p){t.next=57;break}if(m=b,w=f.write(m),x=w.length>0&&f.getStreamingJsonPathAsString(),!(w.length>0&&c)){t.next=29;break}if(!i){t.next=28;break}return O={shape:l,batchType:"partial-result",data:[],length:0,bytesUsed:0,container:f.getPartialResult(),jsonpath:x},t.next=28,O;case 28:c=!1;case 29:j=pe(w),t.prev=30,j.s();case 32:if((_=j.n()).done){t.next=41;break}if(k=_.value,h.addRow(k),!(P=h.getFullBatch({jsonpath:x}))){t.next=39;break}return t.next=39,P;case 39:t.next=32;break;case 41:t.next=46;break;case 43:t.prev=43,t.t0=t.catch(30),j.e(t.t0);case 46:return t.prev=46,j.f(),t.finish(46);case 49:if(h.chunkComplete(m),!(E=h.getFullBatch({jsonpath:x}))){t.next=54;break}return t.next=54,E;case 54:p=!0,t.next=12;break;case 57:t.next=63;break;case 59:t.prev=59,t.t1=t.catch(10),d=!0,y=t.t1;case 63:if(t.prev=63,t.prev=64,p||null==v.return){t.next=68;break}return t.next=68,A()(v.return());case 68:if(t.prev=68,!d){t.next=71;break}throw y;case 71:return t.finish(68);case 72:return t.finish(63);case 73:if(S=f.getStreamingJsonPathAsString(),!(C=h.getFinalBatch({jsonpath:S}))){t.next=78;break}return t.next=78,C;case 78:if(!i){t.next=82;break}return I={shape:l,batchType:"final-result",container:f.getPartialResult(),jsonpath:f.getStreamingJsonPathAsString(),data:[],length:0},t.next=82,I;case 82:case"end":return t.stop()}}),t,null,[[10,59,63,73],[30,43,46,49],[64,,68,72]])})))).apply(this,arguments)}function be(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function me(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?be(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):be(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var we,xe={geojson:{shape:"object-row-table"},json:{jsonpaths:["$","$.features"]},gis:{format:"geojson"}},Oe=me(me({},{name:"GeoJSON",id:"geojson",module:"geojson",version:"3.1.0-alpha.2",worker:!0,extensions:["geojson"],mimeTypes:["application/geo+json"],category:"geometry",text:!0,options:xe}),{},{parse:function(t,e){return je.apply(this,arguments)},parseTextSync:_e,parseInBatches:function(t,e){(e=me(me({},xe),e)).json=me(me({},xe.geojson),e.geojson);var r=function(t,e){return ge.apply(this,arguments)}(t,e);switch(e.gis.format){case"binary":return function(t){return ke.apply(this,arguments)}(r);default:return r}}});function je(){return(je=s()(u.a.mark((function t(e,r){return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",_e((new TextDecoder).decode(e),r));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _e(t,e){(e=me(me({},xe),e)).json=me(me({},xe.geojson),e.geojson),e.gis=e.gis||{};var r=H(t,e);switch(e.gis.format){case"binary":return U(r);default:return r}}function ke(){return(ke=E()(u.a.mark((function t(e){var r,n,o,i,s,a,c;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=!0,n=!1,t.prev=2,i=L()(e);case 4:return t.next=6,A()(i.next());case 6:return s=t.sent,r=s.done,t.next=10,A()(s.value);case 10:if(a=t.sent,r){t.next=19;break}return(c=a).data=U(c.data),t.next=16,c;case 16:r=!0,t.next=4;break;case 19:t.next=25;break;case 21:t.prev=21,t.t0=t.catch(2),n=!0,o=t.t0;case 25:if(t.prev=25,t.prev=26,r||null==i.return){t.next=30;break}return t.next=30,A()(i.return());case 30:if(t.prev=30,!n){t.next=33;break}throw o;case 33:return t.finish(30);case 34:return t.finish(25);case 35:case"end":return t.stop()}}),t,null,[[2,21,25,35],[26,,30,34]])})))).apply(this,arguments)}we=Oe,"undefined"!=typeof self&&(g.onmessage=function(){var t=s()(u.a.mark((function t(e,r){var n,o,i,s,a;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=e,t.next="process"===t.t0?3:16;break;case 3:return t.prev=3,n=r.input,o=r.options,i=void 0===o?{}:o,t.next=7,j({loader:we,arrayBuffer:n,options:i,context:{parse:O}});case 7:s=t.sent,g.postMessage("done",{result:s}),t.next=15;break;case 11:t.prev=11,t.t1=t.catch(3),a=t.t1 instanceof Error?t.t1.message:"",g.postMessage("error",{error:a});case 15:return t.abrupt("break",16);case 16:case"end":return t.stop()}}),t,null,[[3,11]])})));return function(e,r){return t.apply(this,arguments)}}())}]);
|
|
2
|
-
|
|
1
|
+
(() => {
|
|
2
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
3
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
4
|
+
const transfersSet = transfers || new Set();
|
|
5
|
+
if (!object) {
|
|
6
|
+
} else if (isTransferable(object)) {
|
|
7
|
+
transfersSet.add(object);
|
|
8
|
+
} else if (isTransferable(object.buffer)) {
|
|
9
|
+
transfersSet.add(object.buffer);
|
|
10
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
11
|
+
} else if (recursive && typeof object === "object") {
|
|
12
|
+
for (const key in object) {
|
|
13
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
17
|
+
}
|
|
18
|
+
function isTransferable(object) {
|
|
19
|
+
if (!object) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (object instanceof ArrayBuffer) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
38
|
+
var onMessageWrapperMap = new Map();
|
|
39
|
+
var WorkerBody = class {
|
|
40
|
+
static set onmessage(onMessage) {
|
|
41
|
+
self.onmessage = (message) => {
|
|
42
|
+
if (!isKnownMessage(message)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { type, payload } = message.data;
|
|
46
|
+
onMessage(type, payload);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static addEventListener(onMessage) {
|
|
50
|
+
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
51
|
+
if (!onMessageWrapper) {
|
|
52
|
+
onMessageWrapper = (message) => {
|
|
53
|
+
if (!isKnownMessage(message)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { type, payload } = message.data;
|
|
57
|
+
onMessage(type, payload);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
self.addEventListener("message", onMessageWrapper);
|
|
61
|
+
}
|
|
62
|
+
static removeEventListener(onMessage) {
|
|
63
|
+
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
64
|
+
onMessageWrapperMap.delete(onMessage);
|
|
65
|
+
self.removeEventListener("message", onMessageWrapper);
|
|
66
|
+
}
|
|
67
|
+
static postMessage(type, payload) {
|
|
68
|
+
if (self) {
|
|
69
|
+
const data = { source: "loaders.gl", type, payload };
|
|
70
|
+
const transferList = getTransferList(payload);
|
|
71
|
+
self.postMessage(data, transferList);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function isKnownMessage(message) {
|
|
76
|
+
const { type, data } = message;
|
|
77
|
+
return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
81
|
+
var requestId = 0;
|
|
82
|
+
function createLoaderWorker(loader) {
|
|
83
|
+
if (typeof self === "undefined") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
WorkerBody.onmessage = async (type, payload) => {
|
|
87
|
+
switch (type) {
|
|
88
|
+
case "process":
|
|
89
|
+
try {
|
|
90
|
+
const { input, options = {} } = payload;
|
|
91
|
+
const result = await parseData({
|
|
92
|
+
loader,
|
|
93
|
+
arrayBuffer: input,
|
|
94
|
+
options,
|
|
95
|
+
context: {
|
|
96
|
+
parse: parseOnMainThread
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
WorkerBody.postMessage("done", { result });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const message = error instanceof Error ? error.message : "";
|
|
102
|
+
WorkerBody.postMessage("error", { error: message });
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function parseOnMainThread(arrayBuffer, options) {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const id = requestId++;
|
|
112
|
+
const onMessage = (type, payload2) => {
|
|
113
|
+
if (payload2.id !== id) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
switch (type) {
|
|
117
|
+
case "done":
|
|
118
|
+
WorkerBody.removeEventListener(onMessage);
|
|
119
|
+
resolve(payload2.result);
|
|
120
|
+
break;
|
|
121
|
+
case "error":
|
|
122
|
+
WorkerBody.removeEventListener(onMessage);
|
|
123
|
+
reject(payload2.error);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
WorkerBody.addEventListener(onMessage);
|
|
129
|
+
const payload = { id, input: arrayBuffer, options };
|
|
130
|
+
WorkerBody.postMessage("process", payload);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async function parseData({ loader, arrayBuffer, options, context }) {
|
|
134
|
+
let data;
|
|
135
|
+
let parser;
|
|
136
|
+
if (loader.parseSync || loader.parse) {
|
|
137
|
+
data = arrayBuffer;
|
|
138
|
+
parser = loader.parseSync || loader.parse;
|
|
139
|
+
} else if (loader.parseTextSync) {
|
|
140
|
+
const textDecoder = new TextDecoder();
|
|
141
|
+
data = textDecoder.decode(arrayBuffer);
|
|
142
|
+
parser = loader.parseTextSync;
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
145
|
+
}
|
|
146
|
+
options = {
|
|
147
|
+
...options,
|
|
148
|
+
modules: loader && loader.options && loader.options.modules || {},
|
|
149
|
+
worker: false
|
|
150
|
+
};
|
|
151
|
+
return await parser(data, { ...options }, context, loader);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
155
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
156
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
157
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
158
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ../gis/src/lib/geojson-to-binary.ts
|
|
163
|
+
function geojsonToBinary(features, options = {}) {
|
|
164
|
+
const firstPassData = firstPass(features);
|
|
165
|
+
return secondPass(features, firstPassData, {
|
|
166
|
+
coordLength: options.coordLength || firstPassData.coordLength,
|
|
167
|
+
numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
|
|
168
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function firstPass(features) {
|
|
172
|
+
let pointPositionsCount = 0;
|
|
173
|
+
let pointFeaturesCount = 0;
|
|
174
|
+
let linePositionsCount = 0;
|
|
175
|
+
let linePathsCount = 0;
|
|
176
|
+
let lineFeaturesCount = 0;
|
|
177
|
+
let polygonPositionsCount = 0;
|
|
178
|
+
let polygonObjectsCount = 0;
|
|
179
|
+
let polygonRingsCount = 0;
|
|
180
|
+
let polygonFeaturesCount = 0;
|
|
181
|
+
const coordLengths = new Set();
|
|
182
|
+
const numericPropKeys = {};
|
|
183
|
+
for (const feature of features) {
|
|
184
|
+
const geometry = feature.geometry;
|
|
185
|
+
switch (geometry.type) {
|
|
186
|
+
case "Point":
|
|
187
|
+
pointFeaturesCount++;
|
|
188
|
+
pointPositionsCount++;
|
|
189
|
+
coordLengths.add(geometry.coordinates.length);
|
|
190
|
+
break;
|
|
191
|
+
case "MultiPoint":
|
|
192
|
+
pointFeaturesCount++;
|
|
193
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
194
|
+
for (const point of geometry.coordinates) {
|
|
195
|
+
coordLengths.add(point.length);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case "LineString":
|
|
199
|
+
lineFeaturesCount++;
|
|
200
|
+
linePositionsCount += geometry.coordinates.length;
|
|
201
|
+
linePathsCount++;
|
|
202
|
+
for (const coord of geometry.coordinates) {
|
|
203
|
+
coordLengths.add(coord.length);
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
case "MultiLineString":
|
|
207
|
+
lineFeaturesCount++;
|
|
208
|
+
for (const line of geometry.coordinates) {
|
|
209
|
+
linePositionsCount += line.length;
|
|
210
|
+
linePathsCount++;
|
|
211
|
+
for (const coord of line) {
|
|
212
|
+
coordLengths.add(coord.length);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
case "Polygon":
|
|
217
|
+
polygonFeaturesCount++;
|
|
218
|
+
polygonObjectsCount++;
|
|
219
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
220
|
+
polygonPositionsCount += flatten(geometry.coordinates).length;
|
|
221
|
+
for (const coord of flatten(geometry.coordinates)) {
|
|
222
|
+
coordLengths.add(coord.length);
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
case "MultiPolygon":
|
|
226
|
+
polygonFeaturesCount++;
|
|
227
|
+
for (const polygon of geometry.coordinates) {
|
|
228
|
+
polygonObjectsCount++;
|
|
229
|
+
polygonRingsCount += polygon.length;
|
|
230
|
+
polygonPositionsCount += flatten(polygon).length;
|
|
231
|
+
for (const coord of flatten(polygon)) {
|
|
232
|
+
coordLengths.add(coord.length);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
default:
|
|
237
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
238
|
+
}
|
|
239
|
+
if (feature.properties) {
|
|
240
|
+
for (const key in feature.properties) {
|
|
241
|
+
const val = feature.properties[key];
|
|
242
|
+
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === void 0 ? isNumeric(val) : numericPropKeys[key];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
248
|
+
pointPositionsCount,
|
|
249
|
+
pointFeaturesCount,
|
|
250
|
+
linePositionsCount,
|
|
251
|
+
linePathsCount,
|
|
252
|
+
lineFeaturesCount,
|
|
253
|
+
polygonPositionsCount,
|
|
254
|
+
polygonObjectsCount,
|
|
255
|
+
polygonRingsCount,
|
|
256
|
+
polygonFeaturesCount,
|
|
257
|
+
numericPropKeys: Object.keys(numericPropKeys).filter((k) => numericPropKeys[k])
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function secondPass(features, firstPassData, options) {
|
|
261
|
+
const {
|
|
262
|
+
pointPositionsCount,
|
|
263
|
+
pointFeaturesCount,
|
|
264
|
+
linePositionsCount,
|
|
265
|
+
linePathsCount,
|
|
266
|
+
lineFeaturesCount,
|
|
267
|
+
polygonPositionsCount,
|
|
268
|
+
polygonObjectsCount,
|
|
269
|
+
polygonRingsCount,
|
|
270
|
+
polygonFeaturesCount
|
|
271
|
+
} = firstPassData;
|
|
272
|
+
const { coordLength, numericPropKeys, PositionDataType = Float32Array } = options;
|
|
273
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
274
|
+
const points = {
|
|
275
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
276
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
277
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
278
|
+
numericProps: {},
|
|
279
|
+
properties: Array(),
|
|
280
|
+
fields: Array()
|
|
281
|
+
};
|
|
282
|
+
const lines = {
|
|
283
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
284
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
285
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
286
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
287
|
+
numericProps: {},
|
|
288
|
+
properties: Array(),
|
|
289
|
+
fields: Array()
|
|
290
|
+
};
|
|
291
|
+
const polygons = {
|
|
292
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
293
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
294
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
295
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
296
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
297
|
+
numericProps: {},
|
|
298
|
+
properties: Array(),
|
|
299
|
+
fields: Array()
|
|
300
|
+
};
|
|
301
|
+
for (const object of [points, lines, polygons]) {
|
|
302
|
+
for (const propName of numericPropKeys || []) {
|
|
303
|
+
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
307
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
308
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
309
|
+
const indexMap = {
|
|
310
|
+
pointPosition: 0,
|
|
311
|
+
pointFeature: 0,
|
|
312
|
+
linePosition: 0,
|
|
313
|
+
linePath: 0,
|
|
314
|
+
lineFeature: 0,
|
|
315
|
+
polygonPosition: 0,
|
|
316
|
+
polygonObject: 0,
|
|
317
|
+
polygonRing: 0,
|
|
318
|
+
polygonFeature: 0,
|
|
319
|
+
feature: 0
|
|
320
|
+
};
|
|
321
|
+
for (const feature of features) {
|
|
322
|
+
const geometry = feature.geometry;
|
|
323
|
+
const properties = feature.properties || {};
|
|
324
|
+
switch (geometry.type) {
|
|
325
|
+
case "Point":
|
|
326
|
+
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
327
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
328
|
+
indexMap.pointFeature++;
|
|
329
|
+
break;
|
|
330
|
+
case "MultiPoint":
|
|
331
|
+
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
332
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
333
|
+
indexMap.pointFeature++;
|
|
334
|
+
break;
|
|
335
|
+
case "LineString":
|
|
336
|
+
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
337
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
338
|
+
indexMap.lineFeature++;
|
|
339
|
+
break;
|
|
340
|
+
case "MultiLineString":
|
|
341
|
+
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
342
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
343
|
+
indexMap.lineFeature++;
|
|
344
|
+
break;
|
|
345
|
+
case "Polygon":
|
|
346
|
+
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
347
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
348
|
+
indexMap.polygonFeature++;
|
|
349
|
+
break;
|
|
350
|
+
case "MultiPolygon":
|
|
351
|
+
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
352
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
353
|
+
indexMap.polygonFeature++;
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
throw new Error("Invalid geometry type");
|
|
357
|
+
}
|
|
358
|
+
indexMap.feature++;
|
|
359
|
+
}
|
|
360
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
361
|
+
}
|
|
362
|
+
function handlePoint(coords, points, indexMap, coordLength, properties) {
|
|
363
|
+
points.positions.set(coords, indexMap.pointPosition * coordLength);
|
|
364
|
+
points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
|
|
365
|
+
points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
|
|
366
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, 1);
|
|
367
|
+
indexMap.pointPosition++;
|
|
368
|
+
}
|
|
369
|
+
function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
|
|
370
|
+
for (const point of coords) {
|
|
371
|
+
handlePoint(point, points, indexMap, coordLength, properties);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function handleLineString(coords, lines, indexMap, coordLength, properties) {
|
|
375
|
+
lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
|
|
376
|
+
indexMap.linePath++;
|
|
377
|
+
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
378
|
+
const nPositions = coords.length;
|
|
379
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
380
|
+
lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
|
|
381
|
+
lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
|
|
382
|
+
indexMap.linePosition += nPositions;
|
|
383
|
+
}
|
|
384
|
+
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
|
|
385
|
+
for (const line of coords) {
|
|
386
|
+
handleLineString(line, lines, indexMap, coordLength, properties);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
390
|
+
polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
|
|
391
|
+
indexMap.polygonObject++;
|
|
392
|
+
for (const ring of coords) {
|
|
393
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
|
|
394
|
+
indexMap.polygonRing++;
|
|
395
|
+
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
|
|
396
|
+
const nPositions = ring.length;
|
|
397
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
398
|
+
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
|
|
399
|
+
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
|
|
400
|
+
indexMap.polygonPosition += nPositions;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
404
|
+
for (const polygon of coords) {
|
|
405
|
+
handlePolygon(polygon, polygons, indexMap, coordLength, properties);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
409
|
+
const returnObj = {
|
|
410
|
+
points: {
|
|
411
|
+
...points,
|
|
412
|
+
positions: { value: points.positions, size: coordLength },
|
|
413
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
414
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
415
|
+
type: "Point"
|
|
416
|
+
},
|
|
417
|
+
lines: {
|
|
418
|
+
...lines,
|
|
419
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
420
|
+
positions: { value: lines.positions, size: coordLength },
|
|
421
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
422
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
423
|
+
type: "LineString"
|
|
424
|
+
},
|
|
425
|
+
polygons: {
|
|
426
|
+
...polygons,
|
|
427
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
428
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
429
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
430
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
431
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
432
|
+
type: "Polygon"
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
for (const geomType in returnObj) {
|
|
436
|
+
for (const numericProp in returnObj[geomType].numericProps) {
|
|
437
|
+
returnObj[geomType].numericProps[numericProp] = {
|
|
438
|
+
value: returnObj[geomType].numericProps[numericProp],
|
|
439
|
+
size: 1
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return returnObj;
|
|
444
|
+
}
|
|
445
|
+
function fillNumericProperties(object, properties, index, length) {
|
|
446
|
+
for (const numericPropName in object.numericProps) {
|
|
447
|
+
if (numericPropName in properties) {
|
|
448
|
+
object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function keepStringProperties(properties, numericKeys) {
|
|
453
|
+
const props = {};
|
|
454
|
+
for (const key in properties) {
|
|
455
|
+
if (!numericKeys.includes(key)) {
|
|
456
|
+
props[key] = properties[key];
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return props;
|
|
460
|
+
}
|
|
461
|
+
function fillCoords(array, coords, startVertex, coordLength) {
|
|
462
|
+
let index = startVertex * coordLength;
|
|
463
|
+
for (const coord of coords) {
|
|
464
|
+
array.set(coord, index);
|
|
465
|
+
index += coordLength;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function flatten(arrays) {
|
|
469
|
+
return [].concat(...arrays);
|
|
470
|
+
}
|
|
471
|
+
function isNumeric(x) {
|
|
472
|
+
return Number.isFinite(x);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/lib/parse-json.ts
|
|
476
|
+
function parseJSONSync(jsonText, options) {
|
|
477
|
+
try {
|
|
478
|
+
const json = JSON.parse(jsonText);
|
|
479
|
+
if (options.json?.table) {
|
|
480
|
+
return getFirstArray(json) || json;
|
|
481
|
+
}
|
|
482
|
+
return json;
|
|
483
|
+
} catch (error) {
|
|
484
|
+
throw new Error("JSONLoader: failed to parse JSON");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function getFirstArray(json) {
|
|
488
|
+
if (Array.isArray(json)) {
|
|
489
|
+
return json;
|
|
490
|
+
}
|
|
491
|
+
if (json && typeof json === "object") {
|
|
492
|
+
for (const value of Object.values(json)) {
|
|
493
|
+
const array = getFirstArray(value);
|
|
494
|
+
if (array) {
|
|
495
|
+
return array;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ../schema/src/lib/batches/base-table-batch-aggregator.ts
|
|
503
|
+
var DEFAULT_ROW_COUNT = 100;
|
|
504
|
+
var RowTableBatchAggregator = class {
|
|
505
|
+
constructor(schema, options) {
|
|
506
|
+
this.length = 0;
|
|
507
|
+
this.rows = null;
|
|
508
|
+
this.cursor = 0;
|
|
509
|
+
this._headers = [];
|
|
510
|
+
this.options = options;
|
|
511
|
+
this.schema = schema;
|
|
512
|
+
if (!Array.isArray(schema)) {
|
|
513
|
+
this._headers = [];
|
|
514
|
+
for (const key in schema) {
|
|
515
|
+
this._headers[schema[key].index] = schema[key].name;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
rowCount() {
|
|
520
|
+
return this.length;
|
|
521
|
+
}
|
|
522
|
+
addArrayRow(row, cursor) {
|
|
523
|
+
if (Number.isFinite(cursor)) {
|
|
524
|
+
this.cursor = cursor;
|
|
525
|
+
}
|
|
526
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
527
|
+
this.rows[this.length] = row;
|
|
528
|
+
this.length++;
|
|
529
|
+
}
|
|
530
|
+
addObjectRow(row, cursor) {
|
|
531
|
+
if (Number.isFinite(cursor)) {
|
|
532
|
+
this.cursor = cursor;
|
|
533
|
+
}
|
|
534
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
535
|
+
this.rows[this.length] = row;
|
|
536
|
+
this.length++;
|
|
537
|
+
}
|
|
538
|
+
getBatch() {
|
|
539
|
+
let rows = this.rows;
|
|
540
|
+
if (!rows) {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
rows = rows.slice(0, this.length);
|
|
544
|
+
this.rows = null;
|
|
545
|
+
const batch = {
|
|
546
|
+
shape: this.options.shape,
|
|
547
|
+
batchType: "data",
|
|
548
|
+
data: rows,
|
|
549
|
+
length: this.length,
|
|
550
|
+
schema: this.schema,
|
|
551
|
+
cursor: this.cursor
|
|
552
|
+
};
|
|
553
|
+
return batch;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// ../schema/src/lib/utils/row-utils.ts
|
|
558
|
+
function convertToObjectRow(arrayRow, headers) {
|
|
559
|
+
if (!arrayRow) {
|
|
560
|
+
throw new Error("null row");
|
|
561
|
+
}
|
|
562
|
+
if (!headers) {
|
|
563
|
+
throw new Error("no headers");
|
|
564
|
+
}
|
|
565
|
+
const objectRow = {};
|
|
566
|
+
for (let i = 0; i < headers.length; i++) {
|
|
567
|
+
objectRow[headers[i]] = arrayRow[i];
|
|
568
|
+
}
|
|
569
|
+
return objectRow;
|
|
570
|
+
}
|
|
571
|
+
function convertToArrayRow(objectRow, headers) {
|
|
572
|
+
if (!objectRow) {
|
|
573
|
+
throw new Error("null row");
|
|
574
|
+
}
|
|
575
|
+
if (!headers) {
|
|
576
|
+
throw new Error("no headers");
|
|
577
|
+
}
|
|
578
|
+
const arrayRow = new Array(headers.length);
|
|
579
|
+
for (let i = 0; i < headers.length; i++) {
|
|
580
|
+
arrayRow[i] = objectRow[headers[i]];
|
|
581
|
+
}
|
|
582
|
+
return arrayRow;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// ../schema/src/lib/batches/row-table-batch-aggregator.ts
|
|
586
|
+
var DEFAULT_ROW_COUNT2 = 100;
|
|
587
|
+
var RowTableBatchAggregator2 = class {
|
|
588
|
+
constructor(schema, options) {
|
|
589
|
+
this.length = 0;
|
|
590
|
+
this.objectRows = null;
|
|
591
|
+
this.arrayRows = null;
|
|
592
|
+
this.cursor = 0;
|
|
593
|
+
this._headers = [];
|
|
594
|
+
this.options = options;
|
|
595
|
+
this.schema = schema;
|
|
596
|
+
if (!Array.isArray(schema)) {
|
|
597
|
+
this._headers = [];
|
|
598
|
+
for (const key in schema) {
|
|
599
|
+
this._headers[schema[key].index] = schema[key].name;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
rowCount() {
|
|
604
|
+
return this.length;
|
|
605
|
+
}
|
|
606
|
+
addArrayRow(row, cursor) {
|
|
607
|
+
if (Number.isFinite(cursor)) {
|
|
608
|
+
this.cursor = cursor;
|
|
609
|
+
}
|
|
610
|
+
switch (this.options.shape) {
|
|
611
|
+
case "object-row-table":
|
|
612
|
+
const rowObject = convertToObjectRow(row, this._headers);
|
|
613
|
+
this.addObjectRow(rowObject, cursor);
|
|
614
|
+
break;
|
|
615
|
+
case "array-row-table":
|
|
616
|
+
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
|
|
617
|
+
this.arrayRows[this.length] = row;
|
|
618
|
+
this.length++;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
addObjectRow(row, cursor) {
|
|
623
|
+
if (Number.isFinite(cursor)) {
|
|
624
|
+
this.cursor = cursor;
|
|
625
|
+
}
|
|
626
|
+
switch (this.options.shape) {
|
|
627
|
+
case "array-row-table":
|
|
628
|
+
const rowArray = convertToArrayRow(row, this._headers);
|
|
629
|
+
this.addArrayRow(rowArray, cursor);
|
|
630
|
+
break;
|
|
631
|
+
case "object-row-table":
|
|
632
|
+
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
|
|
633
|
+
this.objectRows[this.length] = row;
|
|
634
|
+
this.length++;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
getBatch() {
|
|
639
|
+
let rows = this.arrayRows || this.objectRows;
|
|
640
|
+
if (!rows) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
rows = rows.slice(0, this.length);
|
|
644
|
+
this.arrayRows = null;
|
|
645
|
+
this.objectRows = null;
|
|
646
|
+
return {
|
|
647
|
+
shape: this.options.shape,
|
|
648
|
+
batchType: "data",
|
|
649
|
+
data: rows,
|
|
650
|
+
length: this.length,
|
|
651
|
+
schema: this.schema,
|
|
652
|
+
cursor: this.cursor
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// ../schema/src/lib/batches/columnar-table-batch-aggregator.ts
|
|
658
|
+
var DEFAULT_ROW_COUNT3 = 100;
|
|
659
|
+
var ColumnarTableBatchAggregator = class {
|
|
660
|
+
constructor(schema, options) {
|
|
661
|
+
this.length = 0;
|
|
662
|
+
this.allocated = 0;
|
|
663
|
+
this.columns = {};
|
|
664
|
+
this.schema = schema;
|
|
665
|
+
this._reallocateColumns();
|
|
666
|
+
}
|
|
667
|
+
rowCount() {
|
|
668
|
+
return this.length;
|
|
669
|
+
}
|
|
670
|
+
addArrayRow(row) {
|
|
671
|
+
this._reallocateColumns();
|
|
672
|
+
let i = 0;
|
|
673
|
+
for (const fieldName in this.columns) {
|
|
674
|
+
this.columns[fieldName][this.length] = row[i++];
|
|
675
|
+
}
|
|
676
|
+
this.length++;
|
|
677
|
+
}
|
|
678
|
+
addObjectRow(row) {
|
|
679
|
+
this._reallocateColumns();
|
|
680
|
+
for (const fieldName in row) {
|
|
681
|
+
this.columns[fieldName][this.length] = row[fieldName];
|
|
682
|
+
}
|
|
683
|
+
this.length++;
|
|
684
|
+
}
|
|
685
|
+
getBatch() {
|
|
686
|
+
this._pruneColumns();
|
|
687
|
+
const columns = Array.isArray(this.schema) ? this.columns : {};
|
|
688
|
+
if (!Array.isArray(this.schema)) {
|
|
689
|
+
for (const fieldName in this.schema) {
|
|
690
|
+
const field = this.schema[fieldName];
|
|
691
|
+
columns[field.name] = this.columns[field.index];
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
this.columns = {};
|
|
695
|
+
const batch = {
|
|
696
|
+
shape: "columnar-table",
|
|
697
|
+
batchType: "data",
|
|
698
|
+
data: columns,
|
|
699
|
+
schema: this.schema,
|
|
700
|
+
length: this.length
|
|
701
|
+
};
|
|
702
|
+
return batch;
|
|
703
|
+
}
|
|
704
|
+
_reallocateColumns() {
|
|
705
|
+
if (this.length < this.allocated) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
|
|
709
|
+
this.columns = {};
|
|
710
|
+
for (const fieldName in this.schema) {
|
|
711
|
+
const field = this.schema[fieldName];
|
|
712
|
+
const ArrayType = field.type || Float32Array;
|
|
713
|
+
const oldColumn = this.columns[field.index];
|
|
714
|
+
if (oldColumn && ArrayBuffer.isView(oldColumn)) {
|
|
715
|
+
const typedArray = new ArrayType(this.allocated);
|
|
716
|
+
typedArray.set(oldColumn);
|
|
717
|
+
this.columns[field.index] = typedArray;
|
|
718
|
+
} else if (oldColumn) {
|
|
719
|
+
oldColumn.length = this.allocated;
|
|
720
|
+
this.columns[field.index] = oldColumn;
|
|
721
|
+
} else {
|
|
722
|
+
this.columns[field.index] = new ArrayType(this.allocated);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
_pruneColumns() {
|
|
727
|
+
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
728
|
+
this.columns[columnName] = column.slice(0, this.length);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// ../schema/src/lib/batches/table-batch-builder.ts
|
|
734
|
+
var DEFAULT_OPTIONS = {
|
|
735
|
+
shape: "array-row-table",
|
|
736
|
+
batchSize: "auto",
|
|
737
|
+
batchDebounceMs: 0,
|
|
738
|
+
limit: 0,
|
|
739
|
+
_limitMB: 0
|
|
740
|
+
};
|
|
741
|
+
var ERR_MESSAGE = "TableBatchBuilder";
|
|
742
|
+
var TableBatchBuilder = class {
|
|
743
|
+
constructor(schema, options) {
|
|
744
|
+
this.aggregator = null;
|
|
745
|
+
this.batchCount = 0;
|
|
746
|
+
this.bytesUsed = 0;
|
|
747
|
+
this.isChunkComplete = false;
|
|
748
|
+
this.lastBatchEmittedMs = Date.now();
|
|
749
|
+
this.totalLength = 0;
|
|
750
|
+
this.totalBytes = 0;
|
|
751
|
+
this.rowBytes = 0;
|
|
752
|
+
this.schema = schema;
|
|
753
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
754
|
+
}
|
|
755
|
+
limitReached() {
|
|
756
|
+
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
addRow(row) {
|
|
765
|
+
if (this.limitReached()) {
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
this.totalLength++;
|
|
769
|
+
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
770
|
+
this.totalBytes += this.rowBytes;
|
|
771
|
+
if (Array.isArray(row)) {
|
|
772
|
+
this.addArrayRow(row);
|
|
773
|
+
} else {
|
|
774
|
+
this.addObjectRow(row);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
addArrayRow(row) {
|
|
778
|
+
if (!this.aggregator) {
|
|
779
|
+
const TableBatchType = this._getTableBatchType();
|
|
780
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
781
|
+
}
|
|
782
|
+
this.aggregator.addArrayRow(row);
|
|
783
|
+
}
|
|
784
|
+
addObjectRow(row) {
|
|
785
|
+
if (!this.aggregator) {
|
|
786
|
+
const TableBatchType = this._getTableBatchType();
|
|
787
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
788
|
+
}
|
|
789
|
+
this.aggregator.addObjectRow(row);
|
|
790
|
+
}
|
|
791
|
+
chunkComplete(chunk) {
|
|
792
|
+
if (chunk instanceof ArrayBuffer) {
|
|
793
|
+
this.bytesUsed += chunk.byteLength;
|
|
794
|
+
}
|
|
795
|
+
if (typeof chunk === "string") {
|
|
796
|
+
this.bytesUsed += chunk.length;
|
|
797
|
+
}
|
|
798
|
+
this.isChunkComplete = true;
|
|
799
|
+
}
|
|
800
|
+
getFullBatch(options) {
|
|
801
|
+
return this._isFull() ? this._getBatch(options) : null;
|
|
802
|
+
}
|
|
803
|
+
getFinalBatch(options) {
|
|
804
|
+
return this._getBatch(options);
|
|
805
|
+
}
|
|
806
|
+
_estimateRowMB(row) {
|
|
807
|
+
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
808
|
+
}
|
|
809
|
+
_isFull() {
|
|
810
|
+
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
if (this.options.batchSize === "auto") {
|
|
814
|
+
if (!this.isChunkComplete) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
} else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
this.isChunkComplete = false;
|
|
824
|
+
this.lastBatchEmittedMs = Date.now();
|
|
825
|
+
return true;
|
|
826
|
+
}
|
|
827
|
+
_getBatch(options) {
|
|
828
|
+
if (!this.aggregator) {
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
if (options?.bytesUsed) {
|
|
832
|
+
this.bytesUsed = options.bytesUsed;
|
|
833
|
+
}
|
|
834
|
+
const normalizedBatch = this.aggregator.getBatch();
|
|
835
|
+
normalizedBatch.count = this.batchCount;
|
|
836
|
+
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
837
|
+
Object.assign(normalizedBatch, options);
|
|
838
|
+
this.batchCount++;
|
|
839
|
+
this.aggregator = null;
|
|
840
|
+
return normalizedBatch;
|
|
841
|
+
}
|
|
842
|
+
_getTableBatchType() {
|
|
843
|
+
switch (this.options.shape) {
|
|
844
|
+
case "row-table":
|
|
845
|
+
return RowTableBatchAggregator;
|
|
846
|
+
case "array-row-table":
|
|
847
|
+
case "object-row-table":
|
|
848
|
+
return RowTableBatchAggregator2;
|
|
849
|
+
case "columnar-table":
|
|
850
|
+
return ColumnarTableBatchAggregator;
|
|
851
|
+
case "arrow-table":
|
|
852
|
+
if (!TableBatchBuilder.ArrowBatch) {
|
|
853
|
+
throw new Error(ERR_MESSAGE);
|
|
854
|
+
}
|
|
855
|
+
return TableBatchBuilder.ArrowBatch;
|
|
856
|
+
default:
|
|
857
|
+
throw new Error(ERR_MESSAGE);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
// src/lib/clarinet/clarinet.ts
|
|
863
|
+
var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
864
|
+
var STATE;
|
|
865
|
+
(function(STATE2) {
|
|
866
|
+
STATE2[STATE2["BEGIN"] = 0] = "BEGIN";
|
|
867
|
+
STATE2[STATE2["VALUE"] = 1] = "VALUE";
|
|
868
|
+
STATE2[STATE2["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
|
|
869
|
+
STATE2[STATE2["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
|
|
870
|
+
STATE2[STATE2["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
|
|
871
|
+
STATE2[STATE2["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
|
|
872
|
+
STATE2[STATE2["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
|
|
873
|
+
STATE2[STATE2["STRING"] = 7] = "STRING";
|
|
874
|
+
STATE2[STATE2["BACKSLASH"] = 8] = "BACKSLASH";
|
|
875
|
+
STATE2[STATE2["END"] = 9] = "END";
|
|
876
|
+
STATE2[STATE2["OPEN_KEY"] = 10] = "OPEN_KEY";
|
|
877
|
+
STATE2[STATE2["CLOSE_KEY"] = 11] = "CLOSE_KEY";
|
|
878
|
+
STATE2[STATE2["TRUE"] = 12] = "TRUE";
|
|
879
|
+
STATE2[STATE2["TRUE2"] = 13] = "TRUE2";
|
|
880
|
+
STATE2[STATE2["TRUE3"] = 14] = "TRUE3";
|
|
881
|
+
STATE2[STATE2["FALSE"] = 15] = "FALSE";
|
|
882
|
+
STATE2[STATE2["FALSE2"] = 16] = "FALSE2";
|
|
883
|
+
STATE2[STATE2["FALSE3"] = 17] = "FALSE3";
|
|
884
|
+
STATE2[STATE2["FALSE4"] = 18] = "FALSE4";
|
|
885
|
+
STATE2[STATE2["NULL"] = 19] = "NULL";
|
|
886
|
+
STATE2[STATE2["NULL2"] = 20] = "NULL2";
|
|
887
|
+
STATE2[STATE2["NULL3"] = 21] = "NULL3";
|
|
888
|
+
STATE2[STATE2["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
|
|
889
|
+
STATE2[STATE2["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
|
|
890
|
+
})(STATE || (STATE = {}));
|
|
891
|
+
var Char = {
|
|
892
|
+
tab: 9,
|
|
893
|
+
lineFeed: 10,
|
|
894
|
+
carriageReturn: 13,
|
|
895
|
+
space: 32,
|
|
896
|
+
doubleQuote: 34,
|
|
897
|
+
plus: 43,
|
|
898
|
+
comma: 44,
|
|
899
|
+
minus: 45,
|
|
900
|
+
period: 46,
|
|
901
|
+
_0: 48,
|
|
902
|
+
_9: 57,
|
|
903
|
+
colon: 58,
|
|
904
|
+
E: 69,
|
|
905
|
+
openBracket: 91,
|
|
906
|
+
backslash: 92,
|
|
907
|
+
closeBracket: 93,
|
|
908
|
+
a: 97,
|
|
909
|
+
b: 98,
|
|
910
|
+
e: 101,
|
|
911
|
+
f: 102,
|
|
912
|
+
l: 108,
|
|
913
|
+
n: 110,
|
|
914
|
+
r: 114,
|
|
915
|
+
s: 115,
|
|
916
|
+
t: 116,
|
|
917
|
+
u: 117,
|
|
918
|
+
openBrace: 123,
|
|
919
|
+
closeBrace: 125
|
|
920
|
+
};
|
|
921
|
+
var stringTokenPattern = /[\\"\n]/g;
|
|
922
|
+
var DEFAULT_OPTIONS2 = {
|
|
923
|
+
onready: () => {
|
|
924
|
+
},
|
|
925
|
+
onopenobject: () => {
|
|
926
|
+
},
|
|
927
|
+
onkey: () => {
|
|
928
|
+
},
|
|
929
|
+
oncloseobject: () => {
|
|
930
|
+
},
|
|
931
|
+
onopenarray: () => {
|
|
932
|
+
},
|
|
933
|
+
onclosearray: () => {
|
|
934
|
+
},
|
|
935
|
+
onvalue: () => {
|
|
936
|
+
},
|
|
937
|
+
onerror: () => {
|
|
938
|
+
},
|
|
939
|
+
onend: () => {
|
|
940
|
+
},
|
|
941
|
+
onchunkparsed: () => {
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
var ClarinetParser = class {
|
|
945
|
+
constructor(options = {}) {
|
|
946
|
+
this.options = DEFAULT_OPTIONS2;
|
|
947
|
+
this.bufferCheckPosition = MAX_BUFFER_LENGTH;
|
|
948
|
+
this.q = "";
|
|
949
|
+
this.c = "";
|
|
950
|
+
this.p = "";
|
|
951
|
+
this.closed = false;
|
|
952
|
+
this.closedRoot = false;
|
|
953
|
+
this.sawRoot = false;
|
|
954
|
+
this.error = null;
|
|
955
|
+
this.state = 0;
|
|
956
|
+
this.stack = [];
|
|
957
|
+
this.position = 0;
|
|
958
|
+
this.column = 0;
|
|
959
|
+
this.line = 1;
|
|
960
|
+
this.slashed = false;
|
|
961
|
+
this.unicodeI = 0;
|
|
962
|
+
this.unicodeS = null;
|
|
963
|
+
this.depth = 0;
|
|
964
|
+
this.options = { ...DEFAULT_OPTIONS2, ...options };
|
|
965
|
+
this.textNode = void 0;
|
|
966
|
+
this.numberNode = "";
|
|
967
|
+
this.emit("onready");
|
|
968
|
+
}
|
|
969
|
+
end() {
|
|
970
|
+
if (this.state !== 1 || this.depth !== 0)
|
|
971
|
+
this._error("Unexpected end");
|
|
972
|
+
this._closeValue();
|
|
973
|
+
this.c = "";
|
|
974
|
+
this.closed = true;
|
|
975
|
+
this.emit("onend");
|
|
976
|
+
return this;
|
|
977
|
+
}
|
|
978
|
+
resume() {
|
|
979
|
+
this.error = null;
|
|
980
|
+
return this;
|
|
981
|
+
}
|
|
982
|
+
close() {
|
|
983
|
+
return this.write(null);
|
|
984
|
+
}
|
|
985
|
+
emit(event, data) {
|
|
986
|
+
this.options[event]?.(data, this);
|
|
987
|
+
}
|
|
988
|
+
emitNode(event, data) {
|
|
989
|
+
this._closeValue();
|
|
990
|
+
this.emit(event, data);
|
|
991
|
+
}
|
|
992
|
+
write(chunk) {
|
|
993
|
+
if (this.error) {
|
|
994
|
+
throw this.error;
|
|
995
|
+
}
|
|
996
|
+
if (this.closed) {
|
|
997
|
+
return this._error("Cannot write after close. Assign an onready handler.");
|
|
998
|
+
}
|
|
999
|
+
if (chunk === null) {
|
|
1000
|
+
return this.end();
|
|
1001
|
+
}
|
|
1002
|
+
let i = 0;
|
|
1003
|
+
let c = chunk.charCodeAt(0);
|
|
1004
|
+
let p = this.p;
|
|
1005
|
+
while (c) {
|
|
1006
|
+
p = c;
|
|
1007
|
+
this.c = c = chunk.charCodeAt(i++);
|
|
1008
|
+
if (p !== c) {
|
|
1009
|
+
this.p = p;
|
|
1010
|
+
} else {
|
|
1011
|
+
p = this.p;
|
|
1012
|
+
}
|
|
1013
|
+
if (!c)
|
|
1014
|
+
break;
|
|
1015
|
+
this.position++;
|
|
1016
|
+
if (c === Char.lineFeed) {
|
|
1017
|
+
this.line++;
|
|
1018
|
+
this.column = 0;
|
|
1019
|
+
} else
|
|
1020
|
+
this.column++;
|
|
1021
|
+
switch (this.state) {
|
|
1022
|
+
case 0:
|
|
1023
|
+
if (c === Char.openBrace)
|
|
1024
|
+
this.state = 2;
|
|
1025
|
+
else if (c === Char.openBracket)
|
|
1026
|
+
this.state = 4;
|
|
1027
|
+
else if (!isWhitespace(c)) {
|
|
1028
|
+
this._error("Non-whitespace before {[.");
|
|
1029
|
+
}
|
|
1030
|
+
continue;
|
|
1031
|
+
case 10:
|
|
1032
|
+
case 2:
|
|
1033
|
+
if (isWhitespace(c))
|
|
1034
|
+
continue;
|
|
1035
|
+
if (this.state === 10)
|
|
1036
|
+
this.stack.push(11);
|
|
1037
|
+
else if (c === Char.closeBrace) {
|
|
1038
|
+
this.emit("onopenobject");
|
|
1039
|
+
this.depth++;
|
|
1040
|
+
this.emit("oncloseobject");
|
|
1041
|
+
this.depth--;
|
|
1042
|
+
this.state = this.stack.pop() || 1;
|
|
1043
|
+
continue;
|
|
1044
|
+
} else
|
|
1045
|
+
this.stack.push(3);
|
|
1046
|
+
if (c === Char.doubleQuote)
|
|
1047
|
+
this.state = 7;
|
|
1048
|
+
else
|
|
1049
|
+
this._error('Malformed object key should start with "');
|
|
1050
|
+
continue;
|
|
1051
|
+
case 11:
|
|
1052
|
+
case 3:
|
|
1053
|
+
if (isWhitespace(c))
|
|
1054
|
+
continue;
|
|
1055
|
+
if (c === Char.colon) {
|
|
1056
|
+
if (this.state === 3) {
|
|
1057
|
+
this.stack.push(3);
|
|
1058
|
+
this._closeValue("onopenobject");
|
|
1059
|
+
this.depth++;
|
|
1060
|
+
} else
|
|
1061
|
+
this._closeValue("onkey");
|
|
1062
|
+
this.state = 1;
|
|
1063
|
+
} else if (c === Char.closeBrace) {
|
|
1064
|
+
this.emitNode("oncloseobject");
|
|
1065
|
+
this.depth--;
|
|
1066
|
+
this.state = this.stack.pop() || 1;
|
|
1067
|
+
} else if (c === Char.comma) {
|
|
1068
|
+
if (this.state === 3)
|
|
1069
|
+
this.stack.push(3);
|
|
1070
|
+
this._closeValue();
|
|
1071
|
+
this.state = 10;
|
|
1072
|
+
} else
|
|
1073
|
+
this._error("Bad object");
|
|
1074
|
+
continue;
|
|
1075
|
+
case 4:
|
|
1076
|
+
case 1:
|
|
1077
|
+
if (isWhitespace(c))
|
|
1078
|
+
continue;
|
|
1079
|
+
if (this.state === 4) {
|
|
1080
|
+
this.emit("onopenarray");
|
|
1081
|
+
this.depth++;
|
|
1082
|
+
this.state = 1;
|
|
1083
|
+
if (c === Char.closeBracket) {
|
|
1084
|
+
this.emit("onclosearray");
|
|
1085
|
+
this.depth--;
|
|
1086
|
+
this.state = this.stack.pop() || 1;
|
|
1087
|
+
continue;
|
|
1088
|
+
} else {
|
|
1089
|
+
this.stack.push(5);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
if (c === Char.doubleQuote)
|
|
1093
|
+
this.state = 7;
|
|
1094
|
+
else if (c === Char.openBrace)
|
|
1095
|
+
this.state = 2;
|
|
1096
|
+
else if (c === Char.openBracket)
|
|
1097
|
+
this.state = 4;
|
|
1098
|
+
else if (c === Char.t)
|
|
1099
|
+
this.state = 12;
|
|
1100
|
+
else if (c === Char.f)
|
|
1101
|
+
this.state = 15;
|
|
1102
|
+
else if (c === Char.n)
|
|
1103
|
+
this.state = 19;
|
|
1104
|
+
else if (c === Char.minus) {
|
|
1105
|
+
this.numberNode += "-";
|
|
1106
|
+
} else if (Char._0 <= c && c <= Char._9) {
|
|
1107
|
+
this.numberNode += String.fromCharCode(c);
|
|
1108
|
+
this.state = 23;
|
|
1109
|
+
} else
|
|
1110
|
+
this._error("Bad value");
|
|
1111
|
+
continue;
|
|
1112
|
+
case 5:
|
|
1113
|
+
if (c === Char.comma) {
|
|
1114
|
+
this.stack.push(5);
|
|
1115
|
+
this._closeValue("onvalue");
|
|
1116
|
+
this.state = 1;
|
|
1117
|
+
} else if (c === Char.closeBracket) {
|
|
1118
|
+
this.emitNode("onclosearray");
|
|
1119
|
+
this.depth--;
|
|
1120
|
+
this.state = this.stack.pop() || 1;
|
|
1121
|
+
} else if (isWhitespace(c))
|
|
1122
|
+
continue;
|
|
1123
|
+
else
|
|
1124
|
+
this._error("Bad array");
|
|
1125
|
+
continue;
|
|
1126
|
+
case 7:
|
|
1127
|
+
if (this.textNode === void 0) {
|
|
1128
|
+
this.textNode = "";
|
|
1129
|
+
}
|
|
1130
|
+
let starti = i - 1;
|
|
1131
|
+
let slashed = this.slashed;
|
|
1132
|
+
let unicodeI = this.unicodeI;
|
|
1133
|
+
STRING_BIGLOOP:
|
|
1134
|
+
while (true) {
|
|
1135
|
+
while (unicodeI > 0) {
|
|
1136
|
+
this.unicodeS += String.fromCharCode(c);
|
|
1137
|
+
c = chunk.charCodeAt(i++);
|
|
1138
|
+
this.position++;
|
|
1139
|
+
if (unicodeI === 4) {
|
|
1140
|
+
this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
|
|
1141
|
+
unicodeI = 0;
|
|
1142
|
+
starti = i - 1;
|
|
1143
|
+
} else {
|
|
1144
|
+
unicodeI++;
|
|
1145
|
+
}
|
|
1146
|
+
if (!c)
|
|
1147
|
+
break STRING_BIGLOOP;
|
|
1148
|
+
}
|
|
1149
|
+
if (c === Char.doubleQuote && !slashed) {
|
|
1150
|
+
this.state = this.stack.pop() || 1;
|
|
1151
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
1152
|
+
this.position += i - 1 - starti;
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
if (c === Char.backslash && !slashed) {
|
|
1156
|
+
slashed = true;
|
|
1157
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
1158
|
+
this.position += i - 1 - starti;
|
|
1159
|
+
c = chunk.charCodeAt(i++);
|
|
1160
|
+
this.position++;
|
|
1161
|
+
if (!c)
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
if (slashed) {
|
|
1165
|
+
slashed = false;
|
|
1166
|
+
if (c === Char.n) {
|
|
1167
|
+
this.textNode += "\n";
|
|
1168
|
+
} else if (c === Char.r) {
|
|
1169
|
+
this.textNode += "\r";
|
|
1170
|
+
} else if (c === Char.t) {
|
|
1171
|
+
this.textNode += " ";
|
|
1172
|
+
} else if (c === Char.f) {
|
|
1173
|
+
this.textNode += "\f";
|
|
1174
|
+
} else if (c === Char.b) {
|
|
1175
|
+
this.textNode += "\b";
|
|
1176
|
+
} else if (c === Char.u) {
|
|
1177
|
+
unicodeI = 1;
|
|
1178
|
+
this.unicodeS = "";
|
|
1179
|
+
} else {
|
|
1180
|
+
this.textNode += String.fromCharCode(c);
|
|
1181
|
+
}
|
|
1182
|
+
c = chunk.charCodeAt(i++);
|
|
1183
|
+
this.position++;
|
|
1184
|
+
starti = i - 1;
|
|
1185
|
+
if (!c)
|
|
1186
|
+
break;
|
|
1187
|
+
else
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
stringTokenPattern.lastIndex = i;
|
|
1191
|
+
const reResult = stringTokenPattern.exec(chunk);
|
|
1192
|
+
if (reResult === null) {
|
|
1193
|
+
i = chunk.length + 1;
|
|
1194
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
1195
|
+
this.position += i - 1 - starti;
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
i = reResult.index + 1;
|
|
1199
|
+
c = chunk.charCodeAt(reResult.index);
|
|
1200
|
+
if (!c) {
|
|
1201
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
1202
|
+
this.position += i - 1 - starti;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
this.slashed = slashed;
|
|
1207
|
+
this.unicodeI = unicodeI;
|
|
1208
|
+
continue;
|
|
1209
|
+
case 12:
|
|
1210
|
+
if (c === Char.r)
|
|
1211
|
+
this.state = 13;
|
|
1212
|
+
else
|
|
1213
|
+
this._error(`Invalid true started with t${c}`);
|
|
1214
|
+
continue;
|
|
1215
|
+
case 13:
|
|
1216
|
+
if (c === Char.u)
|
|
1217
|
+
this.state = 14;
|
|
1218
|
+
else
|
|
1219
|
+
this._error(`Invalid true started with tr${c}`);
|
|
1220
|
+
continue;
|
|
1221
|
+
case 14:
|
|
1222
|
+
if (c === Char.e) {
|
|
1223
|
+
this.emit("onvalue", true);
|
|
1224
|
+
this.state = this.stack.pop() || 1;
|
|
1225
|
+
} else
|
|
1226
|
+
this._error(`Invalid true started with tru${c}`);
|
|
1227
|
+
continue;
|
|
1228
|
+
case 15:
|
|
1229
|
+
if (c === Char.a)
|
|
1230
|
+
this.state = 16;
|
|
1231
|
+
else
|
|
1232
|
+
this._error(`Invalid false started with f${c}`);
|
|
1233
|
+
continue;
|
|
1234
|
+
case 16:
|
|
1235
|
+
if (c === Char.l)
|
|
1236
|
+
this.state = 17;
|
|
1237
|
+
else
|
|
1238
|
+
this._error(`Invalid false started with fa${c}`);
|
|
1239
|
+
continue;
|
|
1240
|
+
case 17:
|
|
1241
|
+
if (c === Char.s)
|
|
1242
|
+
this.state = 18;
|
|
1243
|
+
else
|
|
1244
|
+
this._error(`Invalid false started with fal${c}`);
|
|
1245
|
+
continue;
|
|
1246
|
+
case 18:
|
|
1247
|
+
if (c === Char.e) {
|
|
1248
|
+
this.emit("onvalue", false);
|
|
1249
|
+
this.state = this.stack.pop() || 1;
|
|
1250
|
+
} else
|
|
1251
|
+
this._error(`Invalid false started with fals${c}`);
|
|
1252
|
+
continue;
|
|
1253
|
+
case 19:
|
|
1254
|
+
if (c === Char.u)
|
|
1255
|
+
this.state = 20;
|
|
1256
|
+
else
|
|
1257
|
+
this._error(`Invalid null started with n${c}`);
|
|
1258
|
+
continue;
|
|
1259
|
+
case 20:
|
|
1260
|
+
if (c === Char.l)
|
|
1261
|
+
this.state = 21;
|
|
1262
|
+
else
|
|
1263
|
+
this._error(`Invalid null started with nu${c}`);
|
|
1264
|
+
continue;
|
|
1265
|
+
case 21:
|
|
1266
|
+
if (c === Char.l) {
|
|
1267
|
+
this.emit("onvalue", null);
|
|
1268
|
+
this.state = this.stack.pop() || 1;
|
|
1269
|
+
} else
|
|
1270
|
+
this._error(`Invalid null started with nul${c}`);
|
|
1271
|
+
continue;
|
|
1272
|
+
case 22:
|
|
1273
|
+
if (c === Char.period) {
|
|
1274
|
+
this.numberNode += ".";
|
|
1275
|
+
this.state = 23;
|
|
1276
|
+
} else
|
|
1277
|
+
this._error("Leading zero not followed by .");
|
|
1278
|
+
continue;
|
|
1279
|
+
case 23:
|
|
1280
|
+
if (Char._0 <= c && c <= Char._9)
|
|
1281
|
+
this.numberNode += String.fromCharCode(c);
|
|
1282
|
+
else if (c === Char.period) {
|
|
1283
|
+
if (this.numberNode.indexOf(".") !== -1)
|
|
1284
|
+
this._error("Invalid number has two dots");
|
|
1285
|
+
this.numberNode += ".";
|
|
1286
|
+
} else if (c === Char.e || c === Char.E) {
|
|
1287
|
+
if (this.numberNode.indexOf("e") !== -1 || this.numberNode.indexOf("E") !== -1)
|
|
1288
|
+
this._error("Invalid number has two exponential");
|
|
1289
|
+
this.numberNode += "e";
|
|
1290
|
+
} else if (c === Char.plus || c === Char.minus) {
|
|
1291
|
+
if (!(p === Char.e || p === Char.E))
|
|
1292
|
+
this._error("Invalid symbol in number");
|
|
1293
|
+
this.numberNode += String.fromCharCode(c);
|
|
1294
|
+
} else {
|
|
1295
|
+
this._closeNumber();
|
|
1296
|
+
i--;
|
|
1297
|
+
this.state = this.stack.pop() || 1;
|
|
1298
|
+
}
|
|
1299
|
+
continue;
|
|
1300
|
+
default:
|
|
1301
|
+
this._error(`Unknown state: ${this.state}`);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
1305
|
+
checkBufferLength(this);
|
|
1306
|
+
}
|
|
1307
|
+
this.emit("onchunkparsed");
|
|
1308
|
+
return this;
|
|
1309
|
+
}
|
|
1310
|
+
_closeValue(event = "onvalue") {
|
|
1311
|
+
if (this.textNode !== void 0) {
|
|
1312
|
+
this.emit(event, this.textNode);
|
|
1313
|
+
}
|
|
1314
|
+
this.textNode = void 0;
|
|
1315
|
+
}
|
|
1316
|
+
_closeNumber() {
|
|
1317
|
+
if (this.numberNode)
|
|
1318
|
+
this.emit("onvalue", parseFloat(this.numberNode));
|
|
1319
|
+
this.numberNode = "";
|
|
1320
|
+
}
|
|
1321
|
+
_error(message = "") {
|
|
1322
|
+
this._closeValue();
|
|
1323
|
+
message += `
|
|
1324
|
+
Line: ${this.line}
|
|
1325
|
+
Column: ${this.column}
|
|
1326
|
+
Char: ${this.c}`;
|
|
1327
|
+
const error = new Error(message);
|
|
1328
|
+
this.error = error;
|
|
1329
|
+
this.emit("onerror", error);
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
function isWhitespace(c) {
|
|
1333
|
+
return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
|
|
1334
|
+
}
|
|
1335
|
+
function checkBufferLength(parser) {
|
|
1336
|
+
const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
|
|
1337
|
+
let maxActual = 0;
|
|
1338
|
+
for (const buffer of ["textNode", "numberNode"]) {
|
|
1339
|
+
const len = parser[buffer] === void 0 ? 0 : parser[buffer].length;
|
|
1340
|
+
if (len > maxAllowed) {
|
|
1341
|
+
switch (buffer) {
|
|
1342
|
+
case "text":
|
|
1343
|
+
break;
|
|
1344
|
+
default:
|
|
1345
|
+
parser._error(`Max buffer length exceeded: ${buffer}`);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
maxActual = Math.max(maxActual, len);
|
|
1349
|
+
}
|
|
1350
|
+
parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// src/lib/jsonpath/jsonpath.ts
|
|
1354
|
+
var JSONPath = class {
|
|
1355
|
+
constructor(path = null) {
|
|
1356
|
+
this.path = ["$"];
|
|
1357
|
+
if (path instanceof JSONPath) {
|
|
1358
|
+
this.path = [...path.path];
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
if (Array.isArray(path)) {
|
|
1362
|
+
this.path.push(...path);
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
if (typeof path === "string") {
|
|
1366
|
+
this.path = path.split(".");
|
|
1367
|
+
if (this.path[0] !== "$") {
|
|
1368
|
+
throw new Error("JSONPaths must start with $");
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
clone() {
|
|
1373
|
+
return new JSONPath(this);
|
|
1374
|
+
}
|
|
1375
|
+
toString() {
|
|
1376
|
+
return this.path.join(".");
|
|
1377
|
+
}
|
|
1378
|
+
push(name) {
|
|
1379
|
+
this.path.push(name);
|
|
1380
|
+
}
|
|
1381
|
+
pop() {
|
|
1382
|
+
return this.path.pop();
|
|
1383
|
+
}
|
|
1384
|
+
set(name) {
|
|
1385
|
+
this.path[this.path.length - 1] = name;
|
|
1386
|
+
}
|
|
1387
|
+
equals(other) {
|
|
1388
|
+
if (!this || !other || this.path.length !== other.path.length) {
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
for (let i = 0; i < this.path.length; ++i) {
|
|
1392
|
+
if (this.path[i] !== other.path[i]) {
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return true;
|
|
1397
|
+
}
|
|
1398
|
+
setFieldAtPath(object, value) {
|
|
1399
|
+
const path = [...this.path];
|
|
1400
|
+
path.shift();
|
|
1401
|
+
const field = path.pop();
|
|
1402
|
+
for (const component of path) {
|
|
1403
|
+
object = object[component];
|
|
1404
|
+
}
|
|
1405
|
+
object[field] = value;
|
|
1406
|
+
}
|
|
1407
|
+
getFieldAtPath(object) {
|
|
1408
|
+
const path = [...this.path];
|
|
1409
|
+
path.shift();
|
|
1410
|
+
const field = path.pop();
|
|
1411
|
+
for (const component of path) {
|
|
1412
|
+
object = object[component];
|
|
1413
|
+
}
|
|
1414
|
+
return object[field];
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// src/lib/parser/json-parser.ts
|
|
1419
|
+
var JSONParser = class {
|
|
1420
|
+
constructor(options) {
|
|
1421
|
+
this.result = void 0;
|
|
1422
|
+
this.previousStates = [];
|
|
1423
|
+
this.currentState = Object.freeze({ container: [], key: null });
|
|
1424
|
+
this.jsonpath = new JSONPath();
|
|
1425
|
+
this.reset();
|
|
1426
|
+
this.parser = new ClarinetParser({
|
|
1427
|
+
onready: () => {
|
|
1428
|
+
this.jsonpath = new JSONPath();
|
|
1429
|
+
this.previousStates.length = 0;
|
|
1430
|
+
this.currentState.container.length = 0;
|
|
1431
|
+
},
|
|
1432
|
+
onopenobject: (name) => {
|
|
1433
|
+
this._openObject({});
|
|
1434
|
+
if (typeof name !== "undefined") {
|
|
1435
|
+
this.parser.emit("onkey", name);
|
|
1436
|
+
}
|
|
1437
|
+
},
|
|
1438
|
+
onkey: (name) => {
|
|
1439
|
+
this.jsonpath.set(name);
|
|
1440
|
+
this.currentState.key = name;
|
|
1441
|
+
},
|
|
1442
|
+
oncloseobject: () => {
|
|
1443
|
+
this._closeObject();
|
|
1444
|
+
},
|
|
1445
|
+
onopenarray: () => {
|
|
1446
|
+
this._openArray();
|
|
1447
|
+
},
|
|
1448
|
+
onclosearray: () => {
|
|
1449
|
+
this._closeArray();
|
|
1450
|
+
},
|
|
1451
|
+
onvalue: (value) => {
|
|
1452
|
+
this._pushOrSet(value);
|
|
1453
|
+
},
|
|
1454
|
+
onerror: (error) => {
|
|
1455
|
+
throw error;
|
|
1456
|
+
},
|
|
1457
|
+
onend: () => {
|
|
1458
|
+
this.result = this.currentState.container.pop();
|
|
1459
|
+
},
|
|
1460
|
+
...options
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
reset() {
|
|
1464
|
+
this.result = void 0;
|
|
1465
|
+
this.previousStates = [];
|
|
1466
|
+
this.currentState = Object.freeze({ container: [], key: null });
|
|
1467
|
+
this.jsonpath = new JSONPath();
|
|
1468
|
+
}
|
|
1469
|
+
write(chunk) {
|
|
1470
|
+
this.parser.write(chunk);
|
|
1471
|
+
}
|
|
1472
|
+
close() {
|
|
1473
|
+
this.parser.close();
|
|
1474
|
+
}
|
|
1475
|
+
_pushOrSet(value) {
|
|
1476
|
+
const { container, key } = this.currentState;
|
|
1477
|
+
if (key !== null) {
|
|
1478
|
+
container[key] = value;
|
|
1479
|
+
this.currentState.key = null;
|
|
1480
|
+
} else {
|
|
1481
|
+
container.push(value);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
_openArray(newContainer = []) {
|
|
1485
|
+
this.jsonpath.push(null);
|
|
1486
|
+
this._pushOrSet(newContainer);
|
|
1487
|
+
this.previousStates.push(this.currentState);
|
|
1488
|
+
this.currentState = { container: newContainer, isArray: true, key: null };
|
|
1489
|
+
}
|
|
1490
|
+
_closeArray() {
|
|
1491
|
+
this.jsonpath.pop();
|
|
1492
|
+
this.currentState = this.previousStates.pop();
|
|
1493
|
+
}
|
|
1494
|
+
_openObject(newContainer = {}) {
|
|
1495
|
+
this.jsonpath.push(null);
|
|
1496
|
+
this._pushOrSet(newContainer);
|
|
1497
|
+
this.previousStates.push(this.currentState);
|
|
1498
|
+
this.currentState = { container: newContainer, isArray: false, key: null };
|
|
1499
|
+
}
|
|
1500
|
+
_closeObject() {
|
|
1501
|
+
this.jsonpath.pop();
|
|
1502
|
+
this.currentState = this.previousStates.pop();
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
// src/lib/parser/streaming-json-parser.ts
|
|
1507
|
+
var StreamingJSONParser = class extends JSONParser {
|
|
1508
|
+
constructor(options = {}) {
|
|
1509
|
+
super({
|
|
1510
|
+
onopenarray: () => {
|
|
1511
|
+
if (!this.streamingArray) {
|
|
1512
|
+
if (this._matchJSONPath()) {
|
|
1513
|
+
this.streamingJsonPath = this.getJsonPath().clone();
|
|
1514
|
+
this.streamingArray = [];
|
|
1515
|
+
this._openArray(this.streamingArray);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
this._openArray();
|
|
1520
|
+
},
|
|
1521
|
+
onopenobject: (name) => {
|
|
1522
|
+
if (!this.topLevelObject) {
|
|
1523
|
+
this.topLevelObject = {};
|
|
1524
|
+
this._openObject(this.topLevelObject);
|
|
1525
|
+
} else {
|
|
1526
|
+
this._openObject({});
|
|
1527
|
+
}
|
|
1528
|
+
if (typeof name !== "undefined") {
|
|
1529
|
+
this.parser.emit("onkey", name);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
this.streamingJsonPath = null;
|
|
1534
|
+
this.streamingArray = null;
|
|
1535
|
+
this.topLevelObject = null;
|
|
1536
|
+
const jsonpaths = options.jsonpaths || [];
|
|
1537
|
+
this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
|
|
1538
|
+
}
|
|
1539
|
+
write(chunk) {
|
|
1540
|
+
super.write(chunk);
|
|
1541
|
+
let array = [];
|
|
1542
|
+
if (this.streamingArray) {
|
|
1543
|
+
array = [...this.streamingArray];
|
|
1544
|
+
this.streamingArray.length = 0;
|
|
1545
|
+
}
|
|
1546
|
+
return array;
|
|
1547
|
+
}
|
|
1548
|
+
getPartialResult() {
|
|
1549
|
+
return this.topLevelObject;
|
|
1550
|
+
}
|
|
1551
|
+
getStreamingJsonPath() {
|
|
1552
|
+
return this.streamingJsonPath;
|
|
1553
|
+
}
|
|
1554
|
+
getStreamingJsonPathAsString() {
|
|
1555
|
+
return this.streamingJsonPath && this.streamingJsonPath.toString();
|
|
1556
|
+
}
|
|
1557
|
+
getJsonPath() {
|
|
1558
|
+
return this.jsonpath;
|
|
1559
|
+
}
|
|
1560
|
+
_matchJSONPath() {
|
|
1561
|
+
const currentPath = this.getJsonPath();
|
|
1562
|
+
if (this.jsonPaths.length === 0) {
|
|
1563
|
+
return true;
|
|
1564
|
+
}
|
|
1565
|
+
for (const jsonPath of this.jsonPaths) {
|
|
1566
|
+
if (jsonPath.equals(currentPath)) {
|
|
1567
|
+
return true;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return false;
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
// src/lib/parse-json-in-batches.ts
|
|
1575
|
+
async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
1576
|
+
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
1577
|
+
const { metadata } = options;
|
|
1578
|
+
const { jsonpaths } = options.json || {};
|
|
1579
|
+
let isFirstChunk = true;
|
|
1580
|
+
const schema = null;
|
|
1581
|
+
const shape = options?.json?.shape || "row-table";
|
|
1582
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
1583
|
+
...options,
|
|
1584
|
+
shape
|
|
1585
|
+
});
|
|
1586
|
+
const parser = new StreamingJSONParser({ jsonpaths });
|
|
1587
|
+
for await (const chunk of asyncIterator) {
|
|
1588
|
+
const rows = parser.write(chunk);
|
|
1589
|
+
const jsonpath2 = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
1590
|
+
if (rows.length > 0 && isFirstChunk) {
|
|
1591
|
+
if (metadata) {
|
|
1592
|
+
const initialBatch = {
|
|
1593
|
+
shape,
|
|
1594
|
+
batchType: "partial-result",
|
|
1595
|
+
data: [],
|
|
1596
|
+
length: 0,
|
|
1597
|
+
bytesUsed: 0,
|
|
1598
|
+
container: parser.getPartialResult(),
|
|
1599
|
+
jsonpath: jsonpath2
|
|
1600
|
+
};
|
|
1601
|
+
yield initialBatch;
|
|
1602
|
+
}
|
|
1603
|
+
isFirstChunk = false;
|
|
1604
|
+
}
|
|
1605
|
+
for (const row of rows) {
|
|
1606
|
+
tableBatchBuilder.addRow(row);
|
|
1607
|
+
const batch3 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1608
|
+
if (batch3) {
|
|
1609
|
+
yield batch3;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
tableBatchBuilder.chunkComplete(chunk);
|
|
1613
|
+
const batch2 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1614
|
+
if (batch2) {
|
|
1615
|
+
yield batch2;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
1619
|
+
const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
|
|
1620
|
+
if (batch) {
|
|
1621
|
+
yield batch;
|
|
1622
|
+
}
|
|
1623
|
+
if (metadata) {
|
|
1624
|
+
const finalBatch = {
|
|
1625
|
+
shape,
|
|
1626
|
+
batchType: "final-result",
|
|
1627
|
+
container: parser.getPartialResult(),
|
|
1628
|
+
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
1629
|
+
data: [],
|
|
1630
|
+
length: 0
|
|
1631
|
+
};
|
|
1632
|
+
yield finalBatch;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// src/geojson-loader.ts
|
|
1637
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1638
|
+
var DEFAULT_GEOJSON_LOADER_OPTIONS = {
|
|
1639
|
+
geojson: {
|
|
1640
|
+
shape: "object-row-table"
|
|
1641
|
+
},
|
|
1642
|
+
json: {
|
|
1643
|
+
jsonpaths: ["$", "$.features"]
|
|
1644
|
+
},
|
|
1645
|
+
gis: {
|
|
1646
|
+
format: "geojson"
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
var GeoJSONWorkerLoader = {
|
|
1650
|
+
name: "GeoJSON",
|
|
1651
|
+
id: "geojson",
|
|
1652
|
+
module: "geojson",
|
|
1653
|
+
version: VERSION,
|
|
1654
|
+
worker: true,
|
|
1655
|
+
extensions: ["geojson"],
|
|
1656
|
+
mimeTypes: ["application/geo+json"],
|
|
1657
|
+
category: "geometry",
|
|
1658
|
+
text: true,
|
|
1659
|
+
options: DEFAULT_GEOJSON_LOADER_OPTIONS
|
|
1660
|
+
};
|
|
1661
|
+
var GeoJSONLoader = {
|
|
1662
|
+
...GeoJSONWorkerLoader,
|
|
1663
|
+
parse,
|
|
1664
|
+
parseTextSync,
|
|
1665
|
+
parseInBatches
|
|
1666
|
+
};
|
|
1667
|
+
async function parse(arrayBuffer, options) {
|
|
1668
|
+
return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
|
|
1669
|
+
}
|
|
1670
|
+
function parseTextSync(text, options) {
|
|
1671
|
+
options = { ...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options };
|
|
1672
|
+
options.json = { ...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson };
|
|
1673
|
+
options.gis = options.gis || {};
|
|
1674
|
+
const json = parseJSONSync(text, options);
|
|
1675
|
+
switch (options.gis.format) {
|
|
1676
|
+
case "binary":
|
|
1677
|
+
return geojsonToBinary(json);
|
|
1678
|
+
default:
|
|
1679
|
+
return json;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
function parseInBatches(asyncIterator, options) {
|
|
1683
|
+
options = { ...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options };
|
|
1684
|
+
options.json = { ...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson };
|
|
1685
|
+
const geojsonIterator = parseJSONInBatches(asyncIterator, options);
|
|
1686
|
+
switch (options.gis.format) {
|
|
1687
|
+
case "binary":
|
|
1688
|
+
return makeBinaryGeometryIterator(geojsonIterator);
|
|
1689
|
+
default:
|
|
1690
|
+
return geojsonIterator;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
async function* makeBinaryGeometryIterator(geojsonIterator) {
|
|
1694
|
+
for await (const batch of geojsonIterator) {
|
|
1695
|
+
batch.data = geojsonToBinary(batch.data);
|
|
1696
|
+
yield batch;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// src/workers/geojson-worker.ts
|
|
1701
|
+
createLoaderWorker(GeoJSONLoader);
|
|
1702
|
+
})();
|