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.
package/dist/plist.js CHANGED
@@ -1,4 +1,4 @@
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){
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
2
  /**
3
3
  * Parser functions.
4
4
  */
@@ -14,7 +14,7 @@ var builderFunctions = require('./lib/build');
14
14
  Object.keys(builderFunctions).forEach(function (k) { exports[k] = builderFunctions[k]; });
15
15
 
16
16
  },{"./lib/build":2,"./lib/parse":3}],2:[function(require,module,exports){
17
- (function (Buffer){
17
+ (function (Buffer){(function (){
18
18
  /**
19
19
  * Module dependencies.
20
20
  */
@@ -153,9 +153,9 @@ function walk_obj(next, next_child) {
153
153
  }
154
154
  }
155
155
 
156
- }).call(this,{"isBuffer":require("../node_modules/is-buffer/index.js")})
156
+ }).call(this)}).call(this,{"isBuffer":require("../node_modules/is-buffer/index.js")})
157
157
  },{"../node_modules/is-buffer/index.js":7,"base64-js":4,"xmlbuilder":29}],3:[function(require,module,exports){
158
- (function (Buffer){
158
+ (function (Buffer){(function (){
159
159
  /**
160
160
  * Module dependencies.
161
161
  */
@@ -348,14 +348,14 @@ function parsePlistXML (node) {
348
348
  } else if (node.nodeName === 'data') {
349
349
  res = '';
350
350
  if (isEmptyNode(node)) {
351
- return new Buffer(res, 'base64');
351
+ return Buffer.from(res, 'base64');
352
352
  }
353
353
  for (i=0; i < node.childNodes.length; i++) {
354
354
  if (node.childNodes[i].nodeType === TEXT_NODE) {
355
355
  res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
356
356
  }
357
357
  }
358
- return new Buffer(res, 'base64');
358
+ return Buffer.from(res, 'base64');
359
359
 
360
360
  } else if (node.nodeName === 'date') {
361
361
  invariant(
@@ -372,7 +372,7 @@ function parsePlistXML (node) {
372
372
  }
373
373
  }
374
374
 
375
- }).call(this,require("buffer").Buffer)
375
+ }).call(this)}).call(this,require("buffer").Buffer)
376
376
  },{"buffer":5,"xmldom":30}],4:[function(require,module,exports){
377
377
  'use strict'
378
378
 
@@ -395,65 +395,98 @@ for (var i = 0, len = code.length; i < len; ++i) {
395
395
  revLookup['-'.charCodeAt(0)] = 62
396
396
  revLookup['_'.charCodeAt(0)] = 63
397
397
 
398
- function placeHoldersCount (b64) {
398
+ function getLens (b64) {
399
399
  var len = b64.length
400
+
400
401
  if (len % 4 > 0) {
401
402
  throw new Error('Invalid string. Length must be a multiple of 4')
402
403
  }
403
404
 
404
- // the number of equal signs (place holders)
405
- // if there are two placeholders, than the two characters before it
406
- // represent one byte
407
- // if there is only one, then the three characters before it represent 2 bytes
408
- // this is just a cheap hack to not do indexOf twice
409
- return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
405
+ // Trim off extra bytes after placeholder bytes are found
406
+ // See: https://github.com/beatgammit/base64-js/issues/42
407
+ var validLen = b64.indexOf('=')
408
+ if (validLen === -1) validLen = len
409
+
410
+ var placeHoldersLen = validLen === len
411
+ ? 0
412
+ : 4 - (validLen % 4)
413
+
414
+ return [validLen, placeHoldersLen]
410
415
  }
411
416
 
417
+ // base64 is 4/3 + up to two characters of the original data
412
418
  function byteLength (b64) {
413
- // base64 is 4/3 + up to two characters of the original data
414
- return (b64.length * 3 / 4) - placeHoldersCount(b64)
419
+ var lens = getLens(b64)
420
+ var validLen = lens[0]
421
+ var placeHoldersLen = lens[1]
422
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
423
+ }
424
+
425
+ function _byteLength (b64, validLen, placeHoldersLen) {
426
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
415
427
  }
416
428
 
417
429
  function toByteArray (b64) {
418
- var i, l, tmp, placeHolders, arr
419
- var len = b64.length
420
- placeHolders = placeHoldersCount(b64)
430
+ var tmp
431
+ var lens = getLens(b64)
432
+ var validLen = lens[0]
433
+ var placeHoldersLen = lens[1]
421
434
 
422
- arr = new Arr((len * 3 / 4) - placeHolders)
435
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
436
+
437
+ var curByte = 0
423
438
 
424
439
  // if there are placeholders, only get up to the last complete 4 chars
425
- l = placeHolders > 0 ? len - 4 : len
440
+ var len = placeHoldersLen > 0
441
+ ? validLen - 4
442
+ : validLen
426
443
 
427
- var L = 0
444
+ var i
445
+ for (i = 0; i < len; i += 4) {
446
+ tmp =
447
+ (revLookup[b64.charCodeAt(i)] << 18) |
448
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
449
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
450
+ revLookup[b64.charCodeAt(i + 3)]
451
+ arr[curByte++] = (tmp >> 16) & 0xFF
452
+ arr[curByte++] = (tmp >> 8) & 0xFF
453
+ arr[curByte++] = tmp & 0xFF
454
+ }
428
455
 
429
- for (i = 0; i < l; i += 4) {
430
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
431
- arr[L++] = (tmp >> 16) & 0xFF
432
- arr[L++] = (tmp >> 8) & 0xFF
433
- arr[L++] = tmp & 0xFF
456
+ if (placeHoldersLen === 2) {
457
+ tmp =
458
+ (revLookup[b64.charCodeAt(i)] << 2) |
459
+ (revLookup[b64.charCodeAt(i + 1)] >> 4)
460
+ arr[curByte++] = tmp & 0xFF
434
461
  }
435
462
 
436
- if (placeHolders === 2) {
437
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
438
- arr[L++] = tmp & 0xFF
439
- } else if (placeHolders === 1) {
440
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
441
- arr[L++] = (tmp >> 8) & 0xFF
442
- arr[L++] = tmp & 0xFF
463
+ if (placeHoldersLen === 1) {
464
+ tmp =
465
+ (revLookup[b64.charCodeAt(i)] << 10) |
466
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
467
+ (revLookup[b64.charCodeAt(i + 2)] >> 2)
468
+ arr[curByte++] = (tmp >> 8) & 0xFF
469
+ arr[curByte++] = tmp & 0xFF
443
470
  }
444
471
 
445
472
  return arr
446
473
  }
447
474
 
448
475
  function tripletToBase64 (num) {
449
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
476
+ return lookup[num >> 18 & 0x3F] +
477
+ lookup[num >> 12 & 0x3F] +
478
+ lookup[num >> 6 & 0x3F] +
479
+ lookup[num & 0x3F]
450
480
  }
451
481
 
452
482
  function encodeChunk (uint8, start, end) {
453
483
  var tmp
454
484
  var output = []
455
485
  for (var i = start; i < end; i += 3) {
456
- tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF)
486
+ tmp =
487
+ ((uint8[i] << 16) & 0xFF0000) +
488
+ ((uint8[i + 1] << 8) & 0xFF00) +
489
+ (uint8[i + 2] & 0xFF)
457
490
  output.push(tripletToBase64(tmp))
458
491
  }
459
492
  return output.join('')
@@ -463,7 +496,6 @@ function fromByteArray (uint8) {
463
496
  var tmp
464
497
  var len = uint8.length
465
498
  var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
466
- var output = ''
467
499
  var parts = []
468
500
  var maxChunkLength = 16383 // must be multiple of 3
469
501
 
@@ -475,23 +507,26 @@ function fromByteArray (uint8) {
475
507
  // pad the end with zeros, but make sure to not forget the extra bytes
476
508
  if (extraBytes === 1) {
477
509
  tmp = uint8[len - 1]
478
- output += lookup[tmp >> 2]
479
- output += lookup[(tmp << 4) & 0x3F]
480
- output += '=='
510
+ parts.push(
511
+ lookup[tmp >> 2] +
512
+ lookup[(tmp << 4) & 0x3F] +
513
+ '=='
514
+ )
481
515
  } else if (extraBytes === 2) {
482
- tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
483
- output += lookup[tmp >> 10]
484
- output += lookup[(tmp >> 4) & 0x3F]
485
- output += lookup[(tmp << 2) & 0x3F]
486
- output += '='
516
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1]
517
+ parts.push(
518
+ lookup[tmp >> 10] +
519
+ lookup[(tmp >> 4) & 0x3F] +
520
+ lookup[(tmp << 2) & 0x3F] +
521
+ '='
522
+ )
487
523
  }
488
524
 
489
- parts.push(output)
490
-
491
525
  return parts.join('')
492
526
  }
493
527
 
494
528
  },{}],5:[function(require,module,exports){
529
+ (function (Buffer){(function (){
495
530
  /*!
496
531
  * The buffer module from node.js, for the browser.
497
532
  *
@@ -540,7 +575,7 @@ function typedArraySupport () {
540
575
  // Can typed array instances can be augmented?
541
576
  try {
542
577
  var arr = new Uint8Array(1)
543
- arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
578
+ arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
544
579
  return arr.foo() === 42
545
580
  } catch (e) {
546
581
  return false
@@ -548,26 +583,24 @@ function typedArraySupport () {
548
583
  }
549
584
 
550
585
  Object.defineProperty(Buffer.prototype, 'parent', {
586
+ enumerable: true,
551
587
  get: function () {
552
- if (!(this instanceof Buffer)) {
553
- return undefined
554
- }
588
+ if (!Buffer.isBuffer(this)) return undefined
555
589
  return this.buffer
556
590
  }
557
591
  })
558
592
 
559
593
  Object.defineProperty(Buffer.prototype, 'offset', {
594
+ enumerable: true,
560
595
  get: function () {
561
- if (!(this instanceof Buffer)) {
562
- return undefined
563
- }
596
+ if (!Buffer.isBuffer(this)) return undefined
564
597
  return this.byteOffset
565
598
  }
566
599
  })
567
600
 
568
601
  function createBuffer (length) {
569
602
  if (length > K_MAX_LENGTH) {
570
- throw new RangeError('Invalid typed array length')
603
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
571
604
  }
572
605
  // Return an augmented `Uint8Array` instance
573
606
  var buf = new Uint8Array(length)
@@ -589,8 +622,8 @@ function Buffer (arg, encodingOrOffset, length) {
589
622
  // Common case.
590
623
  if (typeof arg === 'number') {
591
624
  if (typeof encodingOrOffset === 'string') {
592
- throw new Error(
593
- 'If encoding is specified then the first argument must be a string'
625
+ throw new TypeError(
626
+ 'The "string" argument must be of type string. Received type number'
594
627
  )
595
628
  }
596
629
  return allocUnsafe(arg)
@@ -599,7 +632,7 @@ function Buffer (arg, encodingOrOffset, length) {
599
632
  }
600
633
 
601
634
  // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
602
- if (typeof Symbol !== 'undefined' && Symbol.species &&
635
+ if (typeof Symbol !== 'undefined' && Symbol.species != null &&
603
636
  Buffer[Symbol.species] === Buffer) {
604
637
  Object.defineProperty(Buffer, Symbol.species, {
605
638
  value: null,
@@ -612,19 +645,51 @@ if (typeof Symbol !== 'undefined' && Symbol.species &&
612
645
  Buffer.poolSize = 8192 // not used by this implementation
613
646
 
614
647
  function from (value, encodingOrOffset, length) {
615
- if (typeof value === 'number') {
616
- throw new TypeError('"value" argument must not be a number')
648
+ if (typeof value === 'string') {
649
+ return fromString(value, encodingOrOffset)
650
+ }
651
+
652
+ if (ArrayBuffer.isView(value)) {
653
+ return fromArrayLike(value)
617
654
  }
618
655
 
619
- if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
656
+ if (value == null) {
657
+ throw TypeError(
658
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
659
+ 'or Array-like Object. Received type ' + (typeof value)
660
+ )
661
+ }
662
+
663
+ if (isInstance(value, ArrayBuffer) ||
664
+ (value && isInstance(value.buffer, ArrayBuffer))) {
620
665
  return fromArrayBuffer(value, encodingOrOffset, length)
621
666
  }
622
667
 
623
- if (typeof value === 'string') {
624
- return fromString(value, encodingOrOffset)
668
+ if (typeof value === 'number') {
669
+ throw new TypeError(
670
+ 'The "value" argument must not be of type number. Received type number'
671
+ )
672
+ }
673
+
674
+ var valueOf = value.valueOf && value.valueOf()
675
+ if (valueOf != null && valueOf !== value) {
676
+ return Buffer.from(valueOf, encodingOrOffset, length)
677
+ }
678
+
679
+ var b = fromObject(value)
680
+ if (b) return b
681
+
682
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
683
+ typeof value[Symbol.toPrimitive] === 'function') {
684
+ return Buffer.from(
685
+ value[Symbol.toPrimitive]('string'), encodingOrOffset, length
686
+ )
625
687
  }
626
688
 
627
- return fromObject(value)
689
+ throw new TypeError(
690
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
691
+ 'or Array-like Object. Received type ' + (typeof value)
692
+ )
628
693
  }
629
694
 
630
695
  /**
@@ -648,7 +713,7 @@ function assertSize (size) {
648
713
  if (typeof size !== 'number') {
649
714
  throw new TypeError('"size" argument must be of type number')
650
715
  } else if (size < 0) {
651
- throw new RangeError('"size" argument must not be negative')
716
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
652
717
  }
653
718
  }
654
719
 
@@ -763,20 +828,16 @@ function fromObject (obj) {
763
828
  return buf
764
829
  }
765
830
 
766
- if (obj) {
767
- if (ArrayBuffer.isView(obj) || 'length' in obj) {
768
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
769
- return createBuffer(0)
770
- }
771
- return fromArrayLike(obj)
772
- }
773
-
774
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
775
- return fromArrayLike(obj.data)
831
+ if (obj.length !== undefined) {
832
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
833
+ return createBuffer(0)
776
834
  }
835
+ return fromArrayLike(obj)
777
836
  }
778
837
 
779
- throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
838
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
839
+ return fromArrayLike(obj.data)
840
+ }
780
841
  }
781
842
 
782
843
  function checked (length) {
@@ -797,12 +858,17 @@ function SlowBuffer (length) {
797
858
  }
798
859
 
799
860
  Buffer.isBuffer = function isBuffer (b) {
800
- return b != null && b._isBuffer === true
861
+ return b != null && b._isBuffer === true &&
862
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
801
863
  }
802
864
 
803
865
  Buffer.compare = function compare (a, b) {
866
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
867
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
804
868
  if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
805
- throw new TypeError('Arguments must be Buffers')
869
+ throw new TypeError(
870
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
871
+ )
806
872
  }
807
873
 
808
874
  if (a === b) return 0
@@ -863,7 +929,7 @@ Buffer.concat = function concat (list, length) {
863
929
  var pos = 0
864
930
  for (i = 0; i < list.length; ++i) {
865
931
  var buf = list[i]
866
- if (ArrayBuffer.isView(buf)) {
932
+ if (isInstance(buf, Uint8Array)) {
867
933
  buf = Buffer.from(buf)
868
934
  }
869
935
  if (!Buffer.isBuffer(buf)) {
@@ -879,15 +945,19 @@ function byteLength (string, encoding) {
879
945
  if (Buffer.isBuffer(string)) {
880
946
  return string.length
881
947
  }
882
- if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
948
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
883
949
  return string.byteLength
884
950
  }
885
951
  if (typeof string !== 'string') {
886
- string = '' + string
952
+ throw new TypeError(
953
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
954
+ 'Received type ' + typeof string
955
+ )
887
956
  }
888
957
 
889
958
  var len = string.length
890
- if (len === 0) return 0
959
+ var mustMatch = (arguments.length > 2 && arguments[2] === true)
960
+ if (!mustMatch && len === 0) return 0
891
961
 
892
962
  // Use a for loop to avoid recursion
893
963
  var loweredCase = false
@@ -899,7 +969,6 @@ function byteLength (string, encoding) {
899
969
  return len
900
970
  case 'utf8':
901
971
  case 'utf-8':
902
- case undefined:
903
972
  return utf8ToBytes(string).length
904
973
  case 'ucs2':
905
974
  case 'ucs-2':
@@ -911,7 +980,9 @@ function byteLength (string, encoding) {
911
980
  case 'base64':
912
981
  return base64ToBytes(string).length
913
982
  default:
914
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
983
+ if (loweredCase) {
984
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
985
+ }
915
986
  encoding = ('' + encoding).toLowerCase()
916
987
  loweredCase = true
917
988
  }
@@ -1058,16 +1129,20 @@ Buffer.prototype.equals = function equals (b) {
1058
1129
  Buffer.prototype.inspect = function inspect () {
1059
1130
  var str = ''
1060
1131
  var max = exports.INSPECT_MAX_BYTES
1061
- if (this.length > 0) {
1062
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
1063
- if (this.length > max) str += ' ... '
1064
- }
1132
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
1133
+ if (this.length > max) str += ' ... '
1065
1134
  return '<Buffer ' + str + '>'
1066
1135
  }
1067
1136
 
1068
1137
  Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
1138
+ if (isInstance(target, Uint8Array)) {
1139
+ target = Buffer.from(target, target.offset, target.byteLength)
1140
+ }
1069
1141
  if (!Buffer.isBuffer(target)) {
1070
- throw new TypeError('Argument must be a Buffer')
1142
+ throw new TypeError(
1143
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
1144
+ 'Received type ' + (typeof target)
1145
+ )
1071
1146
  }
1072
1147
 
1073
1148
  if (start === undefined) {
@@ -1146,7 +1221,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
1146
1221
  } else if (byteOffset < -0x80000000) {
1147
1222
  byteOffset = -0x80000000
1148
1223
  }
1149
- byteOffset = +byteOffset // Coerce to Number.
1224
+ byteOffset = +byteOffset // Coerce to Number.
1150
1225
  if (numberIsNaN(byteOffset)) {
1151
1226
  // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1152
1227
  byteOffset = dir ? 0 : (buffer.length - 1)
@@ -1398,8 +1473,8 @@ function utf8Slice (buf, start, end) {
1398
1473
  var codePoint = null
1399
1474
  var bytesPerSequence = (firstByte > 0xEF) ? 4
1400
1475
  : (firstByte > 0xDF) ? 3
1401
- : (firstByte > 0xBF) ? 2
1402
- : 1
1476
+ : (firstByte > 0xBF) ? 2
1477
+ : 1
1403
1478
 
1404
1479
  if (i + bytesPerSequence <= end) {
1405
1480
  var secondByte, thirdByte, fourthByte, tempCodePoint
@@ -2062,7 +2137,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
2062
2137
  } else {
2063
2138
  var bytes = Buffer.isBuffer(val)
2064
2139
  ? val
2065
- : new Buffer(val, encoding)
2140
+ : Buffer.from(val, encoding)
2066
2141
  var len = bytes.length
2067
2142
  if (len === 0) {
2068
2143
  throw new TypeError('The value "' + val +
@@ -2217,19 +2292,22 @@ function blitBuffer (src, dst, offset, length) {
2217
2292
  return i
2218
2293
  }
2219
2294
 
2220
- // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
2221
- // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
2222
- function isArrayBuffer (obj) {
2223
- return obj instanceof ArrayBuffer ||
2224
- (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
2225
- typeof obj.byteLength === 'number')
2295
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2296
+ // the `instanceof` check but they should be treated as of that type.
2297
+ // See: https://github.com/feross/buffer/issues/166
2298
+ function isInstance (obj, type) {
2299
+ return obj instanceof type ||
2300
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
2301
+ obj.constructor.name === type.name)
2226
2302
  }
2227
-
2228
2303
  function numberIsNaN (obj) {
2304
+ // For IE11 support
2229
2305
  return obj !== obj // eslint-disable-line no-self-compare
2230
2306
  }
2231
2307
 
2232
- },{"base64-js":4,"ieee754":6}],6:[function(require,module,exports){
2308
+ }).call(this)}).call(this,require("buffer").Buffer)
2309
+ },{"base64-js":4,"buffer":5,"ieee754":6}],6:[function(require,module,exports){
2310
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
2233
2311
  exports.read = function (buffer, offset, isLE, mLen, nBytes) {
2234
2312
  var e, m
2235
2313
  var eLen = (nBytes * 8) - mLen - 1
@@ -4887,266 +4965,261 @@ function isSlowBuffer (obj) {
4887
4965
  }).call(this);
4888
4966
 
4889
4967
  },{"./Utility":8,"./XMLDocument":18,"./XMLDocumentCB":19,"./XMLStreamWriter":24,"./XMLStringWriter":25}],30:[function(require,module,exports){
4890
- function DOMParser(options){
4891
- this.options = options ||{locator:{}};
4892
-
4893
- }
4894
- DOMParser.prototype.parseFromString = function(source,mimeType){
4895
- var options = this.options;
4896
- var sax = new XMLReader();
4897
- var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
4898
- var errorHandler = options.errorHandler;
4899
- var locator = options.locator;
4900
- var defaultNSMap = options.xmlns||{};
4901
- var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
4902
- if(locator){
4903
- domBuilder.setDocumentLocator(locator)
4904
- }
4905
-
4906
- sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
4907
- sax.domBuilder = options.domBuilder || domBuilder;
4908
- if(/\/x?html?$/.test(mimeType)){
4909
- entityMap.nbsp = '\xa0';
4910
- entityMap.copy = '\xa9';
4911
- defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
4912
- }
4913
- defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
4914
- if(source){
4915
- sax.parse(source,defaultNSMap,entityMap);
4916
- }else{
4917
- sax.errorHandler.error("invalid doc source");
4918
- }
4919
- return domBuilder.doc;
4920
- }
4921
- function buildErrorHandler(errorImpl,domBuilder,locator){
4922
- if(!errorImpl){
4923
- if(domBuilder instanceof DOMHandler){
4924
- return domBuilder;
4925
- }
4926
- errorImpl = domBuilder ;
4927
- }
4928
- var errorHandler = {}
4929
- var isCallback = errorImpl instanceof Function;
4930
- locator = locator||{}
4931
- function build(key){
4932
- var fn = errorImpl[key];
4933
- if(!fn && isCallback){
4934
- fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
4935
- }
4936
- errorHandler[key] = fn && function(msg){
4937
- fn('[xmldom '+key+']\t'+msg+_locator(locator));
4938
- }||function(){};
4939
- }
4940
- build('warning');
4941
- build('error');
4942
- build('fatalError');
4943
- return errorHandler;
4944
- }
4945
-
4946
- //console.log('#\n\n\n\n\n\n\n####')
4947
- /**
4948
- * +ContentHandler+ErrorHandler
4949
- * +LexicalHandler+EntityResolver2
4950
- * -DeclHandler-DTDHandler
4951
- *
4952
- * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
4953
- * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
4954
- * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
4955
- */
4956
- function DOMHandler() {
4957
- this.cdata = false;
4958
- }
4959
- function position(locator,node){
4960
- node.lineNumber = locator.lineNumber;
4961
- node.columnNumber = locator.columnNumber;
4962
- }
4963
- /**
4964
- * @see org.xml.sax.ContentHandler#startDocument
4965
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
4966
- */
4967
- DOMHandler.prototype = {
4968
- startDocument : function() {
4969
- this.doc = new DOMImplementation().createDocument(null, null, null);
4970
- if (this.locator) {
4971
- this.doc.documentURI = this.locator.systemId;
4972
- }
4973
- },
4974
- startElement:function(namespaceURI, localName, qName, attrs) {
4975
- var doc = this.doc;
4976
- var el = doc.createElementNS(namespaceURI, qName||localName);
4977
- var len = attrs.length;
4978
- appendElement(this, el);
4979
- this.currentElement = el;
4980
-
4981
- this.locator && position(this.locator,el)
4982
- for (var i = 0 ; i < len; i++) {
4983
- var namespaceURI = attrs.getURI(i);
4984
- var value = attrs.getValue(i);
4985
- var qName = attrs.getQName(i);
4986
- var attr = doc.createAttributeNS(namespaceURI, qName);
4987
- this.locator &&position(attrs.getLocator(i),attr);
4988
- attr.value = attr.nodeValue = value;
4989
- el.setAttributeNode(attr)
4990
- }
4991
- },
4992
- endElement:function(namespaceURI, localName, qName) {
4993
- var current = this.currentElement
4994
- var tagName = current.tagName;
4995
- this.currentElement = current.parentNode;
4996
- },
4997
- startPrefixMapping:function(prefix, uri) {
4998
- },
4999
- endPrefixMapping:function(prefix) {
5000
- },
5001
- processingInstruction:function(target, data) {
5002
- var ins = this.doc.createProcessingInstruction(target, data);
5003
- this.locator && position(this.locator,ins)
5004
- appendElement(this, ins);
5005
- },
5006
- ignorableWhitespace:function(ch, start, length) {
5007
- },
5008
- characters:function(chars, start, length) {
5009
- chars = _toString.apply(this,arguments)
5010
- //console.log(chars)
5011
- if(chars){
5012
- if (this.cdata) {
5013
- var charNode = this.doc.createCDATASection(chars);
5014
- } else {
5015
- var charNode = this.doc.createTextNode(chars);
5016
- }
5017
- if(this.currentElement){
5018
- this.currentElement.appendChild(charNode);
5019
- }else if(/^\s*$/.test(chars)){
5020
- this.doc.appendChild(charNode);
5021
- //process xml
5022
- }
5023
- this.locator && position(this.locator,charNode)
5024
- }
5025
- },
5026
- skippedEntity:function(name) {
5027
- },
5028
- endDocument:function() {
5029
- this.doc.normalize();
5030
- },
5031
- setDocumentLocator:function (locator) {
5032
- if(this.locator = locator){// && !('lineNumber' in locator)){
5033
- locator.lineNumber = 0;
5034
- }
5035
- },
5036
- //LexicalHandler
5037
- comment:function(chars, start, length) {
5038
- chars = _toString.apply(this,arguments)
5039
- var comm = this.doc.createComment(chars);
5040
- this.locator && position(this.locator,comm)
5041
- appendElement(this, comm);
5042
- },
5043
-
5044
- startCDATA:function() {
5045
- //used in characters() methods
5046
- this.cdata = true;
5047
- },
5048
- endCDATA:function() {
5049
- this.cdata = false;
5050
- },
5051
-
5052
- startDTD:function(name, publicId, systemId) {
5053
- var impl = this.doc.implementation;
5054
- if (impl && impl.createDocumentType) {
5055
- var dt = impl.createDocumentType(name, publicId, systemId);
5056
- this.locator && position(this.locator,dt)
5057
- appendElement(this, dt);
5058
- }
5059
- },
5060
- /**
5061
- * @see org.xml.sax.ErrorHandler
5062
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
5063
- */
5064
- warning:function(error) {
5065
- console.warn('[xmldom warning]\t'+error,_locator(this.locator));
5066
- },
5067
- error:function(error) {
5068
- console.error('[xmldom error]\t'+error,_locator(this.locator));
5069
- },
5070
- fatalError:function(error) {
5071
- console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
5072
- throw error;
5073
- }
5074
- }
5075
- function _locator(l){
5076
- if(l){
5077
- return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
5078
- }
5079
- }
5080
- function _toString(chars,start,length){
5081
- if(typeof chars == 'string'){
5082
- return chars.substr(start,length)
5083
- }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
5084
- if(chars.length >= start+length || start){
5085
- return new java.lang.String(chars,start,length)+'';
5086
- }
5087
- return chars;
5088
- }
5089
- }
5090
-
5091
- /*
5092
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
5093
- * used method of org.xml.sax.ext.LexicalHandler:
5094
- * #comment(chars, start, length)
5095
- * #startCDATA()
5096
- * #endCDATA()
5097
- * #startDTD(name, publicId, systemId)
5098
- *
5099
- *
5100
- * IGNORED method of org.xml.sax.ext.LexicalHandler:
5101
- * #endDTD()
5102
- * #startEntity(name)
5103
- * #endEntity(name)
5104
- *
5105
- *
5106
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
5107
- * IGNORED method of org.xml.sax.ext.DeclHandler
5108
- * #attributeDecl(eName, aName, type, mode, value)
5109
- * #elementDecl(name, model)
5110
- * #externalEntityDecl(name, publicId, systemId)
5111
- * #internalEntityDecl(name, value)
5112
- * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
5113
- * IGNORED method of org.xml.sax.EntityResolver2
5114
- * #resolveEntity(String name,String publicId,String baseURI,String systemId)
5115
- * #resolveEntity(publicId, systemId)
5116
- * #getExternalSubset(name, baseURI)
5117
- * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
5118
- * IGNORED method of org.xml.sax.DTDHandler
5119
- * #notationDecl(name, publicId, systemId) {};
5120
- * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
5121
- */
5122
- "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
5123
- DOMHandler.prototype[key] = function(){return null}
5124
- })
5125
-
5126
- /* 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 */
5127
- function appendElement (hander,node) {
5128
- if (!hander.currentElement) {
5129
- hander.doc.appendChild(node);
5130
- } else {
5131
- hander.currentElement.appendChild(node);
5132
- }
5133
- }//appendChild and setAttributeNS are preformance key
5134
-
5135
- //if(typeof require == 'function'){
5136
- var XMLReader = require('./sax').XMLReader;
5137
- var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
5138
- exports.XMLSerializer = require('./dom').XMLSerializer ;
5139
- exports.DOMParser = DOMParser;
5140
- //}
5141
-
5142
- },{"./dom":31,"./sax":32}],31:[function(require,module,exports){
4968
+ function DOMParser(options){
4969
+ this.options = options ||{locator:{}};
4970
+ }
4971
+
4972
+ DOMParser.prototype.parseFromString = function(source,mimeType){
4973
+ var options = this.options;
4974
+ var sax = new XMLReader();
4975
+ var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
4976
+ var errorHandler = options.errorHandler;
4977
+ var locator = options.locator;
4978
+ var defaultNSMap = options.xmlns||{};
4979
+ var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
4980
+ var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
4981
+ if(locator){
4982
+ domBuilder.setDocumentLocator(locator)
4983
+ }
4984
+
4985
+ sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
4986
+ sax.domBuilder = options.domBuilder || domBuilder;
4987
+ if(isHTML){
4988
+ defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
4989
+ }
4990
+ defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
4991
+ if(source && typeof source === 'string'){
4992
+ sax.parse(source,defaultNSMap,entityMap);
4993
+ }else{
4994
+ sax.errorHandler.error("invalid doc source");
4995
+ }
4996
+ return domBuilder.doc;
4997
+ }
4998
+ function buildErrorHandler(errorImpl,domBuilder,locator){
4999
+ if(!errorImpl){
5000
+ if(domBuilder instanceof DOMHandler){
5001
+ return domBuilder;
5002
+ }
5003
+ errorImpl = domBuilder ;
5004
+ }
5005
+ var errorHandler = {}
5006
+ var isCallback = errorImpl instanceof Function;
5007
+ locator = locator||{}
5008
+ function build(key){
5009
+ var fn = errorImpl[key];
5010
+ if(!fn && isCallback){
5011
+ fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
5012
+ }
5013
+ errorHandler[key] = fn && function(msg){
5014
+ fn('[xmldom '+key+']\t'+msg+_locator(locator));
5015
+ }||function(){};
5016
+ }
5017
+ build('warning');
5018
+ build('error');
5019
+ build('fatalError');
5020
+ return errorHandler;
5021
+ }
5022
+
5023
+ //console.log('#\n\n\n\n\n\n\n####')
5024
+ /**
5025
+ * +ContentHandler+ErrorHandler
5026
+ * +LexicalHandler+EntityResolver2
5027
+ * -DeclHandler-DTDHandler
5028
+ *
5029
+ * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
5030
+ * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
5031
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
5032
+ */
5033
+ function DOMHandler() {
5034
+ this.cdata = false;
5035
+ }
5036
+ function position(locator,node){
5037
+ node.lineNumber = locator.lineNumber;
5038
+ node.columnNumber = locator.columnNumber;
5039
+ }
5040
+ /**
5041
+ * @see org.xml.sax.ContentHandler#startDocument
5042
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
5043
+ */
5044
+ DOMHandler.prototype = {
5045
+ startDocument : function() {
5046
+ this.doc = new DOMImplementation().createDocument(null, null, null);
5047
+ if (this.locator) {
5048
+ this.doc.documentURI = this.locator.systemId;
5049
+ }
5050
+ },
5051
+ startElement:function(namespaceURI, localName, qName, attrs) {
5052
+ var doc = this.doc;
5053
+ var el = doc.createElementNS(namespaceURI, qName||localName);
5054
+ var len = attrs.length;
5055
+ appendElement(this, el);
5056
+ this.currentElement = el;
5057
+
5058
+ this.locator && position(this.locator,el)
5059
+ for (var i = 0 ; i < len; i++) {
5060
+ var namespaceURI = attrs.getURI(i);
5061
+ var value = attrs.getValue(i);
5062
+ var qName = attrs.getQName(i);
5063
+ var attr = doc.createAttributeNS(namespaceURI, qName);
5064
+ this.locator &&position(attrs.getLocator(i),attr);
5065
+ attr.value = attr.nodeValue = value;
5066
+ el.setAttributeNode(attr)
5067
+ }
5068
+ },
5069
+ endElement:function(namespaceURI, localName, qName) {
5070
+ var current = this.currentElement
5071
+ var tagName = current.tagName;
5072
+ this.currentElement = current.parentNode;
5073
+ },
5074
+ startPrefixMapping:function(prefix, uri) {
5075
+ },
5076
+ endPrefixMapping:function(prefix) {
5077
+ },
5078
+ processingInstruction:function(target, data) {
5079
+ var ins = this.doc.createProcessingInstruction(target, data);
5080
+ this.locator && position(this.locator,ins)
5081
+ appendElement(this, ins);
5082
+ },
5083
+ ignorableWhitespace:function(ch, start, length) {
5084
+ },
5085
+ characters:function(chars, start, length) {
5086
+ chars = _toString.apply(this,arguments)
5087
+ //console.log(chars)
5088
+ if(chars){
5089
+ if (this.cdata) {
5090
+ var charNode = this.doc.createCDATASection(chars);
5091
+ } else {
5092
+ var charNode = this.doc.createTextNode(chars);
5093
+ }
5094
+ if(this.currentElement){
5095
+ this.currentElement.appendChild(charNode);
5096
+ }else if(/^\s*$/.test(chars)){
5097
+ this.doc.appendChild(charNode);
5098
+ //process xml
5099
+ }
5100
+ this.locator && position(this.locator,charNode)
5101
+ }
5102
+ },
5103
+ skippedEntity:function(name) {
5104
+ },
5105
+ endDocument:function() {
5106
+ this.doc.normalize();
5107
+ },
5108
+ setDocumentLocator:function (locator) {
5109
+ if(this.locator = locator){// && !('lineNumber' in locator)){
5110
+ locator.lineNumber = 0;
5111
+ }
5112
+ },
5113
+ //LexicalHandler
5114
+ comment:function(chars, start, length) {
5115
+ chars = _toString.apply(this,arguments)
5116
+ var comm = this.doc.createComment(chars);
5117
+ this.locator && position(this.locator,comm)
5118
+ appendElement(this, comm);
5119
+ },
5120
+
5121
+ startCDATA:function() {
5122
+ //used in characters() methods
5123
+ this.cdata = true;
5124
+ },
5125
+ endCDATA:function() {
5126
+ this.cdata = false;
5127
+ },
5128
+
5129
+ startDTD:function(name, publicId, systemId) {
5130
+ var impl = this.doc.implementation;
5131
+ if (impl && impl.createDocumentType) {
5132
+ var dt = impl.createDocumentType(name, publicId, systemId);
5133
+ this.locator && position(this.locator,dt)
5134
+ appendElement(this, dt);
5135
+ }
5136
+ },
5137
+ /**
5138
+ * @see org.xml.sax.ErrorHandler
5139
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
5140
+ */
5141
+ warning:function(error) {
5142
+ console.warn('[xmldom warning]\t'+error,_locator(this.locator));
5143
+ },
5144
+ error:function(error) {
5145
+ console.error('[xmldom error]\t'+error,_locator(this.locator));
5146
+ },
5147
+ fatalError:function(error) {
5148
+ throw new ParseError(error, this.locator);
5149
+ }
5150
+ }
5151
+ function _locator(l){
5152
+ if(l){
5153
+ return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
5154
+ }
5155
+ }
5156
+ function _toString(chars,start,length){
5157
+ if(typeof chars == 'string'){
5158
+ return chars.substr(start,length)
5159
+ }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
5160
+ if(chars.length >= start+length || start){
5161
+ return new java.lang.String(chars,start,length)+'';
5162
+ }
5163
+ return chars;
5164
+ }
5165
+ }
5166
+
5143
5167
  /*
5144
- * DOM Level 2
5145
- * Object DOMException
5146
- * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
5147
- * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
5168
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
5169
+ * used method of org.xml.sax.ext.LexicalHandler:
5170
+ * #comment(chars, start, length)
5171
+ * #startCDATA()
5172
+ * #endCDATA()
5173
+ * #startDTD(name, publicId, systemId)
5174
+ *
5175
+ *
5176
+ * IGNORED method of org.xml.sax.ext.LexicalHandler:
5177
+ * #endDTD()
5178
+ * #startEntity(name)
5179
+ * #endEntity(name)
5180
+ *
5181
+ *
5182
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
5183
+ * IGNORED method of org.xml.sax.ext.DeclHandler
5184
+ * #attributeDecl(eName, aName, type, mode, value)
5185
+ * #elementDecl(name, model)
5186
+ * #externalEntityDecl(name, publicId, systemId)
5187
+ * #internalEntityDecl(name, value)
5188
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
5189
+ * IGNORED method of org.xml.sax.EntityResolver2
5190
+ * #resolveEntity(String name,String publicId,String baseURI,String systemId)
5191
+ * #resolveEntity(publicId, systemId)
5192
+ * #getExternalSubset(name, baseURI)
5193
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
5194
+ * IGNORED method of org.xml.sax.DTDHandler
5195
+ * #notationDecl(name, publicId, systemId) {};
5196
+ * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
5148
5197
  */
5198
+ "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
5199
+ DOMHandler.prototype[key] = function(){return null}
5200
+ })
5149
5201
 
5202
+ /* 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 */
5203
+ function appendElement (hander,node) {
5204
+ if (!hander.currentElement) {
5205
+ hander.doc.appendChild(node);
5206
+ } else {
5207
+ hander.currentElement.appendChild(node);
5208
+ }
5209
+ }//appendChild and setAttributeNS are preformance key
5210
+
5211
+ //if(typeof require == 'function'){
5212
+ var htmlEntity = require('./entities');
5213
+ var sax = require('./sax');
5214
+ var XMLReader = sax.XMLReader;
5215
+ var ParseError = sax.ParseError;
5216
+ var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
5217
+ exports.XMLSerializer = require('./dom').XMLSerializer ;
5218
+ exports.DOMParser = DOMParser;
5219
+ exports.__DOMHandler = DOMHandler;
5220
+ //}
5221
+
5222
+ },{"./dom":31,"./entities":32,"./sax":33}],31:[function(require,module,exports){
5150
5223
  function copy(src,dest){
5151
5224
  for(var p in src){
5152
5225
  dest[p] = src[p];
@@ -5158,10 +5231,6 @@ function copy(src,dest){
5158
5231
  */
5159
5232
  function _extends(Class,Super){
5160
5233
  var pt = Class.prototype;
5161
- if(Object.create){
5162
- var ppt = Object.create(Super.prototype)
5163
- pt.__proto__ = ppt;
5164
- }
5165
5234
  if(!(pt instanceof Super)){
5166
5235
  function t(){};
5167
5236
  t.prototype = Super.prototype;
@@ -5212,7 +5281,12 @@ var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((Exce
5212
5281
  var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
5213
5282
  var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
5214
5283
 
5215
-
5284
+ /**
5285
+ * DOM Level 2
5286
+ * Object DOMException
5287
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
5288
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
5289
+ */
5216
5290
  function DOMException(code, message) {
5217
5291
  if(message instanceof Error){
5218
5292
  var error = message;
@@ -5754,6 +5828,21 @@ Document.prototype = {
5754
5828
  return rtv;
5755
5829
  },
5756
5830
 
5831
+ getElementsByClassName: function(className) {
5832
+ var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
5833
+ return new LiveNodeList(this, function(base) {
5834
+ var ls = [];
5835
+ _visitNode(base.documentElement, function(node) {
5836
+ if(node !== base && node.nodeType == ELEMENT_NODE) {
5837
+ if(pattern.test(node.getAttribute('class'))) {
5838
+ ls.push(node);
5839
+ }
5840
+ }
5841
+ });
5842
+ return ls;
5843
+ });
5844
+ },
5845
+
5757
5846
  //document factory method:
5758
5847
  createElement : function(tagName){
5759
5848
  var node = new Element();
@@ -6058,7 +6147,7 @@ XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
6058
6147
  Node.prototype.toString = nodeSerializeToString;
6059
6148
  function nodeSerializeToString(isHtml,nodeFilter){
6060
6149
  var buf = [];
6061
- var refNode = this.nodeType == 9?this.documentElement:this;
6150
+ var refNode = this.nodeType == 9 && this.documentElement || this;
6062
6151
  var prefix = refNode.prefix;
6063
6152
  var uri = refNode.namespaceURI;
6064
6153
 
@@ -6197,9 +6286,27 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
6197
6286
  }
6198
6287
  return;
6199
6288
  case ATTRIBUTE_NODE:
6200
- return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
6289
+ return buf.push(' ',node.name,'="',node.value.replace(/[&"]/g,_xmlEncoder),'"');
6201
6290
  case TEXT_NODE:
6202
- return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
6291
+ /**
6292
+ * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
6293
+ * except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section.
6294
+ * If they are needed elsewhere, they must be escaped using either numeric character references or the strings
6295
+ * `&amp;` and `&lt;` respectively.
6296
+ * The right angle bracket (>) may be represented using the string " &gt; ", and must, for compatibility,
6297
+ * be escaped using either `&gt;` or a character reference when it appears in the string `]]>` in content,
6298
+ * when that string is not marking the end of a CDATA section.
6299
+ *
6300
+ * In the content of elements, character data is any string of characters
6301
+ * which does not contain the start-delimiter of any markup
6302
+ * and does not include the CDATA-section-close delimiter, `]]>`.
6303
+ *
6304
+ * @see https://www.w3.org/TR/xml/#NT-CharData
6305
+ */
6306
+ return buf.push(node.data
6307
+ .replace(/[<&]/g,_xmlEncoder)
6308
+ .replace(/]]>/g, ']]&gt;')
6309
+ );
6203
6310
  case CDATA_SECTION_NODE:
6204
6311
  return buf.push( '<![CDATA[',node.data,']]>');
6205
6312
  case COMMENT_NODE:
@@ -6209,13 +6316,13 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
6209
6316
  var sysid = node.systemId;
6210
6317
  buf.push('<!DOCTYPE ',node.name);
6211
6318
  if(pubid){
6212
- buf.push(' PUBLIC "',pubid);
6319
+ buf.push(' PUBLIC ', pubid);
6213
6320
  if (sysid && sysid!='.') {
6214
- buf.push( '" "',sysid);
6321
+ buf.push(' ', sysid);
6215
6322
  }
6216
- buf.push('">');
6323
+ buf.push('>');
6217
6324
  }else if(sysid && sysid!='.'){
6218
- buf.push(' SYSTEM "',sysid,'">');
6325
+ buf.push(' SYSTEM ', sysid, '>');
6219
6326
  }else{
6220
6327
  var sub = node.internalSubset;
6221
6328
  if(sub){
@@ -6381,644 +6488,904 @@ try{
6381
6488
  }
6382
6489
 
6383
6490
  //if(typeof require == 'function'){
6491
+ exports.Node = Node;
6492
+ exports.DOMException = DOMException;
6384
6493
  exports.DOMImplementation = DOMImplementation;
6385
6494
  exports.XMLSerializer = XMLSerializer;
6386
6495
  //}
6387
6496
 
6388
6497
  },{}],32:[function(require,module,exports){
6389
- //[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]
6390
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
6391
- //[5] Name ::= NameStartChar (NameChar)*
6392
- 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
6393
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
6394
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
6395
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
6396
- //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(',')
6397
-
6398
- //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
6399
- //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
6400
- var S_TAG = 0;//tag name offerring
6401
- var S_ATTR = 1;//attr name offerring
6402
- var S_ATTR_SPACE=2;//attr name end and space offer
6403
- var S_EQ = 3;//=space?
6404
- var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
6405
- var S_ATTR_END = 5;//attr value end and no space(quot end)
6406
- var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
6407
- var S_TAG_CLOSE = 7;//closed el<el />
6408
-
6409
- function XMLReader(){
6410
-
6411
- }
6412
-
6413
- XMLReader.prototype = {
6414
- parse:function(source,defaultNSMap,entityMap){
6415
- var domBuilder = this.domBuilder;
6416
- domBuilder.startDocument();
6417
- _copy(defaultNSMap ,defaultNSMap = {})
6418
- parse(source,defaultNSMap,entityMap,
6419
- domBuilder,this.errorHandler);
6420
- domBuilder.endDocument();
6421
- }
6422
- }
6423
- function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
6424
- function fixedFromCharCode(code) {
6425
- // String.prototype.fromCharCode does not supports
6426
- // > 2 bytes unicode chars directly
6427
- if (code > 0xffff) {
6428
- code -= 0x10000;
6429
- var surrogate1 = 0xd800 + (code >> 10)
6430
- , surrogate2 = 0xdc00 + (code & 0x3ff);
6431
-
6432
- return String.fromCharCode(surrogate1, surrogate2);
6433
- } else {
6434
- return String.fromCharCode(code);
6435
- }
6436
- }
6437
- function entityReplacer(a){
6438
- var k = a.slice(1,-1);
6439
- if(k in entityMap){
6440
- return entityMap[k];
6441
- }else if(k.charAt(0) === '#'){
6442
- return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
6443
- }else{
6444
- errorHandler.error('entity not found:'+a);
6445
- return a;
6446
- }
6447
- }
6448
- function appendText(end){//has some bugs
6449
- if(end>start){
6450
- var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
6451
- locator&&position(start);
6452
- domBuilder.characters(xt,0,end-start);
6453
- start = end
6454
- }
6455
- }
6456
- function position(p,m){
6457
- while(p>=lineEnd && (m = linePattern.exec(source))){
6458
- lineStart = m.index;
6459
- lineEnd = lineStart + m[0].length;
6460
- locator.lineNumber++;
6461
- //console.log('line++:',locator,startPos,endPos)
6462
- }
6463
- locator.columnNumber = p-lineStart+1;
6464
- }
6465
- var lineStart = 0;
6466
- var lineEnd = 0;
6467
- var linePattern = /.*(?:\r\n?|\n)|.*$/g
6468
- var locator = domBuilder.locator;
6469
-
6470
- var parseStack = [{currentNSMap:defaultNSMapCopy}]
6471
- var closeMap = {};
6472
- var start = 0;
6473
- while(true){
6474
- try{
6475
- var tagStart = source.indexOf('<',start);
6476
- if(tagStart<0){
6477
- if(!source.substr(start).match(/^\s*$/)){
6478
- var doc = domBuilder.doc;
6479
- var text = doc.createTextNode(source.substr(start));
6480
- doc.appendChild(text);
6481
- domBuilder.currentElement = text;
6482
- }
6483
- return;
6484
- }
6485
- if(tagStart>start){
6486
- appendText(tagStart);
6487
- }
6488
- switch(source.charAt(tagStart+1)){
6489
- case '/':
6490
- var end = source.indexOf('>',tagStart+3);
6491
- var tagName = source.substring(tagStart+2,end);
6492
- var config = parseStack.pop();
6493
- if(end<0){
6494
-
6495
- tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
6496
- //console.error('#@@@@@@'+tagName)
6497
- errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
6498
- end = tagStart+1+tagName.length;
6499
- }else if(tagName.match(/\s</)){
6500
- tagName = tagName.replace(/[\s<].*/,'');
6501
- errorHandler.error("end tag name: "+tagName+' maybe not complete');
6502
- end = tagStart+1+tagName.length;
6503
- }
6504
- //console.error(parseStack.length,parseStack)
6505
- //console.error(config);
6506
- var localNSMap = config.localNSMap;
6507
- var endMatch = config.tagName == tagName;
6508
- var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
6509
- if(endIgnoreCaseMach){
6510
- domBuilder.endElement(config.uri,config.localName,tagName);
6511
- if(localNSMap){
6512
- for(var prefix in localNSMap){
6513
- domBuilder.endPrefixMapping(prefix) ;
6514
- }
6515
- }
6516
- if(!endMatch){
6517
- errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
6518
- }
6519
- }else{
6520
- parseStack.push(config)
6521
- }
6522
-
6523
- end++;
6524
- break;
6525
- // end elment
6526
- case '?':// <?...?>
6527
- locator&&position(tagStart);
6528
- end = parseInstruction(source,tagStart,domBuilder);
6529
- break;
6530
- case '!':// <!doctype,<![CDATA,<!--
6531
- locator&&position(tagStart);
6532
- end = parseDCC(source,tagStart,domBuilder,errorHandler);
6533
- break;
6534
- default:
6535
- locator&&position(tagStart);
6536
- var el = new ElementAttributes();
6537
- var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
6538
- //elStartEnd
6539
- var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
6540
- var len = el.length;
6541
-
6542
-
6543
- if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
6544
- el.closed = true;
6545
- if(!entityMap.nbsp){
6546
- errorHandler.warning('unclosed xml attribute');
6547
- }
6548
- }
6549
- if(locator && len){
6550
- var locator2 = copyLocator(locator,{});
6551
- //try{//attribute position fixed
6552
- for(var i = 0;i<len;i++){
6553
- var a = el[i];
6554
- position(a.offset);
6555
- a.locator = copyLocator(locator,{});
6556
- }
6557
- //}catch(e){console.error('@@@@@'+e)}
6558
- domBuilder.locator = locator2
6559
- if(appendElement(el,domBuilder,currentNSMap)){
6560
- parseStack.push(el)
6561
- }
6562
- domBuilder.locator = locator;
6563
- }else{
6564
- if(appendElement(el,domBuilder,currentNSMap)){
6565
- parseStack.push(el)
6566
- }
6567
- }
6568
-
6569
-
6570
-
6571
- if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
6572
- end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
6573
- }else{
6574
- end++;
6575
- }
6576
- }
6577
- }catch(e){
6578
- errorHandler.error('element parse error: '+e)
6579
- //errorHandler.error('element parse error: '+e);
6580
- end = -1;
6581
- //throw e;
6582
- }
6583
- if(end>start){
6584
- start = end;
6585
- }else{
6586
- //TODO: 这里有可能sax回退,有位置错误风险
6587
- appendText(Math.max(tagStart,start)+1);
6588
- }
6589
- }
6590
- }
6591
- function copyLocator(f,t){
6592
- t.lineNumber = f.lineNumber;
6593
- t.columnNumber = f.columnNumber;
6594
- return t;
6595
- }
6596
-
6597
- /**
6598
- * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
6599
- * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
6600
- */
6601
- function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
6602
- var attrName;
6603
- var value;
6604
- var p = ++start;
6605
- var s = S_TAG;//status
6606
- while(true){
6607
- var c = source.charAt(p);
6608
- switch(c){
6609
- case '=':
6610
- if(s === S_ATTR){//attrName
6611
- attrName = source.slice(start,p);
6612
- s = S_EQ;
6613
- }else if(s === S_ATTR_SPACE){
6614
- s = S_EQ;
6615
- }else{
6616
- //fatalError: equal must after attrName or space after attrName
6617
- throw new Error('attribute equal must after attrName');
6618
- }
6619
- break;
6620
- case '\'':
6621
- case '"':
6622
- if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
6623
- ){//equal
6624
- if(s === S_ATTR){
6625
- errorHandler.warning('attribute value must after "="')
6626
- attrName = source.slice(start,p)
6627
- }
6628
- start = p+1;
6629
- p = source.indexOf(c,start)
6630
- if(p>0){
6631
- value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
6632
- el.add(attrName,value,start-1);
6633
- s = S_ATTR_END;
6634
- }else{
6635
- //fatalError: no end quot match
6636
- throw new Error('attribute value no end \''+c+'\' match');
6637
- }
6638
- }else if(s == S_ATTR_NOQUOT_VALUE){
6639
- value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
6640
- //console.log(attrName,value,start,p)
6641
- el.add(attrName,value,start);
6642
- //console.dir(el)
6643
- errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
6644
- start = p+1;
6645
- s = S_ATTR_END
6646
- }else{
6647
- //fatalError: no equal before
6648
- throw new Error('attribute value must after "="');
6649
- }
6650
- break;
6651
- case '/':
6652
- switch(s){
6653
- case S_TAG:
6654
- el.setTagName(source.slice(start,p));
6655
- case S_ATTR_END:
6656
- case S_TAG_SPACE:
6657
- case S_TAG_CLOSE:
6658
- s =S_TAG_CLOSE;
6659
- el.closed = true;
6660
- case S_ATTR_NOQUOT_VALUE:
6661
- case S_ATTR:
6662
- case S_ATTR_SPACE:
6663
- break;
6664
- //case S_EQ:
6665
- default:
6666
- throw new Error("attribute invalid close char('/')")
6667
- }
6668
- break;
6669
- case ''://end document
6670
- //throw new Error('unexpected end of input')
6671
- errorHandler.error('unexpected end of input');
6672
- if(s == S_TAG){
6673
- el.setTagName(source.slice(start,p));
6674
- }
6675
- return p;
6676
- case '>':
6677
- switch(s){
6678
- case S_TAG:
6679
- el.setTagName(source.slice(start,p));
6680
- case S_ATTR_END:
6681
- case S_TAG_SPACE:
6682
- case S_TAG_CLOSE:
6683
- break;//normal
6684
- case S_ATTR_NOQUOT_VALUE://Compatible state
6685
- case S_ATTR:
6686
- value = source.slice(start,p);
6687
- if(value.slice(-1) === '/'){
6688
- el.closed = true;
6689
- value = value.slice(0,-1)
6690
- }
6691
- case S_ATTR_SPACE:
6692
- if(s === S_ATTR_SPACE){
6693
- value = attrName;
6694
- }
6695
- if(s == S_ATTR_NOQUOT_VALUE){
6696
- errorHandler.warning('attribute "'+value+'" missed quot(")!!');
6697
- el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
6698
- }else{
6699
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
6700
- errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
6701
- }
6702
- el.add(value,value,start)
6703
- }
6704
- break;
6705
- case S_EQ:
6706
- throw new Error('attribute value missed!!');
6707
- }
6708
- // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
6709
- return p;
6710
- /*xml space '\x20' | #x9 | #xD | #xA; */
6711
- case '\u0080':
6712
- c = ' ';
6713
- default:
6714
- if(c<= ' '){//space
6715
- switch(s){
6716
- case S_TAG:
6717
- el.setTagName(source.slice(start,p));//tagName
6718
- s = S_TAG_SPACE;
6719
- break;
6720
- case S_ATTR:
6721
- attrName = source.slice(start,p)
6722
- s = S_ATTR_SPACE;
6723
- break;
6724
- case S_ATTR_NOQUOT_VALUE:
6725
- var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
6726
- errorHandler.warning('attribute "'+value+'" missed quot(")!!');
6727
- el.add(attrName,value,start)
6728
- case S_ATTR_END:
6729
- s = S_TAG_SPACE;
6730
- break;
6731
- //case S_TAG_SPACE:
6732
- //case S_EQ:
6733
- //case S_ATTR_SPACE:
6734
- // void();break;
6735
- //case S_TAG_CLOSE:
6736
- //ignore warning
6737
- }
6738
- }else{//not space
6739
- //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
6740
- //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
6741
- switch(s){
6742
- //case S_TAG:void();break;
6743
- //case S_ATTR:void();break;
6744
- //case S_ATTR_NOQUOT_VALUE:void();break;
6745
- case S_ATTR_SPACE:
6746
- var tagName = el.tagName;
6747
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
6748
- errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
6749
- }
6750
- el.add(attrName,attrName,start);
6751
- start = p;
6752
- s = S_ATTR;
6753
- break;
6754
- case S_ATTR_END:
6755
- errorHandler.warning('attribute space is required"'+attrName+'"!!')
6756
- case S_TAG_SPACE:
6757
- s = S_ATTR;
6758
- start = p;
6759
- break;
6760
- case S_EQ:
6761
- s = S_ATTR_NOQUOT_VALUE;
6762
- start = p;
6763
- break;
6764
- case S_TAG_CLOSE:
6765
- throw new Error("elements closed character '/' and '>' must be connected to");
6766
- }
6767
- }
6768
- }//end outer switch
6769
- //console.log('p++',p)
6770
- p++;
6771
- }
6772
- }
6773
- /**
6774
- * @return true if has new namespace define
6775
- */
6776
- function appendElement(el,domBuilder,currentNSMap){
6777
- var tagName = el.tagName;
6778
- var localNSMap = null;
6779
- //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
6780
- var i = el.length;
6781
- while(i--){
6782
- var a = el[i];
6783
- var qName = a.qName;
6784
- var value = a.value;
6785
- var nsp = qName.indexOf(':');
6786
- if(nsp>0){
6787
- var prefix = a.prefix = qName.slice(0,nsp);
6788
- var localName = qName.slice(nsp+1);
6789
- var nsPrefix = prefix === 'xmlns' && localName
6790
- }else{
6791
- localName = qName;
6792
- prefix = null
6793
- nsPrefix = qName === 'xmlns' && ''
6794
- }
6795
- //can not set prefix,because prefix !== ''
6796
- a.localName = localName ;
6797
- //prefix == null for no ns prefix attribute
6798
- if(nsPrefix !== false){//hack!!
6799
- if(localNSMap == null){
6800
- localNSMap = {}
6801
- //console.log(currentNSMap,0)
6802
- _copy(currentNSMap,currentNSMap={})
6803
- //console.log(currentNSMap,1)
6804
- }
6805
- currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
6806
- a.uri = 'http://www.w3.org/2000/xmlns/'
6807
- domBuilder.startPrefixMapping(nsPrefix, value)
6808
- }
6809
- }
6810
- var i = el.length;
6811
- while(i--){
6812
- a = el[i];
6813
- var prefix = a.prefix;
6814
- if(prefix){//no prefix attribute has no namespace
6815
- if(prefix === 'xml'){
6816
- a.uri = 'http://www.w3.org/XML/1998/namespace';
6817
- }if(prefix !== 'xmlns'){
6818
- a.uri = currentNSMap[prefix || '']
6819
-
6820
- //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
6821
- }
6822
- }
6823
- }
6824
- var nsp = tagName.indexOf(':');
6825
- if(nsp>0){
6826
- prefix = el.prefix = tagName.slice(0,nsp);
6827
- localName = el.localName = tagName.slice(nsp+1);
6828
- }else{
6829
- prefix = null;//important!!
6830
- localName = el.localName = tagName;
6831
- }
6832
- //no prefix element has default namespace
6833
- var ns = el.uri = currentNSMap[prefix || ''];
6834
- domBuilder.startElement(ns,localName,tagName,el);
6835
- //endPrefixMapping and startPrefixMapping have not any help for dom builder
6836
- //localNSMap = null
6837
- if(el.closed){
6838
- domBuilder.endElement(ns,localName,tagName);
6839
- if(localNSMap){
6840
- for(prefix in localNSMap){
6841
- domBuilder.endPrefixMapping(prefix)
6842
- }
6843
- }
6844
- }else{
6845
- el.currentNSMap = currentNSMap;
6846
- el.localNSMap = localNSMap;
6847
- //parseStack.push(el);
6848
- return true;
6849
- }
6850
- }
6851
- function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
6852
- if(/^(?:script|textarea)$/i.test(tagName)){
6853
- var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
6854
- var text = source.substring(elStartEnd+1,elEndStart);
6855
- if(/[&<]/.test(text)){
6856
- if(/^script$/i.test(tagName)){
6857
- //if(!/\]\]>/.test(text)){
6858
- //lexHandler.startCDATA();
6859
- domBuilder.characters(text,0,text.length);
6860
- //lexHandler.endCDATA();
6861
- return elEndStart;
6862
- //}
6863
- }//}else{//text area
6864
- text = text.replace(/&#?\w+;/g,entityReplacer);
6865
- domBuilder.characters(text,0,text.length);
6866
- return elEndStart;
6867
- //}
6868
-
6869
- }
6870
- }
6871
- return elStartEnd+1;
6872
- }
6873
- function fixSelfClosed(source,elStartEnd,tagName,closeMap){
6874
- //if(tagName in closeMap){
6875
- var pos = closeMap[tagName];
6876
- if(pos == null){
6877
- //console.log(tagName)
6878
- pos = source.lastIndexOf('</'+tagName+'>')
6879
- if(pos<elStartEnd){//忘记闭合
6880
- pos = source.lastIndexOf('</'+tagName)
6881
- }
6882
- closeMap[tagName] =pos
6883
- }
6884
- return pos<elStartEnd;
6885
- //}
6886
- }
6887
- function _copy(source,target){
6888
- for(var n in source){target[n] = source[n]}
6889
- }
6890
- function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
6891
- var next= source.charAt(start+2)
6892
- switch(next){
6893
- case '-':
6894
- if(source.charAt(start + 3) === '-'){
6895
- var end = source.indexOf('-->',start+4);
6896
- //append comment source.substring(4,end)//<!--
6897
- if(end>start){
6898
- domBuilder.comment(source,start+4,end-start-4);
6899
- return end+3;
6900
- }else{
6901
- errorHandler.error("Unclosed comment");
6902
- return -1;
6903
- }
6904
- }else{
6905
- //error
6906
- return -1;
6907
- }
6908
- default:
6909
- if(source.substr(start+3,6) == 'CDATA['){
6910
- var end = source.indexOf(']]>',start+9);
6911
- domBuilder.startCDATA();
6912
- domBuilder.characters(source,start+9,end-start-9);
6913
- domBuilder.endCDATA()
6914
- return end+3;
6915
- }
6916
- //<!DOCTYPE
6917
- //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
6918
- var matchs = split(source,start);
6919
- var len = matchs.length;
6920
- if(len>1 && /!doctype/i.test(matchs[0][0])){
6921
- var name = matchs[1][0];
6922
- var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
6923
- var sysid = len>4 && matchs[4][0];
6924
- var lastMatch = matchs[len-1]
6925
- domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
6926
- sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
6927
- domBuilder.endDTD();
6928
-
6929
- return lastMatch.index+lastMatch[0].length
6930
- }
6931
- }
6932
- return -1;
6933
- }
6934
-
6935
-
6936
-
6937
- function parseInstruction(source,start,domBuilder){
6938
- var end = source.indexOf('?>',start);
6939
- if(end){
6940
- var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
6941
- if(match){
6942
- var len = match[0].length;
6943
- domBuilder.processingInstruction(match[1], match[2]) ;
6944
- return end+2;
6945
- }else{//error
6946
- return -1;
6947
- }
6948
- }
6949
- return -1;
6950
- }
6951
-
6952
- /**
6953
- * @param source
6954
- */
6955
- function ElementAttributes(source){
6956
-
6957
- }
6958
- ElementAttributes.prototype = {
6959
- setTagName:function(tagName){
6960
- if(!tagNamePattern.test(tagName)){
6961
- throw new Error('invalid tagName:'+tagName)
6962
- }
6963
- this.tagName = tagName
6964
- },
6965
- add:function(qName,value,offset){
6966
- if(!tagNamePattern.test(qName)){
6967
- throw new Error('invalid attribute:'+qName)
6968
- }
6969
- this[this.length++] = {qName:qName,value:value,offset:offset}
6970
- },
6971
- length:0,
6972
- getLocalName:function(i){return this[i].localName},
6973
- getLocator:function(i){return this[i].locator},
6974
- getQName:function(i){return this[i].qName},
6975
- getURI:function(i){return this[i].uri},
6976
- getValue:function(i){return this[i].value}
6977
- // ,getIndex:function(uri, localName)){
6978
- // if(localName){
6979
- //
6980
- // }else{
6981
- // var qName = uri
6982
- // }
6983
- // },
6984
- // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
6985
- // getType:function(uri,localName){}
6986
- // getType:function(i){},
6987
- }
6988
-
6989
-
6990
-
6991
-
6992
- function _set_proto_(thiz,parent){
6993
- thiz.__proto__ = parent;
6994
- return thiz;
6995
- }
6996
- if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
6997
- _set_proto_ = function(thiz,parent){
6998
- function p(){};
6999
- p.prototype = parent;
7000
- p = new p();
7001
- for(parent in thiz){
7002
- p[parent] = thiz[parent];
7003
- }
7004
- return p;
7005
- }
7006
- }
7007
-
7008
- function split(source,start){
7009
- var match;
7010
- var buf = [];
7011
- var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
7012
- reg.lastIndex = start;
7013
- reg.exec(source);//skip <
7014
- while(match = reg.exec(source)){
7015
- buf.push(match);
7016
- if(match[1])return buf;
7017
- }
7018
- }
7019
-
7020
- exports.XMLReader = XMLReader;
7021
-
6498
+ exports.entityMap = {
6499
+ lt: '<',
6500
+ gt: '>',
6501
+ amp: '&',
6502
+ quot: '"',
6503
+ apos: "'",
6504
+ Agrave: "À",
6505
+ Aacute: "Á",
6506
+ Acirc: "Â",
6507
+ Atilde: "Ã",
6508
+ Auml: "Ä",
6509
+ Aring: "Å",
6510
+ AElig: "Æ",
6511
+ Ccedil: "Ç",
6512
+ Egrave: "È",
6513
+ Eacute: "É",
6514
+ Ecirc: "Ê",
6515
+ Euml: "Ë",
6516
+ Igrave: "Ì",
6517
+ Iacute: "Í",
6518
+ Icirc: "Î",
6519
+ Iuml: "Ï",
6520
+ ETH: "Ð",
6521
+ Ntilde: "Ñ",
6522
+ Ograve: "Ò",
6523
+ Oacute: "Ó",
6524
+ Ocirc: "Ô",
6525
+ Otilde: "Õ",
6526
+ Ouml: "Ö",
6527
+ Oslash: "Ø",
6528
+ Ugrave: "Ù",
6529
+ Uacute: "Ú",
6530
+ Ucirc: "Û",
6531
+ Uuml: "Ü",
6532
+ Yacute: "Ý",
6533
+ THORN: "Þ",
6534
+ szlig: "ß",
6535
+ agrave: "à",
6536
+ aacute: "á",
6537
+ acirc: "â",
6538
+ atilde: "ã",
6539
+ auml: "ä",
6540
+ aring: "å",
6541
+ aelig: "æ",
6542
+ ccedil: "ç",
6543
+ egrave: "è",
6544
+ eacute: "é",
6545
+ ecirc: "ê",
6546
+ euml: "ë",
6547
+ igrave: "ì",
6548
+ iacute: "í",
6549
+ icirc: "î",
6550
+ iuml: "ï",
6551
+ eth: "ð",
6552
+ ntilde: "ñ",
6553
+ ograve: "ò",
6554
+ oacute: "ó",
6555
+ ocirc: "ô",
6556
+ otilde: "õ",
6557
+ ouml: "ö",
6558
+ oslash: "ø",
6559
+ ugrave: "ù",
6560
+ uacute: "ú",
6561
+ ucirc: "û",
6562
+ uuml: "ü",
6563
+ yacute: "ý",
6564
+ thorn: "þ",
6565
+ yuml: "ÿ",
6566
+ nbsp: "\u00a0",
6567
+ iexcl: "¡",
6568
+ cent: "¢",
6569
+ pound: "£",
6570
+ curren: "¤",
6571
+ yen: "¥",
6572
+ brvbar: "¦",
6573
+ sect: "§",
6574
+ uml: "¨",
6575
+ copy: "©",
6576
+ ordf: "ª",
6577
+ laquo: "«",
6578
+ not: "¬",
6579
+ shy: "­­",
6580
+ reg: "®",
6581
+ macr: "¯",
6582
+ deg: "°",
6583
+ plusmn: "±",
6584
+ sup2: "²",
6585
+ sup3: "³",
6586
+ acute: "´",
6587
+ micro: "µ",
6588
+ para: "¶",
6589
+ middot: "·",
6590
+ cedil: "¸",
6591
+ sup1: "¹",
6592
+ ordm: "º",
6593
+ raquo: "»",
6594
+ frac14: "¼",
6595
+ frac12: "½",
6596
+ frac34: "¾",
6597
+ iquest: "¿",
6598
+ times: "×",
6599
+ divide: "÷",
6600
+ forall: "∀",
6601
+ part: "∂",
6602
+ exist: "∃",
6603
+ empty: "∅",
6604
+ nabla: "∇",
6605
+ isin: "∈",
6606
+ notin: "∉",
6607
+ ni: "∋",
6608
+ prod: "∏",
6609
+ sum: "∑",
6610
+ minus: "−",
6611
+ lowast: "∗",
6612
+ radic: "√",
6613
+ prop: "∝",
6614
+ infin: "∞",
6615
+ ang: "∠",
6616
+ and: "∧",
6617
+ or: "∨",
6618
+ cap: "∩",
6619
+ cup: "∪",
6620
+ 'int': "∫",
6621
+ there4: "∴",
6622
+ sim: "∼",
6623
+ cong: "≅",
6624
+ asymp: "≈",
6625
+ ne: "≠",
6626
+ equiv: "≡",
6627
+ le: "≤",
6628
+ ge: "≥",
6629
+ sub: "⊂",
6630
+ sup: "⊃",
6631
+ nsub: "⊄",
6632
+ sube: "⊆",
6633
+ supe: "⊇",
6634
+ oplus: "⊕",
6635
+ otimes: "⊗",
6636
+ perp: "⊥",
6637
+ sdot: "⋅",
6638
+ Alpha: "Α",
6639
+ Beta: "Β",
6640
+ Gamma: "Γ",
6641
+ Delta: "Δ",
6642
+ Epsilon: "Ε",
6643
+ Zeta: "Ζ",
6644
+ Eta: "Η",
6645
+ Theta: "Θ",
6646
+ Iota: "Ι",
6647
+ Kappa: "Κ",
6648
+ Lambda: "Λ",
6649
+ Mu: "Μ",
6650
+ Nu: "Ν",
6651
+ Xi: "Ξ",
6652
+ Omicron: "Ο",
6653
+ Pi: "Π",
6654
+ Rho: "Ρ",
6655
+ Sigma: "Σ",
6656
+ Tau: "Τ",
6657
+ Upsilon: "Υ",
6658
+ Phi: "Φ",
6659
+ Chi: "Χ",
6660
+ Psi: "Ψ",
6661
+ Omega: "Ω",
6662
+ alpha: "α",
6663
+ beta: "β",
6664
+ gamma: "γ",
6665
+ delta: "δ",
6666
+ epsilon: "ε",
6667
+ zeta: "ζ",
6668
+ eta: "η",
6669
+ theta: "θ",
6670
+ iota: "ι",
6671
+ kappa: "κ",
6672
+ lambda: "λ",
6673
+ mu: "μ",
6674
+ nu: "ν",
6675
+ xi: "ξ",
6676
+ omicron: "ο",
6677
+ pi: "π",
6678
+ rho: "ρ",
6679
+ sigmaf: "ς",
6680
+ sigma: "σ",
6681
+ tau: "τ",
6682
+ upsilon: "υ",
6683
+ phi: "φ",
6684
+ chi: "χ",
6685
+ psi: "ψ",
6686
+ omega: "ω",
6687
+ thetasym: "ϑ",
6688
+ upsih: "ϒ",
6689
+ piv: "ϖ",
6690
+ OElig: "Œ",
6691
+ oelig: "œ",
6692
+ Scaron: "Š",
6693
+ scaron: "š",
6694
+ Yuml: "Ÿ",
6695
+ fnof: "ƒ",
6696
+ circ: "ˆ",
6697
+ tilde: "˜",
6698
+ ensp: " ",
6699
+ emsp: " ",
6700
+ thinsp: " ",
6701
+ zwnj: "‌",
6702
+ zwj: "‍",
6703
+ lrm: "‎",
6704
+ rlm: "‏",
6705
+ ndash: "–",
6706
+ mdash: "—",
6707
+ lsquo: "‘",
6708
+ rsquo: "’",
6709
+ sbquo: "‚",
6710
+ ldquo: "“",
6711
+ rdquo: "”",
6712
+ bdquo: "„",
6713
+ dagger: "†",
6714
+ Dagger: "‡",
6715
+ bull: "•",
6716
+ hellip: "…",
6717
+ permil: "‰",
6718
+ prime: "′",
6719
+ Prime: "″",
6720
+ lsaquo: "‹",
6721
+ rsaquo: "›",
6722
+ oline: "‾",
6723
+ euro: "€",
6724
+ trade: "™",
6725
+ larr: "←",
6726
+ uarr: "↑",
6727
+ rarr: "→",
6728
+ darr: "↓",
6729
+ harr: "↔",
6730
+ crarr: "↵",
6731
+ lceil: "⌈",
6732
+ rceil: "⌉",
6733
+ lfloor: "⌊",
6734
+ rfloor: "⌋",
6735
+ loz: "◊",
6736
+ spades: "♠",
6737
+ clubs: "♣",
6738
+ hearts: "♥",
6739
+ diams: "♦"
6740
+ };
6741
+
6742
+ },{}],33:[function(require,module,exports){
6743
+ //[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]
6744
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
6745
+ //[5] Name ::= NameStartChar (NameChar)*
6746
+ 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
6747
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
6748
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
6749
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
6750
+ //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(',')
6751
+
6752
+ //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
6753
+ //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
6754
+ var S_TAG = 0;//tag name offerring
6755
+ var S_ATTR = 1;//attr name offerring
6756
+ var S_ATTR_SPACE=2;//attr name end and space offer
6757
+ var S_EQ = 3;//=space?
6758
+ var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
6759
+ var S_ATTR_END = 5;//attr value end and no space(quot end)
6760
+ var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
6761
+ var S_TAG_CLOSE = 7;//closed el<el />
6762
+
6763
+ /**
6764
+ * Creates an error that will not be caught by XMLReader aka the SAX parser.
6765
+ *
6766
+ * @param {string} message
6767
+ * @param {any?} locator Optional, can provide details about the location in the source
6768
+ * @constructor
6769
+ */
6770
+ function ParseError(message, locator) {
6771
+ this.message = message
6772
+ this.locator = locator
6773
+ if(Error.captureStackTrace) Error.captureStackTrace(this, ParseError);
6774
+ }
6775
+ ParseError.prototype = new Error();
6776
+ ParseError.prototype.name = ParseError.name
6777
+
6778
+ function XMLReader(){
6779
+
6780
+ }
6781
+
6782
+ XMLReader.prototype = {
6783
+ parse:function(source,defaultNSMap,entityMap){
6784
+ var domBuilder = this.domBuilder;
6785
+ domBuilder.startDocument();
6786
+ _copy(defaultNSMap ,defaultNSMap = {})
6787
+ parse(source,defaultNSMap,entityMap,
6788
+ domBuilder,this.errorHandler);
6789
+ domBuilder.endDocument();
6790
+ }
6791
+ }
6792
+ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
6793
+ function fixedFromCharCode(code) {
6794
+ // String.prototype.fromCharCode does not supports
6795
+ // > 2 bytes unicode chars directly
6796
+ if (code > 0xffff) {
6797
+ code -= 0x10000;
6798
+ var surrogate1 = 0xd800 + (code >> 10)
6799
+ , surrogate2 = 0xdc00 + (code & 0x3ff);
6800
+
6801
+ return String.fromCharCode(surrogate1, surrogate2);
6802
+ } else {
6803
+ return String.fromCharCode(code);
6804
+ }
6805
+ }
6806
+ function entityReplacer(a){
6807
+ var k = a.slice(1,-1);
6808
+ if(k in entityMap){
6809
+ return entityMap[k];
6810
+ }else if(k.charAt(0) === '#'){
6811
+ return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
6812
+ }else{
6813
+ errorHandler.error('entity not found:'+a);
6814
+ return a;
6815
+ }
6816
+ }
6817
+ function appendText(end){//has some bugs
6818
+ if(end>start){
6819
+ var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
6820
+ locator&&position(start);
6821
+ domBuilder.characters(xt,0,end-start);
6822
+ start = end
6823
+ }
6824
+ }
6825
+ function position(p,m){
6826
+ while(p>=lineEnd && (m = linePattern.exec(source))){
6827
+ lineStart = m.index;
6828
+ lineEnd = lineStart + m[0].length;
6829
+ locator.lineNumber++;
6830
+ //console.log('line++:',locator,startPos,endPos)
6831
+ }
6832
+ locator.columnNumber = p-lineStart+1;
6833
+ }
6834
+ var lineStart = 0;
6835
+ var lineEnd = 0;
6836
+ var linePattern = /.*(?:\r\n?|\n)|.*$/g
6837
+ var locator = domBuilder.locator;
6838
+
6839
+ var parseStack = [{currentNSMap:defaultNSMapCopy}]
6840
+ var closeMap = {};
6841
+ var start = 0;
6842
+ while(true){
6843
+ try{
6844
+ var tagStart = source.indexOf('<',start);
6845
+ if(tagStart<0){
6846
+ if(!source.substr(start).match(/^\s*$/)){
6847
+ var doc = domBuilder.doc;
6848
+ var text = doc.createTextNode(source.substr(start));
6849
+ doc.appendChild(text);
6850
+ domBuilder.currentElement = text;
6851
+ }
6852
+ return;
6853
+ }
6854
+ if(tagStart>start){
6855
+ appendText(tagStart);
6856
+ }
6857
+ switch(source.charAt(tagStart+1)){
6858
+ case '/':
6859
+ var end = source.indexOf('>',tagStart+3);
6860
+ var tagName = source.substring(tagStart+2,end);
6861
+ var config = parseStack.pop();
6862
+ if(end<0){
6863
+
6864
+ tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
6865
+ //console.error('#@@@@@@'+tagName)
6866
+ errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
6867
+ end = tagStart+1+tagName.length;
6868
+ }else if(tagName.match(/\s</)){
6869
+ tagName = tagName.replace(/[\s<].*/,'');
6870
+ errorHandler.error("end tag name: "+tagName+' maybe not complete');
6871
+ end = tagStart+1+tagName.length;
6872
+ }
6873
+ //console.error(parseStack.length,parseStack)
6874
+ //console.error(config);
6875
+ var localNSMap = config.localNSMap;
6876
+ var endMatch = config.tagName == tagName;
6877
+ var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
6878
+ if(endIgnoreCaseMach){
6879
+ domBuilder.endElement(config.uri,config.localName,tagName);
6880
+ if(localNSMap){
6881
+ for(var prefix in localNSMap){
6882
+ domBuilder.endPrefixMapping(prefix) ;
6883
+ }
6884
+ }
6885
+ if(!endMatch){
6886
+ errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName ); // No known test case
6887
+ }
6888
+ }else{
6889
+ parseStack.push(config)
6890
+ }
6891
+
6892
+ end++;
6893
+ break;
6894
+ // end elment
6895
+ case '?':// <?...?>
6896
+ locator&&position(tagStart);
6897
+ end = parseInstruction(source,tagStart,domBuilder);
6898
+ break;
6899
+ case '!':// <!doctype,<![CDATA,<!--
6900
+ locator&&position(tagStart);
6901
+ end = parseDCC(source,tagStart,domBuilder,errorHandler);
6902
+ break;
6903
+ default:
6904
+ locator&&position(tagStart);
6905
+ var el = new ElementAttributes();
6906
+ var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
6907
+ //elStartEnd
6908
+ var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
6909
+ var len = el.length;
6910
+
6911
+
6912
+ if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
6913
+ el.closed = true;
6914
+ if(!entityMap.nbsp){
6915
+ errorHandler.warning('unclosed xml attribute');
6916
+ }
6917
+ }
6918
+ if(locator && len){
6919
+ var locator2 = copyLocator(locator,{});
6920
+ //try{//attribute position fixed
6921
+ for(var i = 0;i<len;i++){
6922
+ var a = el[i];
6923
+ position(a.offset);
6924
+ a.locator = copyLocator(locator,{});
6925
+ }
6926
+ //}catch(e){console.error('@@@@@'+e)}
6927
+ domBuilder.locator = locator2
6928
+ if(appendElement(el,domBuilder,currentNSMap)){
6929
+ parseStack.push(el)
6930
+ }
6931
+ domBuilder.locator = locator;
6932
+ }else{
6933
+ if(appendElement(el,domBuilder,currentNSMap)){
6934
+ parseStack.push(el)
6935
+ }
6936
+ }
6937
+
6938
+
6939
+
6940
+ if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
6941
+ end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
6942
+ }else{
6943
+ end++;
6944
+ }
6945
+ }
6946
+ }catch(e){
6947
+ if (e instanceof ParseError) {
6948
+ throw e;
6949
+ }
6950
+ errorHandler.error('element parse error: '+e)
6951
+ end = -1;
6952
+ }
6953
+ if(end>start){
6954
+ start = end;
6955
+ }else{
6956
+ //TODO: 这里有可能sax回退,有位置错误风险
6957
+ appendText(Math.max(tagStart,start)+1);
6958
+ }
6959
+ }
6960
+ }
6961
+ function copyLocator(f,t){
6962
+ t.lineNumber = f.lineNumber;
6963
+ t.columnNumber = f.columnNumber;
6964
+ return t;
6965
+ }
6966
+
6967
+ /**
6968
+ * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
6969
+ * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
6970
+ */
6971
+ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
6972
+
6973
+ /**
6974
+ * @param {string} qname
6975
+ * @param {string} value
6976
+ * @param {number} startIndex
6977
+ */
6978
+ function addAttribute(qname, value, startIndex) {
6979
+ if (qname in el.attributeNames) errorHandler.fatalError('Attribute ' + qname + ' redefined')
6980
+ el.addValue(qname, value, startIndex)
6981
+ }
6982
+ var attrName;
6983
+ var value;
6984
+ var p = ++start;
6985
+ var s = S_TAG;//status
6986
+ while(true){
6987
+ var c = source.charAt(p);
6988
+ switch(c){
6989
+ case '=':
6990
+ if(s === S_ATTR){//attrName
6991
+ attrName = source.slice(start,p);
6992
+ s = S_EQ;
6993
+ }else if(s === S_ATTR_SPACE){
6994
+ s = S_EQ;
6995
+ }else{
6996
+ //fatalError: equal must after attrName or space after attrName
6997
+ throw new Error('attribute equal must after attrName'); // No known test case
6998
+ }
6999
+ break;
7000
+ case '\'':
7001
+ case '"':
7002
+ if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
7003
+ ){//equal
7004
+ if(s === S_ATTR){
7005
+ errorHandler.warning('attribute value must after "="')
7006
+ attrName = source.slice(start,p)
7007
+ }
7008
+ start = p+1;
7009
+ p = source.indexOf(c,start)
7010
+ if(p>0){
7011
+ value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
7012
+ addAttribute(attrName, value, start-1);
7013
+ s = S_ATTR_END;
7014
+ }else{
7015
+ //fatalError: no end quot match
7016
+ throw new Error('attribute value no end \''+c+'\' match');
7017
+ }
7018
+ }else if(s == S_ATTR_NOQUOT_VALUE){
7019
+ value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
7020
+ //console.log(attrName,value,start,p)
7021
+ addAttribute(attrName, value, start);
7022
+ //console.dir(el)
7023
+ errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
7024
+ start = p+1;
7025
+ s = S_ATTR_END
7026
+ }else{
7027
+ //fatalError: no equal before
7028
+ throw new Error('attribute value must after "="'); // No known test case
7029
+ }
7030
+ break;
7031
+ case '/':
7032
+ switch(s){
7033
+ case S_TAG:
7034
+ el.setTagName(source.slice(start,p));
7035
+ case S_ATTR_END:
7036
+ case S_TAG_SPACE:
7037
+ case S_TAG_CLOSE:
7038
+ s =S_TAG_CLOSE;
7039
+ el.closed = true;
7040
+ case S_ATTR_NOQUOT_VALUE:
7041
+ case S_ATTR:
7042
+ case S_ATTR_SPACE:
7043
+ break;
7044
+ //case S_EQ:
7045
+ default:
7046
+ throw new Error("attribute invalid close char('/')") // No known test case
7047
+ }
7048
+ break;
7049
+ case ''://end document
7050
+ errorHandler.error('unexpected end of input');
7051
+ if(s == S_TAG){
7052
+ el.setTagName(source.slice(start,p));
7053
+ }
7054
+ return p;
7055
+ case '>':
7056
+ switch(s){
7057
+ case S_TAG:
7058
+ el.setTagName(source.slice(start,p));
7059
+ case S_ATTR_END:
7060
+ case S_TAG_SPACE:
7061
+ case S_TAG_CLOSE:
7062
+ break;//normal
7063
+ case S_ATTR_NOQUOT_VALUE://Compatible state
7064
+ case S_ATTR:
7065
+ value = source.slice(start,p);
7066
+ if(value.slice(-1) === '/'){
7067
+ el.closed = true;
7068
+ value = value.slice(0,-1)
7069
+ }
7070
+ case S_ATTR_SPACE:
7071
+ if(s === S_ATTR_SPACE){
7072
+ value = attrName;
7073
+ }
7074
+ if(s == S_ATTR_NOQUOT_VALUE){
7075
+ errorHandler.warning('attribute "'+value+'" missed quot(")!');
7076
+ addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start)
7077
+ }else{
7078
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
7079
+ errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
7080
+ }
7081
+ addAttribute(value, value, start)
7082
+ }
7083
+ break;
7084
+ case S_EQ:
7085
+ throw new Error('attribute value missed!!');
7086
+ }
7087
+ // console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
7088
+ return p;
7089
+ /*xml space '\x20' | #x9 | #xD | #xA; */
7090
+ case '\u0080':
7091
+ c = ' ';
7092
+ default:
7093
+ if(c<= ' '){//space
7094
+ switch(s){
7095
+ case S_TAG:
7096
+ el.setTagName(source.slice(start,p));//tagName
7097
+ s = S_TAG_SPACE;
7098
+ break;
7099
+ case S_ATTR:
7100
+ attrName = source.slice(start,p)
7101
+ s = S_ATTR_SPACE;
7102
+ break;
7103
+ case S_ATTR_NOQUOT_VALUE:
7104
+ var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
7105
+ errorHandler.warning('attribute "'+value+'" missed quot(")!!');
7106
+ addAttribute(attrName, value, start)
7107
+ case S_ATTR_END:
7108
+ s = S_TAG_SPACE;
7109
+ break;
7110
+ //case S_TAG_SPACE:
7111
+ //case S_EQ:
7112
+ //case S_ATTR_SPACE:
7113
+ // void();break;
7114
+ //case S_TAG_CLOSE:
7115
+ //ignore warning
7116
+ }
7117
+ }else{//not space
7118
+ //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
7119
+ //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
7120
+ switch(s){
7121
+ //case S_TAG:void();break;
7122
+ //case S_ATTR:void();break;
7123
+ //case S_ATTR_NOQUOT_VALUE:void();break;
7124
+ case S_ATTR_SPACE:
7125
+ var tagName = el.tagName;
7126
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
7127
+ errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
7128
+ }
7129
+ addAttribute(attrName, attrName, start);
7130
+ start = p;
7131
+ s = S_ATTR;
7132
+ break;
7133
+ case S_ATTR_END:
7134
+ errorHandler.warning('attribute space is required"'+attrName+'"!!')
7135
+ case S_TAG_SPACE:
7136
+ s = S_ATTR;
7137
+ start = p;
7138
+ break;
7139
+ case S_EQ:
7140
+ s = S_ATTR_NOQUOT_VALUE;
7141
+ start = p;
7142
+ break;
7143
+ case S_TAG_CLOSE:
7144
+ throw new Error("elements closed character '/' and '>' must be connected to");
7145
+ }
7146
+ }
7147
+ }//end outer switch
7148
+ //console.log('p++',p)
7149
+ p++;
7150
+ }
7151
+ }
7152
+ /**
7153
+ * @return true if has new namespace define
7154
+ */
7155
+ function appendElement(el,domBuilder,currentNSMap){
7156
+ var tagName = el.tagName;
7157
+ var localNSMap = null;
7158
+ //var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
7159
+ var i = el.length;
7160
+ while(i--){
7161
+ var a = el[i];
7162
+ var qName = a.qName;
7163
+ var value = a.value;
7164
+ var nsp = qName.indexOf(':');
7165
+ if(nsp>0){
7166
+ var prefix = a.prefix = qName.slice(0,nsp);
7167
+ var localName = qName.slice(nsp+1);
7168
+ var nsPrefix = prefix === 'xmlns' && localName
7169
+ }else{
7170
+ localName = qName;
7171
+ prefix = null
7172
+ nsPrefix = qName === 'xmlns' && ''
7173
+ }
7174
+ //can not set prefix,because prefix !== ''
7175
+ a.localName = localName ;
7176
+ //prefix == null for no ns prefix attribute
7177
+ if(nsPrefix !== false){//hack!!
7178
+ if(localNSMap == null){
7179
+ localNSMap = {}
7180
+ //console.log(currentNSMap,0)
7181
+ _copy(currentNSMap,currentNSMap={})
7182
+ //console.log(currentNSMap,1)
7183
+ }
7184
+ currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
7185
+ a.uri = 'http://www.w3.org/2000/xmlns/'
7186
+ domBuilder.startPrefixMapping(nsPrefix, value)
7187
+ }
7188
+ }
7189
+ var i = el.length;
7190
+ while(i--){
7191
+ a = el[i];
7192
+ var prefix = a.prefix;
7193
+ if(prefix){//no prefix attribute has no namespace
7194
+ if(prefix === 'xml'){
7195
+ a.uri = 'http://www.w3.org/XML/1998/namespace';
7196
+ }if(prefix !== 'xmlns'){
7197
+ a.uri = currentNSMap[prefix || '']
7198
+
7199
+ //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
7200
+ }
7201
+ }
7202
+ }
7203
+ var nsp = tagName.indexOf(':');
7204
+ if(nsp>0){
7205
+ prefix = el.prefix = tagName.slice(0,nsp);
7206
+ localName = el.localName = tagName.slice(nsp+1);
7207
+ }else{
7208
+ prefix = null;//important!!
7209
+ localName = el.localName = tagName;
7210
+ }
7211
+ //no prefix element has default namespace
7212
+ var ns = el.uri = currentNSMap[prefix || ''];
7213
+ domBuilder.startElement(ns,localName,tagName,el);
7214
+ //endPrefixMapping and startPrefixMapping have not any help for dom builder
7215
+ //localNSMap = null
7216
+ if(el.closed){
7217
+ domBuilder.endElement(ns,localName,tagName);
7218
+ if(localNSMap){
7219
+ for(prefix in localNSMap){
7220
+ domBuilder.endPrefixMapping(prefix)
7221
+ }
7222
+ }
7223
+ }else{
7224
+ el.currentNSMap = currentNSMap;
7225
+ el.localNSMap = localNSMap;
7226
+ //parseStack.push(el);
7227
+ return true;
7228
+ }
7229
+ }
7230
+ function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
7231
+ if(/^(?:script|textarea)$/i.test(tagName)){
7232
+ var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
7233
+ var text = source.substring(elStartEnd+1,elEndStart);
7234
+ if(/[&<]/.test(text)){
7235
+ if(/^script$/i.test(tagName)){
7236
+ //if(!/\]\]>/.test(text)){
7237
+ //lexHandler.startCDATA();
7238
+ domBuilder.characters(text,0,text.length);
7239
+ //lexHandler.endCDATA();
7240
+ return elEndStart;
7241
+ //}
7242
+ }//}else{//text area
7243
+ text = text.replace(/&#?\w+;/g,entityReplacer);
7244
+ domBuilder.characters(text,0,text.length);
7245
+ return elEndStart;
7246
+ //}
7247
+
7248
+ }
7249
+ }
7250
+ return elStartEnd+1;
7251
+ }
7252
+ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
7253
+ //if(tagName in closeMap){
7254
+ var pos = closeMap[tagName];
7255
+ if(pos == null){
7256
+ //console.log(tagName)
7257
+ pos = source.lastIndexOf('</'+tagName+'>')
7258
+ if(pos<elStartEnd){//忘记闭合
7259
+ pos = source.lastIndexOf('</'+tagName)
7260
+ }
7261
+ closeMap[tagName] =pos
7262
+ }
7263
+ return pos<elStartEnd;
7264
+ //}
7265
+ }
7266
+ function _copy(source,target){
7267
+ for(var n in source){target[n] = source[n]}
7268
+ }
7269
+ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
7270
+ var next= source.charAt(start+2)
7271
+ switch(next){
7272
+ case '-':
7273
+ if(source.charAt(start + 3) === '-'){
7274
+ var end = source.indexOf('-->',start+4);
7275
+ //append comment source.substring(4,end)//<!--
7276
+ if(end>start){
7277
+ domBuilder.comment(source,start+4,end-start-4);
7278
+ return end+3;
7279
+ }else{
7280
+ errorHandler.error("Unclosed comment");
7281
+ return -1;
7282
+ }
7283
+ }else{
7284
+ //error
7285
+ return -1;
7286
+ }
7287
+ default:
7288
+ if(source.substr(start+3,6) == 'CDATA['){
7289
+ var end = source.indexOf(']]>',start+9);
7290
+ domBuilder.startCDATA();
7291
+ domBuilder.characters(source,start+9,end-start-9);
7292
+ domBuilder.endCDATA()
7293
+ return end+3;
7294
+ }
7295
+ //<!DOCTYPE
7296
+ //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
7297
+ var matchs = split(source,start);
7298
+ var len = matchs.length;
7299
+ if(len>1 && /!doctype/i.test(matchs[0][0])){
7300
+ var name = matchs[1][0];
7301
+ var pubid = false;
7302
+ var sysid = false;
7303
+ if(len>3){
7304
+ if(/^public$/i.test(matchs[2][0])){
7305
+ pubid = matchs[3][0];
7306
+ sysid = len>4 && matchs[4][0];
7307
+ }else if(/^system$/i.test(matchs[2][0])){
7308
+ sysid = matchs[3][0];
7309
+ }
7310
+ }
7311
+ var lastMatch = matchs[len-1]
7312
+ domBuilder.startDTD(name, pubid, sysid);
7313
+ domBuilder.endDTD();
7314
+
7315
+ return lastMatch.index+lastMatch[0].length
7316
+ }
7317
+ }
7318
+ return -1;
7319
+ }
7320
+
7321
+
7322
+
7323
+ function parseInstruction(source,start,domBuilder){
7324
+ var end = source.indexOf('?>',start);
7325
+ if(end){
7326
+ var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
7327
+ if(match){
7328
+ var len = match[0].length;
7329
+ domBuilder.processingInstruction(match[1], match[2]) ;
7330
+ return end+2;
7331
+ }else{//error
7332
+ return -1;
7333
+ }
7334
+ }
7335
+ return -1;
7336
+ }
7337
+
7338
+ function ElementAttributes(){
7339
+ this.attributeNames = {}
7340
+ }
7341
+ ElementAttributes.prototype = {
7342
+ setTagName:function(tagName){
7343
+ if(!tagNamePattern.test(tagName)){
7344
+ throw new Error('invalid tagName:'+tagName)
7345
+ }
7346
+ this.tagName = tagName
7347
+ },
7348
+ addValue:function(qName, value, offset) {
7349
+ if(!tagNamePattern.test(qName)){
7350
+ throw new Error('invalid attribute:'+qName)
7351
+ }
7352
+ this.attributeNames[qName] = this.length;
7353
+ this[this.length++] = {qName:qName,value:value,offset:offset}
7354
+ },
7355
+ length:0,
7356
+ getLocalName:function(i){return this[i].localName},
7357
+ getLocator:function(i){return this[i].locator},
7358
+ getQName:function(i){return this[i].qName},
7359
+ getURI:function(i){return this[i].uri},
7360
+ getValue:function(i){return this[i].value}
7361
+ // ,getIndex:function(uri, localName)){
7362
+ // if(localName){
7363
+ //
7364
+ // }else{
7365
+ // var qName = uri
7366
+ // }
7367
+ // },
7368
+ // getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
7369
+ // getType:function(uri,localName){}
7370
+ // getType:function(i){},
7371
+ }
7372
+
7373
+
7374
+
7375
+ function split(source,start){
7376
+ var match;
7377
+ var buf = [];
7378
+ var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
7379
+ reg.lastIndex = start;
7380
+ reg.exec(source);//skip <
7381
+ while(match = reg.exec(source)){
7382
+ buf.push(match);
7383
+ if(match[1])return buf;
7384
+ }
7385
+ }
7386
+
7387
+ exports.XMLReader = XMLReader;
7388
+ exports.ParseError = ParseError;
7022
7389
 
7023
7390
  },{}]},{},[1])(1)
7024
7391
  });