plist 3.0.0 → 3.0.4

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.
@@ -1,5 +1,5 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.plist = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
2
- (function (Buffer){
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.plist = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
+ (function (Buffer){(function (){
3
3
  /**
4
4
  * Module dependencies.
5
5
  */
@@ -192,14 +192,14 @@ function parsePlistXML (node) {
192
192
  } else if (node.nodeName === 'data') {
193
193
  res = '';
194
194
  if (isEmptyNode(node)) {
195
- return new Buffer(res, 'base64');
195
+ return Buffer.from(res, 'base64');
196
196
  }
197
197
  for (i=0; i < node.childNodes.length; i++) {
198
198
  if (node.childNodes[i].nodeType === TEXT_NODE) {
199
199
  res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
200
200
  }
201
201
  }
202
- return new Buffer(res, 'base64');
202
+ return Buffer.from(res, 'base64');
203
203
 
204
204
  } else if (node.nodeName === 'date') {
205
205
  invariant(
@@ -216,7 +216,7 @@ function parsePlistXML (node) {
216
216
  }
217
217
  }
218
218
 
219
- }).call(this,require("buffer").Buffer)
219
+ }).call(this)}).call(this,require("buffer").Buffer)
220
220
  },{"buffer":3,"xmldom":5}],2:[function(require,module,exports){
221
221
  'use strict'
222
222
 
@@ -239,65 +239,98 @@ for (var i = 0, len = code.length; i < len; ++i) {
239
239
  revLookup['-'.charCodeAt(0)] = 62
240
240
  revLookup['_'.charCodeAt(0)] = 63
241
241
 
242
- function placeHoldersCount (b64) {
242
+ function getLens (b64) {
243
243
  var len = b64.length
244
+
244
245
  if (len % 4 > 0) {
245
246
  throw new Error('Invalid string. Length must be a multiple of 4')
246
247
  }
247
248
 
248
- // the number of equal signs (place holders)
249
- // if there are two placeholders, than the two characters before it
250
- // represent one byte
251
- // if there is only one, then the three characters before it represent 2 bytes
252
- // this is just a cheap hack to not do indexOf twice
253
- return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
249
+ // Trim off extra bytes after placeholder bytes are found
250
+ // See: https://github.com/beatgammit/base64-js/issues/42
251
+ var validLen = b64.indexOf('=')
252
+ if (validLen === -1) validLen = len
253
+
254
+ var placeHoldersLen = validLen === len
255
+ ? 0
256
+ : 4 - (validLen % 4)
257
+
258
+ return [validLen, placeHoldersLen]
254
259
  }
255
260
 
261
+ // base64 is 4/3 + up to two characters of the original data
256
262
  function byteLength (b64) {
257
- // base64 is 4/3 + up to two characters of the original data
258
- return (b64.length * 3 / 4) - placeHoldersCount(b64)
263
+ var lens = getLens(b64)
264
+ var validLen = lens[0]
265
+ var placeHoldersLen = lens[1]
266
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
267
+ }
268
+
269
+ function _byteLength (b64, validLen, placeHoldersLen) {
270
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
259
271
  }
260
272
 
261
273
  function toByteArray (b64) {
262
- var i, l, tmp, placeHolders, arr
263
- var len = b64.length
264
- placeHolders = placeHoldersCount(b64)
274
+ var tmp
275
+ var lens = getLens(b64)
276
+ var validLen = lens[0]
277
+ var placeHoldersLen = lens[1]
265
278
 
266
- arr = new Arr((len * 3 / 4) - placeHolders)
279
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
280
+
281
+ var curByte = 0
267
282
 
268
283
  // if there are placeholders, only get up to the last complete 4 chars
269
- l = placeHolders > 0 ? len - 4 : len
284
+ var len = placeHoldersLen > 0
285
+ ? validLen - 4
286
+ : validLen
270
287
 
271
- var L = 0
288
+ var i
289
+ for (i = 0; i < len; i += 4) {
290
+ tmp =
291
+ (revLookup[b64.charCodeAt(i)] << 18) |
292
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
293
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
294
+ revLookup[b64.charCodeAt(i + 3)]
295
+ arr[curByte++] = (tmp >> 16) & 0xFF
296
+ arr[curByte++] = (tmp >> 8) & 0xFF
297
+ arr[curByte++] = tmp & 0xFF
298
+ }
272
299
 
273
- for (i = 0; i < l; i += 4) {
274
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
275
- arr[L++] = (tmp >> 16) & 0xFF
276
- arr[L++] = (tmp >> 8) & 0xFF
277
- arr[L++] = tmp & 0xFF
300
+ if (placeHoldersLen === 2) {
301
+ tmp =
302
+ (revLookup[b64.charCodeAt(i)] << 2) |
303
+ (revLookup[b64.charCodeAt(i + 1)] >> 4)
304
+ arr[curByte++] = tmp & 0xFF
278
305
  }
279
306
 
280
- if (placeHolders === 2) {
281
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
282
- arr[L++] = tmp & 0xFF
283
- } else if (placeHolders === 1) {
284
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
285
- arr[L++] = (tmp >> 8) & 0xFF
286
- arr[L++] = tmp & 0xFF
307
+ if (placeHoldersLen === 1) {
308
+ tmp =
309
+ (revLookup[b64.charCodeAt(i)] << 10) |
310
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
311
+ (revLookup[b64.charCodeAt(i + 2)] >> 2)
312
+ arr[curByte++] = (tmp >> 8) & 0xFF
313
+ arr[curByte++] = tmp & 0xFF
287
314
  }
288
315
 
289
316
  return arr
290
317
  }
291
318
 
292
319
  function tripletToBase64 (num) {
293
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
320
+ return lookup[num >> 18 & 0x3F] +
321
+ lookup[num >> 12 & 0x3F] +
322
+ lookup[num >> 6 & 0x3F] +
323
+ lookup[num & 0x3F]
294
324
  }
295
325
 
296
326
  function encodeChunk (uint8, start, end) {
297
327
  var tmp
298
328
  var output = []
299
329
  for (var i = start; i < end; i += 3) {
300
- tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF)
330
+ tmp =
331
+ ((uint8[i] << 16) & 0xFF0000) +
332
+ ((uint8[i + 1] << 8) & 0xFF00) +
333
+ (uint8[i + 2] & 0xFF)
301
334
  output.push(tripletToBase64(tmp))
302
335
  }
303
336
  return output.join('')
@@ -307,7 +340,6 @@ function fromByteArray (uint8) {
307
340
  var tmp
308
341
  var len = uint8.length
309
342
  var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
310
- var output = ''
311
343
  var parts = []
312
344
  var maxChunkLength = 16383 // must be multiple of 3
313
345
 
@@ -319,23 +351,26 @@ function fromByteArray (uint8) {
319
351
  // pad the end with zeros, but make sure to not forget the extra bytes
320
352
  if (extraBytes === 1) {
321
353
  tmp = uint8[len - 1]
322
- output += lookup[tmp >> 2]
323
- output += lookup[(tmp << 4) & 0x3F]
324
- output += '=='
354
+ parts.push(
355
+ lookup[tmp >> 2] +
356
+ lookup[(tmp << 4) & 0x3F] +
357
+ '=='
358
+ )
325
359
  } else if (extraBytes === 2) {
326
- tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
327
- output += lookup[tmp >> 10]
328
- output += lookup[(tmp >> 4) & 0x3F]
329
- output += lookup[(tmp << 2) & 0x3F]
330
- output += '='
360
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1]
361
+ parts.push(
362
+ lookup[tmp >> 10] +
363
+ lookup[(tmp >> 4) & 0x3F] +
364
+ lookup[(tmp << 2) & 0x3F] +
365
+ '='
366
+ )
331
367
  }
332
368
 
333
- parts.push(output)
334
-
335
369
  return parts.join('')
336
370
  }
337
371
 
338
372
  },{}],3:[function(require,module,exports){
373
+ (function (Buffer){(function (){
339
374
  /*!
340
375
  * The buffer module from node.js, for the browser.
341
376
  *
@@ -384,7 +419,7 @@ function typedArraySupport () {
384
419
  // Can typed array instances can be augmented?
385
420
  try {
386
421
  var arr = new Uint8Array(1)
387
- arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
422
+ arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
388
423
  return arr.foo() === 42
389
424
  } catch (e) {
390
425
  return false
@@ -392,26 +427,24 @@ function typedArraySupport () {
392
427
  }
393
428
 
394
429
  Object.defineProperty(Buffer.prototype, 'parent', {
430
+ enumerable: true,
395
431
  get: function () {
396
- if (!(this instanceof Buffer)) {
397
- return undefined
398
- }
432
+ if (!Buffer.isBuffer(this)) return undefined
399
433
  return this.buffer
400
434
  }
401
435
  })
402
436
 
403
437
  Object.defineProperty(Buffer.prototype, 'offset', {
438
+ enumerable: true,
404
439
  get: function () {
405
- if (!(this instanceof Buffer)) {
406
- return undefined
407
- }
440
+ if (!Buffer.isBuffer(this)) return undefined
408
441
  return this.byteOffset
409
442
  }
410
443
  })
411
444
 
412
445
  function createBuffer (length) {
413
446
  if (length > K_MAX_LENGTH) {
414
- throw new RangeError('Invalid typed array length')
447
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
415
448
  }
416
449
  // Return an augmented `Uint8Array` instance
417
450
  var buf = new Uint8Array(length)
@@ -433,8 +466,8 @@ function Buffer (arg, encodingOrOffset, length) {
433
466
  // Common case.
434
467
  if (typeof arg === 'number') {
435
468
  if (typeof encodingOrOffset === 'string') {
436
- throw new Error(
437
- 'If encoding is specified then the first argument must be a string'
469
+ throw new TypeError(
470
+ 'The "string" argument must be of type string. Received type number'
438
471
  )
439
472
  }
440
473
  return allocUnsafe(arg)
@@ -443,7 +476,7 @@ function Buffer (arg, encodingOrOffset, length) {
443
476
  }
444
477
 
445
478
  // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
446
- if (typeof Symbol !== 'undefined' && Symbol.species &&
479
+ if (typeof Symbol !== 'undefined' && Symbol.species != null &&
447
480
  Buffer[Symbol.species] === Buffer) {
448
481
  Object.defineProperty(Buffer, Symbol.species, {
449
482
  value: null,
@@ -456,19 +489,51 @@ if (typeof Symbol !== 'undefined' && Symbol.species &&
456
489
  Buffer.poolSize = 8192 // not used by this implementation
457
490
 
458
491
  function from (value, encodingOrOffset, length) {
459
- if (typeof value === 'number') {
460
- throw new TypeError('"value" argument must not be a number')
492
+ if (typeof value === 'string') {
493
+ return fromString(value, encodingOrOffset)
494
+ }
495
+
496
+ if (ArrayBuffer.isView(value)) {
497
+ return fromArrayLike(value)
461
498
  }
462
499
 
463
- if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
500
+ if (value == null) {
501
+ throw TypeError(
502
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
503
+ 'or Array-like Object. Received type ' + (typeof value)
504
+ )
505
+ }
506
+
507
+ if (isInstance(value, ArrayBuffer) ||
508
+ (value && isInstance(value.buffer, ArrayBuffer))) {
464
509
  return fromArrayBuffer(value, encodingOrOffset, length)
465
510
  }
466
511
 
467
- if (typeof value === 'string') {
468
- return fromString(value, encodingOrOffset)
512
+ if (typeof value === 'number') {
513
+ throw new TypeError(
514
+ 'The "value" argument must not be of type number. Received type number'
515
+ )
516
+ }
517
+
518
+ var valueOf = value.valueOf && value.valueOf()
519
+ if (valueOf != null && valueOf !== value) {
520
+ return Buffer.from(valueOf, encodingOrOffset, length)
521
+ }
522
+
523
+ var b = fromObject(value)
524
+ if (b) return b
525
+
526
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
527
+ typeof value[Symbol.toPrimitive] === 'function') {
528
+ return Buffer.from(
529
+ value[Symbol.toPrimitive]('string'), encodingOrOffset, length
530
+ )
469
531
  }
470
532
 
471
- return fromObject(value)
533
+ throw new TypeError(
534
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
535
+ 'or Array-like Object. Received type ' + (typeof value)
536
+ )
472
537
  }
473
538
 
474
539
  /**
@@ -492,7 +557,7 @@ function assertSize (size) {
492
557
  if (typeof size !== 'number') {
493
558
  throw new TypeError('"size" argument must be of type number')
494
559
  } else if (size < 0) {
495
- throw new RangeError('"size" argument must not be negative')
560
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
496
561
  }
497
562
  }
498
563
 
@@ -607,20 +672,16 @@ function fromObject (obj) {
607
672
  return buf
608
673
  }
609
674
 
610
- if (obj) {
611
- if (ArrayBuffer.isView(obj) || 'length' in obj) {
612
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
613
- return createBuffer(0)
614
- }
615
- return fromArrayLike(obj)
616
- }
617
-
618
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
619
- return fromArrayLike(obj.data)
675
+ if (obj.length !== undefined) {
676
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
677
+ return createBuffer(0)
620
678
  }
679
+ return fromArrayLike(obj)
621
680
  }
622
681
 
623
- throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
682
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
683
+ return fromArrayLike(obj.data)
684
+ }
624
685
  }
625
686
 
626
687
  function checked (length) {
@@ -641,12 +702,17 @@ function SlowBuffer (length) {
641
702
  }
642
703
 
643
704
  Buffer.isBuffer = function isBuffer (b) {
644
- return b != null && b._isBuffer === true
705
+ return b != null && b._isBuffer === true &&
706
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
645
707
  }
646
708
 
647
709
  Buffer.compare = function compare (a, b) {
710
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
711
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
648
712
  if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
649
- throw new TypeError('Arguments must be Buffers')
713
+ throw new TypeError(
714
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
715
+ )
650
716
  }
651
717
 
652
718
  if (a === b) return 0
@@ -707,7 +773,7 @@ Buffer.concat = function concat (list, length) {
707
773
  var pos = 0
708
774
  for (i = 0; i < list.length; ++i) {
709
775
  var buf = list[i]
710
- if (ArrayBuffer.isView(buf)) {
776
+ if (isInstance(buf, Uint8Array)) {
711
777
  buf = Buffer.from(buf)
712
778
  }
713
779
  if (!Buffer.isBuffer(buf)) {
@@ -723,15 +789,19 @@ function byteLength (string, encoding) {
723
789
  if (Buffer.isBuffer(string)) {
724
790
  return string.length
725
791
  }
726
- if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
792
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
727
793
  return string.byteLength
728
794
  }
729
795
  if (typeof string !== 'string') {
730
- string = '' + string
796
+ throw new TypeError(
797
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
798
+ 'Received type ' + typeof string
799
+ )
731
800
  }
732
801
 
733
802
  var len = string.length
734
- if (len === 0) return 0
803
+ var mustMatch = (arguments.length > 2 && arguments[2] === true)
804
+ if (!mustMatch && len === 0) return 0
735
805
 
736
806
  // Use a for loop to avoid recursion
737
807
  var loweredCase = false
@@ -743,7 +813,6 @@ function byteLength (string, encoding) {
743
813
  return len
744
814
  case 'utf8':
745
815
  case 'utf-8':
746
- case undefined:
747
816
  return utf8ToBytes(string).length
748
817
  case 'ucs2':
749
818
  case 'ucs-2':
@@ -755,7 +824,9 @@ function byteLength (string, encoding) {
755
824
  case 'base64':
756
825
  return base64ToBytes(string).length
757
826
  default:
758
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
827
+ if (loweredCase) {
828
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
829
+ }
759
830
  encoding = ('' + encoding).toLowerCase()
760
831
  loweredCase = true
761
832
  }
@@ -902,16 +973,20 @@ Buffer.prototype.equals = function equals (b) {
902
973
  Buffer.prototype.inspect = function inspect () {
903
974
  var str = ''
904
975
  var max = exports.INSPECT_MAX_BYTES
905
- if (this.length > 0) {
906
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
907
- if (this.length > max) str += ' ... '
908
- }
976
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
977
+ if (this.length > max) str += ' ... '
909
978
  return '<Buffer ' + str + '>'
910
979
  }
911
980
 
912
981
  Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
982
+ if (isInstance(target, Uint8Array)) {
983
+ target = Buffer.from(target, target.offset, target.byteLength)
984
+ }
913
985
  if (!Buffer.isBuffer(target)) {
914
- throw new TypeError('Argument must be a Buffer')
986
+ throw new TypeError(
987
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
988
+ 'Received type ' + (typeof target)
989
+ )
915
990
  }
916
991
 
917
992
  if (start === undefined) {
@@ -990,7 +1065,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
990
1065
  } else if (byteOffset < -0x80000000) {
991
1066
  byteOffset = -0x80000000
992
1067
  }
993
- byteOffset = +byteOffset // Coerce to Number.
1068
+ byteOffset = +byteOffset // Coerce to Number.
994
1069
  if (numberIsNaN(byteOffset)) {
995
1070
  // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
996
1071
  byteOffset = dir ? 0 : (buffer.length - 1)
@@ -1242,8 +1317,8 @@ function utf8Slice (buf, start, end) {
1242
1317
  var codePoint = null
1243
1318
  var bytesPerSequence = (firstByte > 0xEF) ? 4
1244
1319
  : (firstByte > 0xDF) ? 3
1245
- : (firstByte > 0xBF) ? 2
1246
- : 1
1320
+ : (firstByte > 0xBF) ? 2
1321
+ : 1
1247
1322
 
1248
1323
  if (i + bytesPerSequence <= end) {
1249
1324
  var secondByte, thirdByte, fourthByte, tempCodePoint
@@ -1906,7 +1981,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1906
1981
  } else {
1907
1982
  var bytes = Buffer.isBuffer(val)
1908
1983
  ? val
1909
- : new Buffer(val, encoding)
1984
+ : Buffer.from(val, encoding)
1910
1985
  var len = bytes.length
1911
1986
  if (len === 0) {
1912
1987
  throw new TypeError('The value "' + val +
@@ -2061,19 +2136,22 @@ function blitBuffer (src, dst, offset, length) {
2061
2136
  return i
2062
2137
  }
2063
2138
 
2064
- // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
2065
- // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
2066
- function isArrayBuffer (obj) {
2067
- return obj instanceof ArrayBuffer ||
2068
- (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
2069
- typeof obj.byteLength === 'number')
2139
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2140
+ // the `instanceof` check but they should be treated as of that type.
2141
+ // See: https://github.com/feross/buffer/issues/166
2142
+ function isInstance (obj, type) {
2143
+ return obj instanceof type ||
2144
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
2145
+ obj.constructor.name === type.name)
2070
2146
  }
2071
-
2072
2147
  function numberIsNaN (obj) {
2148
+ // For IE11 support
2073
2149
  return obj !== obj // eslint-disable-line no-self-compare
2074
2150
  }
2075
2151
 
2076
- },{"base64-js":2,"ieee754":4}],4:[function(require,module,exports){
2152
+ }).call(this)}).call(this,require("buffer").Buffer)
2153
+ },{"base64-js":2,"buffer":3,"ieee754":4}],4:[function(require,module,exports){
2154
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
2077
2155
  exports.read = function (buffer, offset, isLE, mLen, nBytes) {
2078
2156
  var e, m
2079
2157
  var eLen = (nBytes * 8) - mLen - 1
@@ -2160,266 +2238,261 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
2160
2238
  }
2161
2239
 
2162
2240
  },{}],5:[function(require,module,exports){
2163
- function DOMParser(options){
2164
- this.options = options ||{locator:{}};
2165
-
2166
- }
2167
- DOMParser.prototype.parseFromString = function(source,mimeType){
2168
- var options = this.options;
2169
- var sax = new XMLReader();
2170
- var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
2171
- var errorHandler = options.errorHandler;
2172
- var locator = options.locator;
2173
- var defaultNSMap = options.xmlns||{};
2174
- var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
2175
- if(locator){
2176
- domBuilder.setDocumentLocator(locator)
2177
- }
2178
-
2179
- sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
2180
- sax.domBuilder = options.domBuilder || domBuilder;
2181
- if(/\/x?html?$/.test(mimeType)){
2182
- entityMap.nbsp = '\xa0';
2183
- entityMap.copy = '\xa9';
2184
- defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
2185
- }
2186
- defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
2187
- if(source){
2188
- sax.parse(source,defaultNSMap,entityMap);
2189
- }else{
2190
- sax.errorHandler.error("invalid doc source");
2191
- }
2192
- return domBuilder.doc;
2193
- }
2194
- function buildErrorHandler(errorImpl,domBuilder,locator){
2195
- if(!errorImpl){
2196
- if(domBuilder instanceof DOMHandler){
2197
- return domBuilder;
2198
- }
2199
- errorImpl = domBuilder ;
2200
- }
2201
- var errorHandler = {}
2202
- var isCallback = errorImpl instanceof Function;
2203
- locator = locator||{}
2204
- function build(key){
2205
- var fn = errorImpl[key];
2206
- if(!fn && isCallback){
2207
- fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
2208
- }
2209
- errorHandler[key] = fn && function(msg){
2210
- fn('[xmldom '+key+']\t'+msg+_locator(locator));
2211
- }||function(){};
2212
- }
2213
- build('warning');
2214
- build('error');
2215
- build('fatalError');
2216
- return errorHandler;
2217
- }
2218
-
2219
- //console.log('#\n\n\n\n\n\n\n####')
2220
- /**
2221
- * +ContentHandler+ErrorHandler
2222
- * +LexicalHandler+EntityResolver2
2223
- * -DeclHandler-DTDHandler
2224
- *
2225
- * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
2226
- * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
2227
- * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
2228
- */
2229
- function DOMHandler() {
2230
- this.cdata = false;
2231
- }
2232
- function position(locator,node){
2233
- node.lineNumber = locator.lineNumber;
2234
- node.columnNumber = locator.columnNumber;
2235
- }
2236
- /**
2237
- * @see org.xml.sax.ContentHandler#startDocument
2238
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
2239
- */
2240
- DOMHandler.prototype = {
2241
- startDocument : function() {
2242
- this.doc = new DOMImplementation().createDocument(null, null, null);
2243
- if (this.locator) {
2244
- this.doc.documentURI = this.locator.systemId;
2245
- }
2246
- },
2247
- startElement:function(namespaceURI, localName, qName, attrs) {
2248
- var doc = this.doc;
2249
- var el = doc.createElementNS(namespaceURI, qName||localName);
2250
- var len = attrs.length;
2251
- appendElement(this, el);
2252
- this.currentElement = el;
2253
-
2254
- this.locator && position(this.locator,el)
2255
- for (var i = 0 ; i < len; i++) {
2256
- var namespaceURI = attrs.getURI(i);
2257
- var value = attrs.getValue(i);
2258
- var qName = attrs.getQName(i);
2259
- var attr = doc.createAttributeNS(namespaceURI, qName);
2260
- this.locator &&position(attrs.getLocator(i),attr);
2261
- attr.value = attr.nodeValue = value;
2262
- el.setAttributeNode(attr)
2263
- }
2264
- },
2265
- endElement:function(namespaceURI, localName, qName) {
2266
- var current = this.currentElement
2267
- var tagName = current.tagName;
2268
- this.currentElement = current.parentNode;
2269
- },
2270
- startPrefixMapping:function(prefix, uri) {
2271
- },
2272
- endPrefixMapping:function(prefix) {
2273
- },
2274
- processingInstruction:function(target, data) {
2275
- var ins = this.doc.createProcessingInstruction(target, data);
2276
- this.locator && position(this.locator,ins)
2277
- appendElement(this, ins);
2278
- },
2279
- ignorableWhitespace:function(ch, start, length) {
2280
- },
2281
- characters:function(chars, start, length) {
2282
- chars = _toString.apply(this,arguments)
2283
- //console.log(chars)
2284
- if(chars){
2285
- if (this.cdata) {
2286
- var charNode = this.doc.createCDATASection(chars);
2287
- } else {
2288
- var charNode = this.doc.createTextNode(chars);
2289
- }
2290
- if(this.currentElement){
2291
- this.currentElement.appendChild(charNode);
2292
- }else if(/^\s*$/.test(chars)){
2293
- this.doc.appendChild(charNode);
2294
- //process xml
2295
- }
2296
- this.locator && position(this.locator,charNode)
2297
- }
2298
- },
2299
- skippedEntity:function(name) {
2300
- },
2301
- endDocument:function() {
2302
- this.doc.normalize();
2303
- },
2304
- setDocumentLocator:function (locator) {
2305
- if(this.locator = locator){// && !('lineNumber' in locator)){
2306
- locator.lineNumber = 0;
2307
- }
2308
- },
2309
- //LexicalHandler
2310
- comment:function(chars, start, length) {
2311
- chars = _toString.apply(this,arguments)
2312
- var comm = this.doc.createComment(chars);
2313
- this.locator && position(this.locator,comm)
2314
- appendElement(this, comm);
2315
- },
2316
-
2317
- startCDATA:function() {
2318
- //used in characters() methods
2319
- this.cdata = true;
2320
- },
2321
- endCDATA:function() {
2322
- this.cdata = false;
2323
- },
2324
-
2325
- startDTD:function(name, publicId, systemId) {
2326
- var impl = this.doc.implementation;
2327
- if (impl && impl.createDocumentType) {
2328
- var dt = impl.createDocumentType(name, publicId, systemId);
2329
- this.locator && position(this.locator,dt)
2330
- appendElement(this, dt);
2331
- }
2332
- },
2333
- /**
2334
- * @see org.xml.sax.ErrorHandler
2335
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
2336
- */
2337
- warning:function(error) {
2338
- console.warn('[xmldom warning]\t'+error,_locator(this.locator));
2339
- },
2340
- error:function(error) {
2341
- console.error('[xmldom error]\t'+error,_locator(this.locator));
2342
- },
2343
- fatalError:function(error) {
2344
- console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
2345
- throw error;
2346
- }
2347
- }
2348
- function _locator(l){
2349
- if(l){
2350
- return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
2351
- }
2352
- }
2353
- function _toString(chars,start,length){
2354
- if(typeof chars == 'string'){
2355
- return chars.substr(start,length)
2356
- }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
2357
- if(chars.length >= start+length || start){
2358
- return new java.lang.String(chars,start,length)+'';
2359
- }
2360
- return chars;
2361
- }
2362
- }
2363
-
2364
- /*
2365
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
2366
- * used method of org.xml.sax.ext.LexicalHandler:
2367
- * #comment(chars, start, length)
2368
- * #startCDATA()
2369
- * #endCDATA()
2370
- * #startDTD(name, publicId, systemId)
2371
- *
2372
- *
2373
- * IGNORED method of org.xml.sax.ext.LexicalHandler:
2374
- * #endDTD()
2375
- * #startEntity(name)
2376
- * #endEntity(name)
2377
- *
2378
- *
2379
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
2380
- * IGNORED method of org.xml.sax.ext.DeclHandler
2381
- * #attributeDecl(eName, aName, type, mode, value)
2382
- * #elementDecl(name, model)
2383
- * #externalEntityDecl(name, publicId, systemId)
2384
- * #internalEntityDecl(name, value)
2385
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
2386
- * IGNORED method of org.xml.sax.EntityResolver2
2387
- * #resolveEntity(String name,String publicId,String baseURI,String systemId)
2388
- * #resolveEntity(publicId, systemId)
2389
- * #getExternalSubset(name, baseURI)
2390
- * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
2391
- * IGNORED method of org.xml.sax.DTDHandler
2392
- * #notationDecl(name, publicId, systemId) {};
2393
- * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
2394
- */
2395
- "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
2396
- DOMHandler.prototype[key] = function(){return null}
2397
- })
2398
-
2399
- /* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
2400
- function appendElement (hander,node) {
2401
- if (!hander.currentElement) {
2402
- hander.doc.appendChild(node);
2403
- } else {
2404
- hander.currentElement.appendChild(node);
2405
- }
2406
- }//appendChild and setAttributeNS are preformance key
2407
-
2408
- //if(typeof require == 'function'){
2409
- var XMLReader = require('./sax').XMLReader;
2410
- var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
2411
- exports.XMLSerializer = require('./dom').XMLSerializer ;
2412
- exports.DOMParser = DOMParser;
2413
- //}
2414
-
2415
- },{"./dom":6,"./sax":7}],6:[function(require,module,exports){
2241
+ function DOMParser(options){
2242
+ this.options = options ||{locator:{}};
2243
+ }
2244
+
2245
+ DOMParser.prototype.parseFromString = function(source,mimeType){
2246
+ var options = this.options;
2247
+ var sax = new XMLReader();
2248
+ var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
2249
+ var errorHandler = options.errorHandler;
2250
+ var locator = options.locator;
2251
+ var defaultNSMap = options.xmlns||{};
2252
+ var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
2253
+ var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
2254
+ if(locator){
2255
+ domBuilder.setDocumentLocator(locator)
2256
+ }
2257
+
2258
+ sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
2259
+ sax.domBuilder = options.domBuilder || domBuilder;
2260
+ if(isHTML){
2261
+ defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
2262
+ }
2263
+ defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
2264
+ if(source && typeof source === 'string'){
2265
+ sax.parse(source,defaultNSMap,entityMap);
2266
+ }else{
2267
+ sax.errorHandler.error("invalid doc source");
2268
+ }
2269
+ return domBuilder.doc;
2270
+ }
2271
+ function buildErrorHandler(errorImpl,domBuilder,locator){
2272
+ if(!errorImpl){
2273
+ if(domBuilder instanceof DOMHandler){
2274
+ return domBuilder;
2275
+ }
2276
+ errorImpl = domBuilder ;
2277
+ }
2278
+ var errorHandler = {}
2279
+ var isCallback = errorImpl instanceof Function;
2280
+ locator = locator||{}
2281
+ function build(key){
2282
+ var fn = errorImpl[key];
2283
+ if(!fn && isCallback){
2284
+ fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
2285
+ }
2286
+ errorHandler[key] = fn && function(msg){
2287
+ fn('[xmldom '+key+']\t'+msg+_locator(locator));
2288
+ }||function(){};
2289
+ }
2290
+ build('warning');
2291
+ build('error');
2292
+ build('fatalError');
2293
+ return errorHandler;
2294
+ }
2295
+
2296
+ //console.log('#\n\n\n\n\n\n\n####')
2297
+ /**
2298
+ * +ContentHandler+ErrorHandler
2299
+ * +LexicalHandler+EntityResolver2
2300
+ * -DeclHandler-DTDHandler
2301
+ *
2302
+ * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
2303
+ * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
2304
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
2305
+ */
2306
+ function DOMHandler() {
2307
+ this.cdata = false;
2308
+ }
2309
+ function position(locator,node){
2310
+ node.lineNumber = locator.lineNumber;
2311
+ node.columnNumber = locator.columnNumber;
2312
+ }
2313
+ /**
2314
+ * @see org.xml.sax.ContentHandler#startDocument
2315
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
2316
+ */
2317
+ DOMHandler.prototype = {
2318
+ startDocument : function() {
2319
+ this.doc = new DOMImplementation().createDocument(null, null, null);
2320
+ if (this.locator) {
2321
+ this.doc.documentURI = this.locator.systemId;
2322
+ }
2323
+ },
2324
+ startElement:function(namespaceURI, localName, qName, attrs) {
2325
+ var doc = this.doc;
2326
+ var el = doc.createElementNS(namespaceURI, qName||localName);
2327
+ var len = attrs.length;
2328
+ appendElement(this, el);
2329
+ this.currentElement = el;
2330
+
2331
+ this.locator && position(this.locator,el)
2332
+ for (var i = 0 ; i < len; i++) {
2333
+ var namespaceURI = attrs.getURI(i);
2334
+ var value = attrs.getValue(i);
2335
+ var qName = attrs.getQName(i);
2336
+ var attr = doc.createAttributeNS(namespaceURI, qName);
2337
+ this.locator &&position(attrs.getLocator(i),attr);
2338
+ attr.value = attr.nodeValue = value;
2339
+ el.setAttributeNode(attr)
2340
+ }
2341
+ },
2342
+ endElement:function(namespaceURI, localName, qName) {
2343
+ var current = this.currentElement
2344
+ var tagName = current.tagName;
2345
+ this.currentElement = current.parentNode;
2346
+ },
2347
+ startPrefixMapping:function(prefix, uri) {
2348
+ },
2349
+ endPrefixMapping:function(prefix) {
2350
+ },
2351
+ processingInstruction:function(target, data) {
2352
+ var ins = this.doc.createProcessingInstruction(target, data);
2353
+ this.locator && position(this.locator,ins)
2354
+ appendElement(this, ins);
2355
+ },
2356
+ ignorableWhitespace:function(ch, start, length) {
2357
+ },
2358
+ characters:function(chars, start, length) {
2359
+ chars = _toString.apply(this,arguments)
2360
+ //console.log(chars)
2361
+ if(chars){
2362
+ if (this.cdata) {
2363
+ var charNode = this.doc.createCDATASection(chars);
2364
+ } else {
2365
+ var charNode = this.doc.createTextNode(chars);
2366
+ }
2367
+ if(this.currentElement){
2368
+ this.currentElement.appendChild(charNode);
2369
+ }else if(/^\s*$/.test(chars)){
2370
+ this.doc.appendChild(charNode);
2371
+ //process xml
2372
+ }
2373
+ this.locator && position(this.locator,charNode)
2374
+ }
2375
+ },
2376
+ skippedEntity:function(name) {
2377
+ },
2378
+ endDocument:function() {
2379
+ this.doc.normalize();
2380
+ },
2381
+ setDocumentLocator:function (locator) {
2382
+ if(this.locator = locator){// && !('lineNumber' in locator)){
2383
+ locator.lineNumber = 0;
2384
+ }
2385
+ },
2386
+ //LexicalHandler
2387
+ comment:function(chars, start, length) {
2388
+ chars = _toString.apply(this,arguments)
2389
+ var comm = this.doc.createComment(chars);
2390
+ this.locator && position(this.locator,comm)
2391
+ appendElement(this, comm);
2392
+ },
2393
+
2394
+ startCDATA:function() {
2395
+ //used in characters() methods
2396
+ this.cdata = true;
2397
+ },
2398
+ endCDATA:function() {
2399
+ this.cdata = false;
2400
+ },
2401
+
2402
+ startDTD:function(name, publicId, systemId) {
2403
+ var impl = this.doc.implementation;
2404
+ if (impl && impl.createDocumentType) {
2405
+ var dt = impl.createDocumentType(name, publicId, systemId);
2406
+ this.locator && position(this.locator,dt)
2407
+ appendElement(this, dt);
2408
+ }
2409
+ },
2410
+ /**
2411
+ * @see org.xml.sax.ErrorHandler
2412
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
2413
+ */
2414
+ warning:function(error) {
2415
+ console.warn('[xmldom warning]\t'+error,_locator(this.locator));
2416
+ },
2417
+ error:function(error) {
2418
+ console.error('[xmldom error]\t'+error,_locator(this.locator));
2419
+ },
2420
+ fatalError:function(error) {
2421
+ throw new ParseError(error, this.locator);
2422
+ }
2423
+ }
2424
+ function _locator(l){
2425
+ if(l){
2426
+ return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
2427
+ }
2428
+ }
2429
+ function _toString(chars,start,length){
2430
+ if(typeof chars == 'string'){
2431
+ return chars.substr(start,length)
2432
+ }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
2433
+ if(chars.length >= start+length || start){
2434
+ return new java.lang.String(chars,start,length)+'';
2435
+ }
2436
+ return chars;
2437
+ }
2438
+ }
2439
+
2416
2440
  /*
2417
- * DOM Level 2
2418
- * Object DOMException
2419
- * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
2420
- * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
2441
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
2442
+ * used method of org.xml.sax.ext.LexicalHandler:
2443
+ * #comment(chars, start, length)
2444
+ * #startCDATA()
2445
+ * #endCDATA()
2446
+ * #startDTD(name, publicId, systemId)
2447
+ *
2448
+ *
2449
+ * IGNORED method of org.xml.sax.ext.LexicalHandler:
2450
+ * #endDTD()
2451
+ * #startEntity(name)
2452
+ * #endEntity(name)
2453
+ *
2454
+ *
2455
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
2456
+ * IGNORED method of org.xml.sax.ext.DeclHandler
2457
+ * #attributeDecl(eName, aName, type, mode, value)
2458
+ * #elementDecl(name, model)
2459
+ * #externalEntityDecl(name, publicId, systemId)
2460
+ * #internalEntityDecl(name, value)
2461
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
2462
+ * IGNORED method of org.xml.sax.EntityResolver2
2463
+ * #resolveEntity(String name,String publicId,String baseURI,String systemId)
2464
+ * #resolveEntity(publicId, systemId)
2465
+ * #getExternalSubset(name, baseURI)
2466
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
2467
+ * IGNORED method of org.xml.sax.DTDHandler
2468
+ * #notationDecl(name, publicId, systemId) {};
2469
+ * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
2421
2470
  */
2471
+ "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
2472
+ DOMHandler.prototype[key] = function(){return null}
2473
+ })
2422
2474
 
2475
+ /* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
2476
+ function appendElement (hander,node) {
2477
+ if (!hander.currentElement) {
2478
+ hander.doc.appendChild(node);
2479
+ } else {
2480
+ hander.currentElement.appendChild(node);
2481
+ }
2482
+ }//appendChild and setAttributeNS are preformance key
2483
+
2484
+ //if(typeof require == 'function'){
2485
+ var htmlEntity = require('./entities');
2486
+ var sax = require('./sax');
2487
+ var XMLReader = sax.XMLReader;
2488
+ var ParseError = sax.ParseError;
2489
+ var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
2490
+ exports.XMLSerializer = require('./dom').XMLSerializer ;
2491
+ exports.DOMParser = DOMParser;
2492
+ exports.__DOMHandler = DOMHandler;
2493
+ //}
2494
+
2495
+ },{"./dom":6,"./entities":7,"./sax":8}],6:[function(require,module,exports){
2423
2496
  function copy(src,dest){
2424
2497
  for(var p in src){
2425
2498
  dest[p] = src[p];
@@ -2431,10 +2504,6 @@ function copy(src,dest){
2431
2504
  */
2432
2505
  function _extends(Class,Super){
2433
2506
  var pt = Class.prototype;
2434
- if(Object.create){
2435
- var ppt = Object.create(Super.prototype)
2436
- pt.__proto__ = ppt;
2437
- }
2438
2507
  if(!(pt instanceof Super)){
2439
2508
  function t(){};
2440
2509
  t.prototype = Super.prototype;
@@ -2485,7 +2554,12 @@ var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((Exce
2485
2554
  var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
2486
2555
  var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
2487
2556
 
2488
-
2557
+ /**
2558
+ * DOM Level 2
2559
+ * Object DOMException
2560
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
2561
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
2562
+ */
2489
2563
  function DOMException(code, message) {
2490
2564
  if(message instanceof Error){
2491
2565
  var error = message;
@@ -3027,6 +3101,21 @@ Document.prototype = {
3027
3101
  return rtv;
3028
3102
  },
3029
3103
 
3104
+ getElementsByClassName: function(className) {
3105
+ var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
3106
+ return new LiveNodeList(this, function(base) {
3107
+ var ls = [];
3108
+ _visitNode(base.documentElement, function(node) {
3109
+ if(node !== base && node.nodeType == ELEMENT_NODE) {
3110
+ if(pattern.test(node.getAttribute('class'))) {
3111
+ ls.push(node);
3112
+ }
3113
+ }
3114
+ });
3115
+ return ls;
3116
+ });
3117
+ },
3118
+
3030
3119
  //document factory method:
3031
3120
  createElement : function(tagName){
3032
3121
  var node = new Element();
@@ -3331,7 +3420,7 @@ XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
3331
3420
  Node.prototype.toString = nodeSerializeToString;
3332
3421
  function nodeSerializeToString(isHtml,nodeFilter){
3333
3422
  var buf = [];
3334
- var refNode = this.nodeType == 9?this.documentElement:this;
3423
+ var refNode = this.nodeType == 9 && this.documentElement || this;
3335
3424
  var prefix = refNode.prefix;
3336
3425
  var uri = refNode.namespaceURI;
3337
3426
 
@@ -3470,9 +3559,27 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
3470
3559
  }
3471
3560
  return;
3472
3561
  case ATTRIBUTE_NODE:
3473
- return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
3562
+ return buf.push(' ',node.name,'="',node.value.replace(/[&"]/g,_xmlEncoder),'"');
3474
3563
  case TEXT_NODE:
3475
- return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
3564
+ /**
3565
+ * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
3566
+ * except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section.
3567
+ * If they are needed elsewhere, they must be escaped using either numeric character references or the strings
3568
+ * `&amp;` and `&lt;` respectively.
3569
+ * The right angle bracket (>) may be represented using the string " &gt; ", and must, for compatibility,
3570
+ * be escaped using either `&gt;` or a character reference when it appears in the string `]]>` in content,
3571
+ * when that string is not marking the end of a CDATA section.
3572
+ *
3573
+ * In the content of elements, character data is any string of characters
3574
+ * which does not contain the start-delimiter of any markup
3575
+ * and does not include the CDATA-section-close delimiter, `]]>`.
3576
+ *
3577
+ * @see https://www.w3.org/TR/xml/#NT-CharData
3578
+ */
3579
+ return buf.push(node.data
3580
+ .replace(/[<&]/g,_xmlEncoder)
3581
+ .replace(/]]>/g, ']]&gt;')
3582
+ );
3476
3583
  case CDATA_SECTION_NODE:
3477
3584
  return buf.push( '<![CDATA[',node.data,']]>');
3478
3585
  case COMMENT_NODE:
@@ -3482,13 +3589,13 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
3482
3589
  var sysid = node.systemId;
3483
3590
  buf.push('<!DOCTYPE ',node.name);
3484
3591
  if(pubid){
3485
- buf.push(' PUBLIC "',pubid);
3592
+ buf.push(' PUBLIC ', pubid);
3486
3593
  if (sysid && sysid!='.') {
3487
- buf.push( '" "',sysid);
3594
+ buf.push(' ', sysid);
3488
3595
  }
3489
- buf.push('">');
3596
+ buf.push('>');
3490
3597
  }else if(sysid && sysid!='.'){
3491
- buf.push(' SYSTEM "',sysid,'">');
3598
+ buf.push(' SYSTEM ', sysid, '>');
3492
3599
  }else{
3493
3600
  var sub = node.internalSubset;
3494
3601
  if(sub){
@@ -3654,644 +3761,904 @@ try{
3654
3761
  }
3655
3762
 
3656
3763
  //if(typeof require == 'function'){
3764
+ exports.Node = Node;
3765
+ exports.DOMException = DOMException;
3657
3766
  exports.DOMImplementation = DOMImplementation;
3658
3767
  exports.XMLSerializer = XMLSerializer;
3659
3768
  //}
3660
3769
 
3661
3770
  },{}],7:[function(require,module,exports){
3662
- //[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
3663
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
3664
- //[5] Name ::= NameStartChar (NameChar)*
3665
- var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
3666
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
3667
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
3668
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
3669
- //var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
3670
-
3671
- //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
3672
- //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
3673
- var S_TAG = 0;//tag name offerring
3674
- var S_ATTR = 1;//attr name offerring
3675
- var S_ATTR_SPACE=2;//attr name end and space offer
3676
- var S_EQ = 3;//=space?
3677
- var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
3678
- var S_ATTR_END = 5;//attr value end and no space(quot end)
3679
- var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
3680
- var S_TAG_CLOSE = 7;//closed el<el />
3681
-
3682
- function XMLReader(){
3683
-
3684
- }
3685
-
3686
- XMLReader.prototype = {
3687
- parse:function(source,defaultNSMap,entityMap){
3688
- var domBuilder = this.domBuilder;
3689
- domBuilder.startDocument();
3690
- _copy(defaultNSMap ,defaultNSMap = {})
3691
- parse(source,defaultNSMap,entityMap,
3692
- domBuilder,this.errorHandler);
3693
- domBuilder.endDocument();
3694
- }
3695
- }
3696
- function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
3697
- function fixedFromCharCode(code) {
3698
- // String.prototype.fromCharCode does not supports
3699
- // > 2 bytes unicode chars directly
3700
- if (code > 0xffff) {
3701
- code -= 0x10000;
3702
- var surrogate1 = 0xd800 + (code >> 10)
3703
- , surrogate2 = 0xdc00 + (code & 0x3ff);
3704
-
3705
- return String.fromCharCode(surrogate1, surrogate2);
3706
- } else {
3707
- return String.fromCharCode(code);
3708
- }
3709
- }
3710
- function entityReplacer(a){
3711
- var k = a.slice(1,-1);
3712
- if(k in entityMap){
3713
- return entityMap[k];
3714
- }else if(k.charAt(0) === '#'){
3715
- return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
3716
- }else{
3717
- errorHandler.error('entity not found:'+a);
3718
- return a;
3719
- }
3720
- }
3721
- function appendText(end){//has some bugs
3722
- if(end>start){
3723
- var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
3724
- locator&&position(start);
3725
- domBuilder.characters(xt,0,end-start);
3726
- start = end
3727
- }
3728
- }
3729
- function position(p,m){
3730
- while(p>=lineEnd && (m = linePattern.exec(source))){
3731
- lineStart = m.index;
3732
- lineEnd = lineStart + m[0].length;
3733
- locator.lineNumber++;
3734
- //console.log('line++:',locator,startPos,endPos)
3735
- }
3736
- locator.columnNumber = p-lineStart+1;
3737
- }
3738
- var lineStart = 0;
3739
- var lineEnd = 0;
3740
- var linePattern = /.*(?:\r\n?|\n)|.*$/g
3741
- var locator = domBuilder.locator;
3742
-
3743
- var parseStack = [{currentNSMap:defaultNSMapCopy}]
3744
- var closeMap = {};
3745
- var start = 0;
3746
- while(true){
3747
- try{
3748
- var tagStart = source.indexOf('<',start);
3749
- if(tagStart<0){
3750
- if(!source.substr(start).match(/^\s*$/)){
3751
- var doc = domBuilder.doc;
3752
- var text = doc.createTextNode(source.substr(start));
3753
- doc.appendChild(text);
3754
- domBuilder.currentElement = text;
3755
- }
3756
- return;
3757
- }
3758
- if(tagStart>start){
3759
- appendText(tagStart);
3760
- }
3761
- switch(source.charAt(tagStart+1)){
3762
- case '/':
3763
- var end = source.indexOf('>',tagStart+3);
3764
- var tagName = source.substring(tagStart+2,end);
3765
- var config = parseStack.pop();
3766
- if(end<0){
3767
-
3768
- tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
3769
- //console.error('#@@@@@@'+tagName)
3770
- errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
3771
- end = tagStart+1+tagName.length;
3772
- }else if(tagName.match(/\s</)){
3773
- tagName = tagName.replace(/[\s<].*/,'');
3774
- errorHandler.error("end tag name: "+tagName+' maybe not complete');
3775
- end = tagStart+1+tagName.length;
3776
- }
3777
- //console.error(parseStack.length,parseStack)
3778
- //console.error(config);
3779
- var localNSMap = config.localNSMap;
3780
- var endMatch = config.tagName == tagName;
3781
- var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
3782
- if(endIgnoreCaseMach){
3783
- domBuilder.endElement(config.uri,config.localName,tagName);
3784
- if(localNSMap){
3785
- for(var prefix in localNSMap){
3786
- domBuilder.endPrefixMapping(prefix) ;
3787
- }
3788
- }
3789
- if(!endMatch){
3790
- errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
3791
- }
3792
- }else{
3793
- parseStack.push(config)
3794
- }
3795
-
3796
- end++;
3797
- break;
3798
- // end elment
3799
- case '?':// <?...?>
3800
- locator&&position(tagStart);
3801
- end = parseInstruction(source,tagStart,domBuilder);
3802
- break;
3803
- case '!':// <!doctype,<![CDATA,<!--
3804
- locator&&position(tagStart);
3805
- end = parseDCC(source,tagStart,domBuilder,errorHandler);
3806
- break;
3807
- default:
3808
- locator&&position(tagStart);
3809
- var el = new ElementAttributes();
3810
- var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
3811
- //elStartEnd
3812
- var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
3813
- var len = el.length;
3814
-
3815
-
3816
- if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
3817
- el.closed = true;
3818
- if(!entityMap.nbsp){
3819
- errorHandler.warning('unclosed xml attribute');
3820
- }
3821
- }
3822
- if(locator && len){
3823
- var locator2 = copyLocator(locator,{});
3824
- //try{//attribute position fixed
3825
- for(var i = 0;i<len;i++){
3826
- var a = el[i];
3827
- position(a.offset);
3828
- a.locator = copyLocator(locator,{});
3829
- }
3830
- //}catch(e){console.error('@@@@@'+e)}
3831
- domBuilder.locator = locator2
3832
- if(appendElement(el,domBuilder,currentNSMap)){
3833
- parseStack.push(el)
3834
- }
3835
- domBuilder.locator = locator;
3836
- }else{
3837
- if(appendElement(el,domBuilder,currentNSMap)){
3838
- parseStack.push(el)
3839
- }
3840
- }
3841
-
3842
-
3843
-
3844
- if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
3845
- end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
3846
- }else{
3847
- end++;
3848
- }
3849
- }
3850
- }catch(e){
3851
- errorHandler.error('element parse error: '+e)
3852
- //errorHandler.error('element parse error: '+e);
3853
- end = -1;
3854
- //throw e;
3855
- }
3856
- if(end>start){
3857
- start = end;
3858
- }else{
3859
- //TODO: 这里有可能sax回退,有位置错误风险
3860
- appendText(Math.max(tagStart,start)+1);
3861
- }
3862
- }
3863
- }
3864
- function copyLocator(f,t){
3865
- t.lineNumber = f.lineNumber;
3866
- t.columnNumber = f.columnNumber;
3867
- return t;
3868
- }
3869
-
3870
- /**
3871
- * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
3872
- * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
3873
- */
3874
- function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
3875
- var attrName;
3876
- var value;
3877
- var p = ++start;
3878
- var s = S_TAG;//status
3879
- while(true){
3880
- var c = source.charAt(p);
3881
- switch(c){
3882
- case '=':
3883
- if(s === S_ATTR){//attrName
3884
- attrName = source.slice(start,p);
3885
- s = S_EQ;
3886
- }else if(s === S_ATTR_SPACE){
3887
- s = S_EQ;
3888
- }else{
3889
- //fatalError: equal must after attrName or space after attrName
3890
- throw new Error('attribute equal must after attrName');
3891
- }
3892
- break;
3893
- case '\'':
3894
- case '"':
3895
- if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
3896
- ){//equal
3897
- if(s === S_ATTR){
3898
- errorHandler.warning('attribute value must after "="')
3899
- attrName = source.slice(start,p)
3900
- }
3901
- start = p+1;
3902
- p = source.indexOf(c,start)
3903
- if(p>0){
3904
- value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
3905
- el.add(attrName,value,start-1);
3906
- s = S_ATTR_END;
3907
- }else{
3908
- //fatalError: no end quot match
3909
- throw new Error('attribute value no end \''+c+'\' match');
3910
- }
3911
- }else if(s == S_ATTR_NOQUOT_VALUE){
3912
- value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
3913
- //console.log(attrName,value,start,p)
3914
- el.add(attrName,value,start);
3915
- //console.dir(el)
3916
- errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
3917
- start = p+1;
3918
- s = S_ATTR_END
3919
- }else{
3920
- //fatalError: no equal before
3921
- throw new Error('attribute value must after "="');
3922
- }
3923
- break;
3924
- case '/':
3925
- switch(s){
3926
- case S_TAG:
3927
- el.setTagName(source.slice(start,p));
3928
- case S_ATTR_END:
3929
- case S_TAG_SPACE:
3930
- case S_TAG_CLOSE:
3931
- s =S_TAG_CLOSE;
3932
- el.closed = true;
3933
- case S_ATTR_NOQUOT_VALUE:
3934
- case S_ATTR:
3935
- case S_ATTR_SPACE:
3936
- break;
3937
- //case S_EQ:
3938
- default:
3939
- throw new Error("attribute invalid close char('/')")
3940
- }
3941
- break;
3942
- case ''://end document
3943
- //throw new Error('unexpected end of input')
3944
- errorHandler.error('unexpected end of input');
3945
- if(s == S_TAG){
3946
- el.setTagName(source.slice(start,p));
3947
- }
3948
- return p;
3949
- case '>':
3950
- switch(s){
3951
- case S_TAG:
3952
- el.setTagName(source.slice(start,p));
3953
- case S_ATTR_END:
3954
- case S_TAG_SPACE:
3955
- case S_TAG_CLOSE:
3956
- break;//normal
3957
- case S_ATTR_NOQUOT_VALUE://Compatible state
3958
- case S_ATTR:
3959
- value = source.slice(start,p);
3960
- if(value.slice(-1) === '/'){
3961
- el.closed = true;
3962
- value = value.slice(0,-1)
3963
- }
3964
- case S_ATTR_SPACE:
3965
- if(s === S_ATTR_SPACE){
3966
- value = attrName;
3967
- }
3968
- if(s == S_ATTR_NOQUOT_VALUE){
3969
- errorHandler.warning('attribute "'+value+'" missed quot(")!!');
3970
- el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
3971
- }else{
3972
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
3973
- errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
3974
- }
3975
- el.add(value,value,start)
3976
- }
3977
- break;
3978
- case S_EQ:
3979
- throw new Error('attribute value missed!!');
3980
- }
3981
- // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
3982
- return p;
3983
- /*xml space '\x20' | #x9 | #xD | #xA; */
3984
- case '\u0080':
3985
- c = ' ';
3986
- default:
3987
- if(c<= ' '){//space
3988
- switch(s){
3989
- case S_TAG:
3990
- el.setTagName(source.slice(start,p));//tagName
3991
- s = S_TAG_SPACE;
3992
- break;
3993
- case S_ATTR:
3994
- attrName = source.slice(start,p)
3995
- s = S_ATTR_SPACE;
3996
- break;
3997
- case S_ATTR_NOQUOT_VALUE:
3998
- var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
3999
- errorHandler.warning('attribute "'+value+'" missed quot(")!!');
4000
- el.add(attrName,value,start)
4001
- case S_ATTR_END:
4002
- s = S_TAG_SPACE;
4003
- break;
4004
- //case S_TAG_SPACE:
4005
- //case S_EQ:
4006
- //case S_ATTR_SPACE:
4007
- // void();break;
4008
- //case S_TAG_CLOSE:
4009
- //ignore warning
4010
- }
4011
- }else{//not space
4012
- //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
4013
- //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
4014
- switch(s){
4015
- //case S_TAG:void();break;
4016
- //case S_ATTR:void();break;
4017
- //case S_ATTR_NOQUOT_VALUE:void();break;
4018
- case S_ATTR_SPACE:
4019
- var tagName = el.tagName;
4020
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
4021
- errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
4022
- }
4023
- el.add(attrName,attrName,start);
4024
- start = p;
4025
- s = S_ATTR;
4026
- break;
4027
- case S_ATTR_END:
4028
- errorHandler.warning('attribute space is required"'+attrName+'"!!')
4029
- case S_TAG_SPACE:
4030
- s = S_ATTR;
4031
- start = p;
4032
- break;
4033
- case S_EQ:
4034
- s = S_ATTR_NOQUOT_VALUE;
4035
- start = p;
4036
- break;
4037
- case S_TAG_CLOSE:
4038
- throw new Error("elements closed character '/' and '>' must be connected to");
4039
- }
4040
- }
4041
- }//end outer switch
4042
- //console.log('p++',p)
4043
- p++;
4044
- }
4045
- }
4046
- /**
4047
- * @return true if has new namespace define
4048
- */
4049
- function appendElement(el,domBuilder,currentNSMap){
4050
- var tagName = el.tagName;
4051
- var localNSMap = null;
4052
- //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
4053
- var i = el.length;
4054
- while(i--){
4055
- var a = el[i];
4056
- var qName = a.qName;
4057
- var value = a.value;
4058
- var nsp = qName.indexOf(':');
4059
- if(nsp>0){
4060
- var prefix = a.prefix = qName.slice(0,nsp);
4061
- var localName = qName.slice(nsp+1);
4062
- var nsPrefix = prefix === 'xmlns' && localName
4063
- }else{
4064
- localName = qName;
4065
- prefix = null
4066
- nsPrefix = qName === 'xmlns' && ''
4067
- }
4068
- //can not set prefix,because prefix !== ''
4069
- a.localName = localName ;
4070
- //prefix == null for no ns prefix attribute
4071
- if(nsPrefix !== false){//hack!!
4072
- if(localNSMap == null){
4073
- localNSMap = {}
4074
- //console.log(currentNSMap,0)
4075
- _copy(currentNSMap,currentNSMap={})
4076
- //console.log(currentNSMap,1)
4077
- }
4078
- currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
4079
- a.uri = 'http://www.w3.org/2000/xmlns/'
4080
- domBuilder.startPrefixMapping(nsPrefix, value)
4081
- }
4082
- }
4083
- var i = el.length;
4084
- while(i--){
4085
- a = el[i];
4086
- var prefix = a.prefix;
4087
- if(prefix){//no prefix attribute has no namespace
4088
- if(prefix === 'xml'){
4089
- a.uri = 'http://www.w3.org/XML/1998/namespace';
4090
- }if(prefix !== 'xmlns'){
4091
- a.uri = currentNSMap[prefix || '']
4092
-
4093
- //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
4094
- }
4095
- }
4096
- }
4097
- var nsp = tagName.indexOf(':');
4098
- if(nsp>0){
4099
- prefix = el.prefix = tagName.slice(0,nsp);
4100
- localName = el.localName = tagName.slice(nsp+1);
4101
- }else{
4102
- prefix = null;//important!!
4103
- localName = el.localName = tagName;
4104
- }
4105
- //no prefix element has default namespace
4106
- var ns = el.uri = currentNSMap[prefix || ''];
4107
- domBuilder.startElement(ns,localName,tagName,el);
4108
- //endPrefixMapping and startPrefixMapping have not any help for dom builder
4109
- //localNSMap = null
4110
- if(el.closed){
4111
- domBuilder.endElement(ns,localName,tagName);
4112
- if(localNSMap){
4113
- for(prefix in localNSMap){
4114
- domBuilder.endPrefixMapping(prefix)
4115
- }
4116
- }
4117
- }else{
4118
- el.currentNSMap = currentNSMap;
4119
- el.localNSMap = localNSMap;
4120
- //parseStack.push(el);
4121
- return true;
4122
- }
4123
- }
4124
- function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
4125
- if(/^(?:script|textarea)$/i.test(tagName)){
4126
- var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
4127
- var text = source.substring(elStartEnd+1,elEndStart);
4128
- if(/[&<]/.test(text)){
4129
- if(/^script$/i.test(tagName)){
4130
- //if(!/\]\]>/.test(text)){
4131
- //lexHandler.startCDATA();
4132
- domBuilder.characters(text,0,text.length);
4133
- //lexHandler.endCDATA();
4134
- return elEndStart;
4135
- //}
4136
- }//}else{//text area
4137
- text = text.replace(/&#?\w+;/g,entityReplacer);
4138
- domBuilder.characters(text,0,text.length);
4139
- return elEndStart;
4140
- //}
4141
-
4142
- }
4143
- }
4144
- return elStartEnd+1;
4145
- }
4146
- function fixSelfClosed(source,elStartEnd,tagName,closeMap){
4147
- //if(tagName in closeMap){
4148
- var pos = closeMap[tagName];
4149
- if(pos == null){
4150
- //console.log(tagName)
4151
- pos = source.lastIndexOf('</'+tagName+'>')
4152
- if(pos<elStartEnd){//忘记闭合
4153
- pos = source.lastIndexOf('</'+tagName)
4154
- }
4155
- closeMap[tagName] =pos
4156
- }
4157
- return pos<elStartEnd;
4158
- //}
4159
- }
4160
- function _copy(source,target){
4161
- for(var n in source){target[n] = source[n]}
4162
- }
4163
- function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
4164
- var next= source.charAt(start+2)
4165
- switch(next){
4166
- case '-':
4167
- if(source.charAt(start + 3) === '-'){
4168
- var end = source.indexOf('-->',start+4);
4169
- //append comment source.substring(4,end)//<!--
4170
- if(end>start){
4171
- domBuilder.comment(source,start+4,end-start-4);
4172
- return end+3;
4173
- }else{
4174
- errorHandler.error("Unclosed comment");
4175
- return -1;
4176
- }
4177
- }else{
4178
- //error
4179
- return -1;
4180
- }
4181
- default:
4182
- if(source.substr(start+3,6) == 'CDATA['){
4183
- var end = source.indexOf(']]>',start+9);
4184
- domBuilder.startCDATA();
4185
- domBuilder.characters(source,start+9,end-start-9);
4186
- domBuilder.endCDATA()
4187
- return end+3;
4188
- }
4189
- //<!DOCTYPE
4190
- //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
4191
- var matchs = split(source,start);
4192
- var len = matchs.length;
4193
- if(len>1 && /!doctype/i.test(matchs[0][0])){
4194
- var name = matchs[1][0];
4195
- var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
4196
- var sysid = len>4 && matchs[4][0];
4197
- var lastMatch = matchs[len-1]
4198
- domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
4199
- sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
4200
- domBuilder.endDTD();
4201
-
4202
- return lastMatch.index+lastMatch[0].length
4203
- }
4204
- }
4205
- return -1;
4206
- }
4207
-
4208
-
4209
-
4210
- function parseInstruction(source,start,domBuilder){
4211
- var end = source.indexOf('?>',start);
4212
- if(end){
4213
- var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
4214
- if(match){
4215
- var len = match[0].length;
4216
- domBuilder.processingInstruction(match[1], match[2]) ;
4217
- return end+2;
4218
- }else{//error
4219
- return -1;
4220
- }
4221
- }
4222
- return -1;
4223
- }
4224
-
4225
- /**
4226
- * @param source
4227
- */
4228
- function ElementAttributes(source){
4229
-
4230
- }
4231
- ElementAttributes.prototype = {
4232
- setTagName:function(tagName){
4233
- if(!tagNamePattern.test(tagName)){
4234
- throw new Error('invalid tagName:'+tagName)
4235
- }
4236
- this.tagName = tagName
4237
- },
4238
- add:function(qName,value,offset){
4239
- if(!tagNamePattern.test(qName)){
4240
- throw new Error('invalid attribute:'+qName)
4241
- }
4242
- this[this.length++] = {qName:qName,value:value,offset:offset}
4243
- },
4244
- length:0,
4245
- getLocalName:function(i){return this[i].localName},
4246
- getLocator:function(i){return this[i].locator},
4247
- getQName:function(i){return this[i].qName},
4248
- getURI:function(i){return this[i].uri},
4249
- getValue:function(i){return this[i].value}
4250
- // ,getIndex:function(uri, localName)){
4251
- // if(localName){
4252
- //
4253
- // }else{
4254
- // var qName = uri
4255
- // }
4256
- // },
4257
- // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
4258
- // getType:function(uri,localName){}
4259
- // getType:function(i){},
4260
- }
4261
-
4262
-
4263
-
4264
-
4265
- function _set_proto_(thiz,parent){
4266
- thiz.__proto__ = parent;
4267
- return thiz;
4268
- }
4269
- if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
4270
- _set_proto_ = function(thiz,parent){
4271
- function p(){};
4272
- p.prototype = parent;
4273
- p = new p();
4274
- for(parent in thiz){
4275
- p[parent] = thiz[parent];
4276
- }
4277
- return p;
4278
- }
4279
- }
4280
-
4281
- function split(source,start){
4282
- var match;
4283
- var buf = [];
4284
- var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
4285
- reg.lastIndex = start;
4286
- reg.exec(source);//skip <
4287
- while(match = reg.exec(source)){
4288
- buf.push(match);
4289
- if(match[1])return buf;
4290
- }
4291
- }
4292
-
4293
- exports.XMLReader = XMLReader;
4294
-
3771
+ exports.entityMap = {
3772
+ lt: '<',
3773
+ gt: '>',
3774
+ amp: '&',
3775
+ quot: '"',
3776
+ apos: "'",
3777
+ Agrave: "À",
3778
+ Aacute: "Á",
3779
+ Acirc: "Â",
3780
+ Atilde: "Ã",
3781
+ Auml: "Ä",
3782
+ Aring: "Å",
3783
+ AElig: "Æ",
3784
+ Ccedil: "Ç",
3785
+ Egrave: "È",
3786
+ Eacute: "É",
3787
+ Ecirc: "Ê",
3788
+ Euml: "Ë",
3789
+ Igrave: "Ì",
3790
+ Iacute: "Í",
3791
+ Icirc: "Î",
3792
+ Iuml: "Ï",
3793
+ ETH: "Ð",
3794
+ Ntilde: "Ñ",
3795
+ Ograve: "Ò",
3796
+ Oacute: "Ó",
3797
+ Ocirc: "Ô",
3798
+ Otilde: "Õ",
3799
+ Ouml: "Ö",
3800
+ Oslash: "Ø",
3801
+ Ugrave: "Ù",
3802
+ Uacute: "Ú",
3803
+ Ucirc: "Û",
3804
+ Uuml: "Ü",
3805
+ Yacute: "Ý",
3806
+ THORN: "Þ",
3807
+ szlig: "ß",
3808
+ agrave: "à",
3809
+ aacute: "á",
3810
+ acirc: "â",
3811
+ atilde: "ã",
3812
+ auml: "ä",
3813
+ aring: "å",
3814
+ aelig: "æ",
3815
+ ccedil: "ç",
3816
+ egrave: "è",
3817
+ eacute: "é",
3818
+ ecirc: "ê",
3819
+ euml: "ë",
3820
+ igrave: "ì",
3821
+ iacute: "í",
3822
+ icirc: "î",
3823
+ iuml: "ï",
3824
+ eth: "ð",
3825
+ ntilde: "ñ",
3826
+ ograve: "ò",
3827
+ oacute: "ó",
3828
+ ocirc: "ô",
3829
+ otilde: "õ",
3830
+ ouml: "ö",
3831
+ oslash: "ø",
3832
+ ugrave: "ù",
3833
+ uacute: "ú",
3834
+ ucirc: "û",
3835
+ uuml: "ü",
3836
+ yacute: "ý",
3837
+ thorn: "þ",
3838
+ yuml: "ÿ",
3839
+ nbsp: "\u00a0",
3840
+ iexcl: "¡",
3841
+ cent: "¢",
3842
+ pound: "£",
3843
+ curren: "¤",
3844
+ yen: "¥",
3845
+ brvbar: "¦",
3846
+ sect: "§",
3847
+ uml: "¨",
3848
+ copy: "©",
3849
+ ordf: "ª",
3850
+ laquo: "«",
3851
+ not: "¬",
3852
+ shy: "­­",
3853
+ reg: "®",
3854
+ macr: "¯",
3855
+ deg: "°",
3856
+ plusmn: "±",
3857
+ sup2: "²",
3858
+ sup3: "³",
3859
+ acute: "´",
3860
+ micro: "µ",
3861
+ para: "¶",
3862
+ middot: "·",
3863
+ cedil: "¸",
3864
+ sup1: "¹",
3865
+ ordm: "º",
3866
+ raquo: "»",
3867
+ frac14: "¼",
3868
+ frac12: "½",
3869
+ frac34: "¾",
3870
+ iquest: "¿",
3871
+ times: "×",
3872
+ divide: "÷",
3873
+ forall: "∀",
3874
+ part: "∂",
3875
+ exist: "∃",
3876
+ empty: "∅",
3877
+ nabla: "∇",
3878
+ isin: "∈",
3879
+ notin: "∉",
3880
+ ni: "∋",
3881
+ prod: "∏",
3882
+ sum: "∑",
3883
+ minus: "−",
3884
+ lowast: "∗",
3885
+ radic: "√",
3886
+ prop: "∝",
3887
+ infin: "∞",
3888
+ ang: "∠",
3889
+ and: "∧",
3890
+ or: "∨",
3891
+ cap: "∩",
3892
+ cup: "∪",
3893
+ 'int': "∫",
3894
+ there4: "∴",
3895
+ sim: "∼",
3896
+ cong: "≅",
3897
+ asymp: "≈",
3898
+ ne: "≠",
3899
+ equiv: "≡",
3900
+ le: "≤",
3901
+ ge: "≥",
3902
+ sub: "⊂",
3903
+ sup: "⊃",
3904
+ nsub: "⊄",
3905
+ sube: "⊆",
3906
+ supe: "⊇",
3907
+ oplus: "⊕",
3908
+ otimes: "⊗",
3909
+ perp: "⊥",
3910
+ sdot: "⋅",
3911
+ Alpha: "Α",
3912
+ Beta: "Β",
3913
+ Gamma: "Γ",
3914
+ Delta: "Δ",
3915
+ Epsilon: "Ε",
3916
+ Zeta: "Ζ",
3917
+ Eta: "Η",
3918
+ Theta: "Θ",
3919
+ Iota: "Ι",
3920
+ Kappa: "Κ",
3921
+ Lambda: "Λ",
3922
+ Mu: "Μ",
3923
+ Nu: "Ν",
3924
+ Xi: "Ξ",
3925
+ Omicron: "Ο",
3926
+ Pi: "Π",
3927
+ Rho: "Ρ",
3928
+ Sigma: "Σ",
3929
+ Tau: "Τ",
3930
+ Upsilon: "Υ",
3931
+ Phi: "Φ",
3932
+ Chi: "Χ",
3933
+ Psi: "Ψ",
3934
+ Omega: "Ω",
3935
+ alpha: "α",
3936
+ beta: "β",
3937
+ gamma: "γ",
3938
+ delta: "δ",
3939
+ epsilon: "ε",
3940
+ zeta: "ζ",
3941
+ eta: "η",
3942
+ theta: "θ",
3943
+ iota: "ι",
3944
+ kappa: "κ",
3945
+ lambda: "λ",
3946
+ mu: "μ",
3947
+ nu: "ν",
3948
+ xi: "ξ",
3949
+ omicron: "ο",
3950
+ pi: "π",
3951
+ rho: "ρ",
3952
+ sigmaf: "ς",
3953
+ sigma: "σ",
3954
+ tau: "τ",
3955
+ upsilon: "υ",
3956
+ phi: "φ",
3957
+ chi: "χ",
3958
+ psi: "ψ",
3959
+ omega: "ω",
3960
+ thetasym: "ϑ",
3961
+ upsih: "ϒ",
3962
+ piv: "ϖ",
3963
+ OElig: "Œ",
3964
+ oelig: "œ",
3965
+ Scaron: "Š",
3966
+ scaron: "š",
3967
+ Yuml: "Ÿ",
3968
+ fnof: "ƒ",
3969
+ circ: "ˆ",
3970
+ tilde: "˜",
3971
+ ensp: " ",
3972
+ emsp: " ",
3973
+ thinsp: " ",
3974
+ zwnj: "‌",
3975
+ zwj: "‍",
3976
+ lrm: "‎",
3977
+ rlm: "‏",
3978
+ ndash: "–",
3979
+ mdash: "—",
3980
+ lsquo: "‘",
3981
+ rsquo: "’",
3982
+ sbquo: "‚",
3983
+ ldquo: "“",
3984
+ rdquo: "”",
3985
+ bdquo: "„",
3986
+ dagger: "†",
3987
+ Dagger: "‡",
3988
+ bull: "•",
3989
+ hellip: "…",
3990
+ permil: "‰",
3991
+ prime: "′",
3992
+ Prime: "″",
3993
+ lsaquo: "‹",
3994
+ rsaquo: "›",
3995
+ oline: "‾",
3996
+ euro: "€",
3997
+ trade: "™",
3998
+ larr: "←",
3999
+ uarr: "↑",
4000
+ rarr: "→",
4001
+ darr: "↓",
4002
+ harr: "↔",
4003
+ crarr: "↵",
4004
+ lceil: "⌈",
4005
+ rceil: "⌉",
4006
+ lfloor: "⌊",
4007
+ rfloor: "⌋",
4008
+ loz: "◊",
4009
+ spades: "♠",
4010
+ clubs: "♣",
4011
+ hearts: "♥",
4012
+ diams: "♦"
4013
+ };
4014
+
4015
+ },{}],8:[function(require,module,exports){
4016
+ //[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
4017
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
4018
+ //[5] Name ::= NameStartChar (NameChar)*
4019
+ var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
4020
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
4021
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
4022
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
4023
+ //var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
4024
+
4025
+ //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
4026
+ //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
4027
+ var S_TAG = 0;//tag name offerring
4028
+ var S_ATTR = 1;//attr name offerring
4029
+ var S_ATTR_SPACE=2;//attr name end and space offer
4030
+ var S_EQ = 3;//=space?
4031
+ var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
4032
+ var S_ATTR_END = 5;//attr value end and no space(quot end)
4033
+ var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
4034
+ var S_TAG_CLOSE = 7;//closed el<el />
4035
+
4036
+ /**
4037
+ * Creates an error that will not be caught by XMLReader aka the SAX parser.
4038
+ *
4039
+ * @param {string} message
4040
+ * @param {any?} locator Optional, can provide details about the location in the source
4041
+ * @constructor
4042
+ */
4043
+ function ParseError(message, locator) {
4044
+ this.message = message
4045
+ this.locator = locator
4046
+ if(Error.captureStackTrace) Error.captureStackTrace(this, ParseError);
4047
+ }
4048
+ ParseError.prototype = new Error();
4049
+ ParseError.prototype.name = ParseError.name
4050
+
4051
+ function XMLReader(){
4052
+
4053
+ }
4054
+
4055
+ XMLReader.prototype = {
4056
+ parse:function(source,defaultNSMap,entityMap){
4057
+ var domBuilder = this.domBuilder;
4058
+ domBuilder.startDocument();
4059
+ _copy(defaultNSMap ,defaultNSMap = {})
4060
+ parse(source,defaultNSMap,entityMap,
4061
+ domBuilder,this.errorHandler);
4062
+ domBuilder.endDocument();
4063
+ }
4064
+ }
4065
+ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
4066
+ function fixedFromCharCode(code) {
4067
+ // String.prototype.fromCharCode does not supports
4068
+ // > 2 bytes unicode chars directly
4069
+ if (code > 0xffff) {
4070
+ code -= 0x10000;
4071
+ var surrogate1 = 0xd800 + (code >> 10)
4072
+ , surrogate2 = 0xdc00 + (code & 0x3ff);
4073
+
4074
+ return String.fromCharCode(surrogate1, surrogate2);
4075
+ } else {
4076
+ return String.fromCharCode(code);
4077
+ }
4078
+ }
4079
+ function entityReplacer(a){
4080
+ var k = a.slice(1,-1);
4081
+ if(k in entityMap){
4082
+ return entityMap[k];
4083
+ }else if(k.charAt(0) === '#'){
4084
+ return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
4085
+ }else{
4086
+ errorHandler.error('entity not found:'+a);
4087
+ return a;
4088
+ }
4089
+ }
4090
+ function appendText(end){//has some bugs
4091
+ if(end>start){
4092
+ var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
4093
+ locator&&position(start);
4094
+ domBuilder.characters(xt,0,end-start);
4095
+ start = end
4096
+ }
4097
+ }
4098
+ function position(p,m){
4099
+ while(p>=lineEnd && (m = linePattern.exec(source))){
4100
+ lineStart = m.index;
4101
+ lineEnd = lineStart + m[0].length;
4102
+ locator.lineNumber++;
4103
+ //console.log('line++:',locator,startPos,endPos)
4104
+ }
4105
+ locator.columnNumber = p-lineStart+1;
4106
+ }
4107
+ var lineStart = 0;
4108
+ var lineEnd = 0;
4109
+ var linePattern = /.*(?:\r\n?|\n)|.*$/g
4110
+ var locator = domBuilder.locator;
4111
+
4112
+ var parseStack = [{currentNSMap:defaultNSMapCopy}]
4113
+ var closeMap = {};
4114
+ var start = 0;
4115
+ while(true){
4116
+ try{
4117
+ var tagStart = source.indexOf('<',start);
4118
+ if(tagStart<0){
4119
+ if(!source.substr(start).match(/^\s*$/)){
4120
+ var doc = domBuilder.doc;
4121
+ var text = doc.createTextNode(source.substr(start));
4122
+ doc.appendChild(text);
4123
+ domBuilder.currentElement = text;
4124
+ }
4125
+ return;
4126
+ }
4127
+ if(tagStart>start){
4128
+ appendText(tagStart);
4129
+ }
4130
+ switch(source.charAt(tagStart+1)){
4131
+ case '/':
4132
+ var end = source.indexOf('>',tagStart+3);
4133
+ var tagName = source.substring(tagStart+2,end);
4134
+ var config = parseStack.pop();
4135
+ if(end<0){
4136
+
4137
+ tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
4138
+ //console.error('#@@@@@@'+tagName)
4139
+ errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
4140
+ end = tagStart+1+tagName.length;
4141
+ }else if(tagName.match(/\s</)){
4142
+ tagName = tagName.replace(/[\s<].*/,'');
4143
+ errorHandler.error("end tag name: "+tagName+' maybe not complete');
4144
+ end = tagStart+1+tagName.length;
4145
+ }
4146
+ //console.error(parseStack.length,parseStack)
4147
+ //console.error(config);
4148
+ var localNSMap = config.localNSMap;
4149
+ var endMatch = config.tagName == tagName;
4150
+ var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
4151
+ if(endIgnoreCaseMach){
4152
+ domBuilder.endElement(config.uri,config.localName,tagName);
4153
+ if(localNSMap){
4154
+ for(var prefix in localNSMap){
4155
+ domBuilder.endPrefixMapping(prefix) ;
4156
+ }
4157
+ }
4158
+ if(!endMatch){
4159
+ errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName ); // No known test case
4160
+ }
4161
+ }else{
4162
+ parseStack.push(config)
4163
+ }
4164
+
4165
+ end++;
4166
+ break;
4167
+ // end elment
4168
+ case '?':// <?...?>
4169
+ locator&&position(tagStart);
4170
+ end = parseInstruction(source,tagStart,domBuilder);
4171
+ break;
4172
+ case '!':// <!doctype,<![CDATA,<!--
4173
+ locator&&position(tagStart);
4174
+ end = parseDCC(source,tagStart,domBuilder,errorHandler);
4175
+ break;
4176
+ default:
4177
+ locator&&position(tagStart);
4178
+ var el = new ElementAttributes();
4179
+ var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
4180
+ //elStartEnd
4181
+ var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
4182
+ var len = el.length;
4183
+
4184
+
4185
+ if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
4186
+ el.closed = true;
4187
+ if(!entityMap.nbsp){
4188
+ errorHandler.warning('unclosed xml attribute');
4189
+ }
4190
+ }
4191
+ if(locator && len){
4192
+ var locator2 = copyLocator(locator,{});
4193
+ //try{//attribute position fixed
4194
+ for(var i = 0;i<len;i++){
4195
+ var a = el[i];
4196
+ position(a.offset);
4197
+ a.locator = copyLocator(locator,{});
4198
+ }
4199
+ //}catch(e){console.error('@@@@@'+e)}
4200
+ domBuilder.locator = locator2
4201
+ if(appendElement(el,domBuilder,currentNSMap)){
4202
+ parseStack.push(el)
4203
+ }
4204
+ domBuilder.locator = locator;
4205
+ }else{
4206
+ if(appendElement(el,domBuilder,currentNSMap)){
4207
+ parseStack.push(el)
4208
+ }
4209
+ }
4210
+
4211
+
4212
+
4213
+ if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
4214
+ end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
4215
+ }else{
4216
+ end++;
4217
+ }
4218
+ }
4219
+ }catch(e){
4220
+ if (e instanceof ParseError) {
4221
+ throw e;
4222
+ }
4223
+ errorHandler.error('element parse error: '+e)
4224
+ end = -1;
4225
+ }
4226
+ if(end>start){
4227
+ start = end;
4228
+ }else{
4229
+ //TODO: 这里有可能sax回退,有位置错误风险
4230
+ appendText(Math.max(tagStart,start)+1);
4231
+ }
4232
+ }
4233
+ }
4234
+ function copyLocator(f,t){
4235
+ t.lineNumber = f.lineNumber;
4236
+ t.columnNumber = f.columnNumber;
4237
+ return t;
4238
+ }
4239
+
4240
+ /**
4241
+ * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
4242
+ * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
4243
+ */
4244
+ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
4245
+
4246
+ /**
4247
+ * @param {string} qname
4248
+ * @param {string} value
4249
+ * @param {number} startIndex
4250
+ */
4251
+ function addAttribute(qname, value, startIndex) {
4252
+ if (qname in el.attributeNames) errorHandler.fatalError('Attribute ' + qname + ' redefined')
4253
+ el.addValue(qname, value, startIndex)
4254
+ }
4255
+ var attrName;
4256
+ var value;
4257
+ var p = ++start;
4258
+ var s = S_TAG;//status
4259
+ while(true){
4260
+ var c = source.charAt(p);
4261
+ switch(c){
4262
+ case '=':
4263
+ if(s === S_ATTR){//attrName
4264
+ attrName = source.slice(start,p);
4265
+ s = S_EQ;
4266
+ }else if(s === S_ATTR_SPACE){
4267
+ s = S_EQ;
4268
+ }else{
4269
+ //fatalError: equal must after attrName or space after attrName
4270
+ throw new Error('attribute equal must after attrName'); // No known test case
4271
+ }
4272
+ break;
4273
+ case '\'':
4274
+ case '"':
4275
+ if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
4276
+ ){//equal
4277
+ if(s === S_ATTR){
4278
+ errorHandler.warning('attribute value must after "="')
4279
+ attrName = source.slice(start,p)
4280
+ }
4281
+ start = p+1;
4282
+ p = source.indexOf(c,start)
4283
+ if(p>0){
4284
+ value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
4285
+ addAttribute(attrName, value, start-1);
4286
+ s = S_ATTR_END;
4287
+ }else{
4288
+ //fatalError: no end quot match
4289
+ throw new Error('attribute value no end \''+c+'\' match');
4290
+ }
4291
+ }else if(s == S_ATTR_NOQUOT_VALUE){
4292
+ value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
4293
+ //console.log(attrName,value,start,p)
4294
+ addAttribute(attrName, value, start);
4295
+ //console.dir(el)
4296
+ errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
4297
+ start = p+1;
4298
+ s = S_ATTR_END
4299
+ }else{
4300
+ //fatalError: no equal before
4301
+ throw new Error('attribute value must after "="'); // No known test case
4302
+ }
4303
+ break;
4304
+ case '/':
4305
+ switch(s){
4306
+ case S_TAG:
4307
+ el.setTagName(source.slice(start,p));
4308
+ case S_ATTR_END:
4309
+ case S_TAG_SPACE:
4310
+ case S_TAG_CLOSE:
4311
+ s =S_TAG_CLOSE;
4312
+ el.closed = true;
4313
+ case S_ATTR_NOQUOT_VALUE:
4314
+ case S_ATTR:
4315
+ case S_ATTR_SPACE:
4316
+ break;
4317
+ //case S_EQ:
4318
+ default:
4319
+ throw new Error("attribute invalid close char('/')") // No known test case
4320
+ }
4321
+ break;
4322
+ case ''://end document
4323
+ errorHandler.error('unexpected end of input');
4324
+ if(s == S_TAG){
4325
+ el.setTagName(source.slice(start,p));
4326
+ }
4327
+ return p;
4328
+ case '>':
4329
+ switch(s){
4330
+ case S_TAG:
4331
+ el.setTagName(source.slice(start,p));
4332
+ case S_ATTR_END:
4333
+ case S_TAG_SPACE:
4334
+ case S_TAG_CLOSE:
4335
+ break;//normal
4336
+ case S_ATTR_NOQUOT_VALUE://Compatible state
4337
+ case S_ATTR:
4338
+ value = source.slice(start,p);
4339
+ if(value.slice(-1) === '/'){
4340
+ el.closed = true;
4341
+ value = value.slice(0,-1)
4342
+ }
4343
+ case S_ATTR_SPACE:
4344
+ if(s === S_ATTR_SPACE){
4345
+ value = attrName;
4346
+ }
4347
+ if(s == S_ATTR_NOQUOT_VALUE){
4348
+ errorHandler.warning('attribute "'+value+'" missed quot(")!');
4349
+ addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start)
4350
+ }else{
4351
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
4352
+ errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
4353
+ }
4354
+ addAttribute(value, value, start)
4355
+ }
4356
+ break;
4357
+ case S_EQ:
4358
+ throw new Error('attribute value missed!!');
4359
+ }
4360
+ // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
4361
+ return p;
4362
+ /*xml space '\x20' | #x9 | #xD | #xA; */
4363
+ case '\u0080':
4364
+ c = ' ';
4365
+ default:
4366
+ if(c<= ' '){//space
4367
+ switch(s){
4368
+ case S_TAG:
4369
+ el.setTagName(source.slice(start,p));//tagName
4370
+ s = S_TAG_SPACE;
4371
+ break;
4372
+ case S_ATTR:
4373
+ attrName = source.slice(start,p)
4374
+ s = S_ATTR_SPACE;
4375
+ break;
4376
+ case S_ATTR_NOQUOT_VALUE:
4377
+ var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
4378
+ errorHandler.warning('attribute "'+value+'" missed quot(")!!');
4379
+ addAttribute(attrName, value, start)
4380
+ case S_ATTR_END:
4381
+ s = S_TAG_SPACE;
4382
+ break;
4383
+ //case S_TAG_SPACE:
4384
+ //case S_EQ:
4385
+ //case S_ATTR_SPACE:
4386
+ // void();break;
4387
+ //case S_TAG_CLOSE:
4388
+ //ignore warning
4389
+ }
4390
+ }else{//not space
4391
+ //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
4392
+ //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
4393
+ switch(s){
4394
+ //case S_TAG:void();break;
4395
+ //case S_ATTR:void();break;
4396
+ //case S_ATTR_NOQUOT_VALUE:void();break;
4397
+ case S_ATTR_SPACE:
4398
+ var tagName = el.tagName;
4399
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
4400
+ errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
4401
+ }
4402
+ addAttribute(attrName, attrName, start);
4403
+ start = p;
4404
+ s = S_ATTR;
4405
+ break;
4406
+ case S_ATTR_END:
4407
+ errorHandler.warning('attribute space is required"'+attrName+'"!!')
4408
+ case S_TAG_SPACE:
4409
+ s = S_ATTR;
4410
+ start = p;
4411
+ break;
4412
+ case S_EQ:
4413
+ s = S_ATTR_NOQUOT_VALUE;
4414
+ start = p;
4415
+ break;
4416
+ case S_TAG_CLOSE:
4417
+ throw new Error("elements closed character '/' and '>' must be connected to");
4418
+ }
4419
+ }
4420
+ }//end outer switch
4421
+ //console.log('p++',p)
4422
+ p++;
4423
+ }
4424
+ }
4425
+ /**
4426
+ * @return true if has new namespace define
4427
+ */
4428
+ function appendElement(el,domBuilder,currentNSMap){
4429
+ var tagName = el.tagName;
4430
+ var localNSMap = null;
4431
+ //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
4432
+ var i = el.length;
4433
+ while(i--){
4434
+ var a = el[i];
4435
+ var qName = a.qName;
4436
+ var value = a.value;
4437
+ var nsp = qName.indexOf(':');
4438
+ if(nsp>0){
4439
+ var prefix = a.prefix = qName.slice(0,nsp);
4440
+ var localName = qName.slice(nsp+1);
4441
+ var nsPrefix = prefix === 'xmlns' && localName
4442
+ }else{
4443
+ localName = qName;
4444
+ prefix = null
4445
+ nsPrefix = qName === 'xmlns' && ''
4446
+ }
4447
+ //can not set prefix,because prefix !== ''
4448
+ a.localName = localName ;
4449
+ //prefix == null for no ns prefix attribute
4450
+ if(nsPrefix !== false){//hack!!
4451
+ if(localNSMap == null){
4452
+ localNSMap = {}
4453
+ //console.log(currentNSMap,0)
4454
+ _copy(currentNSMap,currentNSMap={})
4455
+ //console.log(currentNSMap,1)
4456
+ }
4457
+ currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
4458
+ a.uri = 'http://www.w3.org/2000/xmlns/'
4459
+ domBuilder.startPrefixMapping(nsPrefix, value)
4460
+ }
4461
+ }
4462
+ var i = el.length;
4463
+ while(i--){
4464
+ a = el[i];
4465
+ var prefix = a.prefix;
4466
+ if(prefix){//no prefix attribute has no namespace
4467
+ if(prefix === 'xml'){
4468
+ a.uri = 'http://www.w3.org/XML/1998/namespace';
4469
+ }if(prefix !== 'xmlns'){
4470
+ a.uri = currentNSMap[prefix || '']
4471
+
4472
+ //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
4473
+ }
4474
+ }
4475
+ }
4476
+ var nsp = tagName.indexOf(':');
4477
+ if(nsp>0){
4478
+ prefix = el.prefix = tagName.slice(0,nsp);
4479
+ localName = el.localName = tagName.slice(nsp+1);
4480
+ }else{
4481
+ prefix = null;//important!!
4482
+ localName = el.localName = tagName;
4483
+ }
4484
+ //no prefix element has default namespace
4485
+ var ns = el.uri = currentNSMap[prefix || ''];
4486
+ domBuilder.startElement(ns,localName,tagName,el);
4487
+ //endPrefixMapping and startPrefixMapping have not any help for dom builder
4488
+ //localNSMap = null
4489
+ if(el.closed){
4490
+ domBuilder.endElement(ns,localName,tagName);
4491
+ if(localNSMap){
4492
+ for(prefix in localNSMap){
4493
+ domBuilder.endPrefixMapping(prefix)
4494
+ }
4495
+ }
4496
+ }else{
4497
+ el.currentNSMap = currentNSMap;
4498
+ el.localNSMap = localNSMap;
4499
+ //parseStack.push(el);
4500
+ return true;
4501
+ }
4502
+ }
4503
+ function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
4504
+ if(/^(?:script|textarea)$/i.test(tagName)){
4505
+ var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
4506
+ var text = source.substring(elStartEnd+1,elEndStart);
4507
+ if(/[&<]/.test(text)){
4508
+ if(/^script$/i.test(tagName)){
4509
+ //if(!/\]\]>/.test(text)){
4510
+ //lexHandler.startCDATA();
4511
+ domBuilder.characters(text,0,text.length);
4512
+ //lexHandler.endCDATA();
4513
+ return elEndStart;
4514
+ //}
4515
+ }//}else{//text area
4516
+ text = text.replace(/&#?\w+;/g,entityReplacer);
4517
+ domBuilder.characters(text,0,text.length);
4518
+ return elEndStart;
4519
+ //}
4520
+
4521
+ }
4522
+ }
4523
+ return elStartEnd+1;
4524
+ }
4525
+ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
4526
+ //if(tagName in closeMap){
4527
+ var pos = closeMap[tagName];
4528
+ if(pos == null){
4529
+ //console.log(tagName)
4530
+ pos = source.lastIndexOf('</'+tagName+'>')
4531
+ if(pos<elStartEnd){//忘记闭合
4532
+ pos = source.lastIndexOf('</'+tagName)
4533
+ }
4534
+ closeMap[tagName] =pos
4535
+ }
4536
+ return pos<elStartEnd;
4537
+ //}
4538
+ }
4539
+ function _copy(source,target){
4540
+ for(var n in source){target[n] = source[n]}
4541
+ }
4542
+ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
4543
+ var next= source.charAt(start+2)
4544
+ switch(next){
4545
+ case '-':
4546
+ if(source.charAt(start + 3) === '-'){
4547
+ var end = source.indexOf('-->',start+4);
4548
+ //append comment source.substring(4,end)//<!--
4549
+ if(end>start){
4550
+ domBuilder.comment(source,start+4,end-start-4);
4551
+ return end+3;
4552
+ }else{
4553
+ errorHandler.error("Unclosed comment");
4554
+ return -1;
4555
+ }
4556
+ }else{
4557
+ //error
4558
+ return -1;
4559
+ }
4560
+ default:
4561
+ if(source.substr(start+3,6) == 'CDATA['){
4562
+ var end = source.indexOf(']]>',start+9);
4563
+ domBuilder.startCDATA();
4564
+ domBuilder.characters(source,start+9,end-start-9);
4565
+ domBuilder.endCDATA()
4566
+ return end+3;
4567
+ }
4568
+ //<!DOCTYPE
4569
+ //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
4570
+ var matchs = split(source,start);
4571
+ var len = matchs.length;
4572
+ if(len>1 && /!doctype/i.test(matchs[0][0])){
4573
+ var name = matchs[1][0];
4574
+ var pubid = false;
4575
+ var sysid = false;
4576
+ if(len>3){
4577
+ if(/^public$/i.test(matchs[2][0])){
4578
+ pubid = matchs[3][0];
4579
+ sysid = len>4 && matchs[4][0];
4580
+ }else if(/^system$/i.test(matchs[2][0])){
4581
+ sysid = matchs[3][0];
4582
+ }
4583
+ }
4584
+ var lastMatch = matchs[len-1]
4585
+ domBuilder.startDTD(name, pubid, sysid);
4586
+ domBuilder.endDTD();
4587
+
4588
+ return lastMatch.index+lastMatch[0].length
4589
+ }
4590
+ }
4591
+ return -1;
4592
+ }
4593
+
4594
+
4595
+
4596
+ function parseInstruction(source,start,domBuilder){
4597
+ var end = source.indexOf('?>',start);
4598
+ if(end){
4599
+ var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
4600
+ if(match){
4601
+ var len = match[0].length;
4602
+ domBuilder.processingInstruction(match[1], match[2]) ;
4603
+ return end+2;
4604
+ }else{//error
4605
+ return -1;
4606
+ }
4607
+ }
4608
+ return -1;
4609
+ }
4610
+
4611
+ function ElementAttributes(){
4612
+ this.attributeNames = {}
4613
+ }
4614
+ ElementAttributes.prototype = {
4615
+ setTagName:function(tagName){
4616
+ if(!tagNamePattern.test(tagName)){
4617
+ throw new Error('invalid tagName:'+tagName)
4618
+ }
4619
+ this.tagName = tagName
4620
+ },
4621
+ addValue:function(qName, value, offset) {
4622
+ if(!tagNamePattern.test(qName)){
4623
+ throw new Error('invalid attribute:'+qName)
4624
+ }
4625
+ this.attributeNames[qName] = this.length;
4626
+ this[this.length++] = {qName:qName,value:value,offset:offset}
4627
+ },
4628
+ length:0,
4629
+ getLocalName:function(i){return this[i].localName},
4630
+ getLocator:function(i){return this[i].locator},
4631
+ getQName:function(i){return this[i].qName},
4632
+ getURI:function(i){return this[i].uri},
4633
+ getValue:function(i){return this[i].value}
4634
+ // ,getIndex:function(uri, localName)){
4635
+ // if(localName){
4636
+ //
4637
+ // }else{
4638
+ // var qName = uri
4639
+ // }
4640
+ // },
4641
+ // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
4642
+ // getType:function(uri,localName){}
4643
+ // getType:function(i){},
4644
+ }
4645
+
4646
+
4647
+
4648
+ function split(source,start){
4649
+ var match;
4650
+ var buf = [];
4651
+ var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
4652
+ reg.lastIndex = start;
4653
+ reg.exec(source);//skip <
4654
+ while(match = reg.exec(source)){
4655
+ buf.push(match);
4656
+ if(match[1])return buf;
4657
+ }
4658
+ }
4659
+
4660
+ exports.XMLReader = XMLReader;
4661
+ exports.ParseError = ParseError;
4295
4662
 
4296
4663
  },{}]},{},[1])(1)
4297
4664
  });