@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.
Files changed (51) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +2154 -2055
  2. package/dist/{esm/html-loader.js → html-loader.js} +1 -1
  3. package/dist/html-loader.js.map +1 -0
  4. package/dist/index.cjs +1530 -0
  5. package/dist/index.js +6 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/{esm/lib → lib}/parsers/parse-xml.js +2 -2
  8. package/dist/lib/parsers/parse-xml.js.map +1 -0
  9. package/dist/{esm/lib → lib}/parsers/streaming-xml-parser.js +6 -7
  10. package/dist/lib/parsers/streaming-xml-parser.js.map +1 -0
  11. package/dist/lib/xml-utils/uncapitalize.js.map +1 -0
  12. package/dist/lib/xml-utils/xml-utils.js.map +1 -0
  13. package/dist/{esm/sax-ts → sax-ts}/sax.js +75 -76
  14. package/dist/sax-ts/sax.js.map +1 -0
  15. package/dist/{esm/xml-loader.js → xml-loader.js} +2 -2
  16. package/dist/xml-loader.js.map +1 -0
  17. package/package.json +16 -8
  18. package/dist/bundle.d.ts +0 -2
  19. package/dist/bundle.d.ts.map +0 -1
  20. package/dist/es5/bundle.js +0 -6
  21. package/dist/es5/bundle.js.map +0 -1
  22. package/dist/es5/html-loader.js +0 -58
  23. package/dist/es5/html-loader.js.map +0 -1
  24. package/dist/es5/index.js +0 -53
  25. package/dist/es5/index.js.map +0 -1
  26. package/dist/es5/lib/parsers/parse-xml.js +0 -53
  27. package/dist/es5/lib/parsers/parse-xml.js.map +0 -1
  28. package/dist/es5/lib/parsers/streaming-xml-parser.js +0 -134
  29. package/dist/es5/lib/parsers/streaming-xml-parser.js.map +0 -1
  30. package/dist/es5/lib/xml-utils/uncapitalize.js +0 -32
  31. package/dist/es5/lib/xml-utils/uncapitalize.js.map +0 -1
  32. package/dist/es5/lib/xml-utils/xml-utils.js +0 -23
  33. package/dist/es5/lib/xml-utils/xml-utils.js.map +0 -1
  34. package/dist/es5/sax-ts/sax.js +0 -1372
  35. package/dist/es5/sax-ts/sax.js.map +0 -1
  36. package/dist/es5/xml-loader.js +0 -58
  37. package/dist/es5/xml-loader.js.map +0 -1
  38. package/dist/esm/bundle.js +0 -4
  39. package/dist/esm/bundle.js.map +0 -1
  40. package/dist/esm/html-loader.js.map +0 -1
  41. package/dist/esm/index.js +0 -6
  42. package/dist/esm/index.js.map +0 -1
  43. package/dist/esm/lib/parsers/parse-xml.js.map +0 -1
  44. package/dist/esm/lib/parsers/streaming-xml-parser.js.map +0 -1
  45. package/dist/esm/lib/xml-utils/uncapitalize.js.map +0 -1
  46. package/dist/esm/lib/xml-utils/xml-utils.js.map +0 -1
  47. package/dist/esm/sax-ts/sax.js.map +0 -1
  48. package/dist/esm/xml-loader.js.map +0 -1
  49. package/src/bundle.ts +0 -4
  50. /package/dist/{esm/lib → lib}/xml-utils/uncapitalize.js +0 -0
  51. /package/dist/{esm/lib → lib}/xml-utils/xml-utils.js +0 -0
