@loaders.gl/xml 4.0.0-beta.2 → 4.0.0-beta.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/{dist.min.js → dist.dev.js} +2154 -2055
- package/dist/{esm/html-loader.js → html-loader.js} +1 -1
- package/dist/html-loader.js.map +1 -0
- package/dist/index.cjs +1530 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/parse-xml.js +2 -2
- package/dist/lib/parsers/parse-xml.js.map +1 -0
- package/dist/{esm/lib → lib}/parsers/streaming-xml-parser.js +6 -7
- package/dist/lib/parsers/streaming-xml-parser.js.map +1 -0
- package/dist/lib/xml-utils/uncapitalize.js.map +1 -0
- package/dist/lib/xml-utils/xml-utils.js.map +1 -0
- package/dist/{esm/sax-ts → sax-ts}/sax.js +75 -76
- package/dist/sax-ts/sax.js.map +1 -0
- package/dist/{esm/xml-loader.js → xml-loader.js} +2 -2
- package/dist/xml-loader.js.map +1 -0
- package/package.json +16 -8
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/html-loader.js +0 -58
- package/dist/es5/html-loader.js.map +0 -1
- package/dist/es5/index.js +0 -53
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/parsers/parse-xml.js +0 -53
- package/dist/es5/lib/parsers/parse-xml.js.map +0 -1
- package/dist/es5/lib/parsers/streaming-xml-parser.js +0 -134
- package/dist/es5/lib/parsers/streaming-xml-parser.js.map +0 -1
- package/dist/es5/lib/xml-utils/uncapitalize.js +0 -32
- package/dist/es5/lib/xml-utils/uncapitalize.js.map +0 -1
- package/dist/es5/lib/xml-utils/xml-utils.js +0 -23
- package/dist/es5/lib/xml-utils/xml-utils.js.map +0 -1
- package/dist/es5/sax-ts/sax.js +0 -1372
- package/dist/es5/sax-ts/sax.js.map +0 -1
- package/dist/es5/xml-loader.js +0 -58
- package/dist/es5/xml-loader.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/html-loader.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/parsers/parse-xml.js.map +0 -1
- package/dist/esm/lib/parsers/streaming-xml-parser.js.map +0 -1
- package/dist/esm/lib/xml-utils/uncapitalize.js.map +0 -1
- package/dist/esm/lib/xml-utils/xml-utils.js.map +0 -1
- package/dist/esm/sax-ts/sax.js.map +0 -1
- package/dist/esm/xml-loader.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/lib → lib}/xml-utils/uncapitalize.js +0 -0
- /package/dist/{esm/lib → lib}/xml-utils/xml-utils.js +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { XMLLoader } from "./xml-loader.js";
|
|
2
|
+
export { HTMLLoader } from "./html-loader.js";
|
|
3
|
+
export { SAXParser } from "./sax-ts/sax.js";
|
|
4
|
+
export { convertXMLValueToArray, convertXMLFieldToArrayInPlace } from "./lib/xml-utils/xml-utils.js";
|
|
5
|
+
export { uncapitalize as _uncapitalize, uncapitalizeKeys as _uncapitalizeKeys } from "./lib/xml-utils/uncapitalize.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["XMLLoader","HTMLLoader","SAXParser","convertXMLValueToArray","convertXMLFieldToArrayInPlace","uncapitalize","_uncapitalize","uncapitalizeKeys","_uncapitalizeKeys"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// XMLLoader\n\nexport type {XMLLoaderOptions} from './xml-loader';\nexport {XMLLoader} from './xml-loader';\n\n// HTMLLoader\n\nexport type {HTMLLoaderOptions} from './html-loader';\nexport {HTMLLoader} from './html-loader';\n\n// SAX\n\nexport type {SAXParserOptions as SAXParserOptions} from './sax-ts/sax';\nexport {SAXParser as SAXParser} from './sax-ts/sax';\n\n// Utilities\n\nexport {convertXMLValueToArray, convertXMLFieldToArrayInPlace} from './lib/xml-utils/xml-utils';\n\n// Experimental\n\nexport {\n uncapitalize as _uncapitalize,\n uncapitalizeKeys as _uncapitalizeKeys\n} from './lib/xml-utils/uncapitalize';\n"],"mappings":"SAKQA,SAAS;AAAA,SAKTC,UAAU;AAAA,SAKVC,SAAsB;AAAA,SAItBC,sBAAsB,EAAEC,6BAA6B;AAAA,SAK3DC,YAAY,IAAIC,aAAa,EAC7BC,gBAAgB,IAAIC,iBAAiB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StreamingXMLParser } from
|
|
2
|
-
import { uncapitalizeKeys } from
|
|
1
|
+
import { StreamingXMLParser } from "./streaming-xml-parser.js";
|
|
2
|
+
import { uncapitalizeKeys } from "../xml-utils/uncapitalize.js";
|
|
3
3
|
import { XMLParser as FastXMLParser } from 'fast-xml-parser';
|
|
4
4
|
export function parseXMLSync(text, options) {
|
|
5
5
|
if (options !== null && options !== void 0 && options._parser && options._parser !== 'fast-xml-parser') {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-xml.js","names":["StreamingXMLParser","uncapitalizeKeys","XMLParser","FastXMLParser","parseXMLSync","text","options","_parser","Error","fastXMLOptions","allowBooleanAttributes","ignoreDeclaration","removeNSPrefix","textNodeName","isArray","name","jpath","isLeafNode","isAttribute","_options$arrayPaths","array","Boolean","arrayPaths","some","path","_fastXML","xml","fastParseXML","parser","ignoreAttributes","attributeNamePrefix","parsedXML","parse","parseXMLInBatches","arguments","length","undefined","strict","write","close","result"],"sources":["../../../src/lib/parsers/parse-xml.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {SAXParserOptions} from '../../sax-ts/sax';\nimport {StreamingXMLParser} from './streaming-xml-parser';\nimport {uncapitalizeKeys} from '../xml-utils/uncapitalize';\nimport {XMLParser as FastXMLParser} from 'fast-xml-parser';\nimport type {X2jOptions} from 'fast-xml-parser';\n\nexport type ParseXMLOptions = {\n /** XML is typically PascalCase, JavaScript prefects camelCase */\n uncapitalizeKeys?: boolean;\n removeNSPrefix?: boolean;\n textNodeName?: string;\n arrayPaths?: string[];\n\n // NOTE: Only fast-xml-parser is implemented\n _parser?: 'fast-xml-parser' | 'sax';\n /** @deprecated Experimental, passes options to fast-xml-parser, IF it is being used */\n _fastXML?: _FastParseXMLOptions;\n /** @deprecated Experimental, passes options to the SAX XML parser, IF it is being used. */\n _sax?: SAXParserOptions;\n};\n\n/** Type for passing through fast-xml-parser options */\nexport type _FastParseXMLOptions = Partial<X2jOptions>;\n\nexport function parseXMLSync(text: string, options?: ParseXMLOptions): any {\n if (options?._parser && options._parser !== 'fast-xml-parser') {\n throw new Error(options?._parser);\n }\n\n const fastXMLOptions: _FastParseXMLOptions = {\n // Default FastXML options\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes\n allowBooleanAttributes: true,\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration\n ignoreDeclaration: true,\n\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix\n removeNSPrefix: options?.removeNSPrefix,\n\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename\n textNodeName: options?.textNodeName,\n\n // Let's application specify keys that are always arrays\n isArray: (name: string, jpath: string, isLeafNode: boolean, isAttribute: boolean) => {\n const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));\n return array;\n },\n\n // Application overrides\n ...options?._fastXML\n };\n\n const xml = fastParseXML(text, fastXMLOptions);\n\n // Note - could be done with FastXML tag processing\n return options?.uncapitalizeKeys ? uncapitalizeKeys(xml) : xml;\n}\n\nexport function fastParseXML(text: string, options: _FastParseXMLOptions): any {\n const parser = new FastXMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: '',\n ...options\n });\n\n const parsedXML = parser.parse(text);\n\n return parsedXML;\n}\n\n/**\n * @todo Build a streaming XML parser based on sax-js\n * @param text\n * @param options\n * @returns\n */\nexport function parseXMLInBatches(text: string, options = {}): any {\n const parser = new StreamingXMLParser({\n ...options,\n strict: true\n });\n\n parser.write(text);\n parser.close();\n\n return parser.result;\n}\n"],"mappings":"SAGQA,kBAAkB;AAAA,SAClBC,gBAAgB;AACxB,SAAQC,SAAS,IAAIC,aAAa,QAAO,iBAAiB;AAqB1D,OAAO,SAASC,YAAYA,CAACC,IAAY,EAAEC,OAAyB,EAAO;EACzE,IAAIA,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEC,OAAO,IAAID,OAAO,CAACC,OAAO,KAAK,iBAAiB,EAAE;IAC7D,MAAM,IAAIC,KAAK,CAACF,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,OAAO,CAAC;EACnC;EAEA,MAAME,cAAoC,GAAG;IAG3CC,sBAAsB,EAAE,IAAI;IAE5BC,iBAAiB,EAAE,IAAI;IAGvBC,cAAc,EAAEN,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEM,cAAc;IAGvCC,YAAY,EAAEP,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEO,YAAY;IAGnCC,OAAO,EAAEA,CAACC,IAAY,EAAEC,KAAa,EAAEC,UAAmB,EAAEC,WAAoB,KAAK;MAAA,IAAAC,mBAAA;MACnF,MAAMC,KAAK,GAAGC,OAAO,CAACf,OAAO,aAAPA,OAAO,wBAAAa,mBAAA,GAAPb,OAAO,CAAEgB,UAAU,cAAAH,mBAAA,uBAAnBA,mBAAA,CAAqBI,IAAI,CAAEC,IAAI,IAAKR,KAAK,KAAKQ,IAAI,CAAC,CAAC;MAC1E,OAAOJ,KAAK;IACd,CAAC;IAGD,IAAGd,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEmB,QAAQ;EACtB,CAAC;EAED,MAAMC,GAAG,GAAGC,YAAY,CAACtB,IAAI,EAAEI,cAAc,CAAC;EAG9C,OAAOH,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEL,gBAAgB,GAAGA,gBAAgB,CAACyB,GAAG,CAAC,GAAGA,GAAG;AAChE;AAEA,OAAO,SAASC,YAAYA,CAACtB,IAAY,EAAEC,OAA6B,EAAO;EAC7E,MAAMsB,MAAM,GAAG,IAAIzB,aAAa,CAAC;IAC/B0B,gBAAgB,EAAE,KAAK;IACvBC,mBAAmB,EAAE,EAAE;IACvB,GAAGxB;EACL,CAAC,CAAC;EAEF,MAAMyB,SAAS,GAAGH,MAAM,CAACI,KAAK,CAAC3B,IAAI,CAAC;EAEpC,OAAO0B,SAAS;AAClB;AAQA,OAAO,SAASE,iBAAiBA,CAAC5B,IAAY,EAAqB;EAAA,IAAnBC,OAAO,GAAA4B,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1D,MAAMN,MAAM,GAAG,IAAI5B,kBAAkB,CAAC;IACpC,GAAGM,OAAO;IACV+B,MAAM,EAAE;EACV,CAAC,CAAC;EAEFT,MAAM,CAACU,KAAK,CAACjC,IAAI,CAAC;EAClBuB,MAAM,CAACW,KAAK,CAAC,CAAC;EAEd,OAAOX,MAAM,CAACY,MAAM;AACtB"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SAXParser } from '../../sax-ts/sax';
|
|
1
|
+
import { SAXParser } from "../../sax-ts/sax.js";
|
|
3
2
|
export class StreamingXMLParser {
|
|
4
3
|
constructor(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
this.parser = void 0;
|
|
5
|
+
this.result = undefined;
|
|
6
|
+
this.previousStates = [];
|
|
7
|
+
this.currentState = Object.freeze({
|
|
9
8
|
container: [],
|
|
10
9
|
key: null
|
|
11
|
-
})
|
|
10
|
+
});
|
|
12
11
|
this.reset();
|
|
13
12
|
this.parser = new SAXParser({
|
|
14
13
|
onready: () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-xml-parser.js","names":["SAXParser","StreamingXMLParser","constructor","options","parser","result","undefined","previousStates","currentState","Object","freeze","container","key","reset","onready","length","onopentag","_ref","name","attributes","isSelfClosing","_openObject","emit","onkey","onclosetag","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","ontext","value","_pushOrSet","onerror","error","onend","pop","write","chunk","close","Array","isArray","push","newContainer","arguments"],"sources":["../../../src/lib/parsers/streaming-xml-parser.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable */\n\nimport {SAXParser, SAXParserOptions} from '../../sax-ts/sax';\n// import JSONPath from '../jsonpath/jsonpath';\n\nexport type StreamingXMLParserOptions = SAXParserOptions;\n\n/**\n * StreamingXMLParser builds a JSON object using the events emitted by the SAX parser\n */\nexport class StreamingXMLParser {\n readonly parser: SAXParser;\n result = undefined;\n previousStates = [];\n currentState = Object.freeze({container: [], key: null});\n // jsonpath: JSONPath = new JSONPath();\n\n constructor(options: SAXParserOptions) {\n this.reset();\n this.parser = new SAXParser({\n onready: () => {\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopentag: ({name, attributes, isSelfClosing}) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.emit('onkey', name);\n }\n },\n\n onkey: (name) => {\n this.currentState.key = name;\n },\n\n onclosetag: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n ontext: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n },\n\n ...options\n });\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else if (Array.isArray(container)) {\n container.push(value);\n } else if (container) {\n // debugger\n }\n }\n\n _openArray(newContainer = []): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n}\n"],"mappings":"SAGQA,SAAS;AAQjB,OAAO,MAAMC,kBAAkB,CAAC;EAO9BC,WAAWA,CAACC,OAAyB,EAAE;IAAA,KAN9BC,MAAM;IAAA,KACfC,MAAM,GAAGC,SAAS;IAAA,KAClBC,cAAc,GAAG,EAAE;IAAA,KACnBC,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC;MAACC,SAAS,EAAE,EAAE;MAAEC,GAAG,EAAE;IAAI,CAAC,CAAC;IAItD,IAAI,CAACC,KAAK,CAAC,CAAC;IACZ,IAAI,CAACT,MAAM,GAAG,IAAIJ,SAAS,CAAC;MAC1Bc,OAAO,EAAEA,CAAA,KAAM;QACb,IAAI,CAACP,cAAc,CAACQ,MAAM,GAAG,CAAC;QAC9B,IAAI,CAACP,YAAY,CAACG,SAAS,CAACI,MAAM,GAAG,CAAC;MACxC,CAAC;MAEDC,SAAS,EAAEC,IAAA,IAAuC;QAAA,IAAtC;UAACC,IAAI;UAAEC,UAAU;UAAEC;QAAa,CAAC,GAAAH,IAAA;QAC3C,IAAI,CAACI,WAAW,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,OAAOH,IAAI,K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CAACjB,YAAY,GAAG,IAAI,CAACD,cAAc,CAAC6B,GAAG,CAAC,CAAC;EAC/C;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncapitalize.js","names":["uncapitalize","str","charAt","toLowerCase","slice","uncapitalizeKeys","object","Array","isArray","map","element","newObject","key","value","Object","entries"],"sources":["../../../src/lib/xml-utils/uncapitalize.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n/**\n * Uncapitalize first letter of a string\n * @param str\n * @returns\n */\nexport function uncapitalize(str: string): string {\n return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;\n}\n\n/**\n * Recursively uncapitalize all keys in a nested object\n * @param object\n * @returns\n */\nexport function uncapitalizeKeys(object: any): any {\n if (Array.isArray(object)) {\n return object.map((element) => uncapitalizeKeys(element));\n }\n\n if (object && typeof object === 'object') {\n const newObject = {};\n for (const [key, value] of Object.entries(object)) {\n newObject[uncapitalize(key)] = uncapitalizeKeys(value);\n }\n return newObject;\n }\n\n return object;\n}\n"],"mappings":"AAOA,OAAO,SAASA,YAAYA,CAACC,GAAW,EAAU;EAChD,OAAO,OAAOA,GAAG,KAAK,QAAQ,GAAGA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC,GAAGH,GAAG;AACnF;AAOA,OAAO,SAASI,gBAAgBA,CAACC,MAAW,EAAO;EACjD,IAAIC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACzB,OAAOA,MAAM,CAACG,GAAG,CAAEC,OAAO,IAAKL,gBAAgB,CAACK,OAAO,CAAC,CAAC;EAC3D;EAEA,IAAIJ,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IACxC,MAAMK,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,MAAM,CAAC,EAAE;MACjDK,SAAS,CAACX,YAAY,CAACY,GAAG,CAAC,CAAC,GAAGP,gBAAgB,CAACQ,KAAK,CAAC;IACxD;IACA,OAAOF,SAAS;EAClB;EAEA,OAAOL,MAAM;AACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-utils.js","names":["convertXMLValueToArray","xmlValue","Array","isArray","convertXMLFieldToArrayInPlace","xml","key"],"sources":["../../../src/lib/xml-utils/xml-utils.ts"],"sourcesContent":["// TODO - these utilities could be moved to the XML parser.\n// uncapitalizeKeys could be an XMLLoader option\n\n/**\n * Extracts a value or array and always return an array\n * Useful since XML parses to object instead of array when only a single value is provided\n */\nexport function convertXMLValueToArray(xmlValue: unknown): unknown[] {\n if (Array.isArray(xmlValue)) {\n return xmlValue;\n }\n if (xmlValue && typeof xmlValue === 'object' && xmlValue['0']) {\n // Error this is an objectified array\n }\n if (xmlValue) {\n return [xmlValue];\n }\n return [];\n}\n\n/**\n * Mutates a field in place, converting it to array\n * Useful since XML parses to object instead of array when only a single value is provided\n */\nexport function convertXMLFieldToArrayInPlace(xml: any, key: string): void {\n xml[key] = convertXMLValueToArray(xml[key]);\n}\n"],"mappings":"AAOA,OAAO,SAASA,sBAAsBA,CAACC,QAAiB,EAAa;EACnE,IAAIC,KAAK,CAACC,OAAO,CAACF,QAAQ,CAAC,EAAE;IAC3B,OAAOA,QAAQ;EACjB;EACA,IAAIA,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAE/D;EACA,IAAIA,QAAQ,EAAE;IACZ,OAAO,CAACA,QAAQ,CAAC;EACnB;EACA,OAAO,EAAE;AACX;AAMA,OAAO,SAASG,6BAA6BA,CAACC,GAAQ,EAAEC,GAAW,EAAQ;EACzED,GAAG,CAACC,GAAG,CAAC,GAAGN,sBAAsB,CAACK,GAAG,CAACC,GAAG,CAAC,CAAC;AAC7C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
const DEFAULT_SAX_EVENTS = {
|
|
3
2
|
ontext: () => {},
|
|
4
3
|
onprocessinginstruction: () => {},
|
|
@@ -299,41 +298,41 @@ Object.keys(ENTITIES).forEach(key => {
|
|
|
299
298
|
});
|
|
300
299
|
class SAX {
|
|
301
300
|
constructor() {
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
this.EVENTS = EVENTS;
|
|
302
|
+
this.ENTITIES = {
|
|
304
303
|
...ENTITIES
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
};
|
|
305
|
+
this.events = void 0;
|
|
306
|
+
this.XML_ENTITIES = {
|
|
308
307
|
amp: '&',
|
|
309
308
|
gt: '>',
|
|
310
309
|
lt: '<',
|
|
311
310
|
quot: '"',
|
|
312
311
|
apos: "'"
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
312
|
+
};
|
|
313
|
+
this.S = 0;
|
|
314
|
+
this.opt = void 0;
|
|
315
|
+
this.trackPosition = false;
|
|
316
|
+
this.column = 0;
|
|
317
|
+
this.line = 0;
|
|
318
|
+
this.c = '';
|
|
319
|
+
this.error = void 0;
|
|
320
|
+
this.q = '';
|
|
321
|
+
this.bufferCheckPosition = void 0;
|
|
322
|
+
this.closed = false;
|
|
323
|
+
this.tags = [];
|
|
324
|
+
this.looseCase = '';
|
|
325
|
+
this.closedRoot = false;
|
|
326
|
+
this.sawRoot = false;
|
|
327
|
+
this.strict = false;
|
|
328
|
+
this.tag = void 0;
|
|
329
|
+
this.strictEntities = void 0;
|
|
330
|
+
this.state = void 0;
|
|
331
|
+
this.noscript = false;
|
|
332
|
+
this.attribList = [];
|
|
333
|
+
this.ns = void 0;
|
|
334
|
+
this.position = 0;
|
|
335
|
+
this.STATE = {
|
|
337
336
|
BEGIN: this.S++,
|
|
338
337
|
BEGIN_WHITESPACE: this.S++,
|
|
339
338
|
TEXT: this.S++,
|
|
@@ -370,29 +369,29 @@ class SAX {
|
|
|
370
369
|
CLOSE_TAG_SAW_WHITE: this.S++,
|
|
371
370
|
SCRIPT: this.S++,
|
|
372
371
|
SCRIPT_ENDING: this.S++
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
372
|
+
};
|
|
373
|
+
this.BUFFERS = BUFFERS;
|
|
374
|
+
this.CDATA = '[CDATA[';
|
|
375
|
+
this.DOCTYPE = 'DOCTYPE';
|
|
376
|
+
this.XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
377
|
+
this.XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/';
|
|
378
|
+
this.rootNS = {
|
|
380
379
|
xml: this.XML_NAMESPACE,
|
|
381
380
|
xmlns: this.XMLNS_NAMESPACE
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
381
|
+
};
|
|
382
|
+
this.comment = void 0;
|
|
383
|
+
this.sgmlDecl = void 0;
|
|
384
|
+
this.textNode = '';
|
|
385
|
+
this.tagName = void 0;
|
|
386
|
+
this.doctype = void 0;
|
|
387
|
+
this.procInstName = void 0;
|
|
388
|
+
this.procInstBody = void 0;
|
|
389
|
+
this.entity = '';
|
|
390
|
+
this.attribName = void 0;
|
|
391
|
+
this.attribValue = void 0;
|
|
392
|
+
this.cdata = '';
|
|
393
|
+
this.script = '';
|
|
394
|
+
this.startTagPosition = 0;
|
|
396
395
|
this.S = 0;
|
|
397
396
|
for (const s in this.STATE) {
|
|
398
397
|
if (this.STATE.hasOwnProperty(s)) {
|
|
@@ -520,7 +519,7 @@ class SAX {
|
|
|
520
519
|
if (c === '/') {
|
|
521
520
|
this.state = this.S.CLOSE_TAG;
|
|
522
521
|
} else {
|
|
523
|
-
this.script +=
|
|
522
|
+
this.script += `<${c}`;
|
|
524
523
|
this.state = this.S.SCRIPT;
|
|
525
524
|
}
|
|
526
525
|
continue;
|
|
@@ -543,7 +542,7 @@ class SAX {
|
|
|
543
542
|
const pad = this.position - this.startTagPosition;
|
|
544
543
|
c = new Array(pad).join(' ') + c;
|
|
545
544
|
}
|
|
546
|
-
this.textNode +=
|
|
545
|
+
this.textNode += `<${c}`;
|
|
547
546
|
this.state = this.S.TEXT;
|
|
548
547
|
}
|
|
549
548
|
continue;
|
|
@@ -636,14 +635,14 @@ class SAX {
|
|
|
636
635
|
}
|
|
637
636
|
this.comment = '';
|
|
638
637
|
} else {
|
|
639
|
-
this.comment +=
|
|
638
|
+
this.comment += `-${c}`;
|
|
640
639
|
this.state = this.S.COMMENT;
|
|
641
640
|
}
|
|
642
641
|
continue;
|
|
643
642
|
case this.S.COMMENT_ENDED:
|
|
644
643
|
if (c !== '>') {
|
|
645
644
|
this.strictFail('Malformed comment');
|
|
646
|
-
this.comment +=
|
|
645
|
+
this.comment += `--${c}`;
|
|
647
646
|
this.state = this.S.COMMENT;
|
|
648
647
|
} else {
|
|
649
648
|
this.state = this.S.TEXT;
|
|
@@ -660,7 +659,7 @@ class SAX {
|
|
|
660
659
|
if (c === ']') {
|
|
661
660
|
this.state = this.S.CDATA_ENDING_2;
|
|
662
661
|
} else {
|
|
663
|
-
this.cdata +=
|
|
662
|
+
this.cdata += `]${c}`;
|
|
664
663
|
this.state = this.S.CDATA;
|
|
665
664
|
}
|
|
666
665
|
continue;
|
|
@@ -675,7 +674,7 @@ class SAX {
|
|
|
675
674
|
} else if (c === ']') {
|
|
676
675
|
this.cdata += ']';
|
|
677
676
|
} else {
|
|
678
|
-
this.cdata +=
|
|
677
|
+
this.cdata += `]]${c}`;
|
|
679
678
|
this.state = this.S.CDATA;
|
|
680
679
|
}
|
|
681
680
|
continue;
|
|
@@ -706,7 +705,7 @@ class SAX {
|
|
|
706
705
|
this.procInstName = this.procInstBody = '';
|
|
707
706
|
this.state = this.S.TEXT;
|
|
708
707
|
} else {
|
|
709
|
-
this.procInstBody +=
|
|
708
|
+
this.procInstBody += `?${c}`;
|
|
710
709
|
this.state = this.S.PROC_INST_BODY;
|
|
711
710
|
}
|
|
712
711
|
continue;
|
|
@@ -855,7 +854,7 @@ class SAX {
|
|
|
855
854
|
continue;
|
|
856
855
|
} else if (SAX.notMatch(nameStart, c)) {
|
|
857
856
|
if (this.script) {
|
|
858
|
-
this.script +=
|
|
857
|
+
this.script += `</${c}`;
|
|
859
858
|
this.state = this.S.SCRIPT;
|
|
860
859
|
} else {
|
|
861
860
|
this.strictFail('Invalid tagname in closing tag.');
|
|
@@ -868,7 +867,7 @@ class SAX {
|
|
|
868
867
|
} else if (SAX.isMatch(nameBody, c)) {
|
|
869
868
|
this.tagName += c;
|
|
870
869
|
} else if (this.script) {
|
|
871
|
-
this.script +=
|
|
870
|
+
this.script += `</${this.tagName}`;
|
|
872
871
|
this.tagName = '';
|
|
873
872
|
this.state = this.S.SCRIPT;
|
|
874
873
|
} else {
|
|
@@ -907,7 +906,7 @@ class SAX {
|
|
|
907
906
|
buffer = 'attribValue';
|
|
908
907
|
break;
|
|
909
908
|
default:
|
|
910
|
-
throw new Error(
|
|
909
|
+
throw new Error(`Unknown state: ${this.state}`);
|
|
911
910
|
}
|
|
912
911
|
if (c === ';') {
|
|
913
912
|
this[buffer] += this.parseEntity();
|
|
@@ -917,13 +916,13 @@ class SAX {
|
|
|
917
916
|
this.entity += c;
|
|
918
917
|
} else {
|
|
919
918
|
this.strictFail('Invalid character in entity name');
|
|
920
|
-
this[buffer] +=
|
|
919
|
+
this[buffer] += `&${this.entity}${c}`;
|
|
921
920
|
this.entity = '';
|
|
922
921
|
this.state = returnState;
|
|
923
922
|
}
|
|
924
923
|
continue;
|
|
925
924
|
default:
|
|
926
|
-
throw new Error(
|
|
925
|
+
throw new Error(`Unknown state: ${this.state}`);
|
|
927
926
|
}
|
|
928
927
|
}
|
|
929
928
|
if (this.position >= this.bufferCheckPosition) {
|
|
@@ -967,7 +966,7 @@ class SAX {
|
|
|
967
966
|
errorFunction(er) {
|
|
968
967
|
this.closeText();
|
|
969
968
|
if (this.trackPosition) {
|
|
970
|
-
er +=
|
|
969
|
+
er += `\nLine: ${this.line}\nColumn: ${this.column}\nChar: ${this.c}`;
|
|
971
970
|
}
|
|
972
971
|
const error = new Error(er);
|
|
973
972
|
this.error = error;
|
|
@@ -988,9 +987,9 @@ class SAX {
|
|
|
988
987
|
const local = qn.local;
|
|
989
988
|
if (prefix === 'xmlns') {
|
|
990
989
|
if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
|
|
991
|
-
this.strictFail(
|
|
990
|
+
this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}\n` + `Actual: ${this.attribValue}`);
|
|
992
991
|
} else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
|
|
993
|
-
this.strictFail(
|
|
992
|
+
this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}\n` + `Actual: ${this.attribValue}`);
|
|
994
993
|
} else {
|
|
995
994
|
const tag = this.tag;
|
|
996
995
|
const parent = this.tags[this.tags.length - 1] || this;
|
|
@@ -1049,7 +1048,7 @@ class SAX {
|
|
|
1049
1048
|
entity = entity.replace(/^0+/, '');
|
|
1050
1049
|
if (isNaN(num) || numStr.toLowerCase() !== entity) {
|
|
1051
1050
|
this.strictFail('Invalid character entity');
|
|
1052
|
-
return
|
|
1051
|
+
return `&${this.entity};`;
|
|
1053
1052
|
}
|
|
1054
1053
|
return String.fromCodePoint(num);
|
|
1055
1054
|
}
|
|
@@ -1107,7 +1106,7 @@ class SAX {
|
|
|
1107
1106
|
this.script = '';
|
|
1108
1107
|
break;
|
|
1109
1108
|
default:
|
|
1110
|
-
this.errorFunction(
|
|
1109
|
+
this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
|
|
1111
1110
|
}
|
|
1112
1111
|
}
|
|
1113
1112
|
maxActual = Math.max(maxActual, len);
|
|
@@ -1123,7 +1122,7 @@ class SAX {
|
|
|
1123
1122
|
tag.local = qn.local;
|
|
1124
1123
|
tag.uri = tag.ns[qn.prefix] || '';
|
|
1125
1124
|
if (tag.prefix && !tag.uri) {
|
|
1126
|
-
this.strictFail(
|
|
1125
|
+
this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
|
|
1127
1126
|
tag.uri = qn.prefix;
|
|
1128
1127
|
}
|
|
1129
1128
|
const parent = this.tags[this.tags.length - 1] || this;
|
|
@@ -1152,7 +1151,7 @@ class SAX {
|
|
|
1152
1151
|
uri
|
|
1153
1152
|
};
|
|
1154
1153
|
if (prefix && prefix !== 'xmlns' && !uri) {
|
|
1155
|
-
this.strictFail(
|
|
1154
|
+
this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
|
|
1156
1155
|
a.uri = prefix;
|
|
1157
1156
|
}
|
|
1158
1157
|
this.tag.attributes[name] = a;
|
|
@@ -1185,7 +1184,7 @@ class SAX {
|
|
|
1185
1184
|
}
|
|
1186
1185
|
if (this.script) {
|
|
1187
1186
|
if (this.tagName !== 'script') {
|
|
1188
|
-
this.script +=
|
|
1187
|
+
this.script += `</${this.tagName}>`;
|
|
1189
1188
|
this.tagName = '';
|
|
1190
1189
|
this.state = this.S.SCRIPT;
|
|
1191
1190
|
return;
|
|
@@ -1207,8 +1206,8 @@ class SAX {
|
|
|
1207
1206
|
}
|
|
1208
1207
|
}
|
|
1209
1208
|
if (t < 0) {
|
|
1210
|
-
this.strictFail(
|
|
1211
|
-
this.textNode +=
|
|
1209
|
+
this.strictFail(`Unmatched closing tag: ${this.tagName}`);
|
|
1210
|
+
this.textNode += `</${this.tagName}>`;
|
|
1212
1211
|
this.state = this.S.TEXT;
|
|
1213
1212
|
return;
|
|
1214
1213
|
}
|
|
@@ -1245,8 +1244,8 @@ class SAX {
|
|
|
1245
1244
|
export class SAXParser extends SAX {
|
|
1246
1245
|
constructor(opt) {
|
|
1247
1246
|
super();
|
|
1248
|
-
|
|
1249
|
-
|
|
1247
|
+
this.opt = DEFAULT_SAX_PARSER_OPTIONS;
|
|
1248
|
+
this.events = DEFAULT_SAX_EVENTS;
|
|
1250
1249
|
this.clearBuffers();
|
|
1251
1250
|
this.opt = opt = {
|
|
1252
1251
|
...this.opt,
|
|
@@ -1289,5 +1288,5 @@ export class SAXParser extends SAX {
|
|
|
1289
1288
|
this.flushBuffers();
|
|
1290
1289
|
}
|
|
1291
1290
|
}
|
|
1292
|
-
|
|
1291
|
+
SAXParser.ENTITIES = ENTITIES;
|
|
1293
1292
|
//# sourceMappingURL=sax.js.map
|