@loaders.gl/json 3.0.9 → 3.0.13
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/dist.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geojson-loader.js +29 -143
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/json-loader.js +18 -44
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/clarinet/clarinet.js +373 -393
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +54 -101
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/es5/lib/parse-json-in-batches.js +78 -237
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-json.js +4 -9
- package/dist/es5/lib/parse-json.js.map +1 -1
- package/dist/es5/lib/parser/json-parser.js +112 -133
- package/dist/es5/lib/parser/json-parser.js.map +1 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +65 -125
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/esm/geojson-loader.js +1 -1
- package/dist/esm/geojson-loader.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/json-loader.js.map +1 -1
- package/dist/geojson-worker.js +1 -1
- package/dist/geojson-worker.js.map +1 -1
- package/package.json +5 -5
package/dist/dist.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var o in s)("object"==typeof exports?exports:t)[o]=s[o]}}(window,(function(){return function(t){var e={};function s(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=e,s.d=function(t,e,o){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(s.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)s.d(o,i,function(e){return t[e]}.bind(null,i));return o},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=0)}([function(t,e,s){(function(e){const o=s(2),i="undefined"==typeof window?e:window;i.loaders=i.loaders||{},t.exports=Object.assign(i.loaders,o)}).call(this,s(1))},function(t,e){var s;s=function(){return this}();try{s=s||new Function("return this")()}catch(t){"object"==typeof window&&(s=window)}t.exports=s},function(t,e,s){"use strict";function o(t,e){try{var s;const o=JSON.parse(t);return null!==(s=e.json)&&void 0!==s&&s.table&&function t(e){if(Array.isArray(e))return e;if(e&&"object"==typeof e)for(const s of Object.values(e)){const e=t(s);if(e)return e}return null}(o)||o}catch(t){throw new Error("JSONLoader: failed to parse JSON")}}function i(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}s.r(e),s.d(e,"JSONLoader",(function(){return at})),s.d(e,"_GeoJSONLoader",(function(){return Et})),s.d(e,"_GeoJSONWorkerLoader",(function(){return vt})),s.d(e,"_JSONPath",(function(){return et})),s.d(e,"_ClarinetParser",(function(){return q}));class n{constructor(t,e){if(i(this,"schema",void 0),i(this,"options",void 0),i(this,"length",0),i(this,"rows",null),i(this,"cursor",0),i(this,"_headers",[]),this.options=e,this.schema=t,!Array.isArray(t)){this._headers=[];for(const e in t)this._headers[t[e].index]=t[e].name}}rowCount(){return this.length}addArrayRow(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}addObjectRow(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}getBatch(){let t=this.rows;if(!t)return null;t=t.slice(0,this.length),this.rows=null;return{shape:this.options.shape,batchType:"data",data:t,length:this.length,schema:this.schema,cursor:this.cursor}}}function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class a{constructor(t,e){if(r(this,"schema",void 0),r(this,"options",void 0),r(this,"length",0),r(this,"objectRows",null),r(this,"arrayRows",null),r(this,"cursor",0),r(this,"_headers",[]),this.options=e,this.schema=t,!Array.isArray(t)){this._headers=[];for(const e in t)this._headers[t[e].index]=t[e].name}}rowCount(){return this.length}addArrayRow(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"object-row-table":const s=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");const s={};for(let o=0;o<e.length;o++)s[e[o]]=t[o];return s}(t,this._headers);this.addObjectRow(s,e);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=t,this.length++}}addObjectRow(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"array-row-table":const s=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");const s=new Array(e.length);for(let o=0;o<e.length;o++)s[o]=t[e[o]];return s}(t,this._headers);this.addArrayRow(s,e);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=t,this.length++}}getBatch(){let 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}}function h(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class c{constructor(t,e){h(this,"schema",void 0),h(this,"length",0),h(this,"allocated",0),h(this,"columns",{}),this.schema=t,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(t){this._reallocateColumns();let e=0;for(const s in this.columns)this.columns[s][this.length]=t[e++];this.length++}addObjectRow(t){this._reallocateColumns();for(const e in t)this.columns[e][this.length]=t[e];this.length++}getBatch(){this._pruneColumns();const t=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(const e in this.schema){const s=this.schema[e];t[s.name]=this.columns[s.index]}this.columns={};return{shape:"columnar-table",batchType:"data",data:t,schema:this.schema,length:this.length}}_reallocateColumns(){if(!(this.length<this.allocated)){this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={};for(const t in this.schema){const e=this.schema[t],s=e.type||Float32Array,o=this.columns[e.index];if(o&&ArrayBuffer.isView(o)){const t=new s(this.allocated);t.set(o),this.columns[e.index]=t}else o?(o.length=this.allocated,this.columns[e.index]=o):this.columns[e.index]=new s(this.allocated)}}}_pruneColumns(){for(const[t,e]of Object.entries(this.columns))this.columns[t]=e.slice(0,this.length)}}function l(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}const u={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0};class p{constructor(t,e){l(this,"schema",void 0),l(this,"options",void 0),l(this,"aggregator",null),l(this,"batchCount",0),l(this,"bytesUsed",0),l(this,"isChunkComplete",!1),l(this,"lastBatchEmittedMs",Date.now()),l(this,"totalLength",0),l(this,"totalBytes",0),l(this,"rowBytes",0),this.schema=t,this.options={...u,...e}}limitReached(){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)}addRow(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))}addArrayRow(t){if(!this.aggregator){const t=this._getTableBatchType();this.aggregator=new t(this.schema,this.options)}this.aggregator.addArrayRow(t)}addObjectRow(t){if(!this.aggregator){const t=this._getTableBatchType();this.aggregator=new t(this.schema,this.options)}this.aggregator.addObjectRow(t)}chunkComplete(t){t instanceof ArrayBuffer&&(this.bytesUsed+=t.byteLength),"string"==typeof t&&(this.bytesUsed+=t.length),this.isChunkComplete=!0}getFullBatch(t){return this._isFull()?this._getBatch(t):null}getFinalBatch(t){return this._getBatch(t)}_estimateRowMB(t){return Array.isArray(t)?8*t.length:8*Object.keys(t).length}_isFull(){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)}_getBatch(t){if(!this.aggregator)return null;null!=t&&t.bytesUsed&&(this.bytesUsed=t.bytesUsed);const e=this.aggregator.getBatch();return e.count=this.batchCount,e.bytesUsed=this.bytesUsed,Object.assign(e,t),this.batchCount++,this.aggregator=null,e}_getTableBatchType(){switch(this.options.shape){case"row-table":return n;case"array-row-table":case"object-row-table":return a;case"columnar-table":return c;case"arrow-table":if(!p.ArrowBatch)throw new Error("TableBatchBuilder");return p.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}l(p,"ArrowBatch",void 0);const d=Number.MAX_SAFE_INTEGER,f="debug"==={}.CDEBUG,g={textNode:void 0,numberNode:""};let y=0;const b={BEGIN:y++,VALUE:y++,OPEN_OBJECT:y++,CLOSE_OBJECT:y++,OPEN_ARRAY:y++,CLOSE_ARRAY:y++,TEXT_ESCAPE:y++,STRING:y++,BACKSLASH:y++,END:y++,OPEN_KEY:y++,CLOSE_KEY:y++,TRUE:y++,TRUE2:y++,TRUE3:y++,FALSE:y++,FALSE2:y++,FALSE3:y++,FALSE4:y++,NULL:y++,NULL2:y++,NULL3:y++,NUMBER_DECIMAL_POINT:y++,NUMBER_DIGIT:y++};for(var w in b)b[b[w]]=w;y=b;const m=9,A=10,j=13,P=32,v=34,E=43,S=44,_=45,O=46,C=48,N=57,L=58,I=69,R=91,B=92,U=93,k=97,x=98,F=101,T=102,J=108,M=110,z=114,D=115,Y=116,G=117,V=123,K=125;var $=/[\\"\n]/g;class q{constructor(t={}){this._initialize(t)}_initialize(t){this._clearBuffers(this),this.bufferCheckPosition=d,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=y.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),X(this,"onready")}_clearBuffers(){for(var t in g)this[t]=g[t]}end(){return this.state===y.VALUE&&0===this.depth||Z(this,"Unexpected end"),W(this),this.c="",this.closed=!0,X(this,"onend"),this._initialize(this.options),this}resume(){return this.error=null,this}close(){return this.write(null)}write(t){if(this.error)throw this.error;if(this.closed)return Z(this,"Cannot write after close. Assign an onready handler.");if(null===t)return this.end();var e=0,s=t.charCodeAt(0),o=this.p;for(f&&console.log("write -> ["+t+"]");s&&(o=s,this.c=s=t.charCodeAt(e++),o!==s?this.p=o:o=this.p,s);)switch(f&&console.log(e,s,b[this.state]),this.position++,s===A?(this.line++,this.column=0):this.column++,this.state){case y.BEGIN:s===V?this.state=y.OPEN_OBJECT:s===R?this.state=y.OPEN_ARRAY:tt(s)||Z(this,"Non-whitespace before {[.");continue;case y.OPEN_KEY:case y.OPEN_OBJECT:if(tt(s))continue;if(this.state===y.OPEN_KEY)this.stack.push(y.CLOSE_KEY);else{if(s===K){X(this,"onopenobject"),this.depth++,X(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||y.VALUE;continue}this.stack.push(y.CLOSE_OBJECT)}s===v?this.state=y.STRING:Z(this,'Malformed object key should start with "');continue;case y.CLOSE_KEY:case y.CLOSE_OBJECT:if(tt(s))continue;this.state,y.CLOSE_KEY;s===L?(this.state===y.CLOSE_OBJECT?(this.stack.push(y.CLOSE_OBJECT),W(this,"onopenobject"),this.depth++):W(this,"onkey"),this.state=y.VALUE):s===K?(H(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||y.VALUE):s===S?(this.state===y.CLOSE_OBJECT&&this.stack.push(y.CLOSE_OBJECT),W(this),this.state=y.OPEN_KEY):Z(this,"Bad object");continue;case y.OPEN_ARRAY:case y.VALUE:if(tt(s))continue;if(this.state===y.OPEN_ARRAY){if(X(this,"onopenarray"),this.depth++,this.state=y.VALUE,s===U){X(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||y.VALUE;continue}this.stack.push(y.CLOSE_ARRAY)}s===v?this.state=y.STRING:s===V?this.state=y.OPEN_OBJECT:s===R?this.state=y.OPEN_ARRAY:s===Y?this.state=y.TRUE:s===T?this.state=y.FALSE:s===M?this.state=y.NULL:s===_?this.numberNode+="-":C<=s&&s<=N?(this.numberNode+=String.fromCharCode(s),this.state=y.NUMBER_DIGIT):Z(this,"Bad value");continue;case y.CLOSE_ARRAY:if(s===S)this.stack.push(y.CLOSE_ARRAY),W(this,"onvalue"),this.state=y.VALUE;else if(s===U)H(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||y.VALUE;else{if(tt(s))continue;Z(this,"Bad array")}continue;case y.STRING:void 0===this.textNode&&(this.textNode="");var i=e-1,n=this.slashed,r=this.unicodeI;t:for(;;){for(f&&console.log(e,s,b[this.state],n);r>0;)if(this.unicodeS+=String.fromCharCode(s),s=t.charCodeAt(e++),this.position++,4===r?(this.textNode+=String.fromCharCode(parseInt(this.unicodeS,16)),r=0,i=e-1):r++,!s)break t;if(s===v&&!n){this.state=this.stack.pop()||y.VALUE,this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}if(s===B&&!n&&(n=!0,this.textNode+=t.substring(i,e-1),this.position+=e-1-i,s=t.charCodeAt(e++),this.position++,!s))break;if(n){if(n=!1,s===M?this.textNode+="\n":s===z?this.textNode+="\r":s===Y?this.textNode+="\t":s===T?this.textNode+="\f":s===x?this.textNode+="\b":s===G?(r=1,this.unicodeS=""):this.textNode+=String.fromCharCode(s),s=t.charCodeAt(e++),this.position++,i=e-1,s)continue;break}$.lastIndex=e;var a=$.exec(t);if(null===a){e=t.length+1,this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}if(e=a.index+1,!(s=t.charCodeAt(a.index))){this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}}this.slashed=n,this.unicodeI=r;continue;case y.TRUE:s===z?this.state=y.TRUE2:Z(this,"Invalid true started with t"+s);continue;case y.TRUE2:s===G?this.state=y.TRUE3:Z(this,"Invalid true started with tr"+s);continue;case y.TRUE3:s===F?(X(this,"onvalue",!0),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid true started with tru"+s);continue;case y.FALSE:s===k?this.state=y.FALSE2:Z(this,"Invalid false started with f"+s);continue;case y.FALSE2:s===J?this.state=y.FALSE3:Z(this,"Invalid false started with fa"+s);continue;case y.FALSE3:s===D?this.state=y.FALSE4:Z(this,"Invalid false started with fal"+s);continue;case y.FALSE4:s===F?(X(this,"onvalue",!1),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid false started with fals"+s);continue;case y.NULL:s===G?this.state=y.NULL2:Z(this,"Invalid null started with n"+s);continue;case y.NULL2:s===J?this.state=y.NULL3:Z(this,"Invalid null started with nu"+s);continue;case y.NULL3:s===J?(X(this,"onvalue",null),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid null started with nul"+s);continue;case y.NUMBER_DECIMAL_POINT:s===O?(this.numberNode+=".",this.state=y.NUMBER_DIGIT):Z(this,"Leading zero not followed by .");continue;case y.NUMBER_DIGIT:C<=s&&s<=N?this.numberNode+=String.fromCharCode(s):s===O?(-1!==this.numberNode.indexOf(".")&&Z(this,"Invalid number has two dots"),this.numberNode+="."):s===F||s===I?(-1===this.numberNode.indexOf("e")&&-1===this.numberNode.indexOf("E")||Z(this,"Invalid number has two exponential"),this.numberNode+="e"):s===E||s===_?(o!==F&&o!==I&&Z(this,"Invalid symbol in number"),this.numberNode+=String.fromCharCode(s)):(Q(this),e--,this.state=this.stack.pop()||y.VALUE);continue;default:Z(this,"Unknown state: "+this.state)}return this.position>=this.bufferCheckPosition&&function(t){const e=Math.max(d,10);let s=0;for(var o in g){var i=void 0===t[o]?0:t[o].length;if(i>e)switch(o){case"text":closeText(t);break;default:Z(t,"Max buffer length exceeded: "+o)}s=Math.max(s,i)}t.bufferCheckPosition=d-s+t.position}(this),X(this,"onchunkparsed"),this}}function X(t,e,s){f&&console.log("-- emit",e,s),t[e]&&t[e](s,t)}function H(t,e,s){W(t),X(t,e,s)}function W(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&&X(t,e||"onvalue",t.textNode),t.textNode=void 0}function Q(t){t.numberNode&&X(t,"onvalue",parseFloat(t.numberNode)),t.numberNode=""}function Z(t,e){return W(t),e+="\nLine: "+t.line+"\nColumn: "+t.column+"\nChar: "+t.c,e=new Error(e),t.error=e,X(t,"onerror",e),t}function tt(t){return t===j||t===A||t===P||t===m}class et{constructor(t=null){var e,s,o;if(o=void 0,(s="path")in(e=this)?Object.defineProperty(e,s,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[s]=o,this.path=["$"],t instanceof et)this.path=[...t.path];else if(Array.isArray(t))this.path.push(...t);else if("string"==typeof t&&(this.path=t.split("."),"$"!==this.path[0]))throw new Error("JSONPaths must start with $")}clone(){return new et(this)}toString(){return this.path.join(".")}push(t){this.path.push(t)}pop(){return this.path.pop()}set(t){this.path[this.path.length-1]=t}equals(t){if(!this||!t||this.path.length!==t.path.length)return!1;for(let e=0;e<this.path.length;++e)if(this.path[e]!==t.path[e])return!1;return!0}setFieldAtPath(t,e){const s=[...this.path];s.shift();const o=s.pop();for(const e of s)t=t[e];t[o]=e}getFieldAtPath(t){const e=[...this.path];e.shift();const s=e.pop();for(const s of e)t=t[s];return t[s]}}function st(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function ot(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class it extends class{constructor(){st(this,"jsonpath",void 0),st(this,"_parser",void 0),this.reset(),this._initializeParser()}reset(){this.result=void 0,this.previousStates=[],this.currentState=Object.freeze({container:[],key:null}),this.jsonpath=new et}write(t){this.parser.write(t)}close(){this.parser.close()}_pushOrSet(t){const{container:e,key:s}=this.currentState;null!==s?(e[s]=t,this.currentState.key=null):e.push(t)}_openArray(t=[]){this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!0,key:null}}_closeArray(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}_openObject(t={}){this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!1,key:null}}_closeObject(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}_initializeParser(){this._parser=new q({onready:()=>{this.jsonpath=new et,this.previousStates.length=0,this.currentState.container.length=0},onopenobject:t=>{this._openObject({}),void 0!==t&&this.parser.onkey(t)},onkey:t=>{this.jsonpath.set(t),this.currentState.key=t},oncloseobject:()=>{this._closeObject()},onopenarray:()=>{this._openArray()},onclosearray:()=>{this._closeArray()},onvalue:t=>{this._pushOrSet(t)},onerror:t=>{throw t},onend:()=>{this.result=this.currentState.container.pop()}})}get parser(){return this._parser}}{constructor(t={}){super(),ot(this,"jsonPaths",void 0),ot(this,"streamingJsonPath",null),ot(this,"streamingArray",null),ot(this,"topLevelObject",null);const e=t.jsonpaths||[];this.jsonPaths=e.map(t=>new et(t)),this._extendParser()}write(t){super.write(t);let e=[];return this.streamingArray&&(e=[...this.streamingArray],this.streamingArray.length=0),e}getPartialResult(){return this.topLevelObject}getStreamingJsonPath(){return this.streamingJsonPath}getStreamingJsonPathAsString(){return this.streamingJsonPath&&this.streamingJsonPath.toString()}getJsonPath(){return this.jsonpath}_matchJSONPath(){const t=this.getJsonPath();if(0===this.jsonPaths.length)return!0;for(const e of this.jsonPaths)if(e.equals(t))return!0;return!1}_extendParser(){this.parser.onopenarray=()=>{if(!this.streamingArray&&this._matchJSONPath())return this.streamingJsonPath=this.getJsonPath().clone(),this.streamingArray=[],void this._openArray(this.streamingArray);this._openArray()},this.parser.onopenobject=t=>{this.topLevelObject?this._openObject({}):(this.topLevelObject={},this._openObject(this.topLevelObject)),void 0!==t&&this.parser.onkey(t)}}}async function*nt(t,e){var s;const o=async function*(t,e={}){const s=new TextDecoder(void 0,e);for await(const e of t)yield"string"==typeof e?e:s.decode(e,{stream:!0})}(t),{metadata:i}=e,{jsonpaths:n}=e.json||{};let r=!0;const a=(null==e||null===(s=e.json)||void 0===s?void 0:s.shape)||"row-table",h=new p(null,{...e,shape:a}),c=new it({jsonpaths:n});for await(const t of o){const e=c.write(t),s=e.length>0&&c.getStreamingJsonPathAsString();if(e.length>0&&r){if(i){const t={shape:a,batchType:"partial-result",data:[],length:0,bytesUsed:0,container:c.getPartialResult(),jsonpath:s};yield t}r=!1}for(const t of e){h.addRow(t);const e=h.getFullBatch({jsonpath:s});e&&(yield e)}h.chunkComplete(t);const o=h.getFullBatch({jsonpath:s});o&&(yield o)}const l=c.getStreamingJsonPathAsString(),u=h.getFinalBatch({jsonpath:l});if(u&&(yield u),i){const t={shape:a,batchType:"final-result",container:c.getPartialResult(),jsonpath:c.getStreamingJsonPathAsString(),data:[],length:0};yield t}}const rt={json:{shape:"row-table",table:!1,jsonpaths:[]}},at={name:"JSON",id:"json",module:"json",version:"3.0.9",extensions:["json","geojson"],mimeTypes:["application/json"],category:"table",text:!0,parse:async function(t,e){return ht((new TextDecoder).decode(t),e)},parseTextSync:ht,parseInBatches:function(t,e){const s={...e,json:{...rt.json,...null==e?void 0:e.json}};return nt(t,s)},options:rt};function ht(t,e){return o(t,{...e,json:{...rt.json,...null==e?void 0:e.json}})}function ct(t,e={}){const s=lt(t);return ut(t,s,{coordLength:e.coordLength||s.coordLength,numericPropKeys:e.numericPropKeys||s.numericPropKeys,PositionDataType:e.PositionDataType||Float32Array})}function lt(t){let e=0,s=0,o=0,i=0,n=0,r=0,a=0,h=0,c=0;const l=new Set,u={};for(const d of t){const t=d.geometry;switch(t.type){case"Point":s++,e++,l.add(t.coordinates.length);break;case"MultiPoint":s++,e+=t.coordinates.length;for(const e of t.coordinates)l.add(e.length);break;case"LineString":n++,o+=t.coordinates.length,i++;for(const e of t.coordinates)l.add(e.length);break;case"MultiLineString":n++;for(const e of t.coordinates){o+=e.length,i++;for(const t of e)l.add(t.length)}break;case"Polygon":c++,a++,h+=t.coordinates.length,r+=jt(t.coordinates).length;for(const e of jt(t.coordinates))l.add(e.length);break;case"MultiPolygon":c++;for(const e of t.coordinates){a++,h+=e.length,r+=jt(e).length;for(const t of jt(e))l.add(t.length)}break;default:throw new Error("Unsupported geometry type: "+t.type)}if(d.properties)for(const t in d.properties){const e=d.properties[t];u[t]=u[t]||void 0===u[t]?(p=e,Number.isFinite(p)):u[t]}}var p;return{coordLength:l.size>0?Math.max(...l):2,pointPositionsCount:e,pointFeaturesCount:s,linePositionsCount:o,linePathsCount:i,lineFeaturesCount:n,polygonPositionsCount:r,polygonObjectsCount:a,polygonRingsCount:h,polygonFeaturesCount:c,numericPropKeys:Object.keys(u).filter(t=>u[t])}}function ut(t,e,s){const{pointPositionsCount:o,pointFeaturesCount:i,linePositionsCount:n,linePathsCount:r,lineFeaturesCount:a,polygonPositionsCount:h,polygonObjectsCount:c,polygonRingsCount:l,polygonFeaturesCount:u}=e,{coordLength:p,numericPropKeys:d,PositionDataType:f=Float32Array}=s,g=t.length>65535?Uint32Array:Uint16Array,y={positions:new f(o*p),globalFeatureIds:new g(o),featureIds:i>65535?new Uint32Array(o):new Uint16Array(o),numericProps:{},properties:Array(),fields:Array()},b={positions:new f(n*p),pathIndices:n>65535?new Uint32Array(r+1):new Uint16Array(r+1),globalFeatureIds:new g(n),featureIds:a>65535?new Uint32Array(n):new Uint16Array(n),numericProps:{},properties:Array(),fields:Array()},w={positions:new f(h*p),polygonIndices:h>65535?new Uint32Array(c+1):new Uint16Array(c+1),primitivePolygonIndices:h>65535?new Uint32Array(l+1):new Uint16Array(l+1),globalFeatureIds:new g(h),featureIds:u>65535?new Uint32Array(h):new Uint16Array(h),numericProps:{},properties:Array(),fields:Array()};for(const t of[y,b,w])for(const e of d||[])t.numericProps[e]=new Float32Array(t.positions.length/p);b.pathIndices[r]=n,w.polygonIndices[c]=h,w.primitivePolygonIndices[l]=h;const m={pointPosition:0,pointFeature:0,linePosition:0,linePath:0,lineFeature:0,polygonPosition:0,polygonObject:0,polygonRing:0,polygonFeature:0,feature:0};for(const e of t){const t=e.geometry,s=e.properties||{};switch(t.type){case"Point":pt(t.coordinates,y,m,p,s),y.properties.push(mt(s,d)),m.pointFeature++;break;case"MultiPoint":dt(t.coordinates,y,m,p,s),y.properties.push(mt(s,d)),m.pointFeature++;break;case"LineString":ft(t.coordinates,b,m,p,s),b.properties.push(mt(s,d)),m.lineFeature++;break;case"MultiLineString":gt(t.coordinates,b,m,p,s),b.properties.push(mt(s,d)),m.lineFeature++;break;case"Polygon":yt(t.coordinates,w,m,p,s),w.properties.push(mt(s,d)),m.polygonFeature++;break;case"MultiPolygon":bt(t.coordinates,w,m,p,s),w.properties.push(mt(s,d)),m.polygonFeature++;break;default:throw new Error("Invalid geometry type")}m.feature++}return function(t,e,s,o){const i={points:{...t,positions:{value:t.positions,size:o},globalFeatureIds:{value:t.globalFeatureIds,size:1},featureIds:{value:t.featureIds,size:1},type:"Point"},lines:{...e,pathIndices:{value:e.pathIndices,size:1},positions:{value:e.positions,size:o},globalFeatureIds:{value:e.globalFeatureIds,size:1},featureIds:{value:e.featureIds,size:1},type:"LineString"},polygons:{...s,polygonIndices:{value:s.polygonIndices,size:1},primitivePolygonIndices:{value:s.primitivePolygonIndices,size:1},positions:{value:s.positions,size:o},globalFeatureIds:{value:s.globalFeatureIds,size:1},featureIds:{value:s.featureIds,size:1},type:"Polygon"}};for(const t in i)for(const e in i[t].numericProps)i[t].numericProps[e]={value:i[t].numericProps[e],size:1};return i}(y,b,w,p)}function pt(t,e,s,o,i){e.positions.set(t,s.pointPosition*o),e.globalFeatureIds[s.pointPosition]=s.feature,e.featureIds[s.pointPosition]=s.pointFeature,wt(e,i,s.pointPosition,1),s.pointPosition++}function dt(t,e,s,o,i){for(const n of t)pt(n,e,s,o,i)}function ft(t,e,s,o,i){e.pathIndices[s.linePath]=s.linePosition,s.linePath++,At(e.positions,t,s.linePosition,o);const n=t.length;wt(e,i,s.linePosition,n),e.globalFeatureIds.set(new Uint32Array(n).fill(s.feature),s.linePosition),e.featureIds.set(new Uint32Array(n).fill(s.lineFeature),s.linePosition),s.linePosition+=n}function gt(t,e,s,o,i){for(const n of t)ft(n,e,s,o,i)}function yt(t,e,s,o,i){e.polygonIndices[s.polygonObject]=s.polygonPosition,s.polygonObject++;for(const n of t){e.primitivePolygonIndices[s.polygonRing]=s.polygonPosition,s.polygonRing++,At(e.positions,n,s.polygonPosition,o);const t=n.length;wt(e,i,s.polygonPosition,t),e.globalFeatureIds.set(new Uint32Array(t).fill(s.feature),s.polygonPosition),e.featureIds.set(new Uint32Array(t).fill(s.polygonFeature),s.polygonPosition),s.polygonPosition+=t}}function bt(t,e,s,o,i){for(const n of t)yt(n,e,s,o,i)}function wt(t,e,s,o){for(const i in t.numericProps)i in e&&t.numericProps[i].set(new Array(o).fill(e[i]),s)}function mt(t,e){const s={};for(const o in t)e.includes(o)||(s[o]=t[o]);return s}function At(t,e,s,o){let i=s*o;for(const s of e)t.set(s,i),i+=o}function jt(t){return[].concat(...t)}const Pt={geojson:{shape:"object-row-table"},json:{jsonpaths:["$","$.features"]},gis:{format:"geojson"}},vt={name:"GeoJSON",id:"geojson",module:"geojson",version:"3.0.9",worker:!0,extensions:["geojson"],mimeTypes:["application/geo+json"],category:"geometry",text:!0,options:Pt},Et={...vt,parse:async function(t,e){return St((new TextDecoder).decode(t),e)},parseTextSync:St,parseInBatches:function(t,e){(e={...Pt,...e}).json={...Pt.geojson,...e.geojson};const s=nt(t,e);switch(e.gis.format){case"binary":return async function*(t){for await(const e of t)e.data=ct(e.data),yield e}(s);default:return s}}};function St(t,e){(e={...Pt,...e}).json={...Pt.geojson,...e.geojson},e.gis=e.gis||{};const s=o(t,e);switch(e.gis.format){case"binary":return ct(s);default:return s}}}])}));
|
|
1
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var o in s)("object"==typeof exports?exports:t)[o]=s[o]}}(window,(function(){return function(t){var e={};function s(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=e,s.d=function(t,e,o){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(s.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)s.d(o,i,function(e){return t[e]}.bind(null,i));return o},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=0)}([function(t,e,s){(function(e){const o=s(2),i="undefined"==typeof window?e:window;i.loaders=i.loaders||{},t.exports=Object.assign(i.loaders,o)}).call(this,s(1))},function(t,e){var s;s=function(){return this}();try{s=s||new Function("return this")()}catch(t){"object"==typeof window&&(s=window)}t.exports=s},function(t,e,s){"use strict";function o(t,e){try{var s;const o=JSON.parse(t);return null!==(s=e.json)&&void 0!==s&&s.table&&function t(e){if(Array.isArray(e))return e;if(e&&"object"==typeof e)for(const s of Object.values(e)){const e=t(s);if(e)return e}return null}(o)||o}catch(t){throw new Error("JSONLoader: failed to parse JSON")}}function i(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}s.r(e),s.d(e,"JSONLoader",(function(){return at})),s.d(e,"_GeoJSONLoader",(function(){return Et})),s.d(e,"_GeoJSONWorkerLoader",(function(){return vt})),s.d(e,"_JSONPath",(function(){return et})),s.d(e,"_ClarinetParser",(function(){return q}));class n{constructor(t,e){if(i(this,"schema",void 0),i(this,"options",void 0),i(this,"length",0),i(this,"rows",null),i(this,"cursor",0),i(this,"_headers",[]),this.options=e,this.schema=t,!Array.isArray(t)){this._headers=[];for(const e in t)this._headers[t[e].index]=t[e].name}}rowCount(){return this.length}addArrayRow(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}addObjectRow(t,e){Number.isFinite(e)&&(this.cursor=e),this.rows=this.rows||new Array(100),this.rows[this.length]=t,this.length++}getBatch(){let t=this.rows;if(!t)return null;t=t.slice(0,this.length),this.rows=null;return{shape:this.options.shape,batchType:"data",data:t,length:this.length,schema:this.schema,cursor:this.cursor}}}function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class a{constructor(t,e){if(r(this,"schema",void 0),r(this,"options",void 0),r(this,"length",0),r(this,"objectRows",null),r(this,"arrayRows",null),r(this,"cursor",0),r(this,"_headers",[]),this.options=e,this.schema=t,!Array.isArray(t)){this._headers=[];for(const e in t)this._headers[t[e].index]=t[e].name}}rowCount(){return this.length}addArrayRow(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"object-row-table":const s=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");const s={};for(let o=0;o<e.length;o++)s[e[o]]=t[o];return s}(t,this._headers);this.addObjectRow(s,e);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=t,this.length++}}addObjectRow(t,e){switch(Number.isFinite(e)&&(this.cursor=e),this.options.shape){case"array-row-table":const s=function(t,e){if(!t)throw new Error("null row");if(!e)throw new Error("no headers");const s=new Array(e.length);for(let o=0;o<e.length;o++)s[o]=t[e[o]];return s}(t,this._headers);this.addArrayRow(s,e);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=t,this.length++}}getBatch(){let 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}}function h(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class c{constructor(t,e){h(this,"schema",void 0),h(this,"length",0),h(this,"allocated",0),h(this,"columns",{}),this.schema=t,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(t){this._reallocateColumns();let e=0;for(const s in this.columns)this.columns[s][this.length]=t[e++];this.length++}addObjectRow(t){this._reallocateColumns();for(const e in t)this.columns[e][this.length]=t[e];this.length++}getBatch(){this._pruneColumns();const t=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(const e in this.schema){const s=this.schema[e];t[s.name]=this.columns[s.index]}this.columns={};return{shape:"columnar-table",batchType:"data",data:t,schema:this.schema,length:this.length}}_reallocateColumns(){if(!(this.length<this.allocated)){this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={};for(const t in this.schema){const e=this.schema[t],s=e.type||Float32Array,o=this.columns[e.index];if(o&&ArrayBuffer.isView(o)){const t=new s(this.allocated);t.set(o),this.columns[e.index]=t}else o?(o.length=this.allocated,this.columns[e.index]=o):this.columns[e.index]=new s(this.allocated)}}}_pruneColumns(){for(const[t,e]of Object.entries(this.columns))this.columns[t]=e.slice(0,this.length)}}function l(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}const u={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0};class p{constructor(t,e){l(this,"schema",void 0),l(this,"options",void 0),l(this,"aggregator",null),l(this,"batchCount",0),l(this,"bytesUsed",0),l(this,"isChunkComplete",!1),l(this,"lastBatchEmittedMs",Date.now()),l(this,"totalLength",0),l(this,"totalBytes",0),l(this,"rowBytes",0),this.schema=t,this.options={...u,...e}}limitReached(){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)}addRow(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))}addArrayRow(t){if(!this.aggregator){const t=this._getTableBatchType();this.aggregator=new t(this.schema,this.options)}this.aggregator.addArrayRow(t)}addObjectRow(t){if(!this.aggregator){const t=this._getTableBatchType();this.aggregator=new t(this.schema,this.options)}this.aggregator.addObjectRow(t)}chunkComplete(t){t instanceof ArrayBuffer&&(this.bytesUsed+=t.byteLength),"string"==typeof t&&(this.bytesUsed+=t.length),this.isChunkComplete=!0}getFullBatch(t){return this._isFull()?this._getBatch(t):null}getFinalBatch(t){return this._getBatch(t)}_estimateRowMB(t){return Array.isArray(t)?8*t.length:8*Object.keys(t).length}_isFull(){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)}_getBatch(t){if(!this.aggregator)return null;null!=t&&t.bytesUsed&&(this.bytesUsed=t.bytesUsed);const e=this.aggregator.getBatch();return e.count=this.batchCount,e.bytesUsed=this.bytesUsed,Object.assign(e,t),this.batchCount++,this.aggregator=null,e}_getTableBatchType(){switch(this.options.shape){case"row-table":return n;case"array-row-table":case"object-row-table":return a;case"columnar-table":return c;case"arrow-table":if(!p.ArrowBatch)throw new Error("TableBatchBuilder");return p.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}l(p,"ArrowBatch",void 0);const d=Number.MAX_SAFE_INTEGER,f="debug"==={}.CDEBUG,g={textNode:void 0,numberNode:""};let y=0;const b={BEGIN:y++,VALUE:y++,OPEN_OBJECT:y++,CLOSE_OBJECT:y++,OPEN_ARRAY:y++,CLOSE_ARRAY:y++,TEXT_ESCAPE:y++,STRING:y++,BACKSLASH:y++,END:y++,OPEN_KEY:y++,CLOSE_KEY:y++,TRUE:y++,TRUE2:y++,TRUE3:y++,FALSE:y++,FALSE2:y++,FALSE3:y++,FALSE4:y++,NULL:y++,NULL2:y++,NULL3:y++,NUMBER_DECIMAL_POINT:y++,NUMBER_DIGIT:y++};for(var w in b)b[b[w]]=w;y=b;const m=9,A=10,j=13,P=32,v=34,E=43,S=44,_=45,O=46,C=48,N=57,L=58,I=69,R=91,B=92,U=93,k=97,x=98,F=101,T=102,J=108,M=110,z=114,D=115,Y=116,G=117,V=123,K=125;var $=/[\\"\n]/g;class q{constructor(t={}){this._initialize(t)}_initialize(t){this._clearBuffers(this),this.bufferCheckPosition=d,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=y.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),X(this,"onready")}_clearBuffers(){for(var t in g)this[t]=g[t]}end(){return this.state===y.VALUE&&0===this.depth||Z(this,"Unexpected end"),W(this),this.c="",this.closed=!0,X(this,"onend"),this._initialize(this.options),this}resume(){return this.error=null,this}close(){return this.write(null)}write(t){if(this.error)throw this.error;if(this.closed)return Z(this,"Cannot write after close. Assign an onready handler.");if(null===t)return this.end();var e=0,s=t.charCodeAt(0),o=this.p;for(f&&console.log("write -> ["+t+"]");s&&(o=s,this.c=s=t.charCodeAt(e++),o!==s?this.p=o:o=this.p,s);)switch(f&&console.log(e,s,b[this.state]),this.position++,s===A?(this.line++,this.column=0):this.column++,this.state){case y.BEGIN:s===V?this.state=y.OPEN_OBJECT:s===R?this.state=y.OPEN_ARRAY:tt(s)||Z(this,"Non-whitespace before {[.");continue;case y.OPEN_KEY:case y.OPEN_OBJECT:if(tt(s))continue;if(this.state===y.OPEN_KEY)this.stack.push(y.CLOSE_KEY);else{if(s===K){X(this,"onopenobject"),this.depth++,X(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||y.VALUE;continue}this.stack.push(y.CLOSE_OBJECT)}s===v?this.state=y.STRING:Z(this,'Malformed object key should start with "');continue;case y.CLOSE_KEY:case y.CLOSE_OBJECT:if(tt(s))continue;this.state,y.CLOSE_KEY;s===L?(this.state===y.CLOSE_OBJECT?(this.stack.push(y.CLOSE_OBJECT),W(this,"onopenobject"),this.depth++):W(this,"onkey"),this.state=y.VALUE):s===K?(H(this,"oncloseobject"),this.depth--,this.state=this.stack.pop()||y.VALUE):s===S?(this.state===y.CLOSE_OBJECT&&this.stack.push(y.CLOSE_OBJECT),W(this),this.state=y.OPEN_KEY):Z(this,"Bad object");continue;case y.OPEN_ARRAY:case y.VALUE:if(tt(s))continue;if(this.state===y.OPEN_ARRAY){if(X(this,"onopenarray"),this.depth++,this.state=y.VALUE,s===U){X(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||y.VALUE;continue}this.stack.push(y.CLOSE_ARRAY)}s===v?this.state=y.STRING:s===V?this.state=y.OPEN_OBJECT:s===R?this.state=y.OPEN_ARRAY:s===Y?this.state=y.TRUE:s===T?this.state=y.FALSE:s===M?this.state=y.NULL:s===_?this.numberNode+="-":C<=s&&s<=N?(this.numberNode+=String.fromCharCode(s),this.state=y.NUMBER_DIGIT):Z(this,"Bad value");continue;case y.CLOSE_ARRAY:if(s===S)this.stack.push(y.CLOSE_ARRAY),W(this,"onvalue"),this.state=y.VALUE;else if(s===U)H(this,"onclosearray"),this.depth--,this.state=this.stack.pop()||y.VALUE;else{if(tt(s))continue;Z(this,"Bad array")}continue;case y.STRING:void 0===this.textNode&&(this.textNode="");var i=e-1,n=this.slashed,r=this.unicodeI;t:for(;;){for(f&&console.log(e,s,b[this.state],n);r>0;)if(this.unicodeS+=String.fromCharCode(s),s=t.charCodeAt(e++),this.position++,4===r?(this.textNode+=String.fromCharCode(parseInt(this.unicodeS,16)),r=0,i=e-1):r++,!s)break t;if(s===v&&!n){this.state=this.stack.pop()||y.VALUE,this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}if(s===B&&!n&&(n=!0,this.textNode+=t.substring(i,e-1),this.position+=e-1-i,s=t.charCodeAt(e++),this.position++,!s))break;if(n){if(n=!1,s===M?this.textNode+="\n":s===z?this.textNode+="\r":s===Y?this.textNode+="\t":s===T?this.textNode+="\f":s===x?this.textNode+="\b":s===G?(r=1,this.unicodeS=""):this.textNode+=String.fromCharCode(s),s=t.charCodeAt(e++),this.position++,i=e-1,s)continue;break}$.lastIndex=e;var a=$.exec(t);if(null===a){e=t.length+1,this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}if(e=a.index+1,!(s=t.charCodeAt(a.index))){this.textNode+=t.substring(i,e-1),this.position+=e-1-i;break}}this.slashed=n,this.unicodeI=r;continue;case y.TRUE:s===z?this.state=y.TRUE2:Z(this,"Invalid true started with t"+s);continue;case y.TRUE2:s===G?this.state=y.TRUE3:Z(this,"Invalid true started with tr"+s);continue;case y.TRUE3:s===F?(X(this,"onvalue",!0),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid true started with tru"+s);continue;case y.FALSE:s===k?this.state=y.FALSE2:Z(this,"Invalid false started with f"+s);continue;case y.FALSE2:s===J?this.state=y.FALSE3:Z(this,"Invalid false started with fa"+s);continue;case y.FALSE3:s===D?this.state=y.FALSE4:Z(this,"Invalid false started with fal"+s);continue;case y.FALSE4:s===F?(X(this,"onvalue",!1),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid false started with fals"+s);continue;case y.NULL:s===G?this.state=y.NULL2:Z(this,"Invalid null started with n"+s);continue;case y.NULL2:s===J?this.state=y.NULL3:Z(this,"Invalid null started with nu"+s);continue;case y.NULL3:s===J?(X(this,"onvalue",null),this.state=this.stack.pop()||y.VALUE):Z(this,"Invalid null started with nul"+s);continue;case y.NUMBER_DECIMAL_POINT:s===O?(this.numberNode+=".",this.state=y.NUMBER_DIGIT):Z(this,"Leading zero not followed by .");continue;case y.NUMBER_DIGIT:C<=s&&s<=N?this.numberNode+=String.fromCharCode(s):s===O?(-1!==this.numberNode.indexOf(".")&&Z(this,"Invalid number has two dots"),this.numberNode+="."):s===F||s===I?(-1===this.numberNode.indexOf("e")&&-1===this.numberNode.indexOf("E")||Z(this,"Invalid number has two exponential"),this.numberNode+="e"):s===E||s===_?(o!==F&&o!==I&&Z(this,"Invalid symbol in number"),this.numberNode+=String.fromCharCode(s)):(Q(this),e--,this.state=this.stack.pop()||y.VALUE);continue;default:Z(this,"Unknown state: "+this.state)}return this.position>=this.bufferCheckPosition&&function(t){const e=Math.max(d,10);let s=0;for(var o in g){var i=void 0===t[o]?0:t[o].length;if(i>e)switch(o){case"text":closeText(t);break;default:Z(t,"Max buffer length exceeded: "+o)}s=Math.max(s,i)}t.bufferCheckPosition=d-s+t.position}(this),X(this,"onchunkparsed"),this}}function X(t,e,s){f&&console.log("-- emit",e,s),t[e]&&t[e](s,t)}function H(t,e,s){W(t),X(t,e,s)}function W(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&&X(t,e||"onvalue",t.textNode),t.textNode=void 0}function Q(t){t.numberNode&&X(t,"onvalue",parseFloat(t.numberNode)),t.numberNode=""}function Z(t,e){return W(t),e+="\nLine: "+t.line+"\nColumn: "+t.column+"\nChar: "+t.c,e=new Error(e),t.error=e,X(t,"onerror",e),t}function tt(t){return t===j||t===A||t===P||t===m}class et{constructor(t=null){var e,s,o;if(o=void 0,(s="path")in(e=this)?Object.defineProperty(e,s,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[s]=o,this.path=["$"],t instanceof et)this.path=[...t.path];else if(Array.isArray(t))this.path.push(...t);else if("string"==typeof t&&(this.path=t.split("."),"$"!==this.path[0]))throw new Error("JSONPaths must start with $")}clone(){return new et(this)}toString(){return this.path.join(".")}push(t){this.path.push(t)}pop(){return this.path.pop()}set(t){this.path[this.path.length-1]=t}equals(t){if(!this||!t||this.path.length!==t.path.length)return!1;for(let e=0;e<this.path.length;++e)if(this.path[e]!==t.path[e])return!1;return!0}setFieldAtPath(t,e){const s=[...this.path];s.shift();const o=s.pop();for(const e of s)t=t[e];t[o]=e}getFieldAtPath(t){const e=[...this.path];e.shift();const s=e.pop();for(const s of e)t=t[s];return t[s]}}function st(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function ot(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class it extends class{constructor(){st(this,"jsonpath",void 0),st(this,"_parser",void 0),this.reset(),this._initializeParser()}reset(){this.result=void 0,this.previousStates=[],this.currentState=Object.freeze({container:[],key:null}),this.jsonpath=new et}write(t){this.parser.write(t)}close(){this.parser.close()}_pushOrSet(t){const{container:e,key:s}=this.currentState;null!==s?(e[s]=t,this.currentState.key=null):e.push(t)}_openArray(t=[]){this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!0,key:null}}_closeArray(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}_openObject(t={}){this.jsonpath.push(null),this._pushOrSet(t),this.previousStates.push(this.currentState),this.currentState={container:t,isArray:!1,key:null}}_closeObject(){this.jsonpath.pop(),this.currentState=this.previousStates.pop()}_initializeParser(){this._parser=new q({onready:()=>{this.jsonpath=new et,this.previousStates.length=0,this.currentState.container.length=0},onopenobject:t=>{this._openObject({}),void 0!==t&&this.parser.onkey(t)},onkey:t=>{this.jsonpath.set(t),this.currentState.key=t},oncloseobject:()=>{this._closeObject()},onopenarray:()=>{this._openArray()},onclosearray:()=>{this._closeArray()},onvalue:t=>{this._pushOrSet(t)},onerror:t=>{throw t},onend:()=>{this.result=this.currentState.container.pop()}})}get parser(){return this._parser}}{constructor(t={}){super(),ot(this,"jsonPaths",void 0),ot(this,"streamingJsonPath",null),ot(this,"streamingArray",null),ot(this,"topLevelObject",null);const e=t.jsonpaths||[];this.jsonPaths=e.map(t=>new et(t)),this._extendParser()}write(t){super.write(t);let e=[];return this.streamingArray&&(e=[...this.streamingArray],this.streamingArray.length=0),e}getPartialResult(){return this.topLevelObject}getStreamingJsonPath(){return this.streamingJsonPath}getStreamingJsonPathAsString(){return this.streamingJsonPath&&this.streamingJsonPath.toString()}getJsonPath(){return this.jsonpath}_matchJSONPath(){const t=this.getJsonPath();if(0===this.jsonPaths.length)return!0;for(const e of this.jsonPaths)if(e.equals(t))return!0;return!1}_extendParser(){this.parser.onopenarray=()=>{if(!this.streamingArray&&this._matchJSONPath())return this.streamingJsonPath=this.getJsonPath().clone(),this.streamingArray=[],void this._openArray(this.streamingArray);this._openArray()},this.parser.onopenobject=t=>{this.topLevelObject?this._openObject({}):(this.topLevelObject={},this._openObject(this.topLevelObject)),void 0!==t&&this.parser.onkey(t)}}}async function*nt(t,e){var s;const o=async function*(t,e={}){const s=new TextDecoder(void 0,e);for await(const e of t)yield"string"==typeof e?e:s.decode(e,{stream:!0})}(t),{metadata:i}=e,{jsonpaths:n}=e.json||{};let r=!0;const a=(null==e||null===(s=e.json)||void 0===s?void 0:s.shape)||"row-table",h=new p(null,{...e,shape:a}),c=new it({jsonpaths:n});for await(const t of o){const e=c.write(t),s=e.length>0&&c.getStreamingJsonPathAsString();if(e.length>0&&r){if(i){const t={shape:a,batchType:"partial-result",data:[],length:0,bytesUsed:0,container:c.getPartialResult(),jsonpath:s};yield t}r=!1}for(const t of e){h.addRow(t);const e=h.getFullBatch({jsonpath:s});e&&(yield e)}h.chunkComplete(t);const o=h.getFullBatch({jsonpath:s});o&&(yield o)}const l=c.getStreamingJsonPathAsString(),u=h.getFinalBatch({jsonpath:l});if(u&&(yield u),i){const t={shape:a,batchType:"final-result",container:c.getPartialResult(),jsonpath:c.getStreamingJsonPathAsString(),data:[],length:0};yield t}}const rt={json:{shape:"row-table",table:!1,jsonpaths:[]}},at={name:"JSON",id:"json",module:"json",version:"3.0.13",extensions:["json","geojson"],mimeTypes:["application/json"],category:"table",text:!0,parse:async function(t,e){return ht((new TextDecoder).decode(t),e)},parseTextSync:ht,parseInBatches:function(t,e){const s={...e,json:{...rt.json,...null==e?void 0:e.json}};return nt(t,s)},options:rt};function ht(t,e){return o(t,{...e,json:{...rt.json,...null==e?void 0:e.json}})}function ct(t,e={}){const s=lt(t);return ut(t,s,{coordLength:e.coordLength||s.coordLength,numericPropKeys:e.numericPropKeys||s.numericPropKeys,PositionDataType:e.PositionDataType||Float32Array})}function lt(t){let e=0,s=0,o=0,i=0,n=0,r=0,a=0,h=0,c=0;const l=new Set,u={};for(const d of t){const t=d.geometry;switch(t.type){case"Point":s++,e++,l.add(t.coordinates.length);break;case"MultiPoint":s++,e+=t.coordinates.length;for(const e of t.coordinates)l.add(e.length);break;case"LineString":n++,o+=t.coordinates.length,i++;for(const e of t.coordinates)l.add(e.length);break;case"MultiLineString":n++;for(const e of t.coordinates){o+=e.length,i++;for(const t of e)l.add(t.length)}break;case"Polygon":c++,a++,h+=t.coordinates.length,r+=jt(t.coordinates).length;for(const e of jt(t.coordinates))l.add(e.length);break;case"MultiPolygon":c++;for(const e of t.coordinates){a++,h+=e.length,r+=jt(e).length;for(const t of jt(e))l.add(t.length)}break;default:throw new Error("Unsupported geometry type: "+t.type)}if(d.properties)for(const t in d.properties){const e=d.properties[t];u[t]=u[t]||void 0===u[t]?(p=e,Number.isFinite(p)):u[t]}}var p;return{coordLength:l.size>0?Math.max(...l):2,pointPositionsCount:e,pointFeaturesCount:s,linePositionsCount:o,linePathsCount:i,lineFeaturesCount:n,polygonPositionsCount:r,polygonObjectsCount:a,polygonRingsCount:h,polygonFeaturesCount:c,numericPropKeys:Object.keys(u).filter(t=>u[t])}}function ut(t,e,s){const{pointPositionsCount:o,pointFeaturesCount:i,linePositionsCount:n,linePathsCount:r,lineFeaturesCount:a,polygonPositionsCount:h,polygonObjectsCount:c,polygonRingsCount:l,polygonFeaturesCount:u}=e,{coordLength:p,numericPropKeys:d,PositionDataType:f=Float32Array}=s,g=t.length>65535?Uint32Array:Uint16Array,y={positions:new f(o*p),globalFeatureIds:new g(o),featureIds:i>65535?new Uint32Array(o):new Uint16Array(o),numericProps:{},properties:Array(),fields:Array()},b={positions:new f(n*p),pathIndices:n>65535?new Uint32Array(r+1):new Uint16Array(r+1),globalFeatureIds:new g(n),featureIds:a>65535?new Uint32Array(n):new Uint16Array(n),numericProps:{},properties:Array(),fields:Array()},w={positions:new f(h*p),polygonIndices:h>65535?new Uint32Array(c+1):new Uint16Array(c+1),primitivePolygonIndices:h>65535?new Uint32Array(l+1):new Uint16Array(l+1),globalFeatureIds:new g(h),featureIds:u>65535?new Uint32Array(h):new Uint16Array(h),numericProps:{},properties:Array(),fields:Array()};for(const t of[y,b,w])for(const e of d||[])t.numericProps[e]=new Float32Array(t.positions.length/p);b.pathIndices[r]=n,w.polygonIndices[c]=h,w.primitivePolygonIndices[l]=h;const m={pointPosition:0,pointFeature:0,linePosition:0,linePath:0,lineFeature:0,polygonPosition:0,polygonObject:0,polygonRing:0,polygonFeature:0,feature:0};for(const e of t){const t=e.geometry,s=e.properties||{};switch(t.type){case"Point":pt(t.coordinates,y,m,p,s),y.properties.push(mt(s,d)),m.pointFeature++;break;case"MultiPoint":dt(t.coordinates,y,m,p,s),y.properties.push(mt(s,d)),m.pointFeature++;break;case"LineString":ft(t.coordinates,b,m,p,s),b.properties.push(mt(s,d)),m.lineFeature++;break;case"MultiLineString":gt(t.coordinates,b,m,p,s),b.properties.push(mt(s,d)),m.lineFeature++;break;case"Polygon":yt(t.coordinates,w,m,p,s),w.properties.push(mt(s,d)),m.polygonFeature++;break;case"MultiPolygon":bt(t.coordinates,w,m,p,s),w.properties.push(mt(s,d)),m.polygonFeature++;break;default:throw new Error("Invalid geometry type")}m.feature++}return function(t,e,s,o){const i={points:{...t,positions:{value:t.positions,size:o},globalFeatureIds:{value:t.globalFeatureIds,size:1},featureIds:{value:t.featureIds,size:1},type:"Point"},lines:{...e,pathIndices:{value:e.pathIndices,size:1},positions:{value:e.positions,size:o},globalFeatureIds:{value:e.globalFeatureIds,size:1},featureIds:{value:e.featureIds,size:1},type:"LineString"},polygons:{...s,polygonIndices:{value:s.polygonIndices,size:1},primitivePolygonIndices:{value:s.primitivePolygonIndices,size:1},positions:{value:s.positions,size:o},globalFeatureIds:{value:s.globalFeatureIds,size:1},featureIds:{value:s.featureIds,size:1},type:"Polygon"}};for(const t in i)for(const e in i[t].numericProps)i[t].numericProps[e]={value:i[t].numericProps[e],size:1};return i}(y,b,w,p)}function pt(t,e,s,o,i){e.positions.set(t,s.pointPosition*o),e.globalFeatureIds[s.pointPosition]=s.feature,e.featureIds[s.pointPosition]=s.pointFeature,wt(e,i,s.pointPosition,1),s.pointPosition++}function dt(t,e,s,o,i){for(const n of t)pt(n,e,s,o,i)}function ft(t,e,s,o,i){e.pathIndices[s.linePath]=s.linePosition,s.linePath++,At(e.positions,t,s.linePosition,o);const n=t.length;wt(e,i,s.linePosition,n),e.globalFeatureIds.set(new Uint32Array(n).fill(s.feature),s.linePosition),e.featureIds.set(new Uint32Array(n).fill(s.lineFeature),s.linePosition),s.linePosition+=n}function gt(t,e,s,o,i){for(const n of t)ft(n,e,s,o,i)}function yt(t,e,s,o,i){e.polygonIndices[s.polygonObject]=s.polygonPosition,s.polygonObject++;for(const n of t){e.primitivePolygonIndices[s.polygonRing]=s.polygonPosition,s.polygonRing++,At(e.positions,n,s.polygonPosition,o);const t=n.length;wt(e,i,s.polygonPosition,t),e.globalFeatureIds.set(new Uint32Array(t).fill(s.feature),s.polygonPosition),e.featureIds.set(new Uint32Array(t).fill(s.polygonFeature),s.polygonPosition),s.polygonPosition+=t}}function bt(t,e,s,o,i){for(const n of t)yt(n,e,s,o,i)}function wt(t,e,s,o){for(const i in t.numericProps)i in e&&t.numericProps[i].set(new Array(o).fill(e[i]),s)}function mt(t,e){const s={};for(const o in t)e.includes(o)||(s[o]=t[o]);return s}function At(t,e,s,o){let i=s*o;for(const s of e)t.set(s,i),i+=o}function jt(t){return[].concat(...t)}const Pt={geojson:{shape:"object-row-table"},json:{jsonpaths:["$","$.features"]},gis:{format:"geojson"}},vt={name:"GeoJSON",id:"geojson",module:"geojson",version:"3.0.13",worker:!0,extensions:["geojson"],mimeTypes:["application/geo+json"],category:"geometry",text:!0,options:Pt},Et={...vt,parse:async function(t,e){return St((new TextDecoder).decode(t),e)},parseTextSync:St,parseInBatches:function(t,e){(e={...Pt,...e}).json={...Pt.geojson,...e.geojson};const s=nt(t,e);switch(e.gis.format){case"binary":return async function*(t){for await(const e of t)e.data=ct(e.data),yield e}(s);default:return s}}};function St(t,e){(e={...Pt,...e}).json={...Pt.geojson,...e.geojson},e.gis=e.gis||{};const s=o(t,e);switch(e.gis.format){case"binary":return ct(s);default:return s}}}])}));
|
|
2
2
|
//# sourceMappingURL=dist.min.js.map
|