@@ -1,1372 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.SAXParser = exports.ENTITIES = void 0;
8
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
9
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
10
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
11
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
17
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
- var DEFAULT_SAX_EVENTS = {
21
- ontext: function ontext() {},
22
- onprocessinginstruction: function onprocessinginstruction() {},
23
- onsgmldeclaration: function onsgmldeclaration() {},
24
- ondoctype: function ondoctype() {},
25
- oncomment: function oncomment() {},
26
- onopentagstart: function onopentagstart() {},
27
- onattribute: function onattribute() {},
28
- onopentag: function onopentag() {},
29
- onclosetag: function onclosetag() {},
30
- onopencdata: function onopencdata() {},
31
- oncdata: function oncdata() {},
32
- onclosecdata: function onclosecdata() {},
33
- onerror: function onerror() {},
34
- onend: function onend() {},
35
- onready: function onready() {},
36
- onscript: function onscript() {},
37
- onopennamespace: function onopennamespace() {},
38
- onclosenamespace: function onclosenamespace() {}
39
- };
40
- var DEFAULT_SAX_PARSER_OPTIONS = _objectSpread(_objectSpread({}, DEFAULT_SAX_EVENTS), {}, {
41
- strict: false,
42
- MAX_BUFFER_LENGTH: 64 * 1024,
43
- lowercase: false,
44
- lowercasetags: false,
45
- noscript: false,
46
- strictEntities: false,
47
- xmlns: undefined,
48
- position: undefined,
49
- trim: undefined,
50
- normalize: undefined
51
- });
52
- var EVENTS = ['text', 'processinginstruction', 'sgmldeclaration', 'doctype', 'comment', 'opentagstart', 'attribute', 'opentag', 'closetag', 'opencdata', 'cdata', 'closecdata', 'error', 'end', 'ready', 'script', 'opennamespace', 'closenamespace'];
53
- var BUFFERS = ['comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', 'attribValue', 'cdata', 'script'];
54
- var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
55
- var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
56
- var entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
57
- var entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
58
- var ENTITIES = {
59
- amp: '&',
60
- gt: '>',
61
- lt: '<',
62
- quot: '"',
63
- apos: "'",
64
- AElig: 198,
65
- Aacute: 193,
66
- Acirc: 194,
67
- Agrave: 192,
68
- Aring: 197,
69
- Atilde: 195,
70
- Auml: 196,
71
- Ccedil: 199,
72
- ETH: 208,
73
- Eacute: 201,
74
- Ecirc: 202,
75
- Egrave: 200,
76
- Euml: 203,
77
- Iacute: 205,
78
- Icirc: 206,
79
- Igrave: 204,
80
- Iuml: 207,
81
- Ntilde: 209,
82
- Oacute: 211,
83
- Ocirc: 212,
84
- Ograve: 210,
85
- Oslash: 216,
86
- Otilde: 213,
87
- Ouml: 214,
88
- THORN: 222,
89
- Uacute: 218,
90
- Ucirc: 219,
91
- Ugrave: 217,
92
- Uuml: 220,
93
- Yacute: 221,
94
- aacute: 225,
95
- acirc: 226,
96
- aelig: 230,
97
- agrave: 224,
98
- aring: 229,
99
- atilde: 227,
100
- auml: 228,
101
- ccedil: 231,
102
- eacute: 233,
103
- ecirc: 234,
104
- egrave: 232,
105
- eth: 240,
106
- euml: 235,
107
- iacute: 237,
108
- icirc: 238,
109
- igrave: 236,
110
- iuml: 239,
111
- ntilde: 241,
112
- oacute: 243,
113
- ocirc: 244,
114
- ograve: 242,
115
- oslash: 248,
116
- otilde: 245,
117
- ouml: 246,
118
- szlig: 223,
119
- thorn: 254,
120
- uacute: 250,
121
- ucirc: 251,
122
- ugrave: 249,
123
- uuml: 252,
124
- yacute: 253,
125
- yuml: 255,
126
- copy: 169,
127
- reg: 174,
128
- nbsp: 160,
129
- iexcl: 161,
130
- cent: 162,
131
- pound: 163,
132
- curren: 164,
133
- yen: 165,
134
- brvbar: 166,
135
- sect: 167,
136
- uml: 168,
137
- ordf: 170,
138
- laquo: 171,
139
- not: 172,
140
- shy: 173,
141
- macr: 175,
142
- deg: 176,
143
- plusmn: 177,
144
- sup1: 185,
145
- sup2: 178,
146
- sup3: 179,
147
- acute: 180,
148
- micro: 181,
149
- para: 182,
150
- middot: 183,
151
- cedil: 184,
152
- ordm: 186,
153
- raquo: 187,
154
- frac14: 188,
155
- frac12: 189,
156
- frac34: 190,
157
- iquest: 191,
158
- times: 215,
159
- divide: 247,
160
- OElig: 338,
161
- oelig: 339,
162
- Scaron: 352,
163
- scaron: 353,
164
- Yuml: 376,
165
- fnof: 402,
166
- circ: 710,
167
- tilde: 732,
168
- Alpha: 913,
169
- Beta: 914,
170
- Gamma: 915,
171
- Delta: 916,
172
- Epsilon: 917,
173
- Zeta: 918,
174
- Eta: 919,
175
- Theta: 920,
176
- Iota: 921,
177
- Kappa: 922,
178
- Lambda: 923,
179
- Mu: 924,
180
- Nu: 925,
181
- Xi: 926,
182
- Omicron: 927,
183
- Pi: 928,
184
- Rho: 929,
185
- Sigma: 931,
186
- Tau: 932,
187
- Upsilon: 933,
188
- Phi: 934,
189
- Chi: 935,
190
- Psi: 936,
191
- Omega: 937,
192
- alpha: 945,
193
- beta: 946,
194
- gamma: 947,
195
- delta: 948,
196
- epsilon: 949,
197
- zeta: 950,
198
- eta: 951,
199
- theta: 952,
200
- iota: 953,
201
- kappa: 954,
202
- lambda: 955,
203
- mu: 956,
204
- nu: 957,
205
- xi: 958,
206
- omicron: 959,
207
- pi: 960,
208
- rho: 961,
209
- sigmaf: 962,
210
- sigma: 963,
211
- tau: 964,
212
- upsilon: 965,
213
- phi: 966,
214
- chi: 967,
215
- psi: 968,
216
- omega: 969,
217
- thetasym: 977,
218
- upsih: 978,
219
- piv: 982,
220
- ensp: 8194,
221
- emsp: 8195,
222
- thinsp: 8201,
223
- zwnj: 8204,
224
- zwj: 8205,
225
- lrm: 8206,
226
- rlm: 8207,
227
- ndash: 8211,
228
- mdash: 8212,
229
- lsquo: 8216,
230
- rsquo: 8217,
231
- sbquo: 8218,
232
- ldquo: 8220,
233
- rdquo: 8221,
234
- bdquo: 8222,
235
- dagger: 8224,
236
- Dagger: 8225,
237
- bull: 8226,
238
- hellip: 8230,
239
- permil: 8240,
240
- prime: 8242,
241
- Prime: 8243,
242
- lsaquo: 8249,
243
- rsaquo: 8250,
244
- oline: 8254,
245
- frasl: 8260,
246
- euro: 8364,
247
- image: 8465,
248
- weierp: 8472,
249
- real: 8476,
250
- trade: 8482,
251
- alefsym: 8501,
252
- larr: 8592,
253
- uarr: 8593,
254
- rarr: 8594,
255
- darr: 8595,
256
- harr: 8596,
257
- crarr: 8629,
258
- lArr: 8656,
259
- uArr: 8657,
260
- rArr: 8658,
261
- dArr: 8659,
262
- hArr: 8660,
263
- forall: 8704,
264
- part: 8706,
265
- exist: 8707,
266
- empty: 8709,
267
- nabla: 8711,
268
- isin: 8712,
269
- notin: 8713,
270
- ni: 8715,
271
- prod: 8719,
272
- sum: 8721,
273
- minus: 8722,
274
- lowast: 8727,
275
- radic: 8730,
276
- prop: 8733,
277
- infin: 8734,
278
- ang: 8736,
279
- and: 8743,
280
- or: 8744,
281
- cap: 8745,
282
- cup: 8746,
283
- int: 8747,
284
- there4: 8756,
285
- sim: 8764,
286
- cong: 8773,
287
- asymp: 8776,
288
- ne: 8800,
289
- equiv: 8801,
290
- le: 8804,
291
- ge: 8805,
292
- sub: 8834,
293
- sup: 8835,
294
- nsub: 8836,
295
- sube: 8838,
296
- supe: 8839,
297
- oplus: 8853,
298
- otimes: 8855,
299
- perp: 8869,
300
- sdot: 8901,
301
- lceil: 8968,
302
- rceil: 8969,
303
- lfloor: 8970,
304
- rfloor: 8971,
305
- lang: 9001,
306
- rang: 9002,
307
- loz: 9674,
308
- spades: 9824,
309
- clubs: 9827,
310
- hearts: 9829,
311
- diams: 9830
312
- };
313
- exports.ENTITIES = ENTITIES;
314
- Object.keys(ENTITIES).forEach(function (key) {
315
- var e = ENTITIES[key];
316
- ENTITIES[key] = typeof e === 'number' ? String.fromCharCode(e) : e;
317
- });
318
- var SAX = function () {
319
- function SAX() {
320
- (0, _classCallCheck2.default)(this, SAX);
321
- (0, _defineProperty2.default)(this, "EVENTS", EVENTS);
322
- (0, _defineProperty2.default)(this, "ENTITIES", _objectSpread({}, ENTITIES));
323
- (0, _defineProperty2.default)(this, "events", void 0);
324
- (0, _defineProperty2.default)(this, "XML_ENTITIES", {
325
- amp: '&',
326
- gt: '>',
327
- lt: '<',
328
- quot: '"',
329
- apos: "'"
330
- });
331
- (0, _defineProperty2.default)(this, "S", 0);
332
- (0, _defineProperty2.default)(this, "opt", void 0);
333
- (0, _defineProperty2.default)(this, "trackPosition", false);
334
- (0, _defineProperty2.default)(this, "column", 0);
335
- (0, _defineProperty2.default)(this, "line", 0);
336
- (0, _defineProperty2.default)(this, "c", '');
337
- (0, _defineProperty2.default)(this, "error", void 0);
338
- (0, _defineProperty2.default)(this, "q", '');
339
- (0, _defineProperty2.default)(this, "bufferCheckPosition", void 0);
340
- (0, _defineProperty2.default)(this, "closed", false);
341
- (0, _defineProperty2.default)(this, "tags", []);
342
- (0, _defineProperty2.default)(this, "looseCase", '');
343
- (0, _defineProperty2.default)(this, "closedRoot", false);
344
- (0, _defineProperty2.default)(this, "sawRoot", false);
345
- (0, _defineProperty2.default)(this, "strict", false);
346
- (0, _defineProperty2.default)(this, "tag", void 0);
347
- (0, _defineProperty2.default)(this, "strictEntities", void 0);
348
- (0, _defineProperty2.default)(this, "state", void 0);
349
- (0, _defineProperty2.default)(this, "noscript", false);
350
- (0, _defineProperty2.default)(this, "attribList", []);
351
- (0, _defineProperty2.default)(this, "ns", void 0);
352
- (0, _defineProperty2.default)(this, "position", 0);
353
- (0, _defineProperty2.default)(this, "STATE", {
354
- BEGIN: this.S++,
355
- BEGIN_WHITESPACE: this.S++,
356
- TEXT: this.S++,
357
- TEXT_ENTITY: this.S++,
358
- OPEN_WAKA: this.S++,
359
- SGML_DECL: this.S++,
360
- SGML_DECL_QUOTED: this.S++,
361
- DOCTYPE: this.S++,
362
- DOCTYPE_QUOTED: this.S++,
363
- DOCTYPE_DTD: this.S++,
364
- DOCTYPE_DTD_QUOTED: this.S++,
365
- COMMENT_STARTING: this.S++,
366
- COMMENT: this.S++,
367
- COMMENT_ENDING: this.S++,
368
- COMMENT_ENDED: this.S++,
369
- CDATA: this.S++,
370
- CDATA_ENDING: this.S++,
371
- CDATA_ENDING_2: this.S++,
372
- PROC_INST: this.S++,
373
- PROC_INST_BODY: this.S++,
374
- PROC_INST_ENDING: this.S++,
375
- OPEN_TAG: this.S++,
376
- OPEN_TAG_SLASH: this.S++,
377
- ATTRIB: this.S++,
378
- ATTRIB_NAME: this.S++,
379
- ATTRIB_NAME_SAW_WHITE: this.S++,
380
- ATTRIB_VALUE: this.S++,
381
- ATTRIB_VALUE_QUOTED: this.S++,
382
- ATTRIB_VALUE_CLOSED: this.S++,
383
- ATTRIB_VALUE_UNQUOTED: this.S++,
384
- ATTRIB_VALUE_ENTITY_Q: this.S++,
385
- ATTRIB_VALUE_ENTITY_U: this.S++,
386
- CLOSE_TAG: this.S++,
387
- CLOSE_TAG_SAW_WHITE: this.S++,
388
- SCRIPT: this.S++,
389
- SCRIPT_ENDING: this.S++
390
- });
391
- (0, _defineProperty2.default)(this, "BUFFERS", BUFFERS);
392
- (0, _defineProperty2.default)(this, "CDATA", '[CDATA[');
393
- (0, _defineProperty2.default)(this, "DOCTYPE", 'DOCTYPE');
394
- (0, _defineProperty2.default)(this, "XML_NAMESPACE", 'http://www.w3.org/XML/1998/namespace');
395
- (0, _defineProperty2.default)(this, "XMLNS_NAMESPACE", 'http://www.w3.org/2000/xmlns/');
396
- (0, _defineProperty2.default)(this, "rootNS", {
397
- xml: this.XML_NAMESPACE,
398
- xmlns: this.XMLNS_NAMESPACE
399
- });
400
- (0, _defineProperty2.default)(this, "comment", void 0);
401
- (0, _defineProperty2.default)(this, "sgmlDecl", void 0);
402
- (0, _defineProperty2.default)(this, "textNode", '');
403
- (0, _defineProperty2.default)(this, "tagName", void 0);
404
- (0, _defineProperty2.default)(this, "doctype", void 0);
405
- (0, _defineProperty2.default)(this, "procInstName", void 0);
406
- (0, _defineProperty2.default)(this, "procInstBody", void 0);
407
- (0, _defineProperty2.default)(this, "entity", '');
408
- (0, _defineProperty2.default)(this, "attribName", void 0);
409
- (0, _defineProperty2.default)(this, "attribValue", void 0);
410
- (0, _defineProperty2.default)(this, "cdata", '');
411
- (0, _defineProperty2.default)(this, "script", '');
412
- (0, _defineProperty2.default)(this, "startTagPosition", 0);
413
- this.S = 0;
414
- for (var s in this.STATE) {
415
- if (this.STATE.hasOwnProperty(s)) {
416
- this.STATE[this.STATE[s]] = s;
417
- }
418
- }
419
- this.S = this.STATE;
420
- }
421
- (0, _createClass2.default)(SAX, [{
422
- key: "write",
423
- value: function write(chunk) {
424
- if (this.error) {
425
- throw this.error;
426
- }
427
- if (this.closed) {
428
- return this.errorFunction('Cannot write after close. Assign an onready handler.');
429
- }
430
- if (chunk === null) {
431
- return this.end();
432
- }
433
- if ((0, _typeof2.default)(chunk) === 'object') {
434
- chunk = chunk.toString();
435
- }
436
- var i = 0;
437
- var c;
438
- while (true) {
439
- c = SAX.charAt(chunk, i++);
440
- this.c = c;
441
- if (!c) {
442
- break;
443
- }
444
- if (this.trackPosition) {
445
- this.position++;
446
- if (c === '\n') {
447
- this.line++;
448
- this.column = 0;
449
- } else {
450
- this.column++;
451
- }
452
- }
453
- switch (this.state) {
454
- case this.S.BEGIN:
455
- this.state = this.S.BEGIN_WHITESPACE;
456
- if (c === "\uFEFF") {
457
- continue;
458
- }
459
- this.beginWhiteSpace(c);
460
- continue;
461
- case this.S.BEGIN_WHITESPACE:
462
- this.beginWhiteSpace(c);
463
- continue;
464
- case this.S.TEXT:
465
- if (this.sawRoot && !this.closedRoot) {
466
- var starti = i - 1;
467
- while (c && c !== '<' && c !== '&') {
468
- c = SAX.charAt(chunk, i++);
469
- if (c && this.trackPosition) {
470
- this.position++;
471
- if (c === '\n') {
472
- this.line++;
473
- this.column = 0;
474
- } else {
475
- this.column++;
476
- }
477
- }
478
- }
479
- this.textNode += chunk.substring(starti, i - 1);
480
- }
481
- if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
482
- this.state = this.S.OPEN_WAKA;
483
- this.startTagPosition = this.position;
484
- } else {
485
- if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
486
- this.strictFail('Text data outside of root node.');
487
- }
488
- if (c === '&') {
489
- this.state = this.S.TEXT_ENTITY;
490
- } else {
491
- this.textNode += c;
492
- }
493
- }
494
- continue;
495
- case this.S.SCRIPT:
496
- if (c === '<') {
497
- this.state = this.S.SCRIPT_ENDING;
498
- } else {
499
- this.script += c;
500
- }
501
- continue;
502
- case this.S.SCRIPT_ENDING:
503
- if (c === '/') {
504
- this.state = this.S.CLOSE_TAG;
505
- } else {
506
- this.script += "<".concat(c);
507
- this.state = this.S.SCRIPT;
508
- }
509
- continue;
510
- case this.S.OPEN_WAKA:
511
- if (c === '!') {
512
- this.state = this.S.SGML_DECL;
513
- this.sgmlDecl = '';
514
- } else if (SAX.isWhitespace(c)) {} else if (SAX.isMatch(nameStart, c)) {
515
- this.state = this.S.OPEN_TAG;
516
- this.tagName = c;
517
- } else if (c === '/') {
518
- this.state = this.S.CLOSE_TAG;
519
- this.tagName = '';
520
- } else if (c === '?') {
521
- this.state = this.S.PROC_INST;
522
- this.procInstName = this.procInstBody = '';
523
- } else {
524
- this.strictFail('Unencoded <');
525
- if (this.startTagPosition + 1 < this.position) {
526
- var pad = this.position - this.startTagPosition;
527
- c = new Array(pad).join(' ') + c;
528
- }
529
- this.textNode += "<".concat(c);
530
- this.state = this.S.TEXT;
531
- }
532
- continue;
533
- case this.S.SGML_DECL:
534
- if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
535
- this.emitNode('onopencdata');
536
- this.state = this.S.CDATA;
537
- this.sgmlDecl = '';
538
- this.cdata = '';
539
- } else if (this.sgmlDecl + c === '--') {
540
- this.state = this.S.COMMENT;
541
- this.comment = '';
542
- this.sgmlDecl = '';
543
- } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
544
- this.state = this.S.DOCTYPE;
545
- if (this.doctype || this.sawRoot) {
546
- this.strictFail('Inappropriately located doctype declaration');
547
- }
548
- this.doctype = '';
549
- this.sgmlDecl = '';
550
- } else if (c === '>') {
551
- this.emitNode('onsgmldeclaration', this.sgmlDecl);
552
- this.sgmlDecl = '';
553
- this.state = this.S.TEXT;
554
- } else if (SAX.isQuote(c)) {
555
- this.state = this.S.SGML_DECL_QUOTED;
556
- this.sgmlDecl += c;
557
- } else {
558
- this.sgmlDecl += c;
559
- }
560
- continue;
561
- case this.S.SGML_DECL_QUOTED:
562
- if (c === this.q) {
563
- this.state = this.S.SGML_DECL;
564
- this.q = '';
565
- }
566
- this.sgmlDecl += c;
567
- continue;
568
- case this.S.DOCTYPE:
569
- if (c === '>') {
570
- this.state = this.S.TEXT;
571
- this.emitNode('ondoctype', this.doctype);
572
- this.doctype = true;
573
- } else {
574
- this.doctype += c;
575
- if (c === '[') {
576
- this.state = this.S.DOCTYPE_DTD;
577
- } else if (SAX.isQuote(c)) {
578
- this.state = this.S.DOCTYPE_QUOTED;
579
- this.q = c;
580
- }
581
- }
582
- continue;
583
- case this.S.DOCTYPE_QUOTED:
584
- this.doctype += c;
585
- if (c === this.q) {
586
- this.q = '';
587
- this.state = this.S.DOCTYPE;
588
- }
589
- continue;
590
- case this.S.DOCTYPE_DTD:
591
- this.doctype += c;
592
- if (c === ']') {
593
- this.state = this.S.DOCTYPE;
594
- } else if (SAX.isQuote(c)) {
595
- this.state = this.S.DOCTYPE_DTD_QUOTED;
596
- this.q = c;
597
- }
598
- continue;
599
- case this.S.DOCTYPE_DTD_QUOTED:
600
- this.doctype += c;
601
- if (c === this.q) {
602
- this.state = this.S.DOCTYPE_DTD;
603
- this.q = '';
604
- }
605
- continue;
606
- case this.S.COMMENT:
607
- if (c === '-') {
608
- this.state = this.S.COMMENT_ENDING;
609
- } else {
610
- this.comment += c;
611
- }
612
- continue;
613
- case this.S.COMMENT_ENDING:
614
- if (c === '-') {
615
- this.state = this.S.COMMENT_ENDED;
616
- this.comment = this.textApplyOptions(this.comment);
617
- if (this.comment) {
618
- this.emitNode('oncomment', this.comment);
619
- }
620
- this.comment = '';
621
- } else {
622
- this.comment += "-".concat(c);
623
- this.state = this.S.COMMENT;
624
- }
625
- continue;
626
- case this.S.COMMENT_ENDED:
627
- if (c !== '>') {
628
- this.strictFail('Malformed comment');
629
- this.comment += "--".concat(c);
630
- this.state = this.S.COMMENT;
631
- } else {
632
- this.state = this.S.TEXT;
633
- }
634
- continue;
635
- case this.S.CDATA:
636
- if (c === ']') {
637
- this.state = this.S.CDATA_ENDING;
638
- } else {
639
- this.cdata += c;
640
- }
641
- continue;
642
- case this.S.CDATA_ENDING:
643
- if (c === ']') {
644
- this.state = this.S.CDATA_ENDING_2;
645
- } else {
646
- this.cdata += "]".concat(c);
647
- this.state = this.S.CDATA;
648
- }
649
- continue;
650
- case this.S.CDATA_ENDING_2:
651
- if (c === '>') {
652
- if (this.cdata) {
653
- this.emitNode('oncdata', this.cdata);
654
- }
655
- this.emitNode('onclosecdata');
656
- this.cdata = '';
657
- this.state = this.S.TEXT;
658
- } else if (c === ']') {
659
- this.cdata += ']';
660
- } else {
661
- this.cdata += "]]".concat(c);
662
- this.state = this.S.CDATA;
663
- }
664
- continue;
665
- case this.S.PROC_INST:
666
- if (c === '?') {
667
- this.state = this.S.PROC_INST_ENDING;
668
- } else if (SAX.isWhitespace(c)) {
669
- this.state = this.S.PROC_INST_BODY;
670
- } else {
671
- this.procInstName += c;
672
- }
673
- continue;
674
- case this.S.PROC_INST_BODY:
675
- if (!this.procInstBody && SAX.isWhitespace(c)) {
676
- continue;
677
- } else if (c === '?') {
678
- this.state = this.S.PROC_INST_ENDING;
679
- } else {
680
- this.procInstBody += c;
681
- }
682
- continue;
683
- case this.S.PROC_INST_ENDING:
684
- if (c === '>') {
685
- this.emitNode('onprocessinginstruction', {
686
- name: this.procInstName,
687
- body: this.procInstBody
688
- });
689
- this.procInstName = this.procInstBody = '';
690
- this.state = this.S.TEXT;
691
- } else {
692
- this.procInstBody += "?".concat(c);
693
- this.state = this.S.PROC_INST_BODY;
694
- }
695
- continue;
696
- case this.S.OPEN_TAG:
697
- if (SAX.isMatch(nameBody, c)) {
698
- this.tagName += c;
699
- } else {
700
- this.newTag();
701
- if (c === '>') {
702
- this.openTag();
703
- } else if (c === '/') {
704
- this.state = this.S.OPEN_TAG_SLASH;
705
- } else {
706
- if (!SAX.isWhitespace(c)) {
707
- this.strictFail('Invalid character in tag name');
708
- }
709
- this.state = this.S.ATTRIB;
710
- }
711
- }
712
- continue;
713
- case this.S.OPEN_TAG_SLASH:
714
- if (c === '>') {
715
- this.openTag(true);
716
- this.closeTag();
717
- } else {
718
- this.strictFail('Forward-slash in opening tag not followed by >');
719
- this.state = this.S.ATTRIB;
720
- }
721
- continue;
722
- case this.S.ATTRIB:
723
- if (SAX.isWhitespace(c)) {
724
- continue;
725
- } else if (c === '>') {
726
- this.openTag();
727
- } else if (c === '/') {
728
- this.state = this.S.OPEN_TAG_SLASH;
729
- } else if (SAX.isMatch(nameStart, c)) {
730
- this.attribName = c;
731
- this.attribValue = '';
732
- this.state = this.S.ATTRIB_NAME;
733
- } else {
734
- this.strictFail('Invalid attribute name');
735
- }
736
- continue;
737
- case this.S.ATTRIB_NAME:
738
- if (c === '=') {
739
- this.state = this.S.ATTRIB_VALUE;
740
- } else if (c === '>') {
741
- this.strictFail('Attribute without value');
742
- this.attribValue = this.attribName;
743
- this.attrib();
744
- this.openTag();
745
- } else if (SAX.isWhitespace(c)) {
746
- this.state = this.S.ATTRIB_NAME_SAW_WHITE;
747
- } else if (SAX.isMatch(nameBody, c)) {
748
- this.attribName += c;
749
- } else {
750
- this.strictFail('Invalid attribute name');
751
- }
752
- continue;
753
- case this.S.ATTRIB_NAME_SAW_WHITE:
754
- if (c === '=') {
755
- this.state = this.S.ATTRIB_VALUE;
756
- } else if (SAX.isWhitespace(c)) {
757
- continue;
758
- } else {
759
- this.strictFail('Attribute without value');
760
- this.tag.attributes[this.attribName] = '';
761
- this.attribValue = '';
762
- this.emitNode('onattribute', {
763
- name: this.attribName,
764
- value: ''
765
- });
766
- this.attribName = '';
767
- if (c === '>') {
768
- this.openTag();
769
- } else if (SAX.isMatch(nameStart, c)) {
770
- this.attribName = c;
771
- this.state = this.S.ATTRIB_NAME;
772
- } else {
773
- this.strictFail('Invalid attribute name');
774
- this.state = this.S.ATTRIB;
775
- }
776
- }
777
- continue;
778
- case this.S.ATTRIB_VALUE:
779
- if (SAX.isWhitespace(c)) {
780
- continue;
781
- } else if (SAX.isQuote(c)) {
782
- this.q = c;
783
- this.state = this.S.ATTRIB_VALUE_QUOTED;
784
- } else {
785
- this.strictFail('Unquoted attribute value');
786
- this.state = this.S.ATTRIB_VALUE_UNQUOTED;
787
- this.attribValue = c;
788
- }
789
- continue;
790
- case this.S.ATTRIB_VALUE_QUOTED:
791
- if (c !== this.q) {
792
- if (c === '&') {
793
- this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
794
- } else {
795
- this.attribValue += c;
796
- }
797
- continue;
798
- }
799
- this.attrib();
800
- this.q = '';
801
- this.state = this.S.ATTRIB_VALUE_CLOSED;
802
- continue;
803
- case this.S.ATTRIB_VALUE_CLOSED:
804
- if (SAX.isWhitespace(c)) {
805
- this.state = this.S.ATTRIB;
806
- } else if (c === '>') {
807
- this.openTag();
808
- } else if (c === '/') {
809
- this.state = this.S.OPEN_TAG_SLASH;
810
- } else if (SAX.isMatch(nameStart, c)) {
811
- this.strictFail('No whitespace between attributes');
812
- this.attribName = c;
813
- this.attribValue = '';
814
- this.state = this.S.ATTRIB_NAME;
815
- } else {
816
- this.strictFail('Invalid attribute name');
817
- }
818
- continue;
819
- case this.S.ATTRIB_VALUE_UNQUOTED:
820
- if (!SAX.isAttribEnd(c)) {
821
- if (c === '&') {
822
- this.state = this.S.ATTRIB_VALUE_ENTITY_U;
823
- } else {
824
- this.attribValue += c;
825
- }
826
- continue;
827
- }
828
- this.attrib();
829
- if (c === '>') {
830
- this.openTag();
831
- } else {
832
- this.state = this.S.ATTRIB;
833
- }
834
- continue;
835
- case this.S.CLOSE_TAG:
836
- if (!this.tagName) {
837
- if (SAX.isWhitespace(c)) {
838
- continue;
839
- } else if (SAX.notMatch(nameStart, c)) {
840
- if (this.script) {
841
- this.script += "</".concat(c);
842
- this.state = this.S.SCRIPT;
843
- } else {
844
- this.strictFail('Invalid tagname in closing tag.');
845
- }
846
- } else {
847
- this.tagName = c;
848
- }
849
- } else if (c === '>') {
850
- this.closeTag();
851
- } else if (SAX.isMatch(nameBody, c)) {
852
- this.tagName += c;
853
- } else if (this.script) {
854
- this.script += "</".concat(this.tagName);
855
- this.tagName = '';
856
- this.state = this.S.SCRIPT;
857
- } else {
858
- if (!SAX.isWhitespace(c)) {
859
- this.strictFail('Invalid tagname in closing tag');
860
- }
861
- this.state = this.S.CLOSE_TAG_SAW_WHITE;
862
- }
863
- continue;
864
- case this.S.CLOSE_TAG_SAW_WHITE:
865
- if (SAX.isWhitespace(c)) {
866
- continue;
867
- }
868
- if (c === '>') {
869
- this.closeTag();
870
- } else {
871
- this.strictFail('Invalid characters in closing tag');
872
- }
873
- continue;
874
- case this.S.TEXT_ENTITY:
875
- case this.S.ATTRIB_VALUE_ENTITY_Q:
876
- case this.S.ATTRIB_VALUE_ENTITY_U:
877
- var returnState = void 0;
878
- var buffer = void 0;
879
- switch (this.state) {
880
- case this.S.TEXT_ENTITY:
881
- returnState = this.S.TEXT;
882
- buffer = 'textNode';
883
- break;
884
- case this.S.ATTRIB_VALUE_ENTITY_Q:
885
- returnState = this.S.ATTRIB_VALUE_QUOTED;
886
- buffer = 'attribValue';
887
- break;
888
- case this.S.ATTRIB_VALUE_ENTITY_U:
889
- returnState = this.S.ATTRIB_VALUE_UNQUOTED;
890
- buffer = 'attribValue';
891
- break;
892
- default:
893
- throw new Error("Unknown state: ".concat(this.state));
894
- }
895
- if (c === ';') {
896
- this[buffer] += this.parseEntity();
897
- this.entity = '';
898
- this.state = returnState;
899
- } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
900
- this.entity += c;
901
- } else {
902
- this.strictFail('Invalid character in entity name');
903
- this[buffer] += "&".concat(this.entity).concat(c);
904
- this.entity = '';
905
- this.state = returnState;
906
- }
907
- continue;
908
- default:
909
- throw new Error("Unknown state: ".concat(this.state));
910
- }
911
- }
912
- if (this.position >= this.bufferCheckPosition) {
913
- this.checkBufferLength();
914
- }
915
- return this;
916
- }
917
- }, {
918
- key: "emit",
919
- value: function emit(event, data) {
920
- if (this.events.hasOwnProperty(event)) {
921
- var _eventName = event.replace(/^on/, '');
922
- this.events[event](data, _eventName, this);
923
- }
924
- }
925
- }, {
926
- key: "clearBuffers",
927
- value: function clearBuffers() {
928
- for (var i = 0, l = this.BUFFERS.length; i < l; i++) {
929
- this[this[i]] = '';
930
- }
931
- }
932
- }, {
933
- key: "flushBuffers",
934
- value: function flushBuffers() {
935
- this.closeText();
936
- if (this.cdata !== '') {
937
- this.emitNode('oncdata', this.cdata);
938
- this.cdata = '';
939
- }
940
- if (this.script !== '') {
941
- this.emitNode('onscript', this.script);
942
- this.script = '';
943
- }
944
- }
945
- }, {
946
- key: "end",
947
- value: function end() {
948
- if (this.sawRoot && !this.closedRoot) this.strictFail('Unclosed root tag');
949
- if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
950
- this.errorFunction('Unexpected end');
951
- }
952
- this.closeText();
953
- this.c = '';
954
- this.closed = true;
955
- this.emit('onend');
956
- return new SAXParser(this.opt);
957
- }
958
- }, {
959
- key: "errorFunction",
960
- value: function errorFunction(er) {
961
- this.closeText();
962
- if (this.trackPosition) {
963
- er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
964
- }
965
- var error = new Error(er);
966
- this.error = error;
967
- this.emit('onerror', error);
968
- return this;
969
- }
970
- }, {
971
- key: "attrib",
972
- value: function attrib() {
973
- if (!this.strict) {
974
- this.attribName = this.attribName[this.looseCase]();
975
- }
976
- if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
977
- this.attribName = this.attribValue = '';
978
- return;
979
- }
980
- if (this.opt.xmlns) {
981
- var qn = SAX.qname(this.attribName, true);
982
- var prefix = qn.prefix;
983
- var local = qn.local;
984
- if (prefix === 'xmlns') {
985
- if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
986
- this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
987
- } else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
988
- this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
989
- } else {
990
- var tag = this.tag;
991
- var parent = this.tags[this.tags.length - 1] || this;
992
- if (tag.ns === parent.ns) {
993
- tag.ns = Object.create(parent.ns);
994
- }
995
- tag.ns[local] = this.attribValue;
996
- }
997
- }
998
- this.attribList.push([this.attribName, this.attribValue]);
999
- } else {
1000
- this.tag.attributes[this.attribName] = this.attribValue;
1001
- this.emitNode('onattribute', {
1002
- name: this.attribName,
1003
- value: this.attribValue
1004
- });
1005
- }
1006
- this.attribName = this.attribValue = '';
1007
- }
1008
- }, {
1009
- key: "newTag",
1010
- value: function newTag() {
1011
- if (!this.strict) this.tagName = this.tagName[this.looseCase]();
1012
- var parent = this.tags[this.tags.length - 1] || this;
1013
- var tag = this.tag = {
1014
- name: this.tagName,
1015
- attributes: {}
1016
- };
1017
- if (this.opt.xmlns) {
1018
- tag.ns = parent.ns;
1019
- }
1020
- this.attribList.length = 0;
1021
- this.emitNode('onopentagstart', tag);
1022
- }
1023
- }, {
1024
- key: "parseEntity",
1025
- value: function parseEntity() {
1026
- var entity = this.entity;
1027
- var entityLC = entity.toLowerCase();
1028
- var num = NaN;
1029
- var numStr = '';
1030
- if (this.ENTITIES[entity]) {
1031
- return this.ENTITIES[entity];
1032
- }
1033
- if (this.ENTITIES[entityLC]) {
1034
- return this.ENTITIES[entityLC];
1035
- }
1036
- entity = entityLC;
1037
- if (entity.charAt(0) === '#') {
1038
- if (entity.charAt(1) === 'x') {
1039
- entity = entity.slice(2);
1040
- num = parseInt(entity, 16);
1041
- numStr = num.toString(16);
1042
- } else {
1043
- entity = entity.slice(1);
1044
- num = parseInt(entity, 10);
1045
- numStr = num.toString(10);
1046
- }
1047
- }
1048
- entity = entity.replace(/^0+/, '');
1049
- if (isNaN(num) || numStr.toLowerCase() !== entity) {
1050
- this.strictFail('Invalid character entity');
1051
- return "&".concat(this.entity, ";");
1052
- }
1053
- return String.fromCodePoint(num);
1054
- }
1055
- }, {
1056
- key: "beginWhiteSpace",
1057
- value: function beginWhiteSpace(c) {
1058
- if (c === '<') {
1059
- this.state = this.S.OPEN_WAKA;
1060
- this.startTagPosition = this.position;
1061
- } else if (!SAX.isWhitespace(c)) {
1062
- this.strictFail('Non-whitespace before first tag.');
1063
- this.textNode = c;
1064
- this.state = this.S.TEXT;
1065
- } else {}
1066
- }
1067
- }, {
1068
- key: "strictFail",
1069
- value: function strictFail(message) {
1070
- if ((0, _typeof2.default)(this) !== 'object' || !(this instanceof SAXParser)) {
1071
- throw new Error('bad call to strictFail');
1072
- }
1073
- if (this.strict) {
1074
- this.errorFunction(message);
1075
- }
1076
- }
1077
- }, {
1078
- key: "textApplyOptions",
1079
- value: function textApplyOptions(text) {
1080
- if (this.opt.trim) text = text.trim();
1081
- if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
1082
- return text;
1083
- }
1084
- }, {
1085
- key: "emitNode",
1086
- value: function emitNode(nodeType, data) {
1087
- if (this.textNode) this.closeText();
1088
- this.emit(nodeType, data);
1089
- }
1090
- }, {
1091
- key: "closeText",
1092
- value: function closeText() {
1093
- this.textNode = this.textApplyOptions(this.textNode);
1094
- if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
1095
- this.emit('ontext', this.textNode);
1096
- }
1097
- this.textNode = '';
1098
- }
1099
- }, {
1100
- key: "checkBufferLength",
1101
- value: function checkBufferLength() {
1102
- var maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1103
- var maxActual = 0;
1104
- for (var i = 0, l = this.BUFFERS.length; i < l; i++) {
1105
- var _this$this$BUFFERS$i;
1106
- var len = ((_this$this$BUFFERS$i = this[this.BUFFERS[i]]) === null || _this$this$BUFFERS$i === void 0 ? void 0 : _this$this$BUFFERS$i.length) || 0;
1107
- if (len > maxAllowed) {
1108
- switch (this.BUFFERS[i]) {
1109
- case 'textNode':
1110
- this.closeText();
1111
- break;
1112
- case 'cdata':
1113
- this.emitNode('oncdata', this.cdata);
1114
- this.cdata = '';
1115
- break;
1116
- case 'script':
1117
- this.emitNode('onscript', this.script);
1118
- this.script = '';
1119
- break;
1120
- default:
1121
- this.errorFunction("Max buffer length exceeded: ".concat(this.BUFFERS[i]));
1122
- }
1123
- }
1124
- maxActual = Math.max(maxActual, len);
1125
- }
1126
- var m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1127
- this.bufferCheckPosition = m + this.position;
1128
- }
1129
- }, {
1130
- key: "openTag",
1131
- value: function openTag(selfClosing) {
1132
- if (this.opt.xmlns) {
1133
- var tag = this.tag;
1134
- var qn = SAX.qname(this.tagName);
1135
- tag.prefix = qn.prefix;
1136
- tag.local = qn.local;
1137
- tag.uri = tag.ns[qn.prefix] || '';
1138
- if (tag.prefix && !tag.uri) {
1139
- this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(this.tagName)));
1140
- tag.uri = qn.prefix;
1141
- }
1142
- var parent = this.tags[this.tags.length - 1] || this;
1143
- if (tag.ns && parent.ns !== tag.ns) {
1144
- var that = this;
1145
- Object.keys(tag.ns).forEach(function (p) {
1146
- that.emitNode('onopennamespace', {
1147
- prefix: p,
1148
- uri: tag.ns[p]
1149
- });
1150
- });
1151
- }
1152
- for (var i = 0, l = this.attribList.length; i < l; i++) {
1153
- var nv = this.attribList[i];
1154
- var name = nv[0];
1155
- var value = nv[1];
1156
- var qualName = SAX.qname(name, true);
1157
- var prefix = qualName.prefix;
1158
- var local = qualName.local;
1159
- var uri = prefix === '' ? '' : tag.ns[prefix] || '';
1160
- var a = {
1161
- name: name,
1162
- value: value,
1163
- prefix: prefix,
1164
- local: local,
1165
- uri: uri
1166
- };
1167
- if (prefix && prefix !== 'xmlns' && !uri) {
1168
- this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
1169
- a.uri = prefix;
1170
- }
1171
- this.tag.attributes[name] = a;
1172
- this.emitNode('onattribute', a);
1173
- }
1174
- this.attribList.length = 0;
1175
- }
1176
- this.tag.isSelfClosing = Boolean(selfClosing);
1177
- this.sawRoot = true;
1178
- this.tags.push(this.tag);
1179
- this.emitNode('onopentag', this.tag);
1180
- if (!selfClosing) {
1181
- if (!this.noscript && this.tagName.toLowerCase() === 'script') {
1182
- this.state = this.S.SCRIPT;
1183
- } else {
1184
- this.state = this.S.TEXT;
1185
- }
1186
- this.tag = null;
1187
- this.tagName = '';
1188
- }
1189
- this.attribName = this.attribValue = '';
1190
- this.attribList.length = 0;
1191
- }
1192
- }, {
1193
- key: "closeTag",
1194
- value: function closeTag() {
1195
- var _this = this;
1196
- if (!this.tagName) {
1197
- this.strictFail('Weird empty close tag.');
1198
- this.textNode += '</>';
1199
- this.state = this.S.TEXT;
1200
- return;
1201
- }
1202
- if (this.script) {
1203
- if (this.tagName !== 'script') {
1204
- this.script += "</".concat(this.tagName, ">");
1205
- this.tagName = '';
1206
- this.state = this.S.SCRIPT;
1207
- return;
1208
- }
1209
- this.emitNode('onscript', this.script);
1210
- this.script = '';
1211
- }
1212
- var t = this.tags.length;
1213
- var tagName = this.tagName;
1214
- if (!this.strict) {
1215
- tagName = tagName[this.looseCase]();
1216
- }
1217
- while (t--) {
1218
- var close = this.tags[t];
1219
- if (close.name !== tagName) {
1220
- this.strictFail('Unexpected close tag');
1221
- } else {
1222
- break;
1223
- }
1224
- }
1225
- if (t < 0) {
1226
- this.strictFail("Unmatched closing tag: ".concat(this.tagName));
1227
- this.textNode += "</".concat(this.tagName, ">");
1228
- this.state = this.S.TEXT;
1229
- return;
1230
- }
1231
- this.tagName = tagName;
1232
- var s = this.tags.length;
1233
- var _loop = function _loop() {
1234
- var tag = _this.tag = _this.tags.pop();
1235
- _this.tagName = _this.tag.name;
1236
- _this.emitNode('onclosetag', _this.tagName);
1237
- var x = {};
1238
- for (var i in tag.ns) {
1239
- if (tag.ns.hasOwnProperty(i)) {
1240
- x[i] = tag.ns[i];
1241
- }
1242
- }
1243
- var parent = _this.tags[_this.tags.length - 1] || _this;
1244
- if (_this.opt.xmlns && tag.ns !== parent.ns) {
1245
- var that = _this;
1246
- Object.keys(tag.ns).forEach(function (p) {
1247
- var n = tag.ns[p];
1248
- that.emitNode('onclosenamespace', {
1249
- prefix: p,
1250
- uri: n
1251
- });
1252
- });
1253
- }
1254
- };
1255
- while (s-- > t) {
1256
- _loop();
1257
- }
1258
- if (t === 0) this.closedRoot = true;
1259
- this.tagName = this.attribValue = this.attribName = '';
1260
- this.attribList.length = 0;
1261
- this.state = this.S.TEXT;
1262
- }
1263
- }], [{
1264
- key: "charAt",
1265
- value: function charAt(chunk, i) {
1266
- var result = '';
1267
- if (i < chunk.length) {
1268
- result = chunk.charAt(i);
1269
- }
1270
- return result;
1271
- }
1272
- }, {
1273
- key: "isWhitespace",
1274
- value: function isWhitespace(c) {
1275
- return c === ' ' || c === '\n' || c === '\r' || c === '\t';
1276
- }
1277
- }, {
1278
- key: "isQuote",
1279
- value: function isQuote(c) {
1280
- return c === '"' || c === "'";
1281
- }
1282
- }, {
1283
- key: "isAttribEnd",
1284
- value: function isAttribEnd(c) {
1285
- return c === '>' || SAX.isWhitespace(c);
1286
- }
1287
- }, {
1288
- key: "isMatch",
1289
- value: function isMatch(regex, c) {
1290
- return regex.test(c);
1291
- }
1292
- }, {
1293
- key: "notMatch",
1294
- value: function notMatch(regex, c) {
1295
- return !SAX.isMatch(regex, c);
1296
- }
1297
- }, {
1298
- key: "qname",
1299
- value: function qname(name, attribute) {
1300
- var i = name.indexOf(':');
1301
- var qualName = i < 0 ? ['', name] : name.split(':');
1302
- var prefix = qualName[0];
1303
- var local = qualName[1];
1304
- if (attribute && name === 'xmlns') {
1305
- prefix = 'xmlns';
1306
- local = '';
1307
- }
1308
- return {
1309
- prefix: prefix,
1310
- local: local
1311
- };
1312
- }
1313
- }]);
1314
- return SAX;
1315
- }();
1316
- var SAXParser = function (_SAX) {
1317
- (0, _inherits2.default)(SAXParser, _SAX);
1318
- var _super = _createSuper(SAXParser);
1319
- function SAXParser(opt) {
1320
- var _this2;
1321
- (0, _classCallCheck2.default)(this, SAXParser);
1322
- _this2 = _super.call(this);
1323
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "opt", DEFAULT_SAX_PARSER_OPTIONS);
1324
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "events", DEFAULT_SAX_EVENTS);
1325
- _this2.clearBuffers();
1326
- _this2.opt = opt = _objectSpread(_objectSpread({}, _this2.opt), opt);
1327
- _this2.events = _objectSpread(_objectSpread({}, _this2.events), opt);
1328
- _this2.q = _this2.c = '';
1329
- _this2.opt.lowercase = _this2.opt.lowercase || _this2.opt.lowercasetags;
1330
- _this2.bufferCheckPosition = _this2.opt.MAX_BUFFER_LENGTH;
1331
- _this2.looseCase = _this2.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
1332
- _this2.tags = [];
1333
- _this2.closed = _this2.closedRoot = _this2.sawRoot = false;
1334
- _this2.tag = _this2.error = null;
1335
- _this2.strict = Boolean(_this2.opt.strict);
1336
- _this2.noscript = Boolean(_this2.opt.strict || _this2.opt.noscript);
1337
- _this2.state = _this2.S.BEGIN;
1338
- _this2.strictEntities = _this2.opt.strictEntities;
1339
- _this2.ENTITIES = _this2.strictEntities ? Object.create(_this2.XML_ENTITIES) : Object.create(_this2.ENTITIES);
1340
- _this2.attribList = [];
1341
- if (_this2.opt.xmlns) {
1342
- _this2.ns = Object.create(_this2.rootNS);
1343
- }
1344
- _this2.trackPosition = _this2.opt.position !== false;
1345
- if (_this2.trackPosition) {
1346
- _this2.position = _this2.line = _this2.column = 0;
1347
- }
1348
- _this2.emit('onready');
1349
- return _this2;
1350
- }
1351
- (0, _createClass2.default)(SAXParser, [{
1352
- key: "resume",
1353
- value: function resume() {
1354
- this.error = null;
1355
- return this;
1356
- }
1357
- }, {
1358
- key: "close",
1359
- value: function close() {
1360
- return this.write(null);
1361
- }
1362
- }, {
1363
- key: "flush",
1364
- value: function flush() {
1365
- this.flushBuffers();
1366
- }
1367
- }]);
1368
- return SAXParser;
1369
- }(SAX);
1370
- exports.SAXParser = SAXParser;
1371
- (0, _defineProperty2.default)(SAXParser, "ENTITIES", ENTITIES);
1372
- //# sourceMappingURL=sax.js.